Subversion Repositories ALCASAR

Rev

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

Rev 3028 Rev 3030
1
<?php
1
<?php
2
# $Id: network.php 3028 2022-06-30 22:25:09Z rexy $
2
# $Id: network.php 3030 2022-07-04 22:29:44Z rexy $
3
 
3
 
4
// written by steweb57, Rexy, Tom HOUDAYER & Pierre RIVAULT
4
// written by steweb57, Rexy, Tom HOUDAYER & Pierre RIVAULT
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
define('TEMP_FILE', '/tmp/alcasar.conf.temp');
14
define('TEMP_FILE', '/tmp/alcasar.conf.temp');
15
 
15
 
16
$conf_files = [CONF_FILE, ETHERS_FILE, ETHERS_INFO_FILE, DNS_LOCAL_FILE, LETS_ENCRYPT_FILE];
16
$conf_files = [CONF_FILE, ETHERS_FILE, ETHERS_INFO_FILE, DNS_LOCAL_FILE, LETS_ENCRYPT_FILE];
17
 
17
 
18
// Files reading test
18
// Files reading test
19
foreach ($conf_files as $file) {
19
foreach ($conf_files as $file) {
20
	if (!file_exists($file)) {
20
	if (!file_exists($file)) {
21
		exit("Requested file $file isn't present");
21
		exit("Requested file $file isn't present");
22
	}
22
	}
23
	if (!is_readable($file)) {
23
	if (!is_readable($file)) {
24
		exit("Can't read the file $file");
24
		exit("Can't read the file $file");
25
	}
25
	}
26
}
26
}
27
 
27
 
28
// Read ALCASAR CONF_FILE
28
// Read ALCASAR CONF_FILE
29
$file_conf = fopen(CONF_FILE, 'r');
29
$file_conf = fopen(CONF_FILE, 'r');
30
if (!$file_conf) {
30
if (!$file_conf) {
31
	exit('Error opening the file '.CONF_FILE);
31
	exit('Error opening the file '.CONF_FILE);
32
}
32
}
33
while (!feof($file_conf)) {
33
while (!feof($file_conf)) {
34
	$buffer = fgets($file_conf, 4096);
34
	$buffer = fgets($file_conf, 4096);
35
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
35
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
36
		$tmp = explode('=', $buffer, 2);
36
		$tmp = explode('=', $buffer, 2);
37
		$conf[trim($tmp[0])] = trim($tmp[1]);
37
		$conf[trim($tmp[0])] = trim($tmp[1]);
38
	}
38
	}
39
}
39
}
40
fclose($file_conf);
40
fclose($file_conf);
41
 
41
 
42
// Choice of language
42
// Choice of language
43
$Language = 'en';
43
$Language = 'en';
44
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
44
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
45
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
45
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
46
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
46
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
47
}
47
}
48
if ($Language === 'fr') {
48
if ($Language === 'fr') {
49
	$l_network_title	= "Configuration réseau";
49
	$l_network_title	= "Configuration réseau";
50
	$l_internet_legend	= "INTERNET";
50
	$l_internet_legend	= "INTERNET";
51
	$l_ip_mask		= "Masque";
51
	$l_ip_mask		= "Masque";
52
	$l_ip_router		= "Passerelle";
52
	$l_ip_router		= "Passerelle";
53
	$l_ip_public		= "Adresse IP publique";
53
	$l_ip_public		= "Adresse IP publique";
54
	$l_ip_dns1		= "DNS n°1";
54
	$l_ip_dns1		= "DNS n°1";
55
	$l_ip_dns2		= "DNS n°2";
55
	$l_ip_dns2		= "DNS n°2";
56
	$l_dhcp_title		= "Service DHCP";
56
	$l_dhcp_title		= "Service DHCP";
57
	$l_dhcp_state		= "Mode actuel";
57
	$l_dhcp_state		= "Mode actuel";
58
	$l_DHCP_on		= "actif";
58
	$l_DHCP_on		= "actif";
59
	$l_DHCP_off		= "inactif";
59
	$l_DHCP_off		= "inactif";
60
	$l_DHCP_off_explain	= "/!\\ Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
60
	$l_DHCP_off_explain	= "/!\\ Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
61
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques (DHCP)";
61
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques (DHCP)";
62
	$l_mac_address		= "Adresse MAC";
62
	$l_mac_address		= "Adresse MAC";
63
	$l_ip_address		= "Adresse IP";
63
	$l_ip_address		= "Adresse IP";
64
	$l_host_name		= "Nom d'hôte";
64
	$l_host_name		= "Nom d'hôte";
65
	$l_del			= "Supprimer de la liste";
65
	$l_del			= "Supprimer de la liste";
66
	$l_add_to_list		= "Ajouter";
66
	$l_add_to_list		= "Ajouter";
67
	$l_apply		= "Appliquer les changements";
67
	$l_apply		= "Appliquer les changements";
68
	$l_local_dns		= "Résolution local de nom (DNS)";
68
	$l_local_dns		= "Résolution local de nom (DNS)";
69
	$l_import_cert		= "Import de certificat";
69
	$l_import_cert		= "Import de certificat";
70
	$l_private_key		= "Clé privée (.key) :";
70
	$l_private_key		= "Clé privée (.key) :";
71
	$l_certificate		= "Certificat (.crt ou .cer) :";
71
	$l_certificate		= "Certificat (.crt ou .cer) :";
72
	$l_server_chain		= "Chaîne de certification (.crt, .cer ou .pem) :";
72
	$l_server_chain		= "Chaîne de certification (.crt, .cer ou .pem) :";
73
	$l_default_cert		= "Revenir au certificat d'origine :";
73
	$l_default_cert		= "Revenir au certificat d'origine :";
74
	$l_import		= "Importer";
74
	$l_import		= "Importer";
75
	$l_current_certificate  = "Certificat actuel";
75
	$l_current_certificate  = "Certificat actuel";
76
	$l_validated		= "Validé par :";
76
	$l_validated		= "Validé par :";
77
	$l_empty		= "Vide";
77
	$l_empty		= "Vide";
78
	$l_yes			= "Oui";
78
	$l_yes			= "Oui";
79
	$l_no			= "Non";
79
	$l_no			= "Non";
80
	$l_ssl_title		= "Chiffrer les flux d'authentification entre les utilisateurs et ALCASAR";
80
	$l_ssl_title		= "Chiffrer les flux d'authentification entre les utilisateurs et ALCASAR";
-
 
81
	$l_cert_from	= "Date d'émission";
81
	$l_cert_expiration	= "Date d'expiration :";
82
	$l_cert_expiration	= "Date d'expiration :";
82
	$l_cert_commonname	= "Nom commun :";
83
	$l_cert_commonname	= "Nom commun :";
83
	$l_cert_organization	= "Organisation :";
84
	$l_cert_organization	= "Organisation :";
84
	$l_upload_certificate	= "Importer un certificat officiel";
85
	$l_upload_certificate	= "Importer un certificat officiel";
-
 
86
	$l_le_renewal	= "Renouveler le certificat Let's Encrypt";
85
	$l_le_integration	= "Intégrer un certificat Let's Encrypt";
87
	$l_le_integration	= "Intégrer un certificat Let's Encrypt";
86
	$l_le_status		= "Status :";
88
	$l_le_status		= "Status :";
87
	$l_disabled		= "Inactif";
89
	$l_disabled		= "Inactif";
88
	$l_pending_validation	= "En attente de validation";
90
	$l_pending_validation	= "En attente de validation";
89
	$l_enabled		= "Actif";
91
	$l_enabled		= "Actif";
90
	$l_le_email		= "Email :";
92
	$l_le_email		= "Email :";
91
	$l_le_domain_name	= "Nom de domaine :";
93
	$l_le_domain_name	= "Nom de domaine :";
92
	$l_send			= "Envoyer";
94
	$l_send			= "Envoyer";
93
	$l_le_ask_on		= "Demandé le :";
95
	$l_le_ask_on		= "Demandé le :";
94
	$l_le_dns_entry_txt	= "Entrée DNS TXT :";
96
	$l_le_dns_entry_txt	= "Entrée DNS TXT :";
95
	$l_le_challenge		= "Challenge :";
97
	$l_le_challenge		= "Challenge :";
96
	$l_recheck		= "Revérifier";
98
	$l_recheck		= "Revérifier";
97
	$l_cancel		= "Annuler";
99
	$l_cancel		= "Annuler";
98
	$l_le_api		= "API :";
100
	$l_le_api		= "API :";
99
	$l_le_next_renewal	= "Prochain renouvellement :";
101
	$l_le_next_renewal	= "Prochain renouvellement :";
100
	$l_renew		= "Renouveller";
102
	$l_renew		= "Renouveller";
101
	$l_renew_force		= "Renouveller (forcer)";
103
	$l_renew_force		= "Renouveller (forcer)";
102
	$l_previous_LE_cert	= "Revenir au certificat Let's Encrypt :";
104
	$l_previous_LE_cert	= "Revenir au certificat Let's Encrypt :";
103
	$l_gw_weight    = "Poids";
105
	$l_gw_weight    = "Poids";
104
	$l_error        = "Erreur";
106
	$l_error        = "Erreur";
105
	$l_error_bad_ip = "Ceci n'est pas une adresse IP valide";
107
	$l_error_bad_ip = "Ceci n'est pas une adresse IP valide";
106
	$l_error_bad_ip_CIDR = "Ceci n'est pas une adresse CIDR valide";
108
	$l_error_bad_ip_CIDR = "Ceci n'est pas une adresse CIDR valide";
107
	$l_error_bad_ip_port = "Ceci n'est pas une adresse IP + port valide";
109
	$l_error_bad_ip_port = "Ceci n'est pas une adresse IP + port valide";
108
	$l_error_weight = "Ceci n'est pas un poids valide";
110
	$l_error_weight = "Ceci n'est pas un poids valide";
109
    $l_change_successful = "Changement effectué avec succès";
111
    $l_change_successful = "Changement effectué avec succès";
110
 
112
 
111
} else if ($Language === 'es') {
113
} else if ($Language === 'es') {
112
	$l_network_title	= "Configuración de Red";
114
	$l_network_title	= "Configuración de Red";
113
	$l_internet_legend	= "INTERNET";
115
	$l_internet_legend	= "INTERNET";
114
	$l_ip_mask		= "Máscara";
116
	$l_ip_mask		= "Máscara";
115
	$l_ip_router		= "Puerta de enlace";
117
	$l_ip_router		= "Puerta de enlace";
116
	$l_ip_public		= "IP Pública";
118
	$l_ip_public		= "IP Pública";
117
	$l_ip_dns1		= "DNS n°1";
119
	$l_ip_dns1		= "DNS n°1";
118
	$l_ip_dns2		= "DNS n°2";
120
	$l_ip_dns2		= "DNS n°2";
119
	$l_dhcp_title		= "Servicio DHCP";
121
	$l_dhcp_title		= "Servicio DHCP";
120
	$l_dhcp_state		= "Modo actual";
122
	$l_dhcp_state		= "Modo actual";
121
	$l_DHCP_on		= "activado";
123
	$l_DHCP_on		= "activado";
122
	$l_DHCP_off		= "desactivado";
124
	$l_DHCP_off		= "desactivado";
123
	$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";
125
	$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";
124
	$l_static_dhcp_title	= "Reserva de direcciones IP estáticas (DHCP)";
126
	$l_static_dhcp_title	= "Reserva de direcciones IP estáticas (DHCP)";
125
	$l_mac_address		= "Dirección MAC";
127
	$l_mac_address		= "Dirección MAC";
126
	$l_ip_address		= "Dirección IP";
128
	$l_ip_address		= "Dirección IP";
127
	$l_host_name		= "Nombre de Host";
129
	$l_host_name		= "Nombre de Host";
128
	$l_del			= "Borrar de la lista";
130
	$l_del			= "Borrar de la lista";
129
	$l_add_to_list		= "Agregar";
131
	$l_add_to_list		= "Agregar";
130
	$l_apply		= "Aplicar cambios";
132
	$l_apply		= "Aplicar cambios";
131
	$l_local_dns		= "Resolución de Nombres Local (DNS)";
133
	$l_local_dns		= "Resolución de Nombres Local (DNS)";
132
	$l_import_cert		= "Importar Certificado";
134
	$l_import_cert		= "Importar Certificado";
133
	$l_private_key		= "Clave Privada (.key) :";
135
	$l_private_key		= "Clave Privada (.key) :";
134
	$l_certificate		= "Certificado (.crt) :";
136
	$l_certificate		= "Certificado (.crt) :";
135
	$l_server_chain		= "Cadena completa (de ser necesario: .crt) :";
137
	$l_server_chain		= "Cadena completa (de ser necesario: .crt) :";
136
	$l_default_cert		= "Volverl al certificado por defecto";
138
	$l_default_cert		= "Volverl al certificado por defecto";
137
	$l_import		= "Importar";
139
	$l_import		= "Importar";
138
	$l_current_certificate  = "Certificado en uso";
140
	$l_current_certificate  = "Certificado en uso";
139
	$l_validated		= "Validado por :";
141
	$l_validated		= "Validado por :";
140
	$l_empty		= "Vacío";
142
	$l_empty		= "Vacío";
141
	$l_yes			= "Si";
143
	$l_yes			= "Si";
142
	$l_no			= "No";
144
	$l_no			= "No";
143
	$l_ssl_title		= "La autenticación de cifrado fluye entre usuarios y ALCASAR";
145
	$l_ssl_title		= "La autenticación de cifrado fluye entre usuarios y ALCASAR";
-
 
146
	$l_cert_from	= "Fecha de emisión";
144
	$l_cert_expiration	= "Fecha de vencimiento:";
147
	$l_cert_expiration	= "Fecha de vencimiento:";
145
	$l_cert_commonname	= "Common name:";
148
	$l_cert_commonname	= "Common name:";
146
	$l_cert_organization	= "Organización:";
149
	$l_cert_organization	= "Organización:";
147
	$l_upload_certificate	= "Importar un certificado";
150
	$l_upload_certificate	= "Importar un certificado";
148
	$l_le_integration	= "Integración con Let's Encrypt";
151
	$l_le_integration	= "Integración con Let's Encrypt";
-
 
152
	$l_le_renewal	= "Renovación del certificado Let's Encrypt";
149
	$l_le_status		= "Estado:";
153
	$l_le_status		= "Estado:";
150
	$l_disabled		= "Desactivado";
154
	$l_disabled		= "Desactivado";
151
	$l_pending_validation	= "Validación pendiente";
155
	$l_pending_validation	= "Validación pendiente";
152
	$l_enabled		= "Activado";
156
	$l_enabled		= "Activado";
153
	$l_le_email		= "Email:";
157
	$l_le_email		= "Email:";
154
	$l_le_domain_name	= "Nombre de dominio:";
158
	$l_le_domain_name	= "Nombre de dominio:";
155
	$l_send			= "Enviar";
159
	$l_send			= "Enviar";
156
	$l_le_ask_on		= "Preguntar el:";
160
	$l_le_ask_on		= "Preguntar el:";
157
	$l_le_dns_entry_txt	= "Entrada DNS TXT:";
161
	$l_le_dns_entry_txt	= "Entrada DNS TXT:";
158
	$l_le_challenge		= "Desafío:";
162
	$l_le_challenge		= "Desafío:";
159
	$l_recheck		= "Verificar";
163
	$l_recheck		= "Verificar";
160
	$l_cancel		= "Cancelar";
164
	$l_cancel		= "Cancelar";
161
	$l_le_api		= "API:";
165
	$l_le_api		= "API:";
162
	$l_le_next_renewal	= "Siguiente renovación:";
166
	$l_le_next_renewal	= "Siguiente renovación:";
163
	$l_renew		= "Renovar";
167
	$l_renew		= "Renovar";
164
	$l_renew_force		= "Renovar (forzado)";
168
	$l_renew_force		= "Renovar (forzado)";
165
	$l_previous_LE_cert	= "Volver al certificado de Let's Encrypt :";
169
	$l_previous_LE_cert	= "Volver al certificado de Let's Encrypt :";
166
    $l_gw_weight	= "Peso";
170
    $l_gw_weight	= "Peso";
167
    $l_error		= "Error";
171
    $l_error		= "Error";
168
    $l_error_bad_ip	= "Esta no es una dirección IP válida";
172
    $l_error_bad_ip	= "Esta no es una dirección IP válida";
169
    $l_error_bad_ip_CIDR	= "Esta no es una dirección CIDR válida";
173
    $l_error_bad_ip_CIDR	= "Esta no es una dirección CIDR válida";
170
    $l_error_bad_ip_port	= "Esto no es una dirección IP + puerto válidos";
174
    $l_error_bad_ip_port	= "Esto no es una dirección IP + puerto válidos";
171
    $l_error_weight	= "Esto no es un peso válido";
175
    $l_error_weight	= "Esto no es un peso válido";
172
    $l_change_successful	= "Cambio completado con éxito";
176
    $l_change_successful	= "Cambio completado con éxito";
173
} else {
177
} else {
174
	$l_network_title	= "Network configuration";
178
	$l_network_title	= "Network configuration";
175
	$l_internet_legend	= "INTERNET";
179
	$l_internet_legend	= "INTERNET";
176
	$l_ip_mask		= "Mask";
180
	$l_ip_mask		= "Mask";
177
	$l_ip_router		= "Gateway";
181
	$l_ip_router		= "Gateway";
178
	$l_ip_public		= "Public IP address";
182
	$l_ip_public		= "Public IP address";
179
	$l_ip_dns1		= "DNS n°1";
183
	$l_ip_dns1		= "DNS n°1";
180
	$l_ip_dns2		= "DNS n°2";
184
	$l_ip_dns2		= "DNS n°2";
181
	$l_dhcp_title		= "DHCP service";
185
	$l_dhcp_title		= "DHCP service";
182
	$l_dhcp_state		= "Current mode";
186
	$l_dhcp_state		= "Current mode";
183
	$l_DHCP_on		= "enabled";
187
	$l_DHCP_on		= "enabled";
184
	$l_DHCP_off		= "disabled";
188
	$l_DHCP_off		= "disabled";
185
	$l_DHCP_off_explain	= "/!\\ Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
189
	$l_DHCP_off_explain	= "/!\\ Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
186
	$l_static_dhcp_title	= "Static IP addresses reservation (DHCP)";
190
	$l_static_dhcp_title	= "Static IP addresses reservation (DHCP)";
187
	$l_mac_address		= "MAC address";
191
	$l_mac_address		= "MAC address";
188
	$l_ip_address		= "IP address";
192
	$l_ip_address		= "IP address";
189
	$l_host_name		= "Host name";
193
	$l_host_name		= "Host name";
190
	$l_del			= "Delete from list";
194
	$l_del			= "Delete from list";
191
	$l_add_to_list		= "Add";
195
	$l_add_to_list		= "Add";
192
	$l_apply		= "Apply changes";
196
	$l_apply		= "Apply changes";
193
	$l_local_dns		= "Local name resolution (DNS";
197
	$l_local_dns		= "Local name resolution (DNS";
194
	$l_import_cert		= "Certificate import";
198
	$l_import_cert		= "Certificate import";
195
	$l_private_key		= "Private key (.key) :";
199
	$l_private_key		= "Private key (.key) :";
196
	$l_certificate		= "Certificate (.crt or .cer) :";
200
	$l_certificate		= "Certificate (.crt or .cer) :";
197
	$l_server_chain		= "Server-chain (.crt, .cer or .pem) :";
201
	$l_server_chain		= "Server-chain (.crt, .cer or .pem) :";
198
	$l_default_cert		= "Back to default certificate :";
202
	$l_default_cert		= "Back to default certificate :";
199
	$l_import		= "Import";
203
	$l_import		= "Import";
200
	$l_current_certificate  = "Current certificate";
204
	$l_current_certificate  = "Current certificate";
201
	$l_validated		= "Validated by :";
205
	$l_validated		= "Validated by :";
202
	$l_empty		= "Empty";
206
	$l_empty		= "Empty";
203
	$l_yes			= "Yes";
207
	$l_yes			= "Yes";
204
	$l_no			= "No";
208
	$l_no			= "No";
205
	$l_ssl_title		= "Cipher authentication flows between users and ALCASAR";
209
	$l_ssl_title		= "Cipher authentication flows between users and ALCASAR";
-
 
210
	$l_cert_from	= "Date of issue";
206
	$l_cert_expiration	= "Expiration date:";
211
	$l_cert_expiration	= "Expiration date:";
207
	$l_cert_commonname	= "Common name:";
212
	$l_cert_commonname	= "Common name:";
208
	$l_cert_organization	= "Organization:";
213
	$l_cert_organization	= "Organization:";
209
	$l_upload_certificate	= "Import an officlal certificate";
214
	$l_upload_certificate	= "Import an officlal certificate";
210
	$l_le_integration	= "Integrate a Let's Encrypt certificate";
215
	$l_le_integration	= "Integrate a Let's Encrypt certificate";
-
 
216
	$l_le_renewal	= "Renewing the Let's Encrypt certificate";
211
	$l_le_status		= "Status:";
217
	$l_le_status		= "Status:";
212
	$l_disabled		= "Disabled";
218
	$l_disabled		= "Disabled";
213
	$l_pending_validation	= "Pending validation";
219
	$l_pending_validation	= "Pending validation";
214
	$l_enabled		= "Enabled";
220
	$l_enabled		= "Enabled";
215
	$l_le_email		= "Email:";
221
	$l_le_email		= "Email:";
216
	$l_le_domain_name	= "Domain name:";
222
	$l_le_domain_name	= "Domain name:";
217
	$l_send			= "Send";
223
	$l_send			= "Send";
218
	$l_le_ask_on		= "Ask on:";
224
	$l_le_ask_on		= "Ask on:";
219
	$l_le_dns_entry_txt	= "DNS TXT entry:";
225
	$l_le_dns_entry_txt	= "DNS TXT entry:";
220
	$l_le_challenge		= "Challenge:";
226
	$l_le_challenge		= "Challenge:";
221
	$l_recheck		= "Recheck";
227
	$l_recheck		= "Recheck";
222
	$l_cancel		= "Cancel";
228
	$l_cancel		= "Cancel";
223
	$l_le_api		= "API:";
229
	$l_le_api		= "API:";
224
	$l_le_next_renewal	= "Next renewal:";
230
	$l_le_next_renewal	= "Next renewal:";
225
	$l_renew		= "Renew";
231
	$l_renew		= "Renew";
226
	$l_renew_force		= "Renew (force)";
232
	$l_renew_force		= "Renew (force)";
227
	$l_previous_LE_cert	= "Back to the Let's Encrypt certificate :";
233
	$l_previous_LE_cert	= "Back to the Let's Encrypt certificate :";
228
    $l_gw_weight = "Weight";
234
    $l_gw_weight = "Weight";
229
    $l_error        = "Error";
235
    $l_error        = "Error";
230
    $l_error_bad_ip = "This is not a valid IP";
236
    $l_error_bad_ip = "This is not a valid IP";
231
    $l_error_bad_ip_CIDR = "This is not a valid CIDR IP";
237
    $l_error_bad_ip_CIDR = "This is not a valid CIDR IP";
232
    $l_error_bad_ip_port = "This is not a valid IP + port";
238
    $l_error_bad_ip_port = "This is not a valid IP + port";
233
    $l_error_weight = "This is not a valid weight";
239
    $l_error_weight = "This is not a valid weight";
234
    $l_change_successful = "Network updated successfully";
240
    $l_change_successful = "Network updated successfully";
235
}
241
}
236
 
