diff --git a/interface/lib/classes/remote.d/mail.inc.php b/interface/lib/classes/remote.d/mail.inc.php index e579fb67ff7dec16757f6547bb2b815443c19926..29ff0d83b5cc80e13e00655aad3e888c0163d0ae 100644 --- a/interface/lib/classes/remote.d/mail.inc.php +++ b/interface/lib/classes/remote.d/mail.inc.php @@ -309,6 +309,71 @@ class remoting_mail extends remoting { // $app->plugin->raiseEvent('mail:mail_user_filter:on_after_delete',$this); return $affected_rows; } + + // Mail backup list function by Dominik Müller, info@profi-webdesign.net + public function mail_user_backup_list($session_id, $primary_id = null) + { + global $app; + + if(!$this->checkPerm($session_id, 'mail_user_backup')) { + $this->server->fault('permission_denied', 'You do not have the permissions to access this function.'); + return false; + } + + if ($site_id != null) { + $sql = "SELECT * FROM mail_backup WHERE parent_domain_id = ".$app->functions->intval($site_id); + } + else { + $sql = "SELECT * FROM mail_backup"; + } + + $result = $app->db->queryAllRecords($sql); + return $result; + } + + // Mail backup restore/download functions by Dominik Müller, info@profi-webdesign.net + public function mail_user_backup($session_id, $primary_id, $action_type) + { + global $app; + + if(!$this->checkPerm($session_id, 'mail_user_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 `mail_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_mail' and*/ $action_type != 'backup_restore_mail') { + $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`='$primary_id' and `action_type`='$action_type' and `action_state`='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` = '$server_id', `tstamp` = '$tstamp', `action_type` = '$action_type', `action_param` = '$primary_id', `action_state` = '$action_state'")) { + return true; + } else { + return false; + } + } //* Get alias details public function mail_alias_get($session_id, $primary_id) diff --git a/interface/web/mail/lib/remote.conf.php b/interface/web/mail/lib/remote.conf.php index 5ddec4edcc6589e3e828a540d7b02072754d2caa..ae03e9992aa99374c163fe0e2876189e8b9644ec 100644 --- a/interface/web/mail/lib/remote.conf.php +++ b/interface/web/mail/lib/remote.conf.php @@ -17,6 +17,7 @@ $function_list['mail_fetchmail_get,mail_fetchmail_add,mail_fetchmail_update,mail $function_list['mail_spamfilter_whitelist_get,mail_spamfilter_whitelist_add,mail_spamfilter_whitelist_update,mail_spamfilter_whitelist_delete'] = 'Mail spamfilter whitelist functions'; $function_list['mail_spamfilter_blacklist_get,mail_spamfilter_blacklist_add,mail_spamfilter_blacklist_update,mail_spamfilter_blacklist_delete'] = 'Mail spamfilter blacklist functions'; $function_list['mail_user_filter_get,mail_user_filter_add,mail_user_filter_update,mail_user_filter_delete'] = 'Mail user filter functions'; +$function_list['mail_user_backup'] = 'Mail Backup functions'; $function_list['mail_filter_get,mail_filter_add,mail_filter_update,mail_filter_delete'] = 'Mail filter functions'; diff --git a/remoting_client/API-docs/mail_user_backup.html b/remoting_client/API-docs/mail_user_backup.html new file mode 100644 index 0000000000000000000000000000000000000000..896ed9219097e5687964c1ad72c2b6bfcb3051af --- /dev/null +++ b/remoting_client/API-docs/mail_user_backup.html @@ -0,0 +1,26 @@ + +ISCPConfig 3 API Functions + + + + + + + + + + +
+

mail_user_backup($session_id, $primary_id, $action_type);

+
+

Description:

+

Adds a new backup / restore task. Please note: $action_type must be backup_restore_mail

+
+

Input Variables:

+

$session_id, $primary_id, $action_type

+

Output:

+

Returns TRUE if successfull or FALSE if failure.

+
+ + diff --git a/remoting_client/API-docs/mail_user_backup_list.html b/remoting_client/API-docs/mail_user_backup_list.html new file mode 100644 index 0000000000000000000000000000000000000000..9ad9db8806060d6bb1ff470a3be754e5fe79ab18 --- /dev/null +++ b/remoting_client/API-docs/mail_user_backup_list.html @@ -0,0 +1,26 @@ + +ISCPConfig 3 API Functions + + + + + + + + + + +
+

mail_user_backup_list($session_id, $primary_id);

+
+

Description:

+

Gets list of all available mail backups. If no $primary_id (mail-domain-id) is given, all mail backups available on this server are read.

+
+

Input Variables:

+

$session_id, $primary_id (mail-domain-id)

+

Output:

+

Returns array of all available backups.

+
+ + diff --git a/remoting_client/API-docs/navigation.html b/remoting_client/API-docs/navigation.html index 6829df5ca897bec72fb5fd5d0bcf084517953088..917c6ba44581454c96d50cd3830c1561cc5996a3 100644 --- a/remoting_client/API-docs/navigation.html +++ b/remoting_client/API-docs/navigation.html @@ -169,6 +169,8 @@

mail_user_filter_delete

mail_user_filter_get

mail_user_filter_update

+

mail_user_backup_list

+

mail_user_backup

mail_whitelist_add

mail_whitelist_delete

mail_whitelist_get

diff --git a/server/lib/classes/cron.d/500-backup_mail.inc.php b/server/lib/classes/cron.d/500-backup_mail.inc.php index 66006fd6e862c843a4e7f4e0685b0a0d0bfdb73f..55f769056cf89b139134d00c4623018a2e320689 100644 --- a/server/lib/classes/cron.d/500-backup_mail.inc.php +++ b/server/lib/classes/cron.d/500-backup_mail.inc.php @@ -80,10 +80,33 @@ class cronjob_backup_mail extends cronjob { $domain = $temp[1]; unset($temp);; $domain_rec=$app->db->queryOneRecord("SELECT * FROM mail_domain WHERE domain = ?", $domain); + + $backupusername = 'root'; + $backupgroup = 'root'; + if ($global_config['backups_include_into_web_quota'] == 'y') { + // this only works, if mail and webdomains are on the same server + // find webdomain fitting to maildomain + $sql = "SELECT * FROM web_domain WHERE domain = '".$domain_rec['domain']."'"; + $webdomain = $app->db->queryOneRecord($sql); + // if this is not also the website, find website now + if ($webdomain && ($webdomain['parent_domain_id'] != 0)) { + do { + $sql = "SELECT * FROM web_domain WHERE domain_id = ".$webdomain['parent_domain_id']; + $webdomain = $app->db->queryOneRecord($sql); + } while ($webdomain && ($webdomain['parent_domain_id'] != 0)); + } + // if webdomain is found, change username/group now + if ($webdomain) { + $backupusername = $webdomain['system_user']; + $backupgroup = $webdomain['system_group']; + } + } $mail_backup_dir = $backup_dir.'/mail'.$domain_rec['domain_id']; if(!is_dir($mail_backup_dir)) mkdir($mail_backup_dir, 0750); chmod($mail_backup_dir, $backup_dir_permissions); + chown($mail_backup_dir, $backupusername); + chgrp($mail_backup_dir, $backupgroup); $mail_backup_file = 'mail'.$rec['mailuser_id'].'_'.date('Y-m-d_H-i'); @@ -98,33 +121,13 @@ class cronjob_backup_mail extends cronjob { //* create archives if($backup_mode == 'userzip') { $mail_backup_file.='.zip'; - exec('cd '.$domain_dir.' && zip '.$mail_backup_dir.'/'.$mail_backup_file.' -b /tmp -r '.$source_dir.' > /dev/nul', $tmp_output, $retval); + exec('cd '.$domain_dir.' && zip '.$mail_backup_dir.'/'.$mail_backup_file.' -b /tmp -r '.$source_dir.' > /dev/null', $tmp_output, $retval); } else { /* Create a tar.gz backup */ $mail_backup_file.='.tar.gz'; exec(escapeshellcmd('tar pczf '.$mail_backup_dir.'/'.$mail_backup_file.' --directory '.$domain_dir.' '.$source_dir), $tmp_output, $retval); } if($retval == 0){ - $backupusername = 'root'; - $backupgroup = 'root'; - if ($global_config['backups_include_into_web_quota'] == 'y') { - // this only works, if mail and webdomains are on the same server - // find webdomain fitting to maildomain - $sql = "SELECT * FROM web_domain WHERE domain = ".$domain_rec['domain']; - $webdomain = $app->db->queryOneRecord($sql); - // if this is not also the website, find website now - if ($webdomain && ($webdomain['parent_domain_id'] != 0)) { - do { - $sql = "SELECT * FROM web_domain WHERE domain_id = ".$domain_rec['parent_domain_id']; - $webdomain = $app->db->queryOneRecord($sql); - } while ($webdomain && ($webdomain['parent_domain_id'] != 0)); - } - // if webdomain is found, change username/group now - if ($webdomain) { - $backupusername = $webdomain['system_user']; - $backupgroup = $webdomain['system_group']; - } - } chown($mail_backup_dir.'/'.$mail_backup_file, $backupusername); chgrp($mail_backup_dir.'/'.$mail_backup_file, $backupgroup); chmod($mail_backup_dir.'/'.$mail_backup_file, 0640);