Subversion Repositories ALCASAR

Rev

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

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