Marius Cramer
2013-10-14 992797f73c92b413a7fecff02c27c61b7db55b43
server/cron_daily.php
@@ -33,6 +33,7 @@
require(SCRIPT_PATH."/lib/app.inc.php");
set_time_limit(0);
ini_set('error_reporting', E_ALL & ~E_NOTICE);
// make sure server_id is always an int
$conf['server_id'] = intval($conf['server_id']);
@@ -744,7 +745,7 @@
            if($rec['traffic_quota_lock'] != 'y' && ($web_config['overtraffic_notify_admin'] == 'y' || $web_config['overtraffic_notify_client'] == 'y')) {
                    
                    $placeholders = array('{domain}' => $rec['domain'],
                                          '{admin_mail}' => $global_config['admin_mail']);
                                          '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'));
                    
               $recipients = array();
                    //* send email to admin
@@ -861,7 +862,7 @@
                // send notification - everything ok again
                if($rec['last_quota_notification'] && $web_config['overquota_notify_onok'] == 'y' && ($web_config['overquota_notify_admin'] == 'y' || $web_config['overquota_notify_client'] == 'y')) {
                    $placeholders = array('{domain}' => $rec['domain'],
                                          '{admin_mail}' => $global_config['admin_mail'],
                                          '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
                                          '{used}' => $rec['used'],
                                          '{soft}' => $rec['soft'],
                                          '{hard}' => $rec['hard'],
@@ -898,7 +899,7 @@
            $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'],
                                      '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
                                      '{used}' => $rec['used'],
                                      '{soft}' => $rec['soft'],
                                      '{hard}' => $rec['hard'],
@@ -991,7 +992,7 @@
                // send notification - everything ok again
                if($rec['last_quota_notification'] && $mail_config['overquota_notify_onok'] == 'y' && ($mail_config['overquota_notify_admin'] == 'y' || $mail_config['overquota_notify_client'] == 'y')) {
                    $placeholders = array('{email}' => $rec['email'],
                              '{admin_mail}' => $global_config['admin_mail'],
                              '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
                              '{used}' => $rec['used'],
                              '{name}' => $rec['name'],
                              '{quota}' => $rec['quota'],
@@ -1028,7 +1029,7 @@
            $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'],
                          '{admin_mail}' => ($global_config['admin_mail'] != ''? $global_config['admin_mail'] : 'root'),
                          '{used}' => $rec['used'],
                          '{name}' => $rec['name'],
                          '{quota}' => $rec['quota'],
@@ -1076,17 +1077,12 @@
}
#######################################################################################################
// Create website backups
#######################################################################################################
function formatBytes($size, $precision = 2) {
   $base=log($size)/log(1024);
   $suffixes=array('','k','M','G','T');
       return round(pow(1024,$base-floor($base)),$precision).$suffixes[floor($base)];
}
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'];
#######################################################################################################
// Create website backups
#######################################################################################################
$server_config = $app->getconf->get_server_config($conf['server_id'], 'server');
$backup_dir = $server_config['backup_dir'];
$backup_mode = $server_config['backup_mode'];
if($backup_mode == '') $backup_mode = 'userzip';
@@ -1139,7 +1135,7 @@
               $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\* --directory '.escapeshellarg($web_path).' .', $tmp_output, $retval);
            }
            if($retval == 0){
            if($retval == 0 || $backup_mode != 'userzip'){ // tar can return 1 (due to harmless warings) and still create valid backups
               chown($web_backup_dir.'/'.$web_backup_file, 'root');
               chgrp($web_backup_dir.'/'.$web_backup_file, 'root');
               chmod($web_backup_dir.'/'.$web_backup_file, 0750);
@@ -1198,7 +1194,6 @@
            }
            
            $app->system->web_folder_protection($web_path,true);
         }
         /* If backup_interval is set to none and we have a
@@ -1236,7 +1231,8 @@
            $db_id = $rec['database_id'];
            $db_name = $rec['database_name'];
            $db_backup_file = 'db_'.$db_name.'_'.date('Y-m-d_H-i').'.sql';
            $command = "mysqldump -h '".escapeshellcmd($clientdb_host)."' -u '".escapeshellcmd($clientdb_user)."' -p'".escapeshellcmd($clientdb_password)."' -c --add-drop-table --create-options --quick --result-file='".$db_backup_dir.'/'.$db_backup_file."' '".$db_name."'";
            //$command = "mysqldump -h '".escapeshellcmd($clientdb_host)."' -u '".escapeshellcmd($clientdb_user)."' -p'".escapeshellcmd($clientdb_password)."' -c --add-drop-table --create-options --quick --result-file='".$db_backup_dir.'/'.$db_backup_file."' '".$db_name."'";
            $command = "mysqldump -h ".escapeshellarg($clientdb_host)." -u ".escapeshellarg($clientdb_user)." -p".escapeshellarg($clientdb_password)." -c --add-drop-table --create-options --quick --result-file='".$db_backup_dir.'/'.$db_backup_file."' '".$db_name."'";
            exec($command, $tmp_output, $retval);
            //* Compress the backup with gzip
@@ -1299,6 +1295,19 @@
      unset($clientdb_password);
   }
   // remove non-existing backups from database
   $backups = $app->db->queryAllRecords("SELECT * FROM web_backup WHERE server_id = ".$conf['server_id']);
   if(is_array($backups) && !empty($backups)){
      foreach($backups as $backup){
         $backup_file = $backup_dir.'/web'.$backup['parent_domain_id'].'/'.$backup['filename'];
         if(!is_file($backup_file)){
            $sql = "DELETE FROM web_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = ".$backup['parent_domain_id']." AND filename = '".$backup['filename']."'";
            $app->db->query($sql);
            if($app->db->dbHost != $app->dbmaster->dbHost) $app->dbmaster->query($sql);
         }
      }
   }
}