From 4012e7f608d7d993a2fd9ae9f06b2d3197bf2013 Mon Sep 17 00:00:00 2001 From: gpatel-fr <44170243+gpatel-fr@users.noreply.github.com> Date: Sun, 24 Sep 2023 10:52:57 +0200 Subject: [PATCH] add console log to the Alternative FTP backend for debugging purposes (#5034) --- .../AlternativeFTP/AlternativeFTPBackend.cs | 24 +++++++++++++++++++ .../Library/Backend/AlternativeFTP/Strings.cs | 4 ++++ 2 files changed, 28 insertions(+) diff --git a/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs b/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs index c6cf93a30..5cd1dc80d 100644 --- a/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs +++ b/Duplicati/Library/Backend/AlternativeFTP/AlternativeFTPBackend.cs @@ -52,6 +52,9 @@ namespace Duplicati.Library.Backend.AlternativeFTP private const string CONFIG_KEY_AFTP_SSL_PROTOCOLS = "aftp-ssl-protocols"; private const string CONFIG_KEY_AFTP_UPLOAD_DELAY = "aftp-upload-delay"; + private const string CONFIG_KEY_AFTP_LOGTOCONSOLE = "aftp-log-to-console"; + private const string CONFIG_KEY_AFTP_LOGPRIVATEINFOTOCONSOLE = "aftp-log-privateinfo-to-console"; + private const string TEST_FILE_NAME = "duplicati-access-privileges-test.tmp"; private const string TEST_FILE_CONTENT = "This file is used by Duplicati to test access permissions and can be safely deleted."; @@ -67,6 +70,8 @@ namespace Duplicati.Library.Backend.AlternativeFTP private readonly FtpConfig _ftpConfig; private readonly TimeSpan _uploadWaitTime; + private readonly bool _logToConsole = false; + private readonly bool _logPrivateInfoToConsole = false; private readonly byte[] _copybuffer = new byte[CoreUtility.DEFAULT_BUFFER_SIZE]; private readonly bool _accepAllCertificates; private readonly string[] _validHashes; @@ -102,6 +107,8 @@ namespace Duplicati.Library.Backend.AlternativeFTP new CommandLineArgument(CONFIG_KEY_AFTP_ENCRYPTION_MODE, CommandLineArgument.ArgumentType.Enumeration, Strings.DescriptionFtpEncryptionModeShort, Strings.DescriptionFtpEncryptionModeLong, DEFAULT_ENCRYPTION_MODE_STRING, null, Enum.GetNames(typeof(FtpEncryptionMode))), new CommandLineArgument(CONFIG_KEY_AFTP_SSL_PROTOCOLS, CommandLineArgument.ArgumentType.Flags, Strings.DescriptionSslProtocolsShort, Strings.DescriptionSslProtocolsLong, DEFAULT_SSL_PROTOCOLS_STRING, null, Enum.GetNames(typeof(SslProtocols))), new CommandLineArgument(CONFIG_KEY_AFTP_UPLOAD_DELAY, CommandLineArgument.ArgumentType.Timespan, Strings.DescriptionUploadDelayShort, Strings.DescriptionUploadDelayLong, DEFAULT_UPLOAD_DELAY_STRING), + new CommandLineArgument(CONFIG_KEY_AFTP_LOGTOCONSOLE, CommandLineArgument.ArgumentType.Boolean, Strings.DescriptionLogToConsoleShort, Strings.DescriptionLogToConsoleLong), + new CommandLineArgument(CONFIG_KEY_AFTP_LOGPRIVATEINFOTOCONSOLE, CommandLineArgument.ArgumentType.Boolean, Strings.DescriptionLogPrivateInfoToConsoleShort, Strings.DescriptionLogPrivateInfoToConsoleLong, "false"), }); } } @@ -203,12 +210,28 @@ namespace Duplicati.Library.Backend.AlternativeFTP sslProtocols = DEFAULT_SSL_PROTOCOLS; } + if (Utility.Utility.ParseBoolOption(options, CONFIG_KEY_AFTP_LOGTOCONSOLE)) + { + _logToConsole = true; + } + + if (Utility.Utility.ParseBoolOption(options, CONFIG_KEY_AFTP_LOGPRIVATEINFOTOCONSOLE)) + { + _logPrivateInfoToConsole = true; + } + _ftpConfig = new FtpConfig { DataConnectionType = dataConnectionType, EncryptionMode = encryptionMode, SslProtocols = sslProtocols, + LogToConsole = _logToConsole, }; + + if (_logPrivateInfoToConsole) + { + _ftpConfig.LogHost = _ftpConfig.LogPassword = _ftpConfig.LogUserName = true; + } } public IEnumerable List() @@ -537,6 +560,7 @@ namespace Duplicati.Library.Backend.AlternativeFTP ftpClient.ValidateCertificate += HandleValidateCertificate; this.Client = ftpClient; + } // else reuse existing connection if (setWorkingDirectory) diff --git a/Duplicati/Library/Backend/AlternativeFTP/Strings.cs b/Duplicati/Library/Backend/AlternativeFTP/Strings.cs index 6f30591cc..b98e2b108 100644 --- a/Duplicati/Library/Backend/AlternativeFTP/Strings.cs +++ b/Duplicati/Library/Backend/AlternativeFTP/Strings.cs @@ -11,6 +11,10 @@ namespace Duplicati.Library.Backend.AlternativeFTP public static string DescriptionAuthPasswordShort { get { return LC.L(@"Supplies the password used to connect to the server"); } } public static string DescriptionAuthUsernameLong { get { return LC.L(@"The username used to connect to the server. This may also be supplied as the environment variable ""AUTH_USERNAME""."); } } public static string DescriptionAuthUsernameShort { get { return LC.L(@"Supplies the username used to connect to the server"); } } + public static string DescriptionLogToConsoleLong { get { return LC.L(@"Log FTP dialog to terminal console for debugging purposes"); } } + public static string DescriptionLogToConsoleShort { get { return LC.L(@"Log FTP dialog to terminal console"); } } + public static string DescriptionLogPrivateInfoToConsoleLong { get { return LC.L(@"Log FTP PRIVATE info (username, password) to console for debugging purposes (DO NOT POST THIS TO THE INTERNET!)"); } } + public static string DescriptionLogPrivateInfoToConsoleShort { get { return LC.L(@"Log FTP PRIVATE info to console"); } } public static string DisplayName { get { return LC.L(@"Alternative FTP"); } } public static string MissingFolderError(string foldername, string message) { return LC.L(@"The folder {0} was not found. Message: {1}", foldername, message); } 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)); }