mirror of
https://github.com/pfsense/pfsense.git
synced 2025-10-26 11:38:35 +00:00
Add Unbound read function for /etc/hosts
This commit is contained in:
parent
f226576695
commit
4f9de9b540
@ -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;
|
||||
}
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user