Subversion Repositories ALCASAR

Rev

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

Rev 1478 Rev 1484
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(ALCASAR_CHILLI,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_mode		= "Les différents modes sont les suivants :";
-
 
37
	$l_DHCP_full		= "DHCP complet";
-
 
38
	$l_DHCP_half		= "Demi DHCP ";
36
	$l_DHCP_on		= "actif";
39
	$l_DHCP_off			= "Sans DHCP";
37
	$l_DHCP_off		= "inactif";
40
	$l_DHCP_full_explain	= "Le serveur DHCP couvre la totalité des adresses du réseau. Des adresses statiques peuvent être réservées (cf. ci-dessous).";
38
	$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_DHCP_half_explain	= "La première moitié du réseau est réservé à l'adressage statique, l'autre moitié est en adressage dynamique (DHCP).";
-
 
42
	$l_DHCP_off_explain	= "Le serveur DHCP est arrêté.";
-
 
43
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
39
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
44
	$l_mac_address		= "Adresse MAC";
40
	$l_mac_address		= "Adresse MAC";
45
	$l_ip_address		= "Adresse IP";
41
	$l_ip_address		= "Adresse IP";
46
	$l_mac_del			= "Supprimer de la liste";
42
	$l_mac_del			= "Supprimer de la liste";
47
	$l_add_to_list		= "Ajouter";
43
	$l_add_to_list		= "Ajouter";
48
	$l_apply			= "Appliquer les changements";
44
	$l_apply			= "Appliquer les changements";
49
 
45
 
50
} else {
46
} else {
51
	$l_network_title	= "Network configuration";
47
	$l_network_title	= "Network configuration";
52
	$l_extif_legend		= " (Internet connected interface)";
48
	$l_extif_legend		= " (Internet connected interface)";
53
	$l_intif_legend		= " (Private network)";
49
	$l_intif_legend		= " (Private network)";
54
	$l_internet_legend	= "INTERNET";
50
	$l_internet_legend	= "INTERNET";
55
	$l_ip_adr			= "IP Address";
51
	$l_ip_adr			= "IP Address";
56
	$l_ip_mask			= "Mask";
52
	$l_ip_mask			= "Mask";
57
	$l_ip_router		= "Gateway";
53
	$l_ip_router		= "Gateway";
58
	$l_ip_public		= "Public IP address";
54
	$l_ip_public		= "Public IP address";
59
	$l_ip_dns1			= "DNS1 :";
55
	$l_ip_dns1			= "DNS1 :";
60
	$l_ip_dns2			= "DNS2";
56
	$l_ip_dns2			= "DNS2";
61
	$l_dhcp_title		= "DHCP service";
57
	$l_dhcp_title		= "DHCP service";
62
	$l_dhcp_state		= "Current mode";
58
	$l_dhcp_state		= "Current mode";
63
	$l_dhcp_mode		= "The different modes are the following :";
-
 
64
	$l_DHCP_full		= "Full DHCP";
59
	$l_DHCP_on		= "enabled";
65
	$l_DHCP_half		= "Half DHCP ";
-
 
66
	$l_DHCP_off			= "No DHCP";
60
	$l_DHCP_off		= "disabled";
67
	$l_DHCP_full_explain	= "The DHCP server manage all equipments in DHCP mode. Some static addresses can be reserved (see bellow).";
61
	$l_DHCP_off_explain	= "! Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
68
	$l_DHCP_half_explain	= "The first half of LAN's equipments are in static mode, the other are in dynamic mode (DHCP).";
-
 
69
	$l_DHCP_off_explain	= "The DHCP server is off.";
-
 
70
	$l_static_dhcp_title	= "Static IP addresses reservation";
62
	$l_static_dhcp_title	= "Static IP addresses reservation";
71
	$l_mac_address		= "MAC Address";
63
	$l_mac_address		= "MAC Address";
72
	$l_ip_address		= "IP Address";
64
	$l_ip_address		= "IP Address";
73
	$l_mac_del			= "Delete from list";
65
	$l_mac_del			= "Delete from list";
74
	$l_add_to_list		= "Add";
66
	$l_add_to_list		= "Add";
75
	$l_apply			= "Apply changes";
67
	$l_apply			= "Apply changes";
76
}
68
}
77
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
69
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
78
switch ($choix)
70
switch ($choix)
79
{
71
{
80
case 'DHCP_Full' :
72
case 'DHCP_On' :
81
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -full");
73
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -on");
82
	break;
74
	break;
83
case 'DHCP_Off' :
75
case 'DHCP_Off' :
84
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -off");
76
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -off");
85
	break;
77
	break;
86
case 'DHCP_Half' :
-
 
87
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -half");
-
 
88
	break;
-
 
89
case 'new_mac' :
78
case 'new_mac' :
90
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
79
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
91
		{
80
		{
92
		$tab=file(ETHERS_FILE);
81
		$tab=file(ETHERS_FILE);
93
		$insert="True";
82
		$insert="True";
94
		if ($tab)  # le fichier n'est pas vide
83
		if ($tab)  # le fichier n'est pas vide
95
			{
84
			{
96
			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
97
				{
86
				{
98
				$field=explode(" ", $line);
87
				$field=explode(" ", $line);
99
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
88
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
100
				if (strcasecmp(trim($_POST['add_mac']),trim($mac_addr)) == 0)
89
				if (strcasecmp(trim($_POST['add_mac']),trim($mac_addr)) == 0)
101
					{
90
					{
102
					$insert="False";
91
					$insert="False";
103
					break;
92
					break;
104
					}
93
					}
105
				if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
94
				if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
106
					{
95
					{
107
					$insert="False";
96
					$insert="False";
108
					break;
97
					break;
109
					}
98
					}
110
				}
99
				}
111
			}
100
			}
112
		if ($insert == "True") 
101
		if ($insert == "True") 
113
			{
102
			{
114
			$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
103
			$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
115
			$pointeur=fopen(ETHERS_FILE,"a");
104
			$pointeur=fopen(ETHERS_FILE,"a");
116
			fwrite ($pointeur, $line);
105
			fwrite ($pointeur, $line);
117
			fclose ($pointeur);
106
			fclose ($pointeur);
118
			exec ("sudo service chilli restart");
107
			exec ("sudo service chilli restart");
119
			}
108
			}
120
		}
109
		}
121
	break;
110
	break;
122
case 'del_mac' :
111
case 'del_mac' :
123
	$tab=file(ETHERS_FILE);
112
	$tab=file(ETHERS_FILE);
124
	if ($tab)
113
	if ($tab)
125
		{
114
		{
126
		$pointeur=fopen(ETHERS_FILE,"w+");
115
		$pointeur=fopen(ETHERS_FILE,"w+");
127
		foreach ($tab as $line)
116
		foreach ($tab as $line)
128
			{
117
			{
129
			$field=explode(" ", $line);
118
			$field=explode(" ", $line);
130
			$mac_addr=trim($field[0]);
119
			$mac_addr=trim($field[0]);
131
			$remove_line = False;
120
			$remove_line = False;
132
			foreach ($_POST as $key => $value)
121
			foreach ($_POST as $key => $value)
133
				{
122
				{
134
				if ($mac_addr == $key)
123
				if ($mac_addr == $key)
135
			       		{
124
			       		{
136
					$remove_line = True;
125
					$remove_line = True;
137
					break;
126
					break;
138
					}
127
					}
139
				}
128
				}
140
			if (! $remove_line) {fwrite($pointeur,$line);}
129
			if (! $remove_line) {fwrite($pointeur,$line);}
141
			}
130
			}
142
		fclose($pointeur);
131
		fclose($pointeur);
143
		# exec ("sudo service chilli restart");
132
		# exec ("sudo service chilli restart");
144
		}
133
		}
145
	break;
134
	break;
146
}
135
}
147
 
