Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unbound - allow TTL on host overrides. Fixes: #7597 #7616

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/etc/inc/plugins.inc.d/unbound.inc
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,11 @@ function unbound_add_host_entries($ifconfig_details)
}
}

if (empty($host->ttl))
$ttl = 3600;
else
$ttl = $host->ttl;

foreach ($tmp_aliases as $alias) {
$override_is_main = $alias === $tmp_aliases[0];

Expand All @@ -563,7 +568,7 @@ function unbound_add_host_entries($ifconfig_details)
/* Handle wildcard entries which have "*" as a hostname. Since we added a . above, we match on "*.". */
if ($alias['hostname'] == '*.') {
$unbound_entries .= "local-zone: \"{$alias['domain']}\" redirect\n";
$unbound_entries .= "local-data: \"{$alias['domain']} IN {$host->rr} {$host->server}\"\n";
$unbound_entries .= "local-data: \"{$alias['domain']} $ttl IN {$host->rr} {$host->server}\"\n";
} else {
if (($override_is_main || $tmp_aliases[0]['hostname'] === '*') && !in_array($host->server, $ptr_records, true)) {
/* Only generate a PTR record for the non-alias override and only if the IP is not already associated with a PTR.
Expand All @@ -574,11 +579,11 @@ function unbound_add_host_entries($ifconfig_details)
} else {
syslog(LOG_WARNING, 'PTR record already exists for ' . $alias['hostname'] . $alias['domain'] . '(' . $host->server . ')');
}
$unbound_entries .= "local-data: \"{$alias['hostname']}{$alias['domain']} IN {$host->rr} {$host->server}\"\n";
$unbound_entries .= "local-data: \"{$alias['hostname']}{$alias['domain']} $ttl IN {$host->rr} {$host->server}\"\n";
}
break;
case 'MX':
$unbound_entries .= "local-data: \"{$alias['hostname']}{$alias['domain']} IN MX {$host->mxprio} {$host->mx}\"\n";
$unbound_entries .= "local-data: \"{$alias['hostname']}{$alias['domain']} $ttl IN MX {$host->mxprio} {$host->mx}\"\n";
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function searchHostOverrideAction()
{
return $this->searchBase(
'hosts.host',
['enabled', 'hostname', 'domain', 'rr', 'mxprio', 'mx', 'server', 'description'],
['enabled', 'hostname', 'domain', 'rr', 'mxprio', 'mx', 'server', 'ttl', 'description'],
'hostname',
null,
SORT_NATURAL | SORT_FLAG_CASE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<type>text</type>
<help>Host name of MX host, e.g. mail.example.com</help>
</field>
<field>
<id>host.ttl</id>
<label>TTL</label>
<type>text</type>
<help>TTL of the host, e.g. 3600</help>
</field>
<field>
<id>host.server</id>
<label>IP address</label>
Expand Down
3 changes: 3 additions & 0 deletions src/opnsense/mvc/app/models/OPNsense/Unbound/Unbound.xml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@
<Mask>/^(?:(?:[a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])\.)*(?:[a-z0-9]|[a-z0-9][a-z0-9\-]*[a-z0-9])$/i</Mask>
<ValidationMessage>A valid domain must be specified.</ValidationMessage>
</domain>
<ttl type="IntegerField">
<Required>N</Required>
</ttl>
<rr type="OptionField">
<Required>Y</Required>
<Default>A</Default>
Expand Down
1 change: 1 addition & 0 deletions src/opnsense/mvc/app/views/OPNsense/Unbound/overrides.volt
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ $( document ).ready(function() {
<th data-column-id="domain" data-type="string">{{ lang._('Domain') }}</th>
<th data-column-id="rr" data-type="string">{{ lang._('Type') }}</th>
<th data-column-id="server" data-type="string" data-formatter="mxformatter">{{ lang._('Value') }}</th>
<th data-column-id="ttl" data-type="string">{{ lang._('TTL') }}</th>
<th data-column-id="description" data-type="string">{{ lang._('Description') }}</th>
<th data-column-id="commands" data-width="7em" data-formatter="commands" data-sortable="false">{{ lang._('Edit') }} | {{ lang._('Delete') }}</th>
</tr>
Expand Down