diff options
author | Chris Buechler <cmb@pfsense.org> | 2015-08-03 23:10:26 -0500 |
---|---|---|
committer | Chris Buechler <cmb@pfsense.org> | 2015-08-03 23:10:26 -0500 |
commit | 0057e62d240d5e41f1f5d5a53328bc9ace92f34d (patch) | |
tree | d3486aeaec5dace4d3558c72b10e59cbd72385bf | |
parent | 626f10a30c38bdb14e557a33f9fbbd01d4dde992 (diff) | |
download | pfsense-0057e62d240d5e41f1f5d5a53328bc9ace92f34d.zip pfsense-0057e62d240d5e41f1f5d5a53328bc9ace92f34d.tar.gz |
only read file if it exists, and only foreach if an array.
-rw-r--r-- | etc/inc/pfsense-utils.inc | 22 |
1 files 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); } |