Subversion Repositories ALCASAR

Rev

Rev 3173 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
1954 richard 1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
<HTML><!-- written by Rexy -->
3
<HEAD>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
<TITLE>ALCASAR DNS WL filtering</TITLE>
2817 rexy 6
<link rel="stylesheet" href="/css/acc.css" type="text/css">
1954 richard 7
</HEAD>
8
<body>
3028 rexy 9
<div id="ldoverlay" class="overlay">
10
	<div class="lds-spinner" id="spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
11
</div>
1954 richard 12
<?
3179 rexy 13
function form_filter ($form_content){
14
	// Re-encoding : ISO + unix format + end-of-line
1954 richard 15
	$list = str_replace("\r\n", "\n", utf8_decode($form_content));
16
	if (strlen($list) != 0){
17
		if ($list[strlen($list)-1] != "\n") { $list[strlen($list)]="\n";} ;} ;
18
	return $list;
19
}
3179 rexy 20
 
21
function form_filter_ip($form_content, $color){
22
	// IP reconstruction
1954 richard 23
	$list = explode("\n", form_filter($form_content));
24
	$new_list = "";
3179 rexy 25
	foreach ($list as &$value){
26
		if(preg_match('/([0-9]{1,3}.){3}[0-9]{1,3}/', $value)){
1954 richard 27
			$new_list = $new_list.$value."\n";
28
		}
29
	}
3179 rexy 30
	if($color == "white"){
1954 richard 31
		return preg_replace("/(.*)\n/", "add wl_ip_allowed $1\n", $new_list);
32
	}
3179 rexy 33
	else {
1954 richard 34
		return preg_replace("/(.*)\n/", "add bl_ip_blocked $1\n", $new_list);
35
	}
36
}
3179 rexy 37
 
38
function echo_file ($filename){
39
	if (file_exists($filename)){
40
		if (filesize($filename) != 0){
1954 richard 41
			$pointeur=fopen($filename,"r");
42
			$tampon = fread($pointeur, filesize($filename));
43
			fclose($pointeur);
44
			echo $tampon;
45
		}
2688 lucas.echa 46
	}
3179 rexy 47
	else {
1954 richard 48
		echo "$filename doesn't exist";
49
	}
2688 lucas.echa 50
}
3179 rexy 51
 
52
function echo_ip_file ($filename){
2299 tom.houday 53
	$filename = escapeshellarg($filename);
1954 richard 54
	exec("cat $filename | cut -d ' ' -f3", $resultat);
3179 rexy 55
	for($i=0; $i<exec("wc -l $filename"); $i++){
1954 richard 56
		echo $resultat[$i]."\n";
57
	}
58
}
59
 
60
# Choice of language
61
$Language = 'en';
62
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
63
	$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
2647 lucas.echa 64
	$Language = strtolower(substr(chop($Langue[0]),0,2));
