function squid_reconfigure_exe()
{
    $unix = new unix();
    $squidbin = $unix->LOCATE_SQUID_BIN();
    build_progress("Reloading Proxy service...", 10);
    $pid = SQUID_PID();
    if ($unix->process_exists($pid)) {
        build_progress("Reloading Proxy service...", 50);
        system("/etc/init.d/squid reload --force --script=exec.squid.reconfigure.php/" . __LINE__);
        sleep(2);
        $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__));
        }
        build_progress("Reloading Proxy service...{done}", 100);
        return;
    }
    echo "Not running !\n";
    build_progress("Reloading Proxy service {failed}...", 110);
}
function check_status()
{
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    build_progress_status2("{checking_proxy_service}", 20);
    sleep(1);
    $pid = SQUID_PID();
    echo "PID: {$pid}\n";
    if ($unix->process_exists($pid)) {
        $ttl = $unix->PROCCESS_TIME_MIN($pid);
        build_progress_status2("{APP_SQUID}: {running} {since} {$ttl}Mn", 30);
        echo "Running since {$ttl}Mn\n";
    } else {
        build_progress_status2("{APP_SQUID}: {starting_service}", 30);
        start_squid(true);
    }
    $pid = SQUID_PID();
    echo "PID: {$pid}\n";
    if (!$unix->process_exists($pid)) {
        build_progress_status2("{APP_SQUID}: {failed}", 110);
    }
    $GLOBALS["FORCE"] = true;
    build_progress_status2("{APP_SQUID}: {remove_cached_datas}", 50);
    sleep(1);
    echo "Remove ALL_SQUID_STATUS\n";
    @unlink("/usr/share/artica-postfix/ressources/logs/web/squid.status.html");
    @unlink("/usr/share/artica-postfix/ressources/logs/web/status.right.image.cache");
    @unlink("/usr/share/artica-postfix/ressources/databases/ALL_SQUID_STATUS");
    $cmd = "{$php} /usr/share/artica-postfix/exec.status.php --all-squid --nowachdog >/usr/share/artica-postfix/ressources/databases/ALL_SQUID_STATUS 2>&1";
    echo "{$cmd}\n";
    shell_exec($cmd);
    build_progress_status2("{APP_SQUID}: {checking_caches}", 55);
    sleep(1);
    CheckGlobalInfos();
    build_progress_status2("{APP_SQUID}: {checking_caches}", 60);
    sleep(1);
    CheckStoreDirs(true);
    build_progress_status2("{APP_SQUID}: {checking_caches}", 61);
    sleep(1);
    BuilRequestsStats();
    build_progress_status2("{APP_SQUID}: {checking_caches}", 62);
    counters(true);
    sleep(1);
    build_progress_status2("{APP_SQUID}: {checking_caches}", 63);
    ALLKIDS(true);
    sleep(1);
    build_progress_status2("{APP_SQUID}: {checking_caches}", 64);
    sleep(1);
    build_progress_status2("{APP_SQUID}: {checking_caches}", 70);
    sleep(1);
    system("{$php} /usr/share/artica-postfix/exec.cache.pages.php --force");
    build_progress_status2("{APP_SQUID}: {done}", 100);
    sleep(1);
}
Exemple #3
0
function caches_infos($aspid = false)
{
    $cacheFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".time";
    $cachePID = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if ($GLOBALS["FORCE"]) {
        ToSyslog("caches_infos(): Executed in force mode");
    }
    $unix = new unix();
    $sock = new sockets();
    if (!$GLOBALS["VERBOSE"]) {
        if (system_is_overloaded(basename(__FILE__))) {
            EventsWatchdog("Overloaded system, aborting task...");
            ToSyslog("caches_infos(): Overloaded system, aborting task");
            writelogs("Overloaded system, aborting task...", __FUNCTION__, __FILE__, __LINE__);
            return;
        }
        if ($aspid) {
            $pid = @file_get_contents($cachePID);
            if ($unix->process_exists($pid)) {
                $timepid = $unix->PROCCESS_TIME_MIN($pid);
                if ($timepid < 15) {
                    ToSyslog("caches_infos(): Already task PID: {$pid} running since {$timepid}Mn");
                }
                $kill = $unix->find_program("{$kill}");
                unix_system_kill_force($pid);
            }
        }
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "init...\n";
    }
    $q = new mysql_squid_builder();
    if (!$GLOBALS["FORCE"]) {
        $CacheTime = $unix->file_time_min($cacheFile);
        if ($CacheTime < 15) {
            EventsWatchdog("Max 15Mn, current={$CacheTime} ({$cacheFile})...");
            if ($GLOBALS["VERBOSE"]) {
                echo "Max 15Mn, current={$CacheTime}\n";
            }
            return;
        }
    }
    $squid_pid = SQUID_PID();
    if (!$unix->process_exists($squid_pid)) {
        $nohup = $unix->find_program("nohup");
        squid_admin_mysql(0, "Squid-Cache is not running..., start it", null, __FILE__, __LINE__);
        ToSyslog("caches_infos(): Squid-Cache is not running..., start it");
        shell_exec("{$nohup} /etc/init.d/squid start >/dev/null 2>&1 &");
        return;
    }
    @unlink($cacheFile);
    @file_put_contents($cacheFile, time());
    $ttl = $unix->PROCCESS_TIME_MIN($squid_pid);
    if ($unix->PROCCESS_TIME_MIN($squid_pid) < 5) {
        ToSyslog("caches_infos(): squid-cache running only since {$ttl}mn, aborting");
        return;
    }
    ToSyslog("caches_infos(): Starting get Squid-cache informations.");
    $array = $unix->squid_get_cache_infos();
    for ($i = 0; $i < 10; $i++) {
        $check = true;
        if (!is_array($array)) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unix->squid_get_cache_infos() Not an array...\n";
            }
            $check = false;
            sleep(1);
            $array = $unix->squid_get_cache_infos();
            continue;
        }
        if (count($array) == 0) {
            if ($GLOBALS["VERBOSE"]) {
                echo "unix->squid_get_cache_infos() O items !!\n";
            }
            $check = false;
            sleep(1);
            $array = $unix->squid_get_cache_infos();
            continue;
        }
        if ($check) {
            break;
        }
    }
    if (!is_array($array)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "unix->squid_get_cache_infos() Not an array...\n";
        }
        return;
    }
    if (count($array) == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo basename(__FILE__) . "[" . __LINE__ . "] unix->squid_get_cache_infos() O items !!...\n";
        }
        @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", serialize($array));
        @chmod("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", 0755);
        return;
    }
    @unlink("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db");
    @file_put_contents("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", serialize($array));
    @chmod("/usr/share/artica-postfix/ressources/logs/web/squid_get_cache_infos.db", 0755);
    $uuid = $unix->GetUniqueID();
    $profix = "INSERT IGNORE INTO cachestatus(uuid,cachedir,maxsize,currentsize,pourc) VALUES ";
    while (list($directory, $arrayDir) = each($array)) {
        $directory = trim($directory);
        if ($directory == null) {
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "('{$uuid}','{$directory}','{$arrayDir["MAX"]}','{$arrayDir["CURRENT"]}','{$arrayDir["POURC"]}')\n";
        }
        $f[] = "('{$uuid}','{$directory}','{$arrayDir["MAX"]}','{$arrayDir["CURRENT"]}','{$arrayDir["POURC"]}')";
    }
    if (count($f) > 0) {
        $q->QUERY_SQL("DELETE FROM cachestatus WHERE uuid='{$uuid}'");
        $q->QUERY_SQL("{$profix}" . @implode(",", $f));
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
        }
    }
}