function start() { $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 = GET_PID(); if ($unix->process_exists($PID)) { squid_admin_mysql(1, "Watchdog says that rsyslog is off, but exists [action=stamp-pid]", null, __FILE__, __LINE__); $SrcPid = intval(@file_get_contents("/var/run/rsyslogd.pid")); if ($SrcPid != $PID) { squid_admin_mysql(2, "Watchdog says that rsyslog is off (PID:{$SrcPid}), but exists (PID:{$PID}) [action=stamp-pid]", null, __FILE__, __LINE__); @file_put_contents("/var/run/rsyslogd.pid", $PID); } else { squid_admin_mysql(2, "Watchdog says that rsyslog is off (PID:{$SrcPid}), but exists [action=nothing]", null, __FILE__, __LINE__); } @unlink($pidfile); die(1); } squid_admin_mysql(0, "Syslog daemon is down [action=start]", null, __FILE__, __LINE__); system("/etc/init.d/rsyslog start"); $squid = $unix->LOCATE_SQUID_BIN(); if (is_file($squid)) { sleep(3); squid_admin_mysql(1, "Reloading proxy service after starting syslog daemon", null, __FILE__, __LINE__); system("{$squid} -f /etc/squid3/squid.conf -k reconfigure"); } }
function build() { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $sock = new sockets(); $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { die; } $php = $unix->LOCATE_PHP5_BIN(); @file_put_contents($pidfile, getmypid()); progress("{get_system_informations}", 30); support_step1(); progress("{APP_UFDBGUARD}", 40); $EnableUfdbGuard = intval($sock->EnableUfdbGuard()); if ($EnableUfdbGuard == 1) { $ufdbguardd = $unix->find_program("ufdbguardd"); if (is_file($ufdbguardd)) { shell_exec("{$php} /usr/share/artica-postfix/exec.squidguard.php --build --force --verbose >/usr/share/artica-postfix/ressources/support/build-ufdbguard.log 2>&1"); } } progress("{get_all_logs}", 50); support_step2(); progress("{get_all_logs}", 70); export_tables(); progress("{compressing_package}", 90); support_step3(); progress("{success}", 100); }
function xstart() { $unix = new unix(); $sock = new sockets(); $GLOBALS["CLASS_SOCKETS"] = $sock; $FORCED_TEXT = null; $NOTIFY = false; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/usr/share/artica-postfix/ressources/logs/ARTICA_DBS_STATUS_FULL.db"; $pid = $unix->get_pid_from_file($pidfile); $GLOBALS["CLASS_UNIX"] = $unix; if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); echo "Already executed\n"; return; } if (!$GLOBALS["FORCE"]) { if ($unix->file_time_min($pidTime) < 30) { return; } } $GLOBALS["MAIN_ARRAY"] = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/logs/ARTICA_DBS_STATUS.db")); ArticaWebFilter(); ArticaUfdb(); @mkdir("/usr/share/artica-postfix/ressources/logs", 0755, true); @unlink($pidTime); @file_put_contents($pidTime, serialize($GLOBALS["MAIN_ARRAY"])); if ($GLOBALS["VERBOSE"]) { echo "Saving {$pidTime}\n"; } @chmod($pidTime, 0755); }
function scan_connections() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Artica Task Already running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); if (system_is_overloaded()) { system_admin_events("Overloaded system, aborting task", __FUNCTION__, __FILE__, __LINE__); return false; } $q = new mysql(); $sql = "SELECT * FROM texttoldap"; $results = $q->QUERY_SQL($sql, "artica_backup"); if (mysql_num_rows($results) == 0) { return; } while ($ligne = mysql_fetch_assoc($results)) { if (!connect($ligne)) { continue; } import($ligne); $ID = $ligne["ID"]; } }
function xstart() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { return; } $TimeExec = $unix->file_time_min($pidtime); if ($TimeExec < 360) { return; } @unlink($pidtime); @file_put_contents($pidtime, time()); @file_put_contents($pidfile, getmypid()); $php5 = $unix->LOCATE_PHP5_BIN(); $q = new mysql_squid_builder(); $q->CreateCategoryUrisTable("malware"); $COUNT1 = $q->COUNT_ROWS("categoryuris_malware"); vxvault(); malwareurls_joxeankoret(); clean_mx_de(); $COUNT2 = $q->COUNT_ROWS("categoryuris_malware"); $URLS_ADDED = $COUNT2 - $COUNT1; if ($URLS_ADDED > 0) { system("{$php5} /usr/share/artica-postfix/exec.squidguard.php --compile-category malware"); squid_admin_mysql(2, "{$URLS_ADDED} malware URLs added", null, __FILE__, __LINE__); } }
function parse() { $TimeFile = "/etc/artica-postfix/pids/exec.squid.stats.mime.proto.php.time"; $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.mime.proto.php.pid"; $GLOBALS["LogFileDeamonLogDir"] = @file_get_contents("/etc/artica-postfix/settings/Daemons/LogFileDeamonLogDir"); if ($GLOBALS["LogFileDeamonLogDir"] == null) { $GLOBALS["LogFileDeamonLogDir"] = "/home/artica/squid/realtime-events"; } $unix = new unix(); $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "{$pid} already executed since {$timepid}Mn\n"; } if ($timepid < 14) { return; } $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } @file_put_contents($pidfile, getmypid()); $TimeExec = $unix->file_time_min($TimeFile); if (!$GLOBALS["FORCE"]) { if ($TimeExec < 20) { return; } } @unlink($TimeFile); @file_put_contents($TimeFile, time()); parsedb("/var/log/squid"); parsedb($GLOBALS["LogFileDeamonLogDir"]); }
function CheckCMDLine() { $unix = new unix(); $PID_FILE = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pid = $unix->get_pid_from_file($PID_FILE); if ($unix->process_exists($pid)) { return; } @file_put_contents($PID_FILE, getmypid()); if (system_is_overloaded()) { die; } $sock = new sockets(); $ips = unserialize(base64_decode($sock->GET_INFO("RBLCheckIPList"))); if (count($ips) > 0) { if ($GLOBALS["VERBOSE"]) { echo count($ips) . " elements to check\n"; } if (is_array($ips)) { while (list($num, $ip) = each($ips)) { if ($GLOBALS["VERBOSE"]) { echo "{$ip} element...\n"; } ChecksDNSBL($ip, false, true); } ChecksDNSBL(); return; } } ChecksDNSBL(); }
function purge() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidtime = "/etc/artica-postfix/pids/exec.suricata.hourly.purge.time"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); echo "Starting......: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n"; return; } @file_put_contents($pidfile, getmypid()); if (system_is_overloaded()) { return; } $timeExec = $unix->file_time_min($pidtime); if ($timeExec < 1440) { return; } @unlink($pidtime); @file_put_contents($pidtime, time()); $q = new postgres_sql(); $sock = new sockets(); $SuricataPurge = intval($sock->GET_INFO("SuricataPurge")); if ($SuricataPurge == 0) { $SuricataPurge = 15; } $q->QUERY_SQL("DELETE FROM suricata_events WHERE zdate < NOW() - INTERVAL '{$SuricataPurge} days'"); }
function SingleDebug($ID) { $q = new mysql(); $q->BuildTables(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".{$ID}.pid"; $unix = new unix(); $pid = $unix->get_pid_from_file($pidfile); $fetchmail = $unix->find_program("fetchmail"); if ($unix->process_exists($pid)) { SingleDebugEvents("Task aborted", "This task is aborted, it already running PID {$pid}, please wait before executing a new task", $ID); return; } @file_put_contents($pidfile, getmypid()); SingleDebugEvents("Task executed", "Starting rule number {$ID}\nThis task is executed please wait before executing a new task", $ID); $fetch = new fetchmail(); $output = array(); $fetch = new fetchmail(); $l[] = "set logfile /var/log/fetchmail-rule-{$ID}.log"; $l[] = "set daemon {$fetch->FetchmailPoolingTime}"; $l[] = "set postmaster \"{$fetch->FetchmailDaemonPostmaster}\""; $l[] = "set idfile \"/var/log/fetchmail.{$ID}.id\""; $l[] = ""; $GLOBALS["SINGLE_DEBUG"] = true; BuildRules(); $pattern = $GLOBALS["FETCHMAIL_RULES_ID"][$ID]; $l[] = $pattern; @file_put_contents("/tmp/fetchmailrc.{$ID}", @implode("\n", $l)); shell_exec("/bin/chmod 600 /tmp/fetchmailrc.{$ID}"); $cmd = "{$fetchmail} -v -N -f /tmp/fetchmailrc.{$ID} --pidfile /tmp/fetcmailrc.{$ID}.pid 2>&1"; exec($cmd, $output); SingleDebugEvents("Task finish with " . count($output) . " event(s)", @implode("\n", $output), $ID); }
function importActivedirectoryusers() { $sock = new sockets(); $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth"); if (!is_numeric($EnableKerbAuth)) { $EnableKerbAuth = 0; } if ($EnableKerbAuth == 0) { return; } $unix = new unix(); $user = new settings_inc(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { WriteMyLogs("Process {$pid} already exists", __FUNCTION__, __FILE__, __LINE__); return; } if (system_is_overloaded(basename(__FILE__))) { WriteMyLogs("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__); return; } @file_put_contents($pidfile, getmypid()); $TImeStamp = $unix->file_time_min($pidTime); if (!$GLOBALS["FORCE"]) { if ($TImeStamp < 20) { WriteMyLogs("Need 20mn, current={$TImeStamp}Mn executed by:{$GLOBALS["EXECUTOR"]} Params:{$GLOBALS["PARAMS"]}", __FUNCTION__, __FILE__, __LINE__); return; } } @unlink($pidTime); @file_put_contents($pidTime, time()); $netbin = $unix->LOCATE_NET_BIN_PATH(); $usermod = $unix->find_program("usermod"); $chmod = $unix->find_program("chmod"); if (!is_file($netbin)) { WriteMyLogs("net no such binary, aborting", __FUNCTION__, __FILE__, __LINE__); return; } if (is_dir("/var/run/samba/winbindd_privileged")) { shell_exec("{$usermod} -G winbindd_priv squid >/dev/null 2>&1"); shell_exec("{$chmod} 0750 /var/run/samba/winbindd_privileged/ >/dev/null 2>&1"); } $array = unserialize(base64_decode($sock->GET_INFO("KerbAuthInfos"))); $domainUp = strtoupper($array["WINDOWS_DNS_SUFFIX"]); $domain_lower = strtolower($array["WINDOWS_DNS_SUFFIX"]); $adminpassword = $array["WINDOWS_SERVER_PASS"]; $adminpassword = $unix->shellEscapeChars($adminpassword); $adminname = $array["WINDOWS_SERVER_ADMIN"]; $ad_server = $array["WINDOWS_SERVER_NETBIOSNAME"]; $GLOBALS["AUTHCMD"] = " -U {$adminname}%{$adminpassword}"; getNetInfos(); if (!isset($GLOBALS["LDAP_HOST"])) { WriteMyLogs("Unable to get ldap infos, aborting", __FUNCTION__, __FILE__, __LINE__); return; } GetUsersArray(); }
function build_blacklists($aspid = false) { $unix = new unix(); $FINALARRAY = array(); $f = array(); $PidFile = "/etc/artica-postfix/pids/squid_build_blacklists.pid"; $dbfile = "/var/log/squid/ufdbgclient.black.db"; if ($aspid) { $pid = $unix->get_pid_from_file($PidFile); if ($pid != getmypid()) { if ($unix->process_exists($pid, basename(__FILE__))) { echo "Starting......: " . date("H:i:s") . " Blacklists: Another artica script running pid {$pid}, aborting ...\n"; WriteToSyslogMail("build_blacklists():: Another artica script running pid {$pid}, aborting ...", basename(__FILE__)); return; } } } @unlink($dbfile); try { echo "berekley_db:: Creating {$dbfile} database\n"; $db_desttmp = @dba_open($dbfile, "c", "db4"); @dba_close($db_desttmp); } catch (Exception $e) { $error = $e->getMessage(); echo "berekley_db::FATAL ERROR {$error} on {$dbfile}\n"; return; } $q = new mysql_squid_builder(); $array = array(); $db_con = @dba_open($dbfile, "c", "db4"); $sql = "SELECT * FROM deny_websites"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { echo "Starting......: " . date("H:i:s") . " [ACLS]: {$q->mysql_error}\n"; return; } @unlink("/etc/squid3/www-blacklists.db"); while ($ligne = mysql_fetch_assoc($results)) { if ($ligne["items"] == null) { continue; } $item = $ligne["items"]; $item = str_replace("/", "\\/", $item); $item = str_replace(".", "\\.", $item); $item = str_replace("*", ".*?", $item); @dba_replace($item, $item, $db_con); $array[] = $ligne["items"]; } @dba_close($db_con); @file_put_contents("/var/log/squid/ufdbgclient.reload", "#"); @chown("/var/log/squid/ufdbgclient.reload", "squid"); @chgrp("/var/log/squid/ufdbgclient.reload", "squid"); $acl = new squid_acls(); $url_rewrite_program = $acl->clean_dstdomains($array); echo "Starting......: " . date("H:i:s") . " [ACLS]: " . count($url_rewrite_program) . " blacklisted webistes\n"; @file_put_contents("/etc/squid3/www-blacklists.db", @implode("\n", $url_rewrite_program) . "\n"); @chown("/etc/squid3/www-blacklists.db", "squid"); @chgrp("/etc/squid3/www-blacklists.db", "squid"); }
function start() { $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { return; } @file_put_contents($pidFile, getmypid()); $time = $unix->file_time_min($pidtime); if ($time < 5) { return; } @file_put_contents($pidtime, time()); $free = $unix->find_program("free"); $echo = $unix->find_program("echo"); $sync = $unix->find_program("sync"); $swapoff = $unix->find_program("swapoff"); $swapon = $unix->find_program("swapon"); exec("{$free} 2>&1", $results); $used = 0; $total = 0; while (list($num, $ligne) = each($results)) { if (preg_match("#Swap:\\s+([0-9]+)\\s+([0-9]+)\\s+([0-9]+)#", $ligne, $re)) { $total = $re[1]; $used = $re[2]; } } if (!is_numeric($total)) { return; } if ($total == 0) { return; } if ($used == 0) { return; } if ($total == $used) { return; } $tot1 = $used / $total; $tot1 = $tot1 * 100; if ($GLOBALS["VERBOSE"]) { echo "Swap:{$used}/{$total} - {$tot1}\n"; } $perc = round($tot1); if ($GLOBALS["VERBOSE"]) { echo "Swap:{$used}/{$total} {$perc}%\n"; } $t = time(); $GLOBALS["ALL_SCORES"]++; shell_exec("{$swapoff} -a && {$swapon} -a"); $usedTXT = FormatBytes($used); $report = $unix->ps_mem_report(); $distance = $unix->distanceOfTimeInWords($t, time(), true); squid_admin_mysql(0, "System swap exceed rule: {$perc}%", "Used {$usedTXT}\nSystem cache was flushed took {$distance}\nThis means you did have enough memory for this computer.\n{$report}", __FILE__, __LINE__); }
function compile_destination($cacheid) { $unix = new unix(); $sock = new sockets(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".compile_destination." . __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 (!is_numeric($cacheid)) { build_progress("Error Destination ID is not set", 110); return; } if ($cacheid == 0) { build_progress("Error Destination ID is Zero", 110); return; } $q = new mysql_squid_builder(); $sql = "SELECT servername FROM reverse_www WHERE cache_peer_id={$cacheid}"; $results = $q->QUERY_SQL($sql); if (!$q->ok) { build_progress("Error MySQL error", 110); echo $q->mysql_error; return; } $count = mysql_num_rows($results); if ($count == 0) { echo "{$sql}\n"; build_progress("Error no destination for ID {$cacheid}", 110); return; } build_progress("{$count} Destination(s)", 5); $c = 0; $php = $unix->LOCATE_PHP5_BIN(); while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) { $c++; $prc = $c / $count; $prc = $prc * 100; if ($prc > 90) { $prc = 90; } $servername = $ligne["servername"]; build_progress("{reconfigure} {$servername}", $prc); system("{$php} /usr/share/artica-postfix/exec.nginx.single.php {$servername} --no-reload --output --no-buildmain"); } build_progress("{cleaning_old_configs}...", 91); system("{$php} /usr/share/artica-postfix/exec.nginx.wizard.php --check-http"); build_progress("{building_main_settings}", 95); system("{$php} /usr/share/artica-postfix/exec.nginx.php --main"); build_progress("{$ligne["servername"]}: {reloading_reverse_proxy} ", 96); system("/etc/init.d/nginx reload --force"); build_progress("{$ligne["servername"]}: {reloading_reverse_proxy} {done}", 100); }
function install_key($keyfile) { $path = "/usr/share/artica-postfix/ressources/conf/upload/{$keyfile}"; $license_bin = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager"; $time = time(); $unix = new unix(); $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { if ($unix->PROCCESS_TIME_MIN($pid, 10) < 2) { progress("{failed} Already running", 110); echo "Already runinng PID {$pid}\n"; return; } } echo "License....: {$path}\n"; echo "Binary File: {$license_bin}\n"; if (!is_file($path)) { echo "{$path} No such file..\n"; progress("{failed} {$keyfile} No such file", 110); die; } if (!is_file($license_bin)) { echo "{$path} No such file..\n"; progress("{failed} " . basename($license_bin) . " No such binary", 110); @unlink($path); die; } $sock = new sockets(); $nohup = $unix->find_program("nohup"); $sock->SET_INFO("kavicapserverEnabled", 1); @unlink("/etc/artica-postfix/kav4proxy-licensemanager"); @unlink("/etc/artica-postfix/kav4proxy-licensemanager-i"); progress("{removing_old_licenses}", 20); system("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -d a"); progress("{installing} {$keyfile}", 30); $cmd = "/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -c /etc/opt/kaspersky/kav4proxy.conf -a {$path}"; system($cmd); @unlink($path); progress("{analyze_license} {$keyfile}", 50); shell_exec("/opt/kaspersky/kav4proxy/bin/kav4proxy-licensemanager -i >/etc/artica-postfix/kav4proxy-licensemanager-i 2>&1"); progress("{stopping_service}", 60); echo "/etc/init.d/kav4proxy stop\n"; system("/etc/init.d/kav4proxy stop"); progress("{starting_service}", 60); echo "/etc/init.d/kav4proxy start\n"; system("{$nohup} /etc/init.d/kav4proxy start >/dev/null 2>&1 &"); system("{$nohup} /etc/init.d/artica-status restart --force >/dev/null 2>&1 &"); progress("{launch_updates}", 70); $nohup = $unix->find_program("nohup"); $php = $unix - LOCATE_PHP5_BIN(); sleep(2); progress("{launch_updates}", 80); shell_exec("{$nohup} /usr/share/artica-postfix/exec.keepup2date.php --update --force >/dev/null 2>&1 &"); sleep(3); progress("{success}", 100); }
function sealion_pid() { $unix = new unix(); $pid = $unix->get_pid_from_file("/usr/local/sealion-agent/var/run/sealion.pid"); if ($unix->process_exists($pid)) { return $pid; } return 0; }
function squid_transparent_exe() { $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__))) { return; } @file_put_contents($pidfile, getmypid()); $sock = new sockets(); $squid = new squidbee(); $WizardProxyTransparent = unserialize($sock->GET_INFO("WizardProxyTransparent")); $WizardProxyTransparent = unserialize($sock->GET_INFO("WizardProxyTransparent")); $connected_port = intval($WizardProxyTransparent["connected_port"]); $transparent_port = intval($WizardProxyTransparent["transparent_port"]); $transparent_ssl_port = intval($WizardProxyTransparent["transparent_ssl_port"]); $EnableSSLBump = intval($WizardProxyTransparent["EnableSSLBump"]); if ($connected_port == 0) { build_progress("Fatal connected port unconfigured", 110); return; } if ($transparent_port == 0) { build_progress("Fatal Transparent port unconfigured", 110); return; } echo "Connected port........: {$connected_port}\n"; echo "Transparent port......: {$transparent_port}\n"; echo "Transparent SSL.......: {$EnableSSLBump}/{$transparent_ssl_port}\n"; sleep(3); build_progress("{reconfigure}", 20); $squid = new squidbee(); $squid->listen_port = $transparent_port; $squid->second_listen_port = $connected_port; $squid->hasProxyTransparent = 1; if ($EnableSSLBump == 1) { echo "EnableSquidSSLCRTD ----> 1\n"; $sock->SET_INFO("EnableSquidSSLCRTD", 1); $squid->SSL_BUMP = 1; $squid->ssl_port = $transparent_ssl_port; } build_progress("{saving_parameters}", 20); sleep(3); $squid->SaveToLdap(true); echo "hasProxyTransparent -------> 1\n"; $sock->SET_INFO("hasProxyTransparent", 1); echo "SquidTransparentMixed -----> 1\n"; $sock->SET_INFO("SquidTransparentMixed", 1); build_progress("{building_settings}", 30); $php = $unix->LOCATE_PHP5_BIN(); system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force"); build_progress("{restarting_service}", 50); system("{$php} /usr/share/artica-postfix/exec.squid.watchdog.php --restart --force"); build_progress("{apply_firewall_rules}", 90); system("{$php} /usr/share/artica-postfix/exec.squid.transparent.php --force"); build_progress("{done}", 100); }
function PID_NUM() { $unix = new unix(); $pid = $unix->get_pid_from_file("/var/run/openvpn/openvpn-server.pid"); if ($unix->process_exists($pid)) { return $pid; } $Masterbin = $unix->find_program("openvpn"); return $unix->PIDOF_PATTERN("{$Masterbin} --port.+?--dev"); }
function SQUID_PID() { $unix = new unix(); $squidbin = $unix->LOCATE_SQUID_BIN(); $pid = $unix->get_pid_from_file($unix->LOCATE_SQUID_PID()); if (!$unix->process_exists($pid)) { $pid = $unix->PIDOF($squidbin); } return $pid; }
function ScanFoldders() { $sock = new sockets(); $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $timefile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pid = $unix->get_pid_from_file($pidfile); if ($GLOBALS["VERBOSE"]) { echo "{$timefile}\n"; } if (system_is_overloaded(basename(__FILE__))) { die; } if ($unix->process_exists($pid, basename(__FILE__))) { $timeMin = $unix->PROCCESS_TIME_MIN($pid); if ($timeMin > 240) { system_admin_events("Too many TTL, {$pid} will be killed", __FUNCTION__, __FILE__, __LINE__, "logrotate"); $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } else { die; } } if (!$GLOBALS["FORCE"]) { $TimeExec = $unix->file_time_min($timefile); if ($TimeExec < 240) { return; } } @unlink($timefile); @file_put_contents($timefile, time()); $LogRotatePath = $sock->GET_INFO("LogRotatePath"); $SystemLogsPath = $sock->GET_INFO("SystemLogsPath"); $BackupMaxDaysDir = $sock->GET_INFO("BackupMaxDaysDir"); $maillogStoragePath = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/maillogStoragePath")); if ($GLOBALS["VERBOSE"]) { echo "Starting Main\n"; } $q = new mysql(); $q->QUERY_SQL("DROP TABLE `sysstorestatus`", "artica_events"); $sql = "CREATE TABLE IF NOT EXISTS `sysstorestatus` (\n\t\t\t `filepath` VARCHAR(255) NOT NULL,\n\t\t\t `filesize` BIGINT UNSIGNED NOT NULL,\n\t\t\t `zDate` DATETIME,\n\t\t\t PRIMARY KEY (`filepath`),\n\t\t\t KEY `zDate` (`zDate`),\n\t\t\t KEY `filesize` (`filesize`)\n\t\t\n\t\t\t)"; $q->QUERY_SQL($sql, "artica_events"); if (!$q->ok) { echo $q->mysql_error; return; } ScanThis("/home/postfix/maillog"); ScanThis("/home/logrotate"); ScanThis("/home/logrotate_backup"); ScanThis("/home/logs-backup"); ScanThis("/home/backup/postfix"); ScanThis($LogRotatePath); ScanThis($SystemLogsPath); ScanThis($maillogStoragePath); }
function build($uri) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { die; } @file_put_contents($pidfile, getmypid()); $echo = $unix->find_program("echo"); $curl = $unix->find_program("curl"); $squidbin = $unix->LOCATE_SQUID_BIN(); $curl = $unix->find_program("curl"); @unlink("/var/log/squid/request.debug"); $DirFinal = "/usr/share/artica-postfix/ressources/support/" . time(); @mkdir($DirFinal, 0755, true); $SquidMgrListenPort = trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidMgrListenPort")); shell_exec("{$echo} \"Proxy address 127.0.0.1:{$SquidMgrListenPort}\" > /var/log/squid/request.debug 2>&1"); shell_exec("{$echo} \"Url to test: {$uri} \" >> /var/log/squid/request.debug 2>&1"); progress("{rotate_logs_files}", 30); shell_exec("{$echo} \"Rotate & turn to debug... \" >> /var/log/squid/request.debug 2>&1"); @copy("/var/log/squid/access.log", "/var/log/squid/access.log." . time()); shell_exec("{$squidbin} -k rotate >> /var/log/squid/request.debug 2>&1"); progress("{turn_to_debug}", 35); shell_exec("{$squidbin} -k debug >/dev/null 2>&1"); sleep(4); progress("{send_query}", 40); $cmd = "{$curl} --head --verbose --trace-time --proxy http://127.0.0.1:{$SquidMgrListenPort} --url {$uri} >> /var/log/squid/request.debug 2>&1"; shell_exec("{$echo} \"{$cmd}\" >> /var/log/squid/request.debug 2>&1"); shell_exec($cmd); sleep(4); progress("{return_back_to_normal}", 40); LogsThisDebug("************************************************************"); squid_admin_mysql(1, "Reconfiguring proxy service", null, __FILE__, __LINE__); shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__) . " >> /var/log/squid/request.debug 2>&1"); LogsThisDebug("************************************************************"); sleep(1); @copy("/var/log/squid/cache.log", "{$DirFinal}/cache.log"); progress("{compressing_package}", 90); $tar = $unix->find_program("tar"); $rm = $unix->find_program("rm"); $filename = "request.tar.gz"; @unlink("/usr/share/artica-postfix/ressources/support/{$filename}"); @copy("/var/log/squid/request.debug", "{$DirFinal}/request.debug"); @unlink("/var/log/squid/request.debug"); chdir($DirFinal); $cmd = "{$tar} -cvzf /usr/share/artica-postfix/ressources/support/{$filename} * 2>&1"; exec($cmd, $results); @chmod("/usr/share/artica-postfix/ressources/support/{$filename}", 0755); shell_exec("{$rm} -rf {$DirFinal}"); LogsThisDebug("*********************************************************"); $c = 0; progress("{success}", 100); }
function scan() { if (system_is_overloaded(basename(__FILE__))) { apache_admin_mysql(0, "Overloaded system, retry next time....", null, __FILE__, __LINE__); return; } $pidtime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { events("A process, {$pid} Already exists..."); return; } $GLOBALS["MYHOSTNAME_PROXY"] = $unix->hostname_g(); @file_put_contents($pidFile, getmypid()); $time = $unix->file_time_min($pidtime); if (!$GLOBALS["VERBOSE"]) { if ($time < 5) { events("{$time}mn, require minimal 5mn"); return; } } $q = new mysql_squid_builder(); $q->QUERY_SQL("CREATE TABLE IF NOT EXISTS `dashboard_apache_sizes` ( `TIME` DATETIME,\n\t\t\t`zmd5` VARCHAR(90) NOT NULL PRIMARY KEY,\n\t\t\t`SITENAME` VARCHAR(128),\n\t\t\t`SIZE` BIGINT UNSIGNED, `RQS` BIGINT UNSIGNED,\n\t\t\tKEY `TIME` (`TIME`),\n\t\t\tKEY `SIZE` (`SIZE`),\n\t\t\tKEY `RQS` (`RQS`)\n\t\t\t) ENGINE=MYISAM;"); if (!$q->ok) { apache_admin_mysql(0, "Fatal MySQL error", $q->mysql_error, __FILE__, __LINE__); return; } if (!is_file("/home/apache/artica-stats/requests.log")) { echo "/home/apache/artica-stats/requests.log no such file...\n"; return; } @mkdir("/home/apache/artica-stats/works", 0755, true); if (is_file("/home/apache/artica-stats/works/apache.log")) { echo "Parse /home/apache/artica-stats/works/apache.log\n"; Parse("/home/apache/artica-stats/works/apache.log"); return; } if (!@copy("/home/apache/artica-stats/requests.log", "/home/apache/artica-stats/works/apache.log")) { echo "Copy failed\n"; return; } if (!is_file("/home/apache/artica-stats/works/apache.log")) { echo "/home/apache/artica-stats/works/apache.log no such file...\n"; return; } @unlink("/home/apache/artica-stats/requests.log"); echo "Parse /home/apache/artica-stats/works/apache.log\n"; Parse("/home/apache/artica-stats/works/apache.log"); CLEAN_MYSQL(); }
function parse() { $TimeFile = "/etc/artica-postfix/pids/exec.squid.stats.quota-week.parser.php.time"; $pidfile = "/etc/artica-postfix/pids/exec.squid.stats.quota-week.parser.php.pid"; $unix = new unix(); $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "{$pid} already executed since {$timepid}Mn\n"; } if ($timepid < 14) { return; } $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } @file_put_contents($pidfile, getmypid()); $sock = new sockets(); $SquidPerformance = intval($sock->GET_INFO("SquidPerformance")); $time = $unix->file_time_min($TimeFile); if (!$GLOBALS["FORCE"]) { if ($time < 1440) { return; } } @unlink($TimeFile); @file_put_contents($TimeFile, time()); $f = $unix->DirFiles("/var/log/squid", "[0-9]+_QUOTASIZE\\.db"); $export_path = "/home/artica/squid/dbExport"; @mkdir($export_path, 0755, true); while (list($filename, $none) = each($f)) { preg_match("#([0-9]+)_#", $filename, $re); $xdate = $re[1]; echo "{$filename} ( {$xdate} )\n"; if ($SquidPerformance > 1) { if (!@copy("/var/log/squid/{$filename}", "{$export_path}/{$filename}")) { continue; } @unlink("/var/log/squid/{$filename}"); continue; } if (!parse_file("/var/log/squid/{$filename}", $xdate)) { continue; } if (!@copy("/var/log/squid/{$filename}", "{$export_path}/{$filename}")) { continue; } @unlink("/var/log/squid/{$filename}"); } }
function launch_tests() { $unix = new unix(); $php = $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__))) { return; } if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overloaded, aborting task...", __FUNCTION__, __FILE__, __LINE__, "system"); $unix->THREAD_COMMAND_SET("{$php} " . __FILE__); return; } @file_put_contents($pidfile, getmypid()); $datafile = "/etc/artica-postfix/settings/Daemons/HdparmInfos"; writelogs("Testing hard drives ({$datafile})", __FUNCTION__, __FILE__, __LINE__); $timenum = file_time_min($datafile); if (is_file($datafile)) { if (file_time_min($datafile) < 61) { writelogs("{$timenum}Mn executed, waiting 60Mn", __FUNCTION__, __FILE__, __LINE__); die; } } if ($GLOBALS["FIND_HDPARM"] == null) { writelogs("Unable to stat 'hdparm'", __FUNCTION__, __FILE__, __LINE__); die; } $disks = GetDisks(); if (!is_array($disks)) { return null; } while (list($index, $line) = each($disks)) { unset($results); exec("{$GLOBALS["FIND_HDPARM"]} -t {$index}", $results); while (list($num, $line_result) = each($results)) { if (preg_match("#=\\s+([0-9\\.]+)\\s+MB\\/sec\$#", $line_result, $re)) { if (preg_match("#.+?\\/(.+)\$#", $index, $ri)) { system_admin_events("{$ri[1]}:{$re[1]}MB/sec", __FUNCTION__, __FILE__, __LINE__, "system"); writelogs("testing disk {$ri[1]}:{$re[1]}MB/sec...", __FUNCTION__, __FILE__, __LINE__); $array[$ri[1]] = $re[1]; } } } } @unlink($datafile); @file_put_contents($datafile, base64_encode(serialize($array))); if (!is_file($datafile)) { writelogs("{$datafile} no such file or directory", __FUNCTION__, __FILE__, __LINE__); } }
function execute() { $pid = getmypid(); $pidfile = "/etc/artica-postfix/" . basename(__FILE__) . ".pid"; $unix = new unix(); if ($unix->process_exists($unix->get_pid_from_file($pidfile))) { die; } file_put_contents($pidfile, $pid); build_conf(); if (is_file("/etc/spamassassin/sa-learn-cyrus.conf")) { exec("/usr/share/artica-postfix/bin/sa-learn-cyrus", $results); $unix->send_email_events("Junk learning successfully executed for {$GLOBALS["USERS_LIST_COUNT"]} user(s)", @implode("\n", $results), 'mailbox'); } }
function execute(){ $pid=getmypid(); $pidfile="/etc/artica-postfix/".basename(__FILE__).".pid"; $unix=new unix(); if($unix->process_exists($unix->get_pid_from_file($pidfile))){ die(); } file_put_contents($pidfile,$pid); build_conf(); if(is_file("/etc/spamassassin/sa-learn-cyrus.conf")){ exec("/usr/share/artica-postfix/bin/sa-learn-cyrus",$results); } }
function parseQueue() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); $sock = new sockets(); if ($unix->process_exists($pid, basename(__FILE__))) { $pidTime = $unix->PROCCESS_TIME_MIN($pid); events("Already process PID: {$pid} running since {$pidTime} minutes", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } @file_put_contents($pidfile, getmypid()); if (system_is_overloaded(basename(__FILE__))) { events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } $EnableArticaSMTPStatistics = $sock->GET_INFO("EnableArticaSMTPStatistics"); if (!is_numeric($EnableArticaSMTPStatistics)) { $EnableArticaSMTPStatistics = 0; } $directory = "/var/log/artica-mail"; if (!is_dir($directory)) { return; } if (!($handle = @opendir($directory))) { return; } $q = new mysql_postfix_builder(); $q->CheckTables(); events("open {$directory}"); while (false !== ($filename = readdir($handle))) { if ($EnableArticaSMTPStatistics == 0) { @unlink("{$directory}/{$filename}"); continue; } if (!preg_match("#(.+?)\\.[0-9]+\\.aws#", $filename, $re)) { continue; } $instancename = $re[1]; ParseFile("{$directory}/{$filename}"); if (system_is_overloaded(basename(__FILE__))) { system_admin_events("Overloaded system, aborting", __FUNCTION__, __FILE__, __LINE__, "postfix-stats"); return; } } }
function 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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); stop(true); build(); sleep(1); start(true); }
function parse_days() { $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time"; if (!$GLOBALS["VERBOSE"]) { if ($unix->file_time_min($pidTime) < 1440) { return; } } $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); return; } @file_put_contents($pidfile, getmypid()); @unlink($pidTime); @file_put_contents($pidTime, time()); $sock = new sockets(); $EnableNginxStats = $sock->GET_INFO("EnableNginxStats"); if (!is_numeric($EnableNginxStats)) { $EnableNginxStats = 0; } if ($EnableNginxStats == 0) { return; } if (system_is_overloaded(basename(__FILE__))) { events("Overloaded system: {$GLOBALS["SYSTEM_INTERNAL_LOAD"]} aborting", __FUNCTION__, __LINE__); return; } $FALSES["information_schema"] = true; $FALSES["mysql"] = true; $q = new nginx_stats(); $DATABASE_LIST_SIMPLE = $q->DATABASE_LIST_SIMPLE(); while (list($db, $b) = each($DATABASE_LIST_SIMPLE)) { if (isset($FALSES[$db])) { continue; } if ($GLOBALS["VERBOSE"]) { echo "Parsing database {$db}\n"; } parse_database($db); } }
function startx() { if ($GLOBALS["VERBOSE"]) { $GLOBALS["FORCE"] = true; } $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $unix = new unix(); $pid = $unix->get_pid_from_file($pidFile); if ($unix->process_exists($pid)) { build_progress("Process already running PID {$pid}", 110); return; } @file_put_contents($pidFile, getmypid()); $php = $unix->LOCATE_PHP5_BIN(); build_progress("Reconfiguring Proxy service", 10); system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force"); build_progress("{stopping_proxy_service},{please_wait}", 50); system("{$php} /usr/share/artica-postfix/exec.squid.watchdog.php --stop --force"); build_progress("{starting_proxy_service},{please_wait}", 95); system("{$php} /usr/share/artica-postfix/exec.squid.watchdog.php --start --force"); build_progress("{done}", 100); }
function run() { $TimeFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".time"; $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid"; $unix = new unix(); $tmpfile = $unix->FILE_TEMP(); $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["VERBOSE"]) { echo "{$pid} already executed since {$timepid}Mn\n"; } if (!$GLOBALS["FORCE"]) { if ($timepid < 14) { return; } $kill = $unix->find_program("kill"); unix_system_kill_force($pid); } } @file_put_contents($pidfile, getmypid()); if (!$GLOBALS["FORCE"]) { if (!$GLOBALS["VERBOSE"]) { $time = $unix->file_time_min($TimeFile); if ($time < 14) { echo "Current {$time}Mn, require at least 14mn\n"; return; } } } $binary = "/usr/share/artica-postfix/bin/pflogsumm.pl"; @chmod("{$binary}", 0755); system("{$binary} -d today /var/log/mail.log >{$tmpfile}"); ParseReport($tmpfile); @unlink($tmpfile); stats_total(); }