Subversion Repositories ALCASAR

Rev

Rev 2325 | Rev 2379 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log

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