Commit fba56a9a authored by Franco Fichtner's avatar Franco Fichtner

logs: lots of love for logs, filtering is more useful than ever :)

parent dd878efc
......@@ -33,10 +33,10 @@ require_once("system.inc");
require_once("interfaces.inc");
$system_logfile = '/var/log/system.log';
$filtertext = '';
$nentries = 50;
if (empty($config['syslog']['nentries'])) {
$nentries = 50;
} else {
if (isset($config['syslog']['nentries'])) {
$nentries = $config['syslog']['nentries'];
}
......@@ -76,13 +76,7 @@ include("head.inc");
<input id="filtersubmit" name="filtersubmit" type="submit" class="btn btn-primary" value="<?=gettext("Filter");?>" />
</form>
</td></tr>
<?php
if (isset($filtertext)) {
dump_clog($system_logfile, $nentries, true, array("$filtertext"), array("ppp"));
} else {
dump_clog($system_logfile, $nentries, true, array(), array("ppp"));
}
?>
<?php dump_clog($system_logfile, $nentries, $filtertext); ?>
<tr><td colspan="2">
<form action="diag_logs.php" method="post">
<input name="clear" type="submit" class="btn btn-default" value="<?= gettext("Clear log");?>" />
......
......@@ -33,10 +33,9 @@ require_once("system.inc");
require_once("interfaces.inc");
$portal_logfile = '/var/log/portalauth.log';
$nentries = 50;
if (empty($config['syslog']['nentries'])) {
$nentries = 50;
} else {
if (isset($config['syslog']['nentries'])) {
$nentries = $config['syslog']['nentries'];
}
......@@ -65,7 +64,7 @@ include("head.inc");
<div class="table-responsive">
<table class="table table-striped table-sort">
<tr><td colspan="2"><strong><?= sprintf(gettext('Last %s Portal Auth log entries'), $nentries); ?></strong></td></tr>
<?php dump_clog($portal_logfile, $nentries, true); ?>
<?php dump_clog($portal_logfile, $nentries); ?>
<tr><td colspan="2">
<form action="diag_logs_auth.php" method="post">
<input name="clear" type="submit" class="btn" value="<?= gettext("Clear log");?>" />
......
......@@ -34,10 +34,9 @@ require_once("system.inc");
require_once("interfaces.inc");
$dhcpd_logfile = '/var/log/dhcpd.log';
$nentries = 50;
if (empty($config['syslog']['nentries'])) {
$nentries = 50;
} else {
if (isset($config['syslog']['nentries'])) {
$nentries = $config['syslog']['nentries'];
}
......@@ -68,7 +67,7 @@ include("head.inc");
<div class="table-responsive">
<table class="table table-striped table-sort">
<tr><td colspan="2"><?= sprintf(gettext('Last %s DHCP service log entries'), $nentries); ?></strong></td><tr>
<?php dump_clog($dhcpd_logfile, $nentries, true); ?>
<?php dump_clog($dhcpd_logfile, $nentries); ?>
<tr><td colspan="2">
<form action="diag_logs_dhcp.php" method="post">
<input name="clear" type="submit" class="btn" value="<?= gettext("Clear log");?>" />
......
......@@ -35,10 +35,10 @@ require_once("system.inc");
require_once("interfaces.inc");
$system_logfile = '/var/log/gateways.log';
$filtertext = '';
$nentries = 50;
if (empty($config['syslog']['nentries'])) {
$nentries = 50;
} else {
if (isset($config['syslog']['nentries'])) {
$nentries = $config['syslog']['nentries'];
}
......@@ -77,12 +77,7 @@ include("head.inc");
<input id="filtersubmit" name="filtersubmit" type="submit" class="btn btn-primary" value="<?=gettext("Filter");?>" />
</form>
</td></tr>
<?php
if (isset($filtertext))
dump_clog($system_logfile, $nentries, true, array("$filtertext"));
else
dump_clog($system_logfile, $nentries, true, array());
?>
<?php dump_clog($system_logfile, $nentries, $filtertext); ?>
<tr><td colspan="2">
<form action="diag_logs_gateways.php" method="post">
<input name="clear" type="submit" class="btn" value="<?= gettext("Clear log");?>" />
......
......@@ -35,10 +35,10 @@ require_once("system.inc");
require_once("interfaces.inc");
$system_logfile = '/var/log/resolver.log';
$filtertext = '';
$nentries = 50;
if (empty($config['syslog']['nentries'])) {
$nentries = 50;
} else {
if (isset($config['syslog']['nentries'])) {
$nentries = $config['syslog']['nentries'];
}
......@@ -77,12 +77,7 @@ include("head.inc");
<input id="filtersubmit" name="filtersubmit" type="submit" class="btn btn-primary" value="<?=gettext("Filter");?>" />
</form>
</td></tr>
<?php
if (isset($filtertext))
dump_clog($system_logfile, $nentries, true, array("$filtertext"), array("ppp"));
else
dump_clog($system_logfile, $nentries, true, array(), array("ppp"));
?>
<?php dump_clog($system_logfile, $nentries, $filtertext); ?>
<tr><td colspan="2">
<form action="diag_logs_resolver.php" method="post">
<input name="clear" type="submit" class="btn" value="<?= gettext("Clear log");?>" />
......
......@@ -32,10 +32,10 @@ require_once("system.inc");
require_once("interfaces.inc");
$routing_logfile = '/var/log/routing.log';
$filtertext = '';
$nentries = 50;
if (empty($config['syslog']['nentries'])) {
$nentries = 50;
} else {
if (isset($config['syslog']['nentries'])) {
$nentries = $config['syslog']['nentries'];
}
......@@ -76,12 +76,7 @@ include("head.inc");
<input id="filtersubmit" name="filtersubmit" type="submit" class="btn btn-primary" value="<?=gettext("Filter");?>" />
</form>
</td></tr>
<?php
if (isset($filtertext))
dump_clog($routing_logfile, $nentries, true, array("$filtertext"));
else
dump_clog($routing_logfile, $nentries, true, array());
?>
<?php dump_clog($routing_logfile, $nentries, $filtertext); ?>
<tr><td colspan="2">
<form action="diag_logs_routing.php" method="post">
<input name="clear" type="submit" class="btn" value="<?= gettext("Clear log");?>" />
......
......@@ -34,10 +34,10 @@ require_once("system.inc");
require_once("interfaces.inc");
$wireless_logfile = '/var/log/wireless.log';
$filtertext = '';
$nentries = 50;
if (empty($config['syslog']['nentries'])) {
$nentries = 50;
} else {
if (isset($config['syslog']['nentries'])) {
$nentries = $config['syslog']['nentries'];
}
......@@ -77,12 +77,7 @@ include("head.inc");
<input id="filtersubmit" name="filtersubmit" type="submit" class="btn btn-primary" value="<?=gettext("Filter");?>" />
</form>
</td></tr>
<?php
if (isset($filtertext))
dump_clog($wireless_logfile, $nentries, true, array("$filtertext"));
else
dump_clog($wireless_logfile, $nentries, true, array());
?>
<?php dump_clog($wireless_logfile, $nentries, $filtertext); ?>
<tr><td colspan="2">
<form action="diag_logs_wireless.php" method="post">
<input name="clear" type="submit" class="btn" value="<?= gettext("Clear log");?>" />
......
<?php
/*
Copyright (C) 2015 Franco Fichtner <franco@opnsense.org>
Copyright (C) 2014 Deciso B.V.
Copyright (C) 2004 Scott Ullrich
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
......@@ -339,88 +340,85 @@ function clear_clog($logfile, $restart_syslogd = true)
}
}
function print_dump($logarr, $withorig)
function print_dump($logarr)
{
global $config;
if (!is_array($logarr)) {
echo "<tr valign=\"top\">\n";
echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logarr) . "</td>\n";
echo "</tr>\n";
return;
}
foreach ($logarr as $logent) {
$logent = preg_split("/\s+/", $logent, 6);
echo "<tr valign=\"top\">\n";
if ($logent[0] === 'File') {
echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars(join(' ', $logent)) . "</td>\n";
} elseif ($withorig) {
$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
$entry_text = ($logent[3] == $config['system']['hostname']) ? "" : $logent[3] . " ";
$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
echo "<td class=\"listlr nowrap\">{$entry_date_time}</td>\n";
echo "<td class=\"listr\">{$entry_text}</td>\n";
} else {
echo "<td class=\"listlr\" colspan=\"2\">" . htmlspecialchars($logent[5]) . "</td>\n";
}
$entry_date_time = htmlspecialchars(join(" ", array_slice($logent, 0, 3)));
$entry_text = ($logent[3] == $config['system']['hostname']) ? "" : $logent[3] . " ";
$entry_text .= htmlspecialchars($logent[4] . " " . $logent[5]);
echo "<td class=\"listlr nowrap\">{$entry_date_time}</td>\n";
echo "<td class=\"listr\">{$entry_text}</td>\n";
echo "</tr>\n";
}
}
function dump_clog($logfile, $tail, $withorig = true, $grepfor = '', $grepinvert = '')
function dump_clog($logfile, $tail, $grepfor = '')
{
global $config;
$sor = isset($config['syslog']['reverse']) ? '-r' : '';
$grepline = ' ';
$logarr = '';
$logarr = array();
$grepline = '';
if (is_array($grepfor)) {
$grepline .= " | /usr/bin/egrep -i " . escapeshellarg(implode("|", $grepfor));
}
$grepfor = preg_split('/\s+/', trim($grepfor));
if (is_array($grepinvert)) {
$grepline .= " | /usr/bin/egrep -iv " . escapeshellarg(implode("|", $grepinvert));
foreach ($grepfor as $pattern) {
$grepline .= ' | /usr/bin/egrep -i ' . escapeshellarg($pattern);
}
if (is_dir($logfile)) {
$logarr = array("File $logfile is a directory.");
$logarr = sprintf(gettext('File %s is a directory.'), $logfile);
} elseif (!file_exists($logfile)) {
$logarr = array("File $logfile doesn't exist.");
$logarr = sprintf(gettext('File %s doesn\'t exist.'), $logfile);
} else {
exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . "{$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
exec("/usr/local/sbin/clog " . escapeshellarg($logfile) . " {$grepline}| grep -v \"CLOG\" | grep -v \"\033\" | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
}
if (!count($logarr)) {
$logarr[] = sprintf(gettext('File %s yielded no results.'), $logfile);
if (is_array($logarr) && !count($logarr)) {
$logarr = sprintf(gettext('File %s yielded no results.'), $logfile);
}
print_dump($logarr, $withorig);
print_dump($logarr);
}
function dump_log($logfile, $tail, $withorig = true, $grepfor = '', $grepinvert = '')
function dump_log($logfile, $tail, $grepfor = '')
{
global $config;
$sor = isset($config['syslog']['reverse']) ? '-r' : '';
$grepline = ' ';
$logarr = '';
$logarr = array();
$grepline = '';
if (is_array($grepfor)) {
$grepline .= " | /usr/bin/egrep -i " . escapeshellarg(implode("|", $grepfor));
}
$grepfor = preg_split('/\s+/', trim($grepfor));
if (is_array($grepinvert)) {
$grepline .= " | /usr/bin/egrep -iv " . escapeshellarg(implode("|", $grepinvert));
foreach ($grepfor as $pattern) {
$grepline .= ' | /usr/bin/egrep -i ' . escapeshellarg($pattern);
}
if (is_dir($logfile)) {
$logarr = array(sprintf(gettext('File %s is a directory.'), $logfile));
$logarr = sprintf(gettext('File %s is a directory.'), $logfile);
} elseif (!file_exists($logfile)) {
$logarr = array(sprintf(gettext('File %s doesn\'t exist.'), $logfile));
$logarr = sprintf(gettext('File %s doesn\'t exist.'), $logfile);
} else {
exec("cat " . escapeshellarg($logfile) . "{$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
exec("cat " . escapeshellarg($logfile) . " {$grepline} | /usr/bin/tail {$sor} -n " . escapeshellarg($tail), $logarr);
}
if (!count($logarr)) {
$logarr[] = sprintf(gettext('File %s yielded no results.'), $logfile);
if (is_array($logarr) && !count($logarr)) {
$logarr = sprintf(gettext('File %s yielded no results.'), $logfile);
}
print_dump($logarr, $withorig);
print_dump($logarr);
}
/* Check if variable has changed, update and log if it has
......
......@@ -72,7 +72,7 @@ if(is_numeric($_POST['logfiltercount'])) {
<div id="system_log-widgets" class="content-box" style="overflow:scroll;">
<table class="table table-striped" cellspacing="0" cellpadding="0">
<?php dump_clog($system_logfile, $syslogEntriesToFetch, true, array(), array("ppp")); ?>
<?php dump_clog($system_logfile, $syslogEntriesToFetch); ?>
</table>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment