Subversion Repositories ALCASAR

Rev

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

Rev 1493 Rev 1578
1
<?php
1
<?php
2
/* written by steweb57 & Rexy */
2
/* written by steweb57 & Rexy */
3
 
3
 
4
/********************
4
/********************
5
* TEST CONF FILES   *
5
* TEST CONF FILES   *
6
*********************/
6
*********************/
7
define ("ALCASAR_CHILLI", "/etc/chilli.conf");
7
//define ("ALCASAR_CHILLI", "/etc/chilli.conf");
8
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
8
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
9
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers");
9
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers");
10
$conf_files=array(ALCASAR_CHILLI,CONF_FILE,ETHERS_FILE);
10
$conf_files=array(CONF_FILE,ETHERS_FILE);
11
foreach ($conf_files as $file){
11
foreach ($conf_files as $file){
12
if (!file_exists($file)){
12
if (!file_exists($file)){
13
	exit("Requested file ".$file." isn't present");}
13
	exit("Requested file ".$file." isn't present");}
14
if (!is_readable($file)){
14
if (!is_readable($file)){
15
	exit("Can't read the file ".$file);}
15
	exit("Can't read the file ".$file);}
16
}
16
}
17
 
17
 
18
# Choice of language
18
# Choice of language
19
$Language = 'en';
19
$Language = 'en';
20
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
20
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
21
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
21
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
22
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
22
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
23
if($Language == 'fr'){
23
if($Language == 'fr'){
24
	$l_network_title	= "Configuration réseau";
24
	$l_network_title	= "Configuration réseau";
25
	$l_extif_legend		= " (Interface connectée à Internet)";
25
	$l_extif_legend		= " (Interface connectée à Internet)";
26
	$l_intif_legend		= " (Réseau de consultation)";
26
	$l_intif_legend		= " (Réseau de consultation)";
27
	$l_internet_legend	= "INTERNET";
27
	$l_internet_legend	= "INTERNET";
28
	$l_ip_adr			= "Adresse IP";
28
	$l_ip_adr			= "Adresse IP";
29
	$l_ip_mask			= "Masque";
29
	$l_ip_mask			= "Masque";
30
	$l_ip_router		= "Passerelle";
30
	$l_ip_router		= "Passerelle";
31
	$l_ip_public		= "Adresse IP publique";
31
	$l_ip_public		= "Adresse IP publique";
32
	$l_ip_dns1			= "DNS1";
32
	$l_ip_dns1			= "DNS1";
33
	$l_ip_dns2			= "DNS2";
33
	$l_ip_dns2			= "DNS2";
34
	$l_dhcp_title		= "Service DHCP";
34
	$l_dhcp_title		= "Service DHCP";
35
	$l_dhcp_state		= "Mode actuel";
35
	$l_dhcp_state		= "Mode actuel";
36
	$l_DHCP_on		= "actif";
36
	$l_DHCP_on		= "actif";
37
	$l_DHCP_off		= "inactif";
37
	$l_DHCP_off		= "inactif";
38
	$l_DHCP_off_explain	= "! Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
38
	$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_static_dhcp_title	= "Réservation d'adresses IP statiques";
39
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
40
	$l_mac_address		= "Adresse MAC";
40
	$l_mac_address		= "Adresse MAC";
41
	$l_ip_address		= "Adresse IP";
41
	$l_ip_address		= "Adresse IP";
42
	$l_mac_del			= "Supprimer de la liste";
42
	$l_mac_del			= "Supprimer de la liste";
43
	$l_add_to_list		= "Ajouter";
43
	$l_add_to_list		= "Ajouter";
44
	$l_apply			= "Appliquer les changements";
44
	$l_apply			= "Appliquer les changements";
45
 
45
 
46
} else {
46
} else {
47
	$l_network_title	= "Network configuration";
47
	$l_network_title	= "Network configuration";
48
	$l_extif_legend		= " (Internet connected interface)";
48
	$l_extif_legend		= " (Internet connected interface)";
49
	$l_intif_legend		= " (Private network)";
49
	$l_intif_legend		= " (Private network)";
50
	$l_internet_legend	= "INTERNET";
50
	$l_internet_legend	= "INTERNET";
51
	$l_ip_adr			= "IP Address";
51
	$l_ip_adr			= "IP Address";
52
	$l_ip_mask			= "Mask";
52
	$l_ip_mask			= "Mask";
53
	$l_ip_router		= "Gateway";
53
	$l_ip_router		= "Gateway";
54
	$l_ip_public		= "Public IP address";
54
	$l_ip_public		= "Public IP address";
55
	$l_ip_dns1			= "DNS1 :";
55
	$l_ip_dns1			= "DNS1 :";
56
	$l_ip_dns2			= "DNS2";
56
	$l_ip_dns2			= "DNS2";
57
	$l_dhcp_title		= "DHCP service";
57
	$l_dhcp_title		= "DHCP service";
58
	$l_dhcp_state		= "Current mode";
58
	$l_dhcp_state		= "Current mode";
59
	$l_DHCP_on		= "enabled";
59
	$l_DHCP_on		= "enabled";
60
	$l_DHCP_off		= "disabled";
60
	$l_DHCP_off		= "disabled";
61
	$l_DHCP_off_explain	= "! Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
61
	$l_DHCP_off_explain	= "! Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
62
	$l_static_dhcp_title	= "Static IP addresses reservation";
62
	$l_static_dhcp_title	= "Static IP addresses reservation";
63
	$l_mac_address		= "MAC Address";
63
	$l_mac_address		= "MAC Address";
64
	$l_ip_address		= "IP Address";
64
	$l_ip_address		= "IP Address";
65
	$l_mac_del			= "Delete from list";
65
	$l_mac_del			= "Delete from list";
66
	$l_add_to_list		= "Add";
66
	$l_add_to_list		= "Add";
67
	$l_apply			= "Apply changes";
67
	$l_apply			= "Apply changes";
68
}
68
}
69
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
69
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
70
switch ($choix)
70
switch ($choix)
71
{
71
{
72
case 'DHCP_On' :
72
case 'DHCP_On' :
73
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -on");
73
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -on");
74
	break;
74
	break;
75
case 'DHCP_Off' :
75
case 'DHCP_Off' :
76
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -off");
76
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -off");
77
	break;
77
	break;
78
case 'new_mac' :
78
case 'new_mac' :
79
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
79
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
80
		{
80
		{
81
		$tab=file(ETHERS_FILE);
81
		$tab=file(ETHERS_FILE);
82
		$insert="True";
82
		$insert="True";
83
		if ($tab)  # le fichier n'est pas vide
83
		if ($tab)  # le fichier n'est pas vide
84
			{
84
			{
85
			foreach ($tab as $line)  # verify that MAC or IP addresses doesn't exist
85
			foreach ($tab as $line)  # verify that MAC or IP addresses doesn't exist
86
				{
86
				{
87
				$field=explode(" ", $line);
87
				$field=explode(" ", $line);
88
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
88
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
89
				if (strcasecmp(trim($_POST['add_mac']),trim($mac_addr)) == 0)
89
				if (strcasecmp(trim($_POST['add_mac']),trim($mac_addr)) == 0)
90
					{
90
					{
91
					$insert="False";
91
					$insert="False";
92
					break;
92
					break;
93
					}
93
					}
94
				if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
94
				if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
95
					{
95
					{
96
					$insert="False";
96
					$insert="False";
97
					break;
97
					break;
98
					}
98
					}
99
				}
99
				}
100
			}
100
			}
101
		if ($insert == "True") 
101
		if ($insert == "True") 
102
			{
102
			{
103
			$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
103
			$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
104
			$pointeur=fopen(ETHERS_FILE,"a");
104
			$pointeur=fopen(ETHERS_FILE,"a");
105
			fwrite ($pointeur, $line);
105
			fwrite ($pointeur, $line);
106
			fclose ($pointeur);
106
			fclose ($pointeur);
107
			exec ("sudo service chilli restart");
107
			exec ("/usr/bin/systemctl reload chilli");
108
			}
108
			}
109
		}
109
		}
110
	break;
110
	break;
111
case 'del_mac' :
111
case 'del_mac' :
112
	$tab=file(ETHERS_FILE);
112
	$tab=file(ETHERS_FILE);
113
	if ($tab)
113
	if ($tab)
114
		{
114
		{
115
		$pointeur=fopen(ETHERS_FILE,"w+");
115
		$pointeur=fopen(ETHERS_FILE,"w+");
116
		foreach ($tab as $line)
116
		foreach ($tab as $line)
117
			{
117
			{
118
			$field=explode(" ", $line);
118
			$field=explode(" ", $line);
119
			$mac_addr=trim($field[0]);
119
			$mac_addr=trim($field[0]);
120
			$remove_line = False;
120
			$remove_line = False;
121
			foreach ($_POST as $key => $value)
121
			foreach ($_POST as $key => $value)
122
				{
122
				{
123
				if ($mac_addr == $key)
123
				if ($mac_addr == $key)
124
			       		{
124
			       		{
125
					$remove_line = True;
125
					$remove_line = True;
126
					break;
126
					break;
127
					}
127
					}
128
				}
128
				}
129
			if (! $remove_line) {fwrite($pointeur,$line);}
129
			if (! $remove_line) {fwrite($pointeur,$line);}
130
			}
130
			}
131
		fclose($pointeur);
131
		fclose($pointeur);
132
		# exec ("sudo service chilli restart");
132
		exec ("sudo /usr/bin/systemctl reload chilli");
133
		}
133
		}
134
	break;
134
	break;
135
}
135
}
136
 
