Subversion Repositories ALCASAR

Rev

Rev 3287 | Details | Compare with Previous | Last modification | View Log

Rev Author Line No. Line
318 richard 1
<?php
2304 tom.houday 2
# $Id: network.php 3288 2025-05-25 17:03:29Z 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";
81
	$l_ssh_port			= "Port";
3041 rexy 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";
85
	$l_all_ip			= "Pour autoriser toutes les @IP sources: 0.0.0.0";
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 :";
102
	$l_recheck		= "Revérifier";
103
	$l_cancel		= "Annuler";
104
	$l_le_api		= "API :";
105
	$l_le_next_renewal	= "Prochain renouvellement :";
106
	$l_renew		= "Renouveller";
107
	$l_renew_force		= "Renouveller (forcer)";
2813 rexy 108
	$l_previous_LE_cert	= "Revenir au certificat Let's Encrypt :";
2956 rexy 109
	$l_gw_weight    = "Poids";
110
	$l_error        = "Erreur";
3288 rexy 111
	$l_error_bad_mac = "Adresse MAC invalide";
112
	$l_error_bad_ip = "Adresse IP invalide";
113
	$l_error_bad_ip_CIDR = "Adresse IP au format CIDR invalide";
114
	$l_error_bad_ip_port = "Adresse IP + port invalide";
115
	$l_error_weight = "Poids invalide";
2956 rexy 116
    $l_change_successful = "Changement effectué avec succès";
117
 