2688 lucas.echa 65
}
1954 richard 66
if($Language == 'fr'){
2864 rexy 67
	$l_wl="Liste blanche principale";
3179 rexy 68
	$l_state="Sont actuellement autorisés : ";
1954 richard 69
	$l_load="Chargement...";
70
	$l_list_version="Version de la liste : ";
1975 richard 71
	$l_wl_categories="Sélectionnez les catégories à autoriser";
1954 richard 72
	$l_specific_filtering="Filtrage special";
1975 richard 73
	$l_add_to_wl="Noms de domaine ou adresses IP à ajouter à la liste blanche";
2688 lucas.echa 74
	$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";
1954 richard 75
	$l_record="Enregistrer les modifications";
76
	$l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
2662 lucas.echa 77
	$l_safe_searching="Activer le contrôle scolaire/parental pour 'YouTube' et pour les moteurs de recherche 'Google', 'Bing' et 'Qwant'.";
1954 richard 78
	$l_error_open_file="Erreur d'ouverture du fichier";
79
	$l_additional_file_title="Fichiers de 'listes blanches' additionnels";
80
	$l_file_list="Liste des fichiers";
81
	$l_add_file="Ajouter un fichier";
2647 lucas.echa 82
	$l_add_file_explain="Chaque ligne du fichier doit être une adresse IP ou un nom de domaine";
1954 richard 83
	$l_file_name="Nom du fichier";
84
	$l_file_action="Action";
85
	$l_error_upload="Erreur d'envoi du fichier";
86
	$l_remove="Supprimer";
87
	$l_submit="Envoyer";
88
	$l_nb_ip="Nombre d'IP";
89
	$l_nb_domain_names="Nombre de noms de domaine";
3179 rexy 90
	$l_nbDomainNames="noms de domaine";
91
	$l_nbUrl="URL";
92
	$l_nbIp="@IP";
1954 richard 93
	$l_disable="Désactiver";
94
	$l_enable="Activer";
95
	$l_file_state="Etat";
3179 rexy 96
} else if($Language == 'es'){
2864 rexy 97
	$l_wl="Lista blanca principal";
3179 rexy 98
	$l_state="The following are currently authorized : ";
2853 rexy 99
	$l_load="Cargando...";
100
	$l_list_version="Versión de la lista: ";
101
	$l_wl_categories="Seleccione las categorías permitidas";
102
	$l_specific_filtering="Filtrado específico";
103
	$l_add_to_wl="Nombres de dominio o direcciones IP para agregar a la lista blanca";
104
	$l_one_dns_ip="Ingrese un nombre de dominio o una dirección IP o una dirección de red por línea <br> ejemplo (dominio): dominio.org. - ejemplo (IP): 61.54.56.52 - ejemplo (red): 172.16.0.0/16";
105
	$l_record="Guardar cambios";
106
	$l_wait="Una vez validado, son necesarios 10 segundos para aplicar sus modificaciones";
107
	$l_safe_searching="Habilitación del control escolar / parental para 'YouTube' y para los motores de búsqueda 'Google', 'Bing' y 'Qwant'";
108
	$l_error_open_file="Error abriendo el archivo";
109
	$l_additional_file_title="Archivos adicionales de Lista Blanca";
110
	$l_file_list="Lista de archivos";
111
	$l_add_file="Agregar un archivo";
112
	$l_add_file_explain="Cada línea del archivo debe ser una dirección IP o un nombre de dominio";
113
	$l_file_name="Nombre de archivo";
114
	$l_file_action="Acción";
115
	$l_error_upload="Error durante el proceso de carga";
116
	$l_remove="Borrar";
117
	$l_submit="Enviar";
118
	$l_nb_ip="Número de IPs";
119
	$l_nb_domain_names="Número de sitios";
3179 rexy 120
	$l_nbDomainNames="sitios";
121
	$l_nbUrl="URL";
122
	$l_nbIp="IP@";
2853 rexy 123
	$l_disable="Desactivar";
124
	$l_enable="Activar";
125
	$l_file_state="Estado";
126
} else {
2864 rexy 127
	$l_wl="Main WhiteList";
3179 rexy 128
	$l_state="Actualmente están autorizados los siguientes : ";
1954 richard 129
	$l_load="Loading...";
130
	$l_list_version="List version : ";
1975 richard 131
	$l_wl_categories="Select the allowed categories";
1954 richard 132
	$l_specific_filtering="Specific filtering";
1975 richard 133
	$l_add_to_wl="Domain names or IP addresses to add to the whitelist";
2688 lucas.echa 134
	$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";
1954 richard 135
	$l_record="Save changes";
136
	$l_wait="Once validated, 10 seconds are necessary to compute your modifications";
2662 lucas.echa 137
	$l_safe_searching="Enabling school/parental control for 'YouTube' and for the search engines 'Google', 'Bing' and 'Qwant'";
1954 richard 138
	$l_error_open_file="Error opening file";
139
	$l_additional_file_title="Additional WhiteList files";
140
	$l_file_list="Files list";
141
	$l_add_file="Add a file";
2647 lucas.echa 142
	$l_add_file_explain="Each line of the file must be an IP address or a domain name";
1954 richard 143
	$l_file_name="Filename";
144
	$l_file_action="Action";
145
	$l_error_upload="Error during the upload process";
146
	$l_remove="Delete";
147
	$l_submit="Submit";
148
	$l_nb_ip="Number of IP";
149
	$l_nb_domain_names="Number of domain names";
3179 rexy 150
	$l_nbDomainNames="domain names";
151
	$l_nbUrl="URL";
152
	$l_nbIp="IP@";
1954 richard 153
	$l_disable="Disable";
154
	$l_enable="Enable";
155
	$l_file_state="State";
156
}
157
$dir_etc="/usr/local/etc/";
2521 armand.ito 158
$dir_dg="/etc/e2guardian/lists/";
1954 richard 159
$dir_blacklist=$dir_dg."blacklists/";
160
$dir_wl_ip="/usr/local/share/iptables-wl/";
3179 rexy 161
$dir_wl_ip_enabled="/usr/local/share/iptables-wl-enabled/";
162
$dir_wl_domain_names="/usr/local/share/unbound-wl/";
163
$dir_wl_domain_names_enabled="/usr/local/share/unbound-wl-enabled/";
1954 richard 164
$wl_categories=$dir_etc."alcasar-wl-categories";
165
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
166
$conf_file=$dir_etc."alcasar.conf";
2688 lucas.echa 167
$domainfilter_file="/etc/unbound/conf.d/whitelist/domainfilter.conf";
1954 richard 168
$bannedsite_file=$dir_dg."bannedsitelist";
169
$dir_tmp="/tmp/blacklists";
2688 lucas.echa 170
$wl_safesearch="off";
1954 richard 171
 
