Subversion Repositories ALCASAR

Rev

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

Rev Author Line No. Line
318 richard 1
<?php
2304 tom.houday 2
# $Id: network.php 3326 2026-03-01 22:35:33Z 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'];
3326 rexy 634
	if ((!empty($domainName)) && (preg_match($reg_domain, $domainName))) {
3302 rexy 635
			if ((!empty($email)) && (preg_match($reg_email, $email))) {
3326 rexy 636
				exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);}
637
			else {
3302 rexy 638
				exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --domain '.escapeshellarg($domainName), $output, $exitCode);}
639
			$cmdResponse = implode("<br>\n", $output);}
1822 raphael.pi 640
}
3326 rexy 641
 
2316 tom.houday 642
if ($choix === 'le_renewCert') {
3326 rexy 643
	if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
2316 tom.houday 644
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
645
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
3326 rexy 646
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/email=.*/','email=', file_get_contents(LETS_ENCRYPT_FILE)));
647
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/dateIssueRequest=.*/','dateIssueRequest=', file_get_contents(LETS_ENCRYPT_FILE)));	
2316 tom.houday 648
	}
3326 rexy 649
	else {
650
		if ((isset($_POST['recheck_force'])) && (!empty($_POST['recheck_force']))) {
651
			$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : ''; }
652
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
653
		$cmdResponse = implode("<br>\n", $output);
654
	}
1822 raphael.pi 655
}
656
 
2316 tom.houday 657
// Read Let's Encrypt configuration file
658
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
659
if (!$file_conf_LE) {
660
	exit('Error opening the file '.LETS_ENCRYPT_FILE);
2299 tom.houday 661
}
2316 tom.houday 662
while (!feof($file_conf_LE)) {
663
	$buffer = fgets($file_conf_LE, 4096);
2299 tom.houday 664
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
2450 tom.houday 665
		$tmp = explode('=', $buffer, 2);
2316 tom.houday 666
		$LE_conf[trim($tmp[0])] = trim($tmp[1]);
1822 raphael.pi 667
	}
668
}
2316 tom.houday 669
fclose($file_conf_LE);
670
 
671
// Fonction de test de connectivité internet
672
function internetTest() {
673
	$host = 'www.google.fr'; # Google Test
674
	$port = '80';
675
 
676
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
677
		return false;
678
	} else {
679
		fclose($sock);
680
		return true;
681
	}
682
}
683
 
684
$internet_connected = InternetTest();
685
if ($internet_connected) {
2404 tom.houday 686
	$ch = curl_init('https://api.ipify.org/');
687
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
688
	$internet_publicIP = curl_exec($ch);
689
	curl_close($ch);
2316 tom.houday 690
} else {
691
	$internet_publicIP = '-.-.-.-';
692
}
693
 
2956 rexy 694
// Network interfaces, will be use later for multiple LAN interfaces
695
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['INTIF']];
2316 tom.houday 696
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable);
697
 
2956 rexy 698
//retreive gateway(s) parameters
699
$gateways = [
2316 tom.houday 700
	(object) [
2956 rexy 701
		'gateway'   => $conf['GW'],
702
        'weight'    => $conf['PUBLIC_WEIGHT']
2316 tom.houday 703
	]
704
];
2956 rexy 705
exec("grep \"^WAN\" " . CONF_FILE . " | wc -l", $nbIfaces);
706
if ($nbIfaces > 0)
707
{
708
    for ($i = 1; $i <= $nbIfaces[0]; $i++) {
709
        exec("grep \"WAN" . $i . "=\" " . CONF_FILE . " | awk -F'\"' '{ print $2 }' | awk -F, '{ print $1 }'", $temp_gw);
710
        exec("grep \"WAN" . $i . "=\" " . CONF_FILE . " | awk -F'\"' '{ print $2 }' | awk -F, '{ print $2 }'", $temp_weight);
711
        $gateways[] = (object) [
712
            'gateway'   => $temp_gw[0],
713
            'weight'    => $temp_weight[0]
714
        ];
715
        $temp_gw = "";
716
        $temp_weight = "";
717
    }
718
}
719
 
720
//retreive internal networks parameters
2316 tom.houday 721
$internalNetworks = [
722
	(object) [
723
		'interface' => $conf['INTIF'],
724
		'ip'        => $conf['PRIVATE_IP']
725
	]
726
];
727
 
1740 richard 728
?>
2813 rexy 729
<!DOCTYPE HTML>
2316 tom.houday 730
<html>
318 richard 731
<head>
2316 tom.houday 732
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
733
	<title><?= $l_network_title ?></title>
2817 rexy 734
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
2316 tom.houday 735
	<script src="/js/jquery.min.js"></script>
736
	<script src="/js/jquery.connections.js"></script>
737
	<script type="text/javascript">
