From 5f0a37ff3bc666e581d3fbfe0f837684fb87818e Mon Sep 17 00:00:00 2001
From: Dominik <info@profi-webdesign.net>
Date: Mon, 24 Mar 2014 20:04:29 +0100
Subject: [PATCH] added backup-functions to Remote-API (FS#2832)

---
 interface/lib/classes/remote.d/sites.inc.php  | 60 ++++++++++++++++++-
 interface/web/sites/lib/remote.conf.php       |  1 +
 remoting_client/API-docs/navigation.html      |  2 +
 .../API-docs/sites_web_domain_backup.html     | 26 ++++++++
 .../sites_web_domain_backup_list.html         | 26 ++++++++
 5 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 remoting_client/API-docs/sites_web_domain_backup.html
 create mode 100644 remoting_client/API-docs/sites_web_domain_backup_list.html

diff --git a/interface/lib/classes/remote.d/sites.inc.php b/interface/lib/classes/remote.d/sites.inc.php
index 2574ee8a4c..98c5bf6328 100644
--- a/interface/lib/classes/remote.d/sites.inc.php
+++ b/interface/lib/classes/remote.d/sites.inc.php
@@ -893,7 +893,65 @@ class remoting_sites extends remoting {
 		$all = $app->db->queryAllRecords($sql);
 		return $all;
 	}
-
+	
+	//** backup functions -----------------------------------------------------------------------------------
+	public function sites_web_domain_backup_list($session_id, $site_id = null)
+	{
+		global $app;
+	
+		if(!$this->checkPerm($session_id, 'sites_web_domain_backup')) {
+			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
+			return false;
+		}
+		
+		$result = $app->db->queryAllRecords("SELECT * FROM web_backup".(($site_id != null)?' WHERE parent_domain_id = ?':''), $app->functions->intval($site_id));
+		return $result;
+	}
+	
+	//* Backup download and restoration by Abdi Joseph
+	public function sites_web_domain_backup($session_id, $primary_id, $action_type)
+	{
+		global $app;
+	
+		if(!$this->checkPerm($session_id, 'sites_web_domain_backup')) {
+			$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
+			return false;
+		}
+	
+		//*Set variables
+		$backup_record = $app->db->queryOneRecord("SELECT * FROM `web_backup` WHERE `backup_id`= ?", $primary_id);
+		$server_id = $backup_record['server_id'];
+	
+		//*Set default action state
+		$action_state = "pending";
+		$tstamp = time();
+	
+		//* Basic validation of variables
+		if ($server_id <= 0) {
+			$this->server->fault('invalid_backup_id', "Invalid or non existant backup_id $primary_id");
+			return false;
+		}
+	
+		if ($action_type != 'backup_download' and $action_type != 'backup_restore') {
+			$this->server->fault('invalid_action', "Invalid action_type $action_type");
+			return false;
+		}
+	
+		//* Validate instance
+		$instance_record = $app->db->queryOneRecord("SELECT * FROM `sys_remoteaction` WHERE `action_param`= ? and `action_type`= ? and `action_state`= ?", $primary_id, $action_type, 'pending');
+		if ($instance_record['action_id'] >= 1) {
+			$this->server->fault('duplicate_action', "There is already a pending $action_type action");
+			return false;
+		}
+	
+		//* Save the record
+		if ($app->db->query("INSERT INTO `sys_remoteaction` SET `server_id` = ?, `tstamp` = ?, `action_type` = ?, `action_param` = ?, `action_state` = ?", $server_id, $tstamp, $action_type, $primary_id, $action_state)) {
+			return true;
+		} else {
+			return false;
+		}
+	}
+	
 	//** quota functions -----------------------------------------------------------------------------------
 	public function quota_get_by_user($session_id, $client_id)
 	{
diff --git a/interface/web/sites/lib/remote.conf.php b/interface/web/sites/lib/remote.conf.php
index 10a4640137..30e41b9292 100644
--- a/interface/web/sites/lib/remote.conf.php
+++ b/interface/web/sites/lib/remote.conf.php
@@ -5,6 +5,7 @@ $function_list['sites_web_folder_get,sites_web_folder_add,sites_web_folder_updat
 $function_list['sites_ftp_user_get,sites_ftp_user_server_get,sites_ftp_user_add,sites_ftp_user_update,sites_ftp_user_delete'] = 'Sites FTP-User functions';
 $function_list['sites_shell_user_get,sites_shell_user_add,sites_shell_user_update,sites_shell_user_delete'] = 'Sites Shell-User functions';
 $function_list['sites_web_domain_get,sites_web_domain_add,sites_web_domain_update,sites_web_domain_delete,sites_web_domain_set_status'] = 'Sites Domain functions';
+$function_list['sites_web_domain_backup'] = 'Sites Backup functions';
 $function_list['sites_web_aliasdomain_get,sites_web_aliasdomain_add,sites_web_aliasdomain_update,sites_web_aliasdomain_delete'] = 'Sites Aliasdomain functions';
 $function_list['sites_web_subdomain_get,sites_web_subdomain_add,sites_web_subdomain_update,sites_web_subdomain_delete'] = 'Sites Subdomain functions';
 
diff --git a/remoting_client/API-docs/navigation.html b/remoting_client/API-docs/navigation.html
index 27f9f244ef..e0eebb000e 100644
--- a/remoting_client/API-docs/navigation.html
+++ b/remoting_client/API-docs/navigation.html
@@ -226,6 +226,8 @@
 <p><a href="sites_web_domain_get.html" target="content">sites_web_domain_get</a></p>
 <p><a href="sites_web_domain_set_status.html" target="content">sites_web_domain_set_status</a></p>
 <p><a href="sites_web_domain_update.html" target="content">sites_web_domain_update</a></p>
+ p><a href="sites_web_domain_backup_list.html" target="content">sites_web_domain_backup_list</a></p>
+<p><a href="sites_web_domain_backup.html" target="content">sites_web_domain_backup</a></p>
 <p><a href="sites_web_subdomain_add.html" target="content">sites_web_subdomain_add</a></p>
 <p><a href="sites_web_subdomain_delete.html" target="content">sites_web_subdomain_delete</a></p>
 <p><a href="sites_web_subdomain_get.html" target="content">sites_web_subdomain_get</a></p>
diff --git a/remoting_client/API-docs/sites_web_domain_backup.html b/remoting_client/API-docs/sites_web_domain_backup.html
new file mode 100644
index 0000000000..96ddba6964
--- /dev/null
+++ b/remoting_client/API-docs/sites_web_domain_backup.html
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html><head><title>ISCPConfig 3 API Functions</title>
+
+  
+
+  
+  
+  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+  <link rel="stylesheet" type="text/css" href="definitionen.css">
+  <style type="text/css">
+  </style></head>
+
+<body>
+<div style="padding:40px">
+<h1>sites_web_domain_backup(<span class="var">$session_id</span>, <span class="var">$primary_id</span>, <span class="var">$action_type</span>);</h1>
+<br>
+<p class="headgrp">Description: </p>
+<p class="margin"> Adds a new backup / restore task. Please note: <em>$action_type</em> is either <em>backup_download</em> or <em>backup_restore</em></p>
+<br>
+<p class="headgrp">Input Variables: </p> 
+<p class="margin"> <span class="var">$session_id</span>, <span class="var">$primary_id</span>, <span class="var">$action_type</span></p>
+<p class="headgrp">Output: </p> 
+<p class="margin"> Returns <em>TRUE</em> if successfull or <em>FALSE</em> if failure.</p>
+</div>
+
+</body></html>
diff --git a/remoting_client/API-docs/sites_web_domain_backup_list.html b/remoting_client/API-docs/sites_web_domain_backup_list.html
new file mode 100644
index 0000000000..7498900d81
--- /dev/null
+++ b/remoting_client/API-docs/sites_web_domain_backup_list.html
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html><head><title>ISCPConfig 3 API Functions</title>
+
+  
+
+  
+  
+  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+  <link rel="stylesheet" type="text/css" href="definitionen.css">
+  <style type="text/css">
+  </style></head>
+
+<body>
+<div style="padding:40px">
+<h1>sites_web_domain_backup_list(<span class="var">$session_id</span>, <span class="var">$site_id</span>);</h1>
+<br>
+<p class="headgrp">Description: </p>
+<p class="margin"> Gets list of all available backups. If no $site_id given, all backups available on this server are read.</p>
+<br>
+<p class="headgrp">Input Variables: </p> 
+<p class="margin"> <span class="var">$session_id</span>, <span class="var">$site_id</span></p>
+<p class="headgrp">Output: </p> 
+<p class="margin"> Returns array of all available backups.</p>
+</div>
+
+</body></html>
-- 
GitLab