c3a6a6e10bce793b4de623f67d35d5d8a9c7483b
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 // Display errors
324 if (count($message) != 0){
325 msg_dialog::displayChecks($message);
326 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
327 }
329 // Change cassword
330 if(isset($this->force_hash_type[$this->dn])){
331 if(!change_password ($this->dn, $new_password,0,$this->force_hash_type[$this->dn])){
332 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
333 }
334 }else{
335 if(!change_password ($this->dn, $new_password)){
336 return($smarty->fetch(get_template_path('password.tpl', TRUE)));
337 }
338 }
339 if ($this->config->get_cfg_value("core","passwordHook") != ""){
340 $ldap = $this->config->get_ldap_link();
341 $ldap->cd($this->config->current['BASE']);
342 $ldap->cat($this->dn,array('uid'));
343 $attrs = $ldap->fetch();
344 exec($this->config->get_cfg_value("core","passwordHook")." ".$attrs['uid'][0]." ".$new_password, $resarr);
345 }
347 // The user has to change his password on next login
348 // - We are going to update samba and posix attributes here, to enforce
349 // such a password change.
350 if($this->passwordChangeForceable && $this->enforcePasswordChange){
352 // Check if we are able to enforce a password change
353 $ldap = $this->config->get_ldap_link();
354 $ldap->cd($this->config->current['BASE']);
355 $ldap->cat($this->dn);
356 $attrs = $ldap->fetch();
357 $samba = in_array('sambaSamAccount', $attrs['objectClass']);
358 $posix = in_array('posixAccount', $attrs['objectClass']);
360 // Update the posix shadow flag...
361 if($posix){
363 $current= floor(date("U") /60 /60 /24);
364 $enforceDate = $current - $attrs['shadowMax'][0];
365 $new_attrs = array();
366 $new_attrs['shadowLastChange'] = $enforceDate;
367 $ldap->cd($this->dn);
368 $ldap->modify($new_attrs);
370 # $posixAccount = new posixAccount($this->config, $this->dn);
371 # $posixAccount->is_modified=TRUE;
372 # $posixAccount->activate_shadowExpire=1;
373 # $posixAccount->shadowExpire = date('d.m.Y', time() - (1 * 24 * 60 *60));
374 # $posixAccount->save();
375 }
377 // Update the samba kickoff flag...
378 if($samba){
379 $sambaAccount = new sambaAccount($this->config, $this->dn);
380 $sambaAccount->is_modified=TRUE;
381 $sambaAccount->flag_enforcePasswordChange = TRUE;
382 $sambaAccount->flag_cannotChangePassword = FALSE;
383 $sambaAccount->save();
384 }
385 }
387 new log("modify","users/".get_class($this),$this->dn,array(),"Password has been changed");
388 $this->dn ="";
390 } else {
391 msg_dialog::display(_("Password change"),
392 _("You have no permission to change this users password!"),
393 WARNING_DIALOG);
394 }
395 }
397 // Cleanup
398 if(!count($this->pwd_change_queue) && $this->dn=""){
399 $this->remove_lock();
400 $this->closeDialogs();
401 }else{
402 return($this->handlePasswordQueue());
403 }
404 }
407 /*! \brief Save user modifications.
408 * Whenever we save a 'new' user, request a password change for him.
409 */
410 function saveChanges()
411 {
412 $str = management::saveChanges();
414 if(!empty($str)) return($str);
416 if($this->last_tabObject instanceOf multi_plug){
417 foreach($this->last_tabObject->a_handles as $user){
418 if($user->password_change_needed()){
419 $this->force_hash_type[$user->dn] = $user->by_object['user']->pw_storage;
420 $this->pwd_change_queue[] = $user->dn;
421 }
422 }
423 return($this->handlePasswordQueue());
424 }
426 if(isset($this->last_tabObject->by_object['user']) && $this->last_tabObject->by_object['user']->password_change_needed()){
427 $this->force_hash_type[$this->last_tabObject->dn] = $this->last_tabObject->by_object['user']->pw_storage;
428 $this->pwd_change_queue[] = $this->last_tabObject->dn;
429 return($this->handlePasswordQueue());
430 }
431 }
433 function cancelEdit()
434 {
435 $str = management::cancelEdit();
436 if(!empty($str)) return($str);
438 if(isset($this->last_tabObject->by_object['user']) &&
439 $this->last_tabObject->by_object['user']->dn != "new" &&
440 $this->last_tabObject->by_object['user']->password_change_needed()){
441 $this->force_hash_type[$this->last_tabObject->dn] = $this->last_tabObject->by_object['user']->pw_storage;
442 $this->pwd_change_queue[] = $this->last_tabObject->dn;
443 return($this->handlePasswordQueue());
444 }
445 }
448 /*! \brief Intiates user creation.
449 * If we've user templates, then the user will be asked to use to use one.
450 * -> See 'templateContinue' for further handling.
451 */
452 function newUserFromTemplate($action="",$target=array(),$all=array())
453 {
454 // Call parent method, it knows whats to do, locking and so on ...
455 $str = management::newEntry($action,$target,$all);
456 if(!empty($str)) return($str);
458 // Reset uid selection.
459 $this->got_uid= "";
461 // Use template if there are any of them
462 $templates = array();
463 $templates['none']= _("none");
464 $templates = array_merge($templates,$this->get_templates());
466 // We've templates, so preset the current template and display the input dialog.
467 if (count($templates)){
468 $smarty = get_smarty();
469 foreach(array("sn", "givenName", "uid", "got_uid") as $attr){
470 $smarty->assign("$attr", "");
471 }
472 $smarty->assign("template", array_pop($target));
473 $smarty->assign("templates", $templates);
474 $smarty->assign("edit_uid", "");
475 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
477 // -> See 'templateContinue' for further handling!
478 }
479 }
483 /*! \brief Intiates user creation.
484 * If we've user templates, then the user will be asked
485 * if he wants to use one.
486 * -> See 'templateContinue' for further handling.
487 */
488 function newEntry($action="",$target=array(),$all=array(), $altTabClass ="", $altTabType = "", $altAclCategory="")
489 {
491 // Call parent method, it manages everything, locking, object creation...
492 $str = management::newEntry($action,$target,$all);
493 if(!empty($str)) return($str);
495 // If we've at least one template, then ask the user if he wants to use one?
496 $templates = array();
497 $templates['none']= _("none");
498 $templates = array_merge($templates,$this->get_templates());
500 // Display template selection
501 if (count($templates) > 1){
502 $smarty = get_smarty();
504 // Set default variables, normally empty.
505 foreach(array("sn", "givenName", "uid", "got_uid") as $attr){
506 $smarty->assign($attr, "");
507 }
508 $smarty->assign("template", "none");
509 $smarty->assign("templates", $templates);
510 $smarty->assign("edit_uid", "");
511 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
513 // -> See 'templateContinue' for further handling!
514 }
515 }
518 /* !\brief This method is called whenever a template selection was displayed.
519 * Here we act on the use selection.
520 * - Does the user want to create a user from template?
521 * - Create user without template?
522 * - Input correct, every value given and valid?
523 */
524 function templateContinue()
525 {
526 // Get the list of available templates.
527 $templates = array();
528 $templates['none']= _("none");
529 $templates = array_merge($templates,$this->get_templates());
531 // Input validation, if someone wants to create a user from a template
532 // then validate the given values.
533 $message = array();
534 if(!isset($_POST['template']) || (empty($_POST['template']))){
535 $message[]= msgPool::invalid(_("Template"));
536 }
537 if(!isset($_POST['sn']) || (empty($_POST['sn']))){
538 $message[]= msgPool::required(_("Name"));
539 }
540 if(!isset($_POST['givenName']) || (empty($_POST['givenName']))){
541 $message[]= msgPool::required(_("Given name"));
542 }
544 /********************
545 * 1 We've had input errors - Display errors and show input dialog again.
546 ********************/
548 if (count($message) > 0){
549 msg_dialog::displayChecks($message);
551 // Preset input fields with user input.
552 $smarty = get_smarty();
553 foreach(array("sn", "givenName", "uid", "template") as $attr){
554 if(isset($_POST[$attr])){
555 $smarty->assign("$attr", set_post(get_post($attr)));
556 }else{
557 $smarty->assign("$attr", "");
558 }
559 }
561 $smarty->assign("templates",$templates);
562 $smarty->assign("got_uid", $this->got_uid);
563 $smarty->assign("edit_uid",false);
564 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
565 }
567 /********************
568 * 2 There was a template selected, now ask for the uid.
569 ********************/
571 if ($_POST['template'] != 'none' && !isset($_POST['uid'])){
573 // Remember user input.
574 $smarty = get_smarty();
575 $this->sn = get_post('sn');
576 $this->givenName = get_post('givenName');
578 // Avoid duplicate entries, check if such a user already exists.
579 $dn= preg_replace("/^[^,]+,/i", "", get_post('template'));
580 $ldap= $this->config->get_ldap_link();
581 $ldap->cd ($dn);
582 $ldap->search ("(&(sn=".normalizeLdap($this->sn).")(givenName=".normalizeLdap($this->givenName)."))", array("givenName"));
584 if ($ldap->count () != 0){
585 msg_dialog::displayChecks(array(msgPool::duplicated(_("Name"))));
586 }else{
588 // Preset uid field by using the idGenerator
589 $attributes= array('sn' => $this->sn, 'givenName' => $this->givenName);
590 if ($this->config->get_cfg_value("core","idGenerator") != ""){
591 $uids= gen_uids ($this->config->get_cfg_value("core","idGenerator"), $attributes);
592 if (count($uids)){
593 $smarty->assign("edit_uid", "false");
594 $smarty->assign("uids", $uids);
595 $this->uid= current($uids);
596 }
597 } else {
598 $smarty->assign("edit_uid", "");
599 $this->uid= "";
600 }
601 $this->got_uid= true;
602 }
604 // Assign user input
605 foreach(array("sn", "givenName", "uid", "got_uid") as $attr){
606 $smarty->assign("$attr", set_post($this->$attr));
607 }
608 if (isset($_POST['template'])){
609 $smarty->assign("template", get_post('template'));
610 }
611 $smarty->assign("templates",$templates);
612 return($smarty->fetch(get_template_path('template.tpl', TRUE)));
613 }
616 /********************
617 * 3 No template - Ok. Lets fill the data into the user object and skip templating here.
618 ********************/
619 if (get_post('template') == 'none'){
620 foreach(array("sn", "givenName", "uid") as $attr){
621 if (isset($_POST[$attr])){
622 $this->tabObject->by_object['user']->$attr= get_post($attr);
623 }
624 }
626 // The user Tab object is already instantiated, so just go back and let the
627 // management class do the rest.
628 return("");
629 }
632 /********************
633 * 4 Template selected and uid given - Ok, then lets adapt tempalte values.
634 ********************/
635 if(isset($_POST['uid'])){
637 // Move user supplied data to sub plugins
638 foreach(array("uid","sn","givenName") as $attr){
639 $this->$attr = get_post($attr);
640 $this->tabObject->$attr = $this->$attr;
641 $this->tabObject->by_object['user']->$attr = $this->$attr;
642 }
644 // Adapt template values.
645 $template_dn = get_post('template');
646 $this->tabObject->adapt_from_template($template_dn, array("uid","cn","givenName","sn"));
647 $template_base = preg_replace("/^[^,]+,".preg_quote(get_people_ou(), '/i')."/", '', $template_dn);
648 $this->tabObject->by_object['user']->base= $template_base;
650 // The user Tab object is already instantiated, so just go back and let the
651 // management class do the rest.
652 return("");
653 }
654 }
657 /* !\brief This method applies a template to a set of users.
658 */
659 function templatizeUsers($action="",$target=array(),$all=array())
660 {
661 $this->dns = array();
662 if(count($target)){
664 // Get the list of available templates.
665 $templates = $this->get_templates();
667 // Check entry locking
668 foreach($target as $dn){
669 if (($user= get_lock($dn)) != ""){
670 $this->dn = $dn;
671 return(gen_locked_message ($user, $dn));
672 }
673 $this->dns[] = $dn;
674 }
676 // Display template
677 $smarty = get_smarty();
678 $smarty->assign("templates", $templates);
679 return($smarty->fetch(get_template_path('templatize.tpl', TRUE)));
680 }
681 }
684 /* !\brief This method is called whenever the templatize dialog was used.
685 */
686 function templatizeContinue()
687 {
688 // Template readable?
689 $template= get_post('template');
690 $acl = $this->ui->get_permissions($template, $this->aclCategory."/".$this->aclPlugin);
691 if (preg_match('/r/', $acl)){
692 $tab = $this->tabClass;
693 foreach ($this->dns as $dn){
695 // User writeable
696 $acl = $this->ui->get_permissions($dn, $this->aclCategory."/".$this->aclPlugin);
697 if (preg_match('/w/', $acl)){
698 $this->tabObject= new $tab($this->config, $this->config->data['TABS'][$this->tabType], $dn, $this->aclCategory);
699 $this->tabObject->adapt_from_template($template, array("sn", "givenName", "uid"));
700 $this->tabObject->save();
701 } else {
702 msg_dialog::display(_("Permission error"), msgPool::permModify($dn), ERROR_DIALOG);
703 }
704 }
705 } else {
706 msg_dialog::display(_("Permission error"), msgPool::permView($template), ERROR_DIALOG);
707 }
709 // Cleanup!
710 $this->remove_lock();
711 $this->closeDialogs();
712 }
715 /* !\brief Lock/unlock multiple users.
716 */
717 function lockUsers($action,$target,$all)
718 {
719 if(!count($target)) return;
720 if($action == "lockUsers"){
721 $this->lockEntry($action,$target, $all, "lock");
722 }else{
723 $this->lockEntry($action,$target, $all, "unlock");
724 }
725 }
728 /* !\brief Locks/unlocks the given user(s).
729 */
730 function lockEntry($action,$entry, $all, $type = "toggle")
731 {
733 // Filter out entries we are not allowed to modify
734 $disallowed = array();
735 $dns = array();
736 foreach($entry as $dn){
737 if (!preg_match("/w/",$this->ui->get_permissions($dn,"users/password"))){
738 $disallowed[] = $dn;
739 }else{
740 $allowed[] = $dn;
741 }
742 }
743 if(count($disallowed)){
744 msg_dialog::display(_("Permission"),msgPool::permDelete($disallowed),INFO_DIALOG);
745 }
747 // Try to lock/unlock the rest of the entries.
748 $ldap = $this->config->get_ldap_link();
749 foreach($allowed as $dn){
750 $ldap->cat($dn, array('userPassword'));
751 if($ldap->count() == 1){
753 // We can't lock empty passwords.
754 $val = $ldap->fetch();
755 if(!isset($val['userPassword'])){
756 continue;
757 }
759 // Detect the password method and try to lock/unlock.
760 $pwd = $val['userPassword'][0];
761 $method = passwordMethod::get_method($pwd,$val['dn']);
762 $success= true;
763 if($method instanceOf passwordMethod){
764 if($type == "toggle"){
765 if($method->is_locked($this->config,$val['dn'])){
766 $success= $method->unlock_account($this->config,$val['dn']);
767 }else{
768 $success= $method->lock_account($this->config,$val['dn']);
769 }
770 }elseif($type == "lock" && !$method->is_locked($this->config,$val['dn'])){
771 $success= $method->lock_account($this->config,$val['dn']);
772 }elseif($type == "unlock" && $method->is_locked($this->config,$val['dn'])){
773 $success= $method->unlock_account($this->config,$val['dn']);
774 }
776 // Check if everything went fine.
777 if (!$success){
778 $hn= $method->get_hash_name();
779 if (is_array($hn)){
780 $hn= $hn[0];
781 }
782 msg_dialog::display(_("Account locking"),
783 sprintf(_("Password method '%s' does not support locking. Account (%s) has not been locked!"),
784 $hn,$dn),WARNING_DIALOG);
785 }
786 }else{
787 // Can't lock unknown methods.
788 }
789 }
790 }
791 }
794 /* !\brief This method returns a list of all available templates.
795 */
796 function get_templates()
797 {
798 $templates= array();
799 $ldap= $this->config->get_ldap_link();
800 foreach ($this->config->departments as $key => $value){
801 $acl = $this->ui->get_permissions($value,$this->aclCategory."/".$this->aclPlugin);
802 if (preg_match("/c/",$acl)){
804 // Search all templates from the current dn.
805 $ldap->cd (get_people_ou().$value);
806 $ldap->search ("(objectClass=gosaUserTemplate)", array("uid"));
807 if ($ldap->count() != 0){
808 while ($attrs= $ldap->fetch()){
809 $templates[$ldap->getDN()]= $attrs['uid'][0]." - ".LDAP::fix($key);
810 }
811 }
812 }
813 }
814 natcasesort ($templates);
815 reset ($templates);
816 return($templates);
817 }
820 function copyPasteHandler($action="",$target=array(),$all=array(),
821 $altTabClass ="", $altTabType = "", $altAclCategory="",$altAclPlugin="")
822 {
823 if ($this->config->boolValueIsTrue("core", "copyPaste")){
824 $this->cpHandler->lastdn = "";
825 $str = management::copyPasteHandler($action,$target,$all);
826 if($this->cpHandler->lastdn != "" && isset($_POST['passwordTodo']) && $_POST['passwordTodo'] == "new"){
827 $this->pwd_change_queue[] = $this->cpHandler->lastdn;
828 return($this->handlePasswordQueue());
829 }
830 return($str);
831 }
833 return "";
834 }
837 static function filterLockImage($userPassword)
838 {
839 $image= "images/empty.png";
840 if(isset($userPassword[0]) && preg_match("/^\{[^\}]/",$userPassword[0])){
841 if(preg_match("/^[^\}]*+\}!/",$userPassword[0])){
842 $image= "images/lists/locked.png";
843 }else{
844 $image= "images/lists/unlocked.png";
845 }
846 }
847 return $image;
848 }
851 static function filterLockLabel($userPassword)
852 {
853 $label= "";
854 if(isset($userPassword[0]) && preg_match("/^\{[^\}]/",$userPassword[0])){
855 if(preg_match("/^[^\}]*+\}!/",$userPassword[0])){
856 $label= _("Unlock account")."<rowClass:entry-locked/><rowLabel:locked/>";
857 }else{
858 $label= _("Lock account");
859 }
860 }
861 return $label;
862 }
865 static function filterProperties($row, $classes)
866 {
867 $result= "";
868 $map= array( "gosaAccount" => array( "image" => "plugins/users/images/select_user.png",
869 "plugin" => "user",
870 "alt" => _("Generic"),
871 "title" => _("Edit generic properties")),
872 "posixAccount" => array("image" => "images/penguin.png",
873 "plugin" => "posixAccount",
874 "alt" => _("POSIX"),
875 "title" => _("Edit POSIX properties")),
876 "gosaMailAccount" => array("image" => "images/mailto.png",
877 "alt" => _("Mail"),
878 "plugin" => "mailAccount",
879 "title" => _("Edit mail properties")),
880 "sambaSamAccount" => array("image" => "plugins/systems/images/select_winstation.png",
881 "plugin" => "sambaAccount",
882 "alt" => _("Samba"),
883 "title" => _("Edit samba properties")),
884 "apple-user" => array("image" => "plugins/netatalk/images/select_netatalk.png",
885 "plugin" => "netatalk",
886 "alt" => _("Netatalk"),
887 "title" => _("Edit netatalk properties")),
888 "gotoEnvironment" => array("image" => "plugins/users/images/small_environment.png",
889 "plugin" => "environment",
890 "alt" => _("Environment"),
891 "title" => _("Edit environment properties")),
892 "goFaxAccount" => array("image" => "plugins/users/images/fax_small.png",
893 "plugin" => "gofaxAccount",
894 "alt" => _("FAX"),
895 "title" => _("Edit FAX properties")),
896 "goFonAccount" => array("image" => "plugins/gofon/images/select_phone.png",
897 "plugin" => "phoneAccount",
898 "alt" => _("Phone"),
899 "title" => _("Edit phone properties")));
901 // Walk thru map
902 foreach ($map as $oc => $properties) {
903 if (in_array_ics($oc, $classes)) {
904 $result.= image($properties['image'], "listing_edit_".$properties['plugin']."_$row", $properties['title']);
905 } else {
906 $result.= image('images/empty.png');
907 }
908 }
909 return $result;
910 }
912 }
913 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
914 ?>