172
# default values
3179 rexy 173
if (is_file ($conf_file)){
1954 richard 174
	$tab=file($conf_file);
3179 rexy 175
	if ($tab){
176
		foreach ($tab as $line){
1954 richard 177
			$field=explode("=", $line);
3179 rexy 178
			switch ($field[0]){
2688 lucas.echa 179
				case 'PRIVATE_IP':
180
					$PRIVATE_IP_MASK=trim($field[1]);
181
					$tmp = explode("/",$PRIVATE_IP_MASK);
182
					$PRIVATE_IP=$tmp[0];
183
					break;
184
				case 'WL_SAFESEARCH':
3179 rexy 185
					if (strtolower(trim($field[1])) == 'on'){
2688 lucas.echa 186
						$wl_safesearch='on';
187
					}
188
					break;
1954 richard 189
			}
190
		}
2647 lucas.echa 191
	}
2688 lucas.echa 192
}
1954 richard 193
else { echo "$l_error_open_file $conf_file";}
194
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
3179 rexy 195
switch ($choix){
2688 lucas.echa 196
	case 'MAJ_cat_wl' :
3179 rexy 197
		if (file_exists($wl_categories_enabled)){
2688 lucas.echa 198
			exec("/bin/sed -i \"/^ossi-/!d\" $wl_categories_enabled"); // keep ossi custom categories
199
			$pointeur=fopen($wl_categories_enabled, "a+");
3179 rexy 200
			foreach ($_POST as $key => $value){
201
				if (strstr($key,'chk-')){
2688 lucas.echa 202
					$line=str_replace('chk-','',$key)."\n";
203
					fwrite($pointeur,$line);
204
				}
1954 richard 205
			}
2688 lucas.echa 206
			fclose($pointeur);
1954 richard 207
		}
2688 lucas.echa 208
		else {echo "$l_error_open_file $wl_categories_enabled";}
209
		$fichier=fopen($dir_blacklist."ossi-wl/domains","w+");
210
		fputs($fichier, form_filter($_POST['OSSI_wl']));
211
		fclose($fichier);
212
		unset($_POST['OSSI_wl']);
213
		exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
214
		break;
215
	case 'Specific_filtering' :
216
		$wl_safesearch='off';
3179 rexy 217
		foreach ($_POST as $key => $value){
218
			if (strstr($key,'chk-safesearch')){
2688 lucas.echa 219
				$wl_safesearch='on';
220
			}
221
		}
222
		exec ("sudo /usr/local/bin/alcasar-url_filter_wl.sh -safesearch_$wl_safesearch");
223
		break;
224
	case 'MAJ_ossi_file' :
3179 rexy 225
		foreach ($_POST as $fichier => $value){
226
			if($fichier != "choix"){
2688 lucas.echa 227
				$action=$_POST[$fichier];
3179 rexy 228
				if($action == $l_remove){ //delete
2688 lucas.echa 229
					exec("/bin/sed -i ".escapeshellarg("/^$fichier\$/d")." $wl_categories_enabled");
230
					exec("/bin/sed -i ".escapeshellarg("/^$fichier\$/d")." $wl_categories");
231
					exec("rm -rf ".escapeshellarg("$dir_blacklist$fichier"));
232
					exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
233
				}
3179 rexy 234
				if($action == $l_disable){ //disable
2688 lucas.echa 235
					exec("/bin/sed -i ".escapeshellarg("/^$fichier\$/d")." $wl_categories_enabled");
236
					exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
237
				}
3179 rexy 238
				if($action == $l_enable){ //enable
2688 lucas.echa 239
					file_put_contents($wl_categories_enabled, $fichier."\n", FILE_APPEND);
240
					exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
241
				}
1954 richard 242
			}
2688 lucas.echa 243
		}
244
		break;
245
	case 'MAJ_ossi_file_upload' :
246
		$file_name = str_replace (".", "_",basename($_FILES['fichier_ip']['name']));
3179 rexy 247
		if(!empty($file_name)){
2688 lucas.echa 248
			$dest_dir = $dir_blacklist."ossi-wl-".$file_name;
249
			exec("mkdir ".escapeshellarg($dest_dir));
250
			$file=$_FILES['fichier_ip']['tmp_name'];
251
			exec('/usr/bin/dos2unix '.escapeshellarg($file));
3179 rexy 252
			if(move_uploaded_file($_FILES['fichier_ip']['tmp_name'], $dest_dir."/domains")){
2688 lucas.echa 253
				touch ($dest_dir."/urls"); // create the URL file even if it isn't used
254
				file_put_contents ($wl_categories, $dest_dir."\n", FILE_APPEND);
255
				file_put_contents ($wl_categories_enabled, "ossi-wl-".$file_name."\n", FILE_APPEND); //Enabled by default
256
				exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
1954 richard 257
			}
3179 rexy 258
			else {
2688 lucas.echa 259
				exec("rm -rf ".escapeshellarg($dest_dir));
260
				echo $l_error_upload;
1954 richard 261
			}
262
		}
2688 lucas.echa 263
		break;
1954 richard 264
}
265
?>
266
<table width="100%" border="0" cellspacing="0" cellpadding="0">
267
	<tr><th><?php echo $l_wl; ?></th></tr>
