Subversion Repositories ALCASAR

Rev

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

Rev 2299 Rev 2304
1
<?php
1
<?php
-
 
2
# $Id: network.php 2304 2017-06-26 12:56:14Z tom.houdayer $
-
 
3
 
2
/* written by steweb57 & Rexy */
4
/* written by steweb57 & Rexy */
3
 
5
 
4
/********************
6
/********************
5
* READ CONF FILES   *
7
* READ CONF FILES   *
6
*********************/
8
*********************/
7
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
9
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
8
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers");
10
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers");
9
define ("ETHERS_INFO_FILE", "/usr/local/etc/alcasar-ethers-info");
11
define ("ETHERS_INFO_FILE", "/usr/local/etc/alcasar-ethers-info");
10
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');
11
$conf_files=array(CONF_FILE,ETHERS_FILE,ETHERS_INFO_FILE,DNS_LOCAL_FILE);
14
$conf_files=array(CONF_FILE,ETHERS_FILE,ETHERS_INFO_FILE,DNS_LOCAL_FILE, LETS_ENCRYPT_FILE);
12
$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])$/';
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])$/';
13
$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]))$/';
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]))$/';
14
$network_modification=0;
17
$network_modification=0;
15
foreach ($conf_files as $file){
18
foreach ($conf_files as $file){
16
if (!file_exists($file)){
19
if (!file_exists($file)){
17
	exit("Requested file ".$file." isn't present");}
20
	exit("Requested file ".$file." isn't present");}
18
if (!is_readable($file)){
21
if (!is_readable($file)){
19
	exit("Can't read the file ".$file);}
22
	exit("Can't read the file ".$file);}
20
}
23
}
21
# Choice of language
24
# Choice of language
22
$Language = 'en';
25
$Language = 'en';
23
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
26
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
24
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
27
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
25
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
28
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
26
if($Language == 'fr'){
29
if($Language == 'fr'){
27
	$l_network_title	= "Configuration réseau";
30
	$l_network_title	= "Configuration réseau";
28
	$l_extif_legend		= " (Interface connectée à Internet)";
31
	$l_extif_legend		= " (Interface connectée à Internet)";
29
	$l_intif_legend		= " (Réseau de consultation)";
32
	$l_intif_legend		= " (Réseau de consultation)";
30
	$l_internet_legend	= "INTERNET";
33
	$l_internet_legend	= "INTERNET";
31
	$l_ip_mask		= "Masque";
34
	$l_ip_mask		= "Masque";
32
	$l_ip_router		= "Passerelle";
35
	$l_ip_router		= "Passerelle";
33
	$l_ip_public		= "Adresse IP publique";
36
	$l_ip_public		= "Adresse IP publique";
34
	$l_ip_dns1		= "DNS1";
37
	$l_ip_dns1		= "DNS1";
35
	$l_ip_dns2		= "DNS2";
38
	$l_ip_dns2		= "DNS2";
36
	$l_dhcp_title		= "Service DHCP";
39
	$l_dhcp_title		= "Service DHCP";
37
	$l_dhcp_state		= "Mode actuel";
40
	$l_dhcp_state		= "Mode actuel";
38
	$l_DHCP_on		= "actif";
41
	$l_DHCP_on		= "actif";
39
	$l_DHCP_off		= "inactif";
42
	$l_DHCP_off		= "inactif";
40
	$l_DHCP_off_explain	= "! Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
43
	$l_DHCP_off_explain	= "/!\\ Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
41
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
44
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
42
	$l_mac_address		= "Adresse MAC";
45
	$l_mac_address		= "Adresse MAC";
43
	$l_ip_address		= "Adresse IP";
46
	$l_ip_address		= "Adresse IP";
44
	$l_host_name		= "Nom d'hôte";
47
	$l_host_name		= "Nom d'hôte";
45
	$l_del			= "Supprimer de la liste";
48
	$l_del			= "Supprimer de la liste";
46
	$l_add_to_list		= "Ajouter";
49
	$l_add_to_list		= "Ajouter";
47
	$l_apply		= "Appliquer les changements";
50
	$l_apply		= "Appliquer les changements";
48
	$l_local_dns		= "Résolution local de nom";
51
	$l_local_dns		= "Résolution local de nom";
49
	$l_import_cert		= "Import de certificat";
52
	$l_import_cert		= "Import de certificat";
50
	$l_private_key		= "Clé privée (.key) :";
53
	$l_private_key		= "Clé privée (.key) :";
51
	$l_certificate		= "Certificat (.crt) :";
54
	$l_certificate		= "Certificat (.crt) :";
52
	$l_server_chain		= "Chaîne de certification (si nécéssaire : .crt) :";
55
	$l_server_chain		= "Chaîne de certification (si nécéssaire : .crt) :";
53
	$l_default_cert		= "Revenir au certificat d'origine";
56
	$l_default_cert		= "Revenir au certificat d'origine";
54
	$l_import		= "Importer";
57
	$l_import		= "Importer";
55
	$l_current_certificate  = "Certificat actuel";
58
	$l_current_certificate  = "Certificat actuel";
56
	$l_validated		= "Validé par :";
59
	$l_validated		= "Validé par :";
57
} else {
60
} else {
58
	$l_network_title	= "Network configuration";
61
	$l_network_title	= "Network configuration";
59
	$l_extif_legend		= " (Internet connected interface)";
62
	$l_extif_legend		= " (Internet connected interface)";
60
	$l_intif_legend		= " (Private network)";
63
	$l_intif_legend		= " (Private network)";
61
	$l_internet_legend	= "INTERNET";
64
	$l_internet_legend	= "INTERNET";
62
	$l_ip_mask		= "Mask";
65
	$l_ip_mask		= "Mask";
63
	$l_ip_router		= "Gateway";
66
	$l_ip_router		= "Gateway";
64
	$l_ip_public		= "Public IP address";
67
	$l_ip_public		= "Public IP address";
65
	$l_ip_dns1		= "DNS1";
68
	$l_ip_dns1		= "DNS1";
66
	$l_ip_dns2		= "DNS2";
69
	$l_ip_dns2		= "DNS2";
67
	$l_dhcp_title		= "DHCP service";
70
	$l_dhcp_title		= "DHCP service";
68
	$l_dhcp_state		= "Current mode";
71
	$l_dhcp_state		= "Current mode";
69
	$l_DHCP_on		= "enabled";
72
	$l_DHCP_on		= "enabled";
70
	$l_DHCP_off		= "disabled";
73
	$l_DHCP_off		= "disabled";
71
	$l_DHCP_off_explain	= "! Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
74
	$l_DHCP_off_explain	= "/!\\ Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
72
	$l_static_dhcp_title	= "Static IP addresses reservation";
75
	$l_static_dhcp_title	= "Static IP addresses reservation";
73
	$l_mac_address		= "MAC Address";
76
	$l_mac_address		= "MAC Address";
74
	$l_ip_address		= "IP Address";
77
	$l_ip_address		= "IP Address";
75
	$l_host_name		= "Host name";
78
	$l_host_name		= "Host name";
76
	$l_del			= "Delete from list";
79
	$l_del			= "Delete from list";
77
	$l_add_to_list		= "Add";
80
	$l_add_to_list		= "Add";
78
	$l_apply		= "Apply changes";
81
	$l_apply		= "Apply changes";
79
	$l_local_dns		= "Local name resolution";
82
	$l_local_dns		= "Local name resolution";
80
	$l_import_cert		= "Certificate import";
83
	$l_import_cert		= "Certificate import";
81
	$l_private_key		= "Private key (.key) :";
84
	$l_private_key		= "Private key (.key) :";
82
	$l_certificate		= "Certificate (.crt) :";
85
	$l_certificate		= "Certificate (.crt) :";
83
	$l_server_chain		= "Server-chain (if necessary : .crt) :";
86
	$l_server_chain		= "Server-chain (if necessary : .crt) :";
84
	$l_default_cert		= "Back to default certificate";
87
	$l_default_cert		= "Back to default certificate";
85
	$l_import		= "Import";
88
	$l_import		= "Import";
86
	$l_current_certificate  = "Current certificate";
89
	$l_current_certificate  = "Current certificate";
87
	$l_validated		= "Validated by :";
90
	$l_validated		= "Validated by :";
88
}
91
}
89
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
92
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
90
switch ($choix)
93
switch ($choix)
91
{
94
{
92
case 'DHCP_On' :
95
case 'DHCP_On' :
93
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -on");
96
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -on");
94
	break;
97
	break;
95
case 'DHCP_Off' :
98
case 'DHCP_Off' :
96
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -off");
99
	exec ("sudo /usr/local/bin/alcasar-dhcp.sh -off");
97
	break;
100
	break;
98
case 'new_mac' :
101
case 'new_mac' :
99
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
102
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
100
		{
103
		{
101
		$tab=file(ETHERS_FILE);
104
		$tab=file(ETHERS_FILE);
102
		if ($tab)  # the file isn't empty
105
		if ($tab)  # the file isn't empty
103
			{
106
			{
104
			$insert="True";
107
			$insert="True";
105
			$new_mac_addr=trim($_POST['add_mac'],"\x00..\x20");
108
			$new_mac_addr=trim($_POST['add_mac'],"\x00..\x20");
106
			$new_ip_addr=trim($_POST['add_ip'],"\x00..\x20");
109
			$new_ip_addr=trim($_POST['add_ip'],"\x00..\x20");
107
			foreach ($tab as $line)  # verify that MAC or IP address doesn't exist
110
			foreach ($tab as $line)  # verify that MAC or IP address doesn't exist
108
				{
111
				{
109
				$field=explode(" ", $line);
112
				$field=explode(" ", $line);
110
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
113
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
111
				if (strcasecmp($new_mac_addr, $mac_addr) == 0)
114
				if (strcasecmp($new_mac_addr, $mac_addr) == 0)
112
					{
115
					{
113
					$insert="False";
116
					$insert="False";
114
					break;
117
					break;
115
					}
118
					}
116
				if (strcasecmp($new_ip_addr, $ip_addr) == 0)
119
				if (strcasecmp($new_ip_addr, $ip_addr) == 0)
117
					{
120
					{
118
					$insert="False";
121
					$insert="False";
119
					break;
122
					break;
120
					}
123
					}
121
				}
124
				}
122
			if ($insert == "True")
125
			if ($insert == "True")
123
				{
126
				{
124
				$line = $new_mac_addr . " " . $new_ip_addr . "\n";
127
				$line = $new_mac_addr . " " . $new_ip_addr . "\n";
125
				$pointeur=fopen(ETHERS_FILE,"a");
128
				$pointeur=fopen(ETHERS_FILE,"a");
126
				fwrite ($pointeur, $line);
129
				fwrite ($pointeur, $line);
127
				fclose ($pointeur);
130
				fclose ($pointeur);
128
				$pointeur=fopen(ETHERS_INFO_FILE,"a");
131
				$pointeur=fopen(ETHERS_INFO_FILE,"a");
129
				$line = $new_mac_addr . " " . $new_ip_addr . " #" . trim($_POST['info'],"\x00..\x20") . "\n";
132
				$line = $new_mac_addr . " " . $new_ip_addr . " #" . trim($_POST['info'],"\x00..\x20") . "\n";
130
				fwrite ($pointeur, $line);
133
				fwrite ($pointeur, $line);
131
				fclose ($pointeur);
134
				fclose ($pointeur);
132
				exec ("sudo /usr/bin/systemctl reload chilli");
135
				exec ("sudo /usr/bin/systemctl reload chilli");
133
				}
136
				}
134
			}
137
			}
135
		}
138
		}
136
	break;
139
	break;
137
case 'del_mac' :
140
case 'del_mac' :
138
	foreach ($_POST as $key => $value)
141
	foreach ($_POST as $key => $value)
139
		{
142
		{
140
		if ($value == 'on')
143
		if ($value == 'on')
141
			{
144
			{
142
			$ether_file=ETHERS_FILE;
145
			$ether_file=ETHERS_FILE;
143
			exec("/bin/sed -i \"/^$key/d\" $ether_file"); 
146
			exec("/bin/sed -i \"/^$key/d\" $ether_file"); 
144
			$ether_file=ETHERS_INFO_FILE;
147
			$ether_file=ETHERS_INFO_FILE;
145
			exec("/bin/sed -i \"/^$key/d\" $ether_file"); 
148
			exec("/bin/sed -i \"/^$key/d\" $ether_file"); 
146
			exec ("sudo /usr/bin/systemctl reload chilli");
149
			exec ("sudo /usr/bin/systemctl reload chilli");
147
			}
150
			}
148
		}
151
		}
149
	break;
152
	break;
150
case 'new_host' :
153
case 'new_host' :
151
	if ((trim($_POST['add_host']) != "") and (trim($_POST['add_ip']) != ""))
154
	if ((trim($_POST['add_host']) != "") and (trim($_POST['add_ip']) != ""))
152
		{
155
		{
153
		$tab=file(DNS_LOCAL_FILE);
156
		$tab=file(DNS_LOCAL_FILE);
154
		$insert="True";
157
		$insert="True";
155
		if ($tab)  # the file isn't empty
158
		if ($tab)  # the file isn't empty
156
			{
159
			{
157
			foreach ($tab as $line)  # verify that host or IP address doesn't exist
160
			foreach ($tab as $line)  # verify that host or IP address doesn't exist
158
				{
161
				{
159
				if (preg_match ('/^address/', $line))
162
				if (preg_match ('/^address/', $line))
160
					{
163
					{
161
					$field=explode("/", $line);
164
					$field=explode("/", $line);
162
					$host_name=trim($field[1]);$ip_addr=trim($field[2]);
165
					$host_name=trim($field[1]);$ip_addr=trim($field[2]);
163
					if (strcasecmp(trim($_POST['add_host']),trim($host_name)) == 0)
166
					if (strcasecmp(trim($_POST['add_host']),trim($host_name)) == 0)
164
						{
167
						{
165
						$insert="False";
168
						$insert="False";
166
						break;
169
						break;
167
						}
170
						}
168
					if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
171
					if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
169
						{
172
						{
170
						$insert="False";
173
						$insert="False";
171
						break;
174
						break;
172
						}
175
						}
173
					}
176
					}
174
				}
177
				}
175
			if ($insert == "True")
178
			if ($insert == "True")
176
				{
179
				{
177
				$line1 = "address=/".trim($_POST['add_host'])."/".trim($_POST['add_ip'])."\n";
180
				$line1 = "address=/".trim($_POST['add_host'])."/".trim($_POST['add_ip'])."\n";
178
				$explode_ip=explode('.',trim($_POST['add_ip']));
181
				$explode_ip=explode('.',trim($_POST['add_ip']));
179
				$reverse_ip=implode('.',array_reverse($explode_ip));
182
				$reverse_ip=implode('.',array_reverse($explode_ip));
180
				$line2 = "ptr-record=".$reverse_ip.".in-addr.arpa,".trim($_POST['add_host'])."\n";
183
				$line2 = "ptr-record=".$reverse_ip.".in-addr.arpa,".trim($_POST['add_host'])."\n";
181
				$pointeur=fopen(DNS_LOCAL_FILE,"a");
184
				$pointeur=fopen(DNS_LOCAL_FILE,"a");
182
				fwrite ($pointeur, $line1);
185
				fwrite ($pointeur, $line1);
183
				fwrite ($pointeur, $line2);
186
				fwrite ($pointeur, $line2);
184
				fclose ($pointeur);
187
				fclose ($pointeur);
185
				exec ("sudo /usr/bin/systemctl restart dnsmasq");
188
				exec ("sudo /usr/bin/systemctl restart dnsmasq");
186
				exec ("sudo /usr/bin/systemctl restart dnsmasq-blacklist");
189
				exec ("sudo /usr/bin/systemctl restart dnsmasq-blacklist");
187
				exec ("sudo /usr/bin/systemctl restart dnsmasq-whitelist");
190
				exec ("sudo /usr/bin/systemctl restart dnsmasq-whitelist");
188
				}
191
				}
189
			}
192
			}
190
		}
193
		}
191
	break;
194
	break;
192
case 'del_host' :
195
case 'del_host' :
193
	foreach ($_POST as $key => $value)
196
	foreach ($_POST as $key => $value)
194
		{
197
		{
195
		if ($value == 'on')
198
		if ($value == 'on')
196
			{
199
			{
197
			$dns_local_file=DNS_LOCAL_FILE;
200
			$dns_local_file=DNS_LOCAL_FILE;
198
			exec("/bin/sed -i \"/$key/d\" $dns_local_file"); 
201
			exec("/bin/sed -i \"/$key/d\" $dns_local_file"); 
199
			exec ("sudo /usr/bin/systemctl restart dnsmasq");
202
			exec ("sudo /usr/bin/systemctl restart dnsmasq");
200
			exec ("sudo /usr/bin/systemctl restart dnsmasq-blacklist");
203
			exec ("sudo /usr/bin/systemctl restart dnsmasq-blacklist");
201
			exec ("sudo /usr/bin/systemctl restart dnsmasq-whitelist");
204
			exec ("sudo /usr/bin/systemctl restart dnsmasq-whitelist");
202
			}
205
			}
203
		}
206
		}
204
	break;
207
	break;
205
}
208
}
206
 
