Subversion Repositories ALCASAR

Rev

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

Rev 2809 Rev 2813
1
<?php
1
<?php
2
# $Id: network.php 2809 2020-04-12 17:35:46Z rexy $
2
# $Id: network.php 2813 2020-04-26 21:26:32Z 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 (DHCP)";
59
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques (DHCP)";
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 (DNS)";
66
	$l_local_dns		= "Résolution local de nom (DNS)";
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 ou .cer) :";
70
	$l_server_chain		= "Chaîne de certification (si nécéssaire : .crt) :";
70
	$l_server_chain		= "Chaîne de certification (.crt, .cer ou .pem) :";
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_ssl_title		= "Chiffrer les flux d'authentification entre les utilisateurs et ALCASAR";
78
	$l_ssl_title		= "Chiffrer les flux d'authentification entre les utilisateurs et ALCASAR";
79
	$l_cert_expiration	= "Date d'expiration :";
79
	$l_cert_expiration	= "Date d'expiration :";
80
	$l_cert_commonname	= "Nom commun :";
80
	$l_cert_commonname	= "Nom commun :";
81
	$l_cert_organization	= "Organisation :";
81
	$l_cert_organization	= "Organisation :";
82
	$l_upload_certificate	= "Importer un certificat";
82
	$l_upload_certificate	= "Importer un certificat officiel";
83
	$l_le_integration	= "Intégration Let's Encrypt";
83
	$l_le_integration	= "Intégrer un certificat Let's Encrypt";
84
	$l_le_status		= "Status :";
84
	$l_le_status		= "Status :";
85
	$l_disabled		= "Inactif";
85
	$l_disabled		= "Inactif";
86
	$l_pending_validation	= "En attente de validation";
86
	$l_pending_validation	= "En attente de validation";
87
	$l_enabled		= "Actif";
87
	$l_enabled		= "Actif";
88
	$l_le_email		= "Email :";
88
	$l_le_email		= "Email :";
89
	$l_le_domain_name	= "Nom de domaine :";
89
	$l_le_domain_name	= "Nom de domaine :";
90
	$l_send			= "Envoyer";
90
	$l_send			= "Envoyer";
91
	$l_le_ask_on		= "Demandé le :";
91
	$l_le_ask_on		= "Demandé le :";
92
	$l_le_dns_entry_txt	= "Entrée DNS TXT :";
92
	$l_le_dns_entry_txt	= "Entrée DNS TXT :";
93
	$l_le_challenge		= "Challenge :";
93
	$l_le_challenge		= "Challenge :";
94
	$l_recheck		= "Revérifier";
94
	$l_recheck		= "Revérifier";
95
	$l_cancel		= "Annuler";
95
	$l_cancel		= "Annuler";
96
	$l_le_api		= "API :";
96
	$l_le_api		= "API :";
97
	$l_le_next_renewal	= "Prochain renouvellement :";
97
	$l_le_next_renewal	= "Prochain renouvellement :";
98
	$l_renew		= "Renouveller";
98
	$l_renew		= "Renouveller";
99
	$l_renew_force		= "Renouveller (forcer)";
99
	$l_renew_force		= "Renouveller (forcer)";
-
 
100
	$l_previous_LE_cert	= "Revenir au certificat Let's Encrypt :";
100
} else {			// English
101
} else {			// English
101
	$l_network_title	= "Network configuration";
102
	$l_network_title	= "Network configuration";
102
	$l_internet_legend	= "INTERNET";
103
	$l_internet_legend	= "INTERNET";
103
	$l_ip_mask		= "Mask";
104
	$l_ip_mask		= "Mask";
104
	$l_ip_router		= "Gateway";
105
	$l_ip_router		= "Gateway";
105
	$l_ip_public		= "Public IP address";
106
	$l_ip_public		= "Public IP address";
106
	$l_ip_dns1		= "DNS n°1";
107
	$l_ip_dns1		= "DNS n°1";
107
	$l_ip_dns2		= "DNS n°2";
108
	$l_ip_dns2		= "DNS n°2";
108
	$l_dhcp_title		= "DHCP service";
109
	$l_dhcp_title		= "DHCP service";
109
	$l_dhcp_state		= "Current mode";
110
	$l_dhcp_state		= "Current mode";
110
	$l_DHCP_on		= "enabled";
111
	$l_DHCP_on		= "enabled";
111
	$l_DHCP_off		= "disabled";
112
	$l_DHCP_off		= "disabled";
112
	$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)";
113
	$l_static_dhcp_title	= "Static IP addresses reservation (DHCP)";
114
	$l_static_dhcp_title	= "Static IP addresses reservation (DHCP)";
114
	$l_mac_address		= "MAC address";
115
	$l_mac_address		= "MAC address";
115
	$l_ip_address		= "IP address";
116
	$l_ip_address		= "IP address";
116
	$l_port			= "Port";
117
	$l_port			= "Port";
117
	$l_host_name		= "Host name";
118
	$l_host_name		= "Host name";
118
	$l_del			= "Delete from list";
119
	$l_del			= "Delete from list";
119
	$l_add_to_list		= "Add";
120
	$l_add_to_list		= "Add";
120
	$l_apply		= "Apply changes";
121
	$l_apply		= "Apply changes";
121
	$l_local_dns		= "Local name resolution (DNS";
122
	$l_local_dns		= "Local name resolution (DNS";
122
	$l_import_cert		= "Certificate import";
123
	$l_import_cert		= "Certificate import";
123
	$l_private_key		= "Private key (.key) :";
124
	$l_private_key		= "Private key (.key) :";
124
	$l_certificate		= "Certificate (.crt) :";
125
	$l_certificate		= "Certificate (.crt or .cer) :";
125
	$l_server_chain		= "Server-chain (if necessary : .crt) :";
126
	$l_server_chain		= "Server-chain (.crt, .cer or .pem) :";
126
	$l_default_cert		= "Back to default certificate";
127
	$l_default_cert		= "Back to default certificate :";
127
	$l_import		= "Import";
128
	$l_import		= "Import";
128
	$l_current_certificate  = "Current certificate";
129
	$l_current_certificate  = "Current certificate";
129
	$l_validated		= "Validated by :";
130
	$l_validated		= "Validated by :";
130
	$l_empty		= "Empty";
131
	$l_empty		= "Empty";
131
	$l_yes			= "Yes";
132
	$l_yes			= "Yes";
132
	$l_no			= "No";
133
	$l_no			= "No";
133
	$l_ssl_title		= "Cipher authentication flows between users and ALCASAR";
134
	$l_ssl_title		= "Cipher authentication flows between users and ALCASAR";
134
	$l_cert_expiration	= "Expiration date:";
135
	$l_cert_expiration	= "Expiration date:";
135
	$l_cert_commonname	= "Common name:";
136
	$l_cert_commonname	= "Common name:";
136
	$l_cert_organization	= "Organization:";
137
	$l_cert_organization	= "Organization:";
137
	$l_upload_certificate	= "Importer un certificat";
138
	$l_upload_certificate	= "Import an officlal certificate";
138
	$l_le_integration	= "Let's Encrypt integration";
139
	$l_le_integration	= "Integrate a Let's Encrypt certificate";
139
	$l_le_status		= "Status:";
