Subversion Repositories ALCASAR

Rev

Rev 3179 | 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
$dir_tmp="/tmp/blacklists";
2688 lucas.echa 169
$wl_safesearch="off";
1954 richard 170
 
171
# default values
3179 rexy 172
if (is_file ($conf_file)){
1954 richard 173
	$tab=file($conf_file);
3179 rexy 174
	if ($tab){
175
		foreach ($tab as $line){
1954 richard 176
			$field=explode("=", $line);
3179 rexy 177
			switch ($field[0]){
2688 lucas.echa 178
				case 'PRIVATE_IP':
179
					$PRIVATE_IP_MASK=trim($field[1]);
180
					$tmp = explode("/",$PRIVATE_IP_MASK);
181
					$PRIVATE_IP=$tmp[0];
182
					break;
183
				case 'WL_SAFESEARCH':
3179 rexy 184
					if (strtolower(trim($field[1])) == 'on'){
2688 lucas.echa 185
						$wl_safesearch='on';
186
					}
187
					break;
1954 richard 188
			}
189
		}
2647 lucas.echa 190
	}
2688 lucas.echa 191
}
1954 richard 192
else { echo "$l_error_open_file $conf_file";}
193
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
3179 rexy 194
switch ($choix){
2688 lucas.echa 195
	case 'MAJ_cat_wl' :
3179 rexy 196
		if (file_exists($wl_categories_enabled)){
2688 lucas.echa 197
			exec("/bin/sed -i \"/^ossi-/!d\" $wl_categories_enabled"); // keep ossi custom categories
198
			$pointeur=fopen($wl_categories_enabled, "a+");
3179 rexy 199
			foreach ($_POST as $key => $value){
200
				if (strstr($key,'chk-')){
2688 lucas.echa 201
					$line=str_replace('chk-','',$key)."\n";
202
					fwrite($pointeur,$line);
203
				}
1954 richard 204
			}
2688 lucas.echa 205
			fclose($pointeur);
1954 richard 206
		}
2688 lucas.echa 207
		else {echo "$l_error_open_file $wl_categories_enabled";}
208
		$fichier=fopen($dir_blacklist."ossi-wl/domains","w+");
209
		fputs($fichier, form_filter($_POST['OSSI_wl']));
210
		fclose($fichier);
211
		unset($_POST['OSSI_wl']);
212
		exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
213
		break;
214
	case 'Specific_filtering' :
215
		$wl_safesearch='off';
3179 rexy 216
		foreach ($_POST as $key => $value){
217
			if (strstr($key,'chk-safesearch')){
2688 lucas.echa 218
				$wl_safesearch='on';
219
			}
220
		}
221
		exec ("sudo /usr/local/bin/alcasar-url_filter_wl.sh -safesearch_$wl_safesearch");
222
		break;
223
	case 'MAJ_ossi_file' :
3179 rexy 224
		foreach ($_POST as $fichier => $value){
225
			if($fichier != "choix"){
2688 lucas.echa 226
				$action=$_POST[$fichier];
3179 rexy 227
				if($action == $l_remove){ //delete
2688 lucas.echa 228
					exec("/bin/sed -i ".escapeshellarg("/^$fichier\$/d")." $wl_categories_enabled");
229
					exec("/bin/sed -i ".escapeshellarg("/^$fichier\$/d")." $wl_categories");
230
					exec("rm -rf ".escapeshellarg("$dir_blacklist$fichier"));
231
					exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
232
				}
3179 rexy 233
				if($action == $l_disable){ //disable
2688 lucas.echa 234
					exec("/bin/sed -i ".escapeshellarg("/^$fichier\$/d")." $wl_categories_enabled");
235
					exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
236
				}
3179 rexy 237
				if($action == $l_enable){ //enable
2688 lucas.echa 238
					file_put_contents($wl_categories_enabled, $fichier."\n", FILE_APPEND);
239
					exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
240
				}
1954 richard 241
			}
2688 lucas.echa 242
		}
243
		break;
244
	case 'MAJ_ossi_file_upload' :
245
		$file_name = str_replace (".", "_",basename($_FILES['fichier_ip']['name']));
3179 rexy 246
		if(!empty($file_name)){
2688 lucas.echa 247
			$dest_dir = $dir_blacklist."ossi-wl-".$file_name;
248
			exec("mkdir ".escapeshellarg($dest_dir));
249
			$file=$_FILES['fichier_ip']['tmp_name'];
250
			exec('/usr/bin/dos2unix '.escapeshellarg($file));
3179 rexy 251
			if(move_uploaded_file($_FILES['fichier_ip']['tmp_name'], $dest_dir."/domains")){
2688 lucas.echa 252
				touch ($dest_dir."/urls"); // create the URL file even if it isn't used
253
				file_put_contents ($wl_categories, $dest_dir."\n", FILE_APPEND);
254
				file_put_contents ($wl_categories_enabled, "ossi-wl-".$file_name."\n", FILE_APPEND); //Enabled by default
255
				exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
1954 richard 256
			}
3179 rexy 257
			else {
2688 lucas.echa 258
				exec("rm -rf ".escapeshellarg($dest_dir));
259
				echo $l_error_upload;
1954 richard 260
			}
261
		}
2688 lucas.echa 262
		break;
1954 richard 263
}
264
?>
265
<table width="100%" border="0" cellspacing="0" cellpadding="0">
266
	<tr><th><?php echo $l_wl; ?></th></tr>
