Subversion Repositories ALCASAR

Rev

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

Rev 1903 Rev 1954
Line 1... Line 1...
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2
<HTML><!-- written by Rexy -->
2
<HTML><!-- written by Rexy -->
3
<HEAD>
3
<HEAD>
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
4
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
<TITLE>ALCASAR Whitelist filtering</TITLE>
5
<TITLE>ALCASAR DNS WL filtering</TITLE>
6
<link rel="stylesheet" href="/css/style.css" type="text/css">
6
<link rel="stylesheet" href="/css/style.css" type="text/css">
7
</HEAD>
7
</HEAD>
8
<body>
8
<body>
9
<?
9
<?
10
function form_filter ($form_content)
10
function form_filter ($form_content)
11
{
11
{
12
// réencodage iso + format unix + rc fin de ligne (ouf...)
12
// réencodage iso + format unix + rc fin de ligne (ouf...)
13
	$list = str_replace("\r\n", "\n", utf8_decode($form_content));
13
	$list = str_replace("\r\n", "\n", utf8_decode($form_content));
14
	if (strlen($list) != 0){
14
	if (strlen($list) != 0){
15
		if ($list[strlen($list)-1] != "\n") { $list[strlen($list)]="\n";} ;} ;
15
		if ($list[strlen($list)-1] != "\n") { $list[strlen($list)]="\n";} ;} ;
16
	return $list;
16
	return $list;
17
}
17
}
18
function form_filter_ip($form_content, $color)
18
function form_filter_ip($form_content, $color)
19
{
19
{
20
	//# reconstruction des ip
20
	//# reconstruction des ip
21
	$list = explode("\n", form_filter($form_content));
21
	$list = explode("\n", form_filter($form_content));
22
	$new_list = "";
22
	$new_list = "";
23
	foreach($list as &$value)
23
	foreach($list as &$value)
24
	{
24
	{
25
		if(preg_match('/([0-9]{1,3}.){3}[0-9]{1,3}/', $value))
25
		if(preg_match('/([0-9]{1,3}.){3}[0-9]{1,3}/', $value))
26
		{
26
		{
27
			$new_list = $new_list.$value."\n";
27
			$new_list = $new_list.$value."\n";
28
		}
28
		}
29
	}
29
	}
30
	if($color == "white")
30
	if($color == "white")
31
	{
31
	{
32
		return preg_replace("/(.*)\n/", "add wl_ip_allowed $1\n", $new_list);
32
		return preg_replace("/(.*)\n/", "add wl_ip_allowed $1\n", $new_list);
33
	}
33
	}
34
	else
34
	else
35
	{
35
	{
36
		return preg_replace("/(.*)\n/", "add bl_ip_blocked $1\n", $new_list);
36
		return preg_replace("/(.*)\n/", "add bl_ip_blocked $1\n", $new_list);
37
	}
37
	}
38
}
38
}
39
function echo_file ($filename)
39
function echo_file ($filename)
40
	{
40
	{
41
	if (file_exists($filename))
41
	if (file_exists($filename))
42
		{
42
		{
43
		if (filesize($filename) != 0)
43
		if (filesize($filename) != 0)
44
			{
44
			{
45
			$pointeur=fopen($filename,"r");
45
			$pointeur=fopen($filename,"r");
46
			$tampon = fread($pointeur, filesize($filename));
46
			$tampon = fread($pointeur, filesize($filename));
47
			$line = split("\n", $tampon);
47
			fclose($pointeur);
48
			foreach( $line as $x)
48
			echo $tampon;
49
			{
49
			}
50
				if(isset(split('/',$x)[1]))
50
		}
51
				echo split('/',$x)[1]."\n";
51
	else
52
			}
52
		{
53
			fclose($pointeur);
53
		echo "$filename doesn't exist";
54
			}
54
		}
55
		}
55
	}
56
	else
56
function echo_ip_file ($filename)
57
		{
57
{
58
		echo "$filename doesn't exist";
58
	exec("cat $filename | cut -d ' ' -f3", $resultat);
59
		}
59
	for($i=0; $i<exec("wc -l $filename"); $i++)
60
	}
60
	{
61
function echo_ip_file ($filename)
61
		echo $resultat[$i]."\n";
62
{
62
	}
63
	exec("cat $filename | cut -d ' ' -f3", $resultat);
63
}
64
	for($i=0; $i<exec("wc -l $filename"); $i++)
64
 
65
	{
65
#maximum length for top-level DNS
66
		echo $resultat[$i]."\n";
66
function max_tld()
67
	}
67
{
68
}
68
	$url_tld = "http://data.iana.org/TLD/tlds-alpha-by-domain.txt";
69
 
69
	$result_tld = file_get_contents($url_tld,false);
70
#maximum length for top-level DNS
70
	$max_tld = 18; 							#valeur de base si le site ne répond plus
71
function max_tld()
71
	if($result_tld !== FALSE){
72
{
72
		foreach(explode("\n", $result_tld) as $line)
73
	$url_tld = "http://data.iana.org/TLD/tlds-alpha-by-domain.txt";
73
		{
74
	$result_tld = file_get_contents($url_tld,false);
74
			if((strpos($line,'-') === false) and (strpos($line,'#') === false))
75
	$max_tld = 18; 							#valeur de base si le site ne répond plus
75
			{
76
	if($result_tld !== FALSE){
76
				if(strlen($line) > $max_tld)
77
		foreach(explode("\n", $result_tld) as $line)
77
				{
78
		{
78
					$max_tld = strlen($line);
79
			if((strpos($line,'-') === false) and (strpos($line,'#') === false))
79
				}
80
			{
80
			}
81
				if(strlen($line) > $max_tld)
81
		}
82
				{
82
	}
83
					$max_tld = strlen($line);
83
	return $max_tld;
84
				}
84
}
85
			}
85
 
86
		}
86
# Choice of language
87
	}
87
$Language = 'en';
88
	return $max_tld;
88
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
89
}
89
	$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