136
 
137
// Fonction de test de connectivité internet
137
// Fonction de test de connectivité internet
138
function internetTest(){
138
function internetTest(){
139
	$host = "www.google.fr"; # Google Test
139
	$host = "www.google.fr"; # Google Test
140
	$port = "80";
140
	$port = "80";
141
	//var $num;	//non utilisé
141
	//var $num;	//non utilisé
142
	//var $error;	//non utilisé
142
	//var $error;	//non utilisé
143
	
143
	
144
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
144
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
145
		return false;
145
		return false;
146
	} else {
146
	} else {
147
		fclose($sock);
147
		fclose($sock);
148
		return true;
148
		return true;
149
	}
149
	}
150
}
150
}
151
/********************************************************
151
/********************************************************
152
*		Lecture du fichier ALCASAR_CHILLI	*
152
*		Lecture du fichier ALCASAR_CHILLI	*
-
 
153
*		     (not need any more)		*
153
*********************************************************/
154
*********************************************************/
154
$ouvre=fopen(ALCASAR_CHILLI,"r");
155
//$ouvre=fopen(ALCASAR_CHILLI,"r");
155
if ($ouvre){
156
//if ($ouvre){
156
	while (!feof ($ouvre))
157
//	while (!feof ($ouvre))
157
	{
158
//	{
158
		$tampon = fgets($ouvre, 4096);
159
//		$tampon = fgets($ouvre, 4096);
159
		if (strpos($tampon,"=")!==false){
160
//		if (strpos($tampon,"=")!==false){
160
			$tmp = explode("=",$tampon);
161
//			$tmp = explode("=",$tampon);
161
			$chilli[$tmp[0]] = $tmp[1];
162
//			$chilli[$tmp[0]] = $tmp[1];
162
		}
163
//		}
163
	}
164
//	}
164
}else{
165
//}else{
165
	exit("Erreur d'ouverture du fichier ".ALCASAR_CHILLI);
166
//	exit("Erreur d'ouverture du fichier ".ALCASAR_CHILLI);
166
}
167
//}
167
fclose($ouvre);
168
//fclose($ouvre);
168
 
