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 = array( |
|
|
|
|
14
|
|
|
'index', |
15
|
|
|
); |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private static $dependencies = array( |
|
|
|
|
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
|
|
|
$list->push(new ArrayData(array( |
52
|
|
|
'Name' => $field, |
53
|
|
|
'Value' => $value |
54
|
|
|
))); |
55
|
|
|
} |
56
|
|
|
return $list; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
View Code Duplication |
public function UsersSearchLocations() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$locations = Config::inst()->get('LDAPService', 'users_search_locations'); |
62
|
|
|
$list = new ArrayList(); |
63
|
|
|
if ($locations) { |
64
|
|
|
foreach ($locations as $location) { |
|
|
|
|
65
|
|
|
$list->push(new ArrayData(array( |
66
|
|
|
'Value' => $location |
67
|
|
|
))); |
68
|
|
|
} |
69
|
|
|
} else { |
70
|
|
|
$list->push($this->Options()->find('Name', 'baseDn')); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $list; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
View Code Duplication |
public function GroupsSearchLocations() |
|
|
|
|
77
|
|
|
{ |
78
|
|
|
$locations = Config::inst()->get('LDAPService', 'groups_search_locations'); |
79
|
|
|
$list = new ArrayList(); |
80
|
|
|
if ($locations) { |
81
|
|
|
foreach ($locations as $location) { |
|
|
|
|
82
|
|
|
$list->push(new ArrayData(array( |
83
|
|
|
'Value' => $location |
84
|
|
|
))); |
85
|
|
|
} |
86
|
|
|
} else { |
87
|
|
|
$list->push($this->Options()->find('Name', 'baseDn')); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
return $list; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function DefaultGroup() |
94
|
|
|
{ |
95
|
|
|
$code = Config::inst()->get('LDAPService', 'default_group'); |
96
|
|
|
if ($code) { |
97
|
|
|
$group = Group::get()->filter('Code', $code)->limit(1)->first(); |
98
|
|
|
if (!($group && $group->exists())) { |
99
|
|
|
return sprintf( |
100
|
|
|
'WARNING: LDAPService.default_group configured with \'%s\' but there is no Group with that Code in the database!', |
101
|
|
|
$code |
102
|
|
|
); |
103
|
|
|
} else { |
104
|
|
|
return sprintf('%s (Code: %s)', $group->Title, $group->Code); |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
return null; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function MappedGroups() |
112
|
|
|
{ |
113
|
|
|
return LDAPGroupMapping::get(); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
View Code Duplication |
public function Nodes() |
|
|
|
|
117
|
|
|
{ |
118
|
|
|
$groups = $this->ldapService->getNodes(false); |
119
|
|
|
$list = new ArrayList(); |
120
|
|
|
foreach ($groups as $record) { |
121
|
|
|
$list->push(new ArrayData(array( |
122
|
|
|
'DN' => $record['dn'] |
123
|
|
|
))); |
124
|
|
|
} |
125
|
|
|
return $list; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
View Code Duplication |
public function Groups() |
|
|
|
|
129
|
|
|
{ |
130
|
|
|
$groups = $this->ldapService->getGroups(false); |
131
|
|
|
$list = new ArrayList(); |
132
|
|
|
foreach ($groups as $record) { |
133
|
|
|
$list->push(new ArrayData(array( |
134
|
|
|
'DN' => $record['dn'] |
135
|
|
|
))); |
136
|
|
|
} |
137
|
|
|
return $list; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function Users() |
141
|
|
|
{ |
142
|
|
|
return count($this->ldapService->getUsers()); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
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.