90
 
90
	$Language = strtolower(substr(chop($Langue[0]),0,2)); 
91
# Choice of language
91
	}
92
$Language = 'en';
92
if($Language == 'fr'){
93
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
93
	$l_wl="Liste blanche générale";
94
	$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
94
	$l_load="Chargement...";
95
	$Language = strtolower(substr(chop($Langue[0]),0,2)); }
95
	$l_list_version="Version de la liste : ";
96
if($Language == 'fr'){
96
	$l_wl_categories="Sélectionnez les catégories à filtrer";
97
	$l_wl="Liste blanche";
97
	$l_specific_filtering="Filtrage special";
98
	$l_load="Chargement...";
98
	$l_add_to_wl="Noms de domaine ou adresses IP à ajouter à la liste noire";
99
	$l_list_version="Version de la liste : ";
99
	$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";
100
	$l_specific_filtering="Filtrage special";
100
	$l_record="Enregistrer les modifications";
101
	$l_wl_categories="Sélectionnez les catégories à autoriser";
101
	$l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
102
	$l_allowed_dns="Noms de domaine autorisés";
102
	$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)";
103
	$l_one_dns="Entrez un nom de domaine par ligne (exemple : .domaine.org)";
103
	$l_safe_searching="Activer le contrôle scolaire/parental des moteurs de recherche google.";
104
	$l_add_to_wl="Noms de domaine ou IP ajoutés à la liste blanche";
104
	$l_safe_youtube="Pour un contrôle parental sur Youtube, suivez les étapes ici : "; 
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)";
105
	$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>)";
106
	$l_allowed_ip="IP autorisées";
106
	$l_error_open_file="Erreur d'ouverture du fichier";
107
	$l_record="Enregistrer les modifications";
107
	$l_additional_file_title="Fichiers de 'listes blanches' additionnels";
108
	$l_wait="Une fois validées, 10 secondes sont nécessaires pour traiter vos modifications";
108
	$l_file_list="Liste des fichiers";
109
	$l_error_open_file="Erreur d'ouverture du fichier";
109
	$l_add_file="Ajouter un fichier";
110
	$l_additional_file_title="Fichiers de 'listes blanche' additionnels";
110
	$l_add_file_explain="Chaque ligne du fichier doit être une adresse IP ou un nom de domaine"; 
111
	$l_file_list="Liste des fichiers";
111
	$l_file_name="Nom du fichier";
112
	$l_add_file="Ajouter un fichier";
112
	$l_file_action="Action";
113
	$l_add_file_explain="Chaque ligne du fichier doit être une adresse IP ou un nom de domaine"; 
113
	$l_error_upload="Erreur d'envoi du fichier";
114
	$l_file_name="Nom du fichier";
114
	$l_remove="Supprimer";
115
	$l_file_remove="Supprimer";
115
	$l_submit="Envoyer";
116
	$l_error_upload="Erreur d'envoi du fichier";
116
	$l_nb_ip="Nombre d'IP";
117
	$l_remove="Supprimer";
117
	$l_nb_domain_names="Nombre de noms de domaine";
118
	$l_submit="Envoyer";
118
	$l_nbDomainNames="Noms de domaine :";
119
	$l_nb_ip="Nombre d'IP";
119
	$l_nbUrl="Url :";
120
	$l_nb_domain_names="Nombre de noms de domaine";
120
	$l_nbIp="Ip :";
121
	$l_nbDomainNames="Noms de domaine :";
121
	$l_disable="Désactiver";
122
	$l_nbUrl="Url :";
