Esempio n. 1
0
function configure_single_website($servername, $noreload = false, $nopid = false)
{
    $unix = new unix();
    $sock = new sockets();
    if (!$nopid) {
        $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]: Nginx Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $EnableFreeWeb = $sock->GET_INFO("EnableFreeWeb");
    if (!is_numeric($EnableFreeWeb)) {
        $EnableFreeWeb = 0;
    }
    $q = new mysql();
    $sql = "SELECT servername from freeweb WHERE servername='{$servername}'";
    $q = new mysql();
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if ($ligne["servername"] != null) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, {$servername} is a freeweb\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, *** NOTICE *** {$servername} is a freeweb\n";
        }
        configure_single_freeweb($servername);
        if (!$noreload) {
            configure_single_website_reload();
        }
        return;
    }
    $q = new mysql_squid_builder();
    $sql = "SELECT * FROM `reverse_www` WHERE `enabled`=1 AND servername='{$servername}'";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
    if (!$q->ok) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx,[" . __LINE__ . "] {$servername} {$q->mysql_error}\n";
        }
        return;
    }
    configure_single_website_rebuild();
    BuildReverse($ligne, true);
    if (!$noreload) {
        configure_single_website_reload();
    }
}
Esempio n. 2
0
function compile_site($servername)
{
    $servername = trim(strtolower($servername));
    $unix = new unix();
    $sock = new sockets();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".{$servername}." . __FUNCTION__ . ".pid";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        $cmdline = @file_get_contents("/proc/{$pid}/cmdline");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Already Artica task running PID {$pid} since {$time}mn\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx {$cmdline}\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $EnableFreeWeb = $sock->GET_INFO("EnableFreeWeb");
    if (!is_numeric($EnableFreeWeb)) {
        $EnableFreeWeb = 0;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    $sql = "SELECT servername from freeweb WHERE servername='{$servername}'";
    $q = new mysql();
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    if ($ligne["servername"] != null) {
        build_progress("{reconfigure} {$servername}", 10);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:  {$servername} is a freeweb\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:  *** NOTICE *** {$servername} is a freeweb\n";
        }
        configure_single_freeweb($servername);
        shell_exec("{$php} /usr/share/artica-postfix/exec.nginx.wizard.php --avail-status --force >/dev/null 2>&1 &");
        if (!$GLOBALS["NO_RELOAD"]) {
            if (!$GLOBALS["NO_BUILD_MAIN"]) {
                build_progress("{$ligne["servername"]}: {reloading_reverse_proxy} ", 80);
                system("/etc/init.d/nginx reload --force");
                build_progress("{$ligne["servername"]}: {reloading_reverse_proxy}  {done}", 100);
            }
        }
        return;
    }
    $q = new mysql_squid_builder();
    $sql = "SELECT * FROM `reverse_www` WHERE `enabled`=1 AND servername='{$servername}'";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql));
    if ($ligne["servername"] == null) {
        remove_website($servername);
        echo "servername row is null ??...\n";
        build_progress("{reconfigure} {$servername} {disabled}", 110);
        return;
    }
    if (!$q->ok) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "] {$servername} {$q->mysql_error}\n";
        }
        return;
    }
    build_progress("{reconfigure} {$servername}", 10);
    if (!BuildReverse($ligne, true)) {
        return;
    }
    if (!$GLOBALS["NO_BUILD_MAIN"]) {
        build_progress("{building_main_settings}", 85);
        system("{$php} /usr/share/artica-postfix/exec.nginx.php --main");
    } else {
        build_progress("{building_main_settings} skipped", 85);
    }
    shell_exec("{$php} /usr/share/artica-postfix/exec.nginx.wizard.php --avail-status --force >/dev/null 2>&1 &");
    if (!$GLOBALS["NO_RELOAD"]) {
        if (!$GLOBALS["NO_BUILD_MAIN"]) {
            build_progress("{$ligne["servername"]}: {stopping_reverse_proxy} ", 90);
            system("/etc/init.d/nginx stop --force");
            build_progress("{$ligne["servername"]}: {starting_reverse_proxy} ", 95);
            system("/etc/init.d/nginx start --force");
            build_progress("{$ligne["servername"]}: {reloading_reverse_proxy}  {done}", 100);
        } else {
            build_progress("{reloading_reverse_proxy} skipped", 90);
            build_progress("{$ligne["servername"]}: {done}", 100);
        }
    } else {
        build_progress("{reloading_reverse_proxy} skipped", 90);
        build_progress("{$ligne["servername"]}: {done}", 100);
    }
}