738
	function MAC_Control(formulaire){
3301 rexy 739
		// MAC syntax control (hexadecimal upper case and '- or :' separator) + rewrite ":" in "-"
3288 rexy 740
		var regex_mac = <?= $reg_mac ?>;
2316 tom.houday 741
		if (regex_mac.test(document.forms[formulaire].add_mac.value)){
742
			document.forms[formulaire].add_mac.value = document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
743
			return true;
744
		} else {
3288 rexy 745
			alert('<?= $l_error_bad_mac ?>');
2316 tom.houday 746
			return false;
747
		}
1578 richard 748
	}
3288 rexy 749
	function IP_Control(formulaire){
3301 rexy 750
		// IP syntax control (decimal & dot separator)
3288 rexy 751
		var regex_ip = <?= $reg_ip ?>;
752
		if (regex_ip.test(document.forms[formulaire].add_ip.value)){
753
			return true;
754
		} else {
755
			alert('<?= $l_error_bad_ip ?>');
756
			return false;
757
		}
758
	}
3301 rexy 759
	function Domain_Control(formulaire){
760
		// domain name syntax control
761
		var regex_domain = <?= $reg_domain ?>;
762
		if (regex_domain.test(document.forms[formulaire].domainname.value)){
763
			return true;
764
		} else {
765
			alert('<?= $l_error_bad_domain ?>');
766
			return false;
767
		}
768
	}
2316 tom.houday 769
	</script>
770
	<style>
2813 rexy 771
		.network-configurator {
772
			width: 100%;
773
		}
774
		.network-configurator > * {
775
			display: inline-block;
776
			vertical-align: top;
777
			text-align: center;
778
		}
779
		.network-configurator > .internet, .network-configurator > .alcasar {
780
			width: 20%;
781
		}
782
		.network-configurator > .externals, .network-configurator > .internals {
783
			width: 30%;
784
		}
785
		.network-configurator .actions {
2956 rexy 786
            position: absolute;
2813 rexy 787
			background-color: #ddd;
788
			padding: 0 2px;
789
		}
790
		.network-configurator .actions a {
791
			text-decoration: none;
792
		}
793
		.network-configurator .actions a:hover {
794
			font-weight: bold;
795
		}
2956 rexy 796
		.network-configurator .actions-externals {
797
			right: 0;
798
			border-radius: 5px;
799
            position: relative;
800
            text-decoration: none;
2813 rexy 801
		}
802
		.network-configurator > .alcasar .actions-internals {
803
			bottom: 0;
804
			right: 0;
805
			border-radius: 5px 0;
806
		}
807
		.network-configurator .actions-network {
808
			right: 0;
2956 rexy 809
			border-radius: 5px;
810
            position: relative;
811
            text-decoration: none;
2813 rexy 812
		}
813
		.network-configurator .network-box {
814
			display: inline-block;
815
			min-height: 100px;
816
			margin: 5px;
817
			padding: 3px;
818
			text-align: left;
819
			background-color: #f7f3ef;
820
			position: relative;
821
			border-radius: 5px;
822
			border: 2px solid grey;
823
		}
824
		.network-configurator .network-connector {
825
			display: inline-block;
826
			position: absolute;
827
			top: 50%;
828
			margin-top: -5px;
829
			margin-left: -5px;
830
			width: 10px;
831
			height: 10px;
832
			border-radius: 5px;
833
			background-color: black;
834
		}
835
		.network-configurator .network-connector[data-connector-direction="left"] {
2956 rexy 836
			border-radius: 5px 0 0 5px;
2813 rexy 837
		}
838
		.network-configurator .network-connector[data-connector-direction="right"] {
2956 rexy 839
			border-radius: 0 5px 5px 0;
2813 rexy 840
		}
841
		.network-configurator div[data-network-type] {
842
			position: relative;
843
		}
2316 tom.houday 844
	</style>
845
	<script>