122
	$l_enable="Activer";
123
	$l_nbIp="Ip :";
123
	$l_file_state="Etat";
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)";
124
}
125
	$l_safe_searching="Activer le contrôle scolaire/parental des moteurs de recherche : google, yahoo, bing, metacrawler et Youtube.";
125
else {
126
	$l_safe_youtube="Pour Youtube restreint, suivez les étapes ici pour chaque poste : "; 
126
	$l_wl="General WhiteList";
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>)";
127
	$l_load="Loading...";
128
	$l_disable="Désactiver";
128
	$l_list_version="List version : ";
129
	$l_enable="Activer";
129
	$l_wl_categories="Select the categories to filter";
130
	$l_file_state="Etat";
130
	$l_specific_filtering="Specific filtering";
131
}
131
	$l_allowed_dns="Allowed domain names";
132
else {
132
	$l_add_to_wl="Domain names or IP addresses to add to the blacklist";
133
	$l_wl="WhiteList";
133
	$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";
134
	$l_load="Loading...";
134
	$l_record="Save changes";
135
	$l_list_version="List version : ";
135
	$l_wait="Once validated, 10 seconds are necessary to compute your modifications";
136
	$l_wl_categories="Select the categories to allow";
136
	$l_ip_filtering="Filtering URLs that contain an IP address instead of a domain name (ie: http://25.56.58.59/index.htm)";
137
	$l_allowed_dns="Allowed domain names";
137
	$l_safe_searching="Enabling school/parental control for the search engines google"; 
138
	$l_one_dns="Enter one domain name per row (example : .domain.org)";
138
	$l_safe_youtube="For a safe Youtube search, follow these steps : "; 
139
	$l_add_to_wl="Domain names or IP to add to whitelist";
139
	$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>)";
140
	$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)";
140
	$l_error_open_file="Error opening file";
141
	$l_allowed_ip="Allowed IP";
141
	$l_additional_file_title="Additional WhiteList files";
142
	$l_record="Save changes";
142
	$l_file_list="Files list";
143
	$l_wait="Once validated, 10 seconds are necessary to compute your modifications";
143
	$l_add_file="Add a file";
144
	$l_error_open_file="Error opening file";
144
	$l_add_file_explain="Each line of the file must be an IP address or a domain name"; 
145
	$l_additional_file_title="Additional whitelist files";
145
	$l_file_name="Filename";
146
	$l_file_list="Files list";
146
	$l_file_action="Action";
147
	$l_add_file="Add a file";
147
	$l_error_upload="Error during the upload process";
148
	$l_add_file_explain="Each line of the file must be an IP address or a domain name"; 
148
	$l_remove="Delete";
149
	$l_file_name="Filename";
149
	$l_submit="Submit";
150
	$l_file_remove="Remove";
150
	$l_nb_ip="Number of IP";
151
	$l_error_upload="Error during the upload process";
151
	$l_nb_domain_names="Number of domain names";
152
	$l_remove="Delete";
152
	$l_nbDomainNames="Domain names :";
153
	$l_submit="Submit";
153
	$l_nbUrl="Url :";
154
	$l_nb_ip="Number of IP";
154
	$l_nbIp="Ip :";
155
	$l_nb_domain_names="Number of domain names";
155
	$l_disable="Disable";
156
	$l_nbDomainNames="Domain names :";
156
	$l_enable="Enable";
157
	$l_nbUrl="Url :";
157
	$l_file_state="State";
158
	$l_nbIp="Ip :";
158
}
159
	$l_ip_filtering="Filtering URLs that contain an IP address instead of a domain name (ie: http://25.56.58.59/index.htm)";
159
$dir_etc="/usr/local/etc/";
160
	$l_specific_filtering="Specific filtering";
160
$dir_dg="/etc/dansguardian/lists/";
161
	$l_safe_youtube="For safe Youtube, follow steps here for each computer "; 
161
$dir_blacklist=$dir_dg."blacklists/";
162
	$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>)";
162
$dir_wl_ip="/usr/local/share/iptables-wl/";
163
	$l_safe_searching="Enabling school/parental control for the search engines google."; 
163
$dir_wl_ip_enabled= "/usr/local/share/iptables-wl-enabled/";
164
	$l_disable="Disable";
164
$dir_wl_domain_names= "/usr/local/share/dnsmasq-wl/";
165
	$l_enable="Enable";
165
$dir_wl_domain_names_enabled= "/usr/local/share/dnsmasq-wl-enabled/";
166
	$l_file_state="State";