209
 
207
// Fonction de test de connectivité internet
210
// Fonction de test de connectivité internet
208
function internetTest(){
211
function internetTest(){
209
	$host = "www.google.fr"; # Google Test
212
	$host = "www.google.fr"; # Google Test
210
	$port = "80";
213
	$port = "80";
211
	//var $num;	//not used
214
	//var $num;	//not used
212
	//var $error;	//not used
215
	//var $error;	//not used
213
 
216
 
214
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
217
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
215
		return false;
218
		return false;
216
	} else {
219
	} else {
217
		fclose($sock);
220
		fclose($sock);
218
		return true;
221
		return true;
219
	}
222
	}
220
}
223
}
221
/***********************************
224
/***********************************
222
* 	Update ALCASAR_CONF_FILE   *
225
* 	Update ALCASAR_CONF_FILE   *
223
***********************************/
226
***********************************/
224
/*******************************************
227
/*******************************************
225
*	Read ALCASAR_CONF_FILE Before     *
228
*	Read ALCASAR_CONF_FILE Before     *
226
********************************************/
229
********************************************/
227
$file_conf = fopen(CONF_FILE, 'r');
230
$file_conf = fopen(CONF_FILE, 'r');
228
if (!$file_conf) {
231
if (!$file_conf) {
229
	exit('Error opening the file '.CONF_FILE);
232
	exit('Error opening the file '.CONF_FILE);
230
}
233
}
231
while (!feof($file_conf)) {
234
while (!feof($file_conf)) {
232
	$buffer = fgets($file_conf, 4096);
235
	$buffer = fgets($file_conf, 4096);
233
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
236
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
234
		$tmp = explode('=', $buffer);
237
		$tmp = explode('=', $buffer);
235
		$conf[trim($tmp[0])] = trim($tmp[1]);
238
		$conf[trim($tmp[0])] = trim($tmp[1]);
236
	}
239
	}
