function uninstall() { $unix = new unix(); $sock = new sockets(); build_progress("{uninstall}", 15); $pid = sealion_pid(); if ($unix->process_exists($pid)) { for ($i = 0; $i < 6; $i++) { build_progress("{stop_service} {$i}/5", 30); $unix->KILL_PROCESS($pid, 9); $pid = sealion_pid(); if ($unix->process_exists($pid)) { break; } } } build_progress("{uninstall}", 50); chdir("/usr/local/sealion-agent"); system("cd /usr/local/sealion-agent"); system("./uninstall.sh"); chdir("/root"); system("cd /root"); $unix = new unix(); $rm = $unix->find_program("rm"); if (is_dir("/usr/local/sealion-agent")) { shell_exec("rm -rf /usr/local/sealion-agent"); } build_progress("{uninstall} {done}", 100); }
function reload() { $unix = new unix(); $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 "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}: Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); $pid = PID_NUM(); if (!$unix->process_exists($pid)) { start(true); return; } buildconfig(); BuildSSLTables(); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}: Reloading PID {$pid}\n"; } $unix->KILL_PROCESS($pid, 1); }
function KillSquid() { $unix = new unix(); $pidof = $unix->find_program("pidof"); $kill = $unix->find_program("kill"); if (strlen($pidof) < 4) { return; } exec("{$pidof} {$GLOBALS["SQUIDBIN"]}", $results); $f = explode(" ", @implode("", $results)); while (list($num, $val) = each($f)) { $val = trim($val); if (!is_numeric($val)) { continue; } echo "Starting......: " . date("H:i:s") . " stopping pid {$val}\n"; $unix->KILL_PROCESS($val, 9); usleep(10000); } }
function repair_locks() { $Myfile = basename(__FILE__); $timeFile = "/etc/artica-postfix/pids/{$Myfile}." . __FUNCTION__ . ".time"; $pidFile = "/etc/artica-postfix/pids/{$Myfile}." . __FUNCTION__ . ".pid"; $unix = new unix(); $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid, $Myfile)) { writelogs("Die, already process {$pid} running ", __FUNCTION__, __FILE__, __LINE__); return; } $time = $unix->file_time_min($timeFile); if ($time < 5) { writelogs("Die, No more than 5mn ", __FUNCTION__, __FILE__, __LINE__); return; } @unlink($timeFile); @mkdir(dirname($timeFile), 0755, true); @file_put_contents($timeFile, time()); @file_put_contents($pidFile, getmypid()); echo "Starting......: " . date("H:i:s") . " Stopping postfix\n"; shell_exec("{$GLOBALS["postfix"]} stop"); $daemon_directory = $unix->POSTCONF_GET("daemon_directory"); $queue_directory = $unix->POSTCONF_GET("queue_directory"); echo "Starting......: " . date("H:i:s") . " Daemon directory: {$daemon_directory}\n"; echo "Starting......: " . date("H:i:s") . " Queue directory.: {$queue_directory}\n"; $pid = $unix->PIDOF("{$daemon_directory}/master", true); echo "Starting......: " . date("H:i:s") . " Process \"{$daemon_directory}/master\" PID:\"{$pid}\"\n"; for ($i = 0; $i < 10; $i++) { if (is_numeric($pid)) { if ($pid > 5) { echo "Starting......: " . date("H:i:s") . " Killing bad pid {$pid}\n"; $unix->KILL_PROCESS($pid, 9); sleep(1); } } else { echo "Starting......: " . date("H:i:s") . " No {$daemon_directory}/master ghost process\n"; break; } $pid = $unix->PIDOF("{$daemon_directory}/master"); echo "Starting......: " . date("H:i:s") . " Process \"{$daemon_directory}/master\" PID:\"{$pid}\"\n"; } if (file_exists("{$daemon_directory}/master.lock")) { echo "Starting......: " . date("H:i:s") . " Delete {$daemon_directory}/master.lock\n"; @unlink("{$daemon_directory}/master.lock"); } if (file_exists("{$queue_directory}/pid/master.pid")) { echo "Starting......: " . date("H:i:s") . " Delete {$queue_directory}/pid/master.pid\n"; @unlink("{$queue_directory}/pid/master.pid"); } if (file_exists("{$queue_directory}/pid/inet.127.0.0.1:33559")) { echo "Starting......: " . date("H:i:s") . " {$queue_directory}/pid/inet.127.0.0.1:33559\n"; @unlink("{$queue_directory}/pid/inet.127.0.0.1:33559"); } echo "Starting......: " . date("H:i:s") . " Starting postfix\n"; exec("{$GLOBALS["postfix"]} start -v 2>&1", $results); while (list($template, $nothing) = each($results)) { echo "Starting......: " . date("H:i:s") . " Starting postfix {$nothing}\n"; } }
function mQuotaWebFilter() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.hours.php.mQuotaWebFilter.pid"; $timefile = "/etc/artica-postfix/pids/exec.squid.stats.hours.php.mQuotaWebFilter.time"; $sock = new sockets(); $SquidPerformance = intval($sock->GET_INFO("SquidPerformance")); if ($SquidPerformance > 1) { die; } $pid = $unix->get_pid_from_file($pidfile); if (!$GLOBALS["FORCE"]) { if ($pid < 100) { $pid = null; } $unix = new unix(); if ($unix->process_exists($pid, basename(__FILE__))) { $rpcessTime = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "Already executed pid {$pid} since {$rpcessTime}Mn\n"; } if ($rpcessTime < 10) { return; } $unix->KILL_PROCESS($pid, 9); } $timeexec = $unix->file_time_min($timefile); if ($timeexec < 30) { return; } $mypid = getmypid(); @file_put_contents($pidfile, $mypid); } build_last_hour(); $ipClass = new IP(); if ($GLOBALS["VERBOSE"]) { echo "Time File: {$timefile}\n"; } $ARRAY["TIME_BUILD"] = time(); $q = new mysql_squid_builder(); $influx = new influx(); $date_from = InfluxQueryFromUTC(strtotime("-1 hour")); $sql = "SELECT SUM(SIZE) as size,USERID,IPADDR,MAC,CATEGORY FROM access_log GROUP BY time(1h) ,USERID,IPADDR,MAC,CATEGORY WHERE time > {$date_from}s"; if ($GLOBALS["VERBOSE"]) { echo "{$sql}\n"; } $main = $influx->QUERY_SQL($sql); foreach ($main as $row) { $CATEGORY = $row->CATEGORY; $USERID = strtolower($row->USERID); $IPADDR = $row->IPADDR; $MAC = $row->MAC; $size = intval($row->size); if ($size == 0) { continue; } if ($CATEGORY != null) { if (!isset($ARRAY["categories"][$CATEGORY]["HOUR"][$USERID])) { $ARRAY["categories"][$CATEGORY]["HOUR"][$USERID] = $size; } else { $size_old = intval($ARRAY["categories"][$CATEGORY]["HOUR"][$USERID]); $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["HOUR"][$USERID] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["HOUR"][$IPADDR])) { $ARRAY["categories"][$CATEGORY]["HOUR"][$IPADDR] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["HOUR"][$IPADDR]; $size_old = $size_old + $size; if ($size_old == 0) { echo "Warning {$CATEGORY}/{$IPADDR} {$ARRAY["categories"][$CATEGORY]["HOUR"][$IPADDR]} + {$size} = 0\n"; } $ARRAY["categories"][$CATEGORY]["HOUR"][$IPADDR] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["HOUR"][$MAC])) { $ARRAY["categories"][$CATEGORY]["HOUR"][$MAC] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["HOUR"][$MAC]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["HOUR"][$MAC] = $size_old; } } if (!isset($ARRAY["UID"][$USERID]["HOUR"])) { $ARRAY["UID"][$USERID]["HOUR"] = $size; } else { $size_old = $ARRAY["UID"][$USERID]["HOUR"]; $size_old = $size_old + $size; $ARRAY["UID"][$USERID]["HOUR"] = $size_old; } if (!isset($ARRAY["IPADDR"][$IPADDR]["HOUR"])) { $ARRAY["IPADDR"][$IPADDR]["HOUR"] = $size; } else { $size_old = $ARRAY["IPADDR"][$IPADDR]["HOUR"]; $size_old = $size_old + $size; $ARRAY["IPADDR"][$IPADDR]["HOUR"] = $size_old; } if ($ipClass->IsvalidMAC($MAC)) { if (!isset($ARRAY["MAC"][$MAC]["HOUR"])) { $ARRAY["MAC"][$MAC]["HOUR"] = $size; } else { $size_old = $ARRAY["MAC"][$MAC]["HOUR"]; $size_old = $size_old + $size; $ARRAY["MAC"][$MAC]["HOUR"] = $size_old; } } } //----------------------------------------------------------------------------------------------- $date_from = InfluxQueryFromUTC(strtotime("-1 day")); $sql = "SELECT SUM(SIZE) as size,USERID,IPADDR,MAC,CATEGORY FROM access_hour GROUP BY time(1d) ,USERID,IPADDR,MAC,CATEGORY WHERE time > {$date_from}s"; if ($GLOBALS["VERBOSE"]) { echo "{$sql}\n"; } $main = $influx->QUERY_SQL($sql); foreach ($main as $row) { $CATEGORY = $row->CATEGORY; $USERID = strtolower($row->USERID); $IPADDR = $row->IPADDR; $MAC = $row->MAC; $size = intval($row->size); if ($size == 0) { continue; } if ($CATEGORY != null) { if (!isset($ARRAY["categories"][$CATEGORY]["DAY"][$USERID])) { $ARRAY["categories"][$CATEGORY]["DAY"][$USERID] = $size; } else { $size_old = intval($ARRAY["categories"][$CATEGORY]["DAY"][$USERID]); $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["DAY"][$USERID] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["DAY"][$IPADDR])) { $ARRAY["categories"][$CATEGORY]["DAY"][$IPADDR] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["DAY"][$IPADDR]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["DAY"][$IPADDR] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["DAY"][$MAC])) { $ARRAY["categories"][$CATEGORY]["DAY"][$MAC] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["DAY"][$MAC]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["DAY"][$MAC] = $size_old; } } if (!isset($ARRAY["UID"][$USERID]["DAY"])) { $ARRAY["UID"][$USERID]["DAY"] = $size; } else { $size_old = $ARRAY["UID"][$USERID]["DAY"]; $size_old = $size_old + $size; $ARRAY["UID"][$USERID]["DAY"] = $size_old; } if (!isset($ARRAY["IPADDR"][$IPADDR]["DAY"])) { $ARRAY["IPADDR"][$IPADDR]["DAY"] = $size; } else { $size_old = $ARRAY["IPADDR"][$IPADDR]["DAY"]; $size_old = $size_old + $size; $ARRAY["IPADDR"][$IPADDR]["DAY"] = $size_old; } if ($ipClass->IsvalidMAC($MAC)) { if (!isset($ARRAY["MAC"][$MAC]["DAY"])) { $ARRAY["MAC"][$MAC]["DAY"] = $size; } else { $size_old = $ARRAY["MAC"][$MAC]["DAY"]; $size_old = $size_old + $size; $ARRAY["MAC"][$MAC]["DAY"] = $size_old; } } } //----------------------------------------------------------------------------------------------- $influx = new influx(); $date_from = strtotime("-1 week"); $sql = "SELECT SUM(SIZE) as size,USERID,IPADDR,MAC,CATEGORY FROM access_hour GROUP BY time(1w) ,USERID,IPADDR,MAC,CATEGORY WHERE time > {$date_from}s"; $main = $influx->QUERY_SQL($sql); foreach ($main as $row) { $CATEGORY = $row->CATEGORY; $USERID = strtolower($row->USERID); $IPADDR = $row->IPADDR; $MAC = $row->MAC; $size = intval($row->size); if ($size == 0) { continue; } if ($CATEGORY != null) { if (!isset($ARRAY["categories"][$CATEGORY]["WEEK"][$USERID])) { $ARRAY["categories"][$CATEGORY]["WEEK"][$USERID] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["WEEK"][$USERID]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["WEEK"][$USERID] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["WEEK"][$IPADDR])) { $ARRAY["categories"][$CATEGORY]["WEEK"][$IPADDR] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["WEEK"][$IPADDR]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["WEEK"][$IPADDR] = $size_old; } if (!isset($ARRAY["categories"][$CATEGORY]["WEEK"][$MAC])) { $ARRAY["categories"][$CATEGORY]["WEEK"][$MAC] = $size; } else { $size_old = $ARRAY["categories"][$CATEGORY]["WEEK"][$MAC]; $size_old = $size_old + $size; $ARRAY["categories"][$CATEGORY]["WEEK"][$MAC] = $size_old; } } if ($USERID != null) { if (!isset($ARRAY["UID"][$USERID]["WEEK"])) { $ARRAY["UID"][$USERID]["WEEK"] = $size; } else { $size_old = $ARRAY["UID"][$USERID]["WEEK"]; $size_old = $size_old + $size; $ARRAY["UID"][$USERID]["WEEK"] = $size_old; } } if ($ipClass->isValid($IPADDR)) { if (!isset($ARRAY["IPADDR"][$IPADDR]["WEEK"])) { $ARRAY["IPADDR"][$IPADDR]["IPADDR"] = $size; } else { $size_old = $ARRAY["IPADDR"][$IPADDR]["WEEK"]; $size_old = $size_old + $size; $ARRAY["IPADDR"][$IPADDR]["WEEK"] = $size_old; } } if ($ipClass->IsvalidMAC($MAC)) { if (!isset($ARRAY["MAC"][$MAC]["WEEK"])) { $ARRAY["MAC"][$MAC]["WEEK"] = $size; } else { $size_old = $ARRAY["MAC"][$MAC]["WEEK"]; $size_old = $size_old + $size; $ARRAY["MAC"][$MAC]["WEEK"] = $size_old; } } } //----------------------------------------------------------------------------------------------- if ($GLOBALS["VERBOSE"]) { print_r($ARRAY); } @unlink("/usr/share/squid3/CurrentSizesUsers.db"); @file_put_contents("/usr/share/squid3/CurrentSizesUsers.db", serialize($ARRAY)); @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/CurrentSizesUsers.db", serialize($ARRAY)); @chmod("/usr/share/artica-postfix/ressources/logs/web/CurrentSizesUsers.db", 0755); }
function logs_urgency($aspid = false) { $unix = new unix(); $TimeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $Pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; if ($GLOBALS["VERBOSE"]) { echo "TimeFile: {$TimeFile}\n"; } if ($GLOBALS["VERBOSE"]) { echo "Pidfile: {$Pidfile}\n"; } if (!$GLOBALS["FORCE"]) { $timefile = $unix->file_time_min($TimeFile); if ($timefile < 60) { return; } } if ($aspid) { $pid = $unix->get_pid_from_file($Pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $timeprc = $unix->PROCCESS_TIME_MIN($pid); if ($timeprc > 60) { $unix->KILL_PROCESS($pid, 9); } else { if ($GLOBALS["VERBOSE"]) { echo "Aborting Task already running pid {$pid} " . __FUNCTION__ . "()\n"; } return; } } @file_put_contents($Pidfile, getmypid()); } $df = $unix->find_program("df"); $php = $unix->LOCATE_PHP5_BIN(); exec("{$df} -h /var/log 2>&1", $results); while (list($index, $line) = each($results)) { if (!preg_match("#^(.+?)\\s+([0-9\\.,]+)([A-Z])\\s+([0-9\\.,]+).*?\\s+([0-9\\.,]+)%\\s+#", $line, $re)) { continue; } $purc = $re[5]; break; } if ($purc < 100) { return; } $echo = $unix->find_program("echo"); $logf["artica-router.log"] = true; $logf["artica-smtp.log"] = true; $logf["auth.log"] = true; $logf["daemon.log"] = true; $logf["debug"] = true; $logf["dpkg.log"] = true; $logf["fetchmail.log"] = true; $logf["kern.log"] = true; $logf["mail.err"] = true; $logf["mail.log"] = true; $logf["mail.warn"] = true; $logf["messages"] = true; $logf["syslog"] = true; $logf["user.log"] = true; $logf["lighttpd/access.log"] = true; $logf["squid/store.log"] = true; $logf["apache2/unix-varrunnginx-authenticator.sock/nginx.access.log"] = true; $logf["apache2/unix-varrunnginx-authenticator.sock/nginx.error.log"] = true; $logf["artica-postfix/framework.log"] = true; $logf["samba/log.winbindd"] = true; $logf["samba/log.winbindd.old"] = true; $logf["clamav/clamav.log"] = true; $logf["clamav/clamd.log"] = true; $logf["clamav/freshclam.log"] = true; $sock = new sockets(); $BaseWorkDirUrgency = "/home/artica/squidlogs_urgency"; $LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation"); if (!is_numeric($LogsRotateDefaultSizeRotation)) { $LogsRotateDefaultSizeRotation = 100; } $LogRotatePath = $sock->GET_INFO("LogRotatePath"); if ($LogRotatePath == null) { $LogRotatePath = "/home/logrotate"; } $LogRotatePath = "{$LogRotatePath}/work/cache_logs"; while (list($filname, $line) = each($logf)) { $path = "/var/log/{$filname}"; if (!is_file($path)) { continue; } shell_exec("{$echo} \" \" > {$path} 2>&1"); } }
function build() { $timefile = "/etc/artica-postfix/pids/exec.squid.rotate.php.build.time"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; // /etc/artica-postfix/pids/exec.squid.rotate.php.build.time $sock = new sockets(); $unix = new unix(); $ls = $unix->find_program("ls"); $pid = $unix->PIDOF_PATTERN(basename(__FILE__)); $MyPid = getmypid(); if ($MyPid != $pid) { if ($unix->process_exists($pid)) { $timeFile = $unix->PROCESS_TIME_INT($pid); $pidCmdline = @file_get_contents("/proc/{$pid}/cmdline"); if ($timeFile < 30) { echo "Already PID {$pid} is running since {$timeFile}Mn\n"; squid_admin_mysql(1, "[LOG ROTATION]: Skip task, already running {$pid} since {$timeFile}Mn", "Running: {$pidCmdline}", __FILE__, __LINE__); die; } else { squid_admin_mysql(1, "[LOG ROTATION]: Killing old task {$pid} running more than 30mn ({$timeFile}Mn)", "Running: {$pidCmdline}", __FILE__, __LINE__); $unix->KILL_PROCESS($pid); } } } @file_put_contents($pidfile, getmypid()); if (!$GLOBALS["FORCE"]) { $time = $unix->file_time_min($timefile); if ($time < 60) { echo "Only each 60mn\n"; die; } @unlink($timefile); @file_put_contents($timefile, time()); } $syslog = new mysql_storelogs(); $SquidLogRotateFreq = intval($sock->GET_INFO("SquidLogRotateFreq")); if ($SquidLogRotateFreq < 10) { $SquidLogRotateFreq = 1440; } $LastRotate = $unix->file_time_min("/etc/artica-postfix/pids/squid-rotate-cache.time"); $LogsRotateDefaultSizeRotation = $sock->GET_INFO("LogsRotateDefaultSizeRotation"); $SquidRotateOnlySchedule = intval($sock->GET_INFO("SquidRotateOnlySchedule")); if (!is_numeric($LogsRotateDefaultSizeRotation)) { $LogsRotateDefaultSizeRotation = 100; } $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir"); if ($BackupMaxDaysDir == null) { $BackupMaxDaysDir = "/home/logrotate_backup"; } $BackupSquidLogsUseNas = intval($sock->GET_INFO("BackupSquidLogsUseNas")); $SquidRotateAutomount = intval($sock->GET_INFO("SquidRotateAutomount")); $SquidRotateClean = intval($sock->GET_INFO("SquidRotateClean")); $SquidRotateAutomountRes = $sock->GET_INFO("SquidRotateAutomountRes"); $SquidRotateAutomountFolder = $sock->GET_INFO("SquidRotateAutomountFolder"); if ($SquidRotateAutomount == 1) { shell_exec("{$ls} /automounts/{$SquidRotateAutomountRes} >/dev/null 2>&1"); if (ifdirMounted("/automounts/{$SquidRotateAutomountRes}")) { $BackupSquidLogsUseNas = 0; $BackupMaxDaysDir = "/automounts/{$SquidRotateAutomountRes}/{$SquidRotateAutomountFolder}"; } else { $syslog->events("/automounts/{$SquidRotateAutomountRes} not mounted", __FUNCTION__, __LINE__); squid_admin_mysql(1, "[ROTATE],Auto-mount {$SquidRotateAutomountRes} not mounted", null, __FILE__, __LINE__); } } $BackupMaxDaysDir = str_replace("//", "/", $BackupMaxDaysDir); $BackupMaxDaysDir = str_replace("\\", "/", $BackupMaxDaysDir); if (!is_dir($BackupMaxDaysDir)) { @mkdir($BackupMaxDaysDir, 0755, true); } if (!is_dir($BackupMaxDaysDir)) { $syslog->events("{$BackupMaxDaysDir} not such directory or permission denied", __FUNCTION__, __LINE__); squid_admin_mysql(1, "[ROTATE],{$BackupMaxDaysDir} not such directory or permission denied", null, __FILE__, __LINE__); if ($SquidRotateAutomount == 1) { $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir"); if ($BackupMaxDaysDir == null) { $BackupMaxDaysDir = "/home/logrotate_backup"; } if (!is_dir($BackupMaxDaysDir)) { @mkdir($BackupMaxDaysDir, 0755, true); } $syslog->events("Return back to {$BackupMaxDaysDir}", __FUNCTION__, __LINE__); } else { return; } } $php = $unix->LOCATE_PHP5_BIN(); $hostname = $unix->hostname_g(); $InFluxBackupDatabaseDir = $sock->GET_INFO("InFluxBackupDatabaseDir"); if ($InFluxBackupDatabaseDir == null) { $InFluxBackupDatabaseDir = "/home/artica/influx/backup"; } $LogRotatePath = $sock->GET_INFO("LogRotatePath"); if ($LogRotatePath == null) { $LogRotatePath = "/home/logrotate"; } $LogRotateAccess = "{$LogRotatePath}/access"; $LogRotateTail = "{$LogRotatePath}/tail"; $LogRotateCache = "{$LogRotatePath}/cache"; $syslog->events("Launch rotation only by schedule.: {$SquidRotateOnlySchedule}", __FUNCTION__, __LINE__); $syslog->events("SquidLogRotateFreq...............: {$SquidLogRotateFreq}Mn", __FUNCTION__, __LINE__); $syslog->events("LastRotate.......................: {$LastRotate}Mn", __FUNCTION__, __LINE__); $syslog->events("Working directory................: {$LogRotatePath}", __FUNCTION__, __LINE__); $syslog->events("Launch rotation when exceed......: {$LogsRotateDefaultSizeRotation}M", __FUNCTION__, __LINE__); $syslog->events("Final storage directory..........: {$BackupMaxDaysDir}", __FUNCTION__, __LINE__); $syslog->events("Backup files to a NAS............: {$BackupSquidLogsUseNas}", __FUNCTION__, __LINE__); ss5_log($BackupMaxDaysDir); if ($handle = opendir("/var/run/squid")) { while (false !== ($file = readdir($handle))) { if ($file == ".") { continue; } if ($file == "..") { continue; } $path = "/var/run/squid/{$file}"; if (preg_match("#\\.[0-9]+\\.status\$#", $file)) { $time = $unix->file_time_min($path); if ($time > 1440) { $syslog->events("Removing {$path}", __FUNCTION__, __LINE__); @unlink($path); } continue; } if (preg_match("#\\.[0-9]+\\.state\$#", $file)) { $time = $unix->file_time_min($path); if ($time > 1440) { $syslog->events("Removing {$path}", __FUNCTION__, __LINE__); @unlink($path); } continue; } } } $size = @filesize("/var/log/squid/access.log"); $size = $size / 1024; $size = $size / 1024; $syslog->events("/var/log/squid/access.log........: {$size}M", __FUNCTION__, __LINE__); $syslog->events("Analyze /var/log/squid directory for cache.log", __FUNCTION__, __LINE__); if (!($handle = opendir("/var/log/squid"))) { build_progress_rotation("Unable to open /var/log/squid", 110); $syslog->events("Unable to open /var/log/squid directory.", __FUNCTION__, __LINE__); return; } build_progress_rotation("Scanning /var/log/squid", 40); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $path = "/var/log/squid/{$file}"; if (is_dir($path)) { continue; } if (!preg_match("#^cache\\.log\\.[0-9]+\$#", $file)) { continue; } @mkdir("{$LogRotateCache}", 0755, true); $size = @filesize($path); $size = $size / 1024; $size = $size / 1024; $destfile = "{$LogRotateCache}/{$file}." . time() . ".log"; if (!@copy($path, $destfile)) { $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__); @unlink($destfile); continue; } $syslog->events("Removed {$path}", __FUNCTION__, __LINE__); @unlink($path); } } $syslog->events("Analyze /var/log/squid directory for access.log", __FUNCTION__, __LINE__); if (!($handle = opendir("/var/log/squid"))) { $syslog->events("Unable to open /var/log/squid directory.", __FUNCTION__, __LINE__); return; } @mkdir($LogRotateAccess, 0755, true); @mkdir($LogRotateTail, 0755, true); while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $path = "/var/log/squid/{$file}"; if (is_dir($path)) { continue; } if (preg_match("#^childs-access\\.log\\.[0-9]+\$#", $file)) { $destfile = "{$LogRotateAccess}/{$file}." . time() . ".log"; if (!@copy($path, $destfile)) { $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__); @unlink($destfile); continue; } $syslog->events("Removed {$path}", __FUNCTION__, __LINE__); @unlink($path); continue; } $syslog->events("Analyze {$file} ^squidtail\\.log\\.[0-9]+\$", __FUNCTION__, __LINE__); if (preg_match("#^squidtail\\.log\\.[0-9]+\$#", $file)) { $destfile = "{$LogRotateTail}/{$file}"; if (!@copy($path, $destfile)) { $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__); @unlink($destfile); continue; } $syslog->events("Removed {$path}", __FUNCTION__, __LINE__); @unlink($path); continue; } $syslog->events("Analyze {$file} ^access\\.log\\.[0-9]+\$", __FUNCTION__, __LINE__); if (!preg_match("#^access\\.log\\.[0-9]+\$#", $file)) { continue; } @mkdir("{$LogRotatePath}", 0755, true); $destfile = "{$LogRotateAccess}/{$file}." . time() . ".log"; if (!@copy($path, $destfile)) { $syslog->events("Unable to copy {$path} to {$destfile}", __FUNCTION__, __LINE__); @unlink($destfile); continue; } $syslog->events("Removed {$path}", __FUNCTION__, __LINE__); @unlink($path); } } $syslog->events("Analyze {$LogRotateAccess} for access.log", __FUNCTION__, __LINE__); if (!($handle = opendir($LogRotateAccess))) { $syslog->events("Unable to open {$LogRotateAccess} directory.", __FUNCTION__, __LINE__); return; } $ROTATED = false; while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $path = "{$LogRotateAccess}/{$file}"; echo "OPEN {$path}\n"; if (is_dir($path)) { continue; } if (!preg_match("#^access\\.log#", $file)) { continue; } range_fichier_source($path, $BackupMaxDaysDir); $ROTATED = true; } } if ($handle = opendir($LogRotateTail)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $path = "{$LogRotateTail}/{$file}"; echo "OPEN {$path}\n"; if (is_dir($path)) { continue; } if (!preg_match("#^squidtail\\.log#", $file)) { continue; } range_fichier_tail($path, $BackupMaxDaysDir); $ROTATED = true; } } } if (!$ROTATED) { return; } $q = new mysql(); $sql = "CREATE TABLE IF NOT EXISTS `backuped_logs` (\n\t\t\t `path` CHAR(255) NOT NULL,\n\t\t\t `zDate` DATETIME,\n\t\t\t `size` INT UNSIGNED NOT NULL,\n\t\t\t PRIMARY KEY (`path`),\n\t\t\t KEY `zDate` (`zDate`)\n\t\t\t) ENGINE = MYISAM;"; $q->QUERY_SQL($sql, "artica_events"); $syslog->events("Analyze /home/logrotate/work for access.log", __FUNCTION__, __LINE__); build_progress_rotation("Scanning /home/logrotate/work", 45); analyze_directory("/home/logrotate/work", $BackupMaxDaysDir); $BackupMaxDaysDir2 = $sock->GET_INFO("BackupMaxDaysDir"); if ($BackupMaxDaysDir2 == null) { $BackupMaxDaysDir2 = "/home/logrotate_backup"; } if ($BackupMaxDaysDir2 != $BackupMaxDaysDir) { build_progress_rotation("Scanning {$BackupMaxDaysDir2}", 46); $syslog->events("{$BackupMaxDaysDir2} is different of {$BackupMaxDaysDir}", __FUNCTION__, __LINE__); analyze_directory($BackupMaxDaysDir2, $BackupMaxDaysDir); } build_progress_rotation("Scanning /home/logrotate/merged", 47); analyze_garbage_directory("/home/logrotate/merged", $BackupMaxDaysDir, 1440); build_progress_rotation("Scanning {$LogRotateCache}", 48); analyze_cache_directory($LogRotateCache, $BackupMaxDaysDir); build_progress_rotation("Scanning /home/logrotate/work", 49); analyze_cache_directory("/home/logrotate/work", $BackupMaxDaysDir); build_progress_rotation("Scanning /home/squid/cache-logs", 49); analyze_cache_directory("/home/squid/cache-logs", $BackupMaxDaysDir); if ($GLOBALS["VERBOSE"]) { echo "TRUNCATE TABLE backuped_logs !!!\n"; } $q->QUERY_SQL("TRUNCATE TABLE backuped_logs", "artica_events"); if ($BackupSquidLogsUseNas == 1) { build_progress_rotation("Backup to N.A.S", 50); BackupToNas($BackupMaxDaysDir); build_progress_rotation("Backup to N.A.S BigData backups", 50); BackupToNas($InFluxBackupDatabaseDir, false); } else { build_progress_rotation("Scanning {$BackupMaxDaysDir}", 50); analyze_destination_directory($BackupMaxDaysDir); } @file_put_contents("/etc/artica-postfix/settings/Daemons/BackupMaxDaysDirCurrentSize", $unix->DIRSIZE_KO($BackupMaxDaysDir)); @chmod("/etc/artica-postfix/settings/Daemons/BackupMaxDaysDirCurrentSize", 0777); return; }
function reload_stats() { $unix = new unix(); $sock = new sockets(); $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 "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); $kavicapserverEnabled = intval($sock->GET_INFO("kavicapserverEnabled")); if ($kavicapserverEnabled == 0) { if ($GLOBALS["OUTPUT"]) { echo "Reloading......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Not enabled,stop it\n"; } stop(); return; } $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Not running, start it\n"; } start(); return; } $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} TTL of {$timepid}Mn for statistics\n"; } $unix->KILL_PROCESS($pid, 12); }
echo @implode("\n", $conf); die; } if ($argv[1] == "--functions") { $arr = get_defined_functions(); print_r($arr); die; } if ($argv[1] == "--all-squid") { $unix = new unix(); $processes = $unix->PIDOF_PATTERN_ALL(basename(__FILE__) . ".*?{$argv[1]}", true); events(count($processes) . " Running " . @implode(";", $processes), "{$argv[1]}", __LINE__); if (count($processes) > 2) { while (list($num, $pid) = each($processes)) { events("Killing pid {$pid} ", "MAIN", __LINE__); $unix->KILL_PROCESS($pid, 9); } $processes = $unix->PIDOF_PATTERN_ALL(basename(__FILE__) . ".*?{$argv[1]}", true); events(count($processes) . " Running " . @implode(";", $processes), "{$argv[1]}", __LINE__); } if (count($processes) > 0) { events("ALL_SQUID: Processes already exists, aborting", "{$argv[1]}", __LINE__); die; } $cachefile = "/usr/share/artica-postfix/ressources/databases/ALL_SQUID_STATUS"; $GLOBALS["DISABLE_WATCHDOG"] = true; $TimeFile = $cachefile; if ($GLOBALS["SCHEDULE_ID"] > 0) { if ($unix->file_time_min($TimeFile) > 5) { $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup");
function reload() { $unix = new unix(); $sock = new sockets(); $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 "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); $pid = PID_NUM(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Not running, start it\n"; } start(); return; } build(); $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} TTL of {$timepid}Mn\n"; } $unix->KILL_PROCESS($pid, 1); $echo = $unix->find_program("echo"); $sock = new sockets(); $ip_queue_maxlen = intval($sock->GET_INFO("ip_queue_maxlen")); if ($ip_queue_maxlen == 0) { $ip_queue_maxlen = 2048; } if (is_file("/proc/sys/net/ipv4/ip_queue_maxlen")) { shell_exec("{$echo} \"{$ip_queue_maxlen}\" >/proc/sys/net/ipv4/ip_queue_maxlen"); } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} /proc/sys/net/ipv4/ip_queue_maxlen no such file.\n"; } } }
function if_process_import_exists($filename, $killbefore = 0) { $unix = new unix(); $RESULTS = FALSE; $pgrep = $unix->find_program("pgrep"); exec("{$pgrep} -l -f \"bzip2.*{$filename}\" 2>&1", $results); while (list($index, $line) = each($results)) { $line = trim($line); if ($line == null) { continue; } if (preg_match("#pgrep#", $line)) { continue; } if (!preg_match("#^([0-9]+)#", $line, $re)) { continue; } $TTL = $unix->PROCESS_TTL($re[1]); $RESULTS = true; if ($GLOBALS["VERBOSE"]) { echo "{$re[1]} - {$TTL}Mn\n"; } if ($killbefore > 0) { if ($TTL < $killbefore) { if ($GLOBALS["VERBOSE"]) { echo "KILL!!! {$re[1]} - {$TTL}Mn\n"; } $unix->KILL_PROCESS($re[1], 9); } } Export_logs("{$filename} is already processed by PID {$re[1]} since {$TTL}Mn"); } return $RESULTS; }
function nmap_scan_pingnet() { nmap_scan_pingnet_progress("{ping_networks}", 5); $unix = new unix(); $sock = new sockets(); $nmap = $unix->find_program("nmap"); $nohup = $unix->find_program("nohup"); $NmapTimeOutPing = intval($sock->GET_INFO("NmapTimeOutPing")); $NmapFastScan = intval($sock->GET_INFO("NmapFastScan")); if ($NmapTimeOutPing == 0) { $NmapTimeOutPing = 30; } $MaxTime = 10; $net = new networkscanner(); while (list($num, $maks) = each($net->networklist)) { if (trim($maks) == null) { continue; } $hash[$maks] = $maks; } while (list($num, $maks) = each($hash)) { if (!$net->Networks_disabled[$maks]) { if ($GLOBALS["VERBOSE"]) { echo "Network: {$maks} OK\n"; } $cdir[] = $maks; } } if (count($cdir) == 0) { nmap_scan_pingnet_progress("No network", 110); return; } $nets = trim(@implode(" ", $cdir)); nmap_scan_pingnet_progress("Scanning Networks {$nets}", 10); echo "Scanning Networks {$nets}\n"; $TMP = $unix->FILE_TEMP(); $NmapTimeOutPing++; $prc = 10; nmap_scan_pingnet_progress("{fast_scan}: {$NmapFastScan}", 6); while (list($num, $cd) = each($cdir)) { $prc = $prc + 5; if ($prc > 99) { $prc = 99; } nmap_scan_pingnet_progress("Scanning Network {$cd}", $prc); $CONTINUE = true; if ($NmapFastScan == 1) { nmap_scan_pingnet_progress("{$cd} -> arp-scan", $prc); $f1 = arp_scanner($cdir); if (count($f1) > 0) { while (list($num, $line) = each($f1)) { $f[] = $line; } $CONTINUE = false; } } if ($CONTINUE) { echo "{$nmap} -T4 -sP -oX {$TMP} {$cd}\n"; system("{$nohup} {$nmap} -T4 -sP -oX {$TMP} {$cd} >/dev/null 2>&1 &"); for ($i = 1; $i < $NmapTimeOutPing; $i++) { $pid = $unix->PIDOF("{$nmap}"); if (!$unix->process_exists($pid)) { break; } echo "Waiting scanner PID {$pid} {$i}/{$NmapTimeOutPing}\n"; sleep(1); } $pid = $unix->PIDOF("{$nmap}"); if ($unix->process_exists($pid)) { echo "Timed-Out scanner PID {$pid}\n"; nmap_scan_pingnet_progress("{$cd} Timed Out!!", $prc); sleep(3); $unix->KILL_PROCESS($pid, 9); continue; } $date = date("Y-m-d H:i:s"); $xmlstr = @file_get_contents($TMP); @unlink($TMP); $XMLZ = new SimpleXMLElement($xmlstr); foreach ($XMLZ->host as $Hostz) { $ipaddr = mysql_escape_string2($Hostz->address[0]["addr"][0]); $mac = mysql_escape_string2($Hostz->address[1]["addr"][0]); $vendor = mysql_escape_string2($Hostz->address[1]["vendor"][0]); $f[] = "('{$ipaddr}','{$mac}','{$vendor}','{$date}')"; } } } $prc = $prc + 5; if ($prc > 99) { $prc = 99; } nmap_scan_pingnet_progress("Build report", $prc); $q = new mysql(); $sql = "CREATE TABLE IF NOT EXISTS `nmap_scannet` (\n\t`MAC` varchar(90) NOT NULL,\n\t`ipaddr` varchar(90) NOT NULL,\n\t`vendor` varchar(90) NOT NULL DEFAULT '',\n\t`zDate` datetime NOT NULL,\n\tPRIMARY KEY (`MAC`),\n\tKEY `ipaddr` (`ipaddr`),\n\tKEY `vendor` (`vendor`)\n\t) ENGINE=MYISAM;"; $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error . "\n"; nmap_scan_pingnet_progress("MySQL error", "110"); return; } $q->QUERY_SQL("TRUNCATE TABLE nmap_scannet", "artica_backup"); $sql = "INSERT IGNORE INTO nmap_scannet (`ipaddr`,`MAC`,`vendor`,`zDate`) VALUES " . @implode(",", $f); $q->QUERY_SQL($sql, "artica_backup"); if (!$q->ok) { echo $q->mysql_error . "\n"; nmap_scan_pingnet_progress("MySQL error", "110"); return; } nmap_scan_pingnet_progress("{done}", 100); }
function stop() { $unix = new unix(); $sock = new sockets(); $masterbin = $unix->find_program("squid27"); $EnableArticaHotSpot = $sock->GET_INFO("EnableArticaHotSpot"); $SquidHotSpotPort = $sock->GET_INFO("SquidHotSpotPort"); $ArticaHotSpotPort = $sock->GET_INFO("ArticaHotSpotPort"); $ArticaSSLHotSpotPort = $sock->GET_INFO("ArticaSSLHotSpotPort"); $ArticaSplashHotSpotPort = $sock->GET_INFO("ArticaSplashHotSpotPort"); $ArticaSplashHotSpotPortSSL = $sock->GET_INFO("ArticaSplashHotSpotPortSSL"); if (!is_numeric($ArticaHotSpotPort)) { $ArticaHotSpotPort = 0; } if (!is_numeric($ArticaSplashHotSpotPort)) { $ArticaSplashHotSpotPort = 16080; } if (!is_numeric($ArticaSplashHotSpotPortSSL)) { $ArticaSplashHotSpotPortSSL = 16443; } $pid = squid_27_pid(); if (!is_file($masterbin)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Not installed\n"; } return; } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already stopped...\n"; } return; } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $kill = $unix->find_program("kill"); if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Shutdown pid {$pid}...\n"; } shell_exec("{$masterbin} -f /etc/squid27/squid.conf -k shutdown"); for ($i = 0; $i < 5; $i++) { $pid = squid_27_pid(); if (!$unix->process_exists($pid)) { break; } shell_exec("{$masterbin} -f /etc/squid27/squid.conf -k shutdown"); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:{$pid} {$i}/5...\n"; } sleep(1); } $pid = squid_27_pid(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} shutdown - force - pid {$pid}...\n"; } shell_exec("{$masterbin} -f /etc/squid27/squid.conf -k kill"); for ($i = 0; $i < 5; $i++) { $pid = squid_27_pid(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:{$pid} {$i}/5...\n"; } shell_exec("{$masterbin} -f /etc/squid27/squid.conf -k kill"); sleep(1); } if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success stopped...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Killing processes\n"; } for ($i = 0; $i < 5; $i++) { $pid = squid_27_pid(); if (!$unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} kill pid:{$pid} {$i}/5...\n"; } $unix->KILL_PROCESS($pid, 9); } $pid = squid_27_pid(); if (!$unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success stopped...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n"; } }
function BUILD_NETWORK() { $SUBNIC = null; $unix = new unix(); $sock = new sockets(); $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $savedsettings = unserialize(base64_decode(file_get_contents("/etc/artica-postfix/settings/Daemons/WizardSavedSettings"))); $KEEPNET = $savedsettings["KEEPNET"]; if ($KEEPNET == 1) { return; } $netbiosname = $savedsettings["netbiosname"]; if (strlen($netbiosname) > 15) { $netbiosname = substr(0, 15, $netbiosname); } if (isset($savedsettings["domain"])) { $domainname = $savedsettings["domain"]; $SEARCH_DOMAIN = $domainname; } $EnableKerbAuth = intval($sock->GET_INFO("EnableKerbAuth")); if ($EnableKerbAuth == 1) { $array = unserialize(base64_decode($sock->GET_INFO("KerbAuthInfos"))); if (isset($array["WINDOWS_DNS_SUFFIX"])) { $SEARCH_DOMAIN = $array["WINDOWS_DNS_SUFFIX"]; $domainname = $SEARCH_DOMAIN; } } $Encoded = base64_encode(serialize($savedsettings)); @file_put_contents("/etc/artica-postfix/settings/Daemons/WizardSavedSettings", $Encoded); if (!isset($savedsettings["NIC"])) { $savedsettings["NIC"] = "eth0"; } $NIC = $savedsettings["NIC"]; if (preg_match("#(.+?):([0-9]+)#", $savedsettings["NIC"], $re)) { $NIC = trim($re[1]); $SUBNIC = $re[2]; } writeprogress(60, "{building_networks}"); $nics = new system_nic($NIC); $nics->CheckMySQLFields(); $dhclient = $unix->find_program("dhclient"); if (is_file($dhclient)) { $pid = $unix->PIDOF($dhclient); if ($unix->process_exists($pid)) { $unix->KILL_PROCESS($pid, 9); } } $nics->eth = $NIC; if ($SUBNIC != null) { $nics->IPADDR = "127.0.0.2"; $nics->NETMASK = "255.255.255.255"; $nics->GATEWAY = "0.0.0.0"; $nics->BROADCAST = "0.0.0.0"; $nics->DNS1 = $savedsettings["DNS1"]; $nics->DNS2 = $savedsettings["DNS2"]; $nics->dhcp = 0; $nics->metric = $savedsettings["metric"]; $nics->enabled = 1; $nics->defaultroute = 1; } else { $nics->IPADDR = $savedsettings["IPADDR"]; $nics->NETMASK = $savedsettings["NETMASK"]; $nics->GATEWAY = $savedsettings["GATEWAY"]; $nics->BROADCAST = $savedsettings["BROADCAST"]; $nics->DNS1 = $savedsettings["DNS1"]; $nics->DNS2 = $savedsettings["DNS2"]; $nics->dhcp = 0; $nics->metric = $savedsettings["metric"]; $nics->enabled = 1; $nics->defaultroute = 1; } writeprogress(60, "{saving_network}"); $nics->SaveNic(); if ($SUBNIC != null) { $q = new mysql(); $sql = "INSERT INTO nics_virtuals (ID,nic,org,ipaddr,netmask,cdir,gateway,ForceGateway,failover,metric)\n\t\tVALUES('{$SUBNIC}','{$NIC}','','{$savedsettings["IPADDR"]}','{$savedsettings["NETMASK"]}',\n\t\t'','{$savedsettings["GATEWAY"]}',0,0,1);"; $q->QUERY_SQL($sql, "artica_backup"); $sql = "UPDATE nics_virtuals SET nic='{$NIC}',\n\t\torg='',\n\t\tipaddr='{$savedsettings["IPADDR"]}',\n\t\tnetmask='{$savedsettings["NETMASK"]}',\n\t\tcdir='',\n\t\t\t\tgateway='{$savedsettings["GATEWAY"]}',\n\t\t\t\tForceGateway='0',\n\t\t\t\tfailover='0',\n\t\t\t\tmetric='1'\n\t\t\t\tWHERE ID={$SUBNIC}"; $q->QUERY_SQL($sql, "artica_backup"); } writeprogress(60, "Loading resolv library"); $resolv = new resolv_conf(); $arrayNameServers[0] = $savedsettings["DNS1"]; $arrayNameServers[1] = $savedsettings["DNS2"]; $resolv->MainArray["DNS1"] = $arrayNameServers[0]; $resolv->MainArray["DNS2"] = $arrayNameServers[1]; $resolv->MainArray["DOMAINS1"] = $SEARCH_DOMAIN; writeprogress(60, "Saving DNS settings"); $resolv->save(); $nic = new system_nic(); writeprogress(60, "{set_new_hostname} {$netbiosname}.{$domainname}"); $nic->set_hostname("{$netbiosname}.{$domainname}"); $php = $unix->LOCATE_PHP5_BIN(); $nohup = $unix->find_program("nohup"); writeprogress(60, "{building_resolv_configuration}"); shell_exec(trim("{$nohup} " . $unix->LOCATE_PHP5_BIN() . " /usr/share/artica-postfix/exec.virtuals-ip.php --resolvconf >/dev/null 2>&1")); writeprogress(60, "{building_networks_scripts}"); shell_exec("{$php5} /usr/share/artica-postfix/exec.virtuals-ip.php >/dev/null 2>&1"); }
function reload() { $scriptlog = null; if ($GLOBALS["BYSCRIPT"]) { $scriptlog = " by init.d script"; } $unix = new unix(); $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 "Starting......: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Reloading framework PID:{$pid}...\n"; } FrmToSyslog("Reloading framework{$scriptlog}"); $unix->KILL_PROCESS($pid, 1); return; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Starting framework...\n"; } start(true); }
function phpcgi() { $unix = new unix(); $phpcgi = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH(); $pids = $unix->PIDOF_PATTERN_ALL($phpcgi); if (count($pids) == 0) { return; } $c = 0; while (list($pid, $ligne) = each($pids)) { $time = $unix->PROCESS_TTL($pid); if ($time > 1640) { $c++; $unix->KILL_PROCESS($pid, 9); } } }
function redirectors_array($aspid = false) { $cache_file = "/usr/share/artica-postfix/ressources/logs/web/squid_redirectors_status.db"; $NotifyTime = "/etc/artica-postfix/pids/squid.redirectors.notify"; $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); if ($aspid) { $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { $pptime = $unix->PROCCESS_TIME_MIN($pid, 10); if ($GLOBALS["VERBOSE"]) { echo "Process already running PID {$pid} since {$pptime}Mn\n"; } return; } @file_put_contents($pidFile, getmypid()); } $sock = new sockets(); $datas = explode("\n", $unix->squidclient("redirector")); $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig"))); $MonitConfig = watchdog_config_default($MonitConfig); if ($MonitConfig["watchdog"] == 0) { return; } $redirector = array(); $RedirectorsArray = unserialize(base64_decode($sock->GET_INFO("SquidRedirectorsOptions"))); if (!is_numeric($RedirectorsArray["url_rewrite_children"])) { $RedirectorsArray["url_rewrite_children"] = 20; } $PERCENTS = array(); while (list($index, $line) = each($datas)) { if (preg_match("#by kid([0-9]+)#", $line, $re)) { $KID = "Processor #{$re[1]}"; } if (preg_match("#number active:\\s+([0-9]+)\\s+of\\s+([0-9]+)#i", $line, $re)) { $max = $re[2]; $Current = $re[1]; $percent = $Current / $max; $percent = $percent * 100; $LOGs[] = "{$KID}: {$Current}/{$max} = {$percent}%"; Events("{$line} {$Current}/{$max} = {$percent}%"); $PERCENTS[] = round($percent); } if (!preg_match("#([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)(.*?)\\s+([0-9\\.]+)\\s+([0-9\\.]+)\\s+(.*)#", $line, $re)) { continue; } $re[6] = trim($re[6]); $re[3] = trim($re[3]); $re[6] = str_replace(" ", "", $re[6]); $fflosg[] = $re[3]; if ($GLOBALS["VERBOSE"]) { echo "STATE \"{$re[6]}\"\n"; } if ($re[6] == "BS") { $unix->KILL_PROCESS($re[3], 9); if ($GLOBALS["VERBOSE"]) { echo "KILLING \"{$re[3]}\"\n"; } } if ($re[6] == "S") { $unix->KILL_PROCESS($re[3], 9); if ($GLOBALS["VERBOSE"]) { echo "KILLING \"{$re[3]}\"\n"; } } $redirector[$re[1]] = array("FD" => $re[2], "PID" => $re[3], "REQ" => $re[4], "REP" => $re[5], "STATE" => $re[6], "TIME" => $re[7], "OFFSET" => $re[8], "URI" => $re[9]); } $FFperc = 0; $FINAL_PERC = 0; $CountOFPercent = count($PERCENTS); if (count($PERCENTS > 0)) { while (list($index, $pp) = each($PERCENTS)) { $FFperc = $FFperc + $pp; } $FINAL_PERC = round($FFperc / $CountOFPercent, 2); $LOGs[] = "************************************************"; $LOGs[] = "ALL CPUS: {$FINAL_PERC}%"; $LOGs[] = ""; } if ($FINAL_PERC > 90) { $severity = 1; $action = "notify"; $NotifyTimeEx = $unix->file_time_min($NotifyTime); if ($NotifyTimeEx < 10) { return; } @unlink($NotifyTime); @file_put_contents($NotifyTime, time()); if ($FINAL_PERC > 95) { $severity = 1; $action = "reload"; } Events("{$line} {$Current}/{$max} severity = {$severity}"); squid_admin_mysql($severity, "Warning! redirectors reach {$FINAL_PERC}% [action={$action}]", @implode("\n", $LOGs) . "\n\n---------------------------------\n\n" . @implode("\n", $datas)); if ($severity == 0) { shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__)); return; } } @unlink($cache_file); if (count($redirector) == 0) { return; } @file_put_contents($cache_file, serialize($redirector)); @chmod($cache_file, 0755); }
function start() { $unix = new unix(); $pid = getmypid(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if ($GLOBALS["VERBOSE"]) { echo "pidTime: {$pidTime}\n"; } $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid)) { if ($pid != $pid) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($time > 120) { ToSyslog("killing {$pid} (line: Line: " . __LINE__ . ")"); unix_system_kill_force($pid); } else { die; } } } @file_put_contents($pidfile, getmypid()); $pidTimeEx = $unix->file_time_min($pidTime); if (!$GLOBALS["FORCE"]) { if ($pidTimeEx < 240) { ToSyslog("Waiting 240mn minimal - current ({$pidTimeEx}Mn)"); return; } } @unlink($pidTime); @file_put_contents($pidTime, time()); $ARRAY = array(); $curlftps = $unix->find_program("curlftpfs"); $pgrep = $unix->find_program("pgrep"); exec("{$pgrep} -l -f \"{$curlftps}\" 2>&1", $results); while (list($index, $line) = each($results)) { $line = trim($line); if ($line == null) { continue; } $MOUNTED = null; $pidtime = 0; $pid = 0; if (preg_match("#pgrep#", $line)) { continue; } if (preg_match("#^([0-9]+)\\s+(.+)#", $line, $re)) { $pid = $re[1]; $pidtime = $unix->PROCESS_TTL($pid); $cmdline = trim($re[2]); $cmdline = str_replace($curlftps, "", $cmdline); $cmdline = trim($re[2]); if ($GLOBALS["VERBOSE"]) { echo "Found {$pid} {$pidtime}Mn [{$cmdline}]\n"; } $ARRAY[$pid]["TIME"] = $pidtime; if ($GLOBALS["VERBOSE"]) { echo "Explode {$cmdline}\n"; } $TR = explode(" ", $cmdline); while (list($index2, $bg) = each($TR)) { if ($GLOBALS["VERBOSE"]) { echo "Checks {$bg}\n"; } if (substr($bg, 0, 1) == "/") { $MOUNTED = $bg; if ($GLOBALS["VERBOSE"]) { echo "Found {$pid} {$pidtime}Mn mounted on {$bg}\n"; } $ARRAY[$pid]["MOUNTED"] = $MOUNTED; break; } } } } if (count($ARRAY) == 0) { return; } $umount = $unix->find_program("umount"); while (list($pid, $ar) = each($ARRAY)) { $TIME = $ar["TIME"]; $MOUNTED = $ar["MOUNTED"]; if ($TIME < 960) { continue; } ToSyslog("Umounting curlftps process id {$pid} mounted on {$MOUNTED} and running since {$TIME}mn, and exceed 960mn"); shell_exec("{$umount} -l {$MOUNTED}"); if ($unix->process_exists($pid)) { ToSyslog("Killing curlftps process id {$pid}"); $unix->KILL_PROCESS($pid, 9); } } }
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); 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 "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $ROUNDCUBE_MAIN_FOLDER = ROUNDCUBE_MAIN_FOLDER(); if (!is_dir(ROUNDCUBE_MAIN_FOLDER())) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n"; } return; } $RoundCubeHTTPEngineEnabled = intval($sock->GET_INFO("RoundCubeHTTPEngineEnabled")); $pid = LIGHTTPD_PID(); if ($RoundCubeHTTPEngineEnabled == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} disabled (RoundCubeHTTPEngineEnabled)..\n"; } if ($unix->process_exists($pid)) { stop(true); } return; } if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$GLOBALS["SERVICE_NAME"]} already started {$pid} since {$timepid}Mn...\n"; } return; } $nohup = $unix->find_program("nohup"); $php5 = $unix->LOCATE_PHP5_BIN(); $apache2ctl = $unix->LOCATE_APACHE_CTL(); $LIGHTTPD_CONF_PATH = LIGHTTPD_CONF_PATH(); $RoundCubeHTTPSPort = intval($sock->GET_INFO("RoundCubeHTTPSPort")); $RoundCubeHTTPPort = intval($sock->GET_INFO("RoundCubeHTTPPort")); $RoundCubeUseSSL = intval($sock->GET_INFO("RoundCubeUseSSL")); if ($RoundCubeHTTPSPort == 0) { $RoundCubeHTTPSPort = 449; } if ($RoundCubeHTTPPort == 0) { $RoundCubeHTTPPort = 8888; } if (!is_file("/opt/artica/ssl/certs/lighttpd.pem")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating SSL certificate..\n"; } exec("/usr/share/artica-postfix/bin/artica-install -lighttpd-cert 2>&1", $results); while (list($num, $line) = each($results)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$line}\n"; } } } apache_config(); if ($RoundCubeUseSSL == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Get PID from PORT HTTPS/TCP:{$RoundCubeHTTPSPort}\n"; } $pids = $unix->PIDOF_BY_PORT($RoundCubeHTTPSPort); if (count($pids) > 0) { while (list($pid, $line) = each($pids)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} kill PID {$pid} that listens {$RoundCubeHTTPSPort}\n"; } $unix->KILL_PROCESS($pid, 9); } } } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Get PID from PORT HTTP/TCP:{$RoundCubeHTTPPort}\n"; } $pids = $unix->PIDOF_BY_PORT($RoundCubeHTTPPort); if (count($pids) > 0) { while (list($pid, $line) = each($pids)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} kill PID {$pid} that listens {$RoundCubeHTTPPort}\n"; } $unix->KILL_PROCESS($pid, 9); } } $cmd = "{$apache2ctl} -f {$LIGHTTPD_CONF_PATH} -k start"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); for ($i = 0; $i < 6; $i++) { $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting {$i}/6...\n"; } sleep(1); } $pid = LIGHTTPD_PID(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}...\n"; } } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n"; } } }
function ufdguard_start_notify() { squid_admin_mysql(2, "{starting_web_filtering} engine service by init.d script", "", __FILE__, __LINE__); $unix = new unix(); $fuser = $unix->find_program("fuser"); $port = ufdguard_get_listen_port(); $results = array(); echo "Starting......: " . date("H:i:s") . " Webfiltering service Listen on port {$port}\n"; $cmd = "{$fuser} {$port}/tcp 2>&1"; exec("{$cmd}", $results); echo "Starting......: " . date("H:i:s") . " Webfiltering service `{$cmd}` " . count($results) . " lines.\n"; while (list($num, $ligne) = each($results)) { if (preg_match("#{$port}\\/tcp:(.+)#", $ligne, $re)) { $ff = explode(" ", $re[1]); while (list($index, $ligne2) = each($ff)) { $ligne2 = trim($ligne2); if (!is_numeric($ligne2)) { continue; } echo "Starting......: " . date("H:i:s") . " Webfiltering service killing PID {$ligne2}\n"; $unix->KILL_PROCESS($ligne2, 9); } } } }
function ping() { $articameta = new artica_meta(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/var/run/artica-meta-client.run"; $unix = new unix(); $sock = new sockets(); $ArticaMetaKillProcess = intval($sock->GET_INFO("ArticaMetaKillProcess")); if ($ArticaMetaKillProcess == 0) { $ArticaMetaKillProcess = 60; } $pid = @file_get_contents($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $timePid = $unix->PROCCESS_TIME_MIN($pid); if ($timePid < $ArticaMetaKillProcess) { client_progress("A Meta client process already running pid: {$pid} since {$timePid}Mn", 110); $articameta->events("A Meta client process already running pid: {$pid} since {$timePid}Mn", __FUNCTION__, __FILE__, __LINE__); die; } else { $articameta->events("Killing running pid: {$pid} since {$timePid}Mn", __FUNCTION__, __FILE__, __LINE__); $unix->KILL_PROCESS($pid); } } if ($GLOBALS["ENABLE"]) { $sock->SET_INFO("EnableArticaMetaClient", 1); } $T1 = time(); $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient")); $ArticaMetaPooling = intval($sock->GET_INFO("ArticaMetaPooling")); $MetaClientAutoUpdate = intval($sock->GET_INFO("MetaClientAutoUpdate")); if ($ArticaMetaPooling == 0) { $ArticaMetaPooling = 15; } $pidTimeEx = $unix->file_time_min($pidTime); if ($GLOBALS["OUTPUT"]) { echo "EnableArticaMetaClient = {$EnableArticaMetaClient}\n"; } if ($GLOBALS["OUTPUT"]) { echo "Last ping {$pidTimeEx}Mn Pool:{$ArticaMetaPooling}mn\n"; } if (!$GLOBALS["OUTPUT"]) { if ($pidTimeEx < $ArticaMetaPooling) { $articameta->events("{$pidTimeEx} < {$ArticaMetaPooling}, stop processing", __FUNCTION__, __FILE__, __LINE__); return; } } @unlink($pidTime); @file_put_contents($pidTime, time()); @file_put_contents($pidfile, getmypid()); $nice = $unix->EXEC_NICE(); $php = $unix->LOCATE_PHP5_BIN(); if ($EnableArticaMetaClient == 0) { client_progress("{disabled}", 110); if (is_file("/etc/cron.hourly/metaclient.sh")) { @unlink("/etc/cron.hourly/metaclient.sh"); } if (is_file("/etc/cron.d/artica-meta-c")) { @unlink("/etc/cron.d/artica-meta-c"); } return; } $ionice = $unix->EXEC_NICE(); $articameta->events("Creating tasks...", __FUNCTION__, __FILE__, __LINE__); client_progress("Creating tasks Pooling={$ArticaMetaPooling}Mn...", 10); if ($ArticaMetaPooling == 240) { $f[] = "MAILTO=\"\""; $f[] = "0 4,8,12,16,20 * * * * root {$ionice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-meta-c", @implode("\n", $f)); @chmod("/etc/cron.d/artica-meta-c", 0644); unset($f); } if ($ArticaMetaPooling == 120) { $f[] = "MAILTO=\"\""; $f[] = "0 2,4,6,8,10,12,14,16,18,20,22 * * * * root {$ionice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-meta-c", @implode("\n", $f)); @chmod("/etc/cron.d/artica-meta-c", 0644); unset($f); } if ($ArticaMetaPooling == 60) { $f[] = "MAILTO=\"\""; $f[] = "0 * * * * root {$ionice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-meta-c", @implode("\n", $f)); @chmod("/etc/cron.d/artica-meta-c", 0644); unset($f); } if ($ArticaMetaPooling == 30) { $f[] = "MAILTO=\"\""; $f[] = "30,59 * * * * root {$ionice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-meta-c", @implode("\n", $f)); @chmod("/etc/cron.d/artica-meta-c", 0644); unset($f); } if ($ArticaMetaPooling == 20) { $f[] = "MAILTO=\"\""; $f[] = "20,40,59 * * * * root {$ionice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-meta-c", @implode("\n", $f)); @chmod("/etc/cron.d/artica-meta-c", 0644); unset($f); } if ($ArticaMetaPooling == 15) { $f[] = "MAILTO=\"\""; $f[] = "10,15,30,45,59 * * * * root {$ionice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-meta-c", @implode("\n", $f)); @chmod("/etc/cron.d/artica-meta-c", 0644); unset($f); } if ($ArticaMetaPooling == 10) { $f[] = "MAILTO=\"\""; $f[] = "10,20,30,40,50,59 * * * * root {$ionice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-meta-c", @implode("\n", $f)); @chmod("/etc/cron.d/artica-meta-c", 0644); unset($f); } if ($ArticaMetaPooling == 5) { $f[] = "MAILTO=\"\""; $f[] = "5,10,15,20,25,30,35,40,45,50,55,59 * * * * root {$ionice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-meta-c", @implode("\n", $f)); @chmod("/etc/cron.d/artica-meta-c", 0644); unset($f); } if ($ArticaMetaPooling == 2) { $f[] = "MAILTO=\"\""; $f[] = "0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * root {$ionice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-meta-c", @implode("\n", $f)); @chmod("/etc/cron.d/artica-meta-c", 0644); unset($f); } if ($ArticaMetaPooling == 3) { $f[] = "MAILTO=\"\""; $f[] = "3,6,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,55,57,59 * * * * root {$ionice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.d/artica-meta-c", @implode("\n", $f)); @chmod("/etc/cron.d/artica-meta-c", 0644); unset($f); } if (!is_file("/etc/cron.hourly/metaclient.sh")) { $f[] = "#!/bin/sh"; $f[] = "export LC_ALL=C"; $f[] = "{$nice} {$php} " . __FILE__ . " --ping >/dev/null 2>&1"; $f[] = ""; @file_put_contents("/etc/cron.hourly/metaclient.sh", @implode("\n", $f)); @chmod("/etc/cron.hourly/metaclient.sh", 0755); shell_exec("/etc/init.d/cron reload"); unset($f); } $articaMeta = new artica_meta(); $articaMeta->events("Ping the Meta server [{$articaMeta->ArticaMetaHostname}]...", __FUNCTION__, __FILE__, __LINE__); client_progress("Ping the Meta server [{$articaMeta->ArticaMetaHostname}]...", 20); if (!$articaMeta->ping()) { if ($GLOBALS["OUTPUT"]) { echo "PING FAILED\n"; } $articaMeta->events("Ping Failed {$articaMeta->ping_error}", __FUNCTION__, __FILE__, __LINE__); writelogs_meta("Ping Failed {$articaMeta->ping_error}", __FUNCTION__, __FILE__, __LINE__); client_progress("Ping the Meta server {failed}...", 110); return; } $ArticaMetaDumpSQLMD5 = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/ArticaMetaDumpSQLMD5")); $ArticaMetaDumpSQLClientMD5 = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/ArticaMetaDumpSQLClientMD5")); $articaMeta->events("ArticaMetaDumpSQLMD5 = {$ArticaMetaDumpSQLMD5}", __FUNCTION__, __FILE__, __LINE__); $articaMeta->events("ArticaMetaDumpSQLClientMD5 = {$ArticaMetaDumpSQLClientMD5}", __FUNCTION__, __FILE__, __LINE__); if ($ArticaMetaDumpSQLMD5 != null) { if ($ArticaMetaDumpSQLMD5 != $ArticaMetaDumpSQLClientMD5) { if ($articaMeta->retreive_dump_sql($ArticaMetaDumpSQLMD5)) { $articaMeta->events("Update ArticaMetaDumpSQLClientMD5 key with {$ArticaMetaDumpSQLMD5}", __FUNCTION__, __FILE__, __LINE__); @file_put_contents("/etc/artica-postfix/settings/Daemons/ArticaMetaDumpSQLClientMD5", $ArticaMetaDumpSQLMD5); $php = $unix->LOCATE_PHP5_BIN(); system("{$php} /usr/share/artica-postfix/exec.squid-meta.php"); } } } $took = $unix->distanceOfTimeInWords($T1, time(), true); client_progress("Ping the Meta server {succes} {took} {$took}...", 90); events("Ping Success...Took:" . $unix->distanceOfTimeInWords($T1, time(), true), __FUNCTION__, __FILE__, __LINE__); shell_exec("{$php} " . __FILE__ . " --logrotate >/dev/null 2>&1 &"); smtp_to_meta(); if ($MetaClientAutoUpdate == 1) { $articaMeta->events("Check updates from Meta server...", __FUNCTION__, __FILE__, __LINE__); client_progress("Check updates from Meta server...", 95); artica_updates_scheduled(true); } client_progress("{success}", 100); }
function force_restart() { $unix = new unix(); $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 "Starting......: " . date("H:i:s") . " [INIT]: Nginx Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx reloading\n"; } $pid = PID_NUM(); if ($unix->process_exists($pid)) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx reloading PID {$pid} running since {$time}Mn\n"; } $unix->KILL_PROCESS($pid, "HUP"); return; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx not running, start it\n"; } start(true); }
function reload() { $unix = new unix(); suricata_config(); if ($GLOBALS["OUTPUT"]) { echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Reloading service\n"; } $pid = suricata_pid(); if ($unix->process_exists($pid)) { $time = $unix->PROCCESS_TIME_MIN($pid); build_progress_reconfigure("{reloading} Suricata", 20); suricata_config(); build_progress_reconfigure("{reloading} Suricata", 80); if ($GLOBALS["OUTPUT"]) { echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Running since {$time}Mn...\n"; } $unix->KILL_PROCESS($pid, 12); $nohup = $unix->find_program("nohup"); build_progress_reconfigure("{reloading} Suricata", 90); shell_exec("{$nohup} /etc/init.d/suricata-tail restart >/dev/null 2>&1 &"); } else { if ($GLOBALS["OUTPUT"]) { echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Not running, start it\n"; } start(true); } }