166
$wl_categories=$dir_etc."alcasar-wl-categories";
167
}
167
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
168
$dir_etc="/usr/local/etc/";
168
$conf_file=$dir_etc."alcasar.conf";
169
$dir_dg="/etc/dansguardian/lists/";
169
$urlregex_file=$dir_dg."urlregexplist";
170
$file_wl_domains="/usr/local/share/dnsmasq-wl/ossi.conf";
170
$bannedsite_file=$dir_dg."bannedsitelist";
171
$file_wl_ip="/usr/local/share/iptables-wl-enabled/ossi";
171
$dir_tmp="/tmp/blacklists";
172
$wl_categories=$dir_etc."alcasar-wl-categories";
172
 
173
$wl_categories_enabled=$dir_etc."alcasar-wl-categories-enabled";
173
 
174
$conf_file=$dir_etc."alcasar.conf";
174
# default values
175
$tinyproxy_conf="/etc/tinyproxy/tinyproxy.conf";
175
if (is_file ($conf_file))
176
$dnsmasq_conf="/etc/dnsmasq-whitelist.conf";
176
	{
177
$dir_tmp="/tmp/";
177
	$tab=file($conf_file);
178
$upload_dir_ip = "/usr/local/share/iptables-wl-enabled/";
178
	if ($tab)
179
$upload_dir_domain_names = "/usr/local/share/dnsmasq-wl-enabled/";
179
		{
180
$dir_ip = "/usr/local/share/iptables-wl/";
180
		foreach ($tab as $line)
181
$dir_domain_names = "/usr/local/share/dnsmasq-wl/";
181
			{
182
# default values
182
			$field=explode("=", $line);
183
if (is_file ($conf_file))
183
			if ($field[0] == "PRIVATE_IP")
184
	{
184
				{
185
	$tab=file($conf_file);
185
				$PRIVATE_IP_MASK=trim($field[1]);
186
	if ($tab)
186
				$tmp = explode("/",$PRIVATE_IP_MASK);
187
		{
187
				$PRIVATE_IP=$tmp[0];
188
		foreach ($tab as $line)
188
				}
189
			{
189
			}
190
			$field=explode("=", $line);
190
		}
191
			if ($field[0] == "DNS1")
191
	}	
192
				{
192
else { echo "$l_error_open_file $conf_file";}
193
					$DNS1=trim($field[1]);
193
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
194
				}
194
switch ($choix)
195
			}
195
{
196
		}
196
case 'Download_list' :
197
	}
197
	exec ("sudo /usr/local/bin/alcasar-bl.sh --download");
198
else { echo "$l_error_open_file $conf_file";}
198
	break;
199
 
199
case 'Active_list' :
200
if (isset($_POST['choix'])){ $choix=$_POST['choix']; } else { $choix=""; }
200
	exec ("sudo /usr/local/bin/alcasar-bl.sh --adapt");
201
switch ($choix)
201
	exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
202
{
202
	break;
203
case 'Specific_filtering' :
203
case 'Reject_list' :
204
	$safesearch="-safesearch_off"; ;
204
	unlink ("$dir_tmp/blacklists.tar.gz"); unlink ("$dir_tmp/md5sum");
205
	foreach ($_POST as $key => $value)
205
	break;
206
	{
206
case 'MAJ_cat_wl' :
207
		if (strstr($key,'chk-safesearch')) $safesearch="-safesearch_on";
207
	if (file_exists($wl_categories_enabled))
208
	}
208
	{
209
	exec ("sudo /usr/local/bin/alcasar-url_filter_wl.sh $safesearch");
209
		$pointeur=fopen($wl_categories_enabled, "w+");
210
	break;
210
		foreach ($_POST as $key => $value)
211
case 'MAJ_cat_wl' :
211
		{
212
	if (file_exists($wl_categories_enabled))
212
			if (strstr($key,'chk-'))
213
		{
213
			{	
214
		$pointeur=fopen($wl_categories_enabled, "w+");
214
				$line=str_replace('chk-','',$key)."\n";
215
		foreach ($_POST as $key => $value)
215
				fwrite($pointeur,$line);
216
			{
216
			}
217
			if (strstr($key,'chk-'))
217
		}
218
				{	
218
			
219
				$line=str_replace('chk-','',$key)."\n";
219
		fclose($pointeur);
220
				fwrite($pointeur,$line);
220
	}
221
				}
221
	else {echo "$l_error_open_file $wl_categories_enabled";}
222
			}
222
	$fichier=fopen($dir_blacklist."ossi-wl/domains","w+");
223
		fclose($pointeur);
223
	fputs($fichier, form_filter($_POST['OSSI_wl']));
224
		}
224
	fclose($fichier);
225
	else {echo "$l_error_open_file $wl_categories_enabled";}
225
	unset($_POST['OSSI_wl']);
226
	$fichier=fopen($file_wl_domains,"w+");
226
	exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
227
	fputs($fichier, form_filter($_POST['OSSI_wl_domains']));
227
	break;
228
	fclose($fichier);
228
case 'Specific_filtering' :
229
	unset($_POST['OSSI_wl_domains']);
229
	$pureip="-pureip_off"; $safesearch="-safesearch_off"; ;
230
	$fichier=fopen($file_wl_ip, "w+");
230
	foreach ($_POST as $key => $value)
231
	fputs($fichier, form_filter_ip($_POST['OSSI_wl_ip'], "white"));
231
	{
232
	fclose($fichier);
232
		if (strstr($key,'chk-ip')) $pureip="-pureip_on";
233
	unset($_POST['OSSI_wl_ip']);
233
		if (strstr($key,'chk-safesearch')) $safesearch="-safesearch_on";
234
	exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
234
	}
235
	break;
235
	exec ("sudo /usr/local/bin/alcasar-url_filter_bl.sh $safesearch $pureip");
236
	case 'MAJ_ip_file_delete' :
236
	break;
237
	foreach($_POST as $fichier => $value)
237
case 'MAJ_ossi_file' :
238
	{
238
	foreach($_POST as $fichier => $value)
239
		if($fichier != "choix")
239
	{
240
		{
240
		if($fichier != "choix")
241
			$action=$_POST[$fichier];
241
		{
242
			if($action == $l_remove) //delete
242
			$action=$_POST[$fichier];
243
			{
243
			if($action == $l_remove) //delete
244
				exec("rm -rf $upload_dir_ip$fichier");
244
			{
245
				exec("rm -rf $upload_dir_domain_names$fichier");
245
				exec("/bin/sed -i \"/^$fichier$/d\" $wl_categories_enabled"); 
246
				exec("rm -rf $dir_ip$fichier");
246
				exec("rm -rf $dir_blacklist$fichier");
247
				exec("rm -rf $dir_domain_names$fichier");
247
				exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
248
				exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
248
			}
249
			}
249
			if($action == $l_disable) //disable
250
			if($action == $l_disable) //disable
250
			{
251
			{
251
				exec("/bin/sed -i \"/^$fichier$/d\" $wl_categories_enabled"); 
252
				exec("mv -f $upload_dir_ip$fichier $dir_ip$fichier");
252
				exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
253
				exec("mv -f $upload_dir_domain_names$fichier $dir_domain_names$fichier");
253
			}
254
				exec("sudo /usr/local/bin/alcasar-bl.sh --reload");
254
			if($action == $l_enable) //enable
255
			}
255
			{
256
			if($action == $l_enable) //enable
256
				file_put_contents ($wl_categories_enabled, $fichier."/n", FILE_APPEND);
257
			{
257
				exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
258
				exec("mv -f $dir_ip$fichier $upload_dir_ip$fichier");
258
			}
259
				exec("mv -f $dir_domain_names$fichier $upload_dir_domain_names$fichier");
259
		}
260
				exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
260
	}
261
			}
261
	break;
262
		}
262
case 'MAJ_ossi_file_upload' :
263
	}
263
	$file_name = str_replace (".", "_",basename($_FILES['fichier_ip']['name']));
264
	break;
264
	if(!empty($file_name))
265
case 'MAJ_ip_file_upload' :
265
	{	
266
	$nom = str_replace (".", "_",basename($_FILES['fichier_ip']['name']));
266
		$dest_dir = $dir_blacklist."ossi-wl-".$file_name;
267
	# Si un fichier a été choisi
267
		exec ("mkdir $dest_dir");
268
	if(!empty($nom))
268
		if(move_uploaded_file($_FILES['fichier_ip']['tmp_name'], $dest_dir."/domains"))
269
	{	
269
		{
270
		# On l'upload
270
			file_put_contents ($wl_categories, $dest_dir."\n", FILE_APPEND);
271
		if(move_uploaded_file($_FILES['fichier_ip']['tmp_name'], $upload_dir_ip.$nom))
271
			file_put_contents ($wl_categories_enabled, "ossi-wl-".$file_name."\n", FILE_APPEND); //Enabled by default
272
		{
272
			exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
273
		
273
		}
274
		# On extrait uniquement les ip du fichier
274
		else
275
		exec("grep -Eo '([0-9]{1,3}\.){3}[0-9]{1,3}' $upload_dir_ip$nom > $upload_dir_ip\ossi_ip");
275
		{
276
 
276
			exec("rm -rf $dest_dir");
277
		# Suppression des doublons
277
			echo $l_error_upload;
278
		exec("sort -u $upload_dir_ip\ossi_ip > $upload_dir_ip\ossi-$nom && rm -f $upload_dir_ip\ossi_ip");
278
		}
279
 
279
	}
280
		# On adapte le fichier à la sauvegarde du set
280
	break;
281
		exec("sed -i \"s/^/add wl_ip_allowed /g\" $upload_dir_ip\ossi-$nom"); 
281
}
282
		
282
?>
283
		# On extrait uniquement les noms de domaine
283
<table width="100%" border="0" cellspacing="0" cellpadding="0">
284
		# max_tld() retourne le nombre max de charactere pour un top-level dns
284
	<tr><th><?php echo $l_wl; ?></th></tr>
285
		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");
285
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
286
 
286
</table>
287
		# Suppression des doublons
287
<table width="100%" border=1 cellspacing=0 cellpadding=1>
288
		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");
288
<tr><td valign="middle" align="left" colspan=10>
289
 
289
<FORM action='wl_filter.php' method=POST>
290
		# On adapte le fichier pour Dnsmasq
290
<input type='hidden' name='choix' value='MAJ_cat_wl'>
291
		exec("sed -i \"s/^/server=\//g\" $upload_dir_domain_names\ossi-$nom");
291
<?php
292
		exec("sed -i \"s/$/\/$DNS1/g\" $upload_dir_domain_names\ossi-$nom");
292
echo "<center>";
293
 
293
// total number of IP, DNS & URLs
294
		# Suppression du fichier
294
$nbDomainNames = exec ("wc -l /usr/local/share/dnsmasq-wl/* | tail -n 1 | awk '{print $1}'");
295
		exec("rm -f $upload_dir_ip$nom");
295
$nbUrl = "0";
296
		
296
$nbIp = exec ("wc -l /usr/local/share/iptables-wl/* | tail -n 1 | awk '{print $1}'");
297
		}
297
echo "<b>$l_nbDomainNames</b> $nbDomainNames, <b>$l_nbUrl</b> $nbUrl, <b>$l_nbIp</b> $nbIp<br/>";
298
		else
298
echo "$l_wl_categories</center></td></tr>";	
299
		{
299
//read & display all WL categories (checked or not)
300
			echo $l_error_upload;
300
$cols=1; 
301
		}
301
if (file_exists($wl_categories))
302
		exec ("sudo /usr/local/bin/alcasar-bl.sh --reload");
302
	{
303
	}
303
	$wl_files = file($wl_categories);
304
	break;
304
	$wl_files = preg_grep("/ossi-/", $wl_files, 1); // don't display ossi custom categories
305
}
305
	foreach($wl_files as $fichier => $value)
306
?>
306
		{
307
<table width="100%" border="0" cellspacing="0" cellpadding="0">
307
		if ($cols == 1) { echo "<tr>";}
308
	<tr><th><?php echo $l_wl; ?></th></tr>
308
		$categorie=trim(basename($value));
309
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
309
		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>";
310
</table>
310
		echo "<input type='checkbox' name='chk-$categorie'";
311
 
311
		// if the line is commented, the category is disable
312
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
312
		if (preg_match('/^#/',$value, $r)) { echo ">";}
313
<tr><td valign="middle" align="left" colspan=10>
313
		else { echo "checked>"; }
314
<FORM action='wl_filter.php' method=POST>
314
		echo "</td>";
315
<input type='hidden' name='choix' value='MAJ_cat_wl'>
315
		$cols++;
316
<?php
316
		if ($cols > 10) {
317
echo "<center>";
317
			echo "</tr>";
318
$nbDomainNames = exec ("wc -l /usr/local/share/dnsmasq-wl/* | tail -n 1 | awk '{print $1}'");
318
			$cols=1; }
319
$nbUrl = 0;
319
		}
320
$nbIp = 0;
320
	}
