summaryrefslogtreecommitdiffstats
path: root/src/etc
diff options
context:
space:
mode:
authorRenato Botelho <renato@netgate.com>2017-01-11 13:59:21 -0200
committerRenato Botelho <renato@netgate.com>2017-01-11 14:46:33 -0200
commit470efdfcb469d71f731831b0601426b1bcfaf619 (patch)
tree13abf0e07554ea27dfc9a5196d98dec3f36feb5e /src/etc
parent881ebd59520f6140546a45fd3fa21b62eb09f037 (diff)
downloadpfsense-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.inc74
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'];
OpenPOWER on IntegriCloud