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 /*!
24 \brief posixAccount plugin
25 \author Cajus Pollmeier <pollmeier@gonicus.de>
26 \version 2.00
27 \date 24.07.2003
29 This class provides the functionality to read and write all attributes
30 relevant for posixAccounts and shadowAccounts from/to the LDAP. It
31 does syntax checking and displays the formulars required.
32 */
34 class posixAccount extends plugin
35 {
36 /* Definitions */
37 var $plHeadline= "UNIX";
38 var $plDescription= "Edit users POSIX settings";
40 /* Plugin specific values */
41 var $homeDirectory= "";
42 var $loginShell= "/bin/bash";
43 var $uidNumber= "";
44 var $gidNumber= "";
45 var $gecos= "";
46 var $shadowMin= "0";
47 var $shadowMax= "0";
48 var $shadowWarning= "0";
49 var $shadowLastChange= "0";
50 var $shadowInactive= "0";
51 var $shadowExpire= "";
52 var $gosaDefaultPrinter= "";
53 var $accessTo= array();
54 var $trustModel= "";
56 var $glist=array();
57 var $status= "";
58 var $loginShellList= array();
59 var $groupMembership= array();
60 var $savedGroupMembership= array();
61 var $savedUidNumber= "";
62 var $savedGidNumber= "";
63 var $activate_shadowMin= "0";
64 var $activate_shadowMax= "0";
65 var $activate_shadowWarning= "0";
66 var $activate_shadowInactive= "0";
67 var $activate_shadowExpire= "0";
68 var $mustchangepassword= "0";
69 var $force_ids= 0;
70 var $gotoLastSystemLogin= "";
71 var $groupSelect= FALSE;
72 var $trustSelect= FALSE;
73 var $secondaryGroups= array();
74 var $primaryGroup= 0;
75 var $was_trust_account= FALSE;
76 var $memberGroup= array();
77 var $grouplist= array();
78 var $ui= array();
79 var $ssh= null;
80 var $sshAcl= "";
82 var $GroupRegex= "*";
83 var $GroupUserRegex= "*";
84 var $SubSearch= false;
86 var $view_logged= false;
88 /* attribute list for save action */
89 var $CopyPasteVars =
90 array("grouplist","groupMembership","activate_shadowMin",
91 "activate_shadowMax","activate_shadowWarning","activate_shadowInactive","activate_shadowExpire",
92 "must_change_password","printerList","grouplist","savedGidNumber","savedUidNumber");
94 var $attributes = array("homeDirectory", "loginShell", "uidNumber", "gidNumber", "gecos",
95 "shadowMin", "shadowMax", "shadowWarning", "shadowInactive", "shadowLastChange",
96 "shadowExpire", "gosaDefaultPrinter", "uid","accessTo","trustModel", "gotoLastSystemLogin");
98 var $objectclasses= array("posixAccount", "shadowAccount");
100 var $uid= "";
101 var $multiple_support = TRUE;
102 var $groupMembership_some = array();
104 /* constructor, if 'dn' is set, the node loads the given
105 'dn' from LDAP */
106 function posixAccount (&$config, $dn= NULL)
107 {
108 global $class_mapping;
110 /* Configuration is fine, allways */
111 $this->config= $config;
113 /* Load bases attributes */
114 plugin::plugin($config, $dn);
116 /* If gotoLastSystemLogin is available read it from ldap and create a readable
117 date time string, fallback to sambaLogonTime if available.
118 */
119 if(isset($this->attrs['gotoLastSystemLogin'][0]) && preg_match("/^[0-9]*$/",$this->attrs['gotoLastSystemLogin'][0])){
120 $this->gotoLastSystemLogin = date("d.m.Y H:i:s", strtotime($this->attrs['gotoLastSystemLogin'][0]));
121 } else if(isset($this->attrs['sambaLogonTime'][0]) && preg_match("/^[0-9]*$/",$this->attrs['sambaLogonTime'][0])){
122 $this->gotoLastSystemLogin = date("d.m.Y H:i:s", $this->attrs['sambaLogonTime'][0]);
123 }
125 /* Setting uid to default */
126 if(isset($this->attrs['uid'][0])){
127 $this->uid = $this->attrs['uid'][0];
128 }
130 $ldap= $this->config->get_ldap_link();
132 if ($dn !== NULL){
134 /* Correct is_account. shadowAccount is not required. */
135 if (isset($this->attrs['objectClass']) &&
136 in_array ('posixAccount', $this->attrs['objectClass'])){
138 $this->is_account= TRUE;
139 }
141 /* Is this account a trustAccount? */
142 if ($this->is_account && isset($this->attrs['trustModel'])){
143 $this->trustModel= $this->attrs['trustModel'][0];
144 $this->was_trust_account= TRUE;
145 } else {
146 $this->was_trust_account= FALSE;
147 $this->trustModel= "";
148 }
150 $this->accessTo = array();
151 if ($this->is_account && isset($this->attrs['accessTo'])){
152 for ($i= 0; $i<$this->attrs['accessTo']['count']; $i++){
153 $tmp= $this->attrs['accessTo'][$i];
154 $this->accessTo[$tmp]= $tmp;
155 }
156 }
157 $this->initially_was_account= $this->is_account;
159 /* Fill group */
160 $this->primaryGroup= $this->gidNumber;
162 /* Generate status text */
163 $current= date("U");
165 $current= floor($current / 60 /60 / 24);
167 if (($current >= $this->shadowExpire) && $this->shadowExpire){
168 $this->status= _("expired");
169 if (($current - $this->shadowExpire) < $this->shadowInactive){
170 $this->status.= ", "._("grace time active");
171 }
172 } elseif (($this->shadowLastChange + $this->shadowMin) >= $current){
173 $this->status= _("active").", "._("password not changeable");
174 } elseif (($this->shadowLastChange + $this->shadowMax) >= $current){
175 $this->status= _("active").", "._("password expired");
176 } else {
177 $this->status= _("active");
178 }
180 /* Get group membership */
181 $ldap->cd($this->config->current['BASE']);
182 $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->uid."))", array("cn", "description"));
184 while ($attrs= $ldap->fetch()){
185 if (!isset($attrs["description"][0])){
186 $entry= $attrs["cn"][0];
187 } else {
188 $entry= $attrs["cn"][0]." [".$attrs["description"][0]."]";
189 }
190 $this->groupMembership[$ldap->getDN()]= $entry;
191 }
192 asort($this->groupMembership);
193 reset($this->groupMembership);
194 $this->savedGroupMembership= $this->groupMembership;
195 $this->savedUidNumber= $this->uidNumber;
196 $this->savedGidNumber= $this->gidNumber;
198 // Instanciate SSH object if available
199 if (isset($class_mapping["sshPublicKey"])){
200 if (empty($this->acl_base)){
201 $this->acl_base= $config->current['BASE'];
202 }
204 $this->sshAcl= $this->getacl("sshPublicKey");
205 $this->ssh= new sshPublicKey($this->config, $this->dn, $this->sshAcl);
206 }
207 }
209 /* Adjust shadow checkboxes */
210 foreach (array("shadowMin", "shadowMax", "shadowWarning", "shadowInactive",
211 "shadowExpire") as $val){
213 if ($this->$val != 0){
214 $oval= "activate_".$val;
215 $this->$oval= "1";
216 }
217 }
219 /* Convert shadowExpire for usage */
220 if ($this->shadowExpire == 0){
221 $this->shadowExpire= "";
222 } else {
223 $this->shadowExpire= date('d.m.Y', $this->shadowExpire * 60 * 60 * 24);
224 }
227 /* Generate shell list from CONFIG_DIR./shells */
228 if (file_exists(CONFIG_DIR.'/shells')){
229 $shells = file (CONFIG_DIR.'/shells');
230 foreach ($shells as $line){
231 if (!preg_match ("/^#/", $line)){
232 $this->loginShellList[]= trim($line);
233 }
234 }
235 } else {
236 if ($this->loginShell == ""){
237 $this->loginShellList[]= _("unconfigured");
238 }
239 }
241 /* Insert possibly missing loginShell */
242 if ($this->loginShell != "" && !in_array($this->loginShell, $this->loginShellList)){
243 $this->loginShellList[]= $this->loginShell;
244 }
246 /* Generate group list */
247 $this->ui = get_userinfo();
248 $this->secondaryGroups[]= "- "._("automatic")." -";
249 $ldap->cd($this->config->current['BASE']);
250 $ldap->search("(objectClass=posixGroup)", array("cn", "gidNumber"));
251 while($attrs = $ldap->fetch()){
252 $this->secondaryGroups[$attrs['gidNumber'][0]]= $attrs['cn'][0];
253 }
254 asort ($this->secondaryGroups);
256 /* Get global filter config */
257 if (!session::is_set("sysfilter")){
258 $ui= get_userinfo();
259 $base= get_base_from_people($ui->dn);
260 $sysfilter= array( "depselect" => $base,
261 "regex" => "*");
262 session::set("sysfilter", $sysfilter);
263 }
264 $this->ui = get_userinfo();
265 }
268 /* execute generates the html output for this node */
269 function execute($isCopyPaste = false)
270 {
271 /* Call parent execute */
272 plugin::execute();
273 $display= "";
275 /* Log view */
276 if($this->is_account && !$this->view_logged){
277 $this->view_logged = TRUE;
278 new log("view","users/".get_class($this),$this->dn);
279 }
281 /* Department has changed? */
282 if(isset($_POST['depselect'])){
283 session::set('CurrentMainBase',validate($_POST['depselect']));
284 }
286 if($this->multiple_support_active){
287 $this->is_account = TRUE;
288 }
290 if(!$isCopyPaste && ! $this->multiple_support_active){
292 /* Do we need to flip is_account state? */
293 if(isset($_POST['modify_state'])){
294 if($this->is_account && $this->acl_is_removeable()){
295 $this->is_account= FALSE;
296 }elseif(!$this->is_account && $this->acl_is_createable()){
297 $this->is_account= TRUE;
298 }
299 }
301 /* Do we represent a valid posixAccount? */
302 if (!$this->is_account && $this->parent === NULL ){
303 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
304 msgPool::noValidExtension(_("POSIX"))."</b>";
305 $display.= back_to_main();
306 return ($display);
307 }
310 /* Show tab dialog headers */
311 if ($this->parent !== NULL){
312 if ($this->is_account){
313 if (isset($this->parent->by_object['sambaAccount'])){
314 $obj= $this->parent->by_object['sambaAccount'];
315 }
316 if (isset($obj) && $obj->is_account == TRUE &&
317 ((isset($this->parent->by_object['sambaAccount']))&&($this->parent->by_object['sambaAccount']->is_account))
318 ||(isset($this->parent->by_object['environment'] ))&&($this->parent->by_object['environment'] ->is_account)){
320 /* Samba3 dependency on posix accounts are enabled
321 in the moment, because I need to rely on unique
322 uidNumbers. There'll be a better solution later
323 on. */
324 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("POSIX")), msgPool::featuresEnabled(_("POSIX"), array(_("Samba"), _("Environment"))), TRUE);
325 } else {
326 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("POSIX")), msgPool::featuresEnabled(_("POSIX")));
327 }
328 } else {
329 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("POSIX")), msgPool::featuresDisabled(_("POSIX")));
330 return($display);
331 }
332 }
333 }
335 // Display dialog to allow selection of groups
336 if (isset($_POST['edit_groupmembership'])){
337 $this->groupSelect = new groupSelect($this->config,get_userinfo());
338 $this->dialog= TRUE;
339 }
341 // Allow to select trusted machines from a list
342 if (isset($_POST["add_ws"])){
343 $this->trustSelect= new trustSelect($this->config,get_userinfo());
344 $this->dialog= TRUE;
345 }
347 // Cancel trust and group dialog
348 if (isset($_POST['add_groups_cancel']) || isset($_POST['add_ws_cancel'])){
349 $this->groupSelect= NULL;
350 $this->trustSelect= NULL;
351 $this->dialog= FALSE;
352 }
354 // Add groups selected in groupSelect dialog to ours.
355 if (isset($_POST['add_groups_finish']) && $this->groupSelect){
356 $groups = $this->groupSelect->detectPostActions();
357 if(isset($groups['targets'])){
358 $this->addGroup ($groups['targets']);
359 $this->is_modified= TRUE;
360 }
361 $this->groupSelect= NULL;
362 $this->dialog= FALSE;
363 }
365 // Remove groups from currently selected groups.
366 if (isset($_POST['delete_groupmembership']) &&
367 isset($_POST['group_list']) && count($_POST['group_list'])){
369 $this->delGroup ($_POST['group_list']);
370 }
372 // Add selected machines to trusted ones.
373 if (isset($_POST["add_ws_finish"]) && $this->trustSelect){
374 $trusts = $this->trustSelect->detectPostActions();
375 if(isset($trusts['targets'])){
377 $headpage = $this->trustSelect->getHeadpage();
378 foreach($trusts['targets'] as $id){
379 $attrs = $headpage->getEntry($id);
380 $this->accessTo[$attrs['cn'][0]]= $attrs['cn'][0];
381 }
382 ksort($this->accessTo);
383 $this->is_modified= TRUE;
384 }
385 $this->trustSelect= NULL;
386 $this->dialog= FALSE;
387 }
389 // Remove machine from trusted ones.
390 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
391 foreach($_POST['workstation_list'] as $name){
392 unset ($this->accessTo[$name]);
393 }
394 $this->is_modified= TRUE;
395 }
399 /* Templates now! */
400 $smarty= get_smarty();
401 $smarty->assign("usePrototype", "true");
403 /* Show ws dialog */
404 if ($this->trustSelect){
406 // Build up blocklist
407 session::set('filterBlacklist', array('cn' => array_values($this->accessTo)));
408 return($this->trustSelect->execute());
409 }
411 /* Manage group add dialog */
412 if ($this->groupSelect){
414 // Build up blocklist
415 session::set('filterBlacklist', array('dn' => array_keys($this->groupMembership)));
416 return($this->groupSelect->execute());
417 }
419 // Handle ssh dialog?
420 if ($this->ssh instanceOf sshPublicKey && preg_match('/[rw]/', $this->getacl("sshPublicKey"))) {
421 $smarty->assign("usePrototype", "false");
422 if ($result= $this->ssh->execute()) {
423 $this->dialog= true;
424 return $result;
425 }
426 $this->dialog= false;
427 }
430 /* Show main page */
431 $smarty= get_smarty();
432 $smarty->assign("usePrototype", "true");
434 /* In 'MyAccount' mode, we must remove write acls if we are not in editing mode. */
435 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
437 $smarty->assign("sshPublicKeyACL", $this->getacl("sshPublicKey", $SkipWrite));
439 /* Depending on pwmode, currently hardcoded because there are no other methods */
440 if ( 1 == 1 ){
441 $smarty->assign("pwmode", dirname(__FILE__)."/posix_shadow");
443 $shadowMinACL = $this->getacl("shadowMin",$SkipWrite);
444 $smarty->assign("shadowmins", sprintf(_("Password can't be changed up to %s days after last change"),
445 "<input type='text' name=\"shadowMin\" size=3 maxlength=4 value=\"".$this->shadowMin."\">"));
447 $shadowMaxACL = $this->getacl("shadowMax",$SkipWrite);
448 $smarty->assign("shadowmaxs", sprintf(_("Password must be changed after %s days"),
449 "<input type='text' name=\"shadowMax\" size=3 maxlength=4 value=\"".$this->shadowMax."\">"));
451 $shadowInactiveACL= $this->getacl("shadowInactive",$SkipWrite);
452 $smarty->assign("shadowinactives", sprintf(_("Disable account after %s days of inactivity after password expiry"),
453 "<input type='text' name=\"shadowInactive\" size=3 maxlength=4 value=\"".$this->shadowInactive."\">"));
455 $shadowWarningACL = $this->getacl("shadowWarning",$SkipWrite);
456 $smarty->assign("shadowwarnings", sprintf(_("Warn user %s days before password expiry"),
457 "<input type='text' name=\"shadowWarning\" size=3 maxlength=4 value=\"".$this->shadowWarning."\">"));
459 foreach( array("activate_shadowMin", "activate_shadowMax",
460 "activate_shadowExpire", "activate_shadowInactive","activate_shadowWarning") as $val){
461 if ($this->$val == 1){
462 $smarty->assign("$val", "checked");
463 } else {
464 $smarty->assign("$val", "");
465 }
466 $smarty->assign("$val"."ACL", $this->getacl($val,$SkipWrite));
467 }
469 $smarty->assign("mustchangepasswordACL", $this->getacl("mustchangepassword",$SkipWrite));
470 }
472 // Set last system login
473 $smarty->assign("gotoLastSystemLogin",$this->gotoLastSystemLogin);
475 /* Fill arrays */
476 $smarty->assign("shells", $this->loginShellList);
477 $smarty->assign("secondaryGroups", $this->secondaryGroups);
478 $smarty->assign("primaryGroup", $this->primaryGroup);
479 if(!$this->multiple_support_active){
480 if (!count($this->groupMembership)){
481 $smarty->assign("groupMembership", array(" "));
482 } else {
483 $smarty->assign("groupMembership", $this->groupMembership);
484 }
485 }else{
486 $smarty->assign("groupMembership", $this->groupMembership);
487 $smarty->assign("groupMembership_some", $this->groupMembership_some);
488 }
489 if (count($this->groupMembership) > 16){
490 $smarty->assign("groups", "too_many_for_nfs");
491 } else {
492 $smarty->assign("groups", "");
493 }
495 /* Avoid "Undefined index: forceMode" */
496 $smarty->assign("forceMode", "");
498 /* Checkboxes */
499 if ($this->force_ids == 1){
500 $smarty->assign("force_ids", "checked");
501 if (session::get('js')){
502 $smarty->assign("forceMode", "");
503 }
504 } else {
505 if (session::get('js')){
506 $smarty->assign("forceMode", "disabled");
507 }
508 $smarty->assign("force_ids", "");
509 }
511 /* Create onClick="" action string for the "Force UID/GID" option
512 */
513 $onClickIDS ="";
514 if(preg_match("/w/",$this->getacl("uidNumber",$SkipWrite))){
515 $onClickIDS .= "changeState('uidNumber');";
516 }
517 if(preg_match("/w/",$this->getacl("gidNumber",$SkipWrite))){
518 $onClickIDS .= "changeState('gidNumber');";
519 }
520 $smarty->assign("onClickIDS", $onClickIDS);
521 $smarty->assign("force_idsACL", $this->getacl("uidNumber",$SkipWrite).$this->getacl("gidNumber",$SkipWrite));
523 foreach(array("primaryGroup","trustmode","activate_shadowWarning","activate_shadowInactive","activate_shadowMin","activate_shadowMax","activate_shadowExpire","mustchangepassword") as $val){
524 if(in_array($val,$this->multi_boxes)){
525 $smarty->assign("use_".$val,TRUE);
526 }else{
527 $smarty->assign("use_".$val,FALSE);
528 }
529 }
532 /* Load attributes and acl's */
533 foreach($this->attributes as $val){
534 if(in_array($val,$this->multi_boxes)){
535 $smarty->assign("use_".$val,TRUE);
536 }else{
537 $smarty->assign("use_".$val,FALSE);
538 }
540 if((session::get("js"))&&(($val=="uidNumber")||($val=="gidNumber")))
541 {
542 $smarty->assign("$val"."ACL",$this->getacl($val,$SkipWrite));
543 $smarty->assign("$val", $this->$val);
544 continue;
545 }
546 $smarty->assign("$val", $this->$val);
547 $smarty->assign("$val"."ACL", $this->getacl($val,$SkipWrite));
548 }
549 if($SkipWrite){
550 $smarty->assign("groupMembershipACL","r");
551 }else{
552 $smarty->assign("groupMembershipACL","rw");
553 }
554 $smarty->assign("status", $this->status);
556 /* Work on trust modes */
557 $smarty->assign("trusthide", " disabled ");
558 $smarty->assign("trustmodeACL", $this->getacl("trustModel",$SkipWrite));
559 if ($this->trustModel == "fullaccess"){
560 $trustmode= 1;
561 // pervent double disable tag in html code, this will disturb our clean w3c html
562 $smarty->assign("trustmode", $this->getacl("trustModel",$SkipWrite));
564 } elseif ($this->trustModel == "byhost"){
565 $trustmode= 2;
566 $smarty->assign("trusthide", "");
567 } else {
568 // pervent double disable tag in html code, this will disturb our clean w3c html
569 $smarty->assign("trustmode", $this->getacl("trustModel",$SkipWrite));
570 $trustmode= 0;
571 }
572 $smarty->assign("trustmode", $trustmode);
573 $smarty->assign("trustmodes", array( 0 => _("disabled"), 1 => _("full access"),
574 2 => _("allow access to these hosts")));
578 if((count($this->accessTo))==0)
579 $smarty->assign("emptyArrAccess",true);
580 else
581 $smarty->assign("emptyArrAccess",false);
583 if($this->mustchangepassword){
584 $smarty->assign("mustchangepassword", " checked ");
585 } else {
586 $smarty->assign("mustchangepassword", "");
587 }
589 $smarty->assign("workstations", $this->accessTo);
591 // Add SSH button if available
592 $smarty->assign("sshPublicKey", $this->ssh?1:0);
594 $smarty->assign("apply", apply_filter());
595 $smarty->assign("multiple_support" , $this->multiple_support_active);
596 $display.= $smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)));
597 return($display);
598 }
601 /* remove object from parent */
602 function remove_from_parent()
603 {
604 /* Cancel if there's nothing to do here */
605 if ((!$this->initially_was_account) || (!$this->acl_is_removeable())){
606 return;
607 }
610 /* Remove and write to LDAP */
611 plugin::remove_from_parent();
613 /* Zero out array */
614 $this->attrs['gosaHostACL']= array();
616 /* Keep uid, because we need it for authentification! */
617 unset($this->attrs['uid']);
618 unset($this->attrs['trustModel']);
620 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
621 /* include global link_info */
622 $this->attributes, "Save");
623 $ldap= $this->config->get_ldap_link();
624 $ldap->cd($this->dn);
625 $this->cleanup();
626 $ldap->modify ($this->attrs);
628 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
630 if (!$ldap->success()){
631 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
632 }
634 /* Delete group only if cn is uid and there are no other
635 members inside */
636 $ldap->cd ($this->config->current['BASE']);
637 $ldap->search ("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn", "memberUid"));
638 if ($ldap->count() != 0){
639 $attrs= $ldap->fetch();
640 if ($attrs['cn'][0] == $this->uid &&
641 !isset($this->attrs['memberUid'])){
643 $ldap->rmDir($ldap->getDN());
644 }
645 }
647 /* Optionally execute a command after we're done */
648 $this->handle_post_events("remove",array("uid" => $this->uid));
649 }
652 function save_object()
653 {
654 if (isset($_POST['posixTab'])){
655 /* Save values to object */
656 plugin::save_object();
659 /* Save force GID checkbox */
660 if($this->acl_is_writeable("gidNumber") || $this->acl_is_writeable("uidNumber")){
661 if (isset ($_POST['force_ids'])){
662 $data= 1;
663 } else {
664 $data= 0;
665 }
666 if ($this->force_ids != $data){
667 $this->is_modified= TRUE;
668 }
669 $this->force_ids= $data;
670 }
672 /*Save primary group settings */
673 if($this->acl_is_writeable("primaryGroup") && isset($_POST['primaryGroup'])){
674 $data= $_POST['primaryGroup'];
675 if ($this->primaryGroup != $data){
676 $this->is_modified= TRUE;
677 }
678 $this->primaryGroup= $_POST['primaryGroup'];
679 }
681 /* Get seelcted shadow checkboxes */
682 foreach(array("shadowMin","shadowMax","shadowExpire","shadowInactive","shadowWarning") as $var) {
683 if($this->acl_is_writeable($var)){
684 $activate_var = "activate_".$var;
685 if(isset($_POST['activate_'.$var])){
686 $this->$activate_var = true;
687 $this->$var = $_POST[$var];
688 }else{
689 $this->$activate_var = false;
690 if ($var != "shadowExpire") {
691 $this->$var = 0;
692 }
693 }
694 }
695 }
697 /* Force change password ? */
698 if(isset($_POST['mustchangepassword'])){
699 $this->mustchangepassword = TRUE;
700 }else{
701 $this->mustchangepassword = FALSE;
702 }
704 /* Trust mode - special handling */
705 if($this->acl_is_writeable("trustModel")){
706 if (isset($_POST['trustmode'])){
707 $saved= $this->trustModel;
708 if ($_POST['trustmode'] == "1"){
709 $this->trustModel= "fullaccess";
710 } elseif ($_POST['trustmode'] == "2"){
711 $this->trustModel= "byhost";
712 } else {
713 $this->trustModel= "";
714 }
715 if ($this->trustModel != $saved){
716 $this->is_modified= TRUE;
717 }
718 }
719 }
720 }
722 /* Get regex from alphabet */
723 if(isset($_GET['search'])){
724 $this->GroupRegex = $_GET['search']."*";
725 }
727 /* Check checkboxes and regexes */
728 if(isset($_POST["PosixGroupDialogPosted"])){
730 if(isset($_POST['SubSearch']) && ($_POST['SubSearch'])){
731 $this->SubSearch = true;
732 }else{
733 $this->SubSearch = false;
734 }
735 if(isset($_POST['guser'])){
736 $this->GroupUserRegex = $_POST['guser'];
737 }
738 if(isset($_POST['regex'])){
739 $this->GroupRegex = $_POST['regex'];
740 }
741 }
742 $this->GroupRegex = preg_replace("/\*\**/","*",$this->GroupRegex);
743 $this->GroupUserRegex = preg_replace("/\*\**/","*",$this->GroupUserRegex);
744 }
747 /* Save data to LDAP, depending on is_account we save or delete */
748 function save()
749 {
751 /* Adapt shadow values */
752 if (!$this->activate_shadowExpire){
753 $this->shadowExpire= "0";
754 } else {
755 /* Transform date to days since the beginning */
756 list($day, $month, $year)= explode('.', $this->shadowExpire, 3);
757 $this->shadowExpire= (int)(mktime(0, 0, 0, $month, $day, $year)/ (60 * 60 * 24)) ;
758 }
759 if (!$this->activate_shadowMax){
760 $this->shadowMax= "0";
761 }
762 if ($this->mustchangepassword){
763 $this->shadowLastChange= (int)(date("U") / 86400) - $this->shadowMax - 1;
764 } else {
765 $this->shadowLastChange= (int)(date("U") / 86400);
766 }
767 if (!$this->activate_shadowWarning){
768 $this->shadowWarning= "0";
769 }
771 /* Check what to do with ID's
772 Nothing forced, so we may have to generate our own IDs, if not done already.
773 */
774 if ($this->force_ids == 0){
776 /* Handle uidNumber.
777 * - use existing number if possible
778 * - if not, try to create a new uniqe one.
779 * */
780 if ($this->savedUidNumber != ""){
781 $this->uidNumber= $this->savedUidNumber;
782 } else {
784 /* Calculate new id's. We need to place a lock before calling get_next_id
785 to get real unique values.
786 */
787 $wait= 10;
788 while (get_lock("uidnumber") != ""){
789 sleep (1);
791 /* Oups - timed out */
792 if ($wait-- == 0){
793 msg_dialog::display(_("Warning"), _("Timeout while waiting for lock. Ignoring lock!"), WARNING_DIALOG);
794 break;
795 }
796 }
797 add_lock ("uidnumber", "gosa");
798 $this->uidNumber= get_next_id("uidNumber", $this->dn);
799 }
800 }
803 /* Handle gidNumber
804 * - If we do not have a primary group selected (automatic), we will check if there
805 * is already a group with the same name and use this as primary.
806 * - .. if we couldn't find a group with the same name, we will create a new one,
807 * using the users uid as cn and a generated uniqe gidNumber.
808 * */
809 if ($this->primaryGroup == 0 || $this->force_ids){
811 /* Search for existing group */
812 $ldap = $this->config->get_ldap_link();
813 $ldap->cd($this->config->current['BASE']);
815 /* Are we forced to use a special gidNumber? */
816 if($this->force_ids){
817 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn","gidNumber"));
818 }else{
819 $ldap->search("(&(objectClass=posixGroup)(gidNumber=*)(cn=".$this->uid."))", array("cn","gidNumber"));
820 }
822 /* No primary group found, create a new one */
823 if ($ldap->count() == 0){
825 $groupcn = $this->uid;
826 $pri_attr = $this->config->get_cfg_value("accountPrimaryAttribute");
827 $groupdn= preg_replace ('/^'.preg_quote($pri_attr,'/').'=[^,]+,'.preg_quote(get_people_ou(),'/').'/i',
828 'cn='.$groupcn.','.get_groups_ou(), $this->dn);
830 /* Request a new and uniqe gidNumber, if required */
831 if(!$this->force_ids){
832 $this->gidNumber= get_next_id("gidNumber", $this->dn);
833 }
835 /* If forced gidNumber could not be found, then check if the given group name already exists
836 we do not want to modify the gidNumber of an existing group.
837 */
838 $cnt= 0;
839 while($ldap->dn_exists($groupdn) && ($cnt < 100)){
840 $cnt ++;
841 $groupcn = $this->uid."_".$cnt;
842 $groupdn= preg_replace ('/^'.preg_quote($pri_attr,'/').'=[^,]+,'.preg_quote(get_people_ou(),'/').'/i',
843 'cn='.$groupcn.','.get_groups_ou(), $this->dn);
844 }
846 /* Create new primary group and enforce the new gidNumber */
847 $g= new group($this->config, $groupdn);
848 $g->cn= $groupcn;
849 $g->force_gid= 1;
850 $g->gidNumber= $this->gidNumber;
851 $g->description= _("Group of user")." ".$this->givenName." ".$this->sn;
852 $g->save ();
854 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
855 sprintf("Primary group '%s' created, using gidNumber '%s'.",$groupcn,$this->gidNumber),"");
856 }else{
857 $attrs = $ldap->fetch();
858 $this->gidNumber = $attrs['gidNumber'][0];
859 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
860 "Found and used: <i>".$attrs['dn']."</i>",
861 sprintf("Primary group '%s' exists, gidNumber is '%s'.",$this->uid,$this->gidNumber));
862 }
863 }else{
865 /* Primary group was selected by user
866 */
867 $this->gidNumber = $this->primaryGroup;
868 @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,
869 sprintf("Primary group '%s' for user '%s' manually selected.",$this->gidNumber,$this->uid),"");
870 }
872 if ($this->activate_shadowMin != "1" ) {
873 $this->shadowMin = "";
874 }
876 if (($this->activate_shadowMax != "1") && ($this->mustchangepassword != "1")) {
877 $this->shadowMax = "";
878 }
880 if ($this->activate_shadowWarning != "1" ) {
881 $this->shadowWarning = "";
882 }
884 if ($this->activate_shadowInactive != "1" ) {
885 $this->shadowInactive = "";
886 }
888 if ($this->activate_shadowExpire != "1" ) {
889 $this->shadowExpire = "";
890 }
892 /* Fill gecos */
893 if (isset($this->parent) && $this->parent !== NULL){
894 $this->gecos= rewrite($this->parent->by_object['user']->cn);
895 if (!preg_match('/^[a-z0-9 -]+$/i', $this->gecos)){
896 $this->gecos= "";
897 }
898 }
900 foreach(array("shadowMin","shadowMax","shadowWarning","shadowInactive","shadowExpire") as $attr){
901 $this->$attr = (int) $this->$attr;
902 }
903 /* Call parents save to prepare $this->attrs */
904 plugin::save();
906 /* Trust accounts */
907 $objectclasses= array();
908 foreach ($this->attrs['objectClass'] as $key => $class){
909 if (preg_match('/trustAccount/i', $class)){
910 continue;
911 }
912 $objectclasses[]= $this->attrs['objectClass'][$key];
913 }
914 $this->attrs['objectClass']= $objectclasses;
915 if ($this->trustModel != ""){
916 $this->attrs['objectClass'][]= "trustAccount";
917 $this->attrs['trustModel']= $this->trustModel;
918 $this->attrs['accessTo']= array();
919 if ($this->trustModel == "byhost"){
920 foreach ($this->accessTo as $host){
921 $this->attrs['accessTo'][]= $host;
922 }
923 }
924 } else {
925 if ($this->was_trust_account){
926 $this->attrs['accessTo']= array();
927 $this->attrs['trustModel']= array();
928 }
929 }
931 if(empty($this->attrs['gosaDefaultPrinter'])){
932 $thid->attrs['gosaDefaultPrinter']=array();
933 }
936 /* include global link_info */
937 $this->cleanup();
939 /* This is just a test, we have had duplicated ids
940 in the past when copy & paste was used.
941 Normaly this should not happen.
942 */
943 if(isset($this->attrs['uidNumber']) && !$this->force_ids){
944 $used = $this->get_used_uid_numbers();
945 if(isset($used[$this->attrs['uidNumber']]) && $used[$this->attrs['uidNumber']] != $this->dn){
946 msg_dialog::display(_("Warning"),_("A duplicated UID number was written for this user. If this was not intended please verify all used uidNumbers!"), WARNING_DIALOG);
947 }
948 }
950 $ldap= $this->config->get_ldap_link();
951 $ldap->cd($this->dn);
952 unset($this->attrs['uid']);
953 $ldap->modify ($this->attrs);
955 /* Log last action */
956 if($this->initially_was_account){
957 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
958 }else{
959 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
960 }
962 if (!$ldap->success()){
963 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
964 }
966 /* Remove lock needed for unique id generation */
967 del_lock ("uidnumber");
969 // Save ssh stuff if needed
970 if ($this->ssh) {
971 $this->ssh->setDN($this->dn);
972 $this->ssh->save();
973 }
975 /* Take care about groupMembership values: add to groups */
976 foreach ($this->groupMembership as $key => $value){
977 if (!isset($this->savedGroupMembership[$key])){
978 $g= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $key,"groups");
979 $g->set_acl_base($key);
980 $g->by_object['group']->addUser($this->uid);
981 $g->save();
982 }
983 }
985 /* Remove groups not listed in groupMembership */
986 foreach ($this->savedGroupMembership as $key => $value){
987 if (!isset($this->groupMembership[$key])){
988 $g= new grouptabs($this->config,$this->config->data['TABS']['GROUPTABS'], $key,"groups");
989 $g->set_acl_base($key);
990 $g->by_object['group']->removeUser ($this->uid);
991 $g->save();
992 }
993 }
995 /* Optionally execute a command after we're done */
996 if ($this->initially_was_account == $this->is_account){
997 if ($this->is_modified){
998 $this->handle_post_events("modify",array("uid" => $this->uid));
999 }
1000 } else {
1001 $this->handle_post_events("add" ,array("uid"=> $this->uid));
1002 }
1003 }
1006 /* Check formular input */
1007 function check()
1008 {
1009 /* Include global link_info */
1010 $ldap= $this->config->get_ldap_link();
1012 /* Append groups as memberGroup: to check hook
1013 */
1014 $tmp_attributes = $this->attributes;
1015 $this->attributes[] = "memberGroup";
1016 $this->memberGroup = array();
1017 foreach($this->groupMembership as $dn => $name){
1018 $this->memberGroup[] = $name;
1019 }
1021 /* Call common method to give check the hook */
1022 $message= plugin::check();
1023 $this->attributes = $tmp_attributes;
1025 /* must: homeDirectory */
1026 if ($this->homeDirectory == ""){
1027 $message[]= msgPool::required(_("Home directory"));
1028 }
1029 if (!tests::is_path($this->homeDirectory)){
1030 $message[]= msgPool::invalid(_("Home directory"), "", "", "/home/yourname" );
1031 }
1033 /* Check ID's if they are forced by user */
1034 if ($this->force_ids == "1"){
1036 /* Valid uid/gid? */
1037 if (!tests::is_id($this->uidNumber)){
1038 $message[]= msgPool::invalid(_("UID"), $this->uidNumber, "/[0-9]/");
1039 } else {
1040 if ($this->uidNumber < $this->config->get_cfg_value("minId")){
1041 $message[]= msgPool::toosmall(_("UID"), $this->config->get_cfg_value("minId"));
1042 }
1043 }
1044 if (!tests::is_id($this->gidNumber)){
1045 $message[]= msgPool::invalid(_("GID"), $this->gidNumber, "/[0-9]/");
1046 } else {
1047 if ($this->gidNumber < $this->config->get_cfg_value("minId")){
1048 $message[]= msgPool::toosmall(_("GID"), $this->config->get_cfg_value("minId"));
1049 }
1050 }
1051 }
1053 /* Check dates */
1054 if ($this->activate_shadowExpire && ($this->shadowExpire == "" || !tests::is_date($this->shadowExpire))){
1055 $message[]= msgPool::invalid("shadowExpire", $this->shadowExpire);
1056 }
1058 /* Check shadow settings, well I like spaghetties... */
1059 if ($this->activate_shadowMin){
1060 if (!tests::is_id($this->shadowMin)){
1061 $message[]= msgPool::invalid(_("shadowMin"), $this->shadowMin, "/[0-9]/");
1062 }
1063 }
1064 if ($this->activate_shadowMax){
1065 if (!tests::is_id($this->shadowMax)){
1066 $message[]= msgPool::invalid(_("shadowMax"), $this->shadowMax, "/[0-9]/");
1067 }
1068 }
1069 if ($this->activate_shadowWarning){
1070 if (!tests::is_id($this->shadowWarning)){
1071 $message[]= msgPool::invalid(_("shadowWarning"), $this->shadowWarning, "/[0-9]/");
1072 }
1073 if (!$this->activate_shadowMax){
1074 $message[]= msgPool::depends("shadowWarning", "shadowMax");
1075 }
1076 if ($this->shadowWarning > $this->shadowMax){
1077 $message[]= msgPool::toobig("shadowWarning", "shadowMax");
1078 }
1079 if ($this->activate_shadowMin && $this->shadowWarning < $this->shadowMin){
1080 $message[]= msgPool::toosmall("shadowWarning", "shadowMin");
1081 }
1082 }
1083 if ($this->activate_shadowInactive){
1084 if (!tests::is_id($this->shadowInactive)){
1085 $message[]= msgPool::invalid(_("shadowInactive"), $this->shadowInactive, "/[0-9]/");
1086 }
1087 if (!$this->activate_shadowMax){
1088 $message[]= msgPool::depends("shadowInactive", "shadowMax");
1089 }
1090 }
1091 if ($this->activate_shadowMin && $this->activate_shadowMax){
1092 if ($this->shadowMin > $this->shadowMax){
1093 $message[]= msgPool::toobig("shadowMin", "shadowMax");
1094 }
1095 }
1097 return ($message);
1098 }
1101 function multiple_check()
1102 {
1103 $message = plugin::multiple_check();
1104 if ($this->homeDirectory == "" && in_array("homeDirectory",$this->multi_boxes)){
1105 $message[]= msgPool::required(_("Home directory"));
1106 }
1107 if (!tests::is_path($this->homeDirectory) && in_array("homeDirectory",$this->multi_boxes)){
1108 $message[]= msgPool::invalid(_("Home directory"), "", "", "/home/yourname" );
1109 }
1111 /* Check shadow settings, well I like spaghetties... */
1112 if ($this->activate_shadowMin && in_array("activate_shadowMin",$this->multi_boxes)){
1113 if (!tests::is_id($this->shadowMin)){
1114 $message[]= msgPool::invalid(_("shadowMin"), $this->shadowMin, "/[0-9]/");
1115 }
1116 }
1117 if ($this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
1118 if (!tests::is_id($this->shadowMax)){
1119 $message[]= msgPool::invalid(_("shadowMax"), $this->shadowMax, "/[0-9]/");
1120 }
1121 }
1122 if ($this->activate_shadowWarning && in_array("activate_shadowWarning",$this->multi_boxes)){
1123 if (!tests::is_id($this->shadowWarning)){
1124 $message[]= msgPool::invalid(_("shadowWarning"), $this->shadowWarning, "/[0-9]/");
1125 }
1126 if (!$this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
1127 $message[]= msgPool::depends("shadowWarning", "shadowMax");
1128 }
1129 if ($this->shadowWarning > $this->shadowMax && in_array("activate_shadowWarning",$this->multi_boxes)){
1130 $message[]= msgPool::toobig("shadowWarning", "shadowMax");
1131 }
1132 if ($this->activate_shadowMin && $this->shadowWarning < $this->shadowMin && in_array("activate_shadowMin",$this->multi_boxes)){
1133 $message[]= msgPool::tosmall("shadowWarning", "shadowMin");
1134 }
1135 }
1136 if ($this->activate_shadowInactive && in_array("activate_shadowInactive",$this->multi_boxes)){
1137 if (!tests::is_id($this->shadowInactive)){
1138 $message[]= msgPool::invalid(_("shadowInactive"), $this->shadowInactive, "/[0-9]/");
1139 }
1140 if (!$this->activate_shadowMax && in_array("activate_shadowMax",$this->multi_boxes)){
1141 $message[]= msgPool::depends("shadowInactive", "shadowMax");
1142 }
1143 }
1144 if ($this->activate_shadowMin && $this->activate_shadowMax && in_array("activate_shadowMin",$this->multi_boxes)){
1145 if ($this->shadowMin > $this->shadowMax){
1146 $message[]= msgPool::toobig("shadowMin", "shadowMax");
1147 }
1148 }
1150 return($message);
1151 }
1154 function addGroup ($groups)
1155 {
1156 /* include global link_info */
1157 $ldap= $this->config->get_ldap_link();
1159 /* Walk through groups and add the descriptive entry if not exists */
1160 foreach ($groups as $value){
1162 if (!array_key_exists($value, $this->groupMembership)){
1163 $ldap->cat($value, array('cn', 'description', 'dn'));
1164 $attrs= $ldap->fetch();
1165 error_reporting (0);
1166 if (!isset($attrs['description'][0])){
1167 $entry= $attrs["cn"][0];
1168 } else {
1169 $dsc= preg_replace ('/^Group of user/', _("Group of user"), $attrs["description"][0]);
1170 $entry= $attrs["cn"][0]." [$dsc]";
1171 }
1172 error_reporting (E_ALL | E_STRICT);
1174 if(obj_is_writable($attrs['dn'],"groups/group","memberUid")){
1175 $this->groupMembership[$attrs['dn']]= $entry;
1176 if($this->multiple_support_active && isset($this->groupMembership_some[$attrs['dn']])){
1177 unset($this->groupMembership_some[$attrs['dn']]);
1178 }
1179 }
1180 }
1181 }
1183 /* Sort groups */
1184 asort ($this->groupMembership);
1185 reset ($this->groupMembership);
1186 }
1189 /* Del posix user from some groups */
1190 function delGroup ($groups)
1191 {
1192 $dest= array();
1193 foreach($groups as $dn_to_del){
1194 if(isset($this->groupMembership[$dn_to_del]) && obj_is_writable($dn_to_del,"groups/group","memberUid")){
1195 unset($this->groupMembership[$dn_to_del]);
1196 }
1197 if($this->multiple_support_active){
1198 if(isset($this->groupMembership_some[$dn_to_del]) && obj_is_writable($dn_to_del,"groups/group","memberUid")){
1199 unset($this->groupMembership_some[$dn_to_del]);
1200 }
1201 }
1202 }
1203 }
1206 /* Adapt from template, using 'dn' */
1207 function adapt_from_template($dn, $skip= array())
1208 {
1209 /* Include global link_info */
1210 $ldap= $this->config->get_ldap_link();
1212 plugin::adapt_from_template($dn, $skip);
1213 $template= $this->attrs['uid'][0];
1215 /* Adapt group membership */
1216 $ldap->cd($this->config->current['BASE']);
1217 $ldap->search("(&(objectClass=posixGroup)(memberUid=".$this->attrs["uid"][0]."))", array("description", "cn"));
1219 while ($this->attrs= $ldap->fetch()){
1220 if (!isset($this->attrs["description"][0])){
1221 $entry= $this->attrs["cn"][0];
1222 } else {
1223 $entry= $this->attrs["cn"][0]." [".$this->attrs["description"][0]."]";
1224 }
1225 $this->groupMembership[$ldap->getDN()]= $entry;
1226 }
1228 /* Fix primary group settings */
1229 $ldap->cd($this->config->current['BASE']);
1230 $ldap->search("(&(objectClass=posixGroup)(cn=$template)(gidNumber=".$this->gidNumber."))", array("cn"));
1231 if ($ldap->count() != 1){
1232 $this->primaryGroup= $this->gidNumber;
1233 }
1235 $ldap->cd($this->config->current['BASE']);
1236 $ldap->search("(&(objectClass=gosaUserTemplate)(uid=".$template.")(accessTo=*))", array("cn","accessTo"));
1237 while($attr = $ldap->fetch()){
1238 $tmp = $attr['accessTo'];
1239 unset ($tmp['count']);
1240 $this->accessTo = $tmp;
1241 }
1243 /* Adjust shadow checkboxes */
1244 foreach (array("shadowMin", "shadowMax", "shadowWarning", "shadowInactive") as $val){
1245 if ($this->$val != 0){
1246 $oval= "activate_".$val;
1247 $this->$oval= "1";
1248 }
1249 }
1251 /* FIXME: NEED review of this section */
1252 /* Need to check shadowExpire separately */
1254 /*
1255 * If shadowExpire is not enabled in the template, it's a UNIX timestamp - so don't convert it to seconds.
1256 * The check is a hack - if difference between timestamp generated above and here is max 1 day.
1257 */
1258 if(abs($this->shadowExpire - time())>86400) {
1259 $this->shadowExpire= $this->convertToSeconds($this->shadowExpire);
1260 }
1262 /* Only enable checkbox, if shadowExpire is in the future */
1263 if($this->shadowExpire > time()) {
1264 $this->activate_shadowExpire= "1";
1265 }
1266 }
1268 function convertToSeconds($val)
1269 {
1270 if ($val != 0){
1271 $val*= 60 * 60 * 24;
1272 } else {
1273 $date= getdate();
1274 $val= floor($date[0] / (60*60*24)) * 60 * 60 * 24;
1275 }
1276 return($val);
1277 }
1280 function get_used_uid_numbers()
1281 {
1282 $ids= array();
1283 $ldap= $this->config->get_ldap_link();
1285 $ldap->cd ($this->config->current['BASE']);
1286 $ldap->search ("(&(objectClass=posixAccount)(uidNumber=*))", array("uidNumber"));
1288 /* Get list of ids */
1289 while ($attrs= $ldap->fetch()){
1290 $ids[$attrs['uidNumber'][0]] = $attrs['dn'];
1291 }
1292 return($ids);
1293 }
1296 /* Get posts from copy & paste dialog */
1297 function saveCopyDialog()
1298 {
1299 if(isset($_POST['homeDirectory'])){
1300 $this->homeDirectory = $_POST['homeDirectory'];
1301 if (isset ($_POST['force_ids'])){
1302 $data= 1;
1303 $this->gidNumber = $_POST['gidNumber'];
1304 $this->uidNumber = $_POST['uidNumber'];
1305 } else {
1306 $data= 0;
1307 }
1308 if ($this->force_ids != $data){
1309 $this->is_modified= TRUE;
1310 }
1311 $this->force_ids= $data;
1312 $data= $_POST['primaryGroup'];
1313 if ($this->primaryGroup != $data){
1314 $this->is_modified= TRUE;
1315 }
1316 $this->primaryGroup= $_POST['primaryGroup'];
1317 }
1318 }
1321 /* Create the posix dialog part for copy & paste */
1322 function getCopyDialog()
1323 {
1324 /* Skip dialog creation if this is not a valid account*/
1325 if(!$this->is_account) return("");
1326 if ($this->force_ids == 1){
1327 $force_ids = "checked";
1328 if (session::get('js')){
1329 $forceMode = "";
1330 }
1331 } else {
1332 if (session::get('js')){
1333 if($this->acl != "#none#")
1334 $forceMode ="disabled";
1335 }
1336 $force_ids = "";
1337 }
1339 $sta = "";
1341 /* Open group add dialog */
1342 if(isset($_POST['edit_groupmembership'])){
1343 $this->groupSelect = new groupSelect($this->config,get_userinfo());
1344 $sta = "SubDialog";
1345 }
1347 /* If the group-add dialog is closed, call execute
1348 to ensure that the membership is updatd */
1349 if(isset($_POST['add_groups_finish']) || isset($_POST['add_groups_cancel'])){
1350 $this->execute();
1351 $this->groupSelect =NULL;
1352 }
1354 if($this->groupSelect){
1355 $str = $this->execute(true);
1356 $ret = array();
1357 $ret['string'] = $str;
1358 $ret['status'] = $sta;
1359 return($ret);
1360 }
1362 /* If a group member should be deleted, simply call execute */
1363 if(isset($_POST['delete_groupmembership'])){
1364 $this->execute();
1365 }
1367 /* Assigned informations to smarty */
1368 $smarty = get_smarty();
1369 $smarty->assign("homeDirectory",$this->homeDirectory);
1370 $smarty->assign("secondaryGroups",$this->secondaryGroups);
1371 $smarty->assign("primaryGroup",$this->primaryGroup);
1373 $smarty->assign("uidNumber",$this->uidNumber);
1374 $smarty->assign("gidNumber",$this->gidNumber);
1375 $smarty->assign("forceMode",$forceMode);
1376 $smarty->assign("force_ids",$force_ids);
1377 if (!count($this->groupMembership)){
1378 $smarty->assign("groupMembership", array(" "));
1379 } else {
1380 $smarty->assign("groupMembership", $this->groupMembership);
1381 }
1383 /* Display wars message if there are more than 16 group members */
1384 if (count($this->groupMembership) > 16){
1385 $smarty->assign("groups", "too_many_for_nfs");
1386 } else {
1387 $smarty->assign("groups", "");
1388 }
1389 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE,dirname(__FILE__)));
1391 $ret = array();
1392 $ret['string'] = $str;
1393 $ret['status'] = $sta;
1394 return($ret);
1395 }
1398 function PrepareForCopyPaste($source)
1399 {
1400 plugin::PrepareForCopyPaste($source);
1402 /* Avoid using the same gid/uid number as source user
1403 empty numbers to enforce new ones. */
1404 $this->savedUidNumber = "";
1405 $this->savedGidNumber = "";
1407 /* Get group membership */
1408 $ldap = $this->config->get_ldap_link();
1409 $ldap->cd($this->config->current['BASE']);
1410 $ldap->search("(&(objectClass=posixGroup)(memberUid=".$source['uid'][0]."))", array("cn", "description"));
1412 while ($attrs= $ldap->fetch()){
1413 if (!isset($attrs["description"][0])){
1414 $entry= $attrs["cn"][0];
1415 } else {
1416 $entry= $attrs["cn"][0]." [".$attrs["description"][0]."]";
1417 }
1418 $this->groupMembership[$ldap->getDN()]= $entry;
1419 }
1420 asort($this->groupMembership);
1421 reset($this->groupMembership);
1423 /* Fill group */
1424 if(isset($source['gidNumber'][0])){
1425 $this->primaryGroup= $source['gidNumber'][0];
1426 }
1428 }
1431 function multiple_execute()
1432 {
1433 return($this->execute());
1434 }
1437 static function plInfo()
1438 {
1439 return (array(
1440 "plDescription" => _("POSIX account"),
1441 "plSelfModify" => TRUE,
1442 "plDepends" => array("user"),
1443 "plPriority" => 2,
1444 "plSection" => array("personal" => _("My account")),
1445 "plCategory" => array("users"),
1446 "plOptions" => array(),
1448 "plProvidedAcls" => array(
1450 "homeDirectory" => _("Home directory"),
1451 "loginShell" => _("Shell"),
1452 "uidNumber" => _("User ID"),
1453 "gidNumber" => _("Group ID"),
1455 "mustchangepassword"=> _("Force password change on login"),
1456 "shadowMin" => _("Shadow min"),
1457 "shadowMax" => _("Shadow max"),
1458 "shadowWarning" => _("Shadow warning"),
1459 "shadowInactive" => _("Shadow inactive"),
1460 "shadowExpire" => _("Shadow expire"),
1461 "sshPublickey" => _("Public SSH key"),
1462 "trustModel" => _("System trust model")))
1463 );
1464 }
1467 /* Return selected values for multiple edit */
1468 function get_multi_edit_values()
1469 {
1470 $ret = plugin::get_multi_edit_values();
1471 $ret['groupMembership'] = $this->groupMembership;
1472 $ret['groupMembership_some']= $this->groupMembership_some;
1474 if(in_array("primaryGroup",$this->multi_boxes)){
1475 $ret['primaryGroup'] = $this->primaryGroup;
1476 }
1477 if(in_array("trustmode",$this->multi_boxes)){
1478 $ret['trustModel'] = $this->trustModel;
1479 $ret['accessTo'] = $this->accessTo;
1480 }
1481 foreach(array("shadowWarning","shadowInactive","shadowMin","shadowMax", "shadowExpire") as $entry){
1482 $active = "activate_".$entry;
1483 if(in_array($active,$this->multi_boxes)){
1484 $ret[$entry] = $this->$entry;
1485 $ret[$active] = $this->$active;
1486 }
1487 }
1488 if(in_array("mustchangepassword",$this->multi_boxes)){
1489 $ret['mustchangepassword'] = $this->mustchangepassword;
1490 }
1491 return($ret);
1492 }
1495 /* Save posts for multiple edit
1496 */
1497 function multiple_save_object()
1498 {
1499 if(isset($_POST['posix_mulitple_edit'])){
1501 /* Backup expire value */
1502 $expire_tmp = $this->shadowExpire;
1504 /* Update all values */
1505 plugin::multiple_save_object();
1507 /* Get selected checkboxes */
1508 foreach(array("primaryGroup","trustmode","mustchangepassword","activate_shadowWarning","activate_shadowInactive","activate_shadowMin", "activate_shadowMax","activate_shadowExpire") as $val){
1509 if(isset($_POST["use_".$val])){
1510 $this->multi_boxes[] = $val;
1511 }
1512 }
1514 /* Update special values, checkboxes for posixShadow */
1515 foreach(array("shadowMin","shadowMax","shadowExpire","shadowInactive","shadowWarning") as $var) {
1516 if($this->acl_is_writeable($var)){
1517 $activate_var = "activate_".$var;
1518 if(in_array($activate_var, $this->multi_boxes)){
1519 if(isset($_POST['activate_'.$var])){
1520 $this->$activate_var = true;
1521 $this->$var = $_POST[$var];
1522 }else{
1523 $this->$activate_var = false;
1524 $this->$var = 0;
1525 }
1526 }
1527 }
1528 }
1530 /* Restore shadow value, if the shadow attribute isn't used */
1531 if(!in_array("activate_shadowExpire",$this->multi_boxes)){
1532 $this->shadowExpire = $expire_tmp;
1533 }
1535 /* Force change password ? */
1536 if(isset($_POST['mustchangepassword'])){
1537 $this->mustchangepassword = TRUE;
1538 }else{
1539 $this->mustchangepassword = FALSE;
1540 }
1542 /* Trust mode - special handling */
1543 if($this->acl_is_writeable("trustModel")){
1544 if (isset($_POST['trustmode'])){
1545 $saved= $this->trustModel;
1546 if ($_POST['trustmode'] == "1"){
1547 $this->trustModel= "fullaccess";
1548 } elseif ($_POST['trustmode'] == "2"){
1549 $this->trustModel= "byhost";
1550 } else {
1551 $this->trustModel= "";
1552 }
1553 if ($this->trustModel != $saved){
1554 $this->is_modified= TRUE;
1555 }
1556 }
1557 }
1559 /* Save primary group settings */
1560 if($this->acl_is_writeable("primaryGroup") && isset($_POST['primaryGroup'])){
1561 $data= $_POST['primaryGroup'];
1562 if ($this->primaryGroup != $data){
1563 $this->is_modified= TRUE;
1564 }
1565 $this->primaryGroup= $_POST['primaryGroup'];
1566 }
1567 }
1568 }
1571 /* Initialize plugin with given atribute arrays
1572 */
1573 function init_multiple_support($attrs,$all)
1574 {
1575 plugin::init_multiple_support($attrs,$all);
1577 /* Some dummy values */
1578 $groups_some = array();
1579 $groups_all = array();
1580 $groups_uid = array();
1581 $uids = array();
1582 $first = TRUE;
1584 /* Get all groups used by currently edited users */
1585 $uid_filter="";
1586 for($i =0; $i < $this->multi_attrs_all['uid']['count'] ; $i ++){
1587 $uid = $this->multi_attrs_all['uid'][$i];
1588 $uids[] = $uid;
1589 $uid_filter.= "(memberUid=".$uid.")";
1590 }
1591 $uid_filter = "(&(objectClass=posixGroup)(|".$uid_filter."))";
1592 $ldap = $this->config->get_ldap_link();
1593 $ldap->cd($this->config->current['BASE']);
1594 $ldap->search($uid_filter,array("dn","cn","memberUid"));
1595 while($group = $ldap->fetch()){
1596 $groups_some[$group['dn']] = $group['cn'][0];
1597 for($i = 0 ; $i < $group['memberUid']['count'] ; $i++){
1598 $groups_uid[$group['dn']][] = $group['memberUid'][$i];
1599 }
1600 }
1602 /* Create an array, containing all used groups */
1603 $groups_all = $groups_some;
1604 foreach($groups_all as $id => $group){
1605 foreach($uids as $uid){
1606 if(!in_array($uid,$groups_uid[$id])){
1607 unset($groups_all[$id]);
1608 break;
1609 }
1610 }
1611 }
1613 /* Assign group array */
1614 $this->groupMembership = $groups_all;
1616 /* Create an array of all grouops used by all users */
1617 foreach( $groups_all as $dn => $cn){
1618 if(isset($groups_some[$dn])){
1619 unset($groups_some[$dn]);
1620 }
1621 }
1622 $this->groupMembership_some = $groups_some;
1623 $this->primaryGroup = $this->gidNumber;
1625 /* Is this account a trustAccount? */
1626 if (isset($this->multi_attrs['trustModel'])){
1627 $this->trustModel= $this->multi_attrs['trustModel'][0];
1628 $this->was_trust_account= TRUE;
1629 $this->multi_boxes[] = "trustmode";
1630 } else {
1631 $this->was_trust_account= FALSE;
1632 $this->trustModel= "";
1633 }
1635 /* Create access informations */
1636 $this->accessTo = array();
1637 if (isset($this->multi_attrs['accessTo'])){
1638 for ($i= 0; $i<$this->multi_attrs['accessTo']['count']; $i++){
1639 $tmp= $this->multi_attrs['accessTo'][$i];
1640 $this->accessTo[$tmp]= $tmp;
1641 }
1642 }
1644 /* Adjust shadow checkboxes */
1645 foreach (array("shadowMin", "shadowMax", "shadowWarning", "shadowInactive",
1646 "shadowExpire") as $val){
1647 if ($this->$val != 0){
1648 $oval= "activate_".$val;
1649 $this->$oval= "1";
1650 }
1651 }
1653 /* Convert to seconds */
1654 if(isset($this->multi_attrs['shadowExpire'])){
1655 $this->shadowExpire = $this->convertToSeconds($this->multi_attrs['shadowExpire'][0]);
1656 }else{
1657 $this->activate_shadowExpire = FALSE;
1658 }
1659 }
1662 function set_multi_edit_values($attrs)
1663 {
1664 $groups = array();
1666 /* Update groupMembership, keep optinal group */
1667 foreach($attrs['groupMembership_some'] as $dn => $cn){
1668 if(isset($this->groupMembership[$dn])){
1669 $groups[$dn] = $cn;
1670 }
1671 }
1672 /* Update groupMembership, add forced groups */
1673 foreach($attrs['groupMembership'] as $dn => $cn){
1674 $groups[$dn] = $cn;
1675 }
1676 plugin::set_multi_edit_values($attrs);
1677 $this->groupMembership = $groups;
1678 }
1679 }
1681 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1682 ?>