267
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
268
</table>
269
<table width="100%" border=1 cellspacing=0 cellpadding=1>
270
<tr><td valign="middle" align="left" colspan=10>
271
<FORM action='wl_filter.php' method=POST>
272
<input type='hidden' name='choix' value='MAJ_cat_wl'>
273
<?php
274
echo "<center>";
275
// total number of IP, DNS & URLs
3179 rexy 276
$nbDomainNames = exec("wc -l $dir_wl_domain_names_enabled* | tail -n 1 | awk '{print $1}'");
1954 richard 277
$nbUrl = "0";
3179 rexy 278
$nbIp = exec("wc -l $dir_wl_ip_enabled* | tail -n 1 | awk '{print $1}'");
279
echo "$l_state $nbDomainNames <b>$l_nbDomainNames</b>, $nbUrl <b>$l_nbUrl</b>, $nbIp <b>$l_nbIp</b><br/>";
2647 lucas.echa 280
echo "$l_wl_categories</center></td></tr>";
3179 rexy 281
//read & display all categories (checked or not)
2647 lucas.echa 282
$cols=1;
3179 rexy 283
if (file_exists($wl_categories)){
1954 richard 284
	$wl_files = file($wl_categories);
285
	$wl_files = preg_grep("/ossi-/", $wl_files, 1); // don't display ossi custom categories
3179 rexy 286
	foreach ($wl_files as $fichier => $value){
1954 richard 287
		if ($cols == 1) { echo "<tr>";}
288
		$categorie=trim(basename($value));
3179 rexy 289
		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 290
		echo "<input type='checkbox' name='chk-$categorie'";
291
		// if the line is commented, the category is disable
292
		if (preg_match('/^#/',$value, $r)) { echo ">";}
293
		else { echo "checked>"; }
294
		echo "</td>";
295
		$cols++;
3179 rexy 296
		if ($cols > 10){
1954 richard 297
			echo "</tr>";
2688 lucas.echa 298
			$cols=1;
1954 richard 299
		}
300
	}
2688 lucas.echa 301
}
302
else {
1954 richard 303
	echo "$l_error_open_file $wl_categories";
304
}
305
echo "<tr><td valign='middle' align='left' colspan=10>";
306
echo "<center><b>$l_add_to_wl</b></center></td></tr>";
307
echo "<tr><td width=100% colspan=10 align=center>";
308
echo "$l_one_dns_ip<BR>";
309
echo "<textarea name='OSSI_wl' rows=3 cols=40>";
310
echo_file ($dir_blacklist."ossi-wl/domains");
311
echo "</textarea></td>";
312
echo "</tr><tr><td colspan=10>";
3028 rexy 313
echo "<input type='submit' onClick=\"this.disabled=true; document.getElementById('ldoverlay').style.display='block'; this.value='$l_load';submit();\" value='$l_record'>";
1954 richard 314
echo "</form> ($l_wait)";
315
echo "</td></tr></table><br/>";
316
?>
317
<table width="100%" border="0" cellspacing="0" cellpadding="0">
318
	<tr><th><?php echo $l_additional_file_title; ?></th></tr>
319
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
320
</table>
321
<table width="100%" border=1 cellspacing=0 cellpadding=1>
322
<form action='wl_filter.php' method='POST'>
323
<input type='hidden' name='choix' value='MAJ_ossi_file'>
324
<?php
325
echo "<tr><td width=50% colspan=5 align=center>";
326
echo "<H3>$l_file_list</H3>";
327
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>";
328
 
329
//list OSSI custom categories
330
$fichierswl = array_diff(scandir($dir_blacklist), array('..','.','ossi-bl','ossi-wl'));
331
$fichierswl = preg_grep("/^ossi-wl-/",$fichierswl);
3179 rexy 332
foreach ($fichierswl as $fichier => $value){
333
	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 334
	if (file_exists ($dir_wl_domain_names_enabled.$value)) echo " value='$l_disable'>"; else echo " value='$l_enable'>";
335
	echo "</center></td><td><center><input type='submit' name='$value' value='$l_remove'></center></td></tr>";
336
}
337
echo "</table><br/></td></form><form action='wl_filter.php' method='POST' enctype='multipart/form-data'>";
338
echo "<input type='hidden' name='choix' value='MAJ_ossi_file_upload'><td width=50% colspan=5 align=center>";
339
echo "<H3>$l_add_file</H3>";
340
echo "$l_add_file_explain";
341
echo "<input type='file' name='fichier_ip'>";
3028 rexy 342
echo "<input type='submit' onClick=\"this.disabled=true; document.getElementById('ldoverlay').style.display='block'; this.value='$l_load';submit();\" value='$l_submit'>";
1954 richard 343
echo "</td></tr>";
344
echo "</form>";
345
echo "</table><br/>";
346
?>
347
<table width="100%" border="0" cellspacing="0" cellpadding="0">
348
	<tr><th><?php echo $l_specific_filtering; ?></th></tr>
349
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
350
</table>
351
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
352
<FORM action='wl_filter.php' method='POST'>
353
<input type='hidden' name='choix' value='Specific_filtering'>
354
<tr><td>
2688 lucas.echa 355
<input type='checkbox' name='chk-safesearch' <?= $wl_safesearch == 'on' ? 'checked' : ''; ?>><?= $l_safe_searching; ?>
356
</tr></td>
357
<tr><td>
3028 rexy 358
<?= "<input type='submit' onClick=\"this.disabled=true; document.getElementById('ldoverlay').style.display='block'; this.value='$l_load';submit();\" value='$l_record'>"; ?>
2688 lucas.echa 359
</td></tr></FORM>
1954 richard 360
</TABLE>
361
</BODY>
362
</HTML>