Rev 1867 | Rev 1878 | 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 Whitelist 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));
$line = split("\n", $tampon);
foreach( $line as $x)
{
if(isset(split('/',$x)[1]))
echo split('/',$x)[1]."\n";
}
fclose($pointeur);
}
}
else
{
echo "$filename doesn't exist";
}
}
function echo_ip_file ($filename)
{
exec("cat $filename | cut -d ' ' -f3", $resultat);
for($i=0; $i<exec("wc -l $filename"); $i++)
{
echo $resultat[$i]."\n";
}
}
#maximum length for top-level DNS
function max_tld()
{
$url_tld = "http://data.iana.org/TLD/tlds-alpha-by-domain.txt";
$result_tld = file_get_contents($url_tld,false);
$max_tld = 18; #valeur de base si le site ne répond plus
if($result_tld !== FALSE){
foreach(explode("\n", $result_tld) as $line)
{
if((strpos($line,'-') === false) and (strpos($line,'#') === false))
{
if(strlen($line) > $max_tld)
{
$max_tld = strlen($line);
}
}
}
}
return $max_tld;
}
# 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";
$l_load="Chargement...";
$l_list_version="Version de la liste : ";
$l_specific_filtering="Filtrage special";
$l_wl_categories="Sélectionnez les catégories à autoriser";
$l_allowed_dns="Noms de domaine autorisés";
$l_one_dns="Entrez un nom de domaine par ligne (exemple : .domaine.org)";
$l_add_to_wl="Noms de domaine ou IP ajoutés à la liste blanche";
$l_forbidden_ip_explain="Entrez une IP par ligne (exemple : 123.123.123.123)<br/>ou une adresse de réseau (exemple : 123.123.0.0/16)";
$l_allowed_ip="IP autorisées";
$l_record="Enregistrer les modifications";
$l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
$l_error_open_file="Erreur d'ouverture du fichier";
$l_additional_file_title="Fichiers de 'listes blanche' 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_remove="Supprimer";
$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_ip_filtering="Filtrer les URLs contenant une adresse IP au lieu d'un nom de domaine (ex: http://25.56.58.59/index.htm)";
$l_safe_searching="Activer le contrôle scolaire/parental des moteurs de recherche : google, yahoo, bing, metacrawler et Youtube.";
$l_safe_youtube="Pour Youtube restreint, suivez les étapes ici pour chaque poste : ";
$l_youtube_id="(<a href='https://support.google.com/youtube/answer/174084?hl=fr' target='cat_help' onclick=window.open('https://support.google.com/youtube/answer/174084?hl=fr','cat_help','width=800,height=600,toolbar=no,scrollbars=yes,resizable=yes') title='Youtube for school'>lien pour créer un identifiant Youtube (Id)</a>)";
}
else {
$l_wl="WhiteList";
$l_load="Loading...";
$l_list_version="List version : ";
$l_wl_categories="Select the categories to allow";
$l_allowed_dns="Allowed domain names";
$l_one_dns="Enter one domain name per row (example : .domain.org)";
$l_add_to_wl="Domain names or IP to add to whitelist";
$l_forbidden_ip_explain="Enter one IP per row (example : 123.123.123.123)<br/>or a network address (example : 123.123.0.0/16)";
$l_allowed_ip="Allowed IP";
$l_record="Save changes";
$l_wait="Once validated, 10 seconds are necessary to compute your modifications";
$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_remove="Remove";
$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_ip_filtering="Filtering URLs that contain an IP address instead of a domain name (ie: http://25.56.58.59/index.htm)";
$l_specific_filtering="Specific filtering";
$l_safe_youtube="For safe Youtube, follow steps here for each computer ";
$l_youtube_id="(<a href='https://support.google.com/youtube/answer/174084?hl=en' target='cat_help' onclick=window.open('https://support.google.com/youtube/answer/174084?hl=en','cat_help','width=800,height=600,toolbar=no,scrollbars=yes,resizable=yes') title='Youtube for school'>link to create a Youtube Id</a>)";
$l_safe_searching="Enabling school/parental control for the search engines google.";
}
$dir_etc="/usr/local/etc/";
$dir_dg="/etc/dansguardian/lists/";
$file_wl_domains="/usr/local/share/dnsmasq-wl/ossi.conf";
$file_wl_ip="/usr/local/share/iptables-wl-enabled/ossi";
$wl_categories=$dir_etc."alcasar-wl-categories";
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
$conf_file=$dir_etc."alcasar.conf";
$tinyproxy_conf="/etc/tinyproxy/tinyproxy.conf";
$dnsmasq_conf="/etc/dnsmasq-whitelist.conf";
$dir_tmp="/tmp/";
$upload_dir_ip = "/usr/local/share/iptables-wl-enabled/";
$upload_dir_domain_names = "/usr/local/share/dnsmasq-wl-enabled/";
# default values
if (is_file ($conf_file))
{
$tab=file($conf_file);
if ($tab)
{
foreach ($tab as $line)
{
$field=explode("=", $line);
if ($field[0] == "DNS1")
{
$DNS1=trim($field[1]);
}
}
}
}
else { echo "$l_error_open_file $conf_file";}
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
switch ($choix)
{
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_cat_wl' :
if (file_exists($wl_categories_enabled))
{
$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($file_wl_domains,"w+");
fputs($fichier, form_filter($_POST['OSSI_wl_domains']));
fclose($fichier);
unset($_POST['OSSI_wl_domains']);
$fichier=fopen($file_wl_ip, "w+");
fputs($fichier, form_filter_ip($_POST['OSSI_wl_ip'], "white"));
fclose($fichier);
unset($_POST['OSSI_wl_ip']);
exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
break;
case 'MAJ_ip_file_delete' :
foreach($_POST as $fichier => $value)
{
if($fichier != "choix")
{
exec("rm -rf $upload_dir_ip$fichier");
exec("rm -rf $upload_dir_domain_names$fichier");
exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
}
}
break;
case 'MAJ_ip_file_upload' :
$nom = str_replace (".", "_",basename($_FILES['fichier_ip']['name']));
# Si un fichier a été choisi
if(!empty($nom))
{
# On l'upload
if(move_uploaded_file($_FILES['fichier_ip']['tmp_name'], $upload_dir_ip.$nom))
{
# On extrait uniquement les ip du fichier
exec("grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' $upload_dir_ip$nom > $upload_dir_ip\ossi_ip");
# Suppression des doublons
exec("sort -u $upload_dir_ip\ossi_ip > $upload_dir_ip\ossi-$nom && rm -f $upload_dir_ip\ossi_ip");
# On adapte le fichier à la sauvegarde du set
exec("sed -i \"s/^/add wl_ip_allowed /g\" $upload_dir_ip\ossi-$nom");
# On extrait uniquement les noms de domaine
# max_tld() retourne le nombre max de charactere pour un top-level dns
exec("grep -Eo '([a-zA-Z0-9_-]+\.){1,2}[a-zA-Z]{2,".max_tld()."}' $upload_dir_ip$nom > $upload_dir_domain_names\ossi_domain_names");
# Suppression des doublons
exec("sort -u $upload_dir_domain_names\ossi_domain_names > $upload_dir_domain_names\ossi-$nom && rm -f $upload_dir_domain_names\ossi_domain_names");
# On adapte le fichier pour Dnsmasq
exec("sed -i \"s/^/server=\//g\" $upload_dir_domain_names\ossi-$nom");
exec("sed -i \"s/$/\/$DNS1/g\" $upload_dir_domain_names\ossi-$nom");
# Suppression du fichier
exec("rm -f $upload_dir_ip$nom");
}
else
{
echo $l_error_upload;
}
exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
}
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>";
$nbDomainNames = exec ("wc -l /usr/local/share/dnsmasq-wl/* | tail -n 1 | awk '{print $1}'");
$nbUrl = 0;
$nbIp = 0;
echo "<b>$l_nbDomainNames</b> $nbDomainNames, <b>$l_nbUrl</b> $nbUrl, <b>$l_nbIp</b> $nbIp<br/>";
echo "$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?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'";
// 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_wl</b></center></td></tr>";
echo "<tr><td width=50% colspan=5 align=center>";
echo "<H3>$l_allowed_dns</H3>$l_one_dns<BR>";
echo "<textarea name='OSSI_wl_domains' rows=3 cols=40>";
echo_file ($file_wl_domains);
echo "</textarea></td>";
echo "<td width=50% colspan=5 align=center>";
echo "<H3>$l_allowed_ip</H3>$l_forbidden_ip_explain<BR>";
echo "<textarea name='OSSI_wl_ip' rows=3 cols=40>";
echo_ip_file ($file_wl_ip);
echo "</textarea></td></tr>";
echo "<tr><td colspan=10>";
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'></form></td></tr>";
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_ip_file_delete'>
<?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>$l_file_remove</tr>";
$fichiersIp = array_diff(scandir($upload_dir_ip), array('ossi','ossi-ip-safesearch','..','.'));
foreach($fichiersIp as $fichier => $value)
{
echo "<tr><td><center><a href='bl_categories_help.php?liste=wl&cat=$value&ossi=yes&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'>".exec("sed 's/^.....//g' <<< $value")."</a></center></td><td><center>".exec("wc -l $upload_dir_ip$value | awk '{print $1}'")."</center></td><td><center>".exec("wc -l $upload_dir_domain_names$value | awk '{print $1}'")."</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_ip_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';\" 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
//verification du safesearch
if(file_exists($dnsmasq_conf))
{
$f=fopen($dnsmasq_conf, 'r');
while(!feof($f))
{
$line=fgets($f,4096);
if($line && preg_match('/^address=\/\.google/',$line,$r))
{
echo "checked";
break;
}
}
fclose($f);
}
else
echo "$l_error_open_file $dnsmasq_conf";
echo "> $l_safe_searching";
echo "<br></br>$l_safe_youtube";
echo " $l_youtube_id<tr><td>";
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'></form></td></tr>";
?>
</TABLE><br/>
</BODY>
</HTML>