Subversion Repositories ALCASAR

Rev

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

Rev 2380 Rev 2404
1
<?php
1
<?php
2
# $Id: network.php 2380 2017-08-17 15:59:54Z tom.houdayer $
2
# $Id: network.php 2404 2017-08-28 18:10:38Z 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})$/';
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);
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);
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/');
-
 
405
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
404
	$internet_publicIP = file_get_contents('http://ipecho.net/plain');
406
	$internet_publicIP = curl_exec($ch);
-
 
407
	curl_close($ch);
405
} else {
408
} else {
406
	$internet_publicIP = '-.-.-.-';
409
	$internet_publicIP = '-.-.-.-';
407
}
410
}
408
 
411
 
409
 
412
 
410
// Network interfaces
413
// Network interfaces
411
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['EXTIF'], $conf['INTIF']];
414
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['EXTIF'], $conf['INTIF']];
412
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);
413
 
416
 
414
// TODO: Pending the next version
417
// TODO: Pending the next version
415
$externalNetworks = [
418
$externalNetworks = [
416
	(object) [
419
	(object) [
417
		'interface' => $conf['EXTIF'],
420
		'interface' => $conf['EXTIF'],
418
		'ip'        => $conf['PUBLIC_IP'],
421
		'ip'        => $conf['PUBLIC_IP'],
419
		'gateway'   => $conf['GW']
422
		'gateway'   => $conf['GW']
420
	]
423
	]
421
];
424
];
422
$internalNetworks = [
425
$internalNetworks = [
423
	(object) [
426
	(object) [
424
		'interface' => $conf['INTIF'],
427
		'interface' => $conf['INTIF'],
425
		'ip'        => $conf['PRIVATE_IP']
428
		'ip'        => $conf['PRIVATE_IP']
426
	]
429
	]
427
];
430
];
428
 
431
 
429
?>
432
?>
430
<!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">
431
<html>
434
<html>
432
<head>
435
<head>
433
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
436
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
434
	<title><?= $l_network_title ?></title>
437
	<title><?= $l_network_title ?></title>
435
	<link rel="stylesheet" href="/css/style.css" type="text/css">
438
	<link rel="stylesheet" href="/css/style.css" type="text/css">
436
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
439
	<link rel="stylesheet" href="/css/acc.css" type="text/css">
437
	<script src="/js/jquery.min.js"></script>
440
	<script src="/js/jquery.min.js"></script>
438
	<script src="/js/jquery.connections.js"></script>
441
	<script src="/js/jquery.connections.js"></script>
439
	<script type="text/javascript">
442
	<script type="text/javascript">
440
	function MAC_Control(formulaire){
443
	function MAC_Control(formulaire){
441
		// MAC control (upper case and '-' separator)
444
		// MAC control (upper case and '-' separator)
442
		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}$/;
443
		if (regex_mac.test(document.forms[formulaire].add_mac.value)){
446
		if (regex_mac.test(document.forms[formulaire].add_mac.value)){
444
			document.forms[formulaire].add_mac.value = document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
447
			document.forms[formulaire].add_mac.value = document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
445
			return true;
448
			return true;
446
		} else {
449
		} else {
447
			alert('Invalid MAC address');
450
			alert('Invalid MAC address');
448
			return false;
451
			return false;
449
		}
452
		}
450
	}
453
	}
451
	</script>
454
	</script>
452
	<style>
455
	<style>
453
	.network-configurator {
456
	.network-configurator {
454
		width: 100%;
457
		width: 100%;
455
	}
458
	}
456
	.network-configurator > * {
459
	.network-configurator > * {
457
		display: inline-block;
460
		display: inline-block;
458
		vertical-align: top;
461
		vertical-align: top;
459
		text-align: center;
462
		text-align: center;
460
	}
463
	}
461
	.network-configurator > .internet, .network-configurator > .alcasar {
464
	.network-configurator > .internet, .network-configurator > .alcasar {
462
		width: 20%;
465
		width: 20%;
463
	}
466
	}