237
}
240
}
238
fclose($file_conf);
241
fclose($file_conf);
239
	
242
	
240
if(isset($_POST['dns1']) && preg_match($reg_ip,$_POST['dns1']))
243
if(isset($_POST['dns1']) && preg_match($reg_ip,$_POST['dns1']))
241
{
244
{
242
	file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'],'DNS1='.$_POST['dns1']."\n",file_get_contents(CONF_FILE)));
245
	file_put_contents(CONF_FILE, str_replace('DNS1='.$conf['DNS1'],'DNS1='.$_POST['dns1']."\n",file_get_contents(CONF_FILE)));
243
	$network_modification=1;
246
	$network_modification=1;
244
}
247
}
245
if(isset($_POST['dns2']) && preg_match($reg_ip,$_POST['dns2']))
248
if(isset($_POST['dns2']) && preg_match($reg_ip,$_POST['dns2']))
246
{
249
{
247
	file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'],'DNS2='.$_POST['dns2']."\n",file_get_contents(CONF_FILE)));
250
	file_put_contents(CONF_FILE, str_replace('DNS2='.$conf['DNS2'],'DNS2='.$_POST['dns2']."\n",file_get_contents(CONF_FILE)));
248
	$network_modification=1;
251
	$network_modification=1;
249
}
252
}
250
 
