Subversion Repositories ALCASAR

Rev

Rev 2404 | Rev 2479 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

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