Subversion Repositories ALCASAR

Rev

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

Rev 2324 Rev 2325
1
<?php
1
<?php
2
# $Id: network.php 2324 2017-07-10 10:18:59Z tom.houdayer $
2
# $Id: network.php 2325 2017-07-10 12:13:57Z tom.houdayer $
3
 
3
 
4
// written by steweb57, Rexy & Tom HOUDAYER
4
// written by steweb57, Rexy & Tom HOUDAYER
5
 
5
 
6
/********************
6
/********************
7
*  READ CONF FILES  *
7
*  READ CONF FILES  *
8
*********************/
8
*********************/
9
define('CONF_FILE', '/usr/local/etc/alcasar.conf');
9
define('CONF_FILE', '/usr/local/etc/alcasar.conf');
10
define('ETHERS_FILE', '/usr/local/etc/alcasar-ethers');
10
define('ETHERS_FILE', '/usr/local/etc/alcasar-ethers');
11
define('ETHERS_INFO_FILE', '/usr/local/etc/alcasar-ethers-info');
11
define('ETHERS_INFO_FILE', '/usr/local/etc/alcasar-ethers-info');
12
define('DNS_LOCAL_FILE', '/usr/local/etc/alcasar-dns-name');
12
define('DNS_LOCAL_FILE', '/usr/local/etc/alcasar-dns-name');
13
define('LETS_ENCRYPT_FILE', '/usr/local/etc/alcasar-letsencrypt');
13
define('LETS_ENCRYPT_FILE', '/usr/local/etc/alcasar-letsencrypt');
14
$conf_files = [CONF_FILE, ETHERS_FILE, ETHERS_INFO_FILE, DNS_LOCAL_FILE, LETS_ENCRYPT_FILE];
14
$conf_files = [CONF_FILE, ETHERS_FILE, ETHERS_INFO_FILE, DNS_LOCAL_FILE, LETS_ENCRYPT_FILE];
15
 
15
 
16
// Files reading test
16
// Files reading test
17
foreach ($conf_files as $file) {
17
foreach ($conf_files as $file) {
18
	if (!file_exists($file)) {
18
	if (!file_exists($file)) {
19
		exit("Requested file $file isn't present");
19
		exit("Requested file $file isn't present");
20
	}
20
	}
21
	if (!is_readable($file)) {
21
	if (!is_readable($file)) {
22
		exit("Can't read the file $file");
22
		exit("Can't read the file $file");
23
	}
23
	}
24
}
24
}
25
 
25
 
26
// Read ALCASAR CONF_FILE
26
// Read ALCASAR CONF_FILE
27
$file_conf = fopen(CONF_FILE, 'r');
27
$file_conf = fopen(CONF_FILE, 'r');
28
if (!$file_conf) {
28
if (!$file_conf) {
29
	exit('Error opening the file '.CONF_FILE);
29
	exit('Error opening the file '.CONF_FILE);
30
}
30
}
31
while (!feof($file_conf)) {
31
while (!feof($file_conf)) {
32
	$buffer = fgets($file_conf, 4096);
32
	$buffer = fgets($file_conf, 4096);
33
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
33
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
34
		$tmp = explode('=', $buffer);
34
		$tmp = explode('=', $buffer);
35
		$conf[trim($tmp[0])] = trim($tmp[1]);
35
		$conf[trim($tmp[0])] = trim($tmp[1]);
36
	}
36
	}
37
}
37
}
38
fclose($file_conf);
38
fclose($file_conf);
39
 
39
 
40
// Choice of language
40
// Choice of language
41
$Language = 'en';
41
$Language = 'en';
42
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
42
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
43
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
43
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
44
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
44
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
45
}
45
}
46
if ($Language === 'fr') {	// French
46
if ($Language === 'fr') {	// French
47
	$l_network_title	= "Configuration réseau";
47
	$l_network_title	= "Configuration réseau";
48
	$l_internet_legend	= "INTERNET";
48
	$l_internet_legend	= "INTERNET";
49
	$l_ip_mask		= "Masque";
49
	$l_ip_mask		= "Masque";
50
	$l_ip_router		= "Passerelle";
50
	$l_ip_router		= "Passerelle";
51
	$l_ip_public		= "Adresse IP publique";
51
	$l_ip_public		= "Adresse IP publique";
52
	$l_ip_dns1		= "DNS n°1";
52
	$l_ip_dns1		= "DNS n°1";
53
	$l_ip_dns2		= "DNS n°2";
53
	$l_ip_dns2		= "DNS n°2";
54
	$l_dhcp_title		= "Service DHCP";
54
	$l_dhcp_title		= "Service DHCP";
55
	$l_dhcp_state		= "Mode actuel";
55
	$l_dhcp_state		= "Mode actuel";
56
	$l_DHCP_on		= "actif";
56
	$l_DHCP_on		= "actif";
57
	$l_DHCP_off		= "inactif";
57
	$l_DHCP_off		= "inactif";
58
	$l_DHCP_off_explain	= "/!\\ Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
58
	$l_DHCP_off_explain	= "/!\\ Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
59
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
59
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
60
	$l_mac_address		= "Adresse MAC";
60
	$l_mac_address		= "Adresse MAC";
61
	$l_ip_address		= "Adresse IP";
61
	$l_ip_address		= "Adresse IP";
62
	$l_host_name		= "Nom d'hôte";
62
	$l_host_name		= "Nom d'hôte";
63
	$l_del			= "Supprimer de la liste";
63
	$l_del			= "Supprimer de la liste";
64
	$l_add_to_list		= "Ajouter";
64
	$l_add_to_list		= "Ajouter";
65
	$l_apply		= "Appliquer les changements";
65
	$l_apply		= "Appliquer les changements";
66
	$l_local_dns		= "Résolution local de nom";
66
	$l_local_dns		= "Résolution local de nom";
67
	$l_import_cert		= "Import de certificat";
67
	$l_import_cert		= "Import de certificat";
68
	$l_private_key		= "Clé privée (.key) :";
68
	$l_private_key		= "Clé privée (.key) :";
69
	$l_certificate		= "Certificat (.crt) :";
69
	$l_certificate		= "Certificat (.crt) :";
70
	$l_server_chain		= "Chaîne de certification (si nécéssaire : .crt) :";
70
	$l_server_chain		= "Chaîne de certification (si nécéssaire : .crt) :";
71
	$l_default_cert		= "Revenir au certificat d'origine";
71
	$l_default_cert		= "Revenir au certificat d'origine";
72
	$l_import		= "Importer";
72
	$l_import		= "Importer";
73
	$l_current_certificate  = "Certificat actuel";
73
	$l_current_certificate  = "Certificat actuel";
74
	$l_validated		= "Validé par :";
74
	$l_validated		= "Validé par :";
75
	$l_empty		= "Vide";
75
	$l_empty		= "Vide";
76
} else {			// English
76
} else {			// English
77
	$l_network_title	= "Network configuration";
77
	$l_network_title	= "Network configuration";
78
	$l_internet_legend	= "INTERNET";
78
	$l_internet_legend	= "INTERNET";
79
	$l_ip_mask		= "Mask";
79
	$l_ip_mask		= "Mask";
80
	$l_ip_router		= "Gateway";
80
	$l_ip_router		= "Gateway";
81
	$l_ip_public		= "Public IP address";
81
	$l_ip_public		= "Public IP address";
82
	$l_ip_dns1		= "DNS n°1";
82
	$l_ip_dns1		= "DNS n°1";
83
	$l_ip_dns2		= "DNS n°2";
83
	$l_ip_dns2		= "DNS n°2";
84
	$l_dhcp_title		= "DHCP service";
84
	$l_dhcp_title		= "DHCP service";
85
	$l_dhcp_state		= "Current mode";
85
	$l_dhcp_state		= "Current mode";
86
	$l_DHCP_on		= "enabled";
86
	$l_DHCP_on		= "enabled";
87
	$l_DHCP_off		= "disabled";
87
	$l_DHCP_off		= "disabled";
88
	$l_DHCP_off_explain	= "/!\\ Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
88
	$l_DHCP_off_explain	= "/!\\ Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
89
	$l_static_dhcp_title	= "Static IP addresses reservation";
89
	$l_static_dhcp_title	= "Static IP addresses reservation";
90
	$l_mac_address		= "MAC Address";
90
	$l_mac_address		= "MAC Address";
91
	$l_ip_address		= "IP Address";
91
	$l_ip_address		= "IP Address";
92
	$l_host_name		= "Host name";
92
	$l_host_name		= "Host name";
93
	$l_del			= "Delete from list";
93
	$l_del			= "Delete from list";
94
	$l_add_to_list		= "Add";
94
	$l_add_to_list		= "Add";
95
	$l_apply		= "Apply changes";
95
	$l_apply		= "Apply changes";
96
	$l_local_dns		= "Local name resolution";
96
	$l_local_dns		= "Local name resolution";
97
	$l_import_cert		= "Certificate import";
97
	$l_import_cert		= "Certificate import";
98
	$l_private_key		= "Private key (.key) :";
98
	$l_private_key		= "Private key (.key) :";
99
	$l_certificate		= "Certificate (.crt) :";
99
	$l_certificate		= "Certificate (.crt) :";
100
	$l_server_chain		= "Server-chain (if necessary : .crt) :";
100
	$l_server_chain		= "Server-chain (if necessary : .crt) :";
101
	$l_default_cert		= "Back to default certificate";
101
	$l_default_cert		= "Back to default certificate";
102
	$l_import		= "Import";
102
	$l_import		= "Import";
103
	$l_current_certificate  = "Current certificate";
103
	$l_current_certificate  = "Current certificate";
104
	$l_validated		= "Validated by :";
104
	$l_validated		= "Validated by :";
105
	$l_empty		= "Empty";
105
	$l_empty		= "Empty";
106
}
106
}
107
 