268
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
269
</table>
270
<table width="100%" border=1 cellspacing=0 cellpadding=1>
271
<tr><td valign="middle" align="left" colspan=10>
272
<FORM action='wl_filter.php' method=POST>
273
<input type='hidden' name='choix' value='MAJ_cat_wl'>
274
<?php
275
echo "<center>";
276
// total number of IP, DNS & URLs
3179 rexy 277
$nbDomainNames = exec("wc -l $dir_wl_domain_names_enabled* | tail -n 1 | awk '{print $1}'");
1954 richard 278
$nbUrl = "0";
3179 rexy 279
$nbIp = exec("wc -l $dir_wl_ip_enabled* | tail -n 1 | awk '{print $1}'");
280
echo "$l_state $nbDomainNames <b>$l_nbDomainNames</b>, $nbUrl <b>$l_nbUrl</b>, $nbIp <b>$l_nbIp</b><br/>";
2647 lucas.echa 281
echo "$l_wl_categories</center></td></tr>";
3179 rexy 282
//read & display all categories (checked or not)
2647 lucas.echa 283
$cols=1;
3179 rexy 284
if (file_exists($wl_categories)){
1954 richard 285
	$wl_files = file($wl_categories);
286
	$wl_files = preg_grep("/ossi-/", $wl_files, 1); // don't display ossi custom categories
3179 rexy 287
	foreach ($wl_files as $fichier => $value){
1954 richard 288
		if ($cols == 1) { echo "<tr>";}
289
		$categorie=trim(basename($value));
3179 rexy 290
		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=450,toolbar=no,scrollbars=yes,resizable=yes') title='categories help page'>$categorie</a><br>";
1954 richard 291
		echo "<input type='checkbox' name='chk-$categorie'";
292
		// if the line is commented, the category is disable
293
		if (preg_match('/^#/',$value, $r)) { echo ">";}
294
		else { echo "checked>"; }
295
		echo "</td>";
296
		$cols++;
3179 rexy 297
		if ($cols > 10){
1954 richard 298
			echo "</tr>";
2688 lucas.echa 299
			$cols=1;
1954 richard 300
		}
301
	}
2688 lucas.echa 302
}
303
else {
1954 richard 304
	echo "$l_error_open_file $wl_categories";
305
}
306
echo "<tr><td valign='middle' align='left' colspan=10>";
307
echo "<center><b>$l_add_to_wl</b></center></td></tr>";
308
echo "<tr><td width=100% colspan=10 align=center>";
309
echo "$l_one_dns_ip<BR>";
310
echo "<textarea name='OSSI_wl' rows=3 cols=40>";
311
echo_file ($dir_blacklist."ossi-wl/domains");
312
echo "</textarea></td>";
313
echo "</tr><tr><td colspan=10>";
3028 rexy 314
echo "<input type='submit' onClick=\"this.disabled=true; document.getElementById('ldoverlay').style.display='block'; this.value='$l_load';submit();\" value='$l_record'>";
1954 richard 315
echo "</form> ($l_wait)";
316
echo "</td></tr></table><br/>";
317
?>
318
<table width="100%" border="0" cellspacing="0" cellpadding="0">
319
	<tr><th><?php echo $l_additional_file_title; ?></th></tr>
