/** * Print out a hierarchy of groups * * @param LdapConnector $ldap * @param string $currentDn * @param array $open * @return void * @access public * @since 8/31/09 */ function printHierarchy(LdapConnector $ldap, $currentDn, array $open, $tabs = "\n\t\t") { print $tabs . "<li class='group'>"; print "<a name='" . base64_encode($currentDn) . "'></a>"; print "<a href='"; if (in_array($currentDn, $open)) { $parentKey = array_search($currentDn, $open) + 1; if (isset($open[$parentKey])) { print getUrl('list_all', array('current' => base64_encode($open[$parentKey]))) . '#' . base64_encode($currentDn); } else { print getUrl('list_all'); } } else { print getUrl('list_all', array('current' => base64_encode($currentDn))) . '#' . base64_encode($currentDn); } print "'>" . dnToName($currentDn) . "</a>"; if (in_array($currentDn, $open)) { // If this is an OU, print out its children $children = $ldap->getList('(|(objectClass=group)(objectClass=organizationalUnit))', $currentDn, array('dn')); if (count($children)) { print $tabs . "<ul>"; foreach ($children as $child) { printHierarchy($ldap, $child['dn'], $open, $tabs . "\t"); } print $tabs . "</ul>"; } else { $groups = $ldap->read('(objectClass=group)', $currentDn, array('managedby', 'member')); if (count($groups) == 1 && isset($groups[0]['member'])) { if (isset($groups[0]['managedby'][0])) { print $tabs . "<ul class='manager'>"; print $tabs . "\t<li>Group Manager: " . dnToName($groups[0]['managedby'][0]) . "</li>"; print $tabs . "</ul>"; } print $tabs . "<ul class='members'>"; sort($groups[0]['member']); foreach ($groups[0]['member'] as $member) { print $tabs . "\t<li>" . dnToName($member) . "</li>"; } print $tabs . "</ul>"; } } } print $tabs . "</li>"; }
/** * Load all results * * @param array $ldapConfig * @return array * @access public * @since 7/30/09 */ function loadAllResults(array $ldapConfig) { $results = array(); foreach ($ldapConfig as $connectorConfig) { $connector = new LdapConnector($connectorConfig); $connector->connect(); $error = ''; try { switch ($_GET['action']) { case 'search_groups': try { $results = array_merge($results, $connector->searchGroups($_GET)); } catch (InvalidArgumentException $e) { $error = $e->getMessage(); } break; case 'search_groups_by_attributes': try { $results = array_merge($results, $connector->searchGroupsByAttributes($_GET)); } catch (NullArgumentException $e) { $error = $e->getMessage(); } break; case 'search_users': $results = array_merge($results, $connector->searchUsers($_GET)); break; case 'search_users_by_attributes': try { $results = array_merge($results, $connector->searchUsersByAttributes($_GET)); } catch (NullArgumentException $e) { $error = $e->getMessage(); } break; case 'get_group': try { $results = array_merge($results, array($connector->getGroup($_GET))); } catch (UnknownIdException $e) { $error = $e->getMessage(); } break; case 'get_user': try { $results = array_merge($results, array($connector->getUser($_GET))); } catch (UnknownIdException $e) { $error = $e->getMessage(); } break; case 'get_group_members': try { $results = array_merge($results, $connector->getGroupMembers($_GET)); } catch (UnknownIdException $e) { $error = $e->getMessage(); } break; case 'get_all_users': $results = array_merge($results, $connector->getAllUsers($_GET)); break; default: throw new UnknownActionException('action, \'' . $_GET['action'] . '\' is not one of [search_users, search_groups, get_user, get_group].'); } } catch (LDAPException $e) { if ($e->getCode() != 10) { // 10 = LDAP_REFERRAL throw $e; } } $connector->disconnect(); } switch ($_GET['action']) { case 'get_group': case 'get_user': if (empty($results)) { throw new UnknownIdException($error); } break; case 'search_users_by_attributes': break; } return $results; }
} if (!defined('DISPLAY_ERROR_BACKTRACE')) { define('DISPLAY_ERROR_BACKTRACE', false); } require_once MYDIR . '/lib/phpcas/source/CAS.php'; if (!isset($getUserDisplayName)) { $getUserDisplayName = create_function('', 'return phpCAS::getUser();'); } // initialize phpCAS phpCAS::client(CAS_VERSION_2_0, CAS_HOST, CAS_PORT, CAS_PATH, false); // no SSL validation for the CAS server phpCAS::setNoCasServerValidation(); // force CAS authentication phpCAS::forceAuthentication(); // var_dump($_SESSION); $ldap = new LdapConnector($ldapConfig); $ldap->connect(); try { // Check authorization if (!empty($authorizedUserAttributes)) { if (!is_array($authorizedUserAttributes)) { throw new Exception('Configuration Error: $authorizedUserAttributes must be an array'); } $isAuthorized = false; $attributes = phpCAS::getAttributes(); foreach ($authorizedUserAttributes as $attr => $authorized_values) { if (!is_array($authorized_values)) { $authorized_values = array($authorized_values); } foreach ($authorized_values as $authorized_value) { if (!empty($attributes[$attr])) {