mcramer
2012-10-29 c38140ba6cfaf282167cf44beac6ab738fd016d8
server/cron_daily.php
@@ -39,7 +39,7 @@
// Load required base-classes
$app->uses('ini_parser,file,services,getconf');
$app->uses('ini_parser,file,services,getconf,system');
#######################################################################################################
@@ -238,7 +238,13 @@
      exec($command);
      if(is_file($rec['document_root'].'/'.$web_folder.'/stats/index.html')) unlink($rec['document_root'].'/'.$web_folder.'/stats/index.html');
      rename($rec['document_root'].'/'.$web_folder.'/stats/awstats.'.$domain.'.html',$rec['document_root'].'/'.$web_folder.'/stats/awsindex.html');
      if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$rec['document_root']."/".$web_folder."/stats/index.php");
      if(!is_file($rec['document_root']."/".$web_folder."/stats/index.php")) {
         if(file_exists("/usr/local/ispconfig/server/conf-custom/awstats_index.php.master")) {
            copy("/usr/local/ispconfig/server/conf-custom/awstats_index.php.master",$rec['document_root']."/".$web_folder."/stats/index.php");
         } else {
            copy("/usr/local/ispconfig/server/conf/awstats_index.php.master",$rec['document_root']."/".$web_folder."/stats/index.php");
         }
      }
      $app->log('Created awstats statistics with command: '.$command,LOGLEVEL_DEBUG);
   } else {
@@ -472,7 +478,7 @@
         //* get the traffic
         $tmp = $app->db->queryOneRecord("SELECT SUM(traffic_bytes) As total_traffic_bytes FROM web_traffic WHERE traffic_date like '$current_month%' AND hostname = '$domain'");
         $web_traffic = (int)$tmp['total_traffic_bytes']/1024/1024;
         $web_traffic = round($tmp['total_traffic_bytes']/1024/1024);
         //* Website is over quota, we will disable it
         /*if( ($web_traffic_quota > 0 && $web_traffic > $web_traffic_quota) ||
@@ -665,6 +671,9 @@
            unset($dir_handle);
            //* Remove backupdir symlink and create as directory instead
            $app->uses('system');
            $app->system->web_folder_protection($web_path,false);
            if(is_link($web_path.'/backup')) {
               unlink($web_path.'/backup');
            }
@@ -673,6 +682,8 @@
               chown($web_path.'/backup', $rec['system_user']);
               chgrp($web_path.'/backup', $rec['system_group']);
            }
            $app->system->web_folder_protection($web_path,true);
         }
@@ -736,25 +747,28 @@
            $dir_handle = dir($db_backup_dir);
            $files = array();
            while (false !== ($entry = $dir_handle->read())) {
               if($entry != '.' && $entry != '..' && substr($entry,0,2) == 'db' && is_file($db_backup_dir.'/'.$entry)) {
                  $files[] = $entry;
               if($entry != '.' && $entry != '..' && preg_match('/^db_(.*?)_\d{4}-\d{2}-\d{2}_\d{2}-\d{2}\.sql.gz$/', $entry, $matches) && is_file($db_backup_dir.'/'.$entry)) {
                        if(array_key_exists($matches[1], $files) == false) $files[$matches[1]] = array();
                  $files[$matches[1]][] = $entry;
               }
            }
            $dir_handle->close();
            rsort($files);
            for ($n = $backup_copies; $n <= 10; $n++) {
               if(isset($files[$n]) && is_file($db_backup_dir.'/'.$files[$n])) {
                  unlink($db_backup_dir.'/'.$files[$n]);
                  $sql = "SELECT backup_id FROM web_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = $web_id AND filename = '".$app->db->quote($files[$n])."'";
                  $tmp = $app->dbmaster->queryOneRecord($sql);
                  //$app->dbmaster->datalogDelete('web_backup', 'backup_id', $tmp['backup_id']);
                  $sql = "DELETE FROM web_backup WHERE backup_id = ".intval($tmp['backup_id']);
                  $app->db->query($sql);
                  $app->dbmaster->query($sql);
               }
            }
                reset($files);
                foreach($files as $db_name => $filelist) {
                    rsort($filelist);
                    for ($n = $backup_copies; $n <= 10; $n++) {
                        if(isset($filelist[$n]) && is_file($db_backup_dir.'/'.$filelist[$n])) {
                            unlink($db_backup_dir.'/'.$filelist[$n]);
                            $sql = "SELECT backup_id FROM web_backup WHERE server_id = ".$conf['server_id']." AND parent_domain_id = $web_id AND filename = '".$app->db->quote($filelist[$n])."'";
                            $tmp = $app->dbmaster->queryOneRecord($sql);
                            //$app->dbmaster->datalogDelete('web_backup', 'backup_id', $tmp['backup_id']);
                            $sql = "DELETE FROM web_backup WHERE backup_id = ".intval($tmp['backup_id']);
                            $app->db->query($sql);
                            $app->dbmaster->query($sql);
                        }
                    }
                }
            unset($files);
            unset($dir_handle);