aboutsummaryrefslogtreecommitdiffstats
path: root/config/syslog-ng/syslog-ng_log_viewer.php
diff options
context:
space:
mode:
authorLeger Lance <laleger@gmail.com>2012-09-16 18:48:34 +0200
committerLeger Lance <laleger@gmail.com>2012-09-16 18:48:34 +0200
commita6ca28c55bb2317e9870285277d8e0ec5486d2dd (patch)
tree1d44c19a52abfda5ce902c407a5020870fb1f392 /config/syslog-ng/syslog-ng_log_viewer.php
parent7623e022c458816bc28608b0c4344bd319e4629f (diff)
downloadpfsense-packages-a6ca28c55bb2317e9870285277d8e0ec5486d2dd.tar.gz
pfsense-packages-a6ca28c55bb2317e9870285277d8e0ec5486d2dd.tar.bz2
pfsense-packages-a6ca28c55bb2317e9870285277d8e0ec5486d2dd.zip
New syslog-ng package
Diffstat (limited to 'config/syslog-ng/syslog-ng_log_viewer.php')
-rw-r--r--config/syslog-ng/syslog-ng_log_viewer.php167
1 files changed, 167 insertions, 0 deletions
diff --git a/config/syslog-ng/syslog-ng_log_viewer.php b/config/syslog-ng/syslog-ng_log_viewer.php
new file mode 100644
index 00000000..c8183f14
--- /dev/null
+++ b/config/syslog-ng/syslog-ng_log_viewer.php
@@ -0,0 +1,167 @@
+<?php
+/* $Id$ */
+/* ========================================================================== */
+/*
+ syslog-ng_log_viewer.xml
+ part of pfSense (http://www.pfSense.com)
+ Copyright (C) 2012 Lance Leger
+ All rights reserved.
+ */
+/* ========================================================================== */
+/*
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
+ AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+/* ========================================================================== */
+
+require("guiconfig.inc");
+require("/usr/local/pkg/syslog-ng.inc");
+
+$objects = $config['installedpackages']['syslogngadvanced']['config'];
+$default_logdir = $config['installedpackages']['syslogng']['config'][0]['default_logdir'];
+$default_logfile = $config['installedpackages']['syslogng']['config'][0]['default_logfile'];
+$compress_archives = $config['installedpackages']['syslogng']['config'][0]['compress_archives'];
+$compress_type = $config['installedpackages']['syslogng']['config'][0]['compress_type'];
+
+if($_POST['logfile'])
+ $logfile = $_POST['logfile'];
+else
+ $logfile = $default_logdir . "/" . $default_logfile;
+
+if($_POST['limit'])
+ $limit = intval($_POST['limit']);
+else
+ $limit = "10";
+
+if($_POST['archives'])
+ $archives = true;
+
+if($_POST['filter'])
+ $filter = $_POST['filter'];
+
+if($_POST['not'])
+ $not = true;
+
+$log_messages = array();
+if(file_exists($logfile) && (filesize($logfile) > 0)) {
+ $grep = "grep -ih";
+
+ if(($compress_archives == 'on') && glob($logfile . "*" . $compress_type) && $archives) {
+ if($compress_type == 'bz2') {
+ $grep = "bzgrep -ih";
+ } else {
+ $grep = "zgrep -ih";
+ }
+ }
+
+ if(isset($filter) && $not) {
+ $grepcmd = "$grep -v '$filter' $logfile";
+ } else {
+ $grepcmd = "$grep '$filter' $logfile";
+ }
+
+ if($archives)
+ $grepcmd = $grepcmd . "*";
+
+ $log_lines = trim(shell_exec("$grepcmd | wc -l"));
+ $log_output = trim(shell_exec("$grepcmd | sort -M | tail -n $limit"));
+
+ if(!empty($log_output)) {
+ $log_messages = explode("\n", $log_output);
+ $log_messages_count = sizeof($log_messages);
+ }
+}
+
+$pgtitle = "Services: Syslog-ng Log Viewer";
+include("head.inc");
+?>
+<body link="#000000" vlink="#000000" alink="#000000">
+<?php include("fbegin.inc"); ?>
+<?php if ($savemsg) print_info_box($savemsg); ?>
+<form action="syslog-ng_log_viewer.php" method="post" name="iform">
+<table width="99%" border="0" cellpadding="0" cellspacing="0">
+ <tr><td>
+<?php
+ $tab_array = array();
+ $tab_array[] = array("General", false, "/pkg_edit.php?xml=syslog-ng.xml&amp;id=0");
+ $tab_array[] = array("Advanced", false, "/pkg.php?xml=syslog-ng_advanced.xml");
+ $tab_array[] = array("Log Viewer", true, "/syslog-ng_log_viewer.php");
+ display_top_tabs($tab_array);
+?>
+ </td></tr>
+ <tr><td>
+ <div id="mainarea">
+ <table id="maintable" name="maintable" class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
+ <tr><td>
+
+ <table>
+ <tr><td width="22%">Log File</td><td width="78%"><select name="logfile">
+ <?php
+ $log_files = syslogng_get_log_files($objects);
+ foreach($log_files as $log_file) {
+ if($log_file == $logfile) {
+ echo "<option value=\"$log_file\" selected=\"selected\">$log_file</option>\n";
+ } else {
+ echo "<option value=\"$log_file\">$log_file</option>\n";
+ }
+ }
+ ?>
+ </select></td></tr>
+ <tr><td width="22%">Limit</td><td width="78%"><select name="limit">
+ <?php
+ $limit_options = array("10", "20", "50");
+ foreach($limit_options as $limit_option) {
+ if($limit_option == $limit) {
+ echo "<option value=\"$limit_option\" selected=\"selected\">$limit_option</option>\n";
+ } else {
+ echo "<option value=\"$limit_option\">$limit_option</option>\n";
+ }
+ }
+ ?>
+ </select></td></tr>
+ <tr><td width="22%">Include Archives</td><td width="78%"><input type="checkbox" name="archives" <?php if($archives) echo " CHECKED"; ?> /></td></tr>
+ <tr><td colspan="2">
+ <table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="0">
+ <?php
+ if(!empty($log_messages)) {
+ echo "<tr><td class=\"listtopic\">Showing $log_messages_count of $log_lines messages</td></tr>\n";
+ foreach($log_messages as $log_message) {
+ echo "<tr><td class=\"listr\">$log_message</td></tr>\n";
+ }
+ } else {
+ echo "<tr><td><span class=\"red\">No log messages found or log file is empty.</span></td></tr>\n";
+ }
+ ?>
+ </table>
+ </td></tr>
+ <tr><td width="22%">Filter</td><td width="78%"><input name="filter" value="<?=$filter?>" /></td></tr>
+ <tr><td width="22%">Inverse Filter (NOT)</td><td width="78%"><input type="checkbox" name="not" <?php if($not) echo " CHECKED"; ?> /></td></tr>
+ <tr><td colspan="2"><input type="submit" value="Refresh" /></td></tr>
+ </table>
+
+ </td></tr>
+ </table>
+ </div>
+ </td></tr>
+</table>
+</form>
+<?php include("fend.inc"); ?>
+</body> \ No newline at end of file