Subversion Repositories ALCASAR

Rev

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