Subversion Repositories ALCASAR

Rev

Rev 2853 | Rev 2956 | 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 2874 2020-10-31 13:54:28Z rexy $
3
 
2316 tom.houday 4
// written by steweb57, Rexy & Tom HOUDAYER
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');
2316 tom.houday 14
$conf_files = [CONF_FILE, ETHERS_FILE, ETHERS_INFO_FILE, DNS_LOCAL_FILE, LETS_ENCRYPT_FILE];
15
 
16
// Files reading test
17
foreach ($conf_files as $file) {
18
	if (!file_exists($file)) {
19
		exit("Requested file $file isn't present");
20
	}
21
	if (!is_readable($file)) {
22
		exit("Can't read the file $file");
23
	}
841 richard 24
}
2316 tom.houday 25
 
26
// Read ALCASAR CONF_FILE
27
$file_conf = fopen(CONF_FILE, 'r');
28
if (!$file_conf) {
29
	exit('Error opening the file '.CONF_FILE);
30
}
31
while (!feof($file_conf)) {
32
	$buffer = fgets($file_conf, 4096);
33
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
2450 tom.houday 34
		$tmp = explode('=', $buffer, 2);
2316 tom.houday 35
		$conf[trim($tmp[0])] = trim($tmp[1]);
36
	}
37
}
38
fclose($file_conf);
39
 
40
// Choice of language
318 richard 41
$Language = 'en';
2316 tom.houday 42
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
43
	$Langue	  = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);
44
	$Language = strtolower(substr(chop($Langue[0]), 0, 2));
