Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
1843 raphael.pi 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 Whitelist filtering</TITLE>
6
<link rel="stylesheet" href="/css/style.css" type="text/css">
7
</HEAD>
8
<body>
9
<?
10
function form_filter ($form_content)
11
{
12
// réencodage iso + format unix + rc fin de ligne (ouf...)
13
	$list = str_replace("\r\n", "\n", utf8_decode($form_content));
14
	if (strlen($list) != 0){
15
		if ($list[strlen($list)-1] != "\n") { $list[strlen($list)]="\n";} ;} ;
16
	return $list;
17
}
18
function form_filter_ip($form_content, $color)
19
{
20
	//# reconstruction des ip
21
	$list = explode("\n", form_filter($form_content));
22
	$new_list = "";
23
	foreach($list as &$value)
24
	{
25
		if(preg_match('/([0-9]{1,3}.){3}[0-9]{1,3}/', $value))
26
		{
27
			$new_list = $new_list.$value."\n";
28
		}
29
	}
30
	if($color == "white")
31
	{
1867 raphael.pi 32
		return preg_replace("/(.*)\n/", "add wl_ip_allowed $1\n", $new_list);
1843 raphael.pi 33
	}
34
	else
35
	{
1867 raphael.pi 36
		return preg_replace("/(.*)\n/", "add bl_ip_blocked $1\n", $new_list);
1843 raphael.pi 37
	}
38
}
39
function echo_file ($filename)
40
	{
41
	if (file_exists($filename))
42
		{
43
		if (filesize($filename) != 0)
44
			{
45
			$pointeur=fopen($filename,"r");
46
			$tampon = fread($pointeur, filesize($filename));
1855 raphael.pi 47
			$line = split("\n", $tampon);
48
			foreach( $line as $x)
49
			{
50
				if(isset(split('/',$x)[1]))
51
				echo split('/',$x)[1]."\n";
52
			}
1843 raphael.pi 53
			fclose($pointeur);
54
			}
55
		}
56
	else
57
		{
58
		echo "$filename doesn't exist";
59
		}
60
	}
61
function echo_ip_file ($filename)
62
{
63
	exec("cat $filename | cut -d ' ' -f3", $resultat);
64
	for($i=0; $i<exec("wc -l $filename"); $i++)
65
	{
66
		echo $resultat[$i]."\n";
67
	}
68
}
1852 raphael.pi 69
 
70
#maximum length for top-level DNS
71
function max_tld()
72
{
73
	$url_tld = "http://data.iana.org/TLD/tlds-alpha-by-domain.txt";
74
	$result_tld = file_get_contents($url_tld,false);
75
	$max_tld = 18; 							#valeur de base si le site ne répond plus
76
	if($result_tld !== FALSE){
77
		foreach(explode("\n", $result_tld) as $line)
78
		{
79
			if((strpos($line,'-') === false) and (strpos($line,'#') === false))
80
			{
81
				if(strlen($line) > $max_tld)
82
				{
83
					$max_tld = strlen($line);
84
				}
85
			}
86
		}
87
	}
88
	return $max_tld;
89
}
90
 
1843 raphael.pi 91
# Choice of language
92
$Language = 'en';
93
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
1899 raphael.pi 94
	$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
95
	$Language = strtolower(substr(chop($Langue[0]),0,2)); }
1843 raphael.pi 96
if($Language == 'fr'){
1899 raphael.pi 97
	$l_wl="Liste blanche";
98
	$l_load="Chargement...";
99
	$l_list_version="Version de la liste : ";
100
	$l_specific_filtering="Filtrage special";
101
	$l_wl_categories="Sélectionnez les catégories à autoriser";
102
	$l_allowed_dns="Noms de domaine autorisés";
103
	$l_one_dns="Entrez un nom de domaine par ligne (exemple : .domaine.org)";
104
	$l_add_to_wl="Noms de domaine ou IP ajoutés à la liste blanche";
105
	$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)";
106
	$l_allowed_ip="IP autorisées";