140
	$l_le_status		= "Status:";
140
	$l_disabled		= "Disabled";
141
	$l_disabled		= "Disabled";
141
	$l_pending_validation	= "Pending validation";
142
	$l_pending_validation	= "Pending validation";
142
	$l_enabled		= "Enabled";
143
	$l_enabled		= "Enabled";
143
	$l_le_email		= "Email:";
144
	$l_le_email		= "Email:";
144
	$l_le_domain_name	= "Domain name:";
145
	$l_le_domain_name	= "Domain name:";
145
	$l_send			= "Send";
146
	$l_send			= "Send";
146
	$l_le_ask_on		= "Ask on:";
147
	$l_le_ask_on		= "Ask on:";
147
	$l_le_dns_entry_txt	= "DNS TXT entry:";
148
	$l_le_dns_entry_txt	= "DNS TXT entry:";
148
	$l_le_challenge		= "Challenge:";
149
	$l_le_challenge		= "Challenge:";
149
	$l_recheck		= "Recheck";
150
	$l_recheck		= "Recheck";
150
	$l_cancel		= "Cancel";
151
	$l_cancel		= "Cancel";
151
	$l_le_api		= "API:";
152
	$l_le_api		= "API:";
152
	$l_le_next_renewal	= "Next renewal:";
153
	$l_le_next_renewal	= "Next renewal:";
153
	$l_renew		= "Renew";
154
	$l_renew		= "Renew";
154
	$l_renew_force		= "Renew (force)";
155
	$l_renew_force		= "Renew (force)";
-
 
156
	$l_previous_LE_cert	= "Back to the Let's Encrypt certificate :";
155
}
157
}
156
 
158
 
157
$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      = '/^(([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_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_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_mac     = '/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/';
161
$reg_mac     = '/^([0-9A-Fa-f]{2}[:-]){5}([0-9A-Fa-f]{2})$/';
160
$reg_host    = '/^[a-zA-Z0-9-_]+$/';
162
$reg_host    = '/^[a-zA-Z0-9-_]+$/';
161
 
163
 
162
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
164
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
163
 
165
 
164
switch ($choix) {
166
switch ($choix) {
165
	case 'DHCP_On':
167
	case 'DHCP_On':
166
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -on');
168
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -on');
167
		header('Location: '.$_SERVER['PHP_SELF']);
169
		header('Location: '.$_SERVER['PHP_SELF']);
168
		exit();
170
		exit();
169
	case 'DHCP_Off':
171
	case 'DHCP_Off':
170
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
172
		exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
171
		header('Location: '.$_SERVER['PHP_SELF']);
173
		header('Location: '.$_SERVER['PHP_SELF']);
172
		exit();
174
		exit();
173
 
175
 
174
	case 'new_mac':
176
	case 'new_mac':
175
		$new_mac_addr = trim($_POST['add_mac']);
177
		$new_mac_addr = trim($_POST['add_mac']);
176
		$new_ip_addr  = trim($_POST['add_ip']);
178
		$new_ip_addr  = trim($_POST['add_ip']);
177
		if (((!empty($new_mac_addr)) && (preg_match($reg_mac, $new_mac_addr))) && ((!empty($new_ip_addr)) && (preg_match($reg_ip, $new_ip_addr)))) {
179
		if (((!empty($new_mac_addr)) && (preg_match($reg_mac, $new_mac_addr))) && ((!empty($new_ip_addr)) && (preg_match($reg_ip, $new_ip_addr)))) {
178
			$tab = file(ETHERS_FILE);
180
			$tab = file(ETHERS_FILE);
179
			if ($tab) { // the file isn't empty
181
			if ($tab) { // the file isn't empty
180
				$insert = true;
182
				$insert = true;
181
				foreach ($tab as $line) { // verify that MAC or IP address doesn't exist
183
				foreach ($tab as $line) { // verify that MAC or IP address doesn't exist
182
					$field = explode(' ', $line);
184
					$field = explode(' ', $line);
183
					$mac_addr = trim($field[0]);
185
					$mac_addr = trim($field[0]);
184
					$ip_addr  = trim($field[1]);
186
					$ip_addr  = trim($field[1]);
185
					if (strcasecmp($new_mac_addr, $mac_addr) === 0) {
187
					if (strcasecmp($new_mac_addr, $mac_addr) === 0) {
186
						$insert = false;
188
						$insert = false;
187
						break;
189
						break;
188
					}
190
					}
189
					if (strcasecmp($new_ip_addr, $ip_addr) === 0) {
191
					if (strcasecmp($new_ip_addr, $ip_addr) === 0) {
190
						$insert = false;
192
						$insert = false;
191
						break;
193
						break;
192
					}
194
					}
193
				}
195
				}
194
				if ($insert) {
196
				if ($insert) {
195
					$line = $new_mac_addr . ' ' . $new_ip_addr . "\n";
197
					$line = $new_mac_addr . ' ' . $new_ip_addr . "\n";
196
					$pointeur = fopen(ETHERS_FILE, 'a');
198
					$pointeur = fopen(ETHERS_FILE, 'a');
197
					fwrite($pointeur, $line);
199
					fwrite($pointeur, $line);
198
					fclose($pointeur);
200
					fclose($pointeur);
199
					$pointeur = fopen(ETHERS_INFO_FILE, 'a');
201
					$pointeur = fopen(ETHERS_INFO_FILE, 'a');
200
					$line = "$new_mac_addr $new_ip_addr #" . trim($_POST['info'],"\x00..\x20") . "\n";
202
					$line = "$new_mac_addr $new_ip_addr #" . trim($_POST['info'],"\x00..\x20") . "\n";
201
					fwrite($pointeur, $line);
203
					fwrite($pointeur, $line);
202
					fclose($pointeur);
204
					fclose($pointeur);
203
					exec('sudo /usr/bin/systemctl reload chilli');
205
					exec('sudo /usr/bin/systemctl reload chilli');
204
				}
206
				}
205
			}
207
			}
206
		}
208
		}
207
		header('Location: '.$_SERVER['PHP_SELF']);
209
		header('Location: '.$_SERVER['PHP_SELF']);
208
		exit();
210
		exit();
209
	case 'del_mac':
211
	case 'del_mac':
210
		foreach ($_POST as $key => $value) {
212
		foreach ($_POST as $key => $value) {
211
			if ($value == 'on') {
213
			if ($value == 'on') {
212
				$ether_file = ETHERS_FILE;
214
				$ether_file = ETHERS_FILE;
213
				$ether_file_info = ETHERS_INFO_FILE;
215
				$ether_file_info = ETHERS_INFO_FILE;
214
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file");
216
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file");
215
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info");
217
				exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info");
216
				exec('sudo /usr/bin/systemctl reload chilli');
218
				exec('sudo /usr/bin/systemctl reload chilli');
217
			}
219
			}
218
		}
220
		}
219
		header('Location: '.$_SERVER['PHP_SELF']);
221
		header('Location: '.$_SERVER['PHP_SELF']);
220
		exit();
222
		exit();
221
 
223
 
222
	case 'new_host':
224
	case 'new_host':
223
		$add_host = trim($_POST['add_host']);
225
		$add_host = trim($_POST['add_host']);
224
		$add_ip   = trim($_POST['add_ip']);
226
		$add_ip   = trim($_POST['add_ip']);
225
		if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
227
		if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
226
			$tab = file(DNS_LOCAL_FILE);
228
			$tab = file(DNS_LOCAL_FILE);
227
			if ($tab) { // the file isn't empty
229
			if ($tab) { // the file isn't empty
228
				$insert = true;
230
				$insert = true;
229
				foreach ($tab as $line) { // verify that host or IP address doesn't exist
231
				foreach ($tab as $line) { // verify that host or IP address doesn't exist
230
					if (preg_match('/^\d+/', $line)) {
232
					if (preg_match('/^\d+/', $line)) {
231
						$field = preg_split("/\s+/",$line);
233
						$field = preg_split("/\s+/",$line);
232
						$ip_addr = $field[0];
234
						$ip_addr = $field[0];
233
						$host_name = trim($field[1]);
235
						$host_name = trim($field[1]);
234
						if (strcasecmp($add_host, $host_name) === 0) {
236
						if (strcasecmp($add_host, $host_name) === 0) {
235
							$insert = false;
237
							$insert = false;
236
							break;
238
							break;
237
						}
239
						}
238
					}
240
					}
239
				}
241
				}
240
				if ($insert) {
242
				if ($insert) {
241
					exec("sudo /usr/local/bin/alcasar-dns-local.sh --add $add_ip $add_host");
243
					exec("sudo /usr/local/bin/alcasar-dns-local.sh --add $add_ip $add_host");
242
				}
244
				}
243
			}
245
			}
244
		}
246
		}
