diff options
Diffstat (limited to 'config/sarg')
-rw-r--r-- | config/sarg/sarg.inc | 126 | ||||
-rw-r--r-- | config/sarg/sarg.php | 4 | ||||
-rw-r--r-- | config/sarg/sarg.priv.inc | 13 | ||||
-rw-r--r-- | config/sarg/sarg.template | 16 | ||||
-rw-r--r-- | config/sarg/sarg.xml | 25 | ||||
-rwxr-xr-x | config/sarg/sarg_frame.php | 41 | ||||
-rwxr-xr-x | config/sarg/sarg_queue.php | 241 | ||||
-rwxr-xr-x | config/sarg/sarg_realtime.php | 30 | ||||
-rwxr-xr-x | config/sarg/sarg_reports.php | 1 | ||||
-rw-r--r-- | config/sarg/sarg_schedule.xml | 49 |
10 files changed, 247 insertions, 299 deletions
diff --git a/config/sarg/sarg.inc b/config/sarg/sarg.inc index e762d9b8..5d0a91a5 100644 --- a/config/sarg/sarg.inc +++ b/config/sarg/sarg.inc @@ -31,13 +31,28 @@ POSSIBILITY OF SUCH DAMAGE. */ /* ========================================================================== */ +$pf_version=substr(trim(file_get_contents("/etc/version")),0,3); +if ($pf_version > 2.0){ + define('SARG_DIR', '/usr/pbi/sarg-' . php_uname("m")); + define('SQUID_DIR', '/usr/pbi/squid-' . php_uname("m")); + define('DANSG_DIR', '/usr/pbi/dansguardian-' . php_uname("m")); + } +else{ + define('SARG_DIR', '/usr/local'); + define('SQUID_DIR', '/usr/local'); + define('DANSG_DIR', '/usr/local'); +} + +$uname=posix_uname(); +if ($uname['machine']=='amd64') + ini_set('memory_limit', '250M'); // STATIC VARS -$sarg_proxy=array( 'squid_rc'=>'/usr/local/etc/rc.d/squid.sh', - 'squid_config'=>'/var/squid/logs/access.log', - 'squidguard_config'=>'/usr/local/etc/squidGuard/squidGuard.conf', +$sarg_proxy=array( 'squid_rc'=> SQUID_DIR . '/etc/rc.d/squid.sh', + 'squid_config'=> '/var/squid/logs/access.log', + 'squidguard_config'=> SARG_DIR . '/etc/squidGuard/squidGuard.conf', 'squidguard_block_log'=>'/var/squidGuard/log/block.log', - 'dansguardian_config'=>'/usr/local/etc/dansguardian/dansguardian.conf', + 'dansguardian_config'=> DANSG_DIR . '/etc/dansguardian/dansguardian.conf', 'dansguardian_log'=>'/var/log/dansguardian/access.log'); // END STATIC VARS @@ -56,7 +71,7 @@ function sarg_resync() { global $config; if (($_POST['Submit'] == 'Save') || !isset($_POST['Submit'])) sync_package_sarg(); - if ($_POST['Submit'] == 'Force udpate now') + if ($_POST['Submit'] == 'Force update now') run_sarg(); } @@ -80,17 +95,51 @@ function run_sarg($id=-1) { global $config, $g,$sarg_proxy; #mount filesystem writeable conf_mount_rw(); - $cmd = "/usr/local/bin/sarg"; + $cmd = SARG_DIR . "/bin/sarg"; if ($id >= 0 && is_array($config['installedpackages']['sargschedule']['config'])){ $args=$config['installedpackages']['sargschedule']['config'][$id]['args']; $action=$config['installedpackages']['sargschedule']['config'][$id]['action']; + $gzip=$config['installedpackages']['sargschedule']['config'][$id]['gzip']; + $find=$config['installedpackages']['sargschedule']['config'][$id]['find']; + $gziplevel=$config['installedpackages']['sargschedule']['config'][$id]['gziplevel']; + $daylimit=$config['installedpackages']['sargschedule']['config'][$id]['daylimit']; } else{ $args=$_POST['args']; $action=$_POST['action']; + $gzip=$_POST['gzip']; + $find=$_POST['find']; + $gziplevel=$_POST['gziplevel']; + $daylimit=""; } - log_error("Sarg: force refresh now with '".$args."' args and ".$action." action after sarg finish."); + $find=(preg_match("/(\d+)/",$find,$find_matches) ? $find_matches[1] : "60"); + log_error("Sarg: force refresh now with {$args} args, compress({$gzip}) and {$action} action after sarg finish."); + $gzip_script="#!/bin/sh\n"; + if ($gzip=="on"){ + #remove old file if exists + unlink_if_exists("/root/sarg_run_{$id}.sh"); + $gzip_script.=<<<EOF +for a in `/usr/bin/find /usr/local/sarg-reports -cmin -{$find} -type d -mindepth 1 -maxdepth 1` +do +echo \$a +/usr/bin/find \$a -name "*html" | xargs gzip {$gziplevel} +done + +EOF; + } + if (preg_match("/(\d+)/",$daylimit,$day_matches)){ + $gzip_script.=<<<EOF +for a in `/usr/bin/find /usr/local/sarg-reports -ctime +{$find} -type d -mindepth 1 -maxdepth 1` +do +echo \$a +rm -rf \$a +done + +EOF; + } + #create a new file to speedup find search + file_put_contents("/root/sarg_run_{$id}.sh",$gzip_script,LOCK_EX); mwexec($cmd. " ".$args); #check if there is a script to run after file save if (is_array($config['installedpackages']['sarg'])) @@ -99,12 +148,16 @@ function run_sarg($id=-1) { if ($action =="both" || $action=="rotate"){ log_error('executing squidguard log rotate after sarg.'); log_rotate($sarg_proxy['squidguard_block_log']); + file_put_contents($sarg_proxy['squidguard_block_log'],"",LOCK_EX); + chown($sarg_proxy['squidguard_block_log'],'proxy'); + chgrp($sarg_proxy['squidguard_block_log'],'proxy'); + mwexec(SQUID_DIR . '/sbin/squid -k reconfigure'); } - #Leve this case without break to include squid log file on squidguard option + #leave this case without break to run squid rotate too. case "squid": if ($action =="both" || $action=="rotate"){ log_error('executing squid log rotate after sarg.'); - mwexec('squid -k rotate'); + mwexec(SQUID_DIR . '/sbin/squid -k rotate'); } if ($action =="both" || $action=="restart"){ if (file_exists($sarg_proxy['squid_rc'])) @@ -119,12 +172,25 @@ function run_sarg($id=-1) { } break; } + #check compress option + if ($gzip=="on") + mwexec_bg("/bin/sh /root/sarg_run_{$id}.sh"); + #mount filesystem readonly conf_mount_ro(); } function sync_package_sarg() { global $config, $g,$sarg_proxy; + + # detect boot process + if (is_array($_POST)){ + if (!preg_match("/\w+/",$_POST['__csrf_magic'])) + return; + } + #check pkg.php sent a sync request + + $update_conf=0; #mount filesystem writeable conf_mount_rw(); @@ -150,6 +216,7 @@ function sync_package_sarg() { 'ldap_port'=> '389', 'ntlm_user_format'=>'domainname+username'); $sarguser=$config['installedpackages']['sarguser']['config'][0]; + $access_log=$sarg['proxy_server']; switch ($sarg['proxy_server']){ case 'dansguardian': $access_log= $sarg_proxy['dansguardian_log']; @@ -168,7 +235,7 @@ function sync_package_sarg() { $access_log = $config['installedpackages']['squid']['config'][0]['log_dir']. '/access.log'; break; } - if (!file_exists($access_log)){ + if (!file_exists($access_log) && $access_log !=""){ $error="Sarg config error: ".$sarg['proxy_server']." log file ($access_log) does not exists"; log_error($error); file_notice("Sarg", $error, "Sarg Settings", ""); @@ -194,7 +261,7 @@ function sync_package_sarg() { $date_format=(empty($sarg['report_date_format'])?"u":$sarg['report_date_format']); $report_type=preg_replace('/,/',' ',$sarg['report_type']); $report_charset=(empty($sarg['report_charset'])?"UTF-8":$sarg['report_charset']); - $exclude_string=(empty($sarg['exclude_string'])?"":'exclude_string"'.$sarg['exclude_string']."'"); + $exclude_string=(empty($sarg['exclude_string'])?"":'exclude_string "'.$sarg['exclude_string'].'"'); #limits $max_elapsed=(empty($sarg['max_elapsed'])?"0":$sarg['max_elapsed']); @@ -218,8 +285,8 @@ function sync_package_sarg() { $usertab="none"; } else{ - $usertab="/usr/local/etc/sarg/usertab.conf"; - file_put_contents('/usr/local/etc/sarg/usertab.conf', sarg_text_area_decode($sarguser['usertab']),LOCK_EX); + $usertab= SARG_DIR . "/etc/sarg/usertab.conf"; + file_put_contents( SARG_DIR . '/etc/sarg/usertab.conf', sarg_text_area_decode($sarguser['usertab']),LOCK_EX); } if($sarguser['ldap_enable']){ $LDAPHost=(empty($sarguser['ldap_host'])?"":"LDAPHost ".$sarguser['ldap_host']); @@ -231,20 +298,35 @@ function sync_package_sarg() { $LDAPFilterSearch=(empty($sarguser['ldap_filter_search'])?"":"LDAPFilterSearch ".$sarguser['ldap_filter_search']); } - #dirs - $dirs=array("/usr/local/www/sarg-reports"); + + #move old reports + if (is_dir("/usr/local/www/sarg-reports") && !is_dir("/usr/local/sarg-reports")) + rename("/usr/local/www/sarg-reports","/usr/local/sarg-reports"); + + #check dirs + $dirs=array("/usr/local/sarg-reports","/usr/local/www/sarg-images","/usr/local/www/sarg-images/temp"); foreach ($dirs as $dir) if (!is_dir($dir)) mkdir ($dir,0755,true); - + + #images + $simages=array("datetime.png","graph.png","sarg-squidguard-block.png","sarg.png"); + $simgdir1="/usr/local/www/sarg-images"; + $simgdir2= SARG_DIR . "/etc/sarg/images"; + foreach ($simages as $simage){ + if (!file_exists("{$simgdir1}/{$simage}")) + copy("{$simgdir2}/{$simage}","{$simgdir1}/{$simage}"); + } + + //log_error($_POST['__csrf_magic']." sarg log:". $access_log); #create sarg config files + $sarg_dir= SARG_DIR; include("/usr/local/pkg/sarg.template"); - file_put_contents("/usr/local/etc/sarg/sarg.conf", $sg, 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); - file_put_contents('/usr/local/etc/sarg/hostalias',sarg_text_area_decode($sarg['hostalias']),LOCK_EX); - file_put_contents('/usr/local/etc/sarg/exclude_users.conf', sarg_text_area_decode($sarguser['exclude_userlist']),LOCK_EX); - + file_put_contents( SARG_DIR . "/etc/sarg/sarg.conf", $sg, LOCK_EX); + file_put_contents( SARG_DIR . '/etc/sarg/exclude_hosts.conf', sarg_text_area_decode($sarg['exclude_hostlist']),LOCK_EX); + file_put_contents( SARG_DIR . '/etc/sarg/exclude_codes', sarg_text_area_decode($sarg['exclude_codelist']),LOCK_EX); + file_put_contents( SARG_DIR . '/etc/sarg/hostalias',sarg_text_area_decode($sarg['hostalias']),LOCK_EX); + file_put_contents( SARG_DIR . '/etc/sarg/exclude_users.conf', sarg_text_area_decode($sarguser['exclude_userlist']),LOCK_EX); #check cron_tab $new_cron=array(); $cron_found=0; diff --git a/config/sarg/sarg.php b/config/sarg/sarg.php index c2ec00c2..98e6c426 100644 --- a/config/sarg/sarg.php +++ b/config/sarg/sarg.php @@ -39,6 +39,10 @@ require_once("/etc/inc/pkg-utils.inc"); require_once("/etc/inc/globals.inc"); require_once("/usr/local/pkg/sarg.inc"); +$uname=posix_uname(); +if ($uname['machine']=='amd64') + ini_set('memory_limit', '250M'); + if (preg_match ("/(\d+)/",$argv[1],$matches)) run_sarg($matches[1]); diff --git a/config/sarg/sarg.priv.inc b/config/sarg/sarg.priv.inc new file mode 100644 index 00000000..4878c96e --- /dev/null +++ b/config/sarg/sarg.priv.inc @@ -0,0 +1,13 @@ +<?php + +global $priv_list; + +$priv_list['page-status-sarg-reports'] = array(); +$priv_list['page-status-sarg-reports']['name'] = "WebCfg - Status: Sarg reports"; +$priv_list['page-status-sarg-reports']['descr'] = "Allow access to sarg reports page."; +$priv_list['page-status-sarg-reports']['match'] = array(); +$priv_list['page-status-sarg-reports']['match'][] = "sarg_reports.php*"; +$priv_list['page-status-sarg-reports']['match'][] = "sarg_frame.php*"; +$priv_list['page-status-sarg-reports']['match'][] = "sarg_realtime.php*"; + +?> diff --git a/config/sarg/sarg.template b/config/sarg/sarg.template index 913dc892..abda925b 100644 --- a/config/sarg/sarg.template +++ b/config/sarg/sarg.template @@ -33,7 +33,7 @@ # sarg.conf # # TAG: access_log file -# Where is the access.lo +# Where is the access.log # sarg -l file # access_log {$access_log} @@ -42,7 +42,7 @@ access_log {$access_log} # Use graphics where is possible. # graph_days_bytes_bar_color blue|green|yellow|orange|brown|red # -graphs ${graphs} +graphs {$graphs} #graph_days_bytes_bar_color orange # TAG: graph_font @@ -149,7 +149,7 @@ graphs ${graphs} # The reports will be saved in that directory # sarg -o dir # -output_dir /usr/local/www/sarg-reports +output_dir /usr/local/sarg-reports # TAG: anonymous_output_files yes/no # Use anonymous file and directory names in the report. If it is set to @@ -194,7 +194,7 @@ user_sort_field {$sarguser['user_sort_field']} {$sort_order} # users within the file will be excluded from reports. # you can use indexonly to have only index.html file. # -exclude_users /usr/local/etc/sarg/exclude_users.conf +exclude_users {$sarg_dir}/etc/sarg/exclude_users.conf # TAG: exclude_hosts file # Hosts, domains or subnets will be excluded from reports. @@ -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 /usr/local/etc/sarg/exclude_hosts.conf +exclude_hosts {$sarg_dir}/etc/sarg/exclude_hosts.conf # TAG: useragent_log file # useragent.log file patch to generate useragent report. @@ -224,7 +224,7 @@ date_format {$date_format} #per_user_limit none # TAG: lastlog n -# How many reports files must be keept in reports directory. +# How many reports files must be kept in reports directory. # The oldest report file will be automatically removed. # 0 - no limit. # @@ -312,7 +312,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/etc/sarg/exclude_codes +exclude_codes {$sarg_dir}/etc/sarg/exclude_codes # TAG: replace_index string # Replace "index.html" in the main index file with this string @@ -806,6 +806,6 @@ sorttable /sarg_sorttable.js # *.freeav.net antivirus:freeav # *.mail.live.com # 65.52.00.00/14 *.mail.live.com -hostalias /usr/local/etc/sarg/hostalias +hostalias {$sarg_dir}/etc/sarg/hostalias EOF; ?> diff --git a/config/sarg/sarg.xml b/config/sarg/sarg.xml index f1ce5d93..bb345379 100644 --- a/config/sarg/sarg.xml +++ b/config/sarg/sarg.xml @@ -18,7 +18,7 @@ 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, + 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 @@ -88,11 +88,6 @@ <chmod>0755</chmod> </additional_files_needed> <additional_files_needed> - <item>http://www.pfsense.org/packages/config/sarg/sarg_queue.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_reports.php</item> <prefix>/usr/local/www/</prefix> <chmod>0755</chmod> @@ -112,6 +107,11 @@ <prefix>/usr/local/pkg/</prefix> <chmod>0755</chmod> </additional_files_needed> + <additional_files_needed> + <item>http://www.pfsense.org/packages/config/sarg/sarg.priv.inc</item> + <prefix>/etc/inc/priv/</prefix> + <chmod>0755</chmod> + </additional_files_needed> <tabs> <tab> <text>General</text> @@ -275,14 +275,23 @@ <size>10</size> </field> <field> - <fielddescr>Reports limits</fielddescr> + <fielddescr>Reports list limits</fielddescr> <fieldname>lastlog</fieldname> - <description><![CDATA[How many reports files must be keept in reports directory.<br> + <description><![CDATA[How many reports files must be kept in reports directory.<br> The oldest report file will be automatically removed.0 means no limit.]]></description> <type>input</type> <size>10</size> </field> <field> + <fielddescr>Reports days limits</fielddescr> + <fieldname>daylimit</fieldname> + <description><![CDATA[How many days reports files must be kept in reports directory.<br> + Older report file will be automatically removed.<br> + Leave empty to do not remove old reports.]]></description> + <type>input</type> + <size>10</size> + </field> + <field> <fielddescr>Top Users Limit</fielddescr> <fieldname>topuser_num</fieldname> <description><![CDATA[How many users in topsites report. 0 = no limit]]></description> diff --git a/config/sarg/sarg_frame.php b/config/sarg/sarg_frame.php index 73e3a469..4d3421ab 100755 --- a/config/sarg/sarg_frame.php +++ b/config/sarg/sarg_frame.php @@ -27,7 +27,12 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +require_once("authgui.inc"); +$uname=posix_uname(); +if ($uname['machine']=='amd64') + ini_set('memory_limit', '250M'); + if(preg_match("/(\S+)\W(\w+.html)/",$_REQUEST['file'],$matches)){ #https://192.168.1.1/sarg_reports.php?file=2012Mar30-2012Mar30/index.html $url=$matches[2]; @@ -38,21 +43,39 @@ else{ $prefix=""; } $url=($_REQUEST['file'] == ""?"index.html":$_REQUEST['file']); -if (file_exists("/usr/local/www/sarg-reports/".$url)) +$dir="/usr/local/sarg-reports"; +$rand=rand(100000000000,999999999999); +$report=""; +if (file_exists("{$dir}/{$url}")) + $report=file_get_contents("{$dir}/{$url}"); +else if (file_exists("{$dir}/{$url}.gz")) { + $data = gzfile("{$dir}/{$url}.gz"); + $report = implode($data); + unset ($data); + } +if ($report != "" ) { - $report=file_get_contents("/usr/local/www/sarg-reports/".$url); $pattern[0]="/href=\W(\S+html)\W/"; - $replace[0]="href=/sarg_frame.php?prevent=".rand(100000000000,999999999999)."&file=$prefix/$1"; - $pattern[1]='/img src="(\w+\.\w+)/'; - $replace[1]='img src="/sarg-reports'.$prefix.'/$1'; + $replace[0]="href=/sarg_frame.php?prevent=".$rand."&file=$prefix/$1"; + $pattern[1]='/img src="\S+\W([a-zA-Z0-9.-]+.png)/'; + $replace[1]='img src="/sarg-images/$1'; $pattern[2]='@img src="([.a-z/]+)/(\w+\.\w+)@'; - $replace[2]='img src="/sarg-reports'.$prefix.'/$1/$2'; - $pattern[3]='/<head>/'; - $replace[3]='<head><META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"><META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">'; + $replace[2]='img src="/sarg-images'.$prefix.'/$1/$2'; + $pattern[3]='/img src="([a-zA-Z0-9.-_]+).png/'; + $replace[3]='img src="/sarg-images/temp/$1.'.$rand.'.png'; + $pattern[4]='/<head>/'; + $replace[4]='<head><META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"><META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">'; + + #look for graph files inside reports. + if (preg_match_all('/img src="([a-zA-Z0-9._-]+).png/',$report,$images)){ + for ($x=0;$x<count($images[1]);$x++){ + copy("{$dir}/{$prefix}/{$images[1][$x]}.png","/usr/local/www/sarg-images/temp/{$images[1][$x]}.{$rand}.png"); + } + } print preg_replace($pattern,$replace,$report); } else{ - print "<pre>Error: Could not find report index file.<br>Check sarg settings and try to force sarg schedule."; + print "<pre>Error: Could not find report index file.<br>Check and save sarg settings and try to force sarg schedule."; } ?>
\ No newline at end of file diff --git a/config/sarg/sarg_queue.php b/config/sarg/sarg_queue.php deleted file mode 100755 index 8b8329a5..00000000 --- a/config/sarg/sarg_queue.php +++ /dev/null @@ -1,241 +0,0 @@ -<?php -/* - sarg_queue.php - part of pfSense (http://www.pfsense.com/) - Copyright (C) 2012 Marcello Coutinho <marcellocoutinho@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. -*/ - -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: Postfix Mail Queue"; - 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="sarg_realtimex.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("View Report"), false, "/sarg-reports/"); - $tab_array[] = array(gettext("Realtime"), true, "/sarg_real_time.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 Realtime"); ?></td></tr> - <tr> - <td width="22%" valign="top" class="vncell"><?=gettext("Log command: ");?></td> - <td width="78%" class="vtable"> - <select name="drop3" id="cmd"> - <option value="sarg" selected="selected">Sarg Realtime</option> - </select><br><?=gettext("Select queue command to run.");?></td> - </tr> - <tr> - <td width="22%" valign="top" class="vncell"><?=gettext("update frequency: ");?></td> - <td width="78%" class="vtable"> - <select name="drop3" id="updatef"> - <option value="1">01 second</option> - <option value="3" selected="selected">03 seconds</option> - <option value="5">05 seconds</option> - <option value="15">15 Seconds</option> - <option value="30">30 Seconds</option> - <option value="60">One minute</option> - <option value="1">Never</option> - </select><br><?=gettext("Select how often queue cmd will run.");?></td> - </tr> - <tr> - <td width="22%" valign="top" class="vncell"><?=gettext("Report Types: ");?></td> - <td width="78%" class="vtable"> - <select name="drop3" id="qshape" multiple="multiple" size="5"> - <option value="GET" selected="selected">GET</option> - <option value="PUT" selected="selected">PUT</option> - <option value="CONNECT" selected="selected">CONNECT</option> - <option value="ICP_QUERY">ICP_QUERY</option> - <option value="POST">POST</option> - </select><br><?=gettext("Which records must be in realtime report.");?></td> - </tr> - <tr> - <td width="22%" valign="top" class="vncell"><?=gettext("unauthenticated_records: ");?></td> - <td width="78%" class="vtable"> - <select name="drop3" id="qtype"> - <option value="show" selected>show</option> - <option value="hide">hide</option> - </select><br><?=gettext("What to do with unauthenticated records in realtime report.");?></td> - </tr> - - <tr> - <td width="22%" valign="top"></td> - <td width="78%"><input name="Submit" type="button" class="formbtn" id="run" value="<?=gettext("show log");?>" onclick="get_queue('mailq')"><div id="search_help"></div></td> - </table> - </div> - </td> - </tr> - </table> - <br> - <div> - <table class="tabcont" width="100%" border="0" cellpadding="8" cellspacing="0"> - <tr> - <td class="tabcont" > - <div id="file_div"></div> - - </td> - </tr> - </table> - </div> - </div> - </form> - <script type="text/javascript"> - function loopSelected(id) - { - var selectedArray = new Array(); - var selObj = document.getElementById(id); - var i; - var count = 0; - for (i=0; i<selObj.options.length; i++) { - if (selObj.options[i].selected) { - selectedArray[count] = selObj.options[i].value; - count++; - } - } - return(selectedArray); - } - - function get_queue(loop) { - //prevent multiple instances - if ($('run').value=="show log" || loop== 'running'){ - $('run').value="running..."; - $('search_help').innerHTML ="<br><strong>You can change options while running.<br>To Stop seach, change update frequency to Never.</strong>"; - var q_args=loopSelected('qshape'); - var pars = 'cmd='+$('cmd').options[$('cmd').selectedIndex].value; - var pars = pars + '&qshape='+q_args; - var pars = pars + '&type='+$('qtype').options[$('qtype').selectedIndex].value; - var url = "/sarg_queue.php"; - var myAjax = new Ajax.Request( - url, - { - method: 'post', - parameters: pars, - onComplete: activitycallback_queue_file - }); - } - } - function activitycallback_queue_file(transport) { - $('file_div').innerHTML = transport.responseText; - var update=$('updatef').options[$('updatef').selectedIndex].value * 1000; - if (update > 1000){ - setTimeout('get_queue("running")', update); - } - else{ - $('run').value="show log"; - $('search_help').innerHTML =""; - } - } - </script> - <?php - include("fend.inc"); - } - ?> - </body> - </html> diff --git a/config/sarg/sarg_realtime.php b/config/sarg/sarg_realtime.php index 0b8b2cc5..76e89769 100755 --- a/config/sarg/sarg_realtime.php +++ b/config/sarg/sarg_realtime.php @@ -27,7 +27,17 @@ POSSIBILITY OF SUCH DAMAGE. */ -require("guiconfig.inc"); +$pf_version=substr(trim(file_get_contents("/etc/version")),0,3); +if ($pf_version > 2.0) + define('SARG_DIR', '/usr/pbi/sarg-' . php_uname("m")); +else + define('SARG_DIR', '/usr/local'); + +$uname=posix_uname(); +if ($uname['machine']=='amd64') + ini_set('memory_limit', '250M'); + + function get_cmd(){ global $config,$g; #print $_REQUEST['type']; @@ -53,14 +63,14 @@ function get_cmd(){ if($update_config > 0){ write_config(); #write changes to sarg_file - $sarg_config=file_get_contents('/usr/local/etc/sarg/sarg.conf'); + $sarg_config=file_get_contents(SARG_DIR . '/etc/sarg/sarg.conf'); $pattern[0]='/realtime_types\s+[A-Z,,]+/'; $replace[0]="realtime_types ".$_REQUEST['qshape']; $pattern[1]='/realtime_unauthenticated_records\s+\w+/'; $replace[1]="realtime_unauthenticated_records ".$_REQUEST['type']; - file_put_contents('/usr/local/etc/sarg/sarg.conf', preg_replace($pattern,$replace,$sarg_config),LOCK_EX); + file_put_contents(SARG_DIR . '/etc/sarg/sarg.conf', preg_replace($pattern,$replace,$sarg_config),LOCK_EX); } - exec("/usr/local/bin/sarg -r", $sarg); + exec(SARG_DIR ."/bin/sarg -r",$sarg); $pattern[0]="/<?(html|head|style)>/"; $replace[0]=""; $pattern[1]="/header_\w/"; @@ -73,7 +83,6 @@ function get_cmd(){ $replace[4]='cellspacing="0"'; $pattern[5]="/sarg/"; $replace[5]='cellspacing="0"'; - foreach ($sarg as $line){ if (preg_match("/<.head>/",$line)) $print ="ok"; @@ -84,9 +93,12 @@ function get_cmd(){ } if ($_REQUEST['cmd']!=""){ + require_once("authgui.inc"); + require_once("functions.inc"); get_cmd(); } else{ + require("guiconfig.inc"); $pfSversion = str_replace("\n", "", file_get_contents("/etc/version")); if(strstr($pfSversion, "1.2")) $one_two = true; @@ -104,7 +116,7 @@ else{ <?php if ($savemsg) print_info_box($savemsg); ?> - <form action="postfix_view_config.php" method="post"> + <form action="sarg_realtime.php" method="post"> <div id="mainlevel"> <table width="100%" border="0" cellpadding="0" cellspacing="0"> @@ -204,17 +216,19 @@ else{ } return(selectedArray); } - function get_queue(loop) { //prevent multiple instances if ($('run').value=="show log" || loop== 'running'){ $('run').value="running..."; $('search_help').innerHTML ="<br><strong>You can change options while running.<br>To Stop seach, change update frequency to Never.</strong>"; + var axel = Math.random() + ""; + var num = axel * 1000000000000000000; var q_args=loopSelected('qshape'); var pars = 'cmd='+$('cmd').options[$('cmd').selectedIndex].value; var pars = pars + '&qshape='+q_args; + var pars = pars + '&prevent='+num; var pars = pars + '&type='+$('qtype').options[$('qtype').selectedIndex].value; - var url = "/sarg_queue.php"; + var url = "/sarg_realtime.php"; var myAjax = new Ajax.Request( url, { diff --git a/config/sarg/sarg_reports.php b/config/sarg/sarg_reports.php index b64e9966..b1792312 100755 --- a/config/sarg/sarg_reports.php +++ b/config/sarg/sarg_reports.php @@ -61,6 +61,7 @@ require("guiconfig.inc"); $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); + exec('rm -f /usr/local/www/sarg-images/temp/*'); ?> </td></tr> <tr> diff --git a/config/sarg/sarg_schedule.xml b/config/sarg/sarg_schedule.xml index 3d065a7a..0c452335 100644 --- a/config/sarg/sarg_schedule.xml +++ b/config/sarg/sarg_schedule.xml @@ -105,13 +105,18 @@ <fieldname>args</fieldname> </columnitem> <columnitem> + <fielddescr>Gzip</fielddescr> + <fieldname>gzip</fieldname> + </columnitem> + <columnitem> <fielddescr>Post Action</fielddescr> <fieldname>action</fieldname> </columnitem> <columnitem> <fielddescr>Description</fielddescr> <fieldname>description</fieldname> - </columnitem> + </columnitem> + <movable>arrow</movable> </adddeleteeditpagefields> <fields> <field> @@ -148,7 +153,7 @@ <size>5</size> <description><![CDATA[How often extract users from active directory and verify changes<br> Valid options are minutes(m), hours(h), days(d)<br> - Sample: To update every hour, use 1h<br><br>]]><input type="submit" name="Submit" value="Force udpate now"><br></description> + Sample: To update every hour, use 1h<br><br>]]><input type="submit" name="Submit" value="Force update now"><br></description> <required/> </field> <field> @@ -163,6 +168,44 @@ </options> <description>Choose an action after sarg finishes</description> </field> + <field> + <type>listtopic</type> + <fieldname>temp</fieldname> + <name>Compress Options</name> + </field> + <field> + <fielddescr>Enable Compression</fielddescr> + <fieldname>gzip</fieldname> + <description><![CDATA[Enable this option to compress sarg report html files using gzip and reduce 4 times sarg reports data.]]></description> + <type>checkbox</type> + </field> + <field> + <fielddescr>Compression level</fielddescr> + <fieldname>gziplevel</fieldname> + <type>select</type> + <options> + <option><name>Default gzip compression (Recommended)</name><value></value></option> + <option><name>1 (fast)</name><value>--fast</value></option> + <option><name>2</name><value>-2</value></option> + <option><name>3</name><value>-3</value></option> + <option><name>4</name><value>-4</value></option> + <option><name>5</name><value>-5</value></option> + <option><name>6</name><value>-6</value></option> + <option><name>7</name><value>-7</value></option> + <option><name>8</name><value>-8</value></option> + <option><name>9 (best)</name><value>--best</value></option> + </options> + <description>Choose gzip compression level.</description> + </field> + <field> + <fielddescr>Find Limit</fielddescr> + <fieldname>find</fieldname> + <type>input</type> + <default_value>60</default_value> + <size>5</size> + <description><![CDATA[To speed up find process, restrict find search to report files created/changed n minutes ago.<br> + Default is to 60 minutes. If your reports take longer to be created, increase this value.]]></description> + </field> </fields> <custom_php_install_command> sarg_php_install_command(); @@ -178,4 +221,4 @@ <custom_php_resync_config_command> sarg_resync(); </custom_php_resync_config_command> -</packagegui>
\ No newline at end of file +</packagegui> |