Subversion Repositories ALCASAR

Rev

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

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