Пример #1
0
        public GoogleDrive(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = uri.HostAndPath;
            if (!m_path.EndsWith("/", StringComparison.Ordinal))
            {
                m_path += "/";
            }

            string authid = null;

            if (options.ContainsKey(AUTHID_OPTION))
            {
                authid = options[AUTHID_OPTION];
            }

            if (options.ContainsKey(DISABLE_TEAMDRIVE_OPTION))
            {
                m_useTeamDrive = !Library.Utility.Utility.ParseBoolOption(options, DISABLE_TEAMDRIVE_OPTION);
            }

            m_oauth = new OAuthHelper(authid, this.ProtocolKey)
            {
                AutoAuthHeader = true
            };
            m_filecache = new Dictionary <string, GoogleDriveFolderItem[]>();
        }
Пример #2
0
        public AmzCD(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = uri.HostAndPath;
            if (!m_path.EndsWith("/"))
                m_path += "/";

            string authid = null;
            if (options.ContainsKey(AUTHID_OPTION))
                authid = options[AUTHID_OPTION];

            string labels = DEFAULT_LABELS;
            if (options.ContainsKey(LABELS_OPTION))
                labels = options[LABELS_OPTION];

            string delay = DEFAULT_DELAY;
            if (options.ContainsKey(DELAY_OPTION))
                delay = options[DELAY_OPTION];
            
            if (!string.IsNullOrWhiteSpace(labels))
                m_labels = labels.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);

            if (string.IsNullOrWhiteSpace(delay))
                m_delayTimeSpan = new TimeSpan(0);
            else
                m_delayTimeSpan = Library.Utility.Timeparser.ParseTimeSpan(delay);

            m_oauth = new OAuthHelper(authid, this.ProtocolKey) { AutoAuthHeader = true };
            m_userid = authid.Split(new string[] {":"}, StringSplitOptions.RemoveEmptyEntries).First();
        }
Пример #3
0
            /// <summary>
            /// Gets the supported commands for a certain url
            /// </summary>
            /// <param name="url">The url to find commands for</param>
            /// <returns>The supported commands or null if the url scheme was not supported</returns>
            public IList <ICommandLineArgument> GetSupportedCommands(string url)
            {
                var uri = new Utility.Uri(url);

                LoadInterfaces();

                lock (m_lock)
                {
                    IBackend b;
                    if (m_interfaces.TryGetValue(uri.Scheme, out b) && b != null)
                    {
                        return(b.SupportedCommands);
                    }
                    else if (uri.Scheme.EndsWith("s"))
                    {
                        var tmpscheme = uri.Scheme.Substring(0, uri.Scheme.Length - 1);
                        if (m_interfaces.ContainsKey(tmpscheme))
                        {
                            return(m_interfaces[tmpscheme].SupportedCommands);
                        }
                    }

                    return(null);
                }
            }
Пример #4
0
        public AzureBlobBackend(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);
            uri.RequireHost();

            string storageAccountName = null;
            string accessKey = null;
            string containerName = uri.Host.ToLowerInvariant();

            if (options.ContainsKey("auth-username"))
                storageAccountName = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                accessKey = options["auth-password"];
            if (options.ContainsKey("azure_account_name"))
                storageAccountName = options["azure_account_name"];
            if (options.ContainsKey("azure_access_key"))
                accessKey = options["azure_access_key"];
            if (!string.IsNullOrEmpty(uri.Username))
                storageAccountName = uri.Username;
            if (!string.IsNullOrEmpty(uri.Password))
                accessKey = uri.Password;

            if (string.IsNullOrWhiteSpace(storageAccountName))
            {
                throw new Exception(Strings.AzureBlobBackend.NoStorageAccountName);
            }
            if (string.IsNullOrWhiteSpace(accessKey))
            {
                throw new Exception(Strings.AzureBlobBackend.NoAccessKey);
            }

            _azureBlob = new AzureBlobWrapper(storageAccountName, accessKey, containerName);
        }
Пример #5
0
        public SSHv2(string url, Dictionary<string, string> options)
            : this()
        {
            m_options = options;
            var uri = new Utility.Uri(url);
            uri.RequireHost();
            
            if (options.ContainsKey("auth-username"))
                m_username = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                m_password = options["auth-password"];
            if (!string.IsNullOrEmpty(uri .Username))
                m_username = uri.Username;
            if (!string.IsNullOrEmpty(uri .Password))
                m_password = uri.Password;

            m_path = uri.Path;

            if (!string.IsNullOrWhiteSpace(m_path) && !m_path.EndsWith("/"))
                m_path += "/";

            m_server = uri.Host;

            if (uri.Port > 0)
                m_port = uri.Port;
        }
Пример #6
0
        public GoogleCloudStorage(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_bucket = uri.Host;
            m_prefix = Duplicati.Library.Utility.Utility.AppendDirSeparator("/" + uri.Path, "/");

            // For GCS we do not use a leading slash
            if (m_prefix.StartsWith("/", StringComparison.Ordinal))
            {
                m_prefix = m_prefix.Substring(1);
            }

            string authid;

            options.TryGetValue(AUTHID_OPTION, out authid);
            options.TryGetValue(PROJECT_OPTION, out m_project);
            options.TryGetValue(LOCATION_OPTION, out m_location);
            options.TryGetValue(STORAGECLASS_OPTION, out m_storage_class);

            if (string.IsNullOrEmpty(authid))
            {
                throw new UserInformationException(Strings.GoogleCloudStorage.MissingAuthID(AUTHID_OPTION), "GoogleCloudStorageMissingAuthID");
            }

            m_oauth = new OAuthHelper(authid, this.ProtocolKey);
            m_oauth.AutoAuthHeader = true;
        }
Пример #7
0
        public AmzCD(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = uri.HostAndPath;
            if (!m_path.EndsWith("/"))
            {
                m_path += "/";
            }

            string authid = null;

            if (options.ContainsKey(AUTHID_OPTION))
            {
                authid = options[AUTHID_OPTION];
            }

            string labels = DEFAULT_LABELS;

            if (options.ContainsKey(LABELS_OPTION))
            {
                labels = options[LABELS_OPTION];
            }

            if (!string.IsNullOrWhiteSpace(labels))
            {
                m_labels = labels.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            }

            m_oauth = new OAuthHelper(authid, this.ProtocolKey)
            {
                AutoAuthHeader = true
            };
            m_userid = authid.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries).First();
        }
Пример #8
0
        public MegaBackend(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            if (options.ContainsKey("auth-username"))
            {
                m_username = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                m_password = options["auth-password"];
            }

            if (!string.IsNullOrEmpty(uri.Username))
            {
                m_username = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                m_password = uri.Password;
            }

            if (string.IsNullOrEmpty(m_username))
            {
                throw new UserInformationException(Strings.MegaBackend.NoUsernameError, "MegaNoUsername");
            }
            if (string.IsNullOrEmpty(m_password))
            {
                throw new UserInformationException(Strings.MegaBackend.NoPasswordError, "MegaNoPassword");
            }

            m_prefix = uri.HostAndPath ?? "";
        }
Пример #9
0
        public GoogleCloudStorage(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_bucket = uri.Host;
            m_prefix = "/" + uri.Path;
            if (!m_prefix.EndsWith("/"))
                m_prefix += "/";

            // For GCS we do not use a leading slash
            if (m_prefix.StartsWith("/"))
                m_prefix = m_prefix.Substring(1);

            string authid;
            options.TryGetValue(AUTHID_OPTION, out authid);
            options.TryGetValue(PROJECT_OPTION, out m_project);
            options.TryGetValue(LOCATION_OPTION, out m_location);
            options.TryGetValue(STORAGECLASS_OPTION, out m_storage_class);

            if (string.IsNullOrEmpty(authid))
                throw new Exception(Strings.GoogleCloudStorage.MissingAuthID(AUTHID_OPTION));

            m_oauth = new OAuthHelper(authid, this.ProtocolKey);
            m_oauth.AutoAuthHeader = true;
        }
