From 0057e62d240d5e41f1f5d5a53328bc9ace92f34d Mon Sep 17 00:00:00 2001 From: Chris Buechler Date: Mon, 3 Aug 2015 23:10:26 -0500 Subject: only read file if it exists, and only foreach if an array. --- etc/inc/pfsense-utils.inc | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/etc/inc/pfsense-utils.inc b/etc/inc/pfsense-utils.inc index 93719ad..2d42ecb 100644 --- a/etc/inc/pfsense-utils.inc +++ b/etc/inc/pfsense-utils.inc @@ -127,20 +127,24 @@ function get_tmp_file() { /****f* pfsense-utils/get_dns_servers * NAME - * get_dns_servres - get system dns servers + * get_dns_servers - get system dns servers * INPUTS - * $dns_servers - an array of the dns servers + * none * RESULT - * null + * $dns_servers - an array of the dns servers ******/ function get_dns_servers() { $dns_servers = array(); - $dns_s = file("/etc/resolv.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); - foreach ($dns_s as $dns) { - $matches = ""; - if (preg_match("/nameserver (.*)/", $dns, $matches)) { - $dns_servers[] = $matches[1]; - } + if (file_exists("/etc/resolv.conf")) { + $dns_s = file("/etc/resolv.conf", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); + } + if (is_array($dns_s)) { + foreach ($dns_s as $dns) { + $matches = ""; + if (preg_match("/nameserver (.*)/", $dns, $matches)) { + $dns_servers[] = $matches[1]; + } + } } return array_unique($dns_servers); } -- cgit v1.1