Subversion Repositories ALCASAR

Rev

Rev 2709 | Rev 2717 | 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 2713 2019-03-10 23:35:02Z 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');
2558 rexy 12
define('DNS_LOCAL_FILE', '/etc/hosts');
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) !== '#')) {
2450 tom.houday 34
		$tmp = explode('=', $buffer, 2);
2316 tom.houday 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";
2708 tom.houday 60
	$l_dhcp_relay		= "Relais DHCP";
61
	$l_dhcp_relay_local_ip	= "Adresse IP locale";
62
	$l_dhcp_relay_ip	= "Adresse IP DHCP";
63
	$l_dhcp_relay_port	= "Port DHCP";
841 richard 64
	$l_mac_address		= "Adresse MAC";
65
	$l_ip_address		= "Adresse IP";
1959 richard 66
	$l_host_name		= "Nom d'hôte";
67
	$l_del			= "Supprimer de la liste";
841 richard 68
	$l_add_to_list		= "Ajouter";
1733 richard 69
	$l_apply		= "Appliquer les changements";
2709 tom.houday 70
	$l_dns_title		= "Service DNS";
1959 richard 71
	$l_local_dns		= "Résolution local de nom";
2709 tom.houday 72
	$l_dns_internal		= "Serveur DNS interne";
1733 richard 73
	$l_import_cert		= "Import de certificat";
74
	$l_private_key		= "Clé privée (.key) :";
75
	$l_certificate		= "Certificat (.crt) :";
1740 richard 76
	$l_server_chain		= "Chaîne de certification (si nécéssaire : .crt) :";
77
	$l_default_cert		= "Revenir au certificat d'origine";
78
	$l_import		= "Importer";
1743 clement.si 79
	$l_current_certificate  = "Certificat actuel";
80
	$l_validated		= "Validé par :";
2316 tom.houday 81
	$l_empty		= "Vide";
2326 tom.houday 82
	$l_yes			= "Oui";
83
	$l_no			= "Non";
2609 rexy 84
	$l_ssl_title		= "Chiffrer les flux réseau entre les utilisateurs et ALCASAR";
2326 tom.houday 85
	$l_cert_expiration	= "Date d'expiration :";
2380 tom.houday 86
	$l_cert_commonname	= "Nom commun :";
87
	$l_cert_organization	= "Organisation :";
2326 tom.houday 88
	$l_upload_certificate	= "Importer un certificat";
89
	$l_le_integration	= "Intégration Let's Encrypt";
90
	$l_le_status		= "Status :";
91
	$l_disabled		= "Inactif";
92
	$l_pending_validation	= "En attente de validation";
93
	$l_enabled		= "Actif";
94
	$l_le_email		= "Email :";
95
	$l_le_domain_name	= "Nom de domaine :";
96
	$l_send			= "Envoyer";
97
	$l_le_ask_on		= "Demandé le :";
98
	$l_le_dns_entry_txt	= "Entrée DNS TXT :";
99
	$l_le_challenge		= "Challenge :";
100
	$l_recheck		= "Revérifier";
101
	$l_cancel		= "Annuler";
102
	$l_le_api		= "API :";
103
	$l_le_next_renewal	= "Prochain renouvellement :";
104
	$l_renew		= "Renouveller";
105
	$l_renew_force		= "Renouveller (forcer)";
2316 tom.houday 106
} else {			// English
318 richard 107
	$l_network_title	= "Network configuration";
108
	$l_internet_legend	= "INTERNET";
1733 richard 109
	$l_ip_mask		= "Mask";
841 richard 110
	$l_ip_router		= "Gateway";
318 richard 111
	$l_ip_public		= "Public IP address";
2316 tom.houday 112
	$l_ip_dns1		= "DNS n°1";
113
	$l_ip_dns2		= "DNS n°2";
861 richard 114
	$l_dhcp_title		= "DHCP service";
862 richard 115
	$l_dhcp_state		= "Current mode";
1484 richard 116
	$l_DHCP_on		= "enabled";
117
	$l_DHCP_off		= "disabled";
2304 tom.houday 118
	$l_DHCP_off_explain	= "/!\\ Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
841 richard 119
	$l_static_dhcp_title	= "Static IP addresses reservation";
2708 tom.houday 120
	$l_dhcp_relay		= "DHCP relay";
121
	$l_dhcp_relay_local_ip	= "Locale IP address";
122
	$l_dhcp_relay_ip	= "DHCP IP address";
123
	$l_dhcp_relay_port	= "DHCP port";
124
	$l_mac_address		= "MAC address";
125
	$l_ip_address		= "IP address";
126
	$l_port			= "Port";
1959 richard 127
	$l_host_name		= "Host name";
128
	$l_del			= "Delete from list";
841 richard 129
	$l_add_to_list		= "Add";
1733 richard 130
	$l_apply		= "Apply changes";
2709 tom.houday 131
	$l_dns_title		= "DNS service";
1959 richard 132
	$l_local_dns		= "Local name resolution";
2709 tom.houday 133
	$l_dns_internal		= "DNS internal";
1733 richard 134
	$l_import_cert		= "Certificate import";
135
	$l_private_key		= "Private key (.key) :";
136
	$l_certificate		= "Certificate (.crt) :";
1740 richard 137
	$l_server_chain		= "Server-chain (if necessary : .crt) :";
1733 richard 138
	$l_default_cert		= "Back to default certificate";
1740 richard 139
	$l_import		= "Import";
1743 clement.si 140
	$l_current_certificate  = "Current certificate";
141
	$l_validated		= "Validated by :";
2316 tom.houday 142
	$l_empty		= "Empty";
2326 tom.houday 143
	$l_yes			= "Yes";
144
	$l_no			= "No";
2613 tom.houday 145
	$l_ssl_title		= "Cipher the network flows between users and ALCASAR";
2326 tom.houday 146
	$l_cert_expiration	= "Expiration date:";
147
	$l_cert_commonname	= "Common name:";
148
	$l_cert_organization	= "Organization:";
149
	$l_upload_certificate	= "Importer un certificat";
150
	$l_le_integration	= "Let's Encrypt integration";
151
	$l_le_status		= "Status:";
152
	$l_disabled		= "Disabled";
153
	$l_pending_validation	= "Pending validation";
154
	$l_enabled		= "Enabled";
155
	$l_le_email		= "Email:";
156
	$l_le_domain_name	= "Domain name:";
157
	$l_send			= "Send";
158
	$l_le_ask_on		= "Ask on:";
159
	$l_le_dns_entry_txt	= "DNS TXT entry:";
160
	$l_le_challenge		= "Challenge:";
161
	$l_recheck		= "Recheck";
162
	$l_cancel		= "Cancel";
163
	$l_le_api		= "API:";
164
	$l_le_next_renewal	= "Next renewal:";
165
	$l_renew		= "Renew";
166
	$l_renew_force		= "Renew (force)";
318 richard 167
}
2316 tom.houday 168
 