107
 
108
$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])$/';
108
$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])$/';
109
$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]))$/';
109
$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]))$/';
110
 
110
 
111
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
111
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
112
 
112
 
113
switch ($choix) {
113
switch ($choix) {
114
	case 'DHCP_On':
114
	case 'DHCP_On':
115
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -on');
115
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -on');
116
		break;
116
		break;
117
	case 'DHCP_Off':
117
	case 'DHCP_Off':
118
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
118
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
119
		break;
119
		break;
120
 
120
 
121
	case 'new_mac':
121
	case 'new_mac':
122
		if ((!empty(trim($_POST['add_mac']))) && (!empty(trim($_POST['add_ip'])))) {
122
		if ((!empty(trim($_POST['add_mac']))) && (!empty(trim($_POST['add_ip'])))) {
123
			$tab = file(ETHERS_FILE);
123
			$tab = file(ETHERS_FILE);
124
			if ($tab) { // the file isn't empty
124
			if ($tab) { // the file isn't empty
125
				$insert = true;
125
				$insert = true;
126
				$new_mac_addr = trim($_POST['add_mac'], "\x00..\x20");
126
				$new_mac_addr = trim($_POST['add_mac'], "\x00..\x20");
127
				$new_ip_addr  = trim($_POST['add_ip'],  "\x00..\x20");
127
				$new_ip_addr  = trim($_POST['add_ip'],  "\x00..\x20");
128
				foreach ($tab as $line) { // verify that MAC or IP address doesn't exist
128
				foreach ($tab as $line) { // verify that MAC or IP address doesn't exist
129
					$field = explode(' ', $line);
129
					$field = explode(' ', $line);
130
					$mac_addr = trim($field[0]);
130
					$mac_addr = trim($field[0]);
131
					$ip_addr  = trim($field[1]);
131
					$ip_addr  = trim($field[1]);
132
					if (strcasecmp($new_mac_addr, $mac_addr) === 0) {
132
					if (strcasecmp($new_mac_addr, $mac_addr) === 0) {
133
						$insert = false;
133
						$insert = false;
134
						break;
134
						break;
135
					}
135
					}
136
					if (strcasecmp($new_ip_addr, $ip_addr) === 0) {
136
					if (strcasecmp($new_ip_addr, $ip_addr) === 0) {
137
						$insert = false;
137
						$insert = false;
138
						break;
138
						break;
139
					}
139
					}
140
				}
140
				}
141
				if ($insert) {
141
				if ($insert) {
142
					$line = $new_mac_addr . ' ' . $new_ip_addr . "\n";
142
					$line = $new_mac_addr . ' ' . $new_ip_addr . "\n";
143
					$pointeur = fopen(ETHERS_FILE, 'a');
143
					$pointeur = fopen(ETHERS_FILE, 'a');
144
					fwrite($pointeur, $line);
144
					fwrite($pointeur, $line);
145
					fclose($pointeur);
145
					fclose($pointeur);
146
					$pointeur = fopen(ETHERS_INFO_FILE, 'a');
146
					$pointeur = fopen(ETHERS_INFO_FILE, 'a');
147
					$line = "$new_mac_addr $new_ip_addr #" . trim($_POST['info'],"\x00..\x20") . "\n";
147
					$line = "$new_mac_addr $new_ip_addr #" . trim($_POST['info'],"\x00..\x20") . "\n";
148
					fwrite($pointeur, $line);
148
					fwrite($pointeur, $line);
149
					fclose($pointeur);
149
					fclose($pointeur);
150
					exec('sudo /usr/bin/systemctl reload chilli');
150
					exec('sudo /usr/bin/systemctl reload chilli');
151
				}
151
				}
152
			}
152
			}
153
		}
153
		}
154
		break;
154
		break;
155
	case 'del_mac':
155
	case 'del_mac':
156
		foreach ($_POST as $key => $value) {
156
		foreach ($_POST as $key => $value) {
157
			if ($value == 'on') {
157
			if ($value == 'on') {
158
				$ether_file = ETHERS_FILE;
158
				$ether_file = ETHERS_FILE;
159
				$ether_file_info = ETHERS_INFO_FILE;
159
				$ether_file_info = ETHERS_INFO_FILE;
160
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file"); 
160
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file"); 
161
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info"); 
161
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info"); 
162
				exec('sudo /usr/bin/systemctl reload chilli');
162
				exec('sudo /usr/bin/systemctl reload chilli');
163
			}
163
			}
164
		}
164
		}
165
		break;
165
		break;
166
 
166
 
167
	case 'new_host':
167
	case 'new_host':
168
		if ((!empty(trim($_POST['add_host']))) and (!empty(trim($_POST['add_ip'])))) {
168
		if ((!empty(trim($_POST['add_host']))) and (!empty(trim($_POST['add_ip'])))) {
169
			$tab = file(DNS_LOCAL_FILE);
169
			$tab = file(DNS_LOCAL_FILE);
170
			if ($tab) { // the file isn't empty
170
			if ($tab) { // the file isn't empty
171
				$insert = true;
171
				$insert = true;
172
				foreach ($tab as $line) { // verify that host or IP address doesn't exist
172
				foreach ($tab as $line) { // verify that host or IP address doesn't exist
173
					if (preg_match('/^address/', $line)) {
173
					if (preg_match('/^address/', $line)) {
174
						$field = explode('/', $line);
174
						$field = explode('/', $line);
175
						$host_name = trim($field[1]);
175
						$host_name = trim($field[1]);
176
						$ip_addr   = trim($field[2]);
176
						$ip_addr   = trim($field[2]);
177
						if (strcasecmp(trim($_POST['add_host']), trim($host_name)) === 0) {
177
						if (strcasecmp(trim($_POST['add_host']), trim($host_name)) === 0) {
178
							$insert = false;
178
							$insert = false;
179
							break;
179
							break;
180
						}
180
						}
181
						if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) === 0) {
181
						if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) === 0) {
182
							$insert = false;
182
							$insert = false;
183
							break;
183
							break;
184
						}
184
						}
185
					}
185
					}
186
				}
186
				}
187
				if ($insert) {
187
				if ($insert) {
188
					$line1 = 'address=/'.trim($_POST['add_host']).'/'.trim($_POST['add_ip'])."\n";
188
					$line1 = 'address=/'.trim($_POST['add_host']).'/'.trim($_POST['add_ip'])."\n";
189
					$explode_ip = explode('.', trim($_POST['add_ip']));
189
					$explode_ip = explode('.', trim($_POST['add_ip']));
190
					$reverse_ip = implode('.', array_reverse($explode_ip));
190
					$reverse_ip = implode('.', array_reverse($explode_ip));
191
					$line2 = 'ptr-record='.$reverse_ip.'.in-addr.arpa,'.trim($_POST['add_host'])."\n";
191
					$line2 = 'ptr-record='.$reverse_ip.'.in-addr.arpa,'.trim($_POST['add_host'])."\n";
192
					$pointeur=fopen(DNS_LOCAL_FILE, 'a');
192
					$pointeur=fopen(DNS_LOCAL_FILE, 'a');
193
					fwrite($pointeur, $line1);
193
					fwrite($pointeur, $line1);
194
					fwrite($pointeur, $line2);
194
					fwrite($pointeur, $line2);
195
					fclose($pointeur);
195
					fclose($pointeur);
196
					exec('sudo /usr/bin/systemctl restart dnsmasq');
196
					exec('sudo /usr/bin/systemctl restart dnsmasq');
197
					exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist');
197
					exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist');
198
					exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist');
198
					exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist');
199
					}
199
					}
200
				}
200
				}
