From c533da31d810a5e6e8e96864b6e96271985d423a Mon Sep 17 00:00:00 2001 From: marcelloc Date: Wed, 6 Jun 2012 13:01:35 -0300 Subject: squid3 - include real time log monitor tab --- config/squid-reverse/squid.xml | 20 ++ config/squid-reverse/squid_auth.xml | 4 + config/squid-reverse/squid_cache.xml | 4 + config/squid-reverse/squid_log_parser.php | 57 ++++++ config/squid-reverse/squid_monitor.php | 94 ++++++--- config/squid-reverse/squid_monitor_data.php | 252 +++++++++++-------------- config/squid-reverse/squid_nac.xml | 4 + config/squid-reverse/squid_reverse.xml | 4 + config/squid-reverse/squid_reverse_general.xml | 4 + config/squid-reverse/squid_reverse_peer.xml | 4 + config/squid-reverse/squid_reverse_sync.xml | 4 + config/squid-reverse/squid_reverse_uri.xml | 4 + config/squid-reverse/squid_sync.xml | 4 + config/squid-reverse/squid_traffic.xml | 4 + config/squid-reverse/squid_upstream.xml | 4 + config/squid-reverse/squid_users.xml | 4 + 16 files changed, 304 insertions(+), 167 deletions(-) create mode 100755 config/squid-reverse/squid_log_parser.php (limited to 'config') diff --git a/config/squid-reverse/squid.xml b/config/squid-reverse/squid.xml index 2a7771b3..7ca2c1e9 100644 --- a/config/squid-reverse/squid.xml +++ b/config/squid-reverse/squid.xml @@ -98,6 +98,10 @@ Users /pkg.php?xml=squid_users.xml + + Real time + /squid_monitor.php + Sync /pkg_edit.php?xml=squid_sync.xml @@ -194,6 +198,22 @@ 0755 http://www.pfsense.org/packages/config/squid-reverse/swapstate_check.php + + /usr/local/www/ + 0755 + http://www.pfsense.org/packages/config/squid-reverse/squid_monitor.php + + + /usr/local/www/ + 0755 + http://www.pfsense.org/packages/config/squid-reverse/squid_monitor_data.php + + + /usr/local/www/ + 0755 + http://www.pfsense.org/packages/config/squid-reverse/squid_log_parser.php + + Squid General Settings diff --git a/config/squid-reverse/squid_auth.xml b/config/squid-reverse/squid_auth.xml index 43cbe7ea..307669c5 100644 --- a/config/squid-reverse/squid_auth.xml +++ b/config/squid-reverse/squid_auth.xml @@ -79,6 +79,10 @@ Users /pkg.php?xml=squid_users.xml + + Real time + /squid_monitor.php + Sync /pkg_edit.php?xml=squid_sync.xml diff --git a/config/squid-reverse/squid_cache.xml b/config/squid-reverse/squid_cache.xml index c00322cf..7f371f49 100644 --- a/config/squid-reverse/squid_cache.xml +++ b/config/squid-reverse/squid_cache.xml @@ -79,6 +79,10 @@ Users /pkg.php?xml=squid_users.xml + + Real time + /squid_monitor.php + Sync /pkg_edit.php?xml=squid_sync.xml diff --git a/config/squid-reverse/squid_log_parser.php b/config/squid-reverse/squid_log_parser.php new file mode 100755 index 00000000..f6cd7de8 --- /dev/null +++ b/config/squid-reverse/squid_log_parser.php @@ -0,0 +1,57 @@ +#!/usr/local/bin/php -q + \ No newline at end of file diff --git a/config/squid-reverse/squid_monitor.php b/config/squid-reverse/squid_monitor.php index da293358..ccc44fb9 100644 --- a/config/squid-reverse/squid_monitor.php +++ b/config/squid-reverse/squid_monitor.php @@ -1,34 +1,34 @@ - - +
+ + + + + +
+ +
@@ -103,7 +129,9 @@ include("head.inc");
- Enter the string filter: eg. username or ip addr or url. + Enter a grep like string/pattern to filterlog.
+ eg. username, ip addr, url.
+ Use ! to invert the sense of matching, to select non-matching lines.
@@ -131,7 +159,7 @@ include("head.inc");
- + @@ -153,6 +181,12 @@ include("head.inc");
+ +
+
+ |<)/',"",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","$1",$logline); + echo "\n"; + echo "{$logline[0]} {$logline[1]}\n"; + echo "{$logline[3]}\n"; + echo "{$logline[4]}\n"; + echo "{$logline[7]}\n"; + echo "{$logline[8]}\n"; + echo "{$logline_dest[1]}\n"; + echo "\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","$1",$logline); + + + echo "\n"; + echo "{$logline[0]} {$logline[1]}\n"; + echo "{$logline[3]}\n"; + echo "{$logline[4]}\n"; + echo "{$logline[5]}\n"; + echo "{$logline[6]}\n"; + echo "\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 "\n"; - echo "".gettext("Date")."\n"; - echo "".gettext("IP")."\n"; - echo "".gettext("Status")."\n"; - echo "".gettext("Address")."\n"; - echo "".gettext("User")."\n"; - echo "".gettext("Destination")."\n"; - echo "\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","$filter",$logline); - - - echo "\n"; - echo "{$logline[0]} {$logline[1]}\n"; - echo "{$logline[3]}\n"; - echo "{$logline[4]}\n"; - echo "{$logline[7]}\n"; - echo "{$logline[8]}\n"; - echo "{$logline_dest[1]}\n"; - echo "\n"; - } -} - -// Show SquidGuard Logs -function showSGuard() { - // Define log file - $sguard_log='/var/squidGuard/log/block.log'; - - echo "\n"; - echo "".gettext("Date-Time")."\n"; - echo "".gettext("ACL")."\n"; - echo "".gettext("Address")."\n"; - echo "".gettext("Host")."\n"; - echo "".gettext("User")."\n"; - echo "\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/","$filter",$logline); - - echo "\n"; - echo "{$logline[0]} {$logline[1]}\n"; - echo "{$logline[3]}\n"; - echo "{$logline[4]}\n"; - echo "{$logline[5]}\n"; - echo "{$logline[6]}\n"; - echo "\n"; + exec("tail -r -n {$lines} {$log} | php -q squid_log_parser.php", $logarr); } + // return logs + return $logarr; +}; + +function show_tds($tds){ + echo "\n"; + foreach ($tds as $td){ + echo "".gettext($td)."\n"; + } + echo "\n"; } ?> diff --git a/config/squid-reverse/squid_nac.xml b/config/squid-reverse/squid_nac.xml index c951b6f3..9371a0ba 100644 --- a/config/squid-reverse/squid_nac.xml +++ b/config/squid-reverse/squid_nac.xml @@ -79,6 +79,10 @@ Users /pkg.php?xml=squid_users.xml
+ + Real time + /squid_monitor.php + Sync /pkg_edit.php?xml=squid_sync.xml diff --git a/config/squid-reverse/squid_reverse.xml b/config/squid-reverse/squid_reverse.xml index ae0c0e8a..ce09f8e7 100644 --- a/config/squid-reverse/squid_reverse.xml +++ b/config/squid-reverse/squid_reverse.xml @@ -83,6 +83,10 @@ Users /pkg.php?xml=squid_users.xml + + Real time + /squid_monitor.php + Sync /pkg_edit.php?xml=squid_sync.xml diff --git a/config/squid-reverse/squid_reverse_general.xml b/config/squid-reverse/squid_reverse_general.xml index ff74b9d5..ec0bcb7a 100644 --- a/config/squid-reverse/squid_reverse_general.xml +++ b/config/squid-reverse/squid_reverse_general.xml @@ -63,6 +63,10 @@ Mappings /pkg.php?xml=squid_reverse_uri.xml + + Real time + /squid_monitor.php?menu=reverse + Sync /pkg_edit.php?xml=squid_reverse_sync.xml&id=0 diff --git a/config/squid-reverse/squid_reverse_peer.xml b/config/squid-reverse/squid_reverse_peer.xml index fb853eb3..6341567e 100644 --- a/config/squid-reverse/squid_reverse_peer.xml +++ b/config/squid-reverse/squid_reverse_peer.xml @@ -63,6 +63,10 @@ Mappings /pkg.php?xml=squid_reverse_uri.xml + + Real time + /squid_monitor.php?menu=reverse + Sync /pkg_edit.php?xml=squid_reverse_sync.xml&id=0 diff --git a/config/squid-reverse/squid_reverse_sync.xml b/config/squid-reverse/squid_reverse_sync.xml index d666d4e8..408f14f1 100755 --- a/config/squid-reverse/squid_reverse_sync.xml +++ b/config/squid-reverse/squid_reverse_sync.xml @@ -58,6 +58,10 @@ Mappings /pkg.php?xml=squid_reverse_uri.xml + + Real time + /squid_monitor.php?menu=reverse + Sync /pkg_edit.php?xml=squid_reverse_sync.xml&id=0 diff --git a/config/squid-reverse/squid_reverse_uri.xml b/config/squid-reverse/squid_reverse_uri.xml index a7a5a6d6..e2d64fe9 100644 --- a/config/squid-reverse/squid_reverse_uri.xml +++ b/config/squid-reverse/squid_reverse_uri.xml @@ -63,6 +63,10 @@ /pkg.php?xml=squid_reverse_uri.xml + + Real time + /squid_monitor.php?menu=reverse + Sync /pkg_edit.php?xml=squid_reverse_sync.xml&id=0 diff --git a/config/squid-reverse/squid_sync.xml b/config/squid-reverse/squid_sync.xml index c581d2c5..62a726f4 100755 --- a/config/squid-reverse/squid_sync.xml +++ b/config/squid-reverse/squid_sync.xml @@ -74,6 +74,10 @@ Users /pkg.php?xml=squid_users.xml + + Real time + /squid_monitor.php + Sync /pkg_edit.php?xml=squid_sync.xml diff --git a/config/squid-reverse/squid_traffic.xml b/config/squid-reverse/squid_traffic.xml index b1799cce..62269792 100644 --- a/config/squid-reverse/squid_traffic.xml +++ b/config/squid-reverse/squid_traffic.xml @@ -79,6 +79,10 @@ Users /pkg.php?xml=squid_users.xml + + Real time + /squid_monitor.php + Sync /pkg_edit.php?xml=squid_sync.xml diff --git a/config/squid-reverse/squid_upstream.xml b/config/squid-reverse/squid_upstream.xml index 126a0710..049d301c 100644 --- a/config/squid-reverse/squid_upstream.xml +++ b/config/squid-reverse/squid_upstream.xml @@ -80,6 +80,10 @@ Users /pkg.php?xml=squid_users.xml + + Real time + /squid_monitor.php + Sync /pkg_edit.php?xml=squid_sync.xml diff --git a/config/squid-reverse/squid_users.xml b/config/squid-reverse/squid_users.xml index 295ce4fa..791a5fa9 100644 --- a/config/squid-reverse/squid_users.xml +++ b/config/squid-reverse/squid_users.xml @@ -81,6 +81,10 @@ /pkg.php?xml=squid_users.xml + + Real time + /squid_monitor.php + Sync /pkg_edit.php?xml=squid_sync.xml -- cgit v1.2.3