Пример #10
0
        public GoogleCloudStorage(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_bucket = uri.Host;
            m_prefix = "/" + uri.Path;
            if (!m_prefix.EndsWith("/"))
            {
                m_prefix += "/";
            }

            // For GCS we do not use a leading slash
            if (m_prefix.StartsWith("/"))
            {
                m_prefix = m_prefix.Substring(1);
            }

            string authid;

            options.TryGetValue(AUTHID_OPTION, out authid);
            options.TryGetValue(PROJECT_OPTION, out m_project);
            options.TryGetValue(LOCATION_OPTION, out m_location);
            options.TryGetValue(STORAGECLASS_OPTION, out m_storage_class);

            if (string.IsNullOrEmpty(authid))
            {
                throw new Exception(Strings.GoogleCloudStorage.MissingAuthID(AUTHID_OPTION));
            }

            m_oauth = new OAuthHelper(authid, this.ProtocolKey);
            m_oauth.AutoAuthHeader = true;
        }
Пример #11
0
        protected virtual string GetRootPathFromUrl(string url)
        {
            // Extract out the path to the backup root folder from the given URI
            var uri = new Utility.Uri(url);

            return(Utility.Uri.UrlDecode(uri.HostAndPath));
        }
Пример #12
0
        public FTP(string url, Dictionary<string, string> options)
        {
            //This can be made better by keeping a single ftp stream open,
            //unfortunately the .Net model does not allow this as the request is 
            //bound to a single url (path+file).
            //
            //To fix this, a thirdparty FTP library is required,
            //this would also allow a fix for the FTP servers
            //that only support SSL during authentication, not during transfers
            //
            //If you have experience with a stable open source .Net FTP library,
            //please let the Duplicati authors know

            var u = new Utility.Uri(url);
            u.RequireHost();

            if (!string.IsNullOrEmpty(u.Username))
            {
                m_userInfo = new System.Net.NetworkCredential();
                m_userInfo.UserName = u.Username;
                if (!string.IsNullOrEmpty(u.Password))
                    m_userInfo.Password = u.Password;
                else if (options.ContainsKey("auth-password"))
                    m_userInfo.Password = options["auth-password"];
            }
            else
            {
                if (options.ContainsKey("auth-username"))
                {
                    m_userInfo = new System.Net.NetworkCredential();
                    m_userInfo.UserName = options["auth-username"];
                    if (options.ContainsKey("auth-password"))
                        m_userInfo.Password = options["auth-password"];
                }
            }

            //Bugfix, see http://connect.microsoft.com/VisualStudio/feedback/details/695227/networkcredential-default-constructor-leaves-domain-null-leading-to-null-object-reference-exceptions-in-framework-code
            if (m_userInfo != null)
                m_userInfo.Domain = "";

            m_url = u.SetScheme("ftp").SetQuery(null).SetCredentials(null, null).ToString();
            if (!m_url.EndsWith("/"))
                m_url += "/";

            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_listVerify = !Utility.Utility.ParseBoolOption(options, "disable-upload-verify");

            if (Utility.Utility.ParseBoolOption(options, "ftp-passive"))
            {
                m_defaultPassive = false;
                m_passive = true;
            }
            if (Utility.Utility.ParseBoolOption(options, "ftp-regular"))
            {
                m_defaultPassive = false;
                m_passive = false;
            }
        }
Пример #13
0
        public WEBDAV(string url, Dictionary<string, string> options)
        {
            var u = new Utility.Uri(url);
            u.RequireHost();

            if (!string.IsNullOrEmpty(u.Username))
            {
                m_userInfo = new System.Net.NetworkCredential();
                m_userInfo.UserName = u.Username;
                if (!string.IsNullOrEmpty(u.Password))
                    m_userInfo.Password = u.Password;
                else if (options.ContainsKey("auth-password"))
                    m_userInfo.Password = options["auth-password"];
            }
            else
            {
                if (options.ContainsKey("auth-username"))
                {
                    m_userInfo = new System.Net.NetworkCredential();
                    m_userInfo.UserName = options["auth-username"];
                    if (options.ContainsKey("auth-password"))
                        m_userInfo.Password = options["auth-password"];
                }
            }
            
            //Bugfix, see http://connect.microsoft.com/VisualStudio/feedback/details/695227/networkcredential-default-constructor-leaves-domain-null-leading-to-null-object-reference-exceptions-in-framework-code
            if (m_userInfo != null)
                m_userInfo.Domain = "";

            m_useIntegratedAuthentication = Utility.Utility.ParseBoolOption(options, "integrated-authentication");
            m_forceDigestAuthentication = Utility.Utility.ParseBoolOption(options, "force-digest-authentication");
            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_url = u.SetScheme(m_useSSL ? "https" : "http").SetCredentials(null, null).SetQuery(null).ToString();
            if (!m_url.EndsWith("/"))
                m_url += "/";

            m_path = u.Path;
            if (!m_path.StartsWith("/"))
            	m_path = "/" + m_path;
            if (!m_path.EndsWith("/"))
            	m_path += "/";

            m_path = System.Web.HttpUtility.UrlDecode(m_path);
            m_rawurl = new Utility.Uri(m_useSSL ? "https" : "http", u.Host, m_path).ToString();

            int port = u.Port;
            if (port <= 0)
                port = m_useSSL ? 443 : 80;

            m_rawurlPort = new Utility.Uri(m_useSSL ? "https" : "http", u.Host, m_path, null, null, null, port).ToString();
			m_sanitizedUrl = new Utility.Uri(m_useSSL ? "https" : "http", u.Host, m_path).ToString();
			m_reverseProtocolUrl = new Utility.Uri(m_useSSL ? "http" : "https", u.Host, m_path).ToString();
            options.TryGetValue("debug-propfind-file", out m_debugPropfindFile);
        }
Пример #14
0
        public SSHv2(string url, Dictionary <string, string> options)
            : this()
        {
            m_options = options;
            var uri = new Utility.Uri(url);

            uri.RequireHost();

            if (options.ContainsKey("auth-username"))
            {
                m_username = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                m_password = options["auth-password"];
            }
            if (options.ContainsKey(SSH_FINGERPRINT_OPTION))
            {
                m_fingerprint = options[SSH_FINGERPRINT_OPTION];
            }
            if (!string.IsNullOrEmpty(uri.Username))
            {
                m_username = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                m_password = uri.Password;
            }
            if (uri.QueryParameters != null && uri.QueryParameters[SSH_FINGERPRINT_OPTION] != null)
            {
                m_fingerprint = uri.QueryParameters[SSH_FINGERPRINT_OPTION];
            }

            m_fingerprintallowall = Utility.Utility.ParseBoolOption(options, SSH_FINGERPRINT_ACCEPT_ANY_OPTION);

            m_path = uri.Path;

            if (!string.IsNullOrWhiteSpace(m_path) && !m_path.EndsWith("/"))
            {
                m_path += "/";
            }

            if (!m_path.StartsWith("/"))
            {
                m_path = "/" + m_path;
            }

            m_server = uri.Host;

            if (uri.Port > 0)
            {
                m_port = uri.Port;
            }
        }
Пример #15
0
            /// <summary>
            /// Instanciates a specific backend, given the url and options
            /// </summary>
            /// <param name="url">The url to create the instance for</param>
            /// <param name="options">The options to pass to the instance constructor</param>
            /// <returns>The instanciated backend or null if the url is not supported</returns>
            public IBackend GetBackend(string url, Dictionary <string, string> options)
            {
                var uri = new Utility.Uri(url);

                LoadInterfaces();

                var newOpts = new Dictionary <string, string>(options);

                foreach (var key in uri.QueryParameters.AllKeys)
                {
                    newOpts[key] = uri.QueryParameters[key];
                }

                lock (m_lock)
                {
                    try
                    {
                        if (m_interfaces.ContainsKey(uri.Scheme))
                        {
                            return((IBackend)Activator.CreateInstance(m_interfaces[uri.Scheme].GetType(), url, newOpts));
                        }
                        else if (uri.Scheme.EndsWith("s", StringComparison.Ordinal))
                        {
                            var tmpscheme = uri.Scheme.Substring(0, uri.Scheme.Length - 1);
                            if (m_interfaces.ContainsKey(tmpscheme))
                            {
                                var commands = m_interfaces[tmpscheme].SupportedCommands;
                                if (commands != null && (commands.Any(x =>
                                                                      x.Name.Equals("use-ssl", StringComparison.OrdinalIgnoreCase) ||
                                                                      (x.Aliases != null && x.Aliases.Any(y => y.Equals("use-ssl", StringComparison.OrdinalIgnoreCase)))
                                                                      )))
                                {
                                    newOpts["use-ssl"] = "true";
                                    return((IBackend)Activator.CreateInstance(m_interfaces[tmpscheme].GetType(), url, newOpts));
                                }
                            }
                        }
                    }
                    catch (System.Reflection.TargetInvocationException tex)
                    {
                        if (tex.InnerException != null)
                        {
                            // Unwrap exceptions for nicer display.  The ExceptionDispatchInfo class allows us to
                            // rethrow an exception without changing the stack trace.
                            ExceptionDispatchInfo.Capture(tex.InnerException).Throw();
                        }

                        throw;
                    }

                    return(null);
                }
            }