321
echo "<b>$l_nbDomainNames</b> $nbDomainNames, <b>$l_nbUrl</b> $nbUrl, <b>$l_nbIp</b> $nbIp<br/>";
321
else	{
322
echo "$l_wl_categories</center></td></tr>";
322
	echo "$l_error_open_file $wl_categories";
323
//on lit et on interprete le fichier de catégories
323
}
324
$cols=1; 
324
echo "<tr><td valign='middle' align='left' colspan=10>";
325
if (file_exists($wl_categories))
325
echo "<center><b>$l_add_to_wl</b></center></td></tr>";
326
	{
326
echo "<tr><td width=100% colspan=10 align=center>";
327
	$pointeur=fopen($wl_categories,"r");
327
echo "$l_one_dns_ip<BR>";
328
	while (!feof ($pointeur))
328
echo "<textarea name='OSSI_wl' rows=3 cols=40>";
329
		{
329
echo_file ($dir_blacklist."ossi-wl/domains");
330
		$ligne=fgets($pointeur, 4096);
330
echo "</textarea></td>";
331
		if ($ligne)
331
echo "</tr><tr><td colspan=10>";
332
			{
332
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'>";
333
			if ($cols == 1) { echo "<tr>";}
333
echo "</form> ($l_wait)";
334
			$categorie=trim(basename($ligne));
334
echo "</td></tr></table><br/>";
335
			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>";
335
?>
336
			echo "<input type='checkbox' name='chk-$categorie'";
336
<table width="100%" border="0" cellspacing="0" cellpadding="0">
337
			// si la ligne est commentée -> categorie non selectionnée
337
	<tr><th><?php echo $l_additional_file_title; ?></th></tr>
338
			if (preg_match('/^#/',$ligne, $r)) { echo ">";}
338
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
339
			else { echo "checked>"; }
339
</table>
340
			echo "</td>";
340
<table width="100%" border=1 cellspacing=0 cellpadding=1>
341
			$cols++;
341
<form action='wl_filter.php' method='POST'>
342
			if ($cols > 10) {
342
<input type='hidden' name='choix' value='MAJ_ossi_file'>
343
				echo "</tr>";
343
<?php
344
				$cols=1; }
344
echo "<tr><td width=50% colspan=5 align=center>";
345
			}
345
echo "<H3>$l_file_list</H3>";
346
		}
346
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>";
347
	fclose($pointeur);
347
 
348
	}
