Subversion Repositories ALCASAR

Compare Revisions

Ignore whitespace Rev 1958 → Rev 1959

/web/acc/admin/network.php
6,6 → 6,7
*********************/
define ("CONF_FILE", "/usr/local/etc/alcasar.conf");
define ("ETHERS_FILE", "/usr/local/etc/alcasar-ethers");
define ("DNS_LOCAL_FILE", "/usr/local/etc/alcasar-dns-name");
$conf_files=array(CONF_FILE,ETHERS_FILE);
$reg_ip = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/';
$reg_ip_cidr = '/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/';
26,7 → 27,6
$l_extif_legend = " (Interface connectée à Internet)";
$l_intif_legend = " (Réseau de consultation)";
$l_internet_legend = "INTERNET";
$l_ip_adr = "Adresse IP";
$l_ip_mask = "Masque";
$l_ip_router = "Passerelle";
$l_ip_public = "Adresse IP publique";
40,9 → 40,11
$l_static_dhcp_title = "Réservation d'adresses IP statiques";
$l_mac_address = "Adresse MAC";
$l_ip_address = "Adresse IP";
$l_mac_del = "Supprimer de la liste";
$l_host_name = "Nom d'hôte";
$l_del = "Supprimer de la liste";
$l_add_to_list = "Ajouter";
$l_apply = "Appliquer les changements";
$l_local_dns = "Résolution local de nom";
$l_import_cert = "Import de certificat";
$l_private_key = "Clé privée (.key) :";
$l_certificate = "Certificat (.crt) :";
57,7 → 59,6
$l_extif_legend = " (Internet connected interface)";
$l_intif_legend = " (Private network)";
$l_internet_legend = "INTERNET";
$l_ip_adr = "IP Address";
$l_ip_mask = "Mask";
$l_ip_router = "Gateway";
$l_ip_public = "Public IP address";
71,9 → 72,11
$l_static_dhcp_title = "Static IP addresses reservation";
$l_mac_address = "MAC Address";
$l_ip_address = "IP Address";
$l_mac_del = "Delete from list";
$l_host_name = "Host name";
$l_del = "Delete from list";
$l_add_to_list = "Add";
$l_apply = "Apply changes";
$l_local_dns = "Local name resolution";
$l_import_cert = "Certificate import";
$l_private_key = "Private key (.key) :";
$l_certificate = "Certificate (.crt) :";
97,10 → 100,10
if ((trim($_POST['add_mac']) != "") and (trim($_POST['add_ip']) != ""))
{
$tab=file(ETHERS_FILE);
$insert="True";
if ($tab) # the file isn't empty
{
foreach ($tab as $line) # verify that MAC or IP addresses doesn't exist
$insert="True";
foreach ($tab as $line) # verify that MAC or IP address doesn't exist
{
$field=explode(" ", $line);
$mac_addr=trim($field[0]);$ip_addr=trim($field[1]);
115,41 → 118,81
break;
}
}
if ($insert == "True")
{
$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
$pointeur=fopen(ETHERS_FILE,"a");
fwrite ($pointeur, $line);
fclose ($pointeur);
exec ("sudo /usr/bin/systemctl reload chilli");
}
}
if ($insert == "True")
}
break;
case 'del_mac' :
foreach ($_POST as $key => $value)
{
if ($value == 'on')
{
$line = trim($_POST['add_mac']) . " " . trim($_POST['add_ip']) . "\n";
$pointeur=fopen(ETHERS_FILE,"a");
fwrite ($pointeur, $line);
fclose ($pointeur);
$ether_file=ETHERS_FILE;
exec("/bin/sed -i \"/^$key/d\" $ether_file");
exec ("sudo /usr/bin/systemctl reload chilli");
}
}
break;
case 'del_mac' :
$tab=file(ETHERS_FILE);
if ($tab)
case 'new_host' :
if ((trim($_POST['add_host']) != "") and (trim($_POST['add_ip']) != ""))
{
$pointeur=fopen(ETHERS_FILE,"w+");
foreach ($tab as $line)
$tab=file(DNS_LOCAL_FILE);
$insert="True";
if ($tab) # the file isn't empty
{
$field=explode(" ", $line);
$mac_addr=trim($field[0]);
$remove_line = False;
foreach ($_POST as $key => $value)
foreach ($tab as $line) # verify that host or IP address doesn't exist
{
if ($mac_addr == $key)
{
$remove_line = True;
break;
if (preg_match ('/^address/', $line))
{
$field=explode("/", $line);
$host_name=trim($field[1]);$ip_addr=trim($field[2]);
if (strcasecmp(trim($_POST['add_host']),trim($host_name)) == 0)
{
$insert="False";
break;
}
if (strcasecmp(trim($_POST['add_ip']), trim($ip_addr)) == 0)
{
$insert="False";
break;
}
}
}
if (! $remove_line) {fwrite($pointeur,$line);}
if ($insert == "True")
{
$line1 = "address=/".trim($_POST['add_host'])."/".trim($_POST['add_ip'])."\n";
$explode_ip=explode('.',trim($_POST['add_ip']));
$reverse_ip=implode('.',array_reverse($explode_ip));
$line2 = "ptr-record=".$reverse_ip.".in-addr.arpa,".trim($_POST['add_host'])."\n";
$pointeur=fopen(DNS_LOCAL_FILE,"a");
fwrite ($pointeur, $line1);
fwrite ($pointeur, $line2);
fclose ($pointeur);
exec ("sudo /usr/bin/systemctl restart dnsmasq");
exec ("sudo /usr/bin/systemctl restart dnsmasq-blacklist");
exec ("sudo /usr/bin/systemctl restart dnsmasq-whitelist");
}
}
fclose($pointeur);
exec ("sudo /usr/bin/systemctl reload chilli");
}
break;
case 'del_mac' :
foreach ($_POST as $key => $value)
{
if ($value == 'on')
{
$ether_file=ETHERS_FILE;
exec("/bin/sed -i \"/^$key/d\" $ether_file");
exec ("sudo /usr/bin/systemctl reload chilli");
}
}
break;
}
 
