From 688b4f79e1e4a3827c913f752c2573c7a74ad99e Mon Sep 17 00:00:00 2001 From: Marcello Coutinho Date: Fri, 30 Mar 2012 03:47:53 -0300 Subject: sarg - version 0.2 with exclusion lists, bug fixes and gui improves. --- config/sarg/sarg.inc | 32 +++++---- config/sarg/sarg.template | 10 +-- config/sarg/sarg.xml | 46 ++++++++++++- config/sarg/sarg_about.php | 2 +- config/sarg/sarg_queue.php | 4 +- config/sarg/sarg_realtime.php | 6 +- config/sarg/sarg_reports.php | 146 ++++++++++++++++++++++++++++++++++++++++++ config/sarg/sarg_schedule.xml | 4 +- config/sarg/sarg_sync.xml | 4 +- 9 files changed, 223 insertions(+), 31 deletions(-) create mode 100755 config/sarg/sarg_reports.php (limited to 'config/sarg') diff --git a/config/sarg/sarg.inc b/config/sarg/sarg.inc index 2597b30d..4194be64 100644 --- a/config/sarg/sarg.inc +++ b/config/sarg/sarg.inc @@ -55,15 +55,17 @@ function log_rotate($log_file){ global $config, $g; #remove .10 rotate log file - unlink_if_exists($log_file.".10"); - - #rotate logs from 0 to 9 - for ($i = 9; $i < 0; $i--) - if (file_exists($log_file.".$i")) - rename ($log_file,$log_file.".".($i+1)); - + unlink_if_exists("$log_file".".10"); + #rotate logs from 9 to 0 + $i=9; + while ($i>=0){ + if (file_exists($log_file.".".$i)) + rename ($log_file.".".$i,$log_file.".".($i+1)); + $i=$i-1; + } #rotate current log - rename ($log_file,$log_file.".0"); + if (file_exists("$log_file")) + rename ($log_file,$log_file.".0"); } function run_sarg($id=-1) { global $config, $g; @@ -76,9 +78,9 @@ function run_sarg($id=-1) { } else{ $args=$_POST['args']; - $action=$post['action']; + $action=$_POST['action']; } - log_error("Sarg: force refresh now with '".$args."' args."); + log_error("Sarg: force refresh now with '".$args."' args and ".$action." action after sarg finish."); mwexec($cmd. " ".$args); #check if there is a script to run after file save @@ -91,9 +93,11 @@ function run_sarg($id=-1) { mwexec_bg('/usr/local/etc/rc.d/squid restart'); break; case "dansguardian": - if ($action !="none"){ + if (preg_match('/\w+/',$action) && $action !="none"){ log_rotate('/var/log/dansguardian/access.log'); - mwexec('/usr/local/sbin/dansguardian -r'); + log_error('restarting dansguardian after sarg and log rotate.'); + #mwexec('/usr/local/etc/rc.d/dansguardian restart'); + mwexec('/usr/bin/killall -HUP dansguardian'); } break; /*case "squidguard": @@ -147,7 +151,6 @@ function sync_package_sarg() { $use_comma=(preg_match('/use_comma/',$sarg['report_options'])?"yes":"no"); $long_url=(preg_match('/long_url/',$sarg['report_options'])?"yes":"no"); $privacy=(preg_match('/privacy/',$sarg['report_options'])?"yes":"no"); - $report_type=preg_replace('/,/',' ',$sarg['report_type']); if(!empty($sarg['include_userlist'])) $include_users="$include_users ".$sarg['include_userlist']; @@ -156,6 +159,9 @@ function sync_package_sarg() { file_put_contents("/usr/local/etc/sarg/sarg.conf", $sg, LOCK_EX); file_put_contents('/usr/local/etc/sarg/exclude_users.conf', sarg_text_area_decode($sarg['exclude_userlist']),LOCK_EX); + file_put_contents('/usr/local/etc/sarg/exclude_hosts.conf', sarg_text_area_decode($sarg['exclude_hostlist']),LOCK_EX); + file_put_contents('/usr/local/etc/sarg/exclude_codes.conf', sarg_text_area_decode($sarg['exclude_codelist']),LOCK_EX); + $exclude_string=(empty($sarg['exclude_string'])?"":'exclude_string"'.$sarg['exclude_string']."'"); if(empty($sarg['include_userlist'])){ $usertab="none"; } diff --git a/config/sarg/sarg.template b/config/sarg/sarg.template index 560d0c10..024d6d5c 100644 --- a/config/sarg/sarg.template +++ b/config/sarg/sarg.template @@ -204,7 +204,7 @@ exclude_users /usr/local/etc/sarg/exclude_users.conf # s1.acme.foo - exclude hostname only # *.acme.foo - exclude full domain name # -#exclude_hosts none +exclude_hosts /usr/local/etc/sarg/exclude_hosts.conf # TAG: useragent_log file # useragent.log file patch to generate useragent report. @@ -310,7 +310,7 @@ use_comma {$use_comma} # Only codes matching exactly one of the line is rejected. The # comparison is not case sensitive. # -#exclude_codes /usr/local/sarg/exclude_codes +exclude_codes /usr/local/etc/sarg/exclude_codes # TAG: replace_index string # Replace "index.html" in the main index file with this string @@ -462,7 +462,7 @@ privacy {$privacy} # Records from access.log file that contain one of listed strings will be ignored. # #exclude_string none - +{$exclude_string} # TAG: show_successful_message yes|no # Shows "Successful report generated on dir" at end of process. # @@ -581,12 +581,12 @@ squidguard_conf {$squidguard_conf} # TAG: show_sarg_info yes|no # shows sarg information and site path on each report bottom # -#show_sarg_info yes +show_sarg_info no # TAG: show_sarg_logo yes|no # shows sarg logo # -#show_sarg_logo yes +show_sarg_logo no # TAG: parsed_output_log directory # Saves the processed log in a sarg format after parsing the squid log file. diff --git a/config/sarg/sarg.xml b/config/sarg/sarg.xml index 6d7dd00e..98acc20f 100644 --- a/config/sarg/sarg.xml +++ b/config/sarg/sarg.xml @@ -44,7 +44,7 @@ Currently there are no FAQ items provided. sarg 1.0 - Services: sarg + Status: Sarg Settings /usr/local/pkg/sarg.inc Sarg Reports @@ -93,6 +93,11 @@ /usr/local/www/ 0755 + + http://www.pfsense.org/packages/config/sarg/sarg_reports.php + /usr/local/www/ + 0755 + http://www.pfsense.org/packages/config/sarg/sarg.template /usr/local/pkg/ @@ -110,7 +115,7 @@ View Report - /sarg-reports/ + /sarg_reports.php Realtime @@ -236,7 +241,42 @@ 10 base64 - + + Exclude Settings + listtopic + + + Exclude string + exclude_string + + Format: string1:string2:...:stringn]]> + input + 70 + + + Exclude hosts + exclude_hostlist + + Eg.: 192.168.10.10 - exclude ip address only
+ 192.168.10.0/24 - exclude full C class
+ s1.acme.foo - exclude hostname only
+ *.acme.foo - exclude full domain name]]>
+ textarea + 70 + 10 + base64 +
+ + Exclude codes + exclude_codelist + + Write one code per line. Lines starting with a # are ignored.
+ Only codes matching exactly one of the line is rejected. The comparison is not case sensitive.]]>
+ textarea + 70 + 10 + base64 +
sarg_php_install_command(); diff --git a/config/sarg/sarg_about.php b/config/sarg/sarg_about.php index ee415f07..5b728a17 100755 --- a/config/sarg/sarg_about.php +++ b/config/sarg/sarg_about.php @@ -54,7 +54,7 @@ include("head.inc"); $tab_array = array(); $tab_array[] = array(gettext("Settings"), false, "/pkg_edit.php?xml=sarg.xml&id=0"); $tab_array[] = array(gettext("Schedule"), false, "/pkg.php?xml=sarg_schedule.xml"); - $tab_array[] = array(gettext("View Report"), false, "/sarg-reports/"); + $tab_array[] = array(gettext("View Report"), false, "/sarg_reports.php"); $tab_array[] = array(gettext("Realtime"), false, "/sarg_realtime.php"); $tab_array[] = array(gettext("XMLRPC Sync"), false, "/pkg_edit.php?xml=sarg_sync.xml&id=0"); $tab_array[] = array(gettext("Help"), true, "/sarg_about.php"); diff --git a/config/sarg/sarg_queue.php b/config/sarg/sarg_queue.php index 3a27e734..627c06eb 100755 --- a/config/sarg/sarg_queue.php +++ b/config/sarg/sarg_queue.php @@ -104,7 +104,7 @@ else{ -
+
@@ -125,7 +125,7 @@ else{
- +
diff --git a/config/sarg/sarg_realtime.php b/config/sarg/sarg_realtime.php index f585889b..1af3eb70 100755 --- a/config/sarg/sarg_realtime.php +++ b/config/sarg/sarg_realtime.php @@ -92,7 +92,7 @@ else{ if(strstr($pfSversion, "1.2")) $one_two = true; - $pgtitle = "Status: Postfix Mail Queue"; + $pgtitle = "Status: Sarg Realtime"; include("head.inc"); ?> @@ -114,7 +114,7 @@ else{ $tab_array = array(); $tab_array[] = array(gettext("Settings"), false, "/pkg_edit.php?xml=sarg.xml&id=0"); $tab_array[] = array(gettext("Schedule"), false, "/pkg.php?xml=sarg_schedule.xml"); - $tab_array[] = array(gettext("View Report"), false, "/sarg-reports/"); + $tab_array[] = array(gettext("View Report"), false, "/sarg_reports.php"); $tab_array[] = array(gettext("Realtime"), true, "/sarg_realtime.php"); $tab_array[] = array(gettext("XMLRPC Sync"), false, "/pkg_edit.php?xml=sarg_sync.xml&id=0"); $tab_array[] = array(gettext("Help"), false, "/sarg_about.php"); @@ -127,7 +127,7 @@ else{ - +
diff --git a/config/sarg/sarg_reports.php b/config/sarg/sarg_reports.php new file mode 100755 index 00000000..cf013879 --- /dev/null +++ b/config/sarg/sarg_reports.php @@ -0,0 +1,146 @@ + + based on varnish_view_config. + 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"); +function get_cmd(){ + global $config,$g; + if ($_REQUEST['cmd'] =='sarg'){ + + #Check report xml info + if (!is_array($config['installedpackages']['sargrealtime'])){ + $config['installedpackages']['sargrealtime']['config'][0]['realtime_types']= ""; + $config['installedpackages']['sargrealtime']['config'][0]['realtime_users']= ""; + } + #Check report http actions to show + if ($config['installedpackages']['sargrealtime']['config'][0]['realtime_types'] != $_REQUEST['qshape']){ + $config['installedpackages']['sargrealtime']['config'][0]['realtime_types']= $_REQUEST['qshape']; + $update_config++; + } + + #Check report users show + if ($config['installedpackages']['sargrealtime']['config'][0]['realtime_users'] != $_REQUEST['qtype']){ + $config['installedpackages']['sargrealtime']['config'][0]['realtime_users']= $_REQUEST['qtype']; + $update_config++; + } + + if($update_config > 0){ + write_config; + #write changes to sarg_file + $sarg_config=file_get_contents('/usr/local/etc/sarg/sarg.conf'); + $pattern[0]='/realtime_types\s+[A-Z,,]+/'; + $pattern[1]='/realtime_unauthenticated_records\s+\w+/'; + $replace[0]="realtime_types ".$_REQUEST['qshape']; + $replace[1]="realtime_unauthenticated_records ".$_REQUEST['qtype']; + file_put_contents('/usr/local/etc/sarg/sarg.conf', preg_replace($pattern,$replace,$sarg_config),LOCK_EX); + } + exec("/usr/local/bin/sarg -r", $sarg); + $patern[0]="//"; + $replace[0]=""; + $patern[1]="/header_\w/"; + $replace[1]="listtopic"; + $patern[2]="/class=.data./"; + $replace[2]='class="listlr"'; + $patern[3]="/cellpadding=.\d./"; + $replace[3]='cellpadding="0"'; + $patern[4]="/cellspacing=.\d./"; + $replace[4]='cellspacing="0"'; + $patern[5]="/sarg/"; + $replace[5]='cellspacing="0"'; + + foreach ($sarg as $line){ + if (preg_match("/<.head>/",$line)) + $print ="ok"; + if ($print =="ok" && !preg_match("/(sarg realtime|Auto Refresh)/i",$line)) + print preg_replace($patern,$replace,$line); + } + } +} + +if ($_REQUEST['cmd']!=""){ + get_cmd(); + } +else{ + $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); + if(strstr($pfSversion, "1.2")) + $one_two = true; + + $pgtitle = "Status: Sarg Reports"; + include("head.inc"); + + ?> + + + + +

+ + + + + + +
+ + + + + +
+ +
+
+ + + + +
+
+
+ +
+ +
+
+ + + + diff --git a/config/sarg/sarg_schedule.xml b/config/sarg/sarg_schedule.xml index aa804364..e6d06b9c 100644 --- a/config/sarg/sarg_schedule.xml +++ b/config/sarg/sarg_schedule.xml @@ -42,7 +42,7 @@ Currently there are no FAQ items provided. sargschedule 0.5 - sarg + Status: Sarg Schedules /usr/local/pkg/sarg.inc /usr/local/pkg/ @@ -72,7 +72,7 @@ View Report - /sarg-reports/ + /sarg_reports.php Realtime diff --git a/config/sarg/sarg_sync.xml b/config/sarg/sarg_sync.xml index 5e744e58..f3d2ac79 100755 --- a/config/sarg/sarg_sync.xml +++ b/config/sarg/sarg_sync.xml @@ -43,7 +43,7 @@ Currently there are no FAQ items provided. sargsync 1.0 - Services: sarg + Status: Sarg Sync /usr/local/pkg/sarg.inc @@ -56,7 +56,7 @@ View Report - /sarg-reports/ + /sarg_reports.php Realtime -- cgit v1.2.3