From ebd0e986ed11f2a34fb58cdd33efbfab192083ad Mon Sep 17 00:00:00 2001
From: Till Brehm <tbrehm@ispconfig.org>
Date: Fri, 22 Apr 2016 05:26:17 -0400
Subject: [PATCH] Added PHP 7 check in installer and updater.

---
 server/cron_daily.php |  141 ++++++++++++++++++++++++----------------------
 1 files changed, 74 insertions(+), 67 deletions(-)

diff --git a/server/cron_daily.php b/server/cron_daily.php
index 9ffd390..7ba4f61 100644
--- a/server/cron_daily.php
+++ b/server/cron_daily.php
@@ -32,6 +32,8 @@
 require SCRIPT_PATH."/lib/config.inc.php";
 require SCRIPT_PATH."/lib/app.inc.php";
 
+$app->setCaller('cron_daily');
+
 set_time_limit(0);
 ini_set('error_reporting', E_ALL & ~E_NOTICE);
 
@@ -647,7 +649,7 @@
 // function for sending notification emails
 //########
 function send_notification_email($template, $placeholders, $recipients) {
-	global $conf;
+	global $conf, $app;
 
 	if(!is_array($recipients) || count($recipients) < 1) return false;
 	if(!is_array($placeholders)) $placeholders = array();
@@ -668,7 +670,7 @@
 	$mailSubject = '';
 	$inHeader = true;
 	for($l = 0; $l < count($lines); $l++) {
-		if($lines[$l] == '') {
+		if(trim($lines[$l]) == '') {
 			$inHeader = false;
 			continue;
 		}
@@ -886,42 +888,41 @@
 					}
 					send_notification_email('web_quota_ok_notification', $placeholders, $recipients);
 				}
+			} else {
 
-				continue;
-			}
+				// could a notification be sent?
+				$send_notification = false;
+				if(!$rec['last_quota_notification']) $send_notification = true; // not yet notified
+				elseif($web_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $web_config['overquota_notify_freq']) $send_notification = true;
 
-			// could a notification be sent?
-			$send_notification = false;
-			if(!$rec['last_quota_notification']) $send_notification = true; // not yet notified
-			elseif($web_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $web_config['overquota_notify_freq']) $send_notification = true;
+				//* Send quota notifications
+				if(($web_config['overquota_notify_admin'] == 'y' || $web_config['overquota_notify_client'] == 'y') && $send_notification == true) {
+					$app->dbmaster->datalogUpdate('web_domain', "last_quota_notification = CURDATE()", 'domain_id', $rec['domain_id']);
 
-			//* Send quota notifications
-			if(($web_config['overquota_notify_admin'] == 'y' || $web_config['overquota_notify_client'] == 'y') && $send_notification == true) {
-				$app->dbmaster->datalogUpdate('web_domain', "last_quota_notification = CURDATE()", 'domain_id', $rec['domain_id']);
+					$placeholders = array('{domain}' => $rec['domain'],
+						'{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
+						'{used}' => $rec['used'],
+						'{soft}' => $rec['soft'],
+						'{hard}' => $rec['hard'],
+						'{ratio}' => $rec['ratio']);
 
-				$placeholders = array('{domain}' => $rec['domain'],
-					'{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
-					'{used}' => $rec['used'],
-					'{soft}' => $rec['soft'],
-					'{hard}' => $rec['hard'],
-					'{ratio}' => $rec['ratio']);
+					$recipients = array();
 
-				$recipients = array();
-
-				//* send email to admin
-				if($global_config['admin_mail'] != '' && $web_config['overquota_notify_admin'] == 'y') {
-					$recipients[] = $global_config['admin_mail'];
-				}
-
-				//* Send email to client
-				if($web_config['overquota_notify_client'] == 'y') {
-					$client_group_id = $rec["sys_groupid"];
-					$client = $app->db->queryOneRecord("SELECT client.email FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
-					if($client['email'] != '') {
-						$recipients[] = $client['email'];
+					//* send email to admin
+					if($global_config['admin_mail'] != '' && $web_config['overquota_notify_admin'] == 'y') {
+						$recipients[] = $global_config['admin_mail'];
 					}
+
+					//* Send email to client
+					if($web_config['overquota_notify_client'] == 'y') {
+						$client_group_id = $rec["sys_groupid"];
+						$client = $app->db->queryOneRecord("SELECT client.email FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+						if($client['email'] != '') {
+							$recipients[] = $client['email'];
+						}
+					}
+					send_notification_email('web_quota_notification', $placeholders, $recipients);
 				}
-				send_notification_email('web_quota_notification', $placeholders, $recipients);
 			}
 		}
 	}
@@ -1016,42 +1017,41 @@
 
 					send_notification_email('mail_quota_ok_notification', $placeholders, $recipients);
 				}
