Subversion Repositories ALCASAR

Rev

Rev 3300 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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