Code

2f3df17e3f73537515556acbbf73b08fbd01b541
[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;
28   /* Switch for Samba version */
29   var $samba3= FALSE;
30   var $uidNumber= 65535;
31   var $gidNumber= 65535;
33   /* Samba 3 infos */
34   var $display_information = FALSE;
36   /* Samba 2 attributes */
37   var $pwdLastSet= "0";
38   var $logonTime= "0";
39   var $logoffTime= "2147483647";
40   var $kickoffTime= "2147483647";
41   var $pwdCanChange= "0";
42   var $pwdMustChange= "0";
43   var $password_expires= 0;
44   var $acctFlags= "[UX        ]";
45   var $smbHome= "";
46   var $homeDrive= "";
47   var $scriptPath= "";
48   var $profilePath= "";
49   var $rid= "";
50   var $primaryGroupID= "";
52   /* Samba 3 attributes */
53   var $SID= "";
54   var $ridBase= 0;
55   var $sambaSID= "";
56   var $sambaPwdLastSet= "0";
57   var $sambaLogonTime= "0";
58   var $sambaLogoffTime= "2147483647";
59   var $sambaKickoffTime= "2147483647";
60   var $sambaPwdCanChange= "";
61   var $sambaPwdMustChange= "0";
62   var $sambaAcctFlags= "[UX        ]";
63   var $sambaHomePath= "";
64   var $sambaHomeDrive= "";
65   var $sambaLogonScript= "";
66   var $sambaProfilePath= "";
67   var $sambaPrimaryGroupSID= "";
68   var $sambaDomainName= "";
69   var $sambaUserWorkstations= "";
70   var $sambaBadPasswordCount= "";
71   var $sambaBadPasswordTime= "";
72   var $sambaPasswordHistory= "";
73   var $sambaLogonHours= "";
74   var $orig_sambaDomainName= "";
75   var $sambaMungedDial= "";
76   var $mungedObject;
78   /* Helper */
79   var $show_ws_dialog= FALSE;
80   var $logon_time_set= 0;
81   var $logoff_time_set= 0;
82   var $kickoff_time_set= 0;
84   /* attribute list for save action */
85   var $ctxattributes= array();
86   var $attributes= array();
87   var $objectclasses= array();
88   
89   var $uid= "";
90   var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
92   var $multiple_support = TRUE;
94   /* Only used  for multiple edit */
95   var $temporary_disable = FALSE;
96   var $no_password_required = FALSE;
97   var $multiple_sambaUserWorkstations = array();
99   function sambaAccount (&$config, $dn= NULL)
100   {
101     /* Load attributes depending on the samba version */
102     $this->samba3= ($config->get_cfg_value("sambaversion") == 3);
104     if ($this->samba3){
105       $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
106           "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
107           "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
108           "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
109           "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
110           "sambaUserWorkstations", "sambaPasswordHistory",
111           "sambaLogonHours", "sambaBadPasswordTime",
112           "sambaBadPasswordCount");
113       $this->objectclasses= array ("sambaSamAccount");
114       $this->mungedObject= new sambaMungedDial;
115       $this->ctxattributes= $this->mungedObject->ctxattributes;
116     } else {
117       $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
118           "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
119           "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
120       $this->objectclasses= array ("sambaAccount");
121     }
123     plugin::plugin ($config, $dn);
125     /* Setting uid to default */
126     if(isset($this->attrs['uid'][0])){
127       $this->uid = $this->attrs['uid'][0];
128     }
130     /* Get samba Domain in case of samba 3 */
131     if ($this->samba3 && $this->sambaSID != ""){
132       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
133       $ldap= $this->config->get_ldap_link();
134       $ldap->cd($this->config->current['BASE']);
135       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
136       if ($ldap->count() != 0){
137         $attrs= $ldap->fetch();
138         if(isset($attrs['sambaAlgorithmicRidBase'])){
139           $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
140         } else {
141           $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
142         }
143         if ($this->sambaDomainName == ""){
144           $this->sambaDomainName= $attrs['sambaDomainName'][0];
145         }
146       } else {
147         if ($this->sambaDomainName == ""){
148           $this->sambaDomainName= "DEFAULT";
149         }
150         $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
151         $this->SID= $this->config->get_cfg_value("sambaSid");
152       }
154       /* Save in order to compare later on */
155       $this->orig_sambaDomainName= $this->sambaDomainName;
156     }
158     /* Fill mungedDial field */
159     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
160       $this->mungedObject->load($this->sambaMungedDial);
161     }
163     /* Password expiery */
164     if(isset($this->attrs['sambaPwdMustChange']) &&
165         $this->attrs['sambaPwdMustChange'][0] != 0){
166       $this->password_expires= 1;
167     }
169     if(isset($this->attrs['sambaLogonTime']) && ! (
170         $this->attrs['sambaLogonTime'][0] == 0 ||
171         $this->attrs['sambaLogonTime'][0] == 2147483647
172       )){
173       $this->logon_time_set= 1;
174     }
175     if(isset($this->attrs['sambaLogoffTime']) && ! (
176         $this->attrs['sambaLogoffTime'][0] == 0 ||
177         $this->attrs['sambaLogoffTime'][0] == 2147483647
178       )){
179       $this->logoff_time_set= 1;
180     }
181     
182     /* Account expiery */
183     if(isset($this->attrs['sambaKickoffTime']) && ! (
184         $this->attrs['sambaKickoffTime'][0] == 0 ||
185         $this->attrs['sambaKickoffTime'][0] == 2147483647
186       )){
187       $this->kickoff_time_set= 1;
188     }
190     /* Get global filter config */
191     if (!session::is_set("sambafilter")){
192       $ui= get_userinfo();
193       $base= get_base_from_people($ui->dn);
194       $sambafilter= array( "depselect" => $base, "regex" => "*");
195       session::set("sambafilter", $sambafilter);
196     }
198     /* Save initial account state */
199     $this->initially_was_account= $this->is_account;
200   }
202   function execute()
203   {
204     /* Call parent execute */
205     plugin::execute();
207     /* Log view */
208     if($this->is_account && !$this->view_logged){
209       $this->view_logged = TRUE;
210       new log("view","users/".get_class($this),$this->dn);
211     }
213     /* Do we need to flip is_account state? */
214     if (isset($_POST['modify_state'])){
215       $this->is_account= !$this->is_account;
216     }
217     /* Do we represent a valid account? */
218     if (!$this->is_account && $this->parent === NULL){
219       $display= "<img alt=\"\"src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
220         msgPool::noValidExtension(_("Samba"))."</b>";
221       $display.= back_to_main();
222       return ($display);
223     }
225     $display ="";
226     if(!$this->multiple_support_active){
228       /* Show tab dialog headers */
229       $display= "";
230       if ($this->parent !== NULL){
231         if ($this->is_account){
232           $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Samba")),
233               msgPool::featuresEnabled(_("Samba")));
234         } else {
235           $obj= $this->parent->by_object['posixAccount'];
237           /* Samba3 dependency on posix accounts are enabled
238              in the moment, because I need to rely on unique
239              uidNumbers. There'll be a better solution later
240              on. */
241           if ($obj->is_account){
242             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
243                 msgPool::featuresDisabled(_("Samba")));
244           } else {
245             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
246                 msgPool::featuresDisabled(_("Samba"), _("POSIX")), TRUE);
247           }
248           return ($display);
249         }
250       }
251     }
253     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
255     /* Open Samaba Logong hours dialog */
256     if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_readable("sambaLogonHours")){
257       $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
258     }
260     /* Cancel dialog */
261     if(isset($_POST['cancel_logonHours'])){
262       $this->dialog = FALSE;
263     }
265     /* Save selected logon hours */
266     if(isset($_POST['save_logonHours'])){
267       $this->dialog->save_object();
268       if($this->acl_is_writeable("sambaLogonHours")){
269         $this->sambaLogonHours = $this->dialog->save();
270       }
271       $this->dialog = FALSE;
272     }
274     /* Display dialog */
275     if((isset($this->dialog)) && (is_object($this->dialog))){
276       $this->dialog->save_object();
277       return($this->dialog->execute());
278     }
280     /* Prepare templating */
281     $smarty= get_smarty();
283     $tmp = $this->plInfo();
284     foreach($tmp['plProvidedAcls'] as $var => $rest){
285       $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
286     }
288     if(!session::is_set('edit') && !isset($this->parent)){
289       $smarty->assign("sambaLogonHoursACL","");
290     }
292     if ($this->sambaPwdMustChange=="0"){
293       $date= getdate();
294     } else {
295       $date= getdate($this->sambaPwdMustChange);
296     }
298     if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
299       $sambaLogonTime_date= getdate();
300     } else {
301       $sambaLogonTime_date= getdate($this->sambaLogonTime);
302     }
303     
304     if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
305       $sambaLogoffTime_date= getdate();
306     } else {
307       $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
308     }
309     
310     if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
311       $sambaKickoffTime_date= getdate();
312     } else {
313       $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
314     }
316     /* Remove user workstations? */
317     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
319       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
321         if($this->multiple_support_active){
322           foreach($_POST['workstation_list'] as $name){
323             if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
324               unset($this->multiple_sambaUserWorkstations[trim($name)]);
325             }
326           } 
327         }else{
328           $tmp= $this->sambaUserWorkstations;
329           foreach($_POST['workstation_list'] as $name){
330             $tmp= preg_replace("/$name/", '', $tmp);
331             $this->is_modified= TRUE;
332           }
333           $tmp= preg_replace('/,+/', ',', $tmp);
334           $this->sambaUserWorkstations= trim($tmp, ',');
335         }
336       }
337     }
339     /* Add user workstation? */
340     if (isset($_POST["add_ws"])){
341       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
342         $this->show_ws_dialog= TRUE;
343         $this->dialog= TRUE;
344       }
345     }
347     /* Add user workstation finished? */
348     if (isset($_POST["add_ws_cancel"])){
349       $this->show_ws_dialog= FALSE;
350       $this->dialog= FALSE;
351     }
353     /* Add user workstation? */
354     if (isset($_POST["add_ws_finish"])){
356       if (isset($_POST['wslist'])){
357         if($this->multiple_support_active){
358           foreach($_POST['wslist'] as $ws){
359             $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
360           }
361         }else{
362           $tmp= $this->sambaUserWorkstations;
363           foreach($_POST['wslist'] as $ws){
364             $tmp.= ",$ws";
365           }
366           $tmp= preg_replace('/,+/', ',', $tmp);
367           $this->sambaUserWorkstations= trim($tmp, ',');
368         }
369         $this->is_modified= TRUE;
371         $this->show_ws_dialog= FALSE;
372         $this->dialog= FALSE;
373       } else {
374         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
375       }
376     }
378     /* Show ws dialog */
379     if ($this->show_ws_dialog){
381       /* Save data */
382       $sambafilter= session::get("sambafilter");
383       foreach( array("depselect", "regex") as $type){
384         if (isset($_POST[$type])){
385           $sambafilter[$type]= $_POST[$type];
386         }
387       }
388       if (isset($_GET['search'])){
389         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
390         if ($s == "**"){
391           $s= "*";
392         }
393         $sambafilter['regex']= $s;
394       }
395       session::set("sambafilter", $sambafilter);
397       /* Get workstation list */
398       $exclude= "";
400       if($this->multiple_support_active){
401         foreach($this->multiple_sambaUserWorkstations as $ws){
402           if($ws['UsedByAllUsers']){
403             $exclude.= "(cn=".$ws['Name']."$)";
404           }
405         }
406       }else{
407         foreach(split(',', $this->sambaUserWorkstations) as $ws){
408           $exclude.= "(cn=$ws$)";
409         }
410       }
411       if ($exclude != ""){
412         $exclude= "(!(|$exclude))";
413       }
414       $regex= $sambafilter['regex'];
415       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
416       $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
417         
418       $wslist= array();
419       foreach ($res as $attrs){
420         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
421       }
422       asort($wslist);
424       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
425       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
426       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
427       $smarty->assign("deplist", $this->config->idepartments);
428       $smarty->assign("alphabet", generate_alphabet());
429       foreach( array("depselect", "regex") as $type){
430         $smarty->assign("$type", $sambafilter[$type]);
431       }
432       $smarty->assign("hint", print_sizelimit_warning());
433       $smarty->assign("wslist", $wslist);
434       $smarty->assign("apply", apply_filter());
435       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
436                                 dirname(__FILE__)));
437       return ($display);
438     }
440     /* Fill calendar */
441     $days= array();
442     for($d= 1; $d<32; $d++){
443       $days[]= $d;
444     }
445     $years= array();
446     for($y= $date['year']-4; $y<$date['year']+4; $y++){
447       $years[]= $y;
448     }
449     $months= msgPool::months();
450     $smarty->assign("day", $date["mday"]);
451     $smarty->assign("days", $days);
452     $smarty->assign("months", $months);
453     $smarty->assign("month", $date["mon"]-1);
454     $smarty->assign("years", $years);
455     $smarty->assign("year", $date["year"]);
456     
457     $sambaLogonTime_days= array();
458     for($d= 1; $d<32; $d++){
459       $sambaLogonTime_days[]= $d;
460     }
461     $sambaLogonTime_years= array();
462     for($y= $date['year']-4; $y<$date['year']+4; $y++){
463       $sambaLogonTime_years[]= $y;
464     }
465     $sambaLogonTime_months= msgPool::months();
466     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
467     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
468     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
469     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
470     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
471     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
472     
473     $sambaLogoffTime_days= array();
474     for($d= 1; $d<32; $d++){
475       $sambaLogoffTime_days[]= $d;
476     }
477     $sambaLogoffTime_years= array();
478     for($y= $date['year']-4; $y<$date['year']+4; $y++){
479       $sambaLogoffTime_years[]= $y;
480     }
481     $sambaLogoffTime_months= msgPool::months();
482     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
483     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
484     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
485     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
486     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
487     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
488     
489     $sambaKickoffTime_days= array();
490     for($d= 1; $d<32; $d++){
491       $sambaKickoffTime_days[]= $d;
492     }
493     $sambaKickoffTime_years= array();
494     for($y= $date['year']-4; $y<$date['year']+4; $y++){
495       $sambaKickoffTime_years[]= $y;
496     }
497     $sambaKickoffTime_months= msgPool::months();
498     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
499     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
500     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
501     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
502     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
503     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
504     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
505      
506     /* Fill boxes */
507     if ($this->samba3){
508       $domains= array();
509       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
510         $domains[]= $name;
511       }
512       $smarty->assign("domains", $domains);
513     }
514     $letters= array("");
515     for ($i= 68; $i<91; $i++){
516       $letters[]= chr($i).":";
517     }
518     $smarty->assign("drives", $letters);
520     /* Fill terminal server settings */
521     if ($this->samba3){
522       foreach ($this->ctxattributes as $attr){
523         /* Fill common attributes */
524         if (isset($this->mungedObject->ctx[$attr])){
525           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
526           // Set field  to blank if value is 0
527           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
528             if($this->mungedObject->ctx[$attr] == 0) {
529               $smarty->assign("$attr", "");
530             }
531           }
532         } else {
533           $smarty->assign("$attr", "");
534         }
535       }
537       /* Assign enum values for preset items */
538       $shadowModeVals= array( "0" => _("disabled"),
539           "1" => _("input on, notify on"),
540           "2" => _("input on, notify off"),
541           "3" => _("input off, notify on"),
542           "4" => _("input off, nofify off"));
544       $brokenConnModeVals= array(       "0" => _("disconnect"),
545           "1" => _("reset"));
547       $reConnModeVals= array( "0" => _("from any client"),
548           "1" => _("from previous client only"));
550       /* Fill preset items */
551       $smarty->assign("shadow", $shadowModeVals);
552       $smarty->assign("brokenconn", $brokenConnModeVals);
553       $smarty->assign("reconn", $reConnModeVals);
555       /* Fill preset items with values */
556       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
557       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
558       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
560       if(session::get('js')){
561         /* Set form elements to disabled/enable state */
562         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
564         $smarty->assign("inheritstate", "");
565         if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
566           $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
567         }
568       }else{
569         $smarty->assign("tsloginstate", "");
570         $smarty->assign("inheritstate", "");
571       }      
573       /* Set checkboxes to checked or unchecked state */
574       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
575       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
576       $smarty->assign("connectclientdrives",
577                       $this->mungedObject->getConnectClientDrives()?"checked":"");
578       $smarty->assign("connectclientprinters",
579                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
580       $smarty->assign("defaultprinter",
581                       $this->mungedObject->getDefaultPrinter()?"checked":"");
582       $smarty->assign("CtxMaxConnectionTimeF",
583                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
584       $smarty->assign("CtxMaxDisconnectionTimeF",
585                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
586       $smarty->assign("CtxMaxIdleTimeF",
587                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
589       
590       /* Fill sambaUserWorkstations */
591       $ws= split(",", $this->sambaUserWorkstations);
592       sort($ws);
593       
594       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
595       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
597       if($this->multiple_support_active){
598         $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
599       }  
601       $smarty->assign("workstations", $ws);
602     }
604     /* Variables */
605     foreach($this->attributes as $val){
606       $smarty->assign("$val", $this->$val);
607     }
609     /* 'sambaAcctFlags' checkboxes */
610     /* Check for 'lock-account'-flag: 'D' or 'L' */
611     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
612         is_integer(strpos($this->sambaAcctFlags, "L"))) {
613         $smarty->assign("flagsD", "checked");
614     } else {
615         $smarty->assign("flagsD", "");
616     }
617     
618     /* Check for no_password_required flag 'N' */
619     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
620         $smarty->assign("flagsN", "checked");
621     } else {
622         $smarty->assign("flagsN", "");
623     }
625     if($this->samba3){
626       if ($this->sambaPwdCanChange=="1"){
627         $smarty->assign("flagsP", "checked");
628       } else {
629         $smarty->assign("flagsP", "");
630       }
631     }else{
632       if ($this->pwdCanChange=="1"){
633         $smarty->assign("flagsP", "checked");
634       } else {
635         $smarty->assign("flagsP", "");
636       }
637     }
639     if ($this->password_expires=="1"){
640       $smarty->assign("flagsC", "checked");
641     } else {
642       $smarty->assign("flagsC", "");
643     }
644     if ($this->logon_time_set=="1"){
645       $smarty->assign("flagsT", "checked");
646     } else {
647       $smarty->assign("flagsT", "");
648     }
649     if ($this->logoff_time_set=="1"){
650       $smarty->assign("flagsO", "checked");
651     } else {
652       $smarty->assign("flagsO", "");
653     }
654     if ($this->kickoff_time_set=="1"){
655       $smarty->assign("flagsK", "checked");
656     } else {
657       $smarty->assign("flagsK", "");
658     }
659    
661     /* In case of javascript, disable some fields on demand */
662     if ($this->samba3){
663       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
664         $smarty->assign("$key", "$value");
665       }
666     }
669     foreach($this->attributes as $attr){
670       if(in_array($attr,$this->multi_boxes)){
671         $smarty->assign("use_".$attr,TRUE);
672       }else{
673         $smarty->assign("use_".$attr,FALSE);
674       }
675     }
676     foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
677           "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
678           "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
679           "onnectclientprinters","defaultprinter","shadow","brokenconn",
680           "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable", 
681           "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
682           "workstation_list") as $attr){
683       if(in_array($attr,$this->multi_boxes)){
684         $smarty->assign("use_".$attr,TRUE);
685       }else{
686         $smarty->assign("use_".$attr,FALSE);
687       }
688     }
690     if($this->multiple_support_active){
691       $smarty->assign("tsloginstate","");
692     }
694     /* Show main page */
695     $smarty->assign("multiple_support",$this->multiple_support_active);
696     if ($this->samba3){
698       $smarty->assign("samba_information","");
699       $smarty->assign("display_information",$this->display_information);
700       if($this->display_information){
701         $smarty->assign("samba_information",$this->get_samba_information());
702       }
704       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
705     } else {
706       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
707     }
709     return ($display);
710   }
713   function get_samba_information()
714   {
716     /* Defaults 
717      */
718     $sambaMinPwdLength = "unset";
719     $sambaPwdHistoryLength = "unset";
720     $sambaLogonToChgPwd = "unset";
721     $sambaMaxPwdAge = "unset";
722     $sambaMinPwdAge = "unset";
723     $sambaLockoutDuration = "unset";
724     $sambaLockoutThreshold = "unset";
725     $sambaForceLogoff = "unset";
726     $sambaRefuseMachinePwdChange = "unset";
727     $sambaPwdLastSet = "unset";
728     $sambaLogonTime = "unset";
729     $sambaLogoffTime = "unset";
731     $sambaKickoffTime = "unset"; 
732     $sambaPwdCanChange = "unset";
733     $sambaPwdMustChange = "unset";
734     $sambaBadPasswordCount = "unset";
735     $sambaBadPasswordTime = "unset";
737     /* Domain attributes 
738      */
739     $domain_attributes = array("sambaMinPwdLength","sambaPwdHistoryLength","sambaMaxPwdAge",
740         "sambaMinPwdAge","sambaLockoutDuration","sambaRefuseMachinePwdChange",
741         "sambaLogonToChgPwd","sambaLockoutThreshold","sambaForceLogoff");
743     /* User attributes 
744      */
745     $user_attributes = array("sambaBadPasswordTime","sambaPwdLastSet","sambaLogonTime","sambaLogoffTime",
746         "sambaKickoffTime","sambaPwdCanChange","sambaPwdMustChange","sambaBadPasswordCount");
748     /* Get samba SID object and parse settings.
749      */  
750     $ldap = $this->config->get_ldap_link();
751     $ldap->cd($this->config->current['BASE']);
752     if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
753       $cfg = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName];
754       $ldap->search("(&(objectClass=sambaDomain)(sambaSID=".$cfg['SID']."))",array("*"));
755       if($ldap->count() >= 1){
756         $attrs = $ldap->fetch();
757         foreach($domain_attributes as $attr){
758           if(isset($attrs[$attr])){
759             $$attr = $attrs[$attr][0];
760           }
761         }
762       }
763     }
764   
765     /* Get user infos
766      */
767     foreach($user_attributes as $attr){
768       if(isset($this->attrs[$attr])){
769         $$attr = $this->attrs[$attr][0];
770       }
771     }
772     if($this->password_expires){
773       $sambaPwdMustChange = $this->sambaPwdMustChange;
774     }
775     if($this->kickoff_time_set){
776       $sambaKickoffTime = $this->sambaKickoffTime;
777     }
778     $sambaPwdCanChange = $this->sambaPwdCanChange;
781     /* DOMAIN Attributes 
782      */
784     /* sambaMinPwdLength: Password length has a default of 5 
785      */
786     if($sambaMinPwdLength == "unset" || $sambaMinPwdLength == 5){
787       $sambaMinPwdLength  = "5 <i>("._("default").")</i>";
788     }
790     /* sambaPwdHistoryLength: Length of Password History Entries (default: 0 => off)
791      */
792     if($sambaPwdHistoryLength == "unset" || $sambaPwdHistoryLength == 0){
793       $sambaPwdHistoryLength = _("Off")." <i>("._("default").")</i>";
794     }
796     /* sambaLogonToChgPwd: Force Users to logon for password change (default: 0 => off, 2 => on) 
797      */
798     if($sambaLogonToChgPwd == "unset" || $sambaLogonToChgPwd == 0){
799       $sambaLogonToChgPwd = _("Off")." <i>("._("default").")</i>";
800     }else{
801       $sambaLogonToChgPwd = _("On");
802     }
803     
804     /* sambaMaxPwdAge: Maximum password age, in seconds (default: -1 => never expire passwords)'
805      */
806     if($sambaMaxPwdAge == "unset" || $sambaMaxPwdAge == "-1"){
807       $sambaMaxPwdAge = _("disabled")." <i>("._("default").")</i>";
808     }else{
809       $sambaMaxPwdAge .= " "._("seconds"); 
810     }
812     /* sambaMinPwdAge: Minimum password age, in seconds (default: 0 => allow immediate password change
813      */
814     if($sambaMinPwdAge == "unset" || $sambaMinPwdAge == 0){
815       $sambaMinPwdAge = _("disabled")." <i>("._("default").")</i>";
816     }else{
817       $sambaMinPwdAge .= " "._("seconds"); 
818     }
820     /* sambaLockoutDuration: Lockout duration in minutes (default: 30, -1 => forever)
821      */
822     if($sambaLockoutDuration == "unset" || $sambaLockoutDuration == 30){
823       $sambaLockoutDuration = "30 "._("minutes")." <i>("._("default").")</i>";
824     }elseif($sambaLockoutDuration == -1){
825       $sambaLockoutDuration = _("forever");
826     }else{
827       $sambaLockoutDuration .= " "._("minutes");
828     }
830     /* sambaLockoutThreshold: Lockout users after bad logon attempts (default: 0 => off
831      */
832     if($sambaLockoutThreshold == "unset" || $sambaLockoutThreshold == 0){
833       $sambaLockoutThreshold = _("disabled")." <i>("._("default").")</i>";
834     }
836     /* sambaForceLogoff: Disconnect Users outside logon hours (default: -1 => off, 0 => on 
837      */
838     if($sambaForceLogoff == "unset" || $sambaForceLogoff == -1){
839       $sambaForceLogoff = _("off")." <i>("._("default").")</i>";
840     }else{
841       $sambaForceLogoff = _("on");
842     }
844     /* sambaRefuseMachinePwdChange: Allow Machine Password changes (default: 0 => off
845      */
846     if($sambaRefuseMachinePwdChange == "none" || $sambaRefuseMachinePwdChange == 0){
847       $sambaRefuseMachinePwdChange = _("off")." <i>("._("default").")</i>";
848     }else{
849       $sambaRefuseMachinePwdChange = _("on");
850     }
851    
852     /* USER Attributes 
853      */
854     /* sambaBadPasswordTime: Time of the last bad password attempt
855      */
856     if($sambaBadPasswordTime == "unset" || empty($sambaBadPasswordTime)){
857       $sambaBadPasswordTime = "<i>("._("unset").")</i>";
858     }else{
859       $sambaBadPasswordTime = date("d.m.Y H:i:s",$sambaBadPasswordTime);
860     }
862     /* sambaBadPasswordCount: Bad password attempt count 
863      */
864     if($sambaBadPasswordCount == "unset" || empty($sambaBadPasswordCount)){
865       $sambaBadPasswordCount = "<i>("._("unset").")</i>";
866     }else{
867       $sambaBadPasswordCount = date("d.m.Y H:i:s",$sambaBadPasswordCount);
868     }
870     /* sambaPwdLastSet: Timestamp of the last password update
871      */
872     if($sambaPwdLastSet == "unset" || empty($sambaPwdLastSet)){
873       $sambaPwdLastSet = "<i>("._("unset").")</i>";
874     }else{
875       $sambaPwdLastSet = date("d.m.Y H:i:s",$sambaPwdLastSet);
876     }
878     /* sambaLogonTime: Timestamp of last logon
879      */
880     if($sambaLogonTime == "unset" || empty($sambaLogonTime)){
881       $sambaLogonTime = "<i>("._("unset").")</i>";
882     }else{
883       $sambaLogonTime = date("d.m.Y H:i:s",$sambaLogonTime);
884     }
886     /* sambaLogoffTime: Timestamp of last logoff
887      */
888     if($sambaLogoffTime == "unset" || empty($sambaLogoffTime)){
889       $sambaLogoffTime = "<i>("._("unset").")</i>";
890     }else{
891       $sambaLogoffTime = date("d.m.Y H:i:s",$sambaLogoffTime);
892     }
893    
894     /* sambaKickoffTime: Timestamp of when the user will be logged off automatically
895      */
896     if($sambaKickoffTime == "unset" || empty($sambaKickoffTime)){
897       $sambaKickoffTime = "<i>("._("unset").")</i>";
898     }else{
899       $sambaKickoffTime = date("d.m.Y H:i:s",$sambaKickoffTime);
900     }
902     /* sambaPwdMustChange: Timestamp of when the password will expire
903      */
904     if($sambaPwdMustChange == "unset" || empty($sambaPwdMustChange)){
905       $sambaPwdMustChange = "<i>("._("unset").")</i>";
906     }else{
907       $sambaPwdMustChange = date("d.m.Y H:i:s",$sambaPwdMustChange);
908     }
910     /* sambaPwdCanChange: Timestamp of when the user is allowed to update the password
911      */
912     if($sambaPwdCanChange == "unset" || empty($sambaPwdCanChange)){
913       $sambaPwdCanChange = "<i>("._("unset").")</i>";
914     }elseif($sambaPwdCanChange != "unset" && time() > $sambaPwdCanChange){
915       $sambaPwdCanChange = _("immediately") ;
916     }else{
917       $days     = floor((($sambaPwdCanChange - time()) / 60 / 60 / 24)) ;
918       $hours    = floor((($sambaPwdCanChange - time()) / 60 / 60) % 24) ;
919       $minutes  = floor((($sambaPwdCanChange - time()) / 60 ) % 60) ;
920     
921       $sambaPwdCanChange = " ".$days." "._("days");
922       $sambaPwdCanChange.= " ".$hours." "._("hours");
923       $sambaPwdCanChange.= " ".$minutes." "._("minutes");
924     }
926     $str =
927       "\n<table style='width:100%;'><tr><td style='width:50%; border-right: solid 1px #B0B0B0;'>".
928       "\n<table>".
929       "\n<tr><td><b>"._("Domain attributes")."</b></td></tr>". 
930       "\n<tr><td>"._("Min password length").":           </td><td>".$sambaMinPwdLength."</td></tr>". 
931       "\n<tr><td>"._("Min password length").":           </td><td>".$sambaMinPwdLength."</td></tr>". 
932       "\n<tr><td>"._("Password history").":              </td><td>".$sambaPwdHistoryLength."</td></tr>".
933       "\n<tr><td>"._("Force password change").":         </td><td>".$sambaLogonToChgPwd."</td></tr>".
934       "\n<tr><td>"._("Maximum password age").":          </td><td>".$sambaMaxPwdAge."</td></tr>".
935       "\n<tr><td>"._("Minimum password age").":          </td><td>".$sambaMinPwdAge."</td></tr>".
936       "\n<tr><td>"._("Lockout duration").":              </td><td>".$sambaLockoutDuration."</td></tr>".
937       "\n<tr><td>"._("Bad lockout attempt").":           </td><td>".$sambaLockoutThreshold."</td></tr>".
938       "\n<tr><td>"._("Disconnect time").":               </td><td>".$sambaForceLogoff."</td></tr>".
939       "\n<tr><td>"._("Refuse machine password change").":</td><td>".$sambaRefuseMachinePwdChange."</td></tr>".
940       "\n</table></td><td style='vertical-align: top;'><table>".
941       "\n<tr><td><b>"._("User attributes")."</b></td></tr>". 
942       "\n<tr><td>"._("Last failed login").":             </td><td>".$sambaBadPasswordTime."</td></tr>".
943       "\n<tr><td>"._("Logon attempts").":                </td><td>".$sambaBadPasswordCount."</td></tr>".
944       "\n<tr><td>"._("Last password update").":          </td><td>".$sambaPwdLastSet."</td></tr>".
945       "\n<tr><td>"._("Last logon").":                    </td><td>".$sambaLogonTime."</td></tr>".
946       "\n<tr><td>"._("Last logoff").":                   </td><td>".$sambaLogoffTime."</td></tr>".
947       "\n<tr><td>"._("Automatic logoff").":              </td><td>".$sambaKickoffTime."</td></tr>".
948       "\n<tr><td>"._("Password expires").":              </td><td>".$sambaPwdMustChange."</td></tr>".
949       "\n<tr><td>"._("Password change available").":     </td><td>".$sambaPwdCanChange."</td></tr>".
950       "\n</table></td></tr></table>";
951     return($str);
952   }
955   function remove_from_parent()
956   {
957     /* Cancel if there's nothing to do here */
958    if (!$this->initially_was_account){
959      return;
960    }
961     
962     /* include global link_info */
963     $ldap= $this->config->get_ldap_link();
965     plugin::remove_from_parent();
967     /* Keep uid attribute for gosaAccount */
968     unset($this->attrs['uid']);
969     unset($this->attrs['uidNumber']);
970     unset($this->attrs['gidNumber']);
972     /* Remove objectClass for sambaIdmapEntry */
973     $tmp= array();
974     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
975       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
976         $tmp[]= $this->attrs['objectClass'][$i];
977       }
978     }
979     $this->attrs['objectClass']= $tmp;
981     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
982         $this->attributes, "Save");
983     $ldap->cd($this->dn);
984     $this->cleanup();
985     $ldap->modify ($this->attrs); 
987     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
989     if (!$ldap->success()){
990       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
991     }
993     /* Optionally execute a command after we're done */
994     $this->handle_post_events("remove", array("uid" => $this->uid));
995   }
998   /* Check for input problems */
999   function check()
1000   {
1001     /* Call common method to give check the hook */
1002     $message= plugin::check();
1004     if ($this->samba3){
1006       /* sambaHomePath requires sambaHomeDrive and vice versa */
1007       if(!empty($this->sambaHomePath) && empty($this->sambaHomeDrive)){
1008         $message[]= msgPool::required(_("Home drive"));
1009       }
1010       if(!empty($this->sambaHomeDrive) && empty($this->sambaHomePath)){
1011         $message[]= msgPool::required(_("Home path"));
1012       }
1014       /* Strings */
1015       foreach (array( "sambaHomePath" => _("Home directory"),
1016             "sambaProfilePath" => _("Profile path")) as $key => $val){
1017         if (!$this->mungedObject->is_samba_path($this->$key)){
1018           $message[]= msgPool::invalid($val);
1019         }
1020       }
1022       /* Numeric values */
1023       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
1024             "CtxMaxDisconnectionTime" => _("Disconnection"),
1025             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
1027         if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1028           $message[]= msgPool::invalid($val);
1029         }
1030       }
1032       /* Too many workstations? Windows usrmgr only supports eight */
1033       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1034         $message[]= _("The windows usermanager allows eight clients at maximum!");
1035       }
1036     }
1038     return ($message);
1039   }
1042   /* Save data to object */
1043   function save_object()
1044   {
1046     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
1048     /* We only care if we are on the sambaTab... */
1049     if (isset($_POST['sambaTab'])){
1050       plugin::save_object();
1052       if(isset($_POST['display_information'])){
1053         $this->display_information = !$this->display_information;
1054       }
1056       /* Take care about access options */
1057       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1058         if ($this->samba3){
1059           $attrname= "sambaPwdCanChange";
1060         } else {
1061           $attrname= "pwdCanChange";
1062         }
1063         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
1064           $tmp= 1;
1065         } else {
1066           $tmp= 0;
1067         }
1068         if ($this->$attrname != $tmp){
1069           $this->is_modified= TRUE;
1070         }
1071         $this->pwdCanChange= $tmp;
1072         $this->sambaPwdCanChange= $tmp;
1073       }
1074       $tmp= "UX";
1075       $this->no_password_required = FALSE;
1076       if (isset($_POST["no_password_required"])){
1077         if ($_POST["no_password_required"] == 1){
1078           $tmp.= "N";
1079           $this->no_password_required = TRUE;
1080         }
1081       }
1082       if (isset($_POST["password_expires"])){
1083         if ($_POST["password_expires"] == 1){
1084           $this->password_expires= 1;
1085         }
1086       } else {
1087         $this->password_expires= 0;
1088       }
1089       $this->temporary_disable = FALSE;
1090       if (isset($_POST["temporary_disable"])){
1091         if ($_POST["temporary_disable"] == 1){
1092           $this->temporary_disable = TRUE;
1093           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
1094             $tmp.= "L";
1095           } else {
1096             $tmp.= "D";
1097           }
1098         }
1099       }
1100       if (isset($_POST["logon_time_set"])){
1101         if ($_POST["logon_time_set"] == 1){
1102           $this->logon_time_set= 1;
1103         }
1104       } else {
1105         $this->logon_time_set= 0;
1106       }
1107       if (isset($_POST["logoff_time_set"])){
1108         if ($_POST["logoff_time_set"] == 1){
1109           $this->logoff_time_set= 1;
1110         }
1111       } else {
1112         $this->logoff_time_set= 0;
1113       }
1114       if (isset($_POST["kickoff_time_set"])){
1115         if ($_POST["kickoff_time_set"] == 1){
1116           $this->kickoff_time_set= 1;
1117         }
1118       } else {
1119         $this->kickoff_time_set= 0;
1120       }
1121       
1122       $fill= "";
1123       for ($i= strlen($tmp); $i<12; $i++){
1124         $fill.= " ";
1125       }
1127       $tmp= "[$tmp$fill]";
1129       /* Only save if acl's are set */
1130       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1131         if ($this->samba3){
1132           $attrname= "sambaAcctFlags";
1133         } else {
1134           $attrname= "acctFlags";
1135         }
1136         if ($this->$attrname != $tmp){
1137           $this->is_modified= TRUE;
1138         }
1139         $this->$attrname= $tmp;
1140       }
1142       /* Save sambaDomain attribute */
1143       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
1144         $this->sambaDomainName= validate($_POST['sambaDomainName']);
1145       }
1147       /* Save CTX values */
1148       if ($this->samba3){
1150         /* Save obvious values */
1151         foreach($this->ctxattributes as $val){
1152           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
1153             if (get_magic_quotes_gpc()) {
1154               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
1155             } else {
1156               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
1157             }
1158           }
1159         }
1161         /* Save checkbox states. */
1162         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
1163                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1164         // Need to do some index checking to avoid messages like "index ... not found"
1165         if(isset($_POST['brokenconn'])) {
1166           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
1167                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1168         }
1169         if(isset($_POST['reconn'])) {
1170           $this->mungedObject->setReConn($_POST['reconn'] == '1'
1171                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1172         }
1173         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
1174                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1175         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
1176                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1177         $this->mungedObject->setCtxMaxDisconnectionTimeF(
1178                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
1179                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1180         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
1181                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1182         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
1183                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1184         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
1185                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1186         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
1187                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1189         /* Save combo boxes. Takes two values */
1190         if(isset($_POST['reconn'])) {
1191           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
1192         }
1194         /* Check for changes */
1195         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
1196           $this->is_modified= TRUE;
1197         }
1198       }
1199     }
1200   }
1203   /* Save to LDAP */
1204   function save()
1205   {
1206     /* Load uid and gid of this 'dn' */
1207     $ldap= $this->config->get_ldap_link();
1208     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
1209     $tmp= $ldap->fetch();
1210     $this->uidNumber= $tmp['uidNumber'][0];
1211     $this->gidNumber= $tmp['gidNumber'][0];
1213     plugin::save();
1215     /* Remove objectClass for sambaIdmapEntry */
1216     $tmp= array();
1217     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1218       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1219         $tmp[]= $this->attrs['objectClass'][$i];
1220       }
1221     }
1222     $this->attrs['objectClass']= $tmp;
1224     /* Generate rid / primaryGroupId */
1225     if ($this->samba3){
1226       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
1227         msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
1228       } else {
1229         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
1230         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
1231       }
1233       /* Need to generate a new uniqe uid/gid combination? */
1234       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
1235         $uidNumber= $this->uidNumber;
1236         while(TRUE){
1237           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
1238           $ldap->cd($this->config->current['BASE']);
1239           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
1240           if ($ldap->count() == 0){
1241             break;
1242           }
1243           $uidNumber++;
1244         }
1245         $this->attrs['sambaSID']= $sid;
1247         /* Check for users primary group */
1248         $ldap->cd($this->config->current['BASE']);
1249         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
1250         if ($ldap->count() != 1){
1251           msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
1252         } else {
1253           $attrs= $ldap->fetch();
1254           $g= new group($this->config, $ldap->getDN());
1255           if ($g->sambaSID == ""){
1256             $g->sambaDomainName= $this->sambaDomainName;
1257             $g->smbgroup= TRUE;
1258             $g->save ();
1259           }
1260           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
1261         }
1262       }
1264       if ($this->sambaHomeDrive == ""){
1265         $this->attrs["sambaHomeDrive"]= array();
1266       }
1268       /* Generate munged dial value */
1269       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1271       /* User wants me to fake the idMappings? This is useful for
1272          making winbind resolve the user names in a reasonable amount
1273          of time in combination with larger databases. */
1274       if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1275         $this->attrs['objectClass'][]= "sambaIdmapEntry";
1276       }
1279       /* Password expiery */
1280       if ($this->password_expires == "1"){
1281         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1282       } else {
1283         $this->attrs['sambaPwdMustChange']= array();
1284       }
1285       /* Make sure not to save zero in sambaPwdLastset */
1286       if ($this->sambaPwdLastSet != "0"){
1287         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1288       } else {
1289         $this->attrs['sambaPwdLastSet']= array();
1290       }
1291       /* Account expiery */
1292       if ($this->logon_time_set == "1"){
1293         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1294       } else {
1295         $this->attrs['sambaLogonTime']= array();
1296       }
1297       if ($this->logoff_time_set == "1"){
1298         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1299       } else {
1300         $this->attrs['sambaLogoffTime']= array();
1301       }
1302       if ($this->kickoff_time_set == "1"){
1303         # Add one day in unixtime format to be compatible with usrmgr
1304         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1305         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1306       } else {
1307         $this->attrs['sambaKickoffTime']= array();
1308       }
1309     } else {
1310     /* Not samba3 */
1311       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1312       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1314       if ($this->homeDrive == ""){
1315         $this->attrs["homeDrive"]= array();
1316       }
1318       /* Password expiery */
1319       if ($this->password_expires == "1"){
1320         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1321       } else {
1322         $this->attrs['pwdMustChange']= 2147483647;
1323       }
1324       /* Make sure not to save zero in pwdLastset */
1325       if ($this->pwdLastSet != "0"){
1326         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1327       } else {
1328         $this->attrs['pwdLastSet']= array();
1329       }
1330       /* Account expiery */
1331       if ($this->logon_time_set == "1"){
1332         $this->attrs['logonTime']= $this->logonTime;
1333       } else {
1334         $this->attrs['logonTime']= array();
1335       }
1336       if ($this->logoff_time_set == "1"){
1337         $this->attrs['logoffTime']= $this->logoffTime;
1338       } else {
1339         $this->attrs['logoffTime']= array();
1340       }
1341       if ($this->kickoff_time_set == "1"){
1342         # Add one day in unixtime format to be compatible with usrmgr
1343         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1344       } else {
1345         $this->attrs['kickoffTime']= array();
1346       }
1347     }
1349     /* Write back to ldap */
1350     $ldap->cd($this->dn);
1351     $this->cleanup();
1352     $ldap->modify ($this->attrs); 
1354     if($this->initially_was_account){
1355       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1356     }else{
1357       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1358     }
1360     if (!$ldap->success()){
1361       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1362     }
1364     /* Optionally execute a command after we're done */
1365     if ($this->initially_was_account == $this->is_account){
1366       if ($this->is_modified){
1367         $this->handle_post_events("modify", array("uid" => $this->uid));
1368       }
1369     } else {
1370       $this->handle_post_events("add", array("uid" => $this->uid));
1371     }
1372   }
1375   /* Force password set, if this account doesn't have any samba passwords  */
1376   function password_change_needed()
1377   {
1378     if(!$this->initially_was_account && $this->is_account){
1379       $ldap = $this->config->get_ldap_link();
1380       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1381       $attrs = $ldap->fetch();
1382       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1383         return(TRUE);
1384       }
1385     }
1386     return(FALSE);
1387   }
1390   function adapt_from_template($dn, $skip= array())
1391   {
1392     plugin::adapt_from_template($dn, $skip);
1395     $this->sambaSID= "";
1396     $this->sambaPrimaryGroupSID= "";
1398     /* Fill mungedDial field */
1399     if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1400       $this->mungedObject->load($this->sambaMungedDial);
1401     }
1403     /* Adapt munged attributes */
1404     foreach($this->ctxattributes as $attr){
1405       if(isset($this->mungedObject->ctx[$attr]))
1406         $val = $this->mungedObject->ctx[$attr];
1408       foreach (array("sn", "givenName", "uid") as $repl){
1409         if (preg_match("/%$repl/i", $val)){
1410           $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1411         }
1412       }
1413       $this->mungedObject->ctx[$attr] = $val;
1414     }
1416     /* Password expiery */
1417     if(isset($this->attrs['sambaPwdMustChange']) &&
1418         $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1419       $this->password_expires= 1;
1420     }
1422     if(isset($this->attrs['sambaLogonTime']) && ! (
1423         $this->attrs['sambaLogonTime'][0] == 0 ||
1424         $this->attrs['sambaLogonTime'][0] == 2147483647
1425       ) && !in_array('sambaLogonTime', $skip)){
1426       $this->logon_time_set= 1;
1427     }
1428     if(isset($this->attrs['sambaLogoffTime']) && ! (
1429         $this->attrs['sambaLogoffTime'][0] == 0 ||
1430         $this->attrs['sambaLogoffTime'][0] == 2147483647
1431       ) && !in_array('sambaLogonTime', $skip)){
1432       $this->logoff_time_set= 1;
1433     }
1435     /* Account expiery */
1436     if(isset($this->attrs['sambaKickoffTime']) && ! (
1437         $this->attrs['sambaKickoffTime'][0] == 0 ||
1438         $this->attrs['sambaKickoffTime'][0] == 2147483647
1439       ) && !in_array('sambaKickoffTime', $skip)){
1440       $this->kickoff_time_set= 1;
1441     }
1443     /* Get global filter config */
1444     if (!session::is_set("sambafilter")){
1445       $ui= get_userinfo();
1446       $base= get_base_from_people($ui->dn);
1447       $sambafilter= array( "depselect" => $base, "regex" => "*");
1448       session::set("sambafilter", $sambafilter);
1449     }
1450   }
1452   
1453   static function plInfo()
1454   {
1455     return (array(
1456           "plShortName"     => _("Samba"),
1457           "plDescription"   => _("Samba settings"),
1458           "plSelfModify"    => TRUE,
1459           "plDepends"       => array("user"),
1460           "plPriority"      => 5,
1461           "plSection"     => array("personal" => _("My account")),
1462           "plCategory"    => array("users"),
1463           "plOptions"       => array(),
1465           "plProvidedAcls"  => array(
1467             "sambaHomePath"               => _("Generic home directory") ,
1468             "sambaHomeDrive"              => _("Generic samba home drive") ,
1469             "sambaDomainName"             => _("Domain") ,
1470             "sambaLogonScript"            => _("Generic script path") ,
1471             "sambaProfilePath"            => _("Generic profile path") ,
1472             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1473             "InheritClientConfig"         => _("Inherit client config"),
1474             "sambaPwdCanChange"           => _("Allow user to change password") ,
1475             "sambaAcctFlagsN"             => _("Login from windows client requires no password"),
1476             "sambaAcctFlagsL"             => _("Lock samba account"),
1477             "sambaKickoffTime"            => _("Account expires") ,
1478             "sambaPwdMustChange"          => _("Password expires") ,
1479             "sambaLogonTime"              => _("Limit Logon Time") ,
1480             "sambaLogoffTime"             => _("Limit Logoff Time") ,
1481             "sambaLogonHours"             => _("Logon hours") ,
1482             "sambaUserWorkstations"       => _("Allow connection from"))
1483           ));
1484   }    
1486   function enable_multiple_support()
1487   {
1488     plugin::enable_multiple_support();
1489     if($this->samba3){
1490       $this->multiple_support_active = TRUE;
1491     }else{
1492       $this->multiple_support_active = FALSE;
1493     }
1494   } 
1496   function multiple_save_object()
1497   {
1498     if (isset($_POST['sambaTab'])){
1499       $this->save_object();
1500       plugin::multiple_save_object();
1501       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1502             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1503             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1504             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1505             "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1506             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1507             "workstation_list") as $attr){
1508         if(isset($_POST["use_".$attr])){
1509           $this->multi_boxes[] = $attr;
1510         }
1511       }
1512     }
1513   }
1516   function multiple_check()
1517   {
1518     $message = plugin::multiple_check();
1520     /* Strings */
1521     foreach (array( "sambaHomePath" => _("Home directory"),
1522           "sambaProfilePath" => _("Profile path")) as $key => $val){
1523       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1524         $message[]= msgPool::invalid($val);
1525       }
1526     }
1528     /* Numeric values */
1529     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1530                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1531                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1532       if (in_array($key,$this->multi_boxes) && 
1533           isset($this->mungedObject->ctx[$key]) && 
1534           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1535         $message[]=msgPool::invalid($val);
1536       }
1537     }
1539     /* Too many workstations? Windows usrmgr only supports eight */
1540     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1541       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1542     }
1543     return($message);
1544   }
1546   
1547   function get_multi_init_values()
1548   {
1549     $ret = plugin::get_multi_init_values();
1551     /* Parse given sambaUserWorkstations into array
1552      *  to allow "init_multiple_support()" to detect multiple used workstations.
1553      *  Those workstations will be displayed in light grey.
1554      */
1555     $tmp2 = array("count" => 0);
1556     $tmp = split(",", $this->sambaUserWorkstations);
1557     foreach($tmp as $station){
1558       $station = trim($station);
1559       if(!empty($station)){
1560         $tmp2[] = $station;
1561         $tmp2['count'] ++;
1562       }
1563     } 
1564     $ret['sambaUserWorkstations'] = $tmp2;
1565     return($ret);
1566   }
1570   function init_multiple_support($attrs,$all)
1571   {
1572     plugin::init_multiple_support($attrs,$all);
1574     $this->multiple_sambaUserWorkstations = array();
1575     if(isset($all['sambaUserWorkstations'])){
1576       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1577         $station = trim($all['sambaUserWorkstations'][$i]);
1578         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1579       }
1580     }
1581     if(isset($attrs['sambaUserWorkstations'])){
1582       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1583         $station = trim($attrs['sambaUserWorkstations'][$i]);
1584         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1585       }
1586     }
1587   }
1589   function multiple_execute()
1590   {
1591     return($this->execute());
1592   } 
1594   function get_multi_edit_values()
1595   {
1596     $ret = plugin::get_multi_edit_values();
1598     /* Terminal Server  */
1599     if(in_array("tslogin",$this->multi_boxes)){
1600       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1601     }
1602     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1603       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1604     }
1605     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1606       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1607     }
1608     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1609       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1610     }
1612     if(in_array("inherit",$this->multi_boxes)){
1613       $ret['inherit'] = $this->mungedObject->getInheritMode();
1614     }       
1615     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1616       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1617     } 
1618     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1619       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1620     } 
1622     /* Time Limits. Be careful here, there are some negations  */
1623     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1624       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1625       if(!$ret["CtxMaxConnectionTimeF"]){
1626         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1627       }
1628     }
1629     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1630       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1631       if(!$ret["CtxMaxDisconnectionTimeF"]){
1632         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1633       }
1634     }
1635     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1636       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1637       if(!$ret["CtxMaxIdleTimeF"]){
1638         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1639       }
1640     }
1642     /* Client Devices */
1643     if(in_array("connectclientdrives",$this->multi_boxes)){
1644       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1645     }
1646     if(in_array("connectclientprinters",$this->multi_boxes)){
1647       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1648     }
1649     if(in_array("defaultprinter",$this->multi_boxes)){
1650       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1651     }
1653     /* Misc */
1654     if(in_array("shadow",$this->multi_boxes)){
1655       $ret["shadow"]    =$this->mungedObject->getShadow();
1656     }
1657     if(in_array("brokenconn",$this->multi_boxes)){
1658       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1659     }
1660     if(in_array("reconn",$this->multi_boxes)){
1661       $ret["reconn"]    =$this->mungedObject->getReConn();
1662     }
1664     /* Flags */
1665     if(in_array("allow_pwchange",$this->multi_boxes)){
1666       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1667       $ret['pwdCanChange']      = $this->pwdCanChange;
1668     }
1669   
1670     if(in_array("password_expires",$this->multi_boxes)){
1671       $ret['password_expires']  = $this->password_expires;
1672       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1673     }
1674     if(in_array("logon_time_set",$this->multi_boxes)){
1675       $ret['logon_time_set'] = $this->logon_time_set;
1676       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1677     }
1678     if(in_array("logoff_time_set",$this->multi_boxes)){
1679       $ret['logoff_time_set'] = $this->logoff_time_set;
1680       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1681     }
1682     if(in_array("kickoff_time_set",$this->multi_boxes)){
1683       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1684       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1685     }
1687     if(in_array("no_password_required",$this->multi_boxes)){
1688       $ret['no_password_required'] = $this->no_password_required;
1689     }
1691     if(in_array("temporary_disable",$this->multi_boxes)){
1692       $ret['temporary_disable'] = $this->temporary_disable;
1693     }
1694     
1695     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1696       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1697     }
1699     if(in_array("workstation_list",$this->multi_boxes)){
1700       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1701     }
1702     return($ret);
1703   }
1705   function set_multi_edit_values($values)
1706   {
1707     plugin::set_multi_edit_values($values);
1709     /* Prepare current workstation settings to be merged 
1710      *  with multiple edit settings.
1711      */
1712     if(isset($values['multiple_sambaUserWorkstations'])){
1713       $cur_ws = array();
1714       $m_ws = $values['multiple_sambaUserWorkstations'];
1716       /* Prepare current settings to be merged */
1717       if(isset($this->sambaUserWorkstations)){
1718         $ttmp = split(",",$this->sambaUserWorkstations);
1719         foreach($ttmp as $station){
1720           $station = trim($station);
1721           if(!empty($station)){
1722             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1723           }
1724         }
1725       }
1727       /* Unset removed workstations */
1728       foreach($cur_ws as $cur_name => $cur_station){
1729         if(!isset($m_ws[$cur_name])){
1730           unset($cur_ws[$cur_name]);
1731         }
1732       }
1734       /* Add all added workstations */
1735       foreach($m_ws as $name => $station){
1736         if($station['UsedByAllUsers']){
1737           $cur_ws[$name] = $station;
1738         }
1739       }
1741       $this->sambaUserWorkstations = "";
1742       foreach($cur_ws as $name => $ws){
1743         $this->sambaUserWorkstations .= $name.",";
1744       }
1745       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1746     }
1748     /* Enable disabled terminal login, this is inverted somehow */
1749     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1750   
1751     /* Imherit client configuration */
1752     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1753   
1754     /* Get all ctx values posted */
1755     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1756                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1757     foreach($ctx as $attr){
1758       if(isset($values[$attr])){
1759         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1760       }
1761     }
1763     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1764     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1765     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1767     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1768     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1769     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1771     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1772     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1773     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1775   
1776     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1777     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1779     
1780     
1782     if(isset($values['password_expires'])){
1783       $this->password_expires = $values['password_expires'];
1784       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1785     }
1786     if(isset($values['logon_time_set'])){
1787       $this->logon_time_set = $values['logon_time_set'];
1788       $this->sambaLogonTime = $values['sambaLogonTime'];
1789     }
1790     if(isset($values['logoff_time_set'])){
1791       $this->logoff_time_set = $values['logoff_time_set'];
1792       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1793     }
1794     if(isset($values['kickoff_time_set'])){
1795       $this->kickoff_time_set = $values['kickoff_time_set'];
1796       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1797     }
1799     if(isset($values['no_password_required'])){
1800       if($values['no_password_required']){
1801         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1802           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1803         }
1804       }else{
1805         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1806       }
1807     }      
1809     if(isset($values['temporary_disable'])){
1810       if($values['temporary_disable']){
1811         if(preg_match("/L/",$this->sambaAcctFlags)) {
1812           // Keep L
1813         }else{
1814           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1815         }
1816       }else{
1817         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1818       }
1819     }
1820   }
1823   function PrepareForCopyPaste($source)
1824   {
1825     plugin::PrepareForCopyPaste($source);
1827     /* Set a new SID */
1828     $this->sambaSID = "";
1829   }
1833 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1834 ?>