201
			}
201
			}
202
		break;
202
		break;
203
	case 'del_host':
203
	case 'del_host':
204
		foreach ($_POST as $key => $value) {
204
		foreach ($_POST as $key => $value) {
205
			if ($value == 'on') {
205
			if ($value == 'on') {
206
				$dns_local_file = DNS_LOCAL_FILE;
206
				$dns_local_file = DNS_LOCAL_FILE;
207
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $dns_local_file"); 
207
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $dns_local_file"); 
208
				exec('sudo /usr/bin/systemctl restart dnsmasq');
208
				exec('sudo /usr/bin/systemctl restart dnsmasq');
209
				exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist');
209
				exec('sudo /usr/bin/systemctl restart dnsmasq-blacklist');
210
				exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist');
210
				exec('sudo /usr/bin/systemctl restart dnsmasq-whitelist');
211
			}
211
			}
212
		}
212
		}
213
		break;
213
		break;
214
 
214
 
215
	case 'default_cert':	// Restore default certificate
215
	case 'default_cert':	// Restore default certificate
216
		exec('sudo alcasar-importcert.sh -d');
216
		exec('sudo alcasar-importcert.sh -d');
217
		break;
217
		break;
218
 
218
 
219
	case 'import_cert':	// Import certificate
219
	case 'import_cert':	// Import certificate
220
		if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) {
220
		if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) {
221
			if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) {
221
			if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) {
222
				if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt') {
222
				if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt') {
223
					$dest = '/tmp/';
223
					$dest = '/tmp/';
224
					$scpath = "";
224
					$scpath = "";
225
					if (isset($_FILES['sc']) && (pathinfo($_FILES['sc']['name'])['extension'] == 'crt')) {
225
					if (isset($_FILES['sc']) && (pathinfo($_FILES['sc']['name'])['extension'] == 'crt')) {
226
						$scpath = $dest.'server-chain.crt';
226
						$scpath = $dest.'server-chain.crt';
227
						move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
227
						move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
228
					}
228
					}
229
					$keypath = $dest."alcasar.key";
229
					$keypath = $dest."alcasar.key";
230
					$crtpath = $dest."alcasar.crt";
230
					$crtpath = $dest."alcasar.crt";
231
					move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
231
					move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
232
					move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
232
					move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
233
					exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
233
					exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
234
					if (file_exists($crtpath)) unlink($crtpath); 
234
					if (file_exists($crtpath)) unlink($crtpath); 
235
					if (file_exists($keypath)) unlink($keypath); 
235
					if (file_exists($keypath)) unlink($keypath); 
236
					if (file_exists($scpath))  unlink($scpath); 
236
					if (file_exists($scpath))  unlink($scpath); 
237
				}
237
				}
238
			}
238
			}
239
		}
239
		}
240
		break;
240
		break;
241
 
241
 
242
	case 'https_login':	// Set HTTPS login status
242
	case 'https_login':	// Set HTTPS login status
243
		if ($_POST['https_login'] === 'on') {
243
		if ($_POST['https_login'] === 'on') {
244
			exec('sudo /usr/local/bin/alcasar-https.sh --on');
244
			exec('sudo /usr/local/bin/alcasar-https.sh --on');
245
		} else {
245
		} else {
246
			exec('sudo /usr/local/bin/alcasar-https.sh --off');
246
			exec('sudo /usr/local/bin/alcasar-https.sh --off');
247
		}
247
		}
248
		header('Location: '.$_SERVER['PHP_SELF']);
248
		header('Location: '.$_SERVER['PHP_SELF']);
249
		exit();
249
		exit();
250
}
250
}
251
 
251
 
252
// Network changes
252
// Network changes
253
if ($choix === 'network_change') {
253
if ($choix === 'network_change') {
254
	$network_modification = false;
254
	$network_modification = false;
255
 
255
 
256
	if (isset($_POST['dns1']) && (trim($_POST['dns1']) !== $conf['DNS1']) && preg_match($reg_ip, $_POST['dns1'])) {
256
	if (isset($_POST['dns1']) && (trim($_POST['dns1']) !== $conf['DNS1']) && preg_match($reg_ip, $_POST['dns1'])) {
257
		file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'], 'DNS1='.trim($_POST['dns1']), file_get_contents(CONF_FILE)));
257
		file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'], 'DNS1='.trim($_POST['dns1']), file_get_contents(CONF_FILE)));
258
		$network_modification = true;
258
		$network_modification = true;
259
	}
259
	}
260
	if (isset($_POST['dns2']) && (trim($_POST['dns2']) !== $conf['DNS2']) && preg_match($reg_ip, $_POST['dns2'])) {
260
	if (isset($_POST['dns2']) && (trim($_POST['dns2']) !== $conf['DNS2']) && preg_match($reg_ip, $_POST['dns2'])) {
261
		file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'], 'DNS2='.trim($_POST['dns2']), file_get_contents(CONF_FILE)));
261
		file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'], 'DNS2='.trim($_POST['dns2']), file_get_contents(CONF_FILE)));
262
		$network_modification = true;
262
		$network_modification = true;
263
	}
263
	}
264
	if (isset($_POST['ip_public']) && (trim($_POST['ip_public']) !== $conf['PUBLIC_IP']) && preg_match($reg_ip_cidr, $_POST['ip_public'])) {
264
	if (isset($_POST['ip_public']) && (trim($_POST['ip_public']) !== $conf['PUBLIC_IP']) && preg_match($reg_ip_cidr, $_POST['ip_public'])) {
265
		file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'], 'PUBLIC_IP='.trim($_POST['ip_public']), file_get_contents(CONF_FILE)));
265
		file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'], 'PUBLIC_IP='.trim($_POST['ip_public']), file_get_contents(CONF_FILE)));
266
		$network_modification = true;
266
		$network_modification = true;
267
	}
267
	}
268
	if (isset($_POST['ip_gw']) && (trim($_POST['ip_gw']) !== $conf['GW']) && preg_match($reg_ip, $_POST['ip_gw'])) {
268
	if (isset($_POST['ip_gw']) && (trim($_POST['ip_gw']) !== $conf['GW']) && preg_match($reg_ip, $_POST['ip_gw'])) {
269
		file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'], 'GW='.trim($_POST['ip_gw']), file_get_contents(CONF_FILE)));
269
		file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'], 'GW='.trim($_POST['ip_gw']), file_get_contents(CONF_FILE)));
270
		$network_modification = true;
270
		$network_modification = true;
271
	}
271
	}
272
	if (isset($_POST['ip_private']) && (trim($_POST['ip_private']) !== $conf['PRIVATE_IP']) && preg_match($reg_ip_cidr, $_POST['ip_private'])) {
272
	if (isset($_POST['ip_private']) && (trim($_POST['ip_private']) !== $conf['PRIVATE_IP']) && preg_match($reg_ip_cidr, $_POST['ip_private'])) {
273
		file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'], 'PRIVATE_IP='.trim($_POST['ip_private']), file_get_contents(CONF_FILE)));
273
		file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'], 'PRIVATE_IP='.trim($_POST['ip_private']), file_get_contents(CONF_FILE)));
274
		$network_modification = true;
274
		$network_modification = true;
275
	}
275
	}
276
 
276
 
277
	if ($network_modification) {
277
	if ($network_modification) {
278
		exec('sudo /usr/local/bin/alcasar-conf.sh -apply');
278
		exec('sudo /usr/local/bin/alcasar-conf.sh -apply');
279
	}
279
	}
280
 
280
 
281
	// Read CONF_FILE updated
281
	// Read CONF_FILE updated
282
	$file_conf = fopen(CONF_FILE, 'r');
282
	$file_conf = fopen(CONF_FILE, 'r');
283
	if (!$file_conf) {
283
	if (!$file_conf) {
284
		exit('Error opening the file '.CONF_FILE);
284
		exit('Error opening the file '.CONF_FILE);
285
	}
285
	}
286
	while (!feof($file_conf)) {
286
	while (!feof($file_conf)) {
287
		$buffer = fgets($file_conf, 4096);
287
		$buffer = fgets($file_conf, 4096);
288
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
288
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
289
			$tmp = explode('=', $buffer);
289
			$tmp = explode('=', $buffer);
290
			$conf[trim($tmp[0])] = trim($tmp[1]);
290
			$conf[trim($tmp[0])] = trim($tmp[1]);
291
		}
291
		}
292
	}
292
	}
