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