private void TestConnection(string url, RequestInfo info) { var modules = (from n in Library.DynamicLoader.GenericLoader.Modules where n is Library.Interface.IConnectionModule select n).ToArray(); try { var uri = new Library.Utility.Uri(url); var qp = uri.QueryParameters; var opts = new Dictionary <string, string>(); foreach (var k in qp.Keys.Cast <string>()) { opts[k] = qp[k]; } foreach (var n in modules) { n.Configure(opts); } using (var b = Duplicati.Library.DynamicLoader.BackendLoader.GetBackend(url, new Dictionary <string, string>())) b.Test(); info.OutputOK(); } catch (Duplicati.Library.Interface.FolderMissingException) { info.ReportServerError("missing-folder"); } catch (Duplicati.Library.Utility.SslCertificateValidator.InvalidCertificateException icex) { if (string.IsNullOrWhiteSpace(icex.Certificate)) { info.ReportServerError(icex.Message); } else { info.ReportServerError("incorrect-cert:" + icex.Certificate); } } finally { foreach (var n in modules) { if (n is IDisposable) { ((IDisposable)n).Dispose(); } } } }
private void ListFileSets(IBackup backup, RequestInfo info) { var input = info.Request.QueryString; var extra = new Dictionary <string, string>(); extra["list-sets-only"] = "true"; if (input["include-metadata"].Value != null) { extra["list-sets-only"] = (!Library.Utility.Utility.ParseBool(input["include-metadata"].Value, false)).ToString(); } if (input["from-remote-only"].Value != null) { extra["no-local-db"] = Library.Utility.Utility.ParseBool(input["from-remote-only"].Value, false).ToString(); } var r = Runner.Run(Runner.CreateTask(DuplicatiOperation.List, backup, extra), false) as Duplicati.Library.Interface.IListResults; if (r.EncryptedFiles && backup.Settings.Any(x => string.Equals("--no-encryption", x.Name, StringComparison.InvariantCultureIgnoreCase))) { info.ReportServerError("encrypted-storage"); } else { info.OutputOK(r.Filesets); } }
public void POST(string key, RequestInfo info) { switch ((key ?? "").ToLowerInvariant()) { case "check": Program.UpdatePoller.CheckNow(); info.OutputOK(); return; case "install": Program.UpdatePoller.InstallUpdate(); info.OutputOK(); return; case "activate": if (Program.WorkThread.CurrentTask != null || Program.WorkThread.CurrentTasks.Count != 0) { info.ReportServerError("Cannot activate update while task is running or scheduled"); } else { Program.UpdatePoller.ActivateUpdate(); info.OutputOK(); } return; default: info.ReportClientError("No such action", System.Net.HttpStatusCode.NotFound); return; } }
private void TestConnection(string url, RequestInfo info) { var modules = (from n in Library.DynamicLoader.GenericLoader.Modules where n is Library.Interface.IConnectionModule select n).ToArray(); try { var uri = new Library.Utility.Uri(url); var qp = uri.QueryParameters; var opts = new Dictionary<string, string>(); foreach(var k in qp.Keys.Cast<string>()) opts[k] = qp[k]; foreach(var n in modules) n.Configure(opts); using(var b = Duplicati.Library.DynamicLoader.BackendLoader.GetBackend(url, new Dictionary<string, string>())) b.Test(); info.OutputOK(); } catch (Duplicati.Library.Interface.FolderMissingException) { info.ReportServerError("missing-folder"); } catch (Duplicati.Library.Utility.SslCertificateValidator.InvalidCertificateException icex) { if (string.IsNullOrWhiteSpace(icex.Certificate)) info.ReportServerError(icex.Message); else info.ReportServerError("incorrect-cert:" + icex.Certificate); } finally { foreach(var n in modules) if (n is IDisposable) ((IDisposable)n).Dispose(); } }
private void RealGET(string key, RequestInfo info) { var mssqlUtility = new MSSQLUtility(); if (!mssqlUtility.IsMSSQLInstalled || !new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) { info.OutputOK(new string[0]); return; } try { mssqlUtility.QueryDBsInfo(); if (string.IsNullOrEmpty(key)) { info.OutputOK(mssqlUtility.DBs.Select(x => new { id = x.ID, name = x.Name }).ToList()); } else { var foundDBs = mssqlUtility.DBs.FindAll(x => x.ID.Equals(key, StringComparison.OrdinalIgnoreCase)); if (foundDBs.Count == 1) { info.OutputOK(foundDBs[0].DataPaths.Select(x => new { text = x, id = x, cls = "folder", iconCls = "x-tree-icon-leaf", check = "false", leaf = "true" }).ToList()); } else { info.ReportClientError(string.Format("Cannot find DB with ID {0}.", key), System.Net.HttpStatusCode.NotFound); } } } catch (Exception ex) { info.ReportServerError("Failed to enumerate Microsoft SQL Server databases: " + ex.Message); } }
private void RealGET(string key, RequestInfo info) { var hypervUtility = new HyperVUtility(); if (!hypervUtility.IsHyperVInstalled || !new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) { info.OutputOK(new string[0]); return; } try { if (string.IsNullOrEmpty(key)) { hypervUtility.QueryHyperVGuestsInfo(); info.OutputOK(hypervUtility.Guests.Select(x => new { id = x.ID, name = x.Name }).ToList()); } else { hypervUtility.QueryHyperVGuestsInfo(true); var foundVMs = hypervUtility.Guests.FindAll(x => x.ID.Equals(new Guid(key))); if (foundVMs.Count == 1) { info.OutputOK(foundVMs[0].DataPaths.Select(x => new { text = x, id = x, cls = "folder", iconCls = "x-tree-icon-leaf", check = "false", leaf = "true" }).ToList()); } else { info.ReportClientError(string.Format("Cannot find VM with ID {0}.", key), System.Net.HttpStatusCode.NotFound); } } } catch (Exception ex) { info.ReportServerError("Failed to enumerate Hyper-V virtual machines: " + ex.Message); } }
private void Process(string command, string path, RequestInfo info) { if (string.IsNullOrEmpty(path)) { info.ReportClientError("No path parameter was found"); return; } bool skipFiles = Library.Utility.Utility.ParseBool(info.Request.QueryString["onlyfolders"].Value, false); bool showHidden = Library.Utility.Utility.ParseBool(info.Request.QueryString["showhidden"].Value, false); string specialpath = null; string specialtoken = null; if (path.StartsWith("%")) { var ix = path.IndexOf("%", 1); if (ix > 0) { var tk = path.Substring(0, ix + 1); var node = SpecialFolders.Nodes.Where(x => x.id.Equals(tk, StringComparison.OrdinalIgnoreCase)).FirstOrDefault(); if (node != null) { specialpath = node.resolvedpath; specialtoken = node.id; } } } path = SpecialFolders.ExpandEnvironmentVariables(path); if (Duplicati.Library.Utility.Utility.IsClientLinux && !path.StartsWith("/")) { info.ReportClientError("The path parameter must start with a forward-slash"); return; } if (!string.IsNullOrWhiteSpace(command)) { if ("validate".Equals(command, StringComparison.OrdinalIgnoreCase)) { try { if (System.IO.Path.IsPathRooted(path) && (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))) { info.OutputOK(); return; } } catch { } info.ReportServerError("File or folder not found"); return; } else { info.ReportClientError(string.Format("No such operation found: {0}", command)); return; } } try { if (path != "" && path != "/") { path = Duplicati.Library.Utility.Utility.AppendDirSeparator(path); } IEnumerable <Serializable.TreeNode> res; if (!Library.Utility.Utility.IsClientLinux && (path.Equals("/") || path.Equals(""))) { res = DriveInfo.GetDrives() .Where(di => (di.DriveType == DriveType.Fixed || di.DriveType == DriveType.Network || di.DriveType == DriveType.Removable) && di.IsReady // Only try to create TreeNode entries for drives who were ready 'now' ) .Select(TryCreateTreeNodeForDrive) // This will try to create a TreeNode for selected drives .Where(tn => tn != null); // This filters out such entries that could not be created } else { res = ListFolderAsNodes(path, skipFiles, showHidden); } if ((path.Equals("/") || path.Equals("")) && specialtoken == null) { // Prepend special folders res = SpecialFolders.Nodes.Union(res); } if (specialtoken != null) { res = res.Select(x => { x.resolvedpath = x.id; x.id = specialtoken + x.id.Substring(specialpath.Length); return(x); }); } // We have to resolve the query before giving it to OutputOK // If we do not do this, and the query throws an exception when OutputOK resolves it, // the exception would not be handled properly res = res.ToList(); info.OutputOK(res); } catch (Exception ex) { info.ReportClientError("Failed to process the path: " + ex.Message); } }
private void Process(string command, string path, RequestInfo info) { if (string.IsNullOrEmpty(path)) { info.ReportClientError("No path parameter was found"); return; } bool skipFiles = Library.Utility.Utility.ParseBool(info.Request.QueryString["onlyfolders"].Value, false); bool showHidden = Library.Utility.Utility.ParseBool(info.Request.QueryString["showhidden"].Value, false); string specialpath = null; string specialtoken = null; if (path.StartsWith("%")) { var ix = path.IndexOf("%", 1); if (ix > 0) { var tk = path.Substring(0, ix + 1); var node = SpecialFolders.Nodes.Where(x => x.id.Equals(tk, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (node != null) { specialpath = node.resolvedpath; specialtoken = node.id; } } } path = SpecialFolders.ExpandEnvironmentVariables(path); if (Duplicati.Library.Utility.Utility.IsClientLinux && !path.StartsWith("/")) { info.ReportClientError("The path parameter must start with a forward-slash"); return; } if (!string.IsNullOrWhiteSpace(command)) { if ("validate".Equals(command, StringComparison.InvariantCultureIgnoreCase)) { try { if (System.IO.Path.IsPathRooted(path) && (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))) { info.OutputOK(); return; } } catch { } info.ReportServerError("File or folder not found"); return; } else { info.ReportClientError(string.Format("No such operation found: {0}", command)); return; } } try { if (path != "" && path != "/") { path = Duplicati.Library.Utility.Utility.AppendDirSeparator(path); } IEnumerable <Serializable.TreeNode> res; if (!Library.Utility.Utility.IsClientLinux && (path.Equals("/") || path.Equals(""))) { res = from di in System.IO.DriveInfo.GetDrives() where di.DriveType == DriveType.Fixed || di.DriveType == DriveType.Network || di.DriveType == DriveType.Removable select new Serializable.TreeNode() { id = di.RootDirectory.FullName, text = ( string.IsNullOrWhiteSpace(di.VolumeLabel) ? di.RootDirectory.FullName.Replace('\\', ' ') : di.VolumeLabel + " - " + di.RootDirectory.FullName.Replace('\\', ' ') ) + "(" + di.DriveType + ")", iconCls = "x-tree-icon-drive" }; } else { res = ListFolderAsNodes(path, skipFiles, showHidden); } if ((path.Equals("/") || path.Equals("")) && specialtoken == null) { // Prepend special folders res = SpecialFolders.Nodes.Union(res); } if (specialtoken != null) { res = res.Select(x => { x.resolvedpath = x.id; x.id = specialtoken + x.id.Substring(specialpath.Length); return(x); }); } info.OutputOK(res); } catch (Exception ex) { info.ReportClientError("Failed to process the path: " + ex.Message); } }
private void Process(string command, string path, RequestInfo info) { if (string.IsNullOrEmpty(path)) { info.ReportClientError("No path parameter was found"); return; } bool skipFiles = Library.Utility.Utility.ParseBool(info.Request.QueryString["onlyfolders"].Value, false); bool showHidden = Library.Utility.Utility.ParseBool(info.Request.QueryString["showhidden"].Value, false); string specialpath = null; string specialtoken = null; if (path.StartsWith("%")) { var ix = path.IndexOf("%", 1); if (ix > 0) { var tk = path.Substring(0, ix + 1); var node = SpecialFolders.Nodes.Where(x => x.id.Equals(tk, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (node != null) { specialpath = node.resolvedpath; specialtoken = node.id; } } } path = SpecialFolders.ExpandEnvironmentVariables(path); if (Duplicati.Library.Utility.Utility.IsClientLinux && !path.StartsWith("/")) { info.ReportClientError("The path parameter must start with a forward-slash"); return; } if (!string.IsNullOrWhiteSpace(command)) { if ("validate".Equals(command, StringComparison.InvariantCultureIgnoreCase)) { try { if (System.IO.Path.IsPathRooted(path) && (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))) { info.OutputOK(); return; } } catch { } info.ReportServerError("File or folder not found"); return; } else { info.ReportClientError(string.Format("No such operation found: {0}", command)); return; } } try { if (path != "" && path != "/") path = Duplicati.Library.Utility.Utility.AppendDirSeparator(path); IEnumerable<Serializable.TreeNode> res; if (!Library.Utility.Utility.IsClientLinux && (path.Equals("/") || path.Equals(""))) { res = from di in System.IO.DriveInfo.GetDrives() where di.DriveType == DriveType.Fixed || di.DriveType == DriveType.Network || di.DriveType == DriveType.Removable select new Serializable.TreeNode() { id = di.RootDirectory.FullName, text = di.RootDirectory.FullName.Replace('\\', ' ') + "(" + di.DriveType + ")", iconCls = "x-tree-icon-drive" }; } else { res = ListFolderAsNodes(path, skipFiles, showHidden); } if ((path.Equals("/") || path.Equals("")) && specialtoken == null) { // Prepend special folders res = SpecialFolders.Nodes.Union(res); } if (specialtoken != null) { res = res.Select(x => { x.resolvedpath = x.id; x.id = specialtoken + x.id.Substring(specialpath.Length); return x; }); } info.OutputOK(res); } catch (Exception ex) { info.ReportClientError("Failed to process the path: " + ex.Message); } }
{
private void ListFileSets(IBackup backup, RequestInfo info) { var input = info.Request.QueryString; var extra = new Dictionary<string, string>(); extra["list-sets-only"] = "true"; if (input["include-metadata"].Value != null) extra["list-sets-only"] = (!Library.Utility.Utility.ParseBool(input["include-metadata"].Value, false)).ToString(); if (input["from-remote-only"].Value != null) extra["no-local-db"] = Library.Utility.Utility.ParseBool(input["from-remote-only"].Value, false).ToString(); var r = Runner.Run(Runner.CreateTask(DuplicatiOperation.List, backup, extra), false) as Duplicati.Library.Interface.IListResults; if (r.EncryptedFiles && backup.Settings.Any(x => string.Equals("--no-encryption", x.Name, StringComparison.InvariantCultureIgnoreCase))) info.ReportServerError("encrypted-storage"); else info.OutputOK(r.Filesets); }
private void Process(string command, string path, RequestInfo info) { if (string.IsNullOrEmpty(path)) { info.ReportClientError("No path parameter was found"); return; } bool skipFiles = Library.Utility.Utility.ParseBool(info.Request.QueryString["onlyfolders"].Value, false); bool showHidden = Library.Utility.Utility.ParseBool(info.Request.QueryString["showhidden"].Value, false); string specialpath = null; string specialtoken = null; if (path.StartsWith("%")) { var ix = path.IndexOf("%", 1); if (ix > 0) { var tk = path.Substring(0, ix + 1); var node = SpecialFolders.Nodes.Where(x => x.id.Equals(tk, StringComparison.InvariantCultureIgnoreCase)).FirstOrDefault(); if (node != null) { specialpath = node.resolvedpath; specialtoken = node.id; } } } path = SpecialFolders.ExpandEnvironmentVariables(path); if (Duplicati.Library.Utility.Utility.IsClientLinux && !path.StartsWith("/")) { info.ReportClientError("The path parameter must start with a forward-slash"); return; } if (!string.IsNullOrWhiteSpace(command)) { if ("validate".Equals(command, StringComparison.InvariantCultureIgnoreCase)) { try { if (System.IO.Path.IsPathRooted(path) && (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))) { info.OutputOK(); return; } } catch { } info.ReportServerError("File or folder not found"); return; } else { info.ReportClientError(string.Format("No such operation found: {0}", command)); return; } } try { if (path != "" && path != "/") path = Duplicati.Library.Utility.Utility.AppendDirSeparator(path); IEnumerable<Serializable.TreeNode> res; if (!Library.Utility.Utility.IsClientLinux && (path.Equals("/") || path.Equals(""))) { res = DriveInfo.GetDrives() .Where(di => (di.DriveType == DriveType.Fixed || di.DriveType == DriveType.Network || di.DriveType == DriveType.Removable) && di.IsReady // Only try to create TreeNode entries for drives who were ready 'now' ) .Select(TryCreateTreeNodeForDrive) // This will try to create a TreeNode for selected drives .Where(tn => tn != null); // This filters out such entries that could not be created } else { res = ListFolderAsNodes(path, skipFiles, showHidden); } if ((path.Equals("/") || path.Equals("")) && specialtoken == null) { // Prepend special folders res = SpecialFolders.Nodes.Union(res); } if (specialtoken != null) { res = res.Select(x => { x.resolvedpath = x.id; x.id = specialtoken + x.id.Substring(specialpath.Length); return x; }); } // We have to resolve the query before giving it to OutputOK // If we do not do this, and the query throws an exception when OutputOK resolves it, // the exception would not be handled properly res = res.ToList(); info.OutputOK(res); } catch (Exception ex) { info.ReportClientError("Failed to process the path: " + ex.Message); } }
namespace Duplicati.Server.WebServer.RESTMethods