293
	fclose($file_conf);
293
	fclose($file_conf);
294
}
294
}
295
 
295
 
296
// Let's Encrypt actions
296
// Let's Encrypt actions
297
if ($choix === 'le_issueCert') {
297
if ($choix === 'le_issueCert') {
298
	// TODO: check ndd & mail format
298
	// TODO: check ndd & mail format
299
 
299
 
300
	$email      = $_POST['email'];
300
	$email      = $_POST['email'];
301
	$domainName = $_POST['domainname'];
301
	$domainName = $_POST['domainname'];
302
 
302
 
303
	exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);
303
	exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);
304
	
304
	
305
	$cmdResponse = implode("<br>\n", $output);
305
	$cmdResponse = implode("<br>\n", $output);
306
}
306
}
307
if ($choix === 'le_renewCert') {
307
if ($choix === 'le_renewCert') {
308
	if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) {
308
	if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) {
309
		$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : '';
309
		$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : '';
310
 
310
 
311
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
311
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
312
 
312
 
313
		$cmdResponse = implode("<br>\n", $output);
313
		$cmdResponse = implode("<br>\n", $output);
314
	} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
314
	} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
315
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
315
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
316
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
316
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
317
	}
317
	}
318
}
318
}
319
 
319
 
320
 
320
 
321
// Read Let's Encrypt configuration file
321
// Read Let's Encrypt configuration file
322
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
322
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
323
if (!$file_conf_LE) {
323
if (!$file_conf_LE) {
324
	exit('Error opening the file '.LETS_ENCRYPT_FILE);
324
	exit('Error opening the file '.LETS_ENCRYPT_FILE);
325
}
325
}
326
while (!feof($file_conf_LE)) {
326
while (!feof($file_conf_LE)) {
327
	$buffer = fgets($file_conf_LE, 4096);
327
	$buffer = fgets($file_conf_LE, 4096);
328
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
328
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
329
		$tmp = explode('=', $buffer);
329
		$tmp = explode('=', $buffer);
330
		$LE_conf[trim($tmp[0])] = trim($tmp[1]);
330
		$LE_conf[trim($tmp[0])] = trim($tmp[1]);
331
	}
331
	}
332
}
332
}
333
fclose($file_conf_LE);
333
fclose($file_conf_LE);
334
 
334
 
335
 
335
 
336
// Fonction de test de connectivité internet
336
// Fonction de test de connectivité internet
337
function internetTest() {
337
function internetTest() {
338
	$host = 'www.google.fr'; # Google Test
338
	$host = 'www.google.fr'; # Google Test
339
	$port = '80';
339
	$port = '80';
340
 
340
 
341
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
341
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
342
		return false;
342
		return false;
343
	} else {
343
	} else {
344
		fclose($sock);
344
		fclose($sock);
345
		return true;
345
		return true;
346
	}
346
	}
347
}
347
}
348
 
348
 
349
$internet_connected = InternetTest();
349
$internet_connected = InternetTest();
350
if ($internet_connected) {
350
if ($internet_connected) {
351
	$internet_publicIP = file_get_contents('http://ipecho.net/plain');
351
	$internet_publicIP = file_get_contents('http://ipecho.net/plain');
352
} else {
352
} else {
353
	$internet_publicIP = '-.-.-.-';
353
	$internet_publicIP = '-.-.-.-';
354
}
354
}
355
 
355
 
356
 
356
 
357
// Network interfaces
357
// Network interfaces
358
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['EXTIF'], $conf['INTIF']];
358
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['EXTIF'], $conf['INTIF']];
359
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable);
359
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable);
360
 
360
 
361
// TODO: Pending the next version
361
// TODO: Pending the next version
362
$externalNetworks = [
362
$externalNetworks = [
363
	(object) [
363
	(object) [
364
		'interface' => $conf['EXTIF'],
364
		'interface' => $conf['EXTIF'],
365
		'ip'        => $conf['PUBLIC_IP'],
365
		'ip'        => $conf['PUBLIC_IP'],
366
		'gateway'   => $conf['GW']
366
		'gateway'   => $conf['GW']
367
	]
367
	]
368
];
368
];
369
$internalNetworks = [
369
$internalNetworks = [
370
	(object) [
370
	(object) [
371
		'interface' => $conf['INTIF'],
371
		'interface' => $conf['INTIF'],
372
		'ip'        => $conf['PRIVATE_IP']
372
		'ip'        => $conf['PRIVATE_IP']
373
	]
373
	]
374
];
374
];
375
 
375
 
376
?>
376
?>
377
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
377
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
378
<html>
378
<html>
379
<head>
379
<head>
380
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
380
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
381
	<title><?= $l_network_title ?></title>
381
	<title><?= $l_network_title ?></title>
382
	<link rel="stylesheet" href="/css/style.css" type="text/css">
382
	<link rel="stylesheet" href="/css/style.css" type="text/css">
383
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
383
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
384
	<script src="/js/jquery.min.js"></script>
384
	<script src="/js/jquery.min.js"></script>
385
	<script src="/js/jquery.connections.js"></script>
385
	<script src="/js/jquery.connections.js"></script>
386
	<script type="text/javascript">
386
	<script type="text/javascript">
387
	function MAC_Control(formulaire){
387
	function MAC_Control(formulaire){
388
		// MAC control (upper case and '-' separator)
388
		// MAC control (upper case and '-' separator)
389
		var regex_mac = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/;
389
		var regex_mac = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/;
390
		if (regex_mac.test(document.forms[formulaire].add_mac.value)){
390
		if (regex_mac.test(document.forms[formulaire].add_mac.value)){
391
			document.forms[formulaire].add_mac.value = document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
391
			document.forms[formulaire].add_mac.value = document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
392
			return true;
392
			return true;
393
		} else {
393
		} else {
394
			alert('Invalid MAC address');
394
			alert('Invalid MAC address');
395
			return false;
395
			return false;
396
		}
396
		}
397
	}
397
	}
398
	</script>
398
	</script>
399
	<style>
399
	<style>
400
	.network-configurator {
400
	.network-configurator {
401
		width: 100%;
401
		width: 100%;
402
	}
402
	}
403
	.network-configurator > * {
403
	.network-configurator > * {
404
		display: inline-block;
404
		display: inline-block;
405
		vertical-align: top;
405
		vertical-align: top;
406
		text-align: center;
406
		text-align: center;
407
	}
407
	}
408
	.network-configurator > .internet, .network-configurator > .alcasar {
408
	.network-configurator > .internet, .network-configurator > .alcasar {
409
		width: 20%;
409
		width: 20%;
410
	}
410
	}