Пример #16
0
        // ReSharper disable once UnusedMember.Global
        // This constructor is needed by the BackendLoader.
        public AzureBlobBackend(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            uri.RequireHost();

            string storageAccountName = null;
            string accessKey          = null;
            string containerName      = uri.Host.ToLowerInvariant();

            if (options.ContainsKey("auth-username"))
            {
                storageAccountName = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                accessKey = options["auth-password"];
            }
            if (options.ContainsKey("azure_account_name"))
            {
                storageAccountName = options["azure_account_name"];
            }
            if (options.ContainsKey("azure_access_key"))
            {
                accessKey = options["azure_access_key"];
            }
            if (!string.IsNullOrEmpty(uri.Username))
            {
                storageAccountName = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                accessKey = uri.Password;
            }

            if (storageAccountName == null && accessKey == null)
            {
                _azureBlob = new AzureBlobWrapper(url);
                return;
            }

            if (string.IsNullOrWhiteSpace(storageAccountName))
            {
                throw new UserInformationException(Strings.AzureBlobBackend.NoStorageAccountName, "AzureNoAccountName");
            }

            if (string.IsNullOrWhiteSpace(accessKey))
            {
                throw new UserInformationException(Strings.AzureBlobBackend.NoAccessKey, "AzureNoAccessKey");
            }

            _azureBlob = new AzureBlobWrapper(storageAccountName, accessKey, containerName);
        }
Пример #17
0
        /// <summary>
        /// SharePoint has nested subwebs but sometimes different webs
        /// are hooked into a sub path.
        /// For finding files SharePoint is picky to use the correct
        /// path to the web, so we will trial and error here.
        /// The user can give us a hint by supplying an URI with a double
        /// slash to separate web.
        /// Otherwise it's a good guess to look for "/documents", as we expect
        /// that the default document library is used in the path.
        /// If that won't help, we will try all possible pathes from longest
        /// to shortest...
        /// </summary>
        private static string findCorrectWebPath(Utility.Uri orgUrl, System.Net.ICredentials userInfo, out SP.ClientContext retCtx)
        {
            retCtx = null;

            string path            = orgUrl.Path;
            int    webIndicatorPos = path.IndexOf("//", StringComparison.Ordinal);

            // if a hint is supplied, we will of course use this first.
            if (webIndicatorPos >= 0)
            {
                string testUrl = new Utility.Uri(orgUrl.Scheme, orgUrl.Host, path.Substring(0, webIndicatorPos), null, null, null, orgUrl.Port).ToString();
                if (testUrlForWeb(testUrl, userInfo, false, out retCtx) >= 0)
                {
                    return(testUrl);
                }
            }

            // Now go through path and see where we land a success.
            string[] pathParts = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            // first we look for the doc library
            int docLibrary = Array.FindIndex(pathParts, p => StringComparer.OrdinalIgnoreCase.Equals(p, "documents"));

            if (docLibrary >= 0)
            {
                string testUrl = new Utility.Uri(orgUrl.Scheme, orgUrl.Host,
                                                 string.Join("/", pathParts, 0, docLibrary),
                                                 null, null, null, orgUrl.Port).ToString();
                if (testUrlForWeb(testUrl, userInfo, false, out retCtx) >= 0)
                {
                    return(testUrl);
                }
            }

            // last but not least: try one after the other.
            for (int pi = pathParts.Length - 1; pi >= 0; pi--)
            {
                if (pi == docLibrary)
                {
                    continue;                   // already tested
                }
                string testUrl = new Utility.Uri(orgUrl.Scheme, orgUrl.Host,
                                                 string.Join("/", pathParts, 0, pi),
                                                 null, null, null, orgUrl.Port).ToString();
                if (testUrlForWeb(testUrl, userInfo, false, out retCtx) >= 0)
                {
                    return(testUrl);
                }
            }

            // nothing worked :(
            return(null);
        }
Пример #18
0
        public AmzCD(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = uri.HostAndPath;
            if (!m_path.EndsWith("/", StringComparison.Ordinal))
            {
                m_path += "/";
            }

            string authid = null;

            if (options.ContainsKey(AUTHID_OPTION))
            {
                authid = options[AUTHID_OPTION];
            }

            string labels = DEFAULT_LABELS;

            if (options.ContainsKey(LABELS_OPTION))
            {
                labels = options[LABELS_OPTION];
            }

            string delay = DEFAULT_DELAY;

            if (options.ContainsKey(DELAY_OPTION))
            {
                delay = options[DELAY_OPTION];
            }

            if (!string.IsNullOrWhiteSpace(labels))
            {
                m_labels = labels.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            }

            if (string.IsNullOrWhiteSpace(delay))
            {
                m_delayTimeSpan = new TimeSpan(0);
            }
            else
            {
                m_delayTimeSpan = Library.Utility.Timeparser.ParseTimeSpan(delay);
            }
            m_waitUntil = DateTime.Now + m_delayTimeSpan;

            m_oauth = new OAuthHelper(authid, this.ProtocolKey)
            {
                AutoAuthHeader = true
            };
            m_userid = authid.Split(new string[] { ":" }, StringSplitOptions.RemoveEmptyEntries).First();
        }
Пример #19
0
        public GoogleDrive(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = uri.HostAndPath;
            if (!m_path.EndsWith("/"))
                m_path += "/";

            string authid = null;
            if (options.ContainsKey(AUTHID_OPTION))
                authid = options[AUTHID_OPTION];

            m_oauth = new OAuthHelper(authid, this.ProtocolKey) { AutoAuthHeader = true };
            m_filecache = new Dictionary<string, GoogleDriveFolderItem[]>();
        }
Пример #20
0
        public OneDrive(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_rootfolder = uri.Host;
            m_prefix = "/" + uri.Path;
            if (!m_prefix.EndsWith("/"))
                m_prefix += "/";

            string authid = null;
            if (options.ContainsKey(AUTHID_OPTION))
                authid = options[AUTHID_OPTION];

            m_oauth = new OAuthHelper(authid, this.ProtocolKey);
        }
Пример #21
0
        public TahoeBackend(string url, Dictionary<string, string> options)
        {
            //Validate URL
            var u = new Utility.Uri(url);
            u.RequireHost();

            if (!u.Path.StartsWith("uri/URI:DIR2:") && !u.Path.StartsWith("uri/URI%3ADIR2%3A"))
                throw new Exception(Strings.TahoeBackend.UnrecognizedUriError);

            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_url = u.SetScheme(m_useSSL ? "https" : "http").SetQuery(null).SetCredentials(null, null).ToString();
            if (!m_url.EndsWith("/"))
                m_url += "/";
        }
Пример #22
0
        public OneDrive(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_rootfolder = uri.Host;
            m_prefix     = Duplicati.Library.Utility.Utility.AppendDirSeparator("/" + uri.Path, "/");

            string authid = null;

            if (options.ContainsKey(AUTHID_OPTION))
            {
                authid = options[AUTHID_OPTION];
            }

            m_oauth = new OAuthHelper(authid, this.ProtocolKey);
        }
Пример #23
0
        public Dropbox(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = Library.Utility.Uri.UrlDecode(uri.HostAndPath);
            if (m_path.Length != 0 && !m_path.StartsWith("/"))
                m_path = "/" + m_path;

            if (m_path.EndsWith("/"))
                m_path = m_path.Substring(0, m_path.Length - 1);

            if (options.ContainsKey(AUTHID_OPTION))
                m_accesToken = options[AUTHID_OPTION];

            dbx = new DropboxHelper(m_accesToken);
        }
