From 37b29231e47a0c4458dc1c15d98588f16f07e1e2 Mon Sep 17 00:00:00 2001
From: Marius Cramer <m.cramer@pixcept.de>
Date: Thu, 06 Aug 2015 03:18:44 -0400
Subject: [PATCH] - don't set password via remoting if field is empty

---
 server/lib/classes/cron.d/500-backup.inc.php |   40 +++++++++++++++++++++++++++++-----------
 1 files changed, 29 insertions(+), 11 deletions(-)

diff --git a/server/lib/classes/cron.d/500-backup.inc.php b/server/lib/classes/cron.d/500-backup.inc.php
index 87321d5..e196cb5 100644
--- a/server/lib/classes/cron.d/500-backup.inc.php
+++ b/server/lib/classes/cron.d/500-backup.inc.php
@@ -192,11 +192,16 @@
 							$web_user = $rec['system_user'];
 							$web_backup_dir = realpath($backup_dir.'/web'.$web_id);
 							if(is_dir($web_backup_dir)) {
-								exec('sudo -u '.escapeshellarg($web_user).' rm -f '.escapeshellarg($web_backup_dir.'/*'));
-								$sql = "DELETE FROM web_backup WHERE server_id = ? AND parent_domain_id = ?";
-								$app->db->query($sql, $conf['server_id'], $web_id);
-								if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $web_id);
+								$dir_handle = opendir($web_backup_dir.'/');
+								while ($file = readdir($dir_handle)) {
+									if(!is_dir($file)) {
+										unlink ("$web_backup_dir/"."$file");
+									}
+								}
 							}
+							$sql = "DELETE FROM web_backup WHERE server_id = ? AND parent_domain_id = ?";
+							$app->db->query($sql, $conf['server_id'], $web_id);
+							if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql, $conf['server_id'], $web_id);
 						}
 					}
 				}
@@ -353,13 +358,26 @@
 				}
 				//* end run_backups
 				if( $server_config['backup_dir_is_mount'] == 'y' ) $app->system->umount_backup_dir($backup_dir);
-			} else {
-				//* send email to admin that backup directory could not be mounted
-				$global_config = $app->getconf->get_global_config('mail');
-				if($global_config['admin_mail'] != ''){
-					$subject = 'Backup directory '.$backup_dir.' could not be mounted';
-					$message = "Backup directory ".$backup_dir." could not be mounted.\n\nThe command\n\n".$server_config['backup_dir_mount_cmd']."\n\nfailed.";
-					mail($global_config['admin_mail'], $subject, $message);
+			} 
+		}
+		
+		// delete files from backup download dir (/var/www/example.com/backup)
+		unset($records, $entry, $files);
+		$sql = "SELECT * FROM web_domain WHERE server_id = ? AND (type = 'vhost' OR type = 'vhostsubdomain' OR type = 'vhostalias') AND active = 'y'";
+		$records = $app->db->queryAllRecords($sql, $conf['server_id']);
+		if(is_array($records)) {
+			foreach($records as $rec) {
+				$backup_download_dir = $rec['document_root'].'/backup';
+				if(is_dir($backup_download_dir)){
+					$dir_handle = dir($backup_download_dir);
+					$files = array();
+					while (false !== ($entry = $dir_handle->read())) {
+						if($entry != '.' && $entry != '..' && is_file($backup_download_dir.'/'.$entry)) {
+							// delete files older than 3 days
+							if(time() - filemtime($backup_download_dir.'/'.$entry) >= 60*60*24*3) @unlink($backup_download_dir.'/'.$entry);
+						}
+					}
+					$dir_handle->close();
 				}
 			}
 		}

--
Gitblit v1.9.1