2853 rexy 118
} else if ($Language === 'es') {
119
	$l_network_title	= "Configuración de Red";
120
	$l_internet_legend	= "INTERNET";
121
	$l_ip_mask		= "Máscara";
3132 rexy 122
	$l_ip_router		= "Router";
2853 rexy 123
	$l_ip_public		= "IP Pública";
124
	$l_ip_dns1		= "DNS n°1";
125
	$l_ip_dns2		= "DNS n°2";
126
	$l_dhcp_title		= "Servicio DHCP";
127
	$l_dhcp_state		= "Modo actual";
128
	$l_DHCP_on		= "activado";
129
	$l_DHCP_off		= "desactivado";
130
	$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";
131
	$l_static_dhcp_title	= "Reserva de direcciones IP estáticas (DHCP)";
132
	$l_mac_address		= "Dirección MAC";
133
	$l_ip_address		= "Dirección IP";
134
	$l_host_name		= "Nombre de Host";
135
	$l_del			= "Borrar de la lista";
136
	$l_add_to_list		= "Agregar";
137
	$l_apply		= "Aplicar cambios";
3250 rexy 138
	$l_local_dns		= "Resolución local de Nombres (DNS)";
2853 rexy 139
	$l_import_cert		= "Importar Certificado";
140
	$l_private_key		= "Clave Privada (.key) :";
141
	$l_certificate		= "Certificado (.crt) :";
142
	$l_server_chain		= "Cadena completa (de ser necesario: .crt) :";
143
	$l_default_cert		= "Volverl al certificado por defecto";
144
	$l_import		= "Importar";
145
	$l_current_certificate  = "Certificado en uso";
146
	$l_validated		= "Validado por :";
147
	$l_empty		= "Vacío";
148
	$l_yes			= "Si";
149
	$l_no			= "No";
150
	$l_ssl_title		= "La autenticación de cifrado fluye entre usuarios y ALCASAR";
3040 rexy 151
	$l_ssh_title		= "SSH";
152
	$l_ssh_port			= "Puerto";
3041 rexy 153
	$l_ssh_from			= "IP autorizada";
3051 rexy 154
	$l_ssh_wan_activate	= "Activar SSH en el lado WAN";
155
	$l_ssh_lan_activate	= "Activar SSH en el lado LAN";
156
	$l_all_ip			= "Para permitir todas las @IP de origen : 0.0.0.0";
3046 rexy 157
	$l_interlan_title = "Permitir el acceso a la red entre ALCASAR y el router de acceso a Internet";
2853 rexy 158
	$l_cert_expiration	= "Fecha de vencimiento:";
159
	$l_cert_commonname	= "Common name:";
160
	$l_cert_organization	= "Organización:";
161
	$l_upload_certificate	= "Importar un certificado";
162
	$l_le_integration	= "Integración con Let's Encrypt";
163
	$l_le_status		= "Estado:";
164
	$l_disabled		= "Desactivado";
165
	$l_pending_validation	= "Validación pendiente";
166
	$l_enabled		= "Activado";
167
	$l_le_email		= "Email:";
168
	$l_le_domain_name	= "Nombre de dominio:";
169
	$l_send			= "Enviar";
170
	$l_le_ask_on		= "Preguntar el:";
171
	$l_le_dns_entry_txt	= "Entrada DNS TXT:";
172
	$l_le_challenge		= "Desafío:";
173
	$l_recheck		= "Verificar";
174
	$l_cancel		= "Cancelar";
175
	$l_le_api		= "API:";
176
	$l_le_next_renewal	= "Siguiente renovación:";
177
	$l_renew		= "Renovar";
178
	$l_renew_force		= "Renovar (forzado)";
179
	$l_previous_LE_cert	= "Volver al certificado de Let's Encrypt :";
2971 rexy 180
    $l_gw_weight	= "Peso";
181
    $l_error		= "Error";
3288 rexy 182
	$l_error_bad_mac = "Dirección MAC no válida";
183
    $l_error_bad_ip	= "Dirección IP inválida";
184
    $l_error_bad_ip_CIDR	= "Dirección IP no válida en formato CIDR";
185
    $l_error_bad_ip_port	= "Dirección IP + puerto no válidos";
186
    $l_error_weight	= "Peso no válido";
2971 rexy 187
    $l_change_successful	= "Cambio completado con éxito";
2853 rexy 188
} else {
318 richard 189
	$l_network_title	= "Network configuration";
190
	$l_internet_legend	= "INTERNET";
1733 richard 191
	$l_ip_mask		= "Mask";
3132 rexy 192
	$l_ip_router		= "Router";
318 richard 193
	$l_ip_public		= "Public IP address";
2316 tom.houday 194
	$l_ip_dns1		= "DNS n°1";
195
	$l_ip_dns2		= "DNS n°2";
861 richard 196
	$l_dhcp_title		= "DHCP service";
862 richard 197
	$l_dhcp_state		= "Current mode";
1484 richard 198
	$l_DHCP_on		= "enabled";
199
	$l_DHCP_off		= "disabled";
2304 tom.houday 200
	$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 201
	$l_static_dhcp_title	= "Static IP addresses reservation (DHCP)";
2708 tom.houday 202
	$l_mac_address		= "MAC address";
203
	$l_ip_address		= "IP address";
1959 richard 204
	$l_host_name		= "Host name";
205
	$l_del			= "Delete from list";
841 richard 206
	$l_add_to_list		= "Add";
1733 richard 207
	$l_apply		= "Apply changes";
2717 tom.houday 208
	$l_local_dns		= "Local name resolution (DNS";
1733 richard 209
	$l_import_cert		= "Certificate import";
210
	$l_private_key		= "Private key (.key) :";
2813 rexy 211
	$l_certificate		= "Certificate (.crt or .cer) :";
212
	$l_server_chain		= "Server-chain (.crt, .cer or .pem) :";
213
	$l_default_cert		= "Back to default certificate :";
1740 richard 214
	$l_import		= "Import";
1743 clement.si 215
	$l_current_certificate  = "Current certificate";
216
	$l_validated		= "Validated by :";
2316 tom.houday 217
	$l_empty		= "Empty";
2326 tom.houday 218
	$l_yes			= "Yes";
219
	$l_no			= "No";
2736 rexy 220
	$l_ssl_title		= "Cipher authentication flows between users and ALCASAR";
3040 rexy 221
	$l_ssh_title		= "SSH";
222
	$l_ssh_port			= "Port";
3041 rexy 223
	$l_ssh_from			= "Authorized IP";
3051 rexy 224
	$l_ssh_wan_activate	= "Activate SSH on WAN side";
225
	$l_ssh_lan_activate	= "Activate SSH on LAN side";
226
	$l_all_ip			= "To allow all source IP addresses: 0.0.0.0";
3046 rexy 227
	$l_interlan_title = "Authorize access to the network located between ALCASAR and Internet broadband router";
2326 tom.houday 228
	$l_cert_expiration	= "Expiration date:";
229
	$l_cert_commonname	= "Common name:";
230
	$l_cert_organization	= "Organization:";
2813 rexy 231
	$l_upload_certificate	= "Import an officlal certificate";
232
	$l_le_integration	= "Integrate a Let's Encrypt certificate";
2326 tom.houday 233
	$l_le_status		= "Status:";
234
	$l_disabled		= "Disabled";
235
	$l_pending_validation	= "Pending validation";
236
	$l_enabled		= "Enabled";
237
	$l_le_email		= "Email:";
238
	$l_le_domain_name	= "Domain name:";
239
	$l_send			= "Send";
240
	$l_le_ask_on		= "Ask on:";
241
	$l_le_dns_entry_txt	= "DNS TXT entry:";
242
	$l_le_challenge		= "Challenge:";
243
	$l_recheck		= "Recheck";
244
	$l_cancel		= "Cancel";
245
	$l_le_api		= "API:";
246
	$l_le_next_renewal	= "Next renewal:";
247
	$l_renew		= "Renew";
248
	$l_renew_force		= "Renew (force)";
2813 rexy 249
	$l_previous_LE_cert	= "Back to the Let's Encrypt certificate :";
2956 rexy 250
    $l_gw_weight = "Weight";
251
    $l_error        = "Error";
3288 rexy 252
	$l_error_bad_mac = "Invalid mac address";
253
    $l_error_bad_ip = "Invalid IP address";
254
    $l_error_bad_ip_CIDR = "Invalid IP address in CIDR format";
255
    $l_error_bad_ip_port = "Invalid IP address + port";
256
    $l_error_weight = "Invalid weight";
2956 rexy 257
    $l_change_successful = "Network updated successfully";
318 richard 258
}
2316 tom.houday 259
 
