Subversion Repositories ALCASAR

Rev

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