---- cgi-bin/squidguardmgr.cgi.orig	2015-01-23 17:14:48.000000000 +0100
-+++ cgi-bin/squidguardmgr.cgi	2015-03-21 21:08:52.000000000 +0100
+--- cgi-bin/squidguardmgr.cgi.orig	2015-04-11 12:27:37.478461786 +0200
++++ cgi-bin/squidguardmgr.cgi	2015-04-10 22:45:29.000000000 +0200
 @@ -14,6 +14,62 @@
  
  use strict qw{vars subs};

 if ($ACTION eq 'squid') {
 	if ($SQUID_WRAPPER) {
-		$ERROR = `$SQUID_WRAPPER`;
+		$ERROR = `su squid -c $SQUID_WRAPPER 2>&1`;
 	}
 	$ACTION = '';
 }
@@ -928,7 +983,7 @@
 			map { s/^/\+/; } @add;
 			print OUT join("\n", @add), "\n";
 			close OUT;
-			print `$SQUIDGUARD -u $file.tmpdiff`;
+			print `su squid -c $SQUIDGUARD -u $file.tmpdiff`;
 			unlink("$file.tmpdiff");
 		} else {
 			&error("Can't open $file.tmpdiff for writing: $!<br>");
@@ -993,7 +1048,7 @@
 				map { s/^/\-/; } @removed;
 				print OUT join("\n", @removed), "\n";
 				close OUT;
-				print `$SQUIDGUARD -u $file.tmpdiff`;
+				print `su squid -c $SQUIDGUARD -u $file.tmpdiff`;
 				unlink("$file.tmpdiff");
 			} else {
 				&error("Can't open $file.tmpdiff for writing: $!");
@@ -2634,7 +2689,7 @@
 		# Create a diff file
 		if ($DIFF) {
 			`$DIFF -U 0 $CONFIG->{dbhome}/$bl $CONFIG->{dbhome}/$bl.tmp  | $GREP -v "^\@\@" | $GREP -v "^--- " | $GREP -v "^+++ " > $CONFIG->{dbhome}/$bl.tmpdiff`;
-			print `$SQUIDGUARD -u $CONFIG->{dbhome}/$bl.tmpdiff`;
+			print `su squid -c $SQUIDGUARD -u $CONFIG->{dbhome}/$bl.tmpdiff`;
 			# Save diff into the historical file.
 			if ($KEEP_DIFF) {
 				if (open(IN, "$CONFIG->{dbhome}/$bl.tmpdiff")) {
@@ -3586,9 +3641,9 @@
 	my $bl = shift;
 
 	if ($bl eq 'all') {
-		$ERROR = `$SQUIDGUARD -C all`;
+		$ERROR = `su squid -c SQUIDGUARD -C all`;
 	} else {
-		$ERROR = `$SQUIDGUARD -C $bl`;
+		$ERROR = `su squid -c $SQUIDGUARD -C $bl`;
 	}
 }
 

 our $IMG_DIR    = 'images';
 our $CSS_FILE   = 'squidguardmgr.css';
 our $JS_FILE    = 'squidguardmgr.js';
@@ -48,7 +103,7 @@
 our $SQUID_WRAPPER = '/var/www/squidguardmgr/squid_wrapper';
 our $C_ICAP_SOCKET = '/var/run/c-icap/c-icap.ctl';
 our $KEEP_DIFF  = 1;
-our $BLUMASK    = 0027;
+our $BLUMASK    = 0022;
 
 # Configuration file
 my $SGM_CONF    = 'squidguardmgr.conf';
@@ -161,7 +216,7 @@
 	if ($VIEW eq 'squid') {
 		if ($SQUID_WRAPPER) {
 			print "Running: $SQUID_WRAPPER ... \n";
-			$ERROR = `$SQUID_WRAPPER 2>&1`;
+			$ERROR = `su squid -c "$SQUID_WRAPPER 2>&1"`;
 			&error($ERROR) if ($ERROR);
 			print "Ok." if (!$ERROR);
 		}
