| | |
| | | // Create awstats statistics |
| | | //###################################################################################################### |
| | | |
| | | $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); |
| | | $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' or type = 'vhostalias') and stats_type = 'awstats' AND server_id = ?"; |
| | | $records = $app->db->queryAllRecords($sql, $conf['server_id']); |
| | | |
| | | $web_config = $app->getconf->get_server_config($conf['server_id'], 'web'); |
| | | |
| | |
| | | $yesterday = date('Ymd', strtotime("-1 day", time())); |
| | | |
| | | $log_folder = 'log'; |
| | | if($rec['type'] == 'vhostsubdomain') { |
| | | $tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = '.intval($rec['parent_domain_id'])); |
| | | if($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') { |
| | | $tmp = $app->db->queryOneRecord('SELECT `domain` FROM web_domain WHERE domain_id = ?', $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; |
| | |
| | | continue; |
| | | } |
| | | } |
| | | $web_folder = ($rec['type'] == 'vhostsubdomain' ? $rec['web_folder'] : 'web'); |
| | | $web_folder = (($rec['type'] == 'vhostsubdomain' || $rec['type'] == 'vhostalias') ? $rec['web_folder'] : 'web'); |
| | | $domain = escapeshellcmd($rec['domain']); |
| | | $statsdir = escapeshellcmd($rec['document_root'].'/'.$web_folder.'/stats'); |
| | | $awstats_pl = $web_config['awstats_pl']; |
| | |
| | | |
| | | if(is_file($awstats_website_conf_file)) unlink($awstats_website_conf_file); |
| | | |
| | | $sql = "SELECT domain FROM web_domain WHERE (type = 'alias' OR type = 'subdomain') AND parent_domain_id = ".$rec['domain_id']; |
| | | $aliases = $app->db->queryAllRecords($sql); |
| | | $sql = "SELECT domain FROM web_domain WHERE (type = 'alias' OR type = 'subdomain') AND parent_domain_id = ?"; |
| | | $aliases = $app->db->queryAllRecords($sql, $rec['domain_id']); |
| | | $aliasdomain = ''; |
| | | |
| | | if(is_array($aliases)) { |
| | |
| | | } |
| | | |
| | | if(!is_file($awstats_website_conf_file)) { |
| | | $awstats_conf_file_content = 'Include "'.$awstats_conf_dir.'/awstats.conf" |
| | | if (is_file($awstats_conf_dir."/awstats.conf")) { |
| | | $include_file = $awstats_conf_dir."/awstats.conf"; |
| | | } elseif (is_file($awstats_conf_dir."/awstats.model.conf")) { |
| | | $include_file = $awstats_conf_dir."/awstats.model.conf"; |
| | | } |
| | | $awstats_conf_file_content = 'Include "'.$include_file.'" |
| | | LogFile="/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log" |
| | | SiteDomain="'.$domain.'" |
| | | HostAliases="www.'.$domain.' localhost 127.0.0.1'.$aliasdomain.'"'; |
| | | file_put_contents($awstats_website_conf_file, $awstats_conf_file_content); |
| | | if (isset($include_file)) { |
| | | file_put_contents($awstats_website_conf_file, $awstats_conf_file_content); |
| | | } else { |
| | | $app->log("No awstats base config found. Either awstats.conf or awstats.model.conf must exist in ".$awstats_conf_dir.".", LOGLEVEL_WARN); |
| | | } |
| | | } |
| | | |
| | | if(!@is_dir($statsdir)) mkdir($statsdir); |
| | | $username = escapeshellcmd($rec['system_user']); |
| | | $groupname = escapeshellcmd($rec['system_group']); |
| | | chown($statsdir, $username); |
| | | chgrp($statsdir, $groupname); |
| | | if(is_link('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log')) unlink('/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log'); |
| | | symlink($logfile, '/var/log/ispconfig/httpd/'.$domain.'/yesterday-access.log'); |
| | | |
| | |
| | | chgrp($rec['document_root']."/".$web_folder."/stats/index.php", $rec['system_group']); |
| | | } |
| | | |
| | | exec('chown -R '.$username.':'.$groupname.' '.$statsdir); |
| | | } |
| | | |
| | | |