Ejemplo n.º 1
0
function check()
{
    $unix = new unix();
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    if ($MEMORY < 624288) {
        writelogs(basename(__FILE__) . ":Too low memory, die();", basename(__FILE__), __FILE__, __LINE__);
        die;
    }
    if (!is_file("/usr/bin/ruby1.8")) {
        $unix->DEBIAN_INSTALL_PACKAGE("ruby1.8");
    }
    $EnablePhileSight = GET_INFO_DAEMON("EnablePhileSight");
    if ($EnablePhileSight == null) {
        $EnablePhileSight = 0;
    }
    if ($EnablePhileSight == 0) {
        writelogs("feature disabled, aborting...", __FUNCTION__, __FILE__, __LINE__);
        die;
    }
    if (system_is_overloaded()) {
        writelogs("System overloaded, aborting this feature for the moment", __FUNCTION__, __FILE__, __LINE__);
        die;
    }
    @mkdir("/opt/artica/philesight");
    $unix = new unix();
    $min = $unix->file_time_min("/opt/artica/philesight/database.db");
    $sock = new sockets();
    $rr = $sock->GET_INFO("PhileSizeRefreshEach");
    if ($rr == null) {
        $rr = 120;
    }
    if ($rr == "disable") {
        die;
    }
    writelogs("/opt/artica/philesight/database.db = {$min} minutes, {$rr} minutes to run", __FUNCTION__, __FILE__, __LINE__);
    if ($min >= $rr) {
        run();
    }
}
Ejemplo n.º 2
0
function enable_icap()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        echo basename(__FILE__) . ":Already executed pid {$pid}.. aborting the process\n";
        progress("{failed}", 110);
        return;
    }
    $sock = new sockets();
    $sock->SET_INFO("kavicapserverEnabled", 1);
    $MEM = $unix->MEM_TOTAL_INSTALLEE();
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        $sock->SET_INFO("kavicapserverEnabled", 0);
        if ($GLOBALS["OUTPUT"]) {
            echo "Not enough memory - {$MEM}\n";
        }
        progress("{failed}", 110);
        return;
    }
    $q = new mysql_squid_builder();
    progress("{verify_icap_center}", 10);
    $q->CheckTablesICAP();
    if ($q->COUNT_ROWS("c_icap_services") == 0) {
        progress("{verify_icap_center} {failed}", 110);
    }
    progress("{hooking_local_service}", 10);
    $q->QUERY_SQL("UPDATE c_icap_services SET `enabled`=1 WHERE ID=6");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        progress("{hooking_local_service} {failed}", 110);
    }
    $q->QUERY_SQL("UPDATE c_icap_services SET `enabled`=1 WHERE ID=5");
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
        progress("{hooking_local_service} {failed}", 110);
    }
    progress("{reloading} {APP_KAV4PROXY}", 20);
    build();
    system("/etc/init.d/kav4proxy reload");
    progress("{configuring} {APP_SQUID}", 50);
    $php = $unix->LOCATE_PHP5_BIN();
    system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force --noverifcaches");
    progress("{restarting} {APP_SQUID}", 70);
    system("/etc/init.d/squid restart --force {$GLOBALS["SCRIPT_SUFFIX"]}");
    progress("{restarting} Artica-status", 80);
    system("/etc/init.d/artica-status restart --force");
    progress("{refresh} License", 90);
    $GLOBALS["FORCE"] = true;
    license_infos(true);
    progress("{success} {hooking_local_service}", 100);
}
Ejemplo n.º 3
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $users = new usersMenus();
    $Masterbin = "/usr/local/ArticaStats/bin/postgres";
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, arpd not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} not enough memory\n";
        }
        if ($unix->process_exists($pid)) {
            stop();
        }
        build_progress_restart("{starting} {failed} no memory", 110);
        return;
    }
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        build_progress_restart("{starting} {success}", 30);
        return true;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    $su = $unix->find_program("su");
    $rm = $unix->find_program("rm");
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    $EnableInfluxDB = intval($sock->GET_INFO("EnableInfluxDB"));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} EnableInfluxDB: {$EnableInfluxDB}\n";
    }
    $InfluxUseRemote = intval($sock->GET_INFO("InfluxUseRemote"));
    if ($users->POSTFIX_INSTALLED) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Postfix installed: True\n";
        }
    }
    if ($InfluxUseRemote == 1) {
        $EnableInfluxDB = 0;
    }
    $FreeZePostGres = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/FreeZePostGres"));
    if ($FreeZePostGres == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Freeze !!! Aborting...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Use Remote statistics.: {$InfluxUseRemote}\n";
    }
    if (!$users->POSTFIX_INSTALLED) {
        $EnableIntelCeleron = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableIntelCeleron"));
        if ($EnableIntelCeleron == 1) {
            $EnableInfluxDB = 0;
        }
    }
    if (is_file("/etc/artica-postfix/STATS_APPLIANCE")) {
        $EnableInfluxDB = 1;
        $SquidPerformance = 0;
        $EnableIntelCeleron = 0;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Use Statistics DB.....: {$EnableInfluxDB}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Use Intel Celeron mode: {$EnableIntelCeleron}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Use Performance.......: {$SquidPerformance}\n";
    }
    if ($EnableInfluxDB == 0) {
        build_progress_restart("{starting} {failed} {disabled}", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableInflux)\n";
        }
        return;
    }
    if (!function_exists("pg_connect")) {
        build_progress_restart("{starting} installing php5-pgsql", 35);
        $unix->DEBIAN_INSTALL_PACKAGE("php5-pgsql");
        system("/usr/share/artica-postfix/exec.php.ini.php");
        if (!function_exists("pg_connect")) {
            build_progress_restart("{starting} installing php5-pgsql {failed}", 110);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} pg_connect no such function\n";
            }
            return;
        }
        system("/etc/init.d/artica-webconsole restart");
    }
    build_progress_restart("{starting}", 40);
    if (!$unix->UnixUserExists("ArticaStats")) {
        $unix->CreateUnixUser("ArticaStats", "ArticaStats");
    }
    @mkdir("/var/run/ArticaStats", 0755, true);
    @mkdir("/home/ArticaStatsDB", 0700, true);
    @mkdir("/var/log/ArticaStatsDB", 0755, true);
    @chown("/home/ArticaStatsDB", "ArticaStats");
    @chgrp("/home/ArticaStatsDB", "ArticaStats");
    @chown("/var/run/ArticaStats", "ArticaStats");
    @chgrp("/var/run/ArticaStats", "ArticaStats");
    @chown("/var/log/ArticaStatsDB", "ArticaStats");
    @chgrp("/var/log/ArticaStatsDB", "ArticaStats");
    if (is_file("/var/log/ArticaStatsDB/ArticaStatsDB.log")) {
        @unlink("/var/log/ArticaStatsDB/ArticaStatsDB.log");
        @touch("/var/log/ArticaStatsDB/ArticaStatsDB.log");
    }
    @chown("/var/log/ArticaStatsDB/ArticaStatsDB.log", "ArticaStats");
    @chgrp("/var/log/ArticaStatsDB/ArticaStatsDB.log", "ArticaStats");
    if (is_file("/var/run/ArticaStats/.s.PGSQL.8086")) {
        @unlink("/var/run/ArticaStats/.s.PGSQL.8086");
    }
    $php = $unix->LOCATE_PHP5_BIN();
    if (!is_file("/etc/artica-postfix/locales.gen")) {
        squid_admin_mysql(1, "Generating languages for the PostGreSQL compatibility", null, __FILE__, __LINE__);
        build_progress_restart("{generating_langs}", 42);
        system("{$php} /usr/share/artica-postfix/exec.locale.gen.php");
    }
    if (!is_dir("/home/ArticaStatsDB/base/1")) {
        squid_admin_mysql(0, "Creating a new PostgreSQL database in ArticaStatsDB", null, __FILE__, __LINE__);
        build_progress_restart("{starting}", 45);
        $rm = $unix->find_program("rm");
        shell_exec("{$rm} -rf /home/ArticaStatsDB/*");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} initialize database...\n";
        }
        system("{$su} -c \"/usr/local/ArticaStats/bin/initdb --username=ArticaStats /home/ArticaStatsDB --no-locale -E UTF8\" ArticaStats");
    }
    if (!is_dir("/home/ArticaStatsDB/base/1")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} initialize database failed...\n";
        }
        $rm = $unix->find_program("rm");
        shell_exec("{$rm} -rf /home/ArticaStatsDB/*");
        return;
    }
    build_progress_restart("{starting}", 50);
    xbuild();
    fuser_port();
    build_progress_restart("{starting} {permissions}", 55);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Apply permissions on /home/ArticaStatsDB\n";
    }
    $chown = $unix->find_program("chown");
    $chmod = $unix->find_program("chmod");
    shell_exec("{$chown} -R ArticaStats:ArticaStats /home/ArticaStatsDB");
    shell_exec("{$chmod} 0700 /home/ArticaStatsDB");
    if (is_file("/home/ArticaStatsDB/postmaster.pid")) {
        @unlink("/home/ArticaStatsDB/postmaster.pid");
    }
    $f[] = "su -l ArticaStats -c '";
    $f[] = "/usr/local/ArticaStats/bin/pg_ctl -o \"-k /tmp,/var/run/ArticaStats\"  -D /home/ArticaStatsDB -l /var/log/ArticaStatsDB/ArticaStatsDB.log start'";
    $cmd = @implode(" ", $f) . " >/dev/null 2>&1 &";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        build_progress_restart("{starting} {wait} {$i}/5", 70);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        build_progress_restart("{starting} {success}", 75);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
        $pg = new postgres_sql();
        $pg->CREATE_TABLES();
        return true;
    } else {
        build_progress_restart("{starting} {failed}", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
}
Ejemplo n.º 4
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $spawn_fcgi = $unix->find_program("spawn-fcgi");
    if (!is_file($spawn_fcgi)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n";
        }
        return;
    }
    $pid = DEFAULT_PID();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $phpcgi = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    $EnablePHPFPM = intval($sock->GET_INFO("EnablePHPFPM"));
    $EnablePHPFPMFrameWork = $sock->GET_INFO("EnablePHPFPMFrameWork");
    $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM");
    $EnablePHPFPMFreeWeb = $sock->GET_INFO("EnablePHPFPMFreeWeb");
    $EnableFreeWeb = $sock->GET_INFO("EnableFreeWeb");
    if (!is_numeric($EnablePHPFPMFrameWork)) {
        $EnablePHPFPMFrameWork = 0;
    }
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if (!is_numeric($EnablePHPFPMFreeWeb)) {
        $EnablePHPFPMFreeWeb = 0;
    }
    if (!is_numeric($EnableFreeWeb)) {
        $EnableFreeWeb = 0;
    }
    if ($EnableFreeWeb == 0) {
        $EnablePHPFPMFreeWeb = 1;
    }
    $enabled = 1;
    if ($EnablePHPFPM == 1) {
        if ($EnablePHPFPMFrameWork == 1) {
            if ($EnableArticaApachePHPFPM == 1) {
                if ($EnablePHPFPMFreeWeb == 1) {
                    $enabled = 0;
                }
            }
        }
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnablePHPFPM............: {$EnablePHPFPM}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnablePHPFPMFrameWork...: {$EnablePHPFPMFrameWork}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnableArticaApachePHPFPM: {$EnableArticaApachePHPFPM}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnablePHPFPMFreeWeb.....: {$EnablePHPFPMFreeWeb}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Enabled.................: {$enabled}\n";
    }
    if ($enabled == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} is disabled...\n";
        }
        stop();
    }
    if (!is_file($phpcgi)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} FATAL no php-cgi can be enabled !\n";
        }
        return false;
    }
    $unix->chmod_func(0777, "/var/run");
    if ($unix->is_socket("/var/run/php-fcgi.sock")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} remove old socket /var/run/php-fcgi.sock\n";
        }
        @unlink("/var/run/php-fcgi.sock");
    }
    $params = LOAD_CMDLINES();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} version {$params["VERSION"]}\n";
    }
    $PROCESSES = 3;
    $CHILDREN = 5;
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    if ($MEMORY < 624288) {
        $PROCESSES = 1;
        $CHILDREN = 2;
    }
    $pid = $unix->get_pid_from_file("/var/run/spawn-fcgi.pid");
    $f[] = $spawn_fcgi;
    $f[] = "-s /var/run/php-fcgi.sock";
    if (isset($params["C"])) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$PROCESSES} Processes\n";
        }
        $f[] = "-C {$PROCESSES}";
    }
    if (isset($params["F"])) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$CHILDREN} Children\n";
        }
        $f[] = "-F {$CHILDREN}";
    }
    $f[] = "-u www-data -g www-data";
    $f[] = "-f {$phpcgi}";
    $f[] = "-P /var/run/spawn-fcgi.pid";
    $cmd = @implode(" ", $f);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$cmd}\n";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    for ($i = 0; $i < 4; $i++) {
        $pid = DEFAULT_PID();
        if ($unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting {$i}/4...\n";
        }
        sleep(1);
    }
    $pid = DEFAULT_PID();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success service started pid:{$pid}...\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n";
        }
    }
}
Ejemplo n.º 5
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("arpd");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, arpd not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} not enough memory\n";
        }
        if ($unix->process_exists($pid)) {
            stop();
        }
        return;
    }
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $EnableSargGenerator = intval($sock->GET_INFO("EnableSargGenerator"));
    $EnableSargWeb = intval($sock->GET_INFO("EnableSargWeb"));
    if ($EnableSargGenerator == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableSargGenerator)\n";
        }
        return;
    }
    if ($EnableSargWeb == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableSargWeb)\n";
        }
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    $apache2ctl = $unix->LOCATE_APACHE_CTL();
    apache_config();
    $cmd = "{$apache2ctl} -f {$GLOBALS["APACHE_CONFIG_PATH"]} -k start";
    shell_exec($cmd);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
}
Ejemplo n.º 6
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = "/usr/bandwidthd/bandwidthd";
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, arpd not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} not enough memory\n";
        }
        if ($unix->process_exists($pid)) {
            stop();
        }
        return;
    }
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $EnableDaemon = intval($sock->Bandwidthd_enabled());
    if ($EnableDaemon == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableBandwidthd)\n";
        }
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    build();
    $cmd = "{$nohup} {$Masterbin} >/dev/null 2>&1 &";
    @unlink("/var/run/bandwidthd.pid");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
}
Ejemplo n.º 7
0
function buildConfig()
{
    $unix = new unix();
    $sock = new sockets();
    $phpcgi = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    @mkdir("/usr/share/artica-postfix/framework", 0755, true);
    @mkdir("/usr/share/artica-postfix/ressources/sock", 0755, true);
    @mkdir("/usr/share/artica-postfix/ressources/web", 0755, true);
    @mkdir("/var/run/artica-framework", 0755, true);
    $LighttpdRunAsminimal = $sock->GET_INFO("LighttpdRunAsminimal");
    $LighttpdArticaMaxProcs = $sock->GET_INFO("LighttpdArticaMaxProcs");
    $LighttpdArticaMaxChildren = $sock->GET_INFO("LighttpdArticaMaxChildren");
    $PHP_FCGI_MAX_REQUESTS = $sock->GET_INFO("PHP_FCGI_MAX_REQUESTS");
    $EnablePHPFPMFrameWork = $sock->GET_INFO("EnablePHPFPMFrameWork");
    if (!is_numeric($EnablePHPFPMFrameWork)) {
        $EnablePHPFPMFrameWork = 0;
    }
    if (!is_numeric($LighttpdRunAsminimal)) {
        $LighttpdRunAsminimal = 0;
    }
    if (!is_numeric($LighttpdArticaMaxProcs)) {
        $LighttpdArticaMaxProcs = 0;
    }
    if (!is_numeric($LighttpdArticaMaxChildren)) {
        $LighttpdArticaMaxChildren = 0;
    }
    if (!is_numeric($PHP_FCGI_MAX_REQUESTS)) {
        $PHP_FCGI_MAX_REQUESTS = 200;
    }
    $PHP_FCGI_CHILDREN = 1;
    $max_procs = 5;
    if ($LighttpdArticaMaxProcs > 0) {
        $max_procs = $LighttpdArticaMaxProcs;
    }
    if ($LighttpdArticaMaxChildren > 0) {
        $PHP_FCGI_CHILDREN = $LighttpdArticaMaxChildren;
    }
    if (!$unix->ISMemoryHiger1G()) {
        $PHP_FCGI_CHILDREN = 2;
        $max_procs = 2;
        $PHP_FCGI_MAX_REQUESTS = 200;
    }
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    if ($MEMORY < 624288) {
        $LighttpdRunAsminimal = 1;
    }
    if ($LighttpdRunAsminimal == 1) {
        $max_procs = 2;
        $PHP_FCGI_CHILDREN = 1;
        $PHP_FCGI_MAX_REQUESTS = 500;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: MAX Procs............: {$max_procs}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Php5 processes.......: {$PHP_FCGI_CHILDREN}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Max cnx/processes....: {$PHP_FCGI_MAX_REQUESTS}\n";
    }
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    $EnablePHPFPM = $sock->GET_INFO("EnablePHPFPM");
    if (!is_numeric($EnablePHPFPM)) {
        $EnablePHPFPM = 0;
    }
    if (!is_file($phpfpm)) {
        $EnablePHPFPM = 0;
    }
    $PHP_FPM_Params = PHP_FPM_Params();
    if (!isset($ParseParams["allow-to-run-as-root"])) {
        $EnablePHPFPMFrameWork = 0;
    }
    if ($EnablePHPFPMFrameWork == 0) {
        $EnablePHPFPM = 0;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: php-fpm..............: {$phpfpm}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: EnablePHPFPMFrameWork: {$EnablePHPFPMFrameWork}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: EnablePHPFPM.........: {$EnablePHPFPM}\n";
    }
    if ($EnablePHPFPM == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Using PHP-FPM........: Yes\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Using PHP-FPM........: No\n";
        }
    }
    $phpcgi_path = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: php-cgi path.........: {$phpcgi_path}\n";
    }
    $f[] = "#artica-postfix saved by artica lighttpd.conf";
    $f[] = "";
    $f[] = "server.modules = (";
    $f[] = "        \"mod_alias\",";
    $f[] = "        \"mod_access\",";
    $f[] = "        \"mod_accesslog\",";
    $f[] = "        \"mod_compress\",";
    $f[] = "        \"mod_fastcgi\",";
    $f[] = "        \"mod_cgi\",";
    $f[] = "\t       \"mod_status\"";
    $f[] = ")";
    $f[] = "";
    $f[] = "server.document-root        = \"/usr/share/artica-postfix/framework\"";
    $f[] = "server.errorlog             = \"/var/log/artica-postfix/framework_error.log\"";
    $f[] = "index-file.names            = ( \"index.php\")";
    $f[] = "";
    $f[] = "mimetype.assign             = (";
    $f[] = "  \".pdf\"          =>      \"application/pdf\",";
    $f[] = "  \".sig\"          =>      \"application/pgp-signature\",";
    $f[] = "  \".spl\"          =>      \"application/futuresplash\",";
    $f[] = "  \".class\"        =>      \"application/octet-stream\",";
    $f[] = "  \".ps\"           =>      \"application/postscript\",";
    $f[] = "  \".torrent\"      =>      \"application/x-bittorrent\",";
    $f[] = "  \".dvi\"          =>      \"application/x-dvi\",";
    $f[] = "  \".gz\"           =>      \"application/x-gzip\",";
    $f[] = "  \".pac\"          =>      \"application/x-ns-proxy-autoconfig\",";
    $f[] = "  \".swf\"          =>      \"application/x-shockwave-flash\",";
    $f[] = "  \".tar.gz\"       =>      \"application/x-tgz\",";
    $f[] = "  \".tgz\"          =>      \"application/x-tgz\",";
    $f[] = "  \".tar\"          =>      \"application/x-tar\",";
    $f[] = "  \".zip\"          =>      \"application/zip\",";
    $f[] = "  \".mp3\"          =>      \"audio/mpeg\",";
    $f[] = "  \".m3u\"          =>      \"audio/x-mpegurl\",";
    $f[] = "  \".wma\"          =>      \"audio/x-ms-wma\",";
    $f[] = "  \".wax\"          =>      \"audio/x-ms-wax\",";
    $f[] = "  \".ogg\"          =>      \"application/ogg\",";
    $f[] = "  \".wav\"          =>      \"audio/x-wav\",";
    $f[] = "  \".gif\"          =>      \"image/gif\",";
    $f[] = "  \".jar\"          =>      \"application/x-java-archive\",";
    $f[] = "  \".jpg\"          =>      \"image/jpeg\",";
    $f[] = "  \".jpeg\"         =>      \"image/jpeg\",";
    $f[] = "  \".png\"          =>      \"image/png\",";
    $f[] = "  \".xbm\"          =>      \"image/x-xbitmap\",";
    $f[] = "  \".xpm\"          =>      \"image/x-xpixmap\",";
    $f[] = "  \".xwd\"          =>      \"image/x-xwindowdump\",";
    $f[] = "  \".css\"          =>      \"text/css\",";
    $f[] = "  \".html\"         =>      \"text/html\",";
    $f[] = "  \".htm\"          =>      \"text/html\",";
    $f[] = "  \".js\"           =>      \"text/javascript\",";
    $f[] = "  \".asc\"          =>      \"text/plain\",";
    $f[] = "  \".c\"            =>      \"text/plain\",";
    $f[] = "  \".cpp\"          =>      \"text/plain\",";
    $f[] = "  \".log\"          =>      \"text/plain\",";
    $f[] = "  \".conf\"         =>      \"text/plain\",";
    $f[] = "  \".text\"         =>      \"text/plain\",";
    $f[] = "  \".txt\"          =>      \"text/plain\",";
    $f[] = "  \".dtd\"          =>      \"text/xml\",";
    $f[] = "  \".xml\"          =>      \"text/xml\",";
    $f[] = "  \".mpeg\"         =>      \"video/mpeg\",";
    $f[] = "  \".mpg\"          =>      \"video/mpeg\",";
    $f[] = "  \".mov\"          =>      \"video/quicktime\",";
    $f[] = "  \".qt\"           =>      \"video/quicktime\",";
    $f[] = "  \".avi\"          =>      \"video/x-msvideo\",";
    $f[] = "  \".asf\"          =>      \"video/x-ms-asf\",";
    $f[] = "  \".asx\"          =>      \"video/x-ms-asf\",";
    $f[] = "  \".wmv\"          =>      \"video/x-ms-wmv\",";
    $f[] = "  \".bz2\"          =>      \"application/x-bzip\",";
    $f[] = "  \".tbz\"          =>      \"application/x-bzip-compressed-tar\",";
    $f[] = "  \".tar.bz2\"      =>      \"application/x-bzip-compressed-tar\",";
    $f[] = "  \"\"              =>      \"application/octet-stream\",";
    $f[] = " )";
    $f[] = "";
    $f[] = "";
    $f[] = "accesslog.filename          = \"/var/log/artica-postfix/framework.log\"";
    $f[] = "url.access-deny             = ( \"~\", \".inc\" )";
    $f[] = "";
    $f[] = "static-file.exclude-extensions = ( \".php\", \".pl\", \".fcgi\" )";
    $f[] = "#server.port                 = 47980";
    $f[] = "server.bind                = \"/usr/share/artica-postfix/ressources/web/framework.sock\"";
    $f[] = "#server.error-handler-404   = \"/error-handler.html\"";
    $f[] = "#server.error-handler-404   = \"/error-handler.php\"";
    $f[] = "server.pid-file             = \"/var/run/lighttpd/framework.pid\"";
    $f[] = "server.max-keep-alive-requests = 0";
    $f[] = "server.max-keep-alive-idle = 4";
    $f[] = "server.stat-cache-engine = \"simple\"";
    $f[] = "server.max-fds \t\t   = 2048";
    $f[] = "server.network-backend      = \"writev\"";
    $f[] = "";
    if ($EnablePHPFPM == 0) {
        $f[] = "fastcgi.server = ( \".php\" =>((";
        $f[] = "                \"bin-path\" => \"{$phpcgi_path}\",";
        $f[] = "                \"socket\" => \"/var/run/artica-framework/fastcgi-\" + PID + \".sock\",";
    } else {
        $f[] = "fastcgi.server = ( \".php\" =>((";
        $f[] = "                \"socket\" => \"/var/run/php-fpm-framework.sock\",";
    }
    $f[] = "                \"max-procs\" => {$max_procs},";
    $f[] = "                \"idle-timeout\" => 20,";
    $f[] = "                \"bin-environment\" => (";
    $f[] = "                        \"PHP_FCGI_CHILDREN\" => \"{$PHP_FCGI_CHILDREN}\",";
    $f[] = "                        \"HOME\" => \"/home\",";
    $f[] = "                        \"PHP_FCGI_MAX_REQUESTS\" => \"{$PHP_FCGI_MAX_REQUESTS}\",";
    $f[] = "                        \"PATH\" => \"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin:/usr/kerberos/bin\",";
    $f[] = "                        \"LD_LIBRARY_PATH\" => \"/lib:/usr/local/lib:/usr/lib/libmilter:/usr/lib\",";
    $f[] = "                        \"CPPFLAGS\" => \"-I/usr/include/libmilter -I/usr/include -I/usr/local/include -I/usr/include/linux -I/usr/include/sm/os\",";
    $f[] = "                        \"LDFLAGS\" => \"-L/lib -L/usr/local/lib -L/usr/lib/libmilter -L/usr/lib\",";
    $f[] = "                ),";
    $f[] = "                \"broken-scriptfilename\" => \"enable\"";
    $f[] = "        ))";
    $f[] = ")";
    $f[] = "ssl.engine                 = \"disable\"";
    $f[] = "status.status-url          = \"/server-status\"";
    $f[] = "status.config-url          = \"/server-config\"";
    $f[] = "\$HTTP[\"url\"] =~ \"^/webmail\" {";
    $f[] = "\tserver.follow-symlink = \"enable\"";
    $f[] = "}";
    $f[] = "alias.url += ( \"/cgi-bin/\" => \"/usr/lib/cgi-bin/\" )";
    $f[] = "alias.url += ( \"/css/\" => \"/usr/share/artica-postfix/css/\" )";
    $f[] = "alias.url += ( \"/img/\" => \"/usr/share/artica-postfix/img/\" )";
    $f[] = "alias.url += ( \"/js/\" => \"/usr/share/artica-postfix/js/\" )";
    $f[] = "";
    $f[] = "cgi.assign= (";
    $f[] = "\t\".pl\"  => \"/usr/bin/perl\",";
    $f[] = "\t\".php\" => \"/usr/bin/php-cgi\",";
    $f[] = "\t\".py\"  => \"/usr/bin/python\",";
    $f[] = "\t\".cgi\"  => \"/usr/bin/perl\",";
    $f[] = ")\n";
    @unlink("/var/log/artica-postfix/framework_error.log");
    @unlink("/var/log/artica-postfix/framework.log");
    @touch("/var/log/artica-postfix/framework_error.log");
    @touch("/var/log/artica-postfix/framework.log");
    @file_put_contents("/etc/artica-postfix/framework.conf", @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: /etc/artica-postfix/framework.conf done\n";
    }
}
Ejemplo n.º 8
0
function SERVICE_START($nochecks = false, $nopid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $kill = $unix->find_program("kill");
    if (!$nopid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            echo "Starting......: " . date("H:i:s") . " MySQL this script is already executed PID: {$pid} since {$time}Mn\n";
            if ($time < 5) {
                if (!$GLOBALS["FORCE"]) {
                    return;
                }
            }
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    if (is_file("/etc/artica-postfix/mysql.stop")) {
        echo "Starting......: " . date("H:i:s") . " MySQL locked, exiting\n";
        return;
    }
    $PID_NUM = PID_NUM();
    if ($unix->process_exists($PID_NUM)) {
        $timemin = $unix->PROCCESS_TIME_MIN($PID_NUM);
        echo "Starting......: " . date("H:i:s") . " MySQL already running PID \"{$PID_NUM}\" since {$timemin}Mn\n";
        return;
    }
    $mysql_install_db = $unix->find_program('mysql_install_db');
    $mysqlbin = $unix->LOCATE_mysqld_bin();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    if (!is_file($mysqlbin)) {
        echo "Starting......: " . date("H:i:s") . " MySQL is not installed, abort\n";
        return;
    }
    $EnableMysqlFeatures = $sock->GET_INFO('EnableMysqlFeatures');
    $MysqlBinAllAdresses = $sock->GET_INFO('MysqlBinAllAdresses');
    $MySQLTMPMEMSIZE = $sock->GET_INFO('MySQLTMPMEMSIZE');
    $MysqlTooManyConnections = $sock->GET_INFO("MysqlTooManyConnections");
    $MysqlRemoveidbLogs = $sock->GET_INFO("MysqlRemoveidbLogs");
    $innodb_force_recovery = $sock->GET_INFO("innodb_force_recovery");
    if (!is_numeric($innodb_force_recovery)) {
        $innodb_force_recovery = 0;
    }
    if (!is_numeric($MysqlRemoveidbLogs)) {
        $MysqlRemoveidbLogs = 0;
    }
    if (!is_numeric($MysqlBinAllAdresses)) {
        $MysqlBinAllAdresses = 0;
    }
    if (!is_numeric($MySQLTMPMEMSIZE)) {
        $MySQLTMPMEMSIZE = 0;
    }
    if (!is_numeric($MysqlTooManyConnections)) {
        $MysqlTooManyConnections = 0;
    }
    if (!is_numeric($EnableMysqlFeatures)) {
        $EnableMysqlFeatures = 1;
    }
    $MySqlTmpDir = $sock->GET_INFO('MySQLTMPDIR');
    $MySQLLOgErrorPath = $sock->GET_INFO('MySQLLOgErrorPath');
    $datadir = $unix->MYSQL_DATA_DIR();
    $EnableMysqlLog = $sock->GET_INFO("EnableMysqlLog");
    if (!is_numeric($EnableMysqlLog)) {
        $EnableMysqlLog = 0;
    }
    if ($datadir == null) {
        $datadir = '/var/lib/mysql';
    }
    if ($MySqlTmpDir == '/tmp') {
        $MySqlTmpDir = null;
    }
    if ($MySQLLOgErrorPath == null) {
        $MySQLLOgErrorPath = $datadir . '/mysqld.err';
    }
    if ($MysqlTooManyConnections == 1) {
        echo "Starting......: " . date("H:i:s") . " MySQL MysqlTooManyConnections=1, abort\n";
        return;
    }
    if (isset($GLOBALS["RECOVERY"])) {
        $innodb_force_recovery = $GLOBALS["RECOVERY"];
    }
    if (strlen($MySqlTmpDir) > 3) {
        echo "Starting......: " . date("H:i:s") . " MySQL tempdir : {$MySqlTmpDir}\n";
        shell_exec("{$php5} /usr/share/artica-postfix/exec.mysql.build.php --tmpfs");
        $MySqlTmpDir = str_replace("//", "/", $MySqlTmpDir);
        if (!is_dir($MySqlTmpDir)) {
            @mkdir($MySqlTmpDir, 0755, true);
            $unix->chown_func("mysql", "mysql", $MySqlTmpDir);
        }
        $MySqlTmpDirCMD = " --tmpdir={$MySqlTmpDir}";
    }
    if ($EnableMysqlFeatures == 0) {
        echo "Starting......: " . date("H:i:s") . " MySQL is disabled by \"EnableMysqlFeatures\"...\n";
        return;
    }
    $pid_file = "/var/run/mysqld/mysqld.pid";
    $socket = "/var/run/mysqld/mysqld.sock";
    $mysql_user = "******";
    @mkdir("/var/run/mysqld", 0755, true);
    @mkdir("/var/log/mysql", 0755, true);
    @mkdir($datadir, 0755, true);
    $dirs = $unix->dirdir("/var/lib/mysql");
    while (list($num, $directory) = each($dirs)) {
        echo "Starting......: " . date("H:i:s") . " MySQL, apply permissions on " . basename($directory) . "\n";
        $unix->chown_func("mysql", "mysql", "{$directory}/*");
    }
    $bind_address = ' --bind-address=127.0.0.1';
    $bind_address2 = "127.0.0.1";
    if ($MysqlBinAllAdresses == 1) {
        $bind_address2 = 'All (0.0.0.0)';
        $bind_address = ' --bind-address=0.0.0.0';
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Pid path.......:{$pid_file}\n";
    echo "Starting......: " . date("H:i:s") . " datadir..............:{$datadir}\n";
    echo "Starting......: " . date("H:i:s") . " Log error............:{$MySQLLOgErrorPath}\n";
    echo "Starting......: " . date("H:i:s") . " socket...............:{$socket}\n";
    echo "Starting......: " . date("H:i:s") . " user.................:{$mysql_user}\n";
    echo "Starting......: " . date("H:i:s") . " LOGS ENABLED.........:{$EnableMysqlLog}\n";
    echo "Starting......: " . date("H:i:s") . " Daemon...............:{$mysqlbin}\n";
    echo "Starting......: " . date("H:i:s") . " Bind address.........:{$bind_address2}\n";
    echo "Starting......: " . date("H:i:s") . " Temp Dir.............:{$MySqlTmpDir}\n";
    echo "Starting......: " . date("H:i:s") . " innodb_force_recovery:{$innodb_force_recovery}\n";
    mysql_admin_mysql(1, "Starting MySQL service...", null, __FILE__, __LINE__);
    echo "Starting......: " . date("H:i:s") . " Settings permissions..\n";
    @mkdir("/var/run/mysqld", 0755, true);
    $unix->chown_func($mysql_user, $mysql_user, "/var/run/mysqld");
    $unix->chown_func($mysql_user, $mysql_user, "/var/log/mysql");
    $unix->chown_func($mysql_user, $mysql_user, $datadir);
    $unix->chown_func($mysql_user, $mysql_user, "{$datadir}/*");
    if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
        @unlink("/var/run/mysqld/mysqld.sock");
    }
    if (is_file('/var/run/mysqld/mysqld.err')) {
        @unlink('/var/run/mysqld/mysqld.err');
    }
    if (is_file("/var/run/mysqld/mysqld.pid")) {
        $unix->chown_func($mysql_user, $mysql_user, "/var/run/mysqld/mysqld.pid");
    }
    if ($MysqlRemoveidbLogs == 1) {
        shell_exec('/bin/mv /var/lib/mysql/ib_logfile* /tmp/');
        $sock->SET_INFO('MysqlRemoveidbLogs', '0');
    }
    $logpathstring = " --log-error={$MySQLLOgErrorPath}";
    if ($EnableMysqlLog == 1) {
        $logpathstring = " --log=/var/log/mysql.log --log-slow-queries=/var/log/mysql-slow-queries.log --log-error={$MySQLLOgErrorPath} --log-warnings";
    }
    $toTouch[] = "/var/log/mysql-slow-queries.log";
    $toTouch[] = "/var/log/mysql.error";
    $toTouch[] = "/var/log/mysql.log";
    $toTouch[] = "/var/log/mysql.warn";
    while (list($num, $filename) = each($toTouch)) {
        if (!is_file($filename)) {
            @file_put_contents($filename, "#\n");
        }
        $unix->chown_func($mysql_user, $mysql_user, $filename);
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Checking : {$datadir}/mysql/host.frm\n";
    if (!is_file("{$datadir}/mysql/host.frm")) {
        if (is_file($mysql_install_db)) {
            echo "Starting......: " . date("H:i:s") . " MySQL Installing default databases\n";
            shell_exec("{$mysql_install_db} --datadir=\"{$datadir}\"");
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " MySQL Checking : {$datadir}/mysql/host.frm OK\n";
    }
    $cmd2 = array();
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    $AsCategoriesAppliance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance"));
    if ($AsCategoriesAppliance == 1) {
        $MEMORY = 620288;
    }
    if ($MEMORY < 624288) {
        $GetStartedValues = GetStartedValues();
        echo "Starting......: " . date("H:i:s") . " MySQL Warning memory did not respond to pre-requesites, tuning to lower memory\n";
        if ($GetStartedValues["--key-buffer-size"]) {
            $cmd2[] = "--key-buffer-size=8M";
        }
        if ($GetStartedValues["--max-allowed-packet"]) {
            $cmd2[] = "--max-allowed-packet=4M";
        }
        if ($GetStartedValues["--table-cache"]) {
            $cmd2[] = "--table-cache=4";
        }
        if ($GetStartedValues["--sort-buffer-size"]) {
            $cmd2[] = "--sort-buffer-size=64k";
        }
        if ($GetStartedValues["--read-buffer-size"]) {
            $cmd2[] = "--read-buffer-size=256k";
        }
        if ($GetStartedValues["--read-rnd-buffer-size"]) {
            $cmd2[] = "--read-rnd-buffer-size=128k";
        }
        if ($GetStartedValues["--net-buffer-length"]) {
            $cmd2[] = "--net-buffer-length=2k";
        }
        if ($GetStartedValues["--thread-stack"]) {
            $cmd2[] = "--thread-stack=192k";
        }
        if ($GetStartedValues["--thread-cache-size"]) {
            $cmd2[] = "--thread-cache-size=128";
        }
        if ($GetStartedValues["--thread-concurrency"]) {
            $cmd2[] = "--thread-concurrency=10";
        }
        if ($GetStartedValues["--default-storage-engine"]) {
            $cmd2[] = "--default-storage-engine=MyISAM";
        }
        if ($GetStartedValues["--default-tmp-storage-engine"]) {
            $cmd2[] = "--default-tmp-storage-engine=MyISAM";
        }
        if ($GetStartedValues["--tmp-table-size"]) {
            $cmd2[] = "--tmp-table-size=16M";
        }
        if ($GetStartedValues["--table-cache"]) {
            $cmd2[] = "--table-cache=64";
        }
        if ($GetStartedValues["--query-cache-limit"]) {
            $cmd2[] = "--query-cache-limit=4M";
        }
        if ($GetStartedValues["--query-cache-size"]) {
            $cmd2[] = "--query-cache-size=32M";
        }
        if ($GetStartedValues["--max-connections"]) {
            $cmd2[] = "--max-connections=50";
        }
        if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
            $cmd2[] = "--innodb=OFF";
        }
        echo "Starting......: " . date("H:i:s") . " MySQL " . count($cmd2) . " forced option(s)\n";
    }
    if (is_file($MySQLLOgErrorPath)) {
        @unlink($MySQLLOgErrorPath);
    }
    $cmds[] = $mysqlbin;
    if ($MEMORY < 624288) {
        $cmds[] = "--no-defaults --user=mysql";
    }
    $cmds[] = "--pid-file=/var/run/mysqld/mysqld.pid";
    $cmds[] = trim($logpathstring);
    $cmds[] = trim($MySqlTmpDirCMD);
    $cmds[] = "--socket={$socket}";
    $cmds[] = "--datadir=\"{$datadir}\"";
    if (count($cmd2) == 0) {
        if ($innodb_force_recovery > 0) {
            $cmds[] = "--innodb-force-recovery={$innodb_force_recovery}";
        }
    }
    if (count($cmd2) > 0) {
        $cmds[] = @implode(" ", $cmd2);
    }
    $cmds[] = ">/dev/null 2>&1 &";
    if (is_file('/usr/sbin/aa-complain')) {
        echo "Starting......: " . date("H:i:s") . " Mysql Adding mysql in apparamor complain mode...\n";
        shell_exec("/usr/sbin/aa-complain {$mysqlbin} >/dev/null 2>&1");
    }
    $cmd = @implode(" ", $cmds);
    while (list($num, $ligne) = each($cmds)) {
        echo "Starting......: " . date("H:i:s") . " MySQL Option: {$ligne}\n";
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Starting daemon, please wait\n";
    writelogs("Starting MySQL {$cmd}", __FUNCTION__, __FILE__, __LINE__);
    shell_exec($cmd);
    $count = 0;
    sleep(2);
    for ($i = 0; $i < 6; $i++) {
        $pid = PID_NUM();
        if ($unix->process_exists($pid, $mysqlbin)) {
            echo "Starting......: " . date("H:i:s") . " MySQL Checks daemon running...\n";
            break;
        }
        echo "Starting......: " . date("H:i:s") . " MySQL Checks daemon, please wait ({$i}/6)\n";
        sleep(1);
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " MySQL failed\n";
        echo "Starting......: " . date("H:i:s") . " {$cmd}\n";
        system_admin_events("Failed to start MySQL server", __FUNCTION__, __FILE__, __LINE__, "services");
        $php5 = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.mysql.build.php >/dev/null 2>&1 &");
    } else {
        for ($i = 0; $i < 4; $i++) {
            echo "Starting......: " . date("H:i:s") . " MySQL Checks mysqld.sock waiting {$i}/3\n";
            if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
                break;
            }
            sleep(1);
        }
        if (!$unix->is_socket("/var/run/mysqld/mysqld.sock")) {
            mysql_admin_mysql(0, "Failed to start MySQL Server /var/run/mysqld/mysqld.sock no such socket after 4 seconds", null, __FILE__, __LINE__);
            echo "Starting......: " . date("H:i:s") . " MySQL Checks mysqld.sock failed...\n";
        }
        mysql_admin_mysql(1, "Success to start MySQL Server with new pid {$pid}", null, __FILE__, __LINE__);
        echo "Starting......: " . date("H:i:s") . " MySQL Success pid {$pid}\n";
        $q = new mysql_squid_builder();
        $q->MEMORY_TABLES_RESTORE();
    }
}
Ejemplo n.º 9
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"));
}
Ejemplo n.º 10
0
function start_ldap($aspid = false)
{
    $sock = new sockets();
    $ldaps = array();
    $unix = new unix();
    $kill = $unix->find_program("kill");
    if (!$GLOBALS["FORCE"]) {
        $pid = $unix->get_pid_from_file('/etc/artica-postfix/pids/exec.backup.artica.php.restore.pid');
        if ($unix->process_exists($pid)) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            if ($pidtime < 15) {
                echo "slapd: [INFO] Artica restore task already running pid {$pid} since {$pidtime}mn\n";
                restart_ldap_progress("{success}", 100);
                return;
            }
        }
    }
    $MYPID_FILE = "/etc/artica-postfix/pids/start_ldap.pid";
    if (!$aspid) {
        $pid = $unix->get_pid_from_file($MYPID_FILE);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            $unix->ToSyslog("Artica task already running pid {$pid} since {$pidtime}mn", false, basename(__FILE__));
            echo "slapd: [INFO] Artica task already running pid {$pid} since {$pidtime}mn\n";
            if ($pidtime > 10) {
                echo "slapd: [INFO] Killing this Artica task...\n";
                unix_system_kill_force($pid);
            } else {
                die;
            }
        }
        $MYPID_FILE_TIME = $unix->file_time_min($MYPID_FILE);
        if (!$GLOBALS["FORCE"]) {
            if ($MYPID_FILE_TIME < 1) {
                echo "slapd: [INFO] Task must be executed only each 1mn (use --force to by pass)\n";
                die;
            }
        }
        @unlink($MYPID_FILE);
        @file_put_contents($MYPID_FILE, getmypid());
    }
    $slapd = $unix->find_program("slapd");
    $SLAPD_PID_FILE = $unix->SLAPD_PID_PATH();
    $pid = $unix->get_pid_from_file($SLAPD_PID_FILE);
    if ($unix->process_exists($pid)) {
        $pidtime = $unix->PROCCESS_TIME_MIN($pid);
        restart_ldap_progress("{success}", 100);
        echo "slapd: [INFO] slapd already running pid {$pid} since {$pidtime}mn\n";
        @file_put_contents($SLAPD_PID_FILE, $pid);
        return;
    }
    $pid = $unix->PIDOF_PATTERN($slapd);
    echo "slapd: [INFO] detecting presence of `{$slapd}`:{$pid}...\n";
    if ($unix->process_exists($pid)) {
        $pidtime = $unix->PROCCESS_TIME_MIN($pid);
        restart_ldap_progress("{success}", 100);
        echo "slapd: [INFO] slapd already running pid {$pid} since {$pidtime}mn\n";
        @file_put_contents($SLAPD_PID_FILE, $pid);
        return;
    }
    echo "slapd: [INFO] slapd loading required values...\n";
    if (!is_file($slapd)) {
        if (is_file('/usr/lib/openldap/slapd')) {
            $slapd = '/usr/lib/openldap/slapd';
        }
    }
    $OpenLDAPLogLevel = $sock->GET_INFO("OpenLDAPLogLevel");
    $OpenLDAPDisableSSL = $sock->GET_INFO("OpenLDAPDisableSSL");
    $EnableNonEncryptedLdapSession = $sock->GET_INFO("EnableNonEncryptedLdapSession");
    $EnableipV6 = $sock->GET_INFO("EnableipV6");
    if (!is_numeric($EnableipV6)) {
        $EnableipV6 = 0;
    }
    if (!is_numeric($EnableNonEncryptedLdapSession)) {
        $EnableNonEncryptedLdapSession = 1;
    }
    $phpldapadmin = null;
    if (!is_numeric($OpenLDAPDisableSSL)) {
        $OpenLDAPDisableSSL = 0;
    }
    $ZARAFA_INSTALLED = 0;
    if ($GLOBALS["VERBOSE"]) {
        echo "users=new usersMenus();\n";
    }
    $users = new usersMenus();
    if ($GLOBALS["VERBOSE"]) {
        echo "users=new usersMenus() done...;\n";
    }
    if (!is_dir("/var/lib/ldap")) {
        @mkdir("/var/lib/ldap", 0755, true);
    }
    if (!is_dir("/var/run/slapd")) {
        @mkdir("/var/run/slapd", 0755, true);
    }
    if (!is_numeric($OpenLDAPLogLevel)) {
        $OpenLDAPLogLevel = 0;
    }
    if ($OpenLDAPLogLevel != 0) {
        $OpenLDAPLogLevelCmdline = " -d {$OpenLDAPLogLevel}";
    }
    $ifconfig = $unix->find_program("ifconfig");
    echo "slapd: [INFO] start looback address...\n";
    shell_exec("{$ifconfig} lo 127.0.0.1 netmask 255.255.255.0 up >/dev/null 2>&1");
    $ldap[] = "ldapi://" . urlencode("/var/run/slapd/slapd.sock");
    $ldap[] = "ldap://127.0.0.1:389/";
    if (is_file("/etc/artica-postfix/settings/Daemons/LdapListenIPAddr")) {
        $LdapListenIPAddr = explode("\n", @file_get_contents("/etc/artica-postfix/settings/Daemons/LdapListenIPAddr"));
        while (list($num, $ipaddr) = each($LdapListenIPAddr)) {
            $ipaddr = trim($ipaddr);
            if ($ipaddr == null) {
                continue;
            }
            echo "slapd: [INFO] slapd listen `{$ipaddr}`\n";
            if (!$unix->IS_IPADDR_EXISTS($ipaddr)) {
                echo "slapd: [INFO] slapd `{$ipaddr}` does not exists\n";
                continue;
            }
            if ($EnableNonEncryptedLdapSession == 0) {
                $ldaps[] = "ldaps://{$ipaddr}/";
            }
            $ldap[] = "ldap://{$ipaddr}:389/";
        }
    }
    if (count($ldaps) > 0) {
        $SLAPD_SERVICESSSL = " " . @implode(" ", $ldaps);
    }
    $SLAPD_SERVICES = @implode(" ", $ldap) . $SLAPD_SERVICESSSL;
    if ($users->ZARAFA_INSTALLED) {
        $ZARAFA_INSTALLED = 1;
    }
    $DB_RECOVER_BIN = $unix->LOCATE_DB_RECOVER();
    $DB_ARCHIVE_BIN = $unix->LOCATE_DB_ARCHIVE();
    $LDAP_SCHEMA_PATH = $unix->LDAP_SCHEMA_PATH();
    $rm = $unix->find_program("rm");
    $SLAPD_CONF = $unix->SLAPD_CONF_PATH();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $tar = $unix->find_program("tar");
    $pidofbin = $unix->find_program("pidof");
    $ulimit = $unix->find_program("ulimit");
    $nohup = $unix->find_program("nohup");
    $mebin = __FILE__;
    $suffix = @trim(@file_get_contents("/etc/artica-postfix/ldap_settings/suffix"));
    shell_exec("{$nohup} /usr/share/artica-postfix/exec.virtuals-ip.php --resolvconf >/dev/null 2>&1 &");
    echo "slapd: [INFO] slapd `{$slapd}`\n";
    echo "slapd: [INFO] db_recover `{$DB_RECOVER_BIN}`\n";
    echo "slapd: [INFO] db_archive `{$DB_ARCHIVE_BIN}`\n";
    echo "slapd: [INFO] config `{$SLAPD_CONF}`\n";
    echo "slapd: [INFO] pid `{$SLAPD_PID_FILE}`\n";
    echo "slapd: [INFO] services `{$SLAPD_SERVICES}`\n";
    echo "slapd: [INFO] pidof `{$pidofbin}`\n";
    if ($EnableipV6 == 0) {
        echo "slapd: [INFO] ipv4 only...\n";
        $v4 = " -4";
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "-> ARRAY;\n";
    }
    $shemas[] = "core.schema";
    $shemas[] = "cosine.schema";
    $shemas[] = "mod_vhost_ldap.schema";
    $shemas[] = "nis.schema";
    $shemas[] = "inetorgperson.schema";
    $shemas[] = "evolutionperson.schema";
    $shemas[] = "postfix.schema";
    $shemas[] = "dhcp.schema";
    $shemas[] = "samba.schema";
    $shemas[] = "ISPEnv.schema";
    $shemas[] = "mozilla-thunderbird.schema";
    $shemas[] = "officeperson.schema";
    $shemas[] = "pureftpd.schema";
    $shemas[] = "joomla.schema";
    $shemas[] = "autofs.schema";
    $shemas[] = "dnsdomain2.schema";
    $shemas[] = "zarafa.schema";
    restart_ldap_progress("{starting_service}", 50);
    while (list($num, $file) = each($shemas)) {
        if (is_file("/usr/share/artica-postfix/bin/install/{$file}")) {
            if (is_file("{$LDAP_SCHEMA_PATH}/{$file}")) {
                @unlink("{$LDAP_SCHEMA_PATH}/{$file}");
            }
            @copy("/usr/share/artica-postfix/bin/install/{$file}", "{$LDAP_SCHEMA_PATH}/{$file}");
            echo "slapd: [INFO] installing `{$file}` schema\n";
            $unix->chmod_func(0777, "{$LDAP_SCHEMA_PATH}/{$file}");
        }
    }
    if (file_exists($ulimit)) {
        shell_exec("{$ulimit} -HSd unlimited");
    }
    restart_ldap_progress("{starting_service}", 60);
    if (is_dir("/usr/share/phpldapadmin/config")) {
        $phpldapadmin = "{$php5} " . dirname(__FILE__) . "/exec.phpldapadmin.php --build >/dev/null 2>&1";
        echo "slapd: [INFO] please wait, configuring PHPLdapAdminservice... \n";
        shell_exec($phpldapadmin);
    }
    echo "slapd: [INFO] please wait, configuring the daemon...\n";
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        $sock = new sockets();
        $sock->SET_INFO("SlapdThreads", 2);
    }
    restart_ldap_progress("{starting_service}", 70);
    @chmod("/usr/share/artica-postfix/bin/artica-install", 0755);
    shell_exec("/usr/share/artica-postfix/bin/artica-install --slapdconf");
    echo "slapd: [INFO] please wait, building the start script...\n";
    buildscript();
    $unix->ToSyslog("Launching the OpenLDAP daemon ", false, basename(__FILE__));
    echo "slapd: [INFO] please wait, Launching the daemon...\n";
    if (!$unix->NETWORK_INTERFACE_OK("lo")) {
        $ifconfig = $unix->find_program("ifconfig");
        shell_exec("{$ifconfig} lo 127.0.0.1 netmask 255.255.255.0 up >/dev/null 2>&1");
    }
    restart_ldap_progress("{starting_service}", 80);
    $cdmline = "{$nohup} {$slapd}{$v4} -h \"{$SLAPD_SERVICES}\" -f {$SLAPD_CONF} -u root -g root -l local4{$OpenLDAPLogLevelCmdline} >/dev/null 2>&1 &";
    shell_exec($cdmline);
    sleep(1);
    for ($i = 0; $i < 5; $i++) {
        $pid = $unix->get_pid_from_file($SLAPD_PID_FILE);
        if ($unix->process_exists($pid)) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            echo "slapd: [INFO] slapd success Running pid {$pid}\n";
            restart_ldap_progress("{success}", 100);
            if ($users->ZARAFA_INSTALLED) {
                start_zarafa();
            }
            return;
        }
        $pid = $unix->PIDOF($slapd);
        if ($unix->process_exists($pid)) {
            $pidtime = $unix->PROCCESS_TIME_MIN($pid);
            echo "slapd: [INFO] slapd success Running pid {$pid}\n";
            if ($users->ZARAFA_INSTALLED) {
                start_zarafa();
            }
            restart_ldap_progress("{success}", 100);
            return;
        }
        echo "slapd: [INFO] please wait, waiting service to start...\n";
        sleep(1);
    }
    restart_ldap_progress("{failed}", 110);
    echo "slapd: [ERR ] Failed to start the service with `{$cdmline}`\n";
}
Ejemplo n.º 11
0
function MEM_TOTAL_INSTALLEE()
{
    $unix = new unix();
    $MEM_TOTAL_INSTALLEE = $unix->MEM_TOTAL_INSTALLEE();
    echo "<articadatascgi>{$MEM_TOTAL_INSTALLEE}</articadatascgi>";
}
Ejemplo n.º 12
0
function build()
{
    $users = new usersMenus();
    $sock = new sockets();
    $unix = new unix();
    $SystemLoadNotif = $sock->GET_INFO("SystemLoadNotif");
    if (!is_numeric($SystemLoadNotif)) {
        $SystemLoadNotif = 0;
    }
    $EnableSyslogDB = $sock->GET_INFO("EnableSyslogDB");
    if (!is_numeric($EnableSyslogDB)) {
        $EnableSyslogDB = 0;
    }
    $MySQLSyslogType = $sock->GET_INFO("MySQLSyslogType");
    if (!is_numeric($MySQLSyslogType)) {
        $MySQLSyslogType = 1;
    }
    $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");
}
Ejemplo n.º 13
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("arpd");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, arpd not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} not enough memory\n";
        }
        if ($unix->process_exists($pid)) {
            stop();
        }
        return;
    }
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $EnableArpDaemon = $sock->GET_INFO("EnableArpDaemon");
    $ArpdKernelLevel = $sock->GET_INFO("ArpdKernelLevel");
    if (!is_numeric($EnableArpDaemon)) {
        $EnableArpDaemon = 1;
    }
    if (!is_numeric($ArpdKernelLevel)) {
        $ArpdKernelLevel = 0;
    }
    if ($EnableArpDaemon == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see EnableArpDaemon)\n";
        }
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    if ($ArpdKernelLevel > 0) {
        $ArpdKernelLevel_string = " -a {$ArpdKernelLevel}";
    }
    $Interfaces = $unix->NETWORK_ALL_INTERFACES();
    $nic = new system_nic();
    while (list($Interface, $ligne) = each($Interfaces)) {
        if ($Interface == "lo") {
            continue;
        }
        if ($ligne["IPADDR"] == "0.0.0.0") {
            continue;
        }
        $Interface = $nic->NicToOther($Interface);
        $TRA[$Interface] = $Interface;
    }
    while (list($Interface, $ligne) = each($TRA)) {
        $TR[] = $Interface;
    }
    @mkdir('/var/lib/arpd', 0755, true);
    $f[] = "{$Masterbin} -b /var/lib/arpd/arpd.db";
    $f[] = $ArpdKernelLevel;
    if (count($TR) > 0) {
        $f[] = "-k " . @implode($TR, " ");
    }
    $cmd = @implode(" ", $f) . " >/dev/null 2>&1 &";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
}
Ejemplo n.º 14
0
function build()
{
    $unix = new unix();
    $sock = new sockets();
    $Isagetway = false;
    $INSTALL_SERVICE = false;
    $KernelSendRedirects = $sock->GET_INFO("KernelSendRedirects");
    if (!is_numeric($KernelSendRedirects)) {
        $KernelSendRedirects = 1;
    }
    $conntrack = $unix->find_program("conntrack");
    $EnableChilli = $sock->GET_INFO("EnableChilli");
    $EnableArticaAsGateway = $sock->GET_INFO("EnableArticaAsGateway");
    if (!is_numeric($EnableChilli)) {
        $EnableChilli = 0;
    }
    $hasProxyTransparent = $sock->GET_INFO("hasProxyTransparent");
    if (!is_numeric($hasProxyTransparent)) {
        $hasProxyTransparent = 0;
    }
    $hostname = trim(@file_get_contents("/etc/artica-postfix/FULL_HOSTNAME"));
    if ($EnableChilli == 1) {
        $Isagetway = true;
    }
    if ($EnableArticaAsGateway == 1) {
        $Isagetway = true;
    }
    if ($hasProxyTransparent == 1) {
        $Isagetway = true;
    }
    if (is_file("/etc/artica-postfix/IPTABLES_BR_BRIDGE")) {
        $Isagetway = true;
    }
    if (is_file("/etc/artica-postfix/IPTABLES_BRIDGE")) {
        $Isagetway = true;
    }
    $EnableipV6 = $sock->GET_INFO("EnableipV6");
    if (!is_numeric($EnableipV6)) {
        $EnableipV6 = 0;
    }
    $ARRAY = unserialize(base64_decode($sock->GET_INFO("kernel_values")));
    $swappiness = intval($ARRAY["swappiness"]);
    if ($swappiness == 0) {
        $swappiness = 10;
    }
    $tcp_max_syn_backlog = $ARRAY["tcp_max_syn_backlog"];
    if (!is_numeric($tcp_max_syn_backlog)) {
        $tcp_max_syn_backlog = 1024;
    }
    $EnableTCPOptimize = $sock->GET_INFO("EnableTCPOptimize");
    $DisableConntrack = intval($sock->GET_INFO("DisableConntrack"));
    if (!is_numeric($EnableTCPOptimize)) {
        $EnableTCPOptimize = 1;
    }
    $DisableTCPOptimizations = $sock->GET_INFO("DisableTCPOptimizations");
    if ($DisableTCPOptimizations == 1) {
        $EnableTCPOptimize = 0;
    }
    $echo = $unix->find_program("echo");
    $modprobe = $unix->find_program("modprobe");
    $DisableTCPEn = intval(trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisableTCPEn")));
    $DisableTCPWindowScaling = intval(trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/DisableTCPWindowScaling")));
    $EnableSystemOptimize = intval(trim(@file_get_contents("/etc/artica-postfix/settings/Daemons/EnableSystemOptimize")));
    $tcp_ecn = 2;
    $tcp_window_scaling = 1;
    if ($DisableTCPWindowScaling == 1) {
        $tcp_window_scaling = 0;
    }
    if ($DisableTCPEn == 1) {
        $tcp_ecn = 0;
    }
    $sysctl = $unix->find_program("sysctl");
    $f[] = "#";
    $f[] = "# /etc/sysctl.conf - Configuration file for setting system variables";
    $f[] = "# See /etc/sysctl.d/ for additonal system variables";
    $f[] = "# See sysctl.conf (5) for information.";
    $f[] = "#";
    $f[] = "";
    $f[] = "#kernel.domainname = example.com";
    $f[] = "";
    $f[] = "# Uncomment the following to stop low-level messages on console";
    $f[] = "#kernel.printk = 3 4 1 3";
    $f[] = "";
    $f[] = "##############################################################";
    // /proc/sys/vm/dirty_ratio defaults to 20% of RAM
    // /proc/sys/vm/dirty_background_ratio defaults to 10%of RAM
    $memory = $unix->MEM_TOTAL_INSTALLEE() * 1024;
    $dirty_ratio = round($memory * 0.8);
    if ($EnableSystemOptimize == 0) {
        shell_exec("{$echo} 33554432 >/proc/sys/vm/dirty_background_bytes");
        shell_exec("{$echo} {$dirty_ratio} >/proc/sys/vm/dirty_bytes");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Memory: {$memory} bytes\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} dirty_ratio = {$dirty_ratio} bytes \n";
        }
    } else {
        $swappiness = 0;
        shell_exec("{$echo} 1024 > /sys/block/sda/queue/nr_requests");
    }
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $t = explode(".", $hostname);
    if (count($t) > 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} `hostname` = '{$hostname}'\n";
        }
        $f[] = "kernel.hostname={$t[0]}";
        unset($t[0]);
        $f[] = "kernel.domainname=" . @implode(".", $t);
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} `swappiness` = '{$swappiness}%'\n";
    }
    $f[] = "vm.swappiness = {$swappiness}";
    $f[] = "net.ipv4.icmp_ignore_bogus_error_responses = 1";
    $f[] = "net.ipv4.tcp_window_scaling = {$tcp_window_scaling}";
    $f[] = "net.ipv4.tcp_ecn = {$tcp_ecn}";
    $f[] = "net.ipv4.tcp_sack = 1";
    $f[] = "net.ipv4.tcp_fack = 1";
    $f[] = "net.ipv4.tcp_timestamps = 1";
    $f[] = "net.ipv4.icmp_echo_ignore_broadcasts = 1";
    $f[] = "";
    if ($EnableSystemOptimize == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} set dirty pages\n";
        }
        $f[] = "vm.dirty_background_ratio = 4";
        $f[] = "vm.dirty_background_bytes = 33554432";
        $f[] = "vm.dirty_ratio = 64";
        shell_exec("{$echo} \"100663296\" > /proc/sys/vm/dirty_bytes");
        shell_exec("{$echo} \"33554432\" > /proc/sys/vm/dirty_background_bytes");
        if (is_file($squidbin)) {
            if (is_file("/proc/sys/net/local/dgram/recvspace")) {
                $f[] = "net.local.dgram.recvspace=262144";
            }
            if (is_file("/proc/sys/net/local/dgram/maxdgram")) {
                $f[] = "net.local.dgram.maxdgram=16384";
            }
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} revert dirty pages to default\n";
        }
        $f[] = "vm.dirty_background_ratio = 10";
        $f[] = "vm.dirty_ratio = 20";
        $f[] = "vm.dirty_background_bytes = 0";
        $f[] = "vm.dirty_bytes = 0";
    }
    if (is_file($conntrack)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} conntrack installed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} conntrack DisableConntrack = {$DisableConntrack}\n";
        }
        if ($DisableConntrack == 1) {
            $f[] = "net.ipv4.netfilter.ip_conntrack_generic_timeout = 600";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_sent = 120";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_sent2 = 120";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_recv = 60";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = 432000";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait = 120";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait = 60";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_last_ack = 30";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 120";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_close = 10";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_max_retrans = 300";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_loose = 1";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_be_liberal = 0";
            $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_max_retrans = 3";
            $f[] = "net.ipv4.netfilter.ip_conntrack_udp_timeout = 30";
            $f[] = "net.ipv4.netfilter.ip_conntrack_udp_timeout_stream = 180";
            $f[] = "net.ipv4.netfilter.ip_conntrack_icmp_timeout = 30";
            $f[] = "net.ipv4.netfilter.ip_conntrack_max = 32088";
            $f[] = "net.ipv4.netfilter.ip_conntrack_log_invalid = 0";
            $f[] = "net.netfilter.nf_conntrack_acct = 0";
            shell_exec("{$echo} 8022 >/sys/module/nf_conntrack/parameters/hashsize >/dev/null 2>&1");
        } else {
            shell_exec("{$modprobe} nf_conntrack >/dev/null 2>&1");
            shell_exec("{$modprobe} nf_conntrack_ipv4 >/dev/null 2>&1");
            $nf_conntrack_max = 196608;
            $ip_conntrack_tcp_timeout_established = 86400;
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} conntrack MAX....: {$nf_conntrack_max}\n";
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} conntrack Timeout: {$ip_conntrack_tcp_timeout_established}\n";
            }
            if (is_file("/proc/sys/net/netfilter/nf_conntrack_acct")) {
                $f[] = "net.netfilter.nf_conntrack_acct = 1";
                $f[] = "net.netfilter.nf_conntrack_checksum = 0";
                $f[] = "net.netfilter.nf_conntrack_max = {$nf_conntrack_max}";
                $f[] = "net.netfilter.nf_conntrack_tcp_timeout_established = {$ip_conntrack_tcp_timeout_established}";
                $f[] = "net.netfilter.nf_conntrack_udp_timeout = 60";
                $f[] = "net.netfilter.nf_conntrack_udp_timeout_stream = 180";
                $f[] = "net.ipv4.netfilter.ip_conntrack_generic_timeout = 600";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_sent = 120";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_sent2 = 120";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_recv = 60";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_established = {$ip_conntrack_tcp_timeout_established}";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_fin_wait = 120";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_close_wait = 60";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_last_ack = 30";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_time_wait = 120";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_close = 10";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_timeout_max_retrans = 300";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_loose = 1";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_be_liberal = 0";
                $f[] = "net.ipv4.netfilter.ip_conntrack_tcp_max_retrans = 3";
                $f[] = "net.ipv4.netfilter.ip_conntrack_udp_timeout = 30";
                $f[] = "net.ipv4.netfilter.ip_conntrack_udp_timeout_stream = 180";
                $f[] = "net.ipv4.netfilter.ip_conntrack_icmp_timeout = 30";
                $f[] = "net.ipv4.netfilter.ip_conntrack_max = {$nf_conntrack_max}";
                $f[] = "net.ipv4.netfilter.ip_conntrack_checksum = 1";
                $f[] = "net.ipv4.netfilter.ip_conntrack_log_invalid = 0";
                shell_exec("{$echo} " . round($nf_conntrack_max / 8) . " > /sys/module/nf_conntrack/parameters/hashsize >/dev/null 2>&1");
            }
        }
    }
    if ($EnableTCPOptimize) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Optimize TCP stack\n";
        }
        $f[] = "net.ipv4.tcp_rfc1337 = 1";
        $f[] = "net.ipv4.tcp_syn_retries = 3";
        $f[] = "net.ipv4.tcp_synack_retries = 2";
        if ($tcp_max_syn_backlog < 1025) {
            $tcp_max_syn_backlog = 10240;
        }
        $wmem_max = trim(intval(@file_get_contents("/proc/sys/net/core/wmem_max")));
        $f[] = "net.ipv4.tcp_max_syn_backlog = {$tcp_max_syn_backlog}";
        $f[] = "net.ipv4.tcp_timestamps = 0";
        $f[] = "net.ipv4.tcp_fin_timeout = 15";
        $f[] = "net.ipv4.tcp_keepalive_time = 1800";
        $f[] = "net.ipv4.tcp_reordering = 5";
        $f[] = "net.ipv4.tcp_synack_retries = 3";
        $f[] = "net.ipv4.tcp_max_tw_buckets = 360000";
        $f[] = "net.core.netdev_max_backlog = 4000";
        $f[] = "net.core.rmem_default = 262144";
        $f[] = "net.core.rmem_max = 262144";
        $f[] = "net.core.wmem_max = 262144";
        $f[] = "net.ipv4.tcp_rmem=10240 87380 {$wmem_max}";
        $f[] = "net.ipv4.tcp_wmem=10240 87380 {$wmem_max}";
        $f[] = "net.ipv4.tcp_mem = {$wmem_max} {$wmem_max} {$wmem_max}";
        $f[] = "net.ipv4.conf.all.log_martians=0";
        $f[] = "net.ipv4.ip_local_port_range = 1024 65000";
        $f[] = "net.ipv4.tcp_window_scaling = {$tcp_window_scaling}";
        $f[] = "net.ipv4.tcp_ecn = {$tcp_ecn}";
        $f[] = "net.ipv4.tcp_low_latency =1 ";
        $f[] = "net.ipv4.tcp_timestamps=1";
        $f[] = "net.ipv4.tcp_sack=1";
        $f[] = "net.ipv4.tcp_no_metrics_save=1";
        $f[] = "net.core.netdev_max_backlog=16384";
        $f[] = "net.core.rmem_max=12582912";
        $f[] = "net.core.wmem_max = 12582912";
        $f[] = "net.core.wmem_default = 65535";
        $f[] = "net.core.optmem_max = 40960";
        $f[] = "net.ipv6.conf.all.accept_redirects = 1";
        $f[] = "net.ipv6.conf.all.accept_source_route = 0";
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} TCP stack set to default\n";
        }
        $f[] = "net.ipv4.tcp_rfc1337 = 0";
        $f[] = "net.ipv4.tcp_low_latency = 0 ";
        $f[] = "net.ipv4.tcp_syn_retries = 5";
        $f[] = "net.ipv4.tcp_synack_retries = 5";
        $f[] = "net.ipv4.tcp_max_syn_backlog = 512";
        $f[] = "net.ipv4.tcp_timestamps = 1";
        $f[] = "net.ipv4.tcp_fin_timeout = 60";
        $f[] = "net.ipv4.tcp_keepalive_time = 7200";
        $f[] = "net.ipv4.tcp_reordering = 3";
        $f[] = "net.ipv4.tcp_max_tw_buckets = 65536";
        $f[] = "net.ipv4.ip_local_port_range = 32768\t61000";
        $f[] = "net.core.rmem_default = 229376";
        $f[] = "net.core.netdev_max_backlog = 1000";
        $f[] = "net.core.rmem_max = 131071";
        $f[] = "net.core.wmem_max = 131071";
        $f[] = "net.ipv4.tcp_rmem = 4096\t87380\t1033696";
        $f[] = "net.ipv4.tcp_wmem = 4096\t16384\t1033696";
        $f[] = "net.ipv4.tcp_mem = 24225\t32303\t48450";
        $f[] = "net.ipv4.tcp_window_scaling = {$tcp_window_scaling}";
        $f[] = "net.ipv4.tcp_ecn = {$tcp_ecn}";
        $f[] = "net.ipv4.tcp_sack = 1";
        $f[] = "net.ipv4.tcp_no_metrics_save = 0";
        $f[] = "net.core.netdev_max_backlog = 1000";
        $f[] = "net.core.rmem_max = 131071";
        $f[] = "net.core.wmem_max = 131071";
        $f[] = "net.core.wmem_default = 229376";
        $f[] = "net.core.optmem_max = 20480";
        $f[] = "net.ipv4.icmp_echo_ignore_broadcasts = 1";
        $f[] = "net.ipv4.conf.all.send_redirects = 1";
        $f[] = "net.ipv4.conf.all.secure_redirects = 1";
        $f[] = "net.ipv4.conf.all.accept_redirects = 1";
        $f[] = "net.ipv4.conf.all.accept_source_route = 0";
        $f[] = "net.ipv4.conf.all.arp_accept = 0";
        $f[] = "net.ipv4.conf.all.arp_ignore = 0";
        $f[] = "net.ipv4.conf.all.arp_announce = 0";
        $f[] = "net.ipv4.conf.all.arp_filter = 0";
        $f[] = "net.ipv4.conf.all.arp_notify = 0";
        $f[] = "net.ipv4.ip_nonlocal_bind = 0";
        $f[] = "net.ipv4.conf.all.log_martians=0";
        $f[] = "net.ipv4.tcp_max_syn_backlog = 512";
    }
    if ($Isagetway) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Set as gateway...\n";
        }
        $f[] = "net.ipv4.ip_forward=1";
        if ($EnableipV6 == 1) {
            $f[] = "net.ipv6.conf.all.send_redirects = {$KernelSendRedirects}";
            $f[] = "net.ipv6.conf.all.forwarding=1";
            $f[] = "net.ipv6.conf.all.accept_redirects = 1";
            $f[] = "net.ipv6.conf.all.accept_source_route = 1";
            $f[] = "net.ipv6.conf.all.arp_accept=0";
            $f[] = "net.ipv6.conf.all.arp_ignore=1";
            $f[] = "net.ipv6.conf.all.arp_announce=2";
            $f[] = "net.ipv6.conf.all.arp_filter=1";
            $f[] = "net.ipv6.conf.all.arp_notify=1";
        }
    }
    if ($EnableipV6 == 1) {
        $f[] = "net.ipv6.conf.all.disable_ipv6 = 0";
        $f[] = "net.ipv6.conf.default.disable_ipv6 = 0";
        $f[] = "net.ipv6.conf.lo.disable_ipv6 = 0";
    } else {
        $f[] = "net.ipv6.conf.all.disable_ipv6 = 1";
        $f[] = "net.ipv6.conf.default.disable_ipv6 = 1";
        $f[] = "net.ipv6.conf.lo.disable_ipv6 = 1";
    }
    $SCRIPT[] = "#!/bin/sh";
    $SCRIPT[] = "### BEGIN INIT INFO";
    $SCRIPT[] = "# Provides:         artica-optimize";
    $SCRIPT[] = "# Required-Start:    \$local_fs";
    $SCRIPT[] = "# Required-Stop:     \$local_fs";
    $SCRIPT[] = "# Should-Start:";
    $SCRIPT[] = "# Should-Stop:";
    $SCRIPT[] = "# Default-Start:     2 3 4 5";
    $SCRIPT[] = "# Default-Stop:      0 1 6";
    $SCRIPT[] = "# Short-Description: artica-optimize";
    $SCRIPT[] = "# chkconfig: - 80 75";
    $SCRIPT[] = "# description: artica-optimize";
    $SCRIPT[] = "### END INIT INFO";
    $SCRIPT[] = "case \"\$1\" in";
    $SCRIPT[] = " start)";
    $SCRIPT[] = "echo \"Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}\"";
    $echo = $unix->find_program("echo");
    while (list($index, $line) = each($f)) {
        if (!preg_match("#(.+?)=(.+)#", $line, $re)) {
            continue;
        }
        $SCRIPT[] = "{$sysctl} -w \"" . trim($re[1]) . "=" . trim($re[2]) . "\" >/dev/null 2>&1 || true";
    }
    $SCRIPT[] = "echo \"Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}\" done.";
    $SCRIPT[] = ";;";
    $SCRIPT[] = "*)";
    $SCRIPT[] = "echo \"Usage: \$0 start\"";
    $SCRIPT[] = "exit 1";
    $SCRIPT[] = ";;";
    $SCRIPT[] = "esac";
    $SCRIPT[] = "exit 0";
    $SCRIPT[] = "";
    if (!is_file("/etc/init.d/artica-optimize")) {
        $INSTALL_SERVICE = true;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} /etc/init.d/artica-optimize done\n";
    }
    @file_put_contents("/etc/init.d/artica-optimize", @implode("\n", $SCRIPT));
    @chmod("/etc/init.d/artica-optimize", 0755);
    $f[] = "";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Installing init service\n";
    }
    @file_put_contents("/etc/sysctl.conf", @implode("\n", $f));
    if (is_file('/usr/sbin/update-rc.d')) {
        shell_exec("/usr/sbin/update-rc.d -f artica-optimize defaults >/dev/null 2>&1");
    }
    if (is_file('/sbin/chkconfig')) {
        shell_exec("/sbin/chkconfig --add artica-optimize >/dev/null 2>&1");
        shell_exec("/sbin/chkconfig --level 345 artica-optimize on >/dev/null 2>&1");
    }
    shell_exec("/etc/init.d/artica-optimize start");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} /etc/sysctl.conf done\n";
    }
    if ($GLOBALS["REBOOT"]) {
        $reboot = $unix->find_program("reboot");
        shell_exec("{$reboot}");
    }
    start(true);
}
Ejemplo n.º 15
0
function buildConfig()
{
    $unix = new unix();
    $sock = new sockets();
    $phpcgi = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    $chown = $unix->find_program("chown");
    $perlbin = $unix->find_program("perl");
    $nohup = $unix->find_program("nohup");
    $php = $unix->LOCATE_PHP5_BIN();
    $PHP_STANDARD_MODE = true;
    $phpfpm = $unix->find_program('php5-fpm');
    if (!is_file($phpfpm)) {
        $phpfpm = $unix->find_program('php-fpm');
    }
    @mkdir("/usr/share/artica-postfix/framework", 0755, true);
    @mkdir("/usr/share/artica-postfix/ressources/sock", 0755, true);
    $LighttpdRunAsminimal = $sock->GET_INFO("LighttpdRunAsminimal");
    $LighttpdArticaMaxProcs = $sock->GET_INFO("LighttpdArticaMaxProcs");
    $LighttpdArticaMaxChildren = $sock->GET_INFO("LighttpdArticaMaxChildren");
    $PHP_FCGI_MAX_REQUESTS = $sock->GET_INFO("PHP_FCGI_MAX_REQUESTS");
    $SessionPathInMemory = $sock->GET_INFO("SessionPathInMemory");
    if (!is_numeric($LighttpdRunAsminimal)) {
        $LighttpdRunAsminimal = 0;
    }
    if (!is_numeric($LighttpdArticaMaxProcs)) {
        $LighttpdArticaMaxProcs = 0;
    }
    if (!is_numeric($LighttpdArticaMaxChildren)) {
        $LighttpdArticaMaxChildren = 0;
    }
    if (!is_numeric($PHP_FCGI_MAX_REQUESTS)) {
        $PHP_FCGI_MAX_REQUESTS = 200;
    }
    if (!is_numeric($SessionPathInMemory)) {
        $SessionPathInMemory = 0;
    }
    $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM");
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if (!is_file("/opt/artica/ssl/certs/lighttpd.pem")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating SSL certificate..\n";
        }
        exec("/usr/share/artica-postfix/bin/artica-install -lighttpd-cert 2>&1", $results);
        while (list($pid, $line) = each($results)) {
            $line = trim($line);
            if ($line == null) {
                continue;
            }
            if (preg_match("#Starting.*?lighttpd(.+)#", $line, $re)) {
                $line = $re[1];
            }
            $line = str_replace(": ", "", $line);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [ARTI]: {$GLOBALS["SERVICE_NAME"]} {$line}\n";
            }
        }
    }
    $results = array();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Creating PHP configuration..\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Executing artica-install --php-ini..\n";
    }
    exec("/usr/share/artica-postfix/bin/artica-install --php-ini 2>&1", $results);
    while (list($pid, $line) = each($results)) {
        $line = trim($line);
        if ($line == null) {
            continue;
        }
        if (preg_match("#Starting.*?lighttpd(.+)#", $line, $re)) {
            $line = $re[1];
        }
        $line = str_replace(": ", "", $line);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [ARTI]: {$GLOBALS["SERVICE_NAME"]} {$line}\n";
        }
    }
    PHP_MYADMIN();
    $PHP_FCGI_CHILDREN = 3;
    $max_procs = 3;
    if ($LighttpdArticaMaxProcs > 0) {
        $max_procs = $LighttpdArticaMaxProcs;
    }
    if ($LighttpdArticaMaxChildren > 0) {
        $PHP_FCGI_CHILDREN = $LighttpdArticaMaxChildren;
    }
    if (!$unix->ISMemoryHiger1G()) {
        $PHP_FCGI_CHILDREN = 2;
        $max_procs = 1;
    }
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    if ($MEMORY < 624288) {
        $LighttpdRunAsminimal = 1;
    }
    if ($LighttpdRunAsminimal == 1) {
        $max_procs = 1;
        $PHP_FCGI_CHILDREN = 2;
        $PHP_FCGI_MAX_REQUESTS = 500;
    }
    $phpfpm = $unix->APACHE_LOCATE_PHP_FPM();
    $EnablePHPFPM = $sock->GET_INFO("EnablePHPFPM");
    if (!is_numeric($EnablePHPFPM)) {
        $EnablePHPFPM = 0;
    }
    if (!is_file($phpfpm)) {
        $EnablePHPFPM = 0;
    }
    if ($EnablePHPFPM == 0) {
        $EnableArticaApachePHPFPM = 0;
    }
    if ($EnableArticaApachePHPFPM == 0) {
        $EnablePHPFPM = 0;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} EnableArticaApachePHPFPM = {$EnableArticaApachePHPFPM}\n";
    }
    if ($EnablePHPFPM == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Using PHP-FPM........: Yes\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Using PHP-FPM........: No\n";
        }
    }
    $ArticaHttpsPort = 9000;
    $NoLDAPInLighttpdd = 0;
    $ArticaHttpUseSSL = 1;
    $ArticaHttpsPort = $sock->GET_INFO("ArticaHttpsPort");
    $ArticaHttpUseSSL = $sock->GET_INFO("ArticaHttpUseSSL");
    if (!is_numeric($ArticaHttpUseSSL)) {
        $ArticaHttpUseSSL = 1;
    }
    if (!is_numeric($ArticaHttpsPort)) {
        $ArticaHttpsPort = "9000";
    }
    $ArticaHttpUseSSL = $sock->GET_INFO('ArticaHttpUseSSL');
    if (!is_numeric($ArticaHttpUseSSL)) {
        $ArticaHttpUseSSL = 1;
    }
    $NoLDAPInLighttpdd = $sock->GET_INFO('NoLDAPInLighttpdd');
    if (!is_numeric($NoLDAPInLighttpdd)) {
        $NoLDAPInLighttpdd = 0;
    }
    $LighttpdUseUnixSocket = $sock->GET_INFO('LighttpdUseUnixSocket');
    if (!is_numeric($LighttpdUseUnixSocket)) {
        $LighttpdUseUnixSocket = 0;
    }
    $lighttpdPhpPort = $sock->GET_INFO('lighttpdPhpPort');
    if (!is_numeric($lighttpdPhpPort)) {
        $lighttpdPhpPort = 1808;
    }
    $DenyMiniWebFromStandardPort = $sock->GET_INFO('DenyMiniWebFromStandardPort');
    if (!is_numeric($DenyMiniWebFromStandardPort)) {
        $DenyMiniWebFromStandardPort = 0;
    }
    $LighttpdArticaDisableSSLv2 = $sock->GET_INFO('LighttpdArticaDisableSSLv2');
    if (!is_numeric($LighttpdArticaDisableSSLv2)) {
        $LighttpdArticaDisableSSLv2 = 1;
    }
    $LighttpdArticaMaxProcs = $sock->GET_INFO('LighttpdArticaMaxProcs');
    if (!is_numeric($LighttpdArticaMaxProcs)) {
        $LighttpdArticaMaxProcs = 0;
    }
    $LighttpdArticaMaxChildren = $sock->GET_INFO('LighttpdArticaMaxChildren');
    if (!is_numeric($LighttpdArticaMaxChildren)) {
        $LighttpdArticaMaxChildren = 0;
    }
    $LighttpdRunAsminimal = $sock->GET_INFO('LighttpdRunAsminimal');
    if (!is_numeric($LighttpdRunAsminimal)) {
        $LighttpdRunAsminimal = 0;
    }
    $PHP_FCGI_MAX_REQUESTS = $sock->GET_INFO('PHP_FCGI_MAX_REQUESTS');
    if (!is_numeric($PHP_FCGI_MAX_REQUESTS)) {
        $PHP_FCGI_MAX_REQUESTS = 200;
    }
    $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM");
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    if (!is_file($phpfpm)) {
        $EnableArticaApachePHPFPM = 0;
    }
    $EnablePHPFPM = intval($sock->GET_INFO("EnablePHPFPM"));
    if (!is_numeric($EnablePHPFPM)) {
        $EnablePHPFPM = 0;
    }
    if ($EnablePHPFPM == 0) {
        $EnableArticaApachePHPFPM = 0;
    }
    if ($EnableArticaApachePHPFPM == 0) {
        $EnablePHPFPM = 0;
    }
    $PHP_STANDARD_MODE = true;
    $LighttpdArticaListenIP = $sock->GET_INFO('LighttpdArticaListenIP');
    $phpcgi_path = $unix->LIGHTTPD_PHP5_CGI_BIN_PATH();
    $LIGHTTPD_GET_USER = LIGHTTPD_GET_USER();
    $LIGHTTPD_CONF_PATH = LIGHTTPD_CONF_PATH();
    if (preg_match("#^(.+?):(.+)#", $LIGHTTPD_GET_USER, $re)) {
        $LIGHTTPD_USER = $re[1];
        $LIGHTTPD_GROUP = $re[1];
    }
    $PHP_FCGI_CHILDREN = 1;
    $max_procs = 2;
    @mkdir("/var/log/lighttpd", 0755, true);
    @mkdir("/usr/share/artica-postfix/ressources/logs", 0755, true);
    if (!is_file("/var/log/lighttpd/access.log")) {
        @touch("/var/log/lighttpd/access.log");
    }
    @chown("/var/log/lighttpd", $LIGHTTPD_USER);
    @chgrp("/var/log/lighttpd", $LIGHTTPD_GROUP);
    @chown("/var/log/lighttpd/access.log", $LIGHTTPD_USER);
    @chgrp("/var/log/lighttpd/access.log", $LIGHTTPD_GROUP);
    @chmod("/var/log/lighttpd/access.log", 0777);
    $unix->chown_func($LIGHTTPD_USER, $LIGHTTPD_GROUP, "/var/log/lighttpd/*");
    $unix->chown_func($LIGHTTPD_USER, $LIGHTTPD_GROUP, "/usr/share/artica-postfix/ressources/logs/*");
    if ($LighttpdArticaMaxProcs > 0) {
        $max_procs = $LighttpdArticaMaxProcs;
    }
    if ($LighttpdArticaMaxChildren > 0) {
        $HP_FCGI_CHILDREN = $LighttpdArticaMaxChildren;
    }
    if ($LighttpdRunAsminimal == 1) {
        $max_procs = 2;
        $PHP_FCGI_CHILDREN = 2;
    }
    $mod_auth = isModule('mod_auth');
    if (is_file('/proc/user_beancounters')) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} VPS mode enabled, swith to socket mode for PHP\n";
        }
        $LighttpdUseUnixSocket = 1;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} MAX Procs............: {$max_procs}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Php5 processes.......: {$PHP_FCGI_CHILDREN}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Max cnx/processes....: {$PHP_FCGI_MAX_REQUESTS}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} php-cgi path.........: {$phpcgi_path}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} chown path...........: {$chown}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} php path.............: {$php}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} php FPM Path.........: {$phpfpm}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} php FPM Enabled......: {$EnableArticaApachePHPFPM}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Perl Path............: {$perlbin}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Conf Path............: {$LIGHTTPD_CONF_PATH}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Pid Path.............: /var/run/lighttpd/lighttpd.pid\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} SSL enabled..........: {$ArticaHttpUseSSL}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Disable SSLv2........: {$LighttpdArticaDisableSSLv2}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Listen Port..........: {$ArticaHttpsPort}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Run as...............: {$LIGHTTPD_USER} / {$LIGHTTPD_GROUP}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} No LDAP in Lighttpd..: {$NoLDAPInLighttpdd}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Mod auth installed...: {$mod_auth}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Use Unix socket......: {$LighttpdUseUnixSocket}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Sessions in Memory...: {$SessionPathInMemory}MB\n";
    }
    $MakeDirs[] = "/opt/artica/ssl/certs";
    $MakeDirs[] = "/var/lib/php/session";
    $MakeDirs[] = "/var/lighttpd/upload";
    $MakeDirs[] = "/var/run/lighttpd";
    $MakeDirs[] = "/var/log/lighttpd";
    $MakeDirs[] = "/opt/artica/share/www/jpegPhoto";
    $MakeDirs[] = dirname($LIGHTTPD_CONF_PATH);
    while (list($pid, $dir) = each($MakeDirs)) {
        if (!is_dir($dir)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} creating {$dir}\n";
            }
        }
        @mkdir($dir, 0755, true);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} permissions on {$dir}\n";
        }
        shell_exec("{$chown} {$LIGHTTPD_GET_USER} {$dir}");
    }
    $f[] = '#artica-postfix saved by artica lighttpd.conf (Artica Install binary) v3.0';
    $f[] = '';
    $f[] = 'server.modules = (';
    $f[] = '        "mod_alias",';
    $f[] = '        "mod_access",';
    $f[] = '        "mod_accesslog",';
    $f[] = '        "mod_compress",';
    $f[] = '        "mod_fastcgi",';
    $f[] = '        "mod_cgi",';
    $f[] = '	       "mod_status",';
    if ($NoLDAPInLighttpdd == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} LDAP Mode is disabled\n";
        }
    }
    if ($mod_auth) {
        $f[] = '	       "mod_auth"';
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} mod_auth module does not exists (should be a security issue !!!)\n";
        }
    }
    $f[] = ')';
    $f[] = '';
    $f[] = 'server.document-root        = "/usr/share/artica-postfix"';
    $f[] = 'server.username = "******"';
    $f[] = 'server.groupname = "' . $LIGHTTPD_GROUP . '"';
    $f[] = 'server.errorlog-use-syslog = "enable"';
    //$f[]='server.errorlog             = "/var/log/lighttpd/error.log"';
    $f[] = 'index-file.names            = ( "index.php","index.cgi")';
    $f[] = '';
    $f[] = 'mimetype.assign             = (';
    $f[] = '  ".pdf"          =>      "application/pdf",';
    $f[] = '  ".sig"          =>      "application/pgp-signature",';
    $f[] = '  ".spl"          =>      "application/futuresplash",';
    $f[] = '  ".class"        =>      "application/octet-stream",';
    $f[] = '  ".ps"           =>      "application/postscript",';
    $f[] = '  ".torrent"      =>      "application/x-bittorrent",';
    $f[] = '  ".dvi"          =>      "application/x-dvi",';
    $f[] = '  ".gz"           =>      "application/x-gzip",';
    $f[] = '  ".pac"          =>      "application/x-ns-proxy-autoconfig",';
    $f[] = '  ".swf"          =>      "application/x-shockwave-flash",';
    $f[] = '  ".tar.gz"       =>      "application/x-tgz",';
    $f[] = '  ".tgz"          =>      "application/x-tgz",';
    $f[] = '  ".tar"          =>      "application/x-tar",';
    $f[] = '  ".zip"          =>      "application/zip",';
    $f[] = '  ".mp3"          =>      "audio/mpeg",';
    $f[] = '  ".m3u"          =>      "audio/x-mpegurl",';
    $f[] = '  ".wma"          =>      "audio/x-ms-wma",';
    $f[] = '  ".wax"          =>      "audio/x-ms-wax",';
    $f[] = '  ".ogg"          =>      "application/ogg",';
    $f[] = '  ".wav"          =>      "audio/x-wav",';
    $f[] = '  ".gif"          =>      "image/gif",';
    $f[] = '  ".jar"          =>      "application/x-java-archive",';
    $f[] = '  ".jpg"          =>      "image/jpeg",';
    $f[] = '  ".jpeg"         =>      "image/jpeg",';
    $f[] = '  ".png"          =>      "image/png",';
    $f[] = '  ".xbm"          =>      "image/x-xbitmap",';
    $f[] = '  ".xpm"          =>      "image/x-xpixmap",';
    $f[] = '  ".xwd"          =>      "image/x-xwindowdump",';
    $f[] = '  ".css"          =>      "text/css",';
    $f[] = '  ".html"         =>      "text/html",';
    $f[] = '  ".htm"          =>      "text/html",';
    $f[] = '  ".js"           =>      "text/javascript",';
    $f[] = '  ".asc"          =>      "text/plain",';
    $f[] = '  ".c"            =>      "text/plain",';
    $f[] = '  ".cpp"          =>      "text/plain",';
    $f[] = '  ".log"          =>      "text/plain",';
    $f[] = '  ".conf"         =>      "text/plain",';
    $f[] = '  ".text"         =>      "text/plain",';
    $f[] = '  ".txt"          =>      "text/plain",';
    $f[] = '  ".dtd"          =>      "text/xml",';
    $f[] = '  ".xml"          =>      "text/xml",';
    $f[] = '  ".mpeg"         =>      "video/mpeg",';
    $f[] = '  ".mpg"          =>      "video/mpeg",';
    $f[] = '  ".mov"          =>      "video/quicktime",';
    $f[] = '  ".qt"           =>      "video/quicktime",';
    $f[] = '  ".avi"          =>      "video/x-msvideo",';
    $f[] = '  ".asf"          =>      "video/x-ms-asf",';
    $f[] = '  ".asx"          =>      "video/x-ms-asf",';
    $f[] = '  ".wmv"          =>      "video/x-ms-wmv",';
    $f[] = '  ".bz2"          =>      "application/x-bzip",';
    $f[] = '  ".tbz"          =>      "application/x-bzip-compressed-tar",';
    $f[] = '  ".tar.bz2"      =>      "application/x-bzip-compressed-tar",';
    $f[] = '  ""              =>      "application/octet-stream",';
    $f[] = ' )';
    $f[] = '';
    $f[] = '';
    $f[] = 'accesslog.filename          = "/var/log/lighttpd/access.log"';
    $f[] = 'url.access-deny             = ( "~", ".inc",".log",".ini" )';
    $f[] = '';
    $f[] = 'static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )';
    $f[] = 'server.port                 = ' . $ArticaHttpsPort;
    if ($LighttpdArticaListenIP != null) {
        $unix = new unix();
        $IPS = $unix->NETWORK_ALL_INTERFACES(true);
        if (!isset($IPS[$LighttpdArticaListenIP])) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} ERROR! Listen IP: {$LighttpdArticaListenIP} -> FALSE !!\n";
            }
            $LighttpdArticaListenIP = null;
        }
    }
    if (strlen($LighttpdArticaListenIP) > 3) {
        $f[] = 'server.bind                = "' . $LighttpdArticaListenIP . '"';
    }
    $f[] = 'server.pid-file             = "/var/run/lighttpd/lighttpd.pid"';
    $f[] = 'server.max-fds 		   = 2048';
    $f[] = 'server.max-connections      = 512';
    $f[] = 'server.network-backend      = "write"';
    shell_exec("{$php} /usr/share/artica-postfix/exec.lighttpd.nets.php");
    shell_exec("{$php} /usr/share/artica-postfix/exec.lighttpd.nets.php --phpmyadmin");
    if (is_file('/etc/artica-postfix/lighttpd_nets')) {
        $f[] = @file_get_contents("/etc/artica-postfix/lighttpd_nets");
    }
    $f[] = '';
    if (is_file($phpfpm)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM is installed\n";
        }
        if ($EnablePHPFPM == 1) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} PHP-FPM is enabled\n";
            }
            $PHP_STANDARD_MODE = false;
            $f[] = 'fastcgi.server = ( ".php" =>((';
            $f[] = '         "socket" => "/var/run/php-fpm.sock",';
        }
    }
    if ($PHP_STANDARD_MODE) {
        $f[] = 'fastcgi.server = ( ".php" =>((';
        $f[] = '         "bin-path" => "/usr/bin/php-cgi",';
        if ($LighttpdUseUnixSocket == 1) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Fast-cgi server unix socket mode\n";
            }
            $f[] = '         "socket" => "/var/run/lighttpd/php.socket" + var.PID,';
        } else {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Fast-cgi server socket 127.0.0.1:{$lighttpdPhpPort}\n";
            }
            $f[] = '         "host" => "127.0.0.1","port" =>' . $lighttpdPhpPort . ',';
        }
    }
    $f[] = '         "min-procs" => 1,';
    $f[] = '         "max-procs" => 1,';
    $f[] = '         "idle-timeout" => 10,';
    $f[] = '         "bin-environment" => (';
    $f[] = '             "PHP_FCGI_CHILDREN" => "' . $PHP_FCGI_CHILDREN . '",';
    $f[] = '             "PHP_FCGI_MAX_REQUESTS" => "' . $PHP_FCGI_MAX_REQUESTS . '"';
    $f[] = '          ),';
    $f[] = '          "bin-copy-environment" => (';
    $f[] = '            "PATH", "SHELL", "USER"';
    $f[] = '           ),';
    $f[] = '          "broken-scriptfilename" => "enable"';
    $f[] = '        ))';
    $f[] = ')';
    if ($ArticaHttpUseSSL == 1) {
        $f[] = 'ssl.engine                 = "enable"';
        $f[] = 'ssl.pemfile                = "/opt/artica/ssl/certs/lighttpd.pem"';
    }
    if ($LighttpdArticaDisableSSLv2 == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Disable SSLv2 and weak ssl cipher\n";
        }
        $f[] = 'ssl.use-sslv2              = "disable"';
        $f[] = 'ssl.cipher-list            = "TLSv1+HIGH !SSLv2 RC4+MEDIUM !aNULL !eNULL !3DES @STRENGTH"';
    } else {
        $f[] = 'ssl.use-sslv2              = "enable"';
        $f[] = 'ssl.cipher-list            = "TLSv1+HIGH RC4+MEDIUM !SSLv2 !3DES !aNULL @STRENGTH"';
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} No LDAP In lighttpd: {$NoLDAPInLighttpdd}\n";
    }
    if ($NoLDAPInLighttpdd == 0) {
        if ($mod_auth) {
            $f[] = 'status.status-url          = "/server-status"';
            $f[] = 'status.config-url          = "/server-config"';
        }
    }
    $f[] = 'server.upload-dirs         = ( "/var/lighttpd/upload" )';
    $f[] = '	server.follow-symlink = "enable"';
    $f[] = 'alias.url +=("/monitorix"  => "/var/www/monitorix/")';
    $f[] = 'alias.url += ("/blocked_attachments"=> "/var/spool/artica-filter/bightml")';
    $f[] = 'alias.url += ("/squid-rrd"=> "/opt/artica/share/www/squid/rrd")';
    $f[] = 'alias.url += ("/artica-agent"=> "/usr/share/artica-postfix/ressources/artica-agent")';
    if ($DenyMiniWebFromStandardPort == 1) {
        $f[] = '$HTTP["url"] =~ "^/miniadm.*|/computers|/user-backup" { url.access-deny = ( "" )}';
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} checking AWSTATS...\n";
    }
    $AWSTATS_www_root = AWSTATS_www_root();
    $f[] = '$HTTP["url"] =~ "^/prxy.*\\.php" { url.access-deny = ( "" )}';
    if (is_dir($AWSTATS_www_root)) {
        $f[] = 'alias.url += ( "/awstats" => "' . $AWSTATS_www_root . '" )';
    }
    if (is_file('/usr/share/poweradmin/index.php')) {
        $f[] = 'alias.url += ( "/powerdns" => "/usr/share/poweradmin" )';
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Checking PowerAdmin\n";
        }
        shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.pdns.php --poweradmin >/dev/null 2>&1 &");
    }
    //$perlbin
    $f[] = 'alias.url += ( "/cgi-bin/" => "/usr/lib/cgi-bin/" )';
    $f[] = '';
    $f[] = 'cgi.assign= (';
    $f[] = '	".pl"  => "' . $perlbin . '",';
    $f[] = '	".php" => "/usr/bin/php-cgi",';
    $f[] = '	".py"  => "/usr/bin/python",';
    $f[] = '	".cgi"  => "' . $perlbin . '",';
    if (is_file("/usr/lib/mailman/bin/mailmanctl")) {
        $f[] = '"/admin" => "",';
        $f[] = '"/admindb" => "",';
        $f[] = '"/confirm" => "",';
        $f[] = '"/create" => "",';
        $f[] = '"/edithtml" => "",';
        $f[] = '"/listinfo" => "",';
        $f[] = '"/options" => "",';
        $f[] = '"/private" => "",';
        $f[] = '"/rmlist" => "",';
        $f[] = '"/roster" => "",';
        $f[] = '"/subscribe" => ""';
    }
    $f[] = ')';
    $f[] = '';
    if ($mod_auth) {
        $f[] = 'auth.debug = 2';
        $f[] = '$HTTP["url"] =~ "^/cgi-bin/" {';
        $f[] = 'auth.backend = "plain"';
        $f[] = 'auth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpassword" ';
        $f[] = 'auth.require = ("/cgi-bin/" => (';
        $f[] = '     "method"  => "basic",';
        $f[] = '     "realm"   => "awstats Statistics",';
        $f[] = '     "require" => "valid-user"';
        $f[] = '  ))';
        $f[] = '}';
        $f[] = '';
        $f[] = '$HTTP["url"] =~ "^/server-status" {';
        $f[] = 'auth.backend = "plain"';
        $f[] = 'auth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpassword" ';
        $f[] = 'auth.require = ("/server-status" => (';
        $f[] = '     "method"  => "basic",';
        $f[] = '     "realm"   => "Lighttpd config - status",';
        $f[] = '     "require" => "valid-user"';
        $f[] = '  ))';
        $f[] = '}';
        $f[] = '';
        $f[] = '$HTTP["url"] =~ "^/server-config" {';
        $f[] = 'auth.backend = "plain"';
        $f[] = 'auth.backend.plain.userfile = "/etc/lighttpd/.lighttpdpassword" ';
        $f[] = 'auth.require = ("/server-config" => (';
        $f[] = '     "method"  => "basic",';
        $f[] = '     "realm"   => "Lighttpd config - status",';
        $f[] = '     "require" => "valid-user"';
        $f[] = '  ))';
        $f[] = '}';
        $f[] = '';
        $f[] = '$HTTP["url"] =~ "^/squid/" {';
        $f[] = 'auth.backend = "plain"';
        $f[] = 'auth.debug = 2';
        $f[] = 'auth.backend.plain.userfile = "/etc/lighttpd/squid-users.passwd" ';
        $f[] = 'auth.require = ("/squid/" => (';
        $f[] = '     "method"  => "basic",';
        $f[] = '     "realm"   => "Squid Statistics",';
        $f[] = '     "require" => "valid-user"';
        $f[] = '  ))';
        $f[] = '}';
        $f[] = '';
        $f[] = '$HTTP["url"] =~ "^/cluebringer/" {';
        $f[] = 'auth.backend = "plain"';
        $f[] = 'auth.debug = 2';
        $f[] = 'auth.backend.plain.userfile = "/etc/lighttpd/cluebringer.passwd" ';
        $f[] = 'auth.require = ("/cluebringer/" => (';
        $f[] = '     "method"  => "basic",';
        $f[] = '     "realm"   => "ClueBringer (Policyd V2) administration",';
        $f[] = '     "require" => "valid-user"';
        $f[] = '  ))';
        $f[] = '}';
        $f[] = '';
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} writing {$LIGHTTPD_CONF_PATH}..\n";
    }
    @file_put_contents($LIGHTTPD_CONF_PATH, @implode("\n", $f));
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$LIGHTTPD_CONF_PATH} done\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Check sessions...\n";
    }
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.shm.php --SessionMem >/dev/null 2>&1 &");
    shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.shm.php --service-up >/dev/null 2>&1 &");
}
include_once dirname(__FILE__) . '/ressources/class.mysql.inc';
include_once dirname(__FILE__) . '/ressources/class.os.system.inc';
include_once dirname(__FILE__) . "/framework/class.unix.inc";
include_once dirname(__FILE__) . "/framework/frame.class.inc";
if (posix_getuid() != 0) {
    die("Cannot be used in web server mode\n\n");
}
if (preg_match("#--verbose#", implode(" ", $argv))) {
    $GLOBALS["VERBOSE"] = true;
}
if (preg_match("#--force#", implode(" ", $argv))) {
    $GLOBALS["FORCE"] = true;
}
$GLOBALS["NO_PID_CHECKS"] = false;
$unix = new unix();
$MEMORY = $unix->MEM_TOTAL_INSTALLEE();
if ($MEMORY < 624288) {
    writelogs(basename(__FILE__) . ":Too low memory, die();", basename(__FILE__), __FILE__, __LINE__);
    die;
}
if ($argv[1] == "--av-uris") {
    ParseKav4UriLogs();
    die;
}
if ($argv[1] == "--av-events") {
    av_events();
    die;
}
if ($argv[1] == "--av-stats") {
    av_stats();
    die;
Ejemplo n.º 17
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = "/opt/kaspersky/kav4proxy/sbin/kav4proxy-kavicapserver";
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        $sock->SET_INFO("kavicapserverEnabled", 0);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Not enough memory\n";
        }
        if ($unix->process_exists($pid)) {
            stop();
        }
        return;
    }
    $pid = PID_NUM();
    $kavicapserverEnabled = intval($sock->GET_INFO("kavicapserverEnabled"));
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        if ($kavicapserverEnabled == 0) {
            stop();
        }
        return;
    }
    if ($kavicapserverEnabled == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see kavicapserverEnabled)\n";
        }
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    $unix->CreateUnixUser("kluser", "klusers");
    build();
    $version = kav4proxy_version();
    $KL_SERVICE_CONFIG = "/etc/opt/kaspersky/kav4proxy.conf";
    $f[] = $nohup;
    $f[] = $Masterbin;
    $f[] = "-C \"{$KL_SERVICE_CONFIG}\"";
    $cmd = @implode(" ", $f) . " >/dev/null 2>&1 &";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
}
Ejemplo n.º 18
0
function max_memory()
{
    $unix = new unix();
    $MyMEM = $unix->MEM_TOTAL_INSTALLEE() / 1000;
    $MyMEM = $MyMEM - 1600;
    $sock = new sockets();
    $NginxMaxMemToUse = intval($sock->GET_INFO("NginxMaxMemToUse"));
    if ($NginxMaxMemToUse == 0) {
        $NginxMaxMemToUse = 75;
    }
    $NginxMaxMemToUse = $NginxMaxMemToUse / 100;
    $MyMEM = round($MyMEM * $NginxMaxMemToUse);
    return $MyMEM;
}
Ejemplo n.º 19
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("saslauthd");
    $instances = 5;
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, saslauthd not installed\n";
        }
        return;
    }
    if (!$aspid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if ($unix->MEM_TOTAL_INSTALLEE() < 624288) {
        $instances = 2;
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} not enough memory instances = {$instances}\n";
        }
        return;
    }
    $EnableDaemon = 1;
    $users = new settings_inc();
    if (!$users->POSTFIX_INSTALLED) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Postfix: Not installed\n";
        }
        if (!$users->cyrus_imapd_installed) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Cyrus Impad: Not installed\n";
            }
            $EnableDaemon = 0;
        }
    }
    if ($EnableDaemon == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see Postfix/Cyrus)\n";
        }
        stop();
        return;
    }
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        return;
    }
    $EnableDaemon = 1;
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    $ln = $unix->find_program("ln");
    $chmod = $unix->find_program("chmod");
    $EnableVirtualDomainsInMailBoxes = $sock->GET_INFO("EnableVirtualDomainsInMailBoxes");
    $SaslAuthdConfigured = $sock->GET_INFO("SaslAuthdConfigured");
    $CyrusToAD = $sock->GET_INFO("CyrusToAD");
    if (!is_numeric($EnableVirtualDomainsInMailBoxes)) {
        $EnableVirtualDomainsInMailBoxes = 0;
    }
    if (!is_numeric($SaslAuthdConfigured)) {
        $SaslAuthdConfigured = 0;
    }
    if (!is_numeric($CyrusToAD)) {
        $CyrusToAD = 0;
    }
    @mkdir("/var/run/saslauthd", 0755, true);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} EnableVirtualDomainsInMailBoxes = {$EnableVirtualDomainsInMailBoxes}\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} CyrusToAD = {$CyrusToAD}\n";
    }
    $mech = "ldap";
    if ($EnableVirtualDomainsInMailBoxes == 1) {
        $moinsr = '-r ';
    }
    if ($CyrusToAD == 1) {
        $mech = 'pam';
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} saslauthd enable pam authentifications\n";
        }
        shell_exec($unix->LOCATE_PHP5_BIN() + ' /usr/share/artica-postfix/exec.cyrus.php --kinit >/dev/null 2>&1');
    }
    if (!$SaslAuthdConfigured) {
        build();
        $sock->SET_INFO("SaslAuthdConfigured", 1);
    }
    $cmd = "{$Masterbin} {$moinsr} -a {$mech} -c -m /var/run/saslauthd -n {$instances}";
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} symlink from /var/run/saslauthd to /var/run/sasl2\n";
        }
        shell_exec("{$ln} -sf /var/run/saslauthd /var/run/sasl2 >/dev/null 2>&1");
        @mkdir('/var/spool/postfix/var', 0755, true);
        shell_exec("{$ln} -sf /var/run /var/spool/postfix/var/run >/dev/null 2>&1");
        shell_exec("{$chmod} 0755 /var/run/saslauthd >/dev/null 2>&1");
        shell_exec("{$chmod} 0777 /var/run/saslauthd/* >/dev/null 2>&1");
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
}