318 |
richard |
1 |
<?php
|
838 |
richard |
2 |
/* written by steweb57 & Rexy */
|
318 |
richard |
3 |
|
841 |
richard |
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 |
|
318 |
richard |
34 |
# Choice of language
|
|
|
35 |
$Language = 'en';
|
|
|
36 |
if(isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])){
|
|
|
37 |
$Langue = explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
|
|
|
38 |
$Language = strtolower(substr(chop($Langue[0]),0,2)); }
|
|
|
39 |
if($Language == 'fr'){
|
|
|
40 |
$l_network_title = "Configuration réseau";
|
|
|
41 |
$l_eth0_legend = "Eth0 (Interface connectée à Internet)";
|
|
|
42 |
$l_eth1_legend = "Eth1 (Réseau de consultation)";
|
|
|
43 |
$l_internet_legend = "INTERNET";
|
|
|
44 |
$l_ip_adr = "Adresse IP";
|
|
|
45 |
$l_ip_mask = "Masque";
|
|
|
46 |
$l_ip_router = "Passerelle";
|
736 |
franck |
47 |
$l_ip_public = "Adresse IP publique";
|
318 |
richard |
48 |
$l_ip_dns1 = "DNS1";
|
|
|
49 |
$l_ip_dns2 = "DNS2";
|
841 |
richard |
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 |
|
318 |
richard |
62 |
} else {
|
|
|
63 |
$l_network_title = "Network configuration";
|
|
|
64 |
$l_eth0_legend = "Eth0 (Internet connected interface)";
|
|
|
65 |
$l_eth1_legend = "Eth1 (Private network)";
|
|
|
66 |
$l_internet_legend = "INTERNET";
|
|
|
67 |
$l_ip_adr = "IP Address";
|
|
|
68 |
$l_ip_mask = "Mask";
|
841 |
richard |
69 |
$l_ip_router = "Gateway";
|
318 |
richard |
70 |
$l_ip_public = "Public IP address";
|
|
|
71 |
$l_ip_dns1 = "DNS1 :";
|
|
|
72 |
$l_ip_dns2 = "DNS2";
|
841 |
richard |
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";
|
318 |
richard |
84 |
}
|
841 |
richard |
85 |
if (isset($_POST['choix'])){$choix=$_POST['choix'];} else {$choix="";}
|
|
|
86 |
switch ($choix)
|
|
|
87 |
{
|
|
|
88 |
case 'DHCP_On' :
|
|
|
89 |
exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -on");
|
|
|
90 |
break;
|
|
|
91 |
case 'DHCP_Off' :
|
|
|
92 |
exec ("sudo /usr/local/sbin/alcasar-dhcp.sh -off");
|
|
|
93 |
break;
|
|
|
94 |
case 'new_mac' :
|
|
|
95 |
if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
|
|
|
96 |
{
|
|
|
97 |
$tab=file(ETHERS_FILE);
|
|
|
98 |
$insert="True";
|
|
|
99 |
if ($tab) # le fichier n'est pas vide
|
|
|
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);
|
|
|
104 |
$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
|
|
|
105 |
if (trim($_POST['add_mac']) == trim ($mac_addr))
|
|
|
106 |
{
|
|
|
107 |
$insert="False";
|
|
|
108 |
break;
|
|
|
109 |
}
|
|
|
110 |
if (trim($_POST['add_iip']) == trim ($ip_addr))
|
|
|
111 |
{
|
|
|
112 |
$insert="False";
|
|
|
113 |
break;
|
|
|
114 |
}
|
|
|
115 |
}
|
|
|
116 |
}
|
|
|
117 |
if ($insert == "True")
|
|
|
118 |
{
|
|
|
119 |
$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
|
|
|
120 |
$pointeur=fopen(ETHERS_FILE,"a");
|
|
|
121 |
fwrite ($pointeur, $line);
|
|
|
122 |
fclose ($pointeur);
|
|
|
123 |
# exec ("sudo service chilli restart");
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
break;
|
|
|
127 |
case 'del_mac' :
|
|
|
128 |
$tab=file(ETHERS_FILE);
|
|
|
129 |
if ($tab)
|
|
|
130 |
{
|
|
|
131 |
$pointeur=fopen(ETHERS_FILE,"w+");
|
|
|
132 |
foreach ($tab as $line)
|
|
|
133 |
{
|
|
|
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 |
}
|
|
|
145 |
if (! $remove_line) {fwrite($pointeur,$line);}
|
|
|
146 |
}
|
|
|
147 |
fclose($pointeur);
|
|
|
148 |
# exec ("sudo service chilli restart");
|
|
|
149 |
}
|
|
|
150 |
break;
|
318 |
richard |
151 |
}
|
|
|
152 |
|
|
|
153 |
// Fonction de test de connectivité internet
|
|
|
154 |
function internetTest(){
|
696 |
franck |
155 |
$host = "www.google.fr"; # Google Test
|
318 |
richard |
156 |
$port = "80";
|
|
|
157 |
//var $num; //non utilisé
|
|
|
158 |
//var $error; //non utilisé
|
|
|
159 |
|
|
|
160 |
if (! $sock = @fsockopen($host, $port, $num, $error, 5)) {
|
|
|
161 |
return false;
|
|
|
162 |
} else {
|
|
|
163 |
fclose($sock);
|
|
|
164 |
return true;
|
|
|
165 |
}
|
|
|
166 |
}
|
838 |
richard |
167 |
/********************************************************
|
|
|
168 |
* Lecture du fichier ALCASAR_CHILLI *
|
|
|
169 |
*********************************************************/
|
318 |
richard |
170 |
$ouvre=fopen(ALCASAR_CHILLI,"r");
|
|
|
171 |
if ($ouvre){
|
|
|
172 |
while (!feof ($ouvre))
|
|
|
173 |
{
|
|
|
174 |
$tampon = fgets($ouvre, 4096);
|
|
|
175 |
if (strpos($tampon,"=")!==false){
|
|
|
176 |
$tmp = explode("=",$tampon);
|
|
|
177 |
$chilli[$tmp[0]] = $tmp[1];
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
}else{
|
|
|
181 |
exit("Erreur d'ouverture du fichier ".ALCASAR_CHILLI);
|
|
|
182 |
}
|
|
|
183 |
fclose($ouvre);
|
|
|
184 |
|
838 |
richard |
185 |
/****************************************************************
|
|
|
186 |
* Lecture du fichier CONF_FILE *
|
|
|
187 |
*****************************************************************/
|
654 |
richard |
188 |
$ouvre=fopen(CONF_FILE,"r");
|
318 |
richard |
189 |
if ($ouvre){
|
|
|
190 |
while (!feof ($ouvre))
|
|
|
191 |
{
|
|
|
192 |
$tampon = fgets($ouvre, 4096);
|
|
|
193 |
if (strpos($tampon,"=")!==false){
|
|
|
194 |
$tmp = explode("=",$tampon);
|
654 |
richard |
195 |
$conf[$tmp[0]] = $tmp[1];
|
318 |
richard |
196 |
}
|
|
|
197 |
}
|
|
|
198 |
}else{
|
841 |
richard |
199 |
exit("Erreur d'ouverture du fichier ".CONF_FILE);
|
318 |
richard |
200 |
}
|
|
|
201 |
fclose($ouvre);
|
|
|
202 |
|
|
|
203 |
/************************
|
|
|
204 |
* TO DO *
|
|
|
205 |
*************************/
|
838 |
richard |
206 |
//modification de la conf réseau --> V3.0
|
318 |
richard |
207 |
|
|
|
208 |
?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
841 |
richard |
209 |
<html><!-- written by steweb57 & rexy -->
|
318 |
richard |
210 |
<head>
|
|
|
211 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
212 |
<title><?php echo $l_network_title; ?></title>
|
335 |
richard |
213 |
<link rel="stylesheet" href="/css/style.css" type="text/css">
|
318 |
richard |
214 |
</head>
|
|
|
215 |
<body>
|
|
|
216 |
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
353 |
richard |
217 |
<tr><th><?php echo $l_network_title; ?></th></tr>
|
318 |
richard |
218 |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
|
|
|
219 |
</table>
|
|
|
220 |
<TABLE width="100%" border=1 cellspacing=0 cellpadding=1>
|
|
|
221 |
<tr><td valign="middle" align="left">
|
|
|
222 |
<fieldset>
|
|
|
223 |
<legend><?php echo $l_internet_legend;
|
|
|
224 |
if (InternetTest()){
|
841 |
richard |
225 |
echo " <img src='/images/state_ok.gif'>";
|
318 |
richard |
226 |
$IP_PUB = exec ("wget http://checkip.dyndns.org/ -O - -o /dev/null | cut -d: -f 2 | cut -d\< -f 1");}
|
|
|
227 |
else {
|
841 |
richard |
228 |
echo " <img src='/images/state_error.gif'>";
|
318 |
richard |
229 |
$IP_PUB = "-.-.-.-";}
|
|
|
230 |
?></legend>
|
|
|
231 |
<table>
|
|
|
232 |
<tr><td><?php echo $l_ip_public." : </td><td>".$IP_PUB;?></td></tr>
|
654 |
richard |
233 |
<tr><td><?php echo $l_ip_dns1." : </td><td>".$conf["DNS1"];?></td></tr>
|
|
|
234 |
<tr><td><?php echo $l_ip_dns2." : </td><td>".$conf["DNS2"];?></td></tr>
|
318 |
richard |
235 |
</table>
|
|
|
236 |
</fieldset>
|
|
|
237 |
</td><td>
|
|
|
238 |
<fieldset>
|
|
|
239 |
<legend><?php echo $l_eth0_legend; ?></legend>
|
|
|
240 |
<table>
|
654 |
richard |
241 |
<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PUBLIC_IP"];?></td></tr>
|
|
|
242 |
<tr><td><?php echo $l_ip_router." : </td><td>".$conf["GW"];?></td></tr>
|
318 |
richard |
243 |
</table>
|
|
|
244 |
</fieldset>
|
|
|
245 |
</td><td>
|
|
|
246 |
<fieldset>
|
|
|
247 |
<legend><?php echo $l_eth1_legend; ?></legend>
|
|
|
248 |
<table>
|
654 |
richard |
249 |
<tr><td><?php echo $l_ip_adr." : </td><td>".$conf["PRIVATE_IP"];?></td></tr>
|
318 |
richard |
250 |
</table>
|
|
|
251 |
</fieldset>
|
|
|
252 |
</td></tr>
|
|
|
253 |
</table>
|
353 |
richard |
254 |
<table width="100%" border="0" cellspacing="0" cellpadding="0">
|
841 |
richard |
255 |
<tr><th><?php echo $l_dhcp_title;?></th></tr>
|
353 |
richard |
256 |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
|
318 |
richard |
257 |
</table>
|
841 |
richard |
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>
|
318 |
richard |
281 |
</body>
|
|
|
282 |
</html>
|