Subversion Repositories ALCASAR

Rev

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