45
}
2853 rexy 46
if ($Language === 'fr') {
318 richard 47
	$l_network_title	= "Configuration réseau";
48
	$l_internet_legend	= "INTERNET";
1733 richard 49
	$l_ip_mask		= "Masque";
318 richard 50
	$l_ip_router		= "Passerelle";
736 franck 51
	$l_ip_public		= "Adresse IP publique";
2316 tom.houday 52
	$l_ip_dns1		= "DNS n°1";
53
	$l_ip_dns2		= "DNS n°2";
861 richard 54
	$l_dhcp_title		= "Service DHCP";
862 richard 55
	$l_dhcp_state		= "Mode actuel";
1484 richard 56
	$l_DHCP_on		= "actif";
57
	$l_DHCP_off		= "inactif";
2304 tom.houday 58
	$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 59
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques (DHCP)";
841 richard 60
	$l_mac_address		= "Adresse MAC";
61
	$l_ip_address		= "Adresse IP";
1959 richard 62
	$l_host_name		= "Nom d'hôte";
63
	$l_del			= "Supprimer de la liste";
841 richard 64
	$l_add_to_list		= "Ajouter";
1733 richard 65
	$l_apply		= "Appliquer les changements";
2717 tom.houday 66
	$l_local_dns		= "Résolution local de nom (DNS)";
1733 richard 67
	$l_import_cert		= "Import de certificat";
68
	$l_private_key		= "Clé privée (.key) :";
2813 rexy 69
	$l_certificate		= "Certificat (.crt ou .cer) :";
70
	$l_server_chain		= "Chaîne de certification (.crt, .cer ou .pem) :";
71
	$l_default_cert		= "Revenir au certificat d'origine :";
1740 richard 72
	$l_import		= "Importer";
1743 clement.si 73
	$l_current_certificate  = "Certificat actuel";
74
	$l_validated		= "Validé par :";
2316 tom.houday 75
	$l_empty		= "Vide";
2326 tom.houday 76
	$l_yes			= "Oui";
77
	$l_no			= "Non";
2736 rexy 78
	$l_ssl_title		= "Chiffrer les flux d'authentification entre les utilisateurs et ALCASAR";
2326 tom.houday 79
	$l_cert_expiration	= "Date d'expiration :";
2380 tom.houday 80
	$l_cert_commonname	= "Nom commun :";
81
	$l_cert_organization	= "Organisation :";
2813 rexy 82
	$l_upload_certificate	= "Importer un certificat officiel";
83
	$l_le_integration	= "Intégrer un certificat Let's Encrypt";
2326 tom.houday 84
	$l_le_status		= "Status :";
85
	$l_disabled		= "Inactif";
86
	$l_pending_validation	= "En attente de validation";
87
	$l_enabled		= "Actif";
88
	$l_le_email		= "Email :";
89
	$l_le_domain_name	= "Nom de domaine :";
90
	$l_send			= "Envoyer";
91
	$l_le_ask_on		= "Demandé le :";
92
	$l_le_dns_entry_txt	= "Entrée DNS TXT :";
93
	$l_le_challenge		= "Challenge :";
94
	$l_recheck		= "Revérifier";
95
	$l_cancel		= "Annuler";
96
	$l_le_api		= "API :";
97
	$l_le_next_renewal	= "Prochain renouvellement :";
98
	$l_renew		= "Renouveller";
99
	$l_renew_force		= "Renouveller (forcer)";
2813 rexy 100
	$l_previous_LE_cert	= "Revenir au certificat Let's Encrypt :";
2853 rexy 101
} else if ($Language === 'es') {
102
	$l_network_title	= "Configuración de Red";
103
	$l_internet_legend	= "INTERNET";
104
	$l_ip_mask		= "Máscara";
105
	$l_ip_router		= "Puerta de enlace";
106
	$l_ip_public		= "IP Pública";
107
	$l_ip_dns1		= "DNS n°1";
108
	$l_ip_dns2		= "DNS n°2";
109
	$l_dhcp_title		= "Servicio DHCP";
110
	$l_dhcp_state		= "Modo actual";
111
	$l_DHCP_on		= "activado";
112
	$l_DHCP_off		= "desactivado";
113
	$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";
114
	$l_static_dhcp_title	= "Reserva de direcciones IP estáticas (DHCP)";
115
	$l_mac_address		= "Dirección MAC";
116
	$l_ip_address		= "Dirección IP";
117
	$l_host_name		= "Nombre de Host";
118
	$l_del			= "Borrar de la lista";
119
	$l_add_to_list		= "Agregar";
120
	$l_apply		= "Aplicar cambios";
121
	$l_local_dns		= "Resolución de Nombres Local (DNS)";
122
	$l_import_cert		= "Importar Certificado";
123
	$l_private_key		= "Clave Privada (.key) :";
124
	$l_certificate		= "Certificado (.crt) :";
125
	$l_server_chain		= "Cadena completa (de ser necesario: .crt) :";
126
	$l_default_cert		= "Volverl al certificado por defecto";
127
	$l_import		= "Importar";
128
	$l_current_certificate  = "Certificado en uso";
129
	$l_validated		= "Validado por :";
130
	$l_empty		= "Vacío";
131
	$l_yes			= "Si";
132
	$l_no			= "No";
133
	$l_ssl_title		= "La autenticación de cifrado fluye entre usuarios y ALCASAR";
134
	$l_cert_expiration	= "Fecha de vencimiento:";
135
	$l_cert_commonname	= "Common name:";
136
	$l_cert_organization	= "Organización:";
137
	$l_upload_certificate	= "Importar un certificado";
138
	$l_le_integration	= "Integración con Let's Encrypt";
139
	$l_le_status		= "Estado:";
140
	$l_disabled		= "Desactivado";
141
	$l_pending_validation	= "Validación pendiente";
142
	$l_enabled		= "Activado";
143
	$l_le_email		= "Email:";
144
	$l_le_domain_name	= "Nombre de dominio:";
145
	$l_send			= "Enviar";
146
	$l_le_ask_on		= "Preguntar el:";
147
	$l_le_dns_entry_txt	= "Entrada DNS TXT:";
148
	$l_le_challenge		= "Desafío:";
149
	$l_recheck		= "Verificar";
150
	$l_cancel		= "Cancelar";
151
	$l_le_api		= "API:";
152
	$l_le_next_renewal	= "Siguiente renovación:";
153
	$l_renew		= "Renovar";
154
	$l_renew_force		= "Renovar (forzado)";
155
	$l_previous_LE_cert	= "Volver al certificado de Let's Encrypt :";
156
} else {
318 richard 157
	$l_network_title	= "Network configuration";
158
	$l_internet_legend	= "INTERNET";
1733 richard 159
	$l_ip_mask		= "Mask";
841 richard 160
	$l_ip_router		= "Gateway";
318 richard 161
	$l_ip_public		= "Public IP address";
2316 tom.houday 162
	$l_ip_dns1		= "DNS n°1";
163
	$l_ip_dns2		= "DNS n°2";
861 richard 164
	$l_dhcp_title		= "DHCP service";
862 richard 165
	$l_dhcp_state		= "Current mode";
1484 richard 166
	$l_DHCP_on		= "enabled";
167
	$l_DHCP_off		= "disabled";
2304 tom.houday 168
	$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 169
	$l_static_dhcp_title	= "Static IP addresses reservation (DHCP)";
2708 tom.houday 170
	$l_mac_address		= "MAC address";
171
	$l_ip_address		= "IP address";
1959 richard 172
	$l_host_name		= "Host name";
173
	$l_del			= "Delete from list";
841 richard 174
	$l_add_to_list		= "Add";
1733 richard 175
	$l_apply		= "Apply changes";
2717 tom.houday 176
	$l_local_dns		= "Local name resolution (DNS";
1733 richard 177
	$l_import_cert		= "Certificate import";
178
	$l_private_key		= "Private key (.key) :";
2813 rexy 179
	$l_certificate		= "Certificate (.crt or .cer) :";
180
	$l_server_chain		= "Server-chain (.crt, .cer or .pem) :";
181
	$l_default_cert		= "Back to default certificate :";
1740 richard 182
	$l_import		= "Import";
1743 clement.si 183
	$l_current_certificate  = "Current certificate";
184
	$l_validated		= "Validated by :";
2316 tom.houday 185
	$l_empty		= "Empty";
2326 tom.houday 186
	$l_yes			= "Yes";
187
	$l_no			= "No";
2736 rexy 188
	$l_ssl_title		= "Cipher authentication flows between users and ALCASAR";
2326 tom.houday 189
	$l_cert_expiration	= "Expiration date:";
190
	$l_cert_commonname	= "Common name:";
191
	$l_cert_organization	= "Organization:";
2813 rexy 192
	$l_upload_certificate	= "Import an officlal certificate";
193
	$l_le_integration	= "Integrate a Let's Encrypt certificate";
2326 tom.houday 194
	$l_le_status		= "Status:";
195
	$l_disabled		= "Disabled";
196
	$l_pending_validation	= "Pending validation";
197
	$l_enabled		= "Enabled";
198
	$l_le_email		= "Email:";
199
	$l_le_domain_name	= "Domain name:";
200
	$l_send			= "Send";
201
	$l_le_ask_on		= "Ask on:";
202
	$l_le_dns_entry_txt	= "DNS TXT entry:";
203
	$l_le_challenge		= "Challenge:";
204
	$l_recheck		= "Recheck";
205
	$l_cancel		= "Cancel";
206
	$l_le_api		= "API:";
207
	$l_le_next_renewal	= "Next renewal:";
208
	$l_renew		= "Renew";
209
	$l_renew_force		= "Renew (force)";
2813 rexy 210
	$l_previous_LE_cert	= "Back to the Let's Encrypt certificate :";
318 richard 211
}
2316 tom.houday 212
 
