Subversion Repositories ALCASAR

Rev

Rev 1867 | Rev 1878 | 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'])){
94
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
95
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
96
if($Language == 'fr'){
97
  $l_wl="Liste blanche";
1852 raphael.pi 98
  $l_load="Chargement...";
1843 raphael.pi 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";
1852 raphael.pi 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";
1843 raphael.pi 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.";
1852 raphael.pi 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>)";
1843 raphael.pi 128
 
129
}
130
else {
131
  $l_wl="WhiteList";
1852 raphael.pi 132
  $l_load="Loading...";
1843 raphael.pi 133
  $l_list_version="List version : ";
134
  $l_wl_categories="Select the categories to allow";
135
  $l_allowed_dns="Allowed domain names";
136
  $l_one_dns="Enter one domain name per row (example : .domain.org)";
137
  $l_add_to_wl="Domain names or IP to add to whitelist";
138
  $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)";
139
  $l_allowed_ip="Allowed IP";
140
  $l_record="Save changes";
141
  $l_wait="Once validated, 10 seconds are necessary to compute your modifications";
142
  $l_error_open_file="Error opening file";
1852 raphael.pi 143
  $l_additional_file_title="Additional whitelist files";
144
  $l_file_list="Files list";
145
  $l_add_file="Add a file";
146
  $l_add_file_explain="Each line of the file must be an IP address or a domain name"; 
147
  $l_file_name="Filename";
148
  $l_file_remove="Remove";
149
  $l_error_upload="Error during the upload process";
150
  $l_remove="Delete";
1843 raphael.pi 151
  $l_submit="Submit";
152
  $l_nb_ip="Number of IP";
153
  $l_nb_domain_names="Number of domain names";
154
  $l_nbDomainNames="Domain names :";
155
  $l_nbUrl="Url :";
156
  $l_nbIp="Ip :";
157
  $l_ip_filtering="Filtering URLs that contain an IP address instead of a domain name (ie: http://25.56.58.59/index.htm)";
158
  $l_specific_filtering="Specific filtering";
1852 raphael.pi 159
  $l_safe_youtube="For safe Youtube, follow steps here for each computer "; 
160
  $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>)";
161
  $l_safe_searching="Enabling school/parental control for the search engines google."; 
1843 raphael.pi 162
 
163
}
164
$dir_etc="/usr/local/etc/";
165
$dir_dg="/etc/dansguardian/lists/";
1855 raphael.pi 166
$file_wl_domains="/usr/local/share/dnsmasq-wl/ossi.conf";
1852 raphael.pi 167
$file_wl_ip="/usr/local/share/iptables-wl-enabled/ossi";
1843 raphael.pi 168
$wl_categories=$dir_etc."alcasar-wl-categories";
169
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
170
$conf_file=$dir_etc."alcasar.conf";
171
$tinyproxy_conf="/etc/tinyproxy/tinyproxy.conf";
172
$dnsmasq_conf="/etc/dnsmasq-whitelist.conf";
1852 raphael.pi 173
$dir_tmp="/tmp/";
174
$upload_dir_ip = "/usr/local/share/iptables-wl-enabled/";
175
$upload_dir_domain_names = "/usr/local/share/dnsmasq-wl-enabled/";
1843 raphael.pi 176
# default values
177
if (is_file ($conf_file))
178
	{
179
	$tab=file($conf_file);
180
	if ($tab)
181
		{
182
		foreach ($tab as $line)
183
			{
184
			$field=explode("=", $line);
1852 raphael.pi 185
			if ($field[0] == "DNS1")
1843 raphael.pi 186
				{
1852 raphael.pi 187
					$DNS1=trim($field[1]);
1843 raphael.pi 188
				}
189
			}
190
		}
191
	}
192
else { echo "$l_error_open_file $conf_file";}
193
 
