Subversion Repositories ALCASAR

Rev

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

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