213
$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])$/';
214
$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]))$/';
2380 tom.houday 215
$reg_mac     = '/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/';
216
$reg_host    = '/^[a-zA-Z0-9-_]+$/';
2316 tom.houday 217
 
218
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
219
 
220
switch ($choix) {
221
	case 'DHCP_On':
222
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -on');
2708 tom.houday 223
		header('Location: '.$_SERVER['PHP_SELF']);
224
		exit();
2316 tom.houday 225
	case 'DHCP_Off':
226
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
2708 tom.houday 227
		header('Location: '.$_SERVER['PHP_SELF']);
228
		exit();
2316 tom.houday 229
 
230
	case 'new_mac':
2380 tom.houday 231
		$new_mac_addr = trim($_POST['add_mac']);
232
		$new_ip_addr  = trim($_POST['add_ip']);
233
		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 234
			$tab = file(ETHERS_FILE);
235
			if ($tab) { // the file isn't empty
236
				$insert = true;
237
				foreach ($tab as $line) { // verify that MAC or IP address doesn't exist
238
					$field = explode(' ', $line);
239
					$mac_addr = trim($field[0]);
240
					$ip_addr  = trim($field[1]);
241
					if (strcasecmp($new_mac_addr, $mac_addr) === 0) {
242
						$insert = false;
243
						break;
841 richard 244
					}
2316 tom.houday 245
					if (strcasecmp($new_ip_addr, $ip_addr) === 0) {
246
						$insert = false;
247
						break;
841 richard 248
					}
249
				}
2316 tom.houday 250
				if ($insert) {
251
					$line = $new_mac_addr . ' ' . $new_ip_addr . "\n";
252
					$pointeur = fopen(ETHERS_FILE, 'a');
253
					fwrite($pointeur, $line);
254
					fclose($pointeur);
255
					$pointeur = fopen(ETHERS_INFO_FILE, 'a');
256
					$line = "$new_mac_addr $new_ip_addr #" . trim($_POST['info'],"\x00..\x20") . "\n";
257
					fwrite($pointeur, $line);
258
					fclose($pointeur);
259
					exec('sudo /usr/bin/systemctl reload chilli');
1959 richard 260
				}
841 richard 261
			}
1959 richard 262
		}
2708 tom.houday 263
		header('Location: '.$_SERVER['PHP_SELF']);
264
		exit();
2316 tom.houday 265
	case 'del_mac':
266
		foreach ($_POST as $key => $value) {
267
			if ($value == 'on') {
268
				$ether_file = ETHERS_FILE;
269
				$ether_file_info = ETHERS_INFO_FILE;
2559 rexy 270
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file");
271
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info");
2316 tom.houday 272
				exec('sudo /usr/bin/systemctl reload chilli');
841 richard 273
			}
274
		}
2708 tom.houday 275
		header('Location: '.$_SERVER['PHP_SELF']);
276
		exit();
2316 tom.houday 277
 
278
	case 'new_host':
2380 tom.houday 279
		$add_host = trim($_POST['add_host']);
280
		$add_ip   = trim($_POST['add_ip']);
281
		if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
2316 tom.houday 282
			$tab = file(DNS_LOCAL_FILE);
283
			if ($tab) { // the file isn't empty
284
				$insert = true;
2559 rexy 285
				foreach ($tab as $line) { // verify that host or IP address doesn't exist
286
					if (preg_match('/^\d+/', $line)) {
287
						$field = preg_split("/\s+/",$line);
288
						$ip_addr = $field[0];
289
						$host_name = trim($field[1]);
290
						if (strcasecmp($add_host, $host_name) === 0) {
291
							$insert = false;
292
							break;
293
						}
841 richard 294
					}
2559 rexy 295
				}
2316 tom.houday 296
				if ($insert) {
2688 lucas.echa 297
					exec("sudo /usr/local/bin/alcasar-dns-local.sh --add $add_ip $add_host");
1959 richard 298
				}
841 richard 299
			}
2380 tom.houday 300
		}
2708 tom.houday 301
		header('Location: '.$_SERVER['PHP_SELF']);
302
		exit();
2316 tom.houday 303
	case 'del_host':
304
		foreach ($_POST as $key => $value) {
305
			if ($value == 'on') {
2559 rexy 306
				$del_host = explode ("|", $key);
307
				$del_ip = str_replace("_",".",$del_host[0]);
308
				exec("sudo /usr/local/bin/alcasar-dns-local.sh --del $del_ip $del_host[1]");
2316 tom.houday 309
			}
841 richard 310
		}
2708 tom.houday 311
		header('Location: '.$_SERVER['PHP_SELF']);
312
		exit();
2316 tom.houday 313
 
2813 rexy 314
	case 'set_default_cert':
2316 tom.houday 315
		exec('sudo alcasar-importcert.sh -d');
316
		break;
2813 rexy 317
	case 'set_last_LE_cert':
318
		exec('sudo alcasar-letsencrypt.sh --install-cert');
319
		break;
2316 tom.houday 320
	case 'import_cert':	// Import certificate
2479 tom.houday 321
		$maxsize = 100000;
