diff --git a/library/Icinga/Protocol/Dns.php b/library/Icinga/Protocol/Dns.php new file mode 100644 index 000000000..b2807ac5d --- /dev/null +++ b/library/Icinga/Protocol/Dns.php @@ -0,0 +1,114 @@ + + * @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2 + * @author Icinga Development Team + * + */ +// {{{ICINGA_LICENSE_HEADER}}} + +namespace Icinga\Protocol; + +/** + * Discover dns records using regular or reverse lookup + */ +class Dns { + + /** + * Get all ldap records for the given domain + * + * @param String $query The domain to query + * + * @return array An array of entries + */ + public static function ldapRecords($query) + { + $ldaps_records = dns_get_record('_ldaps._tcp.' . $query); + $ldap_records = dns_get_record('_ldap._tcp.' . $query); + return array_merge($ldaps_records, $ldap_records); + } + + /** + * Get all ldap records for the given domain + * + * @param String $query The domain to query + * @param int $type The type of DNS-entry to fetch, see http://www.php.net/manual/de/function.dns-get-record.php + * for available types + * + * @return array|Boolean An array of entries + */ + public static function records($query, $type = DNS_ANY) + { + return dns_get_record($query, $type); + } + + /** + * Reverse lookup all hostname on the given ip address + * + * @param $ipAddress + * @param int $type + * + * @return array|Boolean + */ + public static function ptr($ipAddress, $type = DNS_ANY) + { + $host = gethostbyaddr($ipAddress); + if ($host === false || $host === $ipAddress) { + // malformed input or no host found + return false; + } + return self::records($host, $type); + } + + /** + * Get the IPv4 address of the given hostname. + * + * @param $hostname The hostname to resolve + * + * @return String|Boolean The IPv4 address of the given hostname, or false when no entry exists. + */ + public static function ipv4($hostname) + { + $records = dns_get_record($hostname, DNS_A); + if ($records !== false && sizeof($records) > 0) { + return $records[0]['ip']; + } + return false; + } + + /** + * Get the IPv6 address of the given hostname. + * + * @param $hostname The hostname to resolve + * + * @return String|Boolean The IPv6 address of the given hostname, or false when no entry exists. + */ + public static function ipv6($hostname) + { + $records = dns_get_record($hostname, DNS_AAAA); + if ($records !== false && sizeof($records) > 0) { + return $records[0]['ip']; + } + return false; + } +} \ No newline at end of file diff --git a/library/Icinga/Protocol/Ldap/Connection.php b/library/Icinga/Protocol/Ldap/Connection.php index 13ae19fd9..54cc05f53 100644 --- a/library/Icinga/Protocol/Ldap/Connection.php +++ b/library/Icinga/Protocol/Ldap/Connection.php @@ -353,12 +353,6 @@ class Connection return $dir; } - protected function discoverServerlistForDomain($domain) - { - $ldaps_records = dns_get_record('_ldaps._tcp.' . $domain, DNS_SRV); - $ldap_records = dns_get_record('_ldap._tcp.' . $domain, DNS_SRV); - } - protected function prepareNewConnection() { $use_tls = false;