efcef229846210e5b0e85783c110a6c9efea0a1e
1 <?php
2 /*!
3 \brief posixAccount plugin
4 \author Cajus Pollmeier <pollmeier@gonicus.de>
5 \version 2.00
6 \date 24.07.2003
8 This class provides the functionality to read and write all attributes
9 relevant for posixAccounts and shadowAccounts from/to the LDAP. It
10 does syntax checking and displays the formulars required.
11 */
13 class posixAccount extends plugin
14 {
15 /* Definitions */
16 var $plHeadline= "UNIX";
17 var $plDescription= "This does something";
19 /* CLI vars */
20 var $cli_summary= "Manage users posix account";
21 var $cli_description= "Some longer text\nfor help";
22 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
24 /* Plugin specific values */
25 var $homeDirectory= "";
26 var $loginShell= "/bin/bash";
27 var $uidNumber= "";
28 var $gidNumber= "";
29 var $gecos= "";
30 var $shadowMin= "0";
31 var $shadowMax= "0";
32 var $shadowWarning= "0";
33 var $shadowLastChange= "0";
34 var $shadowInactive= "0";
35 var $shadowExpire= "0";
36 var $gosaDefaultPrinter= "";
37 var $accessTo= array();
38 var $trustModel= "";
40 var $glist=array();
41 var $status= "";
42 var $loginShellList= array();
43 var $groupMembership= array();
44 var $savedGroupMembership= array();
45 var $savedUidNumber= "";
46 var $savedGidNumber= "";
47 var $use_shadowMin= "0";
48 var $use_shadowMax= "0";
49 var $use_shadowWarning= "0";
50 var $use_shadowInactive= "0";
51 var $use_shadowExpire= "0";
52 var $mustchangepassword= "0";
53 var $force_ids= 0;
54 var $group_dialog= FALSE;
55 var $show_ws_dialog= FALSE;
56 var $secondaryGroups= array();
57 var $primaryGroup= 0;
58 var $was_trust_account= FALSE;
59 var $memberGroup = array();
60 var $grouplist = array();
61 var $ui = array();
63 var $GroupRegex = "*";
64 var $GroupUserRegex = "*";
65 var $SubSearch = false;
67 var $view_logged = FALSE;
69 /* attribute list for save action */
70 var $CopyPasteVars =
71 array("grouplist","groupMembership","use_shadowMin",
72 "use_shadowMax","use_shadowWarning","use_shadowInactive","use_shadowExpire",
73 "must_change_password","printerList","grouplist","savedGidNumber","savedUidNumber");
75 var $attributes = array("homeDirectory", "loginShell", "uidNumber", "gidNumber", "gecos",
76 "shadowMin", "shadowMax", "shadowWarning", "shadowInactive", "shadowLastChange",
77 "shadowExpire", "gosaDefaultPrinter", "uid","accessTo","trustModel");
79 var $objectclasses= array("posixAccount", "shadowAccount");
81 var $uid= "";
82 var $multiple_support = TRUE;
83 var $groupMembership_some = array();
85 /* constructor, if 'dn' is set, the node loads the given
86 'dn' from LDAP */
87 function posixAccount (&$config, $dn= NULL)
88 {
89 /* Configuration is fine, allways */
90 $this->config= $config;
92 /* Load bases attributes */
93 plugin::plugin($config, $dn);
95 /* Setting uid to default */
96 if(isset($this->attrs['uid'][0])){
97 $this->uid = $this->attrs['uid'][0];
98 }
100 $ldap= $this->config->get_ldap_link();
102 if ($dn !== NULL){
104 /* Correct is_account. shadowAccount is not required. */
105 if (isset($this->attrs['objectClass']) &&
106 in_array ('posixAccount', $this->attrs['objectClass'])){
108 $this->is_account= TRUE;
109 }
111 /* Is this account a trustAccount? */
112 if ($this->is_account && isset($this->attrs['trustModel'])){
113 $this->trustModel= $this->attrs['trustModel'][0];
114 $this->was_trust_account= TRUE;
115 } else {
116 $this->was_trust_account= FALSE;
117 $this->trustModel= "";
118 }
120 $this->accessTo = array();
121 if ($this->is_account && isset($this->attrs['accessTo'])){
122 for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
123 $tmp= $this->attrs['accessTo'][$i];
124 $this->accessTo[$tmp]= $tmp;
125 }
126 }
127 $this->initially_was_account= $this->is_account;
129 /* Fill group */
130 $this->primaryGroup= $this->gidNumber;
132 /* Generate status text */
133 $current= date("U");
135 $current= floor($current / 60 /60 / 24);
137 if (($current >= $this->shadowExpire) && $this->shadowExpire){
138 $this->status= _("expired");
139 if (($current - $this->shadowExpire) < $this->shadowInactive){
140 $this->status.= ", "._("grace time active");
141 }
142 } elseif (($this->shadowLastChange + $this->shadowMin) >= $current){
143 $this->status= _("active, password not changable");
144 } elseif (($this->shadowLastChange + $this->shadowMax) >= $current){
145 $this->status= _("active, password expired");
146 } else {
147 $this->status= _("active");
148 }
150 /* Get group membership */
151 $ldap->cd($this->config->current['BASE']);
152 $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("cn", "description"));
154 while ($this->attrs= $ldap->fetch()){
155 if (!isset($this->attrs["description"][0])){
156 $entry= $this->attrs["cn"][0];
157 } else {
158 $dsc= preg_replace ('/^Group of user/', _("Group of user"), $this->attrs["description"][0]);
159 $entry= $this->attrs["cn"][0]." [$dsc]";
160 }
161 $this->groupMembership[$ldap->getDN()]= $entry;
162 }
163 asort($this->groupMembership);
164 reset($this->groupMembership);
165 $this->savedGroupMembership= $this->groupMembership;
166 $this->savedUidNumber= $this->uidNumber;
167 $this->savedGidNumber= $this->gidNumber;
168 }
170 /* Adjust shadow checkboxes */
171 foreach (array("shadowMin", "shadowMax", "shadowWarning", "shadowInactive",
172 "shadowExpire") as $val){
174 if ($this->$val != 0){
175 $oval= "use_".$val;
176 $this->$oval= "1";
177 }
178 }
180 /* Convert to seconds */
181 $this->shadowExpire= $this->convertToSeconds($this->shadowExpire);
183 /* Generate shell list from CONFIG_DIR./shells */
184 if (file_exists(CONFIG_DIR.'/shells')){
185 $shells = file (CONFIG_DIR.'/shells');
186 foreach ($shells as $line){
187 if (!preg_match ("/^#/", $line)){
188 $this->loginShellList[]= trim($line);
189 }
190 }
191 } else {
192 if ($this->loginShell == ""){
193 $this->loginShellList[]= _("unconfigured");
194 }
195 }
197 /* Insert possibly missing loginShell */
198 if ($this->loginShell != "" && !in_array($this->loginShell, $this->loginShellList)){
199 $this->loginShellList[]= $this->loginShell;
200 }
202 /* Generate group list */
203 $this->ui = get_userinfo();
204 $this->secondaryGroups[]= "- "._("automatic")." -";
205 $ldap->cd($this->config->current['BASE']);
206 $ldap->search("(objectClass=posixGroup)", array("cn", "gidNumber"));
207 while($attrs = $ldap->fetch()){
208 $this->secondaryGroups[$attrs['gidNumber'][0]]= $attrs['cn'][0];
209 }
210 asort ($this->secondaryGroups);
212 /* Get global filter config */
213 if (!is_global("sysfilter")){
214 $ui= get_userinfo();
215 $base= get_base_from_people($ui->dn);
216 $sysfilter= array( "depselect" => $base,
217 "regex" => "*");
218 register_global("sysfilter", $sysfilter);
219 }
220 $this->ui = get_userinfo();
221 }
224 /* execute generates the html output for this node */
225 function execute($isCopyPaste = false)
226 {
227 /* Call parent execute */
228 plugin::execute();
229 $display= "";
231 /* Log view */
232 if($this->is_account && !$this->view_logged){
233 $this->view_logged = TRUE;
234 new log("view","users/".get_class($this),$this->dn);
235 }
237 /* Department has changed? */
238 if(isset($_POST['depselect'])){
239 $_SESSION['CurrentMainBase']= validate($_POST['depselect']);
240 }
242 if($this->multiple_support_active){
243 $this->is_account = TRUE;
244 }
246 if(!$isCopyPaste && ! $this->multiple_support_active){
248 /* Do we need to flip is_account state? */
249 if(isset($_POST['modify_state'])){
250 if($this->is_account && $this->acl_is_removeable()){
251 $this->is_account= FALSE;
252 }elseif(!$this->is_account && $this->acl_is_createable()){
253 $this->is_account= TRUE;
254 }
255 }
257 /* Do we represent a valid posixAccount? */
258 if (!$this->is_account && $this->parent === NULL ){
259 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
260 _("This account has no unix extensions.")."</b>";
261 $display.= back_to_main();
262 return ($display);
263 }
266 /* Show tab dialog headers */
267 if ($this->parent !== NULL){
268 if ($this->is_account){
269 if (isset($this->parent->by_object['sambaAccount'])){
270 $obj= $this->parent->by_object['sambaAccount'];
271 }
272 if (isset($obj) && $obj->is_account == TRUE &&
273 ((isset($this->parent->by_object['sambaAccount']))&&($this->parent->by_object['sambaAccount']->is_account))
274 ||(isset($this->parent->by_object['environment'] ))&&($this->parent->by_object['environment'] ->is_account)){
276 /* Samba3 dependency on posix accounts are enabled
277 in the moment, because I need to rely on unique
278 uidNumbers. There'll be a better solution later
279 on. */
280 $display= $this->show_disable_header(_("Remove posix account"),
281 _("This account has unix features enabled. To disable them, you'll need to remove the samba / environment account first."), TRUE);
282 } else {
283 $display= $this->show_disable_header(_("Remove posix account"),
284 _("This account has posix features enabled. You can disable them by clicking below."));
285 }
286 } else {
287 $display= $this->show_enable_header(_("Create posix account"),
288 _("This account has posix features disabled. You can enable them by clicking below."));
289 return($display);
290 }
291 }
292 }
293 /* Trigger group edit? */
294 if (isset($_POST['edit_groupmembership'])){
295 $this->group_dialog= TRUE;
296 $this->dialog= TRUE;
297 }
299 /* Cancel group edit? */
300 if (isset($_POST['add_groups_cancel']) ||
301 isset($_POST['add_groups_finish'])){
302 $this->group_dialog= FALSE;
303 $this->dialog= FALSE;
304 }
306 /* Add selected groups */
307 if (isset($_POST['add_groups_finish']) && isset($_POST['groups']) &&
308 count($_POST['groups'])){
310 $this->addGroup ($_POST['groups']);
311 }
313 /* Delete selected groups */
314 if (isset($_POST['delete_groupmembership']) &&
315 isset($_POST['group_list']) && count($_POST['group_list'])){
317 $this->delGroup ($_POST['group_list']);
318 }
320 /* Add user workstation? */
321 if (isset($_POST["add_ws"])){
322 $this->show_ws_dialog= TRUE;
323 $this->dialog= TRUE;
324 }
326 /* Add user workstation? */
327 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
328 foreach($_POST['wslist'] as $ws){
329 $this->accessTo[$ws]= $ws;
330 }
331 ksort($this->accessTo);
332 $this->is_modified= TRUE;
333 }
335 /* Remove user workstations? */
336 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
337 foreach($_POST['workstation_list'] as $name){
338 unset ($this->accessTo[$name]);
339 }
340 $this->is_modified= TRUE;
341 }
343 /* Add user workstation finished? */
344 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
345 $this->show_ws_dialog= FALSE;
346 $this->dialog= FALSE;
347 }
349 /* Templates now! */
350 $smarty= get_smarty();
352 /* Show ws dialog */
353 if ($this->show_ws_dialog){
354 /* Save data */
355 $sysfilter= get_global("sysfilter");
356 foreach( array("depselect", "regex") as $type){
357 if (isset($_POST[$type])){
358 $sysfilter[$type]= $_POST[$type];
359 }
360 }
361 if (isset($_GET['search'])){
362 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
363 if ($s == "**"){
364 $s= "*";
365 }
366 $sysfilter['regex']= $s;
367 }
368 register_global("sysfilter", $sysfilter);
370 /* Get workstation list */
371 $exclude= "";
372 foreach($this->accessTo as $ws){
373 $exclude.= "(cn=$ws)";
374 }
375 if ($exclude != ""){
376 $exclude= "(!(|$exclude))";
377 }
378 $regex= $sysfilter['regex'];
379 $filter= "(&(|(objectClass=goServer)(objectClass=gotoWorkstation)(objectClass=gotoTerminal))$exclude(cn=*)(cn=$regex))";
380 $res= get_list($filter, "groups", $sysfilter['depselect'], array("cn"), GL_SUBSEARCH | GL_SIZELIMIT);
381 $wslist= array();
382 foreach ($res as $attrs){
383 $wslist[]= preg_replace('/\$/', '', $attrs['cn'][0]);
384 }
385 asort($wslist);
386 $smarty->assign("search_image", get_template_path('images/search.png'));
387 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
388 $smarty->assign("tree_image", get_template_path('images/tree.png'));
389 $smarty->assign("deplist", $this->config->idepartments);
390 $smarty->assign("alphabet", generate_alphabet());
391 foreach( array("depselect", "regex") as $type){
392 $smarty->assign("$type", $sysfilter[$type]);
393 }
394 $smarty->assign("hint", print_sizelimit_warning());
395 $smarty->assign("wslist", $wslist);
396 $smarty->assign("apply", apply_filter());
397 $display= $smarty->fetch (get_template_path('trust_machines.tpl', TRUE, dirname(__FILE__)));
398 return ($display);
399 }
401 /* Manage group add dialog */
402 if ($this->group_dialog){
404 /* Get global filter config */
405 $this->reload();
407 /* remove already assigned groups */
408 $glist= array();
409 foreach ($this->grouplist as $key => $value){
410 if (!isset($this->groupMembership[$key]) && obj_is_writable($key,"groups/group","memberUid")){
411 $glist[$key]= $value;
412 }
413 }
415 if($this->SubSearch){
416 $smarty->assign("SubSearchCHK"," checked ");
417 }else{
418 $smarty->assign("SubSearchCHK","");
419 }
421 $smarty->assign("regex",$this->GroupRegex);
422 $smarty->assign("guser",$this->GroupUserRegex);
423 $smarty->assign("groups", $glist);
424 $smarty->assign("search_image", get_template_path('images/search.png'));
425 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
426 $smarty->assign("tree_image", get_template_path('images/tree.png'));
427 $smarty->assign("deplist", $this->config->idepartments);
428 $smarty->assign("alphabet", generate_alphabet());
429 $smarty->assign("depselect",$_SESSION['CurrentMainBase']);
430 $smarty->assign("hint", print_sizelimit_warning());
432 $smarty->assign("apply", apply_filter());
433 $display.= $smarty->fetch (get_template_path('posix_groups.tpl', TRUE, dirname(__FILE__)));
434 return ($display);
435 }
437 /* Show main page */
438 $smarty= get_smarty();
440 /* In 'MyAccount' mode, we must remove write acls if we are not in editing mode. */
441 $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
443 /* Depending on pwmode, currently hardcoded because there are no other methods */
444 if ( 1 == 1 ){
445 $smarty->assign("pwmode", dirname(__FILE__)."/posix_shadow");
447 $shadowMinACL = $this->getacl("shadowMin",$SkipWrite);
448 $smarty->assign("shadowmins", sprintf(_("Password can't be changed up to %s days after last change"),
449 "<input name=\"shadowMin\" size=3 maxlength=4 value=\"".$this->shadowMin."\">"));
451 $shadowMaxACL = $this->getacl("shadowMax",$SkipWrite);
452 $smarty->assign("shadowmaxs", sprintf(_("Password must be changed after %s days"),
453 "<input name=\"shadowMax\" size=3 maxlength=4 value=\"".$this->shadowMax."\">"));
455 $shadowInactiveACL= $this->getacl("shadowInactive",$SkipWrite);
456 $smarty->assign("shadowinactives", sprintf(_("Disable account after %s days of inactivity after password expiery"),
457 "<input name=\"shadowInactive\" size=3 maxlength=4 value=\"".$this->shadowInactive."\">"));
459 $shadowWarningACL = $this->getacl("shadowWarning",$SkipWrite);
460 $smarty->assign("shadowwarnings", sprintf(_("Warn user %s days before password expiery"),
461 "<input name=\"shadowWarning\" size=3 maxlength=4 value=\"".$this->shadowWarning."\">"));
463 foreach( array("use_shadowMin", "use_shadowMax",
464 "use_shadowExpire", "use_shadowInactive","use_shadowWarning") as $val){
465 if ($this->$val == 1){
466 $smarty->assign("$val", "checked");
467 } else {
468 $smarty->assign("$val", "");
469 }
470 $smarty->assign("$val"."ACL", $this->getacl($val,$SkipWrite));
471 }
473 if($this->mustchangepassword){
474 $smarty->assign("mustchangepassword", "checked");
475 } else {
476 $smarty->assign("mustchangepassword", "");
477 }
478 $smarty->assign("mustchangepasswordACL", $this->getacl("mustchangepassword",$SkipWrite));
479 }
481 /* Fill calendar */
482 /* If this $this->shadowExpire is empty
483 use current date as base for calculating selectbox values.
484 (This attribute is empty if this is a new user )*/
485 if(empty($this->shadowExpire)){
486 $date= getdate(time());
487 }else{
488 $date= getdate($this->shadowExpire);
489 }
491 $days= array();
492 for($d= 1; $d<32; $d++){
493 $days[$d]= $d;
494 }
495 $years= array();
496 for($y= $date['year']-10; $y<$date['year']+10; $y++){
497 $years[]= $y;
498 }
499 $months= array(_("January"), _("February"), _("March"), _("April"),
500 _("May"), _("June"), _("July"), _("August"), _("September"),
501 _("October"), _("November"), _("December"));
502 $smarty->assign("day", $date["mday"]);
503 $smarty->assign("days", $days);
504 $smarty->assign("months", $months);
505 $smarty->assign("month", $date["mon"]-1);
506 $smarty->assign("years", $years);
507 $smarty->assign("year", $date["year"]);
509 /* Fill arrays */
510 $smarty->assign("shells", $this->loginShellList);
511 $smarty->assign("secondaryGroups", $this->secondaryGroups);
512 $smarty->assign("primaryGroup", $this->primaryGroup);
513 if(!$this->multiple_support_active){
514 if (!count($this->groupMembership)){
515 $smarty->assign("groupMembership", array(" "));
516 } else {
517 $smarty->assign("groupMembership", $this->groupMembership);
518 }
519 }else{
520 $smarty->assign("groupMembership", $this->groupMembership);
521 $smarty->assign("groupMembership_some", $this->groupMembership_some);
522 }
523 if (count($this->groupMembership) > 16){
524 $smarty->assign("groups", "too_many_for_nfs");
525 } else {
526 $smarty->assign("groups", "");
527 }
529 /* Avoid "Undefined index: forceMode" */
530 $smarty->assign("forceMode", "");
532 /* Checkboxes */
533 if ($this->force_ids == 1){
534 $smarty->assign("force_ids", "checked");
535 if ($_SESSION['js']){
536 $smarty->assign("forceMode", "");
537 }
538 } else {
539 if ($_SESSION['js']){
540 $smarty->assign("forceMode", "disabled");
541 }
542 $smarty->assign("force_ids", "");
543 }
547 $smarty->assign("force_idsACL", $this->getacl("uidNumber",$SkipWrite).$this->getacl("gidNumber",$SkipWrite));
549 foreach(array("primaryGroup") as $val){
550 if(in_array($val,$this->multi_boxes)){
551 $smarty->assign("use_".$val,TRUE);
552 }else{
553 $smarty->assign("use_".$val,FALSE);
554 }
555 }
558 /* Load attributes and acl's */
559 foreach($this->attributes as $val){
560 if(in_array($val,$this->multi_boxes)){
561 $smarty->assign("use_".$val,TRUE);
562 }else{
563 $smarty->assign("use_".$val,FALSE);
564 }
566 if(($_SESSION["js"])&&(($val=="uidNumber")||($val=="gidNumber")))
567 {
568 $smarty->assign("$val"."ACL",$this->getacl($val,$SkipWrite));
569 $smarty->assign("$val", $this->$val);
570 continue;
571 }
572 $smarty->assign("$val", $this->$val);
573 $smarty->assign("$val"."ACL", $this->getacl($val,$SkipWrite));
574 }
575 if($SkipWrite){
576 $smarty->assign("groupMembershipACL","r");
577 }else{
578 $smarty->assign("groupMembershipACL","rw");
579 }
580 $smarty->assign("status", $this->status);
582 /* Work on trust modes */
583 $smarty->assign("trusthide", " disabled ");
584 $smarty->assign("trustmodeACL", $this->getacl("trustModel",$SkipWrite));
585 if ($this->trustModel == "fullaccess"){
586 $trustmode= 1;
587 // pervent double disable tag in html code, this will disturb our clean w3c html
588 $smarty->assign("trustmode", $this->getacl("trustModel",$SkipWrite));
590 } elseif ($this->trustModel == "byhost"){
591 $trustmode= 2;
592 $smarty->assign("trusthide", "");
593 } else {
594 // pervent double disable tag in html code, this will disturb our clean w3c html
595 $smarty->assign("trustmode", $this->getacl("trustModel",$SkipWrite));
596 $trustmode= 0;
597 }
598 $smarty->assign("trustmode", $trustmode);
599 $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
600 2 => _("allow access to these hosts")));
604 if((count($this->accessTo))==0)
605 $smarty->assign("emptyArrAccess",true);
606 else
607 $smarty->assign("emptyArrAccess",false);
611 $smarty->assign("workstations", $this->accessTo);
613 $smarty->assign("apply", apply_filter());
614 $smarty->assign("multiple_support" , $this->multiple_support_active);
615 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
616 return($display);
617 }
620 /* remove object from parent */
621 function remove_from_parent()
622 {
623 /* Cancel if there's nothing to do here */
624 if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
625 return;
626 }
628 /* include global link_info */
629 $ldap= $this->config->get_ldap_link();
631 /* Remove and write to LDAP */
632 plugin::remove_from_parent();
634 /* Zero out array */
635 $this->attrs['gosaHostACL']= array();
637 /* Keep uid, because we need it for authentification! */
638 unset($this->attrs['uid']);
639 unset($this->attrs['trustModel']);
641 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
642 $this->attributes, "Save");
643 $ldap->cd($this->dn);
644 $this->cleanup();
645 $ldap->modify ($this->attrs);
647 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
649 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/posix account with dn '%s' failed."),$this->dn));
651 /* Delete group only if cn is uid and there are no other
652 members inside */
653 $ldap->cd ($this->config->current['BASE']);
654 $ldap->search ("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn", "memberUid"));
655 if ($ldap->count() != 0){
656 $attrs= $ldap->fetch();
657 if ($attrs['cn'][0] == $this->uid &&
658 !isset($this->attrs['memberUid'])){
660 $ldap->rmDir($ldap->getDN());
661 }
662 }
664 /* Optionally execute a command after we're done */
665 $this->handle_post_events("remove",array("uid" => $this->uid));
666 }
669 function save_object()
670 {
671 if (isset($_POST['posixTab'])){
672 /* Save values to object */
673 plugin::save_object();
676 /* Save force GID checkbox */
677 if($this->acl_is_writeable("gidNumber") || $this->acl_is_writeable("uidNumber")){
678 if (isset ($_POST['force_ids'])){
679 $data= 1;
680 } else {
681 $data= 0;
682 }
683 if ($this->force_ids != $data){
684 $this->is_modified= TRUE;
685 }
686 $this->force_ids= $data;
687 }
689 /*Save primary group settings */
690 if($this->acl_is_writeable("primaryGroup") && isset($_POST['primaryGroup'])){
691 $data= $_POST['primaryGroup'];
692 if ($this->primaryGroup != $data){
693 $this->is_modified= TRUE;
694 }
695 $this->primaryGroup= $_POST['primaryGroup'];
696 }
698 foreach(array("shadowMin","shadowMax","shadowExpire","shadowInactive","shadowWarning","mustchangepassword") as $var) {
699 if($this->acl_is_writeable($var)){
700 $use_var = "use_".$var;
701 if(isset($_POST['use_'.$var])){
702 $this->$use_var = true;
703 $this->$var = $_POST[$var];
704 }else{
705 $this->$use_var = false;
706 $this->$var = 0;
707 }
708 }
709 }
711 /* Trust mode - special handling */
712 if($this->acl_is_writeable("trustModel")){
713 if (isset($_POST['trustmode'])){
714 $saved= $this->trustModel;
715 if ($_POST['trustmode'] == "1"){
716 $this->trustModel= "fullaccess";
717 } elseif ($_POST['trustmode'] == "2"){
718 $this->trustModel= "byhost";
719 } else {
720 $this->trustModel= "";
721 }
722 if ($this->trustModel != $saved){
723 $this->is_modified= TRUE;
724 }
725 }
726 }
727 }
729 /* Get regex from alphabet */
730 if(isset($_GET['search'])){
731 $this->GroupRegex = $_GET['search']."*";
732 }
734 /* Check checkboxes and regexes */
735 if(isset($_POST["PosixGroupDialogPosted"])){
737 if(isset($_POST['SubSearch']) && ($_POST['SubSearch'])){
738 $this->SubSearch = true;
739 }else{
740 $this->SubSearch = false;
741 }
742 if(isset($_POST['guser'])){
743 $this->GroupUserRegex = $_POST['guser'];
744 }
745 if(isset($_POST['regex'])){
746 $this->GroupRegex = $_POST['regex'];
747 }
748 }
749 $this->GroupRegex = preg_replace("/\*\**/","*",$this->GroupRegex);
750 $this->GroupUserRegex = preg_replace("/\*\**/","*",$this->GroupUserRegex);
751 }
754 /* Save data to LDAP, depending on is_account we save or delete */
755 function save()
756 {
758 /* include global link_info */
759 $ldap= $this->config->get_ldap_link();
761 /* Adapt shadow values */
762 if (!$this->use_shadowExpire){
763 $this->shadowExpire= "0";
764 } else {
765 /* Transform seconds to days here */
766 $this->shadowExpire= (int)($this->shadowExpire / (60 * 60 * 24)) ;
767 }
768 if (!$this->use_shadowMax){
769 $this->shadowMax= "0";
770 }
771 if ($this->mustchangepassword){
772 $this->shadowLastChange= (int)(date("U") / 86400) - $this->shadowMax - 1;
773 } else {
774 $this->shadowLastChange= (int)(date("U") / 86400);
775 }
776 if (!$this->use_shadowWarning){
777 $this->shadowWarning= "0";
778 }
780 /* Check what to do with ID's */
781 if ($this->force_ids == 0){
783 /* Use id's that are already set */
784 if ($this->savedUidNumber != ""){
785 $this->uidNumber= $this->savedUidNumber;
786 $this->gidNumber= $this->savedGidNumber;
787 } else {
789 /* Calculate new id's. We need to place a lock before calling get_next_id
790 to get real unique values. */
791 $wait= 10;
792 while (get_lock("uidnumber") != ""){
793 sleep (1);
795 /* Oups - timed out */
796 if ($wait-- == 0){
797 print_red (_("Failed: overriding lock"));
798 break;
799 }
800 }
802 add_lock ("uidnumber", "gosa");
803 $this->uidNumber= $this->get_next_id("uidNumber", $this->dn);
804 if ($this->savedGidNumber != ""){
805 $this->gidNumber= $this->savedGidNumber;
806 } else {
807 $this->gidNumber= $this->get_next_id("gidNumber", $this->dn);
808 }
809 }
811 if ($this->primaryGroup != 0){
812 $this->gidNumber= $this->primaryGroup;
813 }
814 }
816 if ($this->use_shadowMin != "1" ) {
817 $this->shadowMin = "";
818 }
820 if (($this->use_shadowMax != "1") && ($this->mustchangepassword != "1")) {
821 $this->shadowMax = "";
822 }
824 if ($this->use_shadowWarning != "1" ) {
825 $this->shadowWarning = "";
826 }
828 if ($this->use_shadowInactive != "1" ) {
829 $this->shadowInactive = "";
830 }
832 if ($this->use_shadowExpire != "1" ) {
833 $this->shadowExpire = "";
834 }
836 /* Fill gecos */
837 if (isset($this->parent) && $this->parent !== NULL){
838 $this->gecos= rewrite($this->parent->by_object['user']->cn);
839 if (!preg_match('/^[a-z0-9 -]+$/i', $this->gecos)){
840 $this->gecos= "";
841 }
842 }
844 foreach(array("shadowMin","shadowMax","shadowWarning","shadowInactive","shadowExpire") as $attr){
845 $this->$attr = (int) $this->$attr;
846 }
847 /* Call parents save to prepare $this->attrs */
848 plugin::save();
850 /* Trust accounts */
851 $objectclasses= array();
852 foreach ($this->attrs['objectClass'] as $key => $class){
853 if (preg_match('/trustAccount/i', $class)){
854 continue;
855 }
856 $objectclasses[]= $this->attrs['objectClass'][$key];
857 }
858 $this->attrs['objectClass']= $objectclasses;
859 if ($this->trustModel != ""){
860 $this->attrs['objectClass'][]= "trustAccount";
861 $this->attrs['trustModel']= $this->trustModel;
862 $this->attrs['accessTo']= array();
863 if ($this->trustModel == "byhost"){
864 foreach ($this->accessTo as $host){
865 $this->attrs['accessTo'][]= $host;
866 }
867 }
868 } else {
869 if ($this->was_trust_account){
870 $this->attrs['accessTo']= array();
871 $this->attrs['trustModel']= array();
872 }
873 }
875 if(empty($this->attrs['gosaDefaultPrinter'])){
876 $thid->attrs['gosaDefaultPrinter']=array();
877 }
880 /* Save data to LDAP */
881 $ldap->cd($this->dn);
882 $this->cleanup();
883 unset($this->attrs['uid']);
884 $ldap->modify ($this->attrs);
886 /* Log last action */
887 if($this->initially_was_account){
888 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
889 }else{
890 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
891 }
893 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/posix account with dn '%s' failed."),$this->dn));
895 /* Remove lock needed for unique id generation */
896 del_lock ("uidnumber");
898 /* Posix accounts have group interrelationship,
899 take care about these here if this is a new user without forced gidNumber. */
900 if ($this->force_ids == 0 && $this->primaryGroup == 0 && !$this->initially_was_account){
901 $ldap->cd($this->config->current['BASE']);
902 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
904 /* Create group if it doesn't exist */
905 if ($ldap->count() == 0){
906 $groupdn= preg_replace ('/^'.$this->config->current['DNMODE'].'=[^,]+,'.get_people_ou().'/i', 'cn='.$this->uid.','.get_groups_ou(), $this->dn);
908 $g= new group($this->config, $groupdn);
909 $g->cn= $this->uid;
910 $g->force_gid= 1;
911 $g->gidNumber= $this->gidNumber;
912 $g->description= "Group of user ".$this->givenName." ".$this->sn;
913 $g->save ();
914 }
915 }
917 /* Take care about groupMembership values: add to groups */
918 foreach ($this->groupMembership as $key => $value){
919 if (!isset($this->savedGroupMembership[$key])){
920 $g= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $key,"groups");
921 $g->set_acl_base($key);
922 $g->by_object['group']->addUser($this->uid);
923 $g->save();
924 }
925 }
927 /* Remove from groups not listed in groupMembership */
928 foreach ($this->savedGroupMembership as $key => $value){
929 if (!isset($this->groupMembership[$key])){
930 $g= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $key,"groups");
931 $g->set_acl_base($key);
932 $g->by_object['group']->removeUser ($this->uid);
933 $g->save();
934 }
935 }
937 /* Optionally execute a command after we're done */
938 if ($this->initially_was_account == $this->is_account){
939 if ($this->is_modified){
940 $this->handle_post_events("modify",array("uid" => $this->uid));
941 }
942 } else {
943 $this->handle_post_events("add" ,array("uid"=> $this->uid));
944 }
945 }
947 /* Check formular input */
948 function check()
949 {
950 /* Include global link_info */
951 $ldap= $this->config->get_ldap_link();
953 /* Append groups as memberGroup: to check hook
954 */
955 $tmp_attributes = $this->attributes;
956 $this->attributes[] = "memberGroup";
957 $this->memberGroup = array();
958 foreach($this->groupMembership as $dn => $name){
959 $this->memberGroup[] = $name;
960 }
962 /* Call common method to give check the hook */
963 $message= plugin::check();
964 $this->attributes = $tmp_attributes;
966 /* must: homeDirectory */
967 if ($this->homeDirectory == ""){
968 $message[]= _("The required field 'Home directory' is not set.");
969 }
970 if (!is_path($this->homeDirectory)){
971 $message[]= _("Please enter a valid path in 'Home directory' field.");
972 }
974 /* Check ID's if they are forced by user */
975 if ($this->force_ids == "1"){
977 /* Valid uid/gid? */
978 if (!is_id($this->uidNumber)){
979 $message[]= _("Value specified as 'UID' is not valid.");
980 } else {
981 if ($this->uidNumber < $this->config->current['MINID']){
982 $message[]= _("Value specified as 'UID' is too small.");
983 }
984 }
985 if (!is_id($this->gidNumber)){
986 $message[]= _("Value specified as 'GID' is not valid.");
987 } else {
988 if ($this->gidNumber < $this->config->current['MINID']){
989 $message[]= _("Value specified as 'GID' is too small.");
990 }
991 }
992 }
994 /* Check shadow settings, well I like spaghetties... */
995 if ($this->use_shadowMin){
996 if (!is_id($this->shadowMin)){
997 $message[]= _("Value specified as 'shadowMin' is not valid.");
998 }
999 }
1000 if ($this->use_shadowMax){
1001 if (!is_id($this->shadowMax)){
1002 $message[]= _("Value specified as 'shadowMax' is not valid.");
1003 }
1004 }
1005 if ($this->use_shadowWarning){
1006 if (!is_id($this->shadowWarning)){
1007 $message[]= _("Value specified as 'shadowWarning' is not valid.");
1008 }
1009 if (!$this->use_shadowMax){
1010 $message[]= _("'shadowWarning' without 'shadowMax' makes no sense.");
1011 }
1012 if ($this->shadowWarning > $this->shadowMax){
1013 $message[]= _("Value specified as 'shadowWarning' should be smaller than 'shadowMax'.");
1014 }
1015 if ($this->use_shadowMin && $this->shadowWarning < $this->shadowMin){
1016 $message[]= _("Value specified as 'shadowWarning' should be greater than 'shadowMin'.");
1017 }
1018 }
1019 if ($this->use_shadowInactive){
1020 if (!is_id($this->shadowInactive)){
1021 $message[]= _("Value specified as 'shadowInactive' is not valid.");
1022 }
1023 if (!$this->use_shadowMax){
1024 $message[]= _("'shadowInactive' without 'shadowMax' makes no sense.");
1025 }
1026 }
1027 if ($this->use_shadowMin && $this->use_shadowMax){
1028 if ($this->shadowMin > $this->shadowMax){
1029 $message[]= _("Value specified as 'shadowMin' should be smaller than 'shadowMax'.");
1030 }
1031 }
1033 // if(empty($this->gosaDefaultPrinter)){
1034 // $message[]= _("You need to specify a valid default printer.");
1035 // }
1037 return ($message);
1038 }
1040 function addGroup ($groups)
1041 {
1042 /* include global link_info */
1043 $ldap= $this->config->get_ldap_link();
1045 /* Walk through groups and add the descriptive entry if not exists */
1046 foreach ($groups as $value){
1048 if (!array_key_exists($value, $this->groupMembership)){
1049 $ldap->cat($value, array('cn', 'description', 'dn'));
1050 $attrs= $ldap->fetch();
1051 error_reporting (0);
1052 if (!isset($attrs['description'][0])){
1053 $entry= $attrs["cn"][0];
1054 } else {
1055 $dsc= preg_replace ('/^Group of user/', _("Group of user"), $attrs["description"][0]);
1056 $entry= $attrs["cn"][0]." [$dsc]";
1057 }
1058 error_reporting (E_ALL | E_STRICT);
1060 if(obj_is_writable($attrs['dn'],"groups/group","memberUid")){
1061 $this->groupMembership[$attrs['dn']]= $entry;
1062 if($this->multiple_support_active && isset($this->groupMembership_some[$attrs['dn']])){
1063 unset($this->groupMembership_some[$attrs['dn']]);
1064 }
1065 }
1066 }
1067 }
1069 /* Sort groups */
1070 asort ($this->groupMembership);
1071 reset ($this->groupMembership);
1072 }
1075 /* Del posix user from some groups */
1076 function delGroup ($groups)
1077 {
1078 $dest= array();
1079 foreach($groups as $dn_to_del){
1080 if(isset($this->groupMembership[$dn_to_del]) && obj_is_writable($dn_to_del,"groups/group","memberUid")){
1081 unset($this->groupMembership[$dn_to_del]);
1082 }
1083 if($this->multiple_support_active){
1084 if(isset($this->groupMembership_some[$dn_to_del]) && obj_is_writable($dn_to_del,"groups/group","memberUid")){
1085 unset($this->groupMembership_some[$dn_to_del]);
1086 }
1087 }
1088 }
1089 }
1092 /* Adapt from template, using 'dn' */
1093 function adapt_from_template($dn)
1094 {
1095 /* Include global link_info */
1096 $ldap= $this->config->get_ldap_link();
1098 plugin::adapt_from_template($dn);
1099 $template= $this->attrs['uid'][0];
1101 /* Adapt group membership */
1102 $ldap->cd($this->config->current['BASE']);
1103 $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->attrs["uid"][0]."))", array("description", "cn"));
1105 while ($this->attrs= $ldap->fetch()){
1106 if (!isset($this->attrs["description"][0])){
1107 $entry= $this->attrs["cn"][0];
1108 } else {
1109 $entry= $this->attrs["cn"][0]." [".$this->attrs["description"][0]."]";
1110 }
1111 $this->groupMembership[$ldap->getDN()]= $entry;
1112 }
1114 /* Fix primary group settings */
1115 $ldap->cd($this->config->current['BASE']);
1116 $ldap->search("(&(objectClass=posixGroup)(cn=$template)(gidNumber=".$this->gidNumber."))", array("cn"));
1117 if ($ldap->count() != 1){
1118 $this->primaryGroup= $this->gidNumber;
1119 }
1121 $ldap->cd($this->config->current['BASE']);
1122 $ldap->search("(&(objectClass=gosaUserTemplate)(uid=".$template.")(accessTo=*))", array("cn","accessTo"));
1123 while($attr = $ldap->fetch()){
1124 $tmp = $attr['accessTo'];
1125 unset ($tmp['count']);
1126 $this->accessTo = $tmp;
1127 }
1129 /* Adjust shadow checkboxes */
1130 foreach (array("shadowMin", "shadowMax", "shadowWarning", "shadowInactive") as $val){
1131 if ($this->$val != 0){
1132 $oval= "use_".$val;
1133 $this->$oval= "1";
1134 }
1135 }
1137 /* FIXME: NEED review of this section */
1138 /* Need to check shadowExpire separately */
1140 /*
1141 * If shadowExpire is not enabled in the template, it's a UNIX timestamp - so don't convert it to seconds.
1142 * The check is a hack - if difference between timestamp generated above and here is max 1 day.
1143 */
1144 if(abs($this->shadowExpire - time())>86400) {
1145 $this->shadowExpire= $this->convertToSeconds($this->shadowExpire);
1146 }
1148 /* Only enable checkbox, if shadowExpire is in the future */
1149 if($this->shadowExpire > time()) {
1150 $this->use_shadowExpire= "1";
1151 }
1152 }
1154 function convertToSeconds($val)
1155 {
1156 if ($val != 0){
1157 $val*= 60 * 60 * 24;
1158 } else {
1159 $date= getdate();
1160 $val= floor($date[0] / (60*60*24)) * 60 * 60 * 24;
1161 }
1162 return($val);
1163 }
1166 function get_next_id($attrib, $dn)
1167 {
1168 $ids= array();
1169 $ldap= $this->config->get_ldap_link();
1171 $ldap->cd ($this->config->current['BASE']);
1172 if (preg_match('/gidNumber/i', $attrib)){
1173 $oc= "posixGroup";
1174 } else {
1175 $oc= "posixAccount";
1176 }
1177 $ldap->search ("(&(objectClass=$oc)($attrib=*))", array("$attrib"));
1179 /* Get list of ids */
1180 while ($attrs= $ldap->fetch()){
1181 $ids[]= (int)$attrs["$attrib"][0];
1182 }
1184 /* Add the nobody id */
1185 $ids[]= 65534;
1187 /* get the ranges */
1188 $tmp = array('0'=> 1000);
1189 if (preg_match('/posixAccount/', $oc) && isset($this->config->current['UIDBASE'])) {
1190 $tmp= split('-',$this->config->current['UIDBASE']);
1191 } elseif(isset($this->config->current['GIDBASE'])){
1192 $tmp= split('-',$this->config->current['GIDBASE']);
1193 }
1195 /* Set hwm to max if not set - for backward compatibility */
1196 $lwm= $tmp[0];
1197 if (isset($tmp[1])){
1198 $hwm= $tmp[1];
1199 } else {
1200 $hwm= pow(2,32);
1201 }
1203 /* Find out next free id near to UID_BASE */
1204 if (!isset($this->config->current['BASE_HOOK'])){
1205 $base= $lwm;
1206 } else {
1207 /* Call base hook */
1208 $base= get_base_from_hook($dn, $attrib);
1209 }
1210 for ($id= $base; $id++; $id < pow(2,32)){
1211 if (!in_array($id, $ids)){
1212 return ($id);
1213 }
1214 }
1216 /* Should not happen */
1217 if ($id == $hwm){
1218 print_red(_("Too many users, can't allocate a free ID!"));
1219 exit;
1220 }
1222 }
1224 function reload()
1225 {
1226 /* Set base for all searches */
1227 $base = $_SESSION['CurrentMainBase'];
1228 $base = $base;
1229 $ldap = $this->config->get_ldap_link();
1230 $attrs = array("cn", "description", "gidNumber");
1231 $Flags = GL_SIZELIMIT;
1233 /* Get groups */
1234 if ($this->GroupUserRegex == '*'){
1235 $filter = "(&(objectClass=posixGroup)(cn=".$this->GroupRegex."))";
1236 } else {
1237 $filter= "(&(objectClass=posixGroup)(cn=".$this->GroupRegex.")(memberUid=".$this->GroupUserRegex."))";
1238 }
1239 if($this->SubSearch){
1240 $Flags |= GL_SUBSEARCH;
1241 }else{
1242 $base = get_groups_ou().$base;
1243 }
1245 $res= get_list($filter, "groups", $base,$attrs, $Flags);
1247 /* check sizelimit */
1248 if (preg_match("/size limit/i", $ldap->error)){
1249 $_SESSION['limit_exceeded']= TRUE;
1250 }
1252 /* Create a list of users */
1253 $this->grouplist = array();
1254 foreach ($res as $value){
1255 $this->grouplist[$value['gidNumber'][0]]= $value;
1256 }
1258 $tmp=array();
1259 foreach($this->grouplist as $tkey => $val ){
1260 $tmp[strtolower($val['cn'][0]).$val['cn'][0]]=$val;
1261 }
1263 /* Sort index */
1264 ksort($tmp);
1266 /* Recreate index array[dn]=cn[description]*/
1267 $this->grouplist=array();
1268 foreach($tmp as $val){
1269 if(isset($val['description'])){
1270 $this->grouplist[$val['dn']]=$val['cn'][0]." [".$val['description'][0]."]";
1271 }else{
1272 $this->grouplist[$val['dn']]=$val['cn'][0];
1273 }
1274 }
1276 reset ($this->grouplist);
1277 }
1280 /* Get posts from copy & paste dialog */
1281 function saveCopyDialog()
1282 {
1283 if(isset($_POST['homeDirectory'])){
1284 $this->homeDirectory = $_POST['homeDirectory'];
1285 if (isset ($_POST['force_ids'])){
1286 $data= 1;
1287 $this->gidNumber = $_POST['gidNumber'];
1288 $this->uidNumber = $_POST['uidNumber'];
1289 } else {
1290 $data= 0;
1291 }
1292 if ($this->force_ids != $data){
1293 $this->is_modified= TRUE;
1294 }
1295 $this->force_ids= $data;
1296 }
1297 }
1300 /* Create the posix dialog part for copy & paste */
1301 function getCopyDialog()
1302 {
1303 /* Skip dialog creation if this is not a valid account*/
1304 if(!$this->is_account) return("");
1305 if ($this->force_ids == 1){
1306 $force_ids = "checked";
1307 if ($_SESSION['js']){
1308 $forceMode = "";
1309 }
1310 } else {
1311 if ($_SESSION['js']){
1312 if($this->acl != "#none#")
1313 $forceMode ="disabled";
1314 }
1315 $force_ids = "";
1316 }
1318 $sta = "";
1320 /* Open group add dialog */
1321 if(isset($_POST['edit_groupmembership'])){
1322 $this->group_dialog = TRUE;
1323 $sta = "SubDialog";
1324 }
1326 /* If the group-add dialog is closed, call execute
1327 to ensure that the membership is updatd */
1328 if(isset($_POST['add_groups_finish']) || isset($_POST['add_groups_cancel'])){
1329 $this->execute();
1330 $this->group_dialog =FALSE;
1331 }
1333 if($this->group_dialog){
1334 $str = $this->execute(true);
1335 $ret = array();
1336 $ret['string'] = $str;
1337 $ret['status'] = $sta;
1338 return($ret);
1339 }
1341 /* If a group member should be deleted, simply call execute */
1342 if(isset($_POST['delete_groupmembership'])){
1343 $this->execute();
1344 }
1346 /* Assigned informations to smarty */
1347 $smarty = get_smarty();
1348 $smarty->assign("homeDirectory",$this->homeDirectory);
1349 $smarty->assign("uidNumber",$this->uidNumber);
1350 $smarty->assign("gidNumber",$this->gidNumber);
1351 $smarty->assign("forceMode",$forceMode);
1352 $smarty->assign("force_ids",$force_ids);
1353 if (!count($this->groupMembership)){
1354 $smarty->assign("groupMembership", array(" "));
1355 } else {
1356 $smarty->assign("groupMembership", $this->groupMembership);
1357 }
1359 /* Display wars message if there are more than 16 group members */
1360 if (count($this->groupMembership) > 16){
1361 $smarty->assign("groups", "too_many_for_nfs");
1362 } else {
1363 $smarty->assign("groups", "");
1364 }
1365 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1367 $ret = array();
1368 $ret['string'] = $str;
1369 $ret['status'] = $sta;
1370 return($ret);
1371 }
1374 function PrepareForCopyPaste($source)
1375 {
1376 plugin::PrepareForCopyPaste($source);
1378 /* Avoid using the same gid/uid number as source user */
1379 $this->savedUidNumber = $this->get_next_id("gidNumber", $this->dn);
1380 $this->savedGidNumber = $this->get_next_id("uidNumber", $this->dn);
1381 }
1384 function multiple_execute()
1385 {
1386 return($this->execute());
1387 }
1390 static function plInfo()
1391 {
1392 return (array(
1393 "plDescription" => _("POSIX account"),
1394 "plSelfModify" => TRUE,
1395 "plDepends" => array("user"),
1396 "plPriority" => 2,
1397 "plSection" => array("personal" => _("My account")),
1398 "plCategory" => array("users"),
1399 "plOptions" => array(),
1401 "plProvidedAcls" => array(
1403 "homeDirectory" => _("Home directory"),
1404 "loginShell" => _("Shell"),
1405 "uidNumber" => _("User ID"),
1406 "gidNumber" => _("Group ID"),
1408 "mustchangepassword"=> _("Force password change on login"),
1409 "shadowMin" => _("Shadow min"),
1410 "shadowMax" => _("Shadow max"),
1411 "shadowWarning" => _("Shadow warning"),
1412 "shadowInactive" => _("Shadow inactive"),
1413 "shadowExpire" => _("Shadow expire"),
1414 "trustModel" => _("System trust model")))
1415 );
1416 }
1418 function get_multi_edit_values()
1419 {
1420 $ret = plugin::get_multi_edit_values();
1421 $ret['groupMembership'] = $this->groupMembership;
1422 $ret['groupMembership_some']= $this->groupMembership_some;
1424 if(in_array("primaryGroup",$this->multi_boxes)){
1425 $ret['primaryGroup'] = $this->primaryGroup;
1426 }
1427 return($ret);
1428 }
1431 function multiple_save_object()
1432 {
1433 if(isset($_POST['posix_mulitple_edit'])){
1434 plugin::multiple_save_object();
1435 foreach(array("primaryGroup") as $val){
1436 if(isset($_POST["use_".$val])){
1437 $this->multi_boxes[] = $val;
1438 }
1439 }
1441 /* Save primary group settings */
1442 if($this->acl_is_writeable("primaryGroup") && isset($_POST['primaryGroup'])){
1443 $data= $_POST['primaryGroup'];
1444 if ($this->primaryGroup != $data){
1445 $this->is_modified= TRUE;
1446 }
1447 $this->primaryGroup= $_POST['primaryGroup'];
1448 }
1449 }
1450 }
1452 function init_multiple_support($attrs,$all)
1453 {
1454 plugin::init_multiple_support($attrs,$all);
1456 restore_error_handler();
1458 $groups_some = array();
1459 $groups_all = array();
1460 $groups_uid = array();
1461 $uids = array();
1462 $first = TRUE;
1464 $uid_filter="";
1465 for($i =0; $i < $this->multi_attrs_all['uid']['count'] ; $i ++){
1466 $uid = $this->multi_attrs_all['uid'][$i];
1467 $uids[] = $uid;
1468 $uid_filter.= "(memberUid=".$uid.")";
1469 }
1470 $uid_filter = "(&(objectClass=posixGroup)(|".$uid_filter."))";
1471 $ldap = $this->config->get_ldap_link();
1472 $ldap->cd($this->config->current['BASE']);
1473 $ldap->search($uid_filter,array("dn","cn","memberUid"));
1474 while($group = $ldap->fetch()){
1475 $groups_some[$group['dn']] = $group['cn'][0];
1476 for($i = 0 ; $i < $group['memberUid']['count'] ; $i++){
1477 $groups_uid[$group['dn']][] = $group['memberUid'][$i];
1478 }
1479 }
1481 $groups_all = $groups_some;
1482 foreach($groups_all as $id => $group){
1483 foreach($uids as $uid){
1484 if(!in_array($uid,$groups_uid[$id])){
1485 unset($groups_all[$id]);
1486 break;
1487 }
1488 }
1489 }
1491 $this->groupMembership = $groups_all;
1492 foreach( $groups_all as $dn => $cn){
1493 if(isset($groups_some[$dn])){
1494 unset($groups_some[$dn]);
1495 }
1496 }
1497 $this->groupMembership_some = $groups_some;
1499 $this->primaryGroup = $this->gidNumber;
1500 }
1503 function set_multi_edit_values($attrs)
1504 {
1505 $groups = array();
1507 /* Update groupMembership, keep optinal group */
1508 foreach($attrs['groupMembership_some'] as $dn => $cn){
1509 if(isset($this->groupMembership[$dn])){
1510 $groups[$dn] = $cn;
1511 }
1512 }
1513 /* Update groupMembership, add forced groups */
1514 foreach($attrs['groupMembership'] as $dn => $cn){
1515 $groups[$dn] = $cn;
1516 }
1517 plugin::set_multi_edit_values($attrs);
1518 $this->groupMembership = $groups;
1519 }
1520 }
1522 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1523 ?>