2316 tom.houday 322
		if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) {
323
			if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) {
2479 tom.houday 324
				if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && ((pathinfo($_FILES['crt']['name'])['extension'] == 'crt') || (pathinfo($_FILES['crt']['name'])['extension'] == 'cer'))) {
2316 tom.houday 325
					$dest = '/tmp/';
2380 tom.houday 326
					$scpath = '';
2813 rexy 327
					if (isset($_FILES['sc']) && ((pathinfo($_FILES['sc']['name'])['extension'] == 'crt') || (pathinfo($_FILES['sc']['name'])['extension'] == 'cer') || (pathinfo($_FILES['sc']['name']['extension'] == 'pem')))){
328
						$scpath = $dest.'server-chain.pem';
2316 tom.houday 329
						move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
330
					}
2380 tom.houday 331
					$keypath = $dest.'alcasar.key';
332
					$crtpath = $dest.'alcasar.crt';
2316 tom.houday 333
					move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
334
					move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
335
					exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
2688 lucas.echa 336
					if (file_exists($crtpath)) unlink($crtpath);
337
					if (file_exists($keypath)) unlink($keypath);
2610 tom.houday 338
					if (file_exists($scpath))  unlink($scpath);
2316 tom.houday 339
				}
1959 richard 340
			}
341
		}
2316 tom.houday 342
		break;
2324 tom.houday 343
 
344
	case 'https_login':	// Set HTTPS login status
345
		if ($_POST['https_login'] === 'on') {
346
			exec('sudo /usr/local/bin/alcasar-https.sh --on');
347
		} else {
348
			exec('sudo /usr/local/bin/alcasar-https.sh --off');
349
		}
350
		header('Location: '.$_SERVER['PHP_SELF']);
351
		exit();
318 richard 352
}
353
 
2316 tom.houday 354
// Network changes
355
if ($choix === 'network_change') {
356
	$network_modification = false;
1733 richard 357
 
2316 tom.houday 358
	if (isset($_POST['dns1']) && (trim($_POST['dns1']) !== $conf['DNS1']) && preg_match($reg_ip, $_POST['dns1'])) {
359
		file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'], 'DNS1='.trim($_POST['dns1']), file_get_contents(CONF_FILE)));
360
		$network_modification = true;
318 richard 361
	}
2316 tom.houday 362
	if (isset($_POST['dns2']) && (trim($_POST['dns2']) !== $conf['DNS2']) && preg_match($reg_ip, $_POST['dns2'])) {
363
		file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'], 'DNS2='.trim($_POST['dns2']), file_get_contents(CONF_FILE)));
364
		$network_modification = true;
318 richard 365
	}
2316 tom.houday 366
	if (isset($_POST['ip_public']) && (trim($_POST['ip_public']) !== $conf['PUBLIC_IP']) && preg_match($reg_ip_cidr, $_POST['ip_public'])) {
367
		file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'], 'PUBLIC_IP='.trim($_POST['ip_public']), file_get_contents(CONF_FILE)));
368
		$network_modification = true;
369
	}
370
	if (isset($_POST['ip_gw']) && (trim($_POST['ip_gw']) !== $conf['GW']) && preg_match($reg_ip, $_POST['ip_gw'])) {
371
		file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'], 'GW='.trim($_POST['ip_gw']), file_get_contents(CONF_FILE)));
372
		$network_modification = true;
373
	}
374
	if (isset($_POST['ip_private']) && (trim($_POST['ip_private']) !== $conf['PRIVATE_IP']) && preg_match($reg_ip_cidr, $_POST['ip_private'])) {
375
		file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'], 'PRIVATE_IP='.trim($_POST['ip_private']), file_get_contents(CONF_FILE)));
376
		$network_modification = true;
377
	}
378
 
379
	if ($network_modification) {
380
		exec('sudo /usr/local/bin/alcasar-conf.sh -apply');
381
	}
382
 
383
	// Read CONF_FILE updated
384
	$file_conf = fopen(CONF_FILE, 'r');
385
	if (!$file_conf) {
386
		exit('Error opening the file '.CONF_FILE);
387
	}
388
	while (!feof($file_conf)) {
389
		$buffer = fgets($file_conf, 4096);
390
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
2450 tom.houday 391
			$tmp = explode('=', $buffer, 2);
2316 tom.houday 392
			$conf[trim($tmp[0])] = trim($tmp[1]);
393
		}
394
	}
395
	fclose($file_conf);
318 richard 396
}
2316 tom.houday 397
 
398
// Let's Encrypt actions
399
if ($choix === 'le_issueCert') {
400
	// TODO: check ndd & mail format
401
	$email      = $_POST['email'];
402
	$domainName = $_POST['domainname'];
403
	exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);
404
	$cmdResponse = implode("<br>\n", $output);
1822 raphael.pi 405
}
2316 tom.houday 406
if ($choix === 'le_renewCert') {
407
	if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) {
408
		$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : '';
318 richard 409
 
2316 tom.houday 410
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
1822 raphael.pi 411
 
2316 tom.houday 412
		$cmdResponse = implode("<br>\n", $output);
413
	} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
414
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
415
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
416
	}
1822 raphael.pi 417
}
418
 
2316 tom.houday 419
// Read Let's Encrypt configuration file
420
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
421
if (!$file_conf_LE) {
422
	exit('Error opening the file '.LETS_ENCRYPT_FILE);
2299 tom.houday 423
}
2316 tom.houday 424
while (!feof($file_conf_LE)) {
425
	$buffer = fgets($file_conf_LE, 4096);
2299 tom.houday 426
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
2450 tom.houday 427
		$tmp = explode('=', $buffer, 2);
2316 tom.houday 428
		$LE_conf[trim($tmp[0])] = trim($tmp[1]);
1822 raphael.pi 429
	}
430
}
2316 tom.houday 431
fclose($file_conf_LE);
432
 