242
 
237
$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])$/';
243
$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])$/';
238
$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]))$/';
244
$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]))$/';
239
$reg_ip_port = '/^(([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])(\:([1-9]|[1-9][0-9]|[1-9][0-9]{2}|[1-9][0-9]{3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))$/';
245
$reg_ip_port = '/^(([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])(\:([1-9]|[1-9][0-9]|[1-9][0-9]{2}|[1-9][0-9]{3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]))$/';
240
$reg_mac     = '/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/';
246
$reg_mac     = '/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/';
241
$reg_host    = '/^[a-zA-Z0-9-_]+$/';
247
$reg_host    = '/^[a-zA-Z0-9-_]+$/';
242
$reg_weight  = '/^[0-9]*$/';
248
$reg_weight  = '/^[0-9]*$/';
243
$ext_conf_error = false;
249
$ext_conf_error = false;
244
 
250
 
245
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
251
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
246
switch ($choix) {
252
switch ($choix) {
247
	case 'DHCP_On':
253
	case 'DHCP_On':
248
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -on');
254
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -on');
249
		header('Location: '.$_SERVER['PHP_SELF']);
255
		header('Location: '.$_SERVER['PHP_SELF']);
250
		exit();
256
		exit();
251
	case 'DHCP_Off':
257
	case 'DHCP_Off':
252
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
258
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
253
		header('Location: '.$_SERVER['PHP_SELF']);
259
		header('Location: '.$_SERVER['PHP_SELF']);
254
		exit();
260
		exit();
255
	case 'new_mac':
261
	case 'new_mac':
256
		$new_mac_addr = trim($_POST['add_mac']);
262
		$new_mac_addr = trim($_POST['add_mac']);
257
		$new_ip_addr  = trim($_POST['add_ip']);
263
		$new_ip_addr  = trim($_POST['add_ip']);
258
		if (((!empty($new_mac_addr)) && (preg_match($reg_mac, $new_mac_addr))) && ((!empty($new_ip_addr)) && (preg_match($reg_ip, $new_ip_addr)))) {
264
		if (((!empty($new_mac_addr)) && (preg_match($reg_mac, $new_mac_addr))) && ((!empty($new_ip_addr)) && (preg_match($reg_ip, $new_ip_addr)))) {
259
			$tab = file(ETHERS_FILE);
265
			$tab = file(ETHERS_FILE);
260
			if ($tab) { // the file isn't empty
266
			if ($tab) { // the file isn't empty
261
				$insert = true;
267
				$insert = true;
262
				foreach ($tab as $line) { // verify that MAC or IP address doesn't exist
268
				foreach ($tab as $line) { // verify that MAC or IP address doesn't exist
263
					$field = explode(' ', $line);
269
					$field = explode(' ', $line);
264
					$mac_addr = trim($field[0]);
270
					$mac_addr = trim($field[0]);
265
					$ip_addr  = trim($field[1]);
271
					$ip_addr  = trim($field[1]);
266
					if (strcasecmp($new_mac_addr, $mac_addr) === 0) {
272
					if (strcasecmp($new_mac_addr, $mac_addr) === 0) {
267
						$insert = false;
273
						$insert = false;
268
						break;
274
						break;
269
					}
275
					}
270
					if (strcasecmp($new_ip_addr, $ip_addr) === 0) {
276
					if (strcasecmp($new_ip_addr, $ip_addr) === 0) {
271
						$insert = false;
277
						$insert = false;
272
						break;
278
						break;
273
					}
279
					}
274
				}
280
				}
275
				if ($insert) {
281
				if ($insert) {
276
					$line = $new_mac_addr . ' ' . $new_ip_addr . "\n";
282
					$line = $new_mac_addr . ' ' . $new_ip_addr . "\n";
277
					$pointeur = fopen(ETHERS_FILE, 'a');
283
					$pointeur = fopen(ETHERS_FILE, 'a');
278
					fwrite($pointeur, $line);
284
					fwrite($pointeur, $line);
279
					fclose($pointeur);
285
					fclose($pointeur);
280
					$pointeur = fopen(ETHERS_INFO_FILE, 'a');
286
					$pointeur = fopen(ETHERS_INFO_FILE, 'a');
281
					$line = "$new_mac_addr $new_ip_addr #" . trim($_POST['info'],"\x00..\x20") . "\n";
287
					$line = "$new_mac_addr $new_ip_addr #" . trim($_POST['info'],"\x00..\x20") . "\n";
282
					fwrite($pointeur, $line);
288
					fwrite($pointeur, $line);
283
					fclose($pointeur);
289
					fclose($pointeur);
284
					exec('sudo /usr/bin/systemctl reload chilli');
290
					exec('sudo /usr/bin/systemctl reload chilli');
285
				}
291
				}
286
			}
292
			}
287
		}
293
		}
288
		header('Location: '.$_SERVER['PHP_SELF']);
294
		header('Location: '.$_SERVER['PHP_SELF']);
289
		exit();
295
		exit();
290
	case 'del_mac':
296
	case 'del_mac':
291
		foreach ($_POST as $key => $value) {
297
		foreach ($_POST as $key => $value) {
292
			if ($value == 'on') {
298
			if ($value == 'on') {
293
				$ether_file = ETHERS_FILE;
299
				$ether_file = ETHERS_FILE;
294
				$ether_file_info = ETHERS_INFO_FILE;
300
				$ether_file_info = ETHERS_INFO_FILE;
295
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file");
301
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file");
296
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info");
302
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info");
297
				exec('sudo /usr/bin/systemctl reload chilli');
303
				exec('sudo /usr/bin/systemctl reload chilli');
298
			}
304
			}
299
		}
305
		}
300
		header('Location: '.$_SERVER['PHP_SELF']);
306
		header('Location: '.$_SERVER['PHP_SELF']);
301
		exit();
307
		exit();
302
	case 'new_host':
308
	case 'new_host':
303
		$add_host = trim($_POST['add_host']);
309
		$add_host = trim($_POST['add_host']);
304
		$add_ip   = trim($_POST['add_ip']);
310
		$add_ip   = trim($_POST['add_ip']);
305
		if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
311
		if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
306
			$tab = file(DNS_LOCAL_FILE);
312
			$tab = file(DNS_LOCAL_FILE);
307
			if ($tab) { // the file isn't empty
313
			if ($tab) { // the file isn't empty
308
				$insert = true;
314
				$insert = true;
309
				foreach ($tab as $line) { // verify that host or IP address doesn't exist
315
				foreach ($tab as $line) { // verify that host or IP address doesn't exist
310
					if (preg_match('/^\d+/', $line)) {
316
					if (preg_match('/^\d+/', $line)) {
311
						$field = preg_split("/\s+/",$line);
317
						$field = preg_split("/\s+/",$line);
312
						$ip_addr = $field[0];
318
						$ip_addr = $field[0];
313
						$host_name = trim($field[1]);
319
						$host_name = trim($field[1]);
314
						if (strcasecmp($add_host, $host_name) === 0) {
320
						if (strcasecmp($add_host, $host_name) === 0) {
315
							$insert = false;
321
							$insert = false;
316
							break;
322
							break;
317
						}
323
						}
318
					}
324
					}
319
				}
325
				}
320
				if ($insert) {
326
				if ($insert) {
321
					exec("sudo /usr/local/bin/alcasar-dns-local.sh --add $add_ip $add_host");
327
					exec("sudo /usr/local/bin/alcasar-dns-local.sh --add $add_ip $add_host");
322
				}
328
				}
323
			}
329
			}
324
		}
330
		}