245
		header('Location: '.$_SERVER['PHP_SELF']);
247
		header('Location: '.$_SERVER['PHP_SELF']);
246
		exit();
248
		exit();
247
	case 'del_host':
249
	case 'del_host':
248
		foreach ($_POST as $key => $value) {
250
		foreach ($_POST as $key => $value) {
249
			if ($value == 'on') {
251
			if ($value == 'on') {
250
				$del_host = explode ("|", $key);
252
				$del_host = explode ("|", $key);
251
				$del_ip = str_replace("_",".",$del_host[0]);
253
				$del_ip = str_replace("_",".",$del_host[0]);
252
				exec("sudo /usr/local/bin/alcasar-dns-local.sh --del $del_ip $del_host[1]");
254
				exec("sudo /usr/local/bin/alcasar-dns-local.sh --del $del_ip $del_host[1]");
253
			}
255
			}
254
		}
256
		}
255
		header('Location: '.$_SERVER['PHP_SELF']);
257
		header('Location: '.$_SERVER['PHP_SELF']);
256
		exit();
258
		exit();
257
 
259
 
258
	case 'default_cert':	// Restore default certificate
260
	case 'set_default_cert':
259
		exec('sudo alcasar-importcert.sh -d');
261
		exec('sudo alcasar-importcert.sh -d');
260
		break;
262
		break;
-
 
263
	case 'set_last_LE_cert':
-
 
264
		exec('sudo alcasar-letsencrypt.sh --install-cert');
261
 
265
		break;
262
	case 'import_cert':	// Import certificate
266
	case 'import_cert':	// Import certificate
263
		$maxsize = 100000;
267
		$maxsize = 100000;
264
		if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) {
268
		if (isset($_FILES['key']) && isset($_FILES['crt']) && ($_FILES['key']['error'] == 0) && ($_FILES['crt']['error'] == 0)) {
265
			if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) {
269
			if ($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize) {
266
				if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && ((pathinfo($_FILES['crt']['name'])['extension'] == 'crt') || (pathinfo($_FILES['crt']['name'])['extension'] == 'cer'))) {
270
				if (pathinfo($_FILES['key']['name'])['extension'] == 'key' && ((pathinfo($_FILES['crt']['name'])['extension'] == 'crt') || (pathinfo($_FILES['crt']['name'])['extension'] == 'cer'))) {
267
					$dest = '/tmp/';
271
					$dest = '/tmp/';
268
					$scpath = '';
272
					$scpath = '';
269
					if (isset($_FILES['sc']) && ((pathinfo($_FILES['sc']['name'])['extension'] == 'crt') || (pathinfo($_FILES['sc']['name'])['extension'] == 'cer'))) {
273
					if (isset($_FILES['sc']) && ((pathinfo($_FILES['sc']['name'])['extension'] == 'crt') || (pathinfo($_FILES['sc']['name'])['extension'] == 'cer') || (pathinfo($_FILES['sc']['name']['extension'] == 'pem')))){
270
						$scpath = $dest.'server-chain.crt';
274
						$scpath = $dest.'server-chain.pem';
271
						move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
275
						move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
272
					}
276
					}
273
					$keypath = $dest.'alcasar.key';
277
					$keypath = $dest.'alcasar.key';
274
					$crtpath = $dest.'alcasar.crt';
278
					$crtpath = $dest.'alcasar.crt';
275
					move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
279
					move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
276
					move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
280
					move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
277
					exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
281
					exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
278
					if (file_exists($crtpath)) unlink($crtpath);
282
					if (file_exists($crtpath)) unlink($crtpath);
279
					if (file_exists($keypath)) unlink($keypath);
283
					if (file_exists($keypath)) unlink($keypath);
280
					if (file_exists($scpath))  unlink($scpath);
284
					if (file_exists($scpath))  unlink($scpath);
281
				}
285
				}
282
			}
286
			}
283
		}
287
		}
284
		break;
288
		break;
285
 
289
 
286
	case 'https_login':	// Set HTTPS login status
290
	case 'https_login':	// Set HTTPS login status
287
		if ($_POST['https_login'] === 'on') {
291
		if ($_POST['https_login'] === 'on') {
288
			exec('sudo /usr/local/bin/alcasar-https.sh --on');
292
			exec('sudo /usr/local/bin/alcasar-https.sh --on');
289
		} else {
293
		} else {
290
			exec('sudo /usr/local/bin/alcasar-https.sh --off');
294
			exec('sudo /usr/local/bin/alcasar-https.sh --off');
291
		}
295
		}
292
		header('Location: '.$_SERVER['PHP_SELF']);
296
		header('Location: '.$_SERVER['PHP_SELF']);
293
		exit();
297
		exit();
294
}
298
}
295
 
299
 