260
$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])$/';
261
$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 262
$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 263
$reg_mac     = '/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/';
264
$reg_host    = '/^[a-zA-Z0-9-_]+$/';
2956 rexy 265
$reg_weight  = '/^[0-9]*$/';
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) {
299
					$line = $new_mac_addr . ' ' . $new_ip_addr . "\n";
300
					$pointeur = fopen(ETHERS_FILE, 'a');
301
					fwrite($pointeur, $line);
302
					fclose($pointeur);
303
					$pointeur = fopen(ETHERS_INFO_FILE, 'a');
304
					$line = "$new_mac_addr $new_ip_addr #" . trim($_POST['info'],"\x00..\x20") . "\n";
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){
3288 rexy 732
		// MAC control syntax (hexadecimal upper case and '- or :' separator) + rewrite ":" in "-"
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){
743
		// IP control (decimal & dot separator)
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
	}
2316 tom.houday 752
	</script>
753
	<style>
2813 rexy 754
		.network-configurator {
755
			width: 100%;
756
		}
757
		.network-configurator > * {
758
			display: inline-block;
759
			vertical-align: top;
760
			text-align: center;
761
		}
762
		.network-configurator > .internet, .network-configurator > .alcasar {
763
			width: 20%;
764
		}
765
		.network-configurator > .externals, .network-configurator > .internals {
766
			width: 30%;
767
		}
768
		.network-configurator .actions {
2956 rexy 769
            position: absolute;
2813 rexy 770
			background-color: #ddd;
771
			padding: 0 2px;
772
		}
773
		.network-configurator .actions a {
774
			text-decoration: none;
775
		}
776
		.network-configurator .actions a:hover {
777
			font-weight: bold;
778
		}
2956 rexy 779
		.network-configurator .actions-externals {
780
			right: 0;
781
			border-radius: 5px;
782
            position: relative;
783
            text-decoration: none;
2813 rexy 784
		}
785
		.network-configurator > .alcasar .actions-internals {
786
			bottom: 0;
787
			right: 0;
788
			border-radius: 5px 0;
789
		}
790
		.network-configurator .actions-network {
791
			right: 0;
2956 rexy 792
			border-radius: 5px;
793
            position: relative;
794
            text-decoration: none;
2813 rexy 795
		}
796
		.network-configurator .network-box {
797
			display: inline-block;
798
			min-height: 100px;
799
			margin: 5px;
800
			padding: 3px;
801
			text-align: left;
802
			background-color: #f7f3ef;
803
			position: relative;
804
			border-radius: 5px;
805
			border: 2px solid grey;
806
		}
807
		.network-configurator .network-connector {
808
			display: inline-block;
809
			position: absolute;
810
			top: 50%;
811
			margin-top: -5px;
812
			margin-left: -5px;
813
			width: 10px;
814
			height: 10px;
815
			border-radius: 5px;
816
			background-color: black;
817
		}
818
		.network-configurator .network-connector[data-connector-direction="left"] {
2956 rexy 819
			border-radius: 5px 0 0 5px;
2813 rexy 820
		}
821
		.network-configurator .network-connector[data-connector-direction="right"] {
2956 rexy 822
			border-radius: 0 5px 5px 0;
2813 rexy 823
		}
824
		.network-configurator div[data-network-type] {
825
			position: relative;
826
		}
2316 tom.houday 827
	</style>
828
	<script>
