Subversion Repositories ALCASAR

Rev

Rev 1344 | Rev 1390 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
318 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 filtering</TITLE>
6
<link rel="stylesheet" href="/css/style.css" type="text/css">
7
</HEAD>
8
<body>
9
<?
449 richard 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
}
1344 richard 18
function form_filter_ip($form_content, $color)
1339 richard 19
{
1344 richard 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
	}
1339 richard 38
}
318 richard 39
# Choice of language
40
$Language = 'en';
41
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
42
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
43
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
44
if($Language == 'fr'){
1041 richard 45
  $l_bl="Liste noire";
46
  $l_wl="Liste blanche";
47
  $l_list_version="Version de la liste : ";
48
  $l_bl_categories="Sélectionnez les catégories à filtrer";
49
  $l_wl_categories="Sélectionnez les catégories à autoriser";
878 richard 50
  $l_download_bl="Télécharger la dernière version";
51
  $l_fingerprint="L'empreinte numérique du fichier téléchargé est : ";
52
  $l_fingerprint2="Vérifiez-là en suivant ce lien (ligne 'blacklists.tar.gz') : ";
885 richard 53
  $l_activate_bl="Activer la nouvelle version";
54
  $l_reject_bl="Rejeter";
878 richard 55
  $l_warning="Temps estimé : une minute.";
56
  $l_specific_filtering="Filtrage special";
318 richard 57
  $l_forbidden_dns="Noms de domaine filtrés";
441 franck 58
  $l_forbidden_dns_explain="Entrez un nom de domaine par ligne (exemple : .domaine.org)";
1041 richard 59
  $l_allowed_dns="Noms de domaine autorisés";
441 franck 60
  $l_one_dns="Entrez un nom de domaine par ligne (exemple : .domaine.org)";
1339 richard 61
  $l_maj_rehabilitated="Noms de domaine ou IP réhabilités";
318 richard 62
  $l_rehabilitated_dns="Noms de domaine réhabilités";
878 richard 63
  $l_rehabilitated_dns_explain="Entrez ici des noms de domaine bloqués par la liste noire <BR> que vous souhaitez réhabiliter.";
1339 richard 64
  $l_add_to_bl="Noms de domaine ou IP ajoutés à la liste noire";
65
  $l_add_to_wl="Noms de domaine ou IP ajoutés à la liste blanche";
66
  $l_forbidden_ip="IP filtrés";
67
  $l_forbidden_ip_explain="Entrez une IP par ligne (exemple : 123.123.123.123)<br/>ou une ADRESSE RESEAU (exemple : 123.123.0.0/16)";
68
  $l_allowed_ip="IP authorisées";
69
  $l_rehabilitated_ip="IP réhabilitées";
70
  $l_rehabilitated_ip_explain="Entrez ici des IP bloquées par la liste noire <BR> que vous souhaitez réhabiliter.";
71
  $l_one_ip="Entrez une IP par ligne (exemple : 123.123.123.123)";
318 richard 72
  $l_record="Enregistrer les modifications";
1339 richard 73
  $l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
934 franck 74
  $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)";
75
  $l_safe_searching="Activer le contrôle scolaire/parental des moteurs de recherche : google, yahoo, bing, metacrawler et Youtube.";
885 richard 76
  $l_safe_youtube="Pour Youtube, entrez votre identifiant ici : "; 
77
  $l_youtube_id="(<a href='http://www.youtube.com/education_signup' target='cat_help' onclick=window.open('http://www.youtube.com/education_signup','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>)";
1332 richard 78
  $l_error_open_file="Erreur d'ouverture du fichier";
1339 richard 79
  $l_ip_file_title="Fichier d'IP";
80
  $l_file_list="Liste des fichiers IP";
81
  $l_add_ip_file="Ajouter un fichier d'IP (une IP par ligne)";
82
  $l_file_name="Nom du fichier";
83
  $l_file_remove="Supprimer";
84
  $l_error_upload="Erreur d'envoi du fichier d'ip";
85
  $l_remove="Supprimer";
86
  $l_submit="Envoyer";
87
  $l_nb_ip="Nombre d'IP";