296
// Network changes
300
// Network changes
297
if ($choix === 'network_change') {
301
if ($choix === 'network_change') {
298
	$network_modification = false;
302
	$network_modification = false;
299
 
303
 
300
	if (isset($_POST['dns1']) && (trim($_POST['dns1']) !== $conf['DNS1']) && preg_match($reg_ip, $_POST['dns1'])) {
304
	if (isset($_POST['dns1']) && (trim($_POST['dns1']) !== $conf['DNS1']) && preg_match($reg_ip, $_POST['dns1'])) {
301
		file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'], 'DNS1='.trim($_POST['dns1']), file_get_contents(CONF_FILE)));
305
		file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'], 'DNS1='.trim($_POST['dns1']), file_get_contents(CONF_FILE)));
302
		$network_modification = true;
306
		$network_modification = true;
303
	}
307
	}
304
	if (isset($_POST['dns2']) && (trim($_POST['dns2']) !== $conf['DNS2']) && preg_match($reg_ip, $_POST['dns2'])) {
308
	if (isset($_POST['dns2']) && (trim($_POST['dns2']) !== $conf['DNS2']) && preg_match($reg_ip, $_POST['dns2'])) {
305
		file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'], 'DNS2='.trim($_POST['dns2']), file_get_contents(CONF_FILE)));
309
		file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'], 'DNS2='.trim($_POST['dns2']), file_get_contents(CONF_FILE)));
306
		$network_modification = true;
310
		$network_modification = true;
307
	}
311
	}
308
	if (isset($_POST['ip_public']) && (trim($_POST['ip_public']) !== $conf['PUBLIC_IP']) && preg_match($reg_ip_cidr, $_POST['ip_public'])) {
312
	if (isset($_POST['ip_public']) && (trim($_POST['ip_public']) !== $conf['PUBLIC_IP']) && preg_match($reg_ip_cidr, $_POST['ip_public'])) {
309
		file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'], 'PUBLIC_IP='.trim($_POST['ip_public']), file_get_contents(CONF_FILE)));
313
		file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'], 'PUBLIC_IP='.trim($_POST['ip_public']), file_get_contents(CONF_FILE)));
310
		$network_modification = true;
314
		$network_modification = true;
311
	}
315
	}
312
	if (isset($_POST['ip_gw']) && (trim($_POST['ip_gw']) !== $conf['GW']) && preg_match($reg_ip, $_POST['ip_gw'])) {
316
	if (isset($_POST['ip_gw']) && (trim($_POST['ip_gw']) !== $conf['GW']) && preg_match($reg_ip, $_POST['ip_gw'])) {
313
		file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'], 'GW='.trim($_POST['ip_gw']), file_get_contents(CONF_FILE)));
317
		file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'], 'GW='.trim($_POST['ip_gw']), file_get_contents(CONF_FILE)));
314
		$network_modification = true;
318
		$network_modification = true;
315
	}
319
	}
316
	if (isset($_POST['ip_private']) && (trim($_POST['ip_private']) !== $conf['PRIVATE_IP']) && preg_match($reg_ip_cidr, $_POST['ip_private'])) {
320
	if (isset($_POST['ip_private']) && (trim($_POST['ip_private']) !== $conf['PRIVATE_IP']) && preg_match($reg_ip_cidr, $_POST['ip_private'])) {
317
		file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'], 'PRIVATE_IP='.trim($_POST['ip_private']), file_get_contents(CONF_FILE)));
321
		file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'], 'PRIVATE_IP='.trim($_POST['ip_private']), file_get_contents(CONF_FILE)));
318
		$network_modification = true;
322
		$network_modification = true;
319
	}
323
	}
320
 
324
 
321
	if ($network_modification) {
325
	if ($network_modification) {
322
		exec('sudo /usr/local/bin/alcasar-conf.sh -apply');
326
		exec('sudo /usr/local/bin/alcasar-conf.sh -apply');
323
	}
327
	}
324
 
328
 
325
	// Read CONF_FILE updated
329
	// Read CONF_FILE updated
326
	$file_conf = fopen(CONF_FILE, 'r');
330
	$file_conf = fopen(CONF_FILE, 'r');
327
	if (!$file_conf) {
331
	if (!$file_conf) {
328
		exit('Error opening the file '.CONF_FILE);
332
		exit('Error opening the file '.CONF_FILE);
329
	}
333
	}
330
	while (!feof($file_conf)) {
334
	while (!feof($file_conf)) {
331
		$buffer = fgets($file_conf, 4096);
335
		$buffer = fgets($file_conf, 4096);
332
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
336
		if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
333
			$tmp = explode('=', $buffer, 2);
337
			$tmp = explode('=', $buffer, 2);
334
			$conf[trim($tmp[0])] = trim($tmp[1]);
338
			$conf[trim($tmp[0])] = trim($tmp[1]);
335
		}
339
		}
336
	}
340
	}
337
	fclose($file_conf);
341
	fclose($file_conf);
338
}
342
}
339
 
343
 
340
// Let's Encrypt actions
344
// Let's Encrypt actions
341
if ($choix === 'le_issueCert') {
345
if ($choix === 'le_issueCert') {
342
	// TODO: check ndd & mail format
346
	// TODO: check ndd & mail format
343
 
-
 
344
	$email      = $_POST['email'];
347
	$email      = $_POST['email'];
345
	$domainName = $_POST['domainname'];
348
	$domainName = $_POST['domainname'];
346
 
-
 
347
	exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);
349
	exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --issue --email '.escapeshellarg($email).' --domain '.escapeshellarg($domainName), $output, $exitCode);
348
 
-
 
349
	$cmdResponse = implode("<br>\n", $output);
350
	$cmdResponse = implode("<br>\n", $output);
350
}
351
}
351
if ($choix === 'le_renewCert') {
352
if ($choix === 'le_renewCert') {
352
	if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) {
353
	if ((isset($_POST['recheck'])) && ((!empty($_POST['recheck'])) || (!empty($_POST['recheck_force'])))) {
353
		$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : '';
354
		$forceOpt = (!empty($_POST['recheck_force'])) ? ' --force' : '';
354
 
355
 
355
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
356
		exec('sudo /usr/local/bin/alcasar-letsencrypt.sh --renew' . $forceOpt, $output, $exitCode);
356
 
357
 
357
		$cmdResponse = implode("<br>\n", $output);
358
		$cmdResponse = implode("<br>\n", $output);
358
	} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
359
	} else if ((isset($_POST['cancel'])) && (!empty($_POST['cancel']))) {
359
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
360
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/challenge=.*/','challenge=', file_get_contents(LETS_ENCRYPT_FILE)));
360
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
361
		file_put_contents(LETS_ENCRYPT_FILE, preg_replace('/domainRequest=.*/','domainRequest=', file_get_contents(LETS_ENCRYPT_FILE)));
361
	}
362
	}
362
}
363
}
363
 
364
 
364
 
-
 
365
// Read Let's Encrypt configuration file
365
// Read Let's Encrypt configuration file
366
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
366
$file_conf_LE = fopen(LETS_ENCRYPT_FILE, 'r');
367
if (!$file_conf_LE) {
367
if (!$file_conf_LE) {
368
	exit('Error opening the file '.LETS_ENCRYPT_FILE);
368
	exit('Error opening the file '.LETS_ENCRYPT_FILE);
369
}
369
}
370
while (!feof($file_conf_LE)) {
370
while (!feof($file_conf_LE)) {
371
	$buffer = fgets($file_conf_LE, 4096);
371
	$buffer = fgets($file_conf_LE, 4096);
372
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
372
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
373
		$tmp = explode('=', $buffer, 2);
373
		$tmp = explode('=', $buffer, 2);
374
		$LE_conf[trim($tmp[0])] = trim($tmp[1]);
374
		$LE_conf[trim($tmp[0])] = trim($tmp[1]);
375
	}
375
	}
376
}
376
}
377
fclose($file_conf_LE);
377
fclose($file_conf_LE);
378
 
378
 
379
 
-
 
