function start() { $unix = new unix(); $pidpath = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = @file_get_contents($pidpath); if ($unix->process_exists($pid)) { $unix->events(basename(__FILE__) . ":: " . __FUNCTION__ . " Already process {$pid} running.. Aborting"); return; } $sql = "SELECT * FROM postfinder WHERE finish=0 ORDER BY date_start"; $q = new mysql(); $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { find($ligne["pattern"]); } }
function events($text, $function, $file = null, $line = 0) { if ($GLOBALS["OUTPUT"]) { echo "{$text} in {$function}/{$line}\n"; } $unix = new unix(); if ($function == null) { if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[0])) { $file = basename($trace[0]["file"]); $function = $trace[0]["function"]; $line = $trace[0]["line"]; } if (isset($trace[1])) { $file = basename($trace[1]["file"]); $function = $trace[1]["function"]; $line = $trace[1]["line"]; } } } $unix->events($text, "/var/log/artica-meta.log", false, $function, $line, $file); }
function CleanDirLogs($path) { return; if ($GLOBALS["VERBOSE"]) { echo "CleanDirLogs({$path})\n"; } $BigSize = false; if ($path == '/var/log') { $BigSize = true; } if ($GLOBALS["ArticaMaxLogsSize"] < 100) { $GLOBALS["ArticaMaxLogsSize"] = 100; } $maxday = $GLOBALS["MaxTempLogFilesDay"] * 24; $maxday = $maxday * 60; $users = new usersMenus(); $maillog_path = $users->maillog_path; $unix = new unix(); $sock = new sockets(); $restartSyslog = false; if ($path == null) { return; } $countfile = 0; foreach (glob("{$path}/*") as $filepath) { if ($filepath == null) { continue; } if (is_link($filepath)) { continue; } if (is_dir($filepath)) { continue; } if ($filepath == $maillog_path) { continue; } if (preg_match("#\\/log\\/artica-postfix\\/#", $filepath)) { continue; } $countfile++; if ($countfile > 500) { if (is_overloaded()) { $unix->send_email_events("Clean Files: [{$path}/*] System is overloaded ({$GLOBALS["SYSTEM_INTERNAL_LOAD"]}", "The clean logs function is stopped and wait a new schedule with best performances", "logs_cleaning"); die; } $countfile = 0; } usleep(300); $size = round(unix_file_size("{$filepath}") / 1024); $time = $unix->file_time_min($filepath); $unix->events("{$filepath} {$size} Ko, {$time}Mn/{$maxday}Mn TTL"); if ($size > $GLOBALS["ArticaMaxLogsSize"]) { if ($GLOBALS["VERBOSE"]) { echo "Delete {$filepath}\n"; } $restartSyslog = true; $GLOBALS["DELETED_SIZE"] = $GLOBALS["DELETED_SIZE"] + $size; $GLOBALS["DELETED_FILES"] = $GLOBALS["DELETED_FILES"] + 1; $GLOBALS["UNLINKED"][] = $filepath; @unlink($filepath); continue; } if ($time > $maxday) { $GLOBALS["DELETED_SIZE"] = $GLOBALS["DELETED_SIZE"] + $size; $GLOBALS["DELETED_FILES"] = $GLOBALS["DELETED_FILES"] + 1; if ($GLOBALS["VERBOSE"]) { echo "Delete {$filepath}\n"; } @unlink($filepath); $GLOBALS["UNLINKED"][] = $filepath; $restartSyslog = true; continue; } } if ($restartSyslog) { $unix->send_email_events("System log will be restarted", "Logs files was deleted and log daemons will be restarted\n\t\t\t" . @implode("\n", $GLOBALS["UNLINKED"]), "logs_cleaning"); $unix->RESTART_SYSLOG(); } }
function meta_events($text) { $unix = new unix(); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[0])) { $file = basename($trace[0]["file"]); $function = $trace[0]["function"]; $line = $trace[0]["line"]; } if (isset($trace[1])) { $file = basename($trace[1]["file"]); $function = $trace[1]["function"]; $line = $trace[1]["line"]; } } $unix->events($text, "/var/log/artica-meta.log", false, $function, $line, $file); }
function UPGRADE_FROM_INTERFACE() { $unix = new unix(); $php5 = $unix->LOCATE_PHP5_BIN(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $timefile = $unix->file_time_min($pidfile); //$text,$function,$file,$line,$category,$taskid=0 system_admin_events(basename(__FILE__) . ": Already executed pid {$pid} since {$timefile} minutes.. aborting the process", __FUNCTION__, __FILE__, __LINE__, "update"); die; } //if(system_is_overloaded(basename(__FILE__))){system_admin_events("Overloaded system... aborting task...",__FUNCTION__,__FILE__,__LINE__,"system-update");die();} $aptitude = $unix->find_program("aptitude"); if (!is_file($aptitude)) { return; } //if(system_is_overloaded()){$unix->events(basename(__FILE__).": UPGRADE_FROM_INTERFACE() system is overloaded aborting");return;} $q = new mysql(); $sql = "SELECT * FROM syspackages_updt WHERE upgrade=1 AND progress<90"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (mysql_num_rows($results) == 0) { return; } if (!$q->ok) { echo "<H2>{$q->mysql_error}</H2>"; } while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) { if ($ligne["package"] == null) { $q->QUERY_SQL("DELETE FROM syspackages_updt WHERE package=''"); continue; } $q->QUERY_SQL("UPDATE syspackages_updt SET progress=50 WHERE package='{$ligne["package"]}'", "artica_backup"); $results2 = array(); $cmd = "{$aptitude} --safe-resolver --allow-untrusted --allow-new-upgrades -q -y full-upgrade {$ligne["package"]} 2>&1"; exec($cmd, $results2); update_events("Results on upgrade {$ligne["package"]}\n\n" . @implode("\n", $results2), __FUNCTION__, __FILE__, __LINE__, "system-update", "system_update"); $q->QUERY_SQL("UPDATE syspackages_updt SET progress=100 WHERE package='{$ligne["package"]}'", "artica_backup"); if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n" . @implode("\n", $results2); } if (system_is_overloaded()) { $unix->events(basename(__FILE__) . ": UPGRADE_FROM_INTERFACE() system is overloaded aborting"); $unix->THREAD_COMMAND_SET("{$php5} " . __FILE__ . " --pkg-upgrade"); return; } } if (!is_file("/etc/cron.d/pkg-upgrade")) { @unlink("/etc/cron.d/pkg-upgrade"); } GetUpdates(); }
function updatev2_progress2($num, $text) { $array["POURC"] = $num; $array["TEXT"] = $text . " " . date("Y-m-d H:i:s"); if ($GLOBALS["VERBOSE"]) { echo "{$num}% {$text}\n"; } $unix = new unix(); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[0])) { $file = basename($trace[0]["file"]); $function = $trace[0]["function"]; $line = $trace[0]["line"]; } if (isset($trace[1])) { $file = basename($trace[1]["file"]); $function = $trace[1]["function"]; $line = $trace[1]["line"]; } } $unix->events($text, "/var/log/artica-ufdb.log", false, $function, $line, $file); @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/cache/webfilter-artica.progress", serialize($array)); }
function backupevents($text) { $unix = new unix(); $unix->events($text, "/var/log/artica-backup.log"); }
function Events($text) { if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefile = basename($trace[1]["file"]); $sourcefunction = $trace[1]["function"]; $sourceline = $trace[1]["line"]; } } $unix = new unix(); $unix->events($text, dirname(__FILE__) . "/ressources/logs/web/squid.downgrade.html", false, $sourcefunction, $sourceline); @chmod(dirname(__FILE__) . "/ressources/logs/web/squid.downgrade.html", 0755); }
function events($text, $function = null, $line = 0) { if ($GLOBALS["VERBOSE"]) { echo "{$function}:: {$text} (L.{$line})\n"; return; } $filename = basename(__FILE__); $unix = new unix(); $unix->events("{$filename} {$function}:: {$text} (L.{$line})", "/var/log/perfs_queue.log"); }
function events($text, $function = null, $line = null) { $unix = new unix(); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefile = basename($trace[1]["file"]); if ($function == null) { $function = $trace[1]["function"]; } if ($line == null) { $line = $trace[1]["line"]; } } } $unix->events($text, "/var/log/artica-network.log", false, $function, $line); }
function export_hash() { $unix = new unix(); $time = $unix->file_time_min("/etc/artica-postfix/zarafa-export.db"); if ($time < 240) { $unix->events(basename(__FILE__) . ": /etc/artica-postfix/zarafa-export.db {$time} Minutes < 240 aborting..."); return; } $pidfile = "/etc/artica-postfix/cron.2/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if ($unix->process_exists(@file_get_contents($pidfile, basename(__FILE__)))) { $unix->events(basename(__FILE__) . ":Already executed, aborting"); return; } @file_get_contents($pidfile, getmypid()); $GLOBALS["zarafa_admin"] = $unix->find_program("zarafa-admin"); if (!is_file($GLOBALS["zarafa_admin"])) { return; } $companies = array(); exec("{$GLOBALS["zarafa_admin"]} --list-companies 2>&1", $results); while (list($index, $line) = each($results)) { if ($line == null) { continue; } if (preg_match("#------#", $line)) { continue; } if (preg_match("#companyname#", $line)) { continue; } if (preg_match("#list\\s+\\(#", $line)) { continue; } if (preg_match("#\\s+(.+?)\\s+(.+?)\$#", $line, $re)) { $companies[$re[1]]["ADMIN"] = $re[2]; } } if (!is_array($companies)) { return; } while (list($company, $array) = each($companies)) { $companies[$company]["USERS"] = export_hash_users($company); } @unlink("/etc/artica-postfix/zarafa-export.db"); @file_put_contents("/etc/artica-postfix/zarafa-export.db", base64_encode(serialize($companies))); }
function seeker_log($text, $line) { $unix = new unix(); $unix->events($text, "/var/log/seeker.log", false, "seeker", $line, basename(__FILE__)); }
function events($text, $sourcefunction = null, $sourcefile = null, $sourceline = 0) { if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { if ($sourcefile == null) { $sourcefile = basename($trace[1]["file"]); } if ($sourcefunction == null) { $sourcefunction = $trace[1]["function"]; } if ($sourceline == null) { $sourceline = $trace[1]["line"]; } } } $unix = new unix(); $unix->events($text, "/var/log/postfix.stats.log", false, $sourcefunction, $sourceline, basename(__FILE__)); }
function notify_remote_proxys($COMMANDS = null) { $unix = new unix(); include_once dirname(__FILE__) . "/ressources/class.blackboxes.inc"; $EXEC_PID_FILE = "/etc/artica-postfix/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $EXEC_PID_TIME = "/etc/artica-postfix/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pid = @file_get_contents($EXEC_PID_FILE); if ($unix->process_exists($pid, basename(__FILE__))) { $timefile = $unix->file_time_min($EXEC_PID_FILE); if ($timefile < 15) { $unix->events("Skipping, Already executed pid {$pid} {$timefile}Mn", "/var/log/stats-appliance.log"); ufdbguard_admin_events("Skipping, Already executed pid {$pid} {$timefile}Mn...", __FUNCTION__, __FILE__, __LINE__, "communicate"); return; } $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } @file_put_contents($EXEC_PID_FILE, getmypid()); if ($COMMANDS == null) { $COMMANDS = "BUILDCONF"; } if ($COMMANDS == "PING") { $time = $unix->file_time_min($EXEC_PID_TIME); if (!$GLOBALS["VERBOSE"]) { if ($time < 5) { return; } } @unlink($EXEC_PID_TIME); @file_put_contents($EXEC_PID_TIME, time()); $bb = new blackboxes(); $bb->NotifyAll("PING"); return; } $t = time(); $f = new squid_stats_appliance(); $f->export_tables(); $took = $unix->distanceOfTimeInWords($t, time(), true); ufdbguard_admin_events("Exporting MySQL datas done... took:{$took}", __FUNCTION__, __FILE__, __LINE__, "communicate"); $unix->events("Exporting MySQL datas done... took:{$took}", "/var/log/stats-appliance.log"); include_once dirname(__FILE__) . "/ressources/class.blackboxes.inc"; $unix->events("Send order to appliance(s)", "/var/log/stats-appliance.log"); $bb = new blackboxes(); $bb->NotifyAll("BUILDCONF"); }
function events($text, $line) { $unix = new unix(); $unix->events($text, "/var/log/mimedefang-postgres.log", false, "xrun", $line); }
function maintenance() { return null; $unix = new unix(); $time = $unix->file_time_min("/etc/artica-postfix/mysql.optimize.time"); $time1 = time(); $myisamchk = $unix->find_program("myisamchk"); $mysqlcheck = $unix->find_program("mysqlcheck"); if (!$GLOBALS["VERBOSE"]) { if ($time < 1440) { $unix->events(__FILE__ . "::" . __FUNCTION__ . " {$time}Mn wait 1440Mn, aborting"); return; } } $mysqlcheck_logs = ""; @unlink("/etc/artica-postfix/mysql.optimize.time"); @file_put_contents("/etc/artica-postfix/mysql.optimize.time", "#"); if (is_file($mysqlcheck)) { exec("{$mysqlcheck} -A -1 2>&1", $mysqlcheck_array); $mysqlcheck_logs = $mysqlcheck_logs . "\n" . @implode("\n", $mysqlcheck_array); unset($mysqlcheck_array); } $q = new mysql(); $sql = "SHOW TABLES"; $results = $q->QUERY_SQL($sql, "artica_backup"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $table = $ligne["Tables_in_artica_backup"]; $tt = time(); if (is_file($mysqlcheck)) { exec("{$mysqlcheck} -r artica_backup {$table} 2>&1", $mysqlcheck_array); $mysqlcheck_logs = $mysqlcheck_logs . "\n" . @implode("\n", $mysqlcheck_array); unset($mysqlcheck_array); } echo $table . "\n"; if (is_file($myisamchk)) { shell_exec("{$myisamchk} -r --safe-recover --force /var/lib/mysql/artica_backup/{$table}"); } else { $q->REPAIR_TABLE("artica_backup", $table); } $q->QUERY_SQL("OPTIMIZE table {$table}", "artica_backup"); $time_duration = distanceOfTimeInWords($tt, time()); $p[] = "artica_backup/{$table} {$time_duration}"; } $sql = "SHOW TABLES"; $results = $q->QUERY_SQL($sql, "artica_events"); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $table = $ligne["Tables_in_artica_events"]; $tt = time(); echo "Repair & optimize {$table}\n"; if (is_file($mysqlcheck)) { exec("{$mysqlcheck} -r artica_events {$table} 2>&1", $mysqlcheck_array); $mysqlcheck_logs = $mysqlcheck_logs . "\n" . @implode("\n", $mysqlcheck_array); unset($mysqlcheck_array); } if (is_file($myisamchk)) { shell_exec("{$myisamchk} -r --safe-recover --force /var/lib/mysql/artica_events/{$table}"); } else { $q->REPAIR_TABLE("artica_events", $table); } $q->QUERY_SQL("OPTIMIZE table {$table}", "artica_events"); $time_duration = distanceOfTimeInWords($tt, time()); $p[] = "artica_events/{$table} {$time_duration}"; } $t2 = time(); $time_duration = distanceOfTimeInWords($time1, $t2); send_email_events("Maintenance on databases artica_backup & artica_events done {$time_duration}", "Operations has be proceed on \n" . @implode("\n", $p) . "\nmysqlchecks results:\n{$mysqlcheck_logs}", "system"); }
function ngx_mail_events($text, $line) { $unix = new unix(); $unix->events($text, "/var/log/artica-proxy-mail.log", false, "MAIN", $line); }
function ParseLoadQeues() { $unix = new unix(); $du = $unix->find_program("du"); $rm = $unix->find_program("rm"); $EXEC_NICE = EXEC_NICE(); exec("{$EXEC_NICE}{$du} -b -s /etc/artica-postfix/loadavg.queue 2>&1", $results); $tmp = trim(@implode("", $results)); if (preg_match("#[0-9]+\\s+#", $tmp, $re)) { $size = $re[1] / 1024; $size = $size / 1000; if ($size > 100) { shell_exec("/bin/rm -rf /etc/artica-postfix/loadavg.queue/*"); return; } } if (!is_dir('/etc/artica-postfix/loadavg.queue')) { @mkdir("/etc/artica-postfix/loadavg.queue", true); } if ($handle = opendir("/etc/artica-postfix/loadavg.queue")) { while (false !== ($file = readdir($handle))) { if ($file == "." && $file == "..") { continue; } $filename = "/etc/artica-postfix/loadavg.queue/{$file}"; $filebase = basename($filename); if ($GLOBALS["VERBOSE"]) { echo "parse {$filename}\n"; } sleep(1); if (preg_match("#^([0-9]+)\\.([0-9]+)\\.queue\$#", $filebase, $re)) { $filebase = "{$re[1]}.{$re[2]}.0.queue"; } if (preg_match("#([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.queue\$#", $filebase, $re)) { if (system_is_overloaded()) { $unix->events(basename(__FILE__) . ": ParseLoadQeues() system is overloaded aborting for {$filename}"); return; } $datas = loadavg_table($filename, $lsof); if (is_file("{$filename}.lsof")) { $lsofTEXT = ParseLsof("{$filename}.lsof"); @unlink("{$filename}.lsof"); } else { if ($GLOBALS["VERBOSE"]) { echo "{$filename}.lsof no such file\n"; } } if (is_file("{$filename}.iotop")) { $IoText = ParseIotOp("{$filename}.lsof"); @unlink("{$filename}.iotop"); } else { if ($GLOBALS["VERBOSE"]) { echo "{$filename}.iotop no such file\n"; } } $time = date("Y-m-d H:i:s", $re[1]); $load = "{$re[2]},{$re[3]}"; $q = new mysql(); $datas = mysql_escape_string2($datas); $lsofTEXT = mysql_escape_string2($lsofTEXT); $IoText = mysql_escape_string2($IoText); $sql = "INSERT IGNORE INTO avgreports (`zDate`,`loadavg`,`psreport`,`lsofreport`,`iotopreport`) VALUES ('{$time}','{$load}','{$datas}','{$lsofTEXT}','{$IoText}')"; $q->QUERY_SQL($sql, "artica_events"); if ($GLOBALS["VERBOSE"]) { echo "{$time}: {$load}\n"; } $unix->send_email_events("System Load - {$load} - exceed rule (processes)", $datas, "system", $time); if (strlen($lsofTEXT) > 50) { $unix->send_email_events("System Load - {$load} - exceed rule (opened files)", $lsofTEXT, "system", $time); } if (strlen($IoText) > 50) { $unix->send_email_events("System Load - {$load} - exceed rule (Disk perfs)", $IoText, "system", $time); } @unlink($filename); } else { echo "{$filebase} did not match ([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.queue\n"; @unlink($filename); } } } }
function updater_events($text, $sourcefunction = null, $sourceline = 0) { if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefile = basename($trace[1]["file"]); if ($sourcefunction == null) { $sourcefunction = $trace[1]["function"]; } if ($sourceline == 0) { $sourceline = $trace[1]["line"]; } } } $unix = new unix(); $unix->events("{$text}", "/var/log/artica.updater.log", false, $sourcefunction, $sourceline, $sourcefile); }
function events($text) { if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefile = basename($trace[1]["file"]); $sourcefunction = $trace[1]["function"]; $sourceline = $trace[1]["line"]; } else { if (isset($trace[0])) { $sourcefile = basename($trace[0]["file"]); $sourcefunction = $trace[0]["function"]; $sourceline = $trace[0]["line"]; } } } $unix = new unix(); if ($GLOBALS["OUTPUT"]) { echo "{$text}\n"; } $unix->events($text, "/var/log/squid.activedirectory-watchdog.log", false, $sourcefunction, $sourceline); }
function ufdbevents($text = null) { $unix = new unix(); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[0])) { $file = basename($trace[0]["file"]); $function = $trace[0]["function"]; $line = $trace[0]["line"]; } } if ($GLOBALS["OUTPUT"]) { echo "{$text} [{$line}]\n"; } $unix->events($text, "/var/log/artica-ufdb.log", false, $function, $line, $file); }
function xmeta_events($text, $function, $file, $line) { $unix = new unix(); $unix->events($text, "/var/log/artica-meta.log", false, $function, $line, $file); }
function send_notifications($subject, $content) { if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . "\n"; } $unix = new unix(); $sock = new sockets(); $ArticaMetaSMTPNotifs = unserialize(base64_decode($sock->GET_INFO("ArticaMetaSMTPNotifs"))); include_once dirname(__FILE__) . '/ressources/class.mail.inc'; include_once dirname(__FILE__) . "/ressources/smtp/class.phpmailer.inc"; $users = new usersMenus(); $smtp_dest = $ArticaMetaSMTPNotifs["smtp_dest"]; $smtp_sender = $ArticaMetaSMTPNotifs["smtp_sender"]; if ($smtp_dest == null) { return; } if ($smtp_sender == null) { $users = new usersMenus(); $smtp_sender = "artica-meta@{$users->hostname}"; } if (!isset($ArticaMetaSMTPNotifs["ssl_enabled"])) { $ArticaMetaSMTPNotifs["ssl_enabled"] = 0; } $text = str_replace("\n", "\r\n", $content); $mail = new PHPMailer(true); $mail->IsSMTP(); $mail->AddAddress($smtp_dest, $smtp_dest); $mail->AddReplyTo($smtp_sender, $smtp_sender); $mail->From = $smtp_sender; $mail->Subject = $subject; $mail->Body = $text; $mail->Host = $ArticaMetaSMTPNotifs["smtp_server_name"]; $mail->Port = $ArticaMetaSMTPNotifs["smtp_server_port"]; if ($ArticaMetaSMTPNotifs["smtp_auth_user"] != null && $ArticaMetaSMTPNotifs["smtp_auth_passwd"] != null) { $mail->SMTPAuth = true; $mail->Username = $ArticaMetaSMTPNotifs["smtp_auth_user"]; $mail->Password = $ArticaMetaSMTPNotifs["smtp_auth_passwd"]; if ($ArticaMetaSMTPNotifs["tls_enabled"] == 1) { $mail->SMTPSecure = 'tls'; } if ($ArticaMetaSMTPNotifs["ssl_enabled"] == 1) { $mail->SMTPSecure = 'ssl'; } } if ($mail->Send()) { if ($GLOBALS["VERBOSE"]) { echo " ************ SUCCESS *************\n"; } $unix->events("SMTP SEND From <{$smtp_sender}> to <{$smtp_dest}> {$subject}", "/var/log/meta.smtp.log", false, __FUNCTION__, __LINE__, __FILE__); return true; } else { $unix->events("SMTP FAILED From <{$smtp_sender}> to <{$smtp_dest}> {$subject}", "/var/log/meta.smtp.log", false, __FUNCTION__, __LINE__, __FILE__); if ($GLOBALS["VERBOSE"]) { echo " ************ !!! FAILED !!! *************\n"; } } return false; }
function maintenance($force = false) { $unix = new unix(); $time = $unix->file_time_min("/etc/artica-postfix/mysql.optimize.time"); $time1 = time(); $myisamchk = $unix->find_program("myisamchk"); $mysqlcheck = $unix->find_program("mysqlcheck"); $myisamchk = $unix->find_program("myisamchk"); $pgrep = $unix->find_program("pgrep"); exec("{$pgrep} -l -f \"{$myisamchk}\"", $results); while (list($index, $line) = each($results)) { if (preg_match("#pgrep#", $line)) { continue; } if (preg_match("#^[0-9]+\\s+#", $line)) { writelogs("{$line} already executed", @implode("\r\n", $results), __FUNCTION__, __FILE__, __LINE__); return; } } if (!$force) { if (!$GLOBALS["VERBOSE"]) { if ($time < 1440) { $unix->events("Maintenance on aborting {$time}Mn wait 1440Mn minimal"); system_admin_events("Maintenance on aborting {$time}Mn wait 1440Mn minimal", __FUNCTION__, __FILE__, __LINE__, "mysql"); return; } } } @unlink("/etc/artica-postfix/mysql.optimize.time"); @file_put_contents("/etc/artica-postfix/mysql.optimize.time", "#"); if (is_file($mysqlcheck)) { exec("{$mysqlcheck} -A -1 2>&1", $mysqlcheck_array); $mysqlcheck_logs = $mysqlcheck_logs . "\n" . @implode("\n", $mysqlcheck_array); unset($mysqlcheck_array); } $q = new mysql(); $DATAS = $q->DATABASE_LIST(); if ($GLOBALS["VERBOSE"]) { echo "Maintenance on " . count($DATAS) . " databases starting...\n"; } while (list($db, $ligne) = each($DATAS)) { _repair_database($db); } $t2 = time(); $time_duration = distanceOfTimeInWords($time1, $t2); system_admin_events("Maintenance on " . count($DATAS) . " databases done tool:{$time_duration}\nMysql Check events:{$mysqlcheck_logs}", __FUNCTION__, __FILE__, __LINE__, "mysql"); }
function ArticaMeta_events($subject) { // 0 -> RED, 1 -> WARN, 2 -> INFO 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"]; } } $unix = new unix(); $unix->events($subject, "/var/log/artica-metaserver-update.log", false, $function, $line, $file); }
function ParseLoadQeues(){ $unix=new unix(); foreach (glob("/etc/artica-postfix/loadavg.queue/*.queue") as $filename) { $filebase=basename($filename); if($GLOBALS["VERBOSE"]){echo "parse $filename\n";} if(preg_match("#^([0-9]+)\.([0-9]+)\.queue$#",$filebase,$re)){$filebase="{$re[1]}.{$re[2]}.0.queue";} if(preg_match("#([0-9]+)\.([0-9]+)\.([0-9]+)\.queue$#",$filebase,$re)){ if(system_is_overloaded()){ $unix->events(basename(__FILE__).": ParseLoadQeues() system is overloaded aborting for $filename"); return; } if(is_file("$filename.lsof")){ $lsofTEXT=ParseLsof("$filename.lsof"); @unlink("$filename.lsof"); }else{ if($GLOBALS["VERBOSE"]){echo "$filename.lsof no such file\n";} } $time=date("Y-m-d H:i:s",$re[1]); $load="{$re[2]}.{$re[3]}"; if($GLOBALS["VERBOSE"]){echo "$time: $load\n";} $datas=loadavg_table($filename,$lsof); $unix->send_email_events("System Load - $load - exceed rule (processes)",$datas,"system",$time); if(strlen($lsofTEXT)>50){ $unix->send_email_events("System Load - $load - exceed rule (opened files)",$lsofTEXT,"system",$time); } @unlink($filename); }else{ echo "$filebase did not match ([0-9]+)\.([0-9]+)\.([0-9]+)\.queue\n"; } } }
function events($text, $line = 0) { $unix = new unix(); $unix->events($text, "/var/log/seeker.log", false, "MAIN", $line, basename(__FILE__)); }
function writeprogress($perc, $text) { $GLOBALS["PROGRESS_FILE"] = "/usr/share/artica-postfix/ressources/logs/web/wizard.progress"; $array["POURC"] = $perc; $array["TEXT"] = "{set_permissions} {$text}"; echo "{$text}\n"; @mkdir("/usr/share/artica-postfix/ressources/logs/web", true, 0755); @file_put_contents($GLOBALS["PROGRESS_FILE"], serialize($array)); @chmod($GLOBALS["PROGRESS_FILE"], 0755); $unix = new unix(); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefile = basename($trace[1]["file"]); $sourcefunction = $trace[1]["function"]; $sourceline = $trace[1]["line"]; } } $unix->events("{$perc}} {$text}", "/var/log/artica-wizard.log", $sourcefunction, $sourceline, $sourcefile); }
function squid_watchdog_events($text) { $unix = new unix(); if (function_exists("debug_backtrace")) { $trace = debug_backtrace(); if (isset($trace[1])) { $sourcefile = basename($trace[1]["file"]); $sourcefunction = $trace[1]["function"]; $sourceline = $trace[1]["line"]; } } $unix->events($text, "/var/log/squid.watchdog.log", false, $sourcefunction, $sourceline); }
function ParseLoadQeues() { $unix = new unix(); $du = $unix->find_program("du"); $rm = $unix->find_program("rm"); exec("{$du} -b -s /etc/artica-postfix/loadavg.queue 2>&1", $results); $tmp = trim(@implode("", $results)); if (preg_match("#[0-9]+\\s+#", $results, $re)) { $size = $re[1] / 1024; $size = $size / 1000; if ($size > 100) { shell_exec("/bin/rm -rf /etc/artica-postfix/loadavg.queue/*"); return; } } if ($handle = opendir("/etc/artica-postfix/loadavg.queue")) { while (false !== ($file = readdir($handle))) { if ($file == "." && $file == "..") { continue; } $filename = "/etc/artica-postfix/loadavg.queue/{$file}"; $filebase = basename($filename); if ($GLOBALS["VERBOSE"]) { echo "parse {$filename}\n"; } if (preg_match("#^([0-9]+)\\.([0-9]+)\\.queue\$#", $filebase, $re)) { $filebase = "{$re[1]}.{$re[2]}.0.queue"; } if (preg_match("#([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.queue\$#", $filebase, $re)) { if (system_is_overloaded()) { $unix->events(basename(__FILE__) . ": ParseLoadQeues() system is overloaded aborting for {$filename}"); return; } if (is_file("{$filename}.lsof")) { $lsofTEXT = ParseLsof("{$filename}.lsof"); @unlink("{$filename}.lsof"); } else { if ($GLOBALS["VERBOSE"]) { echo "{$filename}.lsof no such file\n"; } } $time = date("Y-m-d H:i:s", $re[1]); $load = "{$re[2]}.{$re[3]}"; if ($GLOBALS["VERBOSE"]) { echo "{$time}: {$load}\n"; } $datas = loadavg_table($filename, $lsof); $unix->send_email_events("System Load - {$load} - exceed rule (processes)", $datas, "system", $time); if (strlen($lsofTEXT) > 50) { $unix->send_email_events("System Load - {$load} - exceed rule (opened files)", $lsofTEXT, "system", $time); } @unlink($filename); } else { echo "{$filebase} did not match ([0-9]+)\\.([0-9]+)\\.([0-9]+)\\.queue\n"; @unlink($filename); } } } }