function load_stats()
{
    events("************************ SCHEDULE ****************************", __FUNCTION__, __LINE__);
    if (!isset($GLOBALS["CLASS_SOCKETS"])) {
        $GLOBALS["CLASS_SOCKETS"] = new sockets();
    }
    if (!isset($GLOBALS["CLASS_UNIX"])) {
        $unix = new unix();
    } else {
        $unix = $GLOBALS["CLASS_UNIX"];
    }
    $array_load = sys_getloadavg();
    $internal_load = $array_load[0];
    $time = time();
    $BASEDIR = "/usr/share/artica-postfix";
    $hash_mem = array();
    $files = $unix->DirFiles("/usr/share/artica-postfix/bin");
    while (list($filename, $line) = each($files)) {
        @chmod("/usr/share/artica-postfix/bin/{$filename}", 0755);
        @chown("/usr/share/artica-postfix/bin/{$filename}", "root");
    }
    @chmod("/usr/share/artica-postfix/ressources/mem.pl", 0755);
    $datas = shell_exec(dirname(__FILE__) . "/mem.pl");
    if (preg_match('#T=([0-9]+) U=([0-9]+)#', $datas, $re)) {
        $ram_used = $re[2];
    }
    @mkdir("/var/log/artica-postfix/sys_loadavg", 0755, true);
    @mkdir("/var/log/artica-postfix/sys_mem", 0755, true);
    @mkdir("/var/log/artica-postfix/sys_alerts", 0755, true);
    @mkdir("/etc/artica-postfix/croned.1", 0755, true);
    @mkdir("/etc/artica-postfix/pids", 0755, true);
    events("Internal Load: {$internal_load} Ram used: {$ram_used}", __FUNCTION__, __LINE__);
    @file_put_contents("/var/log/artica-postfix/sys_loadavg/{$time}", $internal_load);
    @file_put_contents("/var/log/artica-postfix/sys_mem/{$time}", $ram_used);
    $NtpdateAD = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("NtpdateAD"));
    $NTPDClientEnabled = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("NTPDClientEnabled"));
    if ($NtpdateAD == 1) {
        $NTPDClientEnabled = 1;
    }
    if (system_is_overloaded(basename(__FILE__))) {
        $date = time();
        if (!is_file("/var/log/artica-postfix/sys_alerts/{$date}")) {
            $ps = $unix->find_program("ps");
            $load = $GLOBALS["SYSTEM_INTERNAL_LOAD"];
            if (!$unix->process_exists($GLOBALS["CLASS_UNIX"]->PIDOF_PATTERN("{$ps}"))) {
                $cmd = trim($GLOBALS["nohup"] . " {$GLOBALS["NICE"]} {$ps} auxww >/var/log/artica-postfix/sys_alerts/{$date}-{$load} 2>&1");
                shell_exec($cmd);
            }
        }
    } else {
        if (is_file("/etc/artica-postfix/WEBSTATS_APPLIANCE")) {
            shell_exec_time("exec.squid.php --ping-clients-proxy", 5);
        }
    }
    // NTP CLIENT *****************************************************************************
    if ($NTPDClientEnabled == 1) {
        $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.squid.watchdog.php.start_watchdog.ntp.time");
        $NTPDClientPool = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("NTPDClientPool"));
        if ($NTPDClientPool == 0) {
            $NTPDClientPool = 120;
        }
        if ($time_file > $NTPDClientPool) {
            shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.ntpdate.php >/dev/null 2>&1 &");
        }
    }
    // ****************************************************************************************
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.syslog-engine.php.load_stats.time");
    if ($time_file > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.syslog-engine.php --load-stats >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.mpstat.php.time");
    if ($time_file > 1) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.mpstat.php >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.philesight.php.scan_directories.time");
    if ($time_file > 60) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.philesight.php --directories >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.seeker.php.xtart.time");
    events("seeker: {$time_file}mn/30mn");
    $GLOBALS["CLASS_UNIX"]->events("seeker: {$time_file}mn/30mn (/etc/artica-postfix/pids/exec.seeker.php.xtart.time)", "/var/log/seeker.log", false, __FUNCTION__, __LINE__, basename(__FILE__));
    if ($time_file > 5) {
        events("************ Executing seeker... ************");
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.seeker.php >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/croned.1/cron.notifs.php.time");
    if ($time_file > 5) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/cron.notifs.php >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.cleanfiles.php.time");
    if ($time_file > 120) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.cleanfiles.php >/dev/null 2>&1 &");
    }
    $timefile = $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.clean.logs.php.CleanLogs.time");
    if ($time_file > 240) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.clean.logs.php --clean-tmp >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.squid.watchdog.php.CHECK_DNS_SYSTEMS.time");
    events("CHECK_DNS_SYSTEMS: {$time_file}mn", __FUNCTION__, __LINE__);
    if ($time_file > 4) {
        $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.squid.watchdog.php --dns >/dev/null 2>&1 &";
        events($cmd, __FUNCTION__, __LINE__);
        shell_exec2("{$cmd}");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.clean.logs.php.clean_space.time");
    events("clean_space: {$time_file}mn", __FUNCTION__, __LINE__);
    if ($time_file > 240) {
        $cmd = "{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} {$BASEDIR}/exec.clean.logs.php --clean-space >/dev/null 2>&1 &";
        events($cmd, __FUNCTION__, __LINE__);
        shell_exec2("{$cmd}");
    }
    $kill = $GLOBALS["CLASS_UNIX"]->find_program("kill");
    $pgrep = $GLOBALS["CLASS_UNIX"]->find_program("pgrep");
    exec("pgrep -l -f \"exec.schedules.php --run\" 2>&1", $results);
    while (list($index, $line) = each($results)) {
        if (preg_match("#pgrep#", $line)) {
            continue;
        }
        if (!preg_match("#^([0-9]+)\\s+#", $line, $re)) {
            continue;
        }
        $pid = $re[1];
        $TTL = $GLOBALS["CLASS_UNIX"]->PROCCESS_TIME_MIN($pid);
        events("{$line} -> {$TTL}Mn");
        if ($TTL < 420) {
            continue;
        }
        ToSyslog("Killing exec.schedules.php PID {$pid}");
        unix_system_kill_force($pid);
    }
    events("************************ SCHEDULE ****************************", __FUNCTION__, __LINE__);
}
Beispiel #2
0
function Popuplate_cron()
{
    Build_default_values();
    shell_exec_time("exec.sys-stats.php", 2);
    $EnableDNSPerfs = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableDNSPerfs"));
    $EnableSquidQuotasBandwidth = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableSquidQuotasBandwidth"));
    $SquidSMTPNotifs = 0;
    if (is_file("/etc/artica-postfix/settings/Daemons/UfdbguardSMTPNotifs")) {
        $UfdbguardSMTPNotifs = unserialize(base64_decode(@file_get_contents("/etc/artica-postfix/settings/Daemons/UfdbguardSMTPNotifs")));
        if (!isset($UfdbguardSMTPNotifs["UfdbguardSMTPNotifs"]["ENABLED_SQUID_WATCHDOG"])) {
            $UfdbguardSMTPNotifs["UfdbguardSMTPNotifs"]["ENABLED_SQUID_WATCHDOG"] = 0;
        }
        $SquidSMTPNotifs = $UfdbguardSMTPNotifs["UfdbguardSMTPNotifs"]["ENABLED_SQUID_WATCHDOG"];
    }
    testspeed();
    $CRON_RELOAD = false;
    $EnableArticaMetaServer = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableArticaMetaServer"));
    if (!is_file("/etc/cron.hourly/squidrotate.sh")) {
        $CRON[] = "#!/bin/sh";
        $CRON[] = "export LC_ALL=C";
        $CRON[] = "{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.squid.rotate.php --cron >/dev/null 2>&1";
        $CRON[] = "";
        @file_put_contents("/etc/cron.hourly/squidrotate.sh", @implode("\n", $CRON));
        @chmod("/etc/cron.hourly/squidrotate.sh", 0755);
        $CRON_RELOAD = true;
    }
    if ($EnableSquidQuotasBandwidth == 1) {
        $SquidQuotaBandwidthRefresh = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/SquidQuotaBandwidthRefresh"));
        $SquidQuotaBandwidthRefresh_array[15] = "0,15,30,45 * * * *";
        $SquidQuotaBandwidthRefresh_array[30] = "0,30 * * * *";
        $SquidQuotaBandwidthRefresh_array[60] = "0 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * *";
        $SquidQuotaBandwidthRefresh_array[120] = "0 2,4,6,8,10,12,14,16,18,20,22 * * *";
        $FileMD5 = @md5_file("/etc/cron.d/squid-squidbandquot");
        Popuplate_cron_make("squid-squidbandquot", $SquidQuotaBandwidthRefresh_array[$SquidQuotaBandwidthRefresh], "exec.quotaband.php");
        $FileMD52 = @md5_file("/etc/cron.d/squid-squidbandquot");
        if ($FileMD5 != $FileMD52) {
            $CRON_RELOAD = true;
        }
    } else {
        if (is_file("/etc/cron.d/squid-squidbandquot")) {
            @unlink("/etc/cron.d/squid-squidbandquot");
            $CRON_RELOAD = true;
        }
    }
    if ($SquidSMTPNotifs == 1) {
        if (!is_file("/etc/cron.d/squid-notifications")) {
            Popuplate_cron_make("squid-notifications", "* * * * *", "exec.squid.smtp.notifications.php");
            $CRON_RELOAD = true;
        }
    } else {
        if (is_file("/etc/cron.d/squid-notifications")) {
            @unlink("/etc/cron.d/squid-notifications");
            $CRON_RELOAD = true;
        }
    }
    if ($EnableArticaMetaServer == 1) {
        if (!is_file("/etc/cron.d/artica-meta-ufdb")) {
            Popuplate_cron_make("artica-meta-ufdb", "45 0,2,4,6,8,10,12,14,16,18,20,22 * * *", "exec.squid.blacklists.php --bycron");
            $CRON_RELOAD = true;
        }
        if (!is_file("/etc/cron.d/ufdb-db-checkv")) {
            Popuplate_cron_make("ufdb-db-checkv", "30 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 * * *", "exec.squid.blacklists.php --get-version");
            $CRON_RELOAD = true;
        }
    } else {
        if (is_file("/etc/cron.d/artica-meta-ufdb")) {
            @unlink("/etc/cron.d/artica-meta-ufdb");
            $CRON_RELOAD = true;
        }
    }
    if (!is_file("/etc/cron.d/artica-squid-5min")) {
        Popuplate_cron_make("artica-squid-5min", "0,5,10,15,20,25,30,35,40,45,50,55 * * * *", "exec.squidMins.php");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-rxtx-stats")) {
        Popuplate_cron_make("artica-rxtx-stats", "10 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23 * * *", "exec.rxtx.hourly.php");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-sys-stats")) {
        Popuplate_cron_make("artica-sys-stats", "* * * * *", "exec.sys-stats.php");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/access-parser-logs")) {
        Popuplate_cron_make("access-parser-logs", "0 * * * *", "exec.squidparse.hourly.php");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/apache-parser-logs")) {
        Popuplate_cron_make("apache-parser-logs", "30 * * * *", "exec.apache.hour.php");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/access-parser-members")) {
        Popuplate_cron_make("access-parser-members", "5,15,30,45 * * * *", "exec.squidparse.members.php --rtt");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/access-parser-members-h")) {
        Popuplate_cron_make("access-parser-members-h", "0 * * * *", "exec.squidparse.members.php --hour");
        $CRON_RELOAD = true;
    }
    if ($EnableDNSPerfs == 1) {
        if (!is_file("/etc/cron.d/artica-dnsperf")) {
            Popuplate_cron_make("artica-dnsperf", "0,5,10,15,20,25,30,35,40,45,50,55 * * * *", "exec.dnsperf.php");
            $CRON_RELOAD = true;
        }
    } else {
        if (is_file("/etc/cron.d/artica-dnsperf")) {
            @unlink("/etc/cron.d/artica-dnsperf");
            $CRON_RELOAD = true;
        }
    }
    if (!is_file("/etc/cron.d/access-parser-failed")) {
        Popuplate_cron_make("access-parser-failed", "0,5,10,15,20,25,30,35,40,45,50,55 * * * *", "exec.squidparse.hourly.php --failed");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/available-softwares")) {
        Popuplate_cron_make("available-softwares", "30 0,8,16 * * *", "exec.web-community-filter.php --updates");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-clean-logs")) {
        Popuplate_cron_make("artica-clean-logs", "30 0,4,6,12 * * *", "exec.clean.logs.php --clean-tmp1");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-clean-tmp")) {
        Popuplate_cron_make("artica-clean-logs", "30 1,6,20,23 * * *", "exec.clean.logs.php --clean-logs");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-whatsnew")) {
        Popuplate_cron_make("artica-whatsnew", "30 8,10,12,16,18,20,22 * * *", "exec.web-community-filter.php --whatsnew");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-clean-RTTSize")) {
        Popuplate_cron_make("artica-clean-RTTSize", "30 4 * * *", "exec.clean.logs.php --rttsize");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-interface-size")) {
        Popuplate_cron_make("artica-interface-size", "0,15,30,45 * * * *", "exec.squid.interface-size.php");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-interface-hour")) {
        Popuplate_cron_make("artica-interface-hour", "25 * * * *", "exec.squid.interface-size.php --flux-hour");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-sys-alert")) {
        Popuplate_cron_make("artica-sys-alert", "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 * * * *", "exec.mpstat.php");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-auth-logs")) {
        Popuplate_cron_make("artica-auth-logs", "0,5,10,15,20,25,30,35,40,45,50,55 * * * *", "exec.syslog-engine.php --auth-logs");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-loadavg-interface")) {
        Popuplate_cron_make("artica-auth-logs", "0,5,10,15,20,25,30,35,40,45,50,55 * * * *", "exec.loadavg.php");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-usb-scan")) {
        Popuplate_cron_make("artica-usb-scan", "0,30 * * * *", "exec.usb.scan.write.php");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-nightly")) {
        Popuplate_cron_make("artica-nightly", "0,30 * * * *", "exec.nightly.php");
        $CRON_RELOAD = true;
    }
    if (!is_file("/etc/cron.d/artica-process1")) {
        $nice = $GLOBALS["CLASS_UNIX"]->EXEC_NICE();
        $PATH = "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/usr/share/artica-postfix/bin";
        $CRON[] = "PATH={$PATH}";
        $CRON[] = "MAILTO=\"\"";
        $CRON[] = "0 0,2,6,8,10,14,16,18,20 * * *\troot\t{$nice} /usr/share/artica-postfix/bin/process1 --force >/dev/null 2>&1";
        $CRON[] = "";
        file_put_contents("/etc/cron.d/artica-process1", @implode("\n", $CRON));
        chmod("/etc/cron.d/artica-process1", 0640);
        chown("/etc/cron.d/artica-process1", "root");
        $CRON_RELOAD = true;
        $CRON = array();
    }
    if ($CRON_RELOAD) {
        shell_exec2("/etc/init.d/cron reload");
    }
}