433
// Fonction de test de connectivité internet
434
function internetTest() {
435
	$host = 'www.google.fr'; # Google Test
436
	$port = '80';
437
 
438
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
439
		return false;
440
	} else {
441
		fclose($sock);
442
		return true;
443
	}
444
}
445
 
446
$internet_connected = InternetTest();
447
if ($internet_connected) {
2404 tom.houday 448
	$ch = curl_init('https://api.ipify.org/');
449
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
450
	$internet_publicIP = curl_exec($ch);
451
	curl_close($ch);
2316 tom.houday 452
} else {
453
	$internet_publicIP = '-.-.-.-';
454
}
455
 
456
// Network interfaces
457
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['EXTIF'], $conf['INTIF']];
458
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable);
459
 
460
// TODO: Pending the next version
461
$externalNetworks = [
462
	(object) [
463
		'interface' => $conf['EXTIF'],
464
		'ip'        => $conf['PUBLIC_IP'],
465
		'gateway'   => $conf['GW']
466
	]
467
];
468
$internalNetworks = [
469
	(object) [
470
		'interface' => $conf['INTIF'],
471
		'ip'        => $conf['PRIVATE_IP']
472
	]
473
];
474
 
1740 richard 475
?>
2813 rexy 476
<!DOCTYPE HTML>
2316 tom.houday 477
<html>
318 richard 478
<head>
2316 tom.houday 479
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
480
	<title><?= $l_network_title ?></title>
2817 rexy 481
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
2316 tom.houday 482
	<script src="/js/jquery.min.js"></script>
483
	<script src="/js/jquery.connections.js"></script>
484
	<script type="text/javascript">
485
	function MAC_Control(formulaire){
486
		// MAC control (upper case and '-' separator)
487
		var regex_mac = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/;
488
		if (regex_mac.test(document.forms[formulaire].add_mac.value)){
489
			document.forms[formulaire].add_mac.value = document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
490
			return true;
491
		} else {
492
			alert('Invalid MAC address');
493
			return false;
494
		}
1578 richard 495
	}
2316 tom.houday 496
	</script>
497
	<style>
2813 rexy 498
		.network-configurator {
499
			width: 100%;
500
		}
501
		.network-configurator > * {
502
			display: inline-block;
503
			vertical-align: top;
504
			text-align: center;
505
		}
506
		.network-configurator > .internet, .network-configurator > .alcasar {
507
			width: 20%;
508
		}
509
		.network-configurator > .externals, .network-configurator > .internals {
510
			width: 30%;
511
		}
512
		.network-configurator .actions {
513
			position: absolute;
514
			background-color: #ddd;
515
			padding: 0 2px;
516
		}
517
		.network-configurator .actions a {
518
			text-decoration: none;
519
		}
520
		.network-configurator .actions a:hover {
521
			font-weight: bold;
522
		}
523
		.network-configurator > .alcasar .actions-externals {
524
			bottom: 0;
525
			left: 0;
526
			border-radius: 0 5px;
527
		}
528
		.network-configurator > .alcasar .actions-internals {
529
			bottom: 0;
530
			right: 0;
531
			border-radius: 5px 0;
532
		}
533
		.network-configurator .actions-network {
534
			top: 0;
535
			right: 0;
536
			border-radius: 0 5px;
537
		}
538
		.network-configurator .network-box {
539
			display: inline-block;
540
			min-height: 100px;
541
			margin: 5px;
542
			padding: 3px;
543
			text-align: left;
544
			background-color: #f7f3ef;
545
			position: relative;
546
			border-radius: 5px;
547
			border: 2px solid grey;
548
		}
549
		.network-configurator .network-connector {
550
			display: inline-block;
551
			position: absolute;
552
			top: 50%;
553
			margin-top: -5px;
554
			margin-left: -5px;
555
			width: 10px;
556
			height: 10px;
557
			border-radius: 5px;
558
			background-color: black;
559
		}
560
		.network-configurator .network-connector[data-connector-direction="left"] {
561
			border-radius: 5px 0px 0px 5px;
562
		}
563
		.network-configurator .network-connector[data-connector-direction="right"] {
564
			border-radius: 0px 5px 5px 0px;
565
		}
566
		.network-configurator div[data-network-type] {
567
			position: relative;
568
		}
2316 tom.houday 569
	</style>
570
	<script>