348
//list OSSI custom categories
349
else	{
349
$fichierswl = array_diff(scandir($dir_blacklist), array('..','.','ossi-bl','ossi-wl'));
350
	echo "$l_error_open_file $wl_categories";
350
$fichierswl = preg_grep("/^ossi-wl-/",$fichierswl);
351
	}
351
foreach($fichierswl as $fichier => $value)
352
echo "<tr><td valign='middle' align='left' colspan=10>";
352
{
353
echo "<center><b>$l_add_to_wl</b></center></td></tr>";
353
	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'";
354
echo "<tr><td width=50% colspan=5 align=center>";
354
	if (file_exists ($dir_wl_domain_names_enabled.$value)) echo " value='$l_disable'>"; else echo " value='$l_enable'>";
355
echo "<H3>$l_allowed_dns</H3>$l_one_dns<BR>";
355
	echo "</center></td><td><center><input type='submit' name='$value' value='$l_remove'></center></td></tr>";
356
echo "<textarea name='OSSI_wl_domains' rows=3 cols=40>";
356
}
357
echo_file ($file_wl_domains);
357
echo "</table><br/></td></form><form action='wl_filter.php' method='POST' enctype='multipart/form-data'>";
358
echo "</textarea></td>";
358
echo "<input type='hidden' name='choix' value='MAJ_ossi_file_upload'><td width=50% colspan=5 align=center>";
359
echo "<td width=50% colspan=5 align=center>";
359
echo "<H3>$l_add_file</H3>";
360
echo "<H3>$l_allowed_ip</H3>$l_forbidden_ip_explain<BR>";
360
echo "$l_add_file_explain";
361
echo "<textarea name='OSSI_wl_ip' rows=3 cols=40>";
361
echo "<input type='file' name='fichier_ip'>";
362
echo_ip_file ($file_wl_ip);
362
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_submit'>";
363
echo "</textarea></td></tr>";
363
echo "</td></tr>";
364
echo "<tr><td colspan=10>";
364
echo "</form>";
365
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'></form></td></tr>";
365
echo "</table><br/>";
366
echo "</td></tr></table><br/>";
366
?>
367
?>
367
<table width="100%" border="0" cellspacing="0" cellpadding="0">
368
 
