tbrehm
2010-09-16 603bcbfdb00a6836598d25cbfa2873c67535826f
server/cron_daily.php
@@ -132,7 +132,7 @@
   $webalizer_conf = escapeshellcmd($rec["document_root"].'/log/webalizer.conf');
   if(!@is_file($webalizer_conf)) {
      exec("cp $webalizer_conf_main $webalizer_conf");
      copy($webalizer_conf_main,$webalizer_conf);
   }
   if(@is_file($webalizer_conf)) {
@@ -168,19 +168,20 @@
   $domain = escapeshellcmd($rec["domain"]);
   $statsdir = escapeshellcmd($rec["document_root"].'/web/stats');
   $awstats_pl = $web_config['awstats_pl'];
   $awstats_updateall_pl = $web_config['awstats_updateall_pl'];
   $awstats_buildstaticpages_pl = $web_config['awstats_buildstaticpages_pl'];
   
   
   if(!@is_dir($statsdir)) mkdir($statsdir);
   
   // awstats_buildstaticpages.pl -update -config=mydomain.com -lang=en -dir=/var/www/domain.com/web/stats -awstatsprog=/path/to/awstats.pl
   $command = "$awstats_updateall_pl -update -config='$domain' -lang=en -dir='$statsdir' -awstatsprog='$awstats_pl'";
   $command = "$awstats_buildstaticpages_pl -update -config='$domain' -lang=en -dir='$statsdir' -awstatsprog='$awstats_pl'";
   
   if($awstats_pl != '' && $awstats_updateall_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_updateall_pl) == 0) {
   if($awstats_pl != '' && $awstats_buildstaticpages_pl != '' && fileowner($awstats_pl) == 0 && fileowner($awstats_buildstaticpages_pl) == 0) {
      exec($command);
      rename($rec["document_root"].'/web/stats/awstats.'.$domain.'.html',$rec["document_root"].'/web/stats/index.html');
      $app->log("Created awstats statistics with command: $command",LOGLEVEL_DEBUG);
   } else {
      $app->log("No awstats statistics created. Either $awstats_pl or $awstats_updateall_pl is not owned by root user.",LOGLEVEL_WARN);
      $app->log("No awstats statistics created. Either $awstats_pl or $awstats_buildstaticpages_pl is not owned by root user.",LOGLEVEL_WARN);
   }
   
}
@@ -206,6 +207,13 @@
      exec("gzip -c $logfile > $logfile.gz");
      unlink($logfile);
   }
   // rotate and compress the error.log when it exceeds a size of 10 MB
   $logfile = escapeshellcmd($rec["document_root"].'/log/error.log');
   if(is_file($logfile) && filesize($logfile) > 10000000) {
      exec("gzip -c $logfile > $logfile.1.gz");
      exec("cat /dev/null > $logfile");
   }
   // delete logfiles after 30 days
   $month_ago = date("Ymd",time() - 86400 * 30);
@@ -213,6 +221,17 @@
   if(@is_file($logfile)) {
      unlink($logfile);
   }
}
#######################################################################################################
// Rotate the ispconfig.log file
#######################################################################################################
// rotate the ispconfig.log when it exceeds a size of 10 MB
$logfile = '/var/log/ispconfig/ispconfig.log';
if(is_file($logfile) && filesize($logfile) > 10000000) {
   exec("gzip -c $logfile > $logfile.1.gz");
   exec("cat /dev/null > $logfile");
}
#######################################################################################################
@@ -226,7 +245,7 @@
   foreach($records as $rec){
      $tmp_path = realpath(escapeshellcmd($rec["document_root"].'/tmp'));
      if($tmp_path != '' && strlen($tmp_path) > 10 && is_dir($tmp_path) && $app->system->is_user($rec['system_user'])){
         exec("cd ".$tmp_path."; find -mtime +1 -name 'sess_*' | grep -v -w .no_delete | xargs rm &> /dev/null 2> /dev/null");
         exec("cd ".$tmp_path."; find -mtime +1 -name 'sess_*' | grep -v -w .no_delete | xargs rm > /dev/null 2> /dev/null");
      }
   }
}
@@ -352,6 +371,73 @@
}
#######################################################################################################
// Create website backups
#######################################################################################################
$server_config = $app->getconf->get_server_config($conf["server_id"], 'server');
$backup_dir = $server_config['backup_dir'];
if($backup_dir != '') {
   if(!is_dir($backup_dir)) {
      mkdir(escapeshellarg($backup_dir), 0750, true);
   }
   $sql = "SELECT * FROM web_domain WHERE type = 'vhost'";
   $records = $app->db->queryAllRecords($sql);
   if(is_array($records)) {
      foreach($records as $rec) {
         // Create a backup
         if($rec['backup_interval'] == 'daily' or ($rec['backup_interval'] == 'weekly' && date('w') == 0) or ($rec['backup_interval'] == 'monthly' && date('d') == '01')) {
            $web_path = $rec['document_root'];
            $web_user = $rec['system_user'];
            $web_group = $rec['system_group'];
            $web_id = $rec['domain_id'];
            $web_backup_dir = $backup_dir.'/web'.$web_id;
            if(!is_dir($web_backup_dir)) mkdir($web_backup_dir, 0750);
            chmod($web_backup_dir, 0755);
            chown($web_backup_dir, 'root');
            chgrp($web_backup_dir, 'root');
            exec('cd '.escapeshellarg($web_path).' && sudo -u '.escapeshellarg($web_user).' find . -group '.escapeshellarg($web_group).' -print | zip -y '.escapeshellarg($web_backup_dir.'/web.zip').' -@');
            // Rename or remove old backups
            $backup_copies = intval($rec['backup_copies']);
            if(is_file($web_backup_dir.'/web.'.$backup_copies.'.zip')) unlink($web_backup_dir.'/web.'.$backup_copies.'.zip');
            for($n = $backup_copies - 1; $n >= 1; $n--) {
               if(is_file($web_backup_dir.'/web.'.$n.'.zip')) {
                  rename($web_backup_dir.'/web.'.$n.'.zip',$web_backup_dir.'/web.'.($n+1).'.zip');
               }
            }
            if(is_file($web_backup_dir.'/web.zip')) rename($web_backup_dir.'/web.zip',$web_backup_dir.'/web.1.zip');
            // Create backupdir symlink
            if(is_link($web_path.'/backup')) unlink($web_path.'/backup');
            symlink($web_backup_dir,$web_path.'/backup');
         }
         /* If backup_interval is set to none and we have a
         backup directory for the website, then remove the backups */
         if($rec['backup_interval'] == 'none') {
            $web_id = $rec['domain_id'];
            $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.'/*'));
            }
         }
      }
   }
}
die("finished.\n");
?>
?>