| | |
| | | } |
| | | |
| | | |
| | | $sql = "SELECT domain_id, domain, document_root, web_folder, type FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain') and stats_type = 'webalizer' AND server_id = ".$conf['server_id']; |
| | | $sql = "SELECT domain_id, domain, document_root, web_folder, type, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain') and stats_type = 'webalizer' AND server_id = ".$conf['server_id']; |
| | | $records = $app->db->queryAllRecords($sql); |
| | | |
| | | foreach($records as $rec) { |
| | | //$yesterday = date('Ymd',time() - 86400); |
| | | $yesterday = date('Ymd',strtotime("-1 day", time())); |
| | | $logfile = escapeshellcmd($rec['document_root'].'/log/'.$yesterday.'-access.log'); |
| | | |
| | | $log_folder = 'log'; |
| | | if($rec['type'] == 'vhostsubdomain') { |
| | | $tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = '.intval($rec['parent_domain_id'])); |
| | | $subdomain_host = preg_replace('/^(.*)\.' . preg_quote($tmp['domain'], '/') . '$/', '$1', $rec['domain']); |
| | | if($subdomain_host == '') $subdomain_host = 'web'.$rec['domain_id']; |
| | | $log_folder .= '/' . $subdomain_host; |
| | | unset($tmp); |
| | | } |
| | | $logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/'.$yesterday.'-access.log'); |
| | | if(!@is_file($logfile)) { |
| | | $logfile = escapeshellcmd($rec['document_root'].'/log/'.$yesterday.'-access.log.gz'); |
| | | $logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/'.$yesterday.'-access.log.gz'); |
| | | if(!@is_file($logfile)) { |
| | | continue; |
| | | } |
| | |
| | | // Create awstats statistics |
| | | ####################################################################################################### |
| | | |
| | | $sql = "SELECT domain_id, domain, document_root, web_folder, type, system_user, system_group FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain') and stats_type = 'awstats' AND server_id = ".$conf['server_id']; |
| | | $sql = "SELECT domain_id, domain, document_root, web_folder, type, system_user, system_group, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain') and stats_type = 'awstats' AND server_id = ".$conf['server_id']; |
| | | $records = $app->db->queryAllRecords($sql); |
| | | |
| | | $web_config = $app->getconf->get_server_config($conf['server_id'], 'web'); |
| | |
| | | foreach($records as $rec) { |
| | | //$yesterday = date('Ymd',time() - 86400); |
| | | $yesterday = date('Ymd',strtotime("-1 day", time())); |
| | | $logfile = escapeshellcmd($rec['document_root'].'/log/'.$yesterday.'-access.log'); |
| | | |
| | | $log_folder = 'log'; |
| | | if($rec['type'] == 'vhostsubdomain') { |
| | | $tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = '.intval($rec['parent_domain_id'])); |
| | | $subdomain_host = preg_replace('/^(.*)\.' . preg_quote($tmp['domain'], '/') . '$/', '$1', $rec['domain']); |
| | | if($subdomain_host == '') $subdomain_host = 'web'.$rec['domain_id']; |
| | | $log_folder .= '/' . $subdomain_host; |
| | | unset($tmp); |
| | | } |
| | | $logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/'.$yesterday.'-access.log'); |
| | | if(!@is_file($logfile)) { |
| | | $logfile = escapeshellcmd($rec['document_root'].'/log/'.$yesterday.'-access.log.gz'); |
| | | $logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/'.$yesterday.'-access.log.gz'); |
| | | if(!@is_file($logfile)) { |
| | | continue; |
| | | } |
| | |
| | | // Manage and compress web logfiles and create traffic statistics |
| | | ####################################################################################################### |
| | | |
| | | $sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain') AND server_id = ".$conf['server_id']; |
| | | $sql = "SELECT domain_id, domain, type, document_root, web_folder, parent_domain_id FROM web_domain WHERE (type = 'vhost' or type = 'vhostsubdomain') AND server_id = ".$conf['server_id']; |
| | | $records = $app->db->queryAllRecords($sql); |
| | | foreach($records as $rec) { |
| | | |
| | | //* create traffic statistics based on yesterdays access log file |
| | | $yesterday = date('Ymd',time() - 86400); |
| | | $logfile = $rec['document_root'].'/log/'.$yesterday.'-access.log'; |
| | | |
| | | $log_folder = 'log'; |
| | | if($rec['type'] == 'vhostsubdomain') { |
| | | $tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = '.intval($rec['parent_domain_id'])); |
| | | $subdomain_host = preg_replace('/^(.*)\.' . preg_quote($tmp['domain'], '/') . '$/', '$1', $rec['domain']); |
| | | if($subdomain_host == '') $subdomain_host = 'web'.$rec['domain_id']; |
| | | $log_folder .= '/' . $subdomain_host; |
| | | unset($tmp); |
| | | } |
| | | |
| | | $logfile = $rec['document_root'].'/' . $log_folder . '/'.$yesterday.'-access.log'; |
| | | $total_bytes = 0; |
| | | |
| | | $handle = @fopen($logfile, "r"); |
| | |
| | | } |
| | | |
| | | $yesterday2 = date('Ymd',time() - 86400*2); |
| | | $logfile = escapeshellcmd($rec['document_root'].'/log/'.$yesterday2.'-access.log'); |
| | | $logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/'.$yesterday2.'-access.log'); |
| | | |
| | | //* Compress logfile |
| | | if(@is_file($logfile)) { |
| | |
| | | } |
| | | |
| | | // rotate and compress the error.log when it exceeds a size of 10 MB |
| | | $logfile = escapeshellcmd($rec['document_root'].'/log/error.log'); |
| | | $logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/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); |
| | | $logfile = escapeshellcmd($rec['document_root'].'/log/'.$month_ago.'-access.log.gz'); |
| | | $logfile = escapeshellcmd($rec['document_root'].'/' . $log_folder . '/'.$month_ago.'-access.log.gz'); |
| | | if(@is_file($logfile)) { |
| | | unlink($logfile); |
| | | } |
| | |
| | | //* Delete older Log files, in case that we missed them before due to serverdowntimes. |
| | | $datepart = date('Ym',time() - 86400 * 31 * 2); |
| | | |
| | | $logfile = escapeshellcmd($rec['document_root']).'/log/'.$datepart.'*-access.log.gz'; |
| | | $logfile = escapeshellcmd($rec['document_root']).'/' . $log_folder . '/'.$datepart.'*-access.log.gz'; |
| | | exec('rm -f '.$logfile); |
| | | |
| | | $logfile = escapeshellcmd($rec['document_root']).'/log/'.$datepart.'*-access.log'; |
| | | $logfile = escapeshellcmd($rec['document_root']).'/' . $log_folder . '/'.$datepart.'*-access.log'; |
| | | exec('rm -f '.$logfile); |
| | | } |
| | | |
| | | //* Delete old logfiles in /var/log/ispconfig/httpd/ that were created by vlogger for the hostname of the server |
| | | exec('hostname -f', $tmp_hostname); |
| | | if($tmp_hostname[0] != '' && is_dir('/var/log/ispconfig/httpd/'.$tmp_hostname[0])) { |
| | | exec('cd /var/log/ispconfig/httpd/'.$tmp_hostname[0]."; find . -mtime +30 -name '*.log' | xargs rm > /dev/null 2> /dev/null"); |
| | | } |
| | | unset($tmp_hostname); |
| | | |
| | | ####################################################################################################### |
| | | // Rotate the ispconfig.log file |
| | |
| | | } |
| | | |
| | | //* Send email to client |
| | | if($web_config['overtraffic_notify_admin'] == 'y') { |
| | | if($web_config['overtraffic_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'] != '') { |
| | |
| | | |
| | | $web_id = $rec['parent_domain_id']; |
| | | $db_backup_dir = $backup_dir.'/web'.$web_id; |
| | | if(!is_dir($web_backup_dir)) mkdir($web_backup_dir, 0750); |
| | | chmod($web_backup_dir, 0750); |
| | | chown($web_backup_dir, 'root'); |
| | | chgrp($web_backup_dir, 'root'); |
| | | if(!is_dir($db_backup_dir)) mkdir($db_backup_dir, 0750); |
| | | chmod($db_backup_dir, 0750); |
| | | chown($db_backup_dir, 'root'); |
| | | chgrp($db_backup_dir, 'root'); |
| | | |
| | | //* Do the mysql database backup with mysqldump |
| | | $db_id = $rec['database_id']; |