253
 
251
if(isset($_POST['ip_public']) && preg_match($reg_ip_cidr,$_POST['ip_public']))
254
if(isset($_POST['ip_public']) && preg_match($reg_ip_cidr,$_POST['ip_public']))
252
{
255
{
253
	file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'],'PUBLIC_IP='.$_POST['ip_public']."\n",file_get_contents(CONF_FILE)));
256
	file_put_contents(CONF_FILE, str_replace('PUBLIC_IP='.$conf['PUBLIC_IP'],'PUBLIC_IP='.$_POST['ip_public']."\n",file_get_contents(CONF_FILE)));
254
	$network_modification=1;
257
	$network_modification=1;
255
}
258
}
256
 
259
 
257
if(isset($_POST['ip_gw']) && preg_match($reg_ip,$_POST['ip_gw']))
260
if(isset($_POST['ip_gw']) && preg_match($reg_ip,$_POST['ip_gw']))
258
{
261
{
259
	file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'],'GW='.$_POST['ip_gw']."\n",file_get_contents(CONF_FILE)));
262
	file_put_contents(CONF_FILE, str_replace('GW='.$conf['GW'],'GW='.$_POST['ip_gw']."\n",file_get_contents(CONF_FILE)));
260
	$network_modification=1;
263
	$network_modification=1;
261
}
264
}
262
 
265
 
263
if(isset($_POST['ip_private']) && preg_match($reg_ip_cidr,$_POST['ip_private']))
266
if(isset($_POST['ip_private']) && preg_match($reg_ip_cidr,$_POST['ip_private']))
264
{
267
{
265
	file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'],'PRIVATE_IP='.$_POST['ip_private']."\n",file_get_contents(CONF_FILE)));
268
	file_put_contents(CONF_FILE, str_replace('PRIVATE_IP='.$conf['PRIVATE_IP'],'PRIVATE_IP='.$_POST['ip_private']."\n",file_get_contents(CONF_FILE)));
266
	$network_modification=1;
269
	$network_modification=1;
267
}
270
}
268
if($network_modification)
271
if($network_modification)
269
{
272
{
270
	exec("sudo /usr/local/bin/alcasar-conf.sh -apply");
273
	exec("sudo /usr/local/bin/alcasar-conf.sh -apply");
271
}
274
}
272
 