169
$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])$/';
170
$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 171
$reg_mac     = '/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/';
172
$reg_host    = '/^[a-zA-Z0-9-_]+$/';
2316 tom.houday 173
 
174
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
175
 
176
switch ($choix) {
177
	case 'DHCP_On':
178
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -on');
2708 tom.houday 179
		header('Location: '.$_SERVER['PHP_SELF']);
180
		exit();
2316 tom.houday 181
	case 'DHCP_Off':
182
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
2708 tom.houday 183
		header('Location: '.$_SERVER['PHP_SELF']);
184
		exit();
2316 tom.houday 185
 
186
	case 'new_mac':
2380 tom.houday 187
		$new_mac_addr = trim($_POST['add_mac']);
188
		$new_ip_addr  = trim($_POST['add_ip']);
189
		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 190
			$tab = file(ETHERS_FILE);
191
			if ($tab) { // the file isn't empty
192
				$insert = true;
193
				foreach ($tab as $line) { // verify that MAC or IP address doesn't exist
194
					$field = explode(' ', $line);
195
					$mac_addr = trim($field[0]);
196
					$ip_addr  = trim($field[1]);
197
					if (strcasecmp($new_mac_addr, $mac_addr) === 0) {
198
						$insert = false;
199
						break;
841 richard 200
					}
2316 tom.houday 201
					if (strcasecmp($new_ip_addr, $ip_addr) === 0) {
202
						$insert = false;
203
						break;
841 richard 204
					}
205
				}
2316 tom.houday 206
				if ($insert) {
207
					$line = $new_mac_addr . ' ' . $new_ip_addr . "\n";
208
					$pointeur = fopen(ETHERS_FILE, 'a');
209
					fwrite($pointeur, $line);
210
					fclose($pointeur);
211
					$pointeur = fopen(ETHERS_INFO_FILE, 'a');
212
					$line = "$new_mac_addr $new_ip_addr #" . trim($_POST['info'],"\x00..\x20") . "\n";
213
					fwrite($pointeur, $line);
214
					fclose($pointeur);
215
					exec('sudo /usr/bin/systemctl reload chilli');
1959 richard 216
				}
841 richard 217
			}
1959 richard 218
		}
2708 tom.houday 219
		header('Location: '.$_SERVER['PHP_SELF']);
220
		exit();
2316 tom.houday 221
	case 'del_mac':
222
		foreach ($_POST as $key => $value) {
223
			if ($value == 'on') {
224
				$ether_file = ETHERS_FILE;
225
				$ether_file_info = ETHERS_INFO_FILE;
2559 rexy 226
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file");
227
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info");
2316 tom.houday 228
				exec('sudo /usr/bin/systemctl reload chilli');
841 richard 229
			}
230
		}
2708 tom.houday 231
		header('Location: '.$_SERVER['PHP_SELF']);
232
		exit();
2316 tom.houday 233
 
2708 tom.houday 234
	case 'dhcp_relay':	// DHCP relay
235
		// TODO : check DHCP relay before apply?
236
		file_put_contents(CONF_FILE, str_replace('EXT_DHCP_IP='.$conf['EXT_DHCP_IP'],         'EXT_DHCP_IP='.trim($_POST['dhcp_relay_ext_ip']),   file_get_contents(CONF_FILE)));
237
		file_put_contents(CONF_FILE, str_replace('RELAY_DHCP_IP='.$conf['RELAY_DHCP_IP'],     'RELAY_DHCP_IP='.trim($_POST['dhcp_relay_ip']),     file_get_contents(CONF_FILE)));
238
		file_put_contents(CONF_FILE, str_replace('RELAY_DHCP_PORT='.$conf['RELAY_DHCP_PORT'], 'RELAY_DHCP_PORT='.trim($_POST['dhcp_relay_port']), file_get_contents(CONF_FILE)));
239
		header('Location: '.$_SERVER['PHP_SELF']);
240
		exit();
241
 
2316 tom.houday 242
	case 'new_host':
2380 tom.houday 243
		$add_host = trim($_POST['add_host']);
244
		$add_ip   = trim($_POST['add_ip']);
245
		if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
2316 tom.houday 246
			$tab = file(DNS_LOCAL_FILE);
