aboutsummaryrefslogtreecommitdiffstats
path: root/config/squid-reverse/squid_monitor_data.php
diff options
context:
space:
mode:
authormarcelloc <marcellocoutinho@gmail.com>2012-06-06 13:01:35 -0300
committerMarcello Coutinho <marcellocoutinho@gmail.com>2012-06-06 13:01:35 -0300
commitc533da31d810a5e6e8e96864b6e96271985d423a (patch)
treeabffcb37b79212d66f40fde7752e90061dd150ea /config/squid-reverse/squid_monitor_data.php
parent114db1aeaf05bba04efc479d8a0c256ba6d7cfc6 (diff)
downloadpfsense-packages-c533da31d810a5e6e8e96864b6e96271985d423a.tar.gz
pfsense-packages-c533da31d810a5e6e8e96864b6e96271985d423a.tar.bz2
pfsense-packages-c533da31d810a5e6e8e96864b6e96271985d423a.zip
squid3 - include real time log monitor tab
Diffstat (limited to 'config/squid-reverse/squid_monitor_data.php')
-rw-r--r--config/squid-reverse/squid_monitor_data.php252
1 files changed, 115 insertions, 137 deletions
diff --git a/config/squid-reverse/squid_monitor_data.php b/config/squid-reverse/squid_monitor_data.php
index 12d2a34a..fcd5d178 100644
--- a/config/squid-reverse/squid_monitor_data.php
+++ b/config/squid-reverse/squid_monitor_data.php
@@ -1,37 +1,36 @@
-<?php
-/* $Id$ */
+<?php
/* ========================================================================== */
/*
- squid_monitor.php
- part of pfSense (http://www.pfSense.com)
- Copyright (C) 2012 ccesario @ pfsense forum
- All rights reserved.
-
+ squid_monitor_data.php
+ part of pfSense (http://www.pfSense.com)
+ Copyright (C) 2012 Marcello Coutinho
+ Copyright (C) 2012 Carlos Cesario - carloscesario@gmail.com
+ 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.
+ 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.
*/
/* ========================================================================== */
-
# ------------------------------------------------------------------------------
# Defines
# ------------------------------------------------------------------------------
@@ -42,13 +41,77 @@ require_once("guiconfig.inc");
# ------------------------------------------------------------------------------
if ($_POST) {
# Actions
+ $filter = preg_replace('/(@|!|>|<)/',"",htmlspecialchars($_POST['strfilter']));
switch (strtolower($_POST['program'])) {
case 'squid':
- showSquid();
- break;
- case 'sguard';
- showSGuard();
- break;
+ // Define log file
+ $log='/var/squid/logs/access.log';
+ //show table headers
+ show_tds(array("Date","IP","Status","Address","User","Destination"));
+ //fetch lines
+ $logarr=fetch_log($log);
+ // Print lines
+ foreach ($logarr as $logent) {
+ // Split line by space delimiter
+ $logline = preg_split("/\s+/", $logent);
+
+ // Apply date format to first line
+ //$logline[0] = date("d.m.Y H:i:s",$logline[0]);
+
+ // Word wrap the URL
+ $logline[7] = htmlentities($logline[7]);
+ $logline[7] = html_autowrap($logline[7]);
+
+ // Remove /(slash) in destination row
+ $logline_dest = preg_split("/\//", $logline[9]);
+
+ // Apply filter and color
+ // Need validate special chars
+ if ($filter != "")
+ $logline = preg_replace("@($filter)@i","<spam><font color='red'>$1</font></span>",$logline);
+ echo "<tr valign=\"top\">\n";
+ echo "<td class=\"listlr\" nowrap>{$logline[0]} {$logline[1]}</td>\n";
+ echo "<td class=\"listr\">{$logline[3]}</td>\n";
+ echo "<td class=\"listr\">{$logline[4]}</td>\n";
+ echo "<td class=\"listr\" width=\"*\">{$logline[7]}</td>\n";
+ echo "<td class=\"listr\">{$logline[8]}</td>\n";
+ echo "<td class=\"listr\">{$logline_dest[1]}</td>\n";
+ echo "</tr>\n";
+ }
+ break;
+ case 'sguard';
+ $log='/var/squidGuard/log/block.log';
+ //show table headers
+ show_tds(array("Date-Time","ACL","Address","Host","User"));
+ //fetch lines
+ $logarr=fetch_log($log);
+ foreach ($logarr as $logent) {
+ // Split line by space delimiter
+ $logline = preg_split("/\s+/", $logent);
+
+ // Apply time format
+ $logline[0] = date("d.m.Y", strtotime($logline[0]));
+
+ // Word wrap the URL
+ $logline[4] = htmlentities($logline[4]);
+ $logline[4] = html_autowrap($logline[4]);
+
+
+ // Apply filter color
+ // Need validate special chars
+ if ($filter != "")
+ $logline = preg_replace("@($filter)@i","<spam><font color='red'>$1</font></span>",$logline);
+
+
+ echo "<tr>\n";
+ echo "<td class=\"listlr\" nowrap>{$logline[0]} {$logline[1]}</td>\n";
+ echo "<td class=\"listr\">{$logline[3]}</td>\n";
+ echo "<td class=\"listr\" width=\"*\">{$logline[4]}</td>\n";
+ echo "<td class=\"listr\">{$logline[5]}</td>\n";
+ echo "<td class=\"listr\">{$logline[6]}</td>\n";
+ echo "</tr>\n";
+ }
+ break;
}
}
@@ -74,116 +137,31 @@ function html_autowrap($cont)
// Show Squid Logs
-function showSquid() {
- // Define log file
- $squid_log='/var/squid/logs/access.log';
-
- echo "<tr valign=\"top\">\n";
- echo "<td class=\"listhdrr\">".gettext("Date")."</td>\n";
- echo "<td class=\"listhdrr\">".gettext("IP")."</td>\n";
- echo "<td class=\"listhdrr\">".gettext("Status")."</td>\n";
- echo "<td class=\"listhdrr\">".gettext("Address")."</td>\n";
- echo "<td class=\"listhdrr\">".gettext("User")."</td>\n";
- echo "<td class=\"listhdrr\">".gettext("Destination")."</td>\n";
- echo "</tr>\n";
-
- // Get Data from form post
+function fetch_log($log){
+ global $filter;
+ // Get Data from form post
$lines = $_POST['maxlines'];
- $filter = $_POST['strfilter'];
-
-
- // Get logs based in filter expression
- if($filter != "") {
- exec("tail -r -n $lines $squid_log | php -q parser_squid_log.php | grep -i ". escapeshellarg(htmlspecialchars($filter)), $logarr);
- }
- else {
- exec("tail -r -n $lines $squid_log | php -q parser_squid_log.php", $logarr);
- }
-
- // Print lines
- foreach ($logarr as $logent) {
- // Split line by space delimiter
- $logline = preg_split("/\s+/", $logent);
-
- // Apply date format to first line
- //$logline[0] = date("d.m.Y H:i:s",$logline[0]);
-
- // Word wrap the URL
- $logline[7] = htmlentities($logline[7]);
- $logline[7] = html_autowrap($logline[7]);
-
- // Remove /(slash) in destination row
- $logline_dest = preg_split("/\//", $logline[9]);
-
- // Apply filter and color
- // Need validate special chars
- if ($filter != "")
- $logline = preg_replace("/$filter/i","<spam><font color='red'>$filter</font></span>",$logline);
-
-
- echo "<tr valign=\"top\">\n";
- echo "<td class=\"listlr\" nowrap>{$logline[0]} {$logline[1]}</td>\n";
- echo "<td class=\"listr\">{$logline[3]}</td>\n";
- echo "<td class=\"listr\">{$logline[4]}</td>\n";
- echo "<td class=\"listr\" width=\"*\">{$logline[7]}</td>\n";
- echo "<td class=\"listr\">{$logline[8]}</td>\n";
- echo "<td class=\"listr\">{$logline_dest[1]}</td>\n";
- echo "</tr>\n";
- }
-}
-
-// Show SquidGuard Logs
-function showSGuard() {
- // Define log file
- $sguard_log='/var/squidGuard/log/block.log';
-
- echo "<tr valign=\"top\">\n";
- echo "<td class=\"listhdrr\">".gettext("Date-Time")."</td>\n";
- echo "<td class=\"listhdrr\">".gettext("ACL")."</td>\n";
- echo "<td class=\"listhdrr\">".gettext("Address")."</td>\n";
- echo "<td class=\"listhdrr\">".gettext("Host")."</td>\n";
- echo "<td class=\"listhdrr\">".gettext("User")."</td>\n";
- echo "</tr>\n";
-
- // Get Data from form post
- $lines = $_POST['maxlines'];
- $filter = $_POST['strfilter'];
-
+ if (preg_match("/!/",htmlspecialchars($_POST['strfilter'])))
+ $grep_arg="-iv";
+ else
+ $grep_arg="-i";
// Get logs based in filter expression
if($filter != "") {
- exec("tail -r -n $lines $sguard_log | grep -i ". escapeshellarg(htmlspecialchars($filter)), $logarr);
+ exec("tail -2000 {$log} | /usr/bin/grep {$grep_arg} " . escapeshellarg($filter). " | tail -r -n $lines | php -q squid_log_parser.php " , $logarr);
}
else {
- exec("tail -r -n $lines $sguard_log", $logarr);
- }
-
-
- // Print lines
- foreach ($logarr as $logent) {
- // Split line by space delimiter
- $logline = preg_split("/\s+/", $logent);
-
- // Apply time format
- $logline[0] = date("d.m.Y", strtotime($logline[0]));
-
- // Word wrap the URL
- $logline[4] = htmlentities($logline[4]);
- $logline[4] = html_autowrap($logline[4]);
-
-
- // Apply filter color
- // Need validate special chars
- if ($filter != "")
- $logline = preg_replace("/$filter/","<spam><font color='red'>$filter</font></span>",$logline);
-
- echo "<tr>\n";
- echo "<td class=\"listlr\" nowrap>{$logline[0]} {$logline[1]}</td>\n";
- echo "<td class=\"listr\">{$logline[3]}</td>\n";
- echo "<td class=\"listr\" width=\"*\">{$logline[4]}</td>\n";
- echo "<td class=\"listr\">{$logline[5]}</td>\n";
- echo "<td class=\"listr\">{$logline[6]}</td>\n";
- echo "</tr>\n";
+ exec("tail -r -n {$lines} {$log} | php -q squid_log_parser.php", $logarr);
}
+ // return logs
+ return $logarr;
+};
+
+function show_tds($tds){
+ echo "<tr valign='top'>\n";
+ foreach ($tds as $td){
+ echo "<td class='listhdrr'>".gettext($td)."</td>\n";
+ }
+ echo "</tr>\n";
}
?>