Subversion Repositories ALCASAR

Rev

Rev 2647 | Rev 2662 | Go to most recent revision | Blame | Compare with Previous | 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 WL 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;
}
function form_filter_ip($form_content, $color)
{
        //# reconstruction des ip
        $list = explode("\n", form_filter($form_content));
        $new_list = "";
        foreach($list as &$value)
        {
                if(preg_match('/([0-9]{1,3}.){3}[0-9]{1,3}/', $value))
                {
                        $new_list = $new_list.$value."\n";
                }
        }
        if($color == "white")
        {
                return preg_replace("/(.*)\n/", "add wl_ip_allowed $1\n", $new_list);
        }
        else
        {
                return preg_replace("/(.*)\n/", "add bl_ip_blocked $1\n", $new_list);
        }
}
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 "$filename doesn't exist";
                }
        }
function echo_ip_file ($filename)
{
        $filename = escapeshellarg($filename);
        exec("cat $filename | cut -d ' ' -f3", $resultat);
        for($i=0; $i<exec("wc -l $filename"); $i++)
        {
                echo $resultat[$i]."\n";
        }
}

# 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_wl="Liste blanche générale";
        $l_load="Chargement...";
        $l_list_version="Version de la liste : ";
        $l_wl_categories="Sélectionnez les catégories à autoriser";
        $l_specific_filtering="Filtrage special";
        $l_add_to_wl="Noms de domaine ou adresses IP à ajouter à la liste blanche";
        $l_one_dns_ip="Entrez un nom de domaine ou une adresse IP ou une adresse de réseau par ligne<br>exemple (domaine) : .domaine.org - exemple (ip) : 61.54.52.56 - exemple (réseau) : 172.16.0.0/16";
        $l_record="Enregistrer les modifications";
        $l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
        $l_safe_searching="Activer le contrôle scolaire/parental des moteurs de recherche Google, Bing et Youtube.";
        $l_error_open_file="Erreur d'ouverture du fichier";
        $l_additional_file_title="Fichiers de 'listes blanches' additionnels";
        $l_file_list="Liste des fichiers";
        $l_add_file="Ajouter un fichier";
        $l_add_file_explain="Chaque ligne du fichier doit être une adresse IP ou un nom de domaine";
        $l_file_name="Nom du fichier";
        $l_file_action="Action";
        $l_error_upload="Erreur d'envoi du fichier";
        $l_remove="Supprimer";
        $l_submit="Envoyer";
        $l_nb_ip="Nombre d'IP";
        $l_nb_domain_names="Nombre de noms de domaine";
        $l_nbDomainNames="Noms de domaine :";
        $l_nbUrl="Url :";
        $l_nbIp="Ip :";
        $l_disable="Désactiver";
        $l_enable="Activer";
        $l_file_state="Etat";
}
else {
        $l_wl="General WhiteList";
        $l_load="Loading...";
        $l_list_version="List version : ";
        $l_wl_categories="Select the allowed categories";
        $l_specific_filtering="Specific filtering";
        $l_allowed_dns="Allowed domain names";
        $l_add_to_wl="Domain names or IP addresses to add to the whitelist";
        $l_one_dns_ip="Enter one domain name or one IP address or one network address per row <br>example (domain): .domain.org - example (ip): 61.54.56.52 - example (network) : 172.16.0.0/16";
        $l_record="Save changes";
        $l_wait="Once validated, 10 seconds are necessary to compute your modifications";
        $l_safe_searching="Enabling school/parental control for the search engines Google, Bind and Youtube";
        $l_error_open_file="Error opening file";
        $l_additional_file_title="Additional WhiteList files";
        $l_file_list="Files list";
        $l_add_file="Add a file";
        $l_add_file_explain="Each line of the file must be an IP address or a domain name";
        $l_file_name="Filename";
        $l_file_action="Action";
        $l_error_upload="Error during the upload process";
        $l_remove="Delete";
        $l_submit="Submit";
        $l_nb_ip="Number of IP";
        $l_nb_domain_names="Number of domain names";
        $l_nbDomainNames="Domain names :";
        $l_nbUrl="Url :";
        $l_nbIp="Ip :";
        $l_disable="Disable";
        $l_enable="Enable";
        $l_file_state="State";
}
$dir_etc="/usr/local/etc/";
$dir_dg="/etc/e2guardian/lists/";
$dir_blacklist=$dir_dg."blacklists/";
$dir_wl_ip="/usr/local/share/iptables-wl/";
$dir_wl_ip_enabled= "/usr/local/share/iptables-wl-enabled/";
$dir_wl_domain_names= "/usr/local/share/dnsmasq-wl/";
$dir_wl_domain_names_enabled= "/usr/local/share/dnsmasq-wl-enabled/";
$wl_categories=$dir_etc."alcasar-wl-categories";
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
$conf_file=$dir_etc."alcasar.conf";
$iptables_safesearch_file=$dir_wl_ip_enabled."ossi-ip-safesearch";
$bannedsite_file=$dir_dg."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] == "PRIVATE_IP")
                                {
                                $PRIVATE_IP_MASK=trim($field[1]);
                                $tmp = explode("/",$PRIVATE_IP_MASK);
                                $PRIVATE_IP=$tmp[0];
                                }
                        }
                }
        }