368
	<tr><th><?php echo $l_specific_filtering; ?></th></tr>
369
<table width="100%" border="0" cellspacing="0" cellpadding="0">
369
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
370
	<tr><th><?php echo $l_additional_file_title; ?></th></tr>
370
</table>
371
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
371
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
372
</table>
372
<FORM action='wl_filter.php' method='POST'>
373
 
373
<input type='hidden' name='choix' value='Specific_filtering'>
374
<table width="100%" border=1 cellspacing=0 cellpadding=1>
374
<tr><td>
375
<form action='wl_filter.php' method='POST'>
375
<input type='checkbox' name='chk-ip'
376
<input type='hidden' name='choix' value='MAJ_ip_file_delete'>
376
<?php
377
<?php
377
// verify "pureip" filtering state
378
echo "<tr><td width=50% colspan=5 align=center>";
378
if (file_exists($bannedsite_file))
379
echo "<H3>$l_file_list</H3>";
379
	{
380
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_state<th>$l_file_remove</tr>";
380
	$pointeur=fopen($bannedsite_file,"r");
381
 
381
	while (!feof ($pointeur))
382
//liste des fichiers activés
382
		{
383
$fichiersIp = array_diff(scandir($upload_dir_ip), array('ossi','ossi-ip-safesearch','..','.'));
383
		$ligne=fgets($pointeur, 4096);
384
$fichiersIp = preg_grep("/^ossi-/",$fichiersIp);
384
		if ($ligne)
385
foreach($fichiersIp as $fichier => $value)
385
			{
386
{
386
			if (preg_match('/^\*ip$/',$ligne, $r)) 
387
	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_disable'></center></td><td><center><input type='submit' name='$value' value='$l_remove'></center></td></tr>";
387
				{
388
}
388
				echo " checked";
389
//liste des fichiers desactivés
389
				break;
390
$fichiersIp = array_diff(scandir($dir_ip), array('ossi','ossi-ip-safesearch','..','.'));
390
				}
391
$fichiersIp = preg_grep("/^ossi-/",$fichiersIp);
391
			}
392
foreach($fichiersIp as $fichier => $value)
392
		}
393
{
393
	fclose($pointeur);
394
	echo "<tr><td bgcolor='BEBEBE'><center><a href='bl_categories_help.php?liste=wl&cat=$value&ossi=yes&filtre=domain&state=disable' 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 bgcolor='BEBEBE'><center>".exec("wc -l $dir_ip$value | awk '{print $1}'")."</center></td><td bgcolor='BEBEBE'><center>".exec("wc -l $dir_domain_names$value | awk '{print $1}'")."</center></td><td bgcolor='BEBEBE'><center><input type='submit' name='$value' value='$l_enable'></center></td><td bgcolor='BEBEBE'><center><input type='submit' name='$value' value='$l_remove'></center></td></tr>";
394
	}
395
}
395
else	{
396
 
396
	echo "$l_error_open_file $bannedsite_file";
397
 
397
	}