846
	$(document).ready(function () {
847
 
2956 rexy 848
        setTimeout(function(){$("#change_success").fadeOut('normal');}, 10000);
2316 tom.houday 849
 
2956 rexy 850
	    //Will be used later for multiple LAN interfaces
851
		let interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>;
852
		const wireStyles = { available: { border: '5px double green' } };
853
 
854
		// Add gateway
855
		$('.network-configurator').on('click', '.add-external-network', function (event) {
2316 tom.houday 856
			event.preventDefault();
2956 rexy 857
			ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
858
			$('.network-configurator .externals .network-box #ext_gateways').append(' \
859
			            <div id="ip_routeur_' + ifaces_count + '" data-info_type="gateway" data-number="'+ ifaces_count +'">\
860
                        <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="" /> \
861
                        <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"/> \
862
                        <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> ');
863
            ifaces_count++;
864
            document.getElementById("gw_count").setAttribute('value', ifaces_count);
865
            updateGatewayView();
866
            $('div.network-connector[data-connector-network]').connections('update');
2316 tom.houday 867
		});
868
 
869
		// Add internal network
2956 rexy 870
		$('.network-configurator').on('click', '.add-internal-network', function (event) {
2316 tom.houday 871
			event.preventDefault();
872
			$('.network-configurator .internals').append(' \
873
					<div data-network-type="internal"> \
874
						<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div> \
875
						<div class="network-box"> \
876
							<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
877
							<label for="int_interface_X"><?= 'Interface' ?></label> <select name="interface" id="int_interface_X" disabled><option value=""></option></select><br> \
878
							<label for="int_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_X" value="" /><br> \
879
						</div> \
880
					</div>');
881
			addWire($('div[data-network-type="internal"]:last'));
882
		});
883
 
2956 rexy 884
		// Remove gateway
885
		$('.network-box').on('click', '.remove-network', function (event) {
2316 tom.houday 886
			event.preventDefault();
2956 rexy 887
			$(this).parent().parent().fadeOut(200, function() {
2316 tom.houday 888
 
2956 rexy 889
			    $(this).remove();
890
				//update network numbers
891
                $('div[data-info_type="gateway"]').each(function (index, value) {
892
                    updateGatewayNumbers($(this), index);
893
                });
894
                ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
895
                document.getElementById("gw_count").setAttribute('value', (ifaces_count - 1));
896
                updateGatewayView();
897
 
898
                $('div.network-connector[data-connector-network]').connections('update');
2316 tom.houday 899
			});
900
		});
901
 
2956 rexy 902
		//proxy enabled or disabled
903
		$('.network-configurator').on('click', '.enable_proxy', function(event){
904
		    if ($(this).is(':checked'))
905
            {
906
                document.getElementById("add_external").setAttribute('hidden', 'true');
907
                document.getElementById("ext_proxy").removeAttribute('disabled');
908
                $('div[id="ip_routeur_0"]').children('span').html('');
909
                $('div[data-info_type="gateway"]').each(function(index, value) {
910
                    if ($(this).attr('data-number') !== "0")
911
                    {
912
                        $(this).attr('hidden', 'true');
913
                    }
914
                    else
915
                    {
916
                        $(this).children('input[id="ext_weight_0"]').attr('hidden', 'true');
917
                        $(this).children('label[for="ext_weight_0"]').attr('hidden', 'true');
918
                        $(this).children('div[class="actions actions-network"]').css('display', 'none');
919
                    }
920
                });
921
            }
922
            else
923
            {
924
                document.getElementById("add_external").removeAttribute('hidden');
925
                document.getElementById("ext_proxy").setAttribute('disabled', 'true');
926
                $('div[id="ip_routeur_0"]').children('span').html('1');
927
                $('div[data-info_type="gateway"]').each(function(index, value) {
928
                    if ($(this).attr('data-number') !== "0")
929
                    {
930
                        $(this).removeAttr('hidden');
931
                    }
932
                    else
933
                    {
934
                        $(this).children('input[id="ext_weight_0"]').removeAttr('hidden');
935
                        $(this).children('label[for="ext_weight_0"]').removeAttr('hidden');
936
                        $(this).children('div[class="actions actions-network"]').css('display', 'inline-block');
937
                    }
938
                });
939
                updateGatewayView();
940
            }
941
            $('div.network-connector[data-connector-network]').connections('update');
942
        });
943
 
944
		//Add a wire between two connectors
2316 tom.houday 945
		const addWire = function (network) {
946
			const networkType = network.data('networkType');
947
			if (networkType === 'external') {
2956 rexy 948
                $().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 });
949
                $().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 });
950
            } else if (networkType === 'internal') {
951
				$().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 952
			}
2325 tom.houday 953
		};
2316 tom.houday 954
 
2956 rexy 955
		//reindex the gateway numbers when a gateway is deleted
956
		const updateGatewayNumbers = function(gateway, number) {
957
		    old_number = gateway.attr('data-number');
958
            gateway.attr('data-number', number);
959
            gateway.attr('id', 'ip_routeur_'+number);
960
            if (number === 0)
961
            {
962
                gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('name', 'ip_gw');
963
                gateway.children('input[id="ext_weight_'+old_number+'"]').attr('name', 'weight');
964
            }
965
            else
966
            {
967
                gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('name', 'ip_gw_'+number);
968
                gateway.children('input[id="ext_weight_'+old_number+'"]').attr('name', 'weight_'+number);
969
            }
970
            gateway.children('label[for="ext_gateway_'+old_number+'"]').attr('for', 'ext_gateway_'+number);
971
            gateway.children('input[id="ext_gateway_'+old_number+'"]').attr('id', 'ext_gateway_'+number);
972
            gateway.children('label[for="ext_weight_'+old_number+'"]').attr('for', 'ext_weight_'+number);
973
            gateway.children('input[id="ext_weight_'+old_number+'"]').attr('id', 'ext_weight_'+number);
974
            gateway.children('span[class="gw_number"]').html((number+1)+' ');
975
 
976
        };
977
 
978
		//hide the delete button and the weight field when there is only one gateway (or when there is a proxy)
979
		const updateGatewayView = function() {
980
            ifaces_count = parseInt(document.getElementById("gw_count").getAttribute('value'));
981
            if (ifaces_count === 1)
982
            {
983
                $('div#ip_routeur_0').children('input[id="ext_weight_0"]').attr('hidden', 'true');
984
                $('div#ip_routeur_0').children('label[for="ext_weight_0"]').attr('hidden', 'true');
985
                $('div#ip_routeur_0').children('div[class="actions actions-network"]').css('display', 'none');
986
            }
987
            else
988
            {
989
                $('div#ip_routeur_0').children('input[id="ext_weight_0"]').removeAttr('hidden');
990
                $('div#ip_routeur_0').children('label[for="ext_weight_0"]').removeAttr('hidden');
991
                $('div#ip_routeur_0').children('div[class="actions actions-network"]').css('display', 'inline-block');
992
            }
993
        };
994
 
995
		//resize the connections to fit the window
2325 tom.houday 996
		window.addEventListener('resize', function () {
997
			$('div.network-connector[data-connector-network]').connections('update');
998
		});
999
 
2956 rexy 1000
		// Add wires to existing networks at page first render
2316 tom.houday 1001
		$('div[data-network-type="external"]').add('div[data-network-type="internal"]').each(function (index, element) {
1002
			addWire($(this));
2325 tom.houday 1003
		});
2316 tom.houday 1004
	});
1005
	</script>
318 richard 1006
</head>
1007
<body>
3028 rexy 1008
<div id="ldoverlay" class="overlay">
1009
	<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>
1010
</div>
2813 rexy 1011
<div class="panel">
1012
	<div class="panel-header"><?= $l_network_title ?></div>
1013
	<div class="panel-row">
1014
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
1015
			<div class="network-configurator">
1016
				<div class="internet">
1017
					<div data-network-type="internet">
1018
						<div class="network-box">
1019
							<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br>
1020
							<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
1021
							<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
1022
							<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
1023
						</div>
1024
						<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div>
1025
					</div>
2956 rexy 1026
				</div><div id="externals_id" class="externals">
2813 rexy 1027
						<div data-network-type="external">
1028
							<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div>
2316 tom.houday 1029
							<div class="network-box">
2956 rexy 1030
								<label for="ext_interface">Interface</label> <input name="ext_interface" id="ext_interface" value="<?= $conf['EXTIF'] ?>" disabled="disabled"/><br>
1031
								<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>