571
	$(document).ready(function () {
572
		const interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>;
573
 
574
		const wireStyles = {
575
			available: { border: '5px double green' }
2325 tom.houday 576
		};
2316 tom.houday 577
 
578
		// Add external network
579
		$('.network-configurator .add-external-network').click(function (event) {
580
			event.preventDefault();
581
			let options = '';
582
			if (interfacesAvailable.length === 0) {
583
				options = '<option value=""></option>';
584
			} else {
585
				for (let i = 0; i < interfacesAvailable.length; i++) {
586
					options += '<option value="' + interfacesAvailable[i] + '">' + interfacesAvailable[i] + '</option>';
587
				}
588
			}
589
			$('.network-configurator .externals').append(' \
590
				<div data-network-type="external"> \
591
					<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div> \
592
					<div class="network-box"> \
593
						<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
594
						<label for="ext_interface_X"><?= 'Interface' ?></label> <select name="interface" id="ext_interface_X">' + options + '</select><br> \
595
						<label for="ext_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_public" id="ext_ip_X" value="" /><br> \
596
						<label for="ext_gateway_X"><?= $l_ip_router ?></label> <input style="width:120px" type="text" name="ip_gw" id="ext_gateway_X" value="" /> \
597
					</div> \
598
					<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div> \
599
				</div>');
600
			addWire($('div[data-network-type="external"]:last'));
601
		});
602
 
603
		// Add internal network
604
		$('.network-configurator .add-internal-network').click(function (event) {
605
			event.preventDefault();
606
			$('.network-configurator .internals').append(' \
607
					<div data-network-type="internal"> \
608
						<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div> \
609
						<div class="network-box"> \
610
							<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
611
							<label for="int_interface_X"><?= 'Interface' ?></label> <select name="interface" id="int_interface_X" disabled><option value=""></option></select><br> \
612
							<label for="int_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_X" value="" /><br> \
613
						</div> \
614
					</div>');
615
			addWire($('div[data-network-type="internal"]:last'));
616
		});
617
 
618
		// Remove network
619
		$('.network-configurator').on('click', '.remove-network', function (event) {
620
			event.preventDefault();
621
			$(this).parent().parent().parent().fadeOut(200, function() {
622
				const networkType = $(this).data('networkType');
623
				$(this).remove();
624
 
625
				// Update wires
626
				if (networkType === 'external') {
627
					$('div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]').connections('update');
628
					$('div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]').connections('update');
629
				} else if (networkType === 'internal') {
630
					$('div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]').connections('update');
631
				}
632
			});
633
		});
634
 
635
		const addWire = function (network) {
636
			const networkType = network.data('networkType');
637
			if (networkType === 'external') {
638
				$().connections({ from: 'div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]', to: 'div[data-network-type="external"]>div.network-connector[data-connector-network="internet"]:last', css: wireStyles.available, within: 'div[data-network-type="external"]:last' });
639
				$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]', to: 'div[data-network-type="external"]>div.network-connector[data-connector-network="external"]:last', css: wireStyles.available, within: 'div[data-network-type="external"]:last' });
640
			} else if (networkType === 'internal') {
641
				$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]', to: 'div[data-network-type="internal"]>div.network-connector[data-connector-network="internal"]:last', css: wireStyles.available, within: 'div[data-network-type="internal"]:last' });
642
			}
2325 tom.houday 643
		};
2316 tom.houday 644
 
2325 tom.houday 645
		window.addEventListener('resize', function () {
646
			$('div.network-connector[data-connector-network]').connections('update');
647
		});
648
 
2316 tom.houday 649
		// Add wires to existing networks
650
		$('div[data-network-type="external"]').add('div[data-network-type="internal"]').each(function (index, element) {
651
			addWire($(this));
2325 tom.houday 652
		});
2316 tom.houday 653
	});
654
	</script>
318 richard 655
</head>
656
<body>
2813 rexy 657
<div class="panel">
658
	<div class="panel-header"><?= $l_network_title ?></div>
659
	<div class="panel-row">
660
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
661
			<div class="network-configurator">
662
				<div class="internet">
663
					<div data-network-type="internet">
664
						<div class="network-box">
665
							<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br>
666
							<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
667
							<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
668
							<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
669
						</div>
670
						<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div>
671
					</div>
672
				</div><div class="externals">
673
					<?php foreach ($externalNetworks as $index => $network): ?>
674
						<div data-network-type="external">
675
							<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div>
2316 tom.houday 676
							<div class="network-box">
2813 rexy 677
								<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
678
								<label for="ext_interface_<?= $index ?>"><?= 'Interface' ?></label> <select name="ext_interface[<?= $index ?>]" id="ext_interface_<?= $index ?>" disabled><option value="<?= $network->interface ?>"><?= $network->interface ?></option></select><br>
679
								<label for="ext_ip_<?= $index ?>"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_public" id="ext_ip_<?= $index ?>" value="<?= $network->ip ?>" /><br>
680
								<label for="ext_gateway_<?= $index ?>"><?= $l_ip_router ?></label> <input style="width:120px" type="text" name="ip_gw" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>" />
2316 tom.houday 681
							</div>
2813 rexy 682
							<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div>
2316 tom.houday 683
						</div>
2813 rexy 684
					<? endforeach; ?>
685
				</div><div class="alcasar">
686
					<div data-network-type="alcasar">
687
						<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div>
688
						<div class="network-box">
689
							<!-- <div class="actions actions-externals">
690
								<div><a href="#" class="add-external-network" title="Ajouter un réseau externe">+</a></div>
691
							</div> -->
692
							<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div>
693
							<!-- <div class="actions actions-internals">
694
								<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div>
695
								<div><a href="#" class="add-internal-wifi-network">++</a></div>
696
							</div> -->
697
						</div>
698
						<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div>
699
					</div>
700
				</div><div class="internals">
701
					<?php foreach ($internalNetworks as $network): ?>
702
						<div data-network-type="internal">
703
							<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div>
2316 tom.houday 704
							<div class="network-box">
2813 rexy 705
								<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
706
								<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>
707
								<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 708
							</div>
709
						</div>
2813 rexy 710
					<? endforeach; ?>
2316 tom.houday 711
				</div>
2813 rexy 712
			</div>
713
			<hr>
714
			<div style="text-align: center; margin: 5px">
715
				<input type="hidden" name="choix" value="network_change">
716
				<input type="submit" value="<?= $l_apply ?>">
717
			</div>
718
		</form>
2316 tom.houday 719
	</div>
2813 rexy 720
</div>
721
<br>
722
<div class="panel">
723
	<div class="panel-header"><?= $l_static_dhcp_title ?></div>
724
</div>
2304 tom.houday 725
<table width="100%" cellspacing="0" cellpadding="5" border="1">
2708 tom.houday 726
	<tr><td width="50%" align="center" valign="middle">
