Commit 2ca72533 authored by Franco Fichtner's avatar Franco Fichtner

dnsmasq: domain override for dynamic dhcp lease registration

PR: https://github.com/opnsense/core/issues/1250
parent 24c86337
...@@ -273,6 +273,9 @@ function dnsmasq_hosts_generate() ...@@ -273,6 +273,9 @@ function dnsmasq_hosts_generate()
if (isset($config['dnsmasq']['regdhcp']) && file_exists($leases)) { if (isset($config['dnsmasq']['regdhcp']) && file_exists($leases)) {
$domain = $config['system']['domain']; $domain = $config['system']['domain'];
if (isset($config['dnsmasq']['regdhcpdomain'])) {
$domain = $config['dnsmasq']['regdhcpdomain'];
}
mwexecf( mwexecf(
'/usr/local/sbin/dhcpleases -l %s -d %s -p %s -h %s', '/usr/local/sbin/dhcpleases -l %s -d %s -p %s -h %s',
array($leases, $domain, '/var/run/dnsmasq.pid', '/var/etc/dnsmasq-hosts') array($leases, $domain, '/var/run/dnsmasq.pid', '/var/etc/dnsmasq-hosts')
......
...@@ -46,6 +46,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -46,6 +46,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
// booleans // booleans
$pconfig['enable'] = isset($config['dnsmasq']['enable']); $pconfig['enable'] = isset($config['dnsmasq']['enable']);
$pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']); $pconfig['regdhcp'] = isset($config['dnsmasq']['regdhcp']);
$pconfig['regdhcpdomain'] = !empty($config['dnsmasq']['regdhcpdomain']) ? $config['dnsmasq']['regdhcpdomain'] : null;
$pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']); $pconfig['regdhcpstatic'] = isset($config['dnsmasq']['regdhcpstatic']);
$pconfig['dhcpfirst'] = isset($config['dnsmasq']['dhcpfirst']); $pconfig['dhcpfirst'] = isset($config['dnsmasq']['dhcpfirst']);
$pconfig['strict_order'] = isset($config['dnsmasq']['strict_order']); $pconfig['strict_order'] = isset($config['dnsmasq']['strict_order']);
...@@ -63,6 +64,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -63,6 +64,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$input_errors = array(); $input_errors = array();
if (isset($pconfig['submit'])) { if (isset($pconfig['submit'])) {
// validate // validate
if (!empty($pconfig['regdhcpdomain']) && !is_domain($pconfig['regdhcpdomain'])) {
$input_errors[] = gettext("The domain may only contain the characters a-z, 0-9, '-' and '.'.");
}
if (!empty($pconfig['port']) && !is_port($pconfig['port'])) { if (!empty($pconfig['port']) && !is_port($pconfig['port'])) {
$input_errors[] = gettext("You must specify a valid port number"); $input_errors[] = gettext("You must specify a valid port number");
} }
...@@ -91,9 +95,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') { ...@@ -91,9 +95,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$config['dnsmasq']['domain_needed'] = !empty($pconfig['domain_needed']); $config['dnsmasq']['domain_needed'] = !empty($pconfig['domain_needed']);
$config['dnsmasq']['no_private_reverse'] = !empty($pconfig['no_private_reverse']); $config['dnsmasq']['no_private_reverse'] = !empty($pconfig['no_private_reverse']);
$config['dnsmasq']['strictbind'] = !empty($pconfig['strictbind']); $config['dnsmasq']['strictbind'] = !empty($pconfig['strictbind']);
if (!empty($pconfig['regdhcpdomain'])) {
$config['dnsmasq']['regdhcpdomain'] = $pconfig['regdhcpdomain'];
} elseif (isset($config['dnsmasq']['regdhcpdomain'])) {
unset($config['dnsmasq']['regdhcpdomain']);
}
if (!empty($pconfig['interface'])) { if (!empty($pconfig['interface'])) {
$config['dnsmasq']['interface'] = implode(",", $pconfig['interface']); $config['dnsmasq']['interface'] = implode(",", $pconfig['interface']);
} elseif (isset($config['dnsmasq']['interface'])) { } elseif (isset($config['dnsmasq']['interface'])) {
unset($config['dnsmasq']['interface']); unset($config['dnsmasq']['interface']);
} }
if (!empty($pconfig['port'])) { if (!empty($pconfig['port'])) {
...@@ -244,11 +253,21 @@ $( document ).ready(function() { ...@@ -244,11 +253,21 @@ $( document ).ready(function() {
<input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?=!empty($pconfig['regdhcp']) ? "checked=\"checked\"" : "";?> /> <input name="regdhcp" type="checkbox" id="regdhcp" value="yes" <?=!empty($pconfig['regdhcp']) ? "checked=\"checked\"" : "";?> />
<strong><?=gettext("Register DHCP leases in DNS forwarder");?></strong> <strong><?=gettext("Register DHCP leases in DNS forwarder");?></strong>
<div class="hidden" for="help_for_regdhcp"> <div class="hidden" for="help_for_regdhcp">
<?= sprintf(gettext("If this option is set, then machines that specify". <?= gettext("If this option is set, then machines that specify " .
" their hostname when requesting a DHCP lease will be registered". "their hostname when requesting a DHCP lease will be registered " .
" in the DNS forwarder, so that their name can be resolved.". "in the DNS forwarder, so that their name can be resolved.") ?>
" You should also set the domain in %sSystem:". </div>
" General setup%s to the proper value."),'<a href="system_general.php">','</a>')?> </td>
</tr>
<tr>
<td><a id="help_for_regdhcpdomain" href="#" class="showhelp"><i class="fa fa-info-circle"></i></a> <?=gettext("DHCP Domain Override");?></td>
<td>
<input name="regdhcpdomain" type="text" id="regdhcpdomain" value="<?= $pconfig['regdhcpdomain'] ?>"/>
<div class="hidden" for="help_for_regdhcpdomain">
<?= gettext("The domain name to use for DHCP hostname registration. " .
"If empty, the default system domain is used. Note that all DHCP " .
"leases will be assigned to the same domain. If this is undesired, " .
"static DHCP lease registration is able to provide coherent mappings.") ?>
</div> </div>
</td> </td>
</tr> </tr>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment