Subversion Repositories ALCASAR

Rev

Rev 1848 | Rev 1960 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 1848 Rev 1959
1
<?php
1
<?php
2
/* written by steweb57 & Rexy */
2
/* written by steweb57 & Rexy */
3
 
3
 
4
/********************
4
/********************
5
* READ CONF FILES   *
5
* READ CONF FILES   *
6
*********************/
6
*********************/
7
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
7
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
8
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers");
8
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers");
-
 
9
define ("DNS_LOCAL_FILE", "/usr/local/etc/alcasar-dns-name");
9
$conf_files=array(CONF_FILE,ETHERS_FILE);
10
$conf_files=array(CONF_FILE,ETHERS_FILE);
10
$reg_ip = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/';
11
$reg_ip = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/';
11
$reg_ip_cidr = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/';
12
$reg_ip_cidr = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/';
12
$network_modification=0;
13
$network_modification=0;
13
foreach ($conf_files as $file){
14
foreach ($conf_files as $file){
14
if (!file_exists($file)){
15
if (!file_exists($file)){
15
	exit("Requested file ".$file." isn't present");}
16
	exit("Requested file ".$file." isn't present");}
16
if (!is_readable($file)){
17
if (!is_readable($file)){
17
	exit("Can't read the file ".$file);}
18
	exit("Can't read the file ".$file);}
18
}
19
}
19
# Choice of language
20
# Choice of language
20
$Language = 'en';
21
$Language = 'en';
21
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
22
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
22
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
23
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
23
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
24
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
24
if($Language == 'fr'){
25
if($Language == 'fr'){
25
	$l_network_title	= "Configuration réseau";
26
	$l_network_title	= "Configuration réseau";
26
	$l_extif_legend		= " (Interface connectée à Internet)";
27
	$l_extif_legend		= " (Interface connectée à Internet)";
27
	$l_intif_legend		= " (Réseau de consultation)";
28
	$l_intif_legend		= " (Réseau de consultation)";
28
	$l_internet_legend	= "INTERNET";
29
	$l_internet_legend	= "INTERNET";
29
	$l_ip_adr		= "Adresse IP";
-
 
30
	$l_ip_mask		= "Masque";
30
	$l_ip_mask		= "Masque";
31
	$l_ip_router		= "Passerelle";
31
	$l_ip_router		= "Passerelle";
32
	$l_ip_public		= "Adresse IP publique";
32
	$l_ip_public		= "Adresse IP publique";
33
	$l_ip_dns1		= "DNS1";
33
	$l_ip_dns1		= "DNS1";
34
	$l_ip_dns2		= "DNS2";
34
	$l_ip_dns2		= "DNS2";
35
	$l_dhcp_title		= "Service DHCP";
35
	$l_dhcp_title		= "Service DHCP";
36
	$l_dhcp_state		= "Mode actuel";
36
	$l_dhcp_state		= "Mode actuel";
37
	$l_DHCP_on		= "actif";
37
	$l_DHCP_on		= "actif";
38
	$l_DHCP_off		= "inactif";
38
	$l_DHCP_off		= "inactif";
39
	$l_DHCP_off_explain	= "! Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
39
	$l_DHCP_off_explain	= "! Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
40
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
40
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
41
	$l_mac_address		= "Adresse MAC";
41
	$l_mac_address		= "Adresse MAC";
42
	$l_ip_address		= "Adresse IP";
42
	$l_ip_address		= "Adresse IP";
-
 
43
	$l_host_name		= "Nom d'hôte";
43
	$l_mac_del		= "Supprimer de la liste";
44
	$l_del			= "Supprimer de la liste";
44
	$l_add_to_list		= "Ajouter";
45
	$l_add_to_list		= "Ajouter";
45
	$l_apply		= "Appliquer les changements";
46
	$l_apply		= "Appliquer les changements";
-
 
47
	$l_local_dns		= "Résolution local de nom";
46
	$l_import_cert		= "Import de certificat";
48
	$l_import_cert		= "Import de certificat";
47
	$l_private_key		= "Clé privée (.key) :";
49
	$l_private_key		= "Clé privée (.key) :";
48
	$l_certificate		= "Certificat (.crt) :";
50
	$l_certificate		= "Certificat (.crt) :";
49
	$l_server_chain		= "Chaîne de certification (si nécéssaire : .crt) :";
51
	$l_server_chain		= "Chaîne de certification (si nécéssaire : .crt) :";
50
	$l_default_cert		= "Revenir au certificat d'origine";
52
	$l_default_cert		= "Revenir au certificat d'origine";
51
	$l_import		= "Importer";
53
	$l_import		= "Importer";
52
	$l_current_certificate  = "Certificat actuel";
54
	$l_current_certificate  = "Certificat actuel";
53
	$l_validated		= "Validé par :";
55
	$l_validated		= "Validé par :";
54
 
56
 
55
} else {
57
} else {
56
	$l_network_title	= "Network configuration";
58
	$l_network_title	= "Network configuration";
57
	$l_extif_legend		= " (Internet connected interface)";
59
	$l_extif_legend		= " (Internet connected interface)";
58
	$l_intif_legend		= " (Private network)";
60
	$l_intif_legend		= " (Private network)";
59
	$l_internet_legend	= "INTERNET";
61
	$l_internet_legend	= "INTERNET";
60
	$l_ip_adr		= "IP Address";
-
 
61
	$l_ip_mask		= "Mask";
62
	$l_ip_mask		= "Mask";
62
	$l_ip_router		= "Gateway";
63
	$l_ip_router		= "Gateway";
63
	$l_ip_public		= "Public IP address";
64
	$l_ip_public		= "Public IP address";
64
	$l_ip_dns1		= "DNS1";
65
	$l_ip_dns1		= "DNS1";
65
	$l_ip_dns2		= "DNS2";
66
	$l_ip_dns2		= "DNS2";
66
	$l_dhcp_title		= "DHCP service";
67
	$l_dhcp_title		= "DHCP service";
67
	$l_dhcp_state		= "Current mode";
68
	$l_dhcp_state		= "Current mode";
68
	$l_DHCP_on		= "enabled";
69
	$l_DHCP_on		= "enabled";
69
	$l_DHCP_off		= "disabled";
70
	$l_DHCP_off		= "disabled";
70
	$l_DHCP_off_explain	= "! Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
71
	$l_DHCP_off_explain	= "! Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
71
	$l_static_dhcp_title	= "Static IP addresses reservation";
72
	$l_static_dhcp_title	= "Static IP addresses reservation";
72
	$l_mac_address		= "MAC Address";
73
	$l_mac_address		= "MAC Address";
73
	$l_ip_address		= "IP Address";
74
	$l_ip_address		= "IP Address";
-
 
75
	$l_host_name		= "Host name";
74
	$l_mac_del		= "Delete from list";
76
	$l_del			= "Delete from list";
75
	$l_add_to_list		= "Add";
77
	$l_add_to_list		= "Add";
76
	$l_apply		= "Apply changes";
78
	$l_apply		= "Apply changes";
-
 
79
	$l_local_dns		= "Local name resolution";
77
	$l_import_cert		= "Certificate import";
80
	$l_import_cert		= "Certificate import";
78
	$l_private_key		= "Private key (.key) :";
81
	$l_private_key		= "Private key (.key) :";
79
	$l_certificate		= "Certificate (.crt) :";
82
	$l_certificate		= "Certificate (.crt) :";
80
	$l_server_chain		= "Server-chain (if necessary : .crt) :";
83
	$l_server_chain		= "Server-chain (if necessary : .crt) :";
81
	$l_default_cert		= "Back to default certificate";
84
	$l_default_cert		= "Back to default certificate";
82
	$l_import		= "Import";
85
	$l_import		= "Import";
83
	$l_current_certificate  = "Current certificate";
86
	$l_current_certificate  = "Current certificate";
84
	$l_validated		= "Validated by :";
87
	$l_validated		= "Validated by :";
85
 
88
 
86
}
89
}
87
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
90
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
88
switch ($choix)
91
switch ($choix)
89
{
92
{
90
case 'DHCP_On' :
93
case 'DHCP_On' :
91
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -on");
94
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -on");
92
	break;
95
	break;
93
case 'DHCP_Off' :
96
case 'DHCP_Off' :
94
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -off");
97
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -off");
95
	break;
98
	break;
96
case 'new_mac' :
99
case 'new_mac' :
97
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
100
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
98
		{
101
		{
99
		$tab=file(ETHERS_FILE);
102
		$tab=file(ETHERS_FILE);
100
		$insert="True";
-
 
101
		if ($tab)  # the file isn't empty
103
		if ($tab)  # the file isn't empty
102
			{
104
			{
-
 
105
			$insert="True";
103
			foreach ($tab as $line)  # verify that MAC or IP addresses doesn't exist
106
			foreach ($tab as $line)  # verify that MAC or IP address doesn't exist
104
				{
107
				{
105
				$field=explode(" ", $line);
108
				$field=explode(" ", $line);
106
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
109
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
107
				if (strcasecmp(trim($_POST['add_mac']),trim($mac_addr)) == 0)
110
				if (strcasecmp(trim($_POST['add_mac']),trim($mac_addr)) == 0)
108
					{
111
					{
109
					$insert="False";
112
					$insert="False";
110
					break;
113
					break;
111
					}
114
					}
112
				if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
115
				if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
113
					{
116
					{
114
					$insert="False";
117
					$insert="False";
115
					break;
118
					break;
116
					}
119
					}
117
				}
120
				}
-
 
121
			if ($insert == "True")
-
 
122
				{
-
 
123
				$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
-
 
124
				$pointeur=fopen(ETHERS_FILE,"a");
-
 
125
				fwrite ($pointeur, $line);
-
 
126
				fclose ($pointeur);
-
 
127
				exec ("sudo /usr/bin/systemctl reload chilli");
-
 
128
				}
118
			}
129
			}
-
 
130
		}
-
 
131
	break;
-
 
132
case 'del_mac' :
-
 
133
	foreach ($_POST as $key => $value)
-
 
134
		{
119
		if ($insert == "True")
135
		if ($value == 'on')
120
			{
136
			{
121
			$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
-
 
122
			$pointeur=fopen(ETHERS_FILE,"a");
137
			$ether_file=ETHERS_FILE;
123
			fwrite ($pointeur, $line);
138
			exec("/bin/sed -i \"/^$key/d\" $ether_file"); 
124
			fclose ($pointeur);
-
 
125
			exec ("sudo /usr/bin/systemctl reload chilli");
139
			exec ("sudo /usr/bin/systemctl reload chilli");
126
			}
140
			}
127
		}
141
		}
128
	break;
142
	break;
129
case 'del_mac' :
143
case 'new_host' :
130
	$tab=file(ETHERS_FILE);
144
	if ((trim($_POST['add_host']) != "") and (trim($_POST['add_ip']) != ""))
131
	if ($tab)
-
 
132
		{
145
		{
133
		$pointeur=fopen(ETHERS_FILE,"w+");
146
		$tab=file(DNS_LOCAL_FILE);
-
 
147
		$insert="True";
134
		foreach ($tab as $line)
148
		if ($tab)  # the file isn't empty
135
			{
149
			{
136
			$field=explode(" ", $line);
-
 
137
			$mac_addr=trim($field[0]);
-
 
138
			$remove_line = False;
-
 
139
			foreach ($_POST as $key => $value)
150
			foreach ($tab as $line)  # verify that host or IP address doesn't exist
140
				{
151
				{
141
				if ($mac_addr == $key)
152
				if (preg_match ('/^address/', $line))
142
			       		{
153
					{
143
					$remove_line = True;
154
					$field=explode("/", $line);
-
 
155
					$host_name=trim($field[1]);$ip_addr=trim($field[2]);
-
 
156
					if (strcasecmp(trim($_POST['add_host']),trim($host_name)) == 0)
-
 
157
						{
-
 
158
						$insert="False";
144
					break;
159
						break;
-
 
160
						}
-
 
161
					if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
-
 
162
						{
-
 
163
						$insert="False";
-
 
164
						break;
-
 
165
						}
145
					}
166
					}
146
				}
167
				}
-
 
168
			if ($insert == "True")
-
 
169
				{
-
 
170
				$line1 = "address=/".trim($_POST['add_host'])."/".trim($_POST['add_ip'])."\n";
-
 
171
				$explode_ip=explode('.',trim($_POST['add_ip']));
-
 
172
				$reverse_ip=implode('.',array_reverse($explode_ip));
-
 
173
				$line2 = "ptr-record=".$reverse_ip.".in-addr.arpa,".trim($_POST['add_host'])."\n";
-
 
174
				$pointeur=fopen(DNS_LOCAL_FILE,"a");
-
 
175
				fwrite ($pointeur, $line1);
147
			if (! $remove_line) {fwrite($pointeur,$line);}
176
				fwrite ($pointeur, $line2);
-
 
177
				fclose ($pointeur);
-
 
178
				exec ("sudo /usr/bin/systemctl restart dnsmasq");
-
 
179
				exec ("sudo /usr/bin/systemctl restart dnsmasq-blacklist");
-
 
180
				exec ("sudo /usr/bin/systemctl restart dnsmasq-whitelist");
-
 
181
				}
-
 
182
			}
-
 
183
		}
-
 
184
	break;
-
 
185
case 'del_mac' :
-
 
186
	foreach ($_POST as $key => $value)
-
 
187
		{
-
 
188
		if ($value == 'on')
-
 
189
			{
-
 
190
			$ether_file=ETHERS_FILE;
-
 
191
			exec("/bin/sed -i \"/^$key/d\" $ether_file"); 
-
 
192
			exec ("sudo /usr/bin/systemctl reload chilli");
148
			}
193
			}
149
		fclose($pointeur);
-
 
150
		exec ("sudo /usr/bin/systemctl reload chilli");
-
 
151
		}
194
		}
152
	break;
195
	break;
153
}
196
}
154
 
197
 
155
// Fonction de test de connectivité internet
198
// Fonction de test de connectivité internet
156
function internetTest(){
199
function internetTest(){
157
	$host = "www.google.fr"; # Google Test
200
	$host = "www.google.fr"; # Google Test
158
	$port = "80";
201
	$port = "80";
159
	//var $num;	//not used
202
	//var $num;	//not used
160
	//var $error;	//not used
203
	//var $error;	//not used
161
 
204
 
162
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
205
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
163
		return false;
206
		return false;
164
	} else {
207
	} else {
165
		fclose($sock);
208
		fclose($sock);
166
		return true;
209
		return true;
167
	}
210
	}
168
}
211
}
169
/***********************************
212
/***********************************
170
* 	Update ALCASAR_CONF_FILE   *
213
* 	Update ALCASAR_CONF_FILE   *
171
***********************************/
214
***********************************/
172
/*******************************************
215
/*******************************************
173
*	Read ALCASAR_CONF_FILE Before     *
216
*	Read ALCASAR_CONF_FILE Before     *
174
********************************************/
217
********************************************/
175
$ouvre=fopen(CONF_FILE,"r");
218
$ouvre=fopen(CONF_FILE,"r");
176
if ($ouvre){
219
if ($ouvre){
177
	while (!feof ($ouvre))
220
	while (!feof ($ouvre))
178
	{
221
	{
179
		$tampon = fgets($ouvre, 4096);
222
		$tampon = fgets($ouvre, 4096);
180
		if (strpos($tampon,"=")!==false){
223
		if (strpos($tampon,"=")!==false){
181
			$tmp = explode("=",$tampon);
224
			$tmp = explode("=",$tampon);
182
			$conf[$tmp[0]] = $tmp[1];
225
			$conf[$tmp[0]] = $tmp[1];
183
		}
226
		}
184
	}
227
	}
185
	fclose($ouvre);
228
	fclose($ouvre);
186
}
229
}
187
	
