function dump_main() { $date = date("Y-m-d H:i:00"); $influx = new influx(); while (list($xdate, $array) = each($GLOBALS["MAIN"])) { if ($xdate == $date) { continue; } while (list($category, $count) = each($array)) { $zArray = array(); $zArray["tags"]["category"] = $category; $zArray["fields"]["hits"] = intval($count); $zArray["tags"]["proxyname"] = $GLOBALS["MYHOSTNAME"]; squid_watchdog_events("Influx -> {$xdate}/{$date}: {$category}: {$count}"); $influx->insert("hypercache", $zArray); } unset($GLOBALS["MAIN"][$xdate]); } reset($GLOBALS["MAIN"]); }
function support_step2() { $files[] = "/var/log/squid/cache.log"; $files[] = "/var/log/syslog"; $files[] = "/var/log/messages"; $files[] = "/var/log/auth.log"; $files[] = "/var/log/squid/access.log"; $files[] = "/var/log/squid/external-acl.log"; $files[] = "/var/log/squid/logfile_daemon.debug"; $files[] = "/var/log/php.log"; $files[] = "/var/log/mail.log"; $files[] = "/var/log/squid.watchdog.log"; $files[] = "/var/log/squid/ufdbguardd.log"; $files[] = "/var/log/samba/log.winbindd"; $files[] = "/etc/samba/smb.conf"; $files[] = "/var/log/samba/log.nmbd"; $files[] = "/var/log/samba/log.smbd"; $files[] = "/var/run/mysqld/mysqld.err"; $files[] = "/etc/init.d/artica-ifup"; $files[] = "/var/log/net-start.log"; $files[] = "/var/log/artica-ufdb.log"; $files[] = "/var/log/artica-meta.log"; $files[] = "/var/log/webfiltering-update.log"; $files[] = "{$GLOBALS["ARTICALOGDIR"]}/ufdbguard-tail.debug"; $unix = new unix(); $cp = $unix->find_program("cp"); $dmesg = $unix->find_program("dmesg"); @mkdir("/usr/share/artica-postfix/ressources/support", 0755, true); shell_exec("{$dmesg} >/usr/share/artica-postfix/ressources/support/dmesg.txt"); progress("{get_all_logs}", 45); if (is_dir("/etc/squid3")) { @mkdir("/usr/share/artica-postfix/ressources/support/etc-squid3", 0755, true); $cmd = "/bin/cp -rf /etc/squid3/* /usr/share/artica-postfix/ressources/support/etc-squid3/"; shell_exec("{$cmd}"); } $squidbin = $unix->LOCATE_SQUID_BIN(); progress("{get_all_logs}", 46); if (is_file("/tmp/squid.conf")) { if (is_file($squidbin)) { shell_exec("{$squidbin} -f /tmp/squid.conf -k parse >/etc-squid3/tmp.squid.conf.log 2>&1"); } @copy("/tmp/squid.conf", "/usr/share/artica-postfix/ressources/support/etc-squid3/tmp.squid.conf"); } progress("{get_all_logs}", 47); if (is_dir("/etc/postfix")) { @mkdir("/usr/share/artica-postfix/ressources/support/etc-postfix", 0755, true); $cmd = "/bin/cp -rf /etc/postfix/* /usr/share/artica-postfix/ressources/support/etc-postfix/"; shell_exec("{$cmd}"); } progress("{get_all_logs}", 48); while (list($a, $b) = each($files)) { if (is_file($b)) { progress("{get_all_logs}:" . basename($b), 48); $destfile = basename("{$b}.gz"); $unix->compress($b, "/usr/share/artica-postfix/ressources/support/{$destfile}"); } } progress("{get_all_logs} lshw", 49); $lshw = $unix->find_program("lshw"); exec("{$lshw} -class network 2>&1", $results); progress("{get_all_logs} ifconfig", 50); $ifconfig = $unix->find_program("ifconfig"); exec("{$ifconfig} -a 2>&1", $results); $results[] = "\n\t***************\n"; progress("{get_all_logs} IP", 50); $ip = $unix->find_program("ip"); exec("{$ip} link show 2>&1", $results); $results[] = "\n\t***************\n"; progress("{get_all_logs} Route", 50); exec("{$ip} route 2>&1", $results); $results[] = "\n\t***************\n"; $f = explode("\n", @file_get_contents("/etc/iproute2/rt_tables")); while (list($a, $line) = each($f)) { if (!preg_match("#^([0-9]+)\\s+(.+)#", $line, $re)) { continue; } $table_num = $re[1]; $tablename = $re[2]; if ($table_num == 0) { continue; } if ($table_num > 252) { continue; } $results[] = "\n\t***** Table route {$table_num} named {$tablename} *****\n"; exec("{$ip} route show table {$table_num} 2>&1", $results); $results[] = "\n\t***************\n"; } progress("{get_all_logs} uname", 51); $unix = new unix(); $uname = $unix->find_program("uname"); $results[] = "{$uname} -a:"; exec("{$uname} -a 2>&1", $results); $results[] = "\n"; $results[] = "/bin/bash --version:"; exec("/bin/bash --version 2>&1", $results); $results[] = "\n"; progress("{get_all_logs} gdb", 52); $gdb = $unix->find_program("gdb"); if (is_file($gdb)) { $results[] = "{$gdb} --version:"; exec("{$gdb} --version 2>&1", $results); } else { $results[] = "gdb no such binary...."; } $results[] = "\n"; $smbd = $unix->find_program("smbd"); if (is_file($smbd)) { $results[] = "{$smbd} -V:"; exec("{$smbd} -V 2>&1", $results); } else { $results[] = "smbd no such binary...."; } $results[] = "\n"; progress("{get_all_logs} {$squidbin}", 53); if (is_file($squidbin)) { $results[] = "{$squidbin} -v:"; exec("{$squidbin} -v 2>&1", $results); squid_watchdog_events("Reconfiguring Proxy parameters..."); exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . " 2>&1", $results); squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @implode("\n", $results)); } else { $results[] = "squid no such binary...."; } $results[] = "\n"; progress("{get_all_logs}", 54); if (is_file($squidbin)) { $results[] = "{$squidbin} -v:"; exec("{$squidbin} -v 2>&1", $results); squid_watchdog_events("Reconfiguring Proxy parameters..."); exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . " 2>&1", $results); squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @implode("\n", $results)); shell_exec("{$squidbin} -f /etc/squid3/squid.conf -k check -X >/usr/share/artica-postfix/ressources/support/squid-conf-check.txt"); if (is_file("/tmp/squid.conf")) { shell_exec("{$squidbin} -f /tmp/squid.conf -k check -X >/usr/share/artica-postfix/ressources/support/squid-temp-check.txt"); } } else { $results[] = "squid3 no such binary...."; } progress("{get_all_logs} DF", 55); $results[] = "\n"; $df = $unix->find_program("df"); if (is_file($df)) { $results[] = "{$df} -h:"; exec("{$df} -h 2>&1", $results); } else { $results[] = "{$df} no such binary...."; } progress("{get_all_logs}", 56); @file_put_contents("/usr/share/artica-postfix/ressources/support/generated.versions.txt", @implode("\n", $results)); }
function squid_k_reconfigure() { $unix = new unix(); $squid = $unix->LOCATE_SQUID_BIN(); $force = null; if (isset($_GET["force"])) { $force = " --force"; } squid_watchdog_events("Reconfiguring Proxy parameters..."); SQUID_REFRESH_PANEL_STATUS(); $statusfile = $GLOBALS["SQUID_REFRESH_PANEL_STATUS"]; $unix->chmod_func(0755, "/etc/artica-postfix/settings/Daemons/*"); if (isset($_GET["ApplyConfToo"])) { $php5 = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.squid.php --build{$force} >> {$GLOBALS["SQUID_REFRESH_PANEL_STATUS"]} 2>&1 &"; squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @file_get_contents($statusfile)); writelogs_framework("{$cmd}", __FUNCTION__, __FILE__, __LINE__); shell_exec($cmd); return; } shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.squid.php --kreconfigure >> {$GLOBALS["SQUID_REFRESH_PANEL_STATUS"]} 2>&1"); squid_admin_mysql(2, "Framework executed to reconfigure squid-cache", @file_get_contents($statusfile)); sleep(2); $tail = $unix->find_program("tail"); shell_exec("{$tail} -n 100 /var/log/squid/cache.log >> {$statusfile} 2>&1"); }
function wrapzap_compile() { $sql = "SELECT * FROM squid_adzapper WHERE enabled=1"; $q = new mysql(); $f = array(); $tpl = new templates(); $unix = new unix(); $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { writelogs($q->mysql_error, __FUNCTION__, __FILE__, __LINE__); return; } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $f[] = "{$ligne["uri_type"]} {$ligne["uri"]}"; } echo "Starting......: " . date("H:i:s") . " adZapper " . count($f) . " rows\n"; @file_put_contents("/etc/squid3/zapper.post-database.txt", @implode("\n", $f)); $squiduser = SquidUser(); $unix->chown_func($squiduser, null, "/etc/squid3/zapper.pre-database.txt"); $unix->chown_func($squiduser, null, "/etc/squid3/zapper.post-database.txt"); if ($GLOBALS["RELOAD"]) { $unix = new unix(); squid_watchdog_events("Reconfiguring Proxy parameters..."); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $file = basename($trace[1]["file"]); $function = $trace[1]["function"]; $line = $trace[1]["line"]; $called = "Called by {$function}() from line {$line}"; } } $cmd = "/etc/init.d/squid reload --script=" . basename(__FILE__) . " >/dev/null"; shell_exec($cmd); } }
function winbindd_logs($disabled = false) { $f[] = "log.nmbd"; $f[] = "log.smbd"; $f[] = "log.wb-BUILTIN"; $f[] = "log.winbindd"; $f[] = "log.winbindd-idmap"; $unix = new unix(); $echo = $GLOBALS["CLASS_UNIX"]->find_program("echo"); while (list($num, $filename) = each($f)) { if (!is_file("/var/log/samba/{$filename}")) { continue; } if ($disabled) { @unlink("/var/log/samba/{$filename}"); continue; } $size = @filesize("/var/log/samba/{$filename}"); $size = $size / 1024; $size = $size / 1024; squid_watchdog_events("[winbindd]: {$filename} = {$size}Mb"); if ($size > 100) { squid_admin_mysql(1, "{$filename} exceed 100M [action=clean]", null, __FILE__, __LINE__); shell_exec("{$echo} \"\" >/var/log/samba/{$filename}"); continue; } $time = $unix->file_time_min("/var/log/samba/{$filename}"); squid_watchdog_events("[winbindd]: {$filename} = {$time}mn"); if ($time > 2880) { squid_admin_mysql(1, "{$filename} exceed 2880mn ({$time}mn) [action=remove]", null, __FILE__, __LINE__); @unlink("/var/log/samba/{$filename}"); continue; } } }
function rebuildcaches() { $logFile = "/usr/share/artica-postfix/ressources/logs/web/rebuild-cache.txt"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidfile); if ($pid < 100) { $pid = null; } $unix = new unix(); $sock = new sockets(); if ($unix->process_exists($pid, basename(__FILE__))) { ouputz("Already process exists {$pid}, aborting", __LINE__); die; } $mypid = getmypid(); @file_put_contents($pidfile, $mypid); @unlink($logFile); ouputz("Please wait, rebuild caches....", __LINE__); $t = time(); ouputz("Listing caches....", __LINE__); $array = ListCaches(); $mv = $unix->find_program("mv"); $rm = $unix->find_program("rm"); $php5 = $unix->LOCATE_PHP5_BIN(); ouputz(count($array) . " caches to delete...", __LINE__); if (count($array) == 0) { ouputz("Fatal, unable to list available caches...", __LINE__); squid_admin_mysql(0, "Fatal, unable to list available caches", null, __FILE__, __LINE__); @unlink("/etc/artica-postfix/squid.lock"); die; } $t = time(); @unlink("/etc/artica-postfix/squid.lock"); @file_put_contents("/etc/artica-postfix/squid.lock", time()); $squidbin = $unix->LOCATE_SQUID_BIN(); if (!is_file($squidbin)) { ouputz("squid, no such binary file", __LINE__); @unlink("/etc/artica-postfix/squid.lock"); return; } squid_admin_mysql(1, "Stopping Proxy service in order to rebuild caches", null, __FILE__, __LINE__); ouputz("Stopping squid, please wait...", __LINE__); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefunction = $trace[1]["function"]; $sourceline = $trace[1]["line"]; $executed = "Executed by {$sourcefunction}() line {$sourceline}\nusing argv:{$GLOBALS["ARGVS"]}\n"; } } squid_admin_notifs("Asking to Stop Squid for rebuilding caches\n" . @implode("\n", $GLOBALS["LOGS"]) . "\n{$executed}", __FUNCTION__, __FILE__, __LINE__, "proxy"); shell_exec("/etc/init.d/squid stop --force --script=" . basename(__FILE__)); if ($GLOBALS["REPORT"]) { while (list($cache_dir, $ligne) = each($array)) { $DIRARRAY = $unix->DIR_STATUS($cache_dir); $size = $array["SIZE"]; $used = $array["USED"]; $pourc = $array["POURC"]; $mounted = $array["MOUNTED"]; $logs[] = "{$cache_dir} size: {$size}, used:{$used} {$pourc}% mounted on {$mounted}"; } squid_admin_mysql(2, "Report on caches status", @implode("\n", $logs), __FILE__, __LINE__); } while (list($cache_dir, $ligne) = each($array)) { if (preg_match("#MemBooster#", $cache_dir)) { squid_admin_mysql(1, "Removing cache {$cache_dir}", null, __FILE__, __LINE__); ouputz("Removing {$cache_dir} content...", __LINE__); squid_admin_mysql(2, "Removing cache {$cache_dir} done", null, __FILE__, __LINE__); shell_exec("{$rm} -rf {$cache_dir}/*"); continue; } $DISK_STATUS = $unix->DF_SATUS_K($cache_dir); $DIRECTORY_SIZE = $unix->DIRSIZE_BYTES($cache_dir) / 1024 / 1024; $AIVA = $DISK_STATUS["AIVA"] * 1024; if ($AIVA < 10) { ouputz("Removing {$cache_dir} '{$DIRECTORY_SIZE}'M Available {$AIVA}M", __LINE__); shell_exec("{$rm} -rf {$cache_dir}"); ouputz("re-create {$cache_dir}", __LINE__); squid_admin_mysql(2, "Re-create {$cache_dir}", null, __FILE__, __LINE__); @mkdir($cache_dir, 0755, true); @chown($cache_dir, "squid"); @chgrp($cache_dir, "squid"); continue; } $DIRECTORY_SIZE_NEC = $DIRECTORY_SIZE * 2; if ($AIVA < $DIRECTORY_SIZE_NEC) { ouputz("Removing {$cache_dir} '{$DIRECTORY_SIZE}'M Available {$AIVA}M", __LINE__); shell_exec("{$rm} -rf {$cache_dir}"); ouputz("re-create {$cache_dir}", __LINE__); squid_admin_mysql(2, "Re-create {$cache_dir}", null, __FILE__, __LINE__); @mkdir($cache_dir, 0755, true); @chown($cache_dir, "squid"); @chgrp($cache_dir, "squid"); continue; } $cachesRename[] = "{$cache_dir}-delete-{$t}"; ouputz("Moving {$cache_dir} to {$cache_dir}-delete-{$t}...", __LINE__); exec("{$mv} {$cache_dir} {$cache_dir}-delete-{$t} 2>&1", $results); $results = array(); while (list($num, $ll) = each($results)) { ouputz("{$ligne}", __LINE__); } ouputz("re-create {$cache_dir}", __LINE__); squid_admin_mysql(2, "Re-create {$cache_dir}", null, __FILE__, __LINE__); @mkdir($cache_dir, 0755, true); @chown($cache_dir, "squid"); @chgrp($cache_dir, "squid"); } $su = $unix->find_program("su"); $results = array(); ouputz("Building new caches {$su} -c \"{$squidbin} -z\" squid", __LINE__); exec("{$su} -c \"{$squidbin} -z\" squid 2>&1", $results); while (list($num, $ligne) = each($results)) { ouputz("{$ligne}", __LINE__); } ouputz("Remove lock file...", __LINE__); @unlink("/etc/artica-postfix/squid.lock"); ouputz("Starting squid, please wait...", __LINE__); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefunction = $trace[1]["function"]; $sourceline = $trace[1]["line"]; $executed = "Executed by {$sourcefunction}() line {$sourceline}\nusing argv:{$GLOBALS["ARGVS"]}\n"; } } squid_admin_notifs("Asking to start squid after rebuilding caches...\n{$executed}", __FUNCTION__, __FILE__, __LINE__, "proxy"); squid_admin_mysql(2, "Starting Proxy Service", null, __FILE__, __LINE__); shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.watchdog.php --start"); for ($i = 0; $i < 60; $i++) { $array = $unix->squid_get_cache_infos(); if (count($array) > 0) { break; } ouputz("Waiting {$i}s/60 to Squid-cache be ready...", __LINE__); sleep(1); } ouputz("Done... Squid-cache seems to be ready...", __LINE__); squid_admin_mysql(2, "Reloading {$squidbin} cache", null, __FILE__, __LINE__); ouputz("Reloading {$squidbin} cache", __LINE__); $results = array(); squid_watchdog_events("Reconfiguring Proxy parameters..."); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $file = basename($trace[1]["file"]); $function = $trace[1]["function"]; $line = $trace[1]["line"]; $called = "Called by {$function}() from line {$line}"; } } $cmd = "/etc/init.d/squid reload --script=" . basename(__FILE__) . " >/dev/null"; shell_exec($cmd); $NICE = $unix->EXEC_NICE(); $nohup = $unix->find_program("nohup"); ouputz("Refresh caches information, please wait...", __LINE__); shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --cache-infos --force"); if (is_array($cachesRename)) { reset($cachesRename); while (list($index, $cache_dir) = each($cachesRename)) { $cmd = "{$nohup} {$NICE} {$rm} -rf {$cache_dir} >/dev/null 2>&1 &"; squid_admin_mysql(2, "Ask to delete old cache dir {$cache_dir} done", "{$called}", __FILE__, __LINE__); ouputz("Deleting {$cache_dir} {$cmd}", __LINE__); shell_exec($cmd); } } $took = $unix->distanceOfTimeInWords($t, time()); squid_admin_mysql(2, "All Proxy caches was rebuilded took: {$took}", "{$called}", __FILE__, __LINE__); $sock->TOP_NOTIFY("All Proxy caches was rebuilded took: {$took}", "info"); }