Exemplo n.º 1
0
function netdiscover()
{
    $Masterbin = "/usr/share/artica-postfix/bin/netdiscover";
    if (!is_file($Masterbin)) {
        $l[] = "";
        $l[] = "[APP_NETDISCOVER]";
        $l[] = "service_name=APP_NETDISCOVER";
        $l[] = "installed=0";
        $l[] = "service_disabled=0";
        $l[] = "";
        return @implode("\n", $l);
    }
    $Enable = 1;
    $DisableNetDiscover = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("DisableNetDiscover"));
    $SquidPerformance = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("SquidPerformance"));
    if ($SquidPerformance > 2) {
        $DisableNetDiscover = 1;
    }
    $DisableNetDiscover2 = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance"));
    if (!is_file("/etc/artica-postfix/settings/Daemons/NetDiscoverSaved")) {
        $DisableNetDiscover = 1;
    }
    if ($DisableNetDiscover == 1) {
        $Enable = 0;
    }
    if ($DisableNetDiscover2 == 1) {
        $Enable = 0;
    }
    $l[] = "";
    $l[] = "[APP_NETDISCOVER]";
    $l[] = "service_name=APP_NETDISCOVER";
    $l[] = "master_version=" . netdiscover_version();
    $l[] = "service_cmd=/etc/init.d/netdiscover";
    $l[] = "service_disabled={$Enable}";
    $l[] = "watchdog_features=1";
    $l[] = "installed=1";
    $l[] = "family=network";
    if ($Enable == 0) {
        $l[] = "";
        return implode("\n", $l);
        return;
    }
    $master_pid = netdiscover_pid();
    if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.netdiscover.php --start >/dev/null 2>&1 &");
        $l[] = "";
        return implode("\n", $l);
    }
    $l[] = GetMemoriesOf($master_pid);
    $l[] = "";
    $unix = new unix();
    $time = $GLOBALS["CLASS_UNIX"]->PROCCESS_TIME_MIN($master_pid);
    if ($time > 30) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.netdiscover.php --restart >/dev/null 2>&1 &");
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.netdiscover.php.stats.time");
    if ($time_file > 14) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.netdiscover.php --stats >/dev/null 2>&1 &");
    }
    return implode("\n", $l);
    return;
}
Exemplo n.º 2
0
function start($aspid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $Masterbin = "/usr/share/artica-postfix/bin/netdiscover";
    if (!is_file($Masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]}, 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());
    }
    $DisableNetDiscover = intval($sock->GET_INFO("DisableNetDiscover"));
    $DisableNetDiscover = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance"));
    if (!is_file("/etc/artica-postfix/settings/Daemons/NetDiscoverSaved")) {
        $DisableNetDiscover = 1;
    }
    $pid = PID_NUM();
    $DisableNetDiscover = intval($sock->GET_INFO("DisableNetDiscover"));
    if ($unix->process_exists($pid)) {
        $timepid = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Service already started {$pid} since {$timepid}Mn...\n";
        }
        if ($DisableNetDiscover == 1) {
            stop();
        }
        return;
    }
    $sock = new sockets();
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    if ($SquidPerformance > 2) {
        $DisableNetDiscover = 1;
    }
    if ($DisableNetDiscover == 1) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service disabled (see DisableNetDiscover)\n";
        }
        return;
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    $sysctl = $unix->find_program("sysctl");
    $echo = $unix->find_program("echo");
    $nohup = $unix->find_program("nohup");
    build(true);
    @chmod("{$Masterbin}", 0755);
    $version = netdiscover_version();
    $f[] = $nohup;
    $f[] = $Masterbin;
    $f[] = "-p -P >/etc/artica-postfix/discover.txt  2>&1 &";
    $cmd = @implode(" ", $f);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service\n";
    }
    shell_exec($cmd);
    for ($i = 1; $i < 5; $i++) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} waiting {$i}/5\n";
        }
        sleep(1);
        $pid = PID_NUM();
        if ($unix->process_exists($pid)) {
            break;
        }
    }
    $pid = PID_NUM();
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Success PID {$pid}\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} {$cmd}\n";
        }
    }
}