Пример #24
0
        public Sia(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_apihost    = uri.Host;
            m_apiport    = uri.Port;
            m_targetpath = uri.Path;

            m_redundancy = 1.5F;
            if (options.ContainsKey(SIA_REDUNDANCY))
            {
                m_redundancy = float.Parse(options[SIA_REDUNDANCY]);
            }

            if (m_apiport <= 0)
            {
                m_apiport = 9980;
            }

            if (options.ContainsKey(SIA_TARGETPATH))
            {
                m_targetpath = options[SIA_TARGETPATH];
            }
            while (m_targetpath.Contains("//"))
            {
                m_targetpath = m_targetpath.Replace("//", "/");
            }
            while (m_targetpath.StartsWith("/", StringComparison.Ordinal))
            {
                m_targetpath = m_targetpath.Substring(1);
            }
            while (m_targetpath.EndsWith("/", StringComparison.Ordinal))
            {
                m_targetpath = m_targetpath.Remove(m_targetpath.Length - 1);
            }

            if (m_targetpath.Length == 0)
            {
                m_targetpath = "backup";
            }

            m_user = new System.Net.NetworkCredential();
            if (options.ContainsKey(SIA_PASSWORD))
            {
                m_user.Password = options[SIA_PASSWORD];
            }
        }
Пример #25
0
        public OpenStackStorage(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_container = uri.Host;
            m_prefix    = "/" + uri.Path;
            if (!m_prefix.EndsWith("/", StringComparison.Ordinal))
            {
                m_prefix += "/";
            }

            // For OpenStack we do not use a leading slash
            if (m_prefix.StartsWith("/", StringComparison.Ordinal))
            {
                m_prefix = m_prefix.Substring(1);
            }

            options.TryGetValue(USERNAME_OPTION, out m_username);
            options.TryGetValue(PASSWORD_OPTION, out m_password);
            options.TryGetValue(TENANTNAME_OPTION, out m_tenantName);
            options.TryGetValue(AUTHURI_OPTION, out m_authUri);
            options.TryGetValue(APIKEY_OPTION, out m_apikey);
            options.TryGetValue(REGION_OPTION, out m_region);

            if (string.IsNullOrWhiteSpace(m_username))
            {
                throw new UserInformationException(Strings.OpenStack.MissingOptionError(USERNAME_OPTION), "OpenStackMissingUsername");
            }
            if (string.IsNullOrWhiteSpace(m_authUri))
            {
                throw new UserInformationException(Strings.OpenStack.MissingOptionError(AUTHURI_OPTION), "OpenStackMissingAuthUri");
            }

            if (string.IsNullOrWhiteSpace(m_apikey))
            {
                if (string.IsNullOrWhiteSpace(m_password))
                {
                    throw new UserInformationException(Strings.OpenStack.MissingOptionError(PASSWORD_OPTION), "OpenStackMissingPassword");
                }
                if (string.IsNullOrWhiteSpace(m_tenantName))
                {
                    throw new UserInformationException(Strings.OpenStack.MissingOptionError(TENANTNAME_OPTION), "OpenStackMissingTenantName");
                }
            }

            m_helper = new WebHelper(this);
        }
Пример #26
0
        public TahoeBackend(string url, Dictionary <string, string> options)
        {
            //Validate URL
            var u = new Utility.Uri(url);

            u.RequireHost();

            if (!u.Path.StartsWith("uri/URI:DIR2:", StringComparison.Ordinal) && !u.Path.StartsWith("uri/URI%3ADIR2%3A", StringComparison.Ordinal))
            {
                throw new UserInformationException(Strings.TahoeBackend.UnrecognizedUriError, "TahoeInvalidUri");
            }

            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_url = u.SetScheme(m_useSSL ? "https" : "http").SetQuery(null).SetCredentials(null, null).ToString();
            m_url = Util.AppendDirSeparator(m_url, "/");
        }
Пример #27
0
        public BoxBackend(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = Util.AppendDirSeparator(uri.HostAndPath, "/");

            string authid = null;

            if (options.ContainsKey(AUTHID_OPTION))
            {
                authid = options[AUTHID_OPTION];
            }

            m_deleteFromTrash = Library.Utility.Utility.ParseBoolOption(options, REALLY_DELETE_OPTION);

            m_oauth = new BoxHelper(authid);
        }
Пример #28
0
        // ReSharper disable once UnusedMember.Global
        // This constructor is needed by the BackendLoader.
        public AmzCD(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = Util.AppendDirSeparator(uri.HostAndPath, "/");

            if (options.ContainsKey(AUTHID_OPTION))
            {
                m_authid = options[AUTHID_OPTION];
            }

            string labels = DEFAULT_LABELS;

            if (options.ContainsKey(LABELS_OPTION))
            {
                labels = options[LABELS_OPTION];
            }

            string delay = DEFAULT_DELAY;

            if (options.ContainsKey(DELAY_OPTION))
            {
                delay = options[DELAY_OPTION];
            }

            if (!string.IsNullOrWhiteSpace(labels))
            {
                m_labels = labels.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            }

            if (string.IsNullOrWhiteSpace(delay))
            {
                m_delayTimeSpan = new TimeSpan(0);
            }
            else
            {
                m_delayTimeSpan = Library.Utility.Timeparser.ParseTimeSpan(delay);
            }

            m_oauth = new OAuthHelper(m_authid, this.ProtocolKey)
            {
                AutoAuthHeader = true
            };
            m_userid = m_authid.Split(new [] { ":" }, StringSplitOptions.RemoveEmptyEntries).First();
        }
Пример #29
0
        public Idrivee2Backend(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_bucket = uri.Host;
            m_prefix = uri.Path;
            m_prefix = m_prefix.Trim();
            if (m_prefix.Length != 0)
            {
                m_prefix = Util.AppendDirSeparator(m_prefix, "/");
            }
            string accessKeyId     = null;
            string accessKeySecret = null;

            if (options.ContainsKey("auth-username"))
            {
                accessKeyId = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                accessKeySecret = options["auth-password"];
            }

            if (options.ContainsKey("access_key_id"))
            {
                accessKeyId = options["access_key_id"];
            }
            if (options.ContainsKey("secret_access_key"))
            {
                accessKeySecret = options["secret_access_key"];
            }

            if (string.IsNullOrEmpty(accessKeyId))
            {
                throw new UserInformationException(Strings.Idrivee2Backend.NoKeyIdError, "Idrivee2NoKeyId");
            }
            if (string.IsNullOrEmpty(accessKeySecret))
            {
                throw new UserInformationException(Strings.Idrivee2Backend.NoKeySecretError, "Idrivee2NoKeySecret");
            }
            string host = GetRegionEndpoint("https://api.idrivee2.com/api/service/get_region_end_point/" + accessKeyId);


            m_s3Client = new S3AwsClient(accessKeyId, accessKeySecret, null, host, null, true, options);
        }
Пример #30
0
        public Sia(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_apihost    = uri.Host;
            m_apiport    = uri.Port;
            m_targetpath = uri.Path;

            m_redundancy = 1.5F;
            if (options.ContainsKey(SIA_REDUNDANCY))
            {
                m_redundancy = float.Parse(options[SIA_REDUNDANCY]);
            }

            if (m_apiport <= 0)
            {
                m_apiport = 9980;
            }

            if (options.ContainsKey(SIA_TARGETPATH))
            {
                m_targetpath = options[SIA_TARGETPATH];
            }
            while (m_targetpath.Contains("//"))
            {
                m_targetpath = m_targetpath.Replace("//", "/");
            }
            while (m_targetpath.StartsWith("/", StringComparison.Ordinal))
            {
                m_targetpath = m_targetpath.Substring(1);
            }
            while (m_targetpath.EndsWith("/", StringComparison.Ordinal))
            {
                m_targetpath = m_targetpath.Remove(m_targetpath.Length - 1);
            }

            if (m_targetpath.Length == 0)
            {
                m_targetpath = "backup";
            }

            m_authorization = options.ContainsKey(SIA_PASSWORD) && !string.IsNullOrEmpty(options[SIA_PASSWORD])
                ? "Basic " + System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(":" + options[SIA_PASSWORD]))
                : null;
        }
Пример #31
0
        public SSHv2(string url, Dictionary <string, string> options)
            : this()
        {
            m_options = options;
            var uri = new Utility.Uri(url);

            uri.RequireHost();

            if (options.ContainsKey("auth-username"))
            {
                m_username = options["auth-username"];
            }
            if (options.ContainsKey("auth-password"))
            {
                m_password = options["auth-password"];
            }
            if (!string.IsNullOrEmpty(uri.Username))
            {
                m_username = uri.Username;
            }
            if (!string.IsNullOrEmpty(uri.Password))
            {
                m_password = uri.Password;
            }

            m_path = uri.Path;

            if (!string.IsNullOrWhiteSpace(m_path) && !m_path.EndsWith("/"))
            {
                m_path += "/";
            }

            if (!m_path.StartsWith("/"))
            {
                m_path = "/" + m_path;
            }

            m_server = uri.Host;

            if (uri.Port > 0)
            {
                m_port = uri.Port;
            }
        }
