| Line 1... |
Line 1... |
| 1 |
<?php
|
1 |
<?php
|
| 2 |
# $Id: network.php 2688 2019-01-18 23:15:49Z lucas.echard $
|
2 |
# $Id: network.php 2708 2019-03-05 23:17:43Z tom.houdayer $
|
| 3 |
|
3 |
|
| 4 |
// written by steweb57, Rexy & Tom HOUDAYER
|
4 |
// written by steweb57, Rexy & Tom HOUDAYER
|
| 5 |
|
5 |
|
| 6 |
/********************
|
6 |
/********************
|
| 7 |
* READ CONF FILES *
|
7 |
* READ CONF FILES *
|
| Line 55... |
Line 55... |
| 55 |
$l_dhcp_state = "Mode actuel";
|
55 |
$l_dhcp_state = "Mode actuel";
|
| 56 |
$l_DHCP_on = "actif";
|
56 |
$l_DHCP_on = "actif";
|
| 57 |
$l_DHCP_off = "inactif";
|
57 |
$l_DHCP_off = "inactif";
|
| 58 |
$l_DHCP_off_explain = "/!\\ Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
|
58 |
$l_DHCP_off_explain = "/!\\ Avant d'arrêter le serveur DHCP, vous devez renseigner les paramètres d'un serveur externe (cf. documentation).";
|
| 59 |
$l_static_dhcp_title = "Réservation d'adresses IP statiques";
|
59 |
$l_static_dhcp_title = "Réservation d'adresses IP statiques";
|
| - |
|
60 |
$l_dhcp_relay = "Relais DHCP";
|
| - |
|
61 |
$l_dhcp_relay_local_ip = "Adresse IP locale";
|
| - |
|
62 |
$l_dhcp_relay_ip = "Adresse IP DHCP";
|
| - |
|
63 |
$l_dhcp_relay_port = "Port DHCP";
|
| 60 |
$l_mac_address = "Adresse MAC";
|
64 |
$l_mac_address = "Adresse MAC";
|
| 61 |
$l_ip_address = "Adresse IP";
|
65 |
$l_ip_address = "Adresse IP";
|
| 62 |
$l_host_name = "Nom d'hôte";
|
66 |
$l_host_name = "Nom d'hôte";
|
| 63 |
$l_del = "Supprimer de la liste";
|
67 |
$l_del = "Supprimer de la liste";
|
| 64 |
$l_add_to_list = "Ajouter";
|
68 |
$l_add_to_list = "Ajouter";
|
| Line 109... |
Line 113... |
| 109 |
$l_dhcp_state = "Current mode";
|
113 |
$l_dhcp_state = "Current mode";
|
| 110 |
$l_DHCP_on = "enabled";
|
114 |
$l_DHCP_on = "enabled";
|
| 111 |
$l_DHCP_off = "disabled";
|
115 |
$l_DHCP_off = "disabled";
|
| 112 |
$l_DHCP_off_explain = "/!\\ Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
|
116 |
$l_DHCP_off_explain = "/!\\ Before disabling the DHCP server, you must write the extern DHCP parameters in the config file (see Documentation)";
|
| 113 |
$l_static_dhcp_title = "Static IP addresses reservation";
|
117 |
$l_static_dhcp_title = "Static IP addresses reservation";
|
| - |
|
118 |
$l_dhcp_relay = "DHCP relay";
|
| - |
|
119 |
$l_dhcp_relay_local_ip = "Locale IP address";
|
| - |
|
120 |
$l_dhcp_relay_ip = "DHCP IP address";
|
| - |
|
121 |
$l_dhcp_relay_port = "DHCP port";
|
| 114 |
$l_mac_address = "MAC Address";
|
122 |
$l_mac_address = "MAC address";
|
| 115 |
$l_ip_address = "IP Address";
|
123 |
$l_ip_address = "IP address";
|
| - |
|
124 |
$l_port = "Port";
|
| 116 |
$l_host_name = "Host name";
|
125 |
$l_host_name = "Host name";
|
| 117 |
$l_del = "Delete from list";
|
126 |
$l_del = "Delete from list";
|
| 118 |
$l_add_to_list = "Add";
|
127 |
$l_add_to_list = "Add";
|
| 119 |
$l_apply = "Apply changes";
|
128 |
$l_apply = "Apply changes";
|
| 120 |
$l_local_dns = "Local name resolution";
|
129 |
$l_local_dns = "Local name resolution";
|
| Line 161... |
Line 170... |
| 161 |
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
|
170 |
$choix = (isset($_POST['choix'])) ? $_POST['choix'] : '';
|
| 162 |
|
171 |
|
| 163 |
switch ($choix) {
|
172 |
switch ($choix) {
|
| 164 |
case 'DHCP_On':
|
173 |
case 'DHCP_On':
|
| 165 |
exec('sudo /usr/local/bin/alcasar-dhcp.sh -on');
|
174 |
exec('sudo /usr/local/bin/alcasar-dhcp.sh -on');
|
| - |
|
175 |
header('Location: '.$_SERVER['PHP_SELF']);
|
| 166 |
break;
|
176 |
exit();
|
| 167 |
case 'DHCP_Off':
|
177 |
case 'DHCP_Off':
|
| 168 |
exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
|
178 |
exec('sudo /usr/local/bin/alcasar-dhcp.sh -off');
|
| - |
|
179 |
header('Location: '.$_SERVER['PHP_SELF']);
|
| 169 |
break;
|
180 |
exit();
|
| 170 |
|
181 |
|
| 171 |
case 'new_mac':
|
182 |
case 'new_mac':
|
| 172 |
$new_mac_addr = trim($_POST['add_mac']);
|
183 |
$new_mac_addr = trim($_POST['add_mac']);
|
| 173 |
$new_ip_addr = trim($_POST['add_ip']);
|
184 |
$new_ip_addr = trim($_POST['add_ip']);
|
| 174 |
if (((!empty($new_mac_addr)) && (preg_match($reg_mac, $new_mac_addr))) && ((!empty($new_ip_addr)) && (preg_match($reg_ip, $new_ip_addr)))) {
|
185 |
if (((!empty($new_mac_addr)) && (preg_match($reg_mac, $new_mac_addr))) && ((!empty($new_ip_addr)) && (preg_match($reg_ip, $new_ip_addr)))) {
|
| Line 199... |
Line 210... |
| 199 |
fclose($pointeur);
|
210 |
fclose($pointeur);
|
| 200 |
exec('sudo /usr/bin/systemctl reload chilli');
|
211 |
exec('sudo /usr/bin/systemctl reload chilli');
|
| 201 |
}
|
212 |
}
|
| 202 |
}
|
213 |
}
|
| 203 |
}
|
214 |
}
|
| - |
|
215 |
header('Location: '.$_SERVER['PHP_SELF']);
|
| 204 |
break;
|
216 |
exit();
|
| 205 |
case 'del_mac':
|
217 |
case 'del_mac':
|
| 206 |
foreach ($_POST as $key => $value) {
|
218 |
foreach ($_POST as $key => $value) {
|
| 207 |
if ($value == 'on') {
|
219 |
if ($value == 'on') {
|
| 208 |
$ether_file = ETHERS_FILE;
|
220 |
$ether_file = ETHERS_FILE;
|
| 209 |
$ether_file_info = ETHERS_INFO_FILE;
|
221 |
$ether_file_info = ETHERS_INFO_FILE;
|
| 210 |
exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file");
|
222 |
exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file");
|
| 211 |
exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info");
|
223 |
exec("/bin/sed -i ".escapeshellarg("/^$key/d")." $ether_file_info");
|
| 212 |
exec('sudo /usr/bin/systemctl reload chilli');
|
224 |
exec('sudo /usr/bin/systemctl reload chilli');
|
| 213 |
}
|
225 |
}
|
| 214 |
}
|
226 |
}
|
| - |
|
227 |
header('Location: '.$_SERVER['PHP_SELF']);
|
| 215 |
break;
|
228 |
exit();
|
| - |
|
229 |
|
| - |
|
230 |
case 'dhcp_relay': // DHCP relay
|
| - |
|
231 |
// TODO : check DHCP relay before apply?
|
| - |
|
232 |
file_put_contents(CONF_FILE, str_replace('EXT_DHCP_IP='.$conf['EXT_DHCP_IP'], 'EXT_DHCP_IP='.trim($_POST['dhcp_relay_ext_ip']), file_get_contents(CONF_FILE)));
|
| - |
|
233 |
file_put_contents(CONF_FILE, str_replace('RELAY_DHCP_IP='.$conf['RELAY_DHCP_IP'], 'RELAY_DHCP_IP='.trim($_POST['dhcp_relay_ip']), file_get_contents(CONF_FILE)));
|
| - |
|
234 |
file_put_contents(CONF_FILE, str_replace('RELAY_DHCP_PORT='.$conf['RELAY_DHCP_PORT'], 'RELAY_DHCP_PORT='.trim($_POST['dhcp_relay_port']), file_get_contents(CONF_FILE)));
|
| - |
|
235 |
header('Location: '.$_SERVER['PHP_SELF']);
|
| - |
|
236 |
exit();
|
| 216 |
|
237 |
|
| 217 |
case 'new_host':
|
238 |
case 'new_host':
|
| 218 |
$add_host = trim($_POST['add_host']);
|
239 |
$add_host = trim($_POST['add_host']);
|
| 219 |
$add_ip = trim($_POST['add_ip']);
|
240 |
$add_ip = trim($_POST['add_ip']);
|
| 220 |
if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
|
241 |
if (((!empty($add_host)) && (preg_match($reg_host, $add_host))) && ((!empty($add_ip)) && (preg_match($reg_ip, $add_ip)))) {
|
| Line 235... |
Line 256... |
| 235 |
if ($insert) {
|
256 |
if ($insert) {
|
| 236 |
exec("sudo /usr/local/bin/alcasar-dns-local.sh --add $add_ip $add_host");
|
257 |
exec("sudo /usr/local/bin/alcasar-dns-local.sh --add $add_ip $add_host");
|
| 237 |
}
|
258 |
}
|
| 238 |
}
|
259 |
}
|
| 239 |
}
|
260 |
}
|
| - |
|
261 |
header('Location: '.$_SERVER['PHP_SELF']);
|
| 240 |
break;
|
262 |
exit();
|
| 241 |
case 'del_host':
|
263 |
case 'del_host':
|
| 242 |
foreach ($_POST as $key => $value) {
|
264 |
foreach ($_POST as $key => $value) {
|
| 243 |
if ($value == 'on') {
|
265 |
if ($value == 'on') {
|
| 244 |
$del_host = explode ("|", $key);
|
266 |
$del_host = explode ("|", $key);
|
| 245 |
$del_ip = str_replace("_",".",$del_host[0]);
|
267 |
$del_ip = str_replace("_",".",$del_host[0]);
|
| 246 |
exec("sudo /usr/local/bin/alcasar-dns-local.sh --del $del_ip $del_host[1]");
|
268 |
exec("sudo /usr/local/bin/alcasar-dns-local.sh --del $del_ip $del_host[1]");
|
| 247 |
}
|
269 |
}
|
| 248 |
}
|
270 |
}
|
| - |
|
271 |
header('Location: '.$_SERVER['PHP_SELF']);
|
| 249 |
break;
|
272 |
exit();
|
| 250 |
|
273 |
|
| 251 |
case 'default_cert': // Restore default certificate
|
274 |
case 'default_cert': // Restore default certificate
|
| 252 |
exec('sudo alcasar-importcert.sh -d');
|
275 |
exec('sudo alcasar-importcert.sh -d');
|
| 253 |
break;
|
276 |
break;
|
| 254 |
|
277 |
|
| Line 677... |
Line 700... |
| 677 |
<input type="submit" value="<?= $l_apply ?>">
|
700 |
<input type="submit" value="<?= $l_apply ?>">
|
| 678 |
<br><?= $l_DHCP_off_explain ?>
|
701 |
<br><?= $l_DHCP_off_explain ?>
|
| 679 |
</form>
|
702 |
</form>
|
| 680 |
</td></tr>
|
703 |
</td></tr>
|
| 681 |
|
704 |
|
| 682 |
<?php
|
- |
|
| 683 |
if ($conf['DHCP'] === 'on') {
|
705 |
<?php if ($conf['DHCP'] === 'on'): ?>
|
| 684 |
require('network2.php');
|
- |
|
| 685 |
}
|
- |
|
| 686 |
?>
|
- |
|
| 687 |
</table>
|
- |
|
| 688 |
<br>
|
- |
|
| 689 |
|
- |
|
| 690 |
<table width="100%" cellspacing="0" cellpadding="0" border="0">
|
- |
|
| 691 |
<tr><th><?= $l_local_dns?></th></tr>
|
- |
|
| 692 |
<tr bgcolor="#FFCC66"><td><img src="/images/pix.gif" width="1" height="2"></td></tr>
|
706 |
<tr><td colspan="2" align="center"><?= $l_static_dhcp_title ?></td></tr>
|
| 693 |
</table>
|
- |
|
| 694 |
<table width="100%" cellspacing="0" cellpadding="5" border="1">
|
- |
|
| 695 |
<tr>
|
- |
|
| 696 |
<td width="50%" align="center">
|
707 |
<tr><td width="50%" align="center" valign="middle">
|
| 697 |
<form action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
|
708 |
<form action="network.php" method="POST">
|
| 698 |
<table cellspacing="2" cellpadding="3" border="1">
|
709 |
<table cellspacing="2" cellpadding="3" border="1">
|
| 699 |
<tr><th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><th><?= $l_del ?></th></tr>
|
710 |
<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info<th><?= $l_del ?></th></tr>
|
| 700 |
<?php
|
711 |
<?php
|
| 701 |
// Read the "dns_local" file
|
712 |
// Read the "ether" file
|
| - |
|
713 |
exec('sudo /sbin/ip link show '.escapeshellarg($conf["INTIF"]), $output);
|
| - |
|
714 |
$detail = explode(' ', $output[1]);
|
| - |
|
715 |
$intif_mac_addr = strtoupper(str_replace(':', '-', $detail[5]));
|
| - |
|
716 |
unset($output); unset($detail);
|
| 702 |
$line_exist = false;
|
717 |
$line_exist = false;
|
| 703 |
$tab = file(DNS_LOCAL_FILE);
|
718 |
$tab = file(ETHERS_INFO_FILE);
|
| 704 |
if ($tab) { // not empty
|
719 |
if ($tab) { // le fichier n'est pas vide
|
| 705 |
foreach ($tab as $line) {
|
720 |
foreach ($tab as $line) {
|
| 706 |
if (preg_match ('/^\d+/', $line)) { # begin with one or several digit
|
721 |
$fields = explode(' ', $line);
|
| 707 |
$line_exist = true;
|
722 |
$mac_addr = $fields[0];
|
| 708 |
$field = preg_split("/\s+/",$line); # split with one or several whitespace (or tab)
|
- |
|
| 709 |
$ip_addr = $field[0];
|
723 |
$ip_addr = $fields[1];
|
| 710 |
$host_name = $field[1];
|
724 |
$info = (isset($fields[2])) ? $fields[2] : ' ';
|
| - |
|
725 |
|
| - |
|
726 |
echo '<tr>';
|
| 711 |
echo "<tr><td>$ip_addr</td>";
|
727 |
echo "<td>$mac_addr</td>";
|
| 712 |
echo "<td>$host_name</td>";
|
728 |
echo "<td>$ip_addr</td>";
|
| 713 |
if (($ip_addr == "127.0.0.1")|($host_name == "alcasar")) {
|
729 |
if ($mac_addr !== $intif_mac_addr) {
|
| 714 |
echo "<td>";}
|
730 |
echo '<td>'.ltrim($info, '#').'</td>';
|
| 715 |
else {
|
- |
|
| 716 |
echo "<td><input type=\"checkbox\" name=\"$ip_addr|$host_name\">";
|
731 |
echo "<td><input type=\"checkbox\" name=\"$mac_addr\"></td>";
|
| - |
|
732 |
$line_exist=True;
|
| 717 |
}
|
733 |
} else {
|
| - |
|
734 |
echo '<td>ALCASAR</td>';
|
| 718 |
echo "</td></tr>";
|
735 |
echo '<td></td>';
|
| 719 |
}
|
736 |
}
|
| - |
|
737 |
echo '</tr>';
|
| 720 |
}
|
738 |
}
|
| 721 |
}
|
739 |
}
|
| 722 |
if (!$line_exist) {
|
- |
|
| 723 |
echo '<tr><td colspan="3" style="text-align: center;font-style: italic;">'.$l_empty.'</td></tr>';
|
- |
|
| 724 |
}
|
- |
|
| 725 |
?>
|
740 |
?>
|
| 726 |
</table>
|
741 |
</table>
|
| 727 |
<?php if ($line_exist): ?>
|
742 |
<?php if ($line_exist): ?>
|
| 728 |
<input type="hidden" name="choix" value="del_host">
|
743 |
<input type="hidden" name="choix" value="del_mac">
|
| 729 |
<input type="submit" value="<?= $l_apply ?>">
|
744 |
<input type="submit" value="<?= $l_apply ?>">
|
| 730 |
<?php endif; ?>
|
745 |
<?php endif; ?>
|
| 731 |
</form>
|
746 |
</form>
|
| 732 |
</td>
|
- |
|
| 733 |
<td width="50%" valign="middle" align="center">
|
747 |
</td><td width="50%" valign="middle" align="center">
|
| 734 |
<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
|
748 |
<form name="new_mac" action="network.php" method="POST">
|
| 735 |
<table cellspacing="2" cellpadding="3" border="1">
|
749 |
<table cellspacing="2" cellpadding="3" border="1">
|
| 736 |
<tr>
|
- |
|
| 737 |
<th><?= $l_ip_address ?></th><th><?= $l_host_name ?></th><td></td>
|
750 |
<tr><th><?= $l_mac_address ?></th><th><?= $l_ip_address ?></th><th>Info</th><td></td></tr>
|
| 738 |
</tr>
|
- |
|
| 739 |
<tr>
|
- |
|
| 740 |
<td>Ex. : 192.168.182.10</td><td>Ex. : my_nas</td><td></td>
|
751 |
<tr><td>Ex. : 12-2F-36-A4-DF-43</td><td>Ex. : 192.168.182.10</td><td>Ex. : Switch<td></td></tr>
|
| - |
|
752 |
<tr><td><input type="text" name="add_mac" size="17"></td>
|
| - |
|
753 |
<td><input type="text" name="add_ip" size="10"></td>
|
| 741 |
</tr>
|
754 |
<td><input type="text" name="info" size="10"></td>
|
| 742 |
<tr>
|
755 |
<td>
|
| 743 |
<td><input type="text" name="add_ip" size="10"><input type="hidden" name="choix" value="new_host"></td>
|
- |
|
| 744 |
<td><input type="text" name="add_host" size="17"></td>
|
756 |
<input type="hidden" name="choix" value="new_mac">
|
| 745 |
<td><input type=submit class=button value="<?= $l_add_to_list ?>"></td>
|
757 |
<input type="submit" class="button" value="<?= $l_add_to_list ?>" onclick="return MAC_Control('new_mac');">
|
| 746 |
</tr>
|
758 |
</td>
|
| 747 |
</table>
|
759 |
</tr></table>
|
| 748 |
</form>
|
760 |
</form>
|
| - |
|
761 |
</td></tr>
|
| - |
|
762 |
<?php else: ?>
|
| - |
|
763 |
<tr><td colspan="2" align="center"><?= $l_dhcp_relay ?></td></tr>
|
| - |
|
764 |
<tr>
|
| - |
|
765 |
<td colspan="2" align="center">
|
| - |
|
766 |
<form name="new_host" action="<?= htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
|
| - |
|
767 |
<table cellspacing="2" cellpadding="3" border="1">
|
| - |
|
768 |
<tr>
|
| - |
|
769 |
<th><label for="dhcp_relay_ip"><?= $l_dhcp_relay_local_ip ?></label></th><td><input type="text" name="dhcp_relay_ip" id="dhcp_relay_ip" value="<?= $conf['RELAY_DHCP_IP'] ?>" size="32"></td>
|
| - |
|
770 |
</tr>
|
| - |
|
771 |
<tr>
|
| - |
|
772 |
<th><label for="dhcp_relay_ext_ip"><?= $l_dhcp_relay_ip ?></label></th><td><input type="text" name="dhcp_relay_ext_ip" id="dhcp_relay_ext_ip" value="<?= $conf['EXT_DHCP_IP'] ?>" size="32"></td>
|
| - |
|
773 |
</tr>
|
| - |
|
774 |
<tr>
|
| - |
|
775 |
<th><label for="dhcp_relay_port"><?= $l_dhcp_relay_port ?></label></th><td><input type="text" name="dhcp_relay_port" id="dhcp_relay_port" value="<?= $conf['RELAY_DHCP_PORT'] ?>" size="32"></td>
|
| - |
|
776 |
</tr>
|
| - |
|
777 |
</table>
|
| - |
|
778 |
<input type="hidden" name="choix" value="dhcp_relay">
|
| - |
|
779 |
<input type="submit" value="<?= $l_apply ?>">
|
| - |
|
780 |
</form>
|
| 749 |
</td>
|
781 |
</td>
|
| 750 |
</tr>
|
782 |
</tr>
|
| - |
|
783 |
<?php endif; ?>
|
| 751 |
</table>
|
784 |
</table>
|
| 752 |
<br>
|
785 |
<br>
|
| 753 |
|
786 |
|
| 754 |
<table width="100%" cellspacing="0" cellpadding="0" border="0">
|
787 |
<table width="100%" cellspacing="0" cellpadding="0" border="0">
|
| 755 |
<tr><th><?= $l_ssl_title ?></th></tr>
|
788 |
<tr><th><?= $l_ssl_title ?></th></tr>
|