Code

15952a5107f9922621aac8d5dd1a2a0229cac164
[gosa.git] / gosa-plugins / samba / personal / samba / class_sambaAccount.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2004-2005 Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 class sambaAccount extends plugin
22 {
23   /* Definitions */
24   var $plHeadline= "Samba";
25   var $plDescription= "This does something";
26   var $view_logged = FALSE;
27   var $password_expires= 0;
29   /* Switch for Samba version */
30   var $uidNumber= 65535;
31   var $gidNumber= 65535;
33   /* Samba attributes */
34   var $SID= "";
35   var $ridBase= 0;
36   var $sambaSID= "";
37   var $sambaPwdLastSet= "0";
38   var $sambaLogonTime= "0";
39   var $sambaLogoffTime= "2147483647";
40   var $sambaKickoffTime= "2147483647";
41   var $sambaPwdCanChange= "";
42   var $sambaPwdMustChange= "0";
43   var $sambaAcctFlags= "[UX        ]";
44   var $sambaHomePath= "";
45   var $sambaHomeDrive= "";
46   var $sambaLogonScript= "";
47   var $sambaProfilePath= "";
48   var $sambaPrimaryGroupSID= "";
49   var $sambaDomainName= "";
50   var $sambaUserWorkstations= "";
51   var $sambaBadPasswordCount= "";
52   var $sambaBadPasswordTime= "";
53   var $sambaPasswordHistory= "";
54   var $sambaLogonHours= "";
55   var $orig_sambaDomainName= "";
56   var $sambaMungedDial= "";
57   var $mungedObject;
59   /* Helper */
60   var $cache = array();
61   var $trustSelect= FALSE;
62   var $logon_time_set= 0;
63   var $logoff_time_set= 0;
64   var $kickoff_time_set= 0;
66   /* attribute list for save action */
67   var $ctxattributes= array();
68   var $attributes= array("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
69         "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
70         "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
71         "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
72         "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
73         "sambaUserWorkstations", "sambaPasswordHistory",
74         "sambaLogonHours", "sambaBadPasswordTime",
75         "sambaBadPasswordCount");
76   var $objectclasses= array('sambaSamAccount');
77   
78   var $uid= "";
79   var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName","enforcePasswordChange");
81   var $multiple_support = TRUE;
83   /* Only used  for multiple edit */
84   var $temporary_disable = FALSE;
85   var $no_password_required = FALSE;
86   var $no_expiry = FALSE;
87   var $multiple_sambaUserWorkstations = array();
89   var $enforcePasswordChange = FALSE;
91   function sambaAccount (&$config, $dn= NULL)
92   {
93     $this->mungedObject= new sambaMungedDial;
94     $this->ctxattributes= $this->mungedObject->ctxattributes;
96     plugin::plugin ($config, $dn);
98     /* Setting uid to default */
99     if(isset($this->attrs['uid'][0])){
100       $this->uid = $this->attrs['uid'][0];
101     }
103     /* Get samba Domain in case of samba 3 */
104     if ($this->sambaSID != ""){
105       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
106       $ldap= $this->config->get_ldap_link();
107       $ldap->cd($this->config->current['BASE']);
108       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
109       if ($ldap->count() != 0){
110         $attrs= $ldap->fetch();
111         if(isset($attrs['sambaAlgorithmicRidBase'])){
112           $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
113         } else {
114           $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
115         }
116         if ($this->sambaDomainName == ""){
117           $this->sambaDomainName= $attrs['sambaDomainName'][0];
118         }
119       } else {
120         if ($this->sambaDomainName == ""){
121           $this->sambaDomainName= "DEFAULT";
122         }
123         $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
124         $this->SID= $this->config->get_cfg_value("sambaSid");
125       }
127       /* Save in order to compare later on */
128       $this->orig_sambaDomainName= $this->sambaDomainName;
129     }
131     /* Fill mungedDial field */
132     if (isset($this->attrs['sambaMungedDial'])){
133       $this->mungedObject->load($this->sambaMungedDial);
134     }
136     /* Password expiery */
137     if(isset($this->attrs['sambaPwdMustChange']) &&
138         $this->attrs['sambaPwdMustChange'][0] != 0){
139       $this->password_expires= 1;
140     }
142     if(isset($this->attrs['sambaLogonTime']) && ! (
143         $this->attrs['sambaLogonTime'][0] == 0 ||
144         $this->attrs['sambaLogonTime'][0] == 2147483647
145       )){
146       $this->logon_time_set= 1;
147     }
148     if(isset($this->attrs['sambaLogoffTime']) && ! (
149         $this->attrs['sambaLogoffTime'][0] == 0 ||
150         $this->attrs['sambaLogoffTime'][0] == 2147483647
151       )){
152       $this->logoff_time_set= 1;
153     }
154     
155     /* Account expiery */
156     if(isset($this->attrs['sambaKickoffTime']) && ! (
157         $this->attrs['sambaKickoffTime'][0] == 0 ||
158         $this->attrs['sambaKickoffTime'][0] == 2147483647
159       )){
160       $this->kickoff_time_set= 1;
161     }
163     /* Get global filter config */
164     if (!session::is_set("sambafilter")){
165       $ui= get_userinfo();
166       $base= get_base_from_people($ui->dn);
167       $sambafilter= array( "depselect" => $base, "regex" => "*");
168       session::set("sambafilter", $sambafilter);
169     }
171     /* Save initial account state */
172     $this->initially_was_account= $this->is_account;
174     /* Convert kickoff */
175     #TODO: use date format
176     $this->sambaKickoffTime= $this->sambaKickoffTime == 0?"":date('d.m.Y', $this->sambaKickoffTime);
177     $this->sambaPwdMustChange= $this->sambaPwdMustChange == 2147483647?"":date('d.m.Y', $this->sambaPwdMustChange);
179     // Enforce password change?
180     // ------------------------
181     // Check if we've the attribute 'sambaPwdLastSet' set and if its value is 0,
182     //  in this case a password change is forced for this account.
183     $this->enforcePasswordChange = (isset($this->attrs['sambaPwdLastSet']) && $this->attrs['sambaPwdLastSet'][0] == '0');
185     // User cannot change his password?  (sambaPwdLastSet int max(Int))
186     // --------------------------------
187     // The user is not able to change his password while sambaPwdCanChange is 4294967295 (Integer 32 Bit max)
188     $this->cannotChangePassword = (isset($this->attrs['sambaPwdCanChange']) && $this->attrs['sambaPwdCanChange'][0] == '4294967295');
190   }
192   function execute()
193   {
194     /* Call parent execute */
195     plugin::execute();
197     /* Log view */
198     if($this->is_account && !$this->view_logged){
199       $this->view_logged = TRUE;
200       new log("view","users/".get_class($this),$this->dn);
201     }
203     /* Do we need to flip is_account state? */
204     if (isset($_POST['modify_state'])){
205       $this->is_account= !$this->is_account;
206     }
207     /* Do we represent a valid account? */
208     if (!$this->is_account && $this->parent === NULL){
209       $display= "<img alt=\"\"src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
210         msgPool::noValidExtension(_("Samba"))."</b>";
211       $display.= back_to_main();
212       return ($display);
213     }
215     $display ="";
216     if(!$this->multiple_support_active){
218       /* Show tab dialog headers */
219       $display= "";
220       if ($this->parent !== NULL){
221         if ($this->is_account){
222           $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Samba")),
223               msgPool::featuresEnabled(_("Samba")));
224         } else {
225           $obj= $this->parent->by_object['posixAccount'];
227           /* Samba3 dependency on posix accounts are enabled
228              in the moment, because I need to rely on unique
229              uidNumbers. There'll be a better solution later
230              on. */
231           if ($obj->is_account){
232             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
233                 msgPool::featuresDisabled(_("Samba")));
234           } else {
235             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
236                 msgPool::featuresDisabled(_("Samba"), _("POSIX")), TRUE);
237           }
238           return ($display);
239         }
240       }
241     }
243     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
245     /* Open Samaba Logong hours dialog */
246     if(isset($_POST['SetSambaLogonHours']) && $this->acl_is_readable("sambaLogonHours")){
247       $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours, $this->getacl('sambaLogonHours'));
248     }
250     /* Cancel dialog */
251     if(isset($_POST['cancel_logonHours'])){
252       $this->dialog = FALSE;
253     }
255     /* Save selected logon hours */
256     if(isset($_POST['save_logonHours'])){
257       $this->dialog->save_object();
258       if($this->acl_is_writeable("sambaLogonHours")){
259         $this->sambaLogonHours = $this->dialog->save();
260       }
261       $this->dialog = FALSE;
262     }
264     /* Display dialog */
265     if((isset($this->dialog)) && (is_object($this->dialog))){
266       $this->dialog->save_object();
267       return($this->dialog->execute());
268     }
270     /* Prepare templating */
271     $smarty= get_smarty();
272     $smarty->assign("usePrototype", "true");
274     $tmp = $this->plInfo();
275     foreach($tmp['plProvidedAcls'] as $var => $rest){
276       $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
277     }
279     if(!session::is_set('edit') && !isset($this->parent)){
280       $smarty->assign("sambaLogonHoursACL","");
281     }
283     if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
284       $sambaLogonTime_date= getdate();
285     } else {
286       $sambaLogonTime_date= getdate($this->sambaLogonTime);
287     }
288     
289     if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
290       $sambaLogoffTime_date= getdate();
291     } else {
292       $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
293     }
294     
295     /* Remove user workstations? */
296     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
298       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
300         if($this->multiple_support_active){
301           foreach($_POST['workstation_list'] as $name){
302             if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
303               unset($this->multiple_sambaUserWorkstations[trim($name)]);
304             }
305           } 
306         }else{
307           $tmp= $this->sambaUserWorkstations;
308           foreach($_POST['workstation_list'] as $name){
309             $tmp= preg_replace("/$name/", '', $tmp);
310             $this->is_modified= TRUE;
311           }
312           $tmp= preg_replace('/,+/', ',', $tmp);
313           $this->sambaUserWorkstations= trim($tmp, ',');
314         }
315       }
316     }
318     /* Add user workstation? */
319     if (isset($_POST["add_ws"])){
320       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
321         $this->trustSelect= new trustSelect($this->config,get_userinfo());
322         $this->dialog= TRUE;
323       }
324     }
326     /* Add user workstation finished? */
327     if (isset($_POST["add_ws_cancel"])){
328       $this->trustSelect= FALSE;
329       $this->dialog= FALSE;
330     }
332     // Add selected machines to trusted ones.
333     if (isset($_POST["add_ws_finish"]) &&  $this->trustSelect){
334       $trusts = $this->trustSelect->detectPostActions();
335       if(isset($trusts['targets'])){
337         $headpage = $this->trustSelect->getHeadpage();
338         if($this->multiple_support_active){
339           foreach($trusts['targets'] as $id){
340             $attrs = $headpage->getEntry($id);
341             $we =$attrs['cn'][0];
342             $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
343           }
344         }else{
346           $tmp= $this->sambaUserWorkstations;
347           foreach($trusts['targets'] as $id){
348             $attrs = $headpage->getEntry($id);
349             $we =$attrs['cn'][0];
350             $tmp.= ",$we";
351           }
352           $tmp= preg_replace('/,+/', ',', $tmp);
353           $this->sambaUserWorkstations= trim($tmp, ',');
354         }
356         $this->is_modified= TRUE;
357       }
358       $this->trustSelect= NULL;
359       $this->dialog= FALSE;
360     }
362     /* Show ws dialog */
363     if ($this->trustSelect){
365       // Build up blocklist
366       session::set('filterBlacklist', array('cn' => preg_split('/,/',$this->sambaUserWorkstations)));
367       return($this->trustSelect->execute());
368     }
370     /* Fill boxes */
371     $domains= array();
372     foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
373       $domains[]= $name;
374     }
375     $smarty->assign("domains", $domains);
376     $letters= array("");
377     for ($i= 68; $i<91; $i++){
378       $letters[]= chr($i).":";
379     }
380     $smarty->assign("drives", $letters);
382     /* Fill terminal server settings */
383     foreach ($this->ctxattributes as $attr){
384       /* Fill common attributes */
385       if (isset($this->mungedObject->ctx[$attr])){
386         $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
387         // Set field  to blank if value is 0
388         if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
389           if($this->mungedObject->ctx[$attr] == 0) {
390             $smarty->assign("$attr", "");
391           }
392         }
393       } else {
394         $smarty->assign("$attr", "");
395       }
396     }
398     /* Assign enum values for preset items */
399     $shadowModeVals= array( "0" => _("disabled"),
400         "1" => _("input on, notify on"),
401         "2" => _("input on, notify off"),
402         "3" => _("input off, notify on"),
403         "4" => _("input off, nofify off"));
405     $brokenConnModeVals= array(         "0" => _("disconnect"),
406         "1" => _("reset"));
408     $reConnModeVals= array( "0" => _("from any client"),
409         "1" => _("from previous client only"));
411     /* Fill preset items */
412     $smarty->assign("shadow", $shadowModeVals);
413     $smarty->assign("brokenconn", $brokenConnModeVals);
414     $smarty->assign("reconn", $reConnModeVals);
416     /* Fill preset items with values */
417     $smarty->assign("shadowmode", $this->mungedObject->getShadow());
418     $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
419     $smarty->assign("reconnmode", $this->mungedObject->getReConn());
421     if(session::get('js')){
422       /* Set form elements to disabled/enable state */
423       $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
425       $smarty->assign("inheritstate", "");
426       if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
427         $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
428       }
429     }else{
430       $smarty->assign("tsloginstate", "");
431       $smarty->assign("inheritstate", "");
432     }      
434     /* Set checkboxes to checked or unchecked state */
435     $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
436     $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
437     $smarty->assign("connectclientdrives",
438                     $this->mungedObject->getConnectClientDrives()?"checked":"");
439     $smarty->assign("connectclientprinters",
440                     $this->mungedObject->getConnectClientPrinters()?"checked":"");
441     $smarty->assign("defaultprinter",
442                     $this->mungedObject->getDefaultPrinter()?"checked":"");
443     $smarty->assign("CtxMaxConnectionTimeF",
444                     $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
445     $smarty->assign("CtxMaxDisconnectionTimeF",
446                     $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
447     $smarty->assign("CtxMaxIdleTimeF",
448                     $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
450     
451     /* Fill sambaUserWorkstations */
452     $ws= explode(",", $this->sambaUserWorkstations);
453     sort($ws);
454     
455     /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
456     if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
458     if($this->multiple_support_active){
459       $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
460     }  
462     $smarty->assign("workstations", $ws);
463     
465     /* Variables */
466     foreach($this->attributes as $val){
467       $smarty->assign("$val", $this->$val);
468     }
470     /* 'sambaAcctFlags' checkboxes */
471     /* Check for 'lock-account'-flag: 'D' or 'L' */
472     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
473         is_integer(strpos($this->sambaAcctFlags, "L"))) {
474         $smarty->assign("flagsD", "checked");
475     } else {
476         $smarty->assign("flagsD", "");
477     }
478     
479     /* Check for no_password_required flag 'N' */
480     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
481         $smarty->assign("flagsN", "checked");
482     } else {
483         $smarty->assign("flagsN", "");
484     }
486     // check if password never expires
487     if (is_integer(strpos($this->sambaAcctFlags, "X"))) {
488         $smarty->assign("flagsX", "checked");
489     } else {
490         $smarty->assign("flagsX", "");
491     }
493     if ($this->sambaPwdCanChange=="1"){
494       $smarty->assign("flagsP", "checked");
495     } else {
496       $smarty->assign("flagsP", "");
497     }
499     if ($this->password_expires=="1"){
500       $smarty->assign("flagsC", "checked");
501     } else {
502       $smarty->assign("flagsC", "");
503     }
504     if ($this->logon_time_set=="1"){
505       $smarty->assign("flagsT", "checked");
506     } else {
507       $smarty->assign("flagsT", "");
508     }
509     if ($this->logoff_time_set=="1"){
510       $smarty->assign("flagsO", "checked");
511     } else {
512       $smarty->assign("flagsO", "");
513     }
514     if ($this->kickoff_time_set=="1"){
515       $smarty->assign("flagsK", "checked");
516     } else {
517       $smarty->assign("flagsK", "");
518     }
519    
521     /* In case of javascript, disable some fields on demand */
522     foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
523       $smarty->assign("$key", "$value");
524     }
527     foreach($this->attributes as $attr){
528       if(in_array($attr,$this->multi_boxes)){
529         $smarty->assign("use_".$attr,TRUE);
530       }else{
531         $smarty->assign("use_".$attr,FALSE);
532       }
533     }
534     foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
535           "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
536           "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
537           "onnectclientprinters","defaultprinter","shadow","brokenconn",
538           "reconn","allow_pwchange","connectclientprinters","no_expiry","no_password_required","temporary_disable", 
539           "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
540           "workstation_list","enforcePasswordChange","cannotChangePassword") as $attr){
541       if(in_array($attr,$this->multi_boxes)){
542         $smarty->assign("use_".$attr,TRUE);
543       }else{
544         $smarty->assign("use_".$attr,FALSE);
545       }
546     }
548     if($this->multiple_support_active){
549       $smarty->assign("tsloginstate","");
550     }
552     /* Create additional info for sambaKickOffTime and sambaPwdMustChange. 
553        e.g. Display effective kickoff time. Domain policy + user settings. 
554      */
555     $additional_info_PwdMustChange = "";
557     /* Calculate effective max Password Age 
558         This can only be calculated if sambaPwdLastSet ist set. 
559      */
560     if(isset($this->attrs['sambaPwdLastSet'][0])){
561       $last = $this->attrs['sambaPwdLastSet'][0];
563       $sid = $this->get_domain_info();
564       if(isset($sid['sambaMaxPwdAge'][0])){
565         $d = ($last + $sid['sambaMaxPwdAge'][0]) - time();
567         /* A negative value means the password is outdated 
568          */
569         if($d < 0){
570           $additional_info_PwdMustChange = sprintf(_("The password is outdated since %s, by domain policy."),
571               date("d.m.Y H:i:s",$last + $sid['sambaMaxPwdAge'][0]));
572         }else{
573           if($this->password_expires && ($last + $sid['sambaMaxPwdAge'][0]) > $this->sambaPwdMustChange){
574             $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by user policy."),
575                 date("d.m.Y H:i:s",  $this->sambaPwdMustChange));
576           }else{
577              $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by domain policy."),
578                 date("d.m.Y H:i:s",  ($last + $sid['sambaMaxPwdAge'][0])));
579           }
580         }
581       }
582     }
583     $smarty->assign("additional_info_PwdMustChange",$additional_info_PwdMustChange);
584     $smarty->assign("no_expiry",$this->no_expiry);
586     /* Show main page */
587     $smarty->assign("multiple_support",$this->multiple_support_active);
589     $smarty->assign('enforcePasswordChange', $this->enforcePasswordChange);
590     $smarty->assign("cannotChangePassword", $this->cannotChangePassword);
591     $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
592     return ($display);
593   }
596   /*! \brief  Returns the samba Domain object, selected in the samba tab.   
597    */
598   function get_domain_info()
599   {
600     /* Only search once, return last result if available
601      */
602     if(!isset($this->cache['DOMAIN'][$this->sambaDomainName])){
603       $this->cache['DOMAIN'][$this->sambaDomainName] = array();
604       if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
605         $cfg = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName];
606         $ldap = $this->config->get_ldap_link();
607         $ldap->cd($this->config->current['BASE']);
608         $ldap->search("(&(objectClass=sambaDomain)(sambaSID=".$cfg['SID']."))",array("*"));
609         if($ldap->count()){
610           $this->cache['DOMAIN'][$this->sambaDomainName] = $ldap->fetch();
611         }
612       }
613     }
614     return($this->cache['DOMAIN'][$this->sambaDomainName]);
615   }
619   function get_samba_information()
620   {
621     $zone = timezone::get_default_timezone();
623     /* Defaults 
624      */
625     $sambaMinPwdLength = "unset";
626     $sambaPwdHistoryLength = "unset";
627     $sambaLogonToChgPwd = "unset";
628     $sambaMaxPwdAge = "unset";
629     $sambaMinPwdAge = "unset";
630     $sambaLockoutDuration = "unset";
631     $sambaLockoutThreshold = "unset";
632     $sambaForceLogoff = "unset";
633     $sambaRefuseMachinePwdChange = "unset";
634     $sambaPwdLastSet = "unset";
635     $sambaLogonTime = "unset";
636     $sambaLogoffTime = "unset";
638     $sambaKickoffTime = "unset"; 
639     $sambaPwdCanChange = "unset";
640     $sambaPwdMustChange = "unset";
641     $sambaBadPasswordCount = "unset";
642     $sambaBadPasswordTime = "unset";
644     /* Domain attributes 
645      */
646     $domain_attributes = array("sambaMinPwdLength","sambaPwdHistoryLength","sambaMaxPwdAge",
647         "sambaMinPwdAge","sambaLockoutDuration","sambaRefuseMachinePwdChange",
648         "sambaLogonToChgPwd","sambaLockoutThreshold","sambaForceLogoff");
650     /* User attributes 
651      */
652     $user_attributes = array("sambaBadPasswordTime","sambaPwdLastSet","sambaLogonTime","sambaLogoffTime",
653         "sambaKickoffTime","sambaPwdCanChange","sambaPwdMustChange","sambaBadPasswordCount", "sambaSID");
655     /* Get samba SID object and parse settings.
656      */  
657     $ldap = $this->config->get_ldap_link();
658     $ldap->cd($this->config->current['BASE']);
659     if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
660       $attrs = $this->get_domain_info();
661       foreach($domain_attributes as $attr){
662         if(isset($attrs[$attr])){
663           $$attr = $attrs[$attr][0];
664         }
665       }
666     }
667   
668     /* Get user infos
669      */
670     foreach($user_attributes as $attr){
671       if(isset($this->attrs[$attr])){
672         $$attr = $this->attrs[$attr][0];
673       }
674     }
675     if($this->password_expires){
676       $sambaPwdMustChange = $this->sambaPwdMustChange;
677     } else {
678       if (is_numeric($sambaPwdMustChange)) {
679         $sambaPwdMustChange= date('d.m.Y', $sambaPwdMustChange);
680       }
681     }
682     if($this->kickoff_time_set){
683       $sambaKickoffTime = $this->sambaKickoffTime;
684     } else {
685       if (is_numeric($sambaKickoffTime)) {
686         $sambaKickoffTime= date('d.m.Y', $sambaKickoffTime);
687       }
688     }
689     $sambaPwdCanChange = $this->sambaPwdCanChange;
692     /* DOMAIN Attributes 
693      */
695     /* sambaMinPwdLength: Password length has a default of 5 
696      */
697     if($sambaMinPwdLength == "unset" || $sambaMinPwdLength == 5){
698       $sambaMinPwdLength  = "5 <i>("._("default").")</i>";
699     }
701     /* sambaPwdHistoryLength: Length of Password History Entries (default: 0 => off)
702      */
703     if($sambaPwdHistoryLength == "unset" || $sambaPwdHistoryLength == 0){
704       $sambaPwdHistoryLength = _("Off")." <i>("._("default").")</i>";
705     }
707     /* sambaLogonToChgPwd: Force Users to logon for password change (default: 0 => off, 2 => on) 
708      */
709     if($sambaLogonToChgPwd == "unset" || $sambaLogonToChgPwd == 0){
710       $sambaLogonToChgPwd = _("Off")." <i>("._("default").")</i>";
711     }else{
712       $sambaLogonToChgPwd = _("On");
713     }
714     
715     /* sambaMaxPwdAge: Maximum password age, in seconds (default: -1 => never expire passwords)'
716      */
717     if($sambaMaxPwdAge == "unset" || $sambaMaxPwdAge == "-1"){
718       $sambaMaxPwdAge = _("disabled")." <i>("._("default").")</i>";
719     }else{
720       $sambaMaxPwdAge .= " "._("seconds"); 
721     }
723     /* sambaMinPwdAge: Minimum password age, in seconds (default: 0 => allow immediate password change
724      */
725     if($sambaMinPwdAge == "unset" || $sambaMinPwdAge == 0){
726       $sambaMinPwdAge = _("disabled")." <i>("._("default").")</i>";
727     }else{
728       $sambaMinPwdAge .= " "._("seconds"); 
729     }
731     /* sambaLockoutDuration: Lockout duration in minutes (default: 30, -1 => forever)
732      */
733     if($sambaLockoutDuration == "unset" || $sambaLockoutDuration == 30){
734       $sambaLockoutDuration = "30 "._("minutes")." <i>("._("default").")</i>";
735     }elseif($sambaLockoutDuration == -1){
736       $sambaLockoutDuration = _("forever");
737     }else{
738       $sambaLockoutDuration .= " "._("minutes");
739     }
741     /* sambaLockoutThreshold: Lockout users after bad logon attempts (default: 0 => off
742      */
743     if($sambaLockoutThreshold == "unset" || $sambaLockoutThreshold == 0){
744       $sambaLockoutThreshold = _("disabled")." <i>("._("default").")</i>";
745     }
747     /* sambaForceLogoff: Disconnect Users outside logon hours (default: -1 => off, 0 => on 
748      */
749     if($sambaForceLogoff == "unset" || $sambaForceLogoff == -1){
750       $sambaForceLogoff = _("off")." <i>("._("default").")</i>";
751     }else{
752       $sambaForceLogoff = _("on");
753     }
755     /* sambaRefuseMachinePwdChange: Allow Machine Password changes (default: 0 => off
756      */
757     if($sambaRefuseMachinePwdChange == "none" || $sambaRefuseMachinePwdChange == 0){
758       $sambaRefuseMachinePwdChange = _("off")." <i>("._("default").")</i>";
759     }else{
760       $sambaRefuseMachinePwdChange = _("on");
761     }
762    
763     /* USER Attributes 
764      */
765     /* sambaBadPasswordTime: Time of the last bad password attempt
766      */
767     if($sambaBadPasswordTime == "unset" || empty($sambaBadPasswordTime)){
768       $sambaBadPasswordTime = "<i>("._("unset").")</i>";
769     }else{
770       $sambaBadPasswordTime = date("d.m.Y H:i:s",$sambaBadPasswordTime);
771     }
773     /* sambaBadPasswordCount: Bad password attempt count 
774      */
775     if($sambaBadPasswordCount == "unset" || empty($sambaBadPasswordCount)){
776       $sambaBadPasswordCount = "<i>("._("unset").")</i>";
777     }else{
778       $sambaBadPasswordCount = date("d.m.Y H:i:s",$sambaBadPasswordCount);
779     }
781     /* sambaPwdLastSet: Timestamp of the last password update
782      */
783     if($sambaPwdLastSet == "unset" || empty($sambaPwdLastSet)){
784       $sambaPwdLastSet = "<i>("._("unset").")</i>";
785     }else{
786       $sambaPwdLastSet = date("d.m.Y H:i:s",$sambaPwdLastSet);
787     }
789     /* sambaLogonTime: Timestamp of last logon
790      */
791     if($sambaLogonTime == "unset" || empty($sambaLogonTime)){
792       $sambaLogonTime = "<i>("._("unset").")</i>";
793     }else{
794       $sambaLogonTime = date("d.m.Y H:i:s",$sambaLogonTime);
795     }
797     /* sambaLogoffTime: Timestamp of last logoff
798      */
799     if($sambaLogoffTime == "unset" || empty($sambaLogoffTime)){
800       $sambaLogoffTime = "<i>("._("unset").")</i>";
801     }else{
802       $sambaLogoffTime = date("d.m.Y H:i:s",$sambaLogoffTime);
803     }
804    
805     /* sambaKickoffTime: Timestamp of when the user will be logged off automatically
806      */
807     if($sambaKickoffTime == "unset" || empty($sambaKickoffTime)){
808       $sambaKickoffTime = "<i>("._("unset").")</i>";
809     }
811     /* sambaPwdMustChange: Timestamp of when the password will expire
812      */
813     if($sambaPwdMustChange == "unset" || empty($sambaPwdMustChange)){
814       $sambaPwdMustChange = "<i>("._("unset").")</i>";
815     }
817     /* sambaPwdCanChange: Timestamp of when the user is allowed to update the password
818      */
819     if($sambaPwdCanChange == "unset" || empty($sambaPwdCanChange)){
820       $sambaPwdCanChange = "<i>("._("unset").")</i>";
821     }elseif($sambaPwdCanChange != "unset" && time() > $sambaPwdCanChange){
822       $sambaPwdCanChange = _("immediately") ;
823     }else{
824       $days     = floor((($sambaPwdCanChange - time()) / 60 / 60 / 24)) ;
825       $hours    = floor((($sambaPwdCanChange - time()) / 60 / 60) % 24) ;
826       $minutes  = floor((($sambaPwdCanChange - time()) / 60 ) % 60) ;
827     
828       $sambaPwdCanChange = " ".$days." "._("days");
829       $sambaPwdCanChange.= " ".$hours." "._("hours");
830       $sambaPwdCanChange.= " ".$minutes." "._("minutes");
831     }
833     $str =
834       "\n<div style='height:200px; overflow: auto;'>".
835       "\n<table style='width:100%;'>".
836       "\n<tr><td><b>"._("Domain attributes")."</b></td></tr>". 
837       "\n<tr><td>"._("Min password length").":           </td><td>".$sambaMinPwdLength."</td></tr>". 
838       "\n<tr><td>"._("Min password length").":           </td><td>".$sambaMinPwdLength."</td></tr>". 
839       "\n<tr><td>"._("Password history").":              </td><td>".$sambaPwdHistoryLength."</td></tr>".
840       "\n<tr><td>"._("Force password change").":         </td><td>".$sambaLogonToChgPwd."</td></tr>".
841       "\n<tr><td>"._("Maximum password age").":          </td><td>".$sambaMaxPwdAge."</td></tr>".
842       "\n<tr><td>"._("Minimum password age").":          </td><td>".$sambaMinPwdAge."</td></tr>".
843       "\n<tr><td>"._("Lockout duration").":              </td><td>".$sambaLockoutDuration."</td></tr>".
844       "\n<tr><td>"._("Bad lockout attempt").":           </td><td>".$sambaLockoutThreshold."</td></tr>".
845       "\n<tr><td>"._("Disconnect time").":               </td><td>".$sambaForceLogoff."</td></tr>".
846       "\n<tr><td>"._("Refuse machine password change").":</td><td>".$sambaRefuseMachinePwdChange."</td></tr>".
847       "\n<tr><td>&nbsp;</td></tr>". 
848       "\n<tr><td><b>"._("User attributes")."</b></td></tr>". 
849       "\n<tr><td>"._("SID").":                           </td><td>".$sambaSID."</td></tr>".
850       "\n<tr><td>"._("Last failed login").":             </td><td>".$sambaBadPasswordTime."</td></tr>".
851       "\n<tr><td>"._("Logon attempts").":                </td><td>".$sambaBadPasswordCount."</td></tr>".
852       "\n<tr><td>"._("Last password update").":          </td><td>".$sambaPwdLastSet."</td></tr>".
853       "\n<tr><td>"._("Last logon").":                    </td><td>".$sambaLogonTime."</td></tr>".
854       "\n<tr><td>"._("Last logoff").":                   </td><td>".$sambaLogoffTime."</td></tr>".
855       "\n<tr><td>"._("Automatic logoff").":              </td><td>".$sambaKickoffTime."</td></tr>";
857       if($this->no_expiry){
858         $str .= "\n<tr><td>"._("Password expires").":              </td><td>"._("No")."</td></tr>";
859         $str .= "\n<tr><td colspan='2'><font color='gray'>".
860           sprintf(_("The password would expire on %s, but the password expiry is disabled."),$sambaPwdMustChange).
861           "</font></td></tr>";
862       }else{
863         $str .= "\n<tr><td>"._("Password expires").":              </td><td>".$sambaPwdMustChange."</td></tr>";
864       }
865     
866       $str .= "\n<tr><td>"._("Password change available").":     </td><td>".$sambaPwdCanChange."</td></tr>".
867       "\n</table>";
868       "\n</div>";
869     return($str);
870   }
873   function remove_from_parent()
874   {
875     /* Cancel if there's nothing to do here */
876    if (!$this->initially_was_account){
877      return;
878    }
879     
880     /* include global link_info */
881     $ldap= $this->config->get_ldap_link();
883     plugin::remove_from_parent();
885     /* Keep uid attribute for gosaAccount */
886     unset($this->attrs['uid']);
887     unset($this->attrs['uidNumber']);
888     unset($this->attrs['gidNumber']);
890     /* Remove objectClass for sambaIdmapEntry */
891     $tmp= array();
892     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
893       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
894         $tmp[]= $this->attrs['objectClass'][$i];
895       }
896     }
897     $this->attrs['objectClass']= $tmp;
899     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
900         $this->attributes, "Save");
901     $ldap->cd($this->dn);
902     $this->cleanup();
903     $ldap->modify ($this->attrs); 
905     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
907     if (!$ldap->success()){
908       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
909     }
911     /* Optionally execute a command after we're done */
912     $this->handle_post_events("remove", array("uid" => $this->uid));
913   }
916   /* Check for input problems */
917   function check()
918   {
919     /* Call common method to give check the hook */
920     $message= plugin::check();
922     /* sambaHomePath requires sambaHomeDrive and vice versa */
923     if(!empty($this->sambaHomePath) && empty($this->sambaHomeDrive)){
924       $message[]= msgPool::required(_("Home drive"));
925     }
926     if(!empty($this->sambaHomeDrive) && empty($this->sambaHomePath)){
927       $message[]= msgPool::required(_("Home path"));
928     }
930     /* Strings */
931     foreach (array( "sambaHomePath" => _("Home directory"),
932           "sambaProfilePath" => _("Profile path")) as $key => $val){
933       if (!$this->mungedObject->is_samba_path($this->$key)){
934         $message[]= msgPool::invalid($val);
935       }
936     }
938     /* Numeric values */
939     foreach (array(     "CtxMaxConnectionTime" => _("Connection"),
940           "CtxMaxDisconnectionTime" => _("Disconnection"),
941           "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
943       if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
944         $message[]= msgPool::invalid($val);
945       }
946     }
948     /* Check dates */
949     if (!tests::is_date($this->sambaKickoffTime)){
950       $message[]= msgPool::invalid(_("Account expires after"), $this->sambaKickoffTime,"" ,"23.02.2009");
951     }
952     if (!tests::is_date($this->sambaPwdMustChange)){
953       $message[]= msgPool::invalid(_("Password expires on"), $this->sambaPwdMustChange,"" ,"23.02.2009");
954     }
956     /* Too many workstations? Windows usrmgr only supports eight */
957     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
958       $message[]= _("The windows usermanager allows eight clients at maximum!");
959     }
961     return ($message);
962   }
965   /* Save data to object */
966   function save_object()
967   {
969     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
971     /* We only care if we are on the sambaTab... */
972     if (isset($_POST['sambaTab'])){
973       plugin::save_object();
975       $this->enforcePasswordChange = (isset($_POST['enforcePasswordChange']));
976       $this->cannotChangePassword = (isset($_POST['cannotChangePassword']));
978       if(isset($_POST['display_information'])){
979         msg_dialog::display(_("Information"), 
980           $this->get_samba_information(),
981           INFO_DIALOG);
982       }
984       /* Take care about access options */
985       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
986         $attrname= "sambaPwdCanChange";
987         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
988           $tmp= 1;
989         } else {
990           $tmp= 0;
991         }
992         if ($this->$attrname != $tmp){
993           $this->is_modified= TRUE;
994         }
995         $this->sambaPwdCanChange= $tmp;
996       }
997       $tmp= "U";
999       $this->no_expiry = FALSE;
1000       if (isset($_POST["no_expiry"])){
1001         if ($_POST["no_expiry"] == 1){
1002           $tmp.= "X";
1003           $this->no_expiry = TRUE;
1004         }
1005       }
1007       $this->no_password_required = FALSE;
1008       if (isset($_POST["no_password_required"])){
1009         if ($_POST["no_password_required"] == 1){
1010           $tmp.= "N";
1011           $this->no_password_required = TRUE;
1012         }
1013       }
1014       if (isset($_POST["password_expires"])){
1015         if ($_POST["password_expires"] == 1){
1016           $this->password_expires= 1;
1017         }
1018       } else {
1019         $this->password_expires= 0;
1020       }
1021       $this->temporary_disable = FALSE;
1022       if (isset($_POST["temporary_disable"])){
1023         if ($_POST["temporary_disable"] == 1){
1024           $this->temporary_disable = TRUE;
1025           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
1026             $tmp.= "L";
1027           } else {
1028             $tmp.= "D";
1029           }
1030         }
1031       }
1032       if (isset($_POST["logon_time_set"])){
1033         if ($_POST["logon_time_set"] == 1){
1034           $this->logon_time_set= 1;
1035         }
1036       } else {
1037         $this->logon_time_set= 0;
1038       }
1039       if (isset($_POST["logoff_time_set"])){
1040         if ($_POST["logoff_time_set"] == 1){
1041           $this->logoff_time_set= 1;
1042         }
1043       } else {
1044         $this->logoff_time_set= 0;
1045       }
1046       if (isset($_POST["kickoff_time_set"])){
1047         if ($_POST["kickoff_time_set"] == 1){
1048           $this->kickoff_time_set= 1;
1049         }
1050       } else {
1051         $this->kickoff_time_set= 0;
1052       }
1053       
1054       $fill= "";
1055       for ($i= strlen($tmp); $i<12; $i++){
1056         $fill.= " ";
1057       }
1059       $tmp= "[$tmp$fill]";
1061       /* Only save if acl's are set */
1062       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1063         $attrname= "sambaAcctFlags";
1064         if ($this->$attrname != $tmp){
1065           $this->is_modified= TRUE;
1066         }
1067         $this->$attrname= $tmp;
1068       }
1070       /* Save sambaDomain attribute */
1071       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && isset ($_POST['sambaDomainName'],$SkipWrite)){
1072         $this->sambaDomainName= validate($_POST['sambaDomainName']);
1073       }
1075       /* Save CTX values */
1076       /* Save obvious values */
1077       foreach($this->ctxattributes as $val){
1078         if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
1079           if (get_magic_quotes_gpc()) {
1080             $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
1081           } else {
1082             $this->mungedObject->ctx[$val]= validate($_POST[$val]);
1083           }
1084         }
1085       }
1087       /* Save checkbox states. */
1088       $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
1089                       && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1090       // Need to do some index checking to avoid messages like "index ... not found"
1091       if(isset($_POST['brokenconn'])) {
1092         $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
1093                       && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1094       }
1095       if(isset($_POST['reconn'])) {
1096         $this->mungedObject->setReConn($_POST['reconn'] == '1'
1097                       && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1098       }
1099       $this->mungedObject->setInheritMode(isset($_POST['inherit'])
1100                       && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1101       $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
1102                       && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1103       $this->mungedObject->setCtxMaxDisconnectionTimeF(
1104                       !isset($_POST['CtxMaxDisconnectionTimeF']) 
1105                       && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1106       $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
1107                       && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1108       $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
1109                       && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1110       $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
1111                       && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1112       $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
1113                       && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1115       /* Save combo boxes. Takes two values */
1116       if(isset($_POST['reconn'])) {
1117         $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
1118       }
1120       /* Check for changes */
1121       if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
1122         $this->is_modified= TRUE;
1123       }
1124       
1125     }
1126   }
1129   /* Save to LDAP */
1130   function save()
1131   {
1132     /* Load uid and gid of this 'dn' */
1133     $ldap= $this->config->get_ldap_link();
1134     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
1135     $tmp= $ldap->fetch();
1136     $this->uidNumber= $tmp['uidNumber'][0];
1137     $this->gidNumber= $tmp['gidNumber'][0];
1139     plugin::save();
1141     /* Remove objectClass for sambaIdmapEntry */
1142     $tmp= array();
1143     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1144       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1145         $tmp[]= $this->attrs['objectClass'][$i];
1146       }
1147     }
1148     $this->attrs['objectClass']= $tmp;
1150     // Enforce password change
1151     if($this->enforcePasswordChange){
1152         $this->attrs['sambaPwdLastSet'] = 0;
1153     }else{
1154         if ($this->sambaPwdLastSet != "0"){
1155             $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1156         } else {
1157             $this->attrs['sambaPwdLastSet']= array();
1158         }
1159     }
1161     if($this->cannotChangePassword){
1162         $this->attrs['sambaPwdCanChange'] = 4294967295;
1163     }
1165     /* Generate rid / primaryGroupId */
1166     if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
1167       msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
1168     } else {
1169       $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
1170       $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
1171     }
1173     /* Need to generate a new uniqe uid/gid combination? */
1174     if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
1175       $uidNumber= $this->uidNumber;
1176       while(TRUE){
1177         $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
1178         $ldap->cd($this->config->current['BASE']);
1179         $ldap->search("(sambaSID=$sid)", array("sambaSID"));
1180         if ($ldap->count() == 0){
1181           break;
1182         }
1183         $uidNumber++;
1184       }
1185       $this->attrs['sambaSID']= $sid;
1187       /* Check for users primary group */
1188       $ldap->cd($this->config->current['BASE']);
1189       $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
1190       if ($ldap->count() != 1){
1191         msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
1192       } else {
1193         $attrs= $ldap->fetch();
1194         $g= new group($this->config, $ldap->getDN());
1195         if ($g->sambaSID == ""){
1196           $g->sambaDomainName= $this->sambaDomainName;
1197           $g->smbgroup= TRUE;
1198           $g->save ();
1199         }
1200         $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
1201       }
1202     }
1204     if ($this->sambaHomeDrive == ""){
1205       $this->attrs["sambaHomeDrive"]= array();
1206     }
1208     /* Generate munged dial value */
1209     $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1211     /* User wants me to fake the idMappings? This is useful for
1212        making winbind resolve the user names in a reasonable amount
1213        of time in combination with larger databases. */
1214     if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1215       $this->attrs['objectClass'][]= "sambaIdmapEntry";
1216     }
1219     /* Password expiery */
1220     if ($this->password_expires == "1"){
1221       #TODO: check for date format
1222       if ($this->attrs['sambaPwdMustChange'] == ""){
1223         $this->attrs['sambaPwdMustChange']= 0;
1224       } else {
1225         list($day, $month, $year)= explode('.', $this->sambaPwdMustChange);
1226         $this->attrs['sambaPwdMustChange']= mktime(0,0,0,$month, $day, $year);
1227       }
1228     } else {
1229       $this->attrs['sambaPwdMustChange']= array();
1230     }
1231     /* Account expiery */
1232     if ($this->logon_time_set == "1"){
1233       $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1234     } else {
1235       $this->attrs['sambaLogonTime']= array();
1236     }
1237     if ($this->logoff_time_set == "1"){
1238       $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1239     } else {
1240       $this->attrs['sambaLogoffTime']= array();
1241     }
1242     if ($this->kickoff_time_set == "1"){
1243       /* Adapt values to be timestamps */
1244       #TODO: check for date format
1245       if ($this->attrs['sambaKickoffTime'] == ""){
1246         $this->attrs['sambaKickoffTime']= 2147483647;
1247       } else {
1248         list($day, $month, $year)= explode('.', $this->sambaKickoffTime);
1249         $this->attrs['sambaKickoffTime']= mktime(0,0,0,$month, $day, $year);
1250       }
1251     } else {
1252       $this->attrs['sambaKickoffTime']= array();
1253     }
1255     /* Write back to ldap */
1256     $ldap->cd($this->dn);
1257     $this->cleanup();
1258     $ldap->modify ($this->attrs); 
1260     if($this->initially_was_account){
1261       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1262     }else{
1263       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1264     }
1266     if (!$ldap->success()){
1267       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1268     }
1270     /* Optionally execute a command after we're done */
1271     if ($this->initially_was_account == $this->is_account){
1272       if ($this->is_modified){
1273         $this->handle_post_events("modify", array("uid" => $this->uid));
1274       }
1275     } else {
1276       $this->handle_post_events("add", array("uid" => $this->uid));
1277     }
1278   }
1281   /* Force password set, if this account doesn't have any samba passwords  */
1282   function password_change_needed()
1283   {
1284     if(!$this->initially_was_account && $this->is_account){
1285       $ldap = $this->config->get_ldap_link();
1286       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1287       $attrs = $ldap->fetch();
1288       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1289         return(TRUE);
1290       }
1291     }
1292     return(FALSE);
1293   }
1296   function adapt_from_template($dn, $skip= array())
1297   {
1298     plugin::adapt_from_template($dn, $skip);
1301     $this->sambaSID= "";
1302     $this->sambaPrimaryGroupSID= "";
1304     /* Fill mungedDial field */
1305     if (isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1306       $this->mungedObject->load($this->sambaMungedDial);
1307     }
1309     /* Adapt munged attributes */
1310     foreach($this->ctxattributes as $attr){
1311       if(isset($this->mungedObject->ctx[$attr]))
1312         $val = $this->mungedObject->ctx[$attr];
1314       foreach (array("sn", "givenName", "uid") as $repl){
1315         if (preg_match("/%$repl/i", $val)){
1316           $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1317         }
1318       }
1319       $this->mungedObject->ctx[$attr] = $val;
1320     }
1322     /* Password expiery */
1323     if(isset($this->attrs['sambaPwdMustChange']) &&
1324         $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1325       $this->password_expires= 1;
1326     }
1328     if(isset($this->attrs['sambaLogonTime']) && ! (
1329         $this->attrs['sambaLogonTime'][0] == 0 ||
1330         $this->attrs['sambaLogonTime'][0] == 2147483647
1331       ) && !in_array('sambaLogonTime', $skip)){
1332       $this->logon_time_set= 1;
1333     }
1334     if(isset($this->attrs['sambaLogoffTime']) && ! (
1335         $this->attrs['sambaLogoffTime'][0] == 0 ||
1336         $this->attrs['sambaLogoffTime'][0] == 2147483647
1337       ) && !in_array('sambaLogonTime', $skip)){
1338       $this->logoff_time_set= 1;
1339     }
1341     /* Account expiery */
1342     if(isset($this->attrs['sambaKickoffTime']) && ! (
1343         $this->attrs['sambaKickoffTime'][0] == 0 ||
1344         $this->attrs['sambaKickoffTime'][0] == 2147483647
1345       ) && !in_array('sambaKickoffTime', $skip)){
1346       $this->kickoff_time_set= 1;
1347     }
1349     /* Get global filter config */
1350     if (!session::is_set("sambafilter")){
1351       $ui= get_userinfo();
1352       $base= get_base_from_people($ui->dn);
1353       $sambafilter= array( "depselect" => $base, "regex" => "*");
1354       session::set("sambafilter", $sambafilter);
1355     }
1356   }
1358   
1359   static function plInfo()
1360   {
1361     return (array(
1362           "plShortName"     => _("Samba"),
1363           "plDescription"   => _("Samba settings"),
1364           "plSelfModify"    => TRUE,
1365           "plDepends"       => array("user"),
1366           "plPriority"      => 5,
1367           "plSection"     => array("personal" => _("My account")),
1368           "plCategory"    => array("users"),
1369           "plOptions"       => array(),
1371           "plProvidedAcls"  => array(
1373             "sambaHomePath"               => _("Generic home directory") ,
1374             "sambaHomeDrive"              => _("Generic samba home drive") ,
1375             "sambaDomainName"             => _("Domain") ,
1376             "sambaLogonScript"            => _("Generic script path") ,
1377             "sambaProfilePath"            => _("Generic profile path") ,
1378             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1379             "InheritClientConfig"         => _("Inherit client config"),
1380             "sambaPwdCanChange"           => _("Allow user to change password") ,
1381             "sambaAcctFlagsN"             => _("Login from windows client requires no password"),
1382             "sambaAcctFlagsX"             => _("Password never expires"),
1383             "sambaAcctFlagsL"             => _("Lock samba account"),
1384             "sambaPwdMustChange"          => _("Password expires") ,
1385             "enforcePasswordChange"       => _("Enforce password change"),
1386             "cannotChangePassword"        => _("Cannot change password"),
1387             "sambaLogonHours"             => _("Logon hours") ,
1388             "sambaUserWorkstations"       => _("Allow connection from"))
1389           ));
1390   }    
1392   function enable_multiple_support()
1393   {
1394     plugin::enable_multiple_support();
1395     $this->multiple_support_active = TRUE;
1396   } 
1398   function multiple_save_object()
1399   {
1400     if (isset($_POST['sambaTab'])){
1401       $this->save_object();
1402       plugin::multiple_save_object();
1403       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1404             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1405             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1406             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1407             "reconn","allow_pwchange","connectclientprinters","no_expiry","no_password_required","temporary_disable",
1408             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1409             "workstation_list","enforcePasswordChange","cannotChangePassword") as $attr){
1410         if(isset($_POST["use_".$attr])){
1411           $this->multi_boxes[] = $attr;
1412         }
1413       }
1414     }
1415   }
1418   function multiple_check()
1419   {
1420     $message = plugin::multiple_check();
1422     /* Strings */
1423     foreach (array( "sambaHomePath" => _("Home directory"),
1424           "sambaProfilePath" => _("Profile path")) as $key => $val){
1425       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1426         $message[]= msgPool::invalid($val);
1427       }
1428     }
1430     /* Numeric values */
1431     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1432                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1433                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1434       if (in_array($key,$this->multi_boxes) && 
1435           isset($this->mungedObject->ctx[$key]) && 
1436           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1437         $message[]=msgPool::invalid($val);
1438       }
1439     }
1441     /* Too many workstations? Windows usrmgr only supports eight */
1442     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1443       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1444     }
1445     return($message);
1446   }
1448   
1449   function get_multi_init_values()
1450   {
1451     $ret = plugin::get_multi_init_values();
1453     /* Parse given sambaUserWorkstations into array
1454      *  to allow "init_multiple_support()" to detect multiple used workstations.
1455      *  Those workstations will be displayed in light grey.
1456      */
1457     $tmp2 = array("count" => 0);
1458     $tmp = explode(",", $this->sambaUserWorkstations);
1459     foreach($tmp as $station){
1460       $station = trim($station);
1461       if(!empty($station)){
1462         $tmp2[] = $station;
1463         $tmp2['count'] ++;
1464       }
1465     } 
1466     $ret['sambaUserWorkstations'] = $tmp2;
1467     return($ret);
1468   }
1472   function init_multiple_support($attrs,$all)
1473   {
1474     plugin::init_multiple_support($attrs,$all);
1476     $this->multiple_sambaUserWorkstations = array();
1477     if(isset($all['sambaUserWorkstations'])){
1478       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1479         $station = trim($all['sambaUserWorkstations'][$i]);
1480         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1481       }
1482     }
1483     if(isset($attrs['sambaUserWorkstations'])){
1484       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1485         $station = trim($attrs['sambaUserWorkstations'][$i]);
1486         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1487       }
1488     }
1489   }
1491   function multiple_execute()
1492   {
1493     return($this->execute());
1494   } 
1496   function get_multi_edit_values()
1497   {
1498     $ret = plugin::get_multi_edit_values();
1500     /* Terminal Server  */
1501     if(in_array("tslogin",$this->multi_boxes)){
1502       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1503     }
1504     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1505       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1506     }
1507     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1508       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1509     }
1510     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1511       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1512     }
1514     if(in_array("inherit",$this->multi_boxes)){
1515       $ret['inherit'] = $this->mungedObject->getInheritMode();
1516     }       
1517     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1518       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1519     } 
1520     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1521       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1522     } 
1524     /* Time Limits. Be careful here, there are some negations  */
1525     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1526       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1527       if(!$ret["CtxMaxConnectionTimeF"]){
1528         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1529       }
1530     }
1531     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1532       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1533       if(!$ret["CtxMaxDisconnectionTimeF"]){
1534         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1535       }
1536     }
1537     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1538       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1539       if(!$ret["CtxMaxIdleTimeF"]){
1540         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1541       }
1542     }
1544     /* Client Devices */
1545     if(in_array("connectclientdrives",$this->multi_boxes)){
1546       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1547     }
1548     if(in_array("connectclientprinters",$this->multi_boxes)){
1549       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1550     }
1551     if(in_array("defaultprinter",$this->multi_boxes)){
1552       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1553     }
1555     /* Misc */
1556     if(in_array("shadow",$this->multi_boxes)){
1557       $ret["shadow"]    =$this->mungedObject->getShadow();
1558     }
1559     if(in_array("brokenconn",$this->multi_boxes)){
1560       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1561     }
1562     if(in_array("reconn",$this->multi_boxes)){
1563       $ret["reconn"]    =$this->mungedObject->getReConn();
1564     }
1566     /* Flags */
1567     if(in_array("allow_pwchange",$this->multi_boxes)){
1568       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1569     }
1570   
1571     if(in_array("password_expires",$this->multi_boxes)){
1572       $ret['password_expires']  = $this->password_expires;
1573       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1574     }
1575     if(in_array("logon_time_set",$this->multi_boxes)){
1576       $ret['logon_time_set'] = $this->logon_time_set;
1577       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1578     }
1579     if(in_array("logoff_time_set",$this->multi_boxes)){
1580       $ret['logoff_time_set'] = $this->logoff_time_set;
1581       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1582     }
1583     if(in_array("kickoff_time_set",$this->multi_boxes)){
1584       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1585       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1586     }
1588     if(in_array("no_password_required",$this->multi_boxes)){
1589       $ret['no_password_required'] = $this->no_password_required;
1590     }
1592     if(in_array("no_expiry",$this->multi_boxes)){
1593       $ret['no_expiry'] = $this->no_expiry;
1594     }
1596     if(in_array("temporary_disable",$this->multi_boxes)){
1597       $ret['temporary_disable'] = $this->temporary_disable;
1598     }
1599    
1600     if(in_array("enforcePasswordChange",$this->multi_boxes)){
1601         $ret['enforcePasswordChange'] = $this->enforcePasswordChange;
1602     }
1603     if(in_array("cannotChangePassword",$this->multi_boxes)){
1604         $ret['cannotChangePassword'] = $this->cannotChangePassword;
1605     }
1607  
1608     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1609       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1610     }
1612     if(in_array("workstation_list",$this->multi_boxes)){
1613       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1614     }
1615     return($ret);
1616   }
1618   function set_multi_edit_values($values)
1619   {
1620     plugin::set_multi_edit_values($values);
1622     /* Prepare current workstation settings to be merged 
1623      *  with multiple edit settings.
1624      */
1625     if(isset($values['multiple_sambaUserWorkstations'])){
1626       $cur_ws = array();
1627       $m_ws = $values['multiple_sambaUserWorkstations'];
1629       /* Prepare current settings to be merged */
1630       if(isset($this->sambaUserWorkstations)){
1631         $ttmp = explode(",",$this->sambaUserWorkstations);
1632         foreach($ttmp as $station){
1633           $station = trim($station);
1634           if(!empty($station)){
1635             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1636           }
1637         }
1638       }
1640       /* Unset removed workstations */
1641       foreach($cur_ws as $cur_name => $cur_station){
1642         if(!isset($m_ws[$cur_name])){
1643           unset($cur_ws[$cur_name]);
1644         }
1645       }
1647       /* Add all added workstations */
1648       foreach($m_ws as $name => $station){
1649         if($station['UsedByAllUsers']){
1650           $cur_ws[$name] = $station;
1651         }
1652       }
1654       $this->sambaUserWorkstations = "";
1655       foreach($cur_ws as $name => $ws){
1656         $this->sambaUserWorkstations .= $name.",";
1657       }
1658       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1659     }
1661     /* Enable disabled terminal login, this is inverted somehow */
1662     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1663   
1664     /* Imherit client configuration */
1665     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1666   
1667     /* Get all ctx values posted */
1668     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1669                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1670     foreach($ctx as $attr){
1671       if(isset($values[$attr])){
1672         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1673       }
1674     }
1676     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1677     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1678     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1680     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1681     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1682     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1684     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1685     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1686     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1688   
1689     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1691     
1692     
1694     if(isset($values['password_expires'])){
1695       $this->password_expires = $values['password_expires'];
1696       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1697     }
1698     if(isset($values['logon_time_set'])){
1699       $this->logon_time_set = $values['logon_time_set'];
1700       $this->sambaLogonTime = $values['sambaLogonTime'];
1701     }
1702     if(isset($values['logoff_time_set'])){
1703       $this->logoff_time_set = $values['logoff_time_set'];
1704       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1705     }
1706     if(isset($values['kickoff_time_set'])){
1707       $this->kickoff_time_set = $values['kickoff_time_set'];
1708       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1709     }
1711     if(isset($values['no_password_required'])){
1712       if($values['no_password_required']){
1713         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1714           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1715         }
1716       }else{
1717         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1718       }
1719     }      
1721     if(isset($values['no_expiry'])){
1722       if($values['no_expiry']){
1723         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1724           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1725         }
1726       }else{
1727         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1728       }
1729     }      
1731     if(isset($values['temporary_disable'])){
1732       if($values['temporary_disable']){
1733         if(preg_match("/L/",$this->sambaAcctFlags)) {
1734           // Keep L
1735         }else{
1736           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1737         }
1738       }else{
1739         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1740       }
1741     }
1742   }
1745   function PrepareForCopyPaste($source)
1746   {
1747     plugin::PrepareForCopyPaste($source);
1749     /* Set a new SID */
1750     $this->sambaSID = "";
1752     /* Fill mungedDial field */
1753     if (isset($source['sambaMungedDial'])){
1754         $this->mungedObject->load($source['sambaMungedDial'][0]);
1755     }
1757     /* Password expiery */
1758     if(isset($source['sambaPwdMustChange']) &&
1759             $source['sambaPwdMustChange'][0] != 0){
1760         $this->password_expires= 1;
1761     }
1763     if(isset($source['sambaLogonTime']) && ! (
1764                 $source['sambaLogonTime'][0] == 0 ||
1765                 $source['sambaLogonTime'][0] == 2147483647
1766                 )){
1767         $this->logon_time_set= 1;
1768     }
1769     if(isset($source['sambaLogoffTime']) && ! (
1770                 $source['sambaLogoffTime'][0] == 0 ||
1771                 $source['sambaLogoffTime'][0] == 2147483647
1772                 )){
1773         $this->logoff_time_set= 1;
1774     }
1776     /* Account expiery */
1777     if(isset($source['sambaKickoffTime']) && ! (
1778                 $source['sambaKickoffTime'][0] == 0 ||
1779                 $source['sambaKickoffTime'][0] == 2147483647
1780                 )){
1781         $this->kickoff_time_set= 1;
1782     }
1785     if(isset($source['sambaKickoffTime'][0])){
1786         $this->sambaKickoffTime = date('d.m.Y', $source['sambaKickoffTime'][0]); 
1787     }
1788   }
1792 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1793 ?>