-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin_show_user.php
executable file
·419 lines (331 loc) · 11.9 KB
/
admin_show_user.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
<?php
/**
* Change password of other users (admin form).
*
* @package arcanum
* @version $Id: admin_show_user.php 5961 2013-01-04 13:10:38Z avel $
*/
$initLocation = 'admin_show_user';
require_once 'include/init.php';
$show_pwdreset_form = true;
if($config->ldap->servertype == 'sunds') {
$show_pwdreset_form = false;
}
$policies = $_SESSION['policies'];
$arcanumLdap = new Arcanum_Ldap();
$ldap = $arcanumLdap->connect();
/*
// Set up ldap handle and check EVERY TIME if user is authorized to be in this page via LDAP.
// This is to avoid potential session fixation / session hijacking or even XSS vulnerabilities
$sr = ldap_search($ldap, $config->ldap->basedn, sprintf($config->ldap->filter->admin, ldapspecialchars($login_username)), array('uid', 'userpassword'));
if(!$sr) die('Error searching!');
$info = ldap_get_entries($ldap, $sr);
Arcanum_Ldap::sanitize_entry_array($info);
if($info['count']!=1) {
header("Location: signout.php?forced=2");
exit;
}
unset($info);
*/
$msgs = array();
$uid = '';
if (isset($_REQUEST['uid'])) {
$uid = $_REQUEST['uid'];
}
if (isset($_POST['dn'])) {
$dn = $_POST['dn'];
}
/*
* Post actions:
*
* Massive changes from search results:
*
* submitmassivechange
* -> EITHER massivechangefilter: <ldap_filter>
* -> OR massivechangequery: <search_query>
* -> policy: nochange | default | <dn>
* -> lock: nochange | lock | unlock
* -> forcechange: nochange | forcechange | unforcechange
*
* Per user operations:
* action_lock
* action_unlock
* action_force_pw_change
* action_clear_pwdreset
* subpolicy
*/
if (isset($_POST['submitmassivechange']) && (
isset($_POST['massivechangefilter']) || isset($_POST['massivechangequery'])) ) {
if(!empty($_POST['massivechangefilter'])) {
$massivechangefilter = $_POST['massivechangefilter'];
} else {
$massivechangefilter = Arcanum_Ldap::constructFilterFromQuery($_POST['massivechangequery']);
}
$ldapmod = array();
$ldapdel = array();
$policy = $_POST['policy'];
if ($policy != 'nochange') {
if ($policy == 'default') {
$ldapdel['pwdPolicySubentry'] = array();
} else {
$ldapmod['pwdPolicySubentry'] = urldecode($policy);
}
}
$lock = $_POST['lock'];
if ($lock != 'nochange') {
if ($lock == 'lock') {
$ldapmod['pwdaccountlockedtime'] = '000001010000Z';
} elseif ($lock == 'unlock') {
$ldapdel['pwdaccountlockedtime'] = array();
}
}
$forcechange = $_POST['forcechange'];
if ($forcechange != 'nochange') {
if ($forcechange == 'forcechange') {
/*
// for sun ds - TODO
$sr1 = ldap_search(
$ldap, $config->ldap->basedn, $filter,
array('objectclass', 'userPassword')
);
$entries1 = ldap_get_entries($ldap, $sr);
print_r($entries1);
$original_user_password_value = $entries[0]['userPassword'];
$ldapmod['userPassword'] = $original_user_password_value;
*/
$ldapmod['pwdReset'] = 'TRUE';
} elseif ($forcechange == 'unforcechange') {
$ldapdel['pwdReset'] = array();
}
}
if ($ldapmod || $ldapdel) {
$sr = ldap_search(
$ldap, $config->ldap->basedn, $massivechangefilter,
array('objectclass', 'pwdPolicySubentry')
);
$entries = ldap_get_entries($ldap, $sr);
$counters = array(
'total' => $entries['count'],
'modsuccess' => 0,
'delsuccess' => 0,
'delnochange' => 0,
'error' => 0
);
if ($ldapmod) {
for ($i=0; $i<$entries['count']; $i++) {
if (ldap_modify($ldap, $entries[$i]['dn'], $ldapmod) === true) {
$counters['modsuccess']++;
} else {
$counters['error']++;
}
}
}
if ($ldapdel) {
for ($i=0; $i<$entries['count']; $i++) {
if (@ldap_mod_del($ldap, $entries[$i]['dn'], $ldapdel) === true) {
$counters['delsuccess']++;
} else {
$counters['delnochange']++;
// $counters['error']++;
}
}
}
$t->assign('javascripts', $defaultJavascripts);
$t->assign('counters', $counters);
$t->display('html_header');
$t->display('page_header_admin');
$t->display('admin_massive_changes_results');
$t->display('page_footer_admin');
$t->display('html_footer');
exit;
}
}
$secondaryAccounts = array();
if (!empty($uid)) {
if (isset($_POST['action_lock'])) {
// Not implemented yet
$action = 'lock';
$ldapmod = array('pwdaccountlockedtime' => '000001010000Z');
} elseif (isset($_POST['action_unlock'])) {
$action = 'unlock';
$ldapdel = array('pwdaccountlockedtime' => array());
} elseif (isset($_POST['action_force_pw_change'])) {
$action = 'force_pw_change';
// $ldapmod = array('pwdReset' => 'TRUE');
// for sun ds
$filter = sprintf($config->ldap->filter->user, ldapspecialchars($uid));
if ($restrict) {
$filter = '(&'.$filter.$restrict['apply'].')';
}
$sr1 = ldap_search(
$ldap, $config->ldap->basedn, $filter,
array('objectclass', 'userPassword')
);
$entries1 = ldap_get_entries($ldap, $sr1);
$original_user_password_value = $entries1[0]['userpassword'][0];
$ldapmod['userpassword'] = $original_user_password_value;
$ldapmod['pwdReset'] = 'TRUE';
} elseif (isset($_POST['action_clear_pwdreset'])) {
$action = 'clear_pwdreset';
$ldapdel = array('pwdReset' => array() );
} elseif (isset($_POST['subpolicy_submit'])) {
$action = 'subpolicy';
$subpolicy_post = $_POST['subpolicy'];
// validation
if( $subpolicy_post == 'default') {
$subpolicy = 'default';
} else {
for($i=0; $i<$policies['count']; $i++) {
if ($policies[$i]['dn'] == $subpolicy_post) {
$subpolicy = $subpolicy_post;
break;
}
}
}
if($subpolicy == 'default') {
$ldapdel = array('pwdPolicySubentry' => array());
} else {
$ldapmod = array('pwdPolicySubentry' => $subpolicy);
}
}
if (isset($action)) {
// confirm, if needed, that we are allowed to change this user, and at the same time grab the dn
if ($restrict) {
$filter = '(&'.sprintf($config->ldap->filter->user, ldapspecialchars($uid)).$restrict['apply'].')';
} else {
$filter = sprintf($config->ldap->filter->user, ldapspecialchars($uid));
}
$sr = ldap_search(
$ldap, $config->ldap->basedn, $filter,
array_merge($config->admin->show_attrs->toArray(), array('objectclass'))
);
$count = ldap_count_entries($ldap, $sr);
if ($count == 0) {
Arcanum_Session::logout(LOGOUT_REASON_ACCESS_DENIED);
} elseif ($count > 1) {
// Multiple usernames? TODO
Arcanum_Session::logout(LOGOUT_REASON_ACCESS_DENIED);
}
$entries = ldap_get_entries($ldap, $sr);
$dn = $entries[0]['dn'];
if (isset($ldapdel)) {
$res = @ldap_mod_del($ldap, $dn, $ldapdel);
} else {
$res = @ldap_modify($ldap, $dn, $ldapmod);
}
if ($res === false) {
$msgs[] = array('class' => 'error', 'msg' => sprintf( _("LDAP Error: %s"), ldap_error($ldap)));
} else {
$msgs[] = array('class' => 'success', 'msg' => _("Account has been modified successfully.") );
}
}
$secondaryAccounts = array();
//---------
if (!empty($config->ldap->secondary_accounts )) {
$secondaryAccounts = $arcanumLdap->getSecondaryAccounts($uid);
/*
foreach($config->ldap->secondary_accounts->toArray() as $method => $ldapattr ) {
$secondaryAccounts[$method] = strtolower($ldapattr);
}
*/
}
//------------
$allattrs = array_merge($config->admin->show_attrs->toArray(), array('objectclass', $config->ldap->passwordAttribute),
array_keys($arcanumLdap->pwAttributes));
$filter = sprintf($config->ldap->filter->user, ldapspecialchars($uid));
if ($restrict) {
$filter = '(&'.$filter.$restrict['apply'].')';
}
$sr = ldap_search($ldap, $config->ldap->basedn, $filter, array_merge($allattrs, array('+')));
$entries = ldap_get_entries($ldap, $sr);
Arcanum_Ldap::sanitize_entry_array($entries);
if ($entries['count'] != 1) {
$msgs[] = array('class' => 'warning', 'msg' => _("Username not found") );
} else {
$info = array('dn' => $entries[0]['dn']);
foreach($allattrs as $a) {
$attr = strtolower($a);
if (isset($entries[0][$attr]) && $entries[0][$attr]['count'] > 0) {
$info[$attr] = array();
for($i=0; $i<$entries[0][$attr]['count']; $i++) {
$info[$attr][] = $entries[0][$attr][$i];
}
}
}
//$info = $entries[0];
}
}
$exported_display_vars = array();
foreach($config->admin->summary_attrs->toArray() as $attr) {
$exported_display_vars[$attr] = $arcanumLdap->attributes[$attr]['desc'];
}
$inlinejavascript = 'var summaryAttrs = '.json_encode($exported_display_vars) .';';
$enable_advanced_search = false;
if ($role == 'admin_policy') {
// Enable advanced search
$enable_advanced_search = true;
$premade_filters = array(
array(
sprintf( $config->ldap->filter->user, '*'),
_("All users")
),
array(
sprintf( $config->ldap->filter->user, 'a*'),
_("Users with username starting with a")
)
);
if(!empty($config->ldap->filter->user_receivesms)) {
$premade_filters[] = array(
sprintf( $config->ldap->filter->user_receivesms, '*'),
_("Users that are allowed to receive SMS")
);
}
if($config->ldap->restrictfilters) {
$tmp = $config->ldap->restrictfilters->toArray();
if (!empty($tmp)) {
foreach($tmp as $no => $rf) {
$premade_filters[] = array(
'(&' . sprintf( $config->ldap->filter->user, '*' ) . $rf['apply'] . ')',
$rf['description']
);
}
unset($no);
unset($rf);
}
unset($tmp);
}
$t->assign('premade_filters', $premade_filters);
}
$t->assign('enable_advanced_search', $enable_advanced_search);
// =================
// FIXME - Perhaps I should export this more elegantly.
$t->assign('arcanumLdap', $arcanumLdap);
$t->assign('javascripts',
array_merge(
$defaultJavascripts, array(
'javascripts/admin_change_password.js',
'javascripts/admin_choose_user.js'
)
));
$t->assign('inlinejavascript', $inlinejavascript);
$t->assign('policies', $policies);
$t->display('html_header');
$t->display('page_header_admin');
$t->assign('uid', $uid);
if (!empty($msgs)) {
$t->assign('msgs', $msgs);
$t->display('messages');
}
if (!isset($info)) {
$t->display('admin_choose_user');
} else {
$t->assign('show_pwdreset_form', $show_pwdreset_form);
$t->assign('pwAttrs', $arcanumLdap->pwAttributes);
$t->assign('secondaryAccounts', $secondaryAccounts);
$t->assign('userinfo', $entries[0]);
$t->assign('show_attrs', $config->admin->show_attrs->toArray());
$t->assign('info', $info);
$t->display('admin_show_user');
}
$t->display('page_footer_admin');
$t->display('html_footer');