diff --git a/Duplicati.sln b/Duplicati.sln index d162cb249..864d132c9 100644 --- a/Duplicati.sln +++ b/Duplicati.sln @@ -105,6 +105,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Duplicati.Library.Backend.T EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Duplicati.Library.Backend.TencentCOS", "Duplicati\Library\Backend\TencentCOS\Duplicati.Library.Backend.TencentCOS.csproj", "{545DD6D4-9476-42D6-B51C-A28E000C489E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Duplicati.Library.Backend.Telegram", "Duplicati\Library\Backend\Telegram\Duplicati.Library.Backend.Telegram.csproj", "{F61679A9-E5DE-468A-B5A4-05F92D0143D2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TelegramTest", "TelegramTest\TelegramTest.csproj", "{F83A537E-895A-496B-AA5F-693E0F9BAE4B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -315,6 +319,10 @@ Global {545DD6D4-9476-42D6-B51C-A28E000C489E}.Debug|Any CPU.Build.0 = Debug|Any CPU {545DD6D4-9476-42D6-B51C-A28E000C489E}.Release|Any CPU.ActiveCfg = Release|Any CPU {545DD6D4-9476-42D6-B51C-A28E000C489E}.Release|Any CPU.Build.0 = Release|Any CPU + {F83A537E-895A-496B-AA5F-693E0F9BAE4B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F83A537E-895A-496B-AA5F-693E0F9BAE4B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F83A537E-895A-496B-AA5F-693E0F9BAE4B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F83A537E-895A-496B-AA5F-693E0F9BAE4B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Duplicati/CommandLine/BackendTester/Duplicati.CommandLine.BackendTester.csproj b/Duplicati/CommandLine/BackendTester/Duplicati.CommandLine.BackendTester.csproj index 721163ebb..d14298b1e 100644 --- a/Duplicati/CommandLine/BackendTester/Duplicati.CommandLine.BackendTester.csproj +++ b/Duplicati/CommandLine/BackendTester/Duplicati.CommandLine.BackendTester.csproj @@ -90,6 +90,10 @@ {ae035e01-c917-4f13-a35e-78f21c1a2f17} Duplicati.Library.Backend.Tardigrade + + {f61679a9-e5de-468a-b5a4-05f92d0143d2} + Duplicati.Library.Backend.Telegram + {545dd6d4-9476-42d6-b51c-a28e000c489e} Duplicati.Library.Backend.TencentCOS diff --git a/Duplicati/CommandLine/BackendTool/Duplicati.CommandLine.BackendTool.csproj b/Duplicati/CommandLine/BackendTool/Duplicati.CommandLine.BackendTool.csproj index 694439e22..97f949e5e 100644 --- a/Duplicati/CommandLine/BackendTool/Duplicati.CommandLine.BackendTool.csproj +++ b/Duplicati/CommandLine/BackendTool/Duplicati.CommandLine.BackendTool.csproj @@ -96,6 +96,10 @@ {ae035e01-c917-4f13-a35e-78f21c1a2f17} Duplicati.Library.Backend.Tardigrade + + {f61679a9-e5de-468a-b5a4-05f92d0143d2} + Duplicati.Library.Backend.Telegram + {545dd6d4-9476-42d6-b51c-a28e000c489e} Duplicati.Library.Backend.TencentCOS diff --git a/Duplicati/CommandLine/Duplicati.CommandLine.csproj b/Duplicati/CommandLine/Duplicati.CommandLine.csproj index 83b3926dc..8e8661851 100644 --- a/Duplicati/CommandLine/Duplicati.CommandLine.csproj +++ b/Duplicati/CommandLine/Duplicati.CommandLine.csproj @@ -111,6 +111,10 @@ {32a74526-3e5f-413a-8cb4-1efdad4c8b91} Duplicati.Library.Backend.Sia + + {f61679a9-e5de-468a-b5a4-05f92d0143d2} + Duplicati.Library.Backend.Telegram + {19ECCE09-B5EB-406C-8C57-BAC66997D469} Duplicati.Library.Compression diff --git a/Duplicati/CommandLine/RecoveryTool/Duplicati.CommandLine.RecoveryTool.csproj b/Duplicati/CommandLine/RecoveryTool/Duplicati.CommandLine.RecoveryTool.csproj index 819aff870..671e8ed71 100644 --- a/Duplicati/CommandLine/RecoveryTool/Duplicati.CommandLine.RecoveryTool.csproj +++ b/Duplicati/CommandLine/RecoveryTool/Duplicati.CommandLine.RecoveryTool.csproj @@ -134,6 +134,10 @@ {C0270709-2A40-43B5-8CF1-69581B9FA2A1} Duplicati.Library.Backend.TahoeLAFS + + {f61679a9-e5de-468a-b5a4-05f92d0143d2} + Duplicati.Library.Backend.Telegram + {BAE27510-8B5D-44B2-B33E-372A98908041} Duplicati.Library.Backend.WEBDAV diff --git a/Duplicati/GUI/Duplicati.GUI.TrayIcon/Duplicati.GUI.TrayIcon.csproj b/Duplicati/GUI/Duplicati.GUI.TrayIcon/Duplicati.GUI.TrayIcon.csproj index e5b3f7b72..b5dec3e0a 100644 --- a/Duplicati/GUI/Duplicati.GUI.TrayIcon/Duplicati.GUI.TrayIcon.csproj +++ b/Duplicati/GUI/Duplicati.GUI.TrayIcon/Duplicati.GUI.TrayIcon.csproj @@ -221,6 +221,10 @@ {ae035e01-c917-4f13-a35e-78f21c1a2f17} Duplicati.Library.Backend.Tardigrade + + {f61679a9-e5de-468a-b5a4-05f92d0143d2} + Duplicati.Library.Backend.Telegram + {545dd6d4-9476-42d6-b51c-a28e000c489e} Duplicati.Library.Backend.TencentCOS diff --git a/Duplicati/Library/Backend/S3/S3Backend.cs b/Duplicati/Library/Backend/S3/S3Backend.cs index ee1b84eb1..5e7900ecb 100644 --- a/Duplicati/Library/Backend/S3/S3Backend.cs +++ b/Duplicati/Library/Backend/S3/S3Backend.cs @@ -114,6 +114,7 @@ namespace Duplicati.Library.Backend static S3() { + Console.WriteLine("STATIC CONSTRUCTOR!!"); var ns = new Dictionary(StringComparer.OrdinalIgnoreCase) { { "(default)", "" }, { "Standard", "STANDARD" }, @@ -166,10 +167,15 @@ namespace Duplicati.Library.Backend public S3() { + Console.WriteLine("Empty constructor!!"); + Console.WriteLine(this.GetHashCode()); } public S3(string url, Dictionary options) { + Console.WriteLine($"Parameterized constructor with url {url} and options count = {options.Count}"); + Console.WriteLine(this.GetHashCode()); + options.Add(new Random().Next().ToString(), "0"); var uri = new Utility.Uri(url); uri.RequireHost(); @@ -419,6 +425,8 @@ namespace Duplicati.Library.Backend public void Test() { + Console.WriteLine("TEST"); + Console.WriteLine(this.GetHashCode()); this.TestList(); } @@ -443,6 +451,7 @@ namespace Duplicati.Library.Backend public void Dispose() { + Console.WriteLine("Disposed!!!!"); s3Client?.Dispose(); s3Client = null; } diff --git a/Duplicati/Library/Backend/Telegram/Duplicati.Library.Backend.Telegram.csproj b/Duplicati/Library/Backend/Telegram/Duplicati.Library.Backend.Telegram.csproj new file mode 100644 index 000000000..2793355db --- /dev/null +++ b/Duplicati/Library/Backend/Telegram/Duplicati.Library.Backend.Telegram.csproj @@ -0,0 +1,96 @@ + + + + Debug + AnyCPU + {F61679A9-E5DE-468A-B5A4-05F92D0143D2} + Library + Properties + Duplicati.Library.Backend + Duplicati.Library.Backend.FTP + Duplicati.snk + + + 3.5 + v4.7.1 + + + + false + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + True + + + + + + ..\..\..\..\packages\TLSharp.0.1.0.555\lib\net46\TeleSharp.TL.dll + True + + + ..\..\..\..\packages\TLSharp.0.1.0.555\lib\net46\TLSharp.Core.dll + True + + + + + + + + + + + {52826615-7964-47FE-B4B3-1B2DBDF605B9} + Duplicati.Library.Modules.Builtin + + + {DE3E5D4C-51AB-4E5E-BEE8-E636CEBFBA65} + Duplicati.Library.Utility + + + {C5899F45-B0FF-483C-9D38-24A9FCAAB237} + Duplicati.Library.Interface + + + {B68F2214-951F-4F78-8488-66E1ED3F50BF} + Duplicati.Library.Localization + + + {D63E53E4-A458-4C2F-914D-92F715F58ACF} + Duplicati.Library.Common + + + + + + + + + + \ No newline at end of file diff --git a/Duplicati/Library/Backend/Telegram/Duplicati.snk b/Duplicati/Library/Backend/Telegram/Duplicati.snk new file mode 100644 index 000000000..e0c1e2dd8 Binary files /dev/null and b/Duplicati/Library/Backend/Telegram/Duplicati.snk differ diff --git a/Duplicati/Library/Backend/Telegram/InMemorySessionStore.cs b/Duplicati/Library/Backend/Telegram/InMemorySessionStore.cs new file mode 100644 index 000000000..ffc197854 --- /dev/null +++ b/Duplicati/Library/Backend/Telegram/InMemorySessionStore.cs @@ -0,0 +1,41 @@ +using System.Collections.Concurrent; +using TLSharp.Core; + +namespace Duplicati.Library.Backend +{ + public class InMemorySessionStore : ISessionStore + { + private readonly ConcurrentDictionary m_userIdSessionBytesMap = new ConcurrentDictionary(); + private readonly ConcurrentDictionary m_userIdPhoneCodeHashMap = new ConcurrentDictionary(); + + public void Save(Session session) + { + m_userIdSessionBytesMap[session.SessionUserId] = session.ToBytes(); + } + + public Session Load(string sessionUserId) + { + if (m_userIdSessionBytesMap.TryGetValue(sessionUserId, out var sessionBytes)) + { + return Session.FromBytes(sessionBytes, this, sessionUserId); + } + + return null; + } + + public void SetPhoneHash(string sessionUserId, string phoneCodeHash) + { + m_userIdPhoneCodeHashMap[sessionUserId] = phoneCodeHash; + } + + public string GetPhoneHash(string sessionUserId) + { + if (m_userIdPhoneCodeHashMap.TryGetValue(sessionUserId, out var result)) + { + return result; + } + + return null; + } + } +} \ No newline at end of file diff --git a/Duplicati/Library/Backend/Telegram/Properties/AssemblyInfo.cs b/Duplicati/Library/Backend/Telegram/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..35172e8d3 --- /dev/null +++ b/Duplicati/Library/Backend/Telegram/Properties/AssemblyInfo.cs @@ -0,0 +1,54 @@ +#region Disclaimer / License +// Copyright (C) 2015, The Duplicati Team +// http://www.duplicati.com, info@duplicati.com +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// +#endregion +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FTP")] +[assembly: AssemblyDescription("A FTP backend for Duplicati")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Duplicati Team")] +[assembly: AssemblyProduct("Duplicati.Backend.FTP")] +[assembly: AssemblyCopyright("LGPL, Copyright © Duplicati Team 2015")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("afa68988-4d82-490e-8044-acbc7d52ef4f")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Revision and Build Numbers +// by using the '*' as shown below: +[assembly: AssemblyVersion("2.0.0.7")] +[assembly: AssemblyFileVersion("2.0.0.7")] diff --git a/Duplicati/Library/Backend/Telegram/Strings.cs b/Duplicati/Library/Backend/Telegram/Strings.cs new file mode 100644 index 000000000..5b1d00e02 --- /dev/null +++ b/Duplicati/Library/Backend/Telegram/Strings.cs @@ -0,0 +1,17 @@ +using System; +using Duplicati.Library.Localization.Short; +using System.Collections.Generic; + +namespace Duplicati.Library.Backend.Strings { + internal static class TelegramBackend { + public static string Description { get { return LC.L(@"This backend can read and write data to a Telegram backend."); } } + public static string DisplayName { get { return LC.L(@"Telegram"); } } + public static string ListVerifyFailure(string filename, IEnumerable files) { return LC.L(@"The file {0} was uploaded but not found afterwards, the file listing returned {1}", filename, string.Join(Environment.NewLine, files)); } + public static string ListVerifySizeFailure(string filename, long actualsize, long expectedsize) { return LC.L(@"The file {0} was uploaded but the returned size was {1} and it was expected to be {2}", filename, actualsize, expectedsize); } + public static string DescriptionDisableUploadVerifyShort { get { return LC.L(@"Disable upload verification"); } } + public static string DescriptionDisableUploadVerifyLong { get { return LC.L(@"To protect against network failures, every upload will be attempted verified. Use this option to disable this verification to make the upload faster but less reliable."); } } + public static string NoApiIdError { get { return LC.L(@"The API ID is missing."); } } + public static string NoApiHashError { get { return LC.L(@"The API hash is missing."); } } + public static string NoPhoneNumberError { get { return LC.L(@"The phone number is missing."); } } + } +} diff --git a/Duplicati/Library/Backend/Telegram/TelegramBackend.cs b/Duplicati/Library/Backend/Telegram/TelegramBackend.cs new file mode 100644 index 000000000..b9acb3f38 --- /dev/null +++ b/Duplicati/Library/Backend/Telegram/TelegramBackend.cs @@ -0,0 +1,122 @@ +#region Disclaimer / License +// Copyright (C) 2015, The Duplicati Team +// http://www.duplicati.com, info@duplicati.com +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// +#endregion + +using Duplicati.Library.Interface; +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; +using TLSharp.Core; + +namespace Duplicati.Library.Backend +{ + // ReSharper disable once UnusedMember.Global + // This class is instantiated dynamically in the BackendLoader. + public class Telegram : IBackend + { + private static readonly InMemorySessionStore m_sessionStore = new InMemorySessionStore(); + + private readonly int m_apiId; + private readonly string m_apiHash; + private readonly string m_phoneNumber; + + private string m_authCode; + private string m_password; + + public Telegram() + { + Console.WriteLine("Welcome to Telegram parameterless"); + } + + // ReSharper disable once UnusedParameter.Local + // ToDo remove url if not needed + public Telegram(string url, Dictionary options) + { + Console.WriteLine("Welcome to Telegram"); + if (options.TryGetValue("api_id", out var apiId)) + m_apiId = int.Parse(apiId); + + if (options.TryGetValue("api_hash", out var apiHash)) + m_apiHash = apiHash; + + if (options.TryGetValue("phone_number", out var phoneNumber)) + m_phoneNumber = phoneNumber; + + if (options.TryGetValue("auth_code", out var authCode)) + m_authCode = authCode; + + if (options.TryGetValue("password", out var password)) + m_password = password; + + if (m_apiId == 0) + throw new UserInformationException(Strings.TelegramBackend.NoApiIdError, "NoApiIdError"); + + if (string.IsNullOrEmpty(m_apiHash)) + throw new UserInformationException(Strings.TelegramBackend.NoApiHashError, "NoApiHashError"); + + if (string.IsNullOrEmpty(m_phoneNumber)) + throw new UserInformationException(Strings.TelegramBackend.NoPhoneNumberError, "NoPhoneNumberError"); + } + + public void Dispose() + { } + + public string DisplayName { get; } = "Telegram"; + public string ProtocolKey { get; } = "https"; + + public IEnumerable List() + { + throw new NotImplementedException(); + } + + public Task PutAsync(string remotename, string filename, CancellationToken cancelToken) + { + throw new NotImplementedException(); + } + + public void Get(string remotename, string filename) + { + throw new NotImplementedException(); + } + + public void Delete(string remotename) + { + throw new NotImplementedException(); + } + + public IList SupportedCommands { get; } + + public string Description { get; } = Strings.TelegramBackend.Description; + + public string[] DNSName { get; } + + public void Test() + { + throw new NotImplementedException(); + } + + public void CreateFolder() + { + throw new NotImplementedException(); + } + } +} diff --git a/Duplicati/Library/Backend/Telegram/app.config b/Duplicati/Library/Backend/Telegram/app.config new file mode 100644 index 000000000..ba98fc967 --- /dev/null +++ b/Duplicati/Library/Backend/Telegram/app.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/Duplicati/Library/Backend/Telegram/packages.config b/Duplicati/Library/Backend/Telegram/packages.config new file mode 100644 index 000000000..fb6afc7ff --- /dev/null +++ b/Duplicati/Library/Backend/Telegram/packages.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Duplicati/Server/Duplicati.Server.csproj b/Duplicati/Server/Duplicati.Server.csproj index 4a81dbdad..fe7c5b027 100644 --- a/Duplicati/Server/Duplicati.Server.csproj +++ b/Duplicati/Server/Duplicati.Server.csproj @@ -207,6 +207,10 @@ {ae035e01-c917-4f13-a35e-78f21c1a2f17} Duplicati.Library.Backend.Tardigrade + + {f61679a9-e5de-468a-b5a4-05f92d0143d2} + Duplicati.Library.Backend.Telegram + {545dd6d4-9476-42d6-b51c-a28e000c489e} Duplicati.Library.Backend.TencentCOS diff --git a/TelegramTest/TelegramTest.csproj b/TelegramTest/TelegramTest.csproj new file mode 100644 index 000000000..ee0432e6b --- /dev/null +++ b/TelegramTest/TelegramTest.csproj @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + {F83A537E-895A-496B-AA5F-693E0F9BAE4B} + Exe + Properties + TelegramTest + TelegramTest + v4.7.2 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + True + + + + + + + + ..\packages\TLSharp.0.1.0.555\lib\net46\TeleSharp.TL.dll + True + + + ..\packages\TLSharp.0.1.0.555\lib\net46\TLSharp.Core.dll + True + + + + + + + + + + + + +