230
	
188
if(isset($_POST['dns1']) && preg_match($reg_ip,$_POST['dns1']))
231
if(isset($_POST['dns1']) && preg_match($reg_ip,$_POST['dns1']))
189
{
232
{
190
	file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'],'DNS1='.$_POST['dns1']."\n",file_get_contents(CONF_FILE)));
233
	file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'],'DNS1='.$_POST['dns1']."\n",file_get_contents(CONF_FILE)));
191
	$network_modification=1;
234
	$network_modification=1;
192
}
235
}
193
if(isset($_POST['dns2']) && preg_match($reg_ip,$_POST['dns2']))
236
if(isset($_POST['dns2']) && preg_match($reg_ip,$_POST['dns2']))
194
{
237
{
195
	file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'],'DNS2='.$_POST['dns2']."\n",file_get_contents(CONF_FILE)));
238
	file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'],'DNS2='.$_POST['dns2']."\n",file_get_contents(CONF_FILE)));
196
	$network_modification=1;
239
	$network_modification=1;
197
}
240
}
198
 
241
 
199
if(isset($_POST['ip_public']) && preg_match($reg_ip_cidr,$_POST['ip_public']))
242
if(isset($_POST['ip_public']) && preg_match($reg_ip_cidr,$_POST['ip_public']))
200
{
243
{
201
	file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'],'PUBLIC_IP='.$_POST['ip_public']."\n",file_get_contents(CONF_FILE)));
244
	file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'],'PUBLIC_IP='.$_POST['ip_public']."\n",file_get_contents(CONF_FILE)));
202
	$network_modification=1;
245
	$network_modification=1;
203
}
246
}
204
 