247
			if ($tab) { // the file isn't empty
248
				$insert = true;
2559 rexy 249
				foreach ($tab as $line) { // verify that host or IP address doesn't exist
250
					if (preg_match('/^\d+/', $line)) {
251
						$field = preg_split("/\s+/",$line);
252
						$ip_addr = $field[0];
253
						$host_name = trim($field[1]);
254
						if (strcasecmp($add_host, $host_name) === 0) {
255
							$insert = false;
256
							break;
257
						}
841 richard 258
					}
2559 rexy 259
				}
2316 tom.houday 260
				if ($insert) {
2688 lucas.echa 261
					exec("sudo /usr/local/bin/alcasar-dns-local.sh --add $add_ip $add_host");
1959 richard 262
				}
841 richard 263
			}
2380 tom.houday 264
		}
2708 tom.houday 265
		header('Location: '.$_SERVER['PHP_SELF']);
266
		exit();
2316 tom.houday 267
	case 'del_host':
268
		foreach ($_POST as $key => $value) {
269
			if ($value == 'on') {
2559 rexy 270
				$del_host = explode ("|", $key);
271
				$del_ip = str_replace("_",".",$del_host[0]);
272
				exec("sudo /usr/local/bin/alcasar-dns-local.sh --del $del_ip $del_host[1]");
2316 tom.houday 273
			}
841 richard 274
		}
2708 tom.houday 275
		header('Location: '.$_SERVER['PHP_SELF']);
276
		exit();
2316 tom.houday 277
 
2709 tom.houday 278
	case 'dns_internal':	// Internal DNS
279
		// TODO : check @IP / domain before apply? (can break DNS server and shut down the Internet!)
280
		file_put_contents(CONF_FILE, str_replace('INT_DNS_IP='.$conf['INT_DNS_IP'],         'INT_DNS_IP='.trim($_POST['dns_internal_ip']),         file_get_contents(CONF_FILE)));
281
		file_put_contents(CONF_FILE, str_replace('INT_DNS_DOMAIN='.$conf['INT_DNS_DOMAIN'], 'INT_DNS_DOMAIN='.trim($_POST['dns_internal_domain']), file_get_contents(CONF_FILE)));
282
		if ($_POST['dns_internal_active'] === 'on') {
283
			exec('sudo /usr/local/bin/alcasar-dns-local.sh --on');
284
		} else {
285
			exec('sudo /usr/local/bin/alcasar-dns-local.sh --off');
286
		}
287
		header('Location: '.$_SERVER['PHP_SELF']);
288
		exit();
289
 
2316 tom.houday 290
	case 'default_cert':	// Restore default certificate
291
		exec('sudo alcasar-importcert.sh -d');
292
		break;
293
 
294
	case 'import_cert':	// Import certificate
2479 tom.houday 295
		$maxsize = 100000;
2316 tom.houday 296
		if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) {
297
			if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) {
2479 tom.houday 298
				if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && ((pathinfo($_FILES['crt']['name'])['extension'] == 'crt') || (pathinfo($_FILES['crt']['name'])['extension'] == 'cer'))) {
2316 tom.houday 299
					$dest = '/tmp/';
2380 tom.houday 300
					$scpath = '';
2479 tom.houday 301
					if (isset($_FILES['sc']) && ((pathinfo($_FILES['sc']['name'])['extension'] == 'crt') || (pathinfo($_FILES['sc']['name'])['extension'] == 'cer'))) {
2316 tom.houday 302
						$scpath = $dest.'server-chain.crt';
303
						move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
304
					}
2380 tom.houday 305
					$keypath = $dest.'alcasar.key';
306
					$crtpath = $dest.'alcasar.crt';
2316 tom.houday 307
					move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
308
					move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
309
					exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
2688 lucas.echa 310
					if (file_exists($crtpath)) unlink($crtpath);
311
					if (file_exists($keypath)) unlink($keypath);
2610 tom.houday 312
					if (file_exists($scpath))  unlink($scpath);
2316 tom.houday 313
				}
1959 richard 314
			}
315
		}
2316 tom.houday 316
		break;
2324 tom.houday 317
 
318
	case 'https_login':	// Set HTTPS login status
319
		if ($_POST['https_login'] === 'on') {
320
			exec('sudo /usr/local/bin/alcasar-https.sh --on');
321
		} else {
322
			exec('sudo /usr/local/bin/alcasar-https.sh --off');
323
		}
324
		header('Location: '.$_SERVER['PHP_SELF']);
325
		exit();
318 richard 326
}
327
 