107
	$l_record="Enregistrer les modifications";
108
	$l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
109
	$l_error_open_file="Erreur d'ouverture du fichier";
110
	$l_additional_file_title="Fichiers de 'listes blanche' additionnels";
111
	$l_file_list="Liste des fichiers";
112
	$l_add_file="Ajouter un fichier";
113
	$l_add_file_explain="Chaque ligne du fichier doit être une adresse IP ou un nom de domaine"; 
114
	$l_file_name="Nom du fichier";
115
	$l_file_remove="Supprimer";
116
	$l_error_upload="Erreur d'envoi du fichier";
117
	$l_remove="Supprimer";
118
	$l_submit="Envoyer";
119
	$l_nb_ip="Nombre d'IP";
120
	$l_nb_domain_names="Nombre de noms de domaine";
121
	$l_nbDomainNames="Noms de domaine :";
122
	$l_nbUrl="Url :";
123
	$l_nbIp="Ip :";
124
	$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)";
125
	$l_safe_searching="Activer le contrôle scolaire/parental des moteurs de recherche : google, yahoo, bing, metacrawler et Youtube.";
126
	$l_safe_youtube="Pour Youtube restreint, suivez les étapes ici pour chaque poste : "; 
127
	$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>)";
128
	$l_disable="Désactiver";
129
	$l_enable="Activer";
130
	$l_file_state="Etat";
1843 raphael.pi 131
}
132
else {
1899 raphael.pi 133
	$l_wl="WhiteList";
134
	$l_load="Loading...";
135
	$l_list_version="List version : ";
136
	$l_wl_categories="Select the categories to allow";
137
	$l_allowed_dns="Allowed domain names";
138
	$l_one_dns="Enter one domain name per row (example : .domain.org)";
139
	$l_add_to_wl="Domain names or IP to add to whitelist";
140
	$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)";
141
	$l_allowed_ip="Allowed IP";
142
	$l_record="Save changes";
143
	$l_wait="Once validated, 10 seconds are necessary to compute your modifications";
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";
148
	$l_add_file_explain="Each line of the file must be an IP address or a domain name"; 
149
	$l_file_name="Filename";
150
	$l_file_remove="Remove";
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_ip_filtering="Filtering URLs that contain an IP address instead of a domain name (ie: http://25.56.58.59/index.htm)";
160
	$l_specific_filtering="Specific filtering";
161
	$l_safe_youtube="For safe Youtube, follow steps here for each computer "; 
162
	$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>)";
163
	$l_safe_searching="Enabling school/parental control for the search engines google."; 
164
	$l_disable="Disable";
165
	$l_enable="Enable";
166
	$l_file_state="State";
1843 raphael.pi 167
}
168
$dir_etc="/usr/local/etc/";
169
$dir_dg="/etc/dansguardian/lists/";
1855 raphael.pi 170
$file_wl_domains="/usr/local/share/dnsmasq-wl/ossi.conf";
1852 raphael.pi 171
$file_wl_ip="/usr/local/share/iptables-wl-enabled/ossi";
1843 raphael.pi 172
$wl_categories=$dir_etc."alcasar-wl-categories";
173
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
174
$conf_file=$dir_etc."alcasar.conf";
175
$tinyproxy_conf="/etc/tinyproxy/tinyproxy.conf";
176
$dnsmasq_conf="/etc/dnsmasq-whitelist.conf";
1852 raphael.pi 177
$dir_tmp="/tmp/";
178
$upload_dir_ip = "/usr/local/share/iptables-wl-enabled/";
179
$upload_dir_domain_names = "/usr/local/share/dnsmasq-wl-enabled/";
1899 raphael.pi 180
$dir_ip = "/usr/local/share/iptables-wl/";
181
$dir_domain_names = "/usr/local/share/dnsmasq-wl/";
1843 raphael.pi 182
# default values
183
if (is_file ($conf_file))
184
	{
185
	$tab=file($conf_file);
186
	if ($tab)
187
		{
188
		foreach ($tab as $line)
189
			{
190
			$field=explode("=", $line);
1852 raphael.pi 191
			if ($field[0] == "DNS1")
1843 raphael.pi 192
				{
1852 raphael.pi 193
					$DNS1=trim($field[1]);
1843 raphael.pi 194
				}
195
			}
196
		}
197
	}
