  if ($ACTION eq 'squid') {
  	if ($SQUID_WRAPPER) {
 -		$ERROR = `$SQUID_WRAPPER`;
-+		$ERROR = `su squid -c $SQUID_WRAPPER 2>&1`;
++		$ERROR = `su squid -c "$SQUID_WRAPPER 2>&1"`;
  	}
  	$ACTION = '';
  }
-@@ -928,7 +983,7 @@
+@@ -924,14 +979,14 @@
+ 	}
+ 	if (-e "$file.db") {
+ 		# Now load these items dynamically into squidGuard
+-		if (open(OUT, ">$file.tmpdiff")) {
++		if (open(OUT, ">$file.diff")) {
  			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");
+-			unlink("$file.tmpdiff");
++			$ERROR = `su squid -c "$SQUIDGUARD -u"`;
++			unlink("$file.diff");
  		} else {
- 			&error("Can't open $file.tmpdiff for writing: $!<br>");
-@@ -993,7 +1048,7 @@
+-			&error("Can't open $file.tmpdiff for writing: $!<br>");
++			&error("Can't open $file.diff for writing: $!<br>");
+ 		}
+ 	} else {
+ 		$file =~ s#$CONFIG->{dbhome}/##;
+@@ -989,14 +1044,14 @@
+ 		}
+ 		if (-e "$file.db") {
+ 			# Now load these items dynamically into squidGuard
+-			if (open(OUT, ">$file.tmpdiff")) {
++			if (open(OUT, ">$file.diff")) {
  				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");
+-				unlink("$file.tmpdiff");
++				$ERROR = `su squid -c "$SQUIDGUARD -u"`;
++				unlink("$file.diff");
  			} else {
- 				&error("Can't open $file.tmpdiff for writing: $!");
-@@ -2634,7 +2689,7 @@
+-				&error("Can't open $file.tmpdiff for writing: $!");
++				&error("Can't open $file.diff for writing: $!");
+ 			}
+ 		} else {
+ 			$file =~ s#$CONFIG->{dbhome}/##;
+@@ -2633,11 +2688,11 @@
+ 	if (-e "$CONFIG->{dbhome}/$bl") {
  		# 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`;
+-			`$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`;
++			`su squid -c "$DIFF -U 0 $CONFIG->{dbhome}/$bl $CONFIG->{dbhome}/$bl.tmp  | $GREP -v '^\@\@' | $GREP -v '^--- ' | $GREP -v '^+++ ' > $CONFIG->{dbhome}/$bl.diff"`;
++			$ERROR = `su squid -c "$SQUIDGUARD -u"`;
  			# Save diff into the historical file.
  			if ($KEEP_DIFF) {
- 				if (open(IN, "$CONFIG->{dbhome}/$bl.tmpdiff")) {
+-				if (open(IN, "$CONFIG->{dbhome}/$bl.tmpdiff")) {
++				if (open(IN, "$CONFIG->{dbhome}/$bl.diff")) {
+ 					my @text = <IN>;
+ 					close(IN);
+ 					if (open(OUT, ">>$CONFIG->{dbhome}/$bl.diff.hist")) {
+@@ -2647,10 +2702,10 @@
+ 						&error("Can't write to file $CONFIG->{dbhome}/$bl.diff.hist: $!");
+ 					}
+ 				} else {
+-					&error("Can't read file $CONFIG->{dbhome}/$bl.tmpdiff: $!");
++					&error("Can't read file $CONFIG->{dbhome}/$bl.diff: $!");
+ 				}
+ 			}
+-			unlink("$CONFIG->{dbhome}/$bl.tmpdiff");
++			unlink("$CONFIG->{dbhome}/$bl.diff");
+ 		}
+ 		unlink("$CONFIG->{dbhome}/$bl");
+ 		$delbl = 1 if ($nline == 0);
 @@ -3586,9 +3641,9 @@
  	my $bl = shift;
  
  	if ($bl eq 'all') {
 -		$ERROR = `$SQUIDGUARD -C all`;
-+		$ERROR = `su squid -c SQUIDGUARD -C all`;
++		$ERROR = `su squid -c "$SQUIDGUARD -C all"`;
  	} else {
 -		$ERROR = `$SQUIDGUARD -C $bl`;
-+		$ERROR = `su squid -c $SQUIDGUARD -C $bl`;
++		$ERROR = `su squid -c "$SQUIDGUARD -C $bl"`;
  	}
  }
  

--- 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
@@ -14,6 +14,62 @@
 
 use strict qw{vars subs};

 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);
 		}