2316 tom.houday 328
// Network changes
329
if ($choix === 'network_change') {
330
	$network_modification = false;
1733 richard 331
 
2316 tom.houday 332
	if (isset($_POST['dns1']) && (trim($_POST['dns1']) !== $conf['DNS1']) && preg_match($reg_ip, $_POST['dns1'])) {
333
		file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'], 'DNS1='.trim($_POST['dns1']), file_get_contents(CONF_FILE)));
334
		$network_modification = true;
318 richard 335
	}
2316 tom.houday 336
	if (isset($_POST['dns2']) && (trim($_POST['dns2']) !== $conf['DNS2']) && preg_match($reg_ip, $_POST['dns2'])) {
337
		file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'], 'DNS2='.trim($_POST['dns2']), file_get_contents(CONF_FILE)));
338
		$network_modification = true;
318 richard 339
	}
2316 tom.houday 340
	if (isset($_POST['ip_public']) && (trim($_POST['ip_public']) !== $conf['PUBLIC_IP']) && preg_match($reg_ip_cidr, $_POST['ip_public'])) {
341
		file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'], 'PUBLIC_IP='.trim($_POST['ip_public']), file_get_contents(CONF_FILE)));
342
		$network_modification = true;
343
	}
344
	if (isset($_POST['ip_gw']) && (trim($_POST['ip_gw']) !== $conf['GW']) && preg_match($reg_ip, $_POST['ip_gw'])) {
345
		file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'], 'GW='.trim($_POST['ip_gw']), file_get_contents(CONF_FILE)));
346
		$network_modification = true;
347
	}
348
	if (isset($_POST['ip_private']) && (trim($_POST['ip_private']) !== $conf['PRIVATE_IP']) && preg_match($reg_ip_cidr, $_POST['ip_private'])) {
349
		file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'], 'PRIVATE_IP='.trim($_POST['ip_private']), file_get_contents(CONF_FILE)));
350
		$network_modification = true;
351
	}
352
 
353
	if ($network_modification) {
354
		exec('sudo /usr/local/bin/alcasar-conf.sh -apply');
355
	}
356
 
357
	// Read CONF_FILE updated
358
	$file_conf = fopen(CONF_FILE, 'r');
359
	if (!$file_conf) {
360
		exit('Error opening the file '.CONF_FILE);
361
	}
362
	while (!feof($file_conf)) {
363
		$buffer = fgets($file_conf, 4096);
364
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
2450 tom.houday 365
			$tmp = explode('=', $buffer, 2);
2316 tom.houday 366
			$conf[trim($tmp[0])] = trim($tmp[1]);
367
		}
368
	}
369
	fclose($file_conf);
318 richard 370
}
2316 tom.houday 371
 
372
// Let's Encrypt actions
373
if ($choix === 'le_issueCert') {
374
	// TODO: check ndd & mail format
375
 
376
	$email      = $_POST['email'];
377
	$domainName = $_POST['domainname'];
378
 
379
	exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);
2688 lucas.echa 380
 
2316 tom.houday 381
	$cmdResponse = implode("<br>\n", $output);
1822 raphael.pi 382
}
2316 tom.houday 383
if ($choix === 'le_renewCert') {
384
	if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) {
385
		$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : '';
318 richard 386
 
2316 tom.houday 387
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
1822 raphael.pi 388
 
2316 tom.houday 389
		$cmdResponse = implode("<br>\n", $output);
390
	} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
391
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
392
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
393
	}
1822 raphael.pi 394
}
395
 
396
 
2316 tom.houday 397
// Read Let's Encrypt configuration file
398
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
399
if (!$file_conf_LE) {
400
	exit('Error opening the file '.LETS_ENCRYPT_FILE);
2299 tom.houday 401
}
2316 tom.houday 402
while (!feof($file_conf_LE)) {
403
	$buffer = fgets($file_conf_LE, 4096);
2299 tom.houday 404
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
2450 tom.houday 405
		$tmp = explode('=', $buffer, 2);
2316 tom.houday 406
		$LE_conf[trim($tmp[0])] = trim($tmp[1]);
1822 raphael.pi 407
	}
408
}
2316 tom.houday 409
fclose($file_conf_LE);
410
 
411
 
412
// Fonction de test de connectivité internet
413
function internetTest() {
414
	$host = 'www.google.fr'; # Google Test
415
	$port = '80';
416
 
417
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
418
		return false;
419
	} else {
420
		fclose($sock);
421
		return true;
422
	}
423
}
424
 
425
$internet_connected = InternetTest();
426
if ($internet_connected) {
2404 tom.houday 427
	$ch = curl_init('https://api.ipify.org/');
428
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
429
	$internet_publicIP = curl_exec($ch);
430
	curl_close($ch);
2316 tom.houday 431
} else {
432
	$internet_publicIP = '-.-.-.-';
433
}
434
 
435
 
436
// Network interfaces
437
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['EXTIF'], $conf['INTIF']];
438
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable);
439
 
440
// TODO: Pending the next version
441
$externalNetworks = [
442
	(object) [
443
		'interface' => $conf['EXTIF'],
444
		'ip'        => $conf['PUBLIC_IP'],
445
		'gateway'   => $conf['GW']
446
	]
447
];
448
$internalNetworks = [
449
	(object) [
450
		'interface' => $conf['INTIF'],
451
		'ip'        => $conf['PRIVATE_IP']
452
	]
453
];
454
 
1740 richard 455
?>
456
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2316 tom.houday 457
<html>
318 richard 458
<head>
2316 tom.houday 459
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
460
	<title><?= $l_network_title ?></title>
461
	<link rel="stylesheet" href="/css/style.css" type="text/css">
462
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
463
	<script src="/js/jquery.min.js"></script>
464
	<script src="/js/jquery.connections.js"></script>
465
	<script type="text/javascript">
466
	function MAC_Control(formulaire){
467
		// MAC control (upper case and '-' separator)
468
		var regex_mac = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/;
469
		if (regex_mac.test(document.forms[formulaire].add_mac.value)){
470
			document.forms[formulaire].add_mac.value = document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
471
			return true;
472
		} else {
473
			alert('Invalid MAC address');
474
			return false;
475
		}
1578 richard 476
	}
2316 tom.houday 477
	</script>
478
	<style>
479
	.network-configurator {
480
		width: 100%;
481
	}
482
	.network-configurator > * {
483
		display: inline-block;
484
		vertical-align: top;
485
		text-align: center;
486
	}
487
	.network-configurator > .internet, .network-configurator > .alcasar {
488
		width: 20%;
489
	}
490
	.network-configurator > .externals, .network-configurator > .internals {
491
		width: 30%;
492
	}
493
	.network-configurator .actions {
494
		position: absolute;
495
		background-color: #ddd;
496
		padding: 0 2px;
497
	}
