diff --git a/modules/ldapstatus/lib/Auth/Backend/Test/StandardLDAPTest.php b/modules/ldapstatus/lib/Auth/Backend/Test/StandardLDAPTest.php new file mode 100755 index 0000000000000000000000000000000000000000..27c397275e99f40887fbadd71160bb39ae2638eb --- /dev/null +++ b/modules/ldapstatus/lib/Auth/Backend/Test/StandardLDAPTest.php @@ -0,0 +1,201 @@ +<?php + +/** + * The standard Feide LDAP backend implementation. + * + * @author Andreas Ă…kre Solberg <andreas.solberg@uninett.no>, UNINETT AS + * @package simpleSAMLphp + * @version $Id$ + */ +class sspmod_ldapstatus_Auth_Backend_Test_StandardLDAPTest extends sspmod_feide_Auth_Backend_StandardLDAP { + + + private $orgmeta = NULL; + + /** + * @param $location Must be of class Configuration.. + */ + public function __construct ($location, $orgmeta) { + parent::__construct($location); + $this->orgmeta = $orgmeta; + } + + + /** + * Perform a test of the LDAP. Used by the LDAP status page. + */ + public function test() { + + + + $result = array(); + + $tester = new sspmod_ldapstatus_Tester($this->location); + $orgtester = new sspmod_ldapstatus_Tester($this->orgmeta); + $tester->tick('all'); + + $tester->log('Testing config'); + $result['config'] = $tester->checkConfig(array('searchbase', 'hostname')); + + $tester->log('Testing config meta'); + $result['configMeta'] = $orgtester->checkConfig(array('description', array('contactMail', 'contactURL'))); + + $tester->log('Testing config testuser'); + $result['configTest'] = $tester->checkConfig(array('testUser', 'testPassword')); + + if (!$result['config'][0]) { + $tester->log('Skipping because of no configuration'); + $result['time'] = $tester->tack('all', FALSE); + return $result; + } + + /* + $this->log($this->checkParameter($this->orgconfig, 'adminUser')); + $this->log($this->checkParameter($this->orgconfig, 'adminPassword')); + $this->log($this->checkParameter($this->orgconfig, 'testUser')); + $this->log($this->checkParameter($this->orgconfig, 'testPassword')); + */ + $hostname = $this->location->getValue('hostname'); + $urldef = explode(' ', $hostname); + $url = parse_url($urldef[0]); + $port = 389; + if (!empty($url['scheme']) && $url['scheme'] === 'ldaps') $port = 636; + if (!empty($url['port'])) $port = $url['port']; + + $tester->log('ldapstatus Url parse [' . $hostname . '] => [' . $url['host'] . ']:[' . $port . ']' ); + + + $tester->tick('ping'); + $result['ping'] = $tester->phpping($url['host'], $port); + $result['ping'][1] .= $tester->tack('ping'); + + # echo('<pre>'); print_r($result); exit; + + if (!$result['ping'][0]) { + $result['time'] = $tester->tack('all', FALSE); + $tester->log('Skipping because of no ping'); + return $result; + } + + + // LDAP Connect + try { + $tester->tick('connect'); + // Connect to LDAP. + SimpleSAML_Logger::debug('AUTH - ldap-feide: Attempting location: ' . + $this->location->getValue('hostname') . '/' . $this->location->getValue('searchbase')); + + $hostname = $this->location->getString('hostname'); + $enableTLS = $this->location->getBoolean('enable_tls', FALSE); + $debugLDAP = $this->location->getBoolean('debugLDAP', FALSE); + $timeout = $this->location->getValue('timeout', 30); + + $this->ldap = new SimpleSAML_Auth_LDAP($hostname, $enableTLS, $debugLDAP, $timeout); + + $result['connect'] = array(TRUE,$tester->tack('connect')); + + } catch (Exception $e) { + $tester->log('ldapstatus: Connect error() [' .$hostname . ']: ' . $e->getMessage()); + $result['connect'] = array(FALSE,$e->getMessage()); + $result['time'] = $tester->tack('all', FALSE); + return $result; + } + + + // Do an admin bind before searching? + if ($this->location->hasValue('adminUser')) { + try { + $tester->tick('adminBind'); + + $this->adminBind($this->location->hasValue('adminUser'), $this->location->hasValue('adminPassword')); + $result['adminBind'] = array(TRUE,$tester->tack('connect')); + + } catch (Exception $e) { + $tester->log('ldapstatus: Connect error() [' . $hostname . ']: ' . $e->getMessage()); + $result['adminBind'] = array(FALSE,$e->getMessage()); + $result['time'] = $tester->tack('all', FALSE); + return $result; + } + } + + try { + $tester->tick('ldapSearchBogus'); + // Search for eduPersonPrincipalName of user. + $username = 'sd87f6ds8fsd87@feide.no'; + $userDN = $this->searchForUser($username); + $result['ldapSearchBogus'] = array(TRUE,$tester->tack('ldapSearchBogus')); + + } catch (sspmod_feide_Exception_UserNotFound $e) { + $result['ldapSearchBogus'] = array(TRUE,$tester->tack('ldapSearchBogus')); + + } catch (Exception $e) { + $tester->log('ldapstatus: Connect error() [' .$hostname . ']: ' . $e->getMessage()); + $result['ldapSearchBogus'] = array(FALSE,$e->getMessage()); + $result['time'] = $tester->tack('all', FALSE); + + return $result; + } + + + + + + // If test user is available + if ($this->location->hasValue('testUser')) { + + $tester->log('Testuser found in config. Performing test with test user.'); + $attributes = array(); + // Try to search for DN of test account + try { + $tester->tick('ldapSearchTestUser'); + + $userDN = $this->searchForUser($this->location->getValue('testUser')); + $result['ldapSearchTestUser'] = array(TRUE,$tester->tack('ldapSearchTestUser')); + } catch (Exception $e) { + $tester->log('LDAP Search test account:' . $e->getMessage()); + $result['ldapSearchTestUser'] = array(FALSE,$e->getMessage()); + $result['time'] = $tester->tack('all', FALSE); + return $result; + } + + $tester->tick('ldapBindTestUser'); + try { + if ($attributes = $this->userBind( + $userDN, + $this->location->getValue('testPassword') )) { + $result['ldapBindTestUser'] = array(TRUE,$tester->tack('ldapBindTestUser')); + } else { + $tester->log('LDAP Test user bind() failed...'); + $result['ldapBindTestUser'] = array(FALSE,'asdsad'); + $result['time'] = $tester->tack('all', FALSE); + return $result; + } + } catch(Exception $e) { + $tester->log('LDAP Test user bind() failed...'); + $result['ldapBindTestUser'] = array(FALSE,'Failed to bind: ' . $e->getMessage() ); + $result['time'] = $tester->tack('all', FALSE); + return $result; + } + + + try { + $tester->tick('getTestOrg'); + + // Get organization and organizationUnit data. + $this->getOrg(&$attributes, $this->location->getValue('testUser')); + $this->getOrgUnits(&$attributes, $this->location->getValue('testUser')); + $result['getTestOrg'] = array(TRUE,$tester->tack('getTestOrg')); + } catch(Exception $e) { + $tester->log('LDAP Test user attributes failed:' . $e->getMessage()); + $result['getTestOrg'] = array(FALSE,$e->getMessage()); + } + } + $result['time'] = $tester->tack('all', FALSE); + return $result; + } + + + + + +} \ No newline at end of file diff --git a/modules/ldapstatus/lib/LDAPTester.php b/modules/ldapstatus/lib/LDAPTester.php deleted file mode 100644 index 1c8255867660c24e42a96da136645becd5e78852..0000000000000000000000000000000000000000 --- a/modules/ldapstatus/lib/LDAPTester.php +++ /dev/null @@ -1,228 +0,0 @@ -<?php - -/** - * Test LDAP connection... - * - * @author Andreas Ă…kre Solberg, UNINETT AS. - * @package simpleSAMLphp - * @version $Id$ - */ -class sspmod_ldapstatus_LDAPTester { - - - private $orgconfig; - private $debug; - private $debugOutput; - - public function __construct($orgconfig, $debug, $output = FALSE) { - $this->orgconfig = $orgconfig; - $this->debug = $debug; - $this->debugOutput = $output; - } - - private function is_in_array($needles, $haystack) { - $needles = SimpleSAML_Utilities::arrayize($needles); - foreach($needles AS $needle) { - if (array_key_exists($needle, $haystack) && !empty($haystack[$needle])) return TRUE; - } - return FALSE; - } - - private function checkConfig($conf, $req) { - $err = array(); - foreach($req AS $r) { - - if (!$this->is_in_array($r, $conf)) { - $err[] = 'missing or empty: ' . join(', ', SimpleSAML_Utilities::arrayize($r)); - } - } - if (count($err) > 0) { - return array(FALSE, 'Missing: ' . join(', ', $err)); - } - return array(TRUE, ''); - } - - - private function checkParameter($conf, $req) { - $res = $this->checkConfig($conf, array($req)); - if ($res[0]) { - return 'Parameter [' . $req . '] found'; - } else { - return 'Parameter [' . $req . '] NOT found'; - } - } - - private function log($str) { - if ($this->debugOutput) { - echo '<p>' . $str; - } else { - SimpleSAML_Logger::debug($str); - } - flush(); - } - - private function phpping($host, $port) { - - $this->log('ldapstatus phpping(): ping [' . $host . ':' . $port . ']' ); - - $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,''); - } - } - - public function getTimeText($time) { - return 'Operation took ' . ceil($time*1000) . ' ms'; - } - - public function test() { - $start = microtime(TRUE); - - $result = array(); - - $this->log('Testing config'); - $result['config'] = $this->checkConfig($this->orgconfig, array('description', 'searchbase', 'hostname')); - - $this->log('Testing config meta'); - $result['configMeta'] = $this->checkConfig($this->orgconfig, array(array('contactMail', 'contactURL'))); - - $this->log('Testing config testuser'); - $result['configTest'] = $this->checkConfig($this->orgconfig, array('testUser', 'testPassword')); - - if (!$result['config'][0]) { - $this->log('Skipping because of no configuration'); - $result['time'] = microtime(TRUE) - $start; - return $result; - } - - $this->log($this->checkParameter($this->orgconfig, 'adminUser')); - $this->log($this->checkParameter($this->orgconfig, 'adminPassword')); - $this->log($this->checkParameter($this->orgconfig, 'testUser')); - $this->log($this->checkParameter($this->orgconfig, 'testPassword')); - - $urldef = explode(' ', $this->orgconfig['hostname']); - $url = parse_url($urldef[0]); - $port = 389; - if (!empty($url['scheme']) && $url['scheme'] === 'ldaps') $port = 636; - if (!empty($url['port'])) $port = $url['port']; - - $this->log('ldapstatus Url parse [' . $this->orgconfig['hostname'] . '] => [' . $url['host'] . ']:[' . $port . ']' ); - - - - - $laststart = microtime(TRUE); - $result['ping'] = $this->phpping($url['host'], $port); - $result['ping'][1] .= $this->getTimeText(microtime(TRUE) - $laststart); - - if (!$result['ping'][0]) { - $result['time'] = microtime(TRUE) - $start; - $this->log('Skipping because of no ping'); - return $result; - } - - // LDAP Connect - try { - $laststart = microtime(TRUE); - $ldap = new SimpleSAML_Auth_LDAP($this->orgconfig['hostname'], - (array_key_exists('enable_tls', $this->orgconfig) ? $this->orgconfig['enable_tls'] : FALSE), - $this->debug); - - if ($ldap->getLastError()) throw new Exception('LDAP warning: ' . $ldap->getLastError()); - $result['connect'] = array(TRUE,''); - $result['connect'][1] .= $this->getTimeText(microtime(TRUE) - $laststart); - - } catch (Exception $e) { - $this->log('ldapstatus: Connect error() [' .$this->orgconfig['hostname'] . ']: ' . $e->getMessage()); - $result['connect'] = array(FALSE,$e->getMessage()); - $result['time'] = microtime(TRUE) - $start; - return $result; - } - - // Bind as admin user - if (isset($this->orgconfig['adminUser'])) { - try { - $laststart = microtime(TRUE); - $this->log('ldapstatus: Admin bind() [' .$this->orgconfig['hostname'] . ']'); - $success = $ldap->bind($this->orgconfig['adminUser'], $this->orgconfig['adminPassword']); - if ($ldap->getLastError()) throw new Exception('LDAP warning: ' . $ldap->getLastError()); - if ($success) { - $result['adminBind'] = array(TRUE,''); - } else { - $result['adminBind'] = array(FALSE,'Could not bind()' ); - } - $result['adminBind'][1] .= $this->getTimeText(microtime(TRUE) - $laststart); - } catch (Exception $e) { - $this->log('admin Bind() error:' . $e->getMessage()); - $result['adminBind'] = array(FALSE,$e->getMessage()); - $result['time'] = microtime(TRUE) - $start; - return $result; - } - } - - - $eppn = 'asdasdasdasd@feide.no'; - // Search for bogus user - try { - $laststart = microtime(TRUE); - $dn = $ldap->searchfordn($this->orgconfig['searchbase'], 'eduPersonPrincipalName', $eppn, TRUE); - if ($ldap->getLastError()) throw new Exception('LDAP warning: ' . $ldap->getLastError()); - $result['ldapSearchBogus'] = array(TRUE,''); - $result['ldapSearchBogus'][1] .= $this->getTimeText(microtime(TRUE) - $laststart); - } catch (Exception $e) { - $this->log('LDAP Search bogus:' . $e->getMessage()); - $result['ldapSearchBogus'] = array(FALSE,$e->getMessage()); - $result['time'] = microtime(TRUE) - $start; - return $result; - } - - - // If test user is available - if (array_key_exists('testUser', $this->orgconfig)) { - - $this->log('Testuser found in config. Performing test with test user.'); - - // Try to search for DN of test account - try { - $laststart = microtime(TRUE); - $dn = $ldap->searchfordn($this->orgconfig['searchbase'], 'eduPersonPrincipalName', $this->orgconfig['testUser']); - if ($ldap->getLastError()) throw new Exception('LDAP warning: ' . $ldap->getLastError()); - $result['ldapSearchTestUser'] = array(TRUE,''); - $result['ldapSearchTestUser'][1] .= $this->getTimeText(microtime(TRUE) - $laststart); - } catch (Exception $e) { - $this->log('LDAP Search test account:' . $e->getMessage()); - $result['ldapSearchTestUser'] = array(FALSE,$e->getMessage()); - $result['time'] = microtime(TRUE) - $start; - return $result; - } - - if ($ldap->bind($dn, $this->orgconfig['testPassword'])) { - $result['ldapBindTestUser'] = array(TRUE,''); - - } else { - $this->log('LDAP Test user bind() failed...'); - $result['ldapBindTestUser'] = array(FALSE,''); - $result['time'] = microtime(TRUE) - $start; - return $result; - } - - try { - $laststart = microtime(TRUE); - $attributes = $ldap->getAttributes($dn, $this->orgconfig['attributes']); - if ($ldap->getLastError()) throw new Exception('LDAP warning: ' . $ldap->getLastError()); - $result['ldapGetAttributesTestUser'] = array(TRUE,''); - $result['ldapGetAttributesTestUser'][1] .= $this->getTimeText(microtime(TRUE) - $laststart); - } catch(Exception $e) { - $this->log('LDAP Test user attributes failed:' . $e->getMessage()); - $result['ldapGetAttributesTestUser'] = array(FALSE,$e->getMessage()); - } - } - $result['time'] = microtime(TRUE) - $start; - return $result; - } -} -?> \ No newline at end of file diff --git a/modules/ldapstatus/lib/Tester.php b/modules/ldapstatus/lib/Tester.php new file mode 100644 index 0000000000000000000000000000000000000000..89df654d3d9ab6b1400e444e5c8b1c6794cb9387 --- /dev/null +++ b/modules/ldapstatus/lib/Tester.php @@ -0,0 +1,102 @@ +<?php + +/** + * Test helper class. + * + * @author Andreas Ă…kre Solberg, UNINETT AS. + * @package simpleSAMLphp + * @version $Id$ + */ +class sspmod_ldapstatus_Tester { + + + private $location; + private $debugOutput; + private $times; + + public function __construct($location, $debugOutput = FALSE) { + $this->location = $location; + $this->times = array(); + $this->debugOutput = $debugOutput; + } + + /** + * Start timer + */ + public function tick($tag = 'default') { + $this->times[$tag] = microtime(TRUE); + } + + /** + * Stop timer + */ + public function tack($tag = 'default', $text = TRUE) { + if($text) + return $this->getTimeText(microtime(TRUE) - $this->times[$tag]); + return (microtime(TRUE) - $this->times[$tag]); + } + + /** + * Get duration as text. + */ + private function getTimeText($time) { + return 'Operation took ' . ceil($time*1000) . ' ms'; + } + + public function checkConfig($req) { + $err = array(); + foreach($req AS $r) { + $rs = SimpleSAML_Utilities::arrayize($r); + if (!$this->location->hasValueOneOf($rs)) { + $err[] = 'one of (' . join(',', $rs) . ')'; + } + } + if (count($err) > 0) + return array(FALSE, 'Missing: ' . join(' | ', $err)); + return array(TRUE, ''); + } + + + private function checkParameter($conf, $req) { + $res = $this->checkConfig($conf, array($req)); + if ($res[0]) { + return 'Parameter [' . $req . '] found'; + } else { + return 'Parameter [' . $req . '] NOT found'; + } + } + + public function log($str) { + if ($this->debugOutput) { + echo '<p>' . $str; + } else { + SimpleSAML_Logger::debug($str); + } + flush(); + } + + + /** + * TCP ping implemented in php. + * Warning: Will return Success if hostname is illegal. should be fixed. + * + * @param $host Hostname + * @param $port Port number (TCP) + */ + public function phpping($host, $port) { + + $this->log('ldapstatus phpping(): ping [' . $host . ':' . $port . ']' ); + + $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,''); + } + } + + + +} \ No newline at end of file diff --git a/modules/ldapstatus/templates/ldapsinglehost.php b/modules/ldapstatus/templates/ldapsinglehost.php index 0195162727c1a8147972454fe0ab70c61af66595..60d540c2c310a2b7de97f13c30f25695cb914d67 100644 --- a/modules/ldapstatus/templates/ldapsinglehost.php +++ b/modules/ldapstatus/templates/ldapsinglehost.php @@ -109,8 +109,8 @@ if ($ok) { <p>Trying to bind() as the DN found when searching for the test user</p> <?php presentRes('ldapBindTestUser'); ?> -<p>Getting attributes from the DN of the test user</p> -<?php presentRes('ldapGetAttributesTestUser'); ?> +<p>Getting attributes from referred eduOrgDN and eduOrgUnitDN (from test user)</p> +<?php presentRes('getTestOrg'); ?> <p>Checking for additional contact addresss in configuration.</p> <?php presentRes('configMeta'); ?> diff --git a/modules/ldapstatus/templates/ldapstatus.php b/modules/ldapstatus/templates/ldapstatus.php index 218dee697757799f9e7d19b2ff23c04d4a5becd6..446250443c842dc82fcf410133f120a1ad7b70e9 100644 --- a/modules/ldapstatus/templates/ldapstatus.php +++ b/modules/ldapstatus/templates/ldapstatus.php @@ -32,7 +32,7 @@ $this->includeAtTemplateBase('includes/header.php'); <th>test</th> <th>S=test</th> <th>test bind()</th> - <th>attributes</th> + <th>Org-info</th> <th>Meta</th> <th>Time</th> </tr> @@ -67,35 +67,40 @@ $classes = array('odd', 'even'); # $this->data['results'] foreach($this->data['sortedOrgIndex'] as $orgkey) { - $res = $this->data['results'][$orgkey]; - echo('<tr class="' . ($classes[($i++ % 2)]) . '">'); - if (array_key_exists('description', $this->data['orgconfig'][$orgkey])) { - echo('<td><a href="?orgtest=' . htmlentities($orgkey) . '">'); - echo htmlspecialchars( - $this->getTranslation( - SimpleSAML_Utilities::arrayize($this->data['orgconfig'][$orgkey]['description'], 'en') - ) - ); - echo('</a></td>'); - } else { - echo('<td><span style="color: #b4b4b4; font-size: x-small">NA</span> <tt>' . $orgkey . '</tt></td>'); - } - showRes('config', $res, $this); - showRes('ping', $res, $this); - showRes('adminBind', $res, $this); - showRes('ldapSearchBogus', $res, $this); - showRes('configTest', $res, $this); - showRes('ldapSearchTestUser', $res, $this); - showRes('ldapBindTestUser', $res, $this); - showRes('ldapGetAttributesTestUser', $res, $this); - showRes('configMeta', $res, $this); - echo('<td style="text-align: right">' . ceil($res['time']*1000) . ' ms</td>'); - echo('</tr>'); - - if ($this->data['showcomments'] && array_key_exists('comment', $this->data['orgconfig'][$orgkey])) { - echo('<tr><td style="color: #400; padding-left: 5em; font-family: \'Arial Narrow\'; font-size: 85%" colspan="11">' . $this->data['orgconfig'][$orgkey]['comment'] . '</td></tr>'); - } - + $ress = $this->data['results'][$orgkey]; + foreach($ress AS $i => $res) { + + echo('<tr class="' . ($classes[($i++ % 2)]) . '">'); + if (array_key_exists('description', $this->data['orgconfig'][$orgkey])) { + echo('<td><a href="?orgtest=' . htmlentities($orgkey) . '">'); + echo htmlspecialchars( + $this->getTranslation( + SimpleSAML_Utilities::arrayize($this->data['orgconfig'][$orgkey]['description'], 'en') + ) + ); + if(count($ress) > 1) { + echo(' (location ' . ($i) . ')'); + } + echo('</a></td>'); + } else { + echo('<td><span style="color: #b4b4b4; font-size: x-small">NA</span> <tt>' . $orgkey . '</tt></td>'); + } + showRes('config', $res, $this); + showRes('ping', $res, $this); + showRes('adminBind', $res, $this); + showRes('ldapSearchBogus', $res, $this); + showRes('configTest', $res, $this); + showRes('ldapSearchTestUser', $res, $this); + showRes('ldapBindTestUser', $res, $this); + showRes('getTestOrg', $res, $this); + showRes('configMeta', $res, $this); + echo('<td style="text-align: right">' . ceil($res['time']*1000) . ' ms</td>'); + echo('</tr>'); + + if ($this->data['showcomments'] && array_key_exists('comment', $this->data['orgconfig'][$orgkey])) { + echo('<tr><td style="color: #400; padding-left: 5em; font-family: \'Arial Narrow\'; font-size: 85%" colspan="11">' . $this->data['orgconfig'][$orgkey]['comment'] . '</td></tr>'); + } + } } ?> diff --git a/modules/ldapstatus/www/index.php b/modules/ldapstatus/www/index.php index 0e178cfe18215af585b081f387e66a96027eef74..9caa4444e541b71dee5d387eeb2741c54bc154eb 100644 --- a/modules/ldapstatus/www/index.php +++ b/modules/ldapstatus/www/index.php @@ -85,18 +85,11 @@ $ldapconfig = SimpleSAML_Configuration::getConfig('config-login-feide.php'); $ldapStatusConfig = SimpleSAML_Configuration::getConfig('module_ldapstatus.php'); $debug = $ldapconfig->getValue('ldapDebug', FALSE); -$orgs = $ldapconfig->getValue('orgldapconfig'); +$orgs = $ldapconfig->getValue('organizations'); +$locationTemplate = $ldapconfig->getValue('locationTemplate'); -#echo '<pre>'; print_r($orgs); exit; - - - - - -$results = NULL; - $results = $session->getData('module:ldapstatus', 'results'); if (empty($results)) { $results = array(); @@ -116,7 +109,17 @@ $maxtime = $ldapStatusConfig->getValue('maxExecutionTime', 15); if (array_key_exists('orgtest', $_REQUEST)) { #$old_error_handler = set_error_handler("myErrorHandler"); - $tester = new sspmod_ldapstatus_LDAPTester($orgs[$_REQUEST['orgtest']], $debug); + $locindex = 0; + if (array_key_exists('locindex', $_REQUEST)) $locindex = $_REQUEST['locindex']; + + $orgconfig = SimpleSAML_Configuration::loadFromArray($orgs[$_REQUEST['orgtest']], 'org:[' . $_REQUEST['orgtest'] . ']'); + $orgloc = $orgs[$_REQUEST['orgtest']]['locations'][$locindex]; + $orgloc = mergeWithTemplate($orgloc, $locationTemplate); + $classname = SimpleSAML_Module::resolveClass($orgloc['testType'], 'Auth_Backend_Test'); + $tester = new $classname( + SimpleSAML_Configuration::loadFromArray($orgloc, 'Location@[' . $_REQUEST['orgtest'] . ']'), + $orgconfig); + $res = $tester->test(); $t = new SimpleSAML_XHTML_Template($config, 'ldapstatus:ldapsinglehost.php'); @@ -126,25 +129,38 @@ if (array_key_exists('orgtest', $_REQUEST)) { if ($isAdmin) $t->data['secretURL'] = $secretURL; $t->show(); exit; - } +function mergeWithTemplate($location, $template) { + foreach($template AS $key => $value) { + if (!array_key_exists($key, $location)) $location[$key] = $value; + } + return $location; +} -// Traverse and execute tests for each entry... -foreach ($orgs AS $orgkey => $orgconfig) { +$start = microtime(TRUE); +foreach($orgs AS $orgkey => $org) { if (array_key_exists($orgkey, $results)) continue; - - SimpleSAML_Logger::debug('ldapstatus: Executing test on ' . $orgkey); - - $tester = new sspmod_ldapstatus_LDAPTester($orgconfig, $debug); - $results[$orgkey] = $tester->test(); - + $orgconfig = SimpleSAML_Configuration::loadFromArray($org, 'org:[' . $orgkey . ']'); + $orglocs = $org['locations']; + $results[$orgkey] = array(); + foreach($orglocs AS $orgloc) { + $orgloc = mergeWithTemplate($orgloc, $locationTemplate); + $classname = SimpleSAML_Module::resolveClass($orgloc['testType'], 'Auth_Backend_Test'); + $tester = new $classname( + SimpleSAML_Configuration::loadFromArray($orgloc, 'Location@[' . $orgkey . ']'), + $orgconfig); + $results[$orgkey][] = $tester->test(); + } if ((microtime(TRUE) - $start) > $maxtime) { SimpleSAML_Logger::debug('ldapstatus: Completing execution after maxtime [' .(microtime(TRUE) - $start) . ' of maxtime ' . $maxtime . ']'); break; } + } + + $session->setData('module:ldapstatus', 'results', $results); #echo '<pre>'; print_r($results); exit; @@ -154,7 +170,7 @@ $lightCounter = array(0,0,0); function resultCode($res) { global $lightCounter; $code = ''; - $columns = array('configMeta', 'config', 'ping', 'adminBind', 'ldapSearchBogus', 'configTest', 'ldapSearchTestUser', 'ldapBindTestUser', 'ldapGetAttributesTestUser', ); + $columns = array('configMeta', 'config', 'ping', 'adminBind', 'ldapSearchBogus', 'configTest', 'ldapSearchTestUser', 'ldapBindTestUser', 'getTestOrg', ); foreach ($columns AS $c) { if (array_key_exists($c, $res)) { if ($res[$c][0]) { @@ -176,7 +192,7 @@ function resultCode($res) { $ressortable = array(); foreach ($results AS $key => $res) { - $ressortable[$key] = resultCode($res); + $ressortable[$key] = resultCode($res[0]); } asort($ressortable); #echo '<pre>'; print_r($ressortable); exit;