Subversion Repositories ALCASAR

Rev

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

Rev 838 Rev 841
1
<?php
1
<?php
2
/* written by steweb57 & Rexy */
2
/* written by steweb57 & Rexy */
3
 
3
 
-
 
4
/****************************************************************
-
 
5
*	CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION	*
-
 
6
*****************************************************************/
-
 
7
define ("ALCASAR_CHILLI", "/etc/chilli.conf");
-
 
8
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
-
 
9
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers");
-
 
10
 
-
 
11
/********************************************************************************
-
 
12
*				TEST DES FICHIERS DE CONFIGURATION		*
-
 
13
********************************************************************************/
-
 
14
//Test de présence et des droits en lecture des fichiers de configuration.
-
 
15
if (!file_exists(ALCASAR_CHILLI)){
-
 
16
	exit("Fichier de configuration ".ALCASAR_CHILLI." non présent");
-
 
17
}
-
 
18
if (!is_readable(ALCASAR_CHILLI)){
-
 
19
	exit("Vous n'avez pas les droits de lecture sur le fichier ".ALCASAR_CHILLI);
-
 
20
}
-
 
21
if (!file_exists(CONF_FILE)){
-
 
22
	exit("Fichier de configuration ".CONF_FILE." non présent");
-
 
23
}
-
 
24
if (!is_readable(CONF_FILE)){
-
 
25
	exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
-
 
26
}
-
 
27
if (!file_exists(ETHERS_FILE)){
-
 
28
	exit("Fichier de configuration ".ETHERS_FILE." non présent");
-
 
29
}
-
 
30
if (!is_readable(ETHERS_FILE)){
-
 
31
	exit("Vous n'avez pas les droits de lecture sur le fichier ".ETHERS_FILE);
-
 
32
}
-
 
33
 
4
# Choice of language
34
# Choice of language
5
$Language = 'en';
35
$Language = 'en';
6
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
36
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
7
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
37
	$Langue		= explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
8
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
38
	$Language	= strtolower(substr(chop($Langue[0]),0,2)); }
9
if($Language == 'fr'){
39
if($Language == 'fr'){
10
	$l_network_title	= "Configuration réseau";
40
	$l_network_title	= "Configuration réseau";
11
	$l_eth0_legend		= "Eth0 (Interface connectée à Internet)";
41
	$l_eth0_legend		= "Eth0 (Interface connectée à Internet)";
12
	$l_eth1_legend		= "Eth1 (Réseau de consultation)";
42
	$l_eth1_legend		= "Eth1 (Réseau de consultation)";
13
	$l_internet_legend	= "INTERNET";
43
	$l_internet_legend	= "INTERNET";
14
	$l_ip_adr		= "Adresse IP";
44
	$l_ip_adr		= "Adresse IP";
15
	$l_ip_mask		= "Masque";
45
	$l_ip_mask		= "Masque";
16
	$l_ip_router		= "Passerelle";
46
	$l_ip_router		= "Passerelle";
17
	$l_ip_public		= "Adresse IP publique";
47
	$l_ip_public		= "Adresse IP publique";
18
	$l_ip_dns1		= "DNS1";
48
	$l_ip_dns1		= "DNS1";
19
	$l_ip_dns2		= "DNS2";
49
	$l_ip_dns2		= "DNS2";
-
 
50
	$l_dhcp_title		= "Serveur DHCP";
-
 
51
	$l_dhcp_on		= "Le service DHCP est actuellement activé";
-
 
52
	$l_dhcp_off		= "Le service DHCP est actuellement arrêté";
-
 
53
	$l_switch_on		= "Démarrer le service DHCP";
-
 
54
	$l_switch_off		= "Arrêter le service DHCP";
-
 
55
	$l_static_dhcp_title	= "Réservation d'adresses IP statiques";
-
 
56
	$l_mac_address		= "Adresse MAC";
-
 
57
	$l_ip_address		= "Adresse IP";
-
 
58
	$l_mac_del		= "Supprimer de la liste";
-
 
59
	$l_add_to_list		= "Ajouter";
-
 
60
	$l_submit		= "Appliquer";
-
 
61
 
20
} else {
62
} else {
21
	$l_network_title	= "Network configuration";
63
	$l_network_title	= "Network configuration";
22
	$l_eth0_legend		= "Eth0 (Internet connected interface)";
64
	$l_eth0_legend		= "Eth0 (Internet connected interface)";
23
	$l_eth1_legend		= "Eth1 (Private network)";
65
	$l_eth1_legend		= "Eth1 (Private network)";
24
	$l_internet_legend	= "INTERNET";
66
	$l_internet_legend	= "INTERNET";
25
	$l_ip_adr		= "IP Address";
67
	$l_ip_adr		= "IP Address";
26
	$l_ip_mask		= "Mask";
68
	$l_ip_mask		= "Mask";
27
	$l_ip_router		= "Router";
69
	$l_ip_router		= "Gateway";
28
	$l_ip_public		= "Public IP address";
70
	$l_ip_public		= "Public IP address";
29
	$l_ip_dns1		= "DNS1 :";
71
	$l_ip_dns1		= "DNS1 :";
30
	$l_ip_dns2		= "DNS2";
72
	$l_ip_dns2		= "DNS2";
-
 
73
	$l_dhcp_title		= "DHCP server";
-
 
74
	$l_dhcp_on		= "The DHCP service is enabled";
-
 
75
	$l_dhcp_off		= "The DHCP service is disabled";
-
 
76
	$l_switch_on		= "Start the DHCP service";
-
 
77
	$l_switch_off		= "Stop the DHCP service";
-
 
78
	$l_static_dhcp_title	= "Static IP addresses reservation";
-
 
79
	$l_mac_address		= "MAC Address";
-
 
80
	$l_ip_address		= "IP Address";
-
 
81
	$l_mac_del		= "Delete from list";
-
 
82
	$l_add_to_list		= "Add";
-
 
83
	$l_submit		= "Apply";
31
}
84
}
-
 