498
	.network-configurator .actions a {
499
		text-decoration: none;
500
	}
501
	.network-configurator .actions a:hover {
502
		font-weight: bold;
503
	}
504
	.network-configurator > .alcasar .actions-externals {
505
		bottom: 0;
506
		left: 0;
507
		border-radius: 0 5px;
508
	}
509
	.network-configurator > .alcasar .actions-internals {
510
		bottom: 0;
511
		right: 0;
512
		border-radius: 5px 0;
513
	}
514
	.network-configurator .actions-network {
515
		top: 0;
516
		right: 0;
517
		border-radius: 0 5px;
518
	}
519
	.network-configurator .network-box {
520
		display: inline-block;
521
		min-height: 100px;
522
		margin: 5px;
523
		padding: 3px;
524
		text-align: left;
525
		background-color: #f7f3ef;
526
		position: relative;
527
		border-radius: 5px;
528
		border: 2px solid grey;
529
	}
530
	.network-configurator .network-connector {
531
		display: inline-block;
532
		position: absolute;
533
		top: 50%;
534
		margin-top: -5px;
535
		margin-left: -5px;
536
		width: 10px;
537
		height: 10px;
538
		border-radius: 5px;
539
		background-color: black;
540
	}
541
	.network-configurator .network-connector[data-connector-direction="left"] {
542
		border-radius: 5px 0px 0px 5px;
543
	}
544
	.network-configurator .network-connector[data-connector-direction="right"] {
545
		border-radius: 0px 5px 5px 0px;
546
	}
547
	.network-configurator div[data-network-type] {
548
		position: relative;
549
	}
550
	</style>
551
	<script>