398
echo "</table><br/></td></form><form action='wl_filter.php' method='POST' enctype='multipart/form-data'>";
398
echo "> $l_ip_filtering";
399
echo "<input type='hidden' name='choix' value='MAJ_ip_file_upload'><td width=50% colspan=5 align=center>";
399
?>
400
echo "<H3>$l_add_file</H3>";
400
</td></tr>
401
echo "$l_add_file_explain";
401
<tr><td>
402
echo "<input type='file' name='fichier_ip'>";
402
<input type='checkbox' name='chk-safesearch'
403
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_submit'>";
403
<?php
404
echo "</td></tr>";
404
// verify "safesearch" filtering state
405
echo "</form>";
405
if (file_exists($urlregex_file))
406
echo "</table><br/>";
406
	{
407
?>
407
	$pointeur=fopen($urlregex_file,"r");
408
 
408
	while (!feof ($pointeur))
409
<table width="100%" border="0" cellspacing="0" cellpadding="0">
409
		{
410
	<tr><th><?php echo $l_specific_filtering; ?></th></tr>
410
		$ligne=fgets($pointeur, 4096);
411
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
411
		if ($ligne)
412
</table>
412
			{
413
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
413
			if (preg_match('/^\"\(\^http\:\/\/\[0\-9a\-z\]\+\\\.google/',$ligne, $r))
414
<FORM action='wl_filter.php' method='POST'>
414
				{
415
<input type='hidden' name='choix' value='Specific_filtering'>
415
				echo " checked";
416
<tr><td>
416
				break;
417
 
417
				}
418
<input type='checkbox' name='chk-safesearch'
418
			}
419
<?php
419
		}
420
//verification du safesearch
420
	fclose($pointeur);
421
if(file_exists($dnsmasq_conf))
421
	}
422
{
422
else	{
423
	$f=fopen($dnsmasq_conf, 'r');
423
	echo "$l_error_open_file $urlregex_file";
424
	while(!feof($f))
424
	}
425
	{
425
echo "> $l_safe_searching";
426
		$line=fgets($f,4096);
426
echo "<br>$l_safe_youtube";
427
		if($line && preg_match('/^address=\/\.google/',$line,$r))
427
echo " $l_youtube_id<tr><td>";
428
		{
428
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'></td></tr>";
429
			echo "checked";
429
?>
430
			break;
430
</FORM> 
431
		}
431
</TABLE>
432
	}
432
</BODY>
433
	fclose($f);
433
</HTML>
434
}
434
 
435
else
435
 
436
	echo "$l_error_open_file $dnsmasq_conf";
-
 
437
echo "> $l_safe_searching";
-
 
438
 
-
 
439
echo "<br></br>$l_safe_youtube";
-
 
440
echo " $l_youtube_id<tr><td>";
-
 
441
 
-
 
442
echo "<input type='submit' onClick=\"this.disabled=true; this.value='$l_load';\" value='$l_record'></form></td></tr>";
-
 
443
?>
-
 
444
 
-
 
445
</TABLE><br/>
-
 
446
</BODY>
-
 
447
</HTML>
-