85
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
-
 
86
switch ($choix)
32
 
87
{
-
 
88
case 'DHCP_On' :
33
/********************************************************************
89
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -on");
-
 
90
	break;
-
 
91
case 'DHCP_Off' :
34
*	CONSTANTES AVEC CHEMINS DES FICHIERS DE CONFIGURATION			*
92
	exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -off");
-
 
93
	break;
-
 
94
case 'new_mac' :
35
*********************************************************************/
95
	if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
-
 
96
		{
36
define ("ALCASAR_CHILLI", "/etc/chilli.conf");
97
		$tab=file(ETHERS_FILE);
-
 
98
		$insert="True";
37
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
99
		if ($tab)  # le fichier n'est pas vide
38
 
100
			{
-
 
101
			foreach ($tab as $line)  # on vérifie que les adresses mac et IP ne sont pas déjà présentes
-
 
102
				{
-
 
103
				$field=explode(" ", $line);
39
/********************************************************************
104
				$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
40
*				TEST DES FICHIERS DE CONFIGURATION					*
105
				if (trim($_POST['add_mac']) == trim ($mac_addr))
-
 
106
					{
-
 
107
					$insert="False";
-
 
108
					break;
-
 
109
					}
41
*********************************************************************/
110
				if (trim($_POST['add_iip']) == trim ($ip_addr))
-
 
111
					{
-
 
112
					$insert="False";
-
 
113
					break;
-
 
114
					}
-
 
115
				}
-
 
116
			}
-
 
117
		if ($insert == "True") 
-
 
118
			{
42
//Test de présence et des droits en lecture des fichiers de configuration.
119
			$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
43
if (!file_exists(ALCASAR_CHILLI)){
120
			$pointeur=fopen(ETHERS_FILE,"a");
-
 
121
			fwrite ($pointeur, $line);
-
 
122
			fclose ($pointeur);
44
	exit("Fichier de configuration ".ALCASAR_CHILLI." non présent");
123
			# exec ("sudo service chilli restart");
-
 
124
			}
45
}
125
		}
-
 
126
	break;
-
 
127
case 'del_mac' :
46
if (!file_exists(CONF_FILE)){
128
	$tab=file(ETHERS_FILE);
-
 
129
	if ($tab)
-
 
130
		{
47
	exit("Fichier de configuration ".CONF_FILE." non présent");
131
		$pointeur=fopen(ETHERS_FILE,"w+");
-
 
132
		foreach ($tab as $line)
48
}
133
			{
49
if (!is_readable(ALCASAR_CHILLI)){
134
			$field=explode(" ", $line);
-
 
135
			$mac_addr=trim($field[0]);
-
 
136
			$remove_line = False;
-
 
137
			foreach ($_POST as $key => $value)
-
 
138
				{
-
 
139
				if ($mac_addr == $key)
-
 
140
			       		{
-
 
141
					$remove_line = True;
-
 
142
					break;
-
 
143
					}
-
 
144
				}
50
	exit("Vous n'avez pas les droits de lecture sur le fichier ".ALCASAR_CHILLI);
145
			if (! $remove_line) {fwrite($pointeur,$line);}
51
}
146
			}
52
if (!is_readable(CONF_FILE)){
147
		fclose($pointeur);
53
	exit("Vous n'avez pas les droits de lecture sur le fichier ".CONF_FILE);
148
		# exec ("sudo service chilli restart");
-
 
149
		}
-
 
150
	break;
54
}
151
}
55
 