+			} else {
 
-				continue;
-			}
+				//* Send quota notifications
+				// could a notification be sent?
+				$send_notification = false;
+				if(!$rec['last_quota_notification']) $send_notification = true; // not yet notified
+				elseif($mail_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $mail_config['overquota_notify_freq']) $send_notification = true;
 
-			//* Send quota notifications
-			// could a notification be sent?
-			$send_notification = false;
-			if(!$rec['last_quota_notification']) $send_notification = true; // not yet notified
-			elseif($mail_config['overquota_notify_freq'] > 0 && $rec['notified_before'] >= $mail_config['overquota_notify_freq']) $send_notification = true;
+				if(($mail_config['overquota_notify_admin'] == 'y' || $mail_config['overquota_notify_client'] == 'y') && $send_notification == true) {
+					$app->dbmaster->datalogUpdate('mail_user', "last_quota_notification = CURDATE()", 'mailuser_id', $rec['mailuser_id']);
 
-			if(($mail_config['overquota_notify_admin'] == 'y' || $mail_config['overquota_notify_client'] == 'y') && $send_notification == true) {
-				$app->dbmaster->datalogUpdate('mail_user', "last_quota_notification = CURDATE()", 'mailuser_id', $rec['mailuser_id']);
+					$placeholders = array('{email}' => $rec['email'],
+						'{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
+						'{used}' => $rec['used'],
+						'{name}' => $rec['name'],
+						'{quota}' => $rec['quota'],
+						'{ratio}' => $rec['ratio']);
 
-				$placeholders = array('{email}' => $rec['email'],
-					'{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
-					'{used}' => $rec['used'],
-					'{name}' => $rec['name'],
-					'{quota}' => $rec['quota'],
-					'{ratio}' => $rec['ratio']);
-
-				$recipients = array();
-				//* send email to admin
-				if($global_config['admin_mail'] != '' && $mail_config['overquota_notify_admin'] == 'y') {
-					$recipients[] = $global_config['admin_mail'];
-				}
-
-				//* Send email to client
-				if($mail_config['overquota_notify_client'] == 'y') {
-					$client_group_id = $rec["sys_groupid"];
-					$client = $app->db->queryOneRecord("SELECT client.email FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
-					if($client['email'] != '') {
-						$recipients[] = $client['email'];
+					$recipients = array();
+					//* send email to admin
+					if($global_config['admin_mail'] != '' && $mail_config['overquota_notify_admin'] == 'y') {
+						$recipients[] = $global_config['admin_mail'];
 					}
-				}
 
-				send_notification_email('mail_quota_notification', $placeholders, $recipients);
+					//* Send email to client
+					if($mail_config['overquota_notify_client'] == 'y') {
+						$client_group_id = $rec["sys_groupid"];
+						$client = $app->db->queryOneRecord("SELECT client.email FROM sys_group, client WHERE sys_group.client_id = client.client_id and sys_group.groupid = $client_group_id");
+						if($client['email'] != '') {
+							$recipients[] = $client['email'];
+						}
+					}
+
+					send_notification_email('mail_quota_notification', $placeholders, $recipients);
+				}
 			}
 		}
 	}