325
		header('Location: '.$_SERVER['PHP_SELF']);
331
		header('Location: '.$_SERVER['PHP_SELF']);
326
		exit();
332
		exit();
327
	case 'del_host':
333
	case 'del_host':
328
		foreach ($_POST as $key => $value) {
334
		foreach ($_POST as $key => $value) {
329
			if ($value == 'on') {
335
			if ($value == 'on') {
330
				$del_host = explode ("|", $key);
336
				$del_host = explode ("|", $key);
331
				$del_ip = str_replace("_",".",$del_host[0]);
337
				$del_ip = str_replace("_",".",$del_host[0]);
332
				exec("sudo /usr/local/bin/alcasar-dns-local.sh --del $del_ip $del_host[1]");
338
				exec("sudo /usr/local/bin/alcasar-dns-local.sh --del $del_ip $del_host[1]");
333
			}
339
			}
334
		}
340
		}
335
		header('Location: '.$_SERVER['PHP_SELF']);
341
		header('Location: '.$_SERVER['PHP_SELF']);
336
		exit();
342
		exit();
337
 
343
 
338
	case 'set_default_cert':
344
	case 'set_default_cert':
339
		exec('sudo alcasar-importcert.sh -d');
345
		exec('sudo alcasar-importcert.sh -d');
340
		break;
346
		break;
341
	case 'set_last_LE_cert':
347
	case 'set_last_LE_cert':
342
		exec('sudo alcasar-letsencrypt.sh --install-cert');
348
		exec('sudo alcasar-letsencrypt.sh --install-cert');
343
		break;
349
		break;
344
	case 'import_cert':	// Import certificate
350
	case 'import_cert':	// Import certificate
345
		$maxsize = 100000;
351
		$maxsize = 100000;
346
		if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) {
352
		if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) {
347
			if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) {
353
			if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) {
348
				if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && ((pathinfo($_FILES['crt']['name'])['extension'] == 'crt') || (pathinfo($_FILES['crt']['name'])['extension'] == 'cer'))) {
354
				if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && ((pathinfo($_FILES['crt']['name'])['extension'] == 'crt') || (pathinfo($_FILES['crt']['name'])['extension'] == 'cer'))) {
349
					$dest = '/tmp/';
355
					$dest = '/tmp/';
350
					$scpath = '';
356
					$scpath = '';
351
					if (isset($_FILES['sc']) && ((pathinfo($_FILES['sc']['name'])['extension'] == 'crt') || (pathinfo($_FILES['sc']['name'])['extension'] == 'cer') || (pathinfo($_FILES['sc']['name']['extension'] == 'pem')))){
357
					if (isset($_FILES['sc']) && ((pathinfo($_FILES['sc']['name'])['extension'] == 'crt') || (pathinfo($_FILES['sc']['name'])['extension'] == 'cer') || (pathinfo($_FILES['sc']['name']['extension'] == 'pem')))){
352
						$scpath = $dest.'server-chain.pem';
358
						$scpath = $dest.'server-chain.pem';
353
						move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
359
						move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
354
					}
360
					}
355
					$keypath = $dest.'alcasar.key';
361
					$keypath = $dest.'alcasar.key';
356
					$crtpath = $dest.'alcasar.crt';
362
					$crtpath = $dest.'alcasar.crt';
357
					move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
363
					move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
358
					move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
364
					move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
359
					exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
365
					exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
360
					if (file_exists($crtpath)) unlink($crtpath);
366
					if (file_exists($crtpath)) unlink($crtpath);
361
					if (file_exists($keypath)) unlink($keypath);
367
					if (file_exists($keypath)) unlink($keypath);
362
					if (file_exists($scpath))  unlink($scpath);
368
					if (file_exists($scpath))  unlink($scpath);
363
				}
369
				}
364
			}
370
			}
365
		}
371
		}
366
		break;
372
		break;
367
	case 'https_login':	// Set HTTPS login status
373
	case 'https_login':	// Set HTTPS login status
368
		if ($_POST['https_login'] === 'on') {
374
		if ($_POST['https_login'] === 'on') {
369
			exec('sudo /usr/local/bin/alcasar-https.sh --on');
375
			exec('sudo /usr/local/bin/alcasar-https.sh --on');
370
		} else {
376
		} else {
371
			exec('sudo /usr/local/bin/alcasar-https.sh --off');
377
			exec('sudo /usr/local/bin/alcasar-https.sh --off');
372
		}
378
		}
373
		header('Location: '.$_SERVER['PHP_SELF']);
379
		header('Location: '.$_SERVER['PHP_SELF']);
374
		exit();
380
		exit();
375
}
381
}
376
 
382
 
377
// Network changes
383
// Network changes
378
if ($choix === 'network_change') {
384
if ($choix === 'network_change') {
379
    exec('sudo /usr/local/bin/alcasar-network.sh --save');
385
    exec('sudo /usr/local/bin/alcasar-network.sh --save');
380
	$modification_network = false;
386
	$modification_network = false;
381
	$modification_dns = false;
387
	$modification_dns = false;
382
	$modification_proxy = false;
388
	$modification_proxy = false;
383
	$ext_conf_error_list = [];
389
	$ext_conf_error_list = [];
384
	copy(CONF_FILE, TEMP_FILE);
390
	copy(CONF_FILE, TEMP_FILE);
385
 
391
 
386
	if (isset($_POST['dns1']) && (trim($_POST['dns1']) !== $conf['DNS1'])) {
392
	if (isset($_POST['dns1']) && (trim($_POST['dns1']) !== $conf['DNS1'])) {
387
	    if (!preg_match($reg_ip, $_POST['dns1'])) {
393
	    if (!preg_match($reg_ip, $_POST['dns1'])) {
388
            $ext_conf_error = true;
394
            $ext_conf_error = true;
389
            $ext_conf_error_list[] = $l_error.': '.$l_ip_dns1.': '.$l_error_bad_ip;
395
            $ext_conf_error_list[] = $l_error.': '.$l_ip_dns1.': '.$l_error_bad_ip;
390
        }
396
        }
391
		file_put_contents(TEMP_FILE, str_replace('DNS1='.$conf['DNS1'], 'DNS1='.trim($_POST['dns1']), file_get_contents(TEMP_FILE)));
397
		file_put_contents(TEMP_FILE, str_replace('DNS1='.$conf['DNS1'], 'DNS1='.trim($_POST['dns1']), file_get_contents(TEMP_FILE)));
392
		$modification_dns = true;
398
		$modification_dns = true;
393
	}
399
	}
394
	if (isset($_POST['dns2']) && (trim($_POST['dns2']) !== $conf['DNS2'])) {
400
	if (isset($_POST['dns2']) && (trim($_POST['dns2']) !== $conf['DNS2'])) {
395
	    if (!preg_match($reg_ip, $_POST['dns2'])) {
401
	    if (!preg_match($reg_ip, $_POST['dns2'])) {
396
            $ext_conf_error = true;
402
            $ext_conf_error = true;
397
            $ext_conf_error_list[] = $l_error.': '.$l_ip_dns2.': '.$l_error_bad_ip;
403
            $ext_conf_error_list[] = $l_error.': '.$l_ip_dns2.': '.$l_error_bad_ip;
398
        }
404
        }
399
		file_put_contents(TEMP_FILE, str_replace('DNS2='.$conf['DNS2'], 'DNS2='.trim($_POST['dns2']), file_get_contents(TEMP_FILE)));
405
		file_put_contents(TEMP_FILE, str_replace('DNS2='.$conf['DNS2'], 'DNS2='.trim($_POST['dns2']), file_get_contents(TEMP_FILE)));
400
		$modification_dns = true;
406
		$modification_dns = true;
401
	}
407
	}
402
    if (isset($_POST['ip_private']) && (trim($_POST['ip_private']) !== $conf['PRIVATE_IP'])) {
408
    if (isset($_POST['ip_private']) && (trim($_POST['ip_private']) !== $conf['PRIVATE_IP'])) {
403
        if (!preg_match($reg_ip_cidr, $_POST['ip_private'])) {
409
        if (!preg_match($reg_ip_cidr, $_POST['ip_private'])) {
404
            $ext_conf_error = true;
410
            $ext_conf_error = true;
405
            $ext_conf_error_list[] = $l_error.': '.$l_ip_address.' LAN: '.$l_error_bad_ip_CIDR;
411
            $ext_conf_error_list[] = $l_error.': '.$l_ip_address.' LAN: '.$l_error_bad_ip_CIDR;
406
        }
412
        }
407
        file_put_contents(TEMP_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'], 'PRIVATE_IP='.trim($_POST['ip_private']), file_get_contents(TEMP_FILE)));
413
        file_put_contents(TEMP_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'], 'PRIVATE_IP='.trim($_POST['ip_private']), file_get_contents(TEMP_FILE)));
408
        $modification_network = true;
414
        $modification_network = true;
409
    }
415
    }
410
	if (isset($_POST['ip_public']) && (trim($_POST['ip_public']) !== $conf['PUBLIC_IP'])) {
416
	if (isset($_POST['ip_public']) && (trim($_POST['ip_public']) !== $conf['PUBLIC_IP'])) {
411
	    if (!preg_match($reg_ip_cidr, $_POST['ip_public'])) {
417
	    if (!preg_match($reg_ip_cidr, $_POST['ip_public'])) {
412
            $ext_conf_error = true;
418
            $ext_conf_error = true;
413
            $ext_conf_error_list[] = $l_error.': '.$l_ip_address.' WAN: '.$l_error_bad_ip_CIDR;
419
            $ext_conf_error_list[] = $l_error.': '.$l_ip_address.' WAN: '.$l_error_bad_ip_CIDR;
414
        }
420
        }
415
		file_put_contents(TEMP_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'], 'PUBLIC_IP='.trim($_POST['ip_public']), file_get_contents(TEMP_FILE)));
421
		file_put_contents(TEMP_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'], 'PUBLIC_IP='.trim($_POST['ip_public']), file_get_contents(TEMP_FILE)));
416
		$modification_network = true;
422
		$modification_network = true;
417
	}
423
	}
418
    if (isset($_POST['ip_gw']) && (trim($_POST['ip_gw']) !== $conf['GW'])) {
424
    if (isset($_POST['ip_gw']) && (trim($_POST['ip_gw']) !== $conf['GW'])) {
419
        if (!preg_match($reg_ip, $_POST['ip_gw'])) {
425
        if (!preg_match($reg_ip, $_POST['ip_gw'])) {
420
            $ext_conf_error = true;
426
            $ext_conf_error = true;
421
            $ext_conf_error_list[] = $l_error.': '.$l_ip_router.' 1: '.$l_error_bad_ip;
427
            $ext_conf_error_list[] = $l_error.': '.$l_ip_router.' 1: '.$l_error_bad_ip;
422
        }
428
        }
423
        file_put_contents(TEMP_FILE, str_replace('GW='.$conf['GW'], 'GW='.trim($_POST['ip_gw']), file_get_contents(TEMP_FILE)));
429
        file_put_contents(TEMP_FILE, str_replace('GW='.$conf['GW'], 'GW='.trim($_POST['ip_gw']), file_get_contents(TEMP_FILE)));
424
        $modification_network = true;
430
        $modification_network = true;
425
    }
431
    }
426
    if (isset($_POST['enable_proxy']) && $_POST['enable_proxy'] == 'P_Enabled')
432
    if (isset($_POST['enable_proxy']) && $_POST['enable_proxy'] == 'P_Enabled')
427
    {
433
    {
428
        if ($conf['PROXY'] !== 'On')
434
        if ($conf['PROXY'] !== 'On')
429
        {
435
        {
430
            file_put_contents(TEMP_FILE, str_replace('PROXY='.$conf['PROXY'], 'PROXY=On', file_get_contents(TEMP_FILE)));
436
            file_put_contents(TEMP_FILE, str_replace('PROXY='.$conf['PROXY'], 'PROXY=On', file_get_contents(TEMP_FILE)));
431
            $modification_proxy = true;
437
            $modification_proxy = true;
432
        }
438
        }
433
        if (isset($_POST['proxy']) && (trim($_POST['proxy']) !== $conf['PROXY_IP'])) {
439
        if (isset($_POST['proxy']) && (trim($_POST['proxy']) !== $conf['PROXY_IP'])) {
434
            if (!preg_match($reg_ip_port, $_POST['proxy'])) {
440
            if (!preg_match($reg_ip_port, $_POST['proxy'])) {
435
                $ext_conf_error = true;
441
                $ext_conf_error = true;
436
                $ext_conf_error_list[] = $l_error.': Proxy: '.$l_error_bad_ip_port;
442
                $ext_conf_error_list[] = $l_error.': Proxy: '.$l_error_bad_ip_port;
437
            }
443
            }
438
            file_put_contents(TEMP_FILE, str_replace('PROXY_IP='.$conf['PROXY_IP'], 'PROXY_IP='.trim($_POST['proxy']), file_get_contents(TEMP_FILE)));
444
            file_put_contents(TEMP_FILE, str_replace('PROXY_IP='.$conf['PROXY_IP'], 'PROXY_IP='.trim($_POST['proxy']), file_get_contents(TEMP_FILE)));
439
            $modification_proxy = true;
445
            $modification_proxy = true;
440
        }
446
        }
441
        if ($conf['MULTIWAN'] !== 'off')
447
        if ($conf['MULTIWAN'] !== 'off')
442
        {
448
        {
443
            file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], 'MULTIWAN=off', file_get_contents(TEMP_FILE)));
449
            file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], 'MULTIWAN=off', file_get_contents(TEMP_FILE)));
444
            $modification_network = true;
450
            $modification_network = true;
445
        }
451
        }
446
    }
452
    }
