function reload_squid($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    $TimeFile = "/etc/artica-postfix/pids/reloadsquid.time";
    $PidFile = "/etc/artica-postfix/pids/reloadsquid.pid";
    if (!is_file($squidbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Reloading.......: Squid-cache, not installed\n";
        }
        shell_exec("/etc/init.d/dnsmasq restart");
        return;
    }
    if (!$aspid) {
        $pid = $unix->get_pid_from_file($PidFile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $TimeMin = $unix->PROCCESS_TIME_MIN($pid);
            squid_admin_mysql(1, "Reload::{$GLOBALS["BY_OTHER_SCRIPT"]} Already task running PID {$pid} since {$TimeMin}mn", null, __FILE__, __LINE__);
            build_progress_reload("Already task running PID {$pid} since {$TimeMin}mn", 100);
            return;
        }
    }
    @file_put_contents($PidFile, getmypid());
    $SquidCacheReloadTTL = $sock->GET_INFO("SquidCacheReloadTTL");
    if (!is_numeric($SquidCacheReloadTTL)) {
        $SquidCacheReloadTTL = 10;
    }
    $pid = SQUID_PID();
    if (!$unix->process_exists($pid)) {
        start_squid(true);
        return;
    }
    $TimeMin = $unix->PROCCESS_TIME_MIN($pid);
    $php5 = $unix->LOCATE_PHP5_BIN();
    echo "Reloading.......: " . date("H:i:s") . " Building mime type..\n";
    shell_exec("{$php5} /usr/share/artica-postfix/exec.squid.php --mime");
    if ($GLOBALS["FORCE"]) {
        squid_admin_mysql(1, "Reload::{$GLOBALS["BY_OTHER_SCRIPT"]} Reloading + FORCE", null, __FILE__, __LINE__);
        echo "Reloading.....: " . date("H:i:s") . " Squid-cache, Force enabled...\n";
    }
    if (!$GLOBALS["FORCE"]) {
        if ($TimeMin < $SquidCacheReloadTTL) {
            squid_admin_mysql(1, "Reload::{$GLOBALS["BY_OTHER_SCRIPT"]} Aborted need at least {$SquidCacheReloadTTL}mn", null, __FILE__, __LINE__);
            build_progress_reload("Aborted need at least {$SquidCacheReloadTTL}mn", 100);
            echo "Reloading.......: " . date("H:i:s") . " Squid-cache, Reload squid PID {$pid} aborted, need at least {$SquidCacheReloadTTL}mn current {$TimeMin}mn\n";
            return;
        }
    }
    @unlink($TimeFile);
    @file_put_contents($TimeFile, time());
    $suffix = get_action_script_source();
    build_progress_reload("Reloading PID {$pid}", 10);
    echo "Reloading.....: " . date("H:i:s") . " Reloading proxy service PID:{$pid} running since {$TimeMin}Mn {$suffix}...\n";
    squid_admin_mysql(2, "Reloading squid service by [{$GLOBALS["BY_OTHER_SCRIPT"]}] PID:{$pid} running since {$TimeMin}Mn {$suffix}", null, __FILE__, __LINE__);
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $chmod = $unix->find_program("chmod");
    $pgrep = $unix->find_program("pgrep");
    $kill = $unix->find_program("kill");
    $executed = null;
    $EnableTransparent27 = intval($sock->GET_INFO("EnableTransparent27"));
    $SystemInfoCache = "/etc/squid3/squid_get_system_info.db";
    $TimeMin = $unix->file_time_min($TimeFile);
    $EnableWebProxyStatsAppliance = $sock->GET_INFO("EnableWebProxyStatsAppliance");
    $EnableRemoteStatisticsAppliance = $sock->GET_INFO("EnableRemoteStatisticsAppliance");
    $EnableKerbAuth = $sock->GET_INFO("EnableKerbAuth");
    $CicapEnabled = intval($sock->GET_INFO("CicapEnabled"));
    $trace = debug_backtrace();
    if (isset($trace[1])) {
        $called = " called by " . basename($trace[1]["file"]) . " {$trace[1]["function"]}() line {$trace[1]["line"]}";
    }
    if (!is_numeric($EnableWebProxyStatsAppliance)) {
        $EnableWebProxyStatsAppliance = 0;
    }
    if (!is_numeric($EnableRemoteStatisticsAppliance)) {
        $EnableRemoteStatisticsAppliance = 0;
    }
    if (!is_numeric($EnableKerbAuth)) {
        $EnableKerbAuth = 0;
    }
    @unlink($SystemInfoCache);
    build_progress_reload("Reloading PID {$pid}", 15);
    if (!is_file("/etc/squid3/url_rewrite_program.deny.db")) {
        @file_put_contents("/etc/squid3/url_rewrite_program.deny.db", "");
    }
    $ssltrd = $unix->squid_locate_generic_bin("ssl_crtd");
    if (is_file($ssltrd)) {
        if (!is_dir("/var/lib/squid/session/ssl/ssl_db")) {
            @mkdir("/var/lib/squid/session/ssl", 0755, true);
            shell_exec("{$ssltrd} -c -s /var/lib/squid/session/ssl/ssl_db >/dev/null 2>&1");
            $unix->chown_func("squid", "squid", "/var/lib/squid/session/ssl/ssl_db/*");
        }
    }
    $GLOBALS["SQUIDBIN"] = $unix->LOCATE_SQUID_BIN();
    echo "Reloading.....: " . date("H:i:s") . " Squid-cache, Checking transparent mode..\n";
    build_progress_reload("Reloading PID {$pid}", 20);
    if (!is_file("/etc/init.d/tproxy start")) {
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.squid.transparent.php >/dev/null 2>&1 ");
    } else {
        shell_exec("{$nohup} /etc/init.d/tproxy start &");
    }
    build_progress_reload("Check files and security", 22);
    start_prepare();
    build_progress_reload("Reloading PID {$pid}", 25);
    if ($EnableTransparent27 == 1) {
        if (!is_file("/etc/init.d/squid-nat")) {
            shell_exec("{$php5} /usr/share/artica-postfix/exec.initslapd.php --squid-nat");
        }
        echo "Reloading......: " . date("H:i:s") . " Squid-cache, Reloading squid-nat\n";
        shell_exec("/etc/init.d/squid-nat reload");
    }
    build_progress_reload("Reloading PID {$pid}", 30);
    if ($CicapEnabled == 1) {
        echo "Reloading......: " . date("H:i:s") . " Squid-cache, Reloading C-ICAP service\n";
        shell_exec("{$nohup} /etc/init.d/c-icap reload >/dev/null 2>&1 ");
    }
    build_progress_reload("Reloading PID {$pid}", 35);
    if ($EnableKerbAuth == 1) {
        echo "Reloading......: " . date("H:i:s") . " Squid-cache, Checks winbind privileges\n";
        shell_exec("{$php5} /usr/share/artica-postfix/exec.winbindd.php --privs-squid");
    }
    build_progress_reload("Reloading PID {$pid}", 40);
    echo "Reloading.....: " . date("H:i:s") . " Squid-cache, Checks auth-tail\n";
    shell_exec("{$nohup} /etc/init.d/auth-tail restart >/dev/null 2>&1 &");
    if (!is_file($GLOBALS["SQUIDBIN"])) {
        build_progress_reload("Reloading PID {failed}", 100);
        return;
    }
    echo "Reloading.....: " . date("H:i:s") . " Squid-cache, With binary {$GLOBALS["SQUIDBIN"]} PID {$pid}\n";
    if (function_exists("debug_backtrace")) {
        $trace = debug_backtrace();
        if (isset($trace[1])) {
            $file = basename($trace[1]["file"]);
            $function = $trace[1]["function"];
            $line = $trace[1]["line"];
            $called = "Called by {$function}() from line {$line}";
        }
    }
    $results = array();
    build_progress_reload("Reloading PID {$pid}", 45);
    $unix->TCP_TUNE_SQUID_DEFAULT();
    echo "Reloading.....: " . date("H:i:s") . " Squid-cache, Reloading artica-status\n";
    shell_exec("{$nohup} {$php5} /etc/init.d/artica-status reload >/dev/null 2>&1 &");
    shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.clean.logs.php --squid-caches --force >/dev/null 2>&1 &");
    if ($EnableRemoteStatisticsAppliance == 1) {
        echo "Reloading.....: " . date("H:i:s") . " Squid-cache, Sends information to the Statistics Appliance...\n";
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.netagent.php >/dev/null 2>&1 &");
    }
    echo "Reloading.....: " . date("H:i:s") . " Squid-cache, Reloading DNS Cache...\n";
    shell_exec("{$nohup} /usr/share/artica-postfix/exec.dnscache.php --restart >/dev/null 2>&1 &");
    $streamsquidcache = $unix->find_program("streamsquidcache");
    if (is_file($streamsquidcache)) {
        $EnableStreamCache = intval($sock->GET_INFO("EnableStreamCache"));
        if (EnableStreamCache == 1) {
            build_progress_reload("Reloading VideoCache services", 48);
            system("{$php5} /usr/share/artica-postfix/exec.squidstream.php --reload");
        }
    }
    build_progress_reload("Wake-up loaders...", 49);
    LOGFILE_DAEMON_WAKEUP();
    sleep(2);
    build_progress_reload("Reloading Main proxy service PID {$pid}", 50);
    $sock = new sockets();
    exec("{$GLOBALS["SQUIDBIN"]} -f \"/etc/squid3/squid.conf\" -k reconfigure 2>&1", $pgrepArray);
    $sock = new sockets();
    $EnableTransparent27 = intval($sock->GET_INFO("EnableTransparent27"));
    if ($EnableTransparent27 == 1) {
        build_progress("Reloading Proxy NAT service...", 60);
        system("/etc/init.d/squid-nat reload --script=" . basename(__FILE__));
    }
    while (list($num, $ligne) = each($pgrepArray)) {
        if (preg_match("#^.*?\\|\\s+(.+)#", $ligne, $re)) {
            echo "Reloading.....: " . date("H:i:s") . " Squid-cache, {$re[1]}\n";
        }
    }
    build_progress_reload("Reloading PID {$pid}", 100);
}
Example #2
0
function Reload_only_squid()
{
    $unix = new unix();
    $results = array();
    $force = null;
    if (!is_file($GLOBALS["SQUIDBIN"])) {
        $GLOBALS["SQUIDBIN"] = $unix->find_program("squid");
        if (!is_file($GLOBALS["SQUIDBIN"])) {
            $GLOBALS["SQUIDBIN"] = $unix->find_program("squid3");
        }
    }
    if (function_exists("debug_backtrace")) {
        $trace = debug_backtrace();
        if (isset($trace[1])) {
            $file = basename($trace[1]["file"]);
            $function = $trace[1]["function"];
            $line = $trace[1]["line"];
            $called = "Called by {$function}() from line {$line}";
        }
    }
    if ($GLOBALS["FORCE"]) {
        $force = " --force";
    }
    build_progress_reload("{reloading}", 50);
    squid_watchdog_events("Reconfiguring Proxy parameters...");
    $cmd = "/etc/init.d/squid reload{$force} --script=" . basename(__FILE__) . " >/dev/null 2>&1 &";
    shell_exec($cmd);
    while (list($num, $val) = each($results)) {
        echo "Starting......: " . date("H:i:s") . " [RELOAD]: {$val}\n";
    }
    build_progress_reload("{reloading}", 70);
    $pgrep = $unix->find_program("pgrep");
    $kill = $unix->find_program("kill");
    exec("{$pgrep} -l -f \"exec.logfile_daemon.php\" 2>&1", $results2);
    while (list($num, $val) = each($results2)) {
        if (preg_match("#pgrep#", $val)) {
            continue;
        }
        if (!preg_match("#^([0-9]+)\\s+#", $val, $re)) {
            continue;
        }
        $pid = $re[1];
        $processtime = $unix->PROCCESS_TIME_MIN($pid);
        if ($processtime < 1) {
            echo "Starting......: " . date("H:i:s") . " [RELOAD]: exec.logfile_daemon.php {$pid} running since {$processtime}Mn\n";
            continue;
        }
        echo "Starting......: " . date("H:i:s") . " [RELOAD]: Kill exec.logfile_daemon.php {$pid} running since {$processtime}Mn\n";
        unix_system_kill_force($pid);
    }
    $sock = new sockets();
    $EnableTransparent27 = intval($sock->GET_INFO("EnableTransparent27"));
    if ($EnableTransparent27 == 1) {
        system("/etc/init.d/squid-nat reload --script=" . basename(__FILE__));
    }
    build_progress_reload("{done}", 100);
}