function popup() { $ID = $_GET["ID"]; $page = CurrentPageName(); $tpl = new templates(); $q = new mysql_squid_builder(); $services = $tpl->_ENGINE_parse_body("{services}"); $status = $tpl->_ENGINE_parse_body("{status}"); $uptime = $tpl->_ENGINE_parse_body("{uptime}"); $children = $tpl->_ENGINE_parse_body("{children}"); $memory = $tpl->_ENGINE_parse_body("{memory}"); $cpu = $tpl->_ENGINE_parse_body("{cpu}"); $title = $tpl->javascript_parse_text("{APP_MONIT}"); $cache_file = "/usr/share/artica-postfix/ressources/logs/web/monit.status.all"; $sock = new sockets(); $sock->getFrameWork("monit.php?chock-status=yes"); if (is_file($cache_file)) { $min = file_get_time_min($cache_file); } $t = time(); $html = "\n\t<table class='table-{$t}' style='display: none' id='table-{$t}' style='width:99%'></table>\n\t<script>\n\tvar DeleteGroupItemTemp=0;\n\t\$(document).ready(function(){\n\t\$('#table-{$t}').flexigrid({\n\turl: '{$page}?items-list=yes&ID={$ID}',\n\tdataType: 'json',\n\tcolModel : [\n\t{display: '{$services}', name : 'pattern', width : 304, sortable : true, align: 'left'},\n\t{display: '{$status}', name : 'none2', width : 99, sortable : false, align: 'left'},\n\t{display: '{$uptime}', name : 'none3', width : 111, sortable : false, align: 'left'},\n\t{display: '{$children}', name : 'none4', width : 47, sortable : false, align: 'left'},\n\t{display: '{$memory}', name : 'none4', width : 98, sortable : false, align: 'left'},\n\t{display: '{$cpu}', name : 'none5', width : 77, sortable : false, align: 'left'},\n\t\n\t],\n\t\n\t\n\tsortname: 'pattern',\n\tsortorder: 'asc',\n\tusepager: true,\n\ttitle: '{$title} {$min}mn',\n\tuseRp: true,\n\trp: 200,\n\tshowTableToggleBtn: false,\n\twidth: '99%',\n\theight: 350,\n\tsingleSelect: true\n\t\n\t});\n\t});\n\t\n</script>\n\t\n\t"; echo $html; }
function CleanOldInstall() { foreach (glob("/root/APP_*", GLOB_ONLYDIR) as $dirname) { if (!is_dir($dirname)) { return; } $time = file_get_time_min($dirname); if ($time > 2880) { echo "Removing {$dirname}\n"; $GLOBALS["DELETED_SIZE"] = $GLOBALS["DELETED_SIZE"] + dirsize($dirname); shell_exec("/bin/rm -rf {$dirname}"); } } }
} if (systemMaxOverloaded()) { writelogs("This system is too many overloaded, die()", __FUNCTION__, __FILE__, __LINE__); die; } if (!$_GET["FORCE_EXECUTION"]) { if (system_is_overloaded()) { events("die, overloaded"); die; } $sock = new sockets(); $PoolCoverPageSchedule = intval($sock->GET_INFO('PoolCoverPageSchedule')); if ($PoolCoverPageSchedule < 1) { $PoolCoverPageSchedule = 20; } if (file_get_time_min("/etc/artica-postfix/croned.2/" . md5(__FILE__)) < 30) { events("die, {$PoolCoverPageSchedule}mn minimal"); die; } } @unlink("/etc/artica-postfix/croned.2/" . md5(__FILE__)); @file_put_contents("/etc/artica-postfix/croned.2/" . md5(__FILE__), date('Y-m-d H:i:s')); error_log(basename(__FILE__) . " start_execution();"); start_execution(); function services() { postfix_status(); } function start_execution() { $unix = new unix();
function CourbeParHeure($zoom = false) { $day = $_GET["DAY"]; if ($day == null) { $day = date('Y-m-d'); } @mkdir($_GET["BASEPATH"], 0755, true); $f_name = "day-global-{$day}.png"; if ($zoom) { $f_name = "day-global-{$day}-zoom.png"; } $fileName = "{$_GET["BASEPATH"]}/{$f_name}"; if (is_file($fileName)) { if (file_get_time_min($fileName) < 20) { return "{$_GET["IMGPATH"]}/{$f_name}"; } } @unlink($fileName); $q = new mysql(); $sql = "SELECT COUNT(ID) as tcount ,DATE_FORMAT(zDate,'%h') as thour \nFROM `mbx_con` WHERE DATE_FORMAT(zDate,'%Y-%m-%d')='{$day}' GROUP BY thour ORDER BY thour"; $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $ydata[] = $ligne["tcount"]; $xdata[] = $ligne["thour"]; } if (count($ydata) < 2) { $ydata[] = 1; $xdata[] = date('d'); } $width = 500; $height = 200; if ($zoom) { $width = 720; $height = 400; } $graph = new Graph($width, $height); $graph->SetScale('textlin'); $graph->title->Set("Connexions numbers {$day}"); $graph->title->SetColor('white'); $graph->xaxis->title->Set('hours'); $graph->xaxis->SetTickLabels($xdata); $graph->yaxis->title->Set('(connexions)'); $graph->SetBackgroundGradient('darkred:0.7', 'black', 2, BGRAD_MARGIN); $graph->SetPlotGradient('black', 'darkred:0.8', 2); $graph->xaxis->SetColor('lightgray'); $graph->yaxis->SetColor('lightgray'); $graph->xgrid->Show(); $lineplot = new LinePlot($ydata); $lineplot->SetWeight(2); $lineplot->SetColor('orange:0.9'); $lineplot->SetFillColor('white@0.7'); $lineplot->SetFillFromYMin(); $lineplot->SetWeight(2); $lineplot->SetFilled(true); $lineplot->SetFillFromYMin(true); $graph->Add($lineplot); $gdImgHandler = $graph->Stroke(_IMG_HANDLER); $graph->img->Stream($fileName); return "{$_GET["IMGPATH"]}/{$f_name}"; }
function start() { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; if ($GLOBALS["VERBOSE"]) { echo "TimeFile:{$pidTime}\n"; } $unix = new unix(); if ($unix->file_time_min($pidTime) < 1) { die; } if ($unix->process_exists(@file_get_contents($pidfile, basename(__FILE__)))) { if ($GLOBALS["VERBOSE"]) { echo " --> Already executed.. " . @file_get_contents($pidfile) . " aborting the process\n"; } writelogs(basename(__FILE__) . ":Already executed.. aborting the process", basename(__FILE__), __FILE__, __LINE__); die; } @file_put_contents($pidfile, getmypid()); if (system_is_overloaded(basename(__FILE__))) { if ($GLOBALS["VERBOSE"]) { echo "die, overloaded\n"; } die; } @unlink($pidTime); @file_put_contents($pidTime, time()); if ($argv[1] == 'email') { BuildWarning('100', '0'); exit; } $timef = file_get_time_min("/etc/artica-postfix/croned.2/" . md5(__FILE__)); if ($timef < 5) { events("die, 5mn minimal current {$timef}mn"); die; } @unlink("/etc/artica-postfix/croned.2/" . md5(__FILE__)); @file_put_contents("/etc/artica-postfix/croned.2/" . md5(__FILE__), date('Y-m-d H:i:s')); $users = new usersMenus(); $ini = new Bs_IniHandler(); $page = CurrentPageName(); $sock = new sockets(); $ini->loadString($sock->GET_INFO("SmtpNotificationConfig")); if (!isset($ini->_params["SMTP"]["SystemCPUAlarm"])) { die; } if ($ini->_params["SMTP"]["SystemCPUAlarm"] == 0) { die; } if (!is_numeric($ini->_params["SMTP"]["enabled"])) { $ini->_params["SMTP"]["enabled"] = 1; } if (!is_numeric($ini->_params["SMTP"]["SystemCPUAlarm"])) { $ini->_params["SMTP"]["SystemCPUAlarm"] = 0; } if ($ini->_params["SMTP"]["SystemCPUAlarm"] == null) { $ini->_params["SMTP"]["SystemCPUAlarm"] = 0; } if ($ini->_params["SMTP"]["SystemCPUAlarmPourc"] == null) { $ini->_params["SMTP"]["SystemCPUAlarmPourc"] = 95; } if ($ini->_params["SMTP"]["SystemCPUAlarmMin"] == null) { $ini->_params["SMTP"]["SystemCPUAlarmMin"] = 5; } if ($ini->_params["SMTP"]["enabled"] == 0) { events("{$page} SMTP notification is not enabled"); die; } $filestatus = "/etc/artica-postfix/mpstat.status"; $timestamp = mktime(date("H"), date("i"), 0, date('m'), date('Y')); $timestamp_string = date("H") . "," . date("i") . "," . date('j'); if (!isset($GLOBALS["ISVALS"])) { $GLOBALS["ISVALS"] = trim(exec('/usr/share/artica-postfix/bin/cpu-alarm.pl')); } $cpu = intval($GLOBALS["ISVALS"]); if (!is_file($filestatus)) { file_put_contents($filestatus, "{$timestamp_string};{$cpu}\n"); events("{$page} CPU: {$cpu}%"); die; } $cpu_total = 0; $count = 0; $file_datas = explode("\n", file_get_contents($filestatus)); events("{$filestatus}=" . count($file_datas) . " lines number"); $old_timestamp = 0; while (list($num, $ligne) = each($file_datas)) { if (trim($ligne == null)) { continue; } usleep(300000); if (preg_match('#^([0-9,]+);(.+)#', $ligne, $re)) { $newfileARRAY[] = $ligne; $count = $count + 1; $t = explode(",", $re[1]); if ($old_timestamp == 0) { $old_timestamp = mktime($t[0], $t[1], 0, date('m'), date('Y')); events("old_timestamp={$old_timestamp} line {$num}"); } $cpu_total = $cpu_total + intval(trim($re[2])); } else { events("{$page} unable to preg_match {$ligne}"); } } $cpu_total = $cpu_total + $cpu; $cpuaverage = floor($cpu_total / ($count + 1)); $difference = $timestamp - $old_timestamp; $difference = str_replace("-", '', $difference); $difference = intval($difference); $filetime = floor($difference / 60); $newfileARRAY[] = "{$timestamp_string};{$cpu}"; events("{$page} CPU average: {$cpuaverage}% last cpu in " . $filetime . " minute(s) \"{$difference}\" [must reach {$ini->_params["SMTP"]["SystemCPUAlarmMin"]}mn] cache file={$count} line(s): current: {$cpu}%"); if ($filetime < $ini->_params["SMTP"]["SystemCPUAlarmMin"]) { file_put_contents($filestatus, implode("\n", $newfileARRAY)); die; } if ($cpuaverage >= $ini->_params["SMTP"]["SystemCPUAlarmPourc"]) { if (system_is_overloaded()) { events("{$page} Build warning CPU overload {$cpu}% and overloaded {$GLOBALS["SYSTEM_INTERNAL_LOAD"]}/{$GLOBALS["SYSTEM_MAX_LOAD"]}"); BuildWarning($cpuaverage, $filetime); } } events("{$page} Clean cache..."); unset($newfileARRAY); $newfileARRAY[] = "{$timestamp_string};{$cpu}"; file_put_contents($filestatus, implode("\n", $newfileARRAY)); }
function courbe_today($domain) { $tpl = new templates(); $q = new mysql(); $dansguardian_events = "dansguardian_events_" . date('Ym'); $sql = "SELECT COUNT( ID ) AS tcount, sitename, DATE_FORMAT( zdate, '%H' ) AS thour , DATE_FORMAT( zdate, '%Y-%m-%d' ) AS tday\nFROM {$dansguardian_events}\nWHERE sitename = '{$domain}'\nGROUP BY thour , tday\nHAVING tday = DATE_FORMAT( NOW( ) , '%Y-%m-%d' )\nORDER BY thour"; $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $GLOBALS["stats-array-{$domain}"][] = "<tr>\n\t<td style='font-size:12px;font-weight:bold' nowrap>{$ligne["thour"]}:00</td>\n\t<td style='font-size:12px;font-weight:bold' nowrap>{$ligne["tcount"]} hits</td>\n\t</tr>\n\t"; $ydata[] = $ligne["tcount"]; $xdata[] = $ligne["hour"]; } $f_name = "day-squid-{$domain}.png"; $fileName = "ressources/logs/{$f_name}"; if (is_file($fileName)) { if (file_get_time_min($fileName) < 120) { return $fileName; } } $title = "{$domain} " . $tpl->_ENGINE_parse_body('{today}'); @unlink($fileName); $width = 500; $height = 200; if ($zoom) { $width = 720; $height = 400; } JpGraphError::SetImageFlag(false); $graph = new Graph($width, $height); $graph->SetScale('textlin'); $graph->title->Set($title); $graph->title->SetColor('white'); $graph->xaxis->title->Set('hours'); $graph->xaxis->SetTickLabels($xdata); $graph->yaxis->title->Set('(hits number)'); $graph->yaxis->scale->SetGrace(10); $graph->SetBackgroundGradient('darkred:0.7', 'black', 2, BGRAD_MARGIN); $graph->SetPlotGradient('black', 'darkred:0.8', 2); $graph->SetMargin(55, 20, 60, 20); //$graph->img->SetMargin(50,30,30,100); $graph->xaxis->SetColor('lightgray'); $graph->yaxis->SetColor('lightgray'); $graph->xgrid->Show(); $lineplot = new LinePlot($ydata); $lineplot->SetWeight(2); $lineplot->SetColor('orange:0.9'); $lineplot->SetFillColor('white@0.7'); $lineplot->SetFillFromYMin(); $lineplot->SetWeight(2); $lineplot->SetFilled(true); $lineplot->SetFillFromYMin(true); $graph->Add($lineplot); JpGraphError::SetImageFlag(false); try { $gdImgHandler = $graph->Stroke(_IMG_HANDLER); } catch (JpGraphException $e) { // .. do necessary cleanup // Send back error message // $e->Stroke(); } $graph->img->Stream($fileName); return $fileName; }
function iwlist() { $tpl = new templates(); $page = CurrentPageName(); $sock = new sockets(); $WifiAPEnable = $sock->GET_INFO("WifiAPEnable"); $sock = new sockets(); if (!is_file("ressources/logs/iwlist.scan")) { $sock = new sockets(); $sock->getFrameWork("cmd.php?iwlist=yes"); } else { $f = file_get_time_min("ressources/logs/iwlist.scan"); if ($f > 1) { $sock->getFrameWork("cmd.php?iwlist=yes"); } } $users = new usersMenus(); $array = unserialize(@file_get_contents("ressources/logs/iwlist.scan")); if (!is_array($array)) { echo $tpl->_ENGINE_parse_body("<H2>{NO_ESSID}</H2>"); return; } $html = "\n\t\t<div style='margin:4px'>\n\t\t<table style='width:100%'>\n\t\t<tr>\n\t\t\t<td align='right' width=99%'>\n\t\t\t<strong style='font-size:13px'>{enable_wifi_ap}</strong>\n\t\t\t</td>\n\t\t\t<td width=1%>" . Field_checkbox("WifiAPEnable", 1, $WifiAPEnable, "EditWifiAPEnable()") . "</td>\n\t\t</tr>\n\t\t</table>\n\t</div>\n\t<table style='width:100%'>\n\t<tr>\n\t\t<th colspan=2>{ESSID}</th>\n\t\t<th>{quality}</th>\n\t\t<th>{crypted}</th>\n\t\t<th>{bits_rate}</th>\n\t</tr>\n\t"; if (is_array($array)) { while (list($num, $ligne) = each($array)) { $APNUM = $num; $QUALITY = $ligne["QUALITY"]; $ESSID = $ligne["ESSID"]; $KEY = $ligne["KEY"]; if ($KEY) { $key = "<img src='img/22-key.png'>"; } else { $key = " "; } $RATES = explode(";", $ligne["RATES"]); $tooltip = "{connect}"; while (list($a, $b) = each($RATES)) { $b = trim($b); $b = str_replace(" ", " ", $b); if ($b != null) { $RR[] = $b; } } if ($ligne["ESSID_SELECTED"]) { $wifiok = "<img src='img/wifi-ok-22.png'>"; } else { $wifiok = " "; } if ($users->WPA_SUPPLIANT_INSTALLED) { if ($WifiAPEnable == 1) { $js = "WifiConnectAP('{$ESSID}')"; } else { $tooltip = "{WifiConnectAPDisabled}"; } } $html = $html . "\n\t\t\t\t<tr " . CellRollOver($js, "{connect}") . ">\n\t\t\t\t<td width=1%>{$wifiok}</td>\n\t\t\t\t<td valign='middle' nowrap><strong style='font-size:14px'>{$ESSID}</strong></td>\n\t\t\t\t<td valign='top'>" . pourcentage($QUALITY) . "</td>\n\t\t\t\t<td width=1% align='center'>{$key}</td>\n\t\t\t\t<td valign='top' style='font-size:12px'>" . implode(" - ", $RR) . "</td>\n\t\t\t\t\n\t\t\t\t</tr>\n\t\t\t\t<tr><td colspan=5><hr></td></tr>\n\t\t\t\t"; unset($RR); } } $html = $html . "</table>\n\t<div style='margin:5px;width:100%;text-align:right' >" . imgtootltip("32-refresh.png", "{refresh}", "RefreshTab('wifi_main_config');") . "</div>\n\t\n\t\n\t<script>\n\t\tfunction WifiConnectAP(ESSID){\n\t\t\tYahooWin(650,'{$page}?CONNECT='+ESSID,'{connect}::'+ESSID);\n\t\t}\n\t\t\n\t\tfunction x_EditWifiAPEnable(){\n\t\t\tRefreshTab('wifi_main_config');\n\t\t}\n\t\t\n\t\tfunction EditWifiAPEnable(){\n\t\t\tvar XHR = new XHRConnection();\n\t\t\tif(document.getElementById('WifiAPEnable').checked){XHR.appendData('WifiAPEnable','1');}else{XHR.appendData('WifiAPEnable','0');}\n\t\t\tXHR.sendAndLoad('{$page}', 'GET',x_EditWifiAPEnable);\n\t\t}\n\t\n\t</script>\n\t"; echo $tpl->_ENGINE_parse_body("{$html}"); }
function camWebUserFilteredDay($zoom = false) { $day = $_GET["DAY"]; if ($day == null) { $day = date('Y-m-d'); } @mkdir($_GET["BASEPATH"], 0755, true); $f_name = "day-global-users-{$day}-" . __FUNCTION__ . "-pie.png"; if ($zoom) { $f_name = "day-global-users-{$day}-" . __FUNCTION__ . "-pie-zoom.png"; } $fileName = "{$_GET["BASEPATH"]}/{$f_name}"; if (is_file($fileName)) { if (file_get_time_min($fileName) < 20) { return "{$_GET["IMGPATH"]}/{$f_name}"; } } @unlink($fileName); $q = new mysql(); $sql = "SELECT COUNT(ID) as tcount, CLIENT,TYPE FROM `dansguardian_events` \nWHERE DATE_FORMAT(zDate,'%Y-%m-%d')='{$day}' GROUP BY CLIENT,TYPE HAVING TYPE!='PASS' ORDER BY tcount DESC LIMIT 0,10"; $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $ydata[] = $ligne["tcount"]; if (strlen($ligne["CLIENT"]) > 20) { $ligne["CLIENT"] = substr($ligne["uid"], 0, 17) . "..."; } $xdata[] = $ligne["CLIENT"] . " {$ligne["TYPE"]} " . $ligne["tcount"]; } $width = 700; $height = 200; if ($zoom) { $width = 750; $height = 500; } $graph = new PieGraph($width, $height); $graph->title->Set("TOP {filter} {users}"); $p1 = new PiePlot3D($ydata); $p1->SetLegends($xdata); $p1->ExplodeSlice(1); $graph->Add($p1); $gdImgHandler = $graph->Stroke(_IMG_HANDLER); $graph->img->Stream($fileName); return "{$_GET["IMGPATH"]}/{$f_name}"; }
function courbeparmois($zoom = false) { $month = $_GET["MONTH"]; @mkdir($_GET["BASEPATH"], 0755, true); $f_name = "day-global-{$month}.png"; if ($zoom) { $f_name = "day-global-{$month}-zoom.png"; } $fileName = "{$_GET["BASEPATH"]}/{$f_name}"; if (is_file($fileName)) { if (file_get_time_min($fileName) < 120) { return "{$_GET["IMGPATH"]}/{$f_name}"; } } @unlink($fileName); $q = new mysql(); $sql = "SELECT SUM(emails) as tcount , DATE_FORMAT(DAY,'%d') as tday FROM `smtp_logs_day` WHERE DATE_FORMAT(DAY,'%Y-%m')='{$_GET["MONTH"]}' GROUP BY tday ORDER BY tday"; $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $ydata[] = $ligne["tcount"]; $xdata[] = $ligne["DAY"]; } if (count($ydata) < 2) { $ydata[] = 1; $xdata[] = date('d'); } $width = 500; $height = 200; if ($zoom) { $width = 720; $height = 400; } $graph = new Graph($width, $height); $graph->SetScale('textlin'); $graph->title->Set("Received Mails {$_GET["MONTH"]}"); $graph->title->SetColor('white'); $graph->xaxis->title->Set('days'); $graph->xaxis->SetTickLabels($xdata); $graph->yaxis->title->Set('(emails number)'); $graph->yaxis->scale->SetGrace(10); $graph->SetBackgroundGradient('darkred:0.7', 'black', 2, BGRAD_MARGIN); $graph->SetPlotGradient('black', 'darkred:0.8', 2); $graph->SetMargin(55, 20, 60, 20); //$graph->img->SetMargin(50,30,30,100); $graph->xaxis->SetColor('lightgray'); $graph->yaxis->SetColor('lightgray'); $graph->xgrid->Show(); $lineplot = new LinePlot($ydata); $lineplot->SetWeight(2); $lineplot->SetColor('orange:0.9'); $lineplot->SetFillColor('white@0.7'); $lineplot->SetFillFromYMin(); $lineplot->SetWeight(2); $lineplot->SetFilled(true); $lineplot->SetFillFromYMin(true); $graph->Add($lineplot); $gdImgHandler = $graph->Stroke(_IMG_HANDLER); $graph->img->Stream($fileName); return "{$_GET["IMGPATH"]}/{$f_name}"; }
function import() { $pidfile = "/etc/artica-postfix/auditd.pid"; $unix = new unix(); if ($unix->process_exists(@file_get_contents($pidfile))) { die; } @file_put_contents($pidfile, getmypid()); //date_default_timezone_set('Europe/Paris'); //setlocale(LC_ALL, $lang,"en_US.utf8","fr_FR.utf8","nl_BE.utf8","nl_NL.utf8",'de_DE@euro', 'de_DE', 'deu_deu'); $sock = new sockets(); $EnableAuditd = $sock->GET_INFO("EnableAuditd"); $AuditFrequency = $sock->GET_INFO("AuditFrequency"); if ($EnableAuditd == null) { $EnableAuditd = 1; } if ($AuditFrequency == null) { $AuditFrequency = 10; } if ($EnableAuditd != 1) { die; } if (!$GLOBALS["FORCE"]) { $timefile = "/etc/artica-postfix/auditd.time"; $Filetime = file_get_time_min($timefile); if ($Filetime < $AuditFrequency) { die; } @unlink($timefile); @file_put_contents($timefile, "#"); } $ausearch = $unix->find_program("ausearch"); $sock = new sockets(); $AuditdTimeCode = $sock->GET_INFO("AuditdTimeCode"); echo "LANG: {$lang} timecode={$AuditdTimeCode}\n"; if ($AuditdTimeCode > 0) { $start = " -ts " . strftime("%D %T", $AuditdTimeCode); } $FinalAudiTimeCode = time(); $end = " -te " . strftime("%D %T", $FinalAudiTimeCode); $sql = "SELECT `key` FROM auditd_dir"; $q = new mysql(); $q->CheckTables_rsync(); $results = $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { writelogs("{$sql} {$q->mysql_error}", __CLASS__ . '/' . __FUNCTION__, __FILE__, __LINE__); } while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { unset($results2); $key_path = $ligne["key"]; echo "KEY:{$key_path}\n"; $cmd = "{$ausearch} -i -k {$key_path} {$start} {$end}"; echo $cmd . "\n"; exec($cmd, $results2); while (list($num, $line) = each($results2)) { if (preg_match("#type=PATH\\s+msg=audit\\(([0-9\\/\\.]+)\\s+([0-9:]+).+?name=(.+?)\\s+inode=.+?mode=file.+?ouid=(.+?)\\s+ogid=(.+?)\\s+#", $line, $re)) { $date = trim($re[1]) . " " . trim($re[2]); $time_h = $re[2]; if (strlen($date) < 3) { if ($GLOBALS["SIMULE"]) { echo "Failed : {$line}\n"; } } $file = trim($re[3]); $file = addslashes($file); $uid = trim($re[4]); $guid = trim($re[5]); continue; } if (preg_match("#type=SYSCALL msg=audit.+?syscall=([a-zA-Z0-9]+)\\s+success=.+exe=(.+?)key=#", $line, $re)) { $syscall = trim($re[1]); $exe = trim($re[2]); //echo "$date $file ($access)\n"; $date = str_replace("/", "-", $date); $date = str_replace(".", "-", $date); $timestamp = strtotime($date); $newdate = date('Y-m-d H:i:s', $timestamp); if ($newdate == "1970-01-01 01:00:00") { $newdate = date("Y-m-d") . " {$time_h}"; } //writelogs("LANG:$lang::DATE:$date -> $timestamp -> $newdate",__FUNCTION__,__FILE__,__LINE__); if (strtotime($newdate) > time()) { $year = date("Y"); $month = date("m"); $day = date("d") - 1; $newdate = "{$year}-{$month}-{$day} {$time_h}"; } if ($GLOBALS["SIMULE"]) { echo "LANG:{$lang}::DATE:{$date} -> {$timestamp} -> {$newdate} FILE:{$file}\n"; } if (trim($file) == null) { continue; } if (trim($file) == "(null)") { continue; } $sqltOaDD = "('{$newdate}','{$file}','{$syscall}','{$uid}','{$guid}','{$exe}','{$key_path}')\n"; if ($GLOBALS["SIMULE"]) { echo "{$sqltOaDD}\n"; } if ($GLOBALS["md"][md5($sqltOaDD)] == true) { continue; } $VALUES[] = $sqltOaDD; $GLOBALS["md"][md5($sqltOaDD)] = true; $sqltOaDD = null; continue; } } echo "{$key_path}:: " . count($VALUES) . " rows -> next\n"; Purge($key_path); } echo count($VALUES) . " rows final\n"; writelogs(count($VALUES) . " rows time code={$FinalAudiTimeCode}", __FUNCTION__, __FILE__, __LINE__); if (count($VALUES) > 0) { $sql = "INSERT INTO auditd_files (`time`,`file`,`syscall`,`uid`,`gid`,`executable`,`key_path`)\n\tVALUES\n\t" . implode(",", $VALUES); $q = new mysql(); @file_put_contents("/tmp/sql.txt", $sql); if ($GLOBALS["SIMULE"]) { echo $sql . "\n"; } if (!$GLOBALS["SIMULE"]) { $q->QUERY_SQL($sql, "artica_backup"); } if ($q->ok) { writelogs("success " . count($VALUES) . " rows time code={$FinalAudiTimeCode}", __FUNCTION__, __FILE__, __LINE__); echo "success " . count($VALUES) . " rows time code={$FinalAudiTimeCode}\n"; if (!$GLOBALS["SIMULE"]) { $sock->SET_INFO("AuditdTimeCode", "{$FinalAudiTimeCode}"); } } else { send_email_events("APP_AUDITD error mysql", "Error importing " . count($VALUES) . " rows {$q->mysql_error}", "audit"); echo "failed {$q->mysql_error}\n"; } } else { if (!$GLOBALS["SIMULE"]) { $sock->SET_INFO("AuditdTimeCode", "{$FinalAudiTimeCode}"); } } }
function month_hits(){ $fileName = dirname(__FILE__)."/ressources/logs/month-squid-hits.png"; if(file_get_time_min($fileName)<3600){return null;} @unlink($fileName); $g=new artica_graphs($fileName,3600); if(!$g->checkfile()){ writelogs("return $fileName",__FUNCTION__,__FILE__,__LINE__); return $fileName;} $sql="SELECT COUNT(ID) as tcount,DATE_FORMAT(zDate,'%d') as tdate FROM dansguardian_events WHERE MONTH(zDate) = MONTH(NOW()) AND YEAR(zDate)=YEAR(NOW()) GROUP BY tdate"; $q=new mysql(); $results=$q->QUERY_SQL($sql,"artica_events"); if(!$q->ok){ writelogs("$q->mysql_error",__FUNCTION__,__FILE__,__LINE__); } while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){ if($GLOBALS["VERBOSE"]){echo "{$ligne["tdate"]}:{$ligne["tcount"]} ".__FUNCTION__."\n";} $g->ydata[]=$ligne["tcount"]; $g->xdata[]=$ligne["tdate"]; } $g->width=700; $g->title="this_month hits number"; $g->x_title="days"; $g->y_title="hits_number"; $g->line_green(); @chmod($fileName,0777); }