diff options
author | Renato Botelho <renato@netgate.com> | 2015-07-27 15:23:32 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2015-07-27 15:23:32 -0300 |
commit | 58cbb8282ac44aeaaa1ba2aaa06d2c74d3e774f6 (patch) | |
tree | 6f66031118ce4e22cc73c43c9d0ae0f5ce54ba29 /config/haproxy1_5/pkg/haproxy_utils.inc | |
parent | f405fcb345686c536b7ac78bdfbe9d93e6aa3a47 (diff) | |
parent | 6479eab976d425ae2f8d3eb988a4f79d701001a5 (diff) | |
download | pfsense-packages-58cbb8282ac44aeaaa1ba2aaa06d2c74d3e774f6.tar.gz pfsense-packages-58cbb8282ac44aeaaa1ba2aaa06d2c74d3e774f6.tar.bz2 pfsense-packages-58cbb8282ac44aeaaa1ba2aaa06d2c74d3e774f6.zip |
Merge pull request #902 from PiBa-NL/haproxy_v0_27
Diffstat (limited to 'config/haproxy1_5/pkg/haproxy_utils.inc')
-rw-r--r-- | config/haproxy1_5/pkg/haproxy_utils.inc | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/config/haproxy1_5/pkg/haproxy_utils.inc b/config/haproxy1_5/pkg/haproxy_utils.inc index d8c4faf4..ec72b986 100644 --- a/config/haproxy1_5/pkg/haproxy_utils.inc +++ b/config/haproxy1_5/pkg/haproxy_utils.inc @@ -36,24 +36,38 @@ require_once("config.inc"); class haproxy_utils { public static $pf_version; - public function query_dns($host, $querytype="A,AAAA", $dnsserver = "127.0.0.1") { + public function query_dns($host, $querytype="A,AAAA") { $result = array(); - $host = trim($host, " \t\n\r\0\x0B[];\"'"); - $host_esc = escapeshellarg($host); $types = explode(',',$querytype); + $recordtype = 0; foreach($types as $type){ - $resolved = gethostbyname($host); - if($resolved) { - $resolved = array(); - if (haproxy_utils::$pf_version < '2.2') - exec("/usr/bin/dig {$host_esc} $type @$dnsserver | /usr/bin/grep {$host_esc} | /usr/bin/grep -v ';' | /usr/bin/awk '{ print $5 }'", $resolved); - else - exec("/usr/bin/drill {$host_esc} $type @$dnsserver | /usr/bin/grep {$host_esc} | /usr/bin/grep -v ';' | /usr/bin/awk '{ print $5 }'", $resolved); - foreach($resolved as $item) { - $newitem = array(); - $newitem["typeid"] = $type; - $newitem["data"] = $item; - $result[] = $newitem; + switch ($type) { + case 'A': + $recordtype = DNS_A; + break; + case 'AAAA': + $recordtype = DNS_AAAA; + break; + } + if ($recordtype != 0) { + //query one type at a time, querying multiple types in one call dns_get_record fails if one is not present.. + $errreporting = error_reporting(); + error_reporting($errreporting & ~E_WARNING);// dns_get_record throws a warning if nothing is resolved.. + $dnsresult = dns_get_record($host, $recordtype); + error_reporting($errreporting); + if (is_array($dnsresult)) { + foreach($dnsresult as $item) { + $newitem["typeid"] = $item['type']; + switch ($item['type']) { + case 'A': + $newitem["data"] = $item['ip']; + break; + case 'AAAA': + $newitem["data"] = $item['ipv6']; + break; + } + $result[] = $newitem; + } } } } |