diff options
author | Renato Botelho <renato@netgate.com> | 2017-01-11 13:59:21 -0200 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2017-01-11 14:46:33 -0200 |
commit | 470efdfcb469d71f731831b0601426b1bcfaf619 (patch) | |
tree | 13abf0e07554ea27dfc9a5196d98dec3f36feb5e /src/etc | |
parent | 881ebd59520f6140546a45fd3fa21b62eb09f037 (diff) | |
download | pfsense-470efdfcb469d71f731831b0601426b1bcfaf619.zip pfsense-470efdfcb469d71f731831b0601426b1bcfaf619.tar.gz |
Ticket #6712: Create system_hosts_override_entries()
This function will return an array with dnsmasq or unbound items to be added to
/etc/hosts
Diffstat (limited to 'src/etc')
-rw-r--r-- | src/etc/inc/system.inc | 74 |
1 files changed, 51 insertions, 23 deletions
diff --git a/src/etc/inc/system.inc b/src/etc/inc/system.inc index 14b390c..a137bd5 100644 --- a/src/etc/inc/system.inc +++ b/src/etc/inc/system.inc @@ -382,6 +382,52 @@ function system_hosts_local_entries() { return $hosts; } +/* Read host override entries from dnsmasq or unbound */ +function system_hosts_override_entries($dnscfg) { + $hosts = array(); + + if (!is_array($dnscfg) || !isset($dnscfg['enable'])) { + return $hosts; + } + + if (!is_array($dnscfg['hosts'])) { + $dnscfg['hosts'] = array(); + } + + foreach ($dnscfg['hosts'] as $host) { + $fqdn = ''; + if ($host['host'] || $host['host'] == "0") { + $fqdn .= "{$host['host']}."; + } + $fqdn .= $host['domain']; + + $hosts[] = array( + 'ipaddr' => $host['ip'], + 'fqdn' => $fqdn + ); + + if (!is_array($host['aliases']) || + !is_array($host['aliases']['item'])) { + continue; + } + + foreach ($host['aliases']['item'] as $alias) { + $fqdn = ''; + if ($alias['host'] || $alias['host'] == "0") { + $fqdn .= "{$alias['host']}."; + } + $fqdn .= $alias['domain']; + + $hosts[] = array( + 'ipaddr' => $host['ip'], + 'fqdn' => $fqdn + ); + } + } + + return $hosts; +} + function system_hosts_generate() { global $config, $g; if (isset($config['system']['developerspew'])) { @@ -410,32 +456,14 @@ function system_hosts_generate() { } $hosts .= "\n"; } + unset($hosts_array); if (isset($dnsmasqcfg['enable'])) { - if (!is_array($dnsmasqcfg['hosts'])) { - $dnsmasqcfg['hosts'] = array(); - } - - foreach ($dnsmasqcfg['hosts'] as $host) { - $lhosts .= "{$host['ip']}\t"; - if ($host['host'] || $host['host'] == "0") { - $lhosts .= "{$host['host']}."; - } - $lhosts .= "{$host['domain']}\n"; - - if (!is_array($host['aliases']) || - !is_array($host['aliases']['item'])) { - continue; - } - - foreach ($host['aliases']['item'] as $alias) { - $lhosts .= "{$host['ip']}\t"; - if ($alias['host'] || $alias['host'] == "0") { - $lhosts .= "{$alias['host']}."; - } - $lhosts .= "{$alias['domain']}\n"; - } + $hosts_array = system_hosts_override_entries($dnsmasqcfg); + foreach ($hosts_array as $host) { + $lhosts .= "{$host['ipaddr']}\t{$host['fqdn']}\n"; } + unset($hosts_array); if (is_array($config['dhcpd'])) { $conf_dhcpd = $config['dhcpd']; |