152
 
56
// Fonction de test de connectivité internet
153
// Fonction de test de connectivité internet
57
function internetTest(){
154
function internetTest(){
58
	$host = "www.google.fr"; # Google Test
155
	$host = "www.google.fr"; # Google Test
59
	$port = "80";
156
	$port = "80";
60
	//var $num;	//non utilisé
157
	//var $num;	//non utilisé
61
	//var $error;	//non utilisé
158
	//var $error;	//non utilisé
62
	
159
	
63
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
160
	if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
64
		return false;
161
		return false;
65
	} else {
162
	} else {
66
		fclose($sock);
163
		fclose($sock);
67
		return true;
164
		return true;
68
	}
165
	}
69
}
166
}
70
/********************************************************
167
/********************************************************
71
*		Lecture du fichier ALCASAR_CHILLI	*
168
*		Lecture du fichier ALCASAR_CHILLI	*
72
*********************************************************/
169
*********************************************************/
73
$ouvre=fopen(ALCASAR_CHILLI,"r");
170
$ouvre=fopen(ALCASAR_CHILLI,"r");
74
if ($ouvre){
171
if ($ouvre){
75
	while (!feof ($ouvre))
172
	while (!feof ($ouvre))
76
	{
173
	{
77
		$tampon = fgets($ouvre, 4096);
174
		$tampon = fgets($ouvre, 4096);
78
		if (strpos($tampon,"=")!==false){
175
		if (strpos($tampon,"=")!==false){
79
			$tmp = explode("=",$tampon);
176
			$tmp = explode("=",$tampon);
80
			$chilli[$tmp[0]] = $tmp[1];
177
			$chilli[$tmp[0]] = $tmp[1];
81
		}
178
		}
82
	}
179
	}
83
}else{
180
}else{
84
	exit("Erreur d'ouverture du fichier ".ALCASAR_CHILLI);
181
	exit("Erreur d'ouverture du fichier ".ALCASAR_CHILLI);
85
}
182
}
86
fclose($ouvre);
183
fclose($ouvre);
87
 
184
 
88
/****************************************************************
185
/****************************************************************
89
*		Lecture du fichier CONF_FILE			*
186
*		Lecture du fichier CONF_FILE			*
90
*****************************************************************/
187
*****************************************************************/
91
$ouvre=fopen(CONF_FILE,"r");
188
$ouvre=fopen(CONF_FILE,"r");
92
if ($ouvre){
189
if ($ouvre){
93
	while (!feof ($ouvre))
190
	while (!feof ($ouvre))
94
	{
191
	{
95
		$tampon = fgets($ouvre, 4096);
192
		$tampon = fgets($ouvre, 4096);
96
		if (strpos($tampon,"=")!==false){
193
		if (strpos($tampon,"=")!==false){
97
			$tmp = explode("=",$tampon);
194
			$tmp = explode("=",$tampon);
98
			$conf[$tmp[0]] = $tmp[1];
195
			$conf[$tmp[0]] = $tmp[1];
99
		}
196
		}
100
	}
197
	}
101
}else{
198
}else{
102
	exit("Erreur d'ouverture du fichier ".ALCASAR_ETH1);
199
	exit("Erreur d'ouverture du fichier ".CONF_FILE);
103
}
200
}
104
fclose($ouvre);
201
fclose($ouvre);
105
 
202
 
106
/************************
203
/************************
107
*	TO DO		*
204
*	TO DO		*
108
*************************/
205
*************************/
109
//modification de la conf réseau  --> V3.0
206
//modification de la conf réseau  --> V3.0
110
//gestion du dhcp (affichage,modification, ajout @static)
-
 
111
 
207
 
112
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
208
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
113
<html><!-- written by steweb57 / rexy -->
209
<html><!-- written by steweb57 & rexy -->
114
<head>
210
<head>
115
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
211
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
116
<title><?php echo $l_network_title; ?></title>
212
<title><?php echo $l_network_title; ?></title>
117
<link rel="stylesheet" href="/css/style.css" type="text/css">
213
<link rel="stylesheet" href="/css/style.css" type="text/css">
118
</head>
214
</head>
119
<body>
215
<body>
120
<table width="100%" border="0" cellspacing="0" cellpadding="0">
216
<table width="100%" border="0" cellspacing="0" cellpadding="0">
121
	<tr><th><?php echo $l_network_title; ?></th></tr>