194
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
195
switch ($choix)
196
{
197
case 'Specific_filtering' :
198
	$safesearch="-safesearch_off"; ;
199
	foreach ($_POST as $key => $value)
200
	{
201
		if (strstr($key,'chk-safesearch')) $safesearch="-safesearch_on";
202
	}
203
	exec ("sudo /usr/local/bin/alcasar-url_filter_wl.sh $safesearch");
204
	break;
205
case 'MAJ_cat_wl' :
206
	if (file_exists($wl_categories_enabled))
207
		{
208
		$pointeur=fopen($wl_categories_enabled, "w+");
209
		foreach ($_POST as $key => $value)
210
			{
211
			if (strstr($key,'chk-'))
212
				{	
213
				$line=str_replace('chk-','',$key)."\n";
214
				fwrite($pointeur,$line);
215
				}
216
			}
217
		fclose($pointeur);
218
		}
219
	else {echo "$l_error_open_file $wl_categories_enabled";}
1855 raphael.pi 220
	$fichier=fopen($file_wl_domains,"w+");
1843 raphael.pi 221
	fputs($fichier, form_filter($_POST['OSSI_wl_domains']));
222
	fclose($fichier);
223
	unset($_POST['OSSI_wl_domains']);
224
	$fichier=fopen($file_wl_ip, "w+");
225
	fputs($fichier, form_filter_ip($_POST['OSSI_wl_ip'], "white"));
226
	fclose($fichier);
227
	unset($_POST['OSSI_wl_ip']);
228
	exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
229
	break;
1852 raphael.pi 230
	case 'MAJ_ip_file_delete' :
231
	foreach($_POST as $fichier => $value)
232
	{
233
		if($fichier != "choix")
234
		{
235
			exec("rm -rf $upload_dir_ip$fichier");
236
			exec("rm -rf $upload_dir_domain_names$fichier");
237
			exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
238
		}
239
	}
240
	break;
241
case 'MAJ_ip_file_upload' :
242
	$nom = str_replace (".", "_",basename($_FILES['fichier_ip']['name']));
243
	# Si un fichier a été choisi
244
	if(!empty($nom))
245
	{	
246
		# On l'upload
247
		if(move_uploaded_file($_FILES['fichier_ip']['tmp_name'], $upload_dir_ip.$nom))
248
		{
249
 
250
		# On extrait uniquement les ip du fichier
251
		exec("grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' $upload_dir_ip$nom > $upload_dir_ip\ossi_ip");
252
 
253
		# Suppression des doublons
254
		exec("sort -u $upload_dir_ip\ossi_ip > $upload_dir_ip\ossi-$nom && rm -f $upload_dir_ip\ossi_ip");
255
 
256
		# On adapte le fichier à la sauvegarde du set
1867 raphael.pi 257
		exec("sed -i \"s/^/add wl_ip_allowed /g\" $upload_dir_ip\ossi-$nom"); 
1852 raphael.pi 258
 
259
		# On extrait uniquement les noms de domaine
260
		# max_tld() retourne le nombre max de charactere pour un top-level dns
261
		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");
262
 
263
		# Suppression des doublons
264
		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");
265
 
266
		# On adapte le fichier pour Dnsmasq
267
		exec("sed -i \"s/^/server=\//g\" $upload_dir_domain_names\ossi-$nom");
268
		exec("sed -i \"s/$/\/$DNS1/g\" $upload_dir_domain_names\ossi-$nom");
269
 
270
		# Suppression du fichier
271
		exec("rm -f $upload_dir_ip$nom");
272
 
273
		}
274
		else
275
		{
276
			echo $l_error_upload;
277
		}
278
		exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
279
	}
280
	break;
1843 raphael.pi 281
}
282
?>
283
<table width="100%" border="0" cellspacing="0" cellpadding="0">
284
	<tr><th><?php echo $l_wl; ?></th></tr>
285
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
286
</table>
287
 
288
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
289
<tr><td valign="middle" align="left" colspan=10>
290
<FORM action='wl_filter.php' method=POST>
291
<input type='hidden' name='choix' value='MAJ_cat_wl'>
292
<?php
293
echo "<center>";
294
$nbDomainNames = exec ("wc -l /usr/local/share/dnsmasq-wl/* | tail -n 1 | awk '{print $1}'");
295
$nbUrl = 0;
296
$nbIp = 0;
297
echo "<b>$l_nbDomainNames</b> $nbDomainNames, <b>$l_nbUrl</b> $nbUrl, <b>$l_nbIp</b> $nbIp<br/>";
298
echo "$l_wl_categories</center></td></tr>";
299
//on lit et on interprete le fichier de catégories
300
$cols=1; 
301
if (file_exists($wl_categories))
302
	{
303
	$pointeur=fopen($wl_categories,"r");
304
	while (!feof ($pointeur))
305
		{
306
		$ligne=fgets($pointeur, 4096);
307
		if ($ligne)
308
			{
309
			if ($cols == 1) { echo "<tr>";}
310
			$categorie=trim(basename($ligne));
311
			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>";
312
			echo "<input type='checkbox' name='chk-$categorie'";
313
			// si la ligne est commentée -> categorie non selectionnée
314
			if (preg_match('/^#/',$ligne, $r)) { echo ">";}
315
			else { echo "checked>"; }
316
			echo "</td>";
317
			$cols++;
318
			if ($cols > 10) {
319
				echo "</tr>";
320
				$cols=1; }
321
			}
322
		}
323
	fclose($pointeur);
324
	}