380
// Fonction de test de connectivité internet
379
// Fonction de test de connectivité internet
381
function internetTest() {
380
function internetTest() {
382
	$host = 'www.google.fr'; # Google Test
381
	$host = 'www.google.fr'; # Google Test
383
	$port = '80';
382
	$port = '80';
384
 
383
 
385
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
384
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
386
		return false;
385
		return false;
387
	} else {
386
	} else {
388
		fclose($sock);
387
		fclose($sock);
389
		return true;
388
		return true;
390
	}
389
	}
391
}
390
}
392
 
391
 
393
$internet_connected = InternetTest();
392
$internet_connected = InternetTest();
394
if ($internet_connected) {
393
if ($internet_connected) {
395
	$ch = curl_init('https://api.ipify.org/');
394
	$ch = curl_init('https://api.ipify.org/');
396
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
395
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
397
	$internet_publicIP = curl_exec($ch);
396
	$internet_publicIP = curl_exec($ch);
398
	curl_close($ch);
397
	curl_close($ch);
399
} else {
398
} else {
400
	$internet_publicIP = '-.-.-.-';
399
	$internet_publicIP = '-.-.-.-';
401
}
400
}
402
 
401
 
403
 
-
 
404
// Network interfaces
402
// Network interfaces
405
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['EXTIF'], $conf['INTIF']];
403
$interfacesIgnored = ['lo', 'tun[0-9]*', $conf['EXTIF'], $conf['INTIF']];
406
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable);
404
exec("ip -o link show | awk -F': ' '{print $2}' | sed '/^" . implode('\\|', $interfacesIgnored) . "$/d'", $interfacesAvailable);
407
 
405
 
408
// TODO: Pending the next version
406
// TODO: Pending the next version
409
$externalNetworks = [
407
$externalNetworks = [
410
	(object) [
408
	(object) [
411
		'interface' => $conf['EXTIF'],
409
		'interface' => $conf['EXTIF'],
412
		'ip'        => $conf['PUBLIC_IP'],
410
		'ip'        => $conf['PUBLIC_IP'],
413
		'gateway'   => $conf['GW']
411
		'gateway'   => $conf['GW']
414
	]
412
	]
415
];
413
];
416
$internalNetworks = [
414
$internalNetworks = [
417
	(object) [
415
	(object) [
418
		'interface' => $conf['INTIF'],
416
		'interface' => $conf['INTIF'],
419
		'ip'        => $conf['PRIVATE_IP']
417
		'ip'        => $conf['PRIVATE_IP']
420
	]
418
	]
421
];
419
];
422
 
420
 
423
?>
421
?>
424
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
422
<!DOCTYPE HTML>
425
<html>
423
<html>
426
<head>
424
<head>
427
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
425
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
428
	<title><?= $l_network_title ?></title>
426
	<title><?= $l_network_title ?></title>
429
	<link rel="stylesheet" href="/css/style.css" type="text/css">
427
	<link rel="stylesheet" href="/css/style.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-row">
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">
-
 
610
						<div class="network-box">
-
 
611
							<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br>
-
 
612
							<?= $l_ip_public ?> : <?= $internet_publicIP ?><br>
-
 
613
							<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><br>
-
 
614
							<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
-
 
615
						</div>
-
 
616
						<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div>
-
 
617
					</div>
-
 
618
				</div><div class="externals">
-
 
619
					<?php foreach ($externalNetworks as $index => $network): ?>
-
 
620
						<div data-network-type="external">
-
 
621
							<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div>
612
							<div class="network-box">
622
							<div class="network-box">
613
								<?= $l_internet_legend ?> <img src="/images/state_<?= (($internet_connected) ? 'ok' : 'error') ?>.gif"><br>
623
								<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
614
								<?= $l_ip_public ?> : <?= $internet_publicIP ?><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>
615
								<label for="dns1"><?= $l_ip_dns1 ?></label> : <input style="width:120px" type="text" id="dns1" name="dns1" value="<?= $conf['DNS1'] ?>" /><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>
616
								<label for="dns2"><?= $l_ip_dns2 ?></label> : <input style="width:120px" type="text" id="dns2" name="dns2" value="<?= $conf['DNS2'] ?>" />
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 ?>" />
617
							</div>
627
							</div>
618
							<div class="network-connector" data-connector-network="internet" data-connector-direction="right"></div>
628
							<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div>
619
						</div>
629
						</div>
-
 
630
					<? endforeach; ?>
620
					</div><div class="externals">
631
				</div><div class="alcasar">
621
						<?php foreach ($externalNetworks as $index => $network): ?>
-
 
622
							<div data-network-type="external">
632
					<div data-network-type="alcasar">
623
								<div class="network-connector" data-connector-network="internet" data-connector-direction="left"></div>
633
						<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div>
624
								<div class="network-box">
634
						<div class="network-box">
-
 
635
							<!-- <div class="actions actions-externals">
625
									<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
636
								<div><a href="#" class="add-external-network" title="Ajouter un réseau externe">+</a></div>
-
 
637
							</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>
638
							<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div>
-
 
639
							<!-- <div class="actions actions-internals">
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>
640
								<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div>
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 ?>" />
641
								<div><a href="#" class="add-internal-wifi-network">++</a></div>
-
 
642
							</div> -->
629
								</div>
643
						</div>
630
								<div class="network-connector" data-connector-network="external" data-connector-direction="right"></div>
644
						<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div>
631
							</div>
645
					</div>
632
						<? endforeach; ?>
646
				</div><div class="internals">
633
					</div><div class="alcasar">
647
					<?php foreach ($internalNetworks as $network): ?>
634
						<div data-network-type="alcasar">
648
						<div data-network-type="internal">
635
							<div class="network-connector" data-connector-network="external" data-connector-direction="left"></div>
649
							<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div>
636
							<div class="network-box">
650
							<div class="network-box">
637
								<!-- <div class="actions actions-externals">
-
 
638
									<div><a href="#" class="add-external-network" title="Ajouter un réseau externe">+</a></div>
651
								<!-- <div class="actions actions-network"><a href="#" class="remove-network" title="Supprimer ce réseau">-</a></div> -->
639
								</div> -->
-
 
640
								<div class="alcasar-logo"><img src="/images/logo-alcasar.png" style="width: 100px;height: 100px;"></div>
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>
641
								<!-- <div class="actions actions-internals">
-
 
642
									<div><a href="#" class="add-internal-network" title="Ajouter un réseau interne">+</a></div>
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>
643
									<div><a href="#" class="add-internal-wifi-network">++</a></div>
-
 
644
								</div> -->
-
 
645
							</div>
654
							</div>
646
							<div class="network-connector" data-connector-network="internal" data-connector-direction="right"></div>
-
 
647
						</div>
655
						</div>
648
					</div><div class="internals">
-
 
649
						<?php foreach ($internalNetworks as $network): ?>
-
 
650
							<div data-network-type="internal">
-
 
651
								<div class="network-connector" data-connector-network="internal" data-connector-direction="left"></div>
-
 
652
								<div class="network-box">
-
 
653
									<!-- <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>
-
 
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>
-
 
656
								</div>
-
 
657
							</div>
-
 
658
						<? endforeach; ?>
656
					<? endforeach; ?>
659
					</div>
-
 
660
				</div>
-
 
661
				<hr>
-
 
662
				<div style="text-align: center; margin: 5px">
-
 
663
					<input type="hidden" name="choix" value="network_change">
-
 
664
					<input type="submit" value="<?= $l_apply ?>">
