Subversion Repositories ALCASAR

Rev

Rev 1843 | Rev 1854 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1843 Rev 1852
Line 59... Line 59...
59
	for($i=0; $i<exec("wc -l $filename"); $i++)
59
	for($i=0; $i<exec("wc -l $filename"); $i++)
60
	{
60
	{
61
		echo $resultat[$i]."\n";
61
		echo $resultat[$i]."\n";
62
	}
62
	}
63
}
63
}
-
 
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
 
64
# Choice of language
86
# Choice of language
65
$Language = 'en';
87
$Language = 'en';
66
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
88
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
67
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
89
  $Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
68
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
90
  $Language = strtolower(substr(chop($Langue[0]),0,2)); }
69
if($Language == 'fr'){
91
if($Language == 'fr'){
70
  $l_wl="Liste blanche";
92
  $l_wl="Liste blanche";
-
 
93
  $l_load="Chargement...";
71
  $l_list_version="Version de la liste : ";
94
  $l_list_version="Version de la liste : ";
72
  $l_specific_filtering="Filtrage special";
95
  $l_specific_filtering="Filtrage special";
73
  $l_wl_categories="Sélectionnez les catégories à autoriser";
96
  $l_wl_categories="Sélectionnez les catégories à autoriser";
74
  $l_allowed_dns="Noms de domaine autorisés";
97
  $l_allowed_dns="Noms de domaine autorisés";
75
  $l_one_dns="Entrez un nom de domaine par ligne (exemple : .domaine.org)";
98
  $l_one_dns="Entrez un nom de domaine par ligne (exemple : .domaine.org)";
Line 77... Line 100...
77
  $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)";
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)";
78
  $l_allowed_ip="IP autorisées";
101
  $l_allowed_ip="IP autorisées";
79
  $l_record="Enregistrer les modifications";
102
  $l_record="Enregistrer les modifications";
80
  $l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
103
  $l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
81
  $l_error_open_file="Erreur d'ouverture du fichier";
104
  $l_error_open_file="Erreur d'ouverture du fichier";
-
 
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";
82
  $l_submit="Envoyer";
113
  $l_submit="Envoyer";
83
  $l_nb_ip="Nombre d'IP";
114
  $l_nb_ip="Nombre d'IP";
84
  $l_nb_domain_names="Nombre de noms de domaine";
115
  $l_nb_domain_names="Nombre de noms de domaine";
85
  $l_nbDomainNames="Noms de domaine :";
116
  $l_nbDomainNames="Noms de domaine :";
86
  $l_nbUrl="Url :";
117
  $l_nbUrl="Url :";
87
  $l_nbIp="Ip :";
118
  $l_nbIp="Ip :";
88
  $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)";
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)";
89
  $l_safe_searching="Activer le contrôle scolaire/parental des moteurs de recherche : google, yahoo, bing, metacrawler et Youtube.";
120
  $l_safe_searching="Activer le contrôle scolaire/parental des moteurs de recherche : google, yahoo, bing, metacrawler et Youtube.";
90
  $l_safe_youtube="Pour Youtube sain, suivez les étapes ici pour chaque poste : "; 
121
  $l_safe_youtube="Pour Youtube restreint, suivez les étapes ici pour chaque poste : "; 
91
  $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>)";
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>)";
92
  
123
  
93
}
124
}
94
else {
125
else {
95
  $l_wl="WhiteList";
126
  $l_wl="WhiteList";
-
 
127
  $l_load="Loading...";
96
  $l_list_version="List version : ";
128
  $l_list_version="List version : ";
97
  $l_wl_categories="Select the categories to allow";
129
  $l_wl_categories="Select the categories to allow";
98
  $l_allowed_dns="Allowed domain names";
130
  $l_allowed_dns="Allowed domain names";
99
  $l_one_dns="Enter one domain name per row (example : .domain.org)";
131
  $l_one_dns="Enter one domain name per row (example : .domain.org)";
100
  $l_add_to_wl="Domain names or IP to add to whitelist";
132
  $l_add_to_wl="Domain names or IP to add to whitelist";
101
  $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)";
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)";
102
  $l_allowed_ip="Allowed IP";
134
  $l_allowed_ip="Allowed IP";
103
  $l_record="Save changes";
135
  $l_record="Save changes";
104
  $l_wait="Once validated, 10 seconds are necessary to compute your modifications";
136
  $l_wait="Once validated, 10 seconds are necessary to compute your modifications";
105
  $l_error_open_file="Error opening file";
137
  $l_error_open_file="Error opening file";
-
 
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";
106
  $l_submit="Submit";
146
  $l_submit="Submit";
107
  $l_nb_ip="Number of IP";
147
  $l_nb_ip="Number of IP";
108
  $l_nb_domain_names="Number of domain names";
148
  $l_nb_domain_names="Number of domain names";
109
  $l_nbDomainNames="Domain names :";
149
  $l_nbDomainNames="Domain names :";
110
  $l_nbUrl="Url :";
150
  $l_nbUrl="Url :";
111
  $l_nbIp="Ip :";
151
  $l_nbIp="Ip :";
112
  $l_ip_filtering="Filtering URLs that contain an IP address instead of a domain name (ie: http://25.56.58.59/index.htm)";
152
  $l_ip_filtering="Filtering URLs that contain an IP address instead of a domain name (ie: http://25.56.58.59/index.htm)";
