Subversion Repositories ALCASAR

Rev

Rev 2054 | Rev 2299 | 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>
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 wl_ip_allowed $1\n", $new_list);
33
	}
34
	else
35
	{
36
		return preg_replace("/(.*)\n/", "add bl_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
}
64
 
65
# Choice of language
66
$Language = 'en';
67
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
68
	$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
69
	$Language = strtolower(substr(chop($Langue[0]),0,2)); 
70
	}
71
if($Language == 'fr'){
72
	$l_wl="Liste blanche générale";
73
	$l_load="Chargement...";
74
	$l_list_version="Version de la liste : ";
1975 richard 75
	$l_wl_categories="Sélectionnez les catégories à autoriser";
1954 richard 76
	$l_specific_filtering="Filtrage special";
1975 richard 77
	$l_add_to_wl="Noms de domaine ou adresses IP à ajouter à la liste blanche";
1954 richard 78
	$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";
79
	$l_record="Enregistrer les modifications";
80
	$l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
81
	$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)";
82
	$l_safe_searching="Activer le contrôle scolaire/parental des moteurs de recherche google.";
83
	$l_safe_youtube="Pour un contrôle parental sur Youtube, suivez les étapes ici : "; 
84
	$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>)";
85
	$l_error_open_file="Erreur d'ouverture du fichier";
86
	$l_additional_file_title="Fichiers de 'listes blanches' additionnels";
87
	$l_file_list="Liste des fichiers";
88
	$l_add_file="Ajouter un fichier";
89
	$l_add_file_explain="Chaque ligne du fichier doit être une adresse IP ou un nom de domaine"; 
90
	$l_file_name="Nom du fichier";
91
	$l_file_action="Action";
92
	$l_error_upload="Erreur d'envoi du fichier";
93
	$l_remove="Supprimer";
94
	$l_submit="Envoyer";
95
	$l_nb_ip="Nombre d'IP";
96
	$l_nb_domain_names="Nombre de noms de domaine";
97
	$l_nbDomainNames="Noms de domaine :";
98
	$l_nbUrl="Url :";
99
	$l_nbIp="Ip :";
100
	$l_disable="Désactiver";
101
	$l_enable="Activer";
102
	$l_file_state="Etat";
103
}
104
else {
105
	$l_wl="General WhiteList";
106
	$l_load="Loading...";
107
	$l_list_version="List version : ";
1975 richard 108
	$l_wl_categories="Select the allowed categories";
1954 richard 109
	$l_specific_filtering="Specific filtering";
110
	$l_allowed_dns="Allowed domain names";
1975 richard 111
	$l_add_to_wl="Domain names or IP addresses to add to the whitelist";
1954 richard 112
	$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";
113
	$l_record="Save changes";
114
	$l_wait="Once validated, 10 seconds are necessary to compute your modifications";
115
	$l_ip_filtering="Filtering URLs that contain an IP address instead of a domain name (ie: http://25.56.58.59/index.htm)";
116
	$l_safe_searching="Enabling school/parental control for the search engines google"; 
117
	$l_safe_youtube="For a safe Youtube search, follow these steps : "; 
118
	$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>)";
119
	$l_error_open_file="Error opening file";
120
	$l_additional_file_title="Additional WhiteList files";
121
	$l_file_list="Files list";
122
	$l_add_file="Add a file";
123
	$l_add_file_explain="Each line of the file must be an IP address or a domain name"; 
124
	$l_file_name="Filename";
125
	$l_file_action="Action";
126
	$l_error_upload="Error during the upload process";
127
	$l_remove="Delete";
128
	$l_submit="Submit";
129
	$l_nb_ip="Number of IP";
130
	$l_nb_domain_names="Number of domain names";
131
	$l_nbDomainNames="Domain names :";
132
	$l_nbUrl="Url :";
133
	$l_nbIp="Ip :";
134
	$l_disable="Disable";
135
	$l_enable="Enable";
136
	$l_file_state="State";
