uses('ini_parser,file,services'); function setConfigVar( $filename, $varName, $varValue ) { if($lines = @file($filename)) { $out = ''; $found = 0; foreach($lines as $line) { list($key, $value) = split("[\t= ]+", $line, 2); if($key == $varName) { $out .= $varName." ".$varValue."\n"; $found = 1; } else { $out .= $line; } } if($found == 0) { //* add \n if the last line does not end with \n or \r if(substr($out,-1) != "\n" && substr($out,-1) != "\r") $out .= "\n"; //* add the new line at the end of the file if($append == 1) $out .= $varName." ".$varValue."\n"; } #file_put_contents($filename,$out); } } if ( $argv['1'] == "-d" ) { $_domainfilter = "and domain='".$argv['2']."'"; } $sql = "SELECT domain_id, domain, document_root FROM web_domain WHERE server_id = ".$conf["server_id"]. " $_domainfilter"; $records = $app->db->queryAllRecords($sql); foreach($records as $rec) { $yesterday = date("Ymd",time() - 86400); echo $rec['domain']."\n"; $logstack=array(); if ( $rec["document_root"] ) { echo $rec["document_root"]."\n"; $handle = opendir($rec["document_root"].'/log/'); while (false !== ($logfile = readdir($handle))) { if ($logfile != "." && $logfile != "..") { if ( strpos($logfile,"access.log")!==false ) $logstack[$logfile]=$rec["document_root"].'/log/'.$logfile; } } closedir($handle); ksort($logstack); foreach($logstack as $logfile => $logfilepath ) { echo "LOG : $logfilepath\n"; $domain = escapeshellcmd($rec["domain"]); $statsdir = escapeshellcmd($rec["document_root"].'/web/stats'); $out=''; if(!@is_dir($statsdir)) mkdir($statsdir); if ( is_file($logfilepath) ) { if (substr($logfilepath,-3)==".gz") { exec("gunzip $logfilepath"); $logfilepath=substr($logfilepath,0,-3); } if ( file_exists("/etc/awstats/awstats.".$rec["domain"].".conf") ) exec("/usr/lib/cgi-bin/awstats.pl -config=".$rec["domain"]." -LogFile=$logfilepath",$out,$result); // /var/lib/awstats/ print_r($out); if (substr($logfilepath,-3)==".gz") exec("gzip ".$logfilepath); } else echo "SKIPPED\n\n"; #print_r($out); #exit; } } else echo " Alias domain, logs via parent\n"; } die("finished.\n"); ?>