247
 
205
if(isset($_POST['ip_gw']) && preg_match($reg_ip,$_POST['ip_gw']))
248
if(isset($_POST['ip_gw']) && preg_match($reg_ip,$_POST['ip_gw']))
206
{
249
{
207
	file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'],'GW='.$_POST['ip_gw']."\n",file_get_contents(CONF_FILE)));
250
	file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'],'GW='.$_POST['ip_gw']."\n",file_get_contents(CONF_FILE)));
208
	$network_modification=1;
251
	$network_modification=1;
209
}
252
}
210
 
253
 
211
if(isset($_POST['ip_private']) && preg_match($reg_ip_cidr,$_POST['ip_private']))
254
if(isset($_POST['ip_private']) && preg_match($reg_ip_cidr,$_POST['ip_private']))
212
{
255
{
213
	file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'],'PRIVATE_IP='.$_POST['ip_private']."\n",file_get_contents(CONF_FILE)));
256
	file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'],'PRIVATE_IP='.$_POST['ip_private']."\n",file_get_contents(CONF_FILE)));
214
	$network_modification=1;
257
	$network_modification=1;
215
}
258
}
216
if($network_modification)
259
if($network_modification)
217
{
260
{
218
	exec("sudo /usr/local/bin/alcasar-conf.sh -apply");
261
	exec("sudo /usr/local/bin/alcasar-conf.sh -apply");
219
}
262
}
220
 
