Subversion Repositories ALCASAR

Rev

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