137
}
138
$dir_etc="/usr/local/etc/";
139
$dir_dg="/etc/dansguardian/lists/";
140
$dir_blacklist=$dir_dg."blacklists/";
141
$dir_wl_ip="/usr/local/share/iptables-wl/";
142
$dir_wl_ip_enabled= "/usr/local/share/iptables-wl-enabled/";
143
$dir_wl_domain_names= "/usr/local/share/dnsmasq-wl/";
144
$dir_wl_domain_names_enabled= "/usr/local/share/dnsmasq-wl-enabled/";
145
$wl_categories=$dir_etc."alcasar-wl-categories";
146
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
147
$conf_file=$dir_etc."alcasar.conf";
148
$urlregex_file=$dir_dg."urlregexplist";
149
$bannedsite_file=$dir_dg."bannedsitelist";
150
$dir_tmp="/tmp/blacklists";
151
 
152
 
153
# default values
154
if (is_file ($conf_file))
155
	{
156
	$tab=file($conf_file);
157
	if ($tab)
158
		{
159
		foreach ($tab as $line)
160
			{
161
			$field=explode("=", $line);
162
			if ($field[0] == "PRIVATE_IP")
163
				{
164
				$PRIVATE_IP_MASK=trim($field[1]);
165
				$tmp = explode("/",$PRIVATE_IP_MASK);
166
				$PRIVATE_IP=$tmp[0];
167
				}
168
			}
169
		}
170
	}	
171
else { echo "$l_error_open_file $conf_file";}
172
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
173
switch ($choix)
174
{
175
case 'Download_list' :
176
	exec ("sudo /usr/local/bin/alcasar-bl.sh --download");
177
	break;
178
case 'Active_list' :
179
	exec ("sudo /usr/local/bin/alcasar-bl.sh --adapt");
180
	exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
181
	break;
182
case 'Reject_list' :
183
	unlink ("$dir_tmp/blacklists.tar.gz"); unlink ("$dir_tmp/md5sum");
184
	break;
185
case 'MAJ_cat_wl' :
186
	if (file_exists($wl_categories_enabled))
187
	{
1958 richard 188
		exec("/bin/sed -i \"/^ossi-/!d\" $wl_categories_enabled"); // keep ossi custom categories
189
		$pointeur=fopen($wl_categories_enabled, "a+");
1954 richard 190
		foreach ($_POST as $key => $value)
191
		{
192
			if (strstr($key,'chk-'))
193
			{	
194
				$line=str_replace('chk-','',$key)."\n";
195
				fwrite($pointeur,$line);
196
			}
197
		}
198
 
199
		fclose($pointeur);
200
	}
201
	else {echo "$l_error_open_file $wl_categories_enabled";}
202
	$fichier=fopen($dir_blacklist."ossi-wl/domains","w+");
203
	fputs($fichier, form_filter($_POST['OSSI_wl']));
204
	fclose($fichier);
205
	unset($_POST['OSSI_wl']);
206
	exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
207
	break;
208
case 'Specific_filtering' :
209
	$pureip="-pureip_off"; $safesearch="-safesearch_off"; ;
210
	foreach ($_POST as $key => $value)
211
	{
212
		if (strstr($key,'chk-ip')) $pureip="-pureip_on";
213
		if (strstr($key,'chk-safesearch')) $safesearch="-safesearch_on";
214
	}
215
	exec ("sudo /usr/local/bin/alcasar-url_filter_bl.sh $safesearch $pureip");
216
	break;
217
case 'MAJ_ossi_file' :
218
	foreach($_POST as $fichier => $value)
219
	{
220
		if($fichier != "choix")
221
		{
222
			$action=$_POST[$fichier];
223
			if($action == $l_remove) //delete
224
			{
225
				exec("/bin/sed -i \"/^$fichier$/d\" $wl_categories_enabled"); 
226
				exec("rm -rf $dir_blacklist$fichier");
227
				exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
228
			}
229
			if($action == $l_disable) //disable
230
			{
231
				exec("/bin/sed -i \"/^$fichier$/d\" $wl_categories_enabled"); 
232
				exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
233
			}
234
			if($action == $l_enable) //enable
235
			{
236
				file_put_contents ($wl_categories_enabled, $fichier."/n", FILE_APPEND);
237
				exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
238
			}
239
		}
240
	}
241
	break;
242
case 'MAJ_ossi_file_upload' :
243
	$file_name = str_replace (".", "_",basename($_FILES['fichier_ip']['name']));
244
	if(!empty($file_name))
245
	{	
246
		$dest_dir = $dir_blacklist."ossi-wl-".$file_name;
247
		exec ("mkdir $dest_dir");
2005 raphael.pi 248
		$file=$_FILES['fichier_ip']['tmp_name'];
249
                exec("/usr/bin/dos2unix $file $file");
1954 richard 250
		if(move_uploaded_file($_FILES['fichier_ip']['tmp_name'], $dest_dir."/domains"))
251
		{
1955 richard 252
			touch ($dest_dir."/urls"); // create the URL file even if it isn't used
1954 richard 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");
256
		}
257
		else
258
		{
259
			exec("rm -rf $dest_dir");
260
			echo $l_error_upload;
261
		}
262
	}
263
	break;
264
}
265
?>
266
<table width="100%" border="0" cellspacing="0" cellpadding="0">
267
	<tr><th><?php echo $l_wl; ?></th></tr>