136
 
148
// Fonction de test de connectivité internet
137
// Fonction de test de connectivité internet
149
function internetTest(){
138
function internetTest(){
150
	$host = "www.google.fr"; # Google Test
139
	$host = "www.google.fr"; # Google Test
151
	$port = "80";
140
	$port = "80";
152
	//var $num;	//non utilisé
141
	//var $num;	//non utilisé
153
	//var $error;	//non utilisé
142
	//var $error;	//non utilisé
154
	
143
	
155
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
144
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
156
		return false;
145
		return false;
157
	} else {
146
	} else {
158
		fclose($sock);
147
		fclose($sock);
159
		return true;
148
		return true;
160
	}
149
	}
161
}
150
}
162
/********************************************************
151
/********************************************************
163
*		Lecture du fichier ALCASAR_CHILLI	*
152
*		Lecture du fichier ALCASAR_CHILLI	*
164
*********************************************************/
153
*********************************************************/
165
$ouvre=fopen(ALCASAR_CHILLI,"r");
154
$ouvre=fopen(ALCASAR_CHILLI,"r");
166
if ($ouvre){
155
if ($ouvre){
167
	while (!feof ($ouvre))
156
	while (!feof ($ouvre))
168
	{
157
	{
169
		$tampon = fgets($ouvre, 4096);
158
		$tampon = fgets($ouvre, 4096);
170
		if (strpos($tampon,"=")!==false){
159
		if (strpos($tampon,"=")!==false){
171
			$tmp = explode("=",$tampon);
160
			$tmp = explode("=",$tampon);
172
			$chilli[$tmp[0]] = $tmp[1];
161
			$chilli[$tmp[0]] = $tmp[1];
173
		}
162
		}
174
	}
163
	}
175
}else{
164
}else{
176
	exit("Erreur d'ouverture du fichier ".ALCASAR_CHILLI);
165
	exit("Erreur d'ouverture du fichier ".ALCASAR_CHILLI);
177
}
166
}
178
fclose($ouvre);
167
fclose($ouvre);
179
 
