Subversion Repositories ALCASAR

Rev

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

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