From 20e01532de8836a941d9a180ee813a607490e087 Mon Sep 17 00:00:00 2001
From: Marius Cramer <m.cramer@pixcept.de>
Date: Fri, 10 Jan 2014 10:04:47 -0500
Subject: [PATCH] Merge branch 'master' of /home/git/repositories/florian030/ispconfig3

---
 interface/web/admin/lib/lang/de_server_config.lng           |    1 +
 server/plugins-available/apache2_plugin.inc.php             |    2 +-
 interface/web/admin/lib/lang/en_server_config.lng           |    1 +
 server/plugins-available/mail_plugin.inc.php                |    5 +++--
 install/tpl/server.ini.master                               |    1 +
 server/lib/classes/cron.d/500-backup_mail.inc.php           |   21 ++++++---------------
 server/lib/classes/cron.d/500-backup.inc.php                |    2 +-
 interface/web/admin/form/server_config.tform.php            |    6 ++++++
 interface/web/admin/templates/server_config_server_edit.htm |    6 ++++++
 9 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/install/tpl/server.ini.master b/install/tpl/server.ini.master
index b31d604..9186cc1 100644
--- a/install/tpl/server.ini.master
+++ b/install/tpl/server.ini.master
@@ -19,6 +19,7 @@
 backup_dir_is_mount=n
 backup_dir_mount_cmd=
 backup_mode=rootgz
+backup_delete=y
 monit_url=
 monit_user=
 monit_password=
diff --git a/interface/web/admin/form/server_config.tform.php b/interface/web/admin/form/server_config.tform.php
index cde19e4..dde1d74 100644
--- a/interface/web/admin/form/server_config.tform.php
+++ b/interface/web/admin/form/server_config.tform.php
@@ -195,6 +195,12 @@
 			'width' => '40',
 			'maxlength' => '255'
 		),
+		'backup_delete' => array(
+			'datatype' => 'VARCHAR',
+			'formtype' => 'CHECKBOX',
+			'default' => 'y',
+			'value' => array(0 => 'n', 1 => 'y')
+		),
 		'monit_url' => array(
 			'datatype' => 'VARCHAR',
 			'formtype' => 'TEXT',
diff --git a/interface/web/admin/lib/lang/de_server_config.lng b/interface/web/admin/lib/lang/de_server_config.lng
index 769da88..5f615cc 100644
--- a/interface/web/admin/lib/lang/de_server_config.lng
+++ b/interface/web/admin/lib/lang/de_server_config.lng
@@ -193,3 +193,4 @@
 $wb['munin_url_note_txt'] = 'Platzhalter:';
 $wb['backup_dir_is_mount_txt'] = 'Backupverzeichnis ist ein eigener Mount?';
 $wb['backup_dir_mount_cmd_txt'] = 'Mount-Befehl, falls Backupverzeichnis nicht gemountet';
+?>
diff --git a/interface/web/admin/lib/lang/en_server_config.lng b/interface/web/admin/lib/lang/en_server_config.lng
index 385ff9f..07e94af 100644
--- a/interface/web/admin/lib/lang/en_server_config.lng
+++ b/interface/web/admin/lib/lang/en_server_config.lng
@@ -196,4 +196,5 @@
 $wb["v6_prefix_length"] = 'Prefix too long according to defined IPv6 ';
 $wb['backup_dir_is_mount_txt'] = 'Backup directory is a mount?';
 $wb['backup_dir_mount_cmd_txt'] = 'Mount command, if backup directory not mounted';
+$wb['backup_delete_txt'] = 'Delete backups on domain/website delete';
 ?>
diff --git a/interface/web/admin/templates/server_config_server_edit.htm b/interface/web/admin/templates/server_config_server_edit.htm
index 7c0c7b7..e52a543 100644
--- a/interface/web/admin/templates/server_config_server_edit.htm
+++ b/interface/web/admin/templates/server_config_server_edit.htm
@@ -74,6 +74,12 @@
                     {tmpl_var name='backup_mode'}
                 </select>
             </div>
+            <div class="ctrlHolder">
+                <p class="label">{tmpl_var name='backup_delete_txt'}</p>
+                <div class="multiField">
+                    {tmpl_var name='backup_delete'}
+                </div>
+            </div>
 			<div class="ctrlHolder">
                 <label for="monit_url">{tmpl_var name='monit_url_txt'}</label>
                 <input name="monit_url" id="monit_url" value="{tmpl_var name='monit_url'}" size="40" maxlength="255" type="text" class="textInput" />&nbsp;{tmpl_var name='monit_url_note_txt'} <a href="javascript:void(0);" class="addPlaceholder">[SERVERNAME]</a>
diff --git a/server/lib/classes/cron.d/500-backup.inc.php b/server/lib/classes/cron.d/500-backup.inc.php
index df55239..23e7495 100644
--- a/server/lib/classes/cron.d/500-backup.inc.php
+++ b/server/lib/classes/cron.d/500-backup.inc.php
@@ -72,7 +72,7 @@
 				chmod(escapeshellcmd($backup_dir), $backup_dir_permissions);
 			}
 