411
	.network-configurator > .externals, .network-configurator > .internals {
411
	.network-configurator > .externals, .network-configurator > .internals {
412
		width: 30%;
412
		width: 30%;
413
	}
413
	}
414
	.network-configurator .actions {
414
	.network-configurator .actions {
415
		position: absolute;
415
		position: absolute;
416
		background-color: #ddd;
416
		background-color: #ddd;
417
		padding: 0 2px;
417
		padding: 0 2px;
418
	}
418
	}
419
	.network-configurator .actions a {
419
	.network-configurator .actions a {
420
		text-decoration: none;
420
		text-decoration: none;
421
	}
421
	}
422
	.network-configurator .actions a:hover {
422
	.network-configurator .actions a:hover {
423
		font-weight: bold;
423
		font-weight: bold;
424
	}
424
	}
425
	.network-configurator > .alcasar .actions-externals {
425
	.network-configurator > .alcasar .actions-externals {
426
		bottom: 0;
426
		bottom: 0;
427
		left: 0;
427
		left: 0;
428
		border-radius: 0 5px;
428
		border-radius: 0 5px;
429
	}
429
	}
430
	.network-configurator > .alcasar .actions-internals {
430
	.network-configurator > .alcasar .actions-internals {
431
		bottom: 0;
431
		bottom: 0;
432
		right: 0;
432
		right: 0;
433
		border-radius: 5px 0;
433
		border-radius: 5px 0;
434
	}
434
	}
435
	.network-configurator .actions-network {
435
	.network-configurator .actions-network {
436
		top: 0;
436
		top: 0;
437
		right: 0;
437
		right: 0;
438
		border-radius: 0 5px;
438
		border-radius: 0 5px;
439
	}
439
	}
440
	.network-configurator .network-box {
440
	.network-configurator .network-box {
441
		display: inline-block;
441
		display: inline-block;
442
		min-height: 100px;
442
		min-height: 100px;
443
		margin: 5px;
443
		margin: 5px;
444
		padding: 3px;
444
		padding: 3px;
445
		text-align: left;
445
		text-align: left;
446
		background-color: #f7f3ef;
446
		background-color: #f7f3ef;
447
		position: relative;
447
		position: relative;
448
		border-radius: 5px;
448
		border-radius: 5px;
449
		border: 2px solid grey;
449
		border: 2px solid grey;
450
	}
450
	}
451
	.network-configurator .network-connector {
451
	.network-configurator .network-connector {
452
		display: inline-block;
452
		display: inline-block;
453
		position: absolute;
453
		position: absolute;
454
		top: 50%;
454
		top: 50%;
455
		margin-top: -5px;
455
		margin-top: -5px;
456
		margin-left: -5px;
456
		margin-left: -5px;
457
		width: 10px;
457
		width: 10px;
458
		height: 10px;
458
		height: 10px;
459
		border-radius: 5px;
459
		border-radius: 5px;
460
		background-color: black;
460
		background-color: black;
461
	}
461
	}
462
	.network-configurator .network-connector[data-connector-direction="left"] {
462
	.network-configurator .network-connector[data-connector-direction="left"] {
463
		border-radius: 5px 0px 0px 5px;
463
		border-radius: 5px 0px 0px 5px;
464
	}
464
	}
465
	.network-configurator .network-connector[data-connector-direction="right"] {
465
	.network-configurator .network-connector[data-connector-direction="right"] {
466
		border-radius: 0px 5px 5px 0px;
466
		border-radius: 0px 5px 5px 0px;
467
	}
467
	}
468
	.network-configurator div[data-network-type] {
468
	.network-configurator div[data-network-type] {
469
		position: relative;
469
		position: relative;
470
	}
470
	}
471
	</style>
471
	</style>
472
	<script>
472
	<script>
473
	$(document).ready(function () {
473
	$(document).ready(function () {
474
		const interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>;
474
		const interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>;
475
 
475
 
476
		const wireStyles = {
476
		const wireStyles = {
477
			available: { border: '5px double green' }
477
			available: { border: '5px double green' }
478
		}
478
		};
479
 
479
 
480
		// Add external network
480
		// Add external network
481
		$('.network-configurator .add-external-network').click(function (event) {
481
		$('.network-configurator .add-external-network').click(function (event) {
482
			event.preventDefault();
482
			event.preventDefault();
483
			let options = '';
483
			let options = '';
484
			if (interfacesAvailable.length === 0) {
484
			if (interfacesAvailable.length === 0) {
485
				options = '<option value=""></option>';
485
				options = '<option value=""></option>';
486
			} else {
486
			} else {
487
				for (let i = 0; i < interfacesAvailable.length; i++) {
487
				for (let i = 0; i < interfacesAvailable.length; i++) {
488
					options += '<option value="' + interfacesAvailable[i] + '">' + interfacesAvailable[i] + '</option>';
488
					options += '<option value="' + interfacesAvailable[i] + '">' + interfacesAvailable[i] + '</option>';
489
				}
489
				}
490
			}
490
			}
491
			$('.network-configurator .externals').append(' \
491
			$('.network-configurator .externals').append(' \
492
				<div data-network-type="external"> \
492
				<div data-network-type="external"> \
493
					<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div> \
493
					<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div> \
494
					<div class="network-box"> \
494
					<div class="network-box"> \
495
						<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
495
						<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
496
						<label for="ext_interface_X"><?= 'Interface' ?></label> <select name="interface" id="ext_interface_X">' + options + '</select><br> \
496
						<label for="ext_interface_X"><?= 'Interface' ?></label> <select name="interface" id="ext_interface_X">' + options + '</select><br> \
497
						<label for="ext_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_public" id="ext_ip_X" value="" /><br> \
497
						<label for="ext_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_public" id="ext_ip_X" value="" /><br> \
498
						<label for="ext_gateway_X"><?= $l_ip_router ?></label> <input style="width:120px" type="text" name="ip_gw" id="ext_gateway_X" value="" /> \
498
						<label for="ext_gateway_X"><?= $l_ip_router ?></label> <input style="width:120px" type="text" name="ip_gw" id="ext_gateway_X" value="" /> \
499
					</div> \
499
					</div> \
500
					<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div> \
500
					<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div> \
501
				</div>');
501
				</div>');
502
			addWire($('div[data-network-type="external"]:last'));
502
			addWire($('div[data-network-type="external"]:last'));
503
		});
503
		});
504
 
504
 
505
		// Add internal network
505
		// Add internal network
506
		$('.network-configurator .add-internal-network').click(function (event) {
506
		$('.network-configurator .add-internal-network').click(function (event) {
507
			event.preventDefault();
507
			event.preventDefault();
508
			$('.network-configurator .internals').append(' \
508
			$('.network-configurator .internals').append(' \
509
					<div data-network-type="internal"> \
509
					<div data-network-type="internal"> \
510
						<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div> \
510
						<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div> \
511
						<div class="network-box"> \
511
						<div class="network-box"> \
512
							<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
512
							<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
513
							<label for="int_interface_X"><?= 'Interface' ?></label> <select name="interface" id="int_interface_X" disabled><option value=""></option></select><br> \
513
							<label for="int_interface_X"><?= 'Interface' ?></label> <select name="interface" id="int_interface_X" disabled><option value=""></option></select><br> \
514
							<label for="int_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_X" value="" /><br> \
514
							<label for="int_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_X" value="" /><br> \
515
						</div> \
515
						</div> \
516
					</div>');
516
					</div>');
517
			addWire($('div[data-network-type="internal"]:last'));
517
			addWire($('div[data-network-type="internal"]:last'));
518
		});
518
		});
519
 
519
 
520
		// Remove network
520
		// Remove network
521
		$('.network-configurator').on('click', '.remove-network', function (event) {
521
		$('.network-configurator').on('click', '.remove-network', function (event) {
522
			event.preventDefault();
522
			event.preventDefault();
523
			$(this).parent().parent().parent().fadeOut(200, function() {
523
			$(this).parent().parent().parent().fadeOut(200, function() {
524
				const networkType = $(this).data('networkType');
524
				const networkType = $(this).data('networkType');
525
				$(this).remove();
525
				$(this).remove();
526
 
526
 
527
				// Update wires
527
				// Update wires
528
				if (networkType === 'external') {
528
				if (networkType === 'external') {
529
					$('div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]').connections('update');
529
					$('div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]').connections('update');
530
					$('div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]').connections('update');
530
					$('div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]').connections('update');
531
				} else if (networkType === 'internal') {
531
				} else if (networkType === 'internal') {
532
					$('div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]').connections('update');
532
					$('div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]').connections('update');
533
				}
533
				}
534
			});
534
			});
535
		});
535
		});
536
 
536
 
537
		const addWire = function (network) {
537
		const addWire = function (network) {
538
			const networkType = network.data('networkType');
538
			const networkType = network.data('networkType');
539
			if (networkType === 'external') {
539
			if (networkType === 'external') {
540
				$().connections({ from: 'div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]', to: 'div[data-network-type="external"]>div.network-connector[data-connector-network="internet"]:last', css: wireStyles.available, within: 'div[data-network-type="external"]:last' });
540
				$().connections({ from: 'div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]', to: 'div[data-network-type="external"]>div.network-connector[data-connector-network="internet"]:last', css: wireStyles.available, within: 'div[data-network-type="external"]:last' });
541
				$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]', to: 'div[data-network-type="external"]>div.network-connector[data-connector-network="external"]:last', css: wireStyles.available, within: 'div[data-network-type="external"]:last' });
541
				$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]', to: 'div[data-network-type="external"]>div.network-connector[data-connector-network="external"]:last', css: wireStyles.available, within: 'div[data-network-type="external"]:last' });
542
			} else if (networkType === 'internal') {
542
			} else if (networkType === 'internal') {
543
				$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]', to: 'div[data-network-type="internal"]>div.network-connector[data-connector-network="internal"]:last', css: wireStyles.available, within: 'div[data-network-type="internal"]:last' });
543
				$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]', to: 'div[data-network-type="internal"]>div.network-connector[data-connector-network="internal"]:last', css: wireStyles.available, within: 'div[data-network-type="internal"]:last' });
544
			}
544
			}
545
		}
545
		};
-
 
546
 
-
 
547
		window.addEventListener('resize', function () {
-
 
548
			$('div.network-connector[data-connector-network]').connections('update');
-
 
549
		});
546
 
550
 
547
		// Add wires to existing networks
551
		// Add wires to existing networks
548
		$('div[data-network-type="external"]').add('div[data-network-type="internal"]').each(function (index, element) {
552
		$('div[data-network-type="external"]').add('div[data-network-type="internal"]').each(function (index, element) {
549
			addWire($(this));
553
			addWire($(this));
550
		})
554
		});
551
	});
555
	});
