diff options
-rw-r--r-- | config/sarg/sarg.inc | 32 | ||||
-rw-r--r-- | config/sarg/sarg.template | 10 | ||||
-rw-r--r-- | config/sarg/sarg.xml | 46 | ||||
-rwxr-xr-x | config/sarg/sarg_about.php | 2 | ||||
-rwxr-xr-x | config/sarg/sarg_queue.php | 4 | ||||
-rwxr-xr-x | config/sarg/sarg_realtime.php | 6 | ||||
-rwxr-xr-x | config/sarg/sarg_reports.php | 146 | ||||
-rw-r--r-- | config/sarg/sarg_schedule.xml | 4 | ||||
-rwxr-xr-x | config/sarg/sarg_sync.xml | 4 |
9 files changed, 223 insertions, 31 deletions
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 @@ <faq>Currently there are no FAQ items provided.</faq> <name>sarg</name> <version>1.0</version> - <title>Services: sarg</title> + <title>Status: Sarg Settings</title> <include_file>/usr/local/pkg/sarg.inc</include_file> <menu> <name>Sarg Reports</name> @@ -94,6 +94,11 @@ <chmod>0755</chmod> </additional_files_needed> <additional_files_needed> + <item>http://www.pfsense.org/packages/config/sarg/sarg_reports.php</item> + <prefix>/usr/local/www/</prefix> + <chmod>0755</chmod> + </additional_files_needed> + <additional_files_needed> <item>http://www.pfsense.org/packages/config/sarg/sarg.template</item> <prefix>/usr/local/pkg/</prefix> <chmod>0755</chmod> @@ -110,7 +115,7 @@ </tab> <tab> <text>View Report</text> - <url>/sarg-reports/</url> + <url>/sarg_reports.php</url> </tab> <tab> <text>Realtime</text> @@ -236,7 +241,42 @@ <rows>10</rows> <encoding>base64</encoding> </field> - + <field> + <name>Exclude Settings</name> + <type>listtopic</type> + </field> + <field> + <fielddescr>Exclude string</fielddescr> + <fieldname>exclude_string</fieldname> + <description><![CDATA[Records from access.log file that contain one of listed strings will be ignored.<br> + <strong>Format: string1:string2:...:stringn</strong>]]></description> + <type>input</type> + <size>70</size> + </field> + <field> + <fielddescr>Exclude hosts</fielddescr> + <fieldname>exclude_hostlist</fieldname> + <description><![CDATA[Hosts, domains or subnets will be excluded from reports.<br> + Eg.: 192.168.10.10 - exclude ip address only<br> + 192.168.10.0/24 - exclude full C class<br> + s1.acme.foo - exclude hostname only<br> + *.acme.foo - exclude full domain name]]></description> + <type>textarea</type> + <cols>70</cols> + <rows>10</rows> + <encoding>base64</encoding> + </field> + <field> + <fielddescr>Exclude codes</fielddescr> + <fieldname>exclude_codelist</fieldname> + <description><![CDATA[Ignore records with these codes. Eg.: NONE/400<br> + Write one code per line. Lines starting with a # are ignored.<br> + Only codes matching exactly one of the line is rejected. The comparison is not case sensitive.]]></description> + <type>textarea</type> + <cols>70</cols> + <rows>10</rows> + <encoding>base64</encoding> + </field> </fields> <custom_php_install_command> 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{ <?php if ($savemsg) print_info_box($savemsg); ?> - <form action="postfix_view_config.php" method="post"> + <form action="sarg_realtimex.php" method="post"> <div id="mainlevel"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> @@ -125,7 +125,7 @@ else{ <table class="tabcont" width="100%" border="0" cellpadding="8" cellspacing="0"> <tr><td></td></tr> <tr> - <td colspan="2" valign="top" class="listtopic"><?=gettext("Postfix Queue"); ?></td></tr> + <td colspan="2" valign="top" class="listtopic"><?=gettext("Sarg Realtime"); ?></td></tr> <tr> <td width="22%" valign="top" class="vncell"><?=gettext("Log command: ");?></td> <td width="78%" class="vtable"> 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{ <table class="tabcont" width="100%" border="0" cellpadding="8" cellspacing="0"> <tr><td></td></tr> <tr> - <td colspan="2" valign="top" class="listtopic"><?=gettext("Postfix Queue"); ?></td></tr> + <td colspan="2" valign="top" class="listtopic"><?=gettext("Sarg Realtime"); ?></td></tr> <tr> <td width="22%" valign="top" class="vncell"><?=gettext("Log command: ");?></td> <td width="78%" class="vtable"> 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 @@ +<?php +/* + postfix_view_config.php + part of pfSense (http://www.pfsense.com/) + Copyright (C) 2011 Marcello Coutinho <marcellocoutinho@gmail.com> + 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]="/<?(html|head|style)>/"; + $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"); + + ?> + <body link="#0000CC" vlink="#0000CC" alink="#0000CC"> + <?php include("fbegin.inc"); ?> + + <?php if($one_two): ?> + <p class="pgtitle"><?=$pgtitle?></font></p> + <?php endif; ?> + + <?php if ($savemsg) print_info_box($savemsg); ?> + + <form action="postfix_view_config.php" method="post"> + + <div id="mainlevel"> + <table width="100%" border="0" cellpadding="0" cellspacing="0"> + <tr><td> + <?php + $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"), true, "/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"), false, "/pkg_edit.php?xml=sarg_about.php"); + display_top_tabs($tab_array); + ?> + </td></tr> + <tr> + <td> + <div id="mainarea"> + <table class="tabcont" width="100%" border="0" cellpadding="8" cellspacing="0"> + <tr><td></td></tr> + <tr> + <td colspan="2" valign="top" class="listtopic"><?=gettext("Sarg Reports"); ?></td></tr> + </table> + </div> + <br> + <iframe src="/sarg-reports/" frameborder=0 width="100%" height="600"></iframe> + <div id="file_div"></div> + + </td> + </tr> + </table> + </div> + </form> + <?php + include("fend.inc"); + } + ?> + </body> + </html> 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 @@ <faq>Currently there are no FAQ items provided.</faq> <name>sargschedule</name> <version>0.5</version> - <title>sarg</title> + <title>Status: Sarg Schedules</title> <include_file>/usr/local/pkg/sarg.inc</include_file> <additional_files_needed> <prefix>/usr/local/pkg/</prefix> @@ -72,7 +72,7 @@ </tab> <tab> <text>View Report</text> - <url>/sarg-reports/</url> + <url>/sarg_reports.php</url> </tab> <tab> <text>Realtime</text> 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 @@ <faq>Currently there are no FAQ items provided.</faq> <name>sargsync</name> <version>1.0</version> - <title>Services: sarg</title> + <title>Status: Sarg Sync</title> <include_file>/usr/local/pkg/sarg.inc</include_file> <tabs> <tab> @@ -56,7 +56,7 @@ </tab> <tab> <text>View Report</text> - <url>/sarg-reports/</url> + <url>/sarg_reports.php</url> </tab> <tab> <text>Realtime</text> |