Subversion Repositories ALCASAR

Rev

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

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