552
	</script>
556
	</script>
553
</head>
557
</head>
554
<body>
558
<body>
555
	<div class="panel">
559
	<div class="panel">
556
		<div class="panel-header"><?= $l_network_title ?></div>
560
		<div class="panel-header"><?= $l_network_title ?></div>
557
		<div class="panel-body">
561
		<div class="panel-body">
558
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
562
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
559
				<div class="network-configurator">
563
				<div class="network-configurator">
560
					<div class="internet">
564
					<div class="internet">
561
						<div data-network-type="internet">
565
						<div data-network-type="internet">
562
							<div class="network-box">
566
							<div class="network-box">
563
								<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br>
567
								<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br>
564
								<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
568
								<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
565
								<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
569
								<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
566
								<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
570
								<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
567
							</div>
571
							</div>
568
							<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div>
572
							<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div>
569
						</div>
573
						</div>
570
					</div><div class="externals">
574
					</div><div class="externals">
571
						<?php foreach ($externalNetworks as $index => $network): ?>
575
						<?php foreach ($externalNetworks as $index => $network): ?>
572
							<div data-network-type="external">
576
							<div data-network-type="external">
573
								<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div>
577
								<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div>
574
								<div class="network-box">
578
								<div class="network-box">
575
									<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
579
									<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
576
									<label for="ext_interface_<?= $index ?>"><?= 'Interface' ?></label> <select name="ext_interface[<?= $index ?>]" id="ext_interface_<?= $index ?>" disabled><option value="<?= $network->interface ?>"><?= $network->interface ?></option></select><br>
580
									<label for="ext_interface_<?= $index ?>"><?= 'Interface' ?></label> <select name="ext_interface[<?= $index ?>]" id="ext_interface_<?= $index ?>" disabled><option value="<?= $network->interface ?>"><?= $network->interface ?></option></select><br>
577
									<label for="ext_ip_<?= $index ?>"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_public" id="ext_ip_<?= $index ?>" value="<?= $network->ip ?>" /><br>
581
									<label for="ext_ip_<?= $index ?>"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_public" id="ext_ip_<?= $index ?>" value="<?= $network->ip ?>" /><br>
578
									<label for="ext_gateway_<?= $index ?>"><?= $l_ip_router ?></label> <input style="width:120px" type="text" name="ip_gw" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>" />
582
									<label for="ext_gateway_<?= $index ?>"><?= $l_ip_router ?></label> <input style="width:120px" type="text" name="ip_gw" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>" />
579
								</div>
583
								</div>
580
								<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div>
584
								<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div>
581
							</div>
585
							</div>
582
						<? endforeach; ?>
586
						<? endforeach; ?>
583
					</div><div class="alcasar">
587
					</div><div class="alcasar">
584
						<div data-network-type="alcasar">
588
						<div data-network-type="alcasar">
585
							<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div>
589
							<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div>
586
							<div class="network-box">
590
							<div class="network-box">
587
								<!-- <div class="actions actions-externals">
591
								<!-- <div class="actions actions-externals">
588
									<div><a href="#" class="add-external-network" title="Ajouter un réseau externe">+</a></div>
592
									<div><a href="#" class="add-external-network" title="Ajouter un réseau externe">+</a></div>
589
								</div> -->
593
								</div> -->
590
								<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div>
594
								<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div>
591
								<!-- <div class="actions actions-internals">
595
								<!-- <div class="actions actions-internals">
592
									<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div>
596
									<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div>
593
									<div><a href="#" class="add-internal-wifi-network">++</a></div>
597
									<div><a href="#" class="add-internal-wifi-network">++</a></div>
594
								</div> -->
598
								</div> -->
595
							</div>
599
							</div>
596
							<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div>
600
							<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div>
597
						</div>
601
						</div>
598
					</div><div class="internals">
602
					</div><div class="internals">
599
						<?php foreach ($internalNetworks as $network): ?>
603
						<?php foreach ($internalNetworks as $network): ?>
600
							<div data-network-type="internal">
604
							<div data-network-type="internal">
601
								<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div>
605
								<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div>
602
								<div class="network-box">
606
								<div class="network-box">
603
									<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
607
									<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
604
									<label for="int_interface_<?= $index ?>"><?= 'Interface' ?></label> <select name="int_interface[<?= $index ?>]" id="int_interface_<?= $index ?>" disabled><option value="<?= $network->interface ?>"><?= $network->interface ?></option></select><br>
608
									<label for="int_interface_<?= $index ?>"><?= 'Interface' ?></label> <select name="int_interface[<?= $index ?>]" id="int_interface_<?= $index ?>" disabled><option value="<?= $network->interface ?>"><?= $network->interface ?></option></select><br>
605
									<label for="int_ip_<?= $index ?>"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_<?= $index ?>" value="<?= $network->ip ?>" /><br>
609
									<label for="int_ip_<?= $index ?>"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_<?= $index ?>" value="<?= $network->ip ?>" /><br>
606
								</div>
610
								</div>
607
							</div>
611
							</div>
608
						<? endforeach; ?>
612
						<? endforeach; ?>
609
					</div>
613
					</div>
610
				</div>
614
				</div>
611
				<hr>
615
				<hr>
612
				<div style="text-align: center; margin: 5px">
616
				<div style="text-align: center; margin: 5px">
613
					<input type="hidden" name="choix" value="network_change">
617
					<input type="hidden" name="choix" value="network_change">
