From: Frederic Marchal Date: Wed, 21 May 2014 19:42:03 +0000 (+0200) Subject: Clean up sarg-php HTML and report more errors X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ecaa076bd3f09df7f479253b1e7f48672a87c0f6;p=thirdparty%2Fsarg.git Clean up sarg-php HTML and report more errors The original HTML was the bare minimum and no error messages were printed. This patch should fix it if only someone could test it. --- diff --git a/sarg-php/sarg-squidguard-block.php b/sarg-php/sarg-squidguard-block.php index e28deca..806b27b 100755 --- a/sarg-php/sarg-squidguard-block.php +++ b/sarg-php/sarg-squidguard-block.php @@ -52,48 +52,92 @@ if (!isset($_GET['url'])) $url = $_GET['url']; function parse_config($line,$clave) { - if (preg_match("/dbhome/i", $line)) { - global $dbhome; - $l = explode(' ', $line); - list(, $dbhome) = $l; - $dbhome=preg_replace('/\s+/','',$dbhome); - } + if (preg_match("/dbhome/i", $line)) { + global $dbhome; + $l = explode(' ', $line); + list(, $dbhome) = $l; + $dbhome=preg_replace('/\s+/','',$dbhome); + } } -echo "
\n"; -echo "\n"; -echo "\n"; -echo "\n"; -echo "
"; -print(gettext ("Sarg-SquidGuard - URL Blocking")); -echo "
"; -printf(gettext("Choose the rule set where %s will be added"),"$url "); -echo "
\n"; -echo "\n"; - $lines=file($squidGuardConf); array_walk($lines,'parse_config'); -if (is_dir($dbhome)) { - if ($ha1 = opendir($dbhome)) { - while (false !== ($file = readdir($ha1))) { - if ($file == '.' || $file == '..') continue; - echo "\n"; - $dir2 = $dbhome.'/'.$file; - if (is_dir($dir2)) { - if ($ha2 = opendir($dir2)) { - while (false !== ($file2 = readdir($ha2))) { - if ($file2 == '.' || $file2 == '..') continue; - echo "\n"; - } - } - closedir($ha2); - } - } - closedir($ha1); - } -} +?> + + + + +<?php echo gettext("Sarg-SquidGuard - URL Blocking")?> + + +
+
$file
$file2
+ + +
+$url")?>
+\n"; -echo "\n"; +if (!is_dir($dbhome)) +{ + echo "

"; + printf(gettext("The path %s (which is supposed to be the squidGuard DB home) is not a directory"),$dbhome); + echo "

\n"; +} +else +{ + $ha1 = opendir($dbhome); + if ($ha1) + { + $table=false; + while (false !== ($file = readdir($ha1))) + { + if ($file == '.' || $file == '..') continue; + $dir2 = $dbhome.'/'.$file; + if (is_dir($dir2)) + { + if ($ha2 = opendir($dir2)) + { + $first=true; + while (false !== ($file2 = readdir($ha2))) + { + if ($file2 == '.' || $file2 == '..') continue; + if (!$table) + { + echo "\n"; + $table=true; + } + if ($first) + { + echo "\n"; + $first=false; + } + echo "\n"; + } + } + closedir($ha2); + } + } + closedir($ha1); + if ($table) + { + echo "
$file
$file2
\n"; + } + else + { + echo "

"; + printf(gettext("No squidGuard rule found in %s"),$dbhome); + echo "

\n"; + } + } + else + { + echo "

"; + printf(gettext("Cannot read squidGuard DB home directory %s"),$dbhome); + echo "

\n"; + } +} ?> + + diff --git a/sarg-php/sarg-squidguard-block2.php b/sarg-php/sarg-squidguard-block2.php index e717e03..529845b 100755 --- a/sarg-php/sarg-squidguard-block2.php +++ b/sarg-php/sarg-squidguard-block2.php @@ -40,10 +40,6 @@ if (!isset($_GET['url'])) } $url = $_GET['url']; $url = $url."\n"; -if (isset($_GET['lang'])) -{ - $language = $_GET['lang']; -} putenv("LANG=$language"); if (!setlocale(LC_ALL, $language)) @@ -57,19 +53,51 @@ $domain = 'messages'; bindtextdomain($domain, "./locale"); textdomain($domain); +function parse_config($line,$clave) { + if (preg_match("/dbhome/i", $line)) { + global $dbhome; + $l = explode(' ', $line); + list(, $dbhome) = $l; + $dbhome=preg_replace('/\s+/','',$dbhome); + } +} + +global $dbhome; +$lines=file($squidGuardConf); +array_walk($lines,'parse_config'); +$file=$dbhome.'/'.$file; + +?> + + + + +<?php echo gettext("Sarg-SquidGuard - URL Blocking")?> + + +"; + printf(gettext("Could not open file: %s"),$file); + echo "

\n"; + exit; } -else { - $written = fwrite($ha, $url); - fclose($ha); - if ($written != strlen($url)) { - print (gettext ("Write error")); - exit; - } - print (gettext ("Done!")); - echo "

\n"; - printf(gettext("Return to Sarg."),"javascript:history.go(-2)"); + +$written = fwrite($ha, $url); +fclose($ha); +if ($written != strlen($url)) +{ + echo "

"; + echo gettext("Write error"); + echo "

\n"; + exit; } + +echo "

",gettext("Done!"),"

\n

"; +printf(gettext("Return to Sarg."),"javascript:history.go(-2)"); +echo "

\n"; +?> +