Пример #32
0
        public B2(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_bucketname = uri.Host;
            m_prefix = "/" + uri.Path;
            if (!m_prefix.EndsWith("/"))
                m_prefix += "/";

            // For B2 we do not use a leading slash
            while(m_prefix.StartsWith("/"))
                m_prefix = m_prefix.Substring(1);

			m_urlencodedprefix = string.Join("/", m_prefix.Split(new [] { '/' }).Select(x => Library.Utility.Uri.UrlPathEncode(x)));

            m_bucketType = DEFAULT_BUCKET_TYPE;
            if (options.ContainsKey(B2_CREATE_BUCKET_TYPE_OPTION))
                m_bucketType = options[B2_CREATE_BUCKET_TYPE_OPTION];

            string accountId = null;
            string accountKey = null;

            if (options.ContainsKey("auth-username"))
                accountId = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                accountKey = options["auth-password"];

            if (options.ContainsKey(B2_ID_OPTION))
                accountId = options[B2_ID_OPTION];
            if (options.ContainsKey(B2_KEY_OPTION))
                accountKey = options[B2_KEY_OPTION];
            if (!string.IsNullOrEmpty(uri.Username))
                accountId = uri.Username;
            if (!string.IsNullOrEmpty(uri.Password))
                accountKey = uri.Password;

            if (string.IsNullOrEmpty(accountId))
                throw new Exception(Strings.B2.NoB2UserIDError);
            if (string.IsNullOrEmpty(accountKey))
                throw new Exception(Strings.B2.NoB2KeyError);

            m_helper = new B2AuthHelper(accountId, accountKey);
        }
Пример #33
0
        public B2(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_bucketname = uri.Host;
            m_prefix = "/" + uri.Path;
            if (!m_prefix.EndsWith("/"))
                m_prefix += "/";

            // For B2 we do not use a leading slash
            while(m_prefix.StartsWith("/"))
                m_prefix = m_prefix.Substring(1);

            m_urlencodedprefix = string.Join("/", m_prefix.Split(new [] { '/' }).Select(x => Library.Utility.Uri.UrlPathEncode(x)));

            m_bucketType = DEFAULT_BUCKET_TYPE;
            if (options.ContainsKey(B2_CREATE_BUCKET_TYPE_OPTION))
                m_bucketType = options[B2_CREATE_BUCKET_TYPE_OPTION];

            string accountId = null;
            string accountKey = null;

            if (options.ContainsKey("auth-username"))
                accountId = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                accountKey = options["auth-password"];

            if (options.ContainsKey(B2_ID_OPTION))
                accountId = options[B2_ID_OPTION];
            if (options.ContainsKey(B2_KEY_OPTION))
                accountKey = options[B2_KEY_OPTION];
            if (!string.IsNullOrEmpty(uri.Username))
                accountId = uri.Username;
            if (!string.IsNullOrEmpty(uri.Password))
                accountKey = uri.Password;

            if (string.IsNullOrEmpty(accountId))
                throw new UserInformationException(Strings.B2.NoB2UserIDError);
            if (string.IsNullOrEmpty(accountKey))
                throw new UserInformationException(Strings.B2.NoB2KeyError);

            m_helper = new B2AuthHelper(accountId, accountKey);
        }
Пример #34
0
        public COS(string url, Dictionary <string, string> options)
        {
            _cosOptions = new CosOptions();

            var uri    = new Utility.Uri(url?.Trim());
            var prefix = uri.HostAndPath?.Trim()?.Trim('/')?.Trim('\\');

            if (!string.IsNullOrEmpty(prefix))
            {
                _cosOptions.Path = prefix + "/";
            }

            if (options.ContainsKey(COS_APP_ID))
            {
                _cosOptions.Appid = options[COS_APP_ID];
            }

            if (options.ContainsKey(COS_REGION))
            {
                _cosOptions.Region = options[COS_REGION];
            }

            if (options.ContainsKey(COS_SECRET_ID))
            {
                _cosOptions.SecretId = options[COS_SECRET_ID];
            }

            if (options.ContainsKey(COS_SECRET_KEY))
            {
                _cosOptions.SecretKey = options[COS_SECRET_KEY];
            }

            if (options.ContainsKey(COS_BUCKET))
            {
                _cosOptions.Bucket = options[COS_BUCKET];
            }

            if (options.ContainsKey(COS_STORAGE_CLASS))
            {
                _cosOptions.StorageClass = options[COS_STORAGE_CLASS];
            }
        }
Пример #35
0
        public OneDrive(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_rootfolder = uri.Host;
            m_prefix     = "/" + uri.Path;
            if (!m_prefix.EndsWith("/"))
            {
                m_prefix += "/";
            }

            string authid = null;

            if (options.ContainsKey(AUTHID_OPTION))
            {
                authid = options[AUTHID_OPTION];
            }

            m_oauth = new OAuthHelper(authid, this.ProtocolKey);
        }
Пример #36
0
        public TahoeBackend(string url, Dictionary <string, string> options)
        {
            //Validate URL
            var u = new Utility.Uri(url);

            u.RequireHost();

            if (!u.Path.StartsWith("uri/URI:DIR2:") && !u.Path.StartsWith("uri/URI%3ADIR2%3A"))
            {
                throw new UserInformationException(Strings.TahoeBackend.UnrecognizedUriError);
            }

            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_url = u.SetScheme(m_useSSL ? "https" : "http").SetQuery(null).SetCredentials(null, null).ToString();
            if (!m_url.EndsWith("/"))
            {
                m_url += "/";
            }
        }
Пример #37
0
        public BoxBackend(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = uri.HostAndPath;
            if (!m_path.EndsWith("/"))
            {
                m_path += "/";
            }

            string authid = null;

            if (options.ContainsKey(AUTHID_OPTION))
            {
                authid = options[AUTHID_OPTION];
            }

            m_deleteFromTrash = Library.Utility.Utility.ParseBoolOption(options, REALLY_DELETE_OPTION);

            m_oauth = new BoxHelper(authid);
        }
Пример #38
0
        public MegaBackend(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);

            if (options.ContainsKey("auth-username"))
                m_username = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                m_password = options["auth-password"];

            if (!string.IsNullOrEmpty(uri.Username))
                m_username = uri.Username;
            if (!string.IsNullOrEmpty(uri.Password))
                m_password = uri.Password;

            if (string.IsNullOrEmpty(m_username))
                throw new Exception(Strings.MegaBackend.NoUsernameError);
            if (string.IsNullOrEmpty(m_password))
                throw new Exception(Strings.MegaBackend.NoPasswordError);

            m_prefix = uri.HostAndPath ?? "";
        }
Пример #39
0
        public SkyDrive(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_rootfolder = uri.Host;
            m_prefix     = "/" + uri.Path;
            if (!m_prefix.EndsWith("/"))
            {
                m_prefix += "/";
            }

            if (options.ContainsKey(AUTHID_OPTION))
            {
                m_authid = options[AUTHID_OPTION];
            }

            if (string.IsNullOrEmpty(m_authid))
            {
                throw new Exception(string.Format(LC.L("You need an AuthID, you can get it from: {0}"), WLID_LOGIN));
            }
        }
Пример #40
0
        public SkyDrive(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_rootfolder = uri.Host;
            m_prefix     = "/" + uri.Path;
            if (!m_prefix.EndsWith("/"))
            {
                m_prefix += "/";
            }

            if (options.ContainsKey(AUTHID_OPTION))
            {
                m_authid = options[AUTHID_OPTION];
            }

            if (string.IsNullOrEmpty(m_authid))
            {
                throw new Exception(Strings.OneDrive.MissingAuthID(WLID_LOGIN));
            }
        }
Пример #41
0
        public Dropbox(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = Library.Utility.Uri.UrlDecode(uri.HostAndPath);
            if (m_path.Length != 0 && !m_path.StartsWith("/"))
            {
                m_path = "/" + m_path;
            }

            if (m_path.EndsWith("/"))
            {
                m_path = m_path.Substring(0, m_path.Length - 1);
            }

            if (options.ContainsKey(AUTHID_OPTION))
            {
                m_accesToken = options[AUTHID_OPTION];
            }

            dbx = new DropboxHelper(m_accesToken);
        }