275
 
273
/*******************************************
276
/*******************************************
274
*	Read ALCASAR_CONF_FILE Updated     *
277
*	Read ALCASAR_CONF_FILE Updated     *
275
********************************************/
278
********************************************/
276
$file_conf = fopen(CONF_FILE, 'r');
279
$file_conf = fopen(CONF_FILE, 'r');
277
if (!$file_conf) {
280
if (!$file_conf) {
278
	exit('Error opening the file '.CONF_FILE);
281
	exit('Error opening the file '.CONF_FILE);
279
}
282
}
280
while (!feof($file_conf)) {
283
while (!feof($file_conf)) {
281
	$buffer = fgets($file_conf, 4096);
284
	$buffer = fgets($file_conf, 4096);
282
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
285
	if ((strpos($buffer, '=') !== false) && (substr($buffer, 0, 1) !== '#')) {
283
		$tmp = explode('=', $buffer);
286
		$tmp = explode('=', $buffer);
284
		$conf[trim($tmp[0])] = trim($tmp[1]);
287
		$conf[trim($tmp[0])] = trim($tmp[1]);
285
	}
288
	}
286
}
289
}
287
fclose($file_conf);
290
fclose($file_conf);
288
?>
291
?>
289
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
292
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
290
<html><!-- written by steweb57 & rexy -->
293
<html><!-- written by steweb57 & rexy -->
291
<head>
294
<head>
292
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
295
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
293
<title><?php echo $l_network_title; ?></title>
296
<title><?php echo $l_network_title; ?></title>
294
<link rel="stylesheet" href="/css/style.css" type="text/css">
297
<link rel="stylesheet" href="/css/style.css" type="text/css">
295
<script type="text/javascript">
298
<script type="text/javascript">
296
function MAC_Control(formulaire){
299
function MAC_Control(formulaire){
297
/*MAC control (upper case and '-' separator*/
300
/*MAC control (upper case and '-' separator*/
298
	var regex1 = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/; //vérification adresse mac
301
	var regex1 = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/; //vérification adresse mac
299
	if (regex1.test(document.forms[formulaire].add_mac.value)){
302
	if (regex1.test(document.forms[formulaire].add_mac.value)){
300
		document.forms[formulaire].add_mac.value=document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
303
		document.forms[formulaire].add_mac.value=document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
301
		return true;
304
		return true;
302
	} else {
305
	} else {
303
		alert("Invalid MAC address");//non internationnalisé
306
		alert("Invalid MAC address");//non internationnalisé
304
		return false;
307
		return false;
305
	}
308
	}
306
}
309
}
307
</script>
310
</script>
308
</head>
311
</head>
309
<body>
312
<body>
310
<table width="100%" border="0" cellspacing="0" cellpadding="0">
313
<table width="100%" cellspacing="0" cellpadding="0" border="0">
311
	<tr><th><?php echo $l_network_title; ?></th></tr>
314
	<tr><th><?php echo $l_network_title; ?></th></tr>
312
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
315
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
313
</table>
316
</table>
314
<? echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";?>
317
<? echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";?>
315
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
318
<table width="100%" cellspacing="0" cellpadding="5" border="1">
316
	<tr><td valign="middle" align="left">
319
	<tr><td valign="middle" align="left">
317
	<fieldset>
320
	<fieldset>
318
	<legend><?php echo $l_internet_legend;
321
	<legend><?php echo $l_internet_legend;
319
 	if (InternetTest()){
322
 	if (InternetTest()){
320
		echo " <img src='/images/state_ok.gif'>";
323
		echo " <img src='/images/state_ok.gif'>";
321
		$IP_PUB = exec ("wget http://ipecho.net/plain -O - -o /dev/null");}
324
		$IP_PUB = exec ("wget http://ipecho.net/plain -O - -o /dev/null");}
322
	else 	{
325
	else 	{
323
		echo " <img src='/images/state_error.gif'>";
326
		echo " <img src='/images/state_error.gif'>";
324
		$IP_PUB = "-.-.-.-";}
327
		$IP_PUB = "-.-.-.-";}
325
	?></legend>
328
	?></legend>
326
	<table>
329
	<table>
327
		<tr><td><?php echo $l_ip_public." : ".$IP_PUB;?></td></tr>
330
		<tr><td><?php echo $l_ip_public." : ".$IP_PUB;?></td></tr>
328
		<?php
331
		<?php
329
		echo "<tr><td>".$l_ip_dns1." <input style='width:120px' type='text' name='dns1' value=".$conf["DNS1"]."/></td></tr>";
332
		echo '<tr><td>'.$l_ip_dns1.' <input style="width:120px" type="text" name="dns1" value="'.$conf['DNS1'].'" /></td></tr>';
330
		echo "<tr><td>".$l_ip_dns2." <input style='width:120px' type='text' name='dns2' value=".$conf["DNS2"]."/></td></tr>";
333
		echo '<tr><td>'.$l_ip_dns2.' <input style="width:120px" type="text" name="dns2" value="'.$conf['DNS2'].'" /></td></tr>';
331
		?>
334
		?>
332
	</table>
335
	</table>
333
	</fieldset>
336
	</fieldset>
334
	</td><td>
337
	</td><td>
335
	<fieldset>
338
	<fieldset>
336
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
339
	<legend><?php echo $conf['EXTIF'].$l_extif_legend; ?></legend>
337
	<table>
340
	<table>
338
		<?php
341
		<?php