829
	$(document).ready(function () {
830
 
2956 rexy 831
        setTimeout(function(){$("#change_success").fadeOut('normal');}, 10000);
2316 tom.houday 832
 
2956 rexy 833
	    //Will be used later for multiple LAN interfaces
834
		let interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>;
835
		const wireStyles = { available: { border: '5px double green' } };
836
 
837
		// Add gateway
838
		$('.network-configurator').on('click', '.add-external-network', function (event) {
2316 tom.houday 839
			event.preventDefault();
2956 rexy 840
			ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
841
			$('.network-configurator .externals .network-box #ext_gateways').append(' \
842
			            <div id="ip_routeur_' + ifaces_count + '" data-info_type="gateway" data-number="'+ ifaces_count +'">\
843
                        <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="" /> \
844
                        <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"/> \
845
                        <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> ');
846
            ifaces_count++;
847
            document.getElementById("gw_count").setAttribute('value', ifaces_count);
848
            updateGatewayView();
849
            $('div.network-connector[data-connector-network]').connections('update');
2316 tom.houday 850
		});
851
 
852
		// Add internal network
2956 rexy 853
		$('.network-configurator').on('click', '.add-internal-network', function (event) {
2316 tom.houday 854
			event.preventDefault();
855
			$('.network-configurator .internals').append(' \
856
					<div data-network-type="internal"> \
857
						<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div> \
858
						<div class="network-box"> \
859
							<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
860
							<label for="int_interface_X"><?= 'Interface' ?></label> <select name="interface" id="int_interface_X" disabled><option value=""></option></select><br> \
861
							<label for="int_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_X" value="" /><br> \
862
						</div> \
863
					</div>');
864
			addWire($('div[data-network-type="internal"]:last'));
865
		});
866
 
2956 rexy 867
		// Remove gateway
868
		$('.network-box').on('click', '.remove-network', function (event) {
2316 tom.houday 869
			event.preventDefault();
2956 rexy 870
			$(this).parent().parent().fadeOut(200, function() {
2316 tom.houday 871
 
2956 rexy 872
			    $(this).remove();
873
				//update network numbers
874
                $('div[data-info_type="gateway"]').each(function (index, value) {
875
                    updateGatewayNumbers($(this), index);
876
                });
877
                ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
878
                document.getElementById("gw_count").setAttribute('value', (ifaces_count - 1));
879
                updateGatewayView();
880
 
881
                $('div.network-connector[data-connector-network]').connections('update');
2316 tom.houday 882
			});
883
		});
884
 
2956 rexy 885
		//proxy enabled or disabled
886
		$('.network-configurator').on('click', '.enable_proxy', function(event){
887
		    if ($(this).is(':checked'))
888
            {
889
                document.getElementById("add_external").setAttribute('hidden', 'true');
890
                document.getElementById("ext_proxy").removeAttribute('disabled');
891
                $('div[id="ip_routeur_0"]').children('span').html('');
892
                $('div[data-info_type="gateway"]').each(function(index, value) {
893
                    if ($(this).attr('data-number') !== "0")
894
                    {
895
                        $(this).attr('hidden', 'true');
896
                    }
897
                    else
898
                    {
899
                        $(this).children('input[id="ext_weight_0"]').attr('hidden', 'true');
900
                        $(this).children('label[for="ext_weight_0"]').attr('hidden', 'true');
901
                        $(this).children('div[class="actions actions-network"]').css('display', 'none');
902
                    }
903
                });
904
            }
905
            else
906
            {
907
                document.getElementById("add_external").removeAttribute('hidden');
908
                document.getElementById("ext_proxy").setAttribute('disabled', 'true');
909
                $('div[id="ip_routeur_0"]').children('span').html('1');
910
                $('div[data-info_type="gateway"]').each(function(index, value) {
911
                    if ($(this).attr('data-number') !== "0")
912
                    {
913
                        $(this).removeAttr('hidden');
914
                    }
915
                    else
916
                    {
917
                        $(this).children('input[id="ext_weight_0"]').removeAttr('hidden');
918
                        $(this).children('label[for="ext_weight_0"]').removeAttr('hidden');
919
                        $(this).children('div[class="actions actions-network"]').css('display', 'inline-block');
920
                    }
921
                });
922
                updateGatewayView();
923
            }
924
            $('div.network-connector[data-connector-network]').connections('update');
925
        });
926
 
927
		//Add a wire between two connectors
2316 tom.houday 928
		const addWire = function (network) {
929
			const networkType = network.data('networkType');
930
			if (networkType === 'external') {
2956 rexy 931
                $().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 });
932
                $().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 });
933
            } else if (networkType === 'internal') {
934
				$().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 935
			}
2325 tom.houday 936
		};
2316 tom.houday 937
 
2956 rexy 938
		//reindex the gateway numbers when a gateway is deleted
939
		const updateGatewayNumbers = function(gateway, number) {
940
		    old_number = gateway.attr('data-number');
941
            gateway.attr('data-number', number);
942
            gateway.attr('id', 'ip_routeur_'+number);
943
            if (number === 0)
944
            {
945
                gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('name', 'ip_gw');
946
                gateway.children('input[id="ext_weight_'+old_number+'"]').attr('name', 'weight');
947
            }
948
            else
949
            {
950
                gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('name', 'ip_gw_'+number);
951
                gateway.children('input[id="ext_weight_'+old_number+'"]').attr('name', 'weight_'+number);
952
            }
953
            gateway.children('label[for="ext_gateway_'+old_number+'"]').attr('for', 'ext_gateway_'+number);
954
            gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('id', 'ext_gateway_'+number);
955
            gateway.children('label[for="ext_weight_'+old_number+'"]').attr('for', 'ext_weight_'+number);
956
            gateway.children('input[id="ext_weight_'+old_number+'"]').attr('id', 'ext_weight_'+number);
957
            gateway.children('span[class="gw_number"]').html((number+1)+' ');
958
 
959
        };
960
 
961
		//hide the delete button and the weight field when there is only one gateway (or when there is a proxy)
962
		const updateGatewayView = function() {
963
            ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
964
            if (ifaces_count === 1)
965
            {
966
                $('div#ip_routeur_0').children('input[id="ext_weight_0"]').attr('hidden', 'true');
967
                $('div#ip_routeur_0').children('label[for="ext_weight_0"]').attr('hidden', 'true');
968
                $('div#ip_routeur_0').children('div[class="actions actions-network"]').css('display', 'none');
969
            }
970
            else
971
            {
972
                $('div#ip_routeur_0').children('input[id="ext_weight_0"]').removeAttr('hidden');
973
                $('div#ip_routeur_0').children('label[for="ext_weight_0"]').removeAttr('hidden');
974
                $('div#ip_routeur_0').children('div[class="actions actions-network"]').css('display', 'inline-block');
975
            }
976
        };
977
 
978
		//resize the connections to fit the window
2325 tom.houday 979
		window.addEventListener('resize', function () {
980
			$('div.network-connector[data-connector-network]').connections('update');
981
		});
982
 
2956 rexy 983
		// Add wires to existing networks at page first render
2316 tom.houday 984
		$('div[data-network-type="external"]').add('div[data-network-type="internal"]').each(function (index, element) {
985
			addWire($(this));
2325 tom.houday 986
		});
