function peer_status($aspid = false) { if ($GLOBALS["VERBOSE"]) { echo "peer_status();\n"; } $unix = new unix(); $cacheFile = "/usr/share/artica-postfix/ressources/logs/web/squid.peers.db"; if (!is_dir(dirname($cacheFile))) { @mkdir(dirname($cacheFile), 0755, true); } if (!$GLOBALS["DUMP"]) { if (!$GLOBALS["VERBOSE"]) { $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . "Already `task` running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } } } $timefile = $unix->file_time_min($cacheFile); if ($GLOBALS["VERBOSE"]) { echo basename($cacheFile) . " {$timefile}mn\n"; } if (!$GLOBALS["DUMP"]) { if (!$GLOBALS["FORCE"]) { if (!$GLOBALS["VERBOSE"]) { if ($timefile < 5) { return; } } } } if (!is_peer()) { if ($GLOBALS["DUMP"]) { echo "No cache_peer\n"; return; } if ($GLOBALS["VERBOSE"]) { echo "No cache_peer...\n"; } return; } $sock = new sockets(); $datas = trim(CurlGet("server_list")); if ($GLOBALS["DUMP"]) { echo $datas . "\n"; return; } if ($datas == null) { $GLOBALS["RECONFIGURE_COUNT"] = $GLOBALS["RECONFIGURE_COUNT"] + 1; SendLogs("No results for peer, reloading the server reconfigured {{$GLOBALS["RECONFIGURE_COUNT"]}} times"); $unix = new unix(); squid_admin_mysql(1, "Reconfiguring proxy service\n", null, __FILE__, __LINE__); reload_squid(true); $php5 = $unix->LOCATE_PHP5_BIN(); shell_exec("{$php5} " . __FILE__ . " --peer-status --reconfigure-count={$GLOBALS["RECONFIGURE_COUNT"]}"); return; } $tr = explode("\n", CurlGet("server_list")); while (list($num, $val) = each($tr)) { if ($GLOBALS["VERBOSE"]) { echo "Found: \"{$val}\"\n"; } if (preg_match("#Parent\\s+:(.+)#", $val, $re)) { $peer = trim($re[1]); continue; } if (preg_match("#(.+?)\\s+:(.*)#", $val, $re)) { $key = strtoupper(trim($re[1])); $array[$peer][$key] = trim($re[2]); } } if ($GLOBALS["VERBOSE"]) { echo count($array) . " peers detected\n"; } @unlink($cacheFile); @file_put_contents($cacheFile, serialize($array)); @chmod($cacheFile, 0777); }
function peer_status($aspid = false) { if ($GLOBALS["VERBOSE"]) { echo "peer_status();\n"; } $unix = new unix(); $cacheFile = "/usr/share/artica-postfix/ressources/logs/web/squid.peers.db"; if (!is_dir(dirname($cacheFile))) { @mkdir(dirname($cacheFile), 0755, true); } if (!$GLOBALS["DUMP"]) { if (!$GLOBALS["VERBOSE"]) { $unix = new unix(); if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . "Already `task` running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } } } $timefile = $unix->file_time_min($cacheFile); if ($GLOBALS["VERBOSE"]) { echo basename($cacheFile) . " {$timefile}mn\n"; } if (!$GLOBALS["DUMP"]) { if (!$GLOBALS["FORCE"]) { if (!$GLOBALS["VERBOSE"]) { if ($timefile < 5) { return; } } } } if (!is_peer()) { if ($GLOBALS["DUMP"]) { echo "No cache_peer\n"; return; } if ($GLOBALS["VERBOSE"]) { echo "No cache_peer...\n"; } return; } $sock = new sockets(); $datas = trim($unix->squidclient("server_list")); if ($GLOBALS["DUMP"]) { echo $datas . "\n"; return; } if ($datas == null) { return; } $tr = explode("\n", $datas); while (list($num, $val) = each($tr)) { if ($GLOBALS["VERBOSE"]) { echo "Found: \"{$val}\"\n"; } if (preg_match("#Parent\\s+:(.+)#", $val, $re)) { $peer = trim($re[1]); continue; } if (preg_match("#(.+?)\\s+:(.*)#", $val, $re)) { $key = strtoupper(trim($re[1])); $array[$peer][$key] = trim($re[2]); } } if ($GLOBALS["VERBOSE"]) { echo count($array) . " peers detected\n"; } @unlink($cacheFile); @file_put_contents($cacheFile, serialize($array)); @chmod($cacheFile, 0777); }