Subversion Repositories ALCASAR

Rev

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