示例#1
0
function Events($lim, $in, $op, $st, $co, $mod = 0)
{
    global $link, $modgroup, $self, $bg, $bi, $mico, $mbak, $mlvl, $noiplink;
    global $gralbl, $lstlbl, $levlbl, $timlbl, $tgtlbl, $srclbl, $monlbl, $msglbl, $stalbl, $cfglbl, $cmdlbl, $nonlbl, $clalbl, $limlbl;
    $query = GenQuery('events', 's', 'id,level,time,source,info,class,device,type,readcomm', 'id desc', $lim, $in, $op, $st, $co, 'LEFT JOIN devices USING (device)');
    $res = DbQuery($query, $link);
    if ($res) {
        $nmsg = DbNumRows($res);
        if ($nmsg) {
            $row = 0;
            if ($mod > 1) {
                if ($mod == 2) {
                    ?>
<table class="content"><tr>
<th width="50" class="<?php 
                    echo $modgroup[$self];
                    ?>
2"><img src="img/16/idea.png"><br><?php 
                    echo $levlbl;
                    ?>
</th>
<th class="<?php 
                    echo $modgroup[$self];
                    ?>
2"><img src="img/16/clock.png"><br><?php 
                    echo $timlbl;
                    ?>
</th>
<th class="<?php 
                    echo $modgroup[$self];
                    ?>
2"><img src="img/16/say.png"><br><?php 
                    echo $srclbl;
                    ?>
</th>
<th class="<?php 
                    echo $modgroup[$self];
                    ?>
2"><img src="img/16/find.png"><br>Info</th>
</tr>
<?php 
                }
                while ($m = DbFetchRow($res)) {
                    if ($row % 2) {
                        $bg = "txta";
                        $bi = "imga";
                    } else {
                        $bg = "txtb";
                        $bi = "imgb";
                    }
                    $row++;
                    $time = date($_SESSION['date'], $m[2]);
                    $fd = urlencode(date("m/d/Y H:i:s", $m[2]));
                    $usrc = urlencode($m[3]);
                    $ssrc = substr($m[3], 0, $_SESSION['lsiz']);
                    $sinf = strlen($m[4]) > 60 ? substr($m[4], 0, 60) . "..." : $m[4];
                    if ($mod == 2) {
                        TblRow($bg);
                        echo "<th class=\"" . $mbak[$m[1]] . "\"><a href=Monitoring-Events.php?lvl={$m['1']}>\n";
                        echo "<img src=\"img/16/" . $mico[$m[1]] . ".png\" title=\"" . $mlvl[$m[1]] . "\"></a></th>\n";
                        echo "<td nowrap><a href=Monitoring-Events.php?in[]=time&op[]==&st[]={$fd}>{$time}</a></td><td nowrap>\n";
                        echo "<a href=Monitoring-Events.php?in[]=source&op[]==&st[]={$usrc}>{$ssrc}</a></td><td>{$sinf}</td></tr>\n";
                    } else {
                        # Mobile mode, mh.php
                        echo "<tr class=\"" . $mbak[$m[1]] . "\"><th nowrap>{$ssrc}</th><td nowrap>{$time}</td><td>{$sinf}</td></tr>\n";
                    }
                }
                echo "</table>\n";
            } else {
                ?>
<table class="content"><tr>
<th width="50" class="<?php 
                echo $modgroup[$self];
                ?>
2"><img src="img/16/key.png"><br>Id</th>
<th width="50" class="<?php 
                echo $modgroup[$self];
                ?>
2"><img src="img/16/idea.png" title="10=<?php 
                echo $mlvl['10'];
                ?>
,50=<?php 
                echo $mlvl['50'];
                ?>
, 100=<?php 
                echo $mlvl['100'];
                ?>
, 150=<?php 
                echo $mlvl['150'];
                ?>
, 200=<?php 
                echo $mlvl['200'];
                ?>
, 250=<?php 
                echo $mlvl['250'];
                ?>
"><br><?php 
                echo $levlbl;
                ?>
</th>
<th width="120" class="<?php 
                echo $modgroup[$self];
                ?>
2"><img src="img/16/clock.png"><br><?php 
                echo $timlbl;
                ?>
</th>
<th class="<?php 
                echo $modgroup[$self];
                ?>
2"><img src="img/16/say.png" title="<?php 
                echo $monlbl;
                ?>
 <?php 
                echo $tgtlbl;
                ?>
 || IP (<?php 
                echo $msglbl;
                ?>
 <?php 
                echo $levlbl;
                ?>
 < 50)"><br><?php 
                echo $srclbl;
                ?>
</th>
<th width="50" class="<?php 
                echo $modgroup[$self];
                ?>
2"><img src="img/16/abc.png" title="<?php 
                echo $msglbl;
                ?>
 <?php 
                echo $clalbl;
                ?>
:<?php 
                echo $cmdlbl;
                ?>
"><br><?php 
                echo $clalbl;
                ?>
</th>
<th class="<?php 
                echo $modgroup[$self];
                ?>
2"><img src="img/16/find.png"><br>Info</th>
</tr>
<?php 
                while ($m = DbFetchRow($res)) {
                    if ($row % 2) {
                        $bg = "txta";
                        $bi = "imga";
                    } else {
                        $bg = "txtb";
                        $bi = "imgb";
                    }
                    $row++;
                    $time = date($_SESSION['date'], $m[2]);
                    $fd = urlencode(date("m/d/Y H:i:s", $m[2]));
                    $usrc = urlencode($m[3]);
                    $utgt = urlencode($m[6]);
                    list($ei, $et) = EvClass($m[5]);
                    TblRow($bg);
                    echo "<th><a href=\"Monitoring-Events.php?in[]=id&op[]==&st[]={$m['0']}\">{$m['0']}</a></th>\n";
                    echo "<th class=\"" . $mbak[$m[1]] . "\"><a href=\"Monitoring-Events.php?in[]=level&op[]==&st[]={$m['1']}&co[]={$co['0']}&in[]={$in['1']}&op[]={$op['1']}&st[]=" . urlencode($st[1]) . "\"><img src=\"img/16/" . $mico[$m[1]] . ".png\" title=\"" . $mlvl[$m[1]] . "\"></a></th>\n";
                    echo "<td nowrap><a href=\"Monitoring-Events.php?in[]=time&op[]==&st[]={$fd}\">{$time}</a></td>\n";
                    if ($m[7] == 'NeDi Agent') {
                        $agnt = "{$m['8']}://{$utgt}/";
                        $alnk = "on <a href=\"Devices-Status.php?dev={$utgt}\">{$utgt}</a> ";
                    } else {
                        $agnt = "";
                        $alnk = "";
                    }
                    echo "<td><a href=\"Monitoring-Events.php?in[]=source&op[]==&st[]={$usrc}\"><b>{$m['3']}</b></a> {$alnk}</td>\n";
                    $action = "<a href=\"{$agnt}Devices-Status.php?dev={$usrc}&pop=1\"><img src=\"img/16/{$ei}.png\" title=\"{$et}, Device {$stalbl}\"></a>";
                    if ($m[5] == "node") {
                        # Syslog from a node
                        $action = "<a href=\"{$agnt}Nodes-List.php?in[]=name&op[]==&st[]={$m['3']}\"><img src=\"img/16/{$ei}.png\" title=\"{$et}, Node {$lstlbl}\"></a>";
                    } elseif ($m[3] == "NeDi") {
                        # Not related to a dev or node!
                        $action = "<a href=\"{$agnt}System-Files.php\"><img src=\"img/16/{$ei}.png\" title=\"{$et}, NeDi {$cfglbl}\"></a>";
                    } elseif ($m[5] == "moni") {
                        # Monitoring events
                        $action = "<a href=\"{$agnt}Monitoring-Setup.php?in[]=name&op[]=%3D&st[]={$usrc}\"><img src=\"img/16/{$ei}.png\" title=\"{$et}, Monitoring Setup\"></a>";
                    } elseif ($m[5] == "cfgn" or $m[5] == "cfgc") {
                        # New config or changes
                        $action = "<a href=\"Devices-Config.php?shc={$usrc}\"><img src=\"img/16/{$ei}.png\" title=\"{$et}, Device {$cfglbl}\"></a>";
                    } elseif (strpos($m[5], "trf") !== FALSE) {
                        # Traffic warnings or alerts
                        $action = "<a href=\"{$agnt}Devices-Status.php?dev={$usrc}&trg=1&erg=1\"><img src=\"img/16/{$ei}.png\" title=\"{$et}, Device {$stalbl}\"></a>";
                    } elseif ($m[1] < 50) {
                        $action = "<a href=\"{$agnt}Nodes-List.php?in[]=nodip&op[]==&st[]={$m['3']}\"><img src=\"img/16/{$ei}.png\" title=\"{$et}, Node {$lstlbl}\"></a>";
                    } elseif ($m[5] == "ip") {
                        # syslog from unmonitored source
                        $action = "<img src=\"img/16/{$ei}.png\" title=\"{$et} ->{$msglbl} {$clalbl} {$m['5']}\">";
                    } elseif ($m[5] == "secs") {
                        # Security Stolen
                        $action = "<a href=\"{$agnt}Nodes-Stolen.php\"><img src=\"img/16/{$ei}.png\" title=\"{$et}, Nodes Stolen\"></a>";
                    }
                    echo "<th class=\"{$bi}\">{$action}</th><td>";
                    if ($noiplink) {
                        $info = preg_replace('/[\\s:]([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})(\\s|:|,|$)/', " <span class=\"blu\">\$1</span> ", $m[4]);
                        echo preg_replace('/[\\s:]([0-9a-f]{4}[\\.-]?[0-9a-f]{4}[\\.-]?[0-9a-f]{4}|[0-9a-f]{2}[-:][0-9a-f]{2}[-:][0-9a-f]{2}[-:][0-9a-f]{2}[-:][0-9a-f]{2}[-:][0-9a-f]{2})(\\s|$)/', " <span class=\"mrn\">\$1</span> ", $info);
                    } else {
                        $info = preg_replace('/[\\s:]([0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3})(\\s|:|,|$)/', " <span class=\"blu\">\$1</span>\n\t\t\t\t\t\t<a href=\"Nodes-Toolbox.php?Dest=\$1\"><img src=\"img/16/dril.png\" title=\"Lookup\"></a>\n\t\t\t\t\t\t<a href=\"Nodes-List.php?in[]=nodip&op[]=%3D&st[]=\$1\"><img src=\"img/16/nods.png\" title=\"Nodes {$lstlbl}\"></a>\n\t\t\t\t\t\t<a href=\"?in[]=info&op[]=~&st[]=\$1\"><img src=\"img/16/bell.png\" title=\"Monitoring-Events\"></a>", $m[4]);
                        echo preg_replace('/[\\s:]([0-9a-f]{4}[\\.-]?[0-9a-f]{4}[\\.-]?[0-9a-f]{4}|[0-9a-f]{2}[-:][0-9a-f]{2}[-:][0-9a-f]{2}[-:][0-9a-f]{2}[-:][0-9a-f]{2}[-:][0-9a-f]{2})(\\s|$)/', " <span class=\"mrn\">\$1</span> <a href=\"Nodes-Status.php?mac=\$1\"><img src=\"img/16/node.png\" title=\"Node {$stalbl}\"></a> ", $info);
                    }
                    echo "</td></tr>\n";
                }
                ?>
</table>
<table class="content">
<tr><td class="<?php 
                echo $modgroup[$self];
                ?>
2"><?php 
                echo $row;
                ?>
 <?php 
                echo $msglbl;
                echo $lim ? ", {$limlbl}: {$lim}" : "";
                ?>
</td></tr>
</table>
<?php 
            }
        } else {
            echo "<p><h5>{$nonlbl}</h5>";
        }
        DbFreeResult($res);
    } else {
        print DbError($link);
    }
}
 if ($res) {
     $nmsg = 0;
     while ($m = DbFetchArray($res)) {
         if ($det == 'source') {
             $wid = $fmt == 'li' ? "24" : "16";
             if ($m['source'] == 'nedi') {
                 $gico = "<img src=\"img/16/cog.png\" width=\"{$wid}\" title=\"{$srclbl} NeDi\">";
             } elseif ($m['icon']) {
                 $gico = "<img src=\"img/dev/{$m['icon']}.png\" width=\"{$wid}\" title=\"{$srclbl} {$m['source']}\">";
             } else {
                 $gico = "<img src=\"img/16/say.png\" width=\"{$wid}\" title=\"{$srclbl} {$m['source']}\">";
             }
         } elseif ($det == 'level') {
             $gico = "<img src=\"img/16/" . $mico[$m['level']] . ".png\" title=\"" . $mlvl[$m['level']] . "\">";
         } else {
             list($ei, $et) = EvClass($m['class']);
             $gico = "<img src=\"img/16/{$ei}.png\" title=\"{$et}\">";
         }
         if (!strpos($fmt, 'g')) {
             echo "<a href=\"Monitoring-Events.php?in[]=time&op[]=%3E=&st[]={$fs}&co[]=AND&in[]=time&op[]=%3C&st[]={$fe}&in[]={$det}&op[]==&st[]=" . urlencode($m[$det]) . "&co[]=AND&elm={$listlim}\">";
             if (strpos($fmt, 'i')) {
                 echo $gico;
             }
             echo Bar($m['cnt'], $det == 'level' ? "lvl{$m['level']}" : 0, $fmt, $m['cnt']) . "</a>\n";
         }
         $dsico[$m[$det]] = $gico;
         $dsval[$m[$det]][$row] = $m['cnt'];
         $nmsg += $m['cnt'];
     }
     if ($nmsg) {
         if (!strpos($fmt, 'g')) {