339
		echo "<tr><td>".$l_ip_address." <input style='width:150px' type='text' name='ip_public' value=".$conf['PUBLIC_IP']."/></td></tr>";
342
		echo '<tr><td>'.$l_ip_address.' <input style="width:150px" type="text" name="ip_public" value="'.$conf['PUBLIC_IP'].'" /></td></tr>';
340
		echo "<tr><td>".$l_ip_router." <input style='width:120px' type='text' name='ip_gw' value=".$conf['GW']."/></td></tr>";
343
		echo '<tr><td>'.$l_ip_router.' <input style="width:120px" type="text" name="ip_gw" value="'.$conf['GW'].'" /></td></tr>';
341
		?>
344
		?>
342
	</table>
345
	</table>
343
	</fieldset>
346
	</fieldset>
344
	</td><td>
347
	</td><td>
345
	<fieldset>
348
	<fieldset>
346
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
349
	<legend><?php echo $conf['INTIF'].$l_intif_legend; ?></legend>
347
	<table>
350
	<table>
348
	<?php
351
	<?php
349
	echo "<tr><td>".$l_ip_address."</td><td> <input style='width:150px' type='text' name='ip_private' value=".$conf['PRIVATE_IP']." /></td></tr>";
352
	echo '<tr><td>'.$l_ip_address.'</td><td> <input style="width:150px" type="text" name="ip_private" value="'.$conf['PRIVATE_IP'].'" /></td></tr>';
350
	?>
353
	?>
351
	</table>
354
	</table>
352
	</fieldset>
355
	</fieldset>
353
	</td></tr>
356
	</td></tr>
354
	<tr><td colspan="3" align="center">
357
	<tr><td colspan="3" align="center">
355
	<?php echo "<input type='submit' value='$l_apply'>";?>
358
	<?php echo "<input type='submit' value='$l_apply'>";?>
356
	</td></tr>
359
	</td></tr>
357
</table>
360
</table>
358
</form>
361
</form>
359
<table width="100%" border="0" cellspacing="0" cellpadding="0">
362
<table width="100%" cellspacing="0" cellpadding="0" border="0">
360
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
363
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
361
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
364
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
362
</table>
365
</table>
363
<table width="100%" border=1 cellspacing=0 cellpadding=0>
366
<table width="100%" cellspacing="0" cellpadding="5" border="1">
364
<tr><td colspan="2" valign="middle" align="left">
367
<tr><td colspan="2" valign="middle" align="left">
365
<?
368
<?
366
$dhcp_state=trim($conf["DHCP"]);
369
$dhcp_state=trim($conf["DHCP"]);
367
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
370
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
368
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
371
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
369
echo "<select name='choix'>";
372
echo "<select name='choix'>";
370
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
373
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
371
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on";
374
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on";
372
echo "</select>";
375
echo "</select>";
373
echo "<input type=submit value='$l_apply'>";
376
echo "<input type=submit value='$l_apply'>";
374
echo "<br>$l_DHCP_off_explain";
377
echo "<br>$l_DHCP_off_explain";
375
 
378
 
376
echo "</FORM>";
379
echo "</FORM>";
377
echo "</td></tr>";
380
echo "</td></tr>";
378
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
381
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
379
else { echo "</TABLE>"; }
382
else { echo "</table>"; }
380
$maxsize=100000;
383
$maxsize=100000;
381
?>
384
?>
382
 
385
 
383
<table width="100%" border="0" cellspacing="0" cellpadding="0">
386
<table width="100%" cellspacing="0" cellpadding="0" border="0">
384
	<tr><th><?php echo $l_local_dns;?></th></tr>
387
	<tr><th><?php echo $l_local_dns;?></th></tr>
385
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
388
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
386
</table>
389
</table>
387
<table width="100%" border="1" cellspacing="0" cellpadding="0">
390
<table width="100%" cellspacing="0" cellpadding="5" border="1">
388
<tr><td colspan=2 align="center">
391
<tr><td width="50%" align="center">
389
<?
392
<?
390
echo "<FORM action='network.php' method='POST'>";
393
echo "<FORM action='network.php' method='POST'>";
391
echo "<table cellspacing=2 cellpadding=3 border=1>";
394
echo "<table cellspacing=2 cellpadding=3 border=1>";
392
echo "<tr><th>$l_host_name<th>$l_ip_address<th>$l_del</tr>";
395
echo "<tr><th>$l_host_name<th>$l_ip_address<th>$l_del</tr>";
393
// Read the "dns_local" file
396
// Read the "dns_local" file
394
$line_exist=False;
397
$line_exist=False;
395
$tab=file(DNS_LOCAL_FILE);
398
$tab=file(DNS_LOCAL_FILE);
396
if ($tab)  # not empty
399
if ($tab)  # not empty
397
	{
400
	{
398
	foreach ($tab as $line)
401
	foreach ($tab as $line)
399
		{
402
		{
400
			if (preg_match ('/^address/', $line))
403
			if (preg_match ('/^address/', $line))
401
			{
404
			{
402
				$line_exist=True;
405
				$line_exist=True;
403
				$field=explode("/", $line);
406
				$field=explode("/", $line);
404
				$host_name=$field[1];
407
				$host_name=$field[1];
405
				$ip_addr=$field[2];
408
				$ip_addr=$field[2];
406
				echo "<tr><td>$host_name";
409
				echo "<tr><td>$host_name";
407
				echo "<td>$ip_addr";
410
				echo "<td>$ip_addr";
408
				echo "<td><input type='checkbox' name='$host_name'>";
411
				echo "<td><input type='checkbox' name='$host_name'>";
409
				echo "</tr>";
412
				echo "</tr>";
410
			}
413
			}
411
		}
414
		}
412
	}
415
	}