169
 
169
/***********************************
170
/***********************************
170
*	Read ALCASAR_CONF_FILE     *
171
*	Read ALCASAR_CONF_FILE     *
171
************************************/
172
************************************/
172
$ouvre=fopen(CONF_FILE,"r");
173
$ouvre=fopen(CONF_FILE,"r");
173
if ($ouvre){
174
if ($ouvre){
174
	while (!feof ($ouvre))
175
	while (!feof ($ouvre))
175
	{
176
	{
176
		$tampon = fgets($ouvre, 4096);
177
		$tampon = fgets($ouvre, 4096);
177
		if (strpos($tampon,"=")!==false){
178
		if (strpos($tampon,"=")!==false){
178
			$tmp = explode("=",$tampon);
179
			$tmp = explode("=",$tampon);
179
			$conf[$tmp[0]] = $tmp[1];
180
			$conf[$tmp[0]] = $tmp[1];
180
		}
181
		}
181
	}
182
	}
182
}else{
183
}else{
183
	exit("Erreur d'ouverture du fichier ".CONF_FILE);
184
	exit("Erreur d'ouverture du fichier ".CONF_FILE);
184
}
185
}
185
fclose($ouvre);
186
fclose($ouvre);
186
 
187
 
187
/************************
188
/************************
188
*	TO DO		*
189
*	TO DO		*
189
*************************/
190
*************************/
190
//modification de la conf réseau  --> V3.0
191
//modification de la conf réseau  --> V3.0
191
 
192
 
192
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
193
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
193
<html><!-- written by steweb57 & rexy -->
194
<html><!-- written by steweb57 & rexy -->
194
<head>
195
<head>
195
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
196
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
196
<title><?php echo $l_network_title; ?></title>
197
<title><?php echo $l_network_title; ?></title>
197
<link rel="stylesheet" href="/css/style.css" type="text/css">
198
<link rel="stylesheet" href="/css/style.css" type="text/css">
-
 
199
<script type="text/javascript">
-
 