614
					<input type="submit" value="<?= $l_apply ?>">
618
					<input type="submit" value="<?= $l_apply ?>">
615
				</div>
619
				</div>
616
			</form>
620
			</form>
617
		</div>
621
		</div>
618
	</div>
622
	</div>
619
	<br>
623
	<br>
620
 
624
 
621
<table width="100%" cellspacing="0" cellpadding="0" border="0">
625
<table width="100%" cellspacing="0" cellpadding="0" border="0">
622
	<tr><th><?= $l_dhcp_title?></th></tr>
626
	<tr><th><?= $l_dhcp_title?></th></tr>
623
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
627
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
624
</table>
628
</table>
625
<table width="100%" cellspacing="0" cellpadding="5" border="1">
629
<table width="100%" cellspacing="0" cellpadding="5" border="1">
626
	<tr><td colspan="2" valign="middle" align="left">
630
	<tr><td colspan="2" valign="middle" align="left">
627
	<center><h3><?= $l_dhcp_state ?> : <?= ${'l_DHCP_'.$conf['DHCP']} ?></h3></center>
631
	<center><h3><?= $l_dhcp_state ?> : <?= ${'l_DHCP_'.$conf['DHCP']} ?></h3></center>
628
	<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
632
	<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
629
		<select name="choix">
633
		<select name="choix">
630
			<option value="DHCP_Off"<?= ((!strcmp($conf['DHCP'], 'off')) ? ' selected' : '') ?>><?= $l_DHCP_off ?></option>
634
			<option value="DHCP_Off"<?= ((!strcmp($conf['DHCP'], 'off')) ? ' selected' : '') ?>><?= $l_DHCP_off ?></option>
631
			<option value="DHCP_On"<?= ((!strcmp($conf['DHCP'], 'on')) ? ' selected' : '') ?>><?= $l_DHCP_on ?></option>
635
			<option value="DHCP_On"<?= ((!strcmp($conf['DHCP'], 'on')) ? ' selected' : '') ?>><?= $l_DHCP_on ?></option>
632
		</select>
636
		</select>
633
		<input type="submit" value="<?= $l_apply ?>">
637
		<input type="submit" value="<?= $l_apply ?>">
634
		<br><?= $l_DHCP_off_explain ?>
638
		<br><?= $l_DHCP_off_explain ?>
635
	</form>
639
	</form>
636
	</td></tr>
640
	</td></tr>
637
 
641
 
638
	<?php
642
	<?php
639
	if ($conf['DHCP'] === 'on') {
643
	if ($conf['DHCP'] === 'on') {
640
		require('network2.php');
644
		require('network2.php');
641
	}
645
	}
642
	?>
646
	?>
643
</table>
647
</table>
644
<br>
648
<br>
645
 
649
 
646
<table width="100%" cellspacing="0" cellpadding="0" border="0">
650
<table width="100%" cellspacing="0" cellpadding="0" border="0">
647
	<tr><th><?= $l_local_dns?></th></tr>
651
	<tr><th><?= $l_local_dns?></th></tr>
648
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
652
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
649
</table>
653
</table>
650
<table width="100%" cellspacing="0" cellpadding="5" border="1">
654
<table width="100%" cellspacing="0" cellpadding="5" border="1">
651
<tr>
655
<tr>
652
	<td width="50%" align="center">
656
	<td width="50%" align="center">
653
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
657
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
654
		<table cellspacing="2" cellpadding="3" border="1">
658
		<table cellspacing="2" cellpadding="3" border="1">
655
		<tr><th><?= $l_host_name ?></th><th><?= $l_ip_address ?></th><th><?= $l_del ?></th></tr>
659
		<tr><th><?= $l_host_name ?></th><th><?= $l_ip_address ?></th><th><?= $l_del ?></th></tr>
656
		<?php
660
		<?php
657
		// Read the "dns_local" file
661
		// Read the "dns_local" file
658
		$line_exist = false;
662
		$line_exist = false;
659
		$tab = file(DNS_LOCAL_FILE);
663
		$tab = file(DNS_LOCAL_FILE);
660
		if ($tab) { // not empty
664
		if ($tab) { // not empty
661
			foreach ($tab as $line) {
665
			foreach ($tab as $line) {
662
				if (preg_match ('/^address/', $line)) {
666
				if (preg_match ('/^address/', $line)) {
663
					$line_exist = true;
667
					$line_exist = true;
664
					$field = explode('/', $line);
668
					$field = explode('/', $line);
665
					$host_name = $field[1];
669
					$host_name = $field[1];
666
					$ip_addr   = $field[2];
670
					$ip_addr   = $field[2];
667
					echo "<tr><td>$host_name</td>";
671
					echo "<tr><td>$host_name</td>";
668
					echo "<td>$ip_addr</td>";
672
					echo "<td>$ip_addr</td>";
669
					echo "<td><input type=\"checkbox\" name=\"$host_name\"></td>";
673
					echo "<td><input type=\"checkbox\" name=\"$host_name\"></td>";
670
					echo "</tr>";
674
					echo "</tr>";
671
				}
675
				}
672
			}
676
			}
673
		}
677
		}
674
		if (!$line_exist) {
678
		if (!$line_exist) {
675
			echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
679
			echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
676
		}
680
		}
677
		?>
681
		?>
678
		</table>
682
		</table>
679
		<?php if ($line_exist): ?>
683
		<?php if ($line_exist): ?>
680
			<input type="hidden" name="choix" value="del_host">
684
			<input type="hidden" name="choix" value="del_host">
681
			<input type="submit" value="<?= $l_apply ?>">
685
			<input type="submit" value="<?= $l_apply ?>">
682
		<?php endif; ?>
686
		<?php endif; ?>
683
		</form>
687
		</form>
684
	</td>
688
	</td>
685
	<td width="50%" valign="middle" align="center">
689
	<td width="50%" valign="middle" align="center">
686
		<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
690
		<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
687
		<table cellspacing="2" cellpadding="3" border="1">
691
		<table cellspacing="2" cellpadding="3" border="1">
688
		<tr>
692
		<tr>
689
			<th><?= $l_host_name ?></th><th><?= $l_ip_address ?></th><td></td>
693
			<th><?= $l_host_name ?></th><th><?= $l_ip_address ?></th><td></td>
690
		</tr>
694
		</tr>
691
		<tr>
695
		<tr>
692
			<td>Ex. : my_nas</td><td>Ex. : 192.168.182.10</td><td></td>
696
			<td>Ex. : my_nas</td><td>Ex. : 192.168.182.10</td><td></td>
693
		</tr>
697
		</tr>
694
		<tr>
698
		<tr>
695
			<td><input type="text" name="add_host" size="17"></td>
699
			<td><input type="text" name="add_host" size="17"></td>
696
			<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
700
			<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
697
			<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
701
			<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
698
		</tr>
702
		</tr>
699
		</table>
703
		</table>
700
		</form>
704
		</form>
701
	</td>
705
	</td>
702
</tr>
706
</tr>
703
</table>
707
</table>
704
<br>
708
<br>
705
 
709
 
706
<table width="100%" cellspacing="0" cellpadding="0" border="0">
710
<table width="100%" cellspacing="0" cellpadding="0" border="0">
707
	<tr><th><?= $l_import_cert ?></th></tr>
711
	<tr><th><?= $l_import_cert ?></th></tr>
708
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
712
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
709
</table>
713
</table>
710
<table width="100%" cellspacing="0" cellpadding="5" border="1">
714
<table width="100%" cellspacing="0" cellpadding="5" border="1">
711
	<tr>
715
	<tr>
712
		<td width="50%" valign="top">
716
		<td width="50%" valign="top">
713
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
717
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
714
				<input type="hidden" name="choix" value="https_login">
718
				<input type="hidden" name="choix" value="https_login">
715
				<span>Autoriser les utilisateurs à se connecter de manière non sécurisée :</span><br>
719
				<span>Autoriser les utilisateurs à se connecter de manière non sécurisée :</span><br>
716
				<select name="https_login">
720
				<select name="https_login">