-
 
665
				</div>
657
				</div>
666
			</form>
658
			</div>
-
 
659
			<hr>
-
 
660
			<div style="text-align: center; margin: 5px">
-
 
661
				<input type="hidden" name="choix" value="network_change">
-
 
662
				<input type="submit" value="<?= $l_apply ?>">
667
		</div>
663
			</div>
-
 
664
		</form>
668
	</div>
665
	</div>
669
	<br>
666
</div>
670
 
667
<br>
671
<table width="100%" cellspacing="0" cellpadding="0" border="0">
668
<div class="panel">
672
	<tr><th><?= $l_static_dhcp_title?></th></tr>
669
	<div class="panel-header"><?= $l_static_dhcp_title ?></div>
673
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
-
 
674
</table>
670
</div>
675
<table width="100%" cellspacing="0" cellpadding="5" border="1">
671
<table width="100%" cellspacing="0" cellpadding="5" border="1">
676
	<tr><td width="50%" align="center" valign="middle">
672
	<tr><td width="50%" align="center" valign="middle">
677
		<form action="network.php" method="POST">
673
		<form action="network.php" method="POST">
678
		<table cellspacing="2" cellpadding="3" border="1">
674
		<table cellspacing="2" cellpadding="3" border="1">
679
		<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info<th><?= $l_del ?></th></tr>
675
		<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info<th><?= $l_del ?></th></tr>
680
		<?php
676
		<?php
681
		// Read the "ether" file
677
		// Read the "ether" file
682
		exec('sudo /sbin/ip link show '.escapeshellarg($conf["INTIF"]), $output);
678
		exec('sudo /sbin/ip link show '.escapeshellarg($conf["INTIF"]), $output);
683
		$detail = explode(' ', $output[1]);
679
		$detail = explode(' ', $output[1]);
684
		$intif_mac_addr = strtoupper(str_replace(':', '-', $detail[5]));
680
		$intif_mac_addr = strtoupper(str_replace(':', '-', $detail[5]));
685
		unset($output); unset($detail);
681
		unset($output); unset($detail);
686
		$line_exist = false;
682
		$line_exist = false;
687
		$tab = file(ETHERS_INFO_FILE);
683
		$tab = file(ETHERS_INFO_FILE);
688
		if ($tab) { // le fichier n'est pas vide
684
		if ($tab) { // le fichier n'est pas vide
689
			foreach ($tab as $line) {
685
			foreach ($tab as $line) {
690
				$fields = explode(' ', $line);
686
				$fields = explode(' ', $line);
691
				$mac_addr = $fields[0];
687
				$mac_addr = $fields[0];
692
				$ip_addr  = $fields[1];
688
				$ip_addr  = $fields[1];
693
				$info     = (isset($fields[2])) ? implode(' ', array_slice($fields, 2)) : ' ';
689
				$info     = (isset($fields[2])) ? implode(' ', array_slice($fields, 2)) : ' ';
694
 
690
 
695
				echo '<tr>';
691
				echo '<tr>';
696
				echo "<td>$mac_addr</td>";
692
				echo "<td>$mac_addr</td>";
697
				echo "<td>$ip_addr</td>";
693
				echo "<td>$ip_addr</td>";
698
				if ($mac_addr !== $intif_mac_addr) {
694
				if ($mac_addr !== $intif_mac_addr) {
699
					echo '<td>'.ltrim($info, '#').'</td>';
695
					echo '<td>'.ltrim($info, '#').'</td>';
700
					echo "<td><input type=\"checkbox\" name=\"$mac_addr\"></td>";
696
					echo "<td><input type=\"checkbox\" name=\"$mac_addr\"></td>";
701
					$line_exist=True;
697
					$line_exist=True;
702
				} else {
698
				} else {
703
					echo '<td>ALCASAR</td>';
699
					echo '<td>ALCASAR</td>';
704
					echo '<td></td>';
700
					echo '<td></td>';
705
				}
701
				}
706
				echo '</tr>';
702
				echo '</tr>';
707
			}
703
			}
708
		}
704
		}
709
		?>
705
		?>
710
		</table>
706
		</table>
711
		<?php if ($line_exist): ?>
707
		<?php if ($line_exist): ?>
712
			<input type="hidden" name="choix" value="del_mac">
708
			<input type="hidden" name="choix" value="del_mac">
713
			<input type="submit" value="<?= $l_apply ?>">
709
			<input type="submit" value="<?= $l_apply ?>">
714
		<?php endif; ?>
710
		<?php endif; ?>
715
		</form>
711
		</form>
716
	</td><td width="50%" valign="middle" align="center">
712
	</td><td width="50%" valign="middle" align="center">
717
		<form name="new_mac" action="network.php" method="POST">
713
		<form name="new_mac" action="network.php" method="POST">
718
			<table cellspacing="2" cellpadding="3" border="1">
714
			<table cellspacing="2" cellpadding="3" border="1">
719
				<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info</th><td></td></tr>
715
				<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info</th><td></td></tr>
720
				<tr><td>Ex. : 12-2F-36-A4-DF-43</td><td>Ex. : 192.168.182.10</td><td>Ex. : Switch<td></td></tr>
716
				<tr><td>Ex. : 12-2F-36-A4-DF-43</td><td>Ex. : 192.168.182.10</td><td>Ex. : Switch<td></td></tr>
721
				<tr><td><input type="text" name="add_mac" size="17"></td>
717
				<tr><td><input type="text" name="add_mac" size="17"></td>
722
				<td><input type="text" name="add_ip" size="10"></td>
718
				<td><input type="text" name="add_ip" size="10"></td>
723
				<td><input type="text" name="info" size="10"></td>
719
				<td><input type="text" name="info" size="10"></td>
724
				<td>
720
				<td>
725
					<input type="hidden" name="choix" value="new_mac">
721
					<input type="hidden" name="choix" value="new_mac">
726
					<input type="submit" class="button" value="<?= $l_add_to_list ?>" onclick="return MAC_Control('new_mac');">
722
					<input type="submit" class="button" value="<?= $l_add_to_list ?>" onclick="return MAC_Control('new_mac');">
727
				</td>
723
				</td>
728
			</tr></table>
724
			</tr></table>
729
		</form>
725
		</form>
730
	</td></tr>
726
	</td></tr>
731
</table>
727
</table>
732
<br>
728
<br>
733
 
-
 
734
<table width="100%" cellspacing="0" cellpadding="0" border="0">
729
<div class="panel">
735
	<tr><th><?= $l_local_dns ?></th></tr>
730
	<div class="panel-header"><?= $l_local_dns ?></div>
736
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
-
 
737
</table>
731
</div>
738
<table width="100%" cellspacing="0" cellpadding="5" border="1">
732
<table width="100%" cellspacing="0" cellpadding="5" border="1">
739
	<tr>
733
	<tr>
740
		<td width="50%" align="center">
734
		<td width="50%" align="center">
741
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
735
			<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
742
			<table cellspacing="2" cellpadding="3" border="1">
736
			<table cellspacing="2" cellpadding="3" border="1">
743
			<tr><th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><th><?= $l_del ?></th></tr>
737
			<tr><th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><th><?= $l_del ?></th></tr>
744
			<?php
738
			<?php
