Skip to content

Commit 370c6af

Browse files
author
Dominik
committed
Added Mail-Backup remote-functions
Fixed error in Mail-Backup-Cron-Task (created file /dev/nul - missing l)
1 parent b516281 commit 370c6af

File tree

6 files changed

+144
-21
lines changed

6 files changed

+144
-21
lines changed

interface/lib/classes/remote.d/mail.inc.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,71 @@ public function mail_user_filter_delete($session_id, $primary_id)
309309
// $app->plugin->raiseEvent('mail:mail_user_filter:on_after_delete',$this);
310310
return $affected_rows;
311311
}
312+
313+
// Mail backup list function by Dominik Müller, info@profi-webdesign.net
314+
public function mail_user_backup_list($session_id, $primary_id = null)
315+
{
316+
global $app;
317+
318+
if(!$this->checkPerm($session_id, 'mail_user_backup')) {
319+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
320+
return false;
321+
}
322+
323+
if ($site_id != null) {
324+
$sql = "SELECT * FROM mail_backup WHERE parent_domain_id = ".$app->functions->intval($site_id);
325+
}
326+
else {
327+
$sql = "SELECT * FROM mail_backup";
328+
}
329+
330+
$result = $app->db->queryAllRecords($sql);
331+
return $result;
332+
}
333+
334+
// Mail backup restore/download functions by Dominik Müller, info@profi-webdesign.net
335+
public function mail_user_backup($session_id, $primary_id, $action_type)
336+
{
337+
global $app;
338+
339+
if(!$this->checkPerm($session_id, 'mail_user_backup')) {
340+
$this->server->fault('permission_denied', 'You do not have the permissions to access this function.');
341+
return false;
342+
}
343+
344+
//*Set variables
345+
$backup_record = $app->db->queryOneRecord("SELECT * FROM `mail_backup` WHERE `backup_id`='$primary_id'");
346+
$server_id = $backup_record['server_id'];
347+
348+
//*Set default action state
349+
$action_state = "pending";
350+
$tstamp = time();
351+
352+
//* Basic validation of variables
353+
if ($server_id <= 0) {
354+
$this->server->fault('invalid_backup_id', "Invalid or non existant backup_id $primary_id");
355+
return false;
356+
}
357+
358+
if (/*$action_type != 'backup_download_mail' and*/ $action_type != 'backup_restore_mail') {
359+
$this->server->fault('invalid_action', "Invalid action_type $action_type");
360+
return false;
361+
}
362+
363+
//* Validate instance
364+
$instance_record = $app->db->queryOneRecord("SELECT * FROM `sys_remoteaction` WHERE `action_param`='$primary_id' and `action_type`='$action_type' and `action_state`='pending'");
365+
if ($instance_record['action_id'] >= 1) {
366+
$this->server->fault('duplicate_action', "There is already a pending $action_type action");
367+
return false;
368+
}
369+
370+
//* Save the record
371+
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'")) {
372+
return true;
373+
} else {
374+
return false;
375+
}
376+
}
312377

313378
//* Get alias details
314379
public function mail_alias_get($session_id, $primary_id)

interface/web/mail/lib/remote.conf.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
$function_list['mail_spamfilter_whitelist_get,mail_spamfilter_whitelist_add,mail_spamfilter_whitelist_update,mail_spamfilter_whitelist_delete'] = 'Mail spamfilter whitelist functions';
1818
$function_list['mail_spamfilter_blacklist_get,mail_spamfilter_blacklist_add,mail_spamfilter_blacklist_update,mail_spamfilter_blacklist_delete'] = 'Mail spamfilter blacklist functions';
1919
$function_list['mail_user_filter_get,mail_user_filter_add,mail_user_filter_update,mail_user_filter_delete'] = 'Mail user filter functions';
20+
$function_list['mail_user_backup'] = 'Mail Backup functions';
2021
$function_list['mail_filter_get,mail_filter_add,mail_filter_update,mail_filter_delete'] = 'Mail filter functions';
2122

2223

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<html><head><title>ISCPConfig 3 API Functions</title>
3+
4+
5+
6+
7+
8+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
9+
<link rel="stylesheet" type="text/css" href="definitionen.css">
10+
<style type="text/css">
11+
</style></head>
12+
13+
<body>
14+
<div style="padding:40px">
15+
<h1>mail_user_backup(<span class="var">$session_id</span>, <span class="var">$primary_id</span>, <span class="var">$action_type</span>);</h1>
16+
<br>
17+
<p class="headgrp">Description: </p>
18+
<p class="margin"> Adds a new backup / restore task. Please note: <em>$action_type</em> <!-- is either <em>backup_download_mail</em> or --> must be <em>backup_restore_mail</em></p>
19+
<br>
20+
<p class="headgrp">Input Variables: </p>
21+
<p class="margin"> <span class="var">$session_id</span>, <span class="var">$primary_id</span>, <span class="var">$action_type</span></p>
22+
<p class="headgrp">Output: </p>
23+
<p class="margin"> Returns <em>TRUE</em> if successfull or <em>FALSE</em> if failure.</p>
24+
</div>
25+
26+
</body></html>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2+
<html><head><title>ISCPConfig 3 API Functions</title>
3+
4+
5+
6+
7+
8+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
9+
<link rel="stylesheet" type="text/css" href="definitionen.css">
10+
<style type="text/css">
11+
</style></head>
12+
13+
<body>
14+
<div style="padding:40px">
15+
<h1>mail_user_backup_list(<span class="var">$session_id</span>, <span class="var">$primary_id</span>);</h1>
16+
<br>
17+
<p class="headgrp">Description: </p>
18+
<p class="margin"> 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.</p>
19+
<br>
20+
<p class="headgrp">Input Variables: </p>
21+
<p class="margin"> <span class="var">$session_id</span>, <span class="var">$primary_id (mail-domain-id)</span></p>
22+
<p class="headgrp">Output: </p>
23+
<p class="margin"> Returns array of all available backups.</p>
24+
</div>
25+
26+
</body></html>