263
 
221
/*******************************************
264
/*******************************************
222
*	Read ALCASAR_CONF_FILE Updated     *
265
*	Read ALCASAR_CONF_FILE Updated     *
223
********************************************/
266
********************************************/
224
$ouvre=fopen(CONF_FILE,"r");
267
$ouvre=fopen(CONF_FILE,"r");
225
if ($ouvre){
268
if ($ouvre){
226
	while (!feof ($ouvre))
269
	while (!feof ($ouvre))
227
	{
270
	{
228
		$tampon = fgets($ouvre, 4096);
271
		$tampon = fgets($ouvre, 4096);
229
		if (strpos($tampon,"=")!==false){
272
		if (strpos($tampon,"=")!==false){
230
			$tmp = explode("=",$tampon);
273
			$tmp = explode("=",$tampon);
231
			$conf[$tmp[0]] = $tmp[1];
274
			$conf[$tmp[0]] = $tmp[1];
232
		}
275
		}
233
	}
276
	}
234
	fclose($ouvre);
277
	fclose($ouvre);
235
}
278
}
236
?>
279
?>
237
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
280
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
238
<html><!-- written by steweb57 & rexy -->
281
<html><!-- written by steweb57 & rexy -->
239
<head>
282
<head>
240
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
283
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
241
<title><?php echo $l_network_title; ?></title>
284
<title><?php echo $l_network_title; ?></title>
242
<link rel="stylesheet" href="/css/style.css" type="text/css">
285
<link rel="stylesheet" href="/css/style.css" type="text/css">
243
<script type="text/javascript">
286
<script type="text/javascript">
244
function MAC_Control(formulaire){
287
function MAC_Control(formulaire){
245
/*MAC control (upper case and '-' separator*/
288
/*MAC control (upper case and '-' separator*/
246
	var regex1 = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/; //vérification adresse mac
289
	var regex1 = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/; //vérification adresse mac
247
	if (regex1.test(document.forms[formulaire].add_mac.value)){
290
	if (regex1.test(document.forms[formulaire].add_mac.value)){
248
		document.forms[formulaire].add_mac.value=document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
291
		document.forms[formulaire].add_mac.value=document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
249
		return true;
292
		return true;
250
	} else {
293
	} else {
251
		alert("Invalid MAC address");//non internationnalisé
294
		alert("Invalid MAC address");//non internationnalisé
252
		return false;
295
		return false;
253
	}
296
	}
254
}
297
}
255
</script>
298
</script>
256
</head>
299
</head>
257
<body>
300
<body>
258
<table width="100%" border="0" cellspacing="0" cellpadding="0">
301
<table width="100%" border="0" cellspacing="0" cellpadding="0">
259
	<tr><th><?php echo $l_network_title; ?></th></tr>
302
	<tr><th><?php echo $l_network_title; ?></th></tr>
260
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
303
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
261
</table>
304
</table>
262
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
305
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
263
	<tr><td valign="middle" align="left">
306
	<tr><td valign="middle" align="left">
264
	<fieldset>
307
	<fieldset>
265
	<legend><?php echo $l_internet_legend;
308
	<legend><?php echo $l_internet_legend;
266
 	if (InternetTest()){
309
 	if (InternetTest()){
267
		echo " <img src='/images/state_ok.gif'>";
310
		echo " <img src='/images/state_ok.gif'>";
268
		$IP_PUB = exec ("wget http://ipecho.net/plain -O - -o /dev/null");}
311
		$IP_PUB = exec ("wget http://ipecho.net/plain -O - -o /dev/null");}
269
	else 	{
312
	else 	{
270
		echo " <img src='/images/state_error.gif'>";
313
		echo " <img src='/images/state_error.gif'>";
271
		$IP_PUB = "-.-.-.-";}
314
		$IP_PUB = "-.-.-.-";}
272
	?></legend>
315
	?></legend>
273
	<table>
316
	<table>
274
		<tr><td><?php echo $l_ip_public." : ".$IP_PUB;?></td></tr>
317
		<tr><td><?php echo $l_ip_public." : ".$IP_PUB;?></td></tr>
275
		<?php
318
		<?php
276
		echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
319
		echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
277
		echo "<tr><td>".$l_ip_dns1." <input style='width:120px' type='text' name='dns1' value=".$conf["DNS1"]."/></td></tr>";
320
		echo "<tr><td>".$l_ip_dns1." <input style='width:120px' type='text' name='dns1' value=".$conf["DNS1"]."/></td></tr>";