Пример #42
0
        public GoogleDocs(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);
            m_folder = uri.HostAndPath;
            if (m_folder.EndsWith("/"))
                m_folder = m_folder.Substring(0, m_folder.Length - 1);

            string username = null;
            string password = null;

            if (options.ContainsKey("auth-username"))
                username = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                password = options["auth-password"];
            if (options.ContainsKey(USERNAME_OPTION))
                username = options[USERNAME_OPTION];
            if (options.ContainsKey(PASSWORD_OPTION))
                password = options[PASSWORD_OPTION];
            if (!string.IsNullOrEmpty(uri.Username))
                username = uri.Username;
            if (!string.IsNullOrEmpty(uri.Password))
                password = uri.Password;

            string labels;
            if (!options.TryGetValue(ATTRIBUTES_OPTION, out labels))
                labels = DEFAULT_LABELS;

            m_labels = (labels ?? "").Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries);

            if (string.IsNullOrEmpty(username))
                throw new Exception(Strings.GoogleDocs.MissingUsernameError);
            if (string.IsNullOrEmpty(password))
                throw new Exception(Strings.GoogleDocs.MissingPasswordError);

            m_cla = new Google.GData.Client.ClientLoginAuthenticator(USER_AGENT, Google.GData.Client.ServiceNames.Documents, username, password);

            m_settings = new Google.GData.Client.RequestSettings(USER_AGENT, username, password);
            m_settings.AutoPaging = true;
        }
Пример #43
0
        public GoogleDrive(string url, Dictionary <string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = uri.HostAndPath;
            if (!m_path.EndsWith("/"))
            {
                m_path += "/";
            }

            string authid = null;

            if (options.ContainsKey(AUTHID_OPTION))
            {
                authid = options[AUTHID_OPTION];
            }

            m_oauth = new OAuthHelper(authid, this.ProtocolKey)
            {
                AutoAuthHeader = true
            };
            m_filecache = new Dictionary <string, string>();
        }
Пример #44
0
        public S3(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);
            uri.RequireHost();

            string host = uri.Host;
            m_prefix = uri.Path;

            string awsID = null;
            string awsKey = null;

            if (options.ContainsKey("auth-username"))
                awsID = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                awsKey = options["auth-password"];

            if (options.ContainsKey("aws_access_key_id"))
                awsID = options["aws_access_key_id"];
            if (options.ContainsKey("aws_secret_access_key"))
                awsKey = options["aws_secret_access_key"];
            if (!string.IsNullOrEmpty(uri.Username))
                awsID = uri.Username;
            if (!string.IsNullOrEmpty(uri.Password))
                awsKey = uri.Password;

            if (string.IsNullOrEmpty(awsID))
                throw new Exception(Strings.S3Backend.NoAMZUserIDError);
            if (string.IsNullOrEmpty(awsKey))
                throw new Exception(Strings.S3Backend.NoAMZKeyError);

            bool euBuckets = Utility.Utility.ParseBoolOption(options, EU_BUCKETS_OPTION);
            bool useRRS = Utility.Utility.ParseBoolOption(options, RRS_OPTION);
            bool useSSL = Utility.Utility.ParseBoolOption(options, SSL_OPTION);

            string locationConstraint;
            options.TryGetValue(LOCATION_OPTION, out locationConstraint);

            if (!string.IsNullOrEmpty(locationConstraint) && euBuckets)
                throw new Exception(string.Format(Strings.S3Backend.OptionsAreMutuallyExclusiveError, LOCATION_OPTION, EU_BUCKETS_OPTION));

            if (euBuckets)
                locationConstraint = S3_EU_REGION_NAME;

            string s3host;
            options.TryGetValue(SERVER_NAME, out s3host);
            if (string.IsNullOrEmpty(s3host))
            {
                s3host = DEFAULT_S3_HOST;

                //Change in S3, now requires that you use location specific endpoint
                if (!string.IsNullOrEmpty(locationConstraint))
                    foreach(KeyValuePair<string, string> kvp in DEFAULT_S3_LOCATION_BASED_HOSTS)
                        if (kvp.Key.Equals(locationConstraint, StringComparison.InvariantCultureIgnoreCase))
                        {
                            s3host = kvp.Value;
                            break;
                        }
            }

            //Fallback to previous formats
            if (host.Contains(DEFAULT_S3_HOST))
            {
                Uri u = new Uri(url);
                host = u.Host;
                m_prefix = "";

                if (host.ToLower() == s3host)
                {
                    m_bucket = System.Web.HttpUtility.UrlDecode(u.PathAndQuery);

                    if (m_bucket.StartsWith("/"))
                        m_bucket = m_bucket.Substring(1);

                    if (m_bucket.Contains("/"))
                    {
                        m_prefix = m_bucket.Substring(m_bucket.IndexOf("/") + 1);
                        m_bucket = m_bucket.Substring(0, m_bucket.IndexOf("/"));
                    }
                }
                else
                {
                    //Subdomain type lookup
                    if (host.ToLower().EndsWith("." + s3host))
                    {
                        m_bucket = host.Substring(0, host.Length - ("." + s3host).Length);
                        host = s3host;
                        m_prefix = System.Web.HttpUtility.UrlDecode(u.PathAndQuery);

                        if (m_prefix.StartsWith("/"))
                            m_prefix = m_prefix.Substring(1);
                    }
                    else
                        throw new Exception(string.Format(Strings.S3Backend.UnableToDecodeBucketnameError, url));
                }

                try { Console.Error.WriteLine(string.Format(Strings.S3Backend.DeprecatedUrlFormat, "s3://" + m_bucket + "/" + m_prefix)); }
                catch { }
            }
            else
            {
                //The new simplified url style s3://bucket/prefix
                m_bucket = host;
                host = s3host;
            }

            m_options = options;
            m_prefix = m_prefix.Trim();
            if (m_prefix.Length != 0 && !m_prefix.EndsWith("/"))
                m_prefix += "/";

            m_wrapper = new S3Wrapper(awsID, awsKey, locationConstraint, host, useRRS, useSSL);
        }
Пример #45
0
        /// <summary>
        /// SharePoint has nested subwebs but sometimes different webs
        /// are hooked into a sub path.
        /// For finding files SharePoint is picky to use the correct
        /// path to the web, so we will trial and error here.
        /// The user can give us a hint by supplying an URI with a double
        /// slash to separate web.
        /// Otherwise it's a good guess to look for "/documents", as we expect
        /// that the default document library is used in the path.
        /// If that won't help, we will try all possible pathes from longest
        /// to shortest...
        /// </summary>
        private static string findCorrectWebPath(Utility.Uri orgUrl, System.Net.ICredentials userInfo, out SP.ClientContext retCtx)
        {
            retCtx = null;

            string path = orgUrl.Path;
            int webIndicatorPos = path.IndexOf("//");

            // if a hint is supplied, we will of course use this first.
            if (webIndicatorPos >= 0)
            {
                string testUrl = new Utility.Uri(orgUrl.Scheme, orgUrl.Host, path.Substring(0, webIndicatorPos), null, null, null, orgUrl.Port).ToString();
                if (testUrlForWeb(testUrl, userInfo, false, out retCtx) >= 0)
                    return testUrl;
            }

            // Now go through path and see where we land a success.
            string[] pathParts = path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
            // first we look for the doc library
            int docLibrary = Array.FindIndex(pathParts, p => StringComparer.InvariantCultureIgnoreCase.Equals(p, "documents"));
            if (docLibrary >= 0)
            {
                string testUrl = new Utility.Uri(orgUrl.Scheme, orgUrl.Host,
                    string.Join("/", pathParts, 0, docLibrary),
                    null, null, null, orgUrl.Port).ToString();
                if (testUrlForWeb(testUrl, userInfo, false, out retCtx) >= 0)
                    return testUrl;
            }

            // last but not least: try one after the other.
            for (int pi = pathParts.Length - 1; pi >= 0; pi--)
            {
                if (pi == docLibrary) continue; // already tested

                string testUrl = new Utility.Uri(orgUrl.Scheme, orgUrl.Host,
                    string.Join("/", pathParts, 0, pi),
                    null, null, null, orgUrl.Port).ToString();
                if (testUrlForWeb(testUrl, userInfo, false, out retCtx) >= 0)
                    return testUrl;
            }

            // nothing worked :(
            return null;
        }
