Source of file LDAPDebugController.php
Size: 4,243 Bytes - Last Modified: 2021-12-23T10:32:42+00:00
/var/www/docs.ssmods.com/process/src/src/Control/LDAPDebugController.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 | <?php namespace SilverStripe\LDAP\Control; use SilverStripe\CMS\Controllers\ContentController; use SilverStripe\Control\HTTPRequest; use SilverStripe\Core\Config\Config; use SilverStripe\LDAP\Model\LDAPGateway; use SilverStripe\LDAP\Model\LDAPGroupMapping; use SilverStripe\LDAP\Services\LDAPService; use SilverStripe\ORM\ArrayList; use SilverStripe\Security\Group; use SilverStripe\Security\Permission; use SilverStripe\Security\Security; use SilverStripe\View\ArrayData; /** * 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::class ]; /** * @var LDAPService */ public $ldapService; protected function init() { parent::init(); ini_set('memory_limit', '-1'); // Increase memory limit to max possible if (!Permission::check('ADMIN')) { Security::permissionFailure(); } } /** * @param HTTPRequest $request * * @return string */ public function index(HTTPRequest $request) { return $this->renderWith([self::class]); } public function Options() { $list = new ArrayList(); foreach (Config::inst()->get(LDAPGateway::class, '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::class, '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::class, '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::class, '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(['objectguid', 'dn'])); // Only get two attrs to prevent memory errors } } |