552
	$(document).ready(function () {
553
		const interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>;
554
 
555
		const wireStyles = {
556
			available: { border: '5px double green' }
2325 tom.houday 557
		};
2316 tom.houday 558
 
559
		// Add external network
560
		$('.network-configurator .add-external-network').click(function (event) {
561
			event.preventDefault();
562
			let options = '';
563
			if (interfacesAvailable.length === 0) {
564
				options = '<option value=""></option>';
565
			} else {
566
				for (let i = 0; i < interfacesAvailable.length; i++) {
567
					options += '<option value="' + interfacesAvailable[i] + '">' + interfacesAvailable[i] + '</option>';
568
				}
569
			}
570
			$('.network-configurator .externals').append(' \
571
				<div data-network-type="external"> \
572
					<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div> \
573
					<div class="network-box"> \
574
						<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
575
						<label for="ext_interface_X"><?= 'Interface' ?></label> <select name="interface" id="ext_interface_X">' + options + '</select><br> \
576
						<label for="ext_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_public" id="ext_ip_X" value="" /><br> \
577
						<label for="ext_gateway_X"><?= $l_ip_router ?></label> <input style="width:120px" type="text" name="ip_gw" id="ext_gateway_X" value="" /> \
578
					</div> \
579
					<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div> \
580
				</div>');
581
			addWire($('div[data-network-type="external"]:last'));
582
		});
583
 
584
		// Add internal network
585
		$('.network-configurator .add-internal-network').click(function (event) {
586
			event.preventDefault();
587
			$('.network-configurator .internals').append(' \
588
					<div data-network-type="internal"> \
589
						<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div> \
590
						<div class="network-box"> \
591
							<div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> \
592
							<label for="int_interface_X"><?= 'Interface' ?></label> <select name="interface" id="int_interface_X" disabled><option value=""></option></select><br> \
593
							<label for="int_ip_X"><?= $l_ip_address ?></label> <input style="width:150px" type="text" name="ip_private" id="int_ip_X" value="" /><br> \
594
						</div> \
595
					</div>');
596
			addWire($('div[data-network-type="internal"]:last'));
597
		});
598
 
599
		// Remove network
600
		$('.network-configurator').on('click', '.remove-network', function (event) {
601
			event.preventDefault();
602
			$(this).parent().parent().parent().fadeOut(200, function() {
603
				const networkType = $(this).data('networkType');
604
				$(this).remove();
605
 
606
				// Update wires
607
				if (networkType === 'external') {
608
					$('div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]').connections('update');
609
					$('div[data-network-type="alcasar"]>div.network-connector[data-connector-network="external"]').connections('update');
610
				} else if (networkType === 'internal') {
611
					$('div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]').connections('update');
612
				}
613
			});
614
		});
615
 
616
		const addWire = function (network) {
617
			const networkType = network.data('networkType');
618
			if (networkType === 'external') {
619
				$().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' });
620
				$().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' });
621
			} else if (networkType === 'internal') {
622
				$().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' });
623
			}
2325 tom.houday 624
		};
2316 tom.houday 625
 
2325 tom.houday 626
		window.addEventListener('resize', function () {
627
			$('div.network-connector[data-connector-network]').connections('update');
628
		});
629
 
2316 tom.houday 630
		// Add wires to existing networks
631
		$('div[data-network-type="external"]').add('div[data-network-type="internal"]').each(function (index, element) {
632
			addWire($(this));
2325 tom.houday 633
		});
2316 tom.houday 634
	});
635
	</script>
318 richard 636
</head>
637
<body>
2316 tom.houday 638
	<div class="panel">
639
		<div class="panel-header"><?= $l_network_title ?></div>
640
		<div class="panel-body">
641
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
642
				<div class="network-configurator">
643
					<div class="internet">
644
						<div data-network-type="internet">
645
							<div class="network-box">
646
								<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br>
647
								<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
648
								<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
649
								<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
650
							</div>
651
							<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div>
652
						</div>
653
					</div><div class="externals">
654
						<?php foreach ($externalNetworks as $index => $network): ?>
655
							<div data-network-type="external">
656
								<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div>
657
								<div class="network-box">
658
									<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
659
									<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>
660
									<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>
661
									<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 ?>" />
662
								</div>
663
								<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div>
664
							</div>
665
						<? endforeach; ?>
666
					</div><div class="alcasar">
667
						<div data-network-type="alcasar">
668
							<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div>
669
							<div class="network-box">
670
								<!-- <div class="actions actions-externals">
671
									<div><a href="#" class="add-external-network" title="Ajouter un réseau externe">+</a></div>
672
								</div> -->
673
								<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div>
674
								<!-- <div class="actions actions-internals">
675
									<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div>
676
									<div><a href="#" class="add-internal-wifi-network">++</a></div>
677
								</div> -->
678
							</div>
679
							<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div>
680
						</div>
681
					</div><div class="internals">
682
						<?php foreach ($internalNetworks as $network): ?>
683
							<div data-network-type="internal">
684
								<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div>
685
								<div class="network-box">
686
									<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
687
									<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>
688
									<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>
689
								</div>
690
							</div>
691
						<? endforeach; ?>
692
					</div>
693
				</div>
694
				<hr>
695
				<div style="text-align: center; margin: 5px">
696
					<input type="hidden" name="choix" value="network_change">
697
					<input type="submit" value="<?= $l_apply ?>">
698
				</div>
699
			</form>
700
		</div>
701
	</div>
702
	<br>
703
 
2304 tom.houday 704
<table width="100%" cellspacing="0" cellpadding="0" border="0">
2316 tom.houday 705
	<tr><th><?= $l_dhcp_title?></th></tr>
318 richard 706
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
707
</table>
2304 tom.houday 708
<table width="100%" cellspacing="0" cellpadding="5" border="1">
2316 tom.houday 709
	<tr><td colspan="2" valign="middle" align="left">
710
	<center><h3><?= $l_dhcp_state ?> : <?= ${'l_DHCP_'.$conf['DHCP']} ?></h3></center>
711
	<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
2324 tom.houday 712
		<select name="choix">
2316 tom.houday 713
			<option value="DHCP_Off"<?= ((!strcmp($conf['DHCP'], 'off')) ? ' selected' : '') ?>><?= $l_DHCP_off ?></option>
714
			<option value="DHCP_On"<?= ((!strcmp($conf['DHCP'], 'on')) ? ' selected' : '') ?>><?= $l_DHCP_on ?></option>
715
		</select>
716
		<input type="submit" value="<?= $l_apply ?>">
717
		<br><?= $l_DHCP_off_explain ?>
718
	</form>
719
	</td></tr>
720
 
2708 tom.houday 721
<?php if ($conf['DHCP'] === 'on'): ?>
722
	<tr><td colspan="2" align="center"><?= $l_static_dhcp_title ?></td></tr>
723
	<tr><td width="50%" align="center" valign="middle">
724
		<form action="network.php" method="POST">
2316 tom.houday 725
		<table cellspacing="2" cellpadding="3" border="1">
2708 tom.houday 726
		<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info<th><?= $l_del ?></th></tr>
2316 tom.houday 727
		<?php
2708 tom.houday 728
		// Read the "ether" file
729
		exec('sudo /sbin/ip link show '.escapeshellarg($conf["INTIF"]), $output);
730
		$detail = explode(' ', $output[1]);
731
		$intif_mac_addr = strtoupper(str_replace(':', '-', $detail[5]));
732
		unset($output); unset($detail);
2316 tom.houday 733
		$line_exist = false;
2708 tom.houday 734
		$tab = file(ETHERS_INFO_FILE);
735
		if ($tab) { // le fichier n'est pas vide
2316 tom.houday 736
			foreach ($tab as $line) {
2708 tom.houday 737
				$fields = explode(' ', $line);
738
				$mac_addr = $fields[0];
739
				$ip_addr  = $fields[1];
2713 tom.houday 740
				$info     = (isset($fields[2])) ? implode(' ', array_slice($fields, 2)) : ' ';
2708 tom.houday 741
 
742
				echo '<tr>';
743
				echo "<td>$mac_addr</td>";
744
				echo "<td>$ip_addr</td>";
745
				if ($mac_addr !== $intif_mac_addr) {
746
					echo '<td>'.ltrim($info, '#').'</td>';
747
					echo "<td><input type=\"checkbox\" name=\"$mac_addr\"></td>";
748
					$line_exist=True;
749
				} else {
750
					echo '<td>ALCASAR</td>';
751
					echo '<td></td>';
2316 tom.houday 752
				}
2708 tom.houday 753
				echo '</tr>';
1959 richard 754
			}
755
		}
2316 tom.houday 756
		?>
757
		</table>
758
		<?php if ($line_exist): ?>
2708 tom.houday 759
			<input type="hidden" name="choix" value="del_mac">
2316 tom.houday 760
			<input type="submit" value="<?= $l_apply ?>">
761
		<?php endif; ?>
762
		</form>
2708 tom.houday 763
	</td><td width="50%" valign="middle" align="center">
764
		<form name="new_mac" action="network.php" method="POST">
765
			<table cellspacing="2" cellpadding="3" border="1">
766
				<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info</th><td></td></tr>
767
				<tr><td>Ex. : 12-2F-36-A4-DF-43</td><td>Ex. : 192.168.182.10</td><td>Ex. : Switch<td></td></tr>
768
				<tr><td><input type="text" name="add_mac" size="17"></td>
769
				<td><input type="text" name="add_ip" size="10"></td>
770
				<td><input type="text" name="info" size="10"></td>
771
				<td>
772
					<input type="hidden" name="choix" value="new_mac">
773
					<input type="submit" class="button" value="<?= $l_add_to_list ?>" onclick="return MAC_Control('new_mac');">
774
				</td>
775
			</tr></table>
2316 tom.houday 776
		</form>
2708 tom.houday 777
	</td></tr>
778
<?php else: ?>
779
	<tr><td colspan="2" align="center"><?= $l_dhcp_relay ?></td></tr>
780
	<tr>
781
		<td colspan="2" align="center">
782
			<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
783
			<table cellspacing="2" cellpadding="3" border="1">
784
			<tr>
785
				<th><label for="dhcp_relay_ip"><?= $l_dhcp_relay_local_ip ?></label></th><td><input type="text" name="dhcp_relay_ip" id="dhcp_relay_ip" value="<?= $conf['RELAY_DHCP_IP'] ?>" size="32"></td>
786
			</tr>
787
			<tr>
788
				<th><label for="dhcp_relay_ext_ip"><?= $l_dhcp_relay_ip ?></label></th><td><input type="text" name="dhcp_relay_ext_ip" id="dhcp_relay_ext_ip" value="<?= $conf['EXT_DHCP_IP'] ?>" size="32"></td>
789
			</tr>
790
			<tr>
791
				<th><label for="dhcp_relay_port"><?= $l_dhcp_relay_port ?></label></th><td><input type="text" name="dhcp_relay_port" id="dhcp_relay_port" value="<?= $conf['RELAY_DHCP_PORT'] ?>" size="32"></td>
792
			</tr>
793
			</table>
794
			<input type="hidden" name="choix" value="dhcp_relay">
795
			<input type="submit" value="<?= $l_apply ?>">
796
			</form>
797
		</td>
798
	</tr>
799
<?php endif; ?>
1959 richard 800
</table>
2316 tom.houday 801
<br>
802
 
2304 tom.houday 803
<table width="100%" cellspacing="0" cellpadding="0" border="0">
2709 tom.houday 804
	<tr><th><?= $l_dns_title ?></th></tr>
805
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
806
</table>
807
<table width="100%" cellspacing="0" cellpadding="5" border="1">
808
	<tr><td colspan="2" align="center"><?= $l_local_dns ?></td></tr>
809
	<tr>
810
		<td width="50%" align="center">
811
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
812
			<table cellspacing="2" cellpadding="3" border="1">
813
			<tr><th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><th><?= $l_del ?></th></tr>
814
			<?php
815
			// Read the "dns_local" file
816
			$line_exist = false;
817
			$tab = file(DNS_LOCAL_FILE);
818
			if ($tab) { // not empty
819
				foreach ($tab as $line) {
820
					if (preg_match ('/^\d+/', $line)) { # begin with one or several digit
821
						$line_exist = true;
822
						$field = preg_split("/\s+/",$line); # split with one or several whitespace (or tab)
823
						$ip_addr   = $field[0];
824
						$host_name = $field[1];
825
						echo "<tr><td>$ip_addr</td>";
826
						echo "<td>$host_name</td>";
827
						if (($ip_addr == "127.0.0.1")|($host_name == "alcasar")) {
828
							echo "<td>";}
829
						else {
830
							echo "<td><input type=\"checkbox\" name=\"$ip_addr|$host_name\">";
831
						}
832
						echo "</td></tr>";
833
					}
834
				}
835
			}
836
			if (!$line_exist) {
837
				echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
838
			}
839
			?>
840
			</table>
841
			<?php if ($line_exist): ?>
842
				<input type="hidden" name="choix" value="del_host">
843
				<input type="submit" value="<?= $l_apply ?>">
844
			<?php endif; ?>
845
			</form>
846
		</td>
847
		<td width="50%" valign="middle" align="center">
848
			<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
849
			<table cellspacing="2" cellpadding="3" border="1">
850
			<tr>
851
				<th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><td></td>
852
			</tr>
853
			<tr>
854
				<td>Ex. : 192.168.182.10</td><td>Ex. : my_nas</td><td></td>
855
			</tr>
856
			<tr>
857
				<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
858
				<td><input type="text" name="add_host" size="17"></td>
859
				<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
860
			</tr>
861
			</table>
862
			</form>
863
		</td>
864
	</tr>
865
	<tr><td colspan="2" align="center"><?= $l_dns_internal ?></td></tr>
866
	<tr>
867
		<td colspan="2" align="center">
868
			<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
869
			<table cellspacing="2" cellpadding="3" border="1">
870
			<tr>
871
				<th><?= $l_enabled ?></th>
872
				<td>
873
					<select name="dns_internal_active">
874
						<option value="on"<?=  (($conf['INT_DNS_ACTIVE'] === 'on')  ? ' selected' : '') ?>><?= $l_yes ?></option>
875
						<option value="off"<?= (($conf['INT_DNS_ACTIVE'] === 'off') ? ' selected' : '') ?>><?= $l_no ?></option>
876
					</select>
877
				</td>
878
			</tr>
879
			<tr>
880
				<th><?= $l_ip_address ?></th><td><input type="text" name="dns_internal_ip" value="<?= $conf['INT_DNS_IP'] ?>" size="32"></td>
881
			</tr>
882
			<tr>
883
				<th><?= $l_host_name ?></th><td><input type="text" name="dns_internal_domain" value="<?= $conf['INT_DNS_DOMAIN'] ?>" size="32"></td>
884
			</tr>
885
			</table>
886
			<input type="hidden" name="choix" value="dns_internal">
887
			<input type="submit" value="<?= $l_apply ?>">
888
			</form>
889
		</td>
890
	</tr>
891
</table>
892
<br>
893
 
894
<table width="100%" cellspacing="0" cellpadding="0" border="0">
2610 tom.houday 895
	<tr><th><?= $l_ssl_title ?></th></tr>
2609 rexy 896
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
897
</table>
898
<table width="100%" cellspacing="0" cellpadding="5" border="1">
899
	<tr><td valign="middle" align="left">
900
		<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
901
		<input type="hidden" name="choix" value="https_login">
902
		<select name="https_login">
903
			<option value="on"<?=  (($conf['HTTPS_LOGIN'] === 'on')  ? ' selected' : '') ?>><?= $l_yes ?></option>
904
			<option value="off"<?= (($conf['HTTPS_LOGIN'] === 'off') ? ' selected' : '') ?>><?= $l_no ?></option>
905
		</select>
906
		<input type="submit" value="<?= $l_apply ?>"><br>
907
		</form>
908
		<br>
909
	</td></tr>
910
</table>
911
<br>
912
 
913
<table width="100%" cellspacing="0" cellpadding="0" border="0">
2316 tom.houday 914
	<tr><th><?= $l_import_cert ?></th></tr>
1710 richard 915
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
916
</table>
2304 tom.houday 917
<table width="100%" cellspacing="0" cellpadding="5" border="1">
918
	<tr>
2324 tom.houday 919
		<td width="50%" valign="top">
2297 tom.houday 920
			<?php
921
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
922
 
923
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
924
			$domain               = $certificateInfos['subject']['CN'];
925
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
926
			$CAdomain             = $certificateInfos['issuer']['CN'];
927
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
928
			?>
929
			<h3><?= $l_current_certificate ?></h3>
2326 tom.houday 930
			<?= $l_cert_expiration ?> <?= $cert_expiration_date ?><br>
931
			<?= $l_cert_commonname ?> <?= $domain ?><br>
932
			<?= $l_cert_organization ?> <?= $organization ?><br/>
2297 tom.houday 933
			<h4><?=  $l_validated ?></h4>
2326 tom.houday 934
			<?= $l_cert_commonname ?> <?= $CAdomain ?><br>
935
			<?= $l_cert_organization ?> <?= $CAorganization ?><br>
2324 tom.houday 936
		</td>
2609 rexy 937
		<td width="50%" valign="center">
938
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
939
				<input type="hidden" name="choix" value="default_cert">
940
				<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' : '' ?>>
941
			</form>
942
		</td>
2324 tom.houday 943
	</tr>
944
	<tr>
945
		<td width="50%" valign="top">
2326 tom.houday 946
			<h3><?= $l_upload_certificate ?></h3>
2324 tom.houday 947
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
948
				<?= $l_private_key;?> <input type="file" name="key"><br>
949
				<?= $l_certificate;?> <input type="file" name="crt"><br>
950
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
951
				<input type="hidden" name="choix" value="import_cert">
952
				<input type="submit" value="<?= $l_import ?>">
2297 tom.houday 953
			</form>
954
		</td>
2304 tom.houday 955
		<td width="50%" valign="top">
956
			<?php
957
			// Get step
958
			if (empty($LE_conf['domainRequest'])) {
959
				$step = 1;
960
			} else if (!empty($LE_conf['challenge'])) {
961
				$step = 2;
962
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
963
				$step = 3;
964
			} else {
965
				$step = 1;
966
			}
967
			?>
2326 tom.houday 968
			<h3><?= $l_le_integration ?></h3>
2324 tom.houday 969
			<?php if ($step === 1): ?>
2316 tom.houday 970
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
971
					<input type="hidden" name="choix" value="le_issueCert">
2326 tom.houday 972
					<?= $l_le_status ?> <?= $l_disabled ?><br>
973
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
974
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
975
					<input type="submit" name="issue" value="<?= $l_send ?>"><br>
2304 tom.houday 976
				</form>
977
			<?php elseif ($step === 2): ?>
2316 tom.houday 978
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
979
					<input type="hidden" name="choix" value="le_renewCert">
2326 tom.houday 980
					<?= $l_le_status ?> <?= $l_pending_validation ?><br>
981
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
982
					<?= $l_le_ask_on ?> <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br>
983
					<?= $l_le_dns_entry_txt ?> "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
984
					<?= $l_le_challenge ?> "<?= $LE_conf['challenge'] ?>"<br>
985
					<input type="submit" name="recheck" value="<?= $l_recheck ?>"> <input type="submit" name="cancel" value="<?= $l_cancel ?>"><br>
2304 tom.houday 986
				</form>
987
			<?php elseif ($step === 3): ?>
2316 tom.houday 988
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
989
					<input type="hidden" name="choix" value="le_renewCert">
2326 tom.houday 990
					<?= $l_le_status ?> <?= $l_enabled ?><br>
991
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
992
					<?= $l_le_api ?>  <?= $LE_conf['dnsapi'] ?><br>
993
					<?= $l_le_next_renewal ?> <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
2304 tom.houday 994
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
2326 tom.houday 995
						<input type="submit" name="recheck" value="<?= $l_renew ?>"><br>
2304 tom.houday 996
					<?php else: ?>
2326 tom.houday 997
						<input type="submit" name="recheck_force" value="<?= $l_renew_force ?>"><br>
2304 tom.houday 998
					<?php endif; ?>
999
				</form>
1000
			<?php endif; ?>
1001
			<?php if (isset($cmdResponse)): ?>
1002
				<p><?= $cmdResponse ?></p>
1003
			<?php endif; ?>
1004
		</td>
1710 richard 1005
	</tr>
1006
</table>
318 richard 1007
</body>
1008
</html>