1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 class userManagement extends management
24 {
25 var $plHeadline = "Users";
26 var $plDescription = "Manage aspects of user accounts like generic, POSIX, samba and mail settings";
27 var $plIcon = "plugins/users/images/user.png";
29 var $sn = "";
30 var $givenName = "";
31 var $uid = "";
32 var $got_uid = "";
33 var $edit_uid = "";
35 var $pwd_change_queue = array();
36 var $force_hash_type = array();
38 // Tab definition
39 protected $tabClass = "usertabs";
40 protected $tabType = "USERTABS";
41 protected $aclCategory = "users";
42 protected $aclPlugin = "user";
43 protected $objectName = "user";
45 protected $proposal = "";
46 protected $proposalEnabled = FALSE;
47 protected $proposalSelected = FALSE;
49 protected $passwordChangeForceable = FALSE;
50 protected $enforcePasswordChange = FALSE;
52 function __construct($config,$ui)
53 {
54 $this->config = $config;
55 $this->ui = $ui;
57 $this->storagePoints = array(get_ou("core", "userRDN"));
59 // Build filter
60 if (session::global_is_set(get_class($this)."_filter")){
61 $filter= session::global_get(get_class($this)."_filter");
62 } else {
63 $filter = new filter(get_template_path("user-filter.xml", true));
64 $filter->setObjectStorage($this->storagePoints);
65 }
66 $this->setFilter($filter);
68 // Build headpage
69 $headpage = new listing(get_template_path("user-list.xml", true));
70 $headpage->registerElementFilter("lockLabel", "userManagement::filterLockLabel");
71 $headpage->registerElementFilter("lockImage", "userManagement::filterLockImage");
72 $headpage->registerElementFilter("filterProperties", "userManagement::filterProperties");
73 $headpage->setFilter($filter);
75 // Add copy&paste and snapshot handler.
76 if ($this->config->boolValueIsTrue("core", "copyPaste")){
77 $this->cpHandler = new CopyPasteHandler($this->config);
78 }
79 if($this->config->get_cfg_value("core","enableSnapshots") == "true"){
80 $this->snapHandler = new SnapshotHandler($this->config);
81 }
83 parent::__construct($config, $ui, "users", $headpage);
85 // Register special user actions
86 $this->registerAction("lock", "lockEntry");
87 $this->registerAction("lockUsers", "lockUsers");
88 $this->registerAction("unlockUsers", "lockUsers");
89 $this->registerAction("new_template", "newTemplate");
90 $this->registerAction("newfromtpl", "newUserFromTemplate");
91 $this->registerAction("templateContinue", "templateContinue");
92 $this->registerAction("templatize", "templatizeUsers");
93 $this->registerAction("templatizeContinue", "templatizeContinue");
95 $this->registerAction("password", "changePassword");
96 $this->registerAction("passwordQueue", "handlePasswordQueue");
97 $this->registerAction("passwordCancel", "closeDialogs");
99 $this->registerAction("sendMessage", "sendMessage");
100 $this->registerAction("saveEventDialog", "saveEventDialog");
101 $this->registerAction("abortEventDialog", "closeDialogs");
103 // Register shortcut icon actions
104 $this->registerAction("edit_user","editEntry");
105 $this->registerAction("edit_posixAccount","editEntry");
106 $this->registerAction("edit_mailAccount","editEntry");
107 $this->registerAction("edit_sambaAccount","editEntry");
108 $this->registerAction("edit_netatalk","editEntry");
109 $this->registerAction("edit_environment","editEntry");
110 $this->registerAction("edit_gofaxAccount","editEntry");
111 $this->registerAction("edit_phoneAccount","editEntry");
112 }
115 // Inject user actions
116 function detectPostActions()
117 {
118 $action = management::detectPostActions();
119 if(isset($_POST['template_continue'])) $action['action'] = "templateContinue";
120 if(isset($_POST['templatize_continue'])) $action['action'] = "templatizeContinue";
121 if(isset($_POST['save_event_dialog'])) $action['action'] = "saveEventDialog";
122 if(isset($_POST['abort_event_dialog'])) $action['action'] = "abortEventDialog";
123 if(isset($_POST['password_cancel'])){
124 $action['action'] = "passwordCancel";
125 }elseif((count($this->pwd_change_queue) || isset($_POST['password_finish']) || isset($_POST['refreshProposal']))){
126 $action['action'] = "passwordQueue";
127 }
128 return($action);
129 }
132 function editEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
133 {
134 $str = management::editEntry($action,$target);
135 if($str) return($str);
137 if(preg_match("/^edit_/",$action)){
138 $tab = preg_replace("/^edit_/","",$action);
139 if(isset($this->tabObject->by_object[$tab])){
140 $this->tabObject->current = $tab;
141 }else{
142 trigger_error("Unknown tab: ".$tab);
143 }
144 }
145 }
148 function closeDialogs()
149 {
150 management::closeDialogs();
151 $this->pwd_change_queue = array();
152 }
155 /*! \brief Sends a message to a set of users using gosa-si events.
156 */
157 function sendMessage($action="",$target=array(),$all=array())
158 {
159 if(class_available("DaemonEvent")){
160 $uids = array();
161 $ldap = $this->config->get_ldap_link();
162 $ldap->cd($this->config->current['BASE']);
163 foreach($target as $dn){
164 $ldap->cat($dn,array('uid'));
165 $attrs = $ldap->fetch();
166 if(isset($attrs['uid'][0])){
167 $uids[] = $attrs['uid'][0];
168 }
169 }
170 if(count($uids)){
171 $events = DaemonEvent::get_event_types(USER_EVENT);
172 $event = "DaemonEvent_notify";
173 if(isset($events['BY_CLASS'][$event])){
174 $type = $events['BY_CLASS'][$event];
175 $this->dialogObject = new $type['CLASS_NAME']($this->config);
176 $this->dialogObject->add_users($uids);
177 $this->dialogObject->set_type(SCHEDULED_EVENT);
178 }
179 }
180 }
181 }
184 /*! \brief Sends a message to a set of users using gosa-si events.
185 */
186 function saveEventDialog()
187 {
188 $this->dialogObject->save_object();
189 $msgs = $this->dialogObject->check();
190 if(count($msgs)){
191 msg_dialog::displayChecks($msgs);
192 }else{
193 $o_queue = new gosaSupportDaemon();
194 $o_queue->append($this->dialogObject);
195 if($o_queue->is_error()){
196 msg_dialog::display(_("Infrastructure error"), msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
197 }
198 $this->closeDialogs();
199 }
200 }
203 /*! \brief Intiates template creation.
204 */
205 function newTemplate($action,$entry)
206 {
207 $this->newEntry();
208 $this->tabObject->set_template_mode ();
209 }
212 /*! \brief Queues a set of users for password changes
213 */
214 function changePassword($action="",$target=array(),$all=array())
215 {
216 $this->dn ="";
217 $this->pwd_change_queue = $target;
219 // Check permisions
220 $disallowed = array();
221 foreach($this->pwd_change_queue as $key => $dn){
222 if(!preg_match("/w/",$this->ui->get_permissions($dn,$this->aclCategory."/password"))){
223 unset($this->pwd_change_queue[$key]);
224 $disallowed[] = $dn;
225 }
226 }
227 if(count($disallowed)){
228 msg_dialog::display(_("Permission"),msgPool::permModify($disallowed),INFO_DIALOG);
229 }
231 // Now display change dialog.
232 return($this->handlePasswordQueue());
233 }
237 function refreshProposal()
238 {
239 $this->proposal = passwordMethod::getPasswordProposal($this->config);
240 $this->proposalEnabled = (!empty($this->proposal));
241 }
244 function handlePasswordQueue()
245 {
246 // skip if nothing is to do
247 if(empty($this->dn) && !count($this->pwd_change_queue)) return;
249 // Refresh proposal if requested
250 if(isset($_POST['refreshProposal'])) $this->refreshProposal();
251 if(isset($_POST['proposalSelected'])) $this->proposalSelected = get_post('proposalSelected') == 1;
253 $this->enforcePasswordChange = isset($_POST['new_password']) && isset($_POST['enforcePasswordChange']);
255 $smarty = get_smarty();
256 $smarty->assign("proposal" , set_post($this->proposal));
257 $smarty->assign("proposalEnabled" , $this->proposalEnabled);
258 $smarty->assign("proposalSelected" , $this->proposalSelected);
260 $smarty->assign("passwordChangeForceable" , $this->passwordChangeForceable);
261 $smarty->assign("enforcePasswordChange" , $this->enforcePasswordChange);
263 // Get next entry from queue.
264 if(empty($this->dn) && count($this->pwd_change_queue)){
266 // Generate new proposal
267 $this->refreshProposal();
268 $this->proposalSelected = ($this->proposal != "");
269 $this->dn = array_pop($this->pwd_change_queue);
271 // Check if we are able to enforce a password change
272 $ldap = $this->config->get_ldap_link();
273 $ldap->cd($this->config->current['BASE']);
274 $ldap->cat($this->dn);
275 $attrs = $ldap->fetch();
276 $this->passwordChangeForceable =
277 in_array('sambaAccount', $attrs['objectClass']) ||
278 (in_array('posixAccount', $attrs['objectClass']) && isset($attrs['shadowMax']));
279 $smarty->assign("passwordChangeForceable" , $this->passwordChangeForceable);
280 $smarty->assign("enforcePasswordChange" , $this->enforcePasswordChange);
282 // Assign proposal variables
283 $smarty->assign("proposal" , set_post($this->proposal));
284 $smarty->assign("proposalEnabled" , $this->proposalEnabled);
285 $smarty->assign("proposalSelected" , $this->proposalSelected);
287 set_object_info($this->dn);
288 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
289 }
291 // If we've just refreshed the proposal then do not check the password for validity.
292 if(isset($_POST['refreshProposal'])){
293 return ($smarty->fetch(get_template_path('password.tpl', TRUE)));
294 }
296 // Check permissions
297 if(isset($_POST['password_finish'])){
299 $dn = $this->dn;
300 $acl = $this->ui->get_permissions($dn, "users/password");
301 $cacl= $this->ui->get_permissions($dn, "users/user");
302 if (preg_match('/w/', $acl) || preg_match('/c/', $cacl)){
304 // Get posted passwords
305 if($this->proposalSelected){
306 $new_password = $this->proposal;
307 $repeated_password = $this->proposal;
308 }else{
309 $new_password = get_post('new_password');
310 $repeated_password = get_post('repeated_password');
311 }
313 // Check posted passwords now.
314 $message= array();
315 if ($new_password != $repeated_password){
316 $message[]= _("The passwords you've entered as 'New password' and 'Repeated new password' do not match.");
317 } else {
318 if ($new_password == ""){
319 $message[] = msgPool::required(_("New password"));
320 }
321 }
323 // Call external check hook to validate the password change
324 if(!count($message)){
325 $attrs = array();
326 $attrs['current_password'] = '';
327 $attrs['new_password'] = $new_password;
328 $checkRes = password::callCheckHook($this->config,$this->dn,$attrs);
329 if(count($checkRes)){
330 $message[] = sprintf(_("Check-hook reported a problem: %s. Password change canceled!"),
331 implode($checkRes));
332 }
333 }
335 // Display errors
336 if (count($message) != 0){
337 msg_dialog::displayChecks($message);
338 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
339 }
343 // Change password
344 if(isset($this->force_hash_type[$this->dn])){
345 if(!change_password ($this->dn, $new_password,0,$this->force_hash_type[$this->dn],'', $message)){
346 msg_dialog::displayChecks(array($message));
347 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
348 }
349 }else{
350 if(!change_password ($this->dn, $new_password,0,'','',$message)){
351 msg_dialog::displayChecks(array($message));
352 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
353 }
354 }
356 // The user has to change his password on next login
357 // - We are going to update samba and posix attributes here, to enforce
358 // such a password change.
359 if($this->passwordChangeForceable && $this->enforcePasswordChange){
361 // Check if we are able to enforce a password change
362 $ldap = $this->config->get_ldap_link();
363 $ldap->cd($this->config->current['BASE']);
364 $ldap->cat($this->dn);
365 $attrs = $ldap->fetch();
366 $samba = in_array('sambaSamAccount', $attrs['objectClass']);
367 $posix = in_array('posixAccount', $attrs['objectClass']);
369 // Update the posix shadow flag...
370 if($posix){
372 $current= floor(date("U") /60 /60 /24);
373 $enforceDate = $current - $attrs['shadowMax'][0];
374 $new_attrs = array();
375 $new_attrs['shadowLastChange'] = $enforceDate;
376 $ldap->cd($this->dn);
377 $ldap->modify($new_attrs);
379 # $posixAccount = new posixAccount($this->config, $this->dn);
380 # $posixAccount->is_modified=TRUE;
381 # $posixAccount->activate_shadowExpire=1;
382 # $posixAccount->shadowExpire = date('d.m.Y', time() - (1 * 24 * 60 *60));
383 # $posixAccount->save();
384 }
386 // Update the samba kickoff flag...
387 if($samba){
388 $sambaAccount = new sambaAccount($this->config, $this->dn);
389 $sambaAccount->is_modified=TRUE;
390 $sambaAccount->flag_enforcePasswordChange = TRUE;
391 $sambaAccount->flag_cannotChangePassword = FALSE;
392 $sambaAccount->save();
393 }
394 }
396 new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
397 $this->dn ="";
399 } else {
400 msg_dialog::display(_("Password change"),
401 _("You have no permission to change this users password!"),
402 WARNING_DIALOG);
403 }
404 }
406 // Cleanup
407 if(!count($this->pwd_change_queue) && $this->dn=""){
408 $this->remove_lock();
409 $this->closeDialogs();
410 }else{
411 return($this->handlePasswordQueue());
412 }
413 }
416 /*! \brief Save user modifications.
417 * Whenever we save a 'new' user, request a password change for him.
418 */
419 function saveChanges()
420 {
421 $str = management::saveChanges();
423 if(!empty($str)) return($str);
425 if($this->last_tabObject instanceOf multi_plug){
426 foreach($this->last_tabObject->a_handles as $user){
427 if($user->password_change_needed()){
428 $this->force_hash_type[$user->dn] = $user->by_object['user']->pw_storage;
429 $this->pwd_change_queue[] = $user->dn;
430 }
431 }
432 return($this->handlePasswordQueue());
433 }
435 if(isset($this->last_tabObject->by_object['user']) && $this->last_tabObject->by_object['user']->password_change_needed()){
436 $this->force_hash_type[$this->last_tabObject->dn] = $this->last_tabObject->by_object['user']->pw_storage;
437 $this->pwd_change_queue[] = $this->last_tabObject->dn;
438 return($this->handlePasswordQueue());
439 }
440 }
442 function cancelEdit()
443 {
444 $str = management::cancelEdit();
445 if(!empty($str)) return($str);
447 if(isset($this->last_tabObject->by_object['user']) &&
448 $this->last_tabObject->by_object['user']->dn != "new" &&
449 $this->last_tabObject->by_object['user']->password_change_needed()){
450 $this->force_hash_type[$this->last_tabObject->dn] = $this->last_tabObject->by_object['user']->pw_storage;
451 $this->pwd_change_queue[] = $this->last_tabObject->dn;
452 return($this->handlePasswordQueue());
453 }
454 }
457 /*! \brief Intiates user creation.
458 * If we've user templates, then the user will be asked to use to use one.
459 * -> See 'templateContinue' for further handling.
460 */
461 function newUserFromTemplate($action="",$target=array(),$all=array())
462 {
463 // Call parent method, it knows whats to do, locking and so on ...
464 $str = management::newEntry($action,$target,$all);
465 if(!empty($str)) return($str);
467 // Reset uid selection.
468 $this->got_uid= "";
470 // Use template if there are any of them
471 $templates = array();
472 $templates['none']= _("none");
473 $templates = array_merge($templates,$this->get_templates());
475 // We've templates, so preset the current template and display the input dialog.
476 if (count($templates)){
477 $smarty = get_smarty();
478 foreach(array("sn", "givenName", "uid", "got_uid") as $attr){
479 $smarty->assign("$attr", "");
480 }
481 $smarty->assign("template", array_pop($target));
482 $smarty->assign("templates", $templates);
483 $smarty->assign("edit_uid", "");
484 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
486 // -> See 'templateContinue' for further handling!
487 }
488 }
492 /*! \brief Intiates user creation.
493 * If we've user templates, then the user will be asked
494 * if he wants to use one.
495 * -> See 'templateContinue' for further handling.
496 */
497 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
498 {
500 // Call parent method, it manages everything, locking, object creation...
501 $str = management::newEntry($action,$target,$all);
502 if(!empty($str)) return($str);
504 // If we've at least one template, then ask the user if he wants to use one?
505 $templates = array();
506 $templates['none']= _("none");
507 $templates = array_merge($templates,$this->get_templates());
509 // Display template selection
510 if (count($templates) > 1){
511 $smarty = get_smarty();
513 // Set default variables, normally empty.
514 foreach(array("sn", "givenName", "uid", "got_uid") as $attr){
515 $smarty->assign($attr, "");
516 }
517 $smarty->assign("template", "none");
518 $smarty->assign("templates", $templates);
519 $smarty->assign("edit_uid", "");
520 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
522 // -> See 'templateContinue' for further handling!
523 }
524 }
527 /* !\brief This method is called whenever a template selection was displayed.
528 * Here we act on the use selection.
529 * - Does the user want to create a user from template?
530 * - Create user without template?
531 * - Input correct, every value given and valid?
532 */
533 function templateContinue()
534 {
535 // Get the list of available templates.
536 $templates = array();
537 $templates['none']= _("none");
538 $templates = array_merge($templates,$this->get_templates());
540 // Input validation, if someone wants to create a user from a template
541 // then validate the given values.
542 $message = array();
543 if(!isset($_POST['template']) || (empty($_POST['template']))){
544 $message[]= msgPool::invalid(_("Template"));
545 }
546 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
547 $message[]= msgPool::required(_("Name"));
548 }
549 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
550 $message[]= msgPool::required(_("Given name"));
551 }
553 /********************
554 * 1 We've had input errors - Display errors and show input dialog again.
555 ********************/
557 if (count($message) > 0){
558 msg_dialog::displayChecks($message);
560 // Preset input fields with user input.
561 $smarty = get_smarty();
562 foreach(array("sn", "givenName", "uid", "template") as $attr){
563 if(isset($_POST[$attr])){
564 $smarty->assign("$attr", set_post(get_post($attr)));
565 }else{
566 $smarty->assign("$attr", "");
567 }
568 }
570 $smarty->assign("templates",$templates);
571 $smarty->assign("got_uid", $this->got_uid);
572 $smarty->assign("edit_uid",false);
573 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
574 }
576 /********************
577 * 2 There was a template selected, now ask for the uid.
578 ********************/
580 if ($_POST['template'] != 'none' && !isset($_POST['uid'])){
582 // Remember user input.
583 $smarty = get_smarty();
584 $this->sn = get_post('sn');
585 $this->givenName = get_post('givenName');
587 // Avoid duplicate entries, check if such a user already exists.
588 $dn= preg_replace("/^[^,]+,/i", "", get_post('template'));
589 $ldap= $this->config->get_ldap_link();
590 $ldap->cd ($dn);
591 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
593 if ($ldap->count () != 0){
594 msg_dialog::displayChecks(array(msgPool::duplicated(_("Name"))));
595 $smarty->assign("edit_uid", "");
596 }else{
598 // Preset uid field by using the idGenerator
599 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
600 if ($this->config->get_cfg_value("core","idGenerator") != ""){
601 $genStr = $this->config->get_cfg_value("core","idGenerator");
602 $smarty->assign("edit_uid", "");
603 if(!empty($genStr)){
604 $uids= gen_uids($genStr, $attributes);
605 if (count($uids)){
606 $smarty->assign("edit_uid", "false");
607 $smarty->assign("uids", $uids);
608 $this->uid= current($uids);
609 }else{
610 msg_dialog::displayChecks(array(_("Cannot generate a unique id, please specify it manually!")));
611 }
612 }
613 } else {
614 $smarty->assign("edit_uid", "");
615 $this->uid= "";
616 }
617 $this->got_uid= true;
618 }
620 // Assign user input
621 foreach(array("sn", "givenName", "uid", "got_uid") as $attr){
622 $smarty->assign("$attr", set_post($this->$attr));
623 }
624 if (isset($_POST['template'])){
625 $smarty->assign("template", get_post('template'));
626 }
627 $smarty->assign("templates",$templates);
628 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
629 }
632 /********************
633 * 3 No template - Ok. Lets fill the data into the user object and skip templating here.
634 ********************/
635 if (get_post('template') == 'none'){
636 foreach(array("sn", "givenName", "uid") as $attr){
637 if (isset($_POST[$attr])){
638 $this->tabObject->by_object['user']->$attr= get_post($attr);
639 }
640 }
642 // The user Tab object is already instantiated, so just go back and let the
643 // management class do the rest.
644 return("");
645 }
648 /********************
649 * 4 Template selected and uid given - Ok, then lets adapt tempalte values.
650 ********************/
651 if(isset($_POST['uid'])){
653 // Move user supplied data to sub plugins
654 foreach(array("uid","sn","givenName") as $attr){
655 $this->$attr = get_post($attr);
656 $this->tabObject->$attr = $this->$attr;
657 $this->tabObject->by_object['user']->$attr = $this->$attr;
658 }
660 // Adapt template values.
661 $template_dn = get_post('template');
662 $this->tabObject->adapt_from_template($template_dn, array("uid","cn","givenName","sn"));
663 $template_base = preg_replace("/^[^,]+,".preg_quote(get_people_ou(), '/i')."/", '', $template_dn);
664 $this->tabObject->by_object['user']->base= $template_base;
666 // The user Tab object is already instantiated, so just go back and let the
667 // management class do the rest.
668 return("");
669 }
670 }
673 /* !\brief This method applies a template to a set of users.
674 */
675 function templatizeUsers($action="",$target=array(),$all=array())
676 {
677 $this->dns = array();
678 if(count($target)){
680 // Get the list of available templates.
681 $templates = $this->get_templates();
683 // Check entry locking
684 foreach($target as $dn){
685 if (($user= get_lock($dn)) != ""){
686 $this->dn = $dn;
687 return(gen_locked_message ($user, $dn));
688 }
689 $this->dns[] = $dn;
690 }
692 // Display template
693 $smarty = get_smarty();
694 $smarty->assign("templates", $templates);
695 return($smarty->fetch(get_template_path('templatize.tpl', TRUE)));
696 }
697 }
700 /* !\brief This method is called whenever the templatize dialog was used.
701 */
702 function templatizeContinue()
703 {
704 // Template readable?
705 $template= get_post('template');
706 $acl = $this->ui->get_permissions($template, $this->aclCategory."/".$this->aclPlugin);
707 if (preg_match('/r/', $acl)){
708 $tab = $this->tabClass;
709 foreach ($this->dns as $dn){
711 // User writeable
712 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
713 if (preg_match('/w/', $acl)){
714 $this->tabObject= new $tab($this->config, $this->config->data['TABS'][$this->tabType], $dn, $this->aclCategory);
715 $this->tabObject->adapt_from_template($template, array("sn", "givenName", "uid"));
716 $this->tabObject->save();
717 } else {
718 msg_dialog::display(_("Permission error"), msgPool::permModify($dn), ERROR_DIALOG);
719 }
720 }
721 } else {
722 msg_dialog::display(_("Permission error"), msgPool::permView($template), ERROR_DIALOG);
723 }
725 // Cleanup!
726 $this->remove_lock();
727 $this->closeDialogs();
728 }
731 /* !\brief Lock/unlock multiple users.
732 */
733 function lockUsers($action,$target,$all)
734 {
735 if(!count($target)) return;
736 if($action == "lockUsers"){
737 $this->lockEntry($action,$target, $all, "lock");
738 }else{
739 $this->lockEntry($action,$target, $all, "unlock");
740 }
741 }
744 /* !\brief Locks/unlocks the given user(s).
745 */
746 function lockEntry($action,$entry, $all, $type = "toggle")
747 {
749 // Filter out entries we are not allowed to modify
750 $disallowed = array();
751 $dns = array();
752 foreach($entry as $dn){
753 if (!preg_match("/w/",$this->ui->get_permissions($dn,"users/password"))){
754 $disallowed[] = $dn;
755 }else{
756 $allowed[] = $dn;
757 }
758 }
759 if(count($disallowed)){
760 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
761 }
763 // Try to lock/unlock the rest of the entries.
764 $ldap = $this->config->get_ldap_link();
765 foreach($allowed as $dn){
766 $ldap->cat($dn, array('userPassword'));
767 if($ldap->count() == 1){
769 // We can't lock empty passwords.
770 $val = $ldap->fetch();
771 if(!isset($val['userPassword'])){
772 continue;
773 }
775 // Detect the password method and try to lock/unlock.
776 $pwd = $val['userPassword'][0];
777 $method = passwordMethod::get_method($pwd,$val['dn']);
778 $success= true;
779 if($method instanceOf passwordMethod){
780 if($type == "toggle"){
781 if($method->is_locked($this->config,$val['dn'])){
782 $success= $method->unlock_account($this->config,$val['dn']);
783 }else{
784 $success= $method->lock_account($this->config,$val['dn']);
785 }
786 }elseif($type == "lock" && !$method->is_locked($this->config,$val['dn'])){
787 $success= $method->lock_account($this->config,$val['dn']);
788 }elseif($type == "unlock" && $method->is_locked($this->config,$val['dn'])){
789 $success= $method->unlock_account($this->config,$val['dn']);
790 }
792 // Check if everything went fine.
793 if (!$success){
794 $hn= $method->get_hash_name();
795 if (is_array($hn)){
796 $hn= $hn[0];
797 }
798 msg_dialog::display(_("Account locking"),
799 sprintf(_("Password method '%s' does not support locking. Account (%s) has not been locked!"),
800 $hn,$dn),WARNING_DIALOG);
801 }
802 }else{
803 // Can't lock unknown methods.
804 }
805 }
806 }
807 }
810 /* !\brief This method returns a list of all available templates.
811 */
812 function get_templates()
813 {
814 $templates= array();
815 $ldap= $this->config->get_ldap_link();
816 foreach ($this->config->departments as $key => $value){
817 $acl = $this->ui->get_permissions($value,$this->aclCategory."/".$this->aclPlugin);
818 if (preg_match("/c/",$acl)){
820 // Search all templates from the current dn.
821 $ldap->cd (get_people_ou().$value);
822 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
823 if ($ldap->count() != 0){
824 while ($attrs= $ldap->fetch()){
825 $templates[$ldap->getDN()]= $attrs['uid'][0]." - ".LDAP::fix($key);
826 }
827 }
828 }
829 }
830 natcasesort ($templates);
831 reset ($templates);
832 return($templates);
833 }
836 function copyPasteHandler($action="",$target=array(),$all=array(),
837 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
838 {
839 if ($this->config->boolValueIsTrue("core", "copyPaste")){
840 $this->cpHandler->lastdn = "";
841 $str = management::copyPasteHandler($action,$target,$all);
842 if($this->cpHandler->lastdn != "" && isset($_POST['passwordTodo']) && $_POST['passwordTodo'] == "new"){
843 $this->pwd_change_queue[] = $this->cpHandler->lastdn;
844 return($this->handlePasswordQueue());
845 }
846 return($str);
847 }
849 return "";
850 }
853 static function filterLockImage($userPassword)
854 {
855 $image= "images/empty.png";
856 if(isset($userPassword[0]) && preg_match("/^\{[^\}]/",$userPassword[0])){
857 if(preg_match("/^[^\}]*+\}!/",$userPassword[0])){
858 $image= "images/lists/locked.png";
859 }else{
860 $image= "images/lists/unlocked.png";
861 }
862 }
863 return $image;
864 }
867 static function filterLockLabel($userPassword)
868 {
869 $label= "";
870 if(isset($userPassword[0]) && preg_match("/^\{[^\}]/",$userPassword[0])){
871 if(preg_match("/^[^\}]*+\}!/",$userPassword[0])){
872 $label= _("Unlock account")."<rowClass:entry-locked/><rowLabel:locked/>";
873 }else{
874 $label= _("Lock account");
875 }
876 }
877 return $label;
878 }
881 static function filterProperties($row, $classes)
882 {
883 $result= "";
884 $map= array( "gosaAccount" => array( "image" => "plugins/users/images/select_user.png",
885 "plugin" => "user",
886 "alt" => _("Generic"),
887 "title" => _("Edit generic properties")),
888 "posixAccount" => array("image" => "images/penguin.png",
889 "plugin" => "posixAccount",
890 "alt" => _("POSIX"),
891 "title" => _("Edit POSIX properties")),
892 "gosaMailAccount" => array("image" => "images/mailto.png",
893 "alt" => _("Mail"),
894 "plugin" => "mailAccount",
895 "title" => _("Edit mail properties")),
896 "sambaSamAccount" => array("image" => "plugins/systems/images/select_winstation.png",
897 "plugin" => "sambaAccount",
898 "alt" => _("Samba"),
899 "title" => _("Edit samba properties")),
900 "apple-user" => array("image" => "plugins/netatalk/images/select_netatalk.png",
901 "plugin" => "netatalk",
902 "alt" => _("Netatalk"),
903 "title" => _("Edit Netatalk properties")),
904 "gotoEnvironment" => array("image" => "plugins/users/images/small_environment.png",
905 "plugin" => "environment",
906 "alt" => _("Environment"),
907 "title" => _("Edit environment properties")),
908 "goFaxAccount" => array("image" => "plugins/users/images/fax_small.png",
909 "plugin" => "gofaxAccount",
910 "alt" => _("FAX"),
911 "title" => _("Edit FAX properties")),
912 "goFonAccount" => array("image" => "plugins/gofon/images/select_phone.png",
913 "plugin" => "phoneAccount",
914 "alt" => _("Phone"),
915 "title" => _("Edit phone properties")));
917 // Walk thru map
918 foreach ($map as $oc => $properties) {
919 if (in_array_ics($oc, $classes)) {
920 $result.= image($properties['image'], "listing_edit_".$properties['plugin']."_$row", $properties['title']);
921 } else {
922 $result.= image('images/empty.png');
923 }
924 }
925 return $result;
926 }
928 }
929 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
930 ?>