325
else	{
326
	echo "$l_error_open_file $wl_categories";
327
	}
328
echo "<tr><td valign='middle' align='left' colspan=10>";
329
echo "<center><b>$l_add_to_wl</b></center></td></tr>";
330
echo "<tr><td width=50% colspan=5 align=center>";
331
echo "<H3>$l_allowed_dns</H3>$l_one_dns<BR>";
332
echo "<textarea name='OSSI_wl_domains' rows=3 cols=40>";
1855 raphael.pi 333
echo_file ($file_wl_domains);
1843 raphael.pi 334
echo "</textarea></td>";
335
echo "<td width=50% colspan=5 align=center>";
336
echo "<H3>$l_allowed_ip</H3>$l_forbidden_ip_explain<BR>";
337
echo "<textarea name='OSSI_wl_ip' rows=3 cols=40>";
338
echo_ip_file ($file_wl_ip);
339
echo "</textarea></td></tr>";
340
echo "<tr><td colspan=10>";
1852 raphael.pi 341
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'></form></td></tr>";
342
echo "</td></tr></table><br/>";
343
?>
344
 
345
<table width="100%" border="0" cellspacing="0" cellpadding="0">
346
	<tr><th><?php echo $l_additional_file_title; ?></th></tr>
347
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
348
</table>
349
 
350
<table width="100%" border=1 cellspacing=0 cellpadding=1>
351
<form action='wl_filter.php' method='POST'>
352
<input type='hidden' name='choix' value='MAJ_ip_file_delete'>
353
<?php
354
echo "<tr><td width=50% colspan=5 align=center>";
355
echo "<H3>$l_file_list</H3>";
356
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>";
1876 raphael.pi 357
 
358
$fichiersIp = array_diff(scandir($upload_dir_ip), array('ossi','ossi-ip-safesearch','..','.'));
1852 raphael.pi 359
foreach($fichiersIp as $fichier => $value)
360
{
1867 raphael.pi 361
	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_remove'></center></td></tr>";
1852 raphael.pi 362
}
363
echo "</table><br/></td></form><form action='wl_filter.php' method='POST' enctype='multipart/form-data'>";
364
echo "<input type='hidden' name='choix' value='MAJ_ip_file_upload'><td width=50% colspan=5 align=center>";
365
echo "<H3>$l_add_file</H3>";
366
echo "$l_add_file_explain";
367
echo "<input type='file' name='fichier_ip'>";
368
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_submit'>";
369
echo "</td></tr>";
370
echo "</form>";
1843 raphael.pi 371
echo "</table><br/>";
372
?>
373
 
374
<table width="100%" border="0" cellspacing="0" cellpadding="0">
375
	<tr><th><?php echo $l_specific_filtering; ?></th></tr>
376
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
377
</table>
378
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
379
<FORM action='wl_filter.php' method='POST'>
380
<input type='hidden' name='choix' value='Specific_filtering'>
381
<tr><td>
382
 
383
<input type='checkbox' name='chk-safesearch'
384
<?php
385
//verification du safesearch
386
if(file_exists($dnsmasq_conf))
387
{
388
	$f=fopen($dnsmasq_conf, 'r');
389
	while(!feof($f))
390
	{
391
		$line=fgets($f,4096);
392
		if($line && preg_match('/^address=\/\.google/',$line,$r))
393
		{
394
			echo "checked";
395
			break;
396
		}
397
	}
398
	fclose($f);
399
}
400
else
401
	echo "$l_error_open_file $dnsmasq_conf";
402
echo "> $l_safe_searching";
403
 
404
echo "<br></br>$l_safe_youtube";
405
echo " $l_youtube_id<tr><td>";
406
 
1852 raphael.pi 407
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'></form></td></tr>";
1843 raphael.pi 408
?>
409
 
410
</TABLE><br/>
411
</BODY>
412
</HTML>