1032
                                <input class="enable_proxy" type="checkbox" name="enable_proxy" value="P_Enabled" <?php if($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On') { echo 'checked'; }?>/>
1033
                                <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>
1034
                                <div id="ext_gateways" >
1035
                                    <input type="text" name="gw_count" id="gw_count" value="<?=count($gateways)?>" hidden="hidden"/>
1036
                                    <?php foreach ($gateways as $index => $network):
1037
                                        if ($index == 0) {?>
1038
                                            <div id="ip_routeur_<?= $index ?>" data-info_type="gateway" data-number="<?= $index ?>">
1039
                                                <label for="ext_gateway_<?= $index ?>"><?= $l_ip_router.' ' ?></label>
1040
                                                <span class="gw_number"><?= ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')?'':($index+1) ?> </span>
1041
                                                <input style="width:100px" type="text" name="ip_gw" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>" />
1042
                                                <label for="ext_weight_<?= $index ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On'|| $conf['MULTIWAN'] === 'Off' || $conf['MULTIWAN'] === 'off')? 'hidden' : '' ?>><?= $l_gw_weight ?></label>
1043
                                                <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' : '' ?>/>
1044
                                                <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">
1045
                                                    <a style="display:block; text-align:center" href="#" class="remove-network" title="Supprimer ce réseau">-</a>
1046
                                                </div><br>
1047
                                            </div>
1048
                                        <?php } else {?>
1049
                                            <div id="ip_routeur_<?= $index ?>" data-info_type="gateway" data-number="<?= $index ?>" <?php echo ($conf['PROXY'] === 'on' || $conf['PROXY'] === 'On')? 'hidden' : '' ?>>
1050
                                                <label for="ext_gateway_<?= $index ?>"><?= $l_ip_router.' ' ?></label>
1051
                                                <span class="gw_number"><?= ($index+1) ?> </span>
1052
                                                <input style="width:100px" type="text" name="ip_gw_<?= $index ?>" id="ext_gateway_<?= $index ?>" value="<?= $network->gateway ?>"/>
1053
                                                <label for="ext_weight_<?= $index ?>"><?= $l_gw_weight ?></label>
1054
                                                <input style="width:20px" type="text" name="weight_<?= $index ?>" id="ext_weight_<?= $index ?>" value="<?= $network->weight ?>"/>
1055
                                                <div class="actions actions-network" style="display:inline-block; width:11px">
1056
                                                    <a style="display:block; text-align:center" href="#" class="remove-network" title="Supprimer ce réseau">-</a>
1057
                                                </div><br>
1058
                                            </div>
1059
                                    <?php } endforeach; ?>
1060
                                </div>
1061
                                <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>
1062
                            </div>
2813 rexy 1063
							<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div>
2316 tom.houday 1064
						</div>
2813 rexy 1065
				</div><div class="alcasar">
1066
					<div data-network-type="alcasar">
1067
						<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div>
1068
						<div class="network-box">
1069
							<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div>
1070
							<!-- <div class="actions actions-internals">
1071
								<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div>
1072
								<div><a href="#" class="add-internal-wifi-network">++</a></div>
1073
							</div> -->
1074
						</div>
1075
						<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div>
1076
					</div>
2956 rexy 1077
				</div><div id="internals_id" class="internals" data-count="1">
2813 rexy 1078
					<?php foreach ($internalNetworks as $network): ?>
1079
						<div data-network-type="internal">
1080
							<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div>
2316 tom.houday 1081
							<div class="network-box">
2813 rexy 1082
								<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
1083
								<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>
1084
								<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 1085
							</div>
1086
						</div>
2813 rexy 1087
					<? endforeach; ?>
2316 tom.houday 1088
				</div>
2813 rexy 1089
			</div>
2956 rexy 1090
            <?php if ($ext_conf_error == true) {
1091
                echo '<span style="color:red">';
1092
                $temp = 0;
1093
                while (isset($ext_conf_error_list[$temp])) {
1094
                    echo $ext_conf_error_list[$temp].'<br>';
1095
                    $temp++;
1096
                }
1097
                echo '</span>';
1098
            }
1099
            else if (($choix === 'network_change') && ($modification_proxy || $modification_dns || $modification_network)) {
1100
                echo '<span id="change_success" style="color:green">'.$l_change_successful.'</span>';
1101
            }?>
2813 rexy 1102
			<hr>
1103
			<div style="text-align: center; margin: 5px">
1104
				<input type="hidden" name="choix" value="network_change">
3028 rexy 1105
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>">
2813 rexy 1106
			</div>
1107
		</form>
2316 tom.houday 1108
	</div>
2813 rexy 1109
</div>
1110
<br>
1111
<div class="panel">
1112
	<div class="panel-header"><?= $l_static_dhcp_title ?></div>
1113
</div>
2304 tom.houday 1114
<table width="100%" cellspacing="0" cellpadding="5" border="1">
2708 tom.houday 1115
	<tr><td width="50%" align="center" valign="middle">
3288 rexy 1116
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
2316 tom.houday 1117
		<table cellspacing="2" cellpadding="3" border="1">
2708 tom.houday 1118
		<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info<th><?= $l_del ?></th></tr>
2316 tom.houday 1119
		<?php
2708 tom.houday 1120
		// Read the "ether" file
1121
		exec('sudo /sbin/ip link show '.escapeshellarg($conf["INTIF"]), $output);
1122
		$detail = explode(' ', $output[1]);
1123
		$intif_mac_addr = strtoupper(str_replace(':', '-', $detail[5]));
1124
		unset($output); unset($detail);
2316 tom.houday 1125
		$line_exist = false;
2708 tom.houday 1126
		$tab = file(ETHERS_INFO_FILE);
1127
		if ($tab) { // le fichier n'est pas vide
2316 tom.houday 1128
			foreach ($tab as $line) {
2708 tom.houday 1129
				$fields = explode(' ', $line);
1130
				$mac_addr = $fields[0];
1131
				$ip_addr  = $fields[1];
2713 tom.houday 1132
				$info     = (isset($fields[2])) ? implode(' ', array_slice($fields, 2)) : ' ';
2956 rexy 1133
 
2708 tom.houday 1134
				echo '<tr>';
1135
				echo "<td>$mac_addr</td>";
1136
				echo "<td>$ip_addr</td>";
1137
				if ($mac_addr !== $intif_mac_addr) {
1138
					echo '<td>'.ltrim($info, '#').'</td>';
1139
					echo "<td><input type=\"checkbox\" name=\"$mac_addr\"></td>";
1140
					$line_exist=True;
1141
				} else {
1142
					echo '<td>ALCASAR</td>';
1143
					echo '<td></td>';
2316 tom.houday 1144
				}
2708 tom.houday 1145
				echo '</tr>';
1959 richard 1146
			}
1147
		}
2316 tom.houday 1148
		?>
1149
		</table>
1150
		<?php if ($line_exist): ?>
2708 tom.houday 1151
			<input type="hidden" name="choix" value="del_mac">
3028 rexy 1152
			<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>">
2316 tom.houday 1153
		<?php endif; ?>
1154
		</form>
2708 tom.houday 1155
	</td><td width="50%" valign="middle" align="center">
3288 rexy 1156
		<form name="new_mac" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST" onSubmit="document.getElementById('ldoverlay').style.display='block';">
2708 tom.houday 1157
			<table cellspacing="2" cellpadding="3" border="1">
1158
				<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info</th><td></td></tr>
1159
				<tr><td>Ex. : 12-2F-36-A4-DF-43</td><td>Ex. : 192.168.182.10</td><td>Ex. : Switch<td></td></tr>
1160
				<tr><td><input type="text" name="add_mac" size="17"></td>
1161
				<td><input type="text" name="add_ip" size="10"></td>
1162
				<td><input type="text" name="info" size="10"></td>
1163
				<td>
1164
					<input type="hidden" name="choix" value="new_mac">
3288 rexy 1165
					<input type="submit" onClick="return (MAC_Control('new_mac') && IP_Control('new_mac'))" class="button" value="<?= $l_add_to_list ?>">
2708 tom.houday 1166
				</td>
1167
			</tr></table>
2316 tom.houday 1168
		</form>
2708 tom.houday 1169
	</td></tr>
1959 richard 1170
</table>
2316 tom.houday 1171
<br>
2813 rexy 1172
<div class="panel">
1173
	<div class="panel-header"><?= $l_local_dns ?></div>
1174
</div>
2709 tom.houday 1175
<table width="100%" cellspacing="0" cellpadding="5" border="1">
1176
	<tr>
1177
		<td width="50%" align="center">
1178
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
1179
			<table cellspacing="2" cellpadding="3" border="1">
1180
			<tr><th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><th><?= $l_del ?></th></tr>
1181
			<?php
1182
			// Read the "dns_local" file
1183
			$line_exist = false;
1184
			$tab = file(DNS_LOCAL_FILE);
1185
			if ($tab) { // not empty
1186
				foreach ($tab as $line) {
1187
					if (preg_match ('/^\d+/', $line)) { # begin with one or several digit
1188
						$line_exist = true;
1189
						$field = preg_split("/\s+/",$line); # split with one or several whitespace (or tab)
1190
						$ip_addr   = $field[0];
1191
						$host_name = $field[1];
1192
						echo "<tr><td>$ip_addr</td>";
1193
						echo "<td>$host_name</td>";
1194
						if (($ip_addr == "127.0.0.1")|($host_name == "alcasar")) {
1195
							echo "<td>";}
1196
						else {
1197
							echo "<td><input type=\"checkbox\" name=\"$ip_addr|$host_name\">";
1198
						}
1199
						echo "</td></tr>";
1200
					}
1201
				}
1202
			}
1203
			if (!$line_exist) {
1204
				echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
1205
			}
1206
			?>
1207
			</table>
1208
			<?php if ($line_exist): ?>
1209
				<input type="hidden" name="choix" value="del_host">
3288 rexy 1210
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_apply ?>">
2709 tom.houday 1211
			<?php endif; ?>
1212
			</form>
1213
		</td>
1214
		<td width="50%" valign="middle" align="center">
3288 rexy 1215
			<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST" onSubmit="document.getElementById('ldoverlay').style.display='block';">
2709 tom.houday 1216
			<table cellspacing="2" cellpadding="3" border="1">
1217
			<tr>
1218
				<th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><td></td>
1219
			</tr>
1220
			<tr>
1221
				<td>Ex. : 192.168.182.10</td><td>Ex. : my_nas</td><td></td>
1222
			</tr>
1223
			<tr>
1224
				<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
1225
				<td><input type="text" name="add_host" size="17"></td>
3288 rexy 1226
				<td><input type="submit" onClick="return (IP_Control('new_host'))" class="button" value="<?= $l_add_to_list ?>"></td>
2709 tom.houday 1227
			</tr>
1228
			</table>
1229
			</form>
1230
		</td>
1231
	</tr>
1232
</table>
1233
<br>
2813 rexy 1234
<div class="panel">
1235
	<div class="panel-header"><?= $l_ssl_title ?></div>
1236
	<div class="panel-row">
2609 rexy 1237
		<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
3041 rexy 1238
			<input type="hidden" name="choix" value="https_login">
1239
			<input type="checkbox" name="https_login" id="https_login" <?= ($conf['HTTPS_LOGIN'] === 'on')? "checked": "" ?>><b><?= $l_ssl_title ?></b><br>
3288 rexy 1240
			<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_apply ?>"><br>
2609 rexy 1241
		</form>
2813 rexy 1242
	</div>
1243
</div>
2609 rexy 1244
<br>
2813 rexy 1245
<div class="panel">
3046 rexy 1246
	<div class="panel-header"><?= $l_interlan_title ?></div>
1247
	<div class="panel-row">
1248
		<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1249
			<input type="hidden" name="choix" value="interlan">
1250
			<input type="checkbox" name="interlan" id="interlan" <?= ($conf['INTERLAN'] === 'on')? "checked": "" ?>><b><?= $l_interlan_title ?></b><br>
1251
			<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" value="<?= $l_apply ?>"><br>
1252
		</form>
1253
	</div>
1254
</div>
1255
<br>
1256
<div class="panel">
3040 rexy 1257
	<div class="panel-header"><?= $l_ssh_title ?></div>
3041 rexy 1258
	<table width="100%" cellspacing="0" cellpadding="5" border="1">
1259
	<tr>
1260
		<td width="50%" align="center">
1261
			<div class="panel-row">
3288 rexy 1262
				<form name="ssh_lan" method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
3041 rexy 1263
					<input type="hidden" name="choix" value="enable_lan_ssh">
3042 rexy 1264
					<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>
1265
					<div id="sshtablelan" style="display:<?= $conf['SSH_LAN'] !== '0'? "block": "none" ?>">
1266
					<table cellspacing="2" cellpadding="3" border="1">
1267
						<tr>
1268
							<th><?= $l_ssh_port ?></th><th><?= $l_ssh_from ?></th>
1269
						</tr>
1270
						<tr>
1271
							<td><input style="width:120px" type="text" id="ssh_port" name="ssh_port" value="<?= $conf['SSH_LAN'] !== '0' ? $conf['SSH_LAN']:22 ?>" /></td>
1272
							<td><input style="width:120px" type="text" id="ssh_from" name="ssh_from" value="<?= explode('/',$conf['SSH_ADMIN_FROM'])[0] ?>" /></td>		
1273
						</tr>
1274
					</table>
3051 rexy 1275
					<p><?= $l_all_ip ?></p>
3042 rexy 1276
				</div>
3288 rexy 1277
					<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_apply ?>"><br>
3041 rexy 1278
				</form>
1279
			</div>
1280
		</td>
1281
		<td width="50%" align="center">
1282
			<div class="panel-row">
3288 rexy 1283
				<form name="ssh_wan" method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
3041 rexy 1284
				<input type="hidden" name="choix" value="enable_wan_ssh">
3042 rexy 1285
				<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>
1286
				<div id="sshtablewan" style="display:<?= $conf['SSH_WAN'] !== '0'? "block": "none" ?>">
3041 rexy 1287
					<table cellspacing="2" cellpadding="3" border="1">
1288
						<tr>
1289
							<th><?= $l_ssh_port ?></th><th><?= $l_ssh_from ?></th>
1290
						</tr>
1291
						<tr>
3042 rexy 1292
							<td><input style="width:120px" type="text" id="ssh_port" name="ssh_port" value="<?= $conf['SSH_WAN'] !== '0' ? $conf['SSH_WAN']:22 ?>" /></td>
1293
							<td><input style="width:120px" type="text" id="ssh_from" name="ssh_from" value="<?= explode('/',$conf['SSH_ADMIN_FROM'])[1] ?>" /></td>		
3041 rexy 1294
						</tr>
1295
					</table>
3051 rexy 1296
					<p><?= $l_all_ip ?></p>
3041 rexy 1297
				</div>
3288 rexy 1298
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_apply ?>"><br>
3041 rexy 1299
				</form>
1300
			</div>
1301
		</td>
1302
	</tr>
1303
	</table>
3040 rexy 1304
</div>
1305
<br>
1306
<div class="panel">
2813 rexy 1307
	<div class="panel-header"><?= $l_import_cert ?></div>
1308
	<div class="panel-row">
1309
		<div class="panel-cell">
2297 tom.houday 1310
			<?php
3326 rexy 1311
			$certificateInfos     = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
2297 tom.houday 1312
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
1313
			$domain               = $certificateInfos['subject']['CN'];
1314
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
1315
			$CAdomain             = $certificateInfos['issuer']['CN'];
1316
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
1317
			?>
1318
			<h3><?= $l_current_certificate ?></h3>
2813 rexy 1319
			<b><?= $l_cert_commonname ?></b> <?= $domain ?><br>
1320
			<b><?= $l_cert_expiration ?></b> <?= $cert_expiration_date ?><br>
1321
			<b><?= $l_cert_organization ?></b> <?= $organization ?><br>
1322
			<b><?= $l_validated ?></b> <?= $CAdomain ?> (<?= $CAorganization ?>)<br>
1323
		</div>
1324
		<div class="panel-cell">
1325
			<?
1326
			if (file_exists('/etc/pki/tls/certs/alcasar.crt.old') && file_exists('/etc/pki/tls/private/alcasar.key.old')){ // An old default certificate exist ?
3326 rexy 1327
				$certificateInfos     = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt.old'));
3302 rexy 1328
				$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
1329
				$domain               = $certificateInfos['subject']['CN'];
1330
				$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
1331
				$CAdomain             = $certificateInfos['issuer']['CN'];
1332
				$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
2813 rexy 1333
				echo "<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
1334
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_default_cert\">\n";
3302 rexy 1335
				echo "\t\t\t\t<input type=\"submit\" onClick=\"document.getElementById('ldoverlay').style.display='block';\" value=\"$l_default_cert\"><br>\n";
1336
				echo "\t\t\t\t<b>$l_cert_commonname</b> $domain <br>";
1337
				echo "\t\t\t\t<b>$l_cert_expiration</b> $cert_expiration_date <br>";
1338
				echo "\t\t\t\t<b>$l_cert_organization</b> $organization <br>";
1339
				echo "\t\t\t\t<b>$l_validated</b> $CAdomain ($CAorganization)<br>";
2813 rexy 1340
				echo "\t\t\t</form>\n";}
1341
			?>
1342
		</div>
1343
	</div>
1344
	<div class="panel-row">
1345
		<div class="panel-cell">
2326 tom.houday 1346
			<h3><?= $l_upload_certificate ?></h3>
2324 tom.houday 1347
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
1348
				<?= $l_private_key;?> <input type="file" name="key"><br>
1349
				<?= $l_certificate;?> <input type="file" name="crt"><br>
1350
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
1351
				<input type="hidden" name="choix" value="import_cert">
3288 rexy 1352
				<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" class="button" value="<?= $l_import ?>">
2297 tom.houday 1353
			</form>
2813 rexy 1354
		</div>
1355
		<div class="panel-cell">
2304 tom.houday 1356
			<?php
1357
			// Get step
3326 rexy 1358
			$domain=$conf['HOSTNAME'].".".$conf['DOMAIN'];
2304 tom.houday 1359
			if (empty($LE_conf['domainRequest'])) {
1360
				$step = 1;
1361
			} else if (!empty($LE_conf['challenge'])) {
1362
				$step = 2;
1363
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
1364
				$step = 3;
1365
			} else {
1366
				$step = 1;
1367
			}
1368
			?>
3040 rexy 1369
			<h3><?= $l_le_integration ?></h3>
2324 tom.houday 1370
			<?php if ($step === 1): ?>
3301 rexy 1371
				<form name="new_LE"  method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" onSubmit="document.getElementById('ldoverlay').style.display='block';">
2316 tom.houday 1372
					<input type="hidden" name="choix" value="le_issueCert">
2326 tom.houday 1373
					<?= $l_le_status ?> <?= $l_disabled ?><br>
3326 rexy 1374
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
2326 tom.houday 1375
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
3301 rexy 1376
					<input type="submit" onClick="return (Domain_Control('new_LE'))" class="button" name="issue" value="<?= $l_send ?>"><br>
2304 tom.houday 1377
				</form>
1378
			<?php elseif ($step === 2): ?>
2316 tom.houday 1379
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1380
					<input type="hidden" name="choix" value="le_renewCert">
2326 tom.houday 1381
					<?= $l_le_status ?> <?= $l_pending_validation ?><br>
1382
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
3040 rexy 1383
					<?= $l_le_ask_on ?> <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br>
2326 tom.houday 1384
					<?= $l_le_dns_entry_txt ?> "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
1385
					<?= $l_le_challenge ?> "<?= $LE_conf['challenge'] ?>"<br>
3300 rexy 1386
					<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 1387
				</form>
1388
			<?php elseif ($step === 3): ?>
2316 tom.houday 1389
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
1390
					<input type="hidden" name="choix" value="le_renewCert">
2326 tom.houday 1391
					<?= $l_le_status ?> <?= $l_enabled ?><br>
1392
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
1393
					<?= $l_le_api ?>  <?= $LE_conf['dnsapi'] ?><br>
3300 rexy 1394
					<?= $l_le_auto_renewal_warning ?> <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
1395
					<input type="submit" onClick="document.getElementById('ldoverlay').style.display='block';" name="recheck_force" value="<?= $l_renewal_request ?>"><br>
2304 tom.houday 1396
				</form>
1397
			<?php endif; ?>
1398
			<?php if (isset($cmdResponse)): ?>
1399
				<p><?= $cmdResponse ?></p>
1400
			<?php endif; ?>
2813 rexy 1401
		</div>
1402
	</div>
1403
</div>
318 richard 1404
</body>
1405
</html>