727
		<form action="network.php" method="POST">
2316 tom.houday 728
		<table cellspacing="2" cellpadding="3" border="1">
2708 tom.houday 729
		<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info<th><?= $l_del ?></th></tr>
2316 tom.houday 730
		<?php
2708 tom.houday 731
		// Read the "ether" file
732
		exec('sudo /sbin/ip link show '.escapeshellarg($conf["INTIF"]), $output);
733
		$detail = explode(' ', $output[1]);
734
		$intif_mac_addr = strtoupper(str_replace(':', '-', $detail[5]));
735
		unset($output); unset($detail);
2316 tom.houday 736
		$line_exist = false;
2708 tom.houday 737
		$tab = file(ETHERS_INFO_FILE);
738
		if ($tab) { // le fichier n'est pas vide
2316 tom.houday 739
			foreach ($tab as $line) {
2708 tom.houday 740
				$fields = explode(' ', $line);
741
				$mac_addr = $fields[0];
742
				$ip_addr  = $fields[1];
2713 tom.houday 743
				$info     = (isset($fields[2])) ? implode(' ', array_slice($fields, 2)) : ' ';
2708 tom.houday 744
				echo '<tr>';
745
				echo "<td>$mac_addr</td>";
746
				echo "<td>$ip_addr</td>";
747
				if ($mac_addr !== $intif_mac_addr) {
748
					echo '<td>'.ltrim($info, '#').'</td>';
749
					echo "<td><input type=\"checkbox\" name=\"$mac_addr\"></td>";
750
					$line_exist=True;
751
				} else {
752
					echo '<td>ALCASAR</td>';
753
					echo '<td></td>';
2316 tom.houday 754
				}
2708 tom.houday 755
				echo '</tr>';
1959 richard 756
			}
757
		}
2316 tom.houday 758
		?>
759
		</table>
760
		<?php if ($line_exist): ?>
2708 tom.houday 761
			<input type="hidden" name="choix" value="del_mac">
2316 tom.houday 762
			<input type="submit" value="<?= $l_apply ?>">
763
		<?php endif; ?>
764
		</form>
2708 tom.houday 765
	</td><td width="50%" valign="middle" align="center">
766
		<form name="new_mac" action="network.php" method="POST">
767
			<table cellspacing="2" cellpadding="3" border="1">
768
				<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info</th><td></td></tr>
769
				<tr><td>Ex. : 12-2F-36-A4-DF-43</td><td>Ex. : 192.168.182.10</td><td>Ex. : Switch<td></td></tr>
770
				<tr><td><input type="text" name="add_mac" size="17"></td>
771
				<td><input type="text" name="add_ip" size="10"></td>
772
				<td><input type="text" name="info" size="10"></td>
773
				<td>
774
					<input type="hidden" name="choix" value="new_mac">
775
					<input type="submit" class="button" value="<?= $l_add_to_list ?>" onclick="return MAC_Control('new_mac');">
776
				</td>
777
			</tr></table>
2316 tom.houday 778
		</form>
2708 tom.houday 779
	</td></tr>
1959 richard 780
</table>
2316 tom.houday 781
<br>
2813 rexy 782
<div class="panel">
783
	<div class="panel-header"><?= $l_local_dns ?></div>
784
</div>
2709 tom.houday 785
<table width="100%" cellspacing="0" cellpadding="5" border="1">
786
	<tr>
787
		<td width="50%" align="center">
788
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
789
			<table cellspacing="2" cellpadding="3" border="1">
790
			<tr><th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><th><?= $l_del ?></th></tr>
791
			<?php
792
			// Read the "dns_local" file
793
			$line_exist = false;
794
			$tab = file(DNS_LOCAL_FILE);
795
			if ($tab) { // not empty
796
				foreach ($tab as $line) {
797
					if (preg_match ('/^\d+/', $line)) { # begin with one or several digit
798
						$line_exist = true;
799
						$field = preg_split("/\s+/",$line); # split with one or several whitespace (or tab)
800
						$ip_addr   = $field[0];
801
						$host_name = $field[1];
802
						echo "<tr><td>$ip_addr</td>";
803
						echo "<td>$host_name</td>";
804
						if (($ip_addr == "127.0.0.1")|($host_name == "alcasar")) {
805
							echo "<td>";}
806
						else {
807
							echo "<td><input type=\"checkbox\" name=\"$ip_addr|$host_name\">";
808
						}
809
						echo "</td></tr>";
810
					}
811
				}
812
			}
813
			if (!$line_exist) {
814
				echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
815
			}
816
			?>
817
			</table>
818
			<?php if ($line_exist): ?>
819
				<input type="hidden" name="choix" value="del_host">
820
				<input type="submit" value="<?= $l_apply ?>">
821
			<?php endif; ?>
822
			</form>
823
		</td>
824
		<td width="50%" valign="middle" align="center">
825
			<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
826
			<table cellspacing="2" cellpadding="3" border="1">
827
			<tr>
828
				<th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><td></td>
829
			</tr>
830
			<tr>
831
				<td>Ex. : 192.168.182.10</td><td>Ex. : my_nas</td><td></td>
832
			</tr>
833
			<tr>
834
				<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
835
				<td><input type="text" name="add_host" size="17"></td>
836
				<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
837
			</tr>
838
			</table>
839
			</form>
840
		</td>
841
	</tr>
842
</table>
843
<br>
2813 rexy 844
<div class="panel">
845
	<div class="panel-header"><?= $l_ssl_title ?></div>
846
	<div class="panel-row">
2609 rexy 847
		<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
848
		<input type="hidden" name="choix" value="https_login">
