Subversion Repositories ALCASAR

Rev

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