From 116aa4473d36ef7a422c0020b3f4808878b50752 Mon Sep 17 00:00:00 2001 From: Olav Morken <olav.morken@uninett.no> Date: Tue, 15 Sep 2009 08:30:55 +0000 Subject: [PATCH] ldapstatus: Do a connect-test to all ip-addresses for a hostname. git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1756 44740490-163a-0410-bde0-09ae8108e29a --- modules/ldapstatus/lib/Tester.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/modules/ldapstatus/lib/Tester.php b/modules/ldapstatus/lib/Tester.php index 85f568f85..5096c233a 100644 --- a/modules/ldapstatus/lib/Tester.php +++ b/modules/ldapstatus/lib/Tester.php @@ -96,14 +96,25 @@ class sspmod_ldapstatus_Tester { return array(FALSE, 'No IP address found for host ' . $host . '.'); } - $timeout = 1.0; - $socket = @fsockopen($host, $port, $errno, $errstr, $timeout); - if ($socket) @fclose($socket); - if ($errno) { - return array(FALSE, $errno . ':' . $errstr . ' [' . $host . ':' . $port . ']'); - } else { - return array(TRUE,''); + $errors = array(); + foreach ($ips as $ip) { + $timeout = 1.0; + $socket = @fsockopen($ip, $port, $errno, $errstr, $timeout); + if ($errno) { + $errors[] = $errno . ':' . $errstr . ' (' . $host . '[' . $ip . ']:' . $port . ')'; + } elseif ($socket === FALSE) { + $errors[] = '[Unknown error, check log] (' . $host . '[' . $ip . ']:' . $port . ')'; + } else { + @fclose($socket); + } + } + + if (count($errors) === 0) { + return array(TRUE, count($ips) . ' LDAP servers working.'); } + + $error = count($errors) . ' of ' . count($ips) . ' failed: '. implode(';', $errors); + return array(FALSE, $error); } -- GitLab