Subversion Repositories ALCASAR

Rev

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

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