447
    else
453
    else
448
    {
454
    {
449
        //set multiwan value to off and delete every "WANx=" line
455
        //set multiwan value to off and delete every "WANx=" line
450
        if ($_POST['gw_count'] === "1" && $conf['MULTIWAN'] !== 'off')
456
        if ($_POST['gw_count'] === "1" && $conf['MULTIWAN'] !== 'off')
451
        {
457
        {
452
            file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], 'MULTIWAN=off', file_get_contents(TEMP_FILE)));
458
            file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], 'MULTIWAN=off', file_get_contents(TEMP_FILE)));
453
            $temp = 1;
459
            $temp = 1;
454
            while (isset($conf['WAN'.$temp]))
460
            while (isset($conf['WAN'.$temp]))
455
            {
461
            {
456
                file_put_contents(TEMP_FILE, str_replace('WAN'.$temp.'='.$conf['WAN'.$temp]."\n", '', file_get_contents(TEMP_FILE)));
462
                file_put_contents(TEMP_FILE, str_replace('WAN'.$temp.'='.$conf['WAN'.$temp]."\n", '', file_get_contents(TEMP_FILE)));
457
                $temp++;
463
                $temp++;
458
            }
464
            }
459
            $modification_network = true;
465
            $modification_network = true;
460
        }
466
        }
461
        if ($_POST['gw_count'] !== "1")
467
        if ($_POST['gw_count'] !== "1")
462
        {
468
        {
463
            $changed = false;
469
            $changed = false;
464
            //testing the existence of a change in the routing configuration
470
            //testing the existence of a change in the routing configuration
465
            exec("grep \"^WAN\" " . CONF_FILE . " | wc -l", $nb_gw);
471
            exec("grep \"^WAN\" " . CONF_FILE . " | wc -l", $nb_gw);
466
            if ($_POST['gw_count'] == ($nb_gw[0] + 1))
472
            if ($_POST['gw_count'] == ($nb_gw[0] + 1))
467
            {
473
            {
468
                if ($_POST['weight'] !== $conf['PUBLIC_WEIGHT']) {
474
                if ($_POST['weight'] !== $conf['PUBLIC_WEIGHT']) {
469
                    $changed = true;
475
                    $changed = true;
470
                }
476
                }
471
                else {
477
                else {
472
                    for($i=1;$i<$_POST['gw_count'];$i++)
478
                    for($i=1;$i<$_POST['gw_count'];$i++)
473
                    {
479
                    {
474
                        if( '"'.$_POST['ip_gw_'.$i].','.$_POST['weight_'.$i].'"' != $conf['WAN'.$i])
480
                        if( '"'.$_POST['ip_gw_'.$i].','.$_POST['weight_'.$i].'"' != $conf['WAN'.$i])
475
                        {
481
                        {
476
                            $changed = true;
482
                            $changed = true;
477
                            break;
483
                            break;
478
                        }
484
                        }
479
                    }
485
                    }
480
                }
486
                }
481
            }
487
            }
482
            else
488
            else
483
            {
489
            {
484
                $changed = true;
490
                $changed = true;
485
            }
491
            }
486
 
492
 
487
            if ($changed == true)
493
            if ($changed == true)
488
            {
494
            {
489
                //deleting all the old lines containing "WANx="
495
                //deleting all the old lines containing "WANx="
490
                $temp = 1;
496
                $temp = 1;
491
                while (isset($conf['WAN'.$temp]))
497
                while (isset($conf['WAN'.$temp]))
492
                {
498
                {
493
                    file_put_contents(TEMP_FILE, str_replace('WAN'.$temp.'='.$conf['WAN'.$temp]."\n", '', file_get_contents(TEMP_FILE)));
499
                    file_put_contents(TEMP_FILE, str_replace('WAN'.$temp.'='.$conf['WAN'.$temp]."\n", '', file_get_contents(TEMP_FILE)));
494
                    $temp++;
500
                    $temp++;
495
                }
501
                }
496
                //setting back the line "WAN1=" which will be our base
502
                //setting back the line "WAN1=" which will be our base
497
                if (!preg_match($reg_weight, $_POST['weight'])) {
503
                if (!preg_match($reg_weight, $_POST['weight'])) {
498
                    $ext_conf_error = true;
504
                    $ext_conf_error = true;
499
                    $ext_conf_error_list[] = $l_error.': '.$l_gw_weight.' 1: '.$l_error_weight;
505
                    $ext_conf_error_list[] = $l_error.': '.$l_gw_weight.' 1: '.$l_error_weight;
500
                }
506
                }
501
                file_put_contents(TEMP_FILE, str_replace('PUBLIC_WEIGHT='.$conf['PUBLIC_WEIGHT'], 'PUBLIC_WEIGHT='.(($_POST['weight'] !== '')?$_POST['weight']:1), file_get_contents(TEMP_FILE)));
507
                file_put_contents(TEMP_FILE, str_replace('PUBLIC_WEIGHT='.$conf['PUBLIC_WEIGHT'], 'PUBLIC_WEIGHT='.(($_POST['weight'] !== '')?$_POST['weight']:1), file_get_contents(TEMP_FILE)));
502
                //Set Multiwan status
508
                //Set Multiwan status
503
                file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], "MULTIWAN=on\nWAN1=", file_get_contents(TEMP_FILE)));
509
                file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], "MULTIWAN=on\nWAN1=", file_get_contents(TEMP_FILE)));
504
                //Adding the correct number of "WANx=" lines, numbered
510
                //Adding the correct number of "WANx=" lines, numbered
505
                for($i=2;$i<$_POST['gw_count'];$i++)
511
                for($i=2;$i<$_POST['gw_count'];$i++)
506
                {
512
                {
507
                    file_put_contents(TEMP_FILE, str_replace('WAN'.($i-1).'=', 'WAN'.($i-1)."=\nWAN".$i.'=', file_get_contents(TEMP_FILE)));
513
                    file_put_contents(TEMP_FILE, str_replace('WAN'.($i-1).'=', 'WAN'.($i-1)."=\nWAN".$i.'=', file_get_contents(TEMP_FILE)));
508
                }
514
                }
509
                //Adding the content
515
                //Adding the content
510
                for($i=1;$i<$_POST['gw_count'];$i++)
516
                for($i=1;$i<$_POST['gw_count'];$i++)
511
                {
517
                {
512
                    if (!preg_match($reg_ip, $_POST['ip_gw_'.$i])) {
518
                    if (!preg_match($reg_ip, $_POST['ip_gw_'.$i])) {
513
                        $ext_conf_error = true;
519
                        $ext_conf_error = true;
514
                        $ext_conf_error_list[] = $l_error.': '.$l_ip_router.' '.($i+1).': '.$l_error_bad_ip;
520
                        $ext_conf_error_list[] = $l_error.': '.$l_ip_router.' '.($i+1).': '.$l_error_bad_ip;
515
                    }
521
                    }
516
                    if (!preg_match($reg_weight, $_POST['weight_'.$i])) {
522
                    if (!preg_match($reg_weight, $_POST['weight_'.$i])) {
517
                        $ext_conf_error = true;
523
                        $ext_conf_error = true;
518
                        $ext_conf_error_list[] = $l_error.': '.$l_gw_weight.' '.($i+1).': '.$l_error_weight;
524
                        $ext_conf_error_list[] = $l_error.': '.$l_gw_weight.' '.($i+1).': '.$l_error_weight;
519
                    }
525
                    }
520
                    file_put_contents(TEMP_FILE, str_replace('WAN'.$i.'=', 'WAN'.$i.'="'.$_POST['ip_gw_'.$i].','.(($_POST['weight_'.$i] === "0" || $_POST['weight_'.$i] === "")?"1":$_POST['weight_'.$i]).'"', file_get_contents(TEMP_FILE)));
526
                    file_put_contents(TEMP_FILE, str_replace('WAN'.$i.'=', 'WAN'.$i.'="'.$_POST['ip_gw_'.$i].','.(($_POST['weight_'.$i] === "0" || $_POST['weight_'.$i] === "")?"1":$_POST['weight_'.$i]).'"', file_get_contents(TEMP_FILE)));
521
                }
527
                }
522
                $modification_network = true;
528
                $modification_network = true;
523
            }
529
            }
524
        }
530
        }
525
        //set proxy value to off
531
        //set proxy value to off
526
        if ($conf['PROXY'] !== 'Off')
532
        if ($conf['PROXY'] !== 'Off')
527
        {
533
        {
528
            file_put_contents(TEMP_FILE, str_replace('PROXY='.$conf['PROXY'], 'PROXY=Off', file_get_contents(TEMP_FILE)));
534
            file_put_contents(TEMP_FILE, str_replace('PROXY='.$conf['PROXY'], 'PROXY=Off', file_get_contents(TEMP_FILE)));
529
            if($_POST['gw_count'] !== "1" && $conf['MULTIWAN'] !== 'on') {
535
            if($_POST['gw_count'] !== "1" && $conf['MULTIWAN'] !== 'on') {
530
                file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], 'MULTIWAN=on', file_get_contents(TEMP_FILE)));
536
                file_put_contents(TEMP_FILE, str_replace('MULTIWAN='.$conf['MULTIWAN'], 'MULTIWAN=on', file_get_contents(TEMP_FILE)));
531
                $modification_network = true;
537
                $modification_network = true;
532
            }
538
            }
533
            $modification_proxy = true;
539
            $modification_proxy = true;
534
        }
540
        }
535
    }
541
    }
536
 
542
 
537
    //if no errors are detected
543
    //if no errors are detected
538
    if ($ext_conf_error == false) {
544
    if ($ext_conf_error == false) {
539
        copy(TEMP_FILE, CONF_FILE);
545
        copy(TEMP_FILE, CONF_FILE);
540
        //DNS values modification, several services needs to be reloading, reloads the full server.
546
        //DNS values modification, several services needs to be reloading, reloads the full server.
541
        if ($modification_dns) {
547
        if ($modification_dns) {
542
            exec('sudo /usr/local/bin/alcasar-conf.sh -apply');
548
            exec('sudo /usr/local/bin/alcasar-conf.sh -apply');
543
        }
549
        }
544
        //External network modifications, no service reloading
550
        //External network modifications, no service reloading
545
        if ($modification_network) {
551
        if ($modification_network) {
546
            exec('sudo /usr/local/bin/alcasar-network.sh');
552
            exec('sudo /usr/local/bin/alcasar-network.sh');
547
            exec('sudo /usr/local/bin/alcasar-iptables.sh');
553
            exec('sudo /usr/local/bin/alcasar-iptables.sh');
548
        }
554
        }
549
        //If only the proxy has been modified, only the firewall needs a change
555
        //If only the proxy has been modified, only the firewall needs a change
550
        else if ($modification_proxy) {
556
        else if ($modification_proxy) {
551
            exec('sudo /usr/local/bin/alcasar-iptables.sh');
557
            exec('sudo /usr/local/bin/alcasar-iptables.sh');
552
        }
558
        }
553
    }
559
    }
554
    unlink(TEMP_FILE);
560
    unlink(TEMP_FILE);
555
 
561
 
556
	// Read CONF_FILE updated
562
	// Read CONF_FILE updated
557
	$file_conf = fopen(CONF_FILE, 'r');
563
	$file_conf = fopen(CONF_FILE, 'r');
558
	if (!$file_conf) {
564
	if (!$file_conf) {
559
		exit('Error opening the file '.CONF_FILE);
565
		exit('Error opening the file '.CONF_FILE);
560
	}
566
	}
561
	while (!feof($file_conf)) {
567
	while (!feof($file_conf)) {
562
		$buffer = fgets($file_conf, 4096);
568
		$buffer = fgets($file_conf, 4096);
563
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
569
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
564
			$tmp = explode('=', $buffer, 2);
570
			$tmp = explode('=', $buffer, 2);
565
			$conf[trim($tmp[0])] = trim($tmp[1]);
571
			$conf[trim($tmp[0])] = trim($tmp[1]);
566
		}
572
		}
567
	}
573
	}
568
	fclose($file_conf);
574
	fclose($file_conf);
569
}
575
}
570
 
576
 
571
// Let's Encrypt actions
577
// Let's Encrypt actions
572
if ($choix === 'le_issueCert') {
578
if ($choix === 'le_issueCert') {
573
	// TODO: check ndd & mail format
579
	// TODO: check ndd & mail format
574
	$email      = $_POST['email'];
580
	$email      = $_POST['email'];
575
	$domainName = $_POST['domainname'];
581
	$domainName = $_POST['domainname'];
576
	exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);
582
	exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);
577
	$cmdResponse = implode("<br>\n", $output);
583
	$cmdResponse = implode("<br>\n", $output);
578
}
584
}
579
if ($choix === 'le_renewCert') {
585
if ($choix === 'le_renewCert') {
580
	if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) {
586
	if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) {
581
		$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : '';
587
		$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : '';
582
 
588
 
583
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
589
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
584
 
590
 
585
		$cmdResponse = implode("<br>\n", $output);
591
		$cmdResponse = implode("<br>\n", $output);
586
	} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
592
	} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
587
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
593
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
588
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
594
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
589
	}
595
	}
590
}
596
}
591
 
597
 