464
	.network-configurator > .externals, .network-configurator > .internals {
467
	.network-configurator > .externals, .network-configurator > .internals {
465
		width: 30%;
468
		width: 30%;
466
	}
469
	}
467
	.network-configurator .actions {
470
	.network-configurator .actions {
468
		position: absolute;
471
		position: absolute;
469
		background-color: #ddd;
472
		background-color: #ddd;
470
		padding: 0 2px;
473
		padding: 0 2px;
471
	}
474
	}
472
	.network-configurator .actions a {
475
	.network-configurator .actions a {
473
		text-decoration: none;
476
		text-decoration: none;
474
	}
477
	}
475
	.network-configurator .actions a:hover {
478
	.network-configurator .actions a:hover {
476
		font-weight: bold;
479
		font-weight: bold;
477
	}
480
	}
478
	.network-configurator > .alcasar .actions-externals {
481
	.network-configurator > .alcasar .actions-externals {
479
		bottom: 0;
482
		bottom: 0;
480
		left: 0;
483
		left: 0;
481
		border-radius: 0 5px;
484
		border-radius: 0 5px;
482
	}
485
	}
483
	.network-configurator > .alcasar .actions-internals {
486
	.network-configurator > .alcasar .actions-internals {
484
		bottom: 0;
487
		bottom: 0;
485
		right: 0;
488
		right: 0;
486
		border-radius: 5px 0;
489
		border-radius: 5px 0;
487
	}
490
	}
488
	.network-configurator .actions-network {
491
	.network-configurator .actions-network {
489
		top: 0;
492
		top: 0;
490
		right: 0;
493
		right: 0;
491
		border-radius: 0 5px;
494
		border-radius: 0 5px;
492
	}
495
	}
493
	.network-configurator .network-box {
496
	.network-configurator .network-box {
494
		display: inline-block;
497
		display: inline-block;
495
		min-height: 100px;
498
		min-height: 100px;
496
		margin: 5px;
499
		margin: 5px;
497
		padding: 3px;
500
		padding: 3px;
498
		text-align: left;
501
		text-align: left;
499
		background-color: #f7f3ef;
502
		background-color: #f7f3ef;
500
		position: relative;
503
		position: relative;
501
		border-radius: 5px;
504
		border-radius: 5px;
502
		border: 2px solid grey;
505
		border: 2px solid grey;
503
	}
506
	}
504
	.network-configurator .network-connector {
507
	.network-configurator .network-connector {
505
		display: inline-block;
508
		display: inline-block;
506
		position: absolute;
509
		position: absolute;
507
		top: 50%;
510
		top: 50%;
508
		margin-top: -5px;
511
		margin-top: -5px;
509
		margin-left: -5px;
512
		margin-left: -5px;
510
		width: 10px;
513
		width: 10px;
511
		height: 10px;
514
		height: 10px;
512
		border-radius: 5px;
515
		border-radius: 5px;
513
		background-color: black;
516
		background-color: black;
514
	}
517
	}
515
	.network-configurator .network-connector[data-connector-direction="left"] {
518
	.network-configurator .network-connector[data-connector-direction="left"] {
516
		border-radius: 5px 0px 0px 5px;
519
		border-radius: 5px 0px 0px 5px;
517
	}
520
	}
518
	.network-configurator .network-connector[data-connector-direction="right"] {
521
	.network-configurator .network-connector[data-connector-direction="right"] {
519
		border-radius: 0px 5px 5px 0px;
522
		border-radius: 0px 5px 5px 0px;
520
	}
523
	}
521
	.network-configurator div[data-network-type] {
524
	.network-configurator div[data-network-type] {
522
		position: relative;
525
		position: relative;
523
	}
526
	}
524
	</style>
527
	</style>
525
	<script>
528
	<script>
