<input type="submit" name="sho" value="<?php echo $sholbl; ?> "> <p> <input type="hidden" name="off" value="<?php echo $nof; ?> "> <input type="submit" name="p" value=" < "> <input type="submit" name="n" value=" > "> <p> <input type="submit" name="del" value="<?php echo $dellbl; ?> " onclick="return confirm('<?php echo $dellbl; ?> , <?php echo $cfmmsg; ?> ')" > </th></tr> </table></form> <p> <?php } Condition($in, $op, $st, $co); Events($dlim, $in, $op, $st, $co); include_once "inc/footer.php";
function stop_squid($aspid = false) { 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}"; } } $GLOBALS["LOGS"] = array(); $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"; } system_admin_events("stop_squid::Already task running PID {$pid} since {$time}mn", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } @file_put_contents($pidfile, getmypid()); } $sock = new sockets(); $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig"))); $MonitConfig = watchdog_config_default($MonitConfig); $STOP_SQUID_TIMEOUT = $MonitConfig["StopMaxTTL"]; $STOP_SQUID_MAXTTL_DAEMON = $MonitConfig["STOP_SQUID_MAXTTL_DAEMON"]; if (!is_numeric($STOP_SQUID_TIMEOUT)) { $STOP_SQUID_TIMEOUT = 60; } if (!is_numeric($STOP_SQUID_MAXTTL_DAEMON)) { $STOP_SQUID_MAXTTL_DAEMON = 5; } if ($STOP_SQUID_TIMEOUT < 5) { $STOP_SQUID_TIMEOUT = 5; } $squidbin = $unix->find_program("squid"); $kill = $unix->find_program("kill"); $pgrep = $unix->find_program("pgrep"); if (!is_file($squidbin)) { $squidbin = $unix->find_program("squid3"); } if (!is_file($squidbin)) { system_admin_events("Squid not seems to be installed", __FUNCTION__, __FILE__, __LINE__, "proxy"); return; } $suffix = " (by unknown process)"; if ($GLOBALS["MONIT"]) { $suffix = " (by system monitor)"; } if ($GLOBALS["CRASHED"]) { $suffix = " ( after a crash )"; } if ($GLOBALS["BY_CACHE_LOGS"]) { $suffix = " ( ordered by logs monitor )"; } if ($GLOBALS["BY_STATUS"]) { $suffix = " ( by Artica monitor )"; } if ($GLOBALS["BY_CLASS_UNIX"]) { $suffix = " (by Artica class.unix.inc)"; } if ($GLOBALS["BY_FRAMEWORK"]) { $suffix = " (by Artica framework)"; } if ($GLOBALS["BY_OTHER_SCRIPT"]) { $suffix = " (by other script)"; } if ($GLOBALS["BY_ARTICA_INSTALL"]) { $suffix = " (by artica-install)"; } if ($GLOBALS["BY_FORCE_RECONFIGURE"]) { $suffix = " (after building settings)"; } if ($GLOBALS["MONIT"]) { 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}"; } } $pid = SQUID_PID(); if ($unix->process_exists($pid)) { $ps = $unix->find_program("ps"); $grep = $unix->find_program("grep"); exec("{$ps} aux|{$grep} squid 2>&1", $results); return; } squid_admin_mysql(2, "Monit ordered to stop squid", $called); } if ($GLOBALS["BY_ARTICA_INSTALL"]) { $pid = SQUID_PID(); if ($unix->process_exists($pid)) { $ps = $unix->find_program("ps"); $grep = $unix->find_program("grep"); exec("{$ps} aux|{$grep} squid 2>&1", $results); return; } squid_admin_mysql(2, "artica-install ordered to stop squid", $called); } $t1 = time(); $pid = SQUID_PID(); if (!$GLOBALS["FORCE"]) { if ($unix->process_exists($pid)) { $timeTTL = $unix->PROCCESS_TIME_MIN($pid); if ($timeTTL < $STOP_SQUID_MAXTTL_DAEMON) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . "Squid live since {$timeTTL}Mn, this is not intended to stop before {$STOP_SQUID_MAXTTL_DAEMON}Mn\n"; } Events("Squid live since {$timeTTL}Mn, this is not intended to stop before {$STOP_SQUID_MAXTTL_DAEMON}Mn"); 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}"; } } reload_squid(true); return; } } } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service Already stopped...\n"; } KillGhosts(); return; } $date = date("Y-m-d H:i:s"); $timeTTL = $unix->PROCCESS_TIME_MIN($pid); squid_admin_mysql(1, "Stopping Squid-Cache service: running since {$timeTTL}Mn {$suffix}", "{$suffix} - {$date}\nSquid live since {$timeTTL}Mn and a process ask to stop it\n{$called}", __FILE__, __LINE__); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service PID {$pid} running since {$timeTTL}Mn....\n"; } $commut = "shutdown"; if ($GLOBALS["KILL_ALL"]) { $commut = "kill"; } exec("{$squidbin} -f /etc/squid3/squid.conf -k {$commut} 2>&1", $shutdown); if (stop_squid_analyze($shutdown)) { $STOP_SQUID_TIMEOUT = 1; } if ($GLOBALS["FORCE"]) { $STOP_SQUID_TIMEOUT = 5; } if ($GLOBALS["KILL_ALL"]) { $STOP_SQUID_TIMEOUT = 2; } $PRC = 20; $MAXPRC = 30; $AB = 0; for ($i = 0; $i < $STOP_SQUID_TIMEOUT; $i++) { sleep(1); $PRC++; if ($PRC > $MAXPRC - 1) { $PRC = $MAXPRC - 1; } build_progress_restart("{stopping_service}", $PRC); $STOPIT = false; $task = null; $pid = SQUID_PID(); if (!$unix->process_exists($pid)) { break; } $cmdline = @file_get_contents("/proc/{$pid}/cmdline"); if (preg_match("#\\((.+?)\\)-#", $cmdline, $re)) { $task = $re[1]; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service waiting {$i} seconds (max {$STOP_SQUID_TIMEOUT}) for {$pid} PID Task:{$task}....\n"; } $shutdown = array(); if ($STOPIT) { break; } } $pid = SQUID_PID(); if ($unix->process_exists($pid)) { $STOP_SQUID_TIMEOUT = 10; exec("{$squidbin} -f /etc/squid3/squid.conf -k kill >/dev/null 2>&1"); if (stop_squid_analyze($shutdown)) { $STOP_SQUID_TIMEOUT = 1; } if ($GLOBALS["FORCE"]) { $STOP_SQUID_TIMEOUT = 5; } if ($GLOBALS["KILL_ALL"]) { $STOP_SQUID_TIMEOUT = 2; } for ($i = 0; $i < $STOP_SQUID_TIMEOUT; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Killing.......: " . date("H:i:s") . " Squid-Cache service waiting {$i}/10 seconds for {$pid} PID Task:{$task}....\n"; } sleep(1); $pid = SQUID_PID(); if (!$unix->process_exists($pid)) { break; } } } $pidof = $unix->find_program("pidof"); $kill = $unix->find_program("kill"); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service PID(s): " . exec("{$pidof} {$squidbin} 2>&1") . "\n"; } } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service Search ghost processes...\n"; } $pids = explode(" ", exec("{$pidof} {$squidbin} 2>&1")); if ($GLOBALS["VERBOSE"]) { echo "exec({$pidof} {$squidbin} 2>&1) = `" . exec("{$pidof} {$squidbin} 2>&1") . "`"; } while (list($num, $pid) = each($pids)) { if (!is_numeric($pid)) { continue; } if ($pid < 10) { continue; } if (!$unix->process_exists($pid)) { continue; } $cmdline = trim(@file_get_contents("/proc/{$pid}/cmdline")); if (preg_match("#\\((.+?)\\)-#", $cmdline, $re)) { $task = $re[1]; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service Killing ghost task pid {$pid} `{$task}`\n"; } unix_system_kill($pid); if ($unix->process_exists($pid)) { for ($i = 0; $i < 4; $i++) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service waiting {$i} seconds (max 3) for {$pid} PID Task:{$task}....\n"; } if (!$unix->process_exists($pid)) { break; } sleep(1); } } if ($unix->process_exists($pid)) { unix_system_kill_force($pid); } } KillGhosts(); if (is_file("/dev/shm/squid-cache_mem.shm")) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service Removing /dev/shm/squid-cache_mem.shm\n"; } @unlink("/dev/shm/squid-cache_mem.shm"); } if (is_file("/dev/shm/squid-squid-page-pool.shm")) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " Squid-Cache service Removing /dev/shm/squid-squid-page-pool.shm\n"; } @unlink("/dev/shm/squid-squid-page-pool.shm"); } 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"; } } system_admin_events("Squid success to stop\n" . @implode("\n", $GLOBALS["LOGS"]), __FUNCTION__, __FILE__, __LINE__, "proxy"); }
function downgrade_prg($download_size, $downloaded_size, $upload_size, $uploaded_size) { if (!isset($GLOBALS["previousProgress"])) { $GLOBALS["previousProgress"] = 0; } if ($download_size == 0) { $progress = 0; } else { $progress = round($downloaded_size * 100 / $download_size); } if ($progress > $GLOBALS["previousProgress"]) { Events("Downloading: " . $progress . "%, please wait..."); $GLOBALS["previousProgress"] = $progress; } }
if( array_key_exists($ifip,$vrf[$in]) ){echo "<a href=\"Topology-Networks.php?in[]=vrfname&op[]==&st[]=".urlencode($vrf[$in][$ifip])."\">".$vrf[$in][$ifip]."</a>\n";} } } echo "</td></tr>\n"; } } ?> </table> <table class="content" > <tr class="<?= $modgroup[$self] ?>2"><td><?= $row ?>/<?= count( array_keys($ifn) ) ?> Interfaces<?= ($tpow)?", ${tpow}W $totlbl PoE":"" ?></td></tr> </table> <?php } if($stat){ include_once ("inc/librep.php"); ?> <h2> <a href="Monitoring-Events.php?in[]=source&op[]==&st[]=<?= $ud ?>"><img src="img/16/bell.png" title="<?= $msglbl ?>"></a> <?= $mlvl[150] ?> <?= $laslbl ?></h2> <?php Events($_SESSION['lim'],array('level','source'),array('>=','='),array(150,$dev[0]),array('AND') ); MonLatency("device","=",$dev[0],1,0); IncGroup("device","=",$dev[0],$_SESSION['lim'],0); MonAvail("device","=",$dev[0],1,0); } } include_once ("inc/footer.php"); ?>
</form> <div class="code"><?= implode("\n",$charr) ?> </div></td></tr></table> <?php }else{ echo "<p><br><h2><a href=\"Monitoring-Events.php?in[]=class&op[]==&st[]=cfge\"><img src=\"img/16/bell.png\" title=\"$msglbl\"></a> $buplbl $errlbl</h2>"; Events($_SESSION['lim'],array('class'),array('='),array('cfge'),array()); echo "<p><br><h2><a href=\"Monitoring-Events.php?in[]=class&op[]==&st[]=cfgc\"><img src=\"img/16/bell.png\" title=\"$msglbl\"></a>".(($verb1)?"$laslbl $chglbl":"$chglbl $laslbl")."</h2>"; Events($_SESSION['lim'],array('class'),array('='),array('cfgc'),array()); echo "<p><br><h2><a href=\"Monitoring-Events.php?in[]=class&op[]==&st[]=cfgn\"><img src=\"img/16/bell.png\" title=\"$msglbl\"></a>".(($verb1)?"$newlbl $cfglbl":"$cfglbl $newlbl")."</h2>"; Events($_SESSION['lim'],array('class'),array('='),array('cfgn'),array()); } include_once ("inc/footer.php"); function Opdiff($cfg,$mo){ $config = ""; foreach ( explode("\n",$cfg) as $l ){ $row++; if($mo == 'i' and preg_match("/secret 5|hostname|password 7|key 7|access vlan|clock-period|engineID|Current\s|change|updated/",$l) ){ $config .= "\n"; }elseif($mo == 'p' and preg_match("/untagged /",$l) ){ $config .= "\n"; }elseif($mo == 'f' and preg_match("/untagged /",$l) ){ $config .= "\n";
function CHECK_DNS_SYSTEMS() { $unix = new unix(); include_once dirname(__FILE__) . "/ressources/class.influx.inc"; $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $BigTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".week.time"; if (!is_file("/etc/artica-postfix/settings/Daemons/EnableDNSPerfs")) { @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableDNSPerfs", 1); } $EnableDNSPerfs = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableDNSPerfs")); if ($EnableDNSPerfs == 0) { echo "EnableDNSPerfs -> Disabled\n"; die; } $unix = new unix(); $GLOBALS["MYHOSTNAME"] = $unix->hostname_g(); $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { if ($unix->PROCCESS_TIME_MIN($pid, 10) < 2) { return; } } if ($GLOBALS["VERBOSE"]) { echo "pidtime ={$pidtime}\n"; } @file_put_contents($pidFile, getmypid()); $time = $unix->file_time_min($pidtime); if (!$GLOBALS["FORCE"]) { if ($time < 5) { Events("{$time}mn < 5mn ( use --force to bypass)"); if ($GLOBALS["VERBOSE"]) { echo "{$time}mn < 5mn ( use --force to bypass)\n"; } return; } } @unlink($pidtime); @file_put_contents($pidtime, time()); $BigTimeEx = $unix->file_time_min($BigTime); $resolv = new resolv_conf(); $q = new mysql_squid_builder(); $sock = new sockets(); if ($resolv->MainArray["DNS1"] != null) { $DNS[] = $resolv->MainArray["DNS1"]; } if ($resolv->MainArray["DNS2"] != null) { $DNS[] = $resolv->MainArray["DNS2"]; } if (isset($resolv->MainArray["DNS3"])) { if ($resolv->MainArray["DNS3"] != null) { $DNS[] = $resolv->MainArray["DNS3"]; } } $sql = "SELECT * FROM dns_servers"; $q = new mysql_squid_builder(); $results = $q->QUERY_SQL($sql); while ($ligne = mysql_fetch_assoc($results)) { $DNS[] = $ligne["dnsserver"]; } $type = "A"; $ipClass = new IP(); $minperf = $sock->GET_INFO("DNSPerfsPointer"); if (!is_numeric($minperf)) { $minperf = 301450; } while (list($index, $dnsA) = each($DNS)) { $COMP[$dnsA] = true; } while (list($dnsA, $none) = each($COMP)) { Events("Checks DNS {$dnsA}"); if (!$ipClass->isIPAddress($dnsA)) { continue; } if ($GLOBALS["VERBOSE"]) { echo "{$dnsA}\n"; } $t['start'] = microtime(true); $rs = new Net_DNS2_Resolver(array('nameservers' => array($dnsA))); $rs->timeout = 20; try { $date = date("Y-m-d H:i:s"); $tA = rand("10000", "208460"); $result = $rs->query("p4-cpsk2owex6nby-dwvedtapjla4ebei-{$tA}-i2-v6exp3-v4.metric.gstatic.com", "A"); $t[$dnsA] = microtime(true); $time = mini_bench_to($t); $timeC = $time * 10000; } catch (Net_DNS2_Exception $e) { $error = $e->getMessage(); squid_admin_mysql(1, "DNS benchmark failed on {$dnsA} {$error}", $error, __FILE__, __LINE__); continue; } $perc = $minperf / $timeC; $perc = round($perc * 100); Events("{$dnsA} Response Time:{$time} = {$timeC}/{$minperf} {$perc}%"); foreach ($result->answer as $record) { if ($ipClass->isIPAddress($record->address)) { if ($perc > 100) { $perc = 100; } $zDate = date("Y-m-d H:i:s"); $q = new postgres_sql(); $q->QUERY_SQL("INSERT INTO dnsperfs (zDate,PROXYNAME,DNS,PERCENT,RESPONSE)\n\t\t\t\tVALUES ('{$zDate}','{$GLOBALS["MYHOSTNAME"]}','{$dnsA}','{$perc}','{$time}');"); break; } } } GenerateGraph(true); }
function CHECK_WIFIDOG_IPTABLES_RULES() { $sock = new sockets(); $unix = new unix(); $EnableArticaHotSpot = intval($sock->GET_INFO("EnableArticaHotSpot")); if ($EnableArticaHotSpot == 0) { return; } $ArticaHotSpotEnableMIT = $sock->GET_INFO("ArticaHotSpotEnableMIT"); $ArticaHotSpotEnableProxy = $sock->GET_INFO("ArticaHotSpotEnableProxy"); if (!is_numeric($ArticaHotSpotEnableMIT)) { $ArticaHotSpotEnableMIT = 1; } if (!is_numeric($ArticaHotSpotEnableProxy)) { $ArticaHotSpotEnableProxy = 1; } $ArticaHotSpotInterface = $sock->GET_INFO("ArticaHotSpotInterface"); if ($ArticaHotSpotInterface == null) { $ArticaHotSpotInterface = "eth0"; } $Squid_http_port = intval($sock->GET_INFO("SquidHotSpotPort")); $Squid_hssl_port = intval($sock->GET_INFO("SquidHotSpotSSLPort")); $iptables = $unix->find_program("iptables"); $HTTP_RULE = "-t nat -I WiFiDog_{$ArticaHotSpotInterface}_Internet -i {$ArticaHotSpotInterface} -p tcp -m tcp --dport 80 -m mark --mark 0x1 -j REDIRECT --to-ports {$Squid_http_port}"; $HTTPS_RULE = "-t nat -I WiFiDog_{$ArticaHotSpotInterface}_Internet -i {$ArticaHotSpotInterface} -m mark --mark 0x1 -p tcp --dport 443 -j REDIRECT --to-port {$Squid_hssl_port}"; $HTTPS_RULE2 = "-t nat -I WiFiDog_{$ArticaHotSpotInterface}_Internet -i {$ArticaHotSpotInterface} -m mark --mark 0x2 -p tcp --dport 443 -j REDIRECT --to-port {$Squid_hssl_port}"; if ($ArticaHotSpotEnableProxy == 1) { Events("HotSpot must be connected to the HTTP proxy port {$Squid_http_port} Interface {$ArticaHotSpotInterface}"); if (!CHECK_WIFIDOG_IPTABLES_EXISTS(80, $Squid_http_port)) { squid_admin_mysql(0, "Fatal HotSpot is not link to {$ArticaHotSpotInterface}:{$Squid_http_port} [action=relink]", null, __FILE__, __LINE__); shell_exec("{$iptables} {$HTTP_RULE}"); } else { Events("HotSpot 80 -> {$Squid_http_port} OK"); } } if ($ArticaHotSpotEnableMIT == 1) { if ($Squid_hssl_port < 10) { echo "Warning {$Squid_hssl_port} < 10\n"; return; } Events("HotSpot must be connected to the HTTPS proxy port {$Squid_hssl_port} Interface {$ArticaHotSpotInterface}"); if (!CHECK_WIFIDOG_IPTABLES_EXISTS(443, $Squid_hssl_port)) { squid_admin_mysql(0, "Fatal HotSpot is not link to {$ArticaHotSpotInterface}:{$Squid_hssl_port} [action=relink]", $HTTPS_RULE, __FILE__, __LINE__); shell_exec("{$iptables} {$HTTPS_RULE}"); shell_exec("{$iptables} {$HTTPS_RULE2}"); } else { Events("HotSpot 443 -> {$Squid_hssl_port} OK"); } } }
} echo "</table>\n"; } else { echo "<p><h5>{$nonlbl}</h5>"; } DbFreeResult($res); } else { print DbError($link); } ?> </td> <td width="75%" class="helper"> <h3><?php echo $mlvl[200]; ?> & <?php echo $mlvl[250]; ?> <?php echo $lstlbl; ?> </h3> <?php Events($_SESSION['lim'], array('level', 'time', 'location'), array('>=', '>', '~'), array(200, $firstmsg, $loc), array('AND', 'AND'), 1); echo "</td></tr></table>"; if ($_SESSION['opt']) { MonAvail('', '', '', $_SESSION['lim'], ''); } include_once "inc/footer.php";