2015-01-20 21:44:52 +01:00
|
|
|
// Copyright (C) 2015, The Duplicati Team
|
2014-06-27 13:23:05 +02:00
|
|
|
|
2015-01-20 21:44:52 +01:00
|
|
|
// http://www.duplicati.com, info@duplicati.com
|
2014-06-27 13:23:05 +02:00
|
|
|
//
|
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU Lesser General Public License as
|
|
|
|
|
// published by the Free Software Foundation; either version 2.1 of the
|
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
|
//
|
|
|
|
|
// This library is distributed in the hope that it will be useful, but
|
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
// Lesser General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using HttpServer;
|
|
|
|
|
using HttpServer.HttpModules;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Duplicati.Server.Serialization;
|
2014-08-04 01:06:29 +02:00
|
|
|
using System.IO;
|
2014-06-27 13:23:05 +02:00
|
|
|
|
|
|
|
|
namespace Duplicati.Server.WebServer
|
|
|
|
|
{
|
|
|
|
|
internal partial class ControlHandler : HttpModule
|
|
|
|
|
{
|
|
|
|
|
private delegate void ProcessSub(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter writer);
|
|
|
|
|
private readonly Dictionary<string, ProcessSub> SUPPORTED_METHODS;
|
|
|
|
|
|
2015-02-26 23:21:22 +01:00
|
|
|
public const string CONTROL_HANDLER_URI = "/control.cgi";
|
|
|
|
|
|
2014-06-27 13:23:05 +02:00
|
|
|
public ControlHandler()
|
|
|
|
|
{
|
|
|
|
|
SUPPORTED_METHODS = new Dictionary<string, ProcessSub>(System.StringComparer.InvariantCultureIgnoreCase);
|
|
|
|
|
|
|
|
|
|
//Make a list of all supported actions
|
|
|
|
|
SUPPORTED_METHODS.Add("supported-actions", ListSupportedActions);
|
|
|
|
|
SUPPORTED_METHODS.Add("system-info", ListSystemInfo);
|
|
|
|
|
SUPPORTED_METHODS.Add("list-backups", ListBackups);
|
|
|
|
|
SUPPORTED_METHODS.Add("get-current-state", GetCurrentState);
|
|
|
|
|
SUPPORTED_METHODS.Add("get-progress-state", GetProgressState);
|
|
|
|
|
SUPPORTED_METHODS.Add("list-application-settings", ListApplicationSettings);
|
|
|
|
|
SUPPORTED_METHODS.Add("send-command", SendCommand);
|
|
|
|
|
SUPPORTED_METHODS.Add("get-backup-defaults", GetBackupDefaults);
|
|
|
|
|
SUPPORTED_METHODS.Add("get-folder-contents", GetFolderContents);
|
|
|
|
|
SUPPORTED_METHODS.Add("get-backup", GetBackup);
|
|
|
|
|
SUPPORTED_METHODS.Add("add-backup", AddBackup);
|
|
|
|
|
SUPPORTED_METHODS.Add("update-backup", UpdateBackup);
|
|
|
|
|
SUPPORTED_METHODS.Add("delete-backup", DeleteBackup);
|
2015-04-08 21:02:01 +02:00
|
|
|
SUPPORTED_METHODS.Add("copy-backup-to-temp", CopyBackupToTemporary);
|
2014-06-27 13:23:05 +02:00
|
|
|
SUPPORTED_METHODS.Add("validate-path", ValidatePath);
|
|
|
|
|
SUPPORTED_METHODS.Add("list-tags", ListTags);
|
|
|
|
|
SUPPORTED_METHODS.Add("test-backend", TestBackend);
|
2014-07-15 17:10:44 +02:00
|
|
|
SUPPORTED_METHODS.Add("create-remote-folder", CreateRemoteFolder);
|
2014-06-27 13:23:05 +02:00
|
|
|
SUPPORTED_METHODS.Add("list-remote-folder", ListRemoteFolder);
|
|
|
|
|
SUPPORTED_METHODS.Add("list-backup-sets", ListBackupSets);
|
|
|
|
|
SUPPORTED_METHODS.Add("search-backup-files", SearchBackupFiles);
|
|
|
|
|
SUPPORTED_METHODS.Add("restore-files", RestoreFiles);
|
|
|
|
|
SUPPORTED_METHODS.Add("read-log", ReadLogData);
|
|
|
|
|
SUPPORTED_METHODS.Add("get-license-data", GetLicenseData);
|
2014-07-09 22:40:11 +02:00
|
|
|
SUPPORTED_METHODS.Add("get-changelog", GetChangelog);
|
2014-08-06 11:23:23 +02:00
|
|
|
SUPPORTED_METHODS.Add("get-acknowledgements", GetAcknowledgements);
|
2014-07-25 22:17:48 +02:00
|
|
|
SUPPORTED_METHODS.Add("locate-uri-db", LocateUriDb);
|
2014-08-01 11:18:10 +02:00
|
|
|
SUPPORTED_METHODS.Add("poll-log-messages", PollLogMessages);
|
2014-08-02 01:10:39 +02:00
|
|
|
SUPPORTED_METHODS.Add("export-backup", ExportBackup);
|
|
|
|
|
SUPPORTED_METHODS.Add("import-backup", ImportBackup);
|
2014-08-04 01:06:29 +02:00
|
|
|
SUPPORTED_METHODS.Add("get-ui-settings", GetUISettings);
|
|
|
|
|
SUPPORTED_METHODS.Add("set-ui-settings", SetUISettings);
|
|
|
|
|
SUPPORTED_METHODS.Add("get-ui-schemes", GetUISettingSchemes);
|
|
|
|
|
SUPPORTED_METHODS.Add("get-notifications", GetNotifications);
|
|
|
|
|
SUPPORTED_METHODS.Add("dismiss-notification", DismissNotification);
|
2014-08-05 23:04:00 +02:00
|
|
|
SUPPORTED_METHODS.Add("download-bug-report", DownloadBugReport);
|
2014-08-07 21:05:44 +02:00
|
|
|
SUPPORTED_METHODS.Add("delete-local-data", DeleteLocalData);
|
2014-08-15 01:51:48 +02:00
|
|
|
SUPPORTED_METHODS.Add("get-server-options", GetServerOptions);
|
|
|
|
|
SUPPORTED_METHODS.Add("set-server-options", SetServerOptions);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override bool Process (HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session)
|
|
|
|
|
{
|
|
|
|
|
//We use the fake entry point /control.cgi to listen for requests
|
|
|
|
|
//This ensures that the rest of the webserver can just serve plain files
|
2015-02-26 23:21:22 +01:00
|
|
|
if (!request.Uri.AbsolutePath.Equals(CONTROL_HANDLER_URI, StringComparison.InvariantCultureIgnoreCase))
|
2014-06-27 13:23:05 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
|
|
|
|
|
string action = input["action"].Value ?? "";
|
|
|
|
|
|
|
|
|
|
//Lookup the actual handler method
|
|
|
|
|
ProcessSub method;
|
|
|
|
|
SUPPORTED_METHODS.TryGetValue(action, out method);
|
|
|
|
|
|
|
|
|
|
if (method == null) {
|
|
|
|
|
response.Status = System.Net.HttpStatusCode.NotImplemented;
|
|
|
|
|
response.Reason = "Unsupported action: " + (action == null ? "<null>" : "");
|
|
|
|
|
response.Send();
|
|
|
|
|
} else {
|
|
|
|
|
//Default setup
|
|
|
|
|
response.Status = System.Net.HttpStatusCode.OK;
|
|
|
|
|
response.Reason = "OK";
|
|
|
|
|
#if DEBUG
|
|
|
|
|
response.ContentType = "text/plain";
|
|
|
|
|
#else
|
|
|
|
|
response.ContentType = "text/json";
|
|
|
|
|
#endif
|
2015-07-30 14:31:27 +02:00
|
|
|
using (BodyWriter bw = new BodyWriter(response, request))
|
2014-06-27 13:23:05 +02:00
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
method(request, response, session, bw);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2014-08-02 01:10:39 +02:00
|
|
|
Program.DataConnection.LogError("", string.Format("Request for {0} gave error", action), ex);
|
2014-08-05 23:04:00 +02:00
|
|
|
Console.WriteLine(ex.ToString());
|
2014-08-02 01:10:39 +02:00
|
|
|
|
2014-06-27 13:23:05 +02:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (!response.HeadersSent)
|
|
|
|
|
{
|
|
|
|
|
response.Status = System.Net.HttpStatusCode.InternalServerError;
|
|
|
|
|
response.Reason = "Error";
|
|
|
|
|
response.ContentType = "text/plain";
|
|
|
|
|
|
|
|
|
|
bw.WriteJsonObject(new
|
|
|
|
|
{
|
|
|
|
|
Message = ex.Message,
|
|
|
|
|
Type = ex.GetType().Name,
|
|
|
|
|
#if DEBUG
|
|
|
|
|
Stacktrace = ex.ToString()
|
|
|
|
|
#endif
|
|
|
|
|
});
|
|
|
|
|
bw.Flush();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception flex)
|
|
|
|
|
{
|
2014-08-02 01:10:39 +02:00
|
|
|
Program.DataConnection.LogError("", "Reporting error gave error", flex);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ReportError(HttpServer.IHttpResponse response, BodyWriter bw, string message)
|
|
|
|
|
{
|
|
|
|
|
response.Status = System.Net.HttpStatusCode.InternalServerError;
|
|
|
|
|
response.Reason = message;
|
|
|
|
|
|
|
|
|
|
bw.WriteJsonObject(new { Error = message });
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
private void ReadLogData(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
2014-06-27 13:23:05 +02:00
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
2014-06-27 13:23:05 +02:00
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
if (string.IsNullOrEmpty(input["id"].Value))
|
|
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.LogData));
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var key = string.Format("{0}/{1}", input["id"].Value, Duplicati.Library.Utility.Utility.ParseBool(input["remotelog"].Value, false) ? "remotelog" : "log");
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, request.Method, typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
|
|
|
|
}
|
2014-06-27 13:23:05 +02:00
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
}
|
2014-06-27 13:23:05 +02:00
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
private void LocateUriDb(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
|
|
|
|
var input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/dbpath", Library.Utility.Uri.UrlPathEncode(input["uri"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "GET", typeof(RESTMethods.RemoteOperation).Name.ToLowerInvariant(), key);
|
|
|
|
|
}
|
2014-06-27 13:23:05 +02:00
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
private void SearchBackupFiles(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
|
|
|
|
var input = request.Method.Equals("POST", StringComparison.InvariantCultureIgnoreCase) ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/files/{1}", input["id"].Value, input["filter"].Value);
|
2014-06-27 13:23:05 +02:00
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.DoProcess(request, response, session, request.Method, typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
}
|
2014-06-27 13:23:05 +02:00
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
private void GetFolderContents(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, request.Method, typeof(RESTMethods.Filesystem).Name.ToLowerInvariant(), Library.Utility.Uri.UrlPathEncode(request.QueryString["path"].Value));
|
|
|
|
|
}
|
2014-06-27 13:23:05 +02:00
|
|
|
|
|
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
private void GetBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
|
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Backup));
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
private void DeleteBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
2014-07-25 22:17:48 +02:00
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
request.Method = HttpServer.Method.Delete;
|
|
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Backup));
|
|
|
|
|
}
|
2014-07-25 22:17:48 +02:00
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
private class AddOrUpdateBackupData
|
|
|
|
|
{
|
|
|
|
|
public Database.Schedule Schedule {get; set;}
|
|
|
|
|
public Database.Backup Backup {get; set;}
|
|
|
|
|
}
|
2014-07-25 22:17:48 +02:00
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
private void UpdateBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
|
|
|
|
request.Method = HttpServer.Method.Put;
|
|
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Backup));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void AddBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
|
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Backups));
|
2014-08-06 11:23:23 +02:00
|
|
|
}
|
2014-07-25 22:17:48 +02:00
|
|
|
|
2014-08-06 11:23:23 +02:00
|
|
|
private void GetAcknowledgements(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Acknowledgements));
|
2014-07-25 22:17:48 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-09 22:40:11 +02:00
|
|
|
private void GetChangelog(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Changelog));
|
2014-07-09 22:40:11 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-27 13:23:05 +02:00
|
|
|
private void GetLicenseData(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-11-28 21:54:21 +01:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Licenses));
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RestoreFiles(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/restore", input["id"].Value);
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ListBackupSets(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/filesets", input["id"].Value);
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, request.Method, typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ListRemoteFolder(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/list", Library.Utility.Uri.UrlPathEncode(input["url"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, request.Method, typeof(RESTMethods.RemoteOperation).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
2015-07-30 14:31:27 +02:00
|
|
|
|
2014-07-15 17:10:44 +02:00
|
|
|
private void CreateRemoteFolder(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/create", Library.Utility.Uri.UrlPathEncode(input["url"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, request.Method, typeof(RESTMethods.RemoteOperation).Name.ToLowerInvariant(), key);
|
2014-07-15 17:10:44 +02:00
|
|
|
}
|
2014-06-27 13:23:05 +02:00
|
|
|
|
|
|
|
|
private void TestBackend(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/test", Library.Utility.Uri.UrlPathEncode(input["url"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, request.Method, typeof(RESTMethods.RemoteOperation).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ListSystemInfo(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-04 13:42:52 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.SystemInfo));
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ListSupportedActions(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2014-07-02 15:03:45 +02:00
|
|
|
bw.OutputOK(new { Version = 1, Methods = SUPPORTED_METHODS.Keys });
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ListBackups (HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-04 13:42:52 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Backups));
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ListTags(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Tags));
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ValidatePath(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/validate", Library.Utility.Uri.UrlPathEncode(input["path"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "GET", typeof(RESTMethods.Filesystem).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetProgressState(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-04 13:42:52 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.ProgressState));
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetCurrentState (HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-04 13:42:52 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.ServerState));
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
2015-07-30 14:31:27 +02:00
|
|
|
|
2014-06-27 13:23:05 +02:00
|
|
|
private void ListApplicationSettings(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-04 13:42:52 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.SystemWideSettings));
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-05 23:04:00 +02:00
|
|
|
private void DownloadBugReport(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.BugReport));
|
2014-08-05 23:04:00 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-07 21:05:44 +02:00
|
|
|
private void DeleteLocalData(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/deletedb", Library.Utility.Uri.UrlPathEncode(input["id"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2014-08-07 21:05:44 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-15 01:51:48 +02:00
|
|
|
private void GetServerOptions(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.ServerSettings));
|
2014-08-15 01:51:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetServerOptions(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
request.Method = "PATCH";
|
|
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.ServerSettings));
|
2014-08-15 01:51:48 +02:00
|
|
|
}
|
2015-04-08 21:02:01 +02:00
|
|
|
|
|
|
|
|
private void CopyBackupToTemporary(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/copytotemp", Library.Utility.Uri.UrlPathEncode(input["id"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2015-04-08 21:02:01 +02:00
|
|
|
}
|
2014-10-14 14:45:49 +02:00
|
|
|
|
2014-08-02 01:10:39 +02:00
|
|
|
private void ExportBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
var key = string.Format("{0}/export", Library.Utility.Uri.UrlPathEncode(input["id"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, request.Method, typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2014-08-02 01:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void ImportBackup(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Backups).Name.ToLowerInvariant(), "import");
|
2014-08-02 01:10:39 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-04 01:06:29 +02:00
|
|
|
private void GetNotifications(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Notifications));
|
2014-08-04 01:06:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DismissNotification(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
request.Method = "DELETE";
|
|
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.Notification));
|
2014-08-04 01:06:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetUISettings(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
request.Method = "GET";
|
|
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.UISettings));
|
2014-08-04 01:06:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetUISettings(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
request.Method = "POST";
|
|
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.UISettings));
|
2014-08-04 01:06:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetUISettingSchemes(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.UISettings));
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetBackupDefaults(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.HandleControlCGI(request, response, session, bw, typeof(RESTMethods.BackupDefaults));
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
|
2014-08-01 11:18:10 +02:00
|
|
|
private void PollLogMessages(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.DoProcess(request, response, session, "GET", typeof(RESTMethods.LogData).Name.ToLowerInvariant(), "poll");
|
2014-08-01 11:18:10 +02:00
|
|
|
}
|
|
|
|
|
|
2014-06-27 13:23:05 +02:00
|
|
|
private void SendCommand(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session, BodyWriter bw)
|
|
|
|
|
{
|
|
|
|
|
HttpServer.HttpInput input = request.Method.ToUpper() == "POST" ? request.Form : request.QueryString;
|
|
|
|
|
|
|
|
|
|
string command = input["command"].Value ?? "";
|
|
|
|
|
|
|
|
|
|
switch (command.ToLowerInvariant())
|
|
|
|
|
{
|
2014-06-30 11:31:06 +02:00
|
|
|
case "check-update":
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Updates).Name.ToLowerInvariant(), "check");
|
2014-06-30 11:31:06 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case "install-update":
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Updates).Name.ToLowerInvariant(), "install");
|
2014-06-30 11:31:06 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case "activate-update":
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Updates).Name.ToLowerInvariant(), "activate");
|
2014-06-30 11:31:06 +02:00
|
|
|
return;
|
|
|
|
|
|
2014-06-27 13:23:05 +02:00
|
|
|
case "pause":
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.ServerState).Name.ToLowerInvariant(), "pause");
|
2014-06-27 13:23:05 +02:00
|
|
|
return;
|
2015-07-30 14:31:27 +02:00
|
|
|
|
2014-06-27 13:23:05 +02:00
|
|
|
case "resume":
|
2015-07-30 14:31:27 +02:00
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.ServerState).Name.ToLowerInvariant(), "resume");
|
2014-06-27 13:23:05 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case "stop":
|
|
|
|
|
case "abort":
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var key = string.Format("{0}/{1}", input["taskid"].Value, command);
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Task).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
2015-07-30 14:31:27 +02:00
|
|
|
return;
|
2014-06-27 13:23:05 +02:00
|
|
|
|
|
|
|
|
case "is-backup-active":
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var key = string.Format("{0}/isactive", Library.Utility.Uri.UrlPathEncode(input["id"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "GET", typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
2015-07-30 14:31:27 +02:00
|
|
|
return;
|
2014-06-27 13:23:05 +02:00
|
|
|
|
|
|
|
|
case "run":
|
|
|
|
|
case "run-backup":
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var key = string.Format("{0}/start", Library.Utility.Uri.UrlPathEncode(input["id"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
case "run-verify":
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var key = string.Format("{0}/verify", Library.Utility.Uri.UrlPathEncode(input["id"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
2015-04-08 21:01:36 +02:00
|
|
|
case "run-repair-update":
|
2014-06-27 13:23:05 +02:00
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var key = string.Format("{0}/repairupdate", Library.Utility.Uri.UrlPathEncode(input["id"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2014-06-27 13:23:05 +02:00
|
|
|
|
2015-07-30 14:31:27 +02:00
|
|
|
case "run-repair":
|
|
|
|
|
{
|
|
|
|
|
var key = string.Format("{0}/repair", Library.Utility.Uri.UrlPathEncode(input["id"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
case "create-report":
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var key = string.Format("{0}/createreport", Library.Utility.Uri.UrlPathEncode(input["id"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.Backup).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
{
|
2015-07-30 14:31:27 +02:00
|
|
|
var key = string.Format("{0}", Library.Utility.Uri.UrlPathEncode(input["command"].Value));
|
|
|
|
|
RESTHandler.DoProcess(request, response, session, "POST", typeof(RESTMethods.WebModule).Name.ToLowerInvariant(), key);
|
2014-06-27 13:23:05 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|