Subversion Repositories ALCASAR

Rev

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

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