Subversion Repositories ALCASAR

Rev

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