526
	$(document).ready(function () {
529
	$(document).ready(function () {
527
		const interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>;
530
		const interfacesAvailable = <?= ((!empty($interfacesAvailable)) ? "['".implode("', '", $interfacesAvailable)."']" : '[]') ?>;
528
 
531
 
529
		const wireStyles = {
532
		const wireStyles = {
530
			available: { border: '5px double green' }
533
			available: { border: '5px double green' }
531
		};
534
		};
532
 
535
 
533
		// Add external network
536
		// Add external network
534
		$('.network-configurator .add-external-network').click(function (event) {
537
		$('.network-configurator .add-external-network').click(function (event) {
535
			event.preventDefault();
538
			event.preventDefault();
536
			let options = '';
539
			let options = '';
537
			if (interfacesAvailable.length === 0) {
540
			if (interfacesAvailable.length === 0) {
538
				options = '<option value=""></option>';
541
				options = '<option value=""></option>';
539
			} else {
542
			} else {
540
				for (let i = 0; i < interfacesAvailable.length; i++) {
543
				for (let i = 0; i < interfacesAvailable.length; i++) {
541
					options += '<option value="' + interfacesAvailable[i] + '">' + interfacesAvailable[i] + '</option>';
544
					options += '<option value="' + interfacesAvailable[i] + '">' + interfacesAvailable[i] + '</option>';
542
				}
545
				}
543
			}
546
			}
544
			$('.network-configurator .externals').append(' \
547
			$('.network-configurator .externals').append(' \
545
				<div data-network-type="external"> \
548
				<div data-network-type="external"> \
546
					<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> \
547
					<div class="network-box"> \
550
					<div class="network-box"> \
548
						<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> \
549
						<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> \
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> \
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> \
551
						<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="" /> \
552
					</div> \
555
					</div> \
553
					<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> \
554
				</div>');
557
				</div>');
555
			addWire($('div[data-network-type="external"]:last'));
558
			addWire($('div[data-network-type="external"]:last'));
556
		});
559
		});
557
 
560
 
558
		// Add internal network
561
		// Add internal network
559
		$('.network-configurator .add-internal-network').click(function (event) {
562
		$('.network-configurator .add-internal-network').click(function (event) {
560
			event.preventDefault();
563
			event.preventDefault();
561
			$('.network-configurator .internals').append(' \
564
			$('.network-configurator .internals').append(' \
562
					<div data-network-type="internal"> \
565
					<div data-network-type="internal"> \
563
						<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> \
564
						<div class="network-box"> \
567
						<div class="network-box"> \
565
							<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> \
566
							<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> \
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> \
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> \
568
						</div> \
571
						</div> \
569
					</div>');
572
					</div>');
570
			addWire($('div[data-network-type="internal"]:last'));
573
			addWire($('div[data-network-type="internal"]:last'));
571
		});
574
		});
572
 
575
 
573
		// Remove network
576
		// Remove network
574
		$('.network-configurator').on('click', '.remove-network', function (event) {
577
		$('.network-configurator').on('click', '.remove-network', function (event) {
575
			event.preventDefault();
578
			event.preventDefault();
576
			$(this).parent().parent().parent().fadeOut(200, function() {
579
			$(this).parent().parent().parent().fadeOut(200, function() {
577
				const networkType = $(this).data('networkType');
580
				const networkType = $(this).data('networkType');
578
				$(this).remove();
581
				$(this).remove();
579
 
582
 
580
				// Update wires
583
				// Update wires
581
				if (networkType === 'external') {
584
				if (networkType === 'external') {
582
					$('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');
583
					$('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');
584
				} else if (networkType === 'internal') {
587
				} else if (networkType === 'internal') {
585
					$('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');
586
				}
589
				}
587
			});
590
			});
588
		});
591
		});
589
 
592
 
590
		const addWire = function (network) {
593
		const addWire = function (network) {
591
			const networkType = network.data('networkType');
594
			const networkType = network.data('networkType');
592
			if (networkType === 'external') {
595
			if (networkType === 'external') {
593
				$().connections({ from: 'div[data-network-type="internet"]>div.network-connector[data-connector-network="internet"]', to: 'div[data-network-type="external"]>div.network-connector[data-connector-network="internet"]:last', css: wireStyles.available, within: 'div[data-network-type="external"]:last' });
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' });
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' });
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' });
595
			} else if (networkType === 'internal') {
598
			} else if (networkType === 'internal') {
596
				$().connections({ from: 'div[data-network-type="alcasar"]>div.network-connector[data-connector-network="internal"]', to: 'div[data-network-type="internal"]>div.network-connector[data-connector-network="internal"]:last', css: wireStyles.available, within: 'div[data-network-type="internal"]:last' });
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' });
597
			}
600
			}
598
		};
601
		};
599
 
602
 
600
		window.addEventListener('resize', function () {
603
		window.addEventListener('resize', function () {
601
			$('div.network-connector[data-connector-network]').connections('update');
604
			$('div.network-connector[data-connector-network]').connections('update');
602
		});
605
		});
603
 
606
 
604
		// Add wires to existing networks
607
		// Add wires to existing networks
605
		$('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) {
606
			addWire($(this));
609
			addWire($(this));
607
		});
610
		});
608
	});
611
	});
609
	</script>
612
	</script>
610
</head>
613
</head>
611
<body>
614
<body>
612
	<div class="panel">
615
	<div class="panel">
613
		<div class="panel-header"><?= $l_network_title ?></div>
616
		<div class="panel-header"><?= $l_network_title ?></div>
614
		<div class="panel-body">
617
		<div class="panel-body">
615
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
618
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="post">
616
				<div class="network-configurator">
619
				<div class="network-configurator">
617
					<div class="internet">
620
					<div class="internet">
618
						<div data-network-type="internet">
621
						<div data-network-type="internet">
619
							<div class="network-box">
622
							<div class="network-box">
620
								<?= $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>
621
								<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
624
								<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
622
								<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
625
								<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
623
								<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
626
								<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
624
							</div>
627
							</div>
625
							<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>
626
						</div>
629
						</div>
627
					</div><div class="externals">
630
					</div><div class="externals">
628
						<?php foreach ($externalNetworks as $index => $network): ?>
631
						<?php foreach ($externalNetworks as $index => $network): ?>
629
							<div data-network-type="external">
632
							<div data-network-type="external">
630
								<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>
631
								<div class="network-box">
634
								<div class="network-box">
632
									<!-- <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> -->
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>
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>
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>
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>
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 ?>" />
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 ?>" />
636
								</div>
639
								</div>
637
								<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>
638
							</div>
641
							</div>
639
						<? endforeach; ?>
642
						<? endforeach; ?>
640
					</div><div class="alcasar">
643
					</div><div class="alcasar">
641
						<div data-network-type="alcasar">
644
						<div data-network-type="alcasar">
642
							<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>
643
							<div class="network-box">
646
							<div class="network-box">
644
								<!-- <div class="actions actions-externals">
647
								<!-- <div class="actions actions-externals">
645
									<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>
646
								</div> -->
649
								</div> -->
647
								<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>
648
								<!-- <div class="actions actions-internals">
651
								<!-- <div class="actions actions-internals">
649
									<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>
650
									<div><a href="#" class="add-internal-wifi-network">++</a></div>
653
									<div><a href="#" class="add-internal-wifi-network">++</a></div>
651
								</div> -->
654
								</div> -->
652
							</div>
655
							</div>
653
							<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>
654
						</div>
657
						</div>
655
					</div><div class="internals">
658
					</div><div class="internals">
656
						<?php foreach ($internalNetworks as $network): ?>
659
						<?php foreach ($internalNetworks as $network): ?>
657
							<div data-network-type="internal">
660
							<div data-network-type="internal">
658
								<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>
659
								<div class="network-box">
662
								<div class="network-box">
660
									<!-- <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> -->
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>
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>
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>
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>
663
								</div>
666
								</div>
664
							</div>
667
							</div>
665
						<? endforeach; ?>
668
						<? endforeach; ?>
666
					</div>
669
					</div>
667
				</div>
670
				</div>
668
				<hr>
671
				<hr>
669
				<div style="text-align: center; margin: 5px">
672
				<div style="text-align: center; margin: 5px">
670
					<input type="hidden" name="choix" value="network_change">
673
					<input type="hidden" name="choix" value="network_change">
671
					<input type="submit" value="<?= $l_apply ?>">
674
					<input type="submit" value="<?= $l_apply ?>">
672
				</div>
675
				</div>
673
			</form>
676
			</form>
674
		</div>
677
		</div>
675
	</div>
678
	</div>
676
	<br>
679
	<br>
677
 
680
 
678
<table width="100%" cellspacing="0" cellpadding="0" border="0">
681
<table width="100%" cellspacing="0" cellpadding="0" border="0">
679
	<tr><th><?= $l_dhcp_title?></th></tr>
682
	<tr><th><?= $l_dhcp_title?></th></tr>
680
	<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>
681
</table>
684
</table>
682
<table width="100%" cellspacing="0" cellpadding="5" border="1">
685
<table width="100%" cellspacing="0" cellpadding="5" border="1">
683
	<tr><td colspan="2" valign="middle" align="left">
686
	<tr><td colspan="2" valign="middle" align="left">
684
	<center><h3><?= $l_dhcp_state ?> : <?= ${'l_DHCP_'.$conf['DHCP']} ?></h3></center>
687
	<center><h3><?= $l_dhcp_state ?> : <?= ${'l_DHCP_'.$conf['DHCP']} ?></h3></center>
685
	<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
688
	<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
686
		<select name="choix">
689
		<select name="choix">
687
			<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>
688
			<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>
689
		</select>
692
		</select>
690
		<input type="submit" value="<?= $l_apply ?>">
693
		<input type="submit" value="<?= $l_apply ?>">
691
		<br><?= $l_DHCP_off_explain ?>
694
		<br><?= $l_DHCP_off_explain ?>
692
	</form>
695
	</form>
693
	</td></tr>
696
	</td></tr>
694
 
697
 
695
	<?php
698
	<?php
696
	if ($conf['DHCP'] === 'on') {
699
	if ($conf['DHCP'] === 'on') {
697
		require('network2.php');
700
		require('network2.php');
698
	}
701
	}
699
	?>
702
	?>
700
</table>
703
</table>
701
<br>
704
<br>
702
 
705
 
703
<table width="100%" cellspacing="0" cellpadding="0" border="0">
706
<table width="100%" cellspacing="0" cellpadding="0" border="0">
704
	<tr><th><?= $l_local_dns?></th></tr>
707
	<tr><th><?= $l_local_dns?></th></tr>
705
	<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>
706
</table>
709
</table>
707
<table width="100%" cellspacing="0" cellpadding="5" border="1">
710
<table width="100%" cellspacing="0" cellpadding="5" border="1">
708
<tr>
711
<tr>
709
	<td width="50%" align="center">
712
	<td width="50%" align="center">
710
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
713
		<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
711
		<table cellspacing="2" cellpadding="3" border="1">
714
		<table cellspacing="2" cellpadding="3" border="1">
712
		<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>
713
		<?php
716
		<?php
714
		// Read the "dns_local" file
717
		// Read the "dns_local" file
715
		$line_exist = false;
718
		$line_exist = false;
716
		$tab = file(DNS_LOCAL_FILE);
719
		$tab = file(DNS_LOCAL_FILE);
717
		if ($tab) { // not empty
720
		if ($tab) { // not empty
718
			foreach ($tab as $line) {
721
			foreach ($tab as $line) {
719
				if (preg_match ('/^address/', $line)) {
722
				if (preg_match ('/^address/', $line)) {
720
					$line_exist = true;
723
					$line_exist = true;
721
					$field = explode('/', $line);
724
					$field = explode('/', $line);
722
					$host_name = $field[1];
725
					$host_name = $field[1];
723
					$ip_addr   = $field[2];
726
					$ip_addr   = $field[2];
724
					echo "<tr><td>$host_name</td>";
727
					echo "<tr><td>$host_name</td>";
725
					echo "<td>$ip_addr</td>";
728
					echo "<td>$ip_addr</td>";
726
					echo "<td><input type=\"checkbox\" name=\"$host_name\"></td>";
729
					echo "<td><input type=\"checkbox\" name=\"$host_name\"></td>";
727
					echo "</tr>";
730
					echo "</tr>";
728
				}
731
				}
729
			}
732
			}
730
		}
733
		}
731
		if (!$line_exist) {
734
		if (!$line_exist) {
732
			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>';
733
		}
736
		}
734
		?>
737
		?>
735
		</table>
738
		</table>
736
		<?php if ($line_exist): ?>
739
		<?php if ($line_exist): ?>
737
			<input type="hidden" name="choix" value="del_host">
740
			<input type="hidden" name="choix" value="del_host">
738
			<input type="submit" value="<?= $l_apply ?>">
741
			<input type="submit" value="<?= $l_apply ?>">
739
		<?php endif; ?>
742
		<?php endif; ?>
740
		</form>
743
		</form>
741
	</td>
744
	</td>
742
	<td width="50%" valign="middle" align="center">
745
	<td width="50%" valign="middle" align="center">
743
		<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
746
		<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
744
		<table cellspacing="2" cellpadding="3" border="1">
747
		<table cellspacing="2" cellpadding="3" border="1">
745
		<tr>
748
		<tr>
746
			<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>
747
		</tr>
750
		</tr>
748
		<tr>
751
		<tr>
749
			<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>
750
		</tr>
753
		</tr>
751
		<tr>
754
		<tr>
752
			<td><input type="text" name="add_host" size="17"></td>
755
			<td><input type="text" name="add_host" size="17"></td>
753
			<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
756
			<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
754
			<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
757
			<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
755
		</tr>
758
		</tr>
756
		</table>
759
		</table>
757
		</form>
760
		</form>
758
	</td>
761
	</td>
759
</tr>
762
</tr>
760
</table>
763
</table>
761
<br>
764
<br>
762
 
765
 
763
<table width="100%" cellspacing="0" cellpadding="0" border="0">
766
<table width="100%" cellspacing="0" cellpadding="0" border="0">
764
	<tr><th><?= $l_import_cert ?></th></tr>
767
	<tr><th><?= $l_import_cert ?></th></tr>
765
	<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>
766
</table>
769
</table>
767
<table width="100%" cellspacing="0" cellpadding="5" border="1">
770
<table width="100%" cellspacing="0" cellpadding="5" border="1">
768
	<tr>
771
	<tr>
769
		<td width="50%" valign="top">
772
		<td width="50%" valign="top">
770
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
773
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
771
				<input type="hidden" name="choix" value="https_login">
774
				<input type="hidden" name="choix" value="https_login">
772
				<span><?= $l_allow_unsecured_login ?></span><br>
775
				<span><?= $l_allow_unsecured_login ?></span><br>
773
				<select name="https_login">
776
				<select name="https_login">
774
					<option value="on"<?=  (($conf['HTTPS_LOGIN'] === 'on')  ? ' selected' : '') ?>><?= $l_no ?></option>
777
					<option value="on"<?=  (($conf['HTTPS_LOGIN'] === 'on')  ? ' selected' : '') ?>><?= $l_no ?></option>
775
					<option value="off"<?= (($conf['HTTPS_LOGIN'] === 'off') ? ' selected' : '') ?>><?= $l_yes ?></option>
778
					<option value="off"<?= (($conf['HTTPS_LOGIN'] === 'off') ? ' selected' : '') ?>><?= $l_yes ?></option>
776
				</select>
779
				</select>
777
				<input type="submit" value="<?= $l_apply ?>"><br>
780
				<input type="submit" value="<?= $l_apply ?>"><br>
778
				<span><?= $l_unsecured_login_warning ?></span>
781
				<span><?= $l_unsecured_login_warning ?></span>
779
			</form>
782
			</form>
780
			<br>
783
			<br>
781
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
784
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
782
				<input type="hidden" name="choix" value="default_cert">
785
				<input type="hidden" name="choix" value="default_cert">
783
				<input type="submit" value="<?= $l_default_cert ?>" <?= (!file_exists('/etc/pki/tls/certs/alcasar.crt.old') || !file_exists('/etc/pki/tls/private/alcasar.key.old')) ? ' disabled' : '' ?>>
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' : '' ?>>
784
			</form>
787
			</form>
785
		</td>
788
		</td>
786
		<td width="50%" valign="top">
789
		<td width="50%" valign="top">
787
			<?php
790
			<?php
788
			$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'));
789
 
792
 
790
			$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']);
791
			$domain               = $certificateInfos['subject']['CN'];
794
			$domain               = $certificateInfos['subject']['CN'];
792
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
795
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
793
			$CAdomain             = $certificateInfos['issuer']['CN'];
796
			$CAdomain             = $certificateInfos['issuer']['CN'];
794
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
797
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
795
			?>
798
			?>
796
			<h3><?= $l_current_certificate ?></h3>
799
			<h3><?= $l_current_certificate ?></h3>
797
			<?= $l_cert_expiration ?> <?= $cert_expiration_date ?><br>
800
			<?= $l_cert_expiration ?> <?= $cert_expiration_date ?><br>
798
			<?= $l_cert_commonname ?> <?= $domain ?><br>
801
			<?= $l_cert_commonname ?> <?= $domain ?><br>
799
			<?= $l_cert_organization ?> <?= $organization ?><br/>
802
			<?= $l_cert_organization ?> <?= $organization ?><br/>
800
			<h4><?=  $l_validated ?></h4>
803
			<h4><?=  $l_validated ?></h4>
801
			<?= $l_cert_commonname ?> <?= $CAdomain ?><br>
804
			<?= $l_cert_commonname ?> <?= $CAdomain ?><br>
802
			<?= $l_cert_organization ?> <?= $CAorganization ?><br>
805
			<?= $l_cert_organization ?> <?= $CAorganization ?><br>
803
		</td>
806
		</td>
804
	</tr>
807
	</tr>
805
	<tr>
808
	<tr>
806
		<td width="50%" valign="top">
809
		<td width="50%" valign="top">
807
			<h3><?= $l_upload_certificate ?></h3>
810
			<h3><?= $l_upload_certificate ?></h3>
808
			<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">
809
				<?= $l_private_key;?> <input type="file" name="key"><br>
812
				<?= $l_private_key;?> <input type="file" name="key"><br>
810
				<?= $l_certificate;?> <input type="file" name="crt"><br>
813
				<?= $l_certificate;?> <input type="file" name="crt"><br>
811
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
814
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
812
				<input type="hidden" name="choix" value="import_cert">
815
				<input type="hidden" name="choix" value="import_cert">
813
				<input type="submit" value="<?= $l_import ?>">
816
				<input type="submit" value="<?= $l_import ?>">
814
			</form>
817
			</form>
815
		</td>
818
		</td>
816
		<td width="50%" valign="top">
819
		<td width="50%" valign="top">
817
			<?php
820
			<?php
818
			// Get step
821
			// Get step
819
			if (empty($LE_conf['domainRequest'])) {
822
			if (empty($LE_conf['domainRequest'])) {
820
				$step = 1;
823
				$step = 1;
821
			} else if (!empty($LE_conf['challenge'])) {
824
			} else if (!empty($LE_conf['challenge'])) {
822
				$step = 2;
825
				$step = 2;
823
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
826
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
824
				$step = 3;
827
				$step = 3;
825
			} else {
828
			} else {
826
				$step = 1;
829
				$step = 1;
827
			}
830
			}
828
			?>
831
			?>
829
			<h3><?= $l_le_integration ?></h3>
832
			<h3><?= $l_le_integration ?></h3>
830
			<?php if ($step === 1): ?>
833
			<?php if ($step === 1): ?>
831
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
834
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
832
					<input type="hidden" name="choix" value="le_issueCert">
835
					<input type="hidden" name="choix" value="le_issueCert">
833
					<?= $l_le_status ?> <?= $l_disabled ?><br>
836
					<?= $l_le_status ?> <?= $l_disabled ?><br>
834
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
837
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
835
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
838
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
836
					<input type="submit" name="issue" value="<?= $l_send ?>"><br>
839
					<input type="submit" name="issue" value="<?= $l_send ?>"><br>
837
				</form>
840
				</form>
838
			<?php elseif ($step === 2): ?>
841
			<?php elseif ($step === 2): ?>
839
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
842
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
840
					<input type="hidden" name="choix" value="le_renewCert">
843
					<input type="hidden" name="choix" value="le_renewCert">
841
					<?= $l_le_status ?> <?= $l_pending_validation ?><br>
844
					<?= $l_le_status ?> <?= $l_pending_validation ?><br>
842
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
845
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
843
					<?= $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>
844
					<?= $l_le_dns_entry_txt ?> "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
847
					<?= $l_le_dns_entry_txt ?> "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
845
					<?= $l_le_challenge ?> "<?= $LE_conf['challenge'] ?>"<br>
848
					<?= $l_le_challenge ?> "<?= $LE_conf['challenge'] ?>"<br>
846
					<input type="submit" name="recheck" value="<?= $l_recheck ?>"> <input type="submit" name="cancel" value="<?= $l_cancel ?>"><br>
849
					<input type="submit" name="recheck" value="<?= $l_recheck ?>"> <input type="submit" name="cancel" value="<?= $l_cancel ?>"><br>
847
				</form>
850
				</form>
848
			<?php elseif ($step === 3): ?>
851
			<?php elseif ($step === 3): ?>
849
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
852
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
850
					<input type="hidden" name="choix" value="le_renewCert">
853
					<input type="hidden" name="choix" value="le_renewCert">
851
					<?= $l_le_status ?> <?= $l_enabled ?><br>
854
					<?= $l_le_status ?> <?= $l_enabled ?><br>
852
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
855
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
853
					<?= $l_le_api ?>  <?= $LE_conf['dnsapi'] ?><br>
856
					<?= $l_le_api ?>  <?= $LE_conf['dnsapi'] ?><br>
854
					<?= $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>
855
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
858
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
856
						<input type="submit" name="recheck" value="<?= $l_renew ?>"><br>
859
						<input type="submit" name="recheck" value="<?= $l_renew ?>"><br>
857
					<?php else: ?>
860
					<?php else: ?>
858
						<input type="submit" name="recheck_force" value="<?= $l_renew_force ?>"><br>
861
						<input type="submit" name="recheck_force" value="<?= $l_renew_force ?>"><br>
859
					<?php endif; ?>
862
					<?php endif; ?>
860
				</form>
863
				</form>
861
			<?php endif; ?>
864
			<?php endif; ?>
862
			<?php if (isset($cmdResponse)): ?>
865
			<?php if (isset($cmdResponse)): ?>
863
				<p><?= $cmdResponse ?></p>
866
				<p><?= $cmdResponse ?></p>
864
			<?php endif; ?>
867
			<?php endif; ?>
865
		</td>
868
		</td>
866
	</tr>
869
	</tr>
867
</table>
870
</table>
868
</body>
871
</body>
869
</html>
872
</html>
870
 
873