Source of file LDAPDebugController.php
Size: 3,579 Bytes - Last Modified: 2021-12-23T10:27:14+00:00
/var/www/docs.ssmods.com/process/src/code/control/LDAPDebugController.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 | <?php /** * Class LDAPDebugController * * This controller is used to debug the LDAP connection. */ class LDAPDebugController extends ContentController { /** * @var array */ private static $allowed_actions = [ 'index', ]; /** * @var array */ private static $dependencies = [ 'ldapService' => '%$LDAPService' ]; /** * @var LDAPService */ public $ldapService; public function init() { parent::init(); if (!Permission::check('ADMIN')) { Security::permissionFailure(); } } /** * @param SS_HTTPRequest $request * * @return string */ public function index(\SS_HTTPRequest $request) { return $this->renderWith(['LDAPDebugController']); } public function Options() { $list = new ArrayList(); foreach (Config::inst()->get('LDAPGateway', 'options') as $field => $value) { if ($field === 'password') { $value = '***'; } $list->push(new ArrayData([ 'Name' => $field, 'Value' => $value ])); } return $list; } public function UsersSearchLocations() { $locations = Config::inst()->get('LDAPService', 'users_search_locations'); $list = new ArrayList(); if ($locations) { foreach ($locations as $location) { $list->push(new ArrayData([ 'Value' => $location ])); } } else { $list->push($this->Options()->find('Name', 'baseDn')); } return $list; } public function GroupsSearchLocations() { $locations = Config::inst()->get('LDAPService', 'groups_search_locations'); $list = new ArrayList(); if ($locations) { foreach ($locations as $location) { $list->push(new ArrayData([ 'Value' => $location ])); } } else { $list->push($this->Options()->find('Name', 'baseDn')); } return $list; } public function DefaultGroup() { $code = Config::inst()->get('LDAPService', 'default_group'); if ($code) { $group = Group::get()->filter('Code', $code)->limit(1)->first(); if (!($group && $group->exists())) { return sprintf( 'WARNING: LDAPService.default_group configured with \'%s\' but there is no Group with that Code in the database!', $code ); } else { return sprintf('%s (Code: %s)', $group->Title, $group->Code); } } return null; } public function MappedGroups() { return LDAPGroupMapping::get(); } public function Nodes() { $groups = $this->ldapService->getNodes(false); $list = new ArrayList(); foreach ($groups as $record) { $list->push(new ArrayData([ 'DN' => $record['dn'] ])); } return $list; } public function Groups() { $groups = $this->ldapService->getGroups(false); $list = new ArrayList(); foreach ($groups as $record) { $list->push(new ArrayData([ 'DN' => $record['dn'] ])); } return $list; } public function Users() { return count($this->ldapService->getUsers()); } } |