// Fonction de test de connectivité internet
285,7 → 328,7
<table>
<?php
echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
echo "<tr><td>".$l_ip_adr." <input style='width:150px' type='text' name='ip_public' value=".$conf['PUBLIC_IP']."/></td></tr>";
echo "<tr><td>".$l_ip_address." <input style='width:150px' type='text' name='ip_public' value=".$conf['PUBLIC_IP']."/></td></tr>";
echo "<tr><td>".$l_ip_router." <input style='width:120px' type='text' name='ip_gw' value=".$conf['GW']."/></td></tr>";
?>
</table>
296,7 → 339,7
<table>
<?php
echo "<form action=".$_SERVER['PHP_SELF']." method='post'>";
echo "<tr><td>".$l_ip_adr."</td><td> <input style='width:150px' type='text' name='ip_private' value=".$conf['PRIVATE_IP']." /></td></tr>";
echo "<tr><td>".$l_ip_address."</td><td> <input style='width:150px' type='text' name='ip_private' value=".$conf['PRIVATE_IP']." /></td></tr>";
?>
</table>
</fieldset>
330,6 → 373,56
?>
 
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><th><?php echo $l_local_dns;?></th></tr>
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
</table>
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr><td colspan=2 align="center">
<?
echo "<FORM action='network.php' method='POST'>";
echo "<table cellspacing=2 cellpadding=3 border=1>";
echo "<tr><th>$l_host_name<th>$l_ip_address<th>$l_del</tr>";
// Read the "dns_local" file
$line_exist=False;
$tab=file(DNS_LOCAL_FILE);
if ($tab) # not empty
{
$line_exist=True;
foreach ($tab as $line)
{
if (preg_match ('/^address/', $line))
{
$field=explode("/", $line);
$ip_addr=$field[1];
$host_name=$field[2];
echo "<tr><td>$ip_addr";
echo "<td>$host_name";
echo "<td><input type='checkbox' name='$host_name'>";
echo "</tr>";
}
}
}
echo "</table>";
if ($line_exist)
{
echo "<input type='hidden' name='choix' value='del_host'>";
echo "<input type='submit' value='$l_apply'>";
}
echo "</form></td><td valign='middle' align='center'>";
echo "<FORM name='new_host' action='network.php' method='POST'>";
echo "<table cellspacing=2 cellpadding=3 border=1>";
echo "<tr><th>$l_host_name<th>$l_ip_address";
?>
<td></td></tr>
<tr><td>exemple : my_nas</td><td>exemple : 192.168.182.10</td><td></td></tr>
<tr><td><input type='text' name='add_host' size='17'></td>
<td><input type='text' name='add_ip' size='10'><input type='hidden' name='choix' value='new_host'></td>
<td><? echo "<input type=submit class=button value=\"$l_add_to_list\">"?></td>
</tr></table>
</form>
</td></tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr><th><?php echo $l_import_cert;?></th></tr>
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
</table>