From 3864c8951c23d691101b18911bb5e76d603e4d1b Mon Sep 17 00:00:00 2001 From: Marcello Coutinho Date: Thu, 24 May 2012 17:13:31 -0300 Subject: sarg - version 0.5 with reports permission inc file and no direct access to reports --- config/sarg/sarg.inc | 23 ++++++++++++++++++++--- config/sarg/sarg.priv.inc | 12 ++++++++++++ config/sarg/sarg.template | 2 +- config/sarg/sarg.xml | 5 +++++ config/sarg/sarg_frame.php | 29 ++++++++++++++++++++--------- config/sarg/sarg_reports.php | 1 + config/sarg/sarg_schedule.xml | 3 ++- 7 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 config/sarg/sarg.priv.inc (limited to 'config') diff --git a/config/sarg/sarg.inc b/config/sarg/sarg.inc index 2bcd4115..0927b164 100644 --- a/config/sarg/sarg.inc +++ b/config/sarg/sarg.inc @@ -139,6 +139,9 @@ function sync_package_sarg() { if (!preg_match("/\w+/",$_POST['__csrf_magic'])) return; } + #check pkg.php sent a sync request + + $update_conf=0; #mount filesystem writeable conf_mount_rw(); @@ -246,12 +249,26 @@ 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="/usr/local/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 include("/usr/local/pkg/sarg.template"); diff --git a/config/sarg/sarg.priv.inc b/config/sarg/sarg.priv.inc new file mode 100644 index 00000000..2de21519 --- /dev/null +++ b/config/sarg/sarg.priv.inc @@ -0,0 +1,12 @@ + \ No newline at end of file diff --git a/config/sarg/sarg.template b/config/sarg/sarg.template index affcdfc2..41c2b2cf 100644 --- a/config/sarg/sarg.template +++ b/config/sarg/sarg.template @@ -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 diff --git a/config/sarg/sarg.xml b/config/sarg/sarg.xml index f1ce5d93..75694601 100644 --- a/config/sarg/sarg.xml +++ b/config/sarg/sarg.xml @@ -112,6 +112,11 @@ /usr/local/pkg/ 0755 + + http://www.pfsense.org/packages/config/sarg/sarg.priv.inc + /etc/inc/priv/ + 0755 + General diff --git a/config/sarg/sarg_frame.php b/config/sarg/sarg_frame.php index 73e3a469..13235b21 100755 --- a/config/sarg/sarg_frame.php +++ b/config/sarg/sarg_frame.php @@ -38,21 +38,32 @@ 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); +if (file_exists("{$dir}/{$url}")) { - $report=file_get_contents("/usr/local/www/sarg-reports/".$url); + $report=file_get_contents("{$dir}/{$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]='//'; - $replace[3]=''; + $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]='//'; + $replace[4]=''; + + #look for graph files inside reports. + if (preg_match_all('/img src="([a-zA-Z0-9._-]+).png/',$report,$images)){ + for ($x=0;$xError: Could not find report index file.
Check sarg settings and try to force sarg schedule."; + print "
Error: Could not find report index file.
Check and save sarg settings and try to force sarg schedule."; } ?> \ No newline at end of file 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/*'); ?> diff --git a/config/sarg/sarg_schedule.xml b/config/sarg/sarg_schedule.xml index 3d065a7a..15527701 100644 --- a/config/sarg/sarg_schedule.xml +++ b/config/sarg/sarg_schedule.xml @@ -111,7 +111,8 @@ Description description - + + arrow -- cgit v1.2.3