-			$sql = "SELECT * FROM web_domain WHERE server_id = '".$conf['server_id']."' AND (type = 'vhost' OR type = 'vhostsubdomain')";
+			$sql = "SELECT * FROM web_domain WHERE server_id = '".$conf['server_id']."' AND (type = 'vhost' OR type = 'vhostsubdomain') AND active = 'y'";
 			$records = $app->db->queryAllRecords($sql);
 			if(is_array($records)) {
 				foreach($records as $rec) {
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 40addb2..fa1fa5c 100644
--- a/server/lib/classes/cron.d/500-backup_mail.inc.php
+++ b/server/lib/classes/cron.d/500-backup_mail.inc.php
@@ -56,7 +56,6 @@
 		$backup_dir_permissions =0750;
 
 		if($backup_dir != '') {
-/*
 			//* mount backup directory, if necessary
 			$run_backups = true;
 			$server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
@@ -67,7 +66,6 @@
 					if(!$app->system->is_mounted($backup_dir)) $run_backups = false;
 				}
 			}
-*/
 
 			$mail_config = $app->getconf->get_server_config($conf['server_id'], 'mail');
 			
@@ -77,18 +75,13 @@
 				chmod(escapeshellcmd($backup_dir), $backup_dir_permissions);
 			}
 
-			$sql = "SELECT * FROM mail_user WHERE server_id = '".$conf['server_id']."' AND maildir <> ''";
+			$sql="SELECT * FROM mail_user JOIN mail_domain ON (mail_domain.active='y' AND mail_user.email like concat('%',mail_domain.domain)) WHERE mail_user.server_id=".$conf['server_id']." AND maildir <> '' ORDER BY mail_domain.domain_id";
 			$records = $app->db->queryAllRecords($sql);
-/*
 			if(is_array($records) && $run_backups) {
-*/
-			if(is_array($records)) {
 				foreach($records as $rec) {
 					//* Do the mailbox backup
 					if($rec['backup_interval'] == 'daily' or ($rec['backup_interval'] == 'weekly' && date('w') == 0) or ($rec['backup_interval'] == 'monthly' && date('d') == '01')) {
-						$sql="SELECT * FROM mail_domain WHERE domain = '".$app->db->quote(explode("@",$rec['email'])[1])."'";
-						$domain_rec=$app->db->queryOneRecord($sql);
-						$mail_backup_dir = $backup_dir.'/mail'.$domain_rec['domain_id'];
+						$mail_backup_dir = $backup_dir.'/mail'.$rec['domain_id'];
 
 						if(!is_dir($mail_backup_dir)) mkdir($mail_backup_dir, 0750);
 						chmod($mail_backup_dir, $backup_dir_permissions);
@@ -113,7 +106,7 @@
 							chgrp($mail_backup_dir.'/'.$mail_backup_file, 'root');
 							chmod($mail_backup_dir.'/'.$mail_backup_file, 0640);
 							/* Insert mail backup record in database */
-							$sql = "INSERT INTO mail_backup (server_id,parent_domain_id,mailuser_id,backup_mode,tstamp,filename,filesize) VALUES (".$conf['server_id'].",".$domain_rec['domain_id'].",".$rec['mailuser_id'].",'".$backup_mode."',".time().",'".$app->db->quote($mail_backup_file)."','".$app->functions->formatBytes(filesize($mail_backup_dir.'/'.$mail_backup_file))."')";
+							$sql = "INSERT INTO mail_backup (server_id,parent_domain_id,mailuser_id,backup_mode,tstamp,filename,filesize) VALUES (".$conf['server_id'].",".$rec['domain_id'].",".$rec['mailuser_id'].",'".$backup_mode."',".time().",'".$app->db->quote($mail_backup_file)."','".$app->functions->formatBytes(filesize($mail_backup_dir.'/'.$mail_backup_file))."')";
 							$app->db->query($sql);	
 							if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql);
 						} else {
@@ -135,7 +128,7 @@
 						for ($n = $backup_copies; $n <= 10; $n++) {
 							if(isset($files[$n]) && is_file($mail_backup_dir.'/'.$files[$n])) {
 								unlink($mail_backup_dir.'/'.$files[$n]);
-								$sql = "DELETE FROM mail_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = ".$domain_rec['domain_id']." AND filename = '".$app->db->quote($files[$n])."'";
+								$sql = "DELETE FROM mail_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = ".$rec['domain_id']." AND filename = '".$app->db->quote($files[$n])."'";
 								$app->db->query($sql);
 								if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql);
 							}
@@ -145,14 +138,12 @@
 					}
 					/* Remove inactive backups */
 					if($rec['backup_interval'] == 'none') {
-						$sql="SELECT * FROM mail_domain WHERE domain = '".$app->db->quote(explode("@",$rec['email'])[1])."'";
-						$domain_rec=$app->db->queryOneRecord($sql);
 						/* remove backups from db */
-						$sql = "DELETE FROM mail_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = ".$domain_rec['domain_id']." AND mailuser_id = ".$rec['mailuser_id'];
+						$sql = "DELETE FROM mail_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = ".$rec['domain_id']." AND mailuser_id = ".$rec['mailuser_id'];
 						$app->db->query($sql);
 						if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql);
 						/* remove archives */
-						$mail_backup_dir = $backup_dir.'/mail'.$domain_rec['domain_id'];	
+						$mail_backup_dir = $backup_dir.'/mail'.$rec['domain_id'];	
 						$mail_backup_file = 'mail'.$rec['mailuser_id'].'_*';
 						if(is_dir($mail_backup_dir)) {
 							foreach (glob($mail_backup_dir.'/'.$mail_backup_file) as $filename) {
diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php
index 499f23e..5fc085b 100644
--- a/server/plugins-available/apache2_plugin.inc.php
+++ b/server/plugins-available/apache2_plugin.inc.php
@@ -1991,7 +1991,7 @@
 				//* mount backup directory, if necessary
 				$mount_backup = true;
 				$server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
-				if($server_config['backup_dir'] != '') {
+				if($server_config['backup_dir'] != '' && $server_config['backup_delete'] == 'y') {
 					if($server_config['backup_dir_is_mount'] == 'y' && $server_config['backup_dir_mount_cmd'] != ''){
 						if(!$app->system->is_mounted($backup_dir)){
 							exec(escapeshellcmd($server_config['backup_dir_mount_cmd']));
diff --git a/server/plugins-available/mail_plugin.inc.php b/server/plugins-available/mail_plugin.inc.php
index 378c4ad..4a308da 100644
--- a/server/plugins-available/mail_plugin.inc.php
+++ b/server/plugins-available/mail_plugin.inc.php
@@ -326,13 +326,14 @@
 		} else {
 			$app->log('Possible security violation when deleting the maildir: '.$data['old']['maildir'], LOGLEVEL_ERROR);
 		}
+
 		//* Delete the mail-backups
 		$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
 		$backup_dir = $server_config['backup_dir'];
 		//* mount backup directory, if necessary
 		$mount_backup = true;
 		$server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
-		if($server_config['backup_dir'] != '' && $maildir_path_deleted) {
+		if($server_config['backup_dir'] != '' && $maildir_path_deleted && $server_config['backup_delete'] == 'y') {
 			if($server_config['backup_dir_is_mount'] == 'y' && $server_config['backup_dir_mount_cmd'] != ''){
 				if(!$app->system->is_mounted($backup_dir)){
 					exec(escapeshellcmd($server_config['backup_dir_mount_cmd']));
@@ -391,7 +392,7 @@
 		//* mount backup directory, if necessary
 		$mount_backup = true;
 		$server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
-		if($server_config['backup_dir'] != '' && $maildomain_path_deleted) {
+		if($server_config['backup_dir'] != '' && $maildomain_path_deleted && $server_config['backup_delete'] == 'y'){
 			if($server_config['backup_dir_is_mount'] == 'y' && $server_config['backup_dir_mount_cmd'] != ''){
 				if(!$app->system->is_mounted($backup_dir)){
 					exec(escapeshellcmd($server_config['backup_dir_mount_cmd']));

--
Gitblit v1.9.1