예제 #1
0
function start($nopid = false)
{
    $sock = new sockets();
    $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]: {$GLOBALS["SERVICE_NAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
    }
    $pid = ntopng_pid();
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already running since {$time}Mn...\n";
        }
        return;
    }
    $Enablentopng = $sock->GET_INFO("Enablentopng");
    if (!is_numeric($Enablentopng)) {
        $Enablentopng = 0;
    }
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    if ($SquidPerformance > 2) {
        $Enablentopng = 0;
    }
    if ($Enablentopng == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Disabled ( see Enablentopng )...\n";
        }
        return;
    }
    $masterbin = $unix->find_program("ntopng");
    if (!is_file($masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Not installed...\n";
        }
        return;
    }
    $redis_pid = redis_pid();
    if (!$unix->process_exists($redis_pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting redis-server\n";
        }
    }
    $redis_pid = redis_pid();
    if (!$unix->process_exists($redis_pid)) {
        $php = $unix->LOCATE_PHP5_BIN();
        system("{$php} /usr/share/artica-postfix/exec.redis-server.php --start");
    }
    $redis_pid = redis_pid();
    if (!$unix->process_exists($redis_pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed, unable to start redis-server\n";
        }
        return;
    }
    CheckFilesAndSecurity();
    $version = ntopng_version();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting service v{$version}\n";
    }
    $net = new networkscanner();
    while (list($num, $maks) = each($net->networklist)) {
        if (trim($maks) == null) {
            continue;
        }
        if (isset($net->Networks_disabled[$maks])) {
            continue;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Analyze {$maks}\n";
        }
        $hash[$maks] = $maks;
    }
    while (list($a, $b) = each($hash)) {
        $MASKZ[] = $a;
    }
    $arrayConf = unserialize(base64_decode($sock->GET_INFO("ntopng")));
    if (!is_numeric($arrayConf["HTTP_PORT"])) {
        $arrayConf["HTTP_PORT"] = 3000;
    }
    $f[] = $masterbin;
    $f[] = "--daemon";
    $f[] = "--dns-mode 1";
    $f[] = "--http-port {$arrayConf["HTTP_PORT"]}";
    $f[] = "--local-networks \"" . @implode(",", $MASKZ) . "\"";
    $f[] = "--user root";
    $f[] = "--data-dir /home/ntopng";
    $f[] = "--pid /var/run/ntopng/ntopng.pid";
    $f[] = "--dump-flows";
    $f[] = all_interfaces();
    if (intval($arrayConf["ENABLE_LOGIN"]) == 0) {
        $f[] = "--disable-login";
    }
    $cmd = @implode(" ", $f);
    shell_exec($cmd);
    $c = 1;
    for ($i = 0; $i < 10; $i++) {
        sleep(1);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting service waiting {$c}/10\n";
        }
        $pid = ntopng_pid();
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success PID {$pid}\n";
            }
            break;
        }
        $c++;
    }
    $pid = ntopng_pid();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$cmd}\n";
        }
    }
}
예제 #2
0
function ntopng()
{
    $base = "/root/ntopng-compiled";
    $Debian = DebianVersion();
    $Architecture = Architecture();
    $version = ntopng_version();
    $f[] = "/usr/local/share/ntopng";
    $f[] = "/usr/local/bin/ntopng";
    $f[] = "/usr/local/man/man8/ntopng.8";
    $f[] = "/usr/local/lib/libndpi.a";
    $f[] = "/usr/local/lib/libndpi.la";
    $f[] = "/usr/local/lib/libndpi.so";
    $f[] = "/usr/local/lib/libndpi.so.1";
    $f[] = "/usr/local/lib/libndpi.so.1.0.0";
    while (list($num, $filename) = each($f)) {
        if (is_dir($filename)) {
            @mkdir("{$base}/{$filename}", 0755, true);
            echo "/bin/cp -rfd {$filename}/* {$base}{$filename}/\n";
            shell_exec("/bin/cp -rfd {$filename}/* {$base}{$filename}/");
            continue;
        }
        if (is_file($filename)) {
            $dirname = dirname($filename);
            if (!is_dir("{$base}/{$dirname}")) {
                @mkdir("{$base}/{$dirname}", 0755, true);
            }
            echo "/bin/cp -fd {$filename} {$base}{$dirname}/\n";
            shell_exec("/bin/cp -fd {$filename} {$base}/{$dirname}/");
        }
    }
    chdir($base);
    if (is_file("{$base}/ntopng-{$Architecture}-{$version}.tar.gz")) {
        @unlink("{$base}/ntopng-{$Architecture}-{$version}.tar.gz");
    }
    $filename = "ntopng-debian{$Debian}-{$Architecture}-{$version}.tar.gz";
    if (is_file("{$base}/{$filename}")) {
        @unlink("{$base}/{$filename}");
    }
    system("tar -czvf {$filename} *");
    shell_exec("/bin/cp {$filename} /root/");
    echo "/root/{$filename} done\n";
}
예제 #3
0
function ntopng()
{
    $masterbin = $GLOBALS["CLASS_UNIX"]->find_program("ntopng");
    if (!is_file($masterbin)) {
        return;
    }
    $enabled = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("Enablentopng"));
    $SquidPerformance = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("SquidPerformance"));
    $EnableIntelCeleron = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableIntelCeleron"));
    if ($SquidPerformance > 2) {
        $Enablentopng = 0;
    }
    if ($EnableIntelCeleron == 1) {
        $Enablentopng = 0;
    }
    $l[] = "[APP_NTOPNG]";
    $l[] = "service_name=APP_NTOPNG";
    $l[] = "master_version=" . ntopng_version();
    $l[] = "service_cmd=/etc/init.d/ntopng";
    $l[] = "service_disabled={$enabled}";
    $l[] = "family=proxy";
    $l[] = "watchdog_features=1";
    if ($enabled == 0) {
        $master_pid = ntopng_pid();
        if ($GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
            ToSyslog("Stopping ntopng pid {$master_pid}, service disabled");
            shell_exec2("{$GLOBALS["nohup"]} /etc/init.d/ntopng stop >/dev/null 2>&1 &");
        }
        return implode("\n", $l);
        return;
    }
    $master_pid = ntopng_pid();
    if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
        if (!$GLOBALS["DISABLE_WATCHDOG"]) {
            shell_exec2("{$GLOBALS["nohup"]} /etc/init.d/ntopng start >/dev/null 2>&1 &");
        }
        $l[] = "running=0\ninstalled=1";
        $l[] = "";
        return implode("\n", $l);
        return;
    }
    $l[] = "running=1";
    $l[] = GetMemoriesOf($master_pid);
    $l[] = "";
    $CacheFile = "/etc/artica-postfix/settings/Daemons/NTOPNgSize";
    if (!is_file($CacheFile)) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.ntopng.php --clean  >/dev/null 2>&1 &");
        return implode("\n", $l);
        return;
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.ntopng.php.cleanstorage.time");
    if ($time_file > 1880) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.ntopng.php --clean  >/dev/null 2>&1 &");
    }
    return implode("\n", $l);
    return;
}