168
 
180
/***********************************
169
/***********************************
181
*	Read ALCASAR_CONF_FILE     *
170
*	Read ALCASAR_CONF_FILE     *
182
************************************/
171
************************************/
183
$ouvre=fopen(CONF_FILE,"r");
172
$ouvre=fopen(CONF_FILE,"r");
184
if ($ouvre){
173
if ($ouvre){
185
	while (!feof ($ouvre))
174
	while (!feof ($ouvre))
186
	{
175
	{
187
		$tampon = fgets($ouvre, 4096);
176
		$tampon = fgets($ouvre, 4096);
188
		if (strpos($tampon,"=")!==false){
177
		if (strpos($tampon,"=")!==false){
189
			$tmp = explode("=",$tampon);
178
			$tmp = explode("=",$tampon);
190
			$conf[$tmp[0]] = $tmp[1];
179
			$conf[$tmp[0]] = $tmp[1];
191
		}
180
		}
192
	}
181
	}
193
}else{
182
}else{
194
	exit("Erreur d'ouverture du fichier ".CONF_FILE);
183
	exit("Erreur d'ouverture du fichier ".CONF_FILE);
195
}
184
}
196
fclose($ouvre);
185
fclose($ouvre);
197
 
186
 
198
/************************
187
/************************
199
*	TO DO		*
188
*	TO DO		*
200
*************************/
189
*************************/
201
//modification de la conf réseau  --> V3.0
190
//modification de la conf réseau  --> V3.0
202
 
191
 
203
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
192
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
204
<html><!-- written by steweb57 & rexy -->
193
<html><!-- written by steweb57 & rexy -->
205
<head>
194
<head>
206
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
195
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
207
<title><?php echo $l_network_title; ?></title>
196
<title><?php echo $l_network_title; ?></title>
208
<link rel="stylesheet" href="/css/style.css" type="text/css">
197
<link rel="stylesheet" href="/css/style.css" type="text/css">
209
</head>
198
</head>
210
<body>
199
<body>
211
<table width="100%" border="0" cellspacing="0" cellpadding="0">
200
<table width="100%" border="0" cellspacing="0" cellpadding="0">
212
	<tr><th><?php echo $l_network_title; ?></th></tr>
201
	<tr><th><?php echo $l_network_title; ?></th></tr>
213
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
202
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
214
</table>
203
</table>
215
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
204
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
216
	<tr><td valign="middle" align="left">
205
	<tr><td valign="middle" align="left">
217
	<fieldset>
206
	<fieldset>
218
	<legend><?php echo $l_internet_legend;
207
	<legend><?php echo $l_internet_legend;