278
		echo "<tr><td>".$l_ip_dns2." <input style='width:120px' type='text' name='dns2' value=".$conf["DNS2"]."/></td></tr>";
321
		echo "<tr><td>".$l_ip_dns2." <input style='width:120px' type='text' name='dns2' value=".$conf["DNS2"]."/></td></tr>";
279
		?>
322
		?>
280
	</table>
323
	</table>
281
	</fieldset>
324
	</fieldset>
282
	</td><td>
325
	</td><td>
283
	<fieldset>
326
	<fieldset>
284
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
327
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
285
	<table>
328
	<table>
286
		<?php
329
		<?php
287
		echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
330
		echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
288
		echo "<tr><td>".$l_ip_adr." <input style='width:150px' type='text' name='ip_public' value=".$conf['PUBLIC_IP']."/></td></tr>";
331
		echo "<tr><td>".$l_ip_address." <input style='width:150px' type='text' name='ip_public' value=".$conf['PUBLIC_IP']."/></td></tr>";
289
		echo "<tr><td>".$l_ip_router." <input style='width:120px' type='text' name='ip_gw' value=".$conf['GW']."/></td></tr>";
332
		echo "<tr><td>".$l_ip_router." <input style='width:120px' type='text' name='ip_gw' value=".$conf['GW']."/></td></tr>";
290
		?>
333
		?>
291
	</table>
334
	</table>
292
	</fieldset>
335
	</fieldset>
293
	</td><td>
336
	</td><td>
294
	<fieldset>
337
	<fieldset>
295
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
338
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
296
	<table>
339
	<table>
297
	<?php
340
	<?php
298
	echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
341
	echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
299
	echo "<tr><td>".$l_ip_adr."</td><td> <input style='width:150px' type='text' name='ip_private' value=".$conf['PRIVATE_IP']." /></td></tr>";
342
	echo "<tr><td>".$l_ip_address."</td><td> <input style='width:150px' type='text' name='ip_private' value=".$conf['PRIVATE_IP']." /></td></tr>";
300
	?>
343
	?>
301
	</table>
344
	</table>
302
	</fieldset>
345
	</fieldset>
303
	</td></tr>
346
	</td></tr>
304
	<?php 
347
	<?php 
305
	echo "<td><input type='submit' value='$l_apply' ></td>"; 	
348
	echo "<td><input type='submit' value='$l_apply' ></td>"; 	
306
	echo "</form>";
349
	echo "</form>";
307
	?>
350
	?>
308
</table>
351
</table>
309
<table width="100%" border="0" cellspacing="0" cellpadding="0">
352
<table width="100%" border="0" cellspacing="0" cellpadding="0">
310
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
353
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
311
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
354
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
312
</table>
355
</table>
313
<table width="100%" border=1 cellspacing=0 cellpadding=0>
356
<table width="100%" border=1 cellspacing=0 cellpadding=0>
314
<tr><td colspan="2" valign="middle" align="left">
357
<tr><td colspan="2" valign="middle" align="left">
315
<?
358
<?
316
$dhcp_state=trim($conf["DHCP"]);
359
$dhcp_state=trim($conf["DHCP"]);
317
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
360
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
318
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
361
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
319
echo "<select name='choix'>";
362
echo "<select name='choix'>";
320
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
363
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
321
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on";
364
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on";
322
echo "</select>";
365
echo "</select>";
323
echo "<input type=submit value='$l_apply'>";
366
echo "<input type=submit value='$l_apply'>";
324
echo "<br>$l_DHCP_off_explain";
367
echo "<br>$l_DHCP_off_explain";
325
echo "</FORM>";
368
echo "</FORM>";
326
echo "</td></tr>";
369
echo "</td></tr>";
327
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
370
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
328
else { echo "</TABLE>"; }
371
else { echo "</TABLE>"; }
329
$maxsize=100000;
372
$maxsize=100000;
330
?>
373
?>
331
 
374
 
332
<table width="100%" border="0" cellspacing="0" cellpadding="0">
375
<table width="100%" border="0" cellspacing="0" cellpadding="0">
-
 
376
	<tr><th><?php echo $l_local_dns;?></th></tr>
-
 
377
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
-
 
378
</table>
-
 
379
<table width="100%" border="1" cellspacing="0" cellpadding="0">
-
 
380
<tr><td colspan=2 align="center">
-
 
381
<?
-
 
382
echo "<FORM action='network.php' method='POST'>";
-
 
383
echo "<table cellspacing=2 cellpadding=3 border=1>";
-
 
384
echo "<tr><th>$l_host_name<th>$l_ip_address<th>$l_del</tr>";
-
 
385
// Read the "dns_local" file
-
 
386
$line_exist=False;
-
 
