summaryrefslogtreecommitdiffstats
path: root/usr/local
diff options
context:
space:
mode:
Diffstat (limited to 'usr/local')
-rwxr-xr-xusr/local/www/diag_dhcp_leases.php4
-rwxr-xr-xusr/local/www/services_dhcp.php72
-rwxr-xr-xusr/local/www/services_dhcp_edit.php30
-rwxr-xr-xusr/local/www/services_dnsmasq.php34
4 files changed, 91 insertions, 49 deletions
diff --git a/usr/local/www/diag_dhcp_leases.php b/usr/local/www/diag_dhcp_leases.php
index 4a94a54..de1d645 100755
--- a/usr/local/www/diag_dhcp_leases.php
+++ b/usr/local/www/diag_dhcp_leases.php
@@ -191,7 +191,7 @@ foreach($config['interfaces'] as $ifname => $ifarr) {
$slease['start'] = gmdate("M d Y H:i:s", time());
$slease['end'] = gmdate("M d Y H:i:s", time());
$slease['end'] = gmdate("M d Y H:i:s", strtotime('+5 minutes'));
- $slease['hostname'] = $static['descr'];
+ $slease['hostname'] = $static['hostname'];
$slease['act'] = "static";
$online = exec("/usr/sbin/arp -an |/usr/bin/grep {$slease['mac']}| /usr/bin/wc -l|/usr/bin/awk '{print $1;}'");
if ($online == 1) {
@@ -263,7 +263,7 @@ foreach ($leases as $data) {
echo "<td class=\"listr\">{$fspans}{$data['act']}{$fspane}&nbsp;</td>\n";
if ($data['type'] == "dynamic") {
- echo "<td class=\"list\" valign=\"middle\"><a href=\"services_dhcp_edit.php?if={$data['if']}&mac={$data['mac']}&descr={$data['hostname']}\">";
+ echo "<td class=\"list\" valign=\"middle\"><a href=\"services_dhcp_edit.php?if={$data['if']}&mac={$data['mac']}&hostname={$data['hostname']}\">";
echo "<img src=\"/themes/{$g['theme']}/images/icons/icon_plus.gif\" width=\"17\" height=\"17\" border=\"0\" title=\"add a static mapping for this MAC address\"></a></td>\n";
} else {
echo "<td class=\"list\" valign=\"middle\">";
diff --git a/usr/local/www/services_dhcp.php b/usr/local/www/services_dhcp.php
index d3f70c4..6625d35 100755
--- a/usr/local/www/services_dhcp.php
+++ b/usr/local/www/services_dhcp.php
@@ -114,8 +114,9 @@ if ($_POST) {
if (($_POST['range_to'] && !is_ipaddr($_POST['range_to']))) {
$input_errors[] = "A valid range must be specified.";
}
- if (($_POST['gateway'] && !is_ipaddr($_POST['gateway'])))
+ if (($_POST['gateway'] && !is_ipaddr($_POST['gateway']))) {
$input_errors[] = "A valid IP address must be specified for the gateway.";
+ }
if (($_POST['wins1'] && !is_ipaddr($_POST['wins1'])) || ($_POST['wins2'] && !is_ipaddr($_POST['wins2']))) {
$input_errors[] = "A valid IP address must be specified for the primary/secondary WINS servers.";
}
@@ -146,12 +147,6 @@ if ($_POST) {
if (isset($config['dhcrelay'][$if]['enable']))
$input_errors[] = "You must disable the DHCP relay on the {$iflist[$if]} interface before enabling the DHCP server.";
}
-
- $retval = 0;
- config_lock();
- $retval = services_dhcpd_configure();
- config_unlock();
-
}
if (!$input_errors) {
@@ -173,29 +168,15 @@ if ($_POST) {
$config['dhcpd'][$if]['winsserver'][] = $_POST['wins2'];
unset($config['dhcpd'][$if]['dnsserver']);
-
if ($_POST['dns1'])
$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns1'];
if ($_POST['dns2'])
$config['dhcpd'][$if]['dnsserver'][] = $_POST['dns2'];
$config['dhcpd'][$if]['gateway'] = $_POST['gateway'];
-
- if($_POST['denyunknown'] == "yes")
- $config['dhcpd'][$if]['denyunknown'] = true;
- else
- unset($config['dhcpd'][$if]['denyunknown']);
-
- if($_POST['enable'] == "yes")
- $config['dhcpd'][$if]['enable'] = $_POST['enable'];
- else
- unset($config['dhcpd'][$if]['enable']);
-
- if($_POST['staticarp'] == "yes") {
- $config['dhcpd'][$if]['staticarp'] = true;
- } else {
- unset($config['dhcpd'][$if]['staticarp']);
- }
+ $config['dhcpd'][$if]['denyunknown'] = ($_POST['denyunknown']) ? true : false;
+ $config['dhcpd'][$if]['enable'] = ($_POST['enable']) ? true : false;
+ $config['dhcpd'][$if]['staticarp'] = ($_POST['staticarp']) ? true : false;
write_config();
@@ -203,9 +184,29 @@ if ($_POST) {
interfaces_staticarp_configure($if);
$retval = 0;
+ $retvaldhcp = 0;
+ $retvaldns = 0;
config_lock();
- $retval = services_dhcpd_configure();
+ /* dnsmasq_configure calls dhcpd_configure */
+ /* no need to restart dhcpd twice */
+ if (isset($config['dnsmasq']['regdhcpstatic'])) {
+ $retvaldns = services_dnsmasq_configure();
+ if ($retvaldns == 0) {
+ if (file_exists($d_hostsdirty_path))
+ unlink($d_hostsdirty_path);
+ if (file_exists($d_staticmapsdirty_path))
+ unlink($d_staticmapsdirty_path);
+ }
+ } else {
+ $retvaldhcp = services_dhcpd_configure();
+ if ($retvaldhcp == 0) {
+ if (file_exists($d_staticmapsdirty_path))
+ unlink($d_staticmapsdirty_path);
+ }
+ }
config_unlock();
+ if($retvaldhcp == 1 || $retvaldns == 1)
+ $retval = 1;
$savemsg = get_std_save_message($retval);
}
}
@@ -214,10 +215,11 @@ if ($_GET['act'] == "del") {
if ($a_maps[$_GET['id']]) {
unset($a_maps[$_GET['id']]);
write_config();
- $retval = 0;
- config_lock();
- $retval = services_dhcpd_configure();
- config_unlock();
+ if(isset($config['dhcpd'][$if]['enable'])) {
+ touch($d_staticmapsdirty_path);
+ if (isset($config['dnsmasq']['regdhcpstatic']))
+ touch($d_hostsdirty_path);
+ }
header("Location: services_dhcp.php?if={$if}");
exit;
}
@@ -438,9 +440,10 @@ function enable_change(enable_over) {
</table>
<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
- <td width="35%" class="listhdrr">MAC address</td>
- <td width="20%" class="listhdrr">IP address</td>
- <td width="35%" class="listhdr">Description</td>
+ <td width="25%" class="listhdrr">MAC address</td>
+ <td width="15%" class="listhdrr">IP address</td>
+ <td width="20%" class="listhdrr">Hostname</td>
+ <td width="30%" class="listhdr">Description</td>
<td width="10%" class="list">
</td>
</tr>
@@ -454,6 +457,9 @@ function enable_change(enable_over) {
<td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
<?=htmlspecialchars($mapent['ipaddr']);?>&nbsp;
</td>
+ <td class="listr" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
+ <?=htmlspecialchars($mapent['hostname']);?>&nbsp;
+ </td>
<td class="listbg" ondblclick="document.location='services_dhcp_edit.php?if=<?=$if;?>&id=<?=$i;?>';">
<font color="#FFFFFF"><?=htmlspecialchars($mapent['descr']);?>&nbsp;</font>
</td>
@@ -470,7 +476,7 @@ function enable_change(enable_over) {
<?php $i++; endforeach; ?>
<?php endif; ?>
<tr>
- <td class="list" colspan="3"></td>
+ <td class="list" colspan="4"></td>
<td class="list">
<table border="0" cellspacing="0" cellpadding="1">
<tr>
diff --git a/usr/local/www/services_dhcp_edit.php b/usr/local/www/services_dhcp_edit.php
index e3c1a2f..238456f 100755
--- a/usr/local/www/services_dhcp_edit.php
+++ b/usr/local/www/services_dhcp_edit.php
@@ -53,10 +53,12 @@ if (isset($_POST['id']))
if (isset($id) && $a_maps[$id]) {
$pconfig['mac'] = $a_maps[$id]['mac'];
+ $pconfig['hostname'] = $a_maps[$id]['hostname'];
$pconfig['ipaddr'] = $a_maps[$id]['ipaddr'];
$pconfig['descr'] = $a_maps[$id]['descr'];
} else {
$pconfig['mac'] = $_GET['mac'];
+ $pconfig['hostname'] = $_GET['hostname'];
$pconfig['descr'] = $_GET['descr'];
}
@@ -74,6 +76,9 @@ if ($_POST) {
/* normalize MAC addresses - lowercase and convert Windows-ized hyphenated MACs to colon delimited */
$_POST['mac'] = strtolower(str_replace("-", ":", $_POST['mac']));
+ if (($_POST['host'] && !is_hostname($_POST['host']))) {
+ $input_errors[] = "A valid host name must be specified.";
+ }
if (($_POST['ipaddr'] && !is_ipaddr($_POST['ipaddr']))) {
$input_errors[] = "A valid IP address must be specified.";
}
@@ -86,8 +91,8 @@ if ($_POST) {
if (isset($id) && ($a_maps[$id]) && ($a_maps[$id] === $mapent))
continue;
- if (($mapent['mac'] == $_POST['mac']) || ($_POST['ipaddr'] && (ip2long($mapent['ipaddr']) == ip2long($_POST['ipaddr'])))) {
- $input_errors[] = "This IP or MAC address already exists.";
+ if (($mapent['hostname'] == $_POST['hostname']) || ($mapent['mac'] == $_POST['mac']) || ($_POST['ipaddr'] && (ip2long($mapent['ipaddr']) == ip2long($_POST['ipaddr'])))) {
+ $input_errors[] = "This Hostname, IP or MAC address already exists.";
break;
}
}
@@ -113,6 +118,7 @@ if ($_POST) {
$mapent = array();
$mapent['mac'] = $_POST['mac'];
$mapent['ipaddr'] = $_POST['ipaddr'];
+ $mapent['hostname'] = $_POST['hostname'];
$mapent['descr'] = $_POST['descr'];
if (isset($id) && $a_maps[$id])
@@ -122,15 +128,11 @@ if ($_POST) {
write_config();
- if (isset($config['dhcpd'][$if]['staticarp']))
- interfaces_staticarp_configure($if);
-
- $retval = 0;
- config_lock();
- $retval = services_dhcpd_configure();
- config_unlock();
-
- $savemsg = get_std_save_message($retval);
+ if(isset($config['dhcpd'][$if]['enable'])) {
+ touch($d_staticmapsdirty_path);
+ if (isset($config['dnsmasq']['regdhcpstatic']))
+ touch($d_hostsdirty_path);
+ }
header("Location: services_dhcp.php?if={$if}");
exit;
@@ -170,6 +172,12 @@ include("head.inc");
If no IP address is given, one will be dynamically allocated from the pool.</td>
</tr>
<tr>
+ <td width="22%" valign="top" class="vncell">Hostname</td>
+ <td width="78%" class="vtable">
+ <input name="hostname" type="text" class="formfld" id="hostname" size="20" value="<?=htmlspecialchars($pconfig['hostname']);?>">
+ <br> <span class="vexpl">Name of the host, without domain part.</span></td>
+ </tr>
+ <tr>
<td width="22%" valign="top" class="vncell">Description</td>
<td width="78%" class="vtable">
<input name="descr" type="text" class="formfld" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>">
diff --git a/usr/local/www/services_dnsmasq.php b/usr/local/www/services_dnsmasq.php
index 841560e..9c6ab8f 100755
--- a/usr/local/www/services_dnsmasq.php
+++ b/usr/local/www/services_dnsmasq.php
@@ -33,6 +33,7 @@ require("guiconfig.inc");
$pconfig['enable'] = isset($config['dnsmasq']['enable']);
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
+$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']);
if (!is_array($config['dnsmasq']['hosts']))
$config['dnsmasq']['hosts'] = array();
@@ -51,6 +52,7 @@ if ($_POST) {
$config['dnsmasq']['enable'] = ($_POST['enable']) ? true : false;
$config['dnsmasq']['regdhcp'] = ($_POST['regdhcp']) ? true : false;
+ $config['dnsmasq']['regdhcpstatic'] = ($_POST['regdhcpstatic']) ? true : false;
write_config();
@@ -94,10 +96,21 @@ include("head.inc");
?>
+<script language="JavaScript">
+<!--
+function enable_change(enable_over) {
+ var endis;
+ endis = !(document.iform.enable.checked || enable_over);
+ document.iform.regdhcp.disabled = endis;
+ document.iform.regdhcpstatic.disabled = endis;
+}
+//-->
+</script>
+
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
<?php include("fbegin.inc"); ?>
<p class="pgtitle"><?=$pgtitle?></p>
-<form action="services_dnsmasq.php" method="post">
+<form action="services_dnsmasq.php" method="post" name="iform" id="iform">
<?php if ($savemsg) print_info_box($savemsg); ?>
<?php if (file_exists($d_hostsdirty_path)): ?><p>
<?php print_info_box_np("The DNS forwarder configuration has been changed.<br>You must apply the changes in order for them to take effect.");?><br>
@@ -105,7 +118,7 @@ include("head.inc");
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr>
<td class="vtable"><p>
- <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?>>
+ <input name="enable" type="checkbox" id="enable" value="yes" <?php if ($pconfig['enable'] == "yes") echo "checked";?> onClick="enable_change(false)">
<strong>Enable DNS forwarder<br>
</strong></p></td>
</tr>
@@ -121,7 +134,17 @@ include("head.inc");
</td>
</tr>
<tr>
- <td> <input name="submit" type="submit" class="formbtn" value="Save">
+ <td class="vtable"><p>
+ <input name="regdhcpstatic" type="checkbox" id="regdhcpstatic" value="yes" <?php if ($pconfig['regdhcpstatic'] == "yes") echo "checked";?>>
+ <strong>Register DHCP static mappings in DNS forwarder<br>
+ </strong>If this option is set, then DHCP static mappings will
+ be registered in the DNS forwarder, so that their name can be
+ resolved. You should also set the domain in <a href="system.php">
+ System: General setup</a> to the proper value.</p>
+ </td>
+ </tr>
+ <tr>
+ <td> <input name="submit" type="submit" class="formbtn" value="Save" onclick="enable_change(true)">
</td>
</tr>
<tr>
@@ -221,6 +244,11 @@ include("head.inc");
</tr>
</table>
</form>
+<script language="JavaScript">
+<!--
+enable_change(false);
+//-->
+</script>
<?php include("fend.inc"); ?>
</body>
</html>
OpenPOWER on IntegriCloud