219
 	if (InternetTest()){
208
 	if (InternetTest()){
220
		echo " <img src='/images/state_ok.gif'>";
209
		echo " <img src='/images/state_ok.gif'>";
221
		$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
210
		$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
222
	else 	{
211
	else 	{
223
		echo " <img src='/images/state_error.gif'>";
212
		echo " <img src='/images/state_error.gif'>";
224
		$IP_PUB = "-.-.-.-";}
213
		$IP_PUB = "-.-.-.-";}
225
	?></legend>
214
	?></legend>
226
	<table>
215
	<table>
227
		<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
216
		<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
228
		<tr><td><?php echo $l_ip_dns1." : </td><td>".$conf["DNS1"];?></td></tr>
217
		<tr><td><?php echo $l_ip_dns1." : </td><td>".$conf["DNS1"];?></td></tr>
229
		<tr><td><?php echo $l_ip_dns2." : </td><td>".$conf["DNS2"];?></td></tr>
218
		<tr><td><?php echo $l_ip_dns2." : </td><td>".$conf["DNS2"];?></td></tr>
230
	</table>
219
	</table>
231
	</fieldset>
220
	</fieldset>
232
	</td><td>
221
	</td><td>
233
	<fieldset>
222
	<fieldset>
234
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
223
	<legend><?php echo $conf["EXTIF"].$l_extif_legend; ?></legend>
235
	<table>
224
	<table>
236
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PUBLIC_IP"];?></td></tr>
225
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PUBLIC_IP"];?></td></tr>
237
		<tr><td><?php echo $l_ip_router." : </td><td>".$conf["GW"];?></td></tr>
226
		<tr><td><?php echo $l_ip_router." : </td><td>".$conf["GW"];?></td></tr>
238
	</table>
227
	</table>
239
	</fieldset>
228
	</fieldset>
240
	</td><td>
229
	</td><td>
241
	<fieldset>
230
	<fieldset>
242
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
231
	<legend><?php echo $conf["INTIF"].$l_intif_legend; ?></legend>
243
	<table>
232
	<table>
244
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PRIVATE_IP"];?></td></tr>
233
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PRIVATE_IP"];?></td></tr>
245
	</table>
234
	</table>
246
	</fieldset>
235
	</fieldset>
247
	</td></tr>
236
	</td></tr>
248
</table>
237
</table>
249
<table width="100%" border="0" cellspacing="0" cellpadding="0">
238
<table width="100%" border="0" cellspacing="0" cellpadding="0">
250
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
239
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
251
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
240
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
252
</table>
241
</table>
253
<table width="100%" border=1 cellspacing=0 cellpadding=0>
242
<table width="100%" border=1 cellspacing=0 cellpadding=0>
254
<tr><td valign="middle" align="left">
243
<tr><td colspan="2" valign="middle" align="left">
255
<?
244
<?
256
$dhcp_state=trim($conf["DHCP"]);
245
$dhcp_state=trim($conf["DHCP"]);
257
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
246
echo "<CENTER><H3>$l_dhcp_state : ${"l_DHCP_".$dhcp_state}</H3></CENTER>";
258
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
247
echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
259
echo "<select name='choix'>";
248
echo "<select name='choix'>";
260
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
249
echo "<option value=\"DHCP_Off\" ";if (!strcmp($dhcp_state,"off")) echo "selected";echo ">$l_DHCP_off";
261
echo "<option value=\"DHCP_Half\" ";if (!strcmp($dhcp_state,"half")) echo "selected";echo ">$l_DHCP_half";
-
 
262
echo "<option value=\"DHCP_Full\" ";if (!strcmp($dhcp_state,"full")) echo "selected";echo ">$l_DHCP_full";
250
echo "<option value=\"DHCP_On\" ";if (!strcmp($dhcp_state,"on")) echo "selected";echo ">$l_DHCP_on";
263
echo "</select>";
251
echo "</select>";
264
echo "<input type=submit value='$l_apply'>";
252
echo "<input type=submit value='$l_apply'>";
265
echo "<td valign='middle' align='left'><center><H3>$l_dhcp_mode</h3></center>";
-
 
266
echo "$l_DHCP_off : $l_DHCP_off_explain<br>$l_DHCP_half : $l_DHCP_half_explain<br>$l_DHCP_full : $l_DHCP_full_explain";
-
 
267
echo "</td>";
253
echo "<br>$l_DHCP_off_explain";
268
echo "</FORM>";
254
echo "</FORM>";
269
echo "</td></tr>";
255
echo "</td></tr>";
270
if (strncmp($conf["DHCP"],"full",2) == 0) { require ('network2.php');}
256
if (strncmp($conf["DHCP"],"on",2) == 0) { require ('network2.php');}
271
else { echo "</TABLE>"; }
257
else { echo "</TABLE>"; }
272
?>
258
?>
273
</body>
259
</body>
274
</html>
260
</html>
275
 
261