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