1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Class LDAPDebugController |
4
|
|
|
* |
5
|
|
|
* This controller is used to debug the LDAP connection. |
6
|
|
|
*/ |
7
|
|
|
class LDAPDebugController extends ContentController |
|
|
|
|
8
|
|
|
{ |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @var array |
12
|
|
|
*/ |
13
|
|
|
private static $allowed_actions = [ |
|
|
|
|
14
|
|
|
'index', |
15
|
|
|
]; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private static $dependencies = [ |
|
|
|
|
21
|
|
|
'ldapService' => '%$LDAPService' |
22
|
|
|
]; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var LDAPService |
26
|
|
|
*/ |
27
|
|
|
public $ldapService; |
28
|
|
|
|
29
|
|
|
public function init() |
30
|
|
|
{ |
31
|
|
|
parent::init(); |
32
|
|
|
|
33
|
|
|
if (!Permission::check('ADMIN')) { |
34
|
|
|
Security::permissionFailure(); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param SS_HTTPRequest $request |
40
|
|
|
* |
41
|
|
|
* @return string |
42
|
|
|
*/ |
43
|
|
|
public function index(\SS_HTTPRequest $request) { |
44
|
|
|
return $this->renderWith(['LDAPDebugController']); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function Options() |
48
|
|
|
{ |
49
|
|
|
$list = new ArrayList(); |
50
|
|
|
foreach (Config::inst()->get('LDAPGateway', 'options') as $field => $value) { |
|
|
|
|
51
|
|
|
if ($field === 'password') { |
52
|
|
|
$value = '***'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
$list->push(new ArrayData([ |
56
|
|
|
'Name' => $field, |
57
|
|
|
'Value' => $value |
58
|
|
|
])); |
59
|
|
|
} |
60
|
|
|
return $list; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
View Code Duplication |
public function UsersSearchLocations() |
|
|
|
|
64
|
|
|
{ |
65
|
|
|
$locations = Config::inst()->get('LDAPService', 'users_search_locations'); |
66
|
|
|
$list = new ArrayList(); |
67
|
|
|
if ($locations) { |
68
|
|
|
foreach ($locations as $location) { |
|
|
|
|
69
|
|
|
$list->push(new ArrayData([ |
70
|
|
|
'Value' => $location |
71
|
|
|
])); |
72
|
|
|
} |
73
|
|
|
} else { |
74
|
|
|
$list->push($this->Options()->find('Name', 'baseDn')); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $list; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
View Code Duplication |
public function GroupsSearchLocations() |
|
|
|
|
81
|
|
|
{ |
82
|
|
|
$locations = Config::inst()->get('LDAPService', 'groups_search_locations'); |
83
|
|
|
$list = new ArrayList(); |
84
|
|
|
if ($locations) { |
85
|
|
|
foreach ($locations as $location) { |
|
|
|
|
86
|
|
|
$list->push(new ArrayData([ |
87
|
|
|
'Value' => $location |
88
|
|
|
])); |
89
|
|
|
} |
90
|
|
|
} else { |
91
|
|
|
$list->push($this->Options()->find('Name', 'baseDn')); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $list; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function DefaultGroup() |
98
|
|
|
{ |
99
|
|
|
$code = Config::inst()->get('LDAPService', 'default_group'); |
100
|
|
|
if ($code) { |
101
|
|
|
$group = Group::get()->filter('Code', $code)->limit(1)->first(); |
102
|
|
|
if (!($group && $group->exists())) { |
103
|
|
|
return sprintf( |
104
|
|
|
'WARNING: LDAPService.default_group configured with \'%s\' but there is no Group with that Code in the database!', |
105
|
|
|
$code |
106
|
|
|
); |
107
|
|
|
} else { |
108
|
|
|
return sprintf('%s (Code: %s)', $group->Title, $group->Code); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
return null; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function MappedGroups() |
116
|
|
|
{ |
117
|
|
|
return LDAPGroupMapping::get(); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
View Code Duplication |
public function Nodes() |
|
|
|
|
121
|
|
|
{ |
122
|
|
|
$groups = $this->ldapService->getNodes(false); |
123
|
|
|
$list = new ArrayList(); |
124
|
|
|
foreach ($groups as $record) { |
125
|
|
|
$list->push(new ArrayData([ |
126
|
|
|
'DN' => $record['dn'] |
127
|
|
|
])); |
128
|
|
|
} |
129
|
|
|
return $list; |
130
|
|
|
} |
131
|
|
|
|
132
|
|
View Code Duplication |
public function Groups() |
|
|
|
|
133
|
|
|
{ |
134
|
|
|
$groups = $this->ldapService->getGroups(false); |
135
|
|
|
$list = new ArrayList(); |
136
|
|
|
foreach ($groups as $record) { |
137
|
|
|
$list->push(new ArrayData([ |
138
|
|
|
'DN' => $record['dn'] |
139
|
|
|
])); |
140
|
|
|
} |
141
|
|
|
return $list; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function Users() |
145
|
|
|
{ |
146
|
|
|
return count($this->ldapService->getUsers()); |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.