Subversion Repositories ALCASAR

Rev

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