"Fossies" - the Fresh Open Source Software Archive

Member "sarg-2.4.0/sarg-php/sarg-squidguard-block.php" (22 Dec 2019, 3800 Bytes) of package /linux/privat/sarg-2.4.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "sarg-squidguard-block.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.3.11_vs_2.4.0.

    1 <?php
    2 
    3 /*
    4  * AUTHOR: Pedro Lineu Orso                         pedro.orso@gmail.com
    5  *                                                            1998, 2006
    6  * SARG Squid Analysis Report Generator            http://sarg-squid.org
    7  *
    8  * SARG donations:
    9  *      please look at http://sarg.sourceforge.net/donations.php
   10  * ---------------------------------------------------------------------
   11  *
   12  *  This program is free software; you can redistribute it and/or modify
   13  *  it under the terms of the GNU General Public License as published by
   14  *  the Free Software Foundation; either version 2 of the License, or
   15  *  (at your option) any later version.
   16  *
   17  *  This program is distributed in the hope that it will be useful,
   18  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   19  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   20  *  GNU General Public License for more details.
   21  *
   22  *  You should have received a copy of the GNU General Public License
   23  *  along with this program; if not, write to the Free Software
   24  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
   25  *
   26  */
   27 
   28 require_once "config.php.inc";
   29 require_once "url_validator.php.inc";
   30 
   31 global $SargConf;
   32 global $dbhome;
   33 
   34 putenv("LANG=$language");
   35 if (!setlocale(LC_ALL, $language))
   36 {
   37     echo "<p>";
   38     printf(gettext("Invalid locale: %s"),$language);
   39     echo "</p>\n";
   40     exit;
   41 }
   42 $domain = 'messages';
   43 bindtextdomain($domain, "./locale");
   44 textdomain($domain);
   45 include_once("style.php");
   46 
   47 if (!isset($_GET['url']))
   48 {
   49     echo "<p>",gettext("No URL to block"),"</p>\n";
   50     exit;
   51 }
   52 
   53 $url = $_GET['url'];
   54 if (!check_url($url))
   55 {
   56     echo "<p>",gettext("Invalid URL to block"),"</p>\n";
   57     exit;
   58 }
   59 
   60 function parse_config($line,$clave) {
   61     if (preg_match("/dbhome/i", $line)) {
   62         global $dbhome;
   63         $l = explode(' ', $line);
   64         list(, $dbhome) = $l;
   65         $dbhome=preg_replace('/\s+/','',$dbhome);
   66     }
   67 }
   68 
   69 $lines=file($squidGuardConf);
   70 array_walk($lines,'parse_config');
   71 
   72 ?>
   73 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
   74 <html xmlns="http://www.w3.org/1999/xhtml">
   75 <head>
   76 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
   77 <title><?php echo gettext("Sarg-SquidGuard - URL Blocking")?></title>
   78 </head>
   79 <body>
   80 <center>
   81 <table>
   82 <tr><td class="title"><?php echo gettext("Sarg-SquidGuard - URL Blocking")?></td></tr>
   83 <tr><td class="header2">
   84 <?php printf(gettext("Choose the rule set where %s will be added"),"<a href=\"http://$url\">".htmlspecialchars($url)."</a>")?></td></tr>
   85 </table>
   86 <?php
   87 
   88 if (!is_dir($dbhome))
   89 {
   90     echo "<p>";
   91     printf(gettext("The path <tt>%s</tt> (which is supposed to be the squidGuard DB home) is not a directory"),$dbhome);
   92     echo "</p>\n";
   93 }
   94 else
   95 {
   96     $ha1 = opendir($dbhome);
   97     if ($ha1)
   98     {
   99         $table=false;
  100         while (false !== ($file = readdir($ha1)))
  101         {
  102             if ($file == '.' || $file == '..') continue;
  103             $dir2 = $dbhome.'/'.$file;
  104             if (is_dir($dir2))
  105             {
  106                 if ($ha2 = opendir($dir2))
  107                 {
  108                     $first=true;
  109                     while (false !== ($file2 = readdir($ha2)))
  110                     {
  111                         if ($file2 == '.' || $file2 == '..') continue;
  112                         if (!$table)
  113                         {
  114                             echo "<table>\n";
  115                             $table=true;
  116                         }
  117                         if ($first)
  118                         {
  119                             echo "<tr><td class=\"header\">$file</td></tr>\n";
  120                             $first=false;
  121                         }
  122                         echo "<tr><td class=\"data2\"><a href=\"sarg-squidguard-block2.php?file=",rawurlencode($file.'/'.$file2),"&url=$url\">$file2</a></td></tr>\n";
  123                     }
  124                 }
  125                 closedir($ha2);
  126             }
  127         }
  128         closedir($ha1);
  129         if ($table)
  130         {
  131             echo "</table>\n";
  132         }
  133         else
  134         {
  135             echo "<p>";
  136             printf(gettext("No squidGuard rule found in <tt>%s</tt>"),$dbhome);
  137             echo "</p>\n";
  138         }
  139     }
  140     else
  141     {
  142         echo "<p>";
  143         printf(gettext("Cannot read squidGuard DB home directory %s"),$dbhome);
  144         echo "</p>\n";
  145     }
  146 }
  147 ?>
  148 </html>
  149 </body>