113
  $l_specific_filtering="Specific filtering";
153
  $l_specific_filtering="Specific filtering";
114
  $l_safe_youtube="For Safe Youtube, follow steps here for each computer "; 
154
  $l_safe_youtube="For safe Youtube, follow steps here for each computer "; 
115
  $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>)";
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>)";
116
  $l_safe_searching="Enabling school/parental control for the search engines google, yahoo, bing, metacrawler and Youtube."; 
156
  $l_safe_searching="Enabling school/parental control for the search engines google."; 
117
  
157
  
118
}
158
}
119
$dir_etc="/usr/local/etc/";
159
$dir_etc="/usr/local/etc/";
120
$dir_dg="/etc/dansguardian/lists/";
160
$dir_dg="/etc/dansguardian/lists/";
121
$file_wl_ip="/usr/local/share/ossi-ip-wl";
161
$file_wl_ip="/usr/local/share/iptables-wl-enabled/ossi";
122
$wl_categories=$dir_etc."alcasar-wl-categories";
162
$wl_categories=$dir_etc."alcasar-wl-categories";
123
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
163
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
124
$conf_file=$dir_etc."alcasar.conf";
164
$conf_file=$dir_etc."alcasar.conf";
125
$tinyproxy_conf="/etc/tinyproxy/tinyproxy.conf";
165
$tinyproxy_conf="/etc/tinyproxy/tinyproxy.conf";
126
$dnsmasq_conf="/etc/dnsmasq-whitelist.conf";
166
$dnsmasq_conf="/etc/dnsmasq-whitelist.conf";
-
 
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/";
127
# default values
170
# default values
128
if (is_file ($conf_file))
171
if (is_file ($conf_file))
129
	{
172
	{
130
	$tab=file($conf_file);
173
	$tab=file($conf_file);
131
	if ($tab)
174
	if ($tab)
132
		{
175
		{
133
		foreach ($tab as $line)
176
		foreach ($tab as $line)
134
			{
177
			{
135
			$field=explode("=", $line);
178
			$field=explode("=", $line);
136
			if ($field[0] == "PRIVATE_IP")
179
			if ($field[0] == "DNS1")
137
				{
180
				{
138
				$PRIVATE_IP_MASK=trim($field[1]);
181
					$DNS1=trim($field[1]);
139
				$tmp = explode("/",$PRIVATE_IP_MASK);
-
 
140
				$PRIVATE_IP=$tmp[0];
-
 
141
				}
182
				}
142
			}
183
			}
143
		}
184
		}
144
	}
185
	}
145
else { echo "$l_error_open_file $conf_file";}
186
else { echo "$l_error_open_file $conf_file";}
Line 178... Line 219...
178
	fputs($fichier, form_filter_ip($_POST['OSSI_wl_ip'], "white"));
219
	fputs($fichier, form_filter_ip($_POST['OSSI_wl_ip'], "white"));
179
	fclose($fichier);
220
	fclose($fichier);
180
	unset($_POST['OSSI_wl_ip']);
221
	unset($_POST['OSSI_wl_ip']);
181
	exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
222
	exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
182
	break;
223
	break;
-
 
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;
183
}
276
}
184
?>
277
?>
185
<table width="100%" border="0" cellspacing="0" cellpadding="0">
278
<table width="100%" border="0" cellspacing="0" cellpadding="0">
186
	<tr><th><?php echo $l_wl; ?></th></tr>
279
	<tr><th><?php echo $l_wl; ?></th></tr>
187
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
280
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
Line 238... Line 331...
238
echo "<H3>$l_allowed_ip</H3>$l_forbidden_ip_explain<BR>";
331
echo "<H3>$l_allowed_ip</H3>$l_forbidden_ip_explain<BR>";
239
echo "<textarea name='OSSI_wl_ip' rows=3 cols=40>";
332
echo "<textarea name='OSSI_wl_ip' rows=3 cols=40>";
240
echo_ip_file ($file_wl_ip);
333
echo_ip_file ($file_wl_ip);
241
echo "</textarea></td></tr>";
334
echo "</textarea></td></tr>";
242
echo "<tr><td colspan=10>";
335
echo "<tr><td colspan=10>";
-
 
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>";
243
echo "</table><br/>";
365
echo "</table><br/>";
244
echo "<input type='submit' value='$l_record'></form></td></tr>";
-
 
245
?>
366
?>
246
 
367
 
247
<table width="100%" border="0" cellspacing="0" cellpadding="0">
368
<table width="100%" border="0" cellspacing="0" cellpadding="0">
248
	<tr><th><?php echo $l_specific_filtering; ?></th></tr>
369
	<tr><th><?php echo $l_specific_filtering; ?></th></tr>
249
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
370
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
Line 275... Line 396...
275
echo "> $l_safe_searching";
396
echo "> $l_safe_searching";
276
 
397
 
277
echo "<br></br>$l_safe_youtube";
398
echo "<br></br>$l_safe_youtube";
278
echo " $l_youtube_id<tr><td>";
399
echo " $l_youtube_id<tr><td>";
279
 
400
 
280
echo "<input type='submit' value='$l_record'></form></td></tr>";
401
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'></form></td></tr>";
281
?>
402
?>
282
 
403
 
283
</TABLE><br/>
404
</TABLE><br/>
284
</BODY>
405
</BODY>
285
</HTML>
406
</HTML>