Subversion Repositories ALCASAR

Rev

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