-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathuser.inc
1286 lines (1214 loc) · 49.3 KB
/
user.inc
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
/*
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2005 - 2019 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/**
* The account type for user accounts (e.g. Unix, Samba and Kolab).
*
* @package types
* @author Roland Gruber
*/
/**
* The account type for user accounts (e.g. Unix, Samba and Kolab).
*
* @package types
*/
class user extends baseType {
/**
* Constructs a new user type object.
*
* @param ConfiguredType $type configuration
*/
public function __construct($type) {
parent::__construct($type);
$this->LABEL_CREATE_ANOTHER_ACCOUNT = _('Create another user');
$this->LABEL_BACK_TO_ACCOUNT_LIST = _('Back to user list');
}
/**
* Returns the alias name of this account type.
*
* @return string alias name
*/
function getAlias() {
return _("Users");
}
/**
* Returns the description of this account type.
*
* @return string description
*/
function getDescription() {
return _("User accounts (e.g. Unix, Samba and Kolab)");
}
/**
* Returns the class name for the list object.
*
* @return string class name
*/
function getListClassName() {
return "lamUserList";
}
/**
* Returns the default attribute list for this account type.
*
* @return string attribute list
*/
function getDefaultListAttributes() {
return "#uid;#givenName;#sn;#uidNumber;#gidNumber";
}
/**
* Returns a list of attributes which have a translated description.
* This is used for the head row in the list view.
*
* @return array list of descriptions
*/
function getListAttributeDescriptions() {
return array_merge(
parent::getListAttributeDescriptions(),
array(
"cn" => _("Common name"),
'company' => _('Company'),
'departmentNumber' => _('Department'),
'displayName' => _('Display name'),
'employeeNumber' => _('Employee number'),
"gecos" => _("Description"),
"gidnumber" => _("GID number"),
"givenname" => _("First name"),
"homedirectory" => _("Home directory"),
"host" => _("Allowed hosts"),
"jpegphoto" => _('Photo'),
"loginshell" => _("Login shell"),
"mail" => _("Email"),
'manager' => _('Manager'),
'o' => _('Organisation'),
'ou' => _('Organisational unit'),
'proxyAddresses' => _('Proxy-Addresses'),
'sambakickofftime' => _('Account expiration date'),
'shadowexpire' => _('Password expiration'),
"sn" => _("Last name"),
'streetAddress' => _('Street'),
'telephoneNumber' => _('Telephone number'),
'title' => _('Job title'),
"uid" => _("User name"),
"uidnumber" => _("UID number"),
'userPrincipalName' => _('User name'),
));
}
/**
* Returns the the title text for the title bar on the new/edit page.
*
* @param accountContainer $container account container
* @return String title text
*/
public function getTitleBarTitle($container) {
// get attributes
$personalAttributes = null;
if ($container->getAccountModule('inetOrgPerson') != null) {
$personalAttributes = $container->getAccountModule('inetOrgPerson')->getAttributes();
}
elseif ($container->getAccountModule('windowsUser') != null) {
$personalAttributes = $container->getAccountModule('windowsUser')->getAttributes();
}
$accountAttributes = null;
if ($container->getAccountModule('account') != null) {
$accountAttributes = $container->getAccountModule('account')->getAttributes();
}
$sambaAttributes = null;
if ($container->getAccountModule('sambaSamAccount') != null) {
$sambaAttributes = $container->getAccountModule('sambaSamAccount')->getAttributes();
}
$unixAttributes = null;
if ($container->getAccountModule('posixAccount') != null) {
$unixAttributes = $container->getAccountModule('posixAccount')->getAttributes();
}
$mitKerberosAttributes = null;
if ($container->getAccountModule('mitKerberosStructural') != null) {
$mitKerberosAttributes = $container->getAccountModule('mitKerberosStructural')->getAttributes();
}
elseif ($container->getAccountModule('mitKerberos') != null) {
$mitKerberosAttributes = $container->getAccountModule('mitKerberos')->getAttributes();
}
// check if first and last name can be shown
if (($personalAttributes != null) && isset($personalAttributes['sn'][0]) && !empty($personalAttributes['sn'][0])
&& isset($personalAttributes['givenName'][0]) && !empty($personalAttributes['givenName'][0])) {
return htmlspecialchars($personalAttributes['givenName'][0] . ' ' . $personalAttributes['sn'][0]);
}
// check if a display name is set
if (($sambaAttributes != null) && isset($sambaAttributes['displayName'][0]) && !empty($sambaAttributes['displayName'][0])) {
return htmlspecialchars($sambaAttributes['displayName'][0]);
}
// check if a common name is set
if (($personalAttributes != null) && isset($personalAttributes['cn'][0]) && !empty($personalAttributes['cn'][0])) {
return htmlspecialchars($personalAttributes['cn'][0]);
}
if (($unixAttributes != null) && isset($unixAttributes['cn'][0]) && !empty($unixAttributes['cn'][0])) {
return htmlspecialchars($unixAttributes['cn'][0]);
}
// check if a user name is set
if (($unixAttributes != null) && isset($unixAttributes['uid'][0]) && !empty($unixAttributes['uid'][0])) {
return htmlspecialchars($unixAttributes['uid'][0]);
}
if (($personalAttributes != null) && isset($personalAttributes['uid'][0]) && !empty($personalAttributes['uid'][0])) {
return htmlspecialchars($personalAttributes['uid'][0]);
}
if (($accountAttributes != null) && isset($accountAttributes['uid'][0]) && !empty($accountAttributes['uid'][0])) {
return htmlspecialchars($accountAttributes['uid'][0]);
}
if (($mitKerberosAttributes != null) && isset($mitKerberosAttributes['krbPrincipalName'][0]) && !empty($mitKerberosAttributes['krbPrincipalName'][0])) {
return htmlspecialchars($mitKerberosAttributes['krbPrincipalName'][0]);
}
if ($container->isNewAccount) {
return _("New user");
}
// fall back to default
return parent::getTitleBarTitle($container);
}
/**
* Returns the the title text for the title bar on the new/edit page.
*
* @param accountContainer $container account container
* @return String title text
*/
public function getTitleBarSubtitle($container) {
$personalAttributes = null;
if ($container->getAccountModule('inetOrgPerson') != null) {
$personalAttributes = $container->getAccountModule('inetOrgPerson')->getAttributes();
}
elseif ($container->getAccountModule('windowsUser') != null) {
$personalAttributes = $container->getAccountModule('windowsUser')->getAttributes();
}
if ($personalAttributes == null) {
return $this->buildAccountStatusIcon($container);
}
$subtitle = $this->buildAccountStatusIcon($container);
$spacer = ' ';
// check if an email address can be shown
if (isset($personalAttributes['mail'][0]) && !empty($personalAttributes['mail'][0])) {
$subtitle .= '<a href="mailto:' . htmlspecialchars($personalAttributes['mail'][0]) . '">' . htmlspecialchars($personalAttributes['mail'][0]) . '</a>' . $spacer;
}
// check if an telephone number can be shown
if (isset($personalAttributes['telephoneNumber'][0]) && !empty($personalAttributes['telephoneNumber'][0])) {
$subtitle .= _('Telephone number') . ' ' . htmlspecialchars($personalAttributes['telephoneNumber'][0]) . $spacer;
}
// check if an mobile number can be shown
if (isset($personalAttributes['mobile'][0]) && !empty($personalAttributes['mobile'][0])) {
$subtitle .= _('Mobile number') . ' ' . htmlspecialchars($personalAttributes['mobile'][0]);
}
if ($subtitle == '') {
return null;
}
return $subtitle;
}
/**
* Builds the HTML code for the icon that shows the account status (locked/unlocked).
*
* @param accountContainer $container account container
* @return String HTML code for icon
*/
private function buildAccountStatusIcon($container) {
$modules = $this->getType()->getModules();
// check if there are account parts that can be locked
$unixAvailable = ($container->getAccountModule('posixAccount') != null) && $container->getAccountModule('posixAccount')->isLockable($modules);
$sambaAvailable = (($container->getAccountModule('sambaSamAccount') != null) && $container->getAccountModule('sambaSamAccount')->isExtensionEnabled());
$ppolicyAvailable = ($container->getAccountModule('ppolicyUser') != null);
$windowsAvailable = ($container->getAccountModule('windowsUser') != null);
$is389dsAvailable = ($container->getAccountModule('locking389ds') != null);
$is389dsLocked = $is389dsAvailable && $container->getAccountModule('locking389ds')->isLocked();
$is389dsDeactivated = $is389dsAvailable && $container->getAccountModule('locking389ds')->isDeactivated();
$is389dsPwdExpired = $is389dsAvailable && locking389ds::isPasswordExpired($container->getAccountModule('locking389ds')->getAttributes());
if (!$unixAvailable && !$sambaAvailable && !$ppolicyAvailable && !$windowsAvailable && !$is389dsAvailable) {
return '';
}
$isEditable = checkIfWriteAccessIsAllowed('user') && ($unixAvailable || $sambaAvailable || $ppolicyAvailable || $windowsAvailable || $is389dsAvailable);
// get locking status
$unixLocked = false;
if ($unixAvailable && $container->getAccountModule('posixAccount')->isLocked($modules)) {
$unixLocked = true;
}
$sambaLocked = false;
if ($sambaAvailable && $container->getAccountModule('sambaSamAccount')->isDeactivated()) {
$sambaLocked = true;
}
$ppolicyLocked = false;
if ($ppolicyAvailable && $container->getAccountModule('ppolicyUser')->isLocked()) {
$ppolicyLocked = true;
}
$windowsLocked = false;
$windowsPasswordLockedTime = null;
$windowsPasswordLocked = false;
if ($windowsAvailable){
$attrs = $container->getAccountModule('windowsUser')->getAttributes();
$attrs['dn'] = $container->dn_orig;
if (windowsUser::isDeactivated($attrs)) {
$windowsLocked = true;
}
$windowsPasswordLockedTime = windowsUser::getPasswordLocked($attrs, $this->getType());
if ($windowsPasswordLockedTime != null) {
$windowsPasswordLocked = true;
}
}
$partiallyLocked = $unixLocked || $sambaLocked
|| $ppolicyLocked || $windowsLocked || $windowsPasswordLocked
|| $is389dsDeactivated || $is389dsLocked || $is389dsPwdExpired;
$fullyLocked = ($unixAvailable || $sambaAvailable || $ppolicyAvailable || $windowsAvailable || $is389dsDeactivated || $is389dsLocked)
&& (!$unixAvailable || $unixLocked)
&& (!$sambaAvailable || $sambaLocked)
&& (!$ppolicyAvailable || $ppolicyLocked)
&& (!$windowsAvailable || $windowsLocked);
// build tooltip
$icon = 'unlocked.png';
if ($fullyLocked) {
$icon = 'lock.png';
}
elseif ($partiallyLocked) {
$icon = 'partiallyLocked.png';
}
$statusTable = '<table border=0>';
// Unix
if ($unixAvailable) {
$unixIcon = 'unlocked.png';
if ($unixLocked) {
$unixIcon = 'lock.png';
}
$statusTable .= '<tr><td>' . _('Unix') . ' </td><td><img height=16 width=16 src="../../graphics/' . $unixIcon . '"></td></tr>';
}
// Samba
if ($sambaAvailable) {
$sambaIcon = 'unlocked.png';
if ($sambaLocked) {
$sambaIcon = 'lock.png';
}
$statusTable .= '<tr><td>' . _('Samba 3') . ' </td><td><img height=16 width=16 src="../../graphics/' . $sambaIcon . '"></td></tr>';
}
// PPolicy
if ($ppolicyAvailable) {
$ppolicyIcon = 'unlocked.png';
if ($ppolicyLocked) {
$ppolicyIcon = 'lock.png';
}
$statusTable .= '<tr><td>' . _('Password policy') . ' </td><td><img height=16 width=16 src="../../graphics/' . $ppolicyIcon . '"></td></tr>';
}
// Windows
if ($windowsAvailable) {
$windowsIcon = 'unlocked.png';
if ($windowsLocked) {
$windowsIcon = 'lock.png';
}
$statusTable .= '<tr><td>' . _('Windows') . ' </td><td><img height=16 width=16 src="../../graphics/' . $windowsIcon . '"></td></tr>';
}
if ($windowsAvailable && $windowsPasswordLocked) {
$statusTable .= '<tr><td>' . _('Locked till') . ' </td><td>' . $windowsPasswordLockedTime->format('Y-m-d H:i:s') . '</td></tr>';
}
// 389ds locked
if ($is389dsLocked) {
$statusTable .= '<tr><td>' . _('Locked') . ' </td><td><img height=16 width=16 src="../../graphics/lock.png"></td></tr>';
}
// 389ds deactivated
if ($is389dsAvailable) {
$text389dsActivation = $is389dsDeactivated ? _('Deactivated') : _('Active');
$icon389dsActivation = $is389dsDeactivated ? 'lock.png' : 'unlocked.png';
$statusTable .= '<tr><td>' . $text389dsActivation . ' </td><td><img height=16 width=16 src="../../graphics/' . $icon389dsActivation . '"></td></tr>';
}
// 389ds password expired
if ($is389dsPwdExpired) {
$statusTable .= '<tr><td>' . _('Password expired') . ' </td><td><img height=16 width=16 src="../../graphics/lock.png"></td></tr>';
}
$statusTable .= '</table>';
$tipContent = $statusTable;
if ($isEditable) {
$tipContent .= '<br><img alt="hint" src="../../graphics/light.png"> ';
$tipContent .= _('Please click to lock/unlock this account.');
}
$dialogDiv = $this->buildAccountStatusDialogDiv($unixAvailable, $unixLocked, $sambaAvailable, $sambaLocked,
$ppolicyAvailable, $ppolicyLocked, $windowsAvailable, $windowsLocked, $windowsPasswordLockedTime,
$is389dsAvailable, $is389dsLocked, $is389dsDeactivated, $is389dsPwdExpired);
$onClick = '';
if ($isEditable) {
$onClick = 'onclick="showConfirmationDialog(\'' . _('Change account status') . '\', \'' . _('Ok') . '\', \'' . _('Cancel') . '\', \'lam_accountStatusDialog\', \'inputForm\', \'lam_accountStatusResult\');"';
}
$dialogDiv .= '<a href="#"><img id="lam_accountStatus" alt="status" ' . $onClick . ' helptitle="' . _('Account status') . '" helpdata="' . $tipContent . '" height=16 width=16 src="../../graphics/' . $icon . '"></a> ';
// expiration status
$expiredLabels = array();
$shadowModule = $container->getAccountModule('shadowAccount');
if ($shadowModule != null) {
$shadowAttrs = $shadowModule->getAttributes();
if (shadowAccount::isAccountExpired($shadowAttrs)) {
$expiredLabels[] = _('Shadow') . ': ' . _('Account expiration');
}
elseif (shadowAccount::isPasswordExpired($shadowAttrs)) {
$expiredLabels[] = _('Shadow') . ': ' . _('Password expiration');
}
}
$windowsModule = $container->getAccountModule('windowsUser');
if ($windowsModule != null) {
$windowsAttrs = $windowsModule->getAttributes();
if (windowsUser::isAccountExpired($windowsAttrs)) {
$expiredLabels[] = _('Windows') . ': ' . _('Account expiration');
}
}
if (!empty($expiredLabels)) {
$expiredTip = '<table border=0>';
foreach ($expiredLabels as $label) {
$expiredTip .= '<tr><td>' . $label . '</td><td><img src="../../graphics/expired.png"/></td></tr>';
}
$expiredTip .= '</table>';
$dialogDiv .= '<img alt="expired" helptitle="' . _('Expired') . '" helpdata="' . $expiredTip . '" height=16 width=16 src="../../graphics/expired.png"> ';
}
return $dialogDiv;
}
/**
* Builds the dialog to (un)lock parts of an account.
*
* @param boolean $unixAvailable Unix part is active
* @param boolean $unixLocked Unix part is locked
* @param boolean $sambaAvailable Samba part is active
* @param boolean $sambaLocked Samba part is locked
* @param boolean $ppolicyAvailable PPolicy part is active
* @param boolean $ppolicyLocked PPolicy part is locked
* @param boolean $windowsAvailable Windows part is active
* @param boolean $windowsLocked Windows part is locked
* @param DateTime $windowsPasswordLockedTime lock time for Windows or null
* @param boolean $is389dsAvailable 389ds is available
* @param boolean $is389dsLocked account is locked
* @param boolean $is389dsDeactivated account is deactivated
* @param boolean $is389dsPwdExpired password expired
*/
private function buildAccountStatusDialogDiv($unixAvailable, $unixLocked, $sambaAvailable, $sambaLocked, $ppolicyAvailable, $ppolicyLocked, $windowsAvailable,
$windowsLocked, $windowsPasswordLockedTime, $is389dsAvailable, $is389dsLocked, $is389dsDeactivated, $is389dsPwdExpired) {
$windowsPasswordLocked = ($windowsPasswordLockedTime != null);
$partiallyLocked = $unixLocked || $sambaLocked || $ppolicyLocked || $windowsLocked || $windowsPasswordLocked || $is389dsLocked || $is389dsDeactivated || $is389dsPwdExpired;
$fullyLocked = ($unixAvailable || $sambaAvailable || $ppolicyAvailable || $windowsAvailable || $is389dsLocked || $is389dsDeactivated)
&& (!$unixAvailable || $unixLocked)
&& (!$sambaAvailable || $sambaLocked)
&& (!$ppolicyAvailable || $ppolicyLocked)
&& (!$windowsAvailable || $windowsLocked || $windowsPasswordLocked);
$container = new htmlResponsiveRow();
// show radio buttons for lock/unlock
$radioDisabled = true;
$selectedRadio = 'unlock';
$onchange = '';
if ($partiallyLocked && !$fullyLocked) {
$radioDisabled = false;
$onchange = 'if (jQuery(\'#lam_accountStatusAction0:checked\').val()) {' .
'jQuery(\'#lam_accountStatusDialogLockDiv\').removeClass(\'hidden\');' .
'jQuery(\'#lam_accountStatusDialogUnlockDiv\').addClass(\'hidden\');' .
'}' .
'else {' .
'jQuery(\'#lam_accountStatusDialogLockDiv\').addClass(\'hidden\');' .
'jQuery(\'#lam_accountStatusDialogUnlockDiv\').removeClass(\'hidden\');' .
'};';
}
if (!$fullyLocked && !$partiallyLocked) {
$selectedRadio = 'lock';
}
if (!$radioDisabled) {
$radio = new htmlRadio('lam_accountStatusAction', array(_('Lock') => 'lock', _('Unlock') => 'unlock'), $selectedRadio);
$radio->setOnchangeEvent($onchange);
$container->add($radio, 12);
}
else {
$radio = new htmlRadio('lam_accountStatusActionDisabled', array(_('Lock') => 'lock', _('Unlock') => 'unlock'), $selectedRadio);
$radio->setIsEnabled(false);
$container->add($radio, 12);
$container->add(new htmlHiddenInput('lam_accountStatusAction', $selectedRadio), 12);
}
$container->add(new htmlHiddenInput('lam_accountStatusResult', 'cancel'), 12);
// locking part
if (!$fullyLocked) {
$lockContent = new htmlTable();
if ($unixAvailable && !$unixLocked) {
$lockContent->addElement(new htmlImage('../../graphics/tux.png'));
$lockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusLockUnix', true, _('Unix'), null, false), true);
}
if ($sambaAvailable && !$sambaLocked) {
$lockContent->addElement(new htmlImage('../../graphics/samba.png'));
$lockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusLockSamba', true, _('Samba 3'), null, false), true);
}
if ($ppolicyAvailable && !$ppolicyLocked) {
$lockContent->addElement(new htmlImage('../../graphics/security.png'));
$lockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusLockPPolicy', true, _('PPolicy'), null, false), true);
}
if ($is389dsAvailable && !$is389dsDeactivated) {
$lockContent->addElement(new htmlImage('../../graphics/security.png'));
$lockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusDeactivate389ds', true, _('Deactivate'), null, false), true);
}
if ($windowsAvailable && !$windowsLocked) {
$lockContent->addElement(new htmlImage('../../graphics/samba.png'));
$lockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusLockWindows', true, _('Windows'), null, false), true);
}
if ($unixAvailable) {
$lockContent->addElement(new htmlImage('../../graphics/groupBig.png'));
$lockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusRemoveUnixGroups', true, _('Remove from all Unix groups'), null, false), true);
}
if ($unixAvailable && posixAccount::areGroupOfNamesActive()) { // check unixAvailable because Unix module removes group memberships
$lockContent->addElement(new htmlImage('../../graphics/groupBig.png'));
$lockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusRemoveGONGroups', true, _('Remove from all group of (unique) names'), null, false), true);
}
$lockDiv = new htmlDiv('lam_accountStatusDialogLockDiv', $lockContent);
if ($fullyLocked || $partiallyLocked) {
$lockDiv->setCSSClasses(array('hidden'));
}
$container->add($lockDiv, 12);
}
// unlocking part
if ($partiallyLocked) {
$unlockContent = new htmlTable();
if ($unixAvailable && $unixLocked) {
$unlockContent->addElement(new htmlImage('../../graphics/tux.png'));
$unlockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusUnlockUnix', true, _('Unix'), null, false), true);
}
if ($sambaAvailable && $sambaLocked) {
$unlockContent->addElement(new htmlImage('../../graphics/samba.png'));
$unlockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusUnlockSamba', true, _('Samba 3'), null, false), true);
}
if ($ppolicyAvailable && $ppolicyLocked) {
$unlockContent->addElement(new htmlImage('../../graphics/security.png'));
$unlockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusUnlockPPolicy', true, _('PPolicy'), null, false), true);
}
if ($is389dsAvailable && $is389dsDeactivated) {
$unlockContent->addElement(new htmlImage('../../graphics/security.png'));
$unlockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusActivate389ds', true, _('Activate'), null, false), true);
}
if ($is389dsAvailable && $is389dsPwdExpired) {
$unlockContent->addElement(new htmlImage('../../graphics/security.png'));
$unlockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusPwdUnexpire389ds', true, _('Clear password expiration'), null, false), true);
}
if ($windowsAvailable && $windowsLocked) {
$unlockContent->addElement(new htmlImage('../../graphics/samba.png'));
$unlockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusUnlockWindows', true, _('Windows'), null, false), true);
}
if ($windowsAvailable && $windowsPasswordLocked) {
$unlockContent->addElement(new htmlImage('../../graphics/samba.png'));
$unlockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusUnlockWindowsPassword', true, _('Locked till') . ' ' . $windowsPasswordLockedTime->format('Y-m-d H:i:s'), null, false), true);
}
if ($is389dsLocked) {
$unlockContent->addElement(new htmlImage('../../graphics/security.png'));
$unlockContent->addElement(new htmlTableExtendedInputCheckbox('lam_accountStatusUnlock389ds', true, _('Unlock'), null, false), true);
}
$unlockDiv = new htmlDiv('lam_accountStatusDialogUnlockDiv', $unlockContent);
if (!$fullyLocked && !$partiallyLocked) {
$unlockDiv->setCSSClasses(array('hidden'));
}
$container->add($unlockDiv, 12);
}
$div = new htmlDiv('lam_accountStatusDialog', $container);
$div->setCSSClasses(array('hidden'));
$tabindex = 999;
ob_start();
parseHtml(null, $div, array(), false, $tabindex, 'user');
$output = ob_get_contents();
ob_clean();
return $output;
}
/**
* This function is called after the edit page is processed and before the page content is generated.
* This can be used to run custom handlers after each page processing.
*
* @param accountContainer $container account container
*/
public function runEditPagePostAction(&$container) {
$modules = $this->getType()->getModules();
// check if account status should be changed
if (isset($_POST['lam_accountStatusResult']) && ($_POST['lam_accountStatusResult'] == 'ok')) {
// lock account
if ($_POST['lam_accountStatusAction'] == 'lock') {
// Unix
if (isset($_POST['lam_accountStatusLockUnix']) && ($_POST['lam_accountStatusLockUnix'] == 'on')) {
$container->getAccountModule('posixAccount')->lock($modules);
}
// Samba
if (isset($_POST['lam_accountStatusLockSamba']) && ($_POST['lam_accountStatusLockSamba'] == 'on')) {
$container->getAccountModule('sambaSamAccount')->deactivate();
}
// PPolicy
if (isset($_POST['lam_accountStatusLockPPolicy']) && ($_POST['lam_accountStatusLockPPolicy'] == 'on')) {
$container->getAccountModule('ppolicyUser')->lock();
}
// 389ds
if (isset($_POST['lam_accountStatusDeactivate389ds']) && ($_POST['lam_accountStatusDeactivate389ds'] == 'on')) {
$container->getAccountModule('locking389ds')->deactivate();
}
// Windows
if (isset($_POST['lam_accountStatusLockWindows']) && ($_POST['lam_accountStatusLockWindows'] == 'on')) {
$container->getAccountModule('windowsUser')->setIsDeactivated(true);
}
// remove Unix groups
if (isset($_POST['lam_accountStatusRemoveUnixGroups']) && ($_POST['lam_accountStatusRemoveUnixGroups'] == 'on')) {
$container->getAccountModule('posixAccount')->removeFromUnixGroups();
}
// remove group of names memberships
if (isset($_POST['lam_accountStatusRemoveGONGroups']) && ($_POST['lam_accountStatusRemoveGONGroups'] == 'on')) {
$container->getAccountModule('posixAccount')->removeFromGONGroups();
}
}
// unlock account
elseif ($_POST['lam_accountStatusAction'] == 'unlock') {
// Unix
if (isset($_POST['lam_accountStatusUnlockUnix']) && ($_POST['lam_accountStatusUnlockUnix'] == 'on')) {
$container->getAccountModule('posixAccount')->unlock($modules);
}
// Samba
if (isset($_POST['lam_accountStatusUnlockSamba']) && ($_POST['lam_accountStatusUnlockSamba'] == 'on')) {
$container->getAccountModule('sambaSamAccount')->activate();
}
// PPolicy
if (isset($_POST['lam_accountStatusUnlockPPolicy']) && ($_POST['lam_accountStatusUnlockPPolicy'] == 'on')) {
$container->getAccountModule('ppolicyUser')->unlock();
}
// 389ds
if (isset($_POST['lam_accountStatusActivate389ds']) && ($_POST['lam_accountStatusActivate389ds'] == 'on')) {
$container->getAccountModule('locking389ds')->activate();
}
if (isset($_POST['lam_accountStatusPwdUnexpire389ds']) && ($_POST['lam_accountStatusPwdUnexpire389ds'] == 'on')) {
$container->getAccountModule('locking389ds')->clearPasswordExpiration();
}
// Windows
if (isset($_POST['lam_accountStatusUnlockWindows']) && ($_POST['lam_accountStatusUnlockWindows'] == 'on')) {
$container->getAccountModule('windowsUser')->setIsDeactivated(false);
}
// Windows password
if (isset($_POST['lam_accountStatusUnlockWindowsPassword']) && ($_POST['lam_accountStatusUnlockWindowsPassword'] == 'on')) {
$container->getAccountModule('windowsUser')->unlockPassword();
}
// 389ds unlocking
if (isset($_POST['lam_accountStatusUnlock389ds']) && ($_POST['lam_accountStatusUnlock389ds'] == 'on')) {
$container->getAccountModule('locking389ds')->unlock(false);
}
}
}
}
}
/**
* Generates the list view.
*
* @package lists
* @author Roland Gruber
*
*/
class lamUserList extends lamList {
/** Controls if GID number is translated to group name */
private $trans_primary = false;
/** Controls if the account status is shown */
private $showAccountStatus = false;
/** translates GID to group name */
private $trans_primary_hash = array();
/** filter value for account status */
private $accountStatusFilter = null;
/** ID for config option to translate primary group GIDs to group names */
const TRANS_PRIMARY_OPTION_NAME = "LU_TP";
/** ID for config option to show account status */
const ACCOUNT_STATUS_OPTION_NAME = "LU_AS";
/** virtual attribute name for account status column */
const ATTR_ACCOUNT_STATUS = 'lam_virtual_account_status';
/** filter value for expired accounts */
const FILTER_EXPIRED = 1;
/** filter value for locked accounts */
const FILTER_LOCKED = 2;
/** filter value for partially locked accounts */
const FILTER_SEMILOCKED = 3;
/** filter value for unlocked accounts */
const FILTER_UNLOCKED = 4;
/**
* Constructor
*
* @param string $type account type
* @return lamList list object
*/
public function __construct($type) {
parent::__construct($type);
$this->labels = array(
'nav' => _("User count: %s"),
'error_noneFound' => _("No users found!"),
'newEntry' => _("New user"),
'deleteEntry' => _("Delete selected users"));
}
/**
* Sets some internal parameters.
*/
protected function listGetParams() {
parent::listGetParams();
// generate hash table for group translation
if ($this->trans_primary == "on" && !$this->refresh && (sizeof($this->trans_primary_hash) == 0)) {
$this->refreshPrimaryGroupTranslation();
}
}
/**
* Rereads the entries from LDAP.
*/
protected function listRefreshData() {
parent::listRefreshData();
// show group names
if ($this->trans_primary == "on") {
$this->refreshPrimaryGroupTranslation();
}
// show account status
if ($this->showAccountStatus) {
$this->injectAccountStatusAttribute();
}
}
/**
* Refreshes the GID to group name cache.
*/
protected function refreshPrimaryGroupTranslation() {
$this->trans_primary_hash = array();
$filter = "objectClass=groupOfNames";
$attrs = array("cn", "gidNumber");
$entries = searchLDAPByAttribute(null, null, 'groupOfNames', $attrs, array('group'));
$entryCount = sizeof($entries);
for ($i = 0; $i < $entryCount; $i++) {
$this->trans_primary_hash[$entries[$i]['gidnumber'][0]] = $entries[$i]['cn'][0];
}
}
/**
* {@inheritDoc}
* @see lamList::getTableCellContent()
*/
protected function getTableCellContent(&$entry, &$attribute) {
// check if there is something to display at all
if (($attribute != self::ATTR_ACCOUNT_STATUS) && (!isset($entry[$attribute]) || !is_array($entry[$attribute]) || (sizeof($entry[$attribute]) < 1))) {
return parent::getTableCellContent($entry, $attribute);
}
// translate GID to group name
if (($attribute == "gidnumber") && ($this->trans_primary == "on")) {
if (isset($this->trans_primary_hash[$entry[$attribute][0]])) {
return new htmlOutputText($this->trans_primary_hash[$entry[$attribute][0]]);
}
else {
return parent::getTableCellContent($entry, $attribute);
}
}
// show user photos
elseif (($attribute == "jpegphoto") && (!empty($entry[$attribute][0]))) {
if (strlen($entry[$attribute][0]) < 100) {
// looks like we have read broken binary data, reread photo
$result = @ldap_read($_SESSION['ldap']->server(), escapeDN($entry['dn']), $attribute . "=*", array($attribute), 0, 0, 0, LDAP_DEREF_NEVER);
if ($result) {
$tempEntry = @ldap_first_entry($_SESSION['ldap']->server(), $result);
if ($tempEntry) {
$binData = ldap_get_values_len($_SESSION['ldap']->server(), $tempEntry, $attribute);
$entry[$attribute] = $binData;
}
}
}
$imgNumber = getRandomNumber();
$jpeg_filename = 'jpg' . $imgNumber . '.jpg';
$outjpeg = @fopen(dirname(__FILE__) . '/../../tmp/' . $jpeg_filename, "wb");
fwrite($outjpeg, $entry[$attribute][0]);
fclose ($outjpeg);
$photoFile = '../../tmp/' . $jpeg_filename;
$image = new htmlImage($photoFile);
$image->enableLightbox();
$image->setCSSClasses(array('thumbnail'));
return $image;
}
elseif (($attribute == 'mail') || ($attribute == 'rfc822Mailbox')) {
$group = new htmlGroup();
if (isset($entry[$attribute][0]) && ($entry[$attribute][0] != '')) {
for ($i = 0; $i < sizeof($entry[$attribute]); $i++) {
if ($i > 0) {
$group->addElement(new htmlOutputText(", "));
}
$group->addElement(new htmlLink($entry[$attribute][$i], "mailto:" . $entry[$attribute][$i]));
}
}
return $group;
}
// expire dates
elseif ($attribute == 'shadowexpire') {
if (!empty($entry[$attribute][0])) {
$time = new DateTime('@' . $entry[$attribute][0] * 24 * 3600, getTimeZone());
return new htmlOutputText($time->format('d.m.Y'));
}
}
elseif ($attribute == 'sambakickofftime') {
if (!empty($entry[$attribute][0])) {
if ($entry[$attribute][0] > 2147483648) {
return new htmlOutputText("∞");
}
else {
$date = new DateTime('@' . $entry[$attribute][0], new DateTimeZone('UTC'));
return new htmlOutputText($date->format('d.m.Y'));
}
}
}
// account status
elseif ($attribute == self::ATTR_ACCOUNT_STATUS) {
return $this->getAccountStatus($entry);
}
// print all other attributes
else {
return parent::getTableCellContent($entry, $attribute);
}
}
/**
* Returns a list of lamListTool objects to display next to the edit/delete buttons.
*
* @return lamListTool[] tools
*/
protected function getAdditionalTools() {
if (!isLAMProVersion()) {
return array();
}
if (checkIfWriteAccessIsAllowed('user') || (checkIfPasswordChangeIsAllowed() && !checkIfWriteAccessIsAllowed())) {
$passwordTool = new lamListTool(_('Change password'), 'key.png', 'changePassword.php');
return array($passwordTool);
}
return array();
}
/**
* Returns a list of possible configuration options.
*
* @return array list of lamListOption objects
*/
protected function listGetAllConfigOptions() {
$options = parent::listGetAllConfigOptions();
$options[] = new lamBooleanListOption(_('Translate GID number to group name'), self::TRANS_PRIMARY_OPTION_NAME);
$options[] = new lamBooleanListOption(_('Show account status'), self::ACCOUNT_STATUS_OPTION_NAME);
return $options;
}
/**
* Called when the configuration options changed.
*/
protected function listConfigurationChanged() {
parent::listConfigurationChanged();
$tpOption = $this->listGetConfigOptionByID(self::TRANS_PRIMARY_OPTION_NAME);
$this->trans_primary = $tpOption->isSelected();
$asOption = $this->listGetConfigOptionByID(self::ACCOUNT_STATUS_OPTION_NAME);
// if account status was activated, reload LDAP data
$asOptionOldValue = $this->showAccountStatus;
$this->showAccountStatus = $asOption->isSelected();
if ($this->showAccountStatus && !$asOptionOldValue) {
$this->forceRefresh();
}
}
/**
* Returns an hash array containing with all attributes to be shown and their descriptions.
* <br>Format: array(attribute => description)
* <br>
* <br>The user list may display an additional account status column
*
* @return array attribute list
*/
protected function listGetAttributeDescriptionList() {
$list = parent::listGetAttributeDescriptionList();
if ($this->showAccountStatus) {
$list[self::ATTR_ACCOUNT_STATUS] = _('Account status');
}
return $list;
}
/**
* Returns if the given attribute can be filtered.
* If filtering is not possible then no filter box will be displayed.
* <br>
* <br>The user list allows no filtering for account status.
*
* @param String $attr attribute name
* @return boolean filtering possible
*/
protected function canBeFiltered($attr) {
if (strtolower($attr) == 'jpegphoto') {
return false;
}
return true;
}
/**
* Prints the content of a single attribute filter area.
*
* @param String $attrName attribute name
* @param boolean $clearFilter true if filter value should be cleared
*/
protected function printFilterArea($attrName, $clearFilter) {
if ($attrName != self::ATTR_ACCOUNT_STATUS) {
parent::printFilterArea($attrName, $clearFilter);
return;
}
$value = "-";
if (!$clearFilter) {
if (isset($this->filters[strtolower($attrName)])) {
$value = $this->filters[strtolower($attrName)];
}
}
$filterOptions = array(
'' => '',
_('Unlocked') => self::FILTER_UNLOCKED,
_('Partially locked') => self::FILTER_SEMILOCKED,
_('Locked') => self::FILTER_LOCKED,
_('Expired') => self::FILTER_EXPIRED,
);
$filterInput = new htmlSelect('filter' . strtolower($attrName), $filterOptions, array($value));
$filterInput->setCSSClasses(array($this->type->getScope() . '-dark'));
$filterInput->setHasDescriptiveElements(true);
$filterInput->setOnchangeEvent('document.getElementsByName(\'apply_filter\')[0].click();');
parseHtml(null, $filterInput, array(), false, $this->tabindex, $this->type->getScope());
}
/**
* Builds the LDAP filter based on the filter entries in the GUI.
*
* @return String LDAP filter
*/
protected function buildLDAPAttributeFilter() {
$this->accountStatusFilter = null;
foreach ($this->filters as $attr => $filter) {
if ($attr == self::ATTR_ACCOUNT_STATUS) {
$this->accountStatusFilter = $filter;
break;
}
}
return parent::buildLDAPAttributeFilter();
}
/**
* {@inheritDoc}
* @see lamList::isAttributeFilteredByServer()
*/
protected function isAttributeFilteredByServer($attrName) {
// do not filter status server side
if ($attrName == self::ATTR_ACCOUNT_STATUS) {
return false;
}
return parent::isAttributeFilteredByServer($attrName);
}
/**
* Returns a list of additional LDAP attributes that should be read.
* This can be used to show additional data even if the user selected other attributes to show in the list.
* <br>
* <br>The user list reads pwdAccountLockedTime, sambaAcctFlags and userPassword
*
* @return array additional attribute names
*/
protected function getAdditionalLDAPAttributesToRead() {
$attrs = parent::getAdditionalLDAPAttributesToRead();
if ($this->showAccountStatus) {
$attrs[] = 'pwdAccountLockedTime';
$attrs[] = 'sambaAcctFlags';
$attrs[] = 'userPassword';
$attrs[] = 'userAccountControl';
$attrs[] = 'lockoutTime';
$attrs[] = 'nsAccountLock';
$attrs[] = 'accountUnlockTime';
$attrs[] = 'shadowExpire';
$attrs[] = 'shadowLastChange';
$attrs[] = 'shadowMax';
$attrs[] = 'shadowInactive';
$attrs[] = 'accountExpires';
$attrs[] = 'passwordExpirationTime';
$attrs[] = 'objectClass';
}
return $attrs;
}
/**
* Injects values for the virtual account status attribute to make it sortable.
*/
private function injectAccountStatusAttribute() {
$entryCount = sizeof($this->ldapEntries);
for ($i = 0; $i < $entryCount; $i++) {
$unixAvailable = self::isUnixAvailable($this->ldapEntries[$i]);
$sambaAvailable = self::isSambaAvailable($this->ldapEntries[$i]);
$ppolicyAvailable = $this->isPPolicyAvailable($this->ldapEntries[$i]);
$windowsAvailable = self::isWindowsAvailable($this->ldapEntries[$i]);
$unixLocked = self::isUnixLocked($this->ldapEntries[$i]);
$sambaLocked = self::isSambaLocked($this->ldapEntries[$i]);
$ppolicyLocked = self::isPPolicyLocked($this->ldapEntries[$i]);
$windowsLocked = self::isWindowsLocked($this->ldapEntries[$i]);
$windowsPasswordLocked = ($this->getWindowsPasswordLockedTime($this->ldapEntries[$i]) != null);
$is389dsLocked = self::is389dsLocked($this->ldapEntries[$i]);
$is389dsDeactivated = self::is389dsDeactivated($this->ldapEntries[$i]);
$is389dsPwdExpired = self::is389dsPwdExpired($this->ldapEntries[$i]);
$hasLocked = ($unixAvailable && $unixLocked)
|| ($sambaAvailable && $sambaLocked)
|| ($ppolicyAvailable && $ppolicyLocked)
|| ($windowsAvailable && ($windowsLocked || $windowsPasswordLocked))
|| $is389dsDeactivated || $is389dsPwdExpired
|| $is389dsLocked;
$hasUnlocked = ($unixAvailable && !$unixLocked)
|| ($sambaAvailable && !$sambaLocked)
|| ($ppolicyAvailable && !$ppolicyLocked)
|| ($windowsAvailable && !$windowsLocked);
$shadowExpired = shadowAccount::isAccountExpired($this->ldapEntries[$i]);
$shadowPasswordExpired = shadowAccount::isPasswordExpired($this->ldapEntries[$i]);
$windowsExpired = windowsUser::isAccountExpired($this->ldapEntries[$i]);
$expired = $shadowExpired || $shadowPasswordExpired || $windowsExpired;
$status = self::FILTER_UNLOCKED;
if ($expired) {
$status = self::FILTER_EXPIRED;
}
elseif ($hasLocked && $hasUnlocked) {