Subversion Repositories ALCASAR

Rev

Rev 2304 | Rev 2324 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

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