217
	<tr><th><?php echo $l_network_title; ?></th></tr>
122
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
218
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
123
</table>
219
</table>
124
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
220
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
125
	<tr><td valign="middle" align="left">
221
	<tr><td valign="middle" align="left">
126
	<fieldset>
222
	<fieldset>
127
	<legend><?php echo $l_internet_legend;
223
	<legend><?php echo $l_internet_legend;
128
 	if (InternetTest()){
224
 	if (InternetTest()){
129
		echo " <img src='/images/state_ok.gif'> $l_enable";
225
		echo " <img src='/images/state_ok.gif'>";
130
		$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
226
		$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
131
	else 	{
227
	else 	{
132
		echo " <img src='/images/state_error.gif'> $l_disable";
228
		echo " <img src='/images/state_error.gif'>";
133
		$IP_PUB = "-.-.-.-";}
229
		$IP_PUB = "-.-.-.-";}
134
	?></legend>
230
	?></legend>
135
	<table>
231
	<table>
136
		<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
232
		<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
137
		<tr><td><?php echo $l_ip_dns1." : </td><td>".$conf["DNS1"];?></td></tr>
233
		<tr><td><?php echo $l_ip_dns1." : </td><td>".$conf["DNS1"];?></td></tr>
138
		<tr><td><?php echo $l_ip_dns2." : </td><td>".$conf["DNS2"];?></td></tr>
234
		<tr><td><?php echo $l_ip_dns2." : </td><td>".$conf["DNS2"];?></td></tr>
139
	</table>
235
	</table>
140
	</fieldset>
236
	</fieldset>
141
	</td><td>
237
	</td><td>
142
	<fieldset>
238
	<fieldset>
143
	<legend><?php echo $l_eth0_legend; ?></legend>
239
	<legend><?php echo $l_eth0_legend; ?></legend>
144
	<table>
240
	<table>
145
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PUBLIC_IP"];?></td></tr>
241
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PUBLIC_IP"];?></td></tr>
146
		<tr><td><?php echo $l_ip_router." : </td><td>".$conf["GW"];?></td></tr>
242
		<tr><td><?php echo $l_ip_router." : </td><td>".$conf["GW"];?></td></tr>
147
	</table>
243
	</table>
148
	</fieldset>
244
	</fieldset>
149
	</td><td>
245
	</td><td>
150
	<fieldset>
246
	<fieldset>
151
	<legend><?php echo $l_eth1_legend; ?></legend>
247
	<legend><?php echo $l_eth1_legend; ?></legend>
152
	<table>
248
	<table>
153
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PRIVATE_IP"];?></td></tr>
249
		<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PRIVATE_IP"];?></td></tr>
154
	</table>
250
	</table>
155
	</fieldset>
251
	</fieldset>
156
	</td></tr>
252
	</td></tr>
157
</table>
253
</table>
158
<table width="100%" border="0" cellspacing="0" cellpadding="0">
254
<table width="100%" border="0" cellspacing="0" cellpadding="0">
159
	<tr><th><?php echo $l_main_services; ?></th></tr>
255
	<tr><th><?php echo $l_dhcp_title;?></th></tr>
160
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
256
	<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
161
</table>
257
</table>
-
 
258
<table width="100%" border=1 cellspacing=0 cellpadding=0>
-
 
259
<tr><td valign="middle" align="left">
-
 
260
<?
-
 
261
if (strncmp ($conf["DHCP"],"on",2) == 0)
-
 
262
 	{
-
 
263
	echo "<CENTER><H3>$l_dhcp_on</H3></CENTER>";
-
 
264
	echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
-
 
265
	echo "<input type=hidden name='choix' value=\"DHCP_Off\">";
-
 
266
	echo "<input type=submit value=\"$l_switch_off\">";
-
 
267
	}
-
 
268
else
-
 
269
	{
-
 
270
	echo "<CENTER><H3>$l_dhcp_off</H3></CENTER>";
-
 
271
 	echo "<FORM action='$_SERVER[PHP_SELF]' method=POST>";
-
 
272
	echo "<input type=hidden name='choix' value=\"DHCP_On\">";
-
 
273
	echo "<input type=submit value=\"$l_switch_on\">";
-
 
274
	}
-
 
275
echo "</FORM>";
-
 
276
echo "</td></tr>";
-
 
277
echo "</TABLE>";
-
 
278
if (strncmp($conf["DHCP"],"on",2) == 0) require ('network2.php');
-
 
279
?>
-
 
280
</BODY>
162
</body>
281
</body>
163
</html>
282
</html>
164
 
283