Subversion Repositories ALCASAR

Rev

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

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