Esempio n. 1
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("ufdbgclient");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, ufdbgclient not installed\n";
        }
        return false;
    }
    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 true;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $sock = new sockets();
    $EnableUfdbGuard = $sock->EnableUfdbGuard();
    if ($EnableUfdbGuard == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Not Enabled\n";
        }
        return false;
    }
    $pids = GetAllPids();
    if (count($pids) > 0) {
        while (list($pid, $none) = each($pids)) {
            $ttl = $unix->PROCESS_TTL($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, already running PID {$pid} since {$ttl}Mn\n";
            }
        }
        return true;
    }
    if (IsInSquid()) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Hooked chock proxy\n";
        }
        shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__));
    } else {
        EnableClient();
    }
    for ($i = 1; $i < 8; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Waiting {$i}/5\n";
        }
        sleep(1);
        $pids = GetAllPids();
        if (count($pids) > 0) {
            break;
        }
    }
    $pids = GetAllPids();
    if (count($pids) > 0) {
        while (list($pid, $none) = each($pids)) {
            $ttl = $unix->PROCESS_TTL($pid);
            $fty[] = "Success PID {$pid} since {$ttl}Mn";
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid} since {$ttl}Mn\n";
            }
        }
        squid_admin_mysql(2, "Succes starting Web Filtering Client service from the proxy{$GLOBALS["ADPLUS"]}", @implode("\n", $fty), __FILE__, __LINE__);
        return true;
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Failed\n";
        }
    }
}
Esempio n. 2
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = $unix->find_program("ufdbgclient");
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, ufdbgclient not installed\n";
        }
        return false;
    }
    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 true;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $sock = new sockets();
    $EnableUfdbGuard = intval($sock->EnableUfdbGuard());
    $SquidUFDBUrgency = intval($sock->GET_INFO("SquidUFDBUrgency"));
    if ($SquidUFDBUrgency == 1) {
        $EnableUfdbGuard = 0;
    }
    if ($EnableUfdbGuard == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Not Enabled\n";
        }
        return false;
    }
    $pids = GetAllPids();
    if (count($pids) > 0) {
        while (list($pid, $none) = each($pids)) {
            $ttl = $unix->PROCESS_TTL($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, already running PID {$pid} since {$ttl}Mn\n";
            }
        }
        return true;
    }
    if (IsInSquid()) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Hooked chock proxy\n";
        }
        squid_admin_mysql(1, "Reload proxy service to run Web filtering clients.", null, __FILE__, __LINE__);
        $squidbin = $unix->LOCATE_SQUID_BIN();
        system("{$squidbin} -f /etc/squid3/squid.conf -k reconfigure");
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Not Hooked! Hook proxy\n";
        }
        EnableClient();
    }
    for ($i = 1; $i < 8; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Waiting {$i}/5\n";
        }
        sleep(1);
        $pids = GetAllPids();
        if (count($pids) > 0) {
            break;
        }
    }
    $pids = GetAllPids();
    if (count($pids) > 0) {
        while (list($pid, $none) = each($pids)) {
            $ttl = $unix->PROCESS_TTL($pid);
            $fty[] = "Success PID {$pid} since {$ttl}Mn";
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid} since {$ttl}Mn\n";
            }
        }
        squid_admin_mysql(2, "Succes {starting_web_filtering} Client service from the proxy{$GLOBALS["ADPLUS"]}", @implode("\n", $fty), __FILE__, __LINE__);
        return true;
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, Failed\n";
        }
    }
}