413
echo "</table>";
416
echo "</table>";
414
if ($line_exist)
417
if ($line_exist)
415
	{
418
	{
416
	echo "<input type='hidden' name='choix' value='del_host'>";
419
	echo "<input type='hidden' name='choix' value='del_host'>";
417
	echo "<input type='submit' value='$l_apply'>";
420
	echo "<input type='submit' value='$l_apply'>";
418
	}	
421
	}	
419
echo "</form></td><td valign='middle' align='center'>";
422
echo "</form></td><td width=\"50%\" valign='middle' align='center'>";
420
echo "<FORM name='new_host' action='network.php' method='POST'>";
423
echo "<FORM name='new_host' action='network.php' method='POST'>";
421
echo "<table cellspacing=2 cellpadding=3 border=1>";
424
echo "<table cellspacing=2 cellpadding=3 border=1>";
422
echo "<tr><th>$l_host_name<th>$l_ip_address";
425
echo "<tr><th>$l_host_name<th>$l_ip_address";
423
?>
426
?>
424
<td></td></tr>
427
<td></td></tr>
425
<tr><td>Ex. : my_nas</td><td>Ex. : 192.168.182.10</td><td></td></tr>
428
<tr><td>Ex. : my_nas</td><td>Ex. : 192.168.182.10</td><td></td></tr>
426
<tr><td><input type='text' name='add_host' size='17'></td>
429
<tr><td><input type='text' name='add_host' size='17'></td>
427
<td><input type='text' name='add_ip' size='10'><input type='hidden' name='choix' value='new_host'></td>
430
<td><input type='text' name='add_ip' size='10'><input type='hidden' name='choix' value='new_host'></td>
428
<td><? echo "<input type=submit class=button value=\"$l_add_to_list\">"?></td>
431
<td><? echo "<input type=submit class=button value=\"$l_add_to_list\">"?></td>
429
</tr></table>
432
</tr></table>
430
</form>
433
</form>
431
</td></tr>
434
</td></tr>
432
</table>
435
</table>
433
<table width="100%" border="0" cellspacing="0" cellpadding="0">
436
<table width="100%" cellspacing="0" cellpadding="0" border="0">
434
	<tr><th><?php echo $l_import_cert;?></th></tr>
437
	<tr><th><?php echo $l_import_cert;?></th></tr>
435
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
438
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
436
</table>
439
</table>
437
<table width="100%" border="1" cellspacing="0" cellpadding="0">
440
<table width="100%" cellspacing="0" cellpadding="5" border="1">
438
	<tr><td>
441
	<tr>
-
 
442
		<td width="50%">
-
 
443
			<h3>Importer un certificat existant</h3>
439
			<form method="post" action="network.php" enctype="multipart/form-data">
444
			<form method="post" action="network.php" enctype="multipart/form-data">
440
			<?php echo $l_private_key;?><input type="file" name="key"><br>
445
			<?php echo $l_private_key;?> <input type="file" name="key"><br>
441
			<?php echo $l_certificate;?><input type="file" name="crt"><br>
446
			<?php echo $l_certificate;?> <input type="file" name="crt"><br>
442
			<?php echo $l_server_chain;?><input type="file" name="sc">
447
			<?php echo $l_server_chain;?> <input type="file" name="sc">
443
			<input type="hidden" name="MAX_FILE_SIZE" value=<?php echo $maxsize;?>><br>
448
			<input type="hidden" name="MAX_FILE_SIZE" value=<?php echo $maxsize;?>><br>
444
			<input type="submit" <?php echo "value=\"".$l_import."\""?>>
449
			<input type="submit" <?php echo "value=\"".$l_import."\""?>>
445
			</form>
450
			</form>
446
 
451
 
447
			<?php
452
			<?php
448
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
453
			$certificateInfos = openssl_x509_parse(file_get_contents('/etc/pki/tls/certs/alcasar.crt'));
449
 
454
 
450
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
455
			$cert_expiration_date = date('d-m-Y H:i:s', $certificateInfos['validTo_time_t']);
451
			$domain               = $certificateInfos['subject']['CN'];
456
			$domain               = $certificateInfos['subject']['CN'];
452
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
457
			$organization         = (isset($certificateInfos['subject']['O'])) ? $certificateInfos['subject']['O'] : '';
453
			$CAdomain             = $certificateInfos['issuer']['CN'];
458
			$CAdomain             = $certificateInfos['issuer']['CN'];
454
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
459
			$CAorganization       = (isset($certificateInfos['issuer']['O'])) ? $certificateInfos['issuer']['O'] : '';
455
			?>
460
			?>
456
			<br>
461
			<br>
457
			<h3><?= $l_current_certificate ?></h3>
462
			<h3><?= $l_current_certificate ?></h3>
458
			Expiration Date : <?= $cert_expiration_date ?><br>
463
			Expiration Date : <?= $cert_expiration_date ?><br>
459
			Common name : <?= $domain ?><br>
464
			Common name : <?= $domain ?><br>
460
			Organization : <?= $organization ?><br/>
465
			Organization : <?= $organization ?><br/>
461
			<h4><?=  $l_validated ?></h4>
466
			<h4><?=  $l_validated ?></h4>
462
			Common name : <?= $CAdomain ?><br>
467
			Common name : <?= $CAdomain ?><br>
463
			Organization : <?= $CAorganization ?><br>
468
			Organization : <?= $CAorganization ?><br>
-
 
469
 
464
			</td><td>
470
			<br>
465
			<form method="post" action="network.php">
471
			<form method="post" action="network.php">
466
			<input type="hidden" name="default">
472
			<input type="hidden" name="default">
467
			<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";}?>>
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";}?>>
468
			</form>
474
			</form>
469
		</td>
475
		</td>
-
 