1377 richard 88
  $l_update_ip="Mettre à jour les IP";
89
  $l_update_ip_info="(Temps estimé : 3 min 30 sec)";
90
  $l_nbDomainNames="Noms de domaine :";
91
  $l_nbUrl="Url :";
92
  $l_nbIp="Ip :";
318 richard 93
}
94
else {
1041 richard 95
  $l_bl="BlackList";
96
  $l_wl="WhiteList";
97
  $l_list_version="List version : ";
98
  $l_bl_categories="Select the categories to filter";
99
  $l_wl_categories="Select the categories to allow";
878 richard 100
  $l_download_bl="Download the last version";
101
  $l_fingerprint="The digital fingerprint of the downloaded blacklist is : ";
102
  $l_fingerprint2="Verify it with this link (line 'blacklists.tar.gz') : ";
885 richard 103
  $l_activate_bl="Activate the new version";
104
  $l_reject_bl="Reject";
878 richard 105
  $l_warning="Estimated time : one minute.";
106
  $l_specific_filtering="Specific filtering";
318 richard 107
  $l_forbidden_dns="Filtered domain names";
441 franck 108
  $l_forbidden_dns_explain="Enter one domain name per row (exemple : .domain.org)";
1041 richard 109
  $l_allowed_dns="Allowed domain names";
441 franck 110
  $l_one_dns="Enter one domain name per row (example : .domain.org)";
1339 richard 111
  $l_maj_rehabilitated="Domain names or IP rehabilitated";
318 richard 112
  $l_rehabilitated_dns="Rehabilitated domain names";
878 richard 113
  $l_rehabilitated_dns_explain="Enter here domain names that are blocked by the blacklist <BR> and you want to rehabilitate.";
1339 richard 114
  $l_add_to_bl="Domain names or IP to add to blacklist";
115
  $l_add_to_wl="Domain names or IP to add to whitelist";
116
  $l_forbidden_ip="Filtered IP";
117
  $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)";
118
  $l_allowed_ip="Allowed IP";
119
  $l_rehabilitated_ip="Rehabilitated IP";
120
  $l_rehabilitated_ip_explain="Enter here IP that are blocked by the blacklist <BR> and you want to rehabilitate.";
121
  $l_one_ip="Enter one IP per row (example : 123.123.123.123)";
318 richard 122
  $l_record="Save changes";
1377 richard 123
  $l_wait="Once validated, 10 seconds are necessary to compute your modifications";
878 richard 124
  $l_ip_filtering="Filtering URLs that contain an IP address instead of a domain name (ie: http://25.56.58.59/index.htm)";
885 richard 125
  $l_safe_searching="Enabling school/parental control for the search engines google, yahoo, bing, metacrawler and Youtube."; 
126
  $l_safe_youtube="For Youtube, enter your ID here : "; 
127
  $l_youtube_id="(<a href='http://www.youtube.com/education_signup' target='cat_help' onclick=window.open('http://www.youtube.com/education_signup','cat_help','width=800,height=600,toolbar=no,scrollbars=yes,resizable=yes') title='Youtube for school'>link to create a Youtube Id</a>)";
1339 richard 128
  $l_error_open_file="Error opening file";
129
  $l_ip_file_title="IP files";
130
  $l_file_list="IP files list";
131
  $l_add_ip_file="Add a file of IP (one IP per line)";
132
  $l_file_name="Filename";
133
  $l_file_remove="Remove";
134
  $l_error_upload="Error during the upload process";
135
  $l_remove="Delete";
136
  $l_submit="Submit";
137
  $l_nb_ip="Number of IP";
1377 richard 138
  $l_update_ip="Update IPs";
139
  $l_update_ip_info="(Estimated time : 3 min 30 sec)";
140
  $l_nbDomainNames="Domain names :";
141
  $l_nbUrl="Url :";
142
  $l_nbIp="Ip :";
