Subversion Repositories ALCASAR

Rev

Rev 3301 | Details | Compare with Previous | Last modification | View Log

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