Пример #1
0
function scanarp_mysql()
{
    $unix = new unix();
    $t = time();
    if (systemMaxOverloaded()) {
        return;
    }
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $me = basename(__FILE__);
    $pid = @file_get_contents($pidfile);
    if ($unix->process_exists($pid, $me)) {
        if ($GLOBALS["VERBOSE"]) {
            echo " --> Already executed.. {$pid} aborting the process\n";
        }
        system_admin_events("--> Already executed.. {$pid} aborting the process", __FUNCTION__, __FILE__, __LINE__, "network");
        die;
    }
    $sock = new sockets();
    $EnableArpDaemon = $sock->GET_INFO("EnableArpDaemon");
    $ArpdKernelLevel = $sock->GET_INFO("ArpdKernelLevel");
    if (!is_numeric($EnableArpDaemon)) {
        $EnableArpDaemon = 1;
    }
    $articastatus_pidfile = "/etc/artica-postfix/exec.status.php.pid";
    $pid = $unix->get_pid_from_file($articastatus_pidfile);
    if (!$unix->process_exists($pid)) {
        syslog_status("artica status doesn't run, start it, old pid was: {$pid}");
        shell_exec("/etc/init.d/artica-status start");
    }
    $list = $unix->PIDOF_PATTERN_ALL($me);
    if (count($list) > 2) {
        system_admin_events("--> Already executed.." . count($list) . " Processes executed");
        die;
    }
    @file_put_contents($pidfile, getmypid());
    $arpbin = $unix->find_program("arp");
    $arpdbin = $unix->find_program("arpd");
    if (!is_file($arpbin)) {
        echo "arp, no such binary...\n";
        return;
    }
    exec("{$arpbin} -a 2>&1", $results);
    if ($GLOBALS["VERBOSE"]) {
        echo "{$arpbin} -a 2>&1\n";
    }
    $prefix = "INSERT INTO arpcache (`mac`,`ipaddr`,`hostname`,`HWtype`,`iface`) VALUES ";
    while (list($num, $ligne) = each($results)) {
        if (preg_match("#^(.+?)\\s+\\((.+?)\\)\\s+.+?\\s+(.+?)\\s+\\[(.+?)\\]\\s+.+?\\s+(.+)#", $ligne, $re)) {
            $mac = trim($re[3]);
            $hostname = trim($re[1]);
            $ipaddr = trim($re[2]);
            $HWtype = trim($re[4]);
            $iface = trim($re[5]);
            if ($GLOBALS["VERBOSE"]) {
                echo "MATCH `{$ligne}` '{$mac}','{$ipaddr}','{$hostname}','{$HWtype}','{$iface}'\n";
            }
            $f[] = "('{$mac}','{$ipaddr}','{$hostname}','{$HWtype}','{$iface}')";
            continue;
        }
        if (preg_match("#^([a-z0-9\\.\\-\\_\\?]+)\\s+\\((.+?)\\).+?incomplete.+?[a-z]+\\s+(.+)\$#", $ligne, $re)) {
            $mac = null;
            $hostname = trim($re[1]);
            $ipaddr = trim($re[2]);
            $HWtype = null;
            $iface = trim($re[3]);
            if ($GLOBALS["VERBOSE"]) {
                echo "MATCH `{$ligne}` '{$mac}','{$ipaddr}','{$hostname}','{$HWtype}','{$iface}'\n";
            }
            $f[] = "('{$mac}','{$ipaddr}','{$hostname}','{$HWtype}','{$iface}')";
            continue;
        }
        if ($GLOBALS["VERBOSE"]) {
            echo "No match `{$ligne}`\n";
        }
    }
    if (is_file($arpdbin)) {
        $results = array();
        exec("{$arpdbin} -l 2>&1", $results);
        while (list($num, $ligne) = each($results)) {
            if (preg_match("#^[0-9]+\\s+([0-9\\.]+)\\s+(.+)#", $ligne, $re)) {
                $mac = trim($re[2]);
                if (preg_match("#FAILED:#", $mac)) {
                    $mac = null;
                }
                $hostname = null;
                $ipaddr = trim($re[1]);
                $HWtype = null;
                $iface = "arpd";
                $f[] = "('{$mac}','{$ipaddr}','{$hostname}','{$HWtype}','{$iface}')";
                continue;
            }
        }
    }
    if (count($f) > 0) {
        $q = new mysql();
        $q->QUERY_SQL("TRUNCATE TABLE `arpcache`", "artica_backup");
        if ($GLOBALS["VERBOSE"]) {
            echo count($f) . " entries\n";
        }
        $sql = $prefix . @implode(",", $f);
        $q->QUERY_SQL($sql, "artica_backup");
        if (!$q->ok) {
            system_admin_events("Fatal, {$q->mysql_error}", __FUNCTION__, __FILE__, __LINE__, "network");
            return;
        }
        $took = $unix->distanceOfTimeInWords($t, time(), true);
        system_admin_events(count($f) . " ARP entries added into MySQL server", __FUNCTION__, __FILE__, __LINE__, "network");
    }
}
Пример #2
0
function php_fpm()
{
    $unix = new unix();
    $bin = $GLOBALS["CLASS_UNIX"]->APACHE_LOCATE_PHP_FPM();
    if (!is_file($bin)) {
        if (!is_file("/etc/debian_version")) {
            return;
        }
        $StampFile = "/etc/artica-postfix/pids/php_fpm.install.time";
        $TimeFile = $GLOBALS["CLASS_UNIX"]->file_time_min($StampFile);
        if ($TimeFile > 1440) {
            @unlink($StampFile);
            @file_put_contents($StampFile, time());
            syslog_status("php5-FPM: Not installed , installing php5-fpm Time:{$TimeFile}Mn", "artica-status");
            $cmd = trim("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.apt-get.php --phpfpm-daemon >/dev/null 2>&1 &");
            shell_exec2($cmd);
        }
        return;
    }
    $master_pid = FPM_PID();
    $EnablePHPFPM = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnablePHPFPM");
    $ZarafaApachePHPFPMEnable = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("ZarafaApachePHPFPMEnable");
    if (!is_numeric($ZarafaApachePHPFPMEnable)) {
        $ZarafaApachePHPFPMEnable = 0;
    }
    $EnableArticaApachePHPFPM = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableArticaApachePHPFPM");
    if (!is_numeric($EnableArticaApachePHPFPM)) {
        $EnableArticaApachePHPFPM = 0;
    }
    $EnablePHPFPMFreeWeb = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnablePHPFPMFreeWeb");
    if (!is_numeric($EnablePHPFPMFreeWeb)) {
        $EnablePHPFPMFreeWeb = 0;
    }
    $EnablePHPFPMFrameWork = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnablePHPFPMFrameWork");
    if (!is_numeric($EnablePHPFPMFrameWork)) {
        $EnablePHPFPMFrameWork = 0;
    }
    if ($EnableArticaApachePHPFPM == 1) {
        $EnablePHPFPM = 1;
    }
    if ($ZarafaApachePHPFPMEnable == 1) {
        $EnablePHPFPM = 1;
    }
    if ($EnablePHPFPMFreeWeb == 1) {
        $EnablePHPFPM = 1;
    }
    if ($EnablePHPFPMFrameWork == 1) {
        $EnablePHPFPM = 1;
    }
    if ($ZarafaApachePHPFPMEnable == 1) {
        $EnablePHPFPM = 1;
    }
    if ($EnableArticaApachePHPFPM == 1) {
        $EnablePHPFPM = 1;
    }
    if (!is_numeric($EnablePHPFPM)) {
        $EnablePHPFPM = 0;
    }
    if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
        $EnablePHPFPM = 1;
        $EnablePHPFPMFreeWeb = 1;
    }
    $l[] = "[APP_PHPFPM]";
    $l[] = "service_name=APP_PHPFPM";
    $l[] = "master_version=" . php_fpm_version();
    $l[] = "service_disabled={$EnablePHPFPM}";
    $l[] = "pid_path=/var/run/php5-fpm.pid";
    $l[] = "service_cmd=/etc/init.d/php5-fpm";
    $l[] = "watchdog_features=1";
    $l[] = "family=network";
    if (is_file("/etc/monit/conf.d/phpfpm.monitrc")) {
        @unlink("/etc/monit/conf.d/phpfpm.monitrc");
        $GLOBALS["CLASS_UNIX"]->MONIT_RELOAD();
    }
    if ($EnablePHPFPM == 0) {
        $l[] = "";
        return implode("\n", $l);
        return;
    }
    if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
        $master_pid = $GLOBALS["CLASS_UNIX"]->PIDOF($bin);
    }
    if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
        if (!$GLOBALS["DISABLE_WATCHDOG"]) {
            syslog_status("php5-FPM: Not running starting php5-fpm", "artica-status");
            $cmd = trim("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.php-fpm.php --start >/dev/null 2>&1 &");
            shell_exec2($cmd);
        }
        $l[] = "";
        return implode("\n", $l);
    }
    $l[] = GetMemoriesOf($master_pid);
    $l[] = "";
    if ($EnableArticaApachePHPFPM == 1) {
        if (!$GLOBALS["CLASS_UNIX"]->is_socket("/var/run/php-fpm.sock")) {
            syslog_status("/var/run/php-fpm.sock: no such file, restarting php5-FPM", "artica-status");
            $cmd = trim("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.php-fpm.php --restart >/dev/null 2>&1 &");
            shell_exec2($cmd);
        }
    }
    if ($EnablePHPFPMFreeWeb == 1) {
        if (!$GLOBALS["CLASS_UNIX"]->is_socket("/var/run/php-fpm-apache2.sock")) {
            syslog_status("/var/run/php-fpm-apache2.sock: no such file, restarting php5-FPM", "artica-status");
            $cmd = trim("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.php-fpm.php --restart >/dev/null 2>&1 &");
            shell_exec2($cmd);
        }
    }
    $zarafabin = $GLOBALS["CLASS_UNIX"]->find_program("zarafa-server");
    if (is_file($zarafabin)) {
        if ($ZarafaApachePHPFPMEnable == 1) {
            if (!$GLOBALS["CLASS_UNIX"]->is_socket("/var/run/php-fpm-zarafa.sock")) {
                syslog_status("/var/run/php-fpm-zarafa.sock: no such file, restarting php5-FPM", "artica-status");
                $cmd = trim("{$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.php-fpm.php --restart >/dev/null 2>&1 &");
                shell_exec2($cmd);
            }
        }
    }
    return implode("\n", $l);
    return;
}