function scan() { $pidtime = "/etc/artica-postfix/pids/exec.haproxy.events-parser.php.scan.time"; $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { events("A process, {$pid} Already exists..."); return; } $GLOBALS["MYHOSTNAME_PROXY"] = $unix->hostname_g(); @file_put_contents($pidFile, getmypid()); if (!$GLOBALS["VERBOSE"]) { $time = $unix->file_time_min($pidtime); if (!$GLOBALS["VERBOSE"]) { if ($time < 5) { events("{$time}mn, require minimal 5mn"); return; } } } $GLOBALS["LogFileDeamonLogDir"] = "/home/artica/haproxy-postgres/realtime-events"; $Workpath = "{$GLOBALS["LogFileDeamonLogDir"]}/access-work"; @file_put_contents($pidtime, time()); @mkdir($GLOBALS["LogFileDeamonLogDir"], 0755, true); $postgres = new postgres_sql(); $postgres->CREATE_TABLES(); if (!$postgres->TABLE_EXISTS("haproxy_log")) { events("haproxy_log, not such table"); die; } if (is_file("{$GLOBALS["LogFileDeamonLogDir"]}/HAPROXY.LOG")) { HAPROXY_LOG("{$GLOBALS["LogFileDeamonLogDir"]}/HAPROXY.LOG"); } HAPROXY_LOG_SCAN($Workpath); }
function graph2() { $page = CurrentPageName(); $tpl = new templates(); $q = new postgres_sql(); $zmd5 = $_GET["zmd5"]; if ($zmd5 == null) { echo "alert('no key sended');UnlockPage();"; die; } $table = "{$zmd5}report"; if (!$q->TABLE_EXISTS($table)) { echo "alert('NO table {$table}...');UnlockPage();"; $q->QUERY_SQL("DELETE FROM reports_cache WHERE `zmd5`='{$zmd5}'"); return; } $results = $q->QUERY_SQL("SELECT SUM(xcount) as xcount,src_ip FROM \"{$table}\" GROUP BY src_ip ORDER BY xcount DESC LIMIT 10"); while ($ligne = @pg_fetch_assoc($results)) { $size = $ligne["xcount"]; $src_ip = $ligne["src_ip"]; $PieData[$src_ip] = $size; } $highcharts = new highcharts(); $highcharts->container = "graph2-{$zmd5}"; $highcharts->PieDatas = $PieData; $highcharts->ChartType = "pie"; $highcharts->PiePlotTitle = "{src_ip}"; $highcharts->Title = $tpl->_ENGINE_parse_body("{src_ip}/{events}"); echo $highcharts->BuildChart(); echo "LoadAjax('table2-{$zmd5}','{$page}?table2=yes&zmd5={$zmd5}&t={$_GET["t"]}');\n"; }
function graph2() { $page = CurrentPageName(); $tpl = new templates(); $q = new postgres_sql(); $zmd5 = $_GET["zmd5"]; if ($zmd5 == null) { echo "alert('no key sended');UnlockPage();"; die; } $table = "{$zmd5}report"; if (!$q->TABLE_EXISTS($table)) { echo "alert('NO table {$table}...');UnlockPage();"; $q->QUERY_SQL("DELETE FROM reports_cache WHERE `zmd5`='{$zmd5}'"); return; } $results = $q->QUERY_SQL("SELECT SUM(size) as size,zdate FROM \"{$table}\" GROUP BY zdate ORDER BY zdate"); while ($ligne = @pg_fetch_assoc($results)) { $size = $ligne["size"] / 1024; $size = $ligne["size"] / 1024; $size = round($size, 1); $x[] = $ligne["zdate"]; $y[] = $size; } $timetext = "{hours}"; $highcharts = new highcharts(); $highcharts->container = "graph2-{$zmd5}"; $highcharts->xAxis = $x; $highcharts->Title = "{messages_size}"; $highcharts->TitleFontSize = "22px"; $highcharts->AxisFontsize = "12px"; $highcharts->yAxisTtitle = "{size}"; $highcharts->xAxis_labels = false; $highcharts->LegendPrefix = $tpl->javascript_parse_text('{date}: '); $highcharts->LegendSuffix = "MB"; $highcharts->xAxisTtitle = $timetext; $highcharts->datas = array("{size}" => $y); echo $highcharts->BuildChart(); echo "\n"; echo "if(document.getElementById('websites-button-area')){document.getElementById('websites-button-area').innerHTML='';}\n"; echo "LoadAjax('table2-{$zmd5}','{$page}?table2=yes&zmd5={$zmd5}&t={$_GET["t"]}');\n"; }
function FLUX_HOUR($astimeout = false) { $TimeFile = "/etc/artica-postfix/pids/exec.squid.interface-size.php.FLUX_HOUR.time"; if ($GLOBALS["VERBOSE"]) { $astimeout = false; } if ($GLOBALS["FORCE"]) { $astimeout = false; } if ($astimeout) { $unix = new unix(); if ($unix->file_time_min($TimeFile) < 5) { events("Aborting, require 5mn minimal"); return; } } @unlink($TimeFile); @file_put_contents($TimeFile, time()); $os = new os_system(); $UPTIME = $os->uptime_int(); build_progress("{uptime} {$UPTIME}", 15); @file_put_contents("{$GLOBALS["BASEDIR"]}/UPTIME", $UPTIME); CACHES_AVG(); $now = strtotime("-24 hour"); $MAIN = array(); $xdata = array(); $ydata = array(); $MAIN = array(); $xdata = array(); $ydata = array(); $influx = new influx(); $sock = new sockets(); echo "# # # # # # # # # # # # # # # # # # # # #\n"; echo "# # # # # # # # FLUX_HOUR # # # # # # # #\n"; echo "# # # # # # # # # # # # # # # # # # # # #\n"; $q = new mysql_squid_builder(); $q2 = new postgres_sql(); if (!$q->TABLE_EXISTS("dashboard_size_day")) { if ($q2->TABLE_EXISTS("access_log")) { FLUX_HOUR_POSTGRES(); return; } return; } if ($q->TABLE_EXISTS("dashboard_size_day")) { build_progress("{refresh_dashboard_values} FLUX HOUR", 16); $sql = "SELECT SUM(SIZE) as SIZE,TIME FROM dashboard_size_day GROUP BY TIME ORDER BY TIME ASC"; echo "FLUX_HOUR:: MySQL ****************** {$sql} **********************\n"; $results = $q->QUERY_SQL($sql); events("{$sql} -> " . mysql_num_rows($results) . " items"); if (!$q->ok) { events($q->mysql_error); } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $size = intval($ligne["SIZE"]) / 1024; $size = $size / 1024; $time = strtotime($ligne["TIME"]); $min = date("l H:i:00", $time); echo "FLUX_HOUR: {$min} = {$size}\n"; $xdata[] = $min; $ydata[] = $size; } build_progress("{refresh_dashboard_values} FLUX HOUR " . count($xdata) . " items", 16); $MAIN["xdata"] = $xdata; $MAIN["ydata"] = $ydata; echo "# # # FLUX_HOUR:: " . count($xdata) . " ITEMS # # #\n"; @file_put_contents("{$GLOBALS["BASEDIR"]}/FLUX_HOUR", serialize($MAIN)); if (count($xdata) < 2) { @unlink("{$GLOBALS["BASEDIR"]}/FLUX_HOUR"); FLUX_HOUR_POSTGRES(); } } // ----------------------------------------------------------------------------------------------------- if ($q->TABLE_EXISTS("dashboard_countwebsite_day")) { $sql = "SELECT FAMILYSITE, SUM(SIZE) as SIZE FROM dashboard_countwebsite_day GROUP BY FAMILYSITE ORDER BY SIZE DESC LIMIT 1"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); @unlink("{$GLOBALS["BASEDIR"]}/TOP_WEBSITE"); if ($ligne["SIZE"] > 0) { @file_put_contents("{$GLOBALS["BASEDIR"]}/TOP_WEBSITE", serialize(array($ligne["SIZE"], $ligne["FAMILYSITE"]))); } } // ----------------------------------------------------------------------------------------------------- if ($q->TABLE_EXISTS("dashboard_user_day")) { $sql = "SELECT USER, SUM(SIZE) as SIZE FROM dashboard_user_day GROUP BY USER ORDER BY SIZE DESC LIMIT 1"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); events("TOP USER: {$ligne["SIZE"]} : {$ligne["USER"]}"); @unlink("{$GLOBALS["BASEDIR"]}/TOP_USER"); if ($ligne["SIZE"] > 0) { echo "TOP USER: saving {$GLOBALS["BASEDIR"]}/TOP_USER\n"; @file_put_contents("{$GLOBALS["BASEDIR"]}/TOP_USER", serialize(array($ligne["SIZE"], $ligne["USER"]))); } } // ----------------------------------------------------------------------------------------------------- if ($q->TABLE_EXISTS("dashboard_blocked_day")) { build_progress("{refresh_dashboard_values} TOP_BLOCKED", 16); @unlink("{$GLOBALS["BASEDIR"]}/TOP_BLOCKED"); $sql = "SELECT WEBSITE, SUM(RQS) as RQS FROM dashboard_blocked_day GROUP BY WEBSITE ORDER BY RQS DESC LIMIT 1"; $ligne = mysql_fetch_array($q->QUERY_SQL($sql)); events("TOP_BLOCKED: {$ligne["RQS"]} : {$ligne["WEBSITE"]}"); @unlink("{$GLOBALS["BASEDIR"]}/TOP_BLOCKED"); if ($ligne["RQS"] > 0) { @file_put_contents("{$GLOBALS["BASEDIR"]}/TOP_BLOCKED", serialize(array($ligne["RQS"], $ligne["WEBSITE"]))); } } // ----------------------------------------------------------------------------------------------------- $now = InfluxQueryFromUTC(strtotime("-24 hour")); $MAIN = array(); $xdata = array(); $ydata = array(); $influx = new influx(); $sock = new sockets(); $ipClass = new IP(); $q = new mysql_squid_builder(); @unlink("{$GLOBALS["BASEDIR"]}/MEMBERS_GRAPH"); $q = new mysql_squid_builder(); if ($q->TABLE_EXISTS("dashboard_countuser_day")) { build_progress("{refresh_dashboard_values}", 50); $sql = "SELECT COUNT(USER) AS TCOUNT,TIME FROM dashboard_user_day GROUP BY TIME ORDER BY TIME ASC"; echo "MEMBERS_GRAPH:: ****************** {$sql} **********************\n"; $results = $q->QUERY_SQL($sql); $CountDedashboard_countuser_day = mysql_num_rows($results); events("{$sql} -> {$CountDedashboard_countuser_day} items"); if (!$q->ok) { events($q->mysql_error); } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $xdata[] = $ligne["TIME"]; $ydata[] = $ligne["TCOUNT"]; } $MAIN["xdata"] = $xdata; $MAIN["ydata"] = $ydata; if (count($ydata) > 1) { @file_put_contents("{$GLOBALS["BASEDIR"]}/MEMBERS_GRAPH", serialize($MAIN)); } } build_progress("{done} FLUX MEMBERS_GRAPH", 100); // ----------------------------------------------------------------------------------------------------- }
function graph2() { $page = CurrentPageName(); $tpl = new templates(); $q = new postgres_sql(); $zmd5 = $_GET["zmd5"]; if ($zmd5 == null) { echo "alert('no key sended');UnlockPage();"; die; } $table = "{$zmd5}report"; if (!$q->TABLE_EXISTS($table)) { echo "alert('NO table {$table}...');UnlockPage();"; $q->QUERY_SQL("DELETE FROM reports_cache WHERE `zmd5`='{$zmd5}'"); return; } $results = $q->QUERY_SQL("SELECT SUM(rqs) as size,familysite FROM \"{$table}\" GROUP BY familysite ORDER BY size DESC LIMIT 10"); while ($ligne = @pg_fetch_assoc($results)) { $size = $ligne["size"]; $size = round($size / 1024); $FAMILYSITE = $ligne["familysite"]; $TOP_WEBSITES_SIZE[$FAMILYSITE] = $size; } $PieData = $TOP_WEBSITES_SIZE; $highcharts = new highcharts(); $highcharts->container = "graph2-{$zmd5}"; $highcharts->PieDatas = $PieData; $highcharts->ChartType = "pie"; $highcharts->PiePlotTitle = "{websites}"; $highcharts->Title = $tpl->_ENGINE_parse_body("{websites}/{hits}"); echo $highcharts->BuildChart(); echo "LoadAjax('table2-{$zmd5}','{$page}?table2=yes&zmd5={$zmd5}&t={$_GET["t"]}');\n"; }
function suricata_dashboard() { $unix = new unix(); $TimeFile = "{$GLOBALS["BASEDIR"]}/suricata.dashboard"; if (!$GLOBALS["FORCE"]) { $TimeEx = $unix->file_time_min($TimeFile); if ($TimeEx < 15) { return; } } $q = new postgres_sql(); if (!$q->TABLE_EXISTS("suricata_events")) { return; } $results = $q->QUERY_SQL("SELECT SUM(xcount) as tcount, severity FROM suricata_events GROUP BY severity"); if (!$q->ok) { return; } while ($ligne = pg_fetch_assoc($results)) { $severity = $ligne["severity"]; $tcount = $ligne["tcount"]; if ($tcount == 0) { continue; } $ARRAY["SEVERITIES"][$severity] = $tcount; } @unlink($TimeFile); @file_put_contents($TimeFile, serialize($ARRAY)); @chmod($TimeFile, 0755); }