From 4f9de9b540b35c1c66f6eae6ebdab8a43d7d2bad Mon Sep 17 00:00:00 2001 From: Warren Baker Date: Sat, 1 Oct 2011 22:06:33 +0200 Subject: [PATCH] Add Unbound read function for /etc/hosts --- etc/inc/unbound.inc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/etc/inc/unbound.inc b/etc/inc/unbound.inc index 3b9016ba40..3fcaa4608e 100644 --- a/etc/inc/unbound.inc +++ b/etc/inc/unbound.inc @@ -439,4 +439,27 @@ function unbound_add_host_entries() { file_put_contents("{$g['unbound_chroot_path']}/etc/host_entries.conf", $unbound_entries); } +/* Read /etc/hosts */ +function read_hosts() { + + // Open /etc/hosts and extract the only dhcpleases info + $etc_hosts = array(); + foreach (file('/etc/hosts') as $line) { + $d = preg_split('/\s/', $line, -1, PREG_SPLIT_NO_EMPTY); + if (empty($d) || substr(reset($d), 0, 1) == "#") + continue; + if ($d[3] == "#") { + $ip = array_shift($d); + $fqdn = array_shift($d); + $name = array_shift($d); + if ($fqdn != "empty") { + if ($name != "empty") + array_push($etc_hosts, array(ipaddr => "$ip", fqdn => "$fqdn", name => "$name")); + else + array_push($etc_hosts, array(ipaddr => "$ip", fqdn => "$fqdn")); + } + } + } + return $etc_hosts; +} ?> \ No newline at end of file