Subversion Repositories ALCASAR

Rev

Rev 2817 | Rev 2874 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log

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