events("Already executed.. aborting the process"); die; } if ($argv[1] == '--date') { echo date("Y-m-d H:i:s") . "\n"; } $pid = getmypid(); $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . ".pid"; @mkdir("/var/log/artica-postfix/squid-stats", 0666, true); events("running {$pid} "); GeoIPavailable(); file_put_contents($pidfile, $pid); $pipe = fopen("php://stdin", "r"); while (!feof($pipe)) { $buffer .= fgets($pipe, 4096); Parseline($buffer); $buffer = null; } fclose($pipe); events("Shutdown..."); die; function Parseline($buffer) { $buffer = trim($buffer); if ($buffer == null) { return null; } if (preg_match("#GET cache_object#", $buffer)) { return null; } if (preg_match('#MAC:(.+?)\\s+(.+?)\\s+.+?\\s+(.*?)\\s+\\[.+?:(.+?)\\s+.+?\\]\\s+"(GET|POST|CONNECT)\\s+(.+?)\\s+.+?"\\s+([0-9]+)\\s+([0-9]+)\\s+([A-Z_]+)#', $buffer, $re)) {
function interact($socket) { events("interact() -> START", __FUNCTION__, __LINE__); while ($buffer = @socket_read($socket, 512, PHP_NORMAL_READ)) { Parseline($buffer); } if (socket_last_error($socket) == 104) { events("Buffer:Connection closed", __FUNCTION__, __LINE__); } events("interact() -> STOP", __FUNCTION__, __LINE__); return; }
$GLOBALS["PDNS_HACK_DB"]=array(); $unix=new unix(); $GLOBALS["NODRYREBOOT"]=$sock->GET_INFO("NoDryReboot"); $GLOBALS["CLASS_SOCKET"]=$sock; $GLOBALS["CLASS_UNIX"]=$unix; $sock=null; $unix=null; $mem=round(((memory_get_usage()/1024)/1000),2);events("{$mem}MB before forking","MAIN",__LINE__); $_GET["server"]=$users->hostname; $pipe = fopen("php://stdin", "r"); while(!feof($pipe)){ $buffer .= fgets($pipe, 4096); try{ Parseline($buffer);}catch (Exception $e) {events("fatal error:". $e->getMessage());} $buffer=null; } fclose($pipe); events("Shutdown..."); die(); function Parseline($buffer){ $buffer=trim($buffer); if(preg_match("#artica-filter#",$buffer)){return true;} if(preg_match("#postfix\/#",$buffer)){return true;} if(preg_match("#CRON\[#",$buffer)){return true;} if(preg_match("#: CACHEMGR:#",$buffer)){return true;} if(preg_match("#exec\.postfix-logger\.php:#",$buffer)){return true;} if(preg_match("#artica-install\[#",$buffer)){return true;}
if (posix_getuid() != 0) { die("Cannot be used in web server mode\n\n"); } if (!Build_pid_func(__FILE__, "MAIN")) { events("Already executed.. aborting the process"); die; } $pid = getmypid(); $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . ".pid"; @mkdir("/home/apache/artica-stats", 0666, true); events("running {$pid} "); file_put_contents($pidfile, $pid); $pipe = fopen("php://stdin", "r"); while (!feof($pipe)) { $buffer .= fgets($pipe, 4096); Parseline(trim($buffer)); $buffer = null; } fclose($pipe); DumpMemory(); events("Shutdown..."); die; function Parseline($buffer) { if ($buffer == null) { return; } $FOUND = false; if (preg_match('#ngx\\[(.*?)\\]\\s+(.+?)\\s+(.+?)\\s+(.*?)\\s+\\[(.+?)\\]\\s+([A-Z]+)\\s+(.+?)\\s+[A-Z]+\\/[0-9\\.]+\\s+"([0-9]+)"\\s+([0-9]+)#', $buffer, $re)) { $FOUND = true; $hostname = $re[1];