268
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
269
</table>
270
<table width="100%" border=1 cellspacing=0 cellpadding=1>
271
<tr><td valign="middle" align="left" colspan=10>
272
<FORM action='wl_filter.php' method=POST>
273
<input type='hidden' name='choix' value='MAJ_cat_wl'>
274
<?php
275
echo "<center>";
276
// total number of IP, DNS & URLs
277
$nbDomainNames = exec ("wc -l /usr/local/share/dnsmasq-wl/* | tail -n 1 | awk '{print $1}'");
278
$nbUrl = "0";
279
$nbIp = exec ("wc -l /usr/local/share/iptables-wl/* | tail -n 1 | awk '{print $1}'");
280
echo "<b>$l_nbDomainNames</b> $nbDomainNames, <b>$l_nbUrl</b> $nbUrl, <b>$l_nbIp</b> $nbIp<br/>";
281
echo "$l_wl_categories</center></td></tr>";	
282
//read & display all WL categories (checked or not)
283
$cols=1; 
284
if (file_exists($wl_categories))
285
	{
286
	$wl_files = file($wl_categories);
287
	$wl_files = preg_grep("/ossi-/", $wl_files, 1); // don't display ossi custom categories
288
	foreach($wl_files as $fichier => $value)
289
		{
290
		if ($cols == 1) { echo "<tr>";}
291
		$categorie=trim(basename($value));
292
		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>";
293
		echo "<input type='checkbox' name='chk-$categorie'";
294
		// if the line is commented, the category is disable
295
		if (preg_match('/^#/',$value, $r)) { echo ">";}
296
		else { echo "checked>"; }
297
		echo "</td>";
298
		$cols++;
299
		if ($cols > 10) {
300
			echo "</tr>";
301
			$cols=1; }
302
		}
303
	}
304
else	{
305
	echo "$l_error_open_file $wl_categories";
306
}
307
echo "<tr><td valign='middle' align='left' colspan=10>";
308
echo "<center><b>$l_add_to_wl</b></center></td></tr>";
309
echo "<tr><td width=100% colspan=10 align=center>";
310
echo "$l_one_dns_ip<BR>";
311
echo "<textarea name='OSSI_wl' rows=3 cols=40>";
312
echo_file ($dir_blacklist."ossi-wl/domains");
313
echo "</textarea></td>";
314
echo "</tr><tr><td colspan=10>";
2054 raphael.pi 315
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';submit();\" value='$l_record'>";
1954 richard 316
echo "</form> ($l_wait)";
317
echo "</td></tr></table><br/>";
318
?>
319
<table width="100%" border="0" cellspacing="0" cellpadding="0">
320
	<tr><th><?php echo $l_additional_file_title; ?></th></tr>