592
// Read Let's Encrypt configuration file
598
// Read Let's Encrypt configuration file
593
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
599
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
594
if (!$file_conf_LE) {
600
if (!$file_conf_LE) {
595
	exit('Error opening the file '.LETS_ENCRYPT_FILE);
601
	exit('Error opening the file '.LETS_ENCRYPT_FILE);
596
}
602
}
597
while (!feof($file_conf_LE)) {
603
while (!feof($file_conf_LE)) {
598
	$buffer = fgets($file_conf_LE, 4096);
604
	$buffer = fgets($file_conf_LE, 4096);
599
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
605
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
600
		$tmp = explode('=', $buffer, 2);
606
		$tmp = explode('=', $buffer, 2);
601
		$LE_conf[trim($tmp[0])] = trim($tmp[1]);
607
		$LE_conf[trim($tmp[0])] = trim($tmp[1]);
602
	}
608
	}
603
}
609
}
604
fclose($file_conf_LE);
610
fclose($file_conf_LE);
605
 
611
 
606
// Fonction de test de connectivité internet
612
// Fonction de test de connectivité internet
607
function internetTest() {
613
function internetTest() {
608
	$host = 'www.google.fr'; # Google Test
614
	$host = 'www.google.fr'; # Google Test
609
	$port = '80';
615
	$port = '80';
610
 
616
 
611
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
617
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
612
		return false;
618
		return false;
613
	} else {
619
	} else {
614
		fclose($sock);
620
		fclose($sock);
615
		return true;
621
		return true;
616
	}
622
	}
617
}
623
}
618
 
624
 
619
$internet_connected = InternetTest();
625
$internet_connected = InternetTest();
620
if ($internet_connected) {
626
if ($internet_connected) {
621
	$ch = curl_init('https://api.ipify.org/');
627
	$ch = curl_init('https://api.ipify.org/');
622
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
628
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
623
	$internet_publicIP = curl_exec($ch);
629
	$internet_publicIP = curl_exec($ch);
624
	curl_close($ch);
630
	curl_close($ch);
625
} else {
631
} else {
626
	$internet_publicIP = '-.-.-.-';
632
	$internet_publicIP = '-.-.-.-';
627
}
633
}
628
 
634
 
629
// Network interfaces, will be use later for multiple LAN interfaces
635
// Network interfaces, will be use later for multiple LAN interfaces
630
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['INTIF']];
636
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['INTIF']];
631
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable);
637
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable);
632
 
638
 
633
//retreive gateway(s) parameters
639
//retreive gateway(s) parameters
634
$gateways = [
640
$gateways = [
635
	(object) [
641
	(object) [
636
		'gateway'   => $conf['GW'],
642
		'gateway'   => $conf['GW'],
637
        'weight'    => $conf['PUBLIC_WEIGHT']
643
        'weight'    => $conf['PUBLIC_WEIGHT']
638
	]
644
	]
639
];
645
];
640
exec("grep \"^WAN\" " . CONF_FILE . " | wc -l", $nbIfaces);
646
exec("grep \"^WAN\" " . CONF_FILE . " | wc -l", $nbIfaces);
641
if ($nbIfaces > 0)
647
if ($nbIfaces > 0)
642
{
648
{
643
    for ($i = 1; $i <= $nbIfaces[0]; $i++) {
649
    for ($i = 1; $i <= $nbIfaces[0]; $i++) {
644
        exec("grep \"WAN" . $i . "=\" " . CONF_FILE . " | awk -F'\"' '{ print $2 }' | awk -F, '{ print $1 }'", $temp_gw);
650
        exec("grep \"WAN" . $i . "=\" " . CONF_FILE . " | awk -F'\"' '{ print $2 }' | awk -F, '{ print $1 }'", $temp_gw);
645
        exec("grep \"WAN" . $i . "=\" " . CONF_FILE . " | awk -F'\"' '{ print $2 }' | awk -F, '{ print $2 }'", $temp_weight);
651
        exec("grep \"WAN" . $i . "=\" " . CONF_FILE . " | awk -F'\"' '{ print $2 }' | awk -F, '{ print $2 }'", $temp_weight);
646
        $gateways[] = (object) [
652
        $gateways[] = (object) [
647
            'gateway'   => $temp_gw[0],
653
            'gateway'   => $temp_gw[0],
648
            'weight'    => $temp_weight[0]
654
            'weight'    => $temp_weight[0]
649
        ];
655
        ];
650
        $temp_gw = "";
656
        $temp_gw = "";
651
        $temp_weight = "";
657
        $temp_weight = "";
652
    }
658
    }
653
}
659
}
654
 
660
 
655
//retreive internal networks parameters
661
//retreive internal networks parameters
656
$internalNetworks = [
662
$internalNetworks = [
657
	(object) [
663
	(object) [
658
		'interface' => $conf['INTIF'],
664
		'interface' => $conf['INTIF'],
659
		'ip'        => $conf['PRIVATE_IP']
665
		'ip'        => $conf['PRIVATE_IP']
660
	]
666
	]
661
];
667
];
662
 
668
 
663
?>
669
?>
664
<!DOCTYPE HTML>
670
<!DOCTYPE HTML>
665
<html>
671
<html>
666
<head>
672
<head>
667
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
673
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
668
	<title><?= $l_network_title ?></title>
674
	<title><?= $l_network_title ?></title>
669
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
675
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
670
	<script src="/js/jquery.min.js"></script>
676
	<script src="/js/jquery.min.js"></script>
671
	<script src="/js/jquery.connections.js"></script>
677
	<script src="/js/jquery.connections.js"></script>
672
	<script type="text/javascript">
678
	<script type="text/javascript">
673
	function MAC_Control(formulaire){
679
	function MAC_Control(formulaire){
674
		// MAC control (upper case and '-' separator)
680
		// MAC control (upper case and '-' separator)
675
		var regex_mac = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/;
681
		var regex_mac = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/;
676
		if (regex_mac.test(document.forms[formulaire].add_mac.value)){
682
		if (regex_mac.test(document.forms[formulaire].add_mac.value)){
677
			document.forms[formulaire].add_mac.value = document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
683
			document.forms[formulaire].add_mac.value = document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
678
			return true;
684
			return true;
679
		} else {
685
		} else {
680
			alert('Invalid MAC address');
686
			alert('Invalid MAC address');
681
			return false;
687
			return false;
682
		}
688
		}
683
	}
689
	}
684
	</script>
690
	</script>
685
	<style>
691
	<style>
686
		.network-configurator {
692
		.network-configurator {
687
			width: 100%;
693
			width: 100%;
688
		}
694
		}
689
		.network-configurator > * {
695
		.network-configurator > * {
690
			display: inline-block;
696
			display: inline-block;
691
			vertical-align: top;
697
			vertical-align: top;
692
			text-align: center;
698
			text-align: center;
693
		}
699
		}
694
		.network-configurator > .internet, .network-configurator > .alcasar {
700
		.network-configurator > .internet, .network-configurator > .alcasar {
695
			width: 20%;
701
			width: 20%;
696
		}
702
		}
697
		.network-configurator > .externals, .network-configurator > .internals {
703
		.network-configurator > .externals, .network-configurator > .internals {
698
			width: 30%;
704
			width: 30%;
699
		}
705
		}
700
		.network-configurator .actions {
706
		.network-configurator .actions {
701
            position: absolute;
707
            position: absolute;
702
			background-color: #ddd;
708
			background-color: #ddd;
703
			padding: 0 2px;
709
			padding: 0 2px;
704
		}
710
		}
705
		.network-configurator .actions a {
711
		.network-configurator .actions a {
706
			text-decoration: none;
712
			text-decoration: none;
707
		}
713
		}
708
		.network-configurator .actions a:hover {
714
		.network-configurator .actions a:hover {
709
			font-weight: bold;
715
			font-weight: bold;
710
		}
716
		}
711
		.network-configurator .actions-externals {
717
		.network-configurator .actions-externals {
712
			right: 0;
718
			right: 0;
713
			border-radius: 5px;
719
			border-radius: 5px;
714
            position: relative;
720
            position: relative;
715
            text-decoration: none;
721
            text-decoration: none;
716
		}
722
		}
717
		.network-configurator > .alcasar .actions-internals {
723
		.network-configurator > .alcasar .actions-internals {
718
			bottom: 0;
724
			bottom: 0;
719
			right: 0;
725
			right: 0;
720
			border-radius: 5px 0;
726
			border-radius: 5px 0;
721
		}
727
		}
722
		.network-configurator .actions-network {
728
		.network-configurator .actions-network {
723
			right: 0;
729
			right: 0;
724
			border-radius: 5px;
730
			border-radius: 5px;
725
            position: relative;
731
            position: relative;
726
            text-decoration: none;
732
            text-decoration: none;
727
		}
733
		}
728
		.network-configurator .network-box {
734
		.network-configurator .network-box {
729
			display: inline-block;
735
			display: inline-block;
730
			min-height: 100px;
736
			min-height: 100px;
731
			margin: 5px;
737
			margin: 5px;
732
			padding: 3px;
738
			padding: 3px;
733
			text-align: left;
739
			text-align: left;
734
			background-color: #f7f3ef;
740
			background-color: #f7f3ef;
735
			position: relative;
741
			position: relative;
736
			border-radius: 5px;
742
			border-radius: 5px;
737
			border: 2px solid grey;
743
			border: 2px solid grey;
738
		}
744
		}
739
		.network-configurator .network-connector {
745
		.network-configurator .network-connector {
740
			display: inline-block;
746
			display: inline-block;
741
			position: absolute;
747
			position: absolute;
742
			top: 50%;
748
			top: 50%;
743
			margin-top: -5px;
749
			margin-top: -5px;
744
			margin-left: -5px;
750
			margin-left: -5px;
745
			width: 10px;
751
			width: 10px;
746
			height: 10px;
752
			height: 10px;
747
			border-radius: 5px;
753
			border-radius: 5px;
748
			background-color: black;
754
			background-color: black;
749
		}
755
		}
750
		.network-configurator .network-connector[data-connector-direction="left"] {
756
		.network-configurator .network-connector[data-connector-direction="left"] {
751
			border-radius: 5px 0 0 5px;
757
			border-radius: 5px 0 0 5px;
752
		}
758
		}
753
		.network-configurator .network-connector[data-connector-direction="right"] {
759
		.network-configurator .network-connector[data-connector-direction="right"] {
754
			border-radius: 0 5px 5px 0;
760
			border-radius: 0 5px 5px 0;
755
		}
761
		}
756
		.network-configurator div[data-network-type] {
762
		.network-configurator div[data-network-type] {
757
			position: relative;
763
			position: relative;
758
		}
764
		}
759
	</style>
765
	</style>
760
	<script>
766
	<script>