717
					<option value="on"<?=  (($conf['HTTPS_LOGIN'] === 'on')  ? ' selected' : '') ?>>Non</option>
721
					<option value="on"<?=  (($conf['HTTPS_LOGIN'] === 'on')  ? ' selected' : '') ?>>Non</option>
718
					<option value="off"<?= (($conf['HTTPS_LOGIN'] === 'off') ? ' selected' : '') ?>>Oui</option>
722
					<option value="off"<?= (($conf['HTTPS_LOGIN'] === 'off') ? ' selected' : '') ?>>Oui</option>
719
				</select>
723
				</select>
720
				<input type="submit" value="<?= $l_apply ?>"><br>
724
				<input type="submit" value="<?= $l_apply ?>"><br>
721
				<span>/!\ Les identifiants de connexion seront envoyés en clair.</span>
725
				<span>/!\ Les identifiants de connexion seront envoyés en clair.</span>
722
			</form>
726
			</form>
723
			<br>
727
			<br>
724
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
728
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
725
				<input type="hidden" name="choix" value="default_cert">
729
				<input type="hidden" name="choix" value="default_cert">
726
				<input type="submit" value="<?= $l_default_cert ?>" <?= (!file_exists('/etc/pki/tls/certs/alcasar.crt.old') || !file_exists('/etc/pki/tls/private/alcasar.key.old')) ? ' disabled' : '' ?>>
730
				<input type="submit" value="<?= $l_default_cert ?>" <?= (!file_exists('/etc/pki/tls/certs/alcasar.crt.old') || !file_exists('/etc/pki/tls/private/alcasar.key.old')) ? ' disabled' : '' ?>>
727
			</form>
731
			</form>
728
		</td>
732
		</td>
729
		<td width="50%" valign="top">
733
		<td width="50%" valign="top">
730
			<?php
734
			<?php
731
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
735
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
732
 
736
 
733
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
737
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
734
			$domain               = $certificateInfos['subject']['CN'];
738
			$domain               = $certificateInfos['subject']['CN'];
735
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
739
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
736
			$CAdomain             = $certificateInfos['issuer']['CN'];
740
			$CAdomain             = $certificateInfos['issuer']['CN'];
737
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
741
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
738
			?>
742
			?>
739
			<h3><?= $l_current_certificate ?></h3>
743
			<h3><?= $l_current_certificate ?></h3>
740
			Expiration Date : <?= $cert_expiration_date ?><br>
744
			Expiration Date : <?= $cert_expiration_date ?><br>
741
			Common name : <?= $domain ?><br>
745
			Common name : <?= $domain ?><br>
742
			Organization : <?= $organization ?><br/>
746
			Organization : <?= $organization ?><br/>
743
			<h4><?=  $l_validated ?></h4>
747
			<h4><?=  $l_validated ?></h4>
744
			Common name : <?= $CAdomain ?><br>
748
			Common name : <?= $CAdomain ?><br>
745
			Organization : <?= $CAorganization ?><br>
749
			Organization : <?= $CAorganization ?><br>
746
		</td>
750
		</td>
747
	</tr>
751
	</tr>
748
	<tr>
752
	<tr>
749
		<td width="50%" valign="top">
753
		<td width="50%" valign="top">
750
			<h3>Importer un certificat</h3>
754
			<h3>Importer un certificat</h3>
751
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
755
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
752
				<?= $l_private_key;?> <input type="file" name="key"><br>
756
				<?= $l_private_key;?> <input type="file" name="key"><br>
753
				<?= $l_certificate;?> <input type="file" name="crt"><br>
757
				<?= $l_certificate;?> <input type="file" name="crt"><br>
754
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
758
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
755
				<input type="hidden" name="choix" value="import_cert">
759
				<input type="hidden" name="choix" value="import_cert">
756
				<input type="submit" value="<?= $l_import ?>">
760
				<input type="submit" value="<?= $l_import ?>">
757
			</form>
761
			</form>
758
		</td>
762
		</td>
759
		<td width="50%" valign="top">
763
		<td width="50%" valign="top">
760
			<?php
764
			<?php
761
			// Get step
765
			// Get step
762
			if (empty($LE_conf['domainRequest'])) {
766
			if (empty($LE_conf['domainRequest'])) {
763
				$step = 1;
767
				$step = 1;
764
			} else if (!empty($LE_conf['challenge'])) {
768
			} else if (!empty($LE_conf['challenge'])) {
765
				$step = 2;
769
				$step = 2;
766
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
770
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
767
				$step = 3;
771
				$step = 3;
768
			} else {
772
			} else {
769
				$step = 1;
773
				$step = 1;
770
			}
774
			}
771
			?>
775
			?>
772
			<h3>Intégration Let's Encrypt</h3>
776
			<h3>Intégration Let's Encrypt</h3>
773
			<?php if ($step === 1): ?>
777
			<?php if ($step === 1): ?>
774
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
778
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
775
					<input type="hidden" name="choix" value="le_issueCert">
779
					<input type="hidden" name="choix" value="le_issueCert">
776
					Status : Inactif<br>
780
					Status : Inactif<br>
777
					Email : <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
781
					Email : <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
778
					Nom de domaine : <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
782
					Nom de domaine : <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
779
					<input type="submit" name="issue" value="Envoyer"><br>
783
					<input type="submit" name="issue" value="Envoyer"><br>
780
				</form>
784
				</form>
781
			<?php elseif ($step === 2): ?>
785
			<?php elseif ($step === 2): ?>
782
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
786
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
783
					<input type="hidden" name="choix" value="le_renewCert">
787
					<input type="hidden" name="choix" value="le_renewCert">
784
					Status : En attente de validation<br>
788
					Status : En attente de validation<br>
785
					Nom de domaine : <?= $LE_conf['domainRequest'] ?><br>
789
					Nom de domaine : <?= $LE_conf['domainRequest'] ?><br>
786
					Demandé le : <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br>
790
					Demandé le : <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br>
787
					Entrée DNS TXT : "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
791
					Entrée DNS TXT : "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
788
					Challenge : "<?= $LE_conf['challenge'] ?>"<br>
792
					Challenge : "<?= $LE_conf['challenge'] ?>"<br>
789
					<input type="submit" name="recheck" value="Revérifier"> <input type="submit" name="cancel" value="Annuler"><br>
793
					<input type="submit" name="recheck" value="Revérifier"> <input type="submit" name="cancel" value="Annuler"><br>
790
				</form>
794
				</form>
791
			<?php elseif ($step === 3): ?>
795
			<?php elseif ($step === 3): ?>
792
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
796
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
793
					<input type="hidden" name="choix" value="le_renewCert">
797
					<input type="hidden" name="choix" value="le_renewCert">
794
					Status : Actif<br>
798
					Status : Actif<br>
795
					Nom de domaine : <?= $LE_conf['domainRequest'] ?><br>
799
					Nom de domaine : <?= $LE_conf['domainRequest'] ?><br>
796
					API :  <?= $LE_conf['dnsapi'] ?><br>
800
					API :  <?= $LE_conf['dnsapi'] ?><br>
797
					Prochain renouvellement : <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
801
					Prochain renouvellement : <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
798
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
802
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
799
						<input type="submit" name="recheck" value="Renouveller"><br>
803
						<input type="submit" name="recheck" value="Renouveller"><br>
800
					<?php else: ?>
804
					<?php else: ?>
801
						<input type="submit" name="recheck_force" value="Renouveller (forcer)"><br>
805
						<input type="submit" name="recheck_force" value="Renouveller (forcer)"><br>
802
					<?php endif; ?>
806
					<?php endif; ?>
803
				</form>
807
				</form>
804
			<?php endif; ?>
808
			<?php endif; ?>
805
			<?php if (isset($cmdResponse)): ?>
809
			<?php if (isset($cmdResponse)): ?>
806
				<p><?= $cmdResponse ?></p>
810
				<p><?= $cmdResponse ?></p>
807
			<?php endif; ?>
811
			<?php endif; ?>
808
		</td>
812
		</td>
809
	</tr>
813
	</tr>
810
</table>
814
</table>
811
</body>
815
</body>
812
</html>
816
</html>
813
 
817