示例#1
0
function framework()
{
    $unix = new unix();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Framework...\n";
    }
    $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());
    if (!is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
        $lighttpdbin = $unix->find_program("lighttpd");
        if (is_file($lighttpdbin)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, {$lighttpdbin} OK turn, to lighttpd...\n";
            }
            return;
        }
    }
    if (!is_file("/etc/php5/fpm/pool.d/framework.conf")) {
        $php = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$php} /usr/share/artica-postfix/exec.php-fpm.php --build");
    }
    if (!is_file("/etc/php5/fpm/pool.d/framework.conf")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Unable to stat framework settings\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, building framework...\n";
    }
    $host = new nginx(47980);
    $host->set_proxy_disabled();
    $host->set_DocumentRoot("/usr/share/artica-postfix/framework");
    $host->set_framework();
    $host->build_proxy();
    $PID = PID_NUM();
    if (!$unix->process_exists($PID)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, not started, start it...\n";
        }
        start(true);
    }
    $kill = $unix->find_program("kill");
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, reloading PID {$PID}\n";
    }
    shell_exec("{$kill} -HUP {$PID} >/dev/null 2>&1");
}
示例#2
0
function BuildReverse($ligne, $backupBefore = false)
{
    $T1 = time();
    $q = new mysql_squid_builder();
    $unix = new unix();
    $ligne["servername"] = trim($ligne["servername"]);
    $GLOBALS["IPADDRS"] = $unix->NETWORK_ALL_INTERFACES(true);
    $IPADDRS = $GLOBALS["IPADDRS"];
    $DenyConf = $ligne["DenyConf"];
    $ligne["servername"] = trim($ligne["servername"]);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  ************* {$ligne["servername"]}:{$ligne["port"]} / {$DenyConf} ************* \n";
    }
    if ($ligne["port"] == 82) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "] 82 port is an apache port, SKIP\n";
        build_progress("Bad port {$ligne["servername"]}:82", 110);
        return;
    }
    if ($GLOBALS["REMOVE_LOCAL_ADDR"]) {
        if (isset($IPADDRS[$ligne["servername"]])) {
            build_progress("{$IPADDRS[$ligne["servername"]]} *** SKIPPED ***", 110);
            echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  {$ligne["servername"]} *** SKIPPED ***\n";
            return;
        }
    }
    if ($DenyConf == 1) {
        build_progress("Denied config *** SKIPPED ***", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  Local web site `{$ligne["servername"]}`, DenyConf = 1,skipped\n";
        }
        return;
    }
    if (isset($ALREADYSET[$ligne["servername"]])) {
        build_progress("Already setup", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  `{$ligne["servername"]}` Already defined, abort\n";
        }
        return;
    }
    $ListenPort = $ligne["port"];
    $SSL = $ligne["ssl"];
    $certificate = $ligne["certificate"];
    echo "Starting......: " . date("H:i:s") . " [INIT]:  ListenPort..............:{$ListenPort}\n";
    echo "Starting......: " . date("H:i:s") . " [INIT]:  SSL.....................:{$SSL}\n";
    echo "Starting......: " . date("H:i:s") . " [INIT]:  Certificate.............:{$certificate}\n";
    echo "Starting......: " . date("H:i:s") . " [INIT]:  OWA.....................:{$ligne["owa"]}\n";
    if ($ligne["owa"] == 1) {
        $GLOBALS["OUTPUT"] = true;
        $nginx_exchange = new nginx_exchange($ligne["servername"]);
        build_progress("{$ligne["servername"]}: {building} Microsoft Exchange Configuration", 50);
        $nginx_exchange->buildConfig();
        build_progress("{$ligne["servername"]}: {building} Microsoft Exchange Configuration {done}", 70);
        $Took = distanceOfTimeInWords($T1, time(), true);
        nginx_admin_mysql(2, "Success build Microsoft Exchange Configuration configuration for {$ligne["servername"]} took: {$Took}", "Took: {$Took}", __FILE__, __LINE__);
        build_progress("{$ligne["servername"]}: Microsoft Exchange Configuration {done}", 80);
        return true;
    }
    build_progress("{$ligne["servername"]}:{$ListenPort} [SSL:{$SSL}]", 20);
    echo "Starting......: " . date("H:i:s") . " [INIT]: Protect remote web site `{$ligne["servername"]}:{$ListenPort} [SSL:{$SSL}]`\n";
    if ($ligne["servername"] == null) {
        echo "Starting......: " . date("H:i:s") . " [INIT]:  skip it...\n";
        return;
    }
    $cache_peer_id = $ligne["cache_peer_id"];
    if ($cache_peer_id > 0) {
        $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM `reverse_sources` WHERE `ID`='{$cache_peer_id}'"));
    }
    $host = new nginx($ligne["servername"]);
    if ($ListenPort == 80 && $SSL == 1) {
        build_progress("{$ligne["servername"]}: Building HTTP", 40);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:  HTTP/HTTPS Enabled [" . __LINE__ . "]...\n";
        }
        $host->set_RedirectQueries($ligne["RedirectQueries"]);
        $host->set_forceddomain($ligne2["forceddomain"]);
        $host->set_ssl(0);
        $host->set_mixed_ssl(1);
        $host->set_proxy_port($ligne2["port"]);
        $host->set_listen_port(80);
        $host->set_poolid($ligne["poolid"]);
        $host->set_owa($ligne["owa"]);
        $host->set_storeid($ligne["cacheid"]);
        $host->set_cache_peer_id($cache_peer_id);
        $host->BackupBefore = $backupBefore;
        build_progress("{$ligne["servername"]}: HTTP/HTTPS Enabled", 50);
        $GLOBALS["NGINX_FATAL_ERRORS"] = array();
        if (!$host->build_proxy()) {
            if ($GLOBALS["NGINX_FATAL_ERROR"] != null) {
                nginx_admin_mysql(0, "Fatal error on {$ligne["servername"]} <{$GLOBALS["NGINX_FATAL_ERROR"]}>", "{$GLOBALS["NGINX_FATAL_ERROR"]}\n" . @implode("\n", $GLOBALS["NGINX_FATAL_ERRORS"]));
                echo "***                                             ***\n";
                echo "*** Fatal error {$GLOBALS["NGINX_FATAL_ERROR"]} ***\n";
                echo "***                                             ***\n";
                build_progress("{$ligne["servername"]}: {failed} {$GLOBALS["NGINX_FATAL_ERROR"]}", 110);
                return;
            }
            build_progress("{$ligne["servername"]}: {failed}", 110);
            return;
        }
        if (!$GLOBALS["NO_RELOAD"]) {
            build_progress("{$ligne["servername"]}: {done}", 80);
            return true;
        }
    }
    if ($ligne["ssl"] == 1) {
        echo "Starting......: " . date("H:i:s") . " [INIT]:  SSL Enabled...\n";
        $ligne2["ssl"] = 1;
    }
    if ($ligne["port"] == 443) {
        $ligne2["ssl"] = 1;
    }
    build_progress("{$ligne["servername"]}", 50);
    $host->BackupBefore = $backupBefore;
    $host->set_owa($ligne["owa"]);
    $host->set_RedirectQueries($ligne["RedirectQueries"]);
    $host->set_ssl_certificate($certificate);
    $host->set_ssl_certificate($ligne2["ssl_commname"]);
    $host->set_forceddomain($ligne2["forceddomain"]);
    $host->set_ssl($ligne2["ssl"]);
    $host->set_proxy_port($ligne2["port"]);
    $host->set_listen_port($ligne["port"]);
    $host->set_poolid($ligne["poolid"]);
    $host->set_owa($ligne["owa"]);
    $host->set_storeid($ligne["cacheid"]);
    $host->set_cache_peer_id($cache_peer_id);
    $host->build_proxy();
    if ($GLOBALS["NGINX_FATAL_ERROR"] != null) {
        nginx_admin_mysql(0, "Fatal error on {$ligne["servername"]} <{$GLOBALS["NGINX_FATAL_ERROR"]}>", "{$GLOBALS["NGINX_FATAL_ERROR"]}\n" . @implode("\n", $GLOBALS["NGINX_FATAL_ERRORS"]), __FILE__, __LINE__);
        echo "*** Fatal error {$GLOBALS["NGINX_FATAL_ERROR"]} ***\n";
        build_progress("{$ligne["servername"]}: {failed}", 110);
        return;
    }
    $Took = distanceOfTimeInWords($T1, time(), true);
    nginx_admin_mysql(2, "Success build configuration for {$ligne["servername"]} took: {$Took}", "Took: {$Took}", __FILE__, __LINE__);
    build_progress("{$ligne["servername"]}: {done}", 80);
    return true;
}