예제 #1
0
function reload()
{
    $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__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Reloading.....: [INIT]: Already task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    $pid = ZARAFA_SEARCH_PID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Reloading.....: [INIT]: {$GLOBALS["SERVICE_NAME"]} stopped...\n";
        }
        $php5 = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$php5} " . __FILE__ . " --start");
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Reloading.....: [INIT]: {$GLOBALS["SERVICE_NAME"]} reloading PID {$pid}...\n";
    }
    $kill = $unix->find_program("kill");
    unix_system_HUP($pid);
}
예제 #2
0
function SingleInstance_reload()
{
    $unix = new unix();
    SingleInstance();
    $pid = SingleInstance_pid();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "{$GLOBALS["deflog_start"]} reloading executed {$pid} since {$timepid}Mn...\n";
        }
        unix_system_HUP($pid);
        sleep(2);
        $pid = SingleInstance_pid();
        if (!$unix->process_exists($pid)) {
            SingleInstance_start(true);
        }
        return;
    }
    SingleInstance_start(true);
}
예제 #3
0
function build_ufdbguard_HUP()
{
    if (isset($GLOBALS["build_ufdbguard_HUP_EXECUTED"])) {
        return;
    }
    $GLOBALS["build_ufdbguard_HUP_EXECUTED"] = true;
    $unix = new unix();
    $sock = new sockets();
    $forceTXT = null;
    $ufdbguardReloadTTL = intval($sock->GET_INFO("ufdbguardReloadTTL"));
    if ($ufdbguardReloadTTL < 1) {
        $ufdbguardReloadTTL = 10;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $rm = $unix->find_program("rm");
    shell_exec("{$php5} /usr/share/artica-postfix/exec.ufdbclient.reload.php");
    shell_exec("{$rm} /home/squid/error_page_cache/*");
    if (function_exists("debug_backtrace")) {
        $trace = @debug_backtrace();
        if (isset($trace[1])) {
            $called = "called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
        }
    }
    $trace = debug_backtrace();
    if (isset($trace[1])) {
        $called = " called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
    }
    $timeFile = "/etc/artica-postfix/pids/UfdbGuardReload.time";
    $TimeReload = $unix->file_time_min($timeFile);
    if (!$GLOBALS["FORCE"]) {
        if ($TimeReload < $ufdbguardReloadTTL) {
            build_progress("{reloading_service} {failed}", 110);
            $unix->_syslog("Webfiltering service Aborting reload, last reload since {$TimeReload}Mn, need at least {$ufdbguardReloadTTL}Mn", basename(__FILE__));
            echo "Starting......: " . date("H:i:s") . " Webfiltering service Aborting reload, last reload since {$TimeReload}Mn, need at least {$ufdbguardReloadTTL}Mn\n";
            return;
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " --- FORCED --- ufdbGuard last reload was {$TimeReload}mn\n";
    }
    @unlink($timeFile);
    @file_put_contents($timeFile, time());
    $pid = ufdbguard_pid();
    build_progress("{reloading_service} {$pid}", 71);
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $ufdbguardd = $unix->find_program("ufdbguardd");
    if (strlen($ufdbguardd) < 5) {
        WriteToSyslogMail("ufdbguardd no such binary", basename(__FILE__));
        return;
    }
    $kill = $unix->find_program("kill");
    if ($unix->process_exists($pid)) {
        $processTTL = intval($unix->PROCCESS_TIME_MIN($pid));
        $LastTime = intval($unix->file_time_min($timeFile));
        build_progress("{reloading_service} {$pid} {$processTTL}Mn", 72);
        echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading service TTL {$processTTL}Mn\n";
        echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading service Last config since {$LastTime}Mn\n";
        echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading Max reload {$ufdbguardReloadTTL}Mn\n";
        if (!$GLOBALS["FORCE"]) {
            echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading force is disabled\n";
            if ($LastTime < $ufdbguardReloadTTL) {
                squid_admin_mysql(2, "Reloading Web Filtering PID: {$pid} [Aborted] last reload {$LastTime}Mn, need {$ufdbguardReloadTTL}mn", null, __FILE__, __LINE__);
                echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading service Aborting... minimal time was {$ufdbguardReloadTTL}mn - Current {$LastTime}mn\n{$called}\n";
                return;
            }
            if ($processTTL < $ufdbguardReloadTTL) {
                squid_admin_mysql(2, "Reloading Web Filtering PID: {$pid} [Aborted] {$processTTL}Mn, need {$ufdbguardReloadTTL}mn", null, __FILE__, __LINE__);
                echo "Starting......: " . date("H:i:s") . " Webfiltering service PID: {$pid}  Reloading service Aborting... minimal time was {$ufdbguardReloadTTL}mn\n{$called}\n";
                return;
            }
        }
        if ($GLOBALS["FORCE"]) {
            $forceTXT = " with option FORCE enabled";
            $prefix = "[FORCED]:";
        }
        @unlink($timeFile);
        @file_put_contents($timeFile, time());
        echo "Starting......: " . date("H:i:s") . " Webfiltering service Reloading service PID:{$pid} {$processTTL}mn\n";
        squid_admin_mysql(1, "{$prefix}Reloading Web Filtering service PID: {$pid} TTL {$processTTL}Mn", "{$forceTXT}\n{$called}\n{$GLOBALS["CMDLINEXEC"]}");
        build_progress("{reloading_service} HUP {$pid}", 75);
        unix_system_HUP($pid);
        build_progress("{reloading_proxy_service}", 76);
        shell_exec("{$php5} /usr/share/artica-postfix/exec.ufdbclient.reload.php");
        $squidbin = $unix->LOCATE_SQUID_BIN();
        squid_admin_mysql(1, "{$prefix}Reloading Proxy service", null, __FILE__, __LINE__);
        system("{$squidbin} -k reconfigure");
        return true;
    }
    squid_admin_mysql(1, "Warning, Reloading Web Filtering but not running [action=start]", "{$forceTXT}\n{$called}\n{$GLOBALS["CMDLINEXEC"]}");
    echo "Starting......: " . date("H:i:s") . " Webfiltering service reloading service no pid is found, Starting service...\n";
    @unlink($timeFile);
    @file_put_contents($timeFile, time());
    build_progress("{starting_service}", 76);
    if (!ufdbguard_start()) {
        return;
    }
    echo "Starting......: " . date("H:i:s") . " Webfiltering Service restarting ufdb-tail process\n";
    shell_exec("/etc/init.d/ufdb-tail restart");
    shell_exec("{$php5} /usr/share/artica-postfix/exec.ufdbclient.reload.php");
    squid_admin_mysql(1, "{$prefix}Reloading Proxy service", null, __FILE__, __LINE__);
    system("{$squidbin} -k reconfigure");
    build_progress("{starting_service} {done}", 77);
    return true;
}
예제 #4
0
function SingleInstance_reload()
{
    $unix = new unix();
    SingleInstance();
    $pid = SingleInstance_pid();
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "{$GLOBALS["deflog_start"]} reloading executed {$pid} since {$timepid}Mn...\n";
        }
        unix_system_HUP($pid);
        sleep(2);
        $pid = SingleInstance_pid();
        if (!$unix->process_exists($pid)) {
            SingleInstance_start(true);
        }
        return;
    }
    $PHP = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    shell_exec("{$nohup} {$PHP} /usr/share/artica-postfix/exec.spamassassin.php --whitelist >/dev/null 2>&1 &");
    SingleInstance_start(true);
}
예제 #5
0
function reload($nopid = false)
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if (!$nopid) {
        $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]: Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
    }
    @file_put_contents($pidfile, getmypid());
    $sock = new sockets();
    $Enablentopng = $sock->GET_INFO("Enablentopng");
    if (!is_numeric($Enablentopng)) {
        $Enablentopng = 0;
    }
    if ($Enablentopng == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Disabled ( see Enablentopng )...\n";
        }
        return;
    }
    build();
    $masterbin = $unix->find_program("ntopng");
    if (!is_file($masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Reload........: [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n";
        }
        return;
    }
    $pid = ntopng_pid();
    $kill = $unix->find_program("kill");
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Reload........: [INIT]: {$GLOBALS["SERVICE_NAME"]} Service running since {$time}Mn...\n";
        }
        unix_system_HUP($pid);
        return;
    }
    start(true);
}
예제 #6
0
function reload()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $sock = new sockets();
    $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;
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        $unix->_syslog("{$GLOBALS["TITLENAME"]} Reloading PID {$pid}\n", basename(__FILE__));
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Reloading PID {$pid}\n";
        }
        CheckDirectories();
        buildconfig();
        unix_system_HUP($pid);
    } else {
        start(true);
    }
}
예제 #7
0
function reload()
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $sock = new sockets();
    $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;
    }
    $DisableUfdbCat = $sock->DisableUfdbCat();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} DisableUfdbCat= {$DisableUfdbCat}\n";
    }
    if ($DisableUfdbCat == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see DisableUfdbCat)\n";
        }
        stop();
        return;
    }
    $pid = PID_NUM();
    $time = $unix->PROCCESS_TIME_MIN($pid);
    if ($unix->process_exists($pid)) {
        CheckDirectories(true);
        CheckDirectoriesTLSE();
        buildconfig();
        $unix->_syslog("{$GLOBALS["TITLENAME"]} Reloading PID {$pid} (running since {$time}Mn)\n", basename(__FILE__));
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Reloading PID {$pid}\n";
        }
        squid_admin_mysql(1, "Reloading Categories service (running since {$time}Mn)", null, __FILE__, __LINE__);
        unix_system_HUP($pid);
    } else {
        start(true);
    }
}
예제 #8
0
function reload($aspid = false)
{
    $unix = new unix();
    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 "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    CheckPermissions();
    BuildConfig();
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Not running, start it...\n";
        }
        start(true);
        return;
    }
    $time = $unix->PROCCESS_TIME_MIN($pid);
    if ($GLOBALS["OUTPUT"]) {
        echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} cyrus-imapd running since {$time}mn\n";
    }
    $kill = $unix->find_program("kill");
    unix_system_HUP($pid);
    $unix->CreateUnixUser("postfix", "postfix");
    $lmtpsocket = "/var/spool/postfix/var/run/cyrus/socket/lmtp";
    for ($i = 1; $i < 5; $i++) {
        if ($unix->is_socket($lmtpsocket)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Reloading.....: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Waiting socket success..\n";
            }
            $unix->chown_func("postfix", "postfix", "/var/spool/postfix/var/run");
            $unix->chown_func("postfix", "postfix", "{$lmtpsocket}");
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Reloading.....: " . date("H:i:s") . " {$GLOBALS["TITLENAME"]} Waiting socket {$i}/5\n";
        }
        sleep(1);
    }
}
예제 #9
0
function build_schedules($notfcron = false)
{
    $unix = new unix();
    $sock = new sockets();
    $squid = $unix->LOCATE_SQUID_BIN();
    if (!is_file($squid)) {
        return;
    }
    @mkdir("/var/log/artica-postfix/youtube", 0755, true);
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidTime = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        writelogs("Already executed pid {$pid}", __FILE__, __FUNCTION__, __LINE__);
        return;
    }
    $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance");
    if (!is_numeric($EnableRemoteStatisticsAppliance)) {
        $EnableRemoteStatisticsAppliance = 0;
    }
    @file_put_contents($pidfile, getmypid());
    $pidTimeINT = $unix->file_time_min($pidTime);
    if (!$GLOBALS["VERBOSE"]) {
        if ($pidTimeINT < 2) {
            writelogs("To short time to execute the process", __FILE__, __FUNCTION__, __LINE__);
            return;
        }
    }
    @file_put_contents($pidTime, time());
    if (!$unix->IsSquidTaskCanBeExecuted()) {
        if ($GLOBALS["VERBOSE"]) {
            echo "These tasks cannot be executed in this server\n";
        }
        return;
    }
    $q = new mysql_squid_builder();
    $q->CheckDefaultSchedules();
    if ($q->COUNT_ROWS("webfilters_schedules") == 0) {
        return;
    }
    $sql = "SELECT *  FROM webfilters_schedules WHERE enabled=1";
    $results = $q->QUERY_SQL($sql);
    if (!$q->ok) {
        return;
    }
    @unlink("/etc/cron.d/SquidTailInjector");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $WorkingDirectory = dirname(__FILE__);
    $chmod = $unix->find_program("chmod");
    foreach (glob("/etc/cron.d/*") as $filename) {
        $file = basename($filename);
        if (preg_match("#squidsch-[0-9]+#", $filename)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Removing old task {$file}\n";
            }
            @unlink($filename);
        }
    }
    @unlink("/etc/artica-postfix/TASKS_SQUID_CACHE.DB");
    $settings = unserialize(base64_decode($sock->GET_INFO("FcronSchedulesParams")));
    if (!isset($settings["max_nice"])) {
        $settings["max_nice"] = 19;
    }
    if (!isset($settings["max_load_avg5"])) {
        $settings["max_load_avg5"] = 3;
    }
    if (!isset($settings["max_load_wait"])) {
        $settings["max_load_wait"] = 10;
    }
    if (!is_numeric($settings["max_load_avg5"])) {
        $settings["max_load_avg5"] = "3";
    }
    if (!is_numeric($settings["max_load_wait"])) {
        $settings["max_load_wait"] = "10";
    }
    if (!is_numeric($settings["max_nice"])) {
        $settings["max_nice"] = "19";
    }
    $max_load_wait = $settings["max_load_wait"];
    $finalsettings = "nice({$settings["max_nice"]}),lavg5({$settings["max_load_avg5"]}),until({$max_load_wait})";
    @unlink("/etc/artica-postfix/squid.schedules");
    $nice = EXEC_NICE();
    $q = new mysql_squid_builder();
    $c = 0;
    $d = 0;
    while ($ligne = mysql_fetch_assoc($results)) {
        $allminutes = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59";
        $TaskType = $ligne["TaskType"];
        $TimeText = $ligne["TimeText"];
        if ($TaskType == 0) {
            continue;
        }
        if ($ligne["TimeText"] == null) {
            continue;
        }
        if ($EnableRemoteStatisticsAppliance == 1) {
            if ($q->tasks_remote_appliance[$TaskType]) {
                $d++;
                continue;
            }
        }
        $md5 = md5("{$TimeText}{$TaskType}");
        if (isset($alreadydone[$md5])) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Starting......: " . date("H:i:s") . " artica-postfix watchdog task {$ligne["ID"]} already set\n";
            }
            continue;
        }
        $alreadydone[$md5] = true;
        if (!isset($q->tasks_processes[$TaskType])) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Starting......: " . date("H:i:s") . " artica-postfix task {$ligne["ID"]} no such task...\n";
            }
            $d++;
            continue;
        }
        if (isset($q->tasks_disabled[$TaskType])) {
            if ($GLOBALS["VERBOSE"]) {
                echo "Starting......: " . date("H:i:s") . " artica-postfix task {$ligne["ID"]} is disabled or did not make sense...\n";
            }
            $d++;
            continue;
        }
        $script = $q->tasks_processes[$TaskType];
        if ($GLOBALS["VERBOSE"]) {
            echo "Starting......: " . date("H:i:s") . " artica-postfix create task {$ligne["ID"]} type {$TaskType}..\n";
        }
        if (trim($ligne["TimeText"] == "{$allminutes} * * * *")) {
            $ligne["TimeText"] = "* * * * *";
        }
        $f = array();
        $f[] = "MAILTO=\"\"";
        $f[] = "{$ligne["TimeText"]}  root {$nice} {$php5} {$WorkingDirectory}/exec.schedules.php --run-squid {$ligne["ID"]} >/dev/null 2>&1";
        $f[] = "";
        @file_put_contents("/etc/cron.d/squidsch-{$ligne["ID"]}", @implode("\n", $f));
        $c++;
        continue;
        if (trim($ligne["TimeText"] == "20,40,59 * * * *")) {
            $f[] = "@{$finalsettings},mail(false) 20 {$php5} {$WorkingDirectory}/{$script} --schedule-id={$ligne["ID"]} >/dev/null 2>&1";
            continue;
        }
        if (trim($ligne["TimeText"] == "0 * * * *")) {
            $f[] = "@{$finalsettings},mail(false) 1h {$php5} {$WorkingDirectory}/{$script} --schedule-id={$ligne["ID"]} >/dev/null 2>&1";
            continue;
        }
        if (trim($ligne["TimeText"] == "10,20,30,40,50 * * * *")) {
            $f[] = "@{$finalsettings},mail(false) 10 {$php5} {$WorkingDirectory}/{$script} --schedule-id={$ligne["ID"]} >/dev/null 2>&1";
            continue;
        }
        if (trim($ligne["TimeText"] == "0 0,3,5,7,9,11,13,15,17,19,23 * * *")) {
            $f[] = "@{$finalsettings},mail(false) 3h {$php5} {$WorkingDirectory}/{$script} --schedule-id={$ligne["ID"]} >/dev/null 2>&1";
            continue;
        }
        if (trim($ligne["TimeText"] == "0 2,4,6,8,10,12,14,16,18,20,22 * * *")) {
            $f[] = "@{$finalsettings},mail(false) 2h {$php5} {$WorkingDirectory}/{$script} --schedule-id={$ligne["ID"]} >/dev/null 2>&1";
            continue;
        }
        if (trim($ligne["TimeText"] == "0 0,2,4,6,8,10,12,14,16,18,20,22 * * *")) {
            $f[] = "@{$finalsettings},mail(false) 2h {$php5} {$WorkingDirectory}/{$script} --schedule-id={$ligne["ID"]} >/dev/null 2>&1";
            continue;
        }
        $f[] = "&{$finalsettings},mail(false) {$ligne["TimeText"]} {$php5} {$WorkingDirectory}/{$script} --schedule-id={$ligne["ID"]} >/dev/null 2>&1";
    }
    @file_put_contents("/etc/artica-postfix/squid.schedules", implode("\n", $f));
    if ($notfcron) {
        echo "Starting......: " . date("H:i:s") . " Squid {$c} scheduled tasks ({$d} disabled)\n";
        return;
    }
    $cron_path = $unix->find_program("cron");
    $kill = $unix->find_program("kill");
    $cron_pid = null;
    if (is_file("/var/run/cron.pid")) {
        $cron_pid = $unix->get_pid_from_file("/var/run/cron.pid");
    }
    if (!$unix->process_exists($cron_pid)) {
        $cron_pid = 0;
    }
    if (!is_numeric($cron_pid) or $cron_pid < 5) {
        $cron_pid = $unix->PIDOF("{$cron_path}");
    }
    if ($cron_pid > 5) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Starting......: " . date("H:i:s") . " artica-postfix reloading {$cron_path} [{$cron_pid}]...\n";
        }
        unix_system_HUP("{$cron_pid}");
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Starting......: " . date("H:i:s") . " artica-postfix reloading fcron...\n";
    }
    $nohup = $unix->find_program("nohup");
    shell_exec("{$nohup} /etc/init.d/artica-postfix restart fcron >/dev/null 2>&1 &");
    shell_exec("/etc/init.d/cron reload");
}
예제 #10
0
function reload_dnsmasq()
{
    $sock = new sockets();
    $EnableDNSMASQ = $sock->GET_INFO("EnableDNSMASQ");
    if (!is_numeric($EnableDNSMASQ)) {
        $EnableDNSMASQ = 0;
    }
    if ($EnableDNSMASQ == 0) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} unable to reload DnsMASQ (not enabled)\n";
        return;
    }
    $unix = new unix();
    $EnableChilli = $sock->GET_INFO("EnableChilli");
    $chilli = $unix->find_program("chilli");
    if (!is_numeric($EnableChilli)) {
        $EnableChilli = 0;
    }
    if (is_file($chilli)) {
        if ($EnableChilli == 1) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} HotSpot is enabled, cannot use this instance\n";
            return;
        }
    }
    $dnsmasqbin = $unix->find_program("dnsmasq");
    if (is_file(!$dnsmasqbin)) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} unable to reload DnsMASQ (not such dsnmasq binary)\n";
        return;
    }
    $pid = $unix->PIDOF($dnsmasqbin);
    if (!is_numeric($pid)) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} unable to reload DnsMASQ (not running)\n";
        return;
    }
    echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} reloading PID:`{$pid}`\n";
    $kill = $unix->find_program("kill");
    unix_system_HUP($pid);
}
예제 #11
0
function build()
{
    $sock = new sockets();
    $EnableDKFilter = $sock->GET_INFO("EnableDkimMilter");
    $DisconnectDKFilter = $sock->GET_INFO("DisconnectDKFilter");
    if (!is_numeric($DisconnectDKFilter)) {
        $DisconnectDKFilter = 0;
    }
    if ($DisconnectDKFilter == 1) {
        return;
    }
    $conf = unserialize(base64_decode($sock->GET_INFO("DkimMilterConfig")));
    if ($EnableDKFilter == null) {
        $EnableDKFilter = 0;
    }
    if ($conf["On-BadSignature"] == null) {
        $conf["On-BadSignature"] = "accept";
    }
    if ($conf["On-NoSignature"] == null) {
        $conf["On-NoSignature"] = "accept";
    }
    if ($conf["On-DNSError"] == null) {
        $conf["On-DNSError"] = "tempfail";
    }
    if ($conf["On-InternalError"] == null) {
        $conf["On-InternalError"] = "accept";
    }
    if ($conf["On-Security"] == null) {
        $conf["On-Security"] = "tempfail";
    }
    if ($conf["On-Default"] == null) {
        $conf["On-Default"] = "accept";
    }
    if ($conf["ADSPDiscard"] == null) {
        $conf["ADSPDiscard"] = "1";
    }
    if ($conf["ADSPNoSuchDomain"] == null) {
        $conf["ADSPNoSuchDomain"] = "1";
    }
    if (trim($conf["SignOutgoing"]) == null) {
        $conf["SignOutgoing"] = "1";
    }
    if (!is_numeric($conf["X-Header"])) {
        $conf["X-Header"] = 1;
    }
    while (list($key, $value) = each($conf)) {
        if ($value == "1") {
            $conf[$key] = "yes";
        }
        if ($value == "0") {
            $conf[$key] = "no";
        }
    }
    if ($conf["SignOutgoing"] == "yes") {
        $mode = "s";
        echo "Starting......: " . date("H:i:s") . " milter-dkim sign outgoing mails\n";
    }
    if ($conf["VerifyIncoming"] == "yes") {
        $mode = $mode . "v";
        echo "Starting......: " . date("H:i:s") . " milter-dkim verify incoming mails\n";
    }
    $ldap = new clladp();
    $domains = $ldap->hash_get_all_domains();
    while (list($key, $value) = each($domains)) {
        $dd[] = $key;
    }
    echo "Starting......: " . date("H:i:s") . " milter-dkim " . count($dd) . " local domains\n";
    $Domain = @implode(",", $dd);
    $f[] = "ADSPDiscard\t\t\t{$conf["ADSPDiscard"]}";
    $f[] = "ADSPNoSuchDomain\t\t{$conf["ADSPNoSuchDomain"]}";
    $f[] = "AllowSHA1Only\t\t\tno";
    $f[] = "AlwaysAddARHeader\t\tno";
    $f[] = "AutoRestart\t\t\tyes";
    $f[] = "AutoRestartCount\t\t2";
    $f[] = "AutoRestartRate\t\t10/1h";
    $f[] = "Background\t\t\tYes";
    $f[] = "BaseDirectory\t\t\t/var/run/dkim-filter";
    $f[] = "BodyLengths\t\t\tNo";
    $f[] = "Canonicalization\t\tsimple/simple";
    $f[] = "ClockDrift\t\t\t300 ";
    $f[] = "Diagnostics\t\t\tyes";
    $f[] = "DNSTimeout\t\t\t10";
    $f[] = "Domain\t\t\t\t{$Domain}";
    $f[] = "EnableCoredumps\t\tno";
    $f[] = "ExternalIgnoreList\t/etc/mail/dkim/trusted-hosts";
    $f[] = "FixCRLF \t\t\t\tno";
    $f[] = "InternalHosts\t\t\t/etc/mail/dkim/internal-hosts";
    $f[] = "KeepTemporaryFiles\tno";
    $f[] = "KeyList \t\t\t\t/etc/mail/dkim/keylist";
    $f[] = "LogWhy\t\t\t\tyes";
    $f[] = "MilterDebug\t\t\t0";
    $f[] = "Mode\t\t\t\t\t{$mode}";
    $f[] = "On-Default         \t{$conf["On-Default"]}";
    $f[] = "On-BadSignature    \t{$conf["On-BadSignature"]}";
    $f[] = "On-DNSError        \t{$conf["On-DNSError"]}";
    $f[] = "On-InternalError   \t{$conf["On-InternalError"]}";
    $f[] = "On-NoSignature     \t{$conf["On-NoSignature"]}";
    $f[] = "On-Security        \t{$conf["On-Security"]}";
    $f[] = "PeerList\t\t\t\t/etc/mail/dkim/trusted-hosts";
    $f[] = "PidFile\t\t\t\t/var/run/dkim-milter/dkim-milter.pid";
    $f[] = "Quarantine\t\t\tNo";
    $f[] = "#QueryCache\t\t\tyes";
    $f[] = "RemoveARAll\t\t\tNo";
    $f[] = "RemoveOldSignatures\tNo";
    $f[] = "ReportAddress\t\t\tpostmaster@example.com";
    $f[] = "RequiredHeaders\t\tNo";
    $f[] = "Selector\t\t\t\tdefault";
    $f[] = "SendADSPReports\t\tNo";
    $f[] = "SendReports\t\t\tNo";
    $f[] = "SignatureAlgorithm\trsa-sha256";
    $f[] = "SignatureTTL\t\t\t0";
    $f[] = "Socket\t\t\t\tlocal:/var/run/dkim-milter/dkim-milter.sock";
    $f[] = "StrictTestMode\t\tno";
    $f[] = "Syslog\t\t\t\tyes";
    $f[] = "SyslogFacility\t\tmail";
    $f[] = "SyslogSuccess\t\t\tyes";
    $f[] = "TemporaryDirectory\t/var/tmp";
    $f[] = "UMask\t\t\t\t\t022";
    $f[] = "UserID\t\t\t\tpostfix";
    $f[] = "X-Header\t\t\t\t{$conf["X-Header"]}";
    $f[] = "";
    /*
    *        KeyList (string)
    Gives the location of  a  file  listing  rules  for signing with mul‐tiple   keys.    If  present, overrides any KeyFile
    setting in the conifguration file.  The  file  named  here  should contain a set of lines of  the form
    sender‐pattern:signing‐domain:keypath where sender‐pattern is  a  pattern  to   match   against message  senders
    (with   the  special  character  "*" interpreted as "zero or more characters"), signing‐domain is the domain to   announce  as  
    the signing   domain   when  generating signatures, and keypath is the path to the PEM‐formatted private key to  be   used for  signing messages  which  match the sender‐pattern.
    The selector used in the signature  will  be  the  filename  portion  of keypath.   
    If  the file  referenced  by  keypath cannot be opened, the
    filter will try again by appending ".pem" and then  ".private"  before giving  up
    */
    //http://www.howtoforge.com/set-up-dkim-for-multiple-domains-on-postfix-with-dkim-milter-2.8.x-centos-5.3
    @mkdir("/etc/dkim-milter", null, true);
    @file_put_contents("/etc/dkim-milter/dkim-milter.conf", @implode("\n", $f));
    keyTable();
    WhitelistDomains();
    WhitelistHosts();
    MyNetworks();
    echo "Starting......: " . date("H:i:s") . " milter-dkim Apply permissions...\n";
    shell_exec("/bin/chmod 755 /etc/mail/dkim >/dev/null 2>&1");
    shell_exec("/bin/chmod 0770 /etc/mail/dkim/keys >/dev/null 2>&1");
    shell_exec("/bin/chmod 0770 /etc/mail/dkim/keys/* >/dev/null 2>&1");
    shell_exec("/bin/chmod 0770 /etc/mail/dkim/keys/*/* >/dev/null 2>&1");
    shell_exec("/bin/chown -R postfix:postfix /etc/mail/dkim >/dev/null 2>&1");
    echo "Starting......: " . date("H:i:s") . " milter-dkim Apply permissions done...\n";
    if ($GLOBALS["RELOAD"]) {
        $unix = new unix();
        $pid = $unix->get_pid_from_file("/var/run/dkim-milter/dkim-milter.pid");
        echo "Starting......: " . date("H:i:s") . " milter-dkim reloading current PID={$pid}\n";
        if ($unix->process_exists($pid)) {
            $kill = $unix->find_program("kill");
            echo "Starting......: " . date("H:i:s") . " milter-dkim reloading PID {$pid}\n";
            unix_system_HUP($pid);
        }
    }
}
예제 #12
0
function reload()
{
    $unix = new unix();
    $smbcontrol = $unix->find_program("smbcontrol");
    if (is_file($smbcontrol)) {
        shell_exec("{$smbcontrol} smbd reload-config");
        shell_exec("{$smbcontrol} winbindd reload-config");
        shell_exec("{$smbcontrol} nmbd reload-config");
        return;
    }
    $pidof = $unix->find_program("pidof");
    $smbd = $unix->find_program("smbd");
    $winbindd = $unix->find_program("winbindd");
    $kill = $unix->find_program("kill");
    exec("{$pidof} {$smbd} 2>&1", $results);
    echo "Starting......: " . date("H:i:s") . " samba reloading smbd:{$smbd}...\n";
    $tbl = explode(" ", @implode(" ", $results));
    while (list($index, $pid) = each($tbl)) {
        $pid = trim($pid);
        if (!is_numeric($pid)) {
            continue;
        }
        if ($pid < 10) {
            continue;
        }
        echo "Starting......: " . date("H:i:s") . " samba reloading smbd pid: {$pid}\n";
        unix_system_HUP($pid);
    }
    $results = array();
    exec("{$pidof} winbindd 2>&1", $results);
    echo "Starting......: " . date("H:i:s") . " samba reloading winbindd:{$smbd}...\n";
    $tbl = explode(" ", @implode(" ", $results));
    while (list($index, $pid) = each($tbl)) {
        $pid = trim($pid);
        if (!is_numeric($pid)) {
            continue;
        }
        if ($pid < 10) {
            continue;
        }
        echo "Starting......: " . date("H:i:s") . " samba reloading winbindd pid: {$pid}\n";
        unix_system_HUP($pid);
    }
}
예제 #13
0
function stop($nopid = false)
{
    $users = new usersMenus();
    $unix = new unix();
    if (!$users->ETTERCAP_INSTALLED) {
        echo "ArpSpoofing.........: [STOP]: Ettercap, not installed...\n";
        return;
    }
    $kill = $unix->find_program("kill");
    if (!$nopid) {
        $me = basename(__FILE__);
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . ".pid";
        $pid = $unix->get_pid_from_file($pidfile);
        if ($unix->process_exists($pid, $me)) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            echo "ArpSpoofing.........: [START]: Ettercap, Already start instance executed PID {$pid} since {$time}Mn...\n";
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pids = GetAllPids();
    if (count($pids) == 0) {
        echo "ArpSpoofing.........: [STOP]: Ettercap, no instance in memory\n";
        return;
    }
    while (list($pid, $ruleid) = each($pids)) {
        echo "ArpSpoofing.........: [STOP]: stopping smoothly pid {$pid} for rule {$ruleid}\n";
        unix_system_HUP($pid);
        unix_system_kill($pid);
    }
    for ($i = 0; $i < 10; $i++) {
        $pids = GetAllPids();
        while (list($pid, $ruleid) = each($pids)) {
            if (!$unix->process_exists($pid)) {
                echo "ArpSpoofing.........: [STOP]: pid {$pid} for rule {$ruleid} stopped...\n";
                unset($pids[$pid]);
                continue;
            }
            echo "ArpSpoofing.........: [STOP]: pid {$pid} for rule {$ruleid} still alive...\n";
        }
        if (count($pids) == 0) {
            break;
        }
        sleep(1);
    }
    $pids = GetAllPids();
    if (count($pids) > 0) {
        reset($pids);
        while (list($pid, $ruleid) = each($pids)) {
            echo "ArpSpoofing.........: [STOP]: pid {$pid} for rule {$ruleid} force stopping...\n";
            unix_system_kill_force($pid);
        }
    }
    $pids = GetAllPids();
    if (count($pids) > 0) {
        reset($pids);
        while (list($pid, $ruleid) = each($pids)) {
            echo "ArpSpoofing.........: [STOP]: pid {$pid} for rule {$ruleid} failed stopping...\n";
        }
    }
    echo "ArpSpoofing.........: [STOP]: DONE...\n";
}
예제 #14
0
function reload($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("clamd");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, clamd 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();
    $kill = $unix->find_program("kill");
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service reloading PID {$pid} running since {$timepid}Mn...\n";
        }
        unix_system_HUP($pid);
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} not running\n";
    }
}
예제 #15
0
function reload()
{
    $unix = new unix();
    $kill = $unix->find_program("kill");
    $tb = explode("\n", @file_get_contents("/var/run/fetchmail.pid"));
    $isrun = false;
    while (list($i, $pid) = each($tb)) {
        if (trim($pid) == null) {
            continue;
        }
        if (!preg_match("#([0-9]+)#", $pid, $re)) {
            continue;
        }
        $pid = $re[1];
        if (!$unix->process_exists($pid)) {
            continue;
        }
        $isrun = true;
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} reload pid {$pid}\n";
        unix_system_HUP($pid);
    }
    if (!$isrun) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} is not running, start it\n";
        start(true);
    }
}
예제 #16
0
function build($OnlySingle = false)
{
    if (isset($GLOBALS[__FILE__ . __FUNCTION__])) {
        return;
    }
    $GLOBALS[__FILE__ . __FUNCTION__] = true;
    $unix = new unix();
    $php5 = $unix->LOCATE_PHP5_BIN();
    shell_exec("/etc/init.d/mysql start");
    build_progress("{building_main_settings}", 10);
    if ($unix->SQUID_GET_LISTEN_PORT() == 80) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Squid listen 80, ports conflicts, change it\n";
        }
        shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Restarting Squid-cache..\n";
        }
        shell_exec("/etc/init.d/squid restart --script=" . basename(__FILE__));
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: done...\n";
        }
    }
    if ($unix->SQUID_GET_LISTEN_SSL_PORT() == 443) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Squid listen 443, ports conflicts, change it\n";
        }
        shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --build --force");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Restarting Squid-cache..\n";
        }
        shell_exec("/etc/init.d/squid restart --script=" . basename(__FILE__));
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: done...\n";
        }
    }
    $reconfigured = false;
    if ($unix->APACHE_GET_LISTEN_PORT() == 80) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Apache listen 80, ports conflicts, change it\n";
        }
        shell_exec("{$php5} /usr/share/artica-postfix/exec.freeweb.php --build --force");
        shell_exec("{$php5} /usr/share/artica-postfix/exec.freeweb.php --stop --force");
        shell_exec("{$php5} /usr/share/artica-postfix/exec.freeweb.php --start --force");
        $reconfigured = true;
    }
    if (!$reconfigured) {
        if ($unix->APACHE_GET_LISTEN_PORT() == 443) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Apache listen 443, ports conflicts, change it\n";
            }
            shell_exec("{$php5} /usr/share/artica-postfix/exec.freeweb.php --build --force");
        }
    }
    $APACHE_USER = $unix->APACHE_SRC_ACCOUNT();
    $APACHE_SRC_GROUP = $unix->APACHE_SRC_GROUP();
    $NginxProxyStorePath = "/home/nginx";
    @mkdir("/etc/nginx/sites-enabled", 0755, true);
    @mkdir("/etc/nginx/local-sites", 0755, true);
    @mkdir("/etc/nginx/local-sslsites", 0755, true);
    @mkdir($NginxProxyStorePath, 0755, true);
    @mkdir($NginxProxyStorePath . "/tmp", 0755, true);
    @mkdir($NginxProxyStorePath . "/disk", 0755, true);
    @mkdir("/var/lib/nginx/fastcgi", 0755, true);
    @mkdir("/home/nginx/tmp", 0755, true);
    $Tempdir = $unix->TEMP_DIR() . "/nginx";
    @mkdir($Tempdir, 0755, true);
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, $NginxProxyStorePath);
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, "/etc/nginx/sites-enabled");
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, $NginxProxyStorePath . "/tmp");
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, $NginxProxyStorePath . "/disk");
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, "/var/lib/nginx/fastcgi");
    $unix->chown_func($APACHE_USER, $APACHE_SRC_GROUP, $Tempdir);
    nginx_ulimit();
    $workers = $unix->CPU_NUMBER();
    build_progress("Building configuration", 15);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Running {$APACHE_USER}:{$APACHE_SRC_GROUP}..\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Running {$workers} worker(s)..\n";
    }
    if (is_file("/etc/nginx/sites-enabled/default")) {
        @unlink("/etc/nginx/sites-enabled/default");
    }
    if (is_link("/etc/nginx/sites-enabled/default")) {
        @unlink("/etc/nginx/sites-enabled/default");
    }
    if (is_link("/etc/nginx/conf.d/example_ssl.conf")) {
        @unlink("/etc/nginx/conf.d/example_ssl.conf");
    }
    $limit = 4096 * $workers;
    if ($limit > 65535) {
        $limit = 65535;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Running limit of {$limit} open files\n";
    }
    $L = explode("\n", @file_get_contents("/etc/security/limits.conf"));
    $FOUNDL = false;
    $T = array();
    while (list($index, $line) = each($L)) {
        $line = trim($line);
        if (trim($line) == null) {
            continue;
        }
        if (substr($line, 0, 1) == "#") {
            continue;
        }
        if (preg_match("#^{$APACHE_USER}#", $line)) {
            continue;
        }
        $T[] = $line;
    }
    if (!$FOUNDL) {
        $T[] = "{$APACHE_USER}       soft    nofile   {$limit}";
        $T[] = "{$APACHE_USER}       hard    nofile   {$limit}";
    }
    @file_put_contents("/etc/security/limits.conf", @implode("\n", $T) . "\n");
    $L = array();
    $T = array();
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    $server_names_hash_bucket_size = 128;
    $worker_connections = 8192;
    if ($MEMORY < 624288) {
        $server_names_hash_bucket_size = 64;
        $worker_connections = 1024;
        $workers = 4;
    }
    $mail_protocols = mail_protocols();
    //
    $f[] = "# Builded on " . date("Y-m-d H:i:s");
    $f[] = "user   {$APACHE_USER};";
    $f[] = "worker_processes  {$workers};";
    $nginx_version = nginx_version();
    preg_match("#^([0-9])+\\.([0-9]+)\\.#", $nginx_version, $re);
    $re[1] = intval($re[1]);
    $re[2] = intval($re[2]);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Major {$re[1]} Minor:{$re[2]}\n";
    }
    $syslog = false;
    $f[] = "worker_rlimit_nofile 16384;";
    $f[] = "timer_resolution 1ms;";
    $f[] = "";
    if ($re[1] > 0) {
        if ($re[2] > 6) {
            $f[] = "error_log syslog:server=127.0.0.1,facility=daemon info;";
            $syslog = true;
        }
    }
    $syslog = false;
    if (!$syslog) {
        $f[] = "error_log  /var/log/nginx/error.log warn;";
    }
    $f[] = "pid        /var/run/nginx.pid;";
    $f[] = "";
    $f[] = "";
    $f[] = "events {";
    $f[] = "    worker_connections  {$worker_connections};";
    $f[] = "    multi_accept  on;";
    $f[] = "    use epoll;";
    $f[] = "\t  accept_mutex_delay 1ms;";
    $f[] = "}";
    $upstream = new nginx_upstream();
    $upstreams_servers = $upstream->build();
    $f[] = "";
    $f[] = "";
    $f[] = "http {";
    $f[] = "\tinclude /etc/nginx/mime.types;";
    $f[] = "\tlog_format  awc_log";
    $f[] = "\t\t'[\$server_name] \$remote_addr - \$remote_user [\$time_local] \$request '";
    $f[] = "\t\t'\"\$status\" \$body_bytes_sent \"\$http_referer\" '";
    $f[] = "\t\t'\"\$http_user_agent\" \"\$http_x_forwarded_for\" [\$upstream_cache_status]';";
    $f[] = "";
    $f[] = "\tlimit_conn_zone \$binary_remote_addr zone=LimitCnx:10m;";
    $q = new mysql_squid_builder();
    $results = $q->QUERY_SQL("SELECT LimitReqs,servername FROM reverse_www WHERE LimitReqs > 0");
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $servername = $ligne["servername"];
        $ZoneName = str_replace(".", "", $servername);
        $ZoneName = str_replace("-", "", $servername);
        $ZoneName = str_replace("_", "", $servername);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, limit {$servername}/{$servername} {$ligne["LimitReqs"]}r/s\n";
        }
        $f[] = "\tlimit_req_zone  \$binary_remote_addr  zone={$ZoneName}:10m   rate={$ligne["LimitReqs"]}r/s;";
    }
    $nginxClass = new nginx();
    if ($nginxClass->IsSubstitutions()) {
        //$f[]="\tsubs_filter_types text/html text/css text/xml;";
    }
    @mkdir($Tempdir, 0775, true);
    @mkdir("/home/nginx/tmp", 0755, true);
    $f[] = "\tlimit_conn_log_level info;";
    $f[] = "\tclient_body_temp_path {$Tempdir} 1 2;";
    $f[] = "\tclient_header_timeout 5s;";
    $f[] = "\tclient_body_timeout 5s;";
    $f[] = "\tsend_timeout 10m;";
    $f[] = "\tconnection_pool_size 128k;";
    $f[] = "\tclient_header_buffer_size 16k;";
    $f[] = "\tlarge_client_header_buffers 1024 128k;";
    $f[] = "\trequest_pool_size 128k;";
    $f[] = "\tkeepalive_requests 1000;";
    $f[] = "\tkeepalive_timeout 10;";
    $f[] = "\tclient_max_body_size 10g;";
    $f[] = "\tclient_body_buffer_size 1m;";
    $f[] = "\tclient_body_in_single_buffer on;";
    $f[] = "\topen_file_cache max=10000 inactive=300s;";
    $f[] = "\treset_timedout_connection on;";
    $f[] = "\ttypes_hash_max_size 8192;";
    $f[] = "\tserver_names_hash_bucket_size 128;";
    $f[] = "\tserver_names_hash_max_size 512;";
    $f[] = "\tvariables_hash_max_size 512;";
    $f[] = "\tvariables_hash_bucket_size 128;";
    $f[] = "\tfastcgi_buffers 8 16k;";
    $f[] = "\tfastcgi_buffer_size 32k;";
    $f[] = "\tfastcgi_connect_timeout 300;";
    $f[] = "\tfastcgi_send_timeout 300;";
    $f[] = "\tfastcgi_read_timeout 300;";
    $f[] = "map \$scheme \$server_https {";
    $f[] = "default off;";
    $f[] = "https on;";
    $f[] = "}\t";
    $f[] = "\tgzip on;";
    $f[] = "\tgzip_disable msie6;";
    $f[] = "\tgzip_static on;";
    $f[] = "\tgzip_min_length 1100;";
    $f[] = "\tgzip_buffers 16 8k;";
    $f[] = "\tgzip_comp_level 9;";
    $f[] = "\tgzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;";
    $f[] = "\tgzip_vary on;";
    $f[] = "\tgzip_proxied any;";
    $f[] = "\toutput_buffers 1000 128k;";
    $f[] = "\tpostpone_output 1460;";
    $f[] = "\tsendfile on;";
    $f[] = "\tsendfile_max_chunk 256k;";
    $f[] = "\ttcp_nopush on;";
    $f[] = "\ttcp_nodelay on;";
    $f[] = "\tserver_tokens off;";
    $dns = new resolv_conf();
    $sock = new sockets();
    if ($sock->dnsmasq_enabled()) {
        $resolver[] = "127.0.0.1";
    }
    if ($dns->MainArray["DNS1"] != null) {
        $resolver[] = $dns->MainArray["DNS1"];
    }
    if ($dns->MainArray["DNS2"] != null) {
        $resolver[] = $dns->MainArray["DNS2"];
    }
    if ($dns->MainArray["DNS3"] != null) {
        $resolver[] = $dns->MainArray["DNS3"];
    }
    $f[] = "\tresolver " . @implode(" ", $resolver) . ";";
    $f[] = "\tignore_invalid_headers on;";
    $f[] = "\tindex index.html;";
    $f[] = "\tadd_header X-CDN \"Served by myself\";";
    $q = new mysql_squid_builder();
    $sql = "SELECT * FROM nginx_caches  ORDER BY directory";
    $results = $q->QUERY_SQL($sql);
    while ($ligne = mysql_fetch_array($results, MYSQL_ASSOC)) {
        $directory = $ligne["directory"];
        @mkdir($directory, 0755, true);
        $unix->chown_func("www-data", "www-data", $directory);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, cache `{$directory}`\n";
        }
        $f[] = "\tproxy_cache_path {$directory} levels={$ligne["levels"]} keys_zone={$ligne["keys_zone"]}:{$ligne["keys_zone_size"]}m max_size={$ligne["max_size"]}G  inactive={$ligne["inactive"]} loader_files={$ligne["loader_files"]} loader_sleep={$ligne["loader_sleep"]} loader_threshold={$ligne["loader_threshold"]};";
    }
    $f[] = "\tproxy_temp_path {$NginxProxyStorePath}/tmp/ 1 2;";
    $f[] = "\tproxy_cache_valid 404 10m;";
    $f[] = "\tproxy_cache_valid 400 501 502 503 504 1m;";
    $f[] = "\tproxy_cache_valid any 4320m;";
    $f[] = "\tproxy_cache_use_stale updating invalid_header error timeout http_404 http_500 http_502 http_503 http_504;";
    $f[] = "\tproxy_next_upstream error timeout invalid_header http_404 http_500 http_502 http_503 http_504;";
    $f[] = "\tproxy_redirect off;";
    $f[] = "\tproxy_set_header Host \$http_host;";
    $f[] = "\tproxy_set_header Server Apache;";
    $f[] = "\tproxy_set_header Connection Close;";
    $f[] = "\tproxy_pass_header Set-Cookie;";
    $f[] = "\tproxy_pass_header User-Agent;";
    $f[] = "\tproxy_set_header X-Accel-Buffering on;";
    $f[] = "\tproxy_hide_header X-CDN;";
    $f[] = "\tproxy_hide_header X-Server;";
    $f[] = "\tproxy_intercept_errors off;";
    $f[] = "\tproxy_ignore_client_abort on;";
    $f[] = "\tproxy_connect_timeout 60s;";
    $f[] = "\tproxy_send_timeout 60s;";
    $f[] = "\tproxy_read_timeout 150s;";
    $f[] = "\tproxy_buffer_size 64k;";
    $f[] = "\tproxy_buffers 16384 128k;";
    $f[] = "\tproxy_busy_buffers_size 256k;";
    $f[] = "\tproxy_temp_file_write_size 128k;";
    $f[] = "\tproxy_headers_hash_bucket_size 128;";
    $f[] = "\tproxy_cache_min_uses 0;";
    $f[] = "";
    $f[] = "{$upstreams_servers}";
    $f[] = "\tinclude /etc/nginx/sites-enabled/*.conf;";
    $f[] = "\tinclude /etc/nginx/local-sites/*.conf;";
    $f[] = "\tinclude /etc/nginx/conf.d/*.conf;";
    $f[] = "\t}";
    $f[] = $mail_protocols;
    $f[] = "";
    @copy("/etc/nginx/nginx.conf", "/etc/nginx/nginx.bak");
    @file_put_contents("/etc/nginx/nginx.conf", @implode("\n", $f));
    if (!$OnlySingle) {
        if ($GLOBALS["VERBOSE"]) {
            echo __FUNCTION__ . "." . __LINE__ . ": OK...\n";
        }
        build_progress("Building default configuration", 10);
        build_default(true);
        build_localhosts();
        if ($GLOBALS["VERBOSE"]) {
            echo __FUNCTION__ . "." . __LINE__ . ": OK...\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Only single defined\n";
        }
    }
    if ($GLOBALS["RECONFIGURE"]) {
        $pid = PID_NUM();
        if (is_numeric($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, reload pid {$pid}\n";
            }
            $kill = $unix->find_program("kill");
            unix_system_HUP($pid);
        } else {
            start(true);
        }
    }
    build_progress("Building configuration done", 10);
}
예제 #17
0
function reload()
{
    $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__))) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    $pid = FPM_PID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: PHP-FPM: Service Stopped...\n";
        }
        start(true);
        return;
    }
    $kill = $unix->find_program("kill");
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: PHP-FPM: Reloading PID {$pid}...\n";
    }
    unix_system_HUP($pid);
}