function log_event($text, $device = NULL, $type = NULL, $reference = NULL, $severity = 6)
{
    if (!is_array($device)) {
        $device = device_by_id_cache($device);
    }
    if ($device['ignore'] && $type != 'device') {
        return FALSE;
    }
    // Do not log events if device ignored
    if ($type == 'port') {
        if (is_array($reference)) {
            $port = $reference;
            $reference = $port['port_id'];
        } else {
            $port = get_port_by_id_cache($reference);
        }
        if ($port['ignore']) {
            return FALSE;
        }
        // Do not log events if interface ignored
    }
    $severity = priority_string_to_numeric($severity);
    // Convert named severities to numeric
    if ($type == 'device' && $severity == 5 || isset($_SESSION['username'])) {
        $severity = $severity == 6 ? 5 : $severity;
        // If severity default, change to notification
        if (isset($_SESSION['username'])) {
            $text .= ' (用户: ' . $_SESSION['username'] . ')';
        } else {
            if (is_cli()) {
                if (is_cron()) {
                    $text .= ' (自动运行)';
                } else {
                    $text .= ' (控制台)';
                }
            }
        }
    }
    $insert = array('device_id' => $device['device_id'] ? $device['device_id'] : "NULL", 'entity_id' => is_numeric($reference) ? $reference : array('NULL'), 'entity_type' => $type ? $type : array('NULL'), 'timestamp' => array("NOW()"), 'severity' => $severity, 'message' => $text);
    $id = dbInsert($insert, 'eventlog');
    return $id;
}
chdir(dirname($argv[0]));
include_once "includes/defaults.inc.php";
include_once "config.php";
$options = getopt("A:Vyaselrptd");
include_once "includes/definitions.inc.php";
include "includes/functions.inc.php";
$scriptname = basename($argv[0]);
$cli = is_cli();
if (isset($options['V'])) {
    print_message(OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION);
    exit;
}
print_message("%g" . OBSERVIUM_PRODUCT . " " . OBSERVIUM_VERSION . "\n%WHouseKeeping%n\n", 'color');
// For interactive prompt/answer checks
// if it is started from crontab - prompt disabled and answer always 'yes'
if (is_cron()) {
    $prompt = FALSE;
} else {
    $prompt = !isset($options['y']);
}
$answer = TRUE;
$modules = array();
if (isset($options['a']) || isset($options['s'])) {
    $modules[] = 'syslog';
}
if (isset($options['a']) || isset($options['e'])) {
    $modules[] = 'eventlog';
}
if (isset($options['a']) || isset($options['l'])) {
    $modules[] = 'alertlog';
}
示例#3
0
function log_event($text, $device = NULL, $type = NULL, $reference = NULL)
{
    if (!is_array($device)) {
        $device = device_by_id_cache($device);
    }
    if ($device['ignore'] && $type != 'device') {
        return FALSE;
    }
    // Do not log events if device ignored
    if ($type == 'port') {
        if (is_array($reference)) {
            $port = $reference;
            $reference = $port['port_id'];
        } else {
            $port = get_port_by_id_cache($reference);
        }
        if ($port['ignore']) {
            return FALSE;
        }
        // Do not log events if interface ignored
    }
    if ($type == 'device') {
        // For events with type 'device' add info about username or cli
        if (isset($_SESSION['username'])) {
            $text .= ' (by user: '******'username'] . ')';
        } else {
            if (is_cli()) {
                if (is_cron()) {
                    $text .= ' (by cron)';
                } else {
                    $text .= ' (by console)';
                }
            }
        }
    }
    $insert = array('device_id' => $device['device_id'] ? $device['device_id'] : "NULL", 'reference' => $reference ? $reference : "NULL", 'type' => $type ? $type : "NULL", 'timestamp' => array("NOW()"), 'message' => $text);
    $id = dbInsert($insert, 'eventlog');
    return $id;
}
示例#4
0
<?php

include_once dirname(__FILE__) . "/frame.class.inc";
include_once dirname(__FILE__) . "/class.unix.inc";
if (isset($_GET["iscron"])) {
    is_cron();
    exit;
}
if (isset($_GET["install"])) {
    install();
    exit;
}
if (isset($_GET["wizard"])) {
    wizard();
    exit;
}
if (isset($_GET["sync-freewebs"])) {
    sync_freewebs();
    exit;
}
if (isset($_GET["access-events"])) {
    access_events();
    exit;
}
if (isset($_GET["freshclam-services"])) {
    freshclam_service();
    exit;
}
if (isset($_GET["freshclam-status"])) {
    freshclam_status();
    exit;