198
else { echo "$l_error_open_file $conf_file";}
199
 
200
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
201
switch ($choix)
202
{
203
case 'Specific_filtering' :
204
	$safesearch="-safesearch_off"; ;
205
	foreach ($_POST as $key => $value)
206
	{
207
		if (strstr($key,'chk-safesearch')) $safesearch="-safesearch_on";
208
	}
209
	exec ("sudo /usr/local/bin/alcasar-url_filter_wl.sh $safesearch");
210
	break;
211
case 'MAJ_cat_wl' :
212
	if (file_exists($wl_categories_enabled))
213
		{
214
		$pointeur=fopen($wl_categories_enabled, "w+");
215
		foreach ($_POST as $key => $value)
216
			{
217
			if (strstr($key,'chk-'))
218
				{	
219
				$line=str_replace('chk-','',$key)."\n";
220
				fwrite($pointeur,$line);
221
				}
222
			}
223
		fclose($pointeur);
224
		}
225
	else {echo "$l_error_open_file $wl_categories_enabled";}
1855 raphael.pi 226
	$fichier=fopen($file_wl_domains,"w+");
1843 raphael.pi 227
	fputs($fichier, form_filter($_POST['OSSI_wl_domains']));
228
	fclose($fichier);
229
	unset($_POST['OSSI_wl_domains']);
230
	$fichier=fopen($file_wl_ip, "w+");
231
	fputs($fichier, form_filter_ip($_POST['OSSI_wl_ip'], "white"));
232
	fclose($fichier);
233
	unset($_POST['OSSI_wl_ip']);
234
	exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
235
	break;
1852 raphael.pi 236
	case 'MAJ_ip_file_delete' :
237
	foreach($_POST as $fichier => $value)
238
	{
239
		if($fichier != "choix")
240
		{
1899 raphael.pi 241
			$action=$_POST[$fichier];
242
			if($action == $l_remove) //delete
243
			{
244
				exec("rm -rf $upload_dir_ip$fichier");
245
				exec("rm -rf $upload_dir_domain_names$fichier");
1903 raphael.pi 246
				exec("rm -rf $dir_ip$fichier");
247
				exec("rm -rf $dir_domain_names$fichier");
1899 raphael.pi 248
				exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
249
			}
250
			if($action == $l_disable) //disable
251
			{
252
				exec("mv -f $upload_dir_ip$fichier $dir_ip$fichier");
253
				exec("mv -f $upload_dir_domain_names$fichier $dir_domain_names$fichier");
254
				exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
255
			}
256
			if($action == $l_enable) //enable
257
			{
258
				exec("mv -f $dir_ip$fichier $upload_dir_ip$fichier");
259
				exec("mv -f $dir_domain_names$fichier $upload_dir_domain_names$fichier");
260
				exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
261
			}
1852 raphael.pi 262
		}
263
	}
264
	break;
265
case 'MAJ_ip_file_upload' :
266
	$nom = str_replace (".", "_",basename($_FILES['fichier_ip']['name']));
267
	# Si un fichier a été choisi
268
	if(!empty($nom))
269
	{	
270
		# On l'upload
271
		if(move_uploaded_file($_FILES['fichier_ip']['tmp_name'], $upload_dir_ip.$nom))
272
		{
273
 
274
		# On extrait uniquement les ip du fichier
275
		exec("grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' $upload_dir_ip$nom > $upload_dir_ip\ossi_ip");
276
 
277
		# Suppression des doublons
278
		exec("sort -u $upload_dir_ip\ossi_ip > $upload_dir_ip\ossi-$nom && rm -f $upload_dir_ip\ossi_ip");
279
 
280
		# On adapte le fichier à la sauvegarde du set
1867 raphael.pi 281
		exec("sed -i \"s/^/add wl_ip_allowed /g\" $upload_dir_ip\ossi-$nom"); 
1852 raphael.pi 282
 
283
		# On extrait uniquement les noms de domaine
284
		# max_tld() retourne le nombre max de charactere pour un top-level dns
285
		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");
286
 
287
		# Suppression des doublons
288
		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");
289
 
290
		# On adapte le fichier pour Dnsmasq
291
		exec("sed -i \"s/^/server=\//g\" $upload_dir_domain_names\ossi-$nom");
292
		exec("sed -i \"s/$/\/$DNS1/g\" $upload_dir_domain_names\ossi-$nom");
293
 
294
		# Suppression du fichier
295
		exec("rm -f $upload_dir_ip$nom");
296
 
297
		}
298
		else
299
		{
300
			echo $l_error_upload;
301
		}
302
		exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
303
	}
304
	break;
1843 raphael.pi 305
}
306
?>
307
<table width="100%" border="0" cellspacing="0" cellpadding="0">
308
	<tr><th><?php echo $l_wl; ?></th></tr>