476
		<td width="50%" valign="top">
-
 
477
			<?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
-
 
517
			if (empty($LE_conf['domainRequest'])) {
-
 
518
				$step = 1;
-
 
519
			} else if (!empty($LE_conf['challenge'])) {
-
 
520
				$step = 2;
-
 
521
			} else if (($domain === $LE_conf['domainRequest']) && (empty($LE_conf['challenge']))) {
-
 
522
				$step = 3;
-
 
523
			} else {
-
 
524
				$step = 1;
-
 
525
			}
-
 
526
			?>
-
 
527
			<h3>Intégration Let's Encrypt</h3>
-
 
528
			<?php if ($step === 1) : ?>
-
 
529
				<form method="post" action="network.php">
-
 
530
					<input type="hidden" name="action" value="le_issueCert">
-
 
531
					Status : Inactif<br>
-
 
532
					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>
-
 
534
					<input type="submit" name="issue" value="Envoyer"><br>
-
 
535
				</form>
-
 
536
			<?php elseif ($step === 2): ?>
-
 
537
				<form method="post" action="network.php">
-
 
538
					<input type="hidden" name="action" value="le_renewCert">
-
 
539
					Status : En attente de validation<br>
-
 
540
					Nom de domaine : <?= $LE_conf['domainRequest'] ?><br>
-
 
541
					Demandé le : <?= date('d-m-Y H:i:s', $LE_conf['dateIssueRequest']) ?><br>
-
 
542
					Entrée DNS TXT : "<?= '_acme-challenge.'.$LE_conf['domainRequest'] ?>"<br>
-
 
543
					Challenge : "<?= $LE_conf['challenge'] ?>"<br>
-
 
544
					<input type="submit" name="recheck" value="Revérifier"> <input type="submit" name="cancel" value="Annuler"><br>
-
 
545
				</form>
-
 
546
			<?php elseif ($step === 3): ?>
-
 
547
				<form method="post" action="network.php">
-
 
548
					<input type="hidden" name="action" value="le_renewCert">
-
 
549
					Status : Actif<br>
-
 
550
					Nom de domaine : <?= $LE_conf['domainRequest'] ?><br>
-
 
551
					API :  <?= $LE_conf['dnsapi'] ?><br>
-
 
552
					Prochain renouvellement : <?= date('d-m-Y', $LE_conf['dateNextRenewal']) ?><br>
-
 
553
					<?php if ($LE_conf['dateNextRenewal'] <= date('U')): ?>
-
 
554
						<input type="submit" name="recheck" value="Renouveller"><br>
-
 
555
					<?php else: ?>
-
 
556
						<input type="submit" name="recheck_force" value="Renouveller (forcer)"><br>
-
 
557
					<?php endif; ?>
-
 
558
				</form>
-
 
559
			<?php endif; ?>
-
 
560
			<?php if (isset($cmdResponse)): ?>
-
 
561
				<p><?= $cmdResponse ?></p>
-
 
562
			<?php endif; ?>
-
 
563
		</td>
470
	</tr>
564
	</tr>
471
</table>
565
</table>
472
</body>
566
</body>
473
</html>
567
</html>
474
 
568
 
475
<?php
569
<?php
476
if(isset($_POST['default'])){
570
if(isset($_POST['default'])){
477
	echo "$l_default_cert";
571
	echo "$l_default_cert";
478
	exec("sudo alcasar-importcert.sh -d");
572
	exec("sudo alcasar-importcert.sh -d");
479
}
573
}
480
if(isset($_POST['MAX_FILE_SIZE'])){
574
if(isset($_POST['MAX_FILE_SIZE'])){
481
	echo "changement";
-
 
482
	$maxsize = 100000;
575
	$maxsize = 100000;
483
	if(isset($_FILES['key']) && isset($_FILES['crt']) && $_FILES['key']['error'] == 0 && $_FILES['crt']['error'] == 0){
576
	if(isset($_FILES['key']) && isset($_FILES['crt']) && $_FILES['key']['error'] == 0 && $_FILES['crt']['error'] == 0){
484
		$dest = "/tmp/";
577
		$dest = "/tmp/";
485
		if($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize)
578
		if($_FILES['key']['size'] <= $maxsize && $_FILES['crt']['size'] <= $maxsize)
486
		{
579
		{
487
			if(pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt')
580
			if(pathinfo($_FILES['key']['name'])['extension'] == 'key' && pathinfo($_FILES['crt']['name'])['extension'] == 'crt')
488
			{
581
			{
489
				$scpath = "";
582
				$scpath = "";
490
				if(isset($_FILES['sc']) && pathinfo($_FILES['sc']['name'])['extension'] == 'crt')
583
				if(isset($_FILES['sc']) && pathinfo($_FILES['sc']['name'])['extension'] == 'crt')
491
				{
584
				{
492
					$scpath = $dest."server-chain.crt";
585
					$scpath = $dest."server-chain.crt";
493
					move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
586
					move_uploaded_file($_FILES['sc']['tmp_name'], $scpath);
494
				}
587
				}
495
				$keypath = $dest."alcasar.key";
588
				$keypath = $dest."alcasar.key";
496
				$crtpath = $dest."alcasar.crt";
589
				$crtpath = $dest."alcasar.crt";
497
				move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
590
				move_uploaded_file($_FILES['key']['tmp_name'], $keypath);
498
				move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
591
				move_uploaded_file($_FILES['crt']['tmp_name'], $crtpath);
499
				exec("sudo alcasar-importcert.sh -i $crtpath -k $keypath -c $scpath");
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); 
500
			}
596
			}
501
		}
597
		}
502
	}
598
	}
503
}
599
}
504
?>
600
?>
505
 
601
 
506
 
602