コード例 #1
0
ファイル: services.php プロジェクト: brucewu16899/1.6.x
function CPU_NUMBER()
{
    $unix = new unix();
    $CPUNUM = $unix->CPU_NUMBER();
    echo "<articadatascgi>{$CPUNUM}</articadatascgi>";
}
コード例 #2
0
ファイル: exec.nginx.php プロジェクト: BillTheBest/1.6.x
function build($OnlySingle = false)
{
    if (isset($GLOBALS[__FILE__ . __FUNCTION__])) {
        return;
    }
    $GLOBALS[__FILE__ . __FUNCTION__] = true;
    $unix = new unix();
    $php5 = $unix->LOCATE_PHP5_BIN();
    shell_exec("/etc/init.d/mysql start");
    build_progress("{building_main_settings}", 10);
    if ($unix->SQUID_GET_LISTEN_PORT() == 80) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Squid listen 80, ports conflicts, change it\n";
        }
        shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Restarting Squid-cache..\n";
        }
        shell_exec("/etc/init.d/squid restart --script=" . basename(__FILE__));
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: done...\n";
        }
    }
    if ($unix->SQUID_GET_LISTEN_SSL_PORT() == 443) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Squid listen 443, ports conflicts, change it\n";
        }
        shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Restarting Squid-cache..\n";
        }
        shell_exec("/etc/init.d/squid restart --script=" . basename(__FILE__));
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: done...\n";
        }
    }
    $reconfigured = false;
    if ($unix->APACHE_GET_LISTEN_PORT() == 80) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache listen 80, ports conflicts, change it\n";
        }
        shell_exec("{$php5} /usr/share/artica-postfix/exec.freeweb.php --build --force");
        shell_exec("{$php5} /usr/share/artica-postfix/exec.freeweb.php --stop --force");
        shell_exec("{$php5} /usr/share/artica-postfix/exec.freeweb.php --start --force");
        $reconfigured = true;
    }
    if (!$reconfigured) {
        if ($unix->APACHE_GET_LISTEN_PORT() == 443) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Apache listen 443, ports conflicts, change it\n";
            }
            shell_exec("{$php5} /usr/share/artica-postfix/exec.freeweb.php --build --force");
        }
    }
    $APACHE_USER = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP();
    $NginxProxyStorePath = "/home/nginx";
    @mkdir("/etc/nginx/sites-enabled", 0755, true);
    @mkdir("/etc/nginx/local-sites", 0755, true);
    @mkdir("/etc/nginx/local-sslsites", 0755, true);
    @mkdir($NginxProxyStorePath, 0755, true);
    @mkdir($NginxProxyStorePath . "/tmp", 0755, true);
    @mkdir($NginxProxyStorePath . "/disk", 0755, true);
    @mkdir("/var/lib/nginx/fastcgi", 0755, true);
    @mkdir("/home/nginx/tmp", 0755, true);
    $Tempdir = $unix->TEMP_DIR() . "/nginx";
    @mkdir($Tempdir, 0755, true);
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, $NginxProxyStorePath);
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, "/etc/nginx/sites-enabled");
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, $NginxProxyStorePath . "/tmp");
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, $NginxProxyStorePath . "/disk");
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, "/var/lib/nginx/fastcgi");
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, $Tempdir);
    nginx_ulimit();
    $workers = $unix->CPU_NUMBER();
    build_progress("Building configuration", 15);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Running {$APACHE_USER}:{$APACHE_SRC_GROUP}..\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Running {$workers} worker(s)..\n";
    }
    if (is_file("/etc/nginx/sites-enabled/default")) {
        @unlink("/etc/nginx/sites-enabled/default");
    }
    if (is_link("/etc/nginx/sites-enabled/default")) {
        @unlink("/etc/nginx/sites-enabled/default");
    }
    if (is_link("/etc/nginx/conf.d/example_ssl.conf")) {
        @unlink("/etc/nginx/conf.d/example_ssl.conf");
    }
    $limit = 4096 * $workers;
    if ($limit > 65535) {
        $limit = 65535;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Running limit of {$limit} open files\n";
    }
    $L = explode("\n", @file_get_contents("/etc/security/limits.conf"));
    $FOUNDL = false;
    $T = array();
    while (list($index, $line) = each($L)) {
        $line = trim($line);
        if (trim($line) == null) {
            continue;
        }
        if (substr($line, 0, 1) == "#") {
            continue;
        }
        if (preg_match("#^{$APACHE_USER}#", $line)) {
            continue;
        }
        $T[] = $line;
    }
    if (!$FOUNDL) {
        $T[] = "{$APACHE_USER}       soft    nofile   {$limit}";
        $T[] = "{$APACHE_USER}       hard    nofile   {$limit}";
    }
    @file_put_contents("/etc/security/limits.conf", @implode("\n", $T) . "\n");
    $L = array();
    $T = array();
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    $server_names_hash_bucket_size = 128;
    $worker_connections = 8192;
    if ($MEMORY < 624288) {
        $server_names_hash_bucket_size = 64;
        $worker_connections = 1024;
        $workers = 4;
    }
    $mail_protocols = mail_protocols();
    //
    $f[] = "# Builded on " . date("Y-m-d H:i:s");
    $f[] = "user   {$APACHE_USER};";
    $f[] = "worker_processes  {$workers};";
    $nginx_version = nginx_version();
    preg_match("#^([0-9])+\\.([0-9]+)\\.#", $nginx_version, $re);
    $re[1] = intval($re[1]);
    $re[2] = intval($re[2]);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Major {$re[1]} Minor:{$re[2]}\n";
    }
    $syslog = false;
    $f[] = "worker_rlimit_nofile 16384;";
    $f[] = "timer_resolution 1ms;";
    $f[] = "";
    if ($re[1] > 0) {
        if ($re[2] > 6) {
            $f[] = "error_log syslog:server=127.0.0.1,facility=daemon info;";
            $syslog = true;
        }
    }
    $syslog = false;
    if (!$syslog) {
        $f[] = "error_log  /var/log/nginx/error.log warn;";
    }
    $f[] = "pid        /var/run/nginx.pid;";
    $f[] = "";
    $f[] = "";
    $f[] = "events {";
    $f[] = "    worker_connections  {$worker_connections};";
    $f[] = "    multi_accept  on;";
    $f[] = "    use epoll;";
    $f[] = "\t  accept_mutex_delay 1ms;";
    $f[] = "}";
    $upstream = new nginx_upstream();
    $upstreams_servers = $upstream->build();
    $f[] = "";
    $f[] = "";
    $f[] = "http {";
    $f[] = "\tinclude /etc/nginx/mime.types;";
    $f[] = "\tlog_format  awc_log";
    $f[] = "\t\t'[\$server_name] \$remote_addr - \$remote_user [\$time_local] \$request '";
    $f[] = "\t\t'\"\$status\" \$body_bytes_sent \"\$http_referer\" '";
    $f[] = "\t\t'\"\$http_user_agent\" \"\$http_x_forwarded_for\" [\$upstream_cache_status]';";
    $f[] = "";
    $f[] = "\tlimit_conn_zone \$binary_remote_addr zone=LimitCnx:10m;";
    $q = new mysql_squid_builder();
    $results = $q->QUERY_SQL("SELECT LimitReqs,servername FROM reverse_www WHERE LimitReqs > 0");
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $servername = $ligne["servername"];
        $ZoneName = str_replace(".", "", $servername);
        $ZoneName = str_replace("-", "", $servername);
        $ZoneName = str_replace("_", "", $servername);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, limit {$servername}/{$servername} {$ligne["LimitReqs"]}r/s\n";
        }
        $f[] = "\tlimit_req_zone  \$binary_remote_addr  zone={$ZoneName}:10m   rate={$ligne["LimitReqs"]}r/s;";
    }
    $nginxClass = new nginx();
    if ($nginxClass->IsSubstitutions()) {
        //$f[]="\tsubs_filter_types text/html text/css text/xml;";
    }
    @mkdir($Tempdir, 0775, true);
    @mkdir("/home/nginx/tmp", 0755, true);
    $f[] = "\tlimit_conn_log_level info;";
    $f[] = "\tclient_body_temp_path {$Tempdir} 1 2;";
    $f[] = "\tclient_header_timeout 5s;";
    $f[] = "\tclient_body_timeout 5s;";
    $f[] = "\tsend_timeout 10m;";
    $f[] = "\tconnection_pool_size 128k;";
    $f[] = "\tclient_header_buffer_size 16k;";
    $f[] = "\tlarge_client_header_buffers 1024 128k;";
    $f[] = "\trequest_pool_size 128k;";
    $f[] = "\tkeepalive_requests 1000;";
    $f[] = "\tkeepalive_timeout 10;";
    $f[] = "\tclient_max_body_size 10g;";
    $f[] = "\tclient_body_buffer_size 1m;";
    $f[] = "\tclient_body_in_single_buffer on;";
    $f[] = "\topen_file_cache max=10000 inactive=300s;";
    $f[] = "\treset_timedout_connection on;";
    $f[] = "\ttypes_hash_max_size 8192;";
    $f[] = "\tserver_names_hash_bucket_size 128;";
    $f[] = "\tserver_names_hash_max_size 512;";
    $f[] = "\tvariables_hash_max_size 512;";
    $f[] = "\tvariables_hash_bucket_size 128;";
    $f[] = "\tfastcgi_buffers 8 16k;";
    $f[] = "\tfastcgi_buffer_size 32k;";
    $f[] = "\tfastcgi_connect_timeout 300;";
    $f[] = "\tfastcgi_send_timeout 300;";
    $f[] = "\tfastcgi_read_timeout 300;";
    $f[] = "map \$scheme \$server_https {";
    $f[] = "default off;";
    $f[] = "https on;";
    $f[] = "}\t";
    $f[] = "\tgzip on;";
    $f[] = "\tgzip_disable msie6;";
    $f[] = "\tgzip_static on;";
    $f[] = "\tgzip_min_length 1100;";
    $f[] = "\tgzip_buffers 16 8k;";
    $f[] = "\tgzip_comp_level 9;";
    $f[] = "\tgzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;";
    $f[] = "\tgzip_vary on;";
    $f[] = "\tgzip_proxied any;";
    $f[] = "\toutput_buffers 1000 128k;";
    $f[] = "\tpostpone_output 1460;";
    $f[] = "\tsendfile on;";
    $f[] = "\tsendfile_max_chunk 256k;";
    $f[] = "\ttcp_nopush on;";
    $f[] = "\ttcp_nodelay on;";
    $f[] = "\tserver_tokens off;";
    $dns = new resolv_conf();
    $sock = new sockets();
    if ($sock->dnsmasq_enabled()) {
        $resolver[] = "127.0.0.1";
    }
    if ($dns->MainArray["DNS1"] != null) {
        $resolver[] = $dns->MainArray["DNS1"];
    }
    if ($dns->MainArray["DNS2"] != null) {
        $resolver[] = $dns->MainArray["DNS2"];
    }
    if ($dns->MainArray["DNS3"] != null) {
        $resolver[] = $dns->MainArray["DNS3"];
    }
    $f[] = "\tresolver " . @implode(" ", $resolver) . ";";
    $f[] = "\tignore_invalid_headers on;";
    $f[] = "\tindex index.html;";
    $f[] = "\tadd_header X-CDN \"Served by myself\";";
    $q = new mysql_squid_builder();
    $sql = "SELECT * FROM nginx_caches  ORDER BY directory";
    $results = $q->QUERY_SQL($sql);
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $directory = $ligne["directory"];
        @mkdir($directory, 0755, true);
        $unix->chown_func("www-data", "www-data", $directory);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, cache `{$directory}`\n";
        }
        $f[] = "\tproxy_cache_path {$directory} levels={$ligne["levels"]} keys_zone={$ligne["keys_zone"]}:{$ligne["keys_zone_size"]}m max_size={$ligne["max_size"]}G  inactive={$ligne["inactive"]} loader_files={$ligne["loader_files"]} loader_sleep={$ligne["loader_sleep"]} loader_threshold={$ligne["loader_threshold"]};";
    }
    $f[] = "\tproxy_temp_path {$NginxProxyStorePath}/tmp/ 1 2;";
    $f[] = "\tproxy_cache_valid 404 10m;";
    $f[] = "\tproxy_cache_valid 400 501 502 503 504 1m;";
    $f[] = "\tproxy_cache_valid any 4320m;";
    $f[] = "\tproxy_cache_use_stale updating invalid_header error timeout http_404 http_500 http_502 http_503 http_504;";
    $f[] = "\tproxy_next_upstream error timeout invalid_header http_404 http_500 http_502 http_503 http_504;";
    $f[] = "\tproxy_redirect off;";
    $f[] = "\tproxy_set_header Host \$http_host;";
    $f[] = "\tproxy_set_header Server Apache;";
    $f[] = "\tproxy_set_header Connection Close;";
    $f[] = "\tproxy_pass_header Set-Cookie;";
    $f[] = "\tproxy_pass_header User-Agent;";
    $f[] = "\tproxy_set_header X-Accel-Buffering on;";
    $f[] = "\tproxy_hide_header X-CDN;";
    $f[] = "\tproxy_hide_header X-Server;";
    $f[] = "\tproxy_intercept_errors off;";
    $f[] = "\tproxy_ignore_client_abort on;";
    $f[] = "\tproxy_connect_timeout 60s;";
    $f[] = "\tproxy_send_timeout 60s;";
    $f[] = "\tproxy_read_timeout 150s;";
    $f[] = "\tproxy_buffer_size 64k;";
    $f[] = "\tproxy_buffers 16384 128k;";
    $f[] = "\tproxy_busy_buffers_size 256k;";
    $f[] = "\tproxy_temp_file_write_size 128k;";
    $f[] = "\tproxy_headers_hash_bucket_size 128;";
    $f[] = "\tproxy_cache_min_uses 0;";
    $f[] = "";
    $f[] = "{$upstreams_servers}";
    $f[] = "\tinclude /etc/nginx/sites-enabled/*.conf;";
    $f[] = "\tinclude /etc/nginx/local-sites/*.conf;";
    $f[] = "\tinclude /etc/nginx/conf.d/*.conf;";
    $f[] = "\t}";
    $f[] = $mail_protocols;
    $f[] = "";
    @copy("/etc/nginx/nginx.conf", "/etc/nginx/nginx.bak");
    @file_put_contents("/etc/nginx/nginx.conf", @implode("\n", $f));
    if (!$OnlySingle) {
        if ($GLOBALS["VERBOSE"]) {
            echo __FUNCTION__ . "." . __LINE__ . ": OK...\n";
        }
        build_progress("Building default configuration", 10);
        build_default(true);
        build_localhosts();
        if ($GLOBALS["VERBOSE"]) {
            echo __FUNCTION__ . "." . __LINE__ . ": OK...\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Only single defined\n";
        }
    }
    if ($GLOBALS["RECONFIGURE"]) {
        $pid = PID_NUM();
        if (is_numeric($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, reload pid {$pid}\n";
            }
            $kill = $unix->find_program("kill");
            unix_system_HUP($pid);
        } else {
            start(true);
        }
    }
    build_progress("Building configuration done", 10);
}
コード例 #3
0
ファイル: exec.monit.php プロジェクト: articatech/artica
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);
}
コード例 #4
0
function system_values()
{
    $unix = new unix();
    $CPU_NUMBER = $unix->CPU_NUMBER();
    @file_put_contents("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER", $CPU_NUMBER);
    events("CPU_NUMBER: {$CPU_NUMBER}");
    @chmod("/usr/share/artica-postfix/ressources/interface-cache/CPU_NUMBER", 0755);
    $influxdb_version = influxdb_version();
    events("InfluxDB version: {$influxdb_version}");
    @file_put_contents("{$GLOBALS["BASEDIR"]}/influxdb_version", $influxdb_version);
    @chmod("{$GLOBALS["BASEDIR"]}/influxdb_version", 0777);
}
コード例 #5
0
function WizardExecute($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    @chmod("/usr/share/artica-postfix/bin/process1", 0755);
    @mkdir("/etc/artica-postfix/settings/Daemons", 0755, true);
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            die;
        }
        $pid = $unix->PIDOF_PATTERN(basename(__FILE__));
        if ($pid != getmypid()) {
            return;
        }
    }
    @file_put_contents($pidfile, getmypid());
    $unix->CREATE_NEW_UUID();
    $uuid = $unix->GetUniqueID();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $php = $php5;
    $nohup = $unix->find_program("nohup");
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $DEBUG_LOG = "/var/log/artica-wizard.log";
    @mkdir("/etc/artica-postfix/ldap_settings", 0755, true);
    @mkdir("/var/lib/ldap", 0755, true);
    $rmbin = $unix->find_program("rm");
    writeprogress(5, "{set_permissions}...");
    shell_exec("{$php} /usr/share/artica-postfix/exec.checkfolder-permissions.php --force --wizard");
    writeprogress(10, "{uuid}: {$uuid}");
    sleep(2);
    $savedsettings = unserialize(base64_decode(file_get_contents("/etc/artica-postfix/settings/Daemons/WizardSavedSettings")));
    if (!is_array($savedsettings)) {
        writeprogress(110, "No saved settings Corrupted Array...");
        die;
    }
    if (count($savedsettings) < 4) {
        writeprogress(110, "No saved settings no enough element...");
        die;
    }
    $smtp_domainname = trim($savedsettings["smtp_domainname"]);
    if ($smtp_domainname == null) {
        if (isset($savedsettings["domain"])) {
            $smtp_domainname = $savedsettings["domain"];
        }
    }
    if (strlen($smtp_domainname) < 3) {
        $smtp_domainname = "my-domain.com";
    }
    if ($smtp_domainname == ".") {
        $smtp_domainname = "my-domain.com";
    }
    if ($smtp_domainname == null) {
        $smtp_domainname = "my-domain.com";
    }
    if (strpos($smtp_domainname, ".") == 0) {
        $smtp_domainname = "my-domain.com";
    }
    writeprogress(12, "Using `{$smtp_domainname}` as LDAP suffix");
    if (strpos($smtp_domainname, ".") > 0) {
        $smtp_domainname_exploded = explode(".", $smtp_domainname);
        writeprogress(12, "{$smtp_domainname} " . count($smtp_domainname_exploded) . " items");
        $suffix = "dc=" . @implode(",dc=", $smtp_domainname_exploded);
    } else {
        $suffix = "dc={$smtp_domainname}";
    }
    $SQUIDEnable = 1;
    $AsCategoriesAppliance = intval($savedsettings["AsCategoriesAppliance"]);
    $AsTransparentProxy = intval($savedsettings["AsTransparentProxy"]);
    $AsReverseProxyAppliance = intval($savedsettings["AsReverseProxyAppliance"]);
    $AsMetaServer = intval($savedsettings["AsMetaServer"]);
    $WizardWebFilteringLevel = $sock->GET_INFO("WizardWebFilteringLevel");
    if (is_numeric($WizardWebFilteringLevel)) {
        $WizardSavedSettings["EnableWebFiltering"] = 1;
    }
    @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableBWMng", 1);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidDatabasesUtlseEnable", 1);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/AsMetaServer", $AsMetaServer);
    @file_put_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance", $AsCategoriesAppliance);
    if ($AsCategoriesAppliance == 1) {
        $savedsettings["EnableWebFiltering"] = 0;
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/ProxyUseArticaDB", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableArpDaemon", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SlapdThreads", 2);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableBWMng", 1);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableNetDiscover", 1);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SambaEnabled", 0);
        $SQUIDEnable = 0;
    }
    if ($AsMetaServer == 1) {
        $savedsettings["EnableWebFiltering"] = 0;
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/ProxyUseArticaDB", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableArpDaemon", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SlapdThreads", 2);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableBWMng", 1);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableNetDiscover", 1);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SambaEnabled", 0);
        $SQUIDEnable = 0;
    }
    if ($AsReverseProxyAppliance == 1) {
        $AsCategoriesAppliance = 0;
        $AsTransparentProxy = 0;
        $savedsettings["EnableWebFiltering"] = 0;
        $savedsettings["adminwebserver"] = null;
        $savedsettings["second_webadmin"] = null;
        $SQUIDEnable = 0;
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableUfdbGuard", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SQUIDEnable", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/ProxyUseArticaDB", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableArpDaemon", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SlapdThreads", 2);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/DisableNetDiscover", 1);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/SambaEnabled", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableFreeWeb", 0);
        @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableNginx", 1);
    }
    if ($savedsettings["administrator"] != null) {
        writeprogress(13, "{creating_accounts} {artica_manager}: {$savedsettings["administrator"]}");
        sleep(2);
        @mkdir("/etc/artica-postfix/ldap_settings", 0755, true);
        @file_put_contents("/etc/artica-postfix/ldap_settings/admin", $savedsettings["administrator"]);
        @file_put_contents("/etc/artica-postfix/ldap_settings/password", $savedsettings["administratorpass"]);
        sleep(1);
        @unlink("/etc/artica-postfix/no-ldap-change");
        @chmod("/usr/share/artica-postfix/bin/artica-install", 0755);
        writeprogress(14, "{building_openldap_configuration_file}");
        system("/usr/share/artica-postfix/bin/artica-install --slapdconf >>{$DEBUG_LOG} 2>&1");
    } else {
        writeprogress(13, "{creating_accounts} {artica_manager}: {default} Manager");
        sleep(2);
    }
    writeprogress(15, "{creating_domain} LDAP {suffix}:{$suffix} ");
    @file_put_contents("/etc/artica-postfix/ldap_settings/suffix", $suffix);
    sleep(3);
    shell_exec("{$rmbin} -rf /var/lib/ldap/*");
    @file_put_contents("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED", time());
    writeprogress(16, "{reconfigure}: {openldap_server}");
    @unlink("/etc/artica-postfix/no-ldap-change");
    @chmod("/usr/share/artica-postfix/bin/artica-install", 0755);
    @chmod("/usr/share/artica-postfix/bin/process1", 0755);
    writeprogress(17, "{building_openldap_configuration_file}");
    system("/usr/share/artica-postfix/bin/artica-install --slapdconf >>{$DEBUG_LOG} 2>&1");
    writeprogress(18, "{restarting_service} {openldap_server} [{$suffix}] (1/3)");
    shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --ldapd-conf --verbose >>{$DEBUG_LOG} 2>&1");
    system("/etc/init.d/slapd restart --force --framework=" . basename(__FILE__) . "-" . __LINE__ . " >>{$DEBUG_LOG} 2>&1");
    usleep(800);
    writeprogress(19, "{restarting_service} {openldap_server} [{$suffix}] (2/3)");
    system("/etc/init.d/slapd restart --force --framework=" . basename(__FILE__) . "-" . __LINE__ . " >>{$DEBUG_LOG} 2>&1");
    usleep(800);
    writeprogress(20, "{restarting_service} {openldap_server} [{$suffix}] (3/3)");
    system("/etc/init.d/slapd restart --force --framework=" . basename(__FILE__) . "-" . __LINE__ . " >>{$DEBUG_LOG} 2>&1");
    sleep(2);
    writeprogress(22, "{refresh_global_settings}");
    system('/usr/share/artica-postfix/bin/process1 --checkout --force --verbose ' . time());
    writeprogress(23, "{scanning_hardware_software}");
    system('/usr/share/artica-postfix/bin/process1 --force --verbose ' . time());
    $SUBNIC = null;
    FINAL___();
    @file_get_contents($pidfile, getmypid());
    writeprogress(24, "{restarting_service}: {mysql_server}");
    system('/etc/init.d/mysql restart --force');
    sleep(1);
    $users = new usersMenus();
    $q = new mysql();
    writeprogress(25, "{creating_databases}");
    sleep(1);
    $q->BuildTables();
    $sock = new sockets();
    $CPU_NUMBERS = $unix->CPU_NUMBER();
    if ($CPU_NUMBERS == 0) {
        $CPU_NUMBERS = 4;
    }
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    $MEMORY_TEXT = FormatBytes($MEMORY);
    $INTEL_CELERON = FALSE;
    writeprogress(25, "CPUs {$CPU_NUMBERS} - {memory}: {$MEMORY_TEXT}");
    sleep(2);
    if ($MEMORY > 1) {
        if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
            @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableIntelCeleron", 1);
            @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance", 3);
            writeprogress(25, "{$MEMORY_TEXT} = Enable Intel Celeron mode....");
            shell_exec("{$php5} /usr/share/artica-postfix/exec.intel.celeron.php");
            $INTEL_CELERON = true;
        }
    }
    if (!$INTEL_CELERON) {
        if ($CPU_NUMBERS < 2) {
            @file_put_contents("/etc/artica-postfix/settings/Daemons/EnableIntelCeleron", 1);
            @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance", 3);
            writeprogress(25, "CPUs:{$CPU_NUMBERS} = Intel Celeron mode....");
            shell_exec("{$php5} /usr/share/artica-postfix/exec.intel.celeron.php");
            $INTEL_CELERON = true;
        }
    }
    if (!$INTEL_CELERON) {
        if ($CPU_NUMBERS < 3) {
            @file_put_contents("/etc/artica-postfix/settings/Daemons/SquidPerformance", 2);
            writeprogress(25, "CPUs:{$CPU_NUMBERS} = {features}: {no_statistics}");
            sleep(1);
        }
    }
    writeprogress(26, "{creating_services}");
    shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.initslapd.php  --force >/dev/null 2>&1 &");
    if (is_file($squidbin)) {
        writeprogress(27, "{RestartingProxyStatisticsDatabase}");
        shell_exec("/etc/init.d/squid-db restart >>{$DEBUG_LOG} 2>&1");
    }
    $cyrus = $unix->LOCATE_CYRUS_DAEMON();
    if (is_file($cyrus)) {
        writeprogress(28, "{restarting_service} SaslAuthd Daemon");
        shell_exec("/etc/init.d/saslauthd restart");
        writeprogress(29, "{restarting_service} Cyrus IMAP Daemon");
        shell_exec("/etc/init.d/cyrus-imapd restart");
        writeprogress(30, "{restarting_service} Postfix Daemon");
        shell_exec("/etc/init.d/postfix restart");
    }
    if (isset($savedsettings["GoldKey"])) {
        if (!$sock->IsGoldKey($savedsettings["GoldKey"])) {
            unset($savedsettings["GoldKey"]);
        }
    }
    if (isset($savedsettings["GoldKey"])) {
        if ($sock->IsGoldKey($savedsettings["GoldKey"])) {
            $WORKDIR = base64_decode("L3Vzci9sb2NhbC9zaGFyZS9hcnRpY2E=");
            $WORKFILE = base64_decode('LmxpYw==');
            $WORKPATH = "{$WORKDIR}/{$WORKFILE}";
            @file_put_contents($WORKPATH, "TRUE");
            $LicenseInfos = unserialize(base64_decode($sock->GET_INFO("LicenseInfos")));
            $LicenseInfos["UUID"] = $savedsettings["UUID_FIRST"];
            $LicenseInfos["TIME"] = time();
            $sock->SaveConfigFile(base64_encode(serialize($LicenseInfos)), "LicenseInfos");
            writeprogress(31, "{register_license}");
            shell_exec("{$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register >/dev/null 2>&1");
            writeprogress(32, "{saving_license}");
            shell_exec("{$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1");
        }
    }
    $ldap = new clladp();
    writeprogress(40, "{building_organization} {$savedsettings["organization"]}");
    if (!$ldap->AddOrganization($savedsettings["organization"])) {
        debug_logs("Building organization failed {$ldap->ldap_last_error}");
        sleep(2);
        if (!$ldap->AddOrganization($savedsettings["organization"])) {
            debug_logs("Building organization failed 2/2 {$ldap->ldap_last_error}");
        }
    }
    sleep(2);
    writeprogress(40, "{creating_domain} {$savedsettings["smtp_domainname"]}");
    if (!$ldap->AddDomainEntity($savedsettings["organization"], $savedsettings["smtp_domainname"])) {
        debug_logs("AddDomainEntity failed {$ldap->ldap_last_error}");
    }
    sleep(2);
    $timezone = $savedsettings["timezones"];
    $sourcefile = "/usr/share/zoneinfo/{$timezone}";
    if (is_file($sourcefile)) {
        writeprogress(60, "{timezone} {$timezone}");
        @unlink("/etc/localtime");
        @copy($sourcefile, "/etc/localtime");
        @file_put_contents("/etc/timezone", $timezone);
    } else {
        writeprogress(60, "{$sourcefile} no such file");
    }
    sleep(2);
    BUILD_NETWORK();
    shell_exec("{$nohup} /etc/init.d/artica-status restart >/dev/null 2>&1 &");
    shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &");
    $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.postfix.maincf.php --reconfigure");
    $unix->THREAD_COMMAND_SET("/usr/share/artica-postfix/bin/artica-install --reconfigure-cyrus");
    $FreeWebAdded = false;
    sleep(3);
    if (!is_file("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED")) {
        if (!$GLOBALS["NOREBOOT"]) {
            $reboot = true;
        }
        $rebootWarn = null;
    }
    if (is_file($squidbin)) {
        include_once dirname(__FILE__) . "/ressources/class.squid.inc";
        if ($SQUIDEnable == 1) {
            $squid = new squidbee();
            if ($AsTransparentProxy == 1) {
                $squid->hasProxyTransparent = 1;
            }
            @file_put_contents("/etc/artica-postfix/settings/Daemons/HyperCacheStoreID", 1);
            $q = new mysql();
            if ($q->COUNT_ROWS("squid_caches_center", "artica_backup") == 0) {
                $cachename = basename($squid->CACHE_PATH);
                $q->QUERY_SQL("INSERT IGNORE INTO `squid_caches_center` (cachename,cpu,cache_dir,cache_type,cache_size,cache_dir_level1,cache_dir_level2,enabled,percentcache,usedcache,remove)\n\t\t\t\tVALUES('{$cachename}',1,'{$squid->CACHE_PATH}','{$squid->CACHE_TYPE}','2000','128','256',1,0,0,0)", "artica_backup");
            }
            $zipfile = "/usr/share/artica-postfix/ressources/conf/upload/squid-zip-import.zip";
            if (is_file($zipfile)) {
                writeprogress(63, "Analyze old squid.conf");
                system("{$php5} /usr/share/artica-postfix/exec.squid.import.conf.php --zip");
            }
            $squid->SaveToLdap(true);
            writeprogress(65, "{ReconfiguringProxy} {please_wait} 1/2");
            shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force");
        } else {
            writeprogress(63, "{stopping} {proxy_service}");
            shell_exec("/etc/init.d/squid stop");
        }
    }
    if ($AsCategoriesAppliance == 1) {
        writeprogress(65, "{starting} Categories service");
        shell_exec("/etc/init.d/ufdbcat start");
    }
    if ($AsReverseProxyAppliance == 1) {
        writeprogress(65, "{starting} Reverse Proxy service...");
        system("{$php5} /usr/share/artica-postfix/exec.nginx.php --build");
        shell_exec("/etc/init.d/nginx restart");
    }
    if (isset($savedsettings["EnablePDNS"])) {
        $sock->SET_INFO("EnablePDNS", $savedsettings["EnablePDNS"]);
    }
    if (isset($savedsettings["EnableDHCPServer"])) {
        $sock->SET_INFO("EnableDHCPServer", $savedsettings["EnableDHCPServer"]);
    }
    if (isset($savedsettings["EnableFreeRadius"])) {
        $sock->SET_INFO("EnableFreeRadius", $savedsettings["EnableFreeRadius"]);
        $sock->getFrameWork("freeradius.php?restart=yes");
    }
    $restart_artica_status = false;
    if ($savedsettings["adminwebserver"] != null) {
        writeprogress(67, "{creating_webservices}{$rebootWarn}");
        $sock->SET_INFO("EnableFreeWeb", 1);
        writeprogress(60, "{restarting_artica_status}");
        $restart_artica_status = true;
        restart_artica_status();
        writeprogress(68, "{restarting_webservices}");
        restart_apache_src();
        writeprogress(69, "{creating_default_website} {$savedsettings["adminwebserver"]}");
        include_once dirname(__FILE__) . "/ressources/class.freeweb.inc";
        $free = new freeweb($savedsettings["adminwebserver"]);
        $free->servername = $savedsettings["adminwebserver"];
        $free->groupware = "ARTICA_MINIADM";
        $free->CreateSite();
        writeprogress(69, "{creating_default_website} {$savedsettings["adminwebserver"]}");
        rebuild_vhost($savedsettings["adminwebserver"]);
    }
    if ($savedsettings["second_webadmin"] != null) {
        $sock->SET_INFO("EnableFreeWeb", 1);
        if (!$restart_artica_status) {
            writeprogress(70, "{creating_webservices}{$rebootWarn}");
            restart_artica_status();
            restart_apache_src();
        }
        include_once dirname(__FILE__) . "/ressources/class.freeweb.inc";
        $free = new freeweb($savedsettings["second_webadmin"]);
        $free->servername = $savedsettings["second_webadmin"];
        $free->groupware = "ARTICA_ADM";
        $free->CreateSite();
        rebuild_vhost($savedsettings["second_webadmin"]);
    }
    if ($savedsettings["statsadministrator"] != null) {
        $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT id FROM radgroupcheck WHERE groupname='WebStatsAdm' LIMIT 0,1", "artica_backup"));
        $gpid = $ligne["id"];
        if (!is_numeric($gpid)) {
            $gpid = 0;
        }
        if ($gpid == 0) {
            $sql = "INSERT IGNORE INTO radgroupcheck  (`groupname`, `attribute`,`op`, `value`) VALUES ('WebStatsAdm', 'Auth-Type',':=', 'Accept');";
            $q->QUERY_SQL($sql, "artica_backup");
            if (!$q->ok) {
                $gpid = 0;
            } else {
                $gpid = $q->last_id;
            }
            if ($gpid > 0) {
                $savedsettings["statsadministrator"] = mysql_escape_string2($savedsettings["statsadministrator"]);
                $administratorpass = mysql_escape_string2(url_decode_special_tool($savedsettings["statsadministratorpass"]));
                $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT value FROM radcheck WHERE username='******' LIMIT 0,1", "artica_backup"));
                if (trim($ligne["value"]) == null) {
                    $sql = "INSERT IGNORE INTO radcheck (`username`, `attribute`, `value`) VALUES ('{$savedsettings["statsadministrator"]}', 'Cleartext-Password', '{$savedsettings["statsadministratorpass"]}');";
                    $q->QUERY_SQL($sql, "artica_backup");
                } else {
                    $sql = "UPDATE radcheck SET `value`='{$savedsettings["statsadministratorpass"]}' WHERE username='******'";
                    $q->QUERY_SQL($sql, "artica_backup");
                    if (!$q->ok) {
                        echo $q->mysql_error;
                    }
                }
                $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT username FROM radcheck WHERE username='******' AND groupname='WebStatsAdm' LIMIT 0,1", "artica_backup"));
                if (trim($ligne["username"]) == null) {
                    $sql = "insert into radusergroup (username, groupname, priority,gpid) VALUES ('{$savedsettings["statsadministrator"]}', 'WebStatsAdm', 1,{$gpid});";
                    $q->QUERY_SQL($sql, "artica_backup");
                    if (!$q->ok) {
                        echo $q->mysql_error;
                    }
                }
            }
        }
    }
    $reboot = false;
    writeprogress(80, "{checking_parameters}{$rebootWarn}");
    if (!is_file("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED")) {
        @file_put_contents("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED", time());
    }
    $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.initslapd.php");
    $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth");
    if (!is_numeric($EnableKerbAuth)) {
        $EnableKerbAuth = 0;
    }
    if ($EnableKerbAuth == 1) {
        writeprogress(82, "{LaunchActiveDirectoryConnection}...");
        system("{$php5} /usr/share/artica-postfix/exec.kerbauth.php --build --force --verbose >>{$DEBUG_LOG} 2>&1");
    }
    $WizardWebFilteringLevel = $sock->GET_INFO("WizardWebFilteringLevel");
    if (is_numeric($WizardWebFilteringLevel)) {
        $savedsettings["EnableWebFiltering"] = 1;
    }
    if ($savedsettings["EnableWebFiltering"] == 1) {
        writeprogress(82, "{activate_webfiltering_service}...");
        sleep(2);
        EnableWebFiltering();
    } else {
        writeprogress(82, "{no_web_filtering}");
        sleep(2);
    }
    if ($users->POSTFIX_INSTALLED) {
        $unix->THREAD_COMMAND_SET("{$php5} /usr/share/artica-postfix/exec.postfix.maincf.php --build --force >>{$DEBUG_LOG} 2>&1");
    }
    writeprogress(83, "{RestartingArticaStatus}");
    system("/etc/init.d/artica-status restart --force");
    $serverbin = $unix->find_program("zarafa-server");
    if (is_file($serverbin)) {
        writeprogress(85, "{restarting_zarafa_services}{$rebootWarn}");
        shell_exec("{$php5} /usr/share/artica-postfix/exec.initdzarafa.php");
        shell_exec("{$php5} /usr/share/artica-postfix/exec.zarafa-db.php --init");
        shell_exec("/etc/init.d/zarafa-db restart");
        shell_exec("/etc/init.d/zarafa-server restart");
        shell_exec("/etc/init.d/zarafa-web restart");
    }
    writeprogress(90, "{restarting_services}{$rebootWarn}");
    shell_exec("{$nohup} /etc/init.d/artica-status reload >/dev/null 2>&1 &");
    shell_exec("{$nohup} /etc/init.d/monit restart >/dev/null 2>&1 &");
    shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.monit.php --build >/dev/null 2>&1");
    shell_exec("{$nohup} /usr/share/artica-postfix/exec.web-community-filter.php --register  >/dev/null 2>&1 &");
    $EnableArticaMetaClient = intval($sock->GET_INFO("EnableArticaMetaClient"));
    if ($EnableArticaMetaClient == 1) {
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.artica-meta-client.php --ping --force >/dev/null 2>&1 &");
    }
    if (is_file($squidbin)) {
        if ($SQUIDEnable == 1) {
            $q = new mysql_squid_builder();
            if ($q->COUNT_ROWS("proxy_ports") == 0) {
                $WizardSqlWait = unserialize(@file_get_contents("/etc/artica-postfix/settings/Daemons/WizardSqlWait"));
                while (list($none, $sql) = each($WizardSqlWait)) {
                    $q->QUERY_SQL($sql);
                }
            }
            writeprogress(95, "{ReconfiguringProxy} {please_wait} 2/2");
            shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force");
            writeprogress(97, "{checking_hypercache_feature} {please_wait}");
            shell_exec("{$php5} /usr/share/artica-postfix/exec.hypercache-dedup.php --wizard");
        }
    }
    writeprogress(98, "{empty_watchdog_events} {please_wait}");
    $q = new mysql();
    $q->QUERY_SQL("TRUNCATE TABLE squid_admin_mysql", "artica_events");
    $time = $unix->file_time_min("/etc/artica-postfix/WIZARD_INSTALL_EXECUTED");
    if (!$reboot) {
        writeprogress(100, "{done}");
        FINAL___();
        return;
    }
    writeprogress(100, "Rebooting");
    FINAL___();
    sleep(10);
    shell_exec($unix->find_program("reboot"));
}
コード例 #6
0
ファイル: exec.monit.php プロジェクト: brucewu16899/1.6.x
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;
    }
    $ZarafaDedicateMySQLServer = $sock->GET_INFO("ZarafaDedicateMySQLServer");
    if (!is_numeric($ZarafaDedicateMySQLServer)) {
        $ZarafaDedicateMySQLServer = 0;
    }
    $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;
    $EnableMONITSmtpNotif = $sock->GET_INFO("EnableMONITSmtpNotif");
    if (!is_numeric($EnableMONITSmtpNotif)) {
        $EnableMONITSmtpNotif = 1;
    }
    $EnableWatchMemoryUsage = $sock->GET_INFO("EnableWatchMemoryUsage");
    if (!is_numeric($EnableWatchMemoryUsage)) {
        $EnableWatchMemoryUsage = 1;
    }
    $EnableWatchCPUsage = $sock->GET_INFO("EnableWatchCPUsage");
    if (!is_numeric($EnableWatchCPUsage)) {
        $EnableWatchCPUsage = 1;
    }
    $SystemWatchMemoryUsage = $sock->GET_INFO("SystemWatchMemoryUsage");
    if (!is_numeric($SystemWatchMemoryUsage)) {
        $SystemWatchMemoryUsage = 75;
    }
    $EnableWatchCPUsage = $sock->GET_INFO("EnableWatchCPUsage");
    if (!is_numeric($EnableWatchCPUsage)) {
        $EnableWatchCPUsage = 1;
    }
    $SystemWatchCPUUser = $sock->GET_INFO("SystemWatchCPUUser");
    if (!is_numeric($SystemWatchCPUUser)) {
        $SystemWatchCPUUser = 80;
    }
    $SystemWatchCPUSystem = $sock->GET_INFO("SystemWatchCPUSystem");
    if (!is_numeric($SystemWatchCPUSystem)) {
        $SystemWatchCPUSystem = 80;
    }
    $EnableLoadAvg1mnUser = $sock->GET_INFO("EnableLoadAvg1mnUser");
    if (!is_numeric($EnableLoadAvg1mnUser)) {
        $EnableLoadAvg1mnUser = 1;
    }
    $EnableLoadAvg5mnUser = $sock->GET_INFO("EnableLoadAvg5mnUser");
    if (!is_numeric($EnableLoadAvg5mnUser)) {
        $EnableLoadAvg5mnUser = 1;
    }
    $EnableLoadAvg15mnUser = $sock->GET_INFO("EnableLoadAvg15mnUser");
    if (!is_numeric($EnableLoadAvg15mnUser)) {
        $EnableLoadAvg15mnUser = 1;
    }
    $Load1mn = $sock->GET_INFO("Load1mn");
    if (!is_numeric($Load1mn)) {
        $Load1mn = $busy;
    }
    $Load15mn = $sock->GET_INFO("Load15mn");
    if (!is_numeric($Load15mn)) {
        $Load15mn = $normal2;
    }
    $Load5mn = $sock->GET_INFO("Load5mn");
    if (!is_numeric($Load5mn)) {
        $Load5mn = $normal;
    }
    $DoNotCheckSystem = 0;
    if ($EnableLoadAvg1mnUser == 0) {
        if ($EnableLoadAvg5mnUser == 0) {
            if ($EnableLoadAvg15mnUser == 0) {
                if ($EnableWatchMemoryUsage == 0) {
                    if ($SystemLoadNotif == 0) {
                        if ($EnableWatchCPUsage == 0) {
                            $DoNotCheckSystem = 1;
                        }
                    }
                }
            }
        }
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $rmbin = $unix->find_program("rm");
    $echo = $unix->find_program("echo");
    if ($SystemWatchCPUSystem > 100) {
        $SystemWatchCPUSystem = 99;
    }
    if ($SystemWatchCPUUser > 100) {
        $SystemWatchCPUUser = 99;
    }
    if ($SystemWatchMemoryUsage > 10) {
        $SystemWatchMemoryUsage = 99;
    }
    if ($SystemWatchCPUSystem < 5) {
        $SystemWatchCPUSystem = 99;
    }
    if ($SystemWatchCPUUser < 5) {
        $SystemWatchCPUUser = 99;
    }
    if ($SystemWatchMemoryUsage < 5) {
        $SystemWatchMemoryUsage = 99;
    }
    $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}}";
                }
            }
        }
    }
    $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();
    if ($DoNotCheckSystem == 0) {
        $f[] = "check system " . $unix->hostname_g();
        if ($SystemLoadNotif > 0) {
            $f[] = "\tif loadavg (1min) > {$SystemLoadNotif} then exec \"{$php5} /usr/share/artica-postfix/exec.watchdog.php --loadavg-notif\"";
        }
        if ($EnableLoadAvg1mnUser == 1) {
            $f[] = "\tif loadavg (1min) > {$Load1mn} for 5 cycles then alert";
        }
        if ($EnableLoadAvg5mnUser == 1) {
            $f[] = "\tif loadavg (5min) > {$Load5mn} for 5 cycles then alert";
        }
        if ($EnableLoadAvg15mnUser == 1) {
            $f[] = "\tif loadavg (15min) > {$Load15mn} for 5 cycles then alert";
        }
        if ($EnableWatchMemoryUsage == 1) {
            $f[] = "\tif memory usage > {$SystemWatchMemoryUsage}% for 5 cycles then alert";
        }
        if ($EnableWatchCPUsage == 1) {
            //$f[]="if cpu usage (user) > $SystemWatchCPUUser% for 5 cycles then exec \"/bin/bash -c '$top -b -n 1 >> /var/log/ArticaProc.log;/bin/date >> /var/log/ArticaProc.log'\"";
            //$f[]="if cpu usage (system) > $SystemWatchCPUSystem% for 5 cycles then exec \"/bin/bash -c '$top -b -n 1 >> /var/log/ArticaProc.log;/bin/date >> /var/log/ArticaProc.log'\"";
        }
    }
    $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();
    //********************************************************************************************************************
    $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[] = "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/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();
    //********************************************************************************************************************
    $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();
    $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();
    @unlink("/etc/monit/conf.d/squid.monitrc");
    @unlink("/etc/monit/conf.d/APP_SQUIDMAIN.monitrc");
    if (is_file($squidbin)) {
        if ($SQUIDEnable == 1) {
            $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig")));
            $SquidMgrListenPort = trim($sock->GET_INFO("SquidMgrListenPort"));
            if (!is_numeric($MonitConfig["watchdog"])) {
                $MonitConfig["watchdog"] = 1;
            }
            if (!is_numeric($MonitConfig["watchdogCPU"])) {
                $MonitConfig["watchdogCPU"] = 95;
            }
            if (!is_numeric($MonitConfig["watchdogMEM"])) {
                $MonitConfig["watchdogMEM"] = 1500;
            }
            if ($MonitConfig["watchdog"] == 1) {
                if ($MonitConfig["watchdogMEM"] > 500) {
                    $AVAILABLE_MEM = $unix->MEM_TOTAL_INSTALLEE();
                    $AVAILABLE_MEM = $AVAILABLE_MEM / 1024;
                    $prc = $MonitConfig["watchdogMEM"] / $AVAILABLE_MEM;
                    $prc = round($prc * 100);
                }
                $f = array();
                $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 ($SquidMgrListenPort > 0) {
                    $f[] = "\tif failed host 127.0.0.1 port {$SquidMgrListenPort}  then restart";
                }
                if ($MonitConfig["watchdogCPU"] > 60) {
                    $f[] = "\tif cpu usage > {$MonitConfig["watchdogCPU"]}% for 5 cycles then restart";
                }
                if ($prc > 10) {
                    $f[] = "\tif mem usage > {$prc}% 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-Cache...\n";
                }
                @file_put_contents("/etc/monit/conf.d/APP_SQUIDMAIN.monitrc", @implode("\n", $f));
            }
        }
    }
    // ********************************************************************************************************************
    $f = array();
    @unlink("/etc/monit/conf.d/APP_SQUIDDB.monitrc");
    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();
    @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();
    @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));
            }
        }
    }
    // ********************************************************************************************************************
    @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));
        }
    }
    //********************************************************************************************************************
    @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");
    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));
    }
    //********************************************************************************************************************
    $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;
    }
    //********************************************************************************************************************
    @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");
    if (is_file($ufdbbin)) {
        $EnableUfdbGuard = $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 ($UseRemoteUfdbguardService == 0) {
                if ($EnableUfdbGuard == 1) {
                    $f = array();
                    $f[] = "check process APP_UFDBGUARD";
                    $f[] = "with pidfile /var/run/urlfilterdb/ufdbguardd.pid";
                    $f[] = "start program = \"/etc/init.d/ufdb start --monit\"";
                    $f[] = "stop program =  \"/etc/init.d/ufdb stop --monit\"";
                    $f[] = "if totalmem > 700 MB for 5 cycles then alert";
                    $f[] = "if cpu > 95% for 5 cycles then alert";
                    $f[] = "if 5 restarts within 5 cycles then timeout";
                    if ($GLOBALS["OUTPUT"]) {
                        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} monitoring Web filtering service...\n";
                    }
                    @file_put_contents("/etc/monit/conf.d/ufdb.monitrc", @implode("\n", $f));
                }
            }
            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;
    @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));
        }
    }
    //********************************************************************************************************************
    $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));
    }
    //********************************************************************************************************************
    $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");
    @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));
        }
    }
    //********************************************************************************************************************
    @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");
}
コード例 #7
0
function register()
{
    if ($GLOBALS["VERBOSE"]) {
        echo __FUNCTION__ . "() in line " . __LINE__ . "\n";
    }
    $sock = new sockets();
    $unix = new unix();
    $URIBASE = $unix->MAIN_URI();
    $URIBASE = str_replace("articatech.net", "artica.fr", $URIBASE);
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $cachetime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid)) {
        WriteMyLogs("Already executed PID:{$pid}, die()", __FUNCTION__, __FILE__, __LINE__);
        die;
    }
    $sock = new sockets();
    $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth");
    if (!is_numeric("{$EnableKerbAuth}")) {
        $EnableKerbAuth = 0;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Loading WizardSavedSettings " . __FUNCTION__ . "() in line " . __LINE__ . "\n";
    }
    $WizardSavedSettings = unserialize(base64_decode($sock->GET_INFO("WizardSavedSettings")));
    $WizardSavedSettingsSend = $sock->GET_INFO("WizardSavedSettingsSend");
    if (count($WizardSavedSettings) < 2) {
        if ($GLOBALS["VERBOSE"]) {
            echo "WizardSavedSettings array is less than 2" . __FUNCTION__ . "() in line " . __LINE__ . "\n";
        }
        return;
    }
    if (!isset($WizardSavedSettings["company_name"])) {
        $WizardSavedSettings["company_name"] = null;
    }
    if ($WizardSavedSettings["company_name"] == null) {
        return;
    }
    if (!is_numeric($WizardSavedSettingsSend)) {
        $WizardSavedSettingsSend = 0;
    }
    if ($WizardSavedSettingsSend == 1) {
        if (!$GLOBALS["FORCE"]) {
            if ($GLOBALS["VERBOSE"]) {
                echo "WizardSavedSettingsSend == 1, aborting.. (use --force)" . __FUNCTION__ . "() in line " . __LINE__ . "\n";
            }
            return;
        }
    }
    $uuid = $unix->GetUniqueID();
    if ($uuid == null) {
        if ($GLOBALS["VERBOSE"]) {
            echo "No system ID !\n";
        }
        return;
    }
    $WizardSavedSettings["ACTIVE_DIRECTORY"] = $EnableKerbAuth;
    if ($EnableKerbAuth == 1) {
        include_once dirname(__FILE__) . "/ressources/class.external.ad.inc";
        $ldap = new external_ad_search();
        $NET_RPC_INFOS = $ldap->NET_RPC_INFOS();
        while (list($a, $b) = each($NET_RPC_INFOS)) {
            $WizardSavedSettings[$a] = $b;
        }
    }
    $WizardSavedSettings["UUID"] = $uuid;
    $WizardSavedSettings["CPUS_NUMBER"] = $unix->CPU_NUMBER();
    $WizardSavedSettings["MEMORY"] = $unix->SYSTEM_GET_MEMORY_MB() . "MB";
    $WizardSavedSettings["LINUX_DISTRI"] = $unix->LINUX_DISTRIBUTION();
    $WizardSavedSettings["ARTICAVERSION"] = @file_get_contents("/usr/share/artica-postfix/VERSION");
    $WizardSavedSettings["STATS_APPLIANCE"] = 0;
    if (is_file("/etc/artica-postfix/STATS_APPLIANCE")) {
        $WizardSavedSettings["APPLIANCE"] = "Artica Stats Appliance";
        $WizardSavedSettings["STATS_APPLIANCE"] = 1;
    }
    $zarafa_server = $unix->find_program("zarafa-server");
    if (is_file($zarafa_server)) {
        $WizardSavedSettings["ZARAFA APPLIANCE"] = "YES";
    }
    $squid = $unix->find_program("squid");
    if (is_file($squid)) {
        $WizardSavedSettings["PROXY INSTALLED"] = "YES";
    }
    if (is_file("/etc/artica-postfix/FROM_ISO")) {
        $WizardSavedSettings["FROM ISO"] = "YES";
    }
    if (is_file("/etc/artica-postfix/SQUID_APPLIANCE")) {
        $WizardSavedSettings["APPLIANCE"] = "Artica Proxy";
        $WizardSavedSettings["PROXY APPLIANCE"] = "YES";
    }
    if (is_file("/etc/artica-postfix/SAMBA_APPLIANCE")) {
        $WizardSavedSettings["APPLIANCE"] = "Artica NAS";
        $WizardSavedSettings["N.A.S APPLIANCE"] = "YES";
    }
    if (is_file("/etc/artica-postfix/artica-iso-first-reboot")) {
        $zDate = filemtime("/etc/artica-postfix/artica-iso-first-reboot");
        $WizardSavedSettings["INSTALL_DATE"] = date("Y-m-d H:i:s", $zDate);
    } else {
        $zDate = filemtime("/etc/artica-postfix/.");
        $WizardSavedSettings["INSTALL_DATE"] = date("Y-m-d H:i:s", $zDate);
    }
    if (is_file("/etc/artica-postfix/dmidecode.cache.url")) {
        $final_array = unserialize(base64_decode(@file_get_contents("/etc/artica-postfix/dmidecode.cache.url")));
        while (list($a, $b) = each($final_array)) {
            $WizardSavedSettings[$a] = $b;
        }
    }
    @file_put_contents("/etc/artica-postfix/settings/Daemons/WizardSavedSettings", base64_encode(serialize($WizardSavedSettings)));
    if ($GLOBALS["VERBOSE"]) {
        echo "Send order to {$URIBASE}/shalla-orders.php " . __FUNCTION__ . "() in line " . __LINE__ . "\n";
    }
    $curl = new ccurl("{$URIBASE}/shalla-orders.php", false, null);
    $curl->parms["REGISTER"] = base64_encode(serialize($WizardSavedSettings));
    if ($GLOBALS["VERBOSE"]) {
        $curl->parms["VERBOSE"] = true;
    }
    $curl->NoLocalProxy();
    $curl->get();
    if ($GLOBALS["VERBOSE"]) {
        echo $curl->data;
    }
    if (preg_match("#GOOD#s", $curl->data)) {
        $sock->SET_INFO("WizardSavedSettingsSend", 1);
    }
}