Пример #46
0
using Duplicati.Library.Backend.GoogleServices;
Пример #47
0
        public OpenStackStorage(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_container = uri.Host;
            m_prefix = "/" + uri.Path;
            if (!m_prefix.EndsWith("/"))
                m_prefix += "/";

            // For OpenStack we do not use a leading slash
            if (m_prefix.StartsWith("/"))
                m_prefix = m_prefix.Substring(1);

            options.TryGetValue(USERNAME_OPTION, out m_username);
            options.TryGetValue(PASSWORD_OPTION, out m_password);
            options.TryGetValue(TENANTNAME_OPTION, out m_tenantName);
            options.TryGetValue(AUTHURI_OPTION, out m_authUri);
            options.TryGetValue(APIKEY_OPTION, out m_apikey);
            options.TryGetValue(REGION_OPTION, out m_region);

            if (string.IsNullOrWhiteSpace(m_username))
                throw new Exception(Strings.OpenStack.MissingOptionError(USERNAME_OPTION));
            if (string.IsNullOrWhiteSpace(m_authUri))
                throw new Exception(Strings.OpenStack.MissingOptionError(AUTHURI_OPTION));

            if (string.IsNullOrWhiteSpace(m_apikey))
            {
                if (string.IsNullOrWhiteSpace(m_password))
                    throw new Exception(Strings.OpenStack.MissingOptionError(PASSWORD_OPTION));
                if (string.IsNullOrWhiteSpace(m_tenantName))
                    throw new Exception(Strings.OpenStack.MissingOptionError(TENANTNAME_OPTION));
            }

            m_helper = new WebHelper(this);
        }
Пример #48
0
using Newtonsoft.Json;
using Duplicati.Library.Backend.GoogleServices;
Пример #49
0
        public File(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);
            m_path = uri.HostAndPath;
            
            if (options.ContainsKey("auth-username"))
                m_username = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                m_password = options["auth-password"];
            if (!string.IsNullOrEmpty(uri.Username))
                m_username = uri.Username;
            if (!string.IsNullOrEmpty(uri.Password))
                m_password = uri.Password;
            
            if (!System.IO.Path.IsPathRooted(m_path))
                m_path = System.IO.Path.GetFullPath(m_path);

            if (options.ContainsKey(OPTION_ALTERNATE_PATHS))
            {
                List<string> paths = new List<string>();
                paths.Add(m_path);
                paths.AddRange(options[OPTION_ALTERNATE_PATHS].Split(new string[] { System.IO.Path.PathSeparator.ToString() }, StringSplitOptions.RemoveEmptyEntries));

                //On windows we expand the drive letter * to all drives
                if (!Utility.Utility.IsClientLinux)
                {
                    System.IO.DriveInfo[] drives = System.IO.DriveInfo.GetDrives();
                    
                    for (int i = 0; i < paths.Count; i++)
                    {
                        if (paths[i].StartsWith("*:"))
                        {
                            string rpl_path = paths[i].Substring(1);
                            paths.RemoveAt(i);
                            i--;
                            foreach (System.IO.DriveInfo di in drives)
                                paths.Insert(++i, di.Name[0] + rpl_path);
                        }
                    }
                }

                string markerfile = null;

                //If there is a marker file, we do not allow the primary target path
                // to be accepted, unless it contains the marker file
                if (options.ContainsKey(OPTION_DESTINATION_MARKER))
                {
                    markerfile = options[OPTION_DESTINATION_MARKER];
                    m_path = null;
                }

                foreach (string p in paths)
                {
                    try
                    {
                        if (System.IO.Directory.Exists(p) && (markerfile == null || System.IO.File.Exists(System.IO.Path.Combine(p, markerfile))))
                        {
                            m_path = p;
                            break;
                        }
                    }
                    catch
                    {
                    }
                }

                if (m_path == null)
                    throw new Exception(Strings.FileBackend.NoDestinationWithMarkerFileError(markerfile, paths.ToArray()));
            }

            m_moveFile = Utility.Utility.ParseBoolOption(options, OPTION_MOVE_FILE);
            m_forceReauth = Utility.Utility.ParseBoolOption(options, OPTION_FORCE_REAUTH);
            m_hasAutenticated = false;
        }
Пример #50
0
        private void doCreateFolder(bool useNewContext)
        {
            SP.ClientContext ctx = getSpClientContext(useNewContext);
            try
            {
                int pathLengthToWeb = new Utility.Uri(m_spWebUrl).Path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Length;

                string[] folderNames = m_serverRelPath.Substring(0, m_serverRelPath.Length - 1).Split('/');
                folderNames = Array.ConvertAll(folderNames, fold => System.Net.WebUtility.UrlDecode(fold));
                var spfolders = new SP.Folder[folderNames.Length];
                string folderRelPath = "";
                int fi = 0;
                for (; fi < folderNames.Length; fi++)
                {
                    folderRelPath += System.Web.HttpUtility.UrlPathEncode(folderNames[fi]) + "/";
                    if (fi < pathLengthToWeb) continue;
                    var folder = ctx.Web.GetFolderByServerRelativeUrl(folderRelPath);
                    spfolders[fi] = folder;
                    ctx.Load(folder, f => f.Exists);
                    try { wrappedExecuteQueryOnConext(ctx, folderRelPath, true); }
                    catch (FolderMissingException)
                    { break; }
                    if (!folder.Exists) break;
                }

                for (; fi < folderNames.Length; fi++)
                    spfolders[fi] = spfolders[fi - 1].Folders.Add(folderNames[fi]);
                ctx.Load(spfolders[folderNames.Length - 1], f => f.Exists);

                wrappedExecuteQueryOnConext(ctx, m_serverRelPath, true);

                if (!spfolders[folderNames.Length - 1].Exists)
                    throw new Interface.FolderMissingException(Strings.SharePoint.MissingElementError(m_serverRelPath, m_spWebUrl));
            }
            catch (ServerException) { throw; /* rethrow if Server answered */ }
            catch (Interface.FileMissingException) { throw; }
            catch (Interface.FolderMissingException) { throw; }
            catch { if (!useNewContext) /* retry */ doCreateFolder(true); else throw; }
            finally { }
        }
Пример #51
0
        public BoxBackend(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);

            m_path = uri.HostAndPath;
            if (!m_path.EndsWith("/"))
                m_path += "/";
            
            string authid = null;
            if (options.ContainsKey(AUTHID_OPTION))
                authid = options[AUTHID_OPTION];

            m_deleteFromTrash = Library.Utility.Utility.ParseBoolOption(options, REALLY_DELETE_OPTION);

            m_oauth = new BoxHelper(authid);
        }
Пример #52
0
        public CloudFiles(string url, Dictionary<string, string> options)
        {
            var uri = new Utility.Uri(url);
            
            if (options.ContainsKey("auth-username"))
                m_username = options["auth-username"];
            if (options.ContainsKey("auth-password"))
                m_password = options["auth-password"];

            if (options.ContainsKey("cloudfiles-username"))
                m_username = options["cloudfiles-username"];
            if (options.ContainsKey("cloudfiles-accesskey"))
                m_password = options["cloudfiles-accesskey"];
            
            if (!string.IsNullOrEmpty(uri.Username))
                m_username = uri.Username;
            if (!string.IsNullOrEmpty(uri.Password))
                m_password = uri.Password;

            if (string.IsNullOrEmpty(m_username))
                throw new Exception(Strings.CloudFiles.NoUserIDError);
            if (string.IsNullOrEmpty(m_password))
                throw new Exception(Strings.CloudFiles.NoAPIKeyError);

            //Fallback to the previous format
            if (url.Contains(DUMMY_HOSTNAME))
            {
                Uri u = new Uri(url);

                if (!string.IsNullOrEmpty(u.UserInfo))
                {
                    if (u.UserInfo.IndexOf(":") >= 0)
                    {
                        m_username = u.UserInfo.Substring(0, u.UserInfo.IndexOf(":"));
                        m_password = u.UserInfo.Substring(u.UserInfo.IndexOf(":") + 1);
                    }
                    else
                    {
                        m_username = u.UserInfo;
                    }
                }

                //We use the api.mosso.com hostname.
                //This allows the use of containers that have names that are not valid hostnames, 
                // such as container names with spaces in them
                if (u.Host.Equals(DUMMY_HOSTNAME))
                    m_path = System.Web.HttpUtility.UrlDecode(u.PathAndQuery);
                else
                    m_path = u.Host + System.Web.HttpUtility.UrlDecode(u.PathAndQuery);
            }
            else
            {
                m_path = uri.HostAndPath;
            }

            if (m_path.EndsWith("/"))
                m_path = m_path.Substring(0, m_path.Length - 1);
            if (!m_path.StartsWith("/"))
                m_path = "/" + m_path;

            if (!options.TryGetValue("cloudfiles-authentication-url", out m_authUrl))
                m_authUrl = Utility.Utility.ParseBoolOption(options, "cloudfiles-uk-account") ? AUTH_URL_UK : AUTH_URL_US;
        }
