Example #1
0
function build()
{
    $users = new usersMenus();
    $sock = new sockets();
    $unix = new unix();
    $SystemLoadNotif = $sock->GET_INFO("SystemLoadNotif");
    if (!is_numeric($SystemLoadNotif)) {
        $SystemLoadNotif = 0;
    }
    $EnableSyslogDB = $sock->GET_INFO("EnableSyslogDB");
    if (!is_numeric($EnableSyslogDB)) {
        $EnableSyslogDB = 0;
    }
    $MySQLSyslogType = $sock->GET_INFO("MySQLSyslogType");
    if (!is_numeric($MySQLSyslogType)) {
        $MySQLSyslogType = 1;
    }
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    $EnableIntelCeleron = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableIntelCeleron"));
    $python = $unix->find_program("python");
    $nice = $unix->EXEC_NICE();
    $ps = $unix->find_program("ps");
    $sort = $unix->find_program("sort");
    $head = $unix->find_program("head");
    $echo = $unix->find_program("echo");
    $date = $unix->find_program("date");
    $mkdir = $unix->find_program("mkdir");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $ZarafaDedicateMySQLServer = $sock->GET_INFO("ZarafaDedicateMySQLServer");
    if (!is_numeric($ZarafaDedicateMySQLServer)) {
        $ZarafaDedicateMySQLServer = 0;
    }
    build_progress_restart("{reconfiguring}", 22);
    $ini = new Bs_IniHandler();
    $ini->loadFile('/etc/artica-postfix/smtpnotif.conf');
    if (!is_numeric($ini->_params["SMTP"]["EnableNotifs"])) {
        $ini->_params["SMTP"]["EnableNotifs"] = 0;
    }
    if (!is_numeric($ini->_params["SMTP"]["tls_enabled"])) {
        $ini->_params["SMTP"]["tls_enabled"] = 0;
    }
    $smtp_server = trim($ini->_params["SMTP"]['smtp_server_name']);
    $smtp_server_port = $ini->_params["SMTP"]['smtp_server_port'];
    $smtp_dest = $ini->_params["SMTP"]['smtp_dest'];
    $smtp_sender = $ini->_params["SMTP"]['smtp_sender'];
    $smtp_auth_user = $ini->_params["SMTP"]['smtp_auth_user'];
    $smtp_auth_passwd = $ini->_params["SMTP"]['smtp_auth_passwd'];
    $tls_enabled = $ini->_params["SMTP"]["tls_enabled"];
    $recipientsZ = explode("\n", "/etc/artica-postfix/settings/Daemons/SmtpNotificationConfigCC");
    $recipients = array();
    while (list($index, $to) = each($recipientsZ)) {
        if (trim($to) == null) {
            continue;
        }
        $recipients[] = $to;
    }
    if ($smtp_server == null) {
        $ini->_params["SMTP"]["EnableNotifs"] = 0;
    }
    if ($smtp_dest == null) {
        if (count($recipients) == 0) {
            $ini->_params["SMTP"]["EnableNotifs"] = 0;
        }
    }
    if (!is_numeric($smtp_server_port)) {
        $smtp_server_port = 25;
    }
    $EnableNotifs = $ini->_params["SMTP"]["EnableNotifs"];
    $monit_not_on = 'instance,action';
    $f[] = 'set daemon 60 with start delay 5';
    $f[] = 'set idfile /var/run/monit/monit.id';
    $cpunum = $unix->CPU_NUMBER();
    $normal = $cpunum * 2 + 1;
    $normal2 = $cpunum * 2;
    $busy = $cpunum * 4;
    build_progress_restart("{reconfiguring}", 23);
    $EnableMONITSmtpNotif = $sock->GET_INFO("EnableMONITSmtpNotif");
    if (!is_numeric($EnableMONITSmtpNotif)) {
        $EnableMONITSmtpNotif = 1;
    }
    $MonitCPUUsage = intval($sock->GET_INFO("MonitCPUUsage"));
    $MonitCPUUsageCycles = intval($sock->GET_INFO("MonitCPUUsageCycles"));
    $MonitMemUsage = intval($sock->GET_INFO("MonitMemUsage"));
    $MonitMemUsageCycles = intval($sock->GET_INFO("MonitMemUsageCycles"));
    $MonitReportLoadVG1mn = intval($sock->GET_INFO("MonitReportLoadVG1mn"));
    $MonitReportLoadVG1mnCycles = intval($sock->GET_INFO("MonitReportLoadVG1mnCycles"));
    if ($MonitReportLoadVG1mnCycles == 0) {
        $MonitReportLoadVG1mnCycles = 5;
    }
    $MonitReportLoadVG5mn = intval($sock->GET_INFO("MonitReportLoadVG5mn"));
    $MonitReportLoadVG5mnCycles = intval($sock->GET_INFO("MonitReportLoadVG5mnCycles"));
    if ($MonitReportLoadVG5mnCycles == 0) {
        $MonitReportLoadVG5mnCycles = 15;
    }
    $MonitReportLoadVG15mn = intval($sock->GET_INFO("MonitReportLoadVG15mn"));
    $MonitReportLoadVG15mnCycles = intval($sock->GET_INFO("MonitReportLoadVG15mnCycles"));
    if ($MonitReportLoadVG15mnCycles == 0) {
        $MonitReportLoadVG15mnCycles = 60;
    }
    $MonitMemPurgeCache = intval($sock->GET_INFO("MonitMemPurgeCache"));
    $MonitMemPurgeCacheCycles = intval($sock->GET_INFO("MonitMemPurgeCacheCycles"));
    if ($MonitMemPurgeCache == 0) {
        $MonitMemPurgeCache = 70;
    }
    if ($MonitMemPurgeCacheCycles == 0) {
        $MonitMemPurgeCacheCycles = 5;
    }
    if ($MonitMemUsageCycles == 0) {
        $MonitMemUsageCycles = 5;
    }
    if ($MonitCPUUsageCycles == 0) {
        $MonitCPUUsageCycles = 15;
    }
    if ($MonitCPUUsage > 0) {
        if ($MonitCPUUsage < 50) {
            $MonitCPUUsage = 90;
        }
    }
    if ($MonitMemUsage > 0) {
        if ($MonitMemUsage < 50) {
            $MonitMemUsage = 90;
        }
    }
    build_progress_restart("{reconfiguring}", 24);
    $rmbin = $unix->find_program("rm");
    $echo = $unix->find_program("echo");
    $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    $f[] = 'set logfile syslog facility log_daemon';
    $f[] = 'set statefile /var/run/monit/monit.state';
    $f[] = '';
    if ($EnableNotifs == 1) {
        if ($EnableMONITSmtpNotif == 1) {
            $f[] = "set mailserver {$smtp_server} PORT {$smtp_server_port}";
            if (strlen($smtp_auth_user) > 0) {
                $f[] = "\tUSERNAME \"{$smtp_auth_user}\" PASSWORD \"{$smtp_auth_passwd}\"";
            }
            if ($tls_enabled == 1) {
                $f[] = "\tusing TLSV1";
            }
            $f[] = "\tset eventqueue";
            $f[] = "\tbasedir /var/monit";
            $f[] = "\tslots 100";
            $f[] = "\tset mail-format {";
            $f[] = "\t\tfrom: {$smtp_sender}";
            $f[] = "\t\tsubject: Artica service monitor: \$SERVICE \$EVENT";
            $f[] = "\t\tmessage: Artica service monitor  \$ACTION  \$SERVICE at  \$DATE on  \$HOST:  \$DESCRIPTION";
            $f[] = "\t}";
            $f[] = "set alert {$smtp_dest} but not on {{$monit_not_on}}";
            if ($recipients > 0) {
                while (list($index, $to) = each($recipientsZ)) {
                    $f[] = "set alert {$to} but not on {{$monit_not_on}}";
                }
            }
        }
    }
    build_progress_restart("{reconfiguring}", 25);
    $allips = $unix->NETWORK_ALL_INTERFACES(true);
    $f[] = "set httpd port 2874 and use address 127.0.0.1";
    $f[] = "\tallow 127.0.0.1";
    while (list($tcpi, $to) = each($allips)) {
        $f[] = "\tallow {$tcpi}";
    }
    $top = $unix->find_program("top");
    $hostname = $unix->hostname_g();
    $TSCR = array();
    if ($MonitReportLoadVG1mn > 0) {
        $TSCR[] = "\tif loadavg (1min) > {$MonitReportLoadVG1mn} for {$MonitReportLoadVG1mnCycles} cycles then exec \"/bin/artica-system-alert.sh LOAD_1 {$MonitReportLoadVG1mn}\"";
    }
    if ($MonitReportLoadVG5mn > 0) {
        $TSCR[] = "\tif loadavg (5min) > {$MonitReportLoadVG5mn} for {$MonitReportLoadVG5mnCycles} cycles then exec \"/bin/artica-system-alert.sh LOAD_5 {$MonitReportLoadVG5mn}\"";
    }
    if ($MonitReportLoadVG15mn > 0) {
        $TSCR[] = "\tif loadavg (15min) > {$MonitReportLoadVG15mn} for {$MonitReportLoadVG15mnCycles} cycles then exec \"/bin/artica-system-alert.sh LOAD_15 {$MonitReportLoadVG15mn}\"";
    }
    if ($MonitCPUUsage > 0) {
        if ($MonitCPUUsage < 75) {
            $MonitCPUUsage = 75;
        }
        $TSCR[] = "\tif cpu usage(system) > {$MonitCPUUsage}% for {$MonitCPUUsageCycles} cycles then exec \"/bin/artica-system-alert.sh CPU_SYSTEM {$MonitCPUUsage}\"";
        $TSCR[] = "\tif cpu usage(user) > {$MonitCPUUsage}% for {$MonitCPUUsageCycles} cycles then exec \"/bin/artica-system-alert.sh CPU_USER {$MonitCPUUsage}\"";
        $TSCR[] = "\tif cpu usage(wait) > {$MonitCPUUsage}% for {$MonitCPUUsageCycles} cycles then exec \"/bin/artica-system-alert.sh CPU_WAIT {$MonitCPUUsage}\"";
    }
    if ($MonitMemUsage > 0) {
        if ($MonitMemUsage < 75) {
            $MonitMemUsage = 75;
        }
        $TSCR[] = "\tif memory > {$MonitMemUsage}% for {$MonitMemUsageCycles} cycles then exec \"/bin/artica-system-alert.sh MEM {$MonitMemUsage}\"";
    }
    if ($MonitMemPurgeCache > 5) {
        @chmod("/usr/share/artica-postfix/exec.kernel.purge.cache.php", 0755);
        $TSCR[] = "\tif memory > {$MonitMemPurgeCache}% for {$MonitMemPurgeCacheCycles} cycles then exec \"/usr/share/artica-postfix/exec.kernel.purge.cache.php\"";
    }
    if (count($TSCR) > 1) {
        $f[] = "check system " . $unix->hostname_g();
        $f[] = @implode("\n", $TSCR);
    }
    $TSCR = array();
    $SCRIPT = array();
    $SCRIPT[] = "#!/bin/sh";
    $SCRIPT[] = "CURRENT=`{$date} +%s`";
    $SCRIPT[] = "DIR=\"/home/artica/system/perf-queue/\$CURRENT\"";
    $SCRIPT[] = "{$mkdir} -p \"\$DIR\"";
    $SCRIPT[] = "{$echo} \$CURRENT >\$DIR/time.txt";
    $SCRIPT[] = "{$echo} \$1 >\$DIR/why.txt";
    $SCRIPT[] = "{$echo} \$2 >\$DIR/why2.txt";
    $iotop = $unix->find_program("iotop");
    if (is_file($iotop)) {
        $SCRIPT[] = "{$iotop} -o -a -b -q -t -n 20  >\$DIR/iotop.txt || true";
    }
    $SCRIPT[] = "{$nice} {$python} /usr/share/artica-postfix/bin/ps_mem.py >\$DIR/psmem.txt 2>&1";
    $SCRIPT[] = "{$ps} --no-heading -eo user,pid,pcpu,args|{$sort} -grbk 3|{$head} -50 >\$DIR/TOP50-CPU.txt 2>&1";
    $SCRIPT[] = "{$ps} --no-heading -eo user,pid,pmem,args|{$sort} -grbk 3|{$head} -50 >\$DIR/TOP50-MEM.txt 2>&1";
    $SCRIPT[] = "{$ps} auxww  >\$DIR/ALLPS.txt 2>&1";
    $SCRIPT[] = "";
    @file_put_contents("/bin/artica-system-alert.sh", @implode("\n", $SCRIPT));
    @chmod("/bin/artica-system-alert.sh", 0755);
    $SCRIPT = array();
    $f[] = "";
    $f[] = "check host loopback with address 127.0.0.1";
    $f[] = "\tif failed icmp type echo with timeout 1 seconds then exec \"/bin/loopbackfailed.sh\"";
    $f[] = "";
    $loopbackfailed[] = "#!/bin/sh";
    $loopbackfailed[] = "{$php5} /usr/share/artica-postfix/exec.virtuals-ip.php --loopback";
    $loopbackfailed[] = "";
    @file_put_contents("/bin/loopbackfailed.sh", @implode("\n", $loopbackfailed));
    @chmod("/bin/loopbackfailed.sh", 0755);
    $loopbackfailed = array();
    build_progress_restart("{reconfiguring}", 25);
    //********************************************************************************************************************
    $f[] = "check file php.log with path /var/log/php.log";
    $f[] = "\tif size > 100 MB then";
    $f[] = "\t\texec \"/bin/clean-phplog.sh\"";
    $f[] = "";
    $f[] = "check file usrphp.log with path /usr/share/artica-postfix/ressources/logs/php.log";
    $f[] = "      if size > 100 MB then";
    $f[] = "\t\texec \"/bin/clean-phplog.sh\"";
    $f[] = "";
    $f[] = "check file squid-logger-start.log with path /var/log/artica-postfix/squid-logger-start.log";
    $f[] = "\tif size > 100 MB then";
    $f[] = "\t\texec \"/bin/squid-logger-start.sh\"";
    $f[] = "";
    build_progress_restart("{reconfiguring}", 26);
    $f[] = "include /etc/monit/conf.d/*";
    @file_put_contents("/etc/monit/monitrc", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} /etc/monit/monitrc done...\n";
    }
    $AA[] = "#!/bin/sh";
    $AA[] = "{$echo} \"#\" >/var/log/artica-postfix/squid-logger-start.log";
    $AA[] = "";
    @file_put_contents("/bin/squid-logger-start.sh", @implode("\n", $AA));
    @chmod("/bin/squid-logger-start.sh", 0755);
    $AA = array();
    $AA[] = "#!/bin/sh";
    $AA[] = "{$echo} \"#\" >/var/log/php.log";
    $AA[] = "";
    @file_put_contents("/bin/clean-phplog.sh", @implode("\n", $AA));
    @chmod("/bin/clean-phplog.sh", 0755);
    $AA = array();
    $monit = new monit();
    $monit->save();
    $INITD_PATH = $unix->SLAPD_INITD_PATH();
    $SLAPD_PID_FILE = $unix->SLAPD_PID_PATH();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    @unlink("/etc/monit/conf.d/APP_OPENLDAP.monitrc");
    //********************************************************************************************************************
    $f = array();
    //********************************************************************************************************************
    build_progress_restart("{reconfiguring}", 27);
    $f = array();
    $f[] = "check process APP_FRAMEWORK";
    $f[] = "with pidfile /var/run/lighttpd/framework.pid";
    $f[] = "start program = \"/etc/init.d/artica-framework start --monit\"";
    $f[] = "stop program =  \"/etc/init.d/artica-framework stop --monit\"";
    $f[] = "if 5 restarts within 5 cycles then timeout";
    @file_put_contents("/etc/monit/conf.d/articaframework.monitrc", @implode("\n", $f));
    $f = array();
    //********************************************************************************************************************
    $f = array();
    @unlink("/etc/monit/conf.d/APP_OPENSSH.monitrc");
    @unlink("/etc/monit/conf.d/APP_MYSQLD.monitrc");
    //********************************************************************************************************************
    $f = array();
    build_progress_restart("{reconfiguring}", 28);
    $f[] = "check process APP_ARTICA_STATUS with pidfile /etc/artica-postfix/exec.status.php.pid";
    $f[] = "\tstart program = \"/etc/init.d/artica-status start --monit\"";
    $f[] = "\tstop program = \"/etc/init.d/artica-status stop --monit\"";
    $f[] = "\tif 5 restarts within 5 cycles then timeout";
    $f[] = "";
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Artica Status...\n";
    }
    @file_put_contents("/etc/monit/conf.d/APP_ARTICASTATUS.monitrc", @implode("\n", $f));
    //********************************************************************************************************************
    $f = array();
    $EnableInflux = 1;
    if ($SquidPerformance > 2) {
        $EnableInflux = 0;
    }
    $InfluxUseRemote = intval($sock->GET_INFO("InfluxUseRemote"));
    $EnableInfluxDB = intval($sock->GET_INFO("EnableInfluxDB"));
    if ($InfluxUseRemote == 1) {
        $EnableInfluxDB = 0;
    }
    if ($EnableIntelCeleron == 1) {
        $EnableInflux = 0;
    }
    if ($EnableInfluxDB == 0) {
        $EnableInflux = 0;
    }
    if (is_file("/etc/artica-postfix/STATS_APPLIANCE")) {
        $EnableInflux = 1;
    }
    build_progress_restart("{reconfiguring}", 29);
    @unlink("/etc/monit/conf.d/APP_INFLUXDB.monitrc");
    @unlink("/etc/monit/conf.d/APP_POSTGRES.monitrc");
    if (is_file("/usr/local/ArticaStats/bin/postgres")) {
        if ($EnableInflux == 1) {
            $InfluxRestartMem = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/InfluxRestartMem"));
            $f[] = "check process APP_POSTGRES with pidfile /home/ArticaStatsDB/postmaster.pid";
            $f[] = "\tstart program = \"/etc/init.d/artica-postgres start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/artica-postgres --monit\"";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            if ($InfluxRestartMem > 50) {
                $f[] = "\tif totalmem > {$InfluxRestartMem} MB for 5 cycles then restart";
            }
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Artica Status...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_POSTGRES.monitrc", @implode("\n", $f));
            //********************************************************************************************************************
        }
    }
    $f = array();
    @unlink("/etc/monit/conf.d/squid.monitrc");
    @unlink("/etc/monit/conf.d/APP_SQUIDMAIN.monitrc");
    // ********************************************************************************************************************
    $f = array();
    @unlink("/etc/monit/conf.d/APP_SQUIDDB.monitrc");
    build_progress_restart("{reconfiguring} Proxy service", 30);
    if (is_dir("/opt/squidsql/data")) {
        if ($SQUIDEnable == 1) {
            $f = array();
            $f[] = "check process APP_SQUID_DB with pidfile /var/run/squid-db.pid";
            $f[] = "\tstart program = \"/etc/init.d/squid-db start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/squid-db stop --monit\"";
            $f[] = "\tif failed unixsocket /var/run/mysqld/squid-db.sock then restart";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Squid MySQL DB...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_SQUIDDB.monitrc", @implode("\n", $f));
        }
    }
    // ********************************************************************************************************************
    $f = array();
    build_progress_restart("{reconfiguring} Dnsmasq", 31);
    @unlink("/etc/monit/conf.d/APP_DNSMASQ.monitrc");
    if ($users->dnsmasq_installed) {
        $enabled = $sock->dnsmasq_enabled();
        if ($enabled == 1) {
            $f[] = "check process APP_DNSMASQ with pidfile /var/run/dnsmasq.pid";
            $f[] = "\tstart program = \"/etc/init.d/dnsmasq start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/dnsmasq stop --monit\"";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring DnsMASQ...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_DNSMASQ.monitrc", @implode("\n", $f));
        }
    }
    // ********************************************************************************************************************
    $f = array();
    build_progress_restart("{reconfiguring} Proftpd", 31);
    @unlink("/etc/monit/conf.d/APP_PROFTPD.monitrc");
    $proftpd = $unix->find_program("proftpd");
    if (is_file($proftpd)) {
        $enabled = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableProFTPD"));
        if ($enabled == 1) {
            $f[] = "check process APP_PROFTPD with pidfile /var/run/proftpd.pid";
            $f[] = "\tstart program = \"/etc/init.d/proftpd start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/proftpd stop --monit\"";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring DnsMASQ...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_PROFTPD.monitrc", @implode("\n", $f));
        }
    }
    // ********************************************************************************************************************
    $f = array();
    build_progress_restart("{reconfiguring} Bandwidthd", 31);
    @unlink("/etc/monit/conf.d/APP_BANDWIDTHD.monitrc");
    if (is_file("/usr/bandwidthd/bandwidthd")) {
        $enabled = $sock->Bandwidthd_enabled();
        if ($enabled == 1) {
            $f[] = "check process APP_BANDWIDTHD with pidfile /var/run/bandwidthd.pid";
            $f[] = "\tstart program = \"/etc/init.d/bandwidthd start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/bandwidthd stop --monit\"";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring DnsMASQ...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_BANDWIDTHD.monitrc", @implode("\n", $f));
        }
    }
    // ********************************************************************************************************************
    $f = array();
    build_progress_restart("{reconfiguring} rsyslog", 32);
    $rsyslogd = $unix->find_program("rsyslogd");
    @unlink("/etc/monit/conf.d/APP_RSYSLOG.monitrc");
    if (is_file($rsyslogd)) {
        $SCRIPT = array();
        $SCRIPT[] = "#!/bin/sh";
        $SCRIPT[] = "{$php5} /usr/share/artica-postfix/exec.watchdog.rsyslogd.php --start";
        $SCRIPT[] = "";
        @file_put_contents("/bin/artica-rsyslog-start.sh", @implode("\n", $SCRIPT));
        @chmod("/bin/artica-rsyslog-start.sh", 0755);
        $SCRIPT = array();
        $SCRIPT[] = "#!/bin/sh";
        $SCRIPT[] = "{$php5} /usr/share/artica-postfix/exec.watchdog.rsyslogd.php --stop";
        $SCRIPT[] = "";
        @file_put_contents("/bin/artica-rsyslog-stop.sh", @implode("\n", $SCRIPT));
        @chmod("/bin/artica-rsyslog-stop.sh", 0755);
        $SCRIPT = array();
        $f[] = "check process APP_RSYSLOG with pidfile /var/run/rsyslogd.pid";
        $f[] = "\tstart program = \"/bin/artica-rsyslog-start.sh\"";
        $f[] = "\tstop program = \"/bin/artica-rsyslog-stop.sh\"";
        $f[] = "\tif 5 restarts within 5 cycles then timeout";
        $f[] = "";
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring rsyslogd...\n";
        }
        @file_put_contents("/etc/monit/conf.d/APP_RSYSLOG.monitrc", @implode("\n", $f));
    }
    // ********************************************************************************************************************
    build_progress_restart("{reconfiguring} Squid-tail", 32);
    $APP_ARTICA_SQUID_TAIL = $unix->SQUID_TAIL_ENABLED();
    @unlink("/etc/monit/conf.d/APP_ARTICA_SQUID_TAIL.monitrc");
    if ($APP_ARTICA_SQUID_TAIL == 1) {
        $f = array();
        $f[] = "check process APP_ARTICA_SQUID_TAIL with pidfile /etc/artica-postfix/pids/exec.logfile_daemon.php.pid";
        $f[] = "\tstart program = \"/etc/init.d/squid-tail start\"";
        $f[] = "\tstop program = \"/etc/init.d/squid-tail stop\"";
        $f[] = "\tif cpu usage > 95% for 5 cycles then restart";
        $f[] = "\tif totalmem > 550.0 MB for 5 cycles then restart";
        $f[] = "\tif 5 restarts within 5 cycles then timeout";
        $f[] = "";
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring squid-tail...\n";
        }
        @file_put_contents("/etc/monit/conf.d/APP_ARTICA_SQUID_TAIL.monitrc", @implode("\n", $f));
    }
    // ********************************************************************************************************************
    build_progress_restart("{reconfiguring} Squid-Proxy", 32);
    $APP_SQUID = $unix->SQUID_ENABLED();
    @unlink("/etc/monit/conf.d/APP_SQUID.monitrc");
    if ($APP_SQUID == 1) {
        $MonitConfig = unserialize(base64_decode(@file_get_contents("/etc/artica-postfix/settings/SquidWatchdogMonitConfig")));
        if (!isset($MonitConfig["watchdog"])) {
            $MonitConfig["watchdog"] = 1;
        }
        if (!is_numeric($MonitConfig["watchdog"])) {
            $MonitConfig["watchdog"] = 1;
        }
        $f = array();
        if ($MonitConfig["watchdog"] == 1) {
            $MonitSquidMaxRestartMem = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/MonitSquidMaxRestartMem"));
            $MonitSquidMaxCPU = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/MonitSquidMaxCPU"));
            $f[] = "check process APP_SQUID with pidfile /var/run/squid/squid.pid";
            $f[] = "\tstart program = \"/etc/init.d/squid start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/squid stop --monit\"";
            if ($MonitSquidMaxCPU > 0) {
                $f[] = "\tif cpu usage > {$MonitSquidMaxCPU}% for 5 cycles then restart";
            }
            if ($MonitSquidMaxRestartMem > 0) {
                $f[] = "\tif totalmem > {$MonitSquidMaxRestartMem}.0 MB for 5 cycles then restart";
            }
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring squid...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_SQUID.monitrc", @implode("\n", $f));
        }
    }
    // ********************************************************************************************************************
    build_progress_restart("{reconfiguring} OpenLDAP", 32);
    $EnableOpenLDAP = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableOpenLDAP"));
    $SLAPD_PID_FILE = $unix->SLAPD_PID_PATH();
    @unlink("/etc/monit/conf.d/APP_SLAPD.monitrc");
    if ($EnableOpenLDAP == 1) {
        if ($EnableIntelCeleron == 0) {
            $f = array();
            $f[] = "check process APP_SLAPD with pidfile {$SLAPD_PID_FILE}";
            $f[] = "\tstart program = \"/etc/init.d/slapd start --force --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/slapd stop --force\"";
            $f[] = "\tif cpu usage > 95% for 5 cycles then restart";
            $f[] = "\tif totalmem > 550.0 MB for 5 cycles then restart";
            $f[] = "\tif failed unixsocket /var/run/slapd/slapd.sock then restart";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring slapd...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_SLAPD.monitrc", @implode("\n", $f));
        }
    }
    // ********************************************************************************************************************
    $f = array();
    build_progress_restart("{reconfiguring} Suricata", 32);
    $EnableSuricata = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableSuricata"));
    @unlink("/etc/monit/conf.d/APP_SURICATA.monitrc");
    @unlink("/etc/monit/conf.d/APP_SURICATA_TAIL.monitrc");
    $suricata = $unix->find_program("suricata");
    if (is_file($suricata)) {
        if ($EnableSuricata == 1) {
            $f[] = "check process APP_SURICATA with pidfile /var/run/suricata/suricata.pid";
            $f[] = "\tstart program = \"/etc/init.d/suricata start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/suricata stop --monit\"";
            $f[] = "\tif cpu usage > 95% for 5 cycles then restart";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Suricata...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_SURICATA.monitrc", @implode("\n", $f));
            $f = array();
            $f[] = "check process APP_SURICATA_TAIL with pidfile /etc/artica-postfix/exec.suricata-tail.php.pid";
            $f[] = "\tstart program = \"/etc/init.d/suricata-tail start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/suricata-tail stop --monit\"";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Suricata tail...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_SURICATA_TAIL.monitrc", @implode("\n", $f));
        }
    }
    // ********************************************************************************************************************
    $f = array();
    build_progress_restart("{reconfiguring}", 32);
    $winbind = $unix->find_program("winbindd");
    if (is_file("/etc/monit/conf.d/winbindd.monitrc")) {
        @unlink("/etc/monit/conf.d/winbindd.monitrc");
    }
    @unlink("/etc/monit/conf.d/winbind.monitrc");
    $EnableKerbAuth = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableKerbAuth"));
    if (is_file($winbind)) {
        if ($EnableKerbAuth == 1) {
            $f[] = "check process winbindd with pidfile /var/run/samba/winbindd.pid";
            $f[] = "\tstart program = \"/etc/init.d/winbind start\"";
            $f[] = "\tstop program = \"/etc/init.d/winbind stop\"";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring winbindd...\n";
            }
            @file_put_contents("/etc/monit/conf.d/winbind.monitrc", @implode("\n", $f));
        }
    }
    // ********************************************************************************************************************
    $f = array();
    build_progress_restart("{reconfiguring}", 33);
    @unlink("/etc/monit/conf.d/APP_CICAP.monitrc");
    if ($users->C_ICAP_INSTALLED) {
        if ($SQUIDEnable == 1) {
            $CicapEnabled = $sock->GET_INFO("CicapEnabled");
            if (!is_numeric($CicapEnabled)) {
                $CicapEnabled = 0;
            }
            if ($CicapEnabled == 1) {
                $f[] = "check process APP_C_ICAP with pidfile /var/run/c-icap/c-icap.pid";
                $f[] = "\tstart program = \"/etc/init.d/artica-postfix start cicap\"";
                $f[] = "\tstop program = \"/etc/init.d/artica-postfix stop cicap\"";
                $f[] = "\tif 5 restarts within 5 cycles then timeout";
                $f[] = "";
                if ($GLOBALS["OUTPUT"]) {
                    echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring C-ICAP...\n";
                }
                @file_put_contents("/etc/monit/conf.d/APP_CICAP.monitrc", @implode("\n", $f));
            }
        }
    }
    // ********************************************************************************************************************
    build_progress_restart("{reconfiguring}", 34);
    @unlink("/etc/monit/conf.d/APP_SYSLOGDB.monitrc");
    if ($EnableSyslogDB == 1) {
        if ($MySQLSyslogType == 1) {
            $f = array();
            $f[] = "check process APP_SYSLOG_DB with pidfile /var/run/syslogdb.pid";
            $f[] = "\tstart program = \"/etc/init.d/syslog-db start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/syslog-db stop --monit\"";
            $f[] = "\tif failed unixsocket /var/run/syslogdb.sock then restart";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring syslogd...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_SYSLOGDB.monitrc", @implode("\n", $f));
            $f = array();
        }
    }
    //********************************************************************************************************************
    $f = array();
    @unlink("/etc/monit/conf.d/cron.monitrc");
    if (is_file("/etc/monit/templates/rootbin")) {
        $f[] = "check process crond with pidfile /var/run/crond.pid";
        $f[] = "   group system";
        $f[] = "   group crond";
        $f[] = "   start program = \"/etc/init.d/cron start\"";
        $f[] = "   stop  program = \"/etc/init.d/cron stop\"";
        $f[] = "   if 5 restarts with 5 cycles then timeout";
        $f[] = "   depend cron_bin";
        $f[] = "   depend cron_rc";
        $f[] = "   depend cron_spool";
        $f[] = "";
        $f[] = " check file cron_bin with path /usr/sbin/cron";
        $f[] = "   group crond";
        $f[] = "   include /etc/monit/templates/rootbin";
        $f[] = "";
        $f[] = " check file cron_rc with path \"/etc/init.d/cron\"";
        $f[] = "   group crond";
        $f[] = "   include /etc/monit/templates/rootbin";
        $f[] = "";
        $f[] = " check directory cron_spool with path /var/spool/cron/crontabs";
        $f[] = "   group crond";
        $f[] = "   if failed permission 1730 then unmonitor";
        $f[] = "   if failed uid root        then unmonitor";
        $f[] = "   if failed gid crontab     then unmonitor";
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring cron...\n";
        }
        @file_put_contents("/etc/monit/conf.d/cron.monitrc", @implode("\n", $f));
        $f = array();
    }
    @unlink("/etc/monit/conf.d/APP_ZARAFASERVER.monitrc");
    @unlink("/etc/monit/conf.d/APP_ZARAFAGATEWAY.monitrc");
    @unlink("/etc/monit/conf.d/APP_ZARAFAAPACHE.monitrc");
    @unlink("/etc/monit/conf.d/APP_ZARAFAWEB.monitrc");
    @unlink("/etc/monit/conf.d/APP_ZARAFASPOOLER.monitrc");
    @unlink("/etc/monit/conf.d/APP_ZARAFADB.monitrc");
    build_progress_restart("{reconfiguring}", 35);
    if (is_file($unix->find_program("zarafa-server"))) {
        $ZarafaApacheEnable = $sock->GET_INFO("ZarafaApacheEnable");
        if (!is_numeric($ZarafaApacheEnable)) {
            $ZarafaApacheEnable = 1;
        }
        $ZarafaApachePort = $sock->GET_INFO("ZarafaApachePort");
        if (!is_numeric($ZarafaApachePort)) {
            $ZarafaApachePort = 9010;
        }
        if ($ZarafaDedicateMySQLServer == 1) {
            $f = array();
            $f[] = "check process APP_ZARAFA_DB with pidfile /var/run/zarafa-db.pid";
            $f[] = "\tstart program = \"/etc/init.d/zarafa-db start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/zarafa-db stop --monit\"";
            $f[] = "\tif failed unixsocket /var/run/mysqld/zarafa-db.sock then restart";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Zarafa Database...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_ZARAFADB.monitrc", @implode("\n", $f));
        }
        $f = array();
        $f[] = "check process APP_ZARAFA_SERVER with pidfile /var/run/zarafa-server.pid";
        $f[] = "\tstart program = \"/etc/init.d/zarafa-server start --monit\"";
        $f[] = "\tstop program = \"/etc/init.d/zarafa-server stop --monit\"";
        $f[] = "\tif failed unixsocket /var/run/zarafa then restart";
        $f[] = "\tif 5 restarts within 5 cycles then timeout";
        $f[] = "";
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Zarafa Server...\n";
        }
        @file_put_contents("/etc/monit/conf.d/APP_ZARAFASERVER.monitrc", @implode("\n", $f));
        $f = array();
        $f[] = "check process APP_ZARAFA_SPOOLER with pidfile /var/run/zarafa-spooler.pid";
        $f[] = "\tstart program = \"/etc/init.d/zarafa-spooler start --monit\"";
        $f[] = "\tstop program = \"/etc/init.d/zarafa-spooler stop --monit\"";
        $f[] = "\tif 5 restarts within 5 cycles then timeout";
        $f[] = "";
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Zarafa Spooler...\n";
        }
        @file_put_contents("/etc/monit/conf.d/APP_ZARAFASPOOLER.monitrc", @implode("\n", $f));
        $f = array();
        $f[] = "check process APP_ZARAFA_GATEWAY with pidfile /var/run/zarafa-gateway.pid";
        $f[] = "\tstart program = \"/etc/init.d/zarafa-gateway start --monit\"";
        $f[] = "\tstop program = \"/etc/init.d/zarafa-gateway stop --monit\"";
        $f[] = "\tif 5 restarts within 5 cycles then timeout";
        $f[] = "";
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Zarafa Gateway...\n";
        }
        @file_put_contents("/etc/monit/conf.d/APP_ZARAFAGATEWAY.monitrc", @implode("\n", $f));
    }
    //********************************************************************************************************************
    build_progress_restart("{reconfiguring}", 36);
    $EnableClamavDaemon = $sock->GET_INFO("EnableClamavDaemon");
    $EnableClamavDaemonForced = $sock->GET_INFO("EnableClamavDaemonForced");
    $CicapEnabled = $sock->GET_INFO("CicapEnabled");
    $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
    if (!is_numeric($EnableClamavDaemon)) {
        $EnableClamavDaemon = 0;
    }
    if (!is_numeric($EnableClamavDaemonForced)) {
        $EnableClamavDaemonForced = 0;
    }
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    if (!is_numeric($CicapEnabled)) {
        $CicapEnabled = 0;
    }
    if ($SQUIDEnable == 1) {
        if ($CicapEnabled == 1) {
            $EnableClamavDaemon = 1;
        }
    }
    if ($EnableClamavDaemonForced == 1) {
        $EnableClamavDaemon = 1;
    }
    //********************************************************************************************************************
    build_progress_restart("{reconfiguring}", 37);
    @unlink("/etc/monit/conf.d/APP_CLAMAV.monitrc");
    $MasterBin = $unix->find_program("clamd");
    if (is_file($MasterBin)) {
        if ($EnableClamavDaemon == 1) {
            $f = array();
            $f[] = "check process APP_CLAMAV";
            $f[] = "with pidfile /var/run/clamav/clamd.pid";
            $f[] = "start program = \"/etc/init.d/clamav-daemon start --monit\"";
            $f[] = "stop program =  \"/etc/init.d/clamav-daemon stop --monit\"";
            $f[] = "if 5 restarts within 5 cycles then timeout";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Clamd service...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_CLAMAV.monitrc", @implode("\n", $f));
            $f = array();
        }
    }
    //********************************************************************************************************************
    @unlink("/etc/monit/conf.d/ufdb.monitrc");
    @unlink("/etc/monit/conf.d/ufdbweb.monitrc");
    $ufdbbin = $unix->find_program("ufdbguardd");
    build_progress_restart("{reconfiguring}", 38);
    if (is_file($ufdbbin)) {
        $EnableUfdbGuard = intval($sock->EnableUfdbGuard());
        $UseRemoteUfdbguardService = $sock->GET_INFO('UseRemoteUfdbguardService');
        $EnableSquidGuardHTTPService = $sock->GET_INFO("EnableSquidGuardHTTPService");
        $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
        $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance");
        $SquidGuardApachePort = $sock->GET_INFO("SquidGuardApachePort");
        $SquidGuardApacheSSLPort = $sock->GET_INFO("SquidGuardApacheSSLPort");
        if (!is_numeric($UseRemoteUfdbguardService)) {
            $UseRemoteUfdbguardService = 0;
        }
        if (!is_numeric($EnableUfdbGuard)) {
            $EnableUfdbGuard = 0;
        }
        if (!is_numeric($EnableSquidGuardHTTPService)) {
            $EnableSquidGuardHTTPService = 1;
        }
        if (!is_numeric($EnableWebProxyStatsAppliance)) {
            $EnableWebProxyStatsAppliance = 0;
        }
        if ($EnableUfdbGuard == 0) {
            $EnableSquidGuardHTTPService = 0;
        }
        if ($EnableWebProxyStatsAppliance == 1) {
            $EnableSquidGuardHTTPService = 1;
        }
        if (!is_numeric($SquidGuardApachePort)) {
            $SquidGuardApachePort = "9020";
        }
        if (!is_numeric($SquidGuardApacheSSLPort)) {
            $SquidGuardApacheSSLPort = 9025;
        }
        if ($SquidPerformance > 2) {
            $EnableSquidGuardHTTPService = 0;
        }
        if ($SQUIDEnable == 1) {
            if ($EnableSquidGuardHTTPService == 1) {
                $f = array();
                $f[] = "check process APP_SQUIDGUARD_HTTP";
                $f[] = "with pidfile /var/run/lighttpd/squidguard-lighttpd.pid";
                $f[] = "start program = \"/etc/init.d/squidguard-http start --monit\"";
                $f[] = "stop program =  \"/etc/init.d/squidguard-http stop --monit\"";
                $f[] = "if failed host 127.0.0.1 port {$SquidGuardApachePort} then restart";
                $f[] = "if 5 restarts within 5 cycles then timeout";
                if ($GLOBALS["OUTPUT"]) {
                    echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Web filtering HTTP service...\n";
                }
                @file_put_contents("/etc/monit/conf.d/ufdbweb.monitrc", @implode("\n", $f));
            }
        }
    }
    //********************************************************************************************************************
    $EnableArticaFrontEndToNGninx = $sock->GET_INFO("EnableArticaFrontEndToNGninx");
    $EnableArticaFrontEndToApache = $sock->GET_INFO("EnableArticaFrontEndToApache");
    if (!is_numeric($EnableArticaFrontEndToNGninx)) {
        $EnableArticaFrontEndToNGninx = 0;
    }
    if (!is_numeric($EnableArticaFrontEndToApache)) {
        $EnableArticaFrontEndToApache = 0;
    }
    $EnableNginx = $sock->GET_INFO("EnableNginx");
    $EnableFreeWeb = $sock->GET_INFO("EnableFreeWeb");
    if (!is_numeric($EnableFreeWeb)) {
        $EnableFreeWeb = 0;
    }
    if (!is_numeric($EnableNginx)) {
        $EnableNginx = 1;
    }
    if ($EnableNginx == 0) {
        $EnableArticaFrontEndToNGninx = 0;
    }
    $pid = null;
    build_progress_restart("{reconfiguring}", 39);
    @unlink("/etc/monit/conf.d/APP_LIGHTTPD.monitrc");
    if ($EnableArticaFrontEndToNGninx == 0) {
        $pid = "/var/run/lighttpd/lighttpd.pid";
        if ($EnableArticaFrontEndToApache == 1) {
            $pid = "/var/run/artica-apache/apache.pid";
        }
        $f = array();
        $f[] = "check process APP_ARTICAWEBCONSOLE with pidfile {$pid}";
        $f[] = "\tstart program = \"/etc/init.d/artica-webconsole start --monit\"";
        $f[] = "\tstop program = \"/etc/init.d/artica-webconsole stop --monit\"";
        $f[] = "\tif 5 restarts within 5 cycles then timeout";
        $f[] = "";
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Artica Web Console...\n";
        }
        @file_put_contents("/etc/monit/conf.d/APP_LIGHTTPD.monitrc", @implode("\n", $f));
    }
    //********************************************************************************************************************
    @unlink("/etc/monit/conf.d/APP_NGINX.monitrc");
    $nginx = $unix->find_program("nginx");
    if (is_file($nginx)) {
        if ($EnableNginx == 1) {
            $f = array();
            $f[] = "check process APP_NGINX with pidfile /var/run/nginx.pid";
            $f[] = "\tstart program = \"/etc/init.d/nginx start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/nginx stop --monit\"";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring NgINX...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_NGINX.monitrc", @implode("\n", $f));
        }
    }
    //********************************************************************************************************************
    build_progress_restart("{reconfiguring}", 40);
    $f = array();
    if (is_file("/etc/init.d/sysklogd")) {
        $f[] = "check process APP_SYSLOGD with pidfile /var/run/syslogd.pid";
        $f[] = "\tstart program = \"/etc/init.d/sysklogd start --monit\"";
        $f[] = "\tstop program = \"/etc/init.d/sysklogd stop --monit\"";
        $f[] = "\tif 5 restarts within 5 cycles then timeout";
        $f[] = "\tcheck file syslogd_file with path /var/log/syslog";
        $f[] = "\tif timestamp > 10 minutes then restart";
        $f[] = "";
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring sysklogd...\n";
        }
        @file_put_contents("/etc/monit/conf.d/APP_SYSKLOGD.monitrc", @implode("\n", $f));
    }
    //********************************************************************************************************************
    build_progress_restart("{reconfiguring}", 41);
    $binpath = $unix->DHCPD_BIN_PATH();
    @unlink("/etc/monit/conf.d/APP_DHCPD.monitrc");
    $f = array();
    if (is_file($binpath)) {
        $EnableDHCPServer = $sock->GET_INFO("EnableDHCPServer");
        if (!is_numeric($EnableDHCPServer)) {
            $EnableDHCPServer = 0;
        }
        if ($EnableDHCPServer == 1) {
            $f[] = "check process APP_DHCP with pidfile /var/run/dhcpd.pid";
            $f[] = "\tstart program = \"/etc/init.d/isc-dhcp-server start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/isc-dhcp-server stop --monit\"";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring DHCP Service...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_DHCPD.monitrc", @implode("\n", $f));
        }
    }
    //********************************************************************************************************************
    $binpath = $unix->find_program("rdpproxy");
    build_progress_restart("{reconfiguring}", 42);
    @unlink("/etc/monit/conf.d/APP_RDPPROXY.monitrc");
    $f = array();
    if (is_file($binpath)) {
        $EnableRDPProxy = $sock->GET_INFO("EnableRDPProxy");
        if (!is_numeric($EnableRDPProxy)) {
            $EnableRDPProxy = 0;
        }
        if ($EnableRDPProxy == 1) {
            $f[] = "check process APP_RDPPROXY with pidfile /var/run/redemption/rdpproxy.pid";
            $f[] = "\tstart program = \"/etc/init.d/rdpproxy start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/rdpproxy stop --monit\"";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring RDP Proxy...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_RDPPROXY.monitrc", @implode("\n", $f));
        }
    }
    //********************************************************************************************************************
    build_progress_restart("{reconfiguring}", 43);
    @unlink("/etc/monit/conf.d/APP_DNSMASQ.monitrc");
    $f = array();
    $binpath = $unix->find_program("dnsmasq");
    if (is_file($binpath)) {
        $EnableDNSMASQ = $users->EnableDNSMASQ();
        if ($EnableDNSMASQ == 1) {
            $f[] = "check process APP_DNSMASQ with pidfile /var/run/dnsmasq.pid";
            $f[] = "\tstart program = \"/etc/init.d/dnsmasq start --monit\"";
            $f[] = "\tstop program = \"/etc/init.d/dnsmasq stop --monit\"";
            $f[] = "\tif 5 restarts within 5 cycles then timeout";
            $f[] = "";
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring DNSMasq Service...\n";
            }
            @file_put_contents("/etc/monit/conf.d/APP_DNSMASQ.monitrc", @implode("\n", $f));
        }
    }
    //********************************************************************************************************************
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} checking syslog\n";
    }
    if (is_file("/etc/init.d/syslog")) {
        checkDebSyslog();
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} configuration done\n";
    }
    shell_exec($GLOBALS["MONIT_CLASS"]->monitor_all_cmdline . " 2>&1");
    build_progress_restart("{reconfiguring}", 45);
}
function server_status()
{
    $PHP5_CURRENT_MEMORY = null;
    if (!$GLOBALS["VERBOSE"]) {
        if (!isset($_GET["without-cache"])) {
            unset($_GET["_"]);
            $md5CacheF = md5("server_status{$_SESSION["uid"]}{$tpl->language}" . serialize($_GET));
            $cachefile = "/usr/share/artica-postfix/ressources/interface-cache/{$md5CacheF}";
            if (file_time_sec_Web($cachefile) < 10) {
                return @file_get_contents($cachefile);
            }
        }
    }
    $BOGOMIPS = 0;
    if (is_file("/usr/share/artica-postfix/ressources/interface-cache/processor_type")) {
        $processor_type = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/interface-cache/processor_type"));
        $BOGOMIPS = intval($processor_type["BOGOMIPS"]);
    }
    $icon = "server-128-ok.png";
    $os = new os_system();
    $sock = new sockets();
    $users = new usersMenus();
    $Warn = false;
    $HyperWarn = true;
    $tpl = new templates();
    $EnableMsftncsi = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableMsftncsi"));
    $EnableIntelCeleron = intval($sock->GET_INFO("EnableIntelCeleron"));
    $ArticaAutoUpateOfficial = $sock->GET_INFO("ArticaAutoUpateOfficial");
    $ArticaAutoUpateNightly = intval($sock->GET_INFO("ArticaAutoUpateNightly"));
    $ArticaUpdateIntervalAllways = intval($sock->GET_INFO("ArticaUpdateIntervalAllways"));
    if (!is_numeric($ArticaAutoUpateOfficial)) {
        $ArticaAutoUpateOfficial = 1;
    }
    $RootPasswordChanged = intval($sock->GET_INFO("RootPasswordChanged"));
    $influxdb_version = @file_get_contents("{$GLOBALS["BASEDIR"]}/influxdb_version");
    $influxdbversionBin = $influxdb_version;
    $RegisterCloudBadEmail = intval($sock->GET_INFO("RegisterCloudBadEmail"));
    $InfluxUseRemote = intval($sock->GET_INFO("InfluxUseRemote"));
    $InfluxUseRemoteInfo = intval($sock->GET_INFO("InfluxUseRemoteInfo"));
    $SessionPathInMemory = intval($sock->GET_INFO("SessionPathInMemory"));
    $EnableBandwithCalculation = intval($sock->GET_INFO("EnableBandwithCalculation"));
    $DashBoardDNSPerfsStats = $sock->GET_INFO("DashBoardDNSPerfsStats");
    $BigDatav3Read = intval($sock->GET_INFO("BigDatav3Read"));
    $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient"));
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    $ArticaTechNetInfluxRepo = unserialize(base64_decode($sock->GET_INFO("ArticaTechNetInfluxRepo")));
    $LicenseInfos = unserialize(base64_decode($sock->GET_INFO("LicenseInfos")));
    $EnableArticaMetaServer = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableArticaMetaServer"));
    if ($EnableArticaMetaServer == 1) {
        $EnableArticaMetaClient = 0;
    }
    if ($EnableArticaMetaClient == 1) {
        $ArticaMetaHost = $sock->GET_INFO("ArticaMetaHost");
        if ($ArticaMetaHost == null) {
            $err[] = proxy_status_warning("{incorrect_meta_server_address}", "{click_to_edit}", "GotoArticaMeta()");
        }
    }
    if ($SessionPathInMemory > 0) {
        exec("/bin/df -h /var/lib/php5 2>&1", $results);
        while (list($num, $ligne) = each($results)) {
            if (!preg_match("#tmpfs\\s+(.+?)\\s+(.+?)\\s+(.+?)\\s+(.+?)%\\s+#", $ligne, $re)) {
                continue;
            }
            $PHP5_CURRENT_MEMORY = $re[4];
            $PHP5_CURRENT_MEMORY_SIZE = $re[1];
        }
    }
    if (!is_file("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER")) {
        $sock = new sockets();
        $CPU_NUMBER = intval($sock->getFrameWork("services.php?CPU-NUMBER=yes"));
    } else {
        $CPU_NUMBER = intval(@file_get_contents("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER"));
    }
    if ($CPU_NUMBER < 2) {
        if ($EnableIntelCeleron == 0) {
            $warn[] = status_important_event("{performance_issue_cpu_number_text}", "{click_to_fix}", "GotoOptimizeSystem()");
        }
    }
    if ($EnableMsftncsi == 1) {
        $msftncsiStatus = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/msftncsiStatus"));
        if ($msftncsiStatus == 3) {
            $warn[] = status_important_event("{network_awareness} !!", "", "GotoWatchdog()");
        }
    }
    $results = array();
    exec("/usr/bin/pgrep -l -f \"philesight --db\" 2>&1", $results);
    while (list($num, $ligne) = each($results)) {
        $ligne = trim($ligne);
        if ($ligne == null) {
            continue;
        }
        if (preg_match("#pgrep#", $ligne)) {
            continue;
        }
        if (!preg_match("#^([0-9]+)\\s+#", $ligne)) {
            $warn[] = status_important_event("{APP_PHILESIGHT_INDEXING}", null, "blur()");
            break;
        }
    }
    $curs = "OnMouseOver=\"this.style.cursor='pointer';\"\n\tOnMouseOut=\"this.style.cursor='auto'\"";
    $os->html_Memory_usage();
    $EnableKerbAuth = intval($sock->GET_INFO("EnableKerbAuth"));
    $MAIN = $os->meta_array;
    $PHP5_CURRENT_MEMORY_COLOR = "black";
    $LOAD_COLOR = "black";
    $ORG_LOAD = $MAIN["LOAD"]["ORG_LOAD"];
    $CPU_NUMBER = $MAIN["LOAD"]["CPU_NUMBER"];
    $MAXOVER = $MAIN["LOAD"]["MAXOVER"];
    $MEM_USED_POURC = $MAIN["MEM"]["MEM_USED_POURC"];
    $MEM_USED_COLOR = "black";
    $SWAP_POURC = $MAIN["SWAP_POURC"];
    $DISKY = array();
    $MAXOVER2 = $CPU_NUMBER - 1;
    if ($MAXOVER2 == 0) {
        $MAXOVER2 = 1.5;
    }
    $EnableIntelCeleronText = null;
    $CURVER = @file_get_contents("VERSION");
    $CURVER_KEY = str_replace(".", "", $CURVER);
    if ($EnableIntelCeleron == 1) {
        $EnableIntelCeleronText = "{intel_celeron_support}";
        $MAXOVER2 = 2;
    }
    $INFO_WORKING_TASK = INFO_WORKING_TASK();
    if (is_array($INFO_WORKING_TASK)) {
        $INFOS = $INFO_WORKING_TASK;
    }
    if (!$users->STATS_APPLIANCE) {
        if ($InfluxUseRemote == 0) {
            if ($EnableIntelCeleron == 0) {
                if ($InfluxUseRemoteInfo == 0) {
                    if ($SquidPerformance < 2) {
                        $INFOS[] = status_info_event("{suggest_remote_statistics_appliance}", "{suggest_remote_statistics_appliance}<br>{click_here}", "Loadjs('influx.remote.suggest.php')");
                    }
                }
            }
        }
    }
    if ($ORG_LOAD > $MAXOVER2) {
        $LOAD_COLOR = "#F59C44";
        $Warn = true;
        $icon = "server-128-warn.png";
        $microerror_text = "{overloaded} {$ORG_LOAD} &raquo; {$MAXOVER2}";
    }
    $SWAPERR = false;
    if ($ORG_LOAD > $MAXOVER) {
        $HyperWarn = true;
        $LOAD_COLOR = "#D32D2D";
        $icon = "server-128-critic.png";
        $microerror_text = "{overloaded} {$ORG_LOAD} &raquo; {$MAXOVER}";
    }
    if ($MEM_USED_POURC > 79) {
        $microerror_text = "{memory_warning}";
        if (!$HyperWarn) {
            $icon = "server-128-warn.png";
        }
        $MEM_USED_COLOR = "#F59C44";
        $jsOn = "GotoSystemMemory()";
        if (!$users->AsArticaAdministrator) {
            $jsOn = "blur()";
        }
        $err[] = "<tr><td style='font-size:18px;color:#d32d2d;vertical-align:middle'>\n\t\t<img src='img/warn-red-32.png' style='float:left;margin-right:10px'>\n\t\t<span style='text-decoration:underline' {$curs} OnClick=\"javascript:{$jsOn}\">{overloaded_memory}</span>\n\t\t</td></tr>";
        $SWAPERR = true;
    }
    if ($MEM_USED_POURC > 90) {
        $microerror_text = "{memory_alert}";
        $icon = "server-128-critic.png";
        $MEM_USED_COLOR = "#D32D2D";
        if (!$SWAPERR) {
            $jsOn = "GotoSystemMemory()";
            if (!$users->AsArticaAdministrator) {
                $jsOn = "blur()";
            }
            $icon = "disks-128-warn.png";
            $err[] = "<tr><td style='font-size:18px;color:#d32d2d;vertical-align:middle'>\n\t\t\t<img src='img/warn-red-32.png' style='float:left;margin-right:10px'>\n\t\t\t<span style='text-decoration:underline' {$curs} OnClick=\"javascript:{$jsOn}\">{overloaded_memory}</span>\n\t\t\t</td></tr>";
            $SWAPERR = true;
        }
    }
    if ($SWAP_POURC > 20) {
        if (!$HyperWarn) {
            $microerror_text = "{swap_warning}";
            $icon = "server-128-warn.png";
        }
        $SWAP_COLOR = "#F59C44";
    }
    if ($PHP5_CURRENT_MEMORY > 80) {
        if (!$HyperWarn) {
            $microerror_text = "{swap_warning}";
            $icon = "server-128-warn.png";
        }
        $PHP5_CURRENT_MEMORY_COLOR = "#F59C44";
    }
    if ($SWAP_POURC > 30) {
        if (!$HyperWarn) {
            $microerror_text = "{swap_warning}";
            $icon = "server-128-warn.png";
        }
        $SWAP_COLOR = "#D32D2D";
    }
    if ($SWAP_POURC > 50) {
        $microerror_text = "{swap_alert}";
        $icon = "server-128-critic.png";
        $SWAP_COLOR = "#D32D2D";
        $jsOn = "GotoSystemMemory()";
        if (!$users->AsArticaAdministrator) {
            $jsOn = "blur()";
        }
        $err[] = proxy_status_warning("{high_swap_value}", "{high_swap_value}", $jsOn);
    }
    if ($PHP5_CURRENT_MEMORY > 95) {
        if (!$HyperWarn) {
            $microerror_text = "{session_memory_warning}";
            $icon = "server-128-warn.png";
        }
        $PHP5_CURRENT_MEMORY_COLOR = "#D32D2D";
    }
    if ($EnableIntelCeleron == 0) {
        $sock->getFrameWork("postgres.php?is-installed=yes");
        $PostgresInstalled = intval($sock->GET_INFO("PostgresInstalled"));
        if ($PostgresInstalled == 0) {
            $jsOn = "Loadjs('influxdb.install.progress.php');";
            if (!$users->AsArticaAdministrator) {
                $jsOn = "blur()";
            }
            $err[] = proxy_status_warning("{influx_not_installed}", "{click_to_install}", $jsOn);
        } else {
            $influxdb_tests = influxdb_tests();
            if ($influxdb_tests != null) {
                $err[] = $influxdb_tests;
            }
        }
    }
    if (isset($LicenseInfos["FINAL_TIME"])) {
        if (is_numeric($LicenseInfos["FINAL_TIME"])) {
            $FINAL_TIME = intval($LicenseInfos["FINAL_TIME"]);
            $ExpiresSoon = intval(time_between_day_Web($FINAL_TIME));
            $jsOn = "GoToArticaLicense()";
            $distanceOfTimeInWords = distanceOfTimeInWords(time(), $FINAL_TIME);
            if (!$users->AsSystemAdministrator) {
                $jsOn = null;
            }
            $corporate_licence_will_expire_explain = $tpl->_ENGINE_parse_body("{corporate_licence_will_expire_explain}");
            $corporate_licence_will_expire_explain = str_replace("%d", $ExpiresSoon, $corporate_licence_will_expire_explain);
            if (time() > $FINAL_TIME) {
                $err[] = proxy_status_warning("{license2}:&nbsp;{license_expired} !!", "{license_expired_explain}", $jsOn);
            }
            if ($FINAL_TIME > time()) {
                if ($ExpiresSoon < 10) {
                    $err[] = proxy_status_warning("{corporate_licence_will_expire} ({$ExpiresSoon} {days})", "{$corporate_licence_will_expire_explain}", $jsOn);
                }
                if ($ExpiresSoon < 31) {
                    $ExpiresSoon = $ExpiresSoon + 1;
                    $warn[] = status_important_event("{license2}:&nbsp;{trial_period} - {$ExpiresSoon} {days} -", "{expiredate}:" . $tpl->time_to_date($FINAL_TIME) . " ({$distanceOfTimeInWords})", $jsOn);
                }
            }
        }
    }
    if (!$users->CGROUPS_INSTALLED) {
        $jsOn = "Loadjs('cgroups.install.progress.php');";
        if (!$users->AsArticaAdministrator) {
            $jsOn = "blur()";
        }
        $warn[] = status_important_event("{cgroups_not_installed}", "{click_to_install}", $jsOn);
    }
    if ($RegisterCloudBadEmail == 1) {
        $warn[] = status_important_event("{incorrect_email_address}", "{incorrect_email_address_cloud}", "GoToArticaLicense()");
    }
    if (!extension_loaded('pgsql')) {
        $warn[] = status_important_event("{missing_postgres_library}", "{missing_postgres_library_explain}", "Loadjs('admin.pgsql.php')");
    } else {
        if (!function_exists("pg_connect")) {
            $warn[] = status_important_event("{missing_postgres_library}", "{missing_postgres_library_explain}", "Loadjs('admin.pgsql.php')");
        }
    }
    if ($BOGOMIPS > 0) {
        if ($users->CGROUPS_INSTALLED) {
            if ($BOGOMIPS < 3500) {
                if ($EnableIntelCeleron == 0) {
                    $jsOn = "Loadjs('system.optimize.celeron.wizard.php');";
                    $err[] = status_important_event("{low_performance}", "{low_performance_link_explain}", $jsOn);
                }
            }
        }
    }
    $q = new mysql();
    $perfs_queue = $q->COUNT_ROWS("perfs_queue", "artica_events");
    if ($perfs_queue > 0) {
        $dashboard_perfs_queue = $tpl->_ENGINE_parse_body("{dashboard_perfs_queue}");
        $dashboard_perfs_queue = str_replace("%s", $perfs_queue, $dashboard_perfs_queue);
        $warn[] = status_important_event($dashboard_perfs_queue, "{$dashboard_perfs_queue}", "GotoDashBoardPerfQueue()");
    }
    $HostType = null;
    if ($users->VMWARE_HOST) {
        $HostType = "VMWare Edition";
        $HostTypejs = "GotoVMWareClient();";
        if (trim($sock->getFrameWork("services.php?vmtools_installed=yes")) != "TRUE") {
            $jsOn = "Loadjs('vmware.install.progress.php');";
            if (!$users->AsArticaAdministrator) {
                $jsOn = "blur()";
            }
            $warn[] = status_important_event("{APP_VMWARE_TOOLS_NOT_INSTALLED}", "{click_to_install}", $jsOn);
        }
    }
    if (is_array($MAIN["DISKS"])) {
        while (list($disk, $array) = each($MAIN["DISKS"])) {
            $POURC = $array["POURC"];
            $LABEL = $array["LABEL"];
            if ($LABEL == null) {
                $LABEL = $disk;
            }
            if ($POURC < 80) {
                continue;
            }
            $DISK_COLOR = "#F59C44";
            $icon = "server-128-warn.png";
            $microerror_text = "{partition_warning}";
            $diskZ = "\t\n\t\t\t<tr>\n\t\t\t<td style='font-size:20px;color:{$DISK_COLOR}'>{$LABEL} {$POURC}% {used}</td>\n\t\t\t</tr>";
            if ($POURC > 95) {
                $DISK_COLOR = "#D32D2D";
                $icon = "server-128-critic.png";
                $diskZ = "\t<tr>\n\t\t\t<td style='font-size:20px;color:{$DISK_COLOR}'>{$LABEL} {$POURC}% {used}</td>\n\t\t\t</tr>";
            }
            $DISKY[] = $diskZ;
        }
    }
    if ($RootPasswordChanged == 0) {
        $jsOn = "Loadjs('system.root.pwd.php')";
        if (!$users->AsSystemAdministrator) {
            $jsOn = null;
        }
        $err[] = status_important_event("{root_password_not_changed}", "{root_password_not_changed_text}", $jsOn);
    }
    if (count($err) > 0) {
        $errT[] = "<tr><td style='font-size:32px;color:#d32d2d;vertical-align:middle'>" . count($err) . " {issues}</td></tr>\n\t\t<tr><td colspan=2>&nbsp;</td></tr>\n\t\t";
    }
    $GotoSpeedTests = "GotoSpeedTests()";
    $GotoBandwidthdStats = "GotoBandwidthdStats()";
    $GoToSystem = "GoToSystem()";
    $GotToArticaUpdate = "GotToArticaUpdate()";
    $GotoOptimizeSystem = "GotoOptimizeSystem()";
    $GotoDNSPerfs = "GotoDNSPerfs()";
    $GotoSystemMemory = "GotoSystemMemory()";
    $GotoStatsSystem = "GotoStatsSystem()";
    $GotoStatsSystem_underline = "underline";
    $HostTypejs_underline = "underline";
    if (!$users->AsSystemAdministrator) {
        $microerror_text = null;
        $HostTypejs_underline = "none";
        $GotoStatsSystem_underline = "none";
        $HostTypejs = "blur();";
        $GoToSystem = "blur()";
        $GotoStatsSystem = "blur()";
        $GotoSystemMemory = "blur()";
        $GotoDNSPerfs = "blur()";
        $GotoOptimizeSystem = "blur()";
        $GotToArticaUpdate = "blur()";
        $GotoBandwidthdStats = "blur()";
        $GotoSpeedTests = "blur()";
    }
    if ($EnableBandwithCalculation == 1) {
        $q = new mysql();
        $sql = "SELECT * FROM speedtests ORDER BY zDate DESC LIMIT 0,1";
        $speedtests = null;
        $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_events"));
        $download = $ligne["download"];
        $upload = $ligne["upload"];
        $ISP = $ligne["ISP"];
        //Kbi/s upload 51.2 Kbi/s
        if ($download > 0) {
            $speedtests = "\n\t\t\t\t<tr>\n\t\t\t\t<td>&nbsp;</td>\n\t\t\t\t</tr>\n\t\t\t\t<tr>\n\t\t\t\t<td style='font-size:16px;'>\n\t\t\t\t<span style='color:black'><a href=\"javascript:blur();\"\n\t\t\t\tOnClick=\"javascript:{$GotoSpeedTests};\" style='text-decoration:{$GotoStatsSystem_underline}'>\n\t\t\t\t{bandwidth}: <i style='font-size:16px'>{$download}Kbit/sec {download2}</i></td>\n\t\t\t\t</tr><tr>\n\t\t\t\t<td style='font-size:16px;'>\n\t\t\t\t<span style='color:black'><a href=\"javascript:blur();\"\n\t\t\t\tOnClick=\"javascript:{$GotoSpeedTests};\" style='text-decoration:{$GotoStatsSystem_underline}'>\n\t\t\t\t{bandwidth}: <i style='font-size:16px'>{$upload}Kbit/sec {upload}</a> ({$ISP})</span></i></td>\n\t\t\t\t</tr>";
        }
    }
    if ($sock->Bandwidthd_enabled() == 1) {
        $q = new mysql_squid_builder();
        $bandwidthd_today = $q->COUNT_ROWS("bandwidthd_today");
        if ($bandwidthd_today > 0) {
            $speedtests = $speedtests . "\n\t\t\t<tr>\n\t\t\t<td style='font-size:18px;'>\n\t\t\t<table style='width:100%'>\n\t\t\t<tr>\n\t\t\t<td valign='middle' style='width:25px'><img src='img/graph-24.png'></td>\n\t\t\t<td valign='middle'>\n\t\t\t<span style='color:black'><a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:{$GotoBandwidthdStats};\" style='text-decoration:{$GotoStatsSystem_underline}'>\n\t\t\t<span style='font-size:18px;font-weight:bold'>{$bandwidthd_today}</span> <span style='font-size:18px;'>{nodes}</span></td>\n\t\t\t</tr>\n\t\t\t</table>\n\t\t\t</td>\n\t\t\t</tr>";
        }
    }
    if ($users->AsSystemAdministrator) {
        if ($EnableArticaMetaClient == 0) {
            if ($ArticaAutoUpateOfficial == 1) {
                $ArticaUpdateRepos = unserialize($sock->GET_INFO("ArticaUpdateRepos"));
                $key_nightly = update_find_latest_nightly($ArticaUpdateRepos);
                $key_offical = update_find_latest($ArticaUpdateRepos);
                $OFFICIALS = $ArticaUpdateRepos["OFF"];
                $Lastest = $OFFICIALS[$key_offical]["VERSION"];
                $MAIN_URI = $OFFICIALS[$key_offical]["URL"];
                $MAIN_MD5 = $OFFICIALS[$key_offical]["MD5"];
                $MAIN_FILENAME = $OFFICIALS[$key_offical]["FILENAME"];
                if ($key_offical > $CURVER_KEY) {
                    $err[] = "<tr><td style='font-size:18px;color:#46a346;vertical-align:middle' nowrap>\n\t\t\t\t<img src='img/32-install-soft.png' style='float:left;margin-right:10px'>\n\t\t\t\t" . texttooltip("{new_version}: {$Lastest}", "{NEW_RELEASE_TEXT}", "{$GotToArticaUpdate}") . "\n\t\t\t\t</td></tr>";
                }
            }
        }
    }
    if ($EnableIntelCeleron == 1) {
        $EnableIntelCeleron_explain = "<tr><td style='font-size:16px;color:#000000;vertical-align:middle' nowrap>\n\t\t\t\t<i>" . texttooltip("{CELERON_METHOD}", "{CELERON_METHOD_EXPLAIN}", $GotoOptimizeSystem) . "</i>\n\t\t\t\t</td></tr>";
    }
    $EnableDNSPerfs = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableDNSPerfs"));
    if ($EnableDNSPerfs == 1) {
        if ($EnableIntelCeleron == 0) {
            $DNS_COLOR = "black;";
            if ($DashBoardDNSPerfsStats != null) {
                $DashBoardDNSPerfsStats = round($DashBoardDNSPerfsStats, 2);
                if ($DashBoardDNSPerfsStats < 30) {
                    $DNS_COLOR = "#D32D2D";
                }
                $DashBoardDNSPerfsStats_text = "\n\t\t\t\t\t<tr>\n\t\t\t\t\t<td style='font-size:20px;color:{$DNS_COLOR}'>" . texttooltip("{dns_performance}", "{dnsperf_explain}", "{$GotoDNSPerfs}") . ": {$DashBoardDNSPerfsStats}%</td>\n\t\t\t\t\t</tr>";
            }
        }
    }
    if ($microerror_text != null) {
        $microerror_text = "<center style='margin-top:10px;font-weight:bold;font-size:14px'>{$microerror_text}</center>";
    }
    if ($HostType != null) {
        $HostType = "<center style='font-size:14px;margin-top:10px;'>\n\t<a href=\"javascript:blur();\" OnClick=\"javascript:{$HostTypejs}\" style='text-decoration:{$HostTypejs_underline}'>\n\t\t{$HostType}</a></center>";
    }
    $html[] = "\n\t<table style='width:100%'>\n\t<tr>\n\t<td valign='top' style='width:128px'  {$curs} OnClick=\"javascript:{$GoToSystem}\">\n\t\t<img src='img/{$icon}'>{$HostType}{$microerror_text}\n\t</td>\n\t<td>\n\t<table style='width:100%'>\n\t<tr>\n\t\t<td style='font-size:30px'  {$curs} OnClick=\"javascript:{$GoToSystem}\">{system}</td>\n\t</tr>\t\n\t<tr>\n\t<td style='font-size:30px;color:{$LOAD_COLOR};text-decoration:{$GotoStatsSystem_underline}' {$curs} OnClick=\"javascript:{$GotoStatsSystem};\">{$ORG_LOAD} {load2}</td>\n\t</tr>\n\t{$EnableIntelCeleron_explain}\n\t<tr>\n\t\t<td style='font-size:20px;'>\n\t\t<span style='color:{$MEM_USED_COLOR}'><a href=\"javascript:blur();\"\n\t\tOnClick=\"javascript:{$GotoSystemMemory};\" style='text-decoration:{$GotoStatsSystem_underline}'>\t\t\n\t\t{$MEM_USED_POURC}% {memory}</a></span>&nbsp;|&nbsp;\n\t\t<span style='color:{$SWAP_COLOR}'>{$SWAP_POURC}% SWAP</span></td>\n\t</tr>\n\t";
    if ($users->AsSystemAdministrator) {
        if ($PHP5_CURRENT_MEMORY != null) {
            $html[] = "<tr>\n\t\t\t<td style='font-size:18px;'>\n\t\t\t<span style='color:{$PHP5_CURRENT_MEMORY_COLOR}'><a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:{$GotoSystemMemory};\" style='text-decoration:{$GotoStatsSystem_underline}'>\n\t\t\t{session_memory}: {$PHP5_CURRENT_MEMORY}%/{$PHP5_CURRENT_MEMORY_SIZE}</a></span></td>\n\t\t\t</tr>";
        }
    }
    if ($users->AsSystemAdministrator) {
        if (is_file("/usr/share/artica-postfix/ressources/logs/web/monit.status.all")) {
            $dataMonit = unserialize(@file_get_contents("/usr/share/artica-postfix/ressources/logs/web/monit.status.all"));
            $dataMonitCount = count($dataMonit);
            $html[] = "<tr>\n\t\t\t<td style='font-size:18px;'>\n\t\t\t<span style='color:black'><a href=\"javascript:blur();\"\n\t\t\tOnClick=\"javascript:Loadjs('monit.php');\" style='text-decoration:underline'>\n\t\t\t{monitored_processes}: {$dataMonitCount}</a></span></td>\n\t\t\t</tr>";
        }
    }
    if (!$users->AsSystemAdministrator) {
        $INFOS = array();
        $errT = array();
        $err = array();
        $warn = array();
    }
    $html[] = $DashBoardDNSPerfsStats_text;
    if ($speedtests != null) {
        $html[] = $speedtests;
    }
    if (count($INFOS) > 0) {
        $html[] = @implode("", $INFOS);
        $html[] = "<tr><td colspan=2>&nbsp;</td></tr>";
    }
    if (count($DISKY) > 0) {
        $html[] = @implode("", $DISKY);
    }
    $page = CurrentPageName();
    $seqfw = "LoadAjaxRound('sequence-firewall','{$page}?sequence-firewall=yes');";
    if (isset($_GET["nofw"])) {
        $seqfw = null;
    }
    $html[] = "" . @implode("", $errT) . "\n\t" . @implode("", $err) . @implode("", $warn) . "\n\t\t\t\n\t</table>\n\t</td>\n\t</tr>\n\t</table>\n\t<script>\n\t\n\tfunction LoadseQuenceProxy(){\n\t\tLoadAjaxSilent('sequence-proxy','{$page}?sequence-proxy=yes&nofw=yes&sequence=yes');\n\t\n\t}\n\t\n\n\tfunction LoadSequenceServer(){\n\t\t\tif( !document.getElementById('sequence-server')){return;}\n\t\t\t\n\t\t\tvar DASHBOARD_SEQUENCE_SERVER=parseInt(document.getElementById('DASHBOARD_SEQUENCE_SERVER').value);\n\t\t\tif(DASHBOARD_SEQUENCE_SERVER<10){\n\t\t\t\tDASHBOARD_SEQUENCE_SERVER=DASHBOARD_SEQUENCE_SERVER+1;\n\t\t\t\tdocument.getElementById('DASHBOARD_SEQUENCE_SERVER').value=DASHBOARD_SEQUENCE_SERVER;\n\t\t\t\tsetTimeout('LoadSequenceServer()',1000);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\t\n\t\t\tdocument.getElementById('DASHBOARD_SEQUENCE_SERVER').value=0;\n\t\t\tLoadAjaxSilent('sequence-server','{$page}?sequence-server=yes&nofw=yes&sequence=yes');\n\t\t\tsetTimeout('LoadseQuenceProxy()',20000);\n\t\t}\n\tsetTimeout('LoadSequenceServer()',5000);\n\t</script>\t\t\n\t";
    $html = $tpl->_ENGINE_parse_body(@implode("", $html));
    @file_put_contents($cachefile, $html);
    return $html;
}
Example #3
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = "/usr/bandwidthd/bandwidthd";
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, arpd not installed\n";
        }
        return;
    }
    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["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} not enough memory\n";
        }
        if ($unix->process_exists($pid)) {
            stop();
        }
        return;
    }
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $EnableDaemon = intval($sock->Bandwidthd_enabled());
    if ($EnableDaemon == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableBandwidthd)\n";
        }
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    build();
    $cmd = "{$nohup} {$Masterbin} >/dev/null 2>&1 &";
    @unlink("/var/run/bandwidthd.pid");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
}