387
$tab=file(DNS_LOCAL_FILE);
-
 
388
if ($tab)  # not empty
-
 
389
	{
-
 
390
	$line_exist=True;
-
 
391
	foreach ($tab as $line)
-
 
392
		{
-
 
393
			if (preg_match ('/^address/', $line))
-
 
394
			{
-
 
395
				$field=explode("/", $line);
-
 
396
				$ip_addr=$field[1];
-
 
397
				$host_name=$field[2];
-
 
398
				echo "<tr><td>$ip_addr";
-
 
399
				echo "<td>$host_name";
-
 
400
				echo "<td><input type='checkbox' name='$host_name'>";
-
 
401
				echo "</tr>";
-
 
402
			}
-
 
403
		}
-
 
404
	}
-
 
405
echo "</table>";
-
 
406
if ($line_exist)
-
 
407
	{
-
 
408
	echo "<input type='hidden' name='choix' value='del_host'>";
-
 
409
	echo "<input type='submit' value='$l_apply'>";
-
 
410
	}	
-
 
411
echo "</form></td><td valign='middle' align='center'>";
-
 
412
echo "<FORM name='new_host' action='network.php' method='POST'>";
-
 
413
echo "<table cellspacing=2 cellpadding=3 border=1>";
-
 
414
echo "<tr><th>$l_host_name<th>$l_ip_address";
-
 
415
?>
-
 
416
<td></td></tr>
-
 
417
<tr><td>exemple : my_nas</td><td>exemple : 192.168.182.10</td><td></td></tr>
-
 
418
<tr><td><input type='text' name='add_host' size='17'></td>
-
 
419
<td><input type='text' name='add_ip' size='10'><input type='hidden' name='choix' value='new_host'></td>
-
 
420
<td><? echo "<input type=submit class=button value=\"$l_add_to_list\">"?></td>
-
 
421
</tr></table>
-
 
422
</form>
-
 
423
</td></tr>
-
 
424
</table>
-
 
425
<table width="100%" border="0" cellspacing="0" cellpadding="0">
333
	<tr><th><?php echo $l_import_cert;?></th></tr>
426
	<tr><th><?php echo $l_import_cert;?></th></tr>
334
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
427
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
335
</table>
428
</table>
336
<table width="100%" border="1" cellspacing="0" cellpadding="0">
429
<table width="100%" border="1" cellspacing="0" cellpadding="0">
337
	<tr><td>
430
	<tr><td>
338
	<form method="post" action="network.php" enctype="multipart/form-data">
431
	<form method="post" action="network.php" enctype="multipart/form-data">
339
	<?php echo $l_private_key;?><input type="file" name="key"><br>
432
	<?php echo $l_private_key;?><input type="file" name="key"><br>
340
	<?php echo $l_certificate;?><input type="file" name="crt"><br>
433
	<?php echo $l_certificate;?><input type="file" name="crt"><br>
341
	<?php echo $l_server_chain;?><input type="file" name="sc">
434
	<?php echo $l_server_chain;?><input type="file" name="sc">
342
	<input type="hidden" name="MAX_FILE_SIZE" value=<?php echo $maxsize;?>><br>
435
	<input type="hidden" name="MAX_FILE_SIZE" value=<?php echo $maxsize;?>><br>
343
	<input type="submit" <?php echo "value=\"".$l_import."\""?>>
436
	<input type="submit" <?php echo "value=\"".$l_import."\""?>>
344
	</form>
437
	</form>
345
<?php
438
<?php
346
$cert_subject = exec("/bin/openssl x509 -noout -subject -in /etc/pki/tls/certs/alcasar.crt");
439
$cert_subject = exec("/bin/openssl x509 -noout -subject -in /etc/pki/tls/certs/alcasar.crt");
347
$cert_issuer = exec("/bin/openssl x509 -noout -issuer -in /etc/pki/tls/certs/alcasar.crt");
440
$cert_issuer = exec("/bin/openssl x509 -noout -issuer -in /etc/pki/tls/certs/alcasar.crt");
348
$cert_expiration_date = exec("/bin/openssl x509 -noout -dates -in /etc/pki/tls/certs/alcasar.crt|grep After|cut -d\"=\" -f2");
441
$cert_expiration_date = exec("/bin/openssl x509 -noout -dates -in /etc/pki/tls/certs/alcasar.crt|grep After|cut -d\"=\" -f2");
349
$domain = exec("echo $cert_subject | sed -n '/^subject/s/^.*CN=//p' | cut -d'/' -f 1");
442
$domain = exec("echo $cert_subject | sed -n '/^subject/s/^.*CN=//p' | cut -d'/' -f 1");
350
$organization = exec("echo $cert_subject | sed -n '/^subject/s/^.*O=//p' | cut -d'/' -f 1");
443
$organization = exec("echo $cert_subject | sed -n '/^subject/s/^.*O=//p' | cut -d'/' -f 1");
351
$CAdomain = exec("echo $cert_issuer | sed -n '/^issuer/s/^.*CN=//p' | cut -d'/' -f 1");
444
$CAdomain = exec("echo $cert_issuer | sed -n '/^issuer/s/^.*CN=//p' | cut -d'/' -f 1");
352
$CAorganization = exec("echo $cert_issuer | sed -n '/^issuer/s/^.*O=//p' | cut -d'/' -f 1");
445
$CAorganization = exec("echo $cert_issuer | sed -n '/^issuer/s/^.*O=//p' | cut -d'/' -f 1");
353
 