@@ -1106,10 +1106,14 @@
 	
 	//* mount backup directory, if necessary
 	$run_backups = true;
-	$server_config['backup_dir_mount_cmd'] = trim($server_config['backup_dir_mount_cmd']);
-	if($server_config['backup_dir_is_mount'] == 'y' && $server_config['backup_dir_mount_cmd'] != ''){
+	$backup_dir_mount_cmd = '/usr/local/ispconfig/server/scripts/backup_dir_mount.sh';
+	if(	$server_config['backup_dir_is_mount'] == 'y' && 
+		is_file($backup_dir_mount_cmd) && 
+		is_executable($backup_dir_mount_cmd) &&
+		fileowner($backup_dir_mount_cmd) === 0
+		){
 		if(!$app->system->is_mounted($backup_dir)){
-			exec(escapeshellcmd($server_config['backup_dir_mount_cmd']));
+			exec($backup_dir_mount_cmd);
 			sleep(1);
 			if(!$app->system->is_mounted($backup_dir)) $run_backups = false;
 		}
@@ -1153,12 +1157,12 @@
 					if($backup_mode == 'userzip') {
 						//* Create a .zip backup as web user and include also files owned by apache / nginx user
 						$web_backup_file = 'web'.$web_id.'_'.date('Y-m-d_H-i').'.zip';
-						exec('cd '.escapeshellarg($web_path).' && sudo -u '.escapeshellarg($web_user).' find . -group '.escapeshellarg($web_group).' -print 2> /dev/null | zip -b /tmp --exclude=backup\*'.$backup_excludes.' --symlinks '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' -@', $tmp_output, $retval);
-						if($retval == 0 || $retval == 12) exec('cd '.escapeshellarg($web_path).' && sudo -u '.escapeshellarg($web_user).' find . -user '.escapeshellarg($http_server_user).' -print 2> /dev/null | zip -b /tmp --exclude=backup\*'.$backup_excludes.' --update --symlinks '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' -@', $tmp_output, $retval);
+						exec('cd '.escapeshellarg($web_path).' && sudo -u '.escapeshellarg($web_user).' find . -group '.escapeshellarg($web_group).' -print 2> /dev/null | zip -b /tmp --exclude=./backup\*'.$backup_excludes.' --symlinks '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' -@', $tmp_output, $retval);
+						if($retval == 0 || $retval == 12) exec('cd '.escapeshellarg($web_path).' && sudo -u '.escapeshellarg($web_user).' find . -user '.escapeshellarg($http_server_user).' -print 2> /dev/null | zip -b /tmp --exclude=./backup\*'.$backup_excludes.' --update --symlinks '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' -@', $tmp_output, $retval);
 					} else {
 						//* Create a tar.gz backup as root user
 						$web_backup_file = 'web'.$web_id.'_'.date('Y-m-d_H-i').'.tar.gz';
-						exec('tar pczf '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' --exclude=backup\*'.$backup_excludes.' --directory '.escapeshellarg($web_path).' .', $tmp_output, $retval);
+						exec('tar pczf '.escapeshellarg($web_backup_dir.'/'.$web_backup_file).' --exclude=./backup\*'.$backup_excludes.' --directory '.escapeshellarg($web_path).' .', $tmp_output, $retval);
 					}
 					if($retval == 0 || ($backup_mode != 'userzip' && $retval == 1) || ($backup_mode == 'userzip' && $retval == 12)) { // tar can return 1, zip can return 12(due to harmless warings) and still create valid backups  
 						if(is_file($web_backup_dir.'/'.$web_backup_file)){
@@ -1230,6 +1234,9 @@
 					$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 = ".intval($conf['server_id'])." AND parent_domain_id = ".intval($web_id);
+						$app->db->query($sql);
+						if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql);
 					}
 				}
 			}

--
Gitblit v1.9.1