function awstats() { $sock = new sockets(); $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if ($unix->file_time_min($pidTime) < 60) { return; } $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); return; } @file_put_contents($pidfile, getmypid()); @unlink($pidTime); @file_put_contents($pidTime, time()); $sock = new sockets(); $EnableNginxStats = $sock->GET_INFO("EnableNginxStats"); if (!is_numeric($EnableNginxStats)) { $EnableNginxStats = 0; } if ($EnableNginxStats == 1) { return; } include_once dirname(__FILE__) . "/ressources/class.awstats.inc"; include_once dirname(__FILE__) . "/ressources/class.mysql.syslogs.inc"; $awstats_bin = $unix->LOCATE_AWSTATS_BIN(); $nice = EXEC_NICE(); $perl = $unix->find_program("perl"); $awstats_buildstaticpages = $unix->LOCATE_AWSTATS_BUILDSTATICPAGES_BIN(); if ($GLOBALS["VERBOSE"]) { echo "awstats......: {$awstats_bin}\n"; echo "statics Pages: {$awstats_buildstaticpages}\n"; echo "Nice.........: {$nice}\n"; echo "perl.........: {$perl}\n"; } if (!is_file($awstats_buildstaticpages)) { echo "buildstaticpages no such binary...\n"; return; } $sock = new sockets(); $kill = $unix->find_program("kill"); $NginxWorkLogsDir = $sock->GET_INFO("NginxWorkLogsDir"); if ($NginxWorkLogsDir == null) { $NginxWorkLogsDir = "/home/nginx/logsWork"; } $sys = new mysql_storelogs(); $files = $unix->DirFiles($NginxWorkLogsDir, "-([0-9\\-]+)\\.log"); while (list($filename, $line) = each($files)) { if (!preg_match("#^(.+?)-[0-9]+-[0-9]+-[0-9]+-[0-9]+\\.log\$#", $filename, $re)) { if ($GLOBALS["VERBOSE"]) { echo "{$filename}, skip\n"; } continue; } if ($GLOBALS["VERBOSE"]) { echo "{$filename}, domain:{$re[1]}\n"; } $servername = $re[1]; $GLOBALS["nice"] = $nice; $aw = new awstats($servername); $aw->set_LogFile("{$NginxWorkLogsDir}/{$filename}"); $aw->set_LogType("W"); $aw->set_LogFormat(1); $config = $aw->buildconf(); $SOURCE_FILE_PATH = "{$NginxWorkLogsDir}/{$filename}"; $configlength = strlen($config); if ($configlength < 10) { if ($GLOBALS["VERBOSE"]) { echo "configuration file lenght failed {$configlength} bytes, aborting {$servername}\n"; } return; } @file_put_contents("/etc/awstats/awstats.{$servername}.conf", $config); @chmod("/etc/awstats/awstats.{$servername}.conf", 644); $Lang = $aw->GET("Lang"); if ($Lang == null) { $Lang = "auto"; } @mkdir("/var/tmp/awstats/{$servername}", 666, true); $t1 = time(); $cmd = "{$nice}{$perl} {$awstats_buildstaticpages} -config={$servername} -update -lang={$Lang} -awstatsprog={$awstats_bin} -dir=/var/tmp/awstats/{$servername} -LogFile=\"{$SOURCE_FILE_PATH}\" 2>&1"; if ($GLOBALS["VERBOSE"]) { echo $cmd . "\n"; } shell_exec($cmd); $filedate = date('Y-m-d H:i:s', filemtime($SOURCE_FILE_PATH)); if (!awstats_import_sql($servername)) { continue; } $sys->ROTATE_TOMYSQL($SOURCE_FILE_PATH, $filedate); } }
function exectute_awstats($servername, $articameta = false) { $unix = new unix(); $perl = $unix->find_program("perl"); $awstats = $unix->LOCATE_AWSTATS_BIN(); $GLOBALS["ARTICAMETA"] = $articameta; $awstats_buildstaticpages = $unix->LOCATE_AWSTATS_BUILDSTATICPAGES_BIN(); $q = new mysql(); $nice = EXEC_NICE(); $GLOBALS["nice"] = $nice; $aw = new awstats($servername); $config = $aw->buildconf(); $configlength = strlen($config); if ($configlength < 10) { if ($GLOBALS["VERBOSE"]) { echo "configuration file lenght failed {$configlength} bytes, aborting {$servername}\n"; } return; } @file_put_contents("/etc/awstats/awstats.{$servername}.conf", $config); @chmod("/etc/awstats/awstats.{$servername}.conf", 644); $Lang = $aw->GET("Lang"); if ($Lang == null) { $Lang = "auto"; } @mkdir("/var/tmp/awstats/{$servername}", 666, true); $t1 = time(); $cmd = "{$nice}{$perl} {$awstats_buildstaticpages} -config={$servername} -update -lang={$Lang} -awstatsprog={$awstats} -dir=/var/tmp/awstats/{$servername} 2>&1"; if ($GLOBALS["VERBOSE"]) { echo $cmd . "\n"; } exec($cmd, $results); if ($GLOBALS["VERBOSE"]) { echo @implode("\n", $results) . "\n"; } $t2 = time(); awstats_import_sql($servername, $articameta); $time_duration = distanceOfTimeInWords($t1, $t2); if ($GLOBALS["VERBOSE"]) { echo "{$time_duration}\n"; } $unix->send_email_events("generating awstats statistics for {$servername} success {$time_duration}", @implode("\n", $results), "system"); }