320
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
321
</table>
322
<table width="100%" border=1 cellspacing=0 cellpadding=1>
323
<form action='wl_filter.php' method='POST'>
324
<input type='hidden' name='choix' value='MAJ_ossi_file'>
325
<?php
326
echo "<tr><td width=50% colspan=5 align=center>";
327
echo "<H3>$l_file_list</H3>";
328
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>";
329
 
330
//list OSSI custom categories
331
$fichierswl = array_diff(scandir($dir_blacklist), array('..','.','ossi-bl','ossi-wl'));
332
$fichierswl = preg_grep("/^ossi-wl-/",$fichierswl);
3179 rexy 333
foreach ($fichierswl as $fichier => $value){
334
	echo "<tr><td><center><a href='bl_categories_help.php?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'";
1954 richard 335
	if (file_exists ($dir_wl_domain_names_enabled.$value)) echo " value='$l_disable'>"; else echo " value='$l_enable'>";
336
	echo "</center></td><td><center><input type='submit' name='$value' value='$l_remove'></center></td></tr>";
337
}
338
echo "</table><br/></td></form><form action='wl_filter.php' method='POST' enctype='multipart/form-data'>";
339
echo "<input type='hidden' name='choix' value='MAJ_ossi_file_upload'><td width=50% colspan=5 align=center>";
340
echo "<H3>$l_add_file</H3>";
341
echo "$l_add_file_explain";
342
echo "<input type='file' name='fichier_ip'>";
3028 rexy 343
echo "<input type='submit' onClick=\"this.disabled=true; document.getElementById('ldoverlay').style.display='block'; this.value='$l_load';submit();\" value='$l_submit'>";
1954 richard 344
echo "</td></tr>";
345
echo "</form>";
346
echo "</table><br/>";
347
?>
348
<table width="100%" border="0" cellspacing="0" cellpadding="0">
349
	<tr><th><?php echo $l_specific_filtering; ?></th></tr>
350
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
351
</table>
352
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
353
<FORM action='wl_filter.php' method='POST'>
354
<input type='hidden' name='choix' value='Specific_filtering'>
355
<tr><td>
2688 lucas.echa 356
<input type='checkbox' name='chk-safesearch' <?= $wl_safesearch == 'on' ? 'checked' : ''; ?>><?= $l_safe_searching; ?>
357
</tr></td>
358
<tr><td>
3028 rexy 359
<?= "<input type='submit' onClick=\"this.disabled=true; document.getElementById('ldoverlay').style.display='block'; this.value='$l_load';submit();\" value='$l_record'>"; ?>
2688 lucas.echa 360
</td></tr></FORM>
1954 richard 361
</TABLE>
362
</BODY>
363
</HTML>