else { echo "$l_error_open_file $conf_file";}
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
switch ($choix)
{
case 'Download_list' :
        exec ("sudo /usr/local/bin/alcasar-bl.sh --download");
        break;
case 'Active_list' :
        exec ("sudo /usr/local/bin/alcasar-bl.sh --adapt");
        exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
        break;
case 'Reject_list' :
        unlink ("$dir_tmp/blacklists.tar.gz"); unlink ("$dir_tmp/md5sum");
        break;
case 'MAJ_cat_wl' :
        if (file_exists($wl_categories_enabled))
        {
                exec("/bin/sed -i \"/^ossi-/!d\" $wl_categories_enabled"); // keep ossi custom categories
                $pointeur=fopen($wl_categories_enabled, "a+");
                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($dir_blacklist."ossi-wl/domains","w+");
        fputs($fichier, form_filter($_POST['OSSI_wl']));
        fclose($fichier);
        unset($_POST['OSSI_wl']);
        exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
        break;
case 'Specific_filtering' :
        $safesearch="-safesearch_off"; ;
        foreach ($_POST as $key => $value)
        {
                if (strstr($key,'chk-safesearch')) $safesearch="-safesearch_on";
        }
        exec ("sudo /usr/local/bin/alcasar-url_filter_wl.sh $safesearch");
        break;
case 'MAJ_ossi_file' :
        foreach($_POST as $fichier => $value)
        {
                if($fichier != "choix")
                {
                        $action=$_POST[$fichier];
                        if($action == $l_remove) //delete
                        {
                                exec("/bin/sed -i ".escapeshellarg("/^$fichier\$/d")." $wl_categories_enabled");
                                exec("/bin/sed -i ".escapeshellarg("/^$fichier\$/d")." $wl_categories");
                                exec("rm -rf ".escapeshellarg("$dir_blacklist$fichier"));
                                exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
                        }
                        if($action == $l_disable) //disable
                        {
                                exec("/bin/sed -i ".escapeshellarg("/^$fichier\$/d")." $wl_categories_enabled");
                                exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
                        }
                        if($action == $l_enable) //enable
                        {
                                file_put_contents($wl_categories_enabled, $fichier."\n", FILE_APPEND);
                                exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
                        }
                }
        }
        break;
case 'MAJ_ossi_file_upload' :
        $file_name = str_replace (".", "_",basename($_FILES['fichier_ip']['name']));
        if(!empty($file_name))
        {
                $dest_dir = $dir_blacklist."ossi-wl-".$file_name;
                exec("mkdir ".escapeshellarg($dest_dir));
                $file=$_FILES['fichier_ip']['tmp_name'];
                exec('/usr/bin/dos2unix '.escapeshellarg($file));
                if(move_uploaded_file($_FILES['fichier_ip']['tmp_name'], $dest_dir."/domains"))
                {
                        touch ($dest_dir."/urls"); // create the URL file even if it isn't used
                        file_put_contents ($wl_categories, $dest_dir."\n", FILE_APPEND);
                        file_put_contents ($wl_categories_enabled, "ossi-wl-".$file_name."\n", FILE_APPEND); //Enabled by default
                        exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
                }
                else
                {
                        exec("rm -rf ".escapeshellarg($dest_dir));
                        echo $l_error_upload;
                }
        }
        break;
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo $l_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='wl_filter.php' method=POST>
<input type='hidden' name='choix' value='MAJ_cat_wl'>
<?php
echo "<center>";
// total number of IP, DNS & URLs
$nbDomainNames = exec("wc -l /usr/local/share/dnsmasq-wl/* | tail -n 1 | awk '{print $1}'");
$nbUrl = "0";
$nbIp = exec("wc -l /usr/local/share/iptables-wl/* | tail -n 1 | awk '{print $1}'");
echo "<b>$l_nbDomainNames</b> $nbDomainNames, <b>$l_nbUrl</b> $nbUrl, <b>$l_nbIp</b> $nbIp<br/>";
echo "$l_wl_categories</center></td></tr>";
//read & display all WL categories (checked or not)
$cols=1;
if (file_exists($wl_categories))
        {
        $wl_files = file($wl_categories);
        $wl_files = preg_grep("/ossi-/", $wl_files, 1); // don't display ossi custom categories
        foreach($wl_files as $fichier => $value)
                {
                if ($cols == 1) { echo "<tr>";}
                $categorie=trim(basename($value));
                echo "<td><a href='bl_categories_help.php?liste=wl&cat=$categorie' target='cat_help' onclick=window.open('bl_categories_help.php','cat_help','width=600,height=450,toolbar=no,scrollbars=yes,resizable=yes') title='categories help page'>$categorie</a><br>";
                echo "<input type='checkbox' name='chk-$categorie'";
                // if the line is commented, the category is disable
                if (preg_match('/^#/',$value, $r)) { echo ">";}
                else { echo "checked>"; }
                echo "</td>";
                $cols++;
                if ($cols > 10) {
                        echo "</tr>";
                        $cols=1; }
                }
        }
else    {
        echo "$l_error_open_file $wl_categories";
}
echo "<tr><td valign='middle' align='left' colspan=10>";
echo "<center><b>$l_add_to_wl</b></center></td></tr>";
echo "<tr><td width=100% colspan=10 align=center>";
echo "$l_one_dns_ip<BR>";
echo "<textarea name='OSSI_wl' rows=3 cols=40>";
echo_file ($dir_blacklist."ossi-wl/domains");
echo "</textarea></td>";
echo "</tr><tr><td colspan=10>";
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';submit();\" value='$l_record'>";
echo "</form> ($l_wait)";
echo "</td></tr></table><br/>";
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo $l_additional_file_title; ?></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>
<form action='wl_filter.php' method='POST'>
<input type='hidden' name='choix' value='MAJ_ossi_file'>
<?php
echo "<tr><td width=50% colspan=5 align=center>";
echo "<H3>$l_file_list</H3>";
echo "<table cellspacing=2 cellpadding=3 border=1><tr><th>$l_file_name<th>$l_nb_ip<th>$l_nb_domain_names<th colspan=2>$l_file_action</tr>";

//list OSSI custom categories
$fichierswl = array_diff(scandir($dir_blacklist), array('..','.','ossi-bl','ossi-wl'));
$fichierswl = preg_grep("/^ossi-wl-/",$fichierswl);
foreach($fichierswl as $fichier => $value)
{
        echo "<tr><td><center><a href='bl_categories_help.php?liste=wl&cat=$value&filtre=domain' target='cat_help' onclick=window.open('bl_categories_help','cat_help','width=600,height=450,toolbar=no,scrollbars=yes,resizable=yes') title='categories help page'>".substr($value,8)."</a></center></td><td><center>".exec("wc -l $dir_wl_ip$value | cut -d\" \" -f1")."</center></td><td><center>".exec("wc -l $dir_wl_domain_names$value.conf | cut -d\" \" -f1")."</center></td><td><center><input type='submit' name='$value'";
        if (file_exists ($dir_wl_domain_names_enabled.$value)) echo " value='$l_disable'>"; else echo " value='$l_enable'>";
        echo "</center></td><td><center><input type='submit' name='$value' value='$l_remove'></center></td></tr>";
}
echo "</table><br/></td></form><form action='wl_filter.php' method='POST' enctype='multipart/form-data'>";
echo "<input type='hidden' name='choix' value='MAJ_ossi_file_upload'><td width=50% colspan=5 align=center>";
echo "<H3>$l_add_file</H3>";
echo "$l_add_file_explain";
echo "<input type='file' name='fichier_ip'>";
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';submit();\" value='$l_submit'>";
echo "</td></tr>";
echo "</form>";
echo "</table><br/>";
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr><th><?php echo $l_specific_filtering; ?></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>
<FORM action='wl_filter.php' method='POST'>
<input type='hidden' name='choix' value='Specific_filtering'>
<tr><td>
<input type='checkbox' name='chk-safesearch'
<?php
// verify "safesearch" filtering state
if (file_exists($iptables_safesearch_file))
{
        echo " checked";
}
echo "> $l_safe_searching<tr><td>";
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';submit();\" value='$l_record'></td></tr>";
?>
</FORM>
</TABLE>
</BODY>
</HTML>