321
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
322
</table>
323
<table width="100%" border=1 cellspacing=0 cellpadding=1>
324
<form action='wl_filter.php' method='POST'>
325
<input type='hidden' name='choix' value='MAJ_ossi_file'>
326
<?php
327
echo "<tr><td width=50% colspan=5 align=center>";
328
echo "<H3>$l_file_list</H3>";
329
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>";
330
 
331
//list OSSI custom categories
332
$fichierswl = array_diff(scandir($dir_blacklist), array('..','.','ossi-bl','ossi-wl'));
333
$fichierswl = preg_grep("/^ossi-wl-/",$fichierswl);
334
foreach($fichierswl as $fichier => $value)
335
{
336
	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'";
337
	if (file_exists ($dir_wl_domain_names_enabled.$value)) echo " value='$l_disable'>"; else echo " value='$l_enable'>";
338
	echo "</center></td><td><center><input type='submit' name='$value' value='$l_remove'></center></td></tr>";
339
}
340
echo "</table><br/></td></form><form action='wl_filter.php' method='POST' enctype='multipart/form-data'>";
341
echo "<input type='hidden' name='choix' value='MAJ_ossi_file_upload'><td width=50% colspan=5 align=center>";
342
echo "<H3>$l_add_file</H3>";
343
echo "$l_add_file_explain";
344
echo "<input type='file' name='fichier_ip'>";
2054 raphael.pi 345
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';submit();\" value='$l_submit'>";
1954 richard 346
echo "</td></tr>";
347
echo "</form>";
348
echo "</table><br/>";
349
?>
350
<table width="100%" border="0" cellspacing="0" cellpadding="0">
351
	<tr><th><?php echo $l_specific_filtering; ?></th></tr>
352
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
353
</table>
354
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
355
<FORM action='wl_filter.php' method='POST'>
356
<input type='hidden' name='choix' value='Specific_filtering'>
357
<tr><td>
358
<input type='checkbox' name='chk-ip'
359
<?php
360
// verify "pureip" filtering state
361
if (file_exists($bannedsite_file))
362
	{
363
	$pointeur=fopen($bannedsite_file,"r");
364
	while (!feof ($pointeur))
365
		{
366
		$ligne=fgets($pointeur, 4096);
367
		if ($ligne)
368
			{
369
			if (preg_match('/^\*ip$/',$ligne, $r)) 
370
				{
371
				echo " checked";
372
				break;
373
				}
374
			}
375
		}
376
	fclose($pointeur);
377
	}
378
else	{
379
	echo "$l_error_open_file $bannedsite_file";
380
	}
381
echo "> $l_ip_filtering";
382
?>
383
</td></tr>
384
<tr><td>
385
<input type='checkbox' name='chk-safesearch'
386
<?php
387
// verify "safesearch" filtering state
388
if (file_exists($urlregex_file))
389
	{
390
	$pointeur=fopen($urlregex_file,"r");
391
	while (!feof ($pointeur))
392
		{
393
		$ligne=fgets($pointeur, 4096);
394
		if ($ligne)
395
			{
396
			if (preg_match('/^\"\(\^http\:\/\/\[0\-9a\-z\]\+\\\.google/',$ligne, $r))
397
				{
398
				echo " checked";
399
				break;
400
				}
401
			}
402
		}
403
	fclose($pointeur);
404
	}
405
else	{
406
	echo "$l_error_open_file $urlregex_file";
407
	}
408
echo "> $l_safe_searching";
409
echo "<br>$l_safe_youtube";
410
echo " $l_youtube_id<tr><td>";
2054 raphael.pi 411
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';submit();\" value='$l_record'></td></tr>";
1954 richard 412
?>
413
</FORM> 
414
</TABLE>
415
</BODY>
416
</HTML>
417
 
418