849
		<select name="https_login">
850
			<option value="on"<?=  (($conf['HTTPS_LOGIN'] === 'on')  ? ' selected' : '') ?>><?= $l_yes ?></option>
851
			<option value="off"<?= (($conf['HTTPS_LOGIN'] === 'off') ? ' selected' : '') ?>><?= $l_no ?></option>
852
		</select>
853
		<input type="submit" value="<?= $l_apply ?>"><br>
854
		</form>
2813 rexy 855
	</div>
856
</div>
2609 rexy 857
<br>
2813 rexy 858
<div class="panel">
859
	<div class="panel-header"><?= $l_import_cert ?></div>
860
	<div class="panel-row">
861
		<div class="panel-cell">
2297 tom.houday 862
			<?php
863
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
864
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
865
			$domain               = $certificateInfos['subject']['CN'];
866
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
867
			$CAdomain             = $certificateInfos['issuer']['CN'];
868
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
869
			?>
870
			<h3><?= $l_current_certificate ?></h3>
2813 rexy 871
			<b><?= $l_cert_commonname ?></b> <?= $domain ?><br>
872
			<b><?= $l_cert_expiration ?></b> <?= $cert_expiration_date ?><br>
873
			<b><?= $l_cert_organization ?></b> <?= $organization ?><br>
874
			<b><?= $l_validated ?></b> <?= $CAdomain ?> (<?= $CAorganization ?>)<br>
875
		</div>
876
		<div class="panel-cell">
877
			<?
878
			if (file_exists('/etc/pki/tls/certs/alcasar.crt.old') && file_exists('/etc/pki/tls/private/alcasar.key.old')){ // An old default certificate exist ?
879
				echo "<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
880
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_default_cert\">\n";
881
				echo "\t\t\t\t<input type=\"submit\" value=\"$l_default_cert\"> (alcasar.localdomain)<br>\n";
882
				echo "\t\t\t</form>\n";}
883
			if (!empty($LE_conf['domainRequest']) && ($domain != $LE_conf['domainRequest'])) { // A Let's encrypt certificate exist & it's not the active one ?
884
				echo "\t\t\t<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
885
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_last_LE_cert\">\n";
886
				echo "\t\t\t\t<input type=\"submit\" value=\"".$l_previous_LE_cert."\"> (".$LE_conf['domainRequest'].")\n";
887
				echo "\t\t\t</form>\n";}
888
			?>
889
		</div>
890
	</div>
891
	<div class="panel-row">
892
		<div class="panel-cell">
2326 tom.houday 893
			<h3><?= $l_upload_certificate ?></h3>
2324 tom.houday 894
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
895
				<?= $l_private_key;?> <input type="file" name="key"><br>
896
				<?= $l_certificate;?> <input type="file" name="crt"><br>
897
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
898
				<input type="hidden" name="choix" value="import_cert">
899
				<input type="submit" value="<?= $l_import ?>">
2297 tom.houday 900
			</form>
2813 rexy 901
		</div>
902
		<div class="panel-cell">
2304 tom.houday 903
			<?php
904
			// Get step
905
			if (empty($LE_conf['domainRequest'])) {
906
				$step = 1;
907
			} else if (!empty($LE_conf['challenge'])) {
908
				$step = 2;
909
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
910
				$step = 3;
911
			} else {
912
				$step = 1;
913
			}
914
			?>
2326 tom.houday 915
			<h3><?= $l_le_integration ?></h3>
2324 tom.houday 916
			<?php if ($step === 1): ?>
2316 tom.houday 917
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
918
					<input type="hidden" name="choix" value="le_issueCert">
2326 tom.houday 919
					<?= $l_le_status ?> <?= $l_disabled ?><br>
920
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
921
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
922
					<input type="submit" name="issue" value="<?= $l_send ?>"><br>
2304 tom.houday 923
				</form>
924
			<?php elseif ($step === 2): ?>
2316 tom.houday 925
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
926
					<input type="hidden" name="choix" value="le_renewCert">
2326 tom.houday 927
					<?= $l_le_status ?> <?= $l_pending_validation ?><br>
928
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
929
					<?= $l_le_ask_on ?> <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br>
930
					<?= $l_le_dns_entry_txt ?> "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
931
					<?= $l_le_challenge ?> "<?= $LE_conf['challenge'] ?>"<br>
932
					<input type="submit" name="recheck" value="<?= $l_recheck ?>"> <input type="submit" name="cancel" value="<?= $l_cancel ?>"><br>
2304 tom.houday 933
				</form>
934
			<?php elseif ($step === 3): ?>
2316 tom.houday 935
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
936
					<input type="hidden" name="choix" value="le_renewCert">
2326 tom.houday 937
					<?= $l_le_status ?> <?= $l_enabled ?><br>
938
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
939
					<?= $l_le_api ?>  <?= $LE_conf['dnsapi'] ?><br>
940
					<?= $l_le_next_renewal ?> <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
2304 tom.houday 941
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
2326 tom.houday 942
						<input type="submit" name="recheck" value="<?= $l_renew ?>"><br>
2304 tom.houday 943
					<?php else: ?>
2326 tom.houday 944
						<input type="submit" name="recheck_force" value="<?= $l_renew_force ?>"><br>
2304 tom.houday 945
					<?php endif; ?>
946
				</form>
947
			<?php endif; ?>
948
			<?php if (isset($cmdResponse)): ?>
949
				<p><?= $cmdResponse ?></p>
950
			<?php endif; ?>
2813 rexy 951
		</div>
952
	</div>
953
</div>
318 richard 954
</body>
955
</html>