761
	$(document).ready(function () {
767
	$(document).ready(function () {
762
 
768
 
763
        setTimeout(function(){$("#change_success").fadeOut('normal');}, 10000);
769
        setTimeout(function(){$("#change_success").fadeOut('normal');}, 10000);
764
 
770
 
765
	    //Will be used later for multiple LAN interfaces
771
	    //Will be used later for multiple LAN interfaces
766
		let interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>;
772
		let interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>;
767
		const wireStyles = { available: { border: '5px double green' } };
773
		const wireStyles = { available: { border: '5px double green' } };
768
 
774
 
769
		// Add gateway
775
		// Add gateway
770
		$('.network-configurator').on('click', '.add-external-network', function (event) {
776
		$('.network-configurator').on('click', '.add-external-network', function (event) {
771
			event.preventDefault();
777
			event.preventDefault();
772
			ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
778
			ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
773
			$('.network-configurator .externals .network-box #ext_gateways').append(' \
779
			$('.network-configurator .externals .network-box #ext_gateways').append(' \
774
			            <div id="ip_routeur_' + ifaces_count + '" data-info_type="gateway" data-number="'+ ifaces_count +'">\
780
			            <div id="ip_routeur_' + ifaces_count + '" data-info_type="gateway" data-number="'+ ifaces_count +'">\
775
                        <label for="ext_gateway_' + ifaces_count + '"><?= $l_ip_router.' ' ?></label><span class="gw_number">'+ (ifaces_count + 1) +'</span> <input style="width:100px" type="text" name="ip_gw_' + ifaces_count + '" id="ext_gateway_' + ifaces_count + '" value="" /> \
781
                        <label for="ext_gateway_' + ifaces_count + '"><?= $l_ip_router.' ' ?></label><span class="gw_number">'+ (ifaces_count + 1) +'</span> <input style="width:100px" type="text" name="ip_gw_' + ifaces_count + '" id="ext_gateway_' + ifaces_count + '" value="" /> \
776
                        <label for="ext_weight_'+ ifaces_count +'"><?= $l_gw_weight ?></label> <input style="width:20px" type="text" name="weight_' + ifaces_count + '" id="ext_weight_'+ ifaces_count +'" value="0"/> \
782
                        <label for="ext_weight_'+ ifaces_count +'"><?= $l_gw_weight ?></label> <input style="width:20px" type="text" name="weight_' + ifaces_count + '" id="ext_weight_'+ ifaces_count +'" value="0"/> \
777
                        <div class="actions actions-network" style="display:inline-block; width:11px"><a href="#" style="display:block; text-align:center" class="remove-network" title="Supprimer ce réseau">-</a></div><br></div> ');
783
                        <div class="actions actions-network" style="display:inline-block; width:11px"><a href="#" style="display:block; text-align:center" class="remove-network" title="Supprimer ce réseau">-</a></div><br></div> ');
778
            ifaces_count++;
784
            ifaces_count++;
779
            document.getElementById("gw_count").setAttribute('value', ifaces_count);
785
            document.getElementById("gw_count").setAttribute('value', ifaces_count);
780
            updateGatewayView();
786
            updateGatewayView();
781
            $('div.network-connector[data-connector-network]').connections('update');
787
            $('div.network-connector[data-connector-network]').connections('update');
782
		});
788
		});
783
 
789
 
784
		// Add internal network
790
		// Add internal network
785
		$('.network-configurator').on('click', '.add-internal-network', function (event) {
791
		$('.network-configurator').on('click', '.add-internal-network', function (event) {
786
			event.preventDefault();
792
			event.preventDefault();
787
			$('.network-configurator .internals').append(' \
793
			$('.network-configurator .internals').append(' \
788
					<div data-network-type="internal"> \
794
					<div data-network-type="internal"> \
789
						<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div> \
795
						<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div> \
790
						<div class="network-box"> \
796
						<div class="network-box"> \
791
							<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
797
							<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
792
							<label for="int_interface_X"><?= 'Interface' ?></label> <select name="interface" id="int_interface_X" disabled><option value=""></option></select><br> \
798
							<label for="int_interface_X"><?= 'Interface' ?></label> <select name="interface" id="int_interface_X" disabled><option value=""></option></select><br> \
793
							<label for="int_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_X" value="" /><br> \
799
							<label for="int_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_X" value="" /><br> \
794
						</div> \
800
						</div> \
795
					</div>');
801
					</div>');
796
			addWire($('div[data-network-type="internal"]:last'));
802
			addWire($('div[data-network-type="internal"]:last'));
797
		});
803
		});
798
 
804
 
799
		// Remove gateway
805
		// Remove gateway
800
		$('.network-box').on('click', '.remove-network', function (event) {
806
		$('.network-box').on('click', '.remove-network', function (event) {
801
			event.preventDefault();
807
			event.preventDefault();
802
			$(this).parent().parent().fadeOut(200, function() {
808
			$(this).parent().parent().fadeOut(200, function() {
803
 
809
 
804
			    $(this).remove();
810
			    $(this).remove();
805
				//update network numbers
811
				//update network numbers
806
                $('div[data-info_type="gateway"]').each(function (index, value) {
812
                $('div[data-info_type="gateway"]').each(function (index, value) {
807
                    updateGatewayNumbers($(this), index);
813
                    updateGatewayNumbers($(this), index);
808
                });
814
                });
809
                ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
815
                ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
810
                document.getElementById("gw_count").setAttribute('value', (ifaces_count - 1));
816
                document.getElementById("gw_count").setAttribute('value', (ifaces_count - 1));
811
                updateGatewayView();
817
                updateGatewayView();
812
 
818
 
813
                $('div.network-connector[data-connector-network]').connections('update');
819
                $('div.network-connector[data-connector-network]').connections('update');
814
			});
820
			});
815
		});
821
		});
816
 
822
 
817
		//proxy enabled or disabled
823
		//proxy enabled or disabled
818
		$('.network-configurator').on('click', '.enable_proxy', function(event){
824
		$('.network-configurator').on('click', '.enable_proxy', function(event){
819
		    if ($(this).is(':checked'))
825
		    if ($(this).is(':checked'))
820
            {
826
            {
821
                document.getElementById("add_external").setAttribute('hidden', 'true');
827
                document.getElementById("add_external").setAttribute('hidden', 'true');
822
                document.getElementById("ext_proxy").removeAttribute('disabled');
828
                document.getElementById("ext_proxy").removeAttribute('disabled');
823
                $('div[id="ip_routeur_0"]').children('span').html('');
829
                $('div[id="ip_routeur_0"]').children('span').html('');
824
                $('div[data-info_type="gateway"]').each(function(index, value) {
830
                $('div[data-info_type="gateway"]').each(function(index, value) {
825
                    if ($(this).attr('data-number') !== "0")
831
                    if ($(this).attr('data-number') !== "0")
826
                    {
832
                    {
827
                        $(this).attr('hidden', 'true');
833
                        $(this).attr('hidden', 'true');
828
                    }
834
                    }
829
                    else
835
                    else
830
                    {
836
                    {
831
                        $(this).children('input[id="ext_weight_0"]').attr('hidden', 'true');
837
                        $(this).children('input[id="ext_weight_0"]').attr('hidden', 'true');
832
                        $(this).children('label[for="ext_weight_0"]').attr('hidden', 'true');
838
                        $(this).children('label[for="ext_weight_0"]').attr('hidden', 'true');
833
                        $(this).children('div[class="actions actions-network"]').css('display', 'none');
839
                        $(this).children('div[class="actions actions-network"]').css('display', 'none');
834
                    }
840
                    }
835
                });
841
                });
836
            }
842
            }
837
            else
843
            else
838
            {
844
            {
839
                document.getElementById("add_external").removeAttribute('hidden');
845
                document.getElementById("add_external").removeAttribute('hidden');
840
                document.getElementById("ext_proxy").setAttribute('disabled', 'true');
846
                document.getElementById("ext_proxy").setAttribute('disabled', 'true');
841
                $('div[id="ip_routeur_0"]').children('span').html('1');
847
                $('div[id="ip_routeur_0"]').children('span').html('1');
842
                $('div[data-info_type="gateway"]').each(function(index, value) {
848
                $('div[data-info_type="gateway"]').each(function(index, value) {
843
                    if ($(this).attr('data-number') !== "0")
849
                    if ($(this).attr('data-number') !== "0")
844
                    {
850
                    {
845
                        $(this).removeAttr('hidden');
851
                        $(this).removeAttr('hidden');
846
                    }
852
                    }
847
                    else
853
                    else
848
                    {
854
                    {
849
                        $(this).children('input[id="ext_weight_0"]').removeAttr('hidden');
855
                        $(this).children('input[id="ext_weight_0"]').removeAttr('hidden');
850
                        $(this).children('label[for="ext_weight_0"]').removeAttr('hidden');
856
                        $(this).children('label[for="ext_weight_0"]').removeAttr('hidden');
851
                        $(this).children('div[class="actions actions-network"]').css('display', 'inline-block');
857
                        $(this).children('div[class="actions actions-network"]').css('display', 'inline-block');
852
                    }
858
                    }
853
                });
859
                });
854
                updateGatewayView();
860
                updateGatewayView();
855
            }
861
            }
856
            $('div.network-connector[data-connector-network]').connections('update');
862
            $('div.network-connector[data-connector-network]').connections('update');
857
        });
863
        });
858
 
864
 
859
		//Add a wire between two connectors
865
		//Add a wire between two connectors
860
		const addWire = function (network) {
866
		const addWire = function (network) {
861
			const networkType = network.data('networkType');
867
			const networkType = network.data('networkType');
862
			if (networkType === 'external') {
868
			if (networkType === 'external') {
863
                $().connections({ from: 'div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]', to: network.children('div.network-connector[data-connector-network="internet"]'), css: wireStyles.available, within: network });
869
                $().connections({ from: 'div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]', to: network.children('div.network-connector[data-connector-network="internet"]'), css: wireStyles.available, within: network });
864
                $().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]', to: network.children('div.network-connector[data-connector-network="external"]'), css: wireStyles.available, within: network });
870
                $().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]', to: network.children('div.network-connector[data-connector-network="external"]'), css: wireStyles.available, within: network });
865
            } else if (networkType === 'internal') {
871
            } else if (networkType === 'internal') {
866
				$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]', to: network.children('div.network-connector[data-connector-network="internal"]'), css: wireStyles.available, within: network });
872
				$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]', to: network.children('div.network-connector[data-connector-network="internal"]'), css: wireStyles.available, within: network });
867
			}
873
			}
868
		};
874
		};
869
 
875
 
870
		//reindex the gateway numbers when a gateway is deleted
876
		//reindex the gateway numbers when a gateway is deleted
871
		const updateGatewayNumbers = function(gateway, number) {
877
		const updateGatewayNumbers = function(gateway, number) {
872
		    old_number = gateway.attr('data-number');
878
		    old_number = gateway.attr('data-number');
873
            gateway.attr('data-number', number);
879
            gateway.attr('data-number', number);
874
            gateway.attr('id', 'ip_routeur_'+number);
880
            gateway.attr('id', 'ip_routeur_'+number);
875
            if (number === 0)
881
            if (number === 0)
876
            {
882
            {
877
                gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('name', 'ip_gw');
883
                gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('name', 'ip_gw');
878
                gateway.children('input[id="ext_weight_'+old_number+'"]').attr('name', 'weight');
884
                gateway.children('input[id="ext_weight_'+old_number+'"]').attr('name', 'weight');
879
            }
885
            }
880
            else
886
            else
881
            {
887
            {
882
                gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('name', 'ip_gw_'+number);
888
                gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('name', 'ip_gw_'+number);
883
                gateway.children('input[id="ext_weight_'+old_number+'"]').attr('name', 'weight_'+number);
889
                gateway.children('input[id="ext_weight_'+old_number+'"]').attr('name', 'weight_'+number);
884
            }
890
            }
885
            gateway.children('label[for="ext_gateway_'+old_number+'"]').attr('for', 'ext_gateway_'+number);
891
            gateway.children('label[for="ext_gateway_'+old_number+'"]').attr('for', 'ext_gateway_'+number);
886
            gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('id', 'ext_gateway_'+number);
892
            gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('id', 'ext_gateway_'+number);
887
            gateway.children('label[for="ext_weight_'+old_number+'"]').attr('for', 'ext_weight_'+number);
893
            gateway.children('label[for="ext_weight_'+old_number+'"]').attr('for', 'ext_weight_'+number);
888
            gateway.children('input[id="ext_weight_'+old_number+'"]').attr('id', 'ext_weight_'+number);
894
            gateway.children('input[id="ext_weight_'+old_number+'"]').attr('id', 'ext_weight_'+number);
889
            gateway.children('span[class="gw_number"]').html((number+1)+' ');
895
            gateway.children('span[class="gw_number"]').html((number+1)+' ');
890
 
896
 
891
        };
897
        };
892
 
898
 
893
		//hide the delete button and the weight field when there is only one gateway (or when there is a proxy)
899
		//hide the delete button and the weight field when there is only one gateway (or when there is a proxy)
894
		const updateGatewayView = function() {
900
		const updateGatewayView = function() {
895
            ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
901
            ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
896
            if (ifaces_count === 1)
902
            if (ifaces_count === 1)
897
            {
903
            {
898
                $('div#ip_routeur_0').children('input[id="ext_weight_0"]').attr('hidden', 'true');
904
                $('div#ip_routeur_0').children('input[id="ext_weight_0"]').attr('hidden', 'true');
899
                $('div#ip_routeur_0').children('label[for="ext_weight_0"]').attr('hidden', 'true');
905
                $('div#ip_routeur_0').children('label[for="ext_weight_0"]').attr('hidden', 'true');
900
                $('div#ip_routeur_0').children('div[class="actions actions-network"]').css('display', 'none');
906
                $('div#ip_routeur_0').children('div[class="actions actions-network"]').css('display', 'none');
901
            }
907
            }
902
            else
908
            else
903
            {
909
            {
904
                $('div#ip_routeur_0').children('input[id="ext_weight_0"]').removeAttr('hidden');
910
                $('div#ip_routeur_0').children('input[id="ext_weight_0"]').removeAttr('hidden');
905
                $('div#ip_routeur_0').children('label[for="ext_weight_0"]').removeAttr('hidden');
911
                $('div#ip_routeur_0').children('label[for="ext_weight_0"]').removeAttr('hidden');
906
                $('div#ip_routeur_0').children('div[class="actions actions-network"]').css('display', 'inline-block');
912
                $('div#ip_routeur_0').children('div[class="actions actions-network"]').css('display', 'inline-block');
907
            }
913
            }
908
        };
914
        };
909
 
915
 
910
		//resize the connections to fit the window
916
		//resize the connections to fit the window
911
		window.addEventListener('resize', function () {
917
		window.addEventListener('resize', function () {
912
			$('div.network-connector[data-connector-network]').connections('update');
918
			$('div.network-connector[data-connector-network]').connections('update');
913
		});
919
		});
914
 
920
 
915
		// Add wires to existing networks at page first render
921
		// Add wires to existing networks at page first render
916
		$('div[data-network-type="external"]').add('div[data-network-type="internal"]').each(function (index, element) {
922
		$('div[data-network-type="external"]').add('div[data-network-type="internal"]').each(function (index, element) {
917
			addWire($(this));
923
			addWire($(this));
918
		});
924
		});
919
	});
925
	});
920
	</script>
926
	</script>
921
</head>
927
</head>
922
<body>
928
<body>
923
<div id="ldoverlay" class="overlay">
929
<div id="ldoverlay" class="overlay">
924
	<div class="lds-spinner" id="spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
930
	<div class="lds-spinner" id="spinner"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div>
925
</div>
931
</div>
926
<div class="panel">
932
<div class="panel">
927
	<div class="panel-header"><?= $l_network_title ?></div>
933
	<div class="panel-header"><?= $l_network_title ?></div>
928
	<div class="panel-row">
934
	<div class="panel-row">
929
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
935
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
930
			<div class="network-configurator">
936
			<div class="network-configurator">
931
				<div class="internet">
937
				<div class="internet">
932
					<div data-network-type="internet">
938
					<div data-network-type="internet">
933
						<div class="network-box">
939
						<div class="network-box">
934
							<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br>
940
							<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br>
935
							<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
941
							<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
936
							<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
942
							<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
937
							<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
943
							<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
938
						</div>
944
						</div>
939
						<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div>
945
						<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div>
940
					</div>
946
					</div>
941
				</div><div id="externals_id" class="externals">
947
				</div><div id="externals_id" class="externals">
942
						<div data-network-type="external">
948
						<div data-network-type="external">
943
							<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div>
949
							<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div>
944
							<div class="network-box">
950
							<div class="network-box">
945
								<label for="ext_interface">Interface</label> <input name="ext_interface" id="ext_interface" value="<?= $conf['EXTIF'] ?>" disabled="disabled"/><br>
951
								<label for="ext_interface">Interface</label> <input name="ext_interface" id="ext_interface" value="<?= $conf['EXTIF'] ?>" disabled="disabled"/><br>
946
								<label for="ext_ip"><?= $l_ip_address ?></label> <input style="width:130px" type="text" name="ip_public" id="ext_ip" value="<?= $conf['PUBLIC_IP'] ?>" /><br>
952
								<label for="ext_ip"><?= $l_ip_address ?></label> <input style="width:130px" type="text" name="ip_public" id="ext_ip" value="<?= $conf['PUBLIC_IP'] ?>" /><br>