2316 tom.houday 987
	});
988
	</script>
318 richard 989
</head>
990
<body>
3028 rexy 991
<div id="ldoverlay" class="overlay">
992
	<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>
993
</div>
2813 rexy 994
<div class="panel">
995
	<div class="panel-header"><?= $l_network_title ?></div>
996
	<div class="panel-row">
997
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
998
			<div class="network-configurator">
999
				<div class="internet">
1000
					<div data-network-type="internet">
1001
						<div class="network-box">
1002
							<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br>
1003
							<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
1004
							<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
1005
							<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
1006
						</div>
1007
						<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div>
1008
					</div>
2956 rexy 1009
				</div><div id="externals_id" class="externals">
2813 rexy 1010
						<div data-network-type="external">
1011
							<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div>
2316 tom.houday 1012
							<div class="network-box">
2956 rexy 1013
								<label for="ext_interface">Interface</label> <input name="ext_interface" id="ext_interface" value="<?= $conf['EXTIF'] ?>" disabled="disabled"/><br>
1014
								<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>
1015
                                <input class="enable_proxy" type="checkbox" name="enable_proxy" value="P_Enabled" <?php if($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On') { echo 'checked'; }?>/>
1016
                                <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>
1017
                                <div id="ext_gateways" >
1018
                                    <input type="text" name="gw_count" id="gw_count" value="<?=count($gateways)?>" hidden="hidden"/>
1019
                                    <?php foreach ($gateways as $index => $network):
1020
                                        if ($index == 0) {?>
1021
                                            <div id="ip_routeur_<?= $index ?>" data-info_type="gateway" data-number="<?= $index ?>">
1022
                                                <label for="ext_gateway_<?= $index ?>"><?= $l_ip_router.' ' ?></label>
1023
                                                <span class="gw_number"><?= ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')?'':($index+1) ?> </span>
1024
                                                <input style="width:100px" type="text" name="ip_gw" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>" />
1025
                                                <label for="ext_weight_<?= $index ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On'|| $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'hidden' : '' ?>><?= $l_gw_weight ?></label>
1026
                                                <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' : '' ?>/>
1027
                                                <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">
1028
                                                    <a style="display:block; text-align:center" href="#" class="remove-network" title="Supprimer ce réseau">-</a>
1029
                                                </div><br>
1030
                                            </div>
1031
                                        <?php } else {?>
1032
                                            <div id="ip_routeur_<?= $index ?>" data-info_type="gateway" data-number="<?= $index ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? 'hidden' : '' ?>>
1033
                                                <label for="ext_gateway_<?= $index ?>"><?= $l_ip_router.' ' ?></label>
1034
                                                <span class="gw_number"><?= ($index+1) ?> </span>
1035
                                                <input style="width:100px" type="text" name="ip_gw_<?= $index ?>" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>"/>
1036
                                                <label for="ext_weight_<?= $index ?>"><?= $l_gw_weight ?></label>
1037
                                                <input style="width:20px" type="text" name="weight_<?= $index ?>" id="ext_weight_<?= $index ?>" value="<?= $network->weight ?>"/>
1038
                                                <div class="actions actions-network" style="display:inline-block; width:11px">
1039
                                                    <a style="display:block; text-align:center" href="#" class="remove-network" title="Supprimer ce réseau">-</a>
1040
                                                </div><br>
1041
                                            </div>
1042
                                    <?php } endforeach; ?>
1043
                                </div>
1044
                                <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>
1045
                            </div>
2813 rexy 1046
							<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div>
2316 tom.houday 1047
						</div>
2813 rexy 1048
				</div><div class="alcasar">
1049
					<div data-network-type="alcasar">
1050
						<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div>
1051
						<div class="network-box">
1052
							<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div>
1053
							<!-- <div class="actions actions-internals">
1054
								<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div>
1055
								<div><a href="#" class="add-internal-wifi-network">++</a></div>
1056
							</div> -->
1057
						</div>
1058
						<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div>
1059
					</div>
2956 rexy 1060
				</div><div id="internals_id" class="internals" data-count="1">
2813 rexy 1061
					<?php foreach ($internalNetworks as $network): ?>
1062
						<div data-network-type="internal">
1063
							<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div>
2316 tom.houday 1064
							<div class="network-box">
2813 rexy 1065
								<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
1066
								<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>
1067
								<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 1068
							</div>
1069
						</div>
2813 rexy 1070
					<? endforeach; ?>
2316 tom.houday 1071
				</div>
2813 rexy 1072
			</div>
2956 rexy 1073
            <?php if ($ext_conf_error == true) {
1074
                echo '<span style="color:red">';
1075
                $temp = 0;
1076
                while (isset($ext_conf_error_list[$temp])) {
1077
                    echo $ext_conf_error_list[$temp].'<br>';
1078
                    $temp++;
1079
                }
1080
                echo '</span>';
1081
            }
1082
            else if (($choix === 'network_change') && ($modification_proxy || $modification_dns || $modification_network)) {
1083
                echo '<span id="change_success" style="color:green">'.$l_change_successful.'</span>';
1084
            }?>
2813 rexy 1085
			<hr>
1086
			<div style="text-align: center; margin: 5px">
1087
				<input type="hidden" name="choix" value="network_change">
3028 rexy 1088
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>">
2813 rexy 1089
			</div>
1090
		</form>
2316 tom.houday 1091
	</div>
2813 rexy 1092
</div>
1093
<br>
1094
<div class="panel">
1095
	<div class="panel-header"><?= $l_static_dhcp_title ?></div>
1096
</div>
2304 tom.houday 1097
<table width="100%" cellspacing="0" cellpadding="5" border="1">
2708 tom.houday 1098
	<tr><td width="50%" align="center" valign="middle">
3288 rexy 1099
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
2316 tom.houday 1100
		<table cellspacing="2" cellpadding="3" border="1">
2708 tom.houday 1101
		<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info<th><?= $l_del ?></th></tr>
2316 tom.houday 1102
		<?php
2708 tom.houday 1103
		// Read the "ether" file
1104
		exec('sudo /sbin/ip link show '.escapeshellarg($conf["INTIF"]), $output);
1105
		$detail = explode(' ', $output[1]);
1106
		$intif_mac_addr = strtoupper(str_replace(':', '-', $detail[5]));
1107
		unset($output); unset($detail);
2316 tom.houday 1108
		$line_exist = false;
2708 tom.houday 1109
		$tab = file(ETHERS_INFO_FILE);
1110
		if ($tab) { // le fichier n'est pas vide
2316 tom.houday 1111
			foreach ($tab as $line) {
2708 tom.houday 1112
				$fields = explode(' ', $line);
1113
				$mac_addr = $fields[0];
1114
				$ip_addr  = $fields[1];
2713 tom.houday 1115
				$info     = (isset($fields[2])) ? implode(' ', array_slice($fields, 2)) : ' ';
2956 rexy 1116
 
2708 tom.houday 1117
				echo '<tr>';
1118
				echo "<td>$mac_addr</td>";
1119
				echo "<td>$ip_addr</td>";
1120
				if ($mac_addr !== $intif_mac_addr) {
1121
					echo '<td>'.ltrim($info, '#').'</td>';
1122
					echo "<td><input type=\"checkbox\" name=\"$mac_addr\"></td>";
1123
					$line_exist=True;
1124
				} else {
1125
					echo '<td>ALCASAR</td>';
1126
					echo '<td></td>';
2316 tom.houday 1127
				}
2708 tom.houday 1128
				echo '</tr>';
1959 richard 1129
			}
1130
		}
2316 tom.houday 1131
		?>
1132
		</table>
1133
		<?php if ($line_exist): ?>
2708 tom.houday 1134
			<input type="hidden" name="choix" value="del_mac">
3028 rexy 1135
			<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>">
2316 tom.houday 1136
		<?php endif; ?>
1137
		</form>
2708 tom.houday 1138
	</td><td width="50%" valign="middle" align="center">
3288 rexy 1139
		<form name="new_mac" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST" onSubmit="document.getElementById('ldoverlay').style.display='block';">
2708 tom.houday 1140
			<table cellspacing="2" cellpadding="3" border="1">
1141
				<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info</th><td></td></tr>
1142
				<tr><td>Ex. : 12-2F-36-A4-DF-43</td><td>Ex. : 192.168.182.10</td><td>Ex. : Switch<td></td></tr>
1143
				<tr><td><input type="text" name="add_mac" size="17"></td>
1144
				<td><input type="text" name="add_ip" size="10"></td>
1145
				<td><input type="text" name="info" size="10"></td>
1146
				<td>
1147
					<input type="hidden" name="choix" value="new_mac">
3288 rexy 1148
					<input type="submit" onClick="return (MAC_Control('new_mac') && IP_Control('new_mac'))" class="button" value="<?= $l_add_to_list ?>">
2708 tom.houday 1149
				</td>
1150
			</tr></table>
2316 tom.houday 1151
		</form>
2708 tom.houday 1152
	</td></tr>
1959 richard 1153
</table>
2316 tom.houday 1154
<br>
2813 rexy 1155
<div class="panel">
1156
	<div class="panel-header"><?= $l_local_dns ?></div>
1157
</div>
2709 tom.houday 1158
<table width="100%" cellspacing="0" cellpadding="5" border="1">
1159
	<tr>
1160
		<td width="50%" align="center">
1161
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
1162
			<table cellspacing="2" cellpadding="3" border="1">
1163
			<tr><th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><th><?= $l_del ?></th></tr>
1164
			<?php
1165
			// Read the "dns_local" file
1166
			$line_exist = false;
1167
			$tab = file(DNS_LOCAL_FILE);
1168
			if ($tab) { // not empty
1169
				foreach ($tab as $line) {
1170
					if (preg_match ('/^\d+/', $line)) { # begin with one or several digit
1171
						$line_exist = true;
1172
						$field = preg_split("/\s+/",$line); # split with one or several whitespace (or tab)
1173
						$ip_addr   = $field[0];
1174
						$host_name = $field[1];
1175
						echo "<tr><td>$ip_addr</td>";
1176
						echo "<td>$host_name</td>";
1177
						if (($ip_addr == "127.0.0.1")|($host_name == "alcasar")) {
1178
							echo "<td>";}
1179
						else {
1180
							echo "<td><input type=\"checkbox\" name=\"$ip_addr|$host_name\">";
1181
						}
1182
						echo "</td></tr>";
1183
					}
1184
				}
1185
			}
1186
			if (!$line_exist) {
1187
				echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
1188
			}
1189
			?>
1190
			</table>
1191
			<?php if ($line_exist): ?>
1192
				<input type="hidden" name="choix" value="del_host">
3288 rexy 1193
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_apply ?>">
2709 tom.houday 1194
			<?php endif; ?>
1195
			</form>
1196
		</td>
1197
		<td width="50%" valign="middle" align="center">
3288 rexy 1198
			<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST" onSubmit="document.getElementById('ldoverlay').style.display='block';">
2709 tom.houday 1199
			<table cellspacing="2" cellpadding="3" border="1">
1200
			<tr>
1201
				<th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><td></td>
1202
			</tr>
1203
			<tr>
1204
				<td>Ex. : 192.168.182.10</td><td>Ex. : my_nas</td><td></td>
1205
			</tr>
1206
			<tr>
1207
				<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
1208
				<td><input type="text" name="add_host" size="17"></td>
3288 rexy 1209
				<td><input type="submit" onClick="return (IP_Control('new_host'))" class="button" value="<?= $l_add_to_list ?>"></td>
2709 tom.houday 1210
			</tr>
1211
			</table>
1212
			</form>
1213
		</td>
1214
	</tr>
1215
</table>
1216
<br>
2813 rexy 1217
<div class="panel">
1218
	<div class="panel-header"><?= $l_ssl_title ?></div>
1219
	<div class="panel-row">
2609 rexy 1220
		<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
3041 rexy 1221
			<input type="hidden" name="choix" value="https_login">
1222
			<input type="checkbox" name="https_login" id="https_login" <?= ($conf['HTTPS_LOGIN'] === 'on')? "checked": "" ?>><b><?= $l_ssl_title ?></b><br>
3288 rexy 1223
			<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_apply ?>"><br>
2609 rexy 1224
		</form>
2813 rexy 1225
	</div>
1226
</div>
2609 rexy 1227
<br>
2813 rexy 1228
<div class="panel">
3046 rexy 1229
	<div class="panel-header"><?= $l_interlan_title ?></div>
1230
	<div class="panel-row">
1231
		<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1232
			<input type="hidden" name="choix" value="interlan">
1233
			<input type="checkbox" name="interlan" id="interlan" <?= ($conf['INTERLAN'] === 'on')? "checked": "" ?>><b><?= $l_interlan_title ?></b><br>
1234
			<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>"><br>
1235
		</form>
1236
	</div>
1237
</div>
1238
<br>
1239
<div class="panel">
3040 rexy 1240
	<div class="panel-header"><?= $l_ssh_title ?></div>
3041 rexy 1241
	<table width="100%" cellspacing="0" cellpadding="5" border="1">
1242
	<tr>
1243
		<td width="50%" align="center">
1244
			<div class="panel-row">
3288 rexy 1245
				<form name="ssh_lan" method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
3041 rexy 1246
					<input type="hidden" name="choix" value="enable_lan_ssh">
3042 rexy 1247
					<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>
1248
					<div id="sshtablelan" style="display:<?= $conf['SSH_LAN'] !== '0'? "block": "none" ?>">
1249
					<table cellspacing="2" cellpadding="3" border="1">
1250
						<tr>
1251
							<th><?= $l_ssh_port ?></th><th><?= $l_ssh_from ?></th>
1252
						</tr>
1253
						<tr>
1254
							<td><input style="width:120px" type="text" id="ssh_port" name="ssh_port" value="<?= $conf['SSH_LAN'] !== '0' ? $conf['SSH_LAN']:22 ?>" /></td>
1255
							<td><input style="width:120px" type="text" id="ssh_from" name="ssh_from" value="<?= explode('/',$conf['SSH_ADMIN_FROM'])[0] ?>" /></td>		
1256
						</tr>
1257
					</table>
3051 rexy 1258
					<p><?= $l_all_ip ?></p>
3042 rexy 1259
				</div>
3288 rexy 1260
					<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_apply ?>"><br>
3041 rexy 1261
				</form>
1262
			</div>
1263
		</td>
1264
		<td width="50%" align="center">
1265
			<div class="panel-row">
3288 rexy 1266
				<form name="ssh_wan" method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
3041 rexy 1267
				<input type="hidden" name="choix" value="enable_wan_ssh">
3042 rexy 1268
				<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>
1269
				<div id="sshtablewan" style="display:<?= $conf['SSH_WAN'] !== '0'? "block": "none" ?>">
3041 rexy 1270
					<table cellspacing="2" cellpadding="3" border="1">
1271
						<tr>
1272
							<th><?= $l_ssh_port ?></th><th><?= $l_ssh_from ?></th>
1273
						</tr>
1274
						<tr>
3042 rexy 1275
							<td><input style="width:120px" type="text" id="ssh_port" name="ssh_port" value="<?= $conf['SSH_WAN'] !== '0' ? $conf['SSH_WAN']:22 ?>" /></td>
1276
							<td><input style="width:120px" type="text" id="ssh_from" name="ssh_from" value="<?= explode('/',$conf['SSH_ADMIN_FROM'])[1] ?>" /></td>		
3041 rexy 1277
						</tr>
1278
					</table>
3051 rexy 1279
					<p><?= $l_all_ip ?></p>
3041 rexy 1280
				</div>
3288 rexy 1281
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_apply ?>"><br>
3041 rexy 1282
				</form>
1283
			</div>
1284
		</td>
1285
	</tr>
1286
	</table>
3040 rexy 1287
</div>
1288
<br>
1289
<div class="panel">
2813 rexy 1290
	<div class="panel-header"><?= $l_import_cert ?></div>
1291
	<div class="panel-row">
1292
		<div class="panel-cell">
2297 tom.houday 1293
			<?php
3040 rexy 1294
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
2297 tom.houday 1295
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
1296
			$domain               = $certificateInfos['subject']['CN'];
1297
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
1298
			$CAdomain             = $certificateInfos['issuer']['CN'];
1299
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
1300
			?>
1301
			<h3><?= $l_current_certificate ?></h3>
2813 rexy 1302
			<b><?= $l_cert_commonname ?></b> <?= $domain ?><br>
1303
			<b><?= $l_cert_expiration ?></b> <?= $cert_expiration_date ?><br>
1304
			<b><?= $l_cert_organization ?></b> <?= $organization ?><br>
1305
			<b><?= $l_validated ?></b> <?= $CAdomain ?> (<?= $CAorganization ?>)<br>
1306
		</div>
1307
		<div class="panel-cell">
1308
			<?
1309
			if (file_exists('/etc/pki/tls/certs/alcasar.crt.old') && file_exists('/etc/pki/tls/private/alcasar.key.old')){ // An old default certificate exist ?
1310
				echo "<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
1311
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_default_cert\">\n";
3238 rexy 1312
				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 1313
				echo "\t\t\t</form>\n";}
1314
			if (!empty($LE_conf['domainRequest']) && ($domain != $LE_conf['domainRequest'])) { // A Let's encrypt certificate exist & it's not the active one ?
1315
				echo "\t\t\t<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
1316
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_last_LE_cert\">\n";
3028 rexy 1317
				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 1318
				echo "\t\t\t</form>\n";}
1319
			?>
1320
		</div>
1321
	</div>
1322
	<div class="panel-row">
1323
		<div class="panel-cell">
2326 tom.houday 1324
			<h3><?= $l_upload_certificate ?></h3>
2324 tom.houday 1325
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
1326
				<?= $l_private_key;?> <input type="file" name="key"><br>
1327
				<?= $l_certificate;?> <input type="file" name="crt"><br>
1328
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
1329
				<input type="hidden" name="choix" value="import_cert">
3288 rexy 1330
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_import ?>">
2297 tom.houday 1331
			</form>
2813 rexy 1332
		</div>
1333
		<div class="panel-cell">
2304 tom.houday 1334
			<?php
1335
			// Get step
1336
			if (empty($LE_conf['domainRequest'])) {
1337
				$step = 1;
1338
			} else if (!empty($LE_conf['challenge'])) {
1339
				$step = 2;
1340
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
1341
				$step = 3;
1342
			} else {
1343
				$step = 1;
1344
			}
1345
			?>
3040 rexy 1346
			<h3><?= $l_le_integration ?></h3>
2324 tom.houday 1347
			<?php if ($step === 1): ?>
2316 tom.houday 1348
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1349
					<input type="hidden" name="choix" value="le_issueCert">
2326 tom.houday 1350
					<?= $l_le_status ?> <?= $l_disabled ?><br>
1351
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
1352
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
3028 rexy 1353
					<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="issue" value="<?= $l_send ?>"><br>
2304 tom.houday 1354
				</form>
1355
			<?php elseif ($step === 2): ?>
2316 tom.houday 1356
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1357
					<input type="hidden" name="choix" value="le_renewCert">
2326 tom.houday 1358
					<?= $l_le_status ?> <?= $l_pending_validation ?><br>
1359
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
3040 rexy 1360
					<?= $l_le_ask_on ?> <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br>
2326 tom.houday 1361
					<?= $l_le_dns_entry_txt ?> "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
1362
					<?= $l_le_challenge ?> "<?= $LE_conf['challenge'] ?>"<br>
3028 rexy 1363
					<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>
2304 tom.houday 1364
				</form>
1365
			<?php elseif ($step === 3): ?>
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_enabled ?><br>
1369
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
1370
					<?= $l_le_api ?>  <?= $LE_conf['dnsapi'] ?><br>
1371
					<?= $l_le_next_renewal ?> <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
2304 tom.houday 1372
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
3028 rexy 1373
						<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="recheck" value="<?= $l_renew ?>"><br>
2304 tom.houday 1374
					<?php else: ?>
3028 rexy 1375
						<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="recheck_force" value="<?= $l_renew_force ?>"><br>
2304 tom.houday 1376
					<?php endif; ?>
1377
				</form>
1378
			<?php endif; ?>
1379
			<?php if (isset($cmdResponse)): ?>
1380
				<p><?= $cmdResponse ?></p>
1381
			<?php endif; ?>
2813 rexy 1382
		</div>
1383
	</div>
1384
</div>
318 richard 1385
</body>
1386
</html>