Subversion Repositories ALCASAR

Rev

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

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