446
 
354
	echo "<br>";
447
	echo "<br>";
355
	echo "<h3>".$l_current_certificate."</h3>";
448
	echo "<h3>".$l_current_certificate."</h3>";
356
	echo "Expiration Date : ".$cert_expiration_date."<br>";
449
	echo "Expiration Date : ".$cert_expiration_date."<br>";
357
	echo "Common name : ".$domain."<br>";
450
	echo "Common name : ".$domain."<br>";
358
	echo "Organization : ".$organization."<br/>";
451
	echo "Organization : ".$organization."<br/>";
359
	echo "<h4>". $l_validated ."</h4>";
452
	echo "<h4>". $l_validated ."</h4>";
360
	echo "Common name : ".$CAdomain."<br>";
453
	echo "Common name : ".$CAdomain."<br>";
361
	echo "Organization : ".$CAorganization."<br>";
454
	echo "Organization : ".$CAorganization."<br>";
362
?>
455
?>
363
	</td><td>
456
	</td><td>
364
	<form method="post" action="network.php">
457
	<form method="post" action="network.php">
365
	<input type="hidden" name="default">
458
	<input type="hidden" name="default">
366
	<input type="submit" <?php echo "value=\"".$l_default_cert."\""; if(!file_exists("/etc/pki/tls/certs/alcasar.crt.old") || !file_exists("/etc/pki/tls/private/alcasar.key.old")){ echo " disabled";}?>>
459
	<input type="submit" <?php echo "value=\"".$l_default_cert."\""; if(!file_exists("/etc/pki/tls/certs/alcasar.crt.old") || !file_exists("/etc/pki/tls/private/alcasar.key.old")){ echo " disabled";}?>>
367
	</form>
460
	</form>
368
	</td>
461
	</td>
369
	</tr>
462
	</tr>
370
</table>
463
</table>
371
</body>
464
</body>
372
</html>
465
</html>
373
 
466
 
374
<?php
467
<?php
375
if(isset($_POST['default'])){
468
if(isset($_POST['default'])){
376
	echo "$l_default_cert";
469
	echo "$l_default_cert";
377
	exec("sudo alcasar-importcert.sh -d");
470
	exec("sudo alcasar-importcert.sh -d");
378
}
471
}
379
if(isset($_POST['MAX_FILE_SIZE'])){
472
if(isset($_POST['MAX_FILE_SIZE'])){
380
	echo "changement";
473
	echo "changement";
381
	$maxsize = 100000;
474
	$maxsize = 100000;
382
	if(isset($_FILES['key']) && isset($_FILES['crt']) && $_FILES['key']['error'] == 0 && $_FILES['crt']['error'] == 0){
475
	if(isset($_FILES['key']) && isset($_FILES['crt']) && $_FILES['key']['error'] == 0 && $_FILES['crt']['error'] == 0){
383
		$dest = "/tmp/";
476
		$dest = "/tmp/";
384
		if($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize)
477
		if($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize)
385
		{
478
		{
386
			if(pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt')
479
			if(pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt')
387
			{
480
			{
388
				$scpath = "";
481
				$scpath = "";
389
				if(isset($_FILES['sc']) && pathinfo($_FILES['sc']['name'])['extension'] == 'crt')
482
				if(isset($_FILES['sc']) && pathinfo($_FILES['sc']['name'])['extension'] == 'crt')
390
				{
483
				{
391
					$scpath = $dest."server-chain.crt";
484
					$scpath = $dest."server-chain.crt";
392
					move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
485
					move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
393
				}
486
				}
394
				$keypath = $dest."alcasar.key";
487
				$keypath = $dest."alcasar.key";
395
				$crtpath = $dest."alcasar.crt";
488
				$crtpath = $dest."alcasar.crt";
396
				move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
489
				move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
397
				move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
490
				move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
398
				exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
491
				exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
399
			}
492
			}
400
		}
493
		}
401
	}
494
	}
402
}
495
}
403
?>
496
?>
404
 
497