745
			// Read the "dns_local" file
739
			// Read the "dns_local" file
746
			$line_exist = false;
740
			$line_exist = false;
747
			$tab = file(DNS_LOCAL_FILE);
741
			$tab = file(DNS_LOCAL_FILE);
748
			if ($tab) { // not empty
742
			if ($tab) { // not empty
749
				foreach ($tab as $line) {
743
				foreach ($tab as $line) {
750
					if (preg_match ('/^\d+/', $line)) { # begin with one or several digit
744
					if (preg_match ('/^\d+/', $line)) { # begin with one or several digit
751
						$line_exist = true;
745
						$line_exist = true;
752
						$field = preg_split("/\s+/",$line); # split with one or several whitespace (or tab)
746
						$field = preg_split("/\s+/",$line); # split with one or several whitespace (or tab)
753
						$ip_addr   = $field[0];
747
						$ip_addr   = $field[0];
754
						$host_name = $field[1];
748
						$host_name = $field[1];
755
						echo "<tr><td>$ip_addr</td>";
749
						echo "<tr><td>$ip_addr</td>";
756
						echo "<td>$host_name</td>";
750
						echo "<td>$host_name</td>";
757
						if (($ip_addr == "127.0.0.1")|($host_name == "alcasar")) {
751
						if (($ip_addr == "127.0.0.1")|($host_name == "alcasar")) {
758
							echo "<td>";}
752
							echo "<td>";}
759
						else {
753
						else {
760
							echo "<td><input type=\"checkbox\" name=\"$ip_addr|$host_name\">";
754
							echo "<td><input type=\"checkbox\" name=\"$ip_addr|$host_name\">";
761
						}
755
						}
762
						echo "</td></tr>";
756
						echo "</td></tr>";
763
					}
757
					}
764
				}
758
				}
765
			}
759
			}
766
			if (!$line_exist) {
760
			if (!$line_exist) {
767
				echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
761
				echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
768
			}
762
			}
769
			?>
763
			?>
770
			</table>
764
			</table>
771
			<?php if ($line_exist): ?>
765
			<?php if ($line_exist): ?>
772
				<input type="hidden" name="choix" value="del_host">
766
				<input type="hidden" name="choix" value="del_host">
773
				<input type="submit" value="<?= $l_apply ?>">
767
				<input type="submit" value="<?= $l_apply ?>">
774
			<?php endif; ?>
768
			<?php endif; ?>
775
			</form>
769
			</form>
776
		</td>
770
		</td>
777
		<td width="50%" valign="middle" align="center">
771
		<td width="50%" valign="middle" align="center">
778
			<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
772
			<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
779
			<table cellspacing="2" cellpadding="3" border="1">
773
			<table cellspacing="2" cellpadding="3" border="1">
780
			<tr>
774
			<tr>
781
				<th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><td></td>
775
				<th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><td></td>
782
			</tr>
776
			</tr>
783
			<tr>
777
			<tr>
784
				<td>Ex. : 192.168.182.10</td><td>Ex. : my_nas</td><td></td>
778
				<td>Ex. : 192.168.182.10</td><td>Ex. : my_nas</td><td></td>
785
			</tr>
779
			</tr>
786
			<tr>
780
			<tr>
787
				<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
781
				<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
788
				<td><input type="text" name="add_host" size="17"></td>
782
				<td><input type="text" name="add_host" size="17"></td>
789
				<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
783
				<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
790
			</tr>
784
			</tr>
791
			</table>
785
			</table>
792
			</form>
786
			</form>
793
		</td>
787
		</td>
794
	</tr>
788
	</tr>
795
</table>
789
</table>
796
<br>
790
<br>
797
 
-
 
798
<table width="100%" cellspacing="0" cellpadding="0" border="0">
791
<div class="panel">
799
	<tr><th><?= $l_ssl_title ?></th></tr>
792
	<div class="panel-header"><?= $l_ssl_title ?></div>
800
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
-
 
801
</table>
-
 
802
<table width="100%" cellspacing="0" cellpadding="5" border="1">
-
 
803
	<tr><td valign="middle" align="left">
793
	<div class="panel-row">
804
		<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
794
		<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
805
		<input type="hidden" name="choix" value="https_login">
795
		<input type="hidden" name="choix" value="https_login">
806
		<select name="https_login">
796
		<select name="https_login">
807
			<option value="on"<?=  (($conf['HTTPS_LOGIN'] === 'on')  ? ' selected' : '') ?>><?= $l_yes ?></option>
797
			<option value="on"<?=  (($conf['HTTPS_LOGIN'] === 'on')  ? ' selected' : '') ?>><?= $l_yes ?></option>
808
			<option value="off"<?= (($conf['HTTPS_LOGIN'] === 'off') ? ' selected' : '') ?>><?= $l_no ?></option>
798
			<option value="off"<?= (($conf['HTTPS_LOGIN'] === 'off') ? ' selected' : '') ?>><?= $l_no ?></option>
809
		</select>
799
		</select>
810
		<input type="submit" value="<?= $l_apply ?>"><br>
800
		<input type="submit" value="<?= $l_apply ?>"><br>
811
		</form>
801
		</form>
812
		<br>
-
 
813
	</td></tr>
802
	</div>
814
</table>
803
</div>
815
<br>
804
<br>
816
 
-
 
817
<table width="100%" cellspacing="0" cellpadding="0" border="0">
805
<div class="panel">
818
	<tr><th><?= $l_import_cert ?></th></tr>
806
	<div class="panel-header"><?= $l_import_cert ?></div>
819
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
-
 
820
</table>
-
 
821
<table width="100%" cellspacing="0" cellpadding="5" border="1">
807
	<div class="panel-row">
822
	<tr>
-
 
823
		<td width="50%" valign="top">
808
		<div class="panel-cell">
824
			<?php
809
			<?php
825
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
810
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
826
 
-
 
827
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
811
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
828
			$domain               = $certificateInfos['subject']['CN'];
812
			$domain               = $certificateInfos['subject']['CN'];
829
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
813
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
830
			$CAdomain             = $certificateInfos['issuer']['CN'];
814
			$CAdomain             = $certificateInfos['issuer']['CN'];
831
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
815
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
832
			?>
816
			?>
833
			<h3><?= $l_current_certificate ?></h3>
817
			<h3><?= $l_current_certificate ?></h3>
834
			<?= $l_cert_expiration ?> <?= $cert_expiration_date ?><br>
-
 
835
			<?= $l_cert_commonname ?> <?= $domain ?><br>
818
			<b><?= $l_cert_commonname ?></b> <?= $domain ?><br>
836
			<?= $l_cert_organization ?> <?= $organization ?><br/>
819
			<b><?= $l_cert_expiration ?></b> <?= $cert_expiration_date ?><br>
837
			<h4><?=  $l_validated ?></h4>
-
 
838
			<?= $l_cert_commonname ?> <?= $CAdomain ?><br>
820
			<b><?= $l_cert_organization ?></b> <?= $organization ?><br>
839
			<?= $l_cert_organization ?> <?= $CAorganization ?><br>
821
			<b><?= $l_validated ?></b> <?= $CAdomain ?> (<?= $CAorganization ?>)<br>
840
		</td>
822
		</div>
841
		<td width="50%" valign="center">