remoting_client/API-docs/navigation.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ <h3>M</h3>
169169
<p><a href="mail_user_filter_delete.html" target="content">mail_user_filter_delete</a></p>
170170
<p><a href="mail_user_filter_get.html" target="content">mail_user_filter_get</a></p>
171171
<p><a href="mail_user_filter_update.html" target="content">mail_user_filter_update</a></p>
172+
<p><a href="mail_user_backup_list.html" target="content">mail_user_backup_list</a></p>
173+
<p><a href="mail_user_backup.html" target="content">mail_user_backup</a></p>
172174
<p><a href="mail_whitelist_add.html" target="content">mail_whitelist_add</a></p>
173175
<p><a href="mail_whitelist_delete.html" target="content">mail_whitelist_delete</a></p>
174176
<p><a href="mail_whitelist_get.html" target="content">mail_whitelist_get</a></p>

server/lib/classes/cron.d/500-backup_mail.inc.php

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,33 @@ public function onRunJob() {
8080
$domain = $temp[1];
8181
unset($temp);;
8282
$domain_rec=$app->db->queryOneRecord("SELECT * FROM mail_domain WHERE domain = ?", $domain);
83+
84+
$backupusername = 'root';
85+
$backupgroup = 'root';
86+
if ($global_config['backups_include_into_web_quota'] == 'y') {
87+
// this only works, if mail and webdomains are on the same server
88+
// find webdomain fitting to maildomain
89+
$sql = "SELECT * FROM web_domain WHERE domain = '".$domain_rec['domain']."'";
90+
$webdomain = $app->db->queryOneRecord($sql);
91+
// if this is not also the website, find website now
92+
if ($webdomain && ($webdomain['parent_domain_id'] != 0)) {
93+
do {
94+
$sql = "SELECT * FROM web_domain WHERE domain_id = ".$webdomain['parent_domain_id'];
95+
$webdomain = $app->db->queryOneRecord($sql);
96+
} while ($webdomain && ($webdomain['parent_domain_id'] != 0));
97+
}
98+
// if webdomain is found, change username/group now
99+
if ($webdomain) {
100+
$backupusername = $webdomain['system_user'];
101+
$backupgroup = $webdomain['system_group'];
102+
}
103+
}
83104

84105
$mail_backup_dir = $backup_dir.'/mail'.$domain_rec['domain_id'];
85106
if(!is_dir($mail_backup_dir)) mkdir($mail_backup_dir, 0750);
86107
chmod($mail_backup_dir, $backup_dir_permissions);
108+
chown($mail_backup_dir, $backupusername);
109+
chgrp($mail_backup_dir, $backupgroup);
87110

88111
$mail_backup_file = 'mail'.$rec['mailuser_id'].'_'.date('Y-m-d_H-i');
89112

@@ -98,33 +121,13 @@ public function onRunJob() {
98121
//* create archives
99122
if($backup_mode == 'userzip') {
100123
$mail_backup_file.='.zip';
101-
exec('cd '.$domain_dir.' && zip '.$mail_backup_dir.'/'.$mail_backup_file.' -b /tmp -r '.$source_dir.' > /dev/nul', $tmp_output, $retval);
124+
exec('cd '.$domain_dir.' && zip '.$mail_backup_dir.'/'.$mail_backup_file.' -b /tmp -r '.$source_dir.' > /dev/null', $tmp_output, $retval);
102125
} else {
103126
/* Create a tar.gz backup */
104127
$mail_backup_file.='.tar.gz';
105128
exec(escapeshellcmd('tar pczf '.$mail_backup_dir.'/'.$mail_backup_file.' --directory '.$domain_dir.' '.$source_dir), $tmp_output, $retval);
106129
}
107130
if($retval == 0){
108-
$backupusername = 'root';
109-
$backupgroup = 'root';
110-
if ($global_config['backups_include_into_web_quota'] == 'y') {
111-
// this only works, if mail and webdomains are on the same server
112-
// find webdomain fitting to maildomain
113-
$sql = "SELECT * FROM web_domain WHERE domain = ".$domain_rec['domain'];
114-
$webdomain = $app->db->queryOneRecord($sql);
115-
// if this is not also the website, find website now
116-
if ($webdomain && ($webdomain['parent_domain_id'] != 0)) {
117-
do {
118-
$sql = "SELECT * FROM web_domain WHERE domain_id = ".$domain_rec['parent_domain_id'];
119-
$webdomain = $app->db->queryOneRecord($sql);
120-
} while ($webdomain && ($webdomain['parent_domain_id'] != 0));
121-
}
122-
// if webdomain is found, change username/group now
123-
if ($webdomain) {
124-
$backupusername = $webdomain['system_user'];
125-
$backupgroup = $webdomain['system_group'];
126-
}
127-
}
128131
chown($mail_backup_dir.'/'.$mail_backup_file, $backupusername);
129132
chgrp($mail_backup_dir.'/'.$mail_backup_file, $backupgroup);
130133
chmod($mail_backup_dir.'/'.$mail_backup_file, 0640);

0 commit comments

Comments
 (0)