318 richard 143
}
1041 richard 144
$dir_etc="/usr/local/etc/";
145
$dir_dg="/etc/dansguardian/lists/";
1339 richard 146
$dir_bl_ip="/usr/local/share/iptables-bl/";
1377 richard 147
$file_wl_ip="/usr/local/share/ossi-ip-wl";
1041 richard 148
$bl_categories=$dir_etc."alcasar-bl-categories";
149
$bl_categories_enabled=$dir_etc."alcasar-bl-categories-enabled";
150
$wl_categories=$dir_etc."alcasar-wl-categories";
151
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
152
$conf_file=$dir_etc."alcasar.conf";
153
$dir_blacklist=$dir_dg."blacklist/";
154
$urlregex_file=$dir_dg."urlregexplist";
155
$bannedsite_file=$dir_dg."bannedsitelist";
885 richard 156
$dir_tmp="/tmp/blacklists";
1339 richard 157
$upload_dir = "/usr/local/share/iptables-bl-enabled/";
885 richard 158
# default values
159
if (is_file ($conf_file))
160
	{
161
	$tab=file($conf_file);
162
	if ($tab)
163
		{
164
		foreach ($tab as $line)
165
			{
166
			$field=explode("=", $line);
167
			if ($field[0] == "YOUTUBE_ID")		{$YOUTUBE_ID=trim($field[1]);}
168
			}
169
		}
170
	}