823
		<div class="panel-cell">
-
 
824
			<?
-
 
825
			if (file_exists('/etc/pki/tls/certs/alcasar.crt.old') && file_exists('/etc/pki/tls/private/alcasar.key.old')){ // An old default certificate exist ?
842
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
826
				echo "<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
843
				<input type="hidden" name="choix" value="default_cert">
827
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_default_cert\">\n";
-
 
828
				echo "\t\t\t\t<input type=\"submit\" value=\"$l_default_cert\"> (alcasar.localdomain)<br>\n";
-
 
829
				echo "\t\t\t</form>\n";}
844
				<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' : '' ?>>
830
			if (!empty($LE_conf['domainRequest']) && ($domain != $LE_conf['domainRequest'])) { // A Let's encrypt certificate exist & it's not the active one ?
-
 
831
				echo "\t\t\t<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'])."\">\n";
-
 
832
				echo "\t\t\t\t<input type=\"hidden\" name=\"choix\" value=\"set_last_LE_cert\">\n";
-
 
833
				echo "\t\t\t\t<input type=\"submit\" value=\"".$l_previous_LE_cert."\"> (".$LE_conf['domainRequest'].")\n";
845
			</form>
834
				echo "\t\t\t</form>\n";}
846
		</td>
835
			?>
847
	</tr>
836
		</div>
848
	<tr>
837
	</div>
-
 
838
	<div class="panel-row">
849
		<td width="50%" valign="top">
839
		<div class="panel-cell">
850
			<h3><?= $l_upload_certificate ?></h3>
840
			<h3><?= $l_upload_certificate ?></h3>
851
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
841
			<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" enctype="multipart/form-data">
852
				<?= $l_private_key;?> <input type="file" name="key"><br>
842
				<?= $l_private_key;?> <input type="file" name="key"><br>
853
				<?= $l_certificate;?> <input type="file" name="crt"><br>
843
				<?= $l_certificate;?> <input type="file" name="crt"><br>
854
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
844
				<?= $l_server_chain;?> <input type="file" name="sc"><br>
855
				<input type="hidden" name="choix" value="import_cert">
845
				<input type="hidden" name="choix" value="import_cert">
856
				<input type="submit" value="<?= $l_import ?>">
846
				<input type="submit" value="<?= $l_import ?>">
857
			</form>
847
			</form>
858
		</td>
848
		</div>
859
		<td width="50%" valign="top">
849
		<div class="panel-cell">
860
			<?php
850
			<?php
861
			// Get step
851
			// Get step
862
			if (empty($LE_conf['domainRequest'])) {
852
			if (empty($LE_conf['domainRequest'])) {
863
				$step = 1;
853
				$step = 1;
864
			} else if (!empty($LE_conf['challenge'])) {
854
			} else if (!empty($LE_conf['challenge'])) {
865
				$step = 2;
855
				$step = 2;
866
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
856
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
867
				$step = 3;
857
				$step = 3;
868
			} else {
858
			} else {
869
				$step = 1;
859
				$step = 1;
870
			}
860
			}
871
			?>
861
			?>
872
			<h3><?= $l_le_integration ?></h3>
862
			<h3><?= $l_le_integration ?></h3>
873
			<?php if ($step === 1): ?>
863
			<?php if ($step === 1): ?>
874
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
864
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
875
					<input type="hidden" name="choix" value="le_issueCert">
865
					<input type="hidden" name="choix" value="le_issueCert">
876
					<?= $l_le_status ?> <?= $l_disabled ?><br>
866
					<?= $l_le_status ?> <?= $l_disabled ?><br>
877
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
867
					<?= $l_le_email ?> <input type="text" name="email" placeholder="adresse@email.com"<?= ((!empty($LE_conf['email'])) ? ' value="'.$LE_conf['email'].'"' : '') ?>><br>
878
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
868
					<?= $l_le_domain_name ?> <input type="text" name="domainname" placeholder="alcasar.domain.tld" required><br>
879
					<input type="submit" name="issue" value="<?= $l_send ?>"><br>
869
					<input type="submit" name="issue" value="<?= $l_send ?>"><br>
880
				</form>
870
				</form>
881
			<?php elseif ($step === 2): ?>
871
			<?php elseif ($step === 2): ?>
882
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
872
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
883
					<input type="hidden" name="choix" value="le_renewCert">
873
					<input type="hidden" name="choix" value="le_renewCert">
884
					<?= $l_le_status ?> <?= $l_pending_validation ?><br>
874
					<?= $l_le_status ?> <?= $l_pending_validation ?><br>
885
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
875
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
886
					<?= $l_le_ask_on ?> <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br>
876
					<?= $l_le_ask_on ?> <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br>
887
					<?= $l_le_dns_entry_txt ?> "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
877
					<?= $l_le_dns_entry_txt ?> "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
888
					<?= $l_le_challenge ?> "<?= $LE_conf['challenge'] ?>"<br>
878
					<?= $l_le_challenge ?> "<?= $LE_conf['challenge'] ?>"<br>
889
					<input type="submit" name="recheck" value="<?= $l_recheck ?>"> <input type="submit" name="cancel" value="<?= $l_cancel ?>"><br>
879
					<input type="submit" name="recheck" value="<?= $l_recheck ?>"> <input type="submit" name="cancel" value="<?= $l_cancel ?>"><br>
890
				</form>
880
				</form>
891
			<?php elseif ($step === 3): ?>
881
			<?php elseif ($step === 3): ?>
892
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
882
				<form method="post" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>">
893
					<input type="hidden" name="choix" value="le_renewCert">
883
					<input type="hidden" name="choix" value="le_renewCert">
894
					<?= $l_le_status ?> <?= $l_enabled ?><br>
884
					<?= $l_le_status ?> <?= $l_enabled ?><br>
895
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
885
					<?= $l_le_domain_name ?> <?= $LE_conf['domainRequest'] ?><br>
896
					<?= $l_le_api ?>  <?= $LE_conf['dnsapi'] ?><br>
886
					<?= $l_le_api ?>  <?= $LE_conf['dnsapi'] ?><br>
897
					<?= $l_le_next_renewal ?> <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
887
					<?= $l_le_next_renewal ?> <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
898
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
888
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
899
						<input type="submit" name="recheck" value="<?= $l_renew ?>"><br>
889
						<input type="submit" name="recheck" value="<?= $l_renew ?>"><br>
900
					<?php else: ?>
890
					<?php else: ?>
901
						<input type="submit" name="recheck_force" value="<?= $l_renew_force ?>"><br>
891
						<input type="submit" name="recheck_force" value="<?= $l_renew_force ?>"><br>
902
					<?php endif; ?>
892
					<?php endif; ?>
903
				</form>
893
				</form>
904
			<?php endif; ?>
894
			<?php endif; ?>
905
			<?php if (isset($cmdResponse)): ?>
895
			<?php if (isset($cmdResponse)): ?>
906
				<p><?= $cmdResponse ?></p>
896
				<p><?= $cmdResponse ?></p>
907
			<?php endif; ?>
897
			<?php endif; ?>
908
		</td>
898
		</div>
909
	</tr>
899
	</div>
910
</table>
900
</div>
911
</body>
901
</body>
912
</html>
902
</html>
913
 
903