Пример #53
0
        public IDictionary<string, string> Execute(IDictionary<string, string> options)
        {
            var res = new Dictionary<string, string>();

            string url;
            string pubkey_s;

            options.TryGetValue(OPTION_URL, out url);
            options.TryGetValue(OPTION_KEY, out pubkey_s);

            if (string.IsNullOrWhiteSpace(url))
                throw new ArgumentException(OPTION_URL);
            if (string.IsNullOrWhiteSpace(pubkey_s))
                throw new ArgumentException(OPTION_KEY);

            var uri = new Utility.Uri(url);
            foreach(var key in uri.QueryParameters.AllKeys)
                options[key] = uri.QueryParameters[key];

            pubkey_s = pubkey_s.Trim();
            var pubkey = pubkey_s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).Where(x => x.Length > 0).ToArray();

            if (pubkey.Length != 3)
                throw new ArgumentException(OPTION_KEY);

            using(var connection = new SSHv2(url, (Dictionary<string, string>)options))
            {
                var client = connection.Client;
                try
                {
                    client.ChangeDirectory(SSH_FOLDER);
                }
                catch
                {
                    client.CreateDirectory(SSH_FOLDER);
                    client.ChangePermissions(SSH_FOLDER, SSH_FOLDER_PERMISSIONS);
                    client.ChangeDirectory(SSH_FOLDER);
                }

                var sshfolder = client.ListDirectory(".").Where(x => x.Name == ".").First();
                client.ChangeDirectory("..");

                if (!sshfolder.OwnerCanRead || !sshfolder.OwnerCanWrite)
                    client.ChangePermissions(SSH_FOLDER, SSH_FOLDER_PERMISSIONS);

                string authorized_keys = "";
                byte[] authorized_keys_bytes = null;

                var existing_authorized_keys = client.ListDirectory(SSH_FOLDER).Where(x => x.Name == AUTHORIZED_KEYS_FILE).Any();
                if (existing_authorized_keys)
                {
                    using(var ms = new System.IO.MemoryStream())
                    {
                        client.DownloadFile(AUTHORIZED_KEYS_PATH, ms);
                        authorized_keys_bytes = ms.ToArray();
                        authorized_keys = System.Text.Encoding.ASCII.GetString(authorized_keys_bytes);
                    }
                }

                var keys = authorized_keys == null ? new string[0] : authorized_keys.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
                var cleaned_keys = keys.Select(x => x.Trim()).Where(x => x.Length > 0 && !x.StartsWith("#"));

                // Does the key already exist?
                if (cleaned_keys.Where(x =>
                {
                    var els = x.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(y => y.Trim()).Where(y => y.Length > 0).ToArray();
                    return els.Length == 3 && els[0] == pubkey[0] && els[1] == pubkey[1];
                }).Any())
                {
                    res["status"] = "Key already existed";
                }
                else
                {
                    var new_file = authorized_keys;
                    if (new_file.Trim().Length > 0)
                        new_file = authorized_keys.Trim() + "\n";
                    new_file += string.Join(" ", pubkey) + "\n";

                    if (existing_authorized_keys)
                    {
                        var filename = AUTHORIZED_KEYS_PATH + ".backup-" + DateTime.UtcNow.ToString("yyyyMMddThhmmss");
                        using(var ms = new System.IO.MemoryStream(authorized_keys_bytes))
                            client.UploadFile(ms, filename);
                        client.ChangePermissions(filename, AUTHORIZED_KEYS_BACKUP_PERMISSIONS);
                    }

                    using(var ms = new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes(new_file)))
                        client.UploadFile(ms, AUTHORIZED_KEYS_PATH);

                    if (!existing_authorized_keys)
                        client.ChangePermissions(AUTHORIZED_KEYS_PATH, AUTHORIZED_KEYS_PERMISSIONS);

                    res["status"] = "Key updated";
                }

            }

            return res;
        }
Пример #54
0
        public SharePointBackend(string url, Dictionary<string, string> options)
        {
            m_deleteToRecycler = Utility.Utility.ParseBoolOption(options, "delete-to-recycler");
            m_useBinaryDirectMode = Utility.Utility.ParseBoolOption(options, "binary-direct-mode");

            try
            {
                string strSpan;
                if (options.TryGetValue("web-timeout", out strSpan))
                {
                    TimeSpan ts = Timeparser.ParseTimeSpan(strSpan);
                    if (ts.TotalMilliseconds > 30000 && ts.TotalMilliseconds < int.MaxValue)
                        this.m_useContextTimeoutMs = (int)ts.TotalMilliseconds;
                }
            }
            catch { }

            try
            {
                string strChunkSize;
                if (options.TryGetValue("chunk-size", out strChunkSize))
                {
                    long pSize = Utility.Sizeparser.ParseSize(strChunkSize, "MB");
                    if (pSize >= (1 << 14) && pSize <= (1 << 30)) // [16kb .. 1GB]
                        this.m_fileChunkSize = (int)pSize;
                }
            }
            catch { }

            var u = new Utility.Uri(url);
            u.RequireHost();

            // Create sanitized plain https-URI (note: still has double slashes for processing web)
            m_orgUrl = new Utility.Uri("https", u.Host, u.Path, null, null, null, u.Port);

            // Actual path to Web will be searched for on first use. Ctor should not throw.
            m_spWebUrl = null;

            m_serverRelPath = u.Path;
            if (!m_serverRelPath.StartsWith("/"))
                m_serverRelPath = "/" + m_serverRelPath;
            if (!m_serverRelPath.EndsWith("/"))
                m_serverRelPath += "/";
            // remove marker for SP-Web
            m_serverRelPath = m_serverRelPath.Replace("//", "/");

            // Authentication settings processing:
            // Default: try integrated auth (will normally not work for Office365, but maybe with on-prem SharePoint...).
            // Otherwise: Use settings from URL(precedence) or from command line options.
            bool useIntegratedAuthentication = Utility.Utility.ParseBoolOption(options, "integrated-authentication");

            string useUsername = null;
            string usePassword = null;

            if (!useIntegratedAuthentication)
            {
                if (!string.IsNullOrEmpty(u.Username))
                {
                    useUsername = u.Username;
                    if (!string.IsNullOrEmpty(u.Password))
                        usePassword = u.Password;
                    else if (options.ContainsKey("auth-password"))
                        usePassword = options["auth-password"];
                }
                else
                {
                    if (options.ContainsKey("auth-username"))
                    {
                        useUsername = options["auth-username"];
                        if (options.ContainsKey("auth-password"))
                            usePassword = options["auth-password"];
                    }
                }
            }

            if (useIntegratedAuthentication || (useUsername == null || usePassword == null))
            {
                // This might or might not work for on-premises SP. Maybe support if someone complains...
                m_userInfo = System.Net.CredentialCache.DefaultNetworkCredentials;
            }
            else
            {
                System.Security.SecureString securePwd = new System.Security.SecureString();
                usePassword.ToList().ForEach(c => securePwd.AppendChar(c));
                m_userInfo = new Microsoft.SharePoint.Client.SharePointOnlineCredentials(useUsername, securePwd);
                // Other options (also ADAL, see class remarks) might be supported on request.
                // Maybe go in deep then and also look at:
                // - Microsoft.SharePoint.Client.AppPrincipalCredential.CreateFromKeyGroup()
                // - ctx.AuthenticationMode = SP.ClientAuthenticationMode.FormsAuthentication;
                // - ctx.FormsAuthenticationLoginInfo = new SP.FormsAuthenticationLoginInfo(user, pwd);
            }
        }