947
                                <input class="enable_proxy" type="checkbox" name="enable_proxy" value="P_Enabled" <?php if($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On') { echo 'checked'; }?>/>
953
                                <input class="enable_proxy" type="checkbox" name="enable_proxy" value="P_Enabled" <?php if($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On') { echo 'checked'; }?>/>
948
                                <label for="proxy">Proxy</label> <input style="width:140px" type="text" name="proxy" id="ext_proxy" value=<?= $conf['PROXY_IP']?> <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? '' : 'disabled'?>/><br>
954
                                <label for="proxy">Proxy</label> <input style="width:140px" type="text" name="proxy" id="ext_proxy" value=<?= $conf['PROXY_IP']?> <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? '' : 'disabled'?>/><br>
949
                                <div id="ext_gateways" >
955
                                <div id="ext_gateways" >
950
                                    <input type="text" name="gw_count" id="gw_count" value="<?=count($gateways)?>" hidden="hidden"/>
956
                                    <input type="text" name="gw_count" id="gw_count" value="<?=count($gateways)?>" hidden="hidden"/>
951
                                    <?php foreach ($gateways as $index => $network):
957
                                    <?php foreach ($gateways as $index => $network):
952
                                        if ($index == 0) {?>
958
                                        if ($index == 0) {?>
953
                                            <div id="ip_routeur_<?= $index ?>" data-info_type="gateway" data-number="<?= $index ?>">
959
                                            <div id="ip_routeur_<?= $index ?>" data-info_type="gateway" data-number="<?= $index ?>">
954
                                                <label for="ext_gateway_<?= $index ?>"><?= $l_ip_router.' ' ?></label>
960
                                                <label for="ext_gateway_<?= $index ?>"><?= $l_ip_router.' ' ?></label>
955
                                                <span class="gw_number"><?= ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')?'':($index+1) ?> </span>
961
                                                <span class="gw_number"><?= ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')?'':($index+1) ?> </span>
956
                                                <input style="width:100px" type="text" name="ip_gw" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>" />
962
                                                <input style="width:100px" type="text" name="ip_gw" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>" />
957
                                                <label for="ext_weight_<?= $index ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On'|| $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'hidden' : '' ?>><?= $l_gw_weight ?></label>
963
                                                <label for="ext_weight_<?= $index ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On'|| $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'hidden' : '' ?>><?= $l_gw_weight ?></label>
958
                                                <input style="width:20px" type="text" name="weight" id="ext_weight_<?= $index ?>" value="<?= $network->weight ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On' || $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'hidden' : '' ?>/>
964
                                                <input style="width:20px" type="text" name="weight" id="ext_weight_<?= $index ?>" value="<?= $network->weight ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On' || $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'hidden' : '' ?>/>
959
                                                <div class="actions actions-network" style="display: <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On'|| $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'none' : 'inline-block' ?>; width:11px">
965
                                                <div class="actions actions-network" style="display: <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On'|| $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'none' : 'inline-block' ?>; width:11px">
960
                                                    <a style="display:block; text-align:center" href="#" class="remove-network" title="Supprimer ce réseau">-</a>
966
                                                    <a style="display:block; text-align:center" href="#" class="remove-network" title="Supprimer ce réseau">-</a>
961
                                                </div><br>
967
                                                </div><br>
962
                                            </div>
968
                                            </div>
963
                                        <?php } else {?>
969
                                        <?php } else {?>
964
                                            <div id="ip_routeur_<?= $index ?>" data-info_type="gateway" data-number="<?= $index ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? 'hidden' : '' ?>>
970
                                            <div id="ip_routeur_<?= $index ?>" data-info_type="gateway" data-number="<?= $index ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? 'hidden' : '' ?>>
965
                                                <label for="ext_gateway_<?= $index ?>"><?= $l_ip_router.' ' ?></label>
971
                                                <label for="ext_gateway_<?= $index ?>"><?= $l_ip_router.' ' ?></label>
966
                                                <span class="gw_number"><?= ($index+1) ?> </span>
972
                                                <span class="gw_number"><?= ($index+1) ?> </span>
967
                                                <input style="width:100px" type="text" name="ip_gw_<?= $index ?>" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>"/>
973
                                                <input style="width:100px" type="text" name="ip_gw_<?= $index ?>" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>"/>
968
                                                <label for="ext_weight_<?= $index ?>"><?= $l_gw_weight ?></label>
974
                                                <label for="ext_weight_<?= $index ?>"><?= $l_gw_weight ?></label>
969
                                                <input style="width:20px" type="text" name="weight_<?= $index ?>" id="ext_weight_<?= $index ?>" value="<?= $network->weight ?>"/>
975
                                                <input style="width:20px" type="text" name="weight_<?= $index ?>" id="ext_weight_<?= $index ?>" value="<?= $network->weight ?>"/>
970
                                                <div class="actions actions-network" style="display:inline-block; width:11px">
976
                                                <div class="actions actions-network" style="display:inline-block; width:11px">
971
                                                    <a style="display:block; text-align:center" href="#" class="remove-network" title="Supprimer ce réseau">-</a>
977
                                                    <a style="display:block; text-align:center" href="#" class="remove-network" title="Supprimer ce réseau">-</a>
972
                                                </div><br>
978
                                                </div><br>
973
                                            </div>
979
                                            </div>
974
                                    <?php } endforeach; ?>
980
                                    <?php } endforeach; ?>
975
                                </div>
981
                                </div>
976
                                <div class="actions actions-externals" style="margin: 0 auto; width:11px"><a id="add_external" href="#" class="add-external-network" title="Ajouter un réseau externe" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? 'hidden' : '' ?>>+</a></div>
982
                                <div class="actions actions-externals" style="margin: 0 auto; width:11px"><a id="add_external" href="#" class="add-external-network" title="Ajouter un réseau externe" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? 'hidden' : '' ?>>+</a></div>
977
                            </div>
983
                            </div>
978
							<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div>
984
							<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div>
979
						</div>
985
						</div>
980
				</div><div class="alcasar">
986
				</div><div class="alcasar">
981
					<div data-network-type="alcasar">
987
					<div data-network-type="alcasar">
982
						<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div>
988
						<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div>
983
						<div class="network-box">
989
						<div class="network-box">
984
							<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div>
990
							<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div>
985
							<!-- <div class="actions actions-internals">
991
							<!-- <div class="actions actions-internals">
986
								<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div>
992
								<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div>
987
								<div><a href="#" class="add-internal-wifi-network">++</a></div>
993
								<div><a href="#" class="add-internal-wifi-network">++</a></div>
988
							</div> -->
994
							</div> -->
989
						</div>
995
						</div>
990
						<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div>
996
						<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div>
991
					</div>
997
					</div>
992
				</div><div id="internals_id" class="internals" data-count="1">
998
				</div><div id="internals_id" class="internals" data-count="1">
993
					<?php foreach ($internalNetworks as $network): ?>
999
					<?php foreach ($internalNetworks as $network): ?>
994
						<div data-network-type="internal">
1000
						<div data-network-type="internal">
995
							<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div>
1001
							<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div>
996
							<div class="network-box">
1002
							<div class="network-box">
997
								<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
1003
								<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
998
								<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>
1004
								<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>
999
								<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>
1005
								<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>
1000
							</div>
1006
							</div>
1001
						</div>
1007
						</div>
1002
					<? endforeach; ?>
1008
					<? endforeach; ?>
1003
				</div>
1009
				</div>
1004
			</div>
1010
			</div>
1005
            <?php if ($ext_conf_error == true) {
1011
            <?php if ($ext_conf_error == true) {
1006
                echo '<span style="color:red">';
1012
                echo '<span style="color:red">';
1007
                $temp = 0;
1013
                $temp = 0;
1008
                while (isset($ext_conf_error_list[$temp])) {
1014
                while (isset($ext_conf_error_list[$temp])) {
1009
                    echo $ext_conf_error_list[$temp].'<br>';
1015
                    echo $ext_conf_error_list[$temp].'<br>';
1010
                    $temp++;
1016
                    $temp++;
1011
                }
1017
                }
1012
                echo '</span>';
1018
                echo '</span>';
1013
            }
1019
            }
1014
            else if (($choix === 'network_change') && ($modification_proxy || $modification_dns || $modification_network)) {
1020
            else if (($choix === 'network_change') && ($modification_proxy || $modification_dns || $modification_network)) {
1015
                echo '<span id="change_success" style="color:green">'.$l_change_successful.'</span>';
1021
                echo '<span id="change_success" style="color:green">'.$l_change_successful.'</span>';
1016
            }?>
1022
            }?>
1017
			<hr>
1023
			<hr>
1018
			<div style="text-align: center; margin: 5px">
1024
			<div style="text-align: center; margin: 5px">
1019
				<input type="hidden" name="choix" value="network_change">
1025
				<input type="hidden" name="choix" value="network_change">
1020
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>">
1026
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>">
1021
			</div>
1027
			</div>
1022
		</form>
1028
		</form>
1023
	</div>
1029
	</div>
1024
</div>
1030
</div>
1025
<br>
1031
<br>
1026
<div class="panel">
1032
<div class="panel">
1027
	<div class="panel-header"><?= $l_static_dhcp_title ?></div>
1033
	<div class="panel-header"><?= $l_static_dhcp_title ?></div>
1028
</div>
1034
</div>
1029
<table width="100%" cellspacing="0" cellpadding="5" border="1">
1035
<table width="100%" cellspacing="0" cellpadding="5" border="1">
1030
	<tr><td width="50%" align="center" valign="middle">
1036
	<tr><td width="50%" align="center" valign="middle">
1031
		<form action="network.php" method="POST">
1037
		<form action="network.php" method="POST">
1032
		<table cellspacing="2" cellpadding="3" border="1">
1038
		<table cellspacing="2" cellpadding="3" border="1">
1033
		<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info<th><?= $l_del ?></th></tr>
1039
		<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info<th><?= $l_del ?></th></tr>
1034
		<?php
1040
		<?php
1035
		// Read the "ether" file
1041
		// Read the "ether" file
1036
		exec('sudo /sbin/ip link show '.escapeshellarg($conf["INTIF"]), $output);
1042
		exec('sudo /sbin/ip link show '.escapeshellarg($conf["INTIF"]), $output);
1037
		$detail = explode(' ', $output[1]);
1043
		$detail = explode(' ', $output[1]);
1038
		$intif_mac_addr = strtoupper(str_replace(':', '-', $detail[5]));
1044
		$intif_mac_addr = strtoupper(str_replace(':', '-', $detail[5]));
1039
		unset($output); unset($detail);
1045
		unset($output); unset($detail);
1040
		$line_exist = false;
1046
		$line_exist = false;
1041
		$tab = file(ETHERS_INFO_FILE);
1047
		$tab = file(ETHERS_INFO_FILE);
1042
		if ($tab) { // le fichier n'est pas vide
1048
		if ($tab) { // le fichier n'est pas vide
1043
			foreach ($tab as $line) {
1049
			foreach ($tab as $line) {
1044
				$fields = explode(' ', $line);
1050
				$fields = explode(' ', $line);
1045
				$mac_addr = $fields[0];
1051
				$mac_addr = $fields[0];
1046
				$ip_addr  = $fields[1];
1052
				$ip_addr  = $fields[1];
1047
				$info     = (isset($fields[2])) ? implode(' ', array_slice($fields, 2)) : ' ';
1053
				$info     = (isset($fields[2])) ? implode(' ', array_slice($fields, 2)) : ' ';
1048
 
1054
 
1049
				echo '<tr>';
1055
				echo '<tr>';
1050
				echo "<td>$mac_addr</td>";
1056
				echo "<td>$mac_addr</td>";
1051
				echo "<td>$ip_addr</td>";
1057
				echo "<td>$ip_addr</td>";
1052
				if ($mac_addr !== $intif_mac_addr) {
1058
				if ($mac_addr !== $intif_mac_addr) {
1053
					echo '<td>'.ltrim($info, '#').'</td>';
1059
					echo '<td>'.ltrim($info, '#').'</td>';
1054
					echo "<td><input type=\"checkbox\" name=\"$mac_addr\"></td>";
1060
					echo "<td><input type=\"checkbox\" name=\"$mac_addr\"></td>";
1055
					$line_exist=True;
1061
					$line_exist=True;
1056
				} else {
1062
				} else {
1057
					echo '<td>ALCASAR</td>';
1063
					echo '<td>ALCASAR</td>';
1058
					echo '<td></td>';
1064
					echo '<td></td>';
1059
				}
1065
				}
1060
				echo '</tr>';
1066
				echo '</tr>';
1061
			}
1067
			}
1062
		}
1068
		}
1063
		?>
1069
		?>
1064
		</table>
1070
		</table>
1065
		<?php if ($line_exist): ?>
1071
		<?php if ($line_exist): ?>
1066
			<input type="hidden" name="choix" value="del_mac">
1072
			<input type="hidden" name="choix" value="del_mac">
1067
			<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>">
1073
			<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>">
1068
		<?php endif; ?>
1074
		<?php endif; ?>
1069
		</form>
1075
		</form>
1070
	</td><td width="50%" valign="middle" align="center">
1076
	</td><td width="50%" valign="middle" align="center">
1071
		<form name="new_mac" action="network.php" method="POST">
1077
		<form name="new_mac" action="network.php" method="POST">
1072
			<table cellspacing="2" cellpadding="3" border="1">
1078
			<table cellspacing="2" cellpadding="3" border="1">
1073
				<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info</th><td></td></tr>
1079
				<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info</th><td></td></tr>
1074
				<tr><td>Ex. : 12-2F-36-A4-DF-43</td><td>Ex. : 192.168.182.10</td><td>Ex. : Switch<td></td></tr>
1080
				<tr><td>Ex. : 12-2F-36-A4-DF-43</td><td>Ex. : 192.168.182.10</td><td>Ex. : Switch<td></td></tr>
1075
				<tr><td><input type="text" name="add_mac" size="17"></td>
1081
				<tr><td><input type="text" name="add_mac" size="17"></td>
1076
				<td><input type="text" name="add_ip" size="10"></td>
1082
				<td><input type="text" name="add_ip" size="10"></td>
1077
				<td><input type="text" name="info" size="10"></td>
1083
				<td><input type="text" name="info" size="10"></td>
1078
				<td>
1084
				<td>
1079
					<input type="hidden" name="choix" value="new_mac">
1085
					<input type="hidden" name="choix" value="new_mac">
1080
					<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_add_to_list ?>" onclick="return MAC_Control('new_mac');">
1086
					<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_add_to_list ?>" onclick="return MAC_Control('new_mac');">
1081
				</td>
1087
				</td>
1082
			</tr></table>
1088
			</tr></table>
1083
		</form>
1089
		</form>
1084
	</td></tr>
1090
	</td></tr>
1085
</table>
1091
</table>
1086
<br>
1092
<br>
1087
<div class="panel">
1093
<div class="panel">
1088
	<div class="panel-header"><?= $l_local_dns ?></div>
1094
	<div class="panel-header"><?= $l_local_dns ?></div>
1089
</div>
1095
</div>
1090
<table width="100%" cellspacing="0" cellpadding="5" border="1">
1096
<table width="100%" cellspacing="0" cellpadding="5" border="1">
1091
	<tr>
1097
	<tr>
1092
		<td width="50%" align="center">
1098
		<td width="50%" align="center">
1093
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
1099
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
1094
			<table cellspacing="2" cellpadding="3" border="1">
1100
			<table cellspacing="2" cellpadding="3" border="1">
1095
			<tr><th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><th><?= $l_del ?></th></tr>
1101
			<tr><th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><th><?= $l_del ?></th></tr>
1096
			<?php
1102
			<?php
1097
			// Read the "dns_local" file
1103
			// Read the "dns_local" file
1098
			$line_exist = false;
1104
			$line_exist = false;
1099
			$tab = file(DNS_LOCAL_FILE);
1105
			$tab = file(DNS_LOCAL_FILE);
1100
			if ($tab) { // not empty
1106
			if ($tab) { // not empty
1101
				foreach ($tab as $line) {
1107
				foreach ($tab as $line) {
1102
					if (preg_match ('/^\d+/', $line)) { # begin with one or several digit
1108
					if (preg_match ('/^\d+/', $line)) { # begin with one or several digit
1103
						$line_exist = true;
1109
						$line_exist = true;
1104
						$field = preg_split("/\s+/",$line); # split with one or several whitespace (or tab)
1110
						$field = preg_split("/\s+/",$line); # split with one or several whitespace (or tab)
1105
						$ip_addr   = $field[0];
1111
						$ip_addr   = $field[0];
1106
						$host_name = $field[1];
1112
						$host_name = $field[1];
1107
						echo "<tr><td>$ip_addr</td>";
1113
						echo "<tr><td>$ip_addr</td>";
1108
						echo "<td>$host_name</td>";
1114
						echo "<td>$host_name</td>";
1109
						if (($ip_addr == "127.0.0.1")|($host_name == "alcasar")) {
1115
						if (($ip_addr == "127.0.0.1")|($host_name == "alcasar")) {
1110
							echo "<td>";}
1116
							echo "<td>";}
1111
						else {
1117
						else {
1112
							echo "<td><input type=\"checkbox\" name=\"$ip_addr|$host_name\">";
1118
							echo "<td><input type=\"checkbox\" name=\"$ip_addr|$host_name\">";
1113
						}
1119
						}
1114
						echo "</td></tr>";
1120
						echo "</td></tr>";
1115
					}
1121
					}
1116
				}
1122
				}
1117
			}
1123
			}
1118
			if (!$line_exist) {
1124
			if (!$line_exist) {
1119
				echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
1125
				echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
1120
			}
1126
			}
1121
			?>
1127
			?>
1122
			</table>
1128
			</table>
1123
			<?php if ($line_exist): ?>
1129
			<?php if ($line_exist): ?>
1124
				<input type="hidden" name="choix" value="del_host">
1130
				<input type="hidden" name="choix" value="del_host">
1125
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>">
1131
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>">
1126
			<?php endif; ?>
1132
			<?php endif; ?>
1127
			</form>
1133
			</form>
1128
		</td>
1134
		</td>
1129
		<td width="50%" valign="middle" align="center">
1135
		<td width="50%" valign="middle" align="center">
1130
			<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
1136
			<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
1131
			<table cellspacing="2" cellpadding="3" border="1">
1137
			<table cellspacing="2" cellpadding="3" border="1">
1132
			<tr>
1138
			<tr>
1133
				<th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><td></td>
1139
				<th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><td></td>
1134
			</tr>
1140
			</tr>
1135
			<tr>
1141
			<tr>
1136
				<td>Ex. : 192.168.182.10</td><td>Ex. : my_nas</td><td></td>
1142
				<td>Ex. : 192.168.182.10</td><td>Ex. : my_nas</td><td></td>
1137
			</tr>
1143
			</tr>
1138
			<tr>
1144
			<tr>
1139
				<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
1145
				<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
1140
				<td><input type="text" name="add_host" size="17"></td>
1146
				<td><input type="text" name="add_host" size="17"></td>
1141
				<td><input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_add_to_list ?>"></td>
1147
				<td><input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_add_to_list ?>"></td>
1142
			</tr>
1148
			</tr>
1143
			</table>
1149
			</table>
1144
			</form>
1150
			</form>
1145
		</td>
1151
		</td>
1146
	</tr>
1152
	</tr>
1147
</table>
1153
</table>
1148
<br>
1154
<br>
1149
<div class="panel">
1155
<div class="panel">
1150
	<div class="panel-header"><?= $l_ssl_title ?></div>
1156
	<div class="panel-header"><?= $l_ssl_title ?></div>
1151
	<div class="panel-row">
1157
	<div class="panel-row">
1152
		<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1158
		<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1153
		<input type="hidden" name="choix" value="https_login">
1159
		<input type="hidden" name="choix" value="https_login">
1154
		<select name="https_login">
1160
		<select name="https_login">
1155
			<option value="on"<?=  (($conf['HTTPS_LOGIN'] === 'on')  ? ' selected' : '') ?>><?= $l_yes ?></option>
1161
			<option value="on"<?=  (($conf['HTTPS_LOGIN'] === 'on')  ? ' selected' : '') ?>><?= $l_yes ?></option>
1156
			<option value="off"<?= (($conf['HTTPS_LOGIN'] === 'off') ? ' selected' : '') ?>><?= $l_no ?></option>
1162
			<option value="off"<?= (($conf['HTTPS_LOGIN'] === 'off') ? ' selected' : '') ?>><?= $l_no ?></option>
1157
		</select>
1163
		</select>
1158
		<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>"><br>
1164
		<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>"><br>
1159
		</form>
1165
		</form>
1160
	</div>
1166
	</div>
1161
</div>
1167
</div>
1162
<br>
1168
<br>
1163
<div class="panel">
1169
<div class="panel">
1164
	<div class="panel-header"><?= $l_import_cert ?></div>
1170
	<div class="panel-header"><?= $l_import_cert ?></div>
1165
	<div class="panel-row">
1171
	<div class="panel-row">
1166
		<div class="panel-cell">
1172
		<div class="panel-cell">
1167
			<?php
1173
			<?php
1168
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
1174
			$certificateInfos     = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
1169
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
1175
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
-
 
1176
			$cert_from_date       = date('d-m-Y H:i:s', $certificateInfos['validFrom_time_t']);
1170
			$domain               = $certificateInfos['subject']['CN'];
1177
			$domain               = $certificateInfos['subject']['CN'];
1171
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
1178
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
1172
			$CAdomain             = $certificateInfos['issuer']['CN'];
1179
			$CAdomain             = $certificateInfos['issuer']['CN'];
1173
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
1180
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
1174
			?>
1181
			?>
1175
			<h3><?= $l_current_certificate ?></h3>
1182
			<h3><?= $l_current_certificate ?></h3>
1176
			<b><?= $l_cert_commonname ?></b> <?= $domain ?><br>
1183
			<b><?= $l_cert_commonname ?></b> <?= $domain ?><br>
-
 
1184
			<b><?= $l_cert_from ?></b> <?= $cert_from_date ?><br>
1177
			<b><?= $l_cert_expiration ?></b> <?= $cert_expiration_date ?><br>
1185
			<b><?= $l_cert_expiration ?></b> <?= $cert_expiration_date ?><br>
1178
			<b><?= $l_cert_organization ?></b> <?= $organization ?><br>
1186
			<b><?= $l_cert_organization ?></b> <?= $organization ?><br>
1179
			<b><?= $l_validated ?></b> <?= $CAdomain ?> (<?= $CAorganization ?>)<br>
1187
			<b><?= $l_validated ?></b> <?= $CAdomain ?> (<?= $CAorganization ?>)<br>
1180
		</div>
1188
		</div>
1181
		<div class="panel-cell">
1189
		<div class="panel-cell">
1182
			<?
1190
			<?
1183
			if (file_exists('/etc/pki/tls/certs/alcasar.crt.old') && file_exists('/etc/pki/tls/private/alcasar.key.old')){ // An old default certificate exist ?
1191
			if (file_exists('/etc/pki/tls/certs/alcasar.crt.old') && file_exists('/etc/pki/tls/private/alcasar.key.old')){ // An old default certificate exist ?
1184
				echo "<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
1192
				echo "<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
1185
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_default_cert\">\n";
1193
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_default_cert\">\n";
1186
				echo "\t\t\t\t<input type=\"submit\" onClick=\"document.getElementById('ldoverlay').style.display='block';\" value=\"$l_default_cert\"> (alcasar.localdomain)<br>\n";
1194
				echo "\t\t\t\t<input type=\"submit\" onClick=\"document.getElementById('ldoverlay').style.display='block';\" value=\"$l_default_cert\"> (alcasar.localdomain)<br>\n";
1187
				echo "\t\t\t</form>\n";}
1195
				echo "\t\t\t</form>\n";}
1188
			if (!empty($LE_conf['domainRequest']) && ($domain != $LE_conf['domainRequest'])) { // A Let's encrypt certificate exist & it's not the active one ?
1196
			if (!empty($LE_conf['domainRequest']) && ($domain != $LE_conf['domainRequest'])) { // A Let's encrypt certificate exist & it's not the active one ?
1189
				echo "\t\t\t<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
1197
				echo "\t\t\t<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
1190
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_last_LE_cert\">\n";
1198
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_last_LE_cert\">\n";
1191
				echo "\t\t\t\t<input type=\"submit\" onClick=\"document.getElementById('ldoverlay').style.display='block';\" value=\"".$l_previous_LE_cert."\"> (".$LE_conf['domainRequest'].")\n";
1199
				echo "\t\t\t\t<input type=\"submit\" onClick=\"document.getElementById('ldoverlay').style.display='block';\" value=\"".$l_previous_LE_cert."\"> (".$LE_conf['domainRequest'].")\n";
1192
				echo "\t\t\t</form>\n";}
1200
				echo "\t\t\t</form>\n";}
1193
			?>
1201
			?>
1194
		</div>
1202
		</div>
1195
	</div>
1203
	</div>
1196
	<div class="panel-row">
1204
	<div class="panel-row">
1197
		<div class="panel-cell">
1205
		<div class="panel-cell">
1198
			<h3><?= $l_upload_certificate ?></h3>
1206
			<h3><?= $l_upload_certificate ?></h3>
1199
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
1207
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
1200
				<?= $l_private_key;?> <input type="file" name="key"><br>
1208
				<?= $l_private_key;?> <input type="file" name="key"><br>
1201
				<?= $l_certificate;?> <input type="file" name="crt"><br>
1209
				<?= $l_certificate;?> <input type="file" name="crt"><br>
1202
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
1210
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
1203
				<input type="hidden" name="choix" value="import_cert">
1211
				<input type="hidden" name="choix" value="import_cert">
1204
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_import ?>">
1212
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_import ?>">
1205
			</form>
1213
			</form>
1206
		</div>
1214
		</div>
1207
		<div class="panel-cell">
1215
		<div class="panel-cell">
1208
			<?php
1216
			<?php
1209
			// Get step
1217
			// Get step
1210
			if (empty($LE_conf['domainRequest'])) {
1218
			if (empty($LE_conf['domainRequest'])) {
1211
				$step = 1;
1219
				$step = 1;
1212
			} else if (!empty($LE_conf['challenge'])) {
1220
			} else if (!empty($LE_conf['challenge'])) {
1213
				$step = 2;
1221
				$step = 2;
1214
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
1222
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
1215
				$step = 3;
1223
				$step = 3;
1216
			} else {
1224
			} else {
1217
				$step = 1;
1225
				$step = 1;
1218
			}
1226
			}
-
 
1227
			if ($step === 2) {
-
 
1228
				echo "<h3>$l_le_renewal</h3>";
-
 
1229
			} else { echo "<h3>$l_le_integration</h3>";}
1219
			?>
1230
			?>
1220
			<h3><?= $l_le_integration ?></h3>
-
 
1221
			<?php if ($step === 1): ?>
1231
			<?php if ($step === 1): ?>
1222
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1232
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1223
					<input type="hidden" name="choix" value="le_issueCert">
1233
					<input type="hidden" name="choix" value="le_issueCert">
1224
					<?= $l_le_status ?> <?= $l_disabled ?><br>
1234
					<?= $l_le_status ?> <?= $l_disabled ?><br>
1225
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
1235
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
1226
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
1236
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
1227
					<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="issue" value="<?= $l_send ?>"><br>
1237
					<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="issue" value="<?= $l_send ?>"><br>
1228
				</form>
1238
				</form>
1229
			<?php elseif ($step === 2): ?>
1239
			<?php elseif ($step === 2): ?>
1230
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1240
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1231
					<input type="hidden" name="choix" value="le_renewCert">
1241
					<input type="hidden" name="choix" value="le_renewCert">
1232
					<?= $l_le_status ?> <?= $l_pending_validation ?><br>
1242
					<?= $l_le_status ?> <?= $l_pending_validation ?><br>
1233
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
1243
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
1234
					<?= $l_le_ask_on ?> <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br>
-
 
1235
					<?= $l_le_dns_entry_txt ?> "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
1244
					<?= $l_le_dns_entry_txt ?> "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
1236
					<?= $l_le_challenge ?> "<?= $LE_conf['challenge'] ?>"<br>
1245
					<?= $l_le_challenge ?> "<?= $LE_conf['challenge'] ?>"<br>
1237
					<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="recheck" value="<?= $l_recheck ?>"> <input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="cancel" value="<?= $l_cancel ?>"><br>
1246
					<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="recheck" value="<?= $l_recheck ?>"> <input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="cancel" value="<?= $l_cancel ?>"><br>
1238
				</form>
1247
				</form>
1239
			<?php elseif ($step === 3): ?>
1248
			<?php elseif ($step === 3): ?>
1240
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1249
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1241
					<input type="hidden" name="choix" value="le_renewCert">
1250
					<input type="hidden" name="choix" value="le_renewCert">
1242
					<?= $l_le_status ?> <?= $l_enabled ?><br>
1251
					<?= $l_le_status ?> <?= $l_enabled ?><br>
1243
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
1252
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
1244
					<?= $l_le_api ?>  <?= $LE_conf['dnsapi'] ?><br>
1253
					<?= $l_le_api ?>  <?= $LE_conf['dnsapi'] ?><br>
1245
					<?= $l_le_next_renewal ?> <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
1254
					<?= $l_le_next_renewal ?> <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
1246
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
1255
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
1247
						<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="recheck" value="<?= $l_renew ?>"><br>
1256
						<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="recheck" value="<?= $l_renew ?>"><br>
1248
					<?php else: ?>
1257
					<?php else: ?>
1249
						<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="recheck_force" value="<?= $l_renew_force ?>"><br>
1258
						<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="recheck_force" value="<?= $l_renew_force ?>"><br>
1250
					<?php endif; ?>
1259
					<?php endif; ?>
1251
				</form>
1260
				</form>
1252
			<?php endif; ?>
1261
			<?php endif; ?>
1253
			<?php if (isset($cmdResponse)): ?>
1262
			<?php if (isset($cmdResponse)): ?>
1254
				<p><?= $cmdResponse ?></p>
1263
				<p><?= $cmdResponse ?></p>
1255
			<?php endif; ?>
1264
			<?php endif; ?>
1256
		</div>
1265
		</div>
1257
	</div>
1266
	</div>
1258
</div>
1267
</div>
1259
</body>
1268
</body>
1260
</html>
1269
</html>
1261
 
1270