171
else { echo "$l_error_open_file $conf_file";}
318 richard 172
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
173
switch ($choix)
174
{
1041 richard 175
case 'Download_list' :
389 franck 176
	exec ("sudo /usr/local/sbin/alcasar-bl.sh --download");
878 richard 177
	break;
1041 richard 178
case 'Active_list' :
878 richard 179
	exec ("sudo /usr/local/sbin/alcasar-bl.sh --adapt");
389 franck 180
	exec ("sudo /usr/local/sbin/alcasar-bl.sh --reload");
1377 richard 181
	shell_exec ("nohup nice -n 10 sudo /usr/local/sbin/alcasar-bl.sh --ip_retrieving > /dev/null 2>/dev/null &");
318 richard 182
	break;
1041 richard 183
case 'Reject_list' :
885 richard 184
	unlink ("$dir_tmp/blacklists.tar.gz"); unlink ("$dir_tmp/md5sum");
185
	break;
1041 richard 186
case 'MAJ_cat_bl' :
1332 richard 187
	$tab=file($bl_categories_enabled);
318 richard 188
	if ($tab)
189
		{
190
		$pointeur=fopen($bl_categories_enabled, "w+");
191
		foreach ($_POST as $key => $value)
192
			{
193
			if (strstr($key,'chk-'))
194
				{	
195
				$line=str_replace('chk-','',$key)."\n";
196
				fwrite($pointeur,$line);
197
				}
198
			}
199
		fclose($pointeur);
200
		}
201
	else {echo "$l_error_open_file $bl_categories_enabled";}
1041 richard 202
	$fichier=fopen($dir_dg."blacklists/ossi/domains","w+");
449 richard 203
	fputs($fichier, form_filter($_POST['OSSI_bl_domains']));
318 richard 204
	fclose($fichier);
205
	unset($_POST['OSSI_bl_domains']);
1041 richard 206
	$fichier=fopen($dir_dg."exceptionsitelist","w+");
207
	fputs($fichier, form_filter($_POST['BL_rehabilited_domains']));
318 richard 208
	fclose($fichier);
1041 richard 209
	unset($_POST['BL_rehabilited_domains']);
1339 richard 210
	$fichier=fopen($dir_bl_ip."ossi","w+");
1344 richard 211
	fputs($fichier, form_filter_ip($_POST['OSSI_bl_ip'], "black"));
318 richard 212
	fclose($fichier);
1339 richard 213
	unset($_POST['OSSI_bl_ip']);
214
	$fichier=fopen($dir_dg."exceptioniplist","w+");
215
	fputs($fichier, form_filter($_POST['BL_rehabilited_ip']));
1041 richard 216
	fclose($fichier);
1339 richard 217
	unset($_POST['BL_rehabilited_ip']);
1041 richard 218
	exec ("sudo /usr/local/sbin/alcasar-bl.sh --reload");
219
	break;
220
case 'MAJ_cat_wl' :
221
	$tab=file($wl_categories_enabled);	
222
	if ($tab)
223
		{
224
		$pointeur=fopen($wl_categories_enabled, "w+");
225
		foreach ($_POST as $key => $value)
226
			{
227
			if (strstr($key,'chk-'))
228
				{	
229
				$line=str_replace('chk-','',$key)."\n";
230
				fwrite($pointeur,$line);
231
				}
232
			}
233
		fclose($pointeur);
234
		}
235
	else {echo "$l_error_open_file $wl_categories_enabled";}
236
	$fichier=fopen($dir_dg."blacklists/ossi/domains_wl","w+");
237
	fputs($fichier, form_filter($_POST['OSSI_wl_domains']));
238
	fclose($fichier);
239
	unset($_POST['OSSI_wl_domains']);
1344 richard 240
	$fichier=fopen($file_wl_ip, "w+");
241
	fputs($fichier, form_filter_ip($_POST['OSSI_wl_ip'], "white"));
318 richard 242
	fclose($fichier);
1344 richard 243
	unset($_POST['OSSI_wl_ip']);
1377 richard 244
	exec ("sudo /usr/local/sbin/alcasar-bl.sh --ip_retrieving_ossi");
1042 richard 245
	exec ("sudo /usr/local/sbin/alcasar-bl.sh --reload");
318 richard 246
	break;
878 richard 247
case 'Specific_filtering' :
882 richard 248
	$pureip="-pureip_off"; $safesearch="-safesearch_off"; ;
249
	foreach ($_POST as $key => $value)
250
	{
251
		if (strstr($key,'chk-ip')) $pureip="-pureip_on";
252
		if (strstr($key,'chk-safesearch')) $safesearch="-safesearch_on";
253
	}
885 richard 254
	if ($_POST['Youtube_ID'] == '') { $New_ID="ABCD1234567890abcdef";} // default ID (no action) 
255
	else {$New_ID=$_POST['Youtube_ID'];}
256
	file_put_contents($conf_file, str_replace("YOUTUBE_ID=$YOUTUBE_ID", "YOUTUBE_ID=$New_ID", file_get_contents($conf_file)));
257
	$YOUTUBE_ID=$New_ID;
258
	exec ("sudo /usr/local/sbin/alcasar-url_filter.sh $safesearch $pureip");
1339 richard 259
	break;
260
case 'MAJ_ip_file_delete' :
261
	foreach($_POST as $fichier => $value)
262
	{
263
		if($fichier != "choix")
264
		{
265
			exec("rm -rf $upload_dir$fichier");
266
		}	
267
	}
268
	exec ("sudo /usr/local/bin/alcasar-iptables.sh");
269
	break;
270
case 'MAJ_ip_file_upload' :
271
	$nom = basename($_FILES['fichier_ip']['name']);
272
	# Si un fichier a été choisi
273
	if(!empty($nom))
274
	{	
275
		# On l'upload
1344 richard 276
		if(move_uploaded_file($_FILES['fichier_ip']['tmp_name'], $upload_dir.$nom))
1339 richard 277
		{
1344 richard 278
			# On extrait uniquement les ip du fichier
279
			exec("grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' $upload_dir$nom > $upload_dir\ossi-$nom");
280
		       	# On crée la sauvegarde du set
281
			exec("sed -i \"s/^/add blacklist_ip_blocked /g\" $upload_dir\ossi-$nom && rm -f $upload_dir$nom");
1339 richard 282
		}
283
		else
284
		{
285
			echo $l_error_upload;
286
		}
287
	}
288
	exec ("sudo /usr/local/bin/alcasar-iptables.sh");
289
	break;
1377 richard 290
case 'Update_IP_WL' :
291
	shell_exec ("nohup nice -n 10 sudo /usr/local/sbin/alcasar-bl.sh --ip_retrieving > /dev/null 2>/dev/null &");
292
	exec ("sudo /usr/local/sbin/alcasar-bl.sh --reload");
293
	break;
318 richard 294
}
295
?>
296
<?php
1377 richard 297
require ('bl_filter2.php');
318 richard 298
?>
299
</BODY>
300
</HTML>