200
function MAC_Control(formulaire){
-
 
201
/*MAC control (upper case and '-' separator*/
-
 
202
	var regex1 = /^([0-9a-fA-F]{2}(-|:)){5}[0-9a-fA-F]{2}$/; //vérification adresse mac
-
 
203
	if (regex1.test(document.forms[formulaire].add_mac.value)){
-
 
204
		document.forms[formulaire].add_mac.value=document.forms[formulaire].add_mac.value.toUpperCase().replace(/:/g, '-');
-
 
205
		return true;
-
 
206
	} else {
-
 
207
		alert("Invalid MAC address");//non internationnalisé
-
 
208
		return false;
-
 
209
	}
-
 
210
}
-
 
211
</script>
198
</head>
212
</head>
199
<body>
213
<body>
200
<table width="100%" border="0" cellspacing="0" cellpadding="0">
214
<table width="100%" border="0" cellspacing="0" cellpadding="0">
201
	<tr><th><?php echo $l_network_title; ?></th></tr>
215
	<tr><th><?php echo $l_network_title; ?></th></tr>
202
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
216
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
203
</table>
217
</table>
204
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
218
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
205
	<tr><td valign="middle" align="left">
219
	<tr><td valign="middle" align="left">
206
	<fieldset>
220
	<fieldset>
207
	<legend><?php echo $l_internet_legend;
221
	<legend><?php echo $l_internet_legend;
208
 	if (InternetTest()){
222
 	if (InternetTest()){
209
		echo " <img src='/images/state_ok.gif'>";
223
		echo " <img src='/images/state_ok.gif'>";
210
		$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
224
		$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
211
	else 	{
225
	else 	{
212
		echo " <img src='/images/state_error.gif'>";
226
		echo " <img src='/images/state_error.gif'>";
213
		$IP_PUB = "-.-.-.-";}
227
		$IP_PUB = "-.-.-.-";}
214
	?></legend>
228
	?></legend>
215
	<table>
229
	<table>
216
		<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
230
		<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
217
		<tr><td><?php echo $l_ip_dns1." : </td><td>".$conf["DNS1"];?></td></tr>
231
		<tr><td><?php echo $l_ip_dns1." : </td><td>".$conf["DNS1"];?></td></tr>
218
		<tr><td><?php echo $l_ip_dns2." : </td><td>".$conf["DNS2"];?></td></tr>
232
		<tr><td><?php echo $l_ip_dns2." : </td><td>".$conf["DNS2"];?></td></tr>
219
	</table>
233
	</table>
220
	</fieldset>
234
	</fieldset>
221
	</td><td>
235
	</td><td>
222
	<fieldset>
236
	<fieldset>
223
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
237
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
224
	<table>
238
	<table>
225
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PUBLIC_IP"];?></td></tr>
239
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PUBLIC_IP"];?></td></tr>
226
		<tr><td><?php echo $l_ip_router." : </td><td>".$conf["GW"];?></td></tr>
240
		<tr><td><?php echo $l_ip_router." : </td><td>".$conf["GW"];?></td></tr>
227
	</table>
241
	</table>
228
	</fieldset>
242
	</fieldset>
229
	</td><td>
243
	</td><td>
230
	<fieldset>
244
	<fieldset>
231
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
245
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
232
	<table>
246
	<table>
233
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PRIVATE_IP"];?></td></tr>
247
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PRIVATE_IP"];?></td></tr>
234
	</table>
248
	</table>
235
	</fieldset>
249
	</fieldset>
236
	</td></tr>
250
	</td></tr>
237
</table>
251
</table>
238
<table width="100%" border="0" cellspacing="0" cellpadding="0">
252
<table width="100%" border="0" cellspacing="0" cellpadding="0">
239
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
253
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
240
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
254
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
241
</table>
255
</table>
242
<table width="100%" border=1 cellspacing=0 cellpadding=0>
256
<table width="100%" border=1 cellspacing=0 cellpadding=0>
243
<tr><td colspan="2" valign="middle" align="left">
257
<tr><td colspan="2" valign="middle" align="left">
244
<?
258
<?
245
$dhcp_state=trim($conf["DHCP"]);
259
$dhcp_state=trim($conf["DHCP"]);
246
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
260
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
247
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
261
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
248
echo "<select name='choix'>";
262
echo "<select name='choix'>";
249
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
263
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
250
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on";
264
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on";
251
echo "</select>";
265
echo "</select>";
252
echo "<input type=submit value='$l_apply'>";
266
echo "<input type=submit value='$l_apply'>";
253
echo "<br>$l_DHCP_off_explain";
267
echo "<br>$l_DHCP_off_explain";
254
echo "</FORM>";
268
echo "</FORM>";
255
echo "</td></tr>";
269
echo "</td></tr>";
256
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
270
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
257
else { echo "</TABLE>"; }
271
else { echo "</TABLE>"; }
258
?>
272
?>
259
</body>
273
</body>
260
</html>
274
</html>
261
 
275