diff options
author | Marcello Coutinho <marcellocoutinho@gmail.com> | 2012-09-14 13:12:12 -0300 |
---|---|---|
committer | Marcello Coutinho <marcellocoutinho@gmail.com> | 2012-09-14 13:12:12 -0300 |
commit | 8c44f779ee7806ac816f028d7323cda77168bee8 (patch) | |
tree | d497c7b3483dd8881134b6bf3a69163450e668e6 /config/sarg/sarg.inc | |
parent | 502bb0945280d409e33b3a3eaaa3ff1596705828 (diff) | |
download | pfsense-packages-8c44f779ee7806ac816f028d7323cda77168bee8.tar.gz pfsense-packages-8c44f779ee7806ac816f028d7323cda77168bee8.tar.bz2 pfsense-packages-8c44f779ee7806ac816f028d7323cda77168bee8.zip |
sarg - add gzip feature to compress reports and save disk space
Diffstat (limited to 'config/sarg/sarg.inc')
-rw-r--r-- | config/sarg/sarg.inc | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/config/sarg/sarg.inc b/config/sarg/sarg.inc index 0927b164..2560fb76 100644 --- a/config/sarg/sarg.inc +++ b/config/sarg/sarg.inc @@ -88,13 +88,34 @@ function run_sarg($id=-1) { 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']; } else{ $args=$_POST['args']; $action=$_POST['action']; + $gzip=$_POST['gzip']; + $find=$_POST['find']; + $gziplevel=$_POST['gziplevel']; + } + $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."); + if ($gzip=="on"){ + #remove old file if exists + unlink_if_exists("/root/sarg_run_{$id}.sh"); + $gzip_script=<<<EOF +#!/bin/sh +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; + #create a new file to speedup find search + file_put_contents("/root/sarg_run_{$id}.sh",$gzip_script,LOCK_EX); } - 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 if (is_array($config['installedpackages']['sarg'])) @@ -127,6 +148,10 @@ 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(); } |