Subversion Repositories ALCASAR

Rev

Go to most recent revision | Blame | Last modification | View Log

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><!-- written by Rexy -->
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<TITLE>ALCASAR DNS filtering</TITLE>
<link rel="stylesheet" href="/css/style.css" type="text/css">
</HEAD>
<body>
<?
function form_filter ($form_content)
{
// réencodage iso + format unix + rc fin de ligne (ouf...)
        $list = str_replace("\r\n", "\n", utf8_decode($form_content));
        if (strlen($list) != 0){
                if ($list[strlen($list)-1] != "\n") { $list[strlen($list)]="\n";} ;} ;
        return $list;
}
# Choice of language
$Language = 'en';
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
if($Language == 'fr'){
  $l_error_open_file="Erreur d'ouverture du fichier";
  $l_main_wl="Liste blanche";
  $l_bl_version="Version actuelle :";
  $l_wl_categories="Choix des catégories à autoriser";
  $l_forbidden_dns="Noms de domaine filtrés";
  $l_forbidden_dns_explain="Entrez un nom de domaine par ligne (exemple : .domaine.org)";
  $l_one_dns="Entrez un nom de domaine par ligne (exemple : .domaine.org)";
  $l_add_to_bl="Noms de domaine ou URLs ajoutés à la liste noire";
  $l_forbidden_url="URL filtrés";
  $l_forbidden_url_explain="Entrez une URL par ligne (exemple : www.domaine.org/perso/index.htm)";
  $l_record="Enregistrer les modifications";
  $l_wait="Une fois validées, 30 secondes sont nécessaires pour traiter vos modifications";
}
else {
  $l_error_open_file="Error opening the file";
  $l_main_wl="Whitelist";
  $l_bl_version="Current version : ";
  $l_wl_categories="Choice of authorized categories";
  $l_forbidden_dns="Filtered domain names";
  $l_forbidden_dns_explain="Enter one domain name per row (exemple : .domain.org)";
  $l_one_dns="Enter one domain name per row (example : .domain.org)";
  $l_add_to_bl="Domain names or URLs to add to blacklist";
  $l_forbidden_url="Filtered URL";
  $l_forbidden_url_explain="Enter one URL per row (example : www.domaine.org/perso/index.htm)";
  $l_record="Save changes";
  $l_wait="Once validated, 30 seconds is necessary to compute your modifications";
}
$wl_categories="/usr/local/etc/alcasar-wl-categories";
$wl_categories_enabled="/usr/local/etc/alcasar-wl-categories-enabled";
$dir_blacklist="/etc/dansguardian/lists/blacklist/";
$conf_file="/usr/local/etc/alcasar.conf";
$urlregex_file="/etc/dansguardian/lists/urlregexplist";
$bannedsite_file="/etc/dansguardian/lists/bannedsitelist";
$dir_tmp="/tmp/blacklists";
# default values
if (is_file ($conf_file))
        {
        $tab=file($conf_file);
        if ($tab)
                {
                foreach ($tab as $line)
                        {
                        $field=explode("=", $line);
                        if ($field[0] == "DNS_FILTERING")       {$DNS_FILTERING=trim($field[1]);}
                        }
                }
        }
else { echo "$l_error_open_file $conf_file";}
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
switch ($choix)
{
case 'MAJ_cat' :
        $tab=file($wl_categories_enabled);      
        if ($tab)
                {
                $pointeur=fopen($wl_categories_enabled, "w+");
                foreach ($_POST as $key => $value)
                        {
                        if (strstr($key,'chk-'))
                                {       
                                $line=str_replace('chk-','',$key)."\n";
                                fwrite($pointeur,$line);
                                }
                        }
                fclose($pointeur);
                }
        else {echo "$l_error_open_file $wl_categories_enabled";}
        $fichier=fopen("/etc/dansguardian/lists/blacklists/ossi/domains","w+");
        fputs($fichier, form_filter($_POST['OSSI_bl_domains']));
        fclose($fichier);
        unset($_POST['OSSI_bl_domains']);
        $fichier=fopen("/etc/dansguardian/lists/exceptionsitelist","w+");
        fputs($fichier, form_filter($_POST['OSSI_wl_domains']));
        fclose($fichier);
        unset($_POST['OSSI_wl_domains']);
        $fichier=fopen("/etc/dansguardian/lists/blacklists/ossi/urls","w+");
        fputs($fichier, form_filter($_POST['OSSI_bl_urls']));
        fclose($fichier);
        unset($_POST['OSSI_bl_urls']);
        $fichier=fopen("/etc/dansguardian/lists/exceptionurllist","w+");
        fputs($fichier, form_filter($_POST['OSSI_wl_urls']));
        fclose($fichier);
        unset($_POST['OSSI_wl_urls']);
        exec ("sudo /usr/local/sbin/alcasar-bl.sh --reload");
        break;
}

function echo_file ($filename)
        {
        if (file_exists($filename))
                {
                if (filesize($filename) != 0)
                        {
                        $pointeur=fopen($filename,"r");
                        $tampon = fread($pointeur, filesize($filename));
                        fclose($pointeur);
                        echo $tampon;
                        }
                }
        else
                {
                echo "$l_error_openfile $filename";
                }
        }
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo $l_main_wl; ?></th></tr>
        <tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
</table>
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
<tr><td valign="middle" align="left" colspan=10>
<FORM action='dns_filter.php' method=POST>
<input type='hidden' name='choix' value='MAJ_cat'>
<?php
echo "<center>$l_wl_categories</center></td></tr>";
//on lit et on interprete le fichier de catégories
$cols=1; 
if (file_exists($wl_categories))
        {
        $pointeur=fopen($wl_categories,"r");
        while (!feof ($pointeur))
                {
                $ligne=fgets($pointeur, 4096);
                if ($ligne)
                        {
                        if ($cols == 1) { echo "<tr>";}
                        $categorie=trim(basename($ligne));
                        echo "<td><a href='bl_categories_help.php?cat=$categorie' target='cat_help' onclick=window.open('bl_categories_help.php','cat_help','width=600,height=150,toolbar=no,scrollbars=no,resizable=yes') title='categories help page'>$categorie</a><br>";
                        echo "<input type='checkbox' name='chk-$categorie'";
                        // si la ligne est commentée -> categorie non selectionnée
                        if (preg_match('/^#/',$ligne, $r)) { echo ">";}
                        else { echo "checked>"; }
                        echo "</td>";
                        $cols++;
                        if ($cols > 10) {
                                echo "</tr>";
                                $cols=1; }
                        }
                }
        fclose($pointeur);
        }
else    {
        echo "$l_error_open_file $wl_categories";
        }
echo "<tr><td valign='middle' align='left' colspan=10>";
echo "<center><b>$l_add_to_bl</b></center></td></tr>";
echo "<tr><td colspan=5 align=center>";
echo "<H3>$l_forbidden_dns</H3>$l_forbidden_dns_explain<BR>";
echo "<textarea name='OSSI_bl_domains' rows=5 cols=40>";
echo_file ("/etc/dansguardian/lists/blacklists/ossi/domains");
echo "</textarea></td>";
echo "<td colspan=5 align=center>";
echo "<H3>$l_forbidden_url</H3>$l_forbidden_url_explain<BR>";
echo "<textarea name='OSSI_bl_urls' rows=5 cols=40>";
echo_file ("/etc/dansguardian/lists/blacklists/ossi/urls");
echo "</textarea></td></tr><tr><td colspan=10>";
echo "<input type='submit' value='$l_record'>";
echo "</form> ($l_wait)";
?>
</td></tr>
</TABLE>
</BODY>
</HTML>