Subversion Repositories ALCASAR

Rev

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

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