309
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
310
</table>
311
 
312
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
313
<tr><td valign="middle" align="left" colspan=10>
314
<FORM action='wl_filter.php' method=POST>
315
<input type='hidden' name='choix' value='MAJ_cat_wl'>
316
<?php
317
echo "<center>";
318
$nbDomainNames = exec ("wc -l /usr/local/share/dnsmasq-wl/* | tail -n 1 | awk '{print $1}'");
319
$nbUrl = 0;
320
$nbIp = 0;
321
echo "<b>$l_nbDomainNames</b> $nbDomainNames, <b>$l_nbUrl</b> $nbUrl, <b>$l_nbIp</b> $nbIp<br/>";
322
echo "$l_wl_categories</center></td></tr>";
323
//on lit et on interprete le fichier de catégories
324
$cols=1; 
325
if (file_exists($wl_categories))
326
	{
327
	$pointeur=fopen($wl_categories,"r");
328
	while (!feof ($pointeur))
329
		{
330
		$ligne=fgets($pointeur, 4096);
331
		if ($ligne)
332
			{
333
			if ($cols == 1) { echo "<tr>";}
334
			$categorie=trim(basename($ligne));
335
			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>";
336
			echo "<input type='checkbox' name='chk-$categorie'";
337
			// si la ligne est commentée -> categorie non selectionnée
338
			if (preg_match('/^#/',$ligne, $r)) { echo ">";}
339
			else { echo "checked>"; }
340
			echo "</td>";
341
			$cols++;
342
			if ($cols > 10) {
343
				echo "</tr>";
344
				$cols=1; }
345
			}
346
		}
347
	fclose($pointeur);
348
	}
349
else	{
350
	echo "$l_error_open_file $wl_categories";
351
	}
352
echo "<tr><td valign='middle' align='left' colspan=10>";
353
echo "<center><b>$l_add_to_wl</b></center></td></tr>";
354
echo "<tr><td width=50% colspan=5 align=center>";
355
echo "<H3>$l_allowed_dns</H3>$l_one_dns<BR>";
356
echo "<textarea name='OSSI_wl_domains' rows=3 cols=40>";
1855 raphael.pi 357
echo_file ($file_wl_domains);
1843 raphael.pi 358
echo "</textarea></td>";
359
echo "<td width=50% colspan=5 align=center>";
360
echo "<H3>$l_allowed_ip</H3>$l_forbidden_ip_explain<BR>";
361
echo "<textarea name='OSSI_wl_ip' rows=3 cols=40>";
362
echo_ip_file ($file_wl_ip);
363
echo "</textarea></td></tr>";
364
echo "<tr><td colspan=10>";
1852 raphael.pi 365
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'></form></td></tr>";
366
echo "</td></tr></table><br/>";
367
?>
368
 
369
<table width="100%" border="0" cellspacing="0" cellpadding="0">
370
	<tr><th><?php echo $l_additional_file_title; ?></th></tr>
371
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
372
</table>
373
 
374
<table width="100%" border=1 cellspacing=0 cellpadding=1>
375
<form action='wl_filter.php' method='POST'>
376
<input type='hidden' name='choix' value='MAJ_ip_file_delete'>
377
<?php
378
echo "<tr><td width=50% colspan=5 align=center>";
379
echo "<H3>$l_file_list</H3>";
1899 raphael.pi 380
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_state<th>$l_file_remove</tr>";
1876 raphael.pi 381
 
1899 raphael.pi 382
//liste des fichiers activés
1876 raphael.pi 383
$fichiersIp = array_diff(scandir($upload_dir_ip), array('ossi','ossi-ip-safesearch','..','.'));
1878 raphael.pi 384
$fichiersIp = preg_grep("/^ossi-/",$fichiersIp);
1852 raphael.pi 385
foreach($fichiersIp as $fichier => $value)
386
{
1899 raphael.pi 387
	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_disable'></center></td><td><center><input type='submit' name='$value' value='$l_remove'></center></td></tr>";
1852 raphael.pi 388
}
1899 raphael.pi 389
//liste des fichiers desactivés
390
$fichiersIp = array_diff(scandir($dir_ip), array('ossi','ossi-ip-safesearch','..','.'));
391
$fichiersIp = preg_grep("/^ossi-/",$fichiersIp);
392
foreach($fichiersIp as $fichier => $value)
393
{
1903 raphael.pi 394
	echo "<tr><td bgcolor='BEBEBE'><center><a href='bl_categories_help.php?liste=wl&cat=$value&ossi=yes&filtre=domain&state=disable' 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 bgcolor='BEBEBE'><center>".exec("wc -l $dir_ip$value | awk '{print $1}'")."</center></td><td bgcolor='BEBEBE'><center>".exec("wc -l $dir_domain_names$value | awk '{print $1}'")."</center></td><td bgcolor='BEBEBE'><center><input type='submit' name='$value' value='$l_enable'></center></td><td bgcolor='BEBEBE'><center><input type='submit' name='$value' value='$l_remove'></center></td></tr>";
1899 raphael.pi 395
}
396
 
397
 
1852 raphael.pi 398
echo "</table><br/></td></form><form action='wl_filter.php' method='POST' enctype='multipart/form-data'>";
399
echo "<input type='hidden' name='choix' value='MAJ_ip_file_upload'><td width=50% colspan=5 align=center>";
400
echo "<H3>$l_add_file</H3>";
401
echo "$l_add_file_explain";
402
echo "<input type='file' name='fichier_ip'>";
403
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_submit'>";
404
echo "</td></tr>";
405
echo "</form>";
1843 raphael.pi 406
echo "</table><br/>";
407
?>
408
 
409
<table width="100%" border="0" cellspacing="0" cellpadding="0">
410
	<tr><th><?php echo $l_specific_filtering; ?></th></tr>
411
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
412
</table>
413
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
414
<FORM action='wl_filter.php' method='POST'>
415
<input type='hidden' name='choix' value='Specific_filtering'>
416
<tr><td>
417
 
418
<input type='checkbox' name='chk-safesearch'
419
<?php
420
//verification du safesearch
421
if(file_exists($dnsmasq_conf))
422
{
423
	$f=fopen($dnsmasq_conf, 'r');
424
	while(!feof($f))
425
	{
426
		$line=fgets($f,4096);
427
		if($line && preg_match('/^address=\/\.google/',$line,$r))
428
		{
429
			echo "checked";
430
			break;
431
		}
432
	}
433
	fclose($f);
434
}
435
else
436
	echo "$l_error_open_file $dnsmasq_conf";
437
echo "> $l_safe_searching";
438
 
439
echo "<br></br>$l_safe_youtube";
440
echo " $l_youtube_id<tr><td>";
441
 
1852 raphael.pi 442
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'></form></td></tr>";
1843 raphael.pi 443
?>
444
 
445
</TABLE><br/>
446
</BODY>
447
</HTML>