Code

Updated Samba tab
[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     /* Create additional info for sambaKickOffTime and sambaPwdMustChange. 
695        e.g. Display effective kickoff time. Domain policy + user settings. 
696      */
697     $additional_info_PwdMustChange = "";
699     /* Calculate effective max Password Age 
700         This can only be calculated if sambaPwdLastSet ist set. 
701      */
702     if(isset($this->attrs['sambaPwdLastSet'][0])){
703       $last = $this->attrs['sambaPwdLastSet'][0];
705       $sid = $this->get_domain_info();
706       if(isset($sid['sambaMaxPwdAge'][0])){
707         $d = ($last + $sid['sambaMaxPwdAge'][0]) - time();
709         /* A negative value means the password is outdated 
710          */
711         if($d < 0){
712           $additional_info_PwdMustChange = sprintf(_("The password is outdated since %s, by domain policy."),
713               date("d.m.Y H:i:s",$last + $sid['sambaMaxPwdAge'][0]));
714         }else{
715           if($this->password_expires && ($last + $sid['sambaMaxPwdAge'][0]) > $this->sambaPwdMustChange){
716             $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by user policy."),
717                 date("d.m.Y H:i:s",  $this->sambaPwdMustChange));
718           }else{
719              $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by domain policy."),
720                 date("d.m.Y H:i:s",  ($last + $sid['sambaMaxPwdAge'][0])));
721           }
722         }
723       }
724     }
725     $smarty->assign("additional_info_PwdMustChange",$additional_info_PwdMustChange);
727     /* Show main page */
728     $smarty->assign("multiple_support",$this->multiple_support_active);
729     if ($this->samba3){
731       $smarty->assign("samba_information","");
732       $smarty->assign("display_information",$this->display_information);
733       if($this->display_information){
734         $smarty->assign("samba_information",$this->get_samba_information());
735       }
737       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
738     } else {
739       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
740     }
742     return ($display);
743   }
746   /*! \brief  Returns the samba Domain object, selected in the samba tab.   
747    */
748   function get_domain_info()
749   {
750     /* Only search once, return last result if available
751      */
752     if(!isset($this->cache['DOMAIN'][$this->sambaDomainName])){
753       $this->cache['DOMAIN'][$this->sambaDomainName] = array();
754       if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
755         $cfg = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName];
756         $ldap = $this->config->get_ldap_link();
757         $ldap->cd($this->config->current['BASE']);
758         $ldap->search("(&(objectClass=sambaDomain)(sambaSID=".$cfg['SID']."))",array("*"));
759         if($ldap->count()){
760           $this->cache['DOMAIN'][$this->sambaDomainName] = $ldap->fetch();
761         }
762       }
763     }
764     return($this->cache['DOMAIN'][$this->sambaDomainName]);
765   }
769   function get_samba_information()
770   {
772     /* Defaults 
773      */
774     $sambaMinPwdLength = "unset";
775     $sambaPwdHistoryLength = "unset";
776     $sambaLogonToChgPwd = "unset";
777     $sambaMaxPwdAge = "unset";
778     $sambaMinPwdAge = "unset";
779     $sambaLockoutDuration = "unset";
780     $sambaLockoutThreshold = "unset";
781     $sambaForceLogoff = "unset";
782     $sambaRefuseMachinePwdChange = "unset";
783     $sambaPwdLastSet = "unset";
784     $sambaLogonTime = "unset";
785     $sambaLogoffTime = "unset";
787     $sambaKickoffTime = "unset"; 
788     $sambaPwdCanChange = "unset";
789     $sambaPwdMustChange = "unset";
790     $sambaBadPasswordCount = "unset";
791     $sambaBadPasswordTime = "unset";
793     /* Domain attributes 
794      */
795     $domain_attributes = array("sambaMinPwdLength","sambaPwdHistoryLength","sambaMaxPwdAge",
796         "sambaMinPwdAge","sambaLockoutDuration","sambaRefuseMachinePwdChange",
797         "sambaLogonToChgPwd","sambaLockoutThreshold","sambaForceLogoff");
799     /* User attributes 
800      */
801     $user_attributes = array("sambaBadPasswordTime","sambaPwdLastSet","sambaLogonTime","sambaLogoffTime",
802         "sambaKickoffTime","sambaPwdCanChange","sambaPwdMustChange","sambaBadPasswordCount");
804     /* Get samba SID object and parse settings.
805      */  
806     $ldap = $this->config->get_ldap_link();
807     $ldap->cd($this->config->current['BASE']);
808     if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
809       $cfg = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName];
810       $ldap->search("(&(objectClass=sambaDomain)(sambaSID=".$cfg['SID']."))",array("*"));
811       if($ldap->count() >= 1){
812         $attrs = $ldap->fetch();
813         foreach($domain_attributes as $attr){
814           if(isset($attrs[$attr])){
815             $$attr = $attrs[$attr][0];
816           }
817         }
818       }
819     }
820   
821     /* Get user infos
822      */
823     foreach($user_attributes as $attr){
824       if(isset($this->attrs[$attr])){
825         $$attr = $this->attrs[$attr][0];
826       }
827     }
828     if($this->password_expires){
829       $sambaPwdMustChange = $this->sambaPwdMustChange;
830     }
831     if($this->kickoff_time_set){
832       $sambaKickoffTime = $this->sambaKickoffTime;
833     }
834     $sambaPwdCanChange = $this->sambaPwdCanChange;
837     /* DOMAIN Attributes 
838      */
840     /* sambaMinPwdLength: Password length has a default of 5 
841      */
842     if($sambaMinPwdLength == "unset" || $sambaMinPwdLength == 5){
843       $sambaMinPwdLength  = "5 <i>("._("default").")</i>";
844     }
846     /* sambaPwdHistoryLength: Length of Password History Entries (default: 0 => off)
847      */
848     if($sambaPwdHistoryLength == "unset" || $sambaPwdHistoryLength == 0){
849       $sambaPwdHistoryLength = _("Off")." <i>("._("default").")</i>";
850     }
852     /* sambaLogonToChgPwd: Force Users to logon for password change (default: 0 => off, 2 => on) 
853      */
854     if($sambaLogonToChgPwd == "unset" || $sambaLogonToChgPwd == 0){
855       $sambaLogonToChgPwd = _("Off")." <i>("._("default").")</i>";
856     }else{
857       $sambaLogonToChgPwd = _("On");
858     }
859     
860     /* sambaMaxPwdAge: Maximum password age, in seconds (default: -1 => never expire passwords)'
861      */
862     if($sambaMaxPwdAge == "unset" || $sambaMaxPwdAge == "-1"){
863       $sambaMaxPwdAge = _("disabled")." <i>("._("default").")</i>";
864     }else{
865       $sambaMaxPwdAge .= " "._("seconds"); 
866     }
868     /* sambaMinPwdAge: Minimum password age, in seconds (default: 0 => allow immediate password change
869      */
870     if($sambaMinPwdAge == "unset" || $sambaMinPwdAge == 0){
871       $sambaMinPwdAge = _("disabled")." <i>("._("default").")</i>";
872     }else{
873       $sambaMinPwdAge .= " "._("seconds"); 
874     }
876     /* sambaLockoutDuration: Lockout duration in minutes (default: 30, -1 => forever)
877      */
878     if($sambaLockoutDuration == "unset" || $sambaLockoutDuration == 30){
879       $sambaLockoutDuration = "30 "._("minutes")." <i>("._("default").")</i>";
880     }elseif($sambaLockoutDuration == -1){
881       $sambaLockoutDuration = _("forever");
882     }else{
883       $sambaLockoutDuration .= " "._("minutes");
884     }
886     /* sambaLockoutThreshold: Lockout users after bad logon attempts (default: 0 => off
887      */
888     if($sambaLockoutThreshold == "unset" || $sambaLockoutThreshold == 0){
889       $sambaLockoutThreshold = _("disabled")." <i>("._("default").")</i>";
890     }
892     /* sambaForceLogoff: Disconnect Users outside logon hours (default: -1 => off, 0 => on 
893      */
894     if($sambaForceLogoff == "unset" || $sambaForceLogoff == -1){
895       $sambaForceLogoff = _("off")." <i>("._("default").")</i>";
896     }else{
897       $sambaForceLogoff = _("on");
898     }
900     /* sambaRefuseMachinePwdChange: Allow Machine Password changes (default: 0 => off
901      */
902     if($sambaRefuseMachinePwdChange == "none" || $sambaRefuseMachinePwdChange == 0){
903       $sambaRefuseMachinePwdChange = _("off")." <i>("._("default").")</i>";
904     }else{
905       $sambaRefuseMachinePwdChange = _("on");
906     }
907    
908     /* USER Attributes 
909      */
910     /* sambaBadPasswordTime: Time of the last bad password attempt
911      */
912     if($sambaBadPasswordTime == "unset" || empty($sambaBadPasswordTime)){
913       $sambaBadPasswordTime = "<i>("._("unset").")</i>";
914     }else{
915       $sambaBadPasswordTime = date("d.m.Y H:i:s",$sambaBadPasswordTime);
916     }
918     /* sambaBadPasswordCount: Bad password attempt count 
919      */
920     if($sambaBadPasswordCount == "unset" || empty($sambaBadPasswordCount)){
921       $sambaBadPasswordCount = "<i>("._("unset").")</i>";
922     }else{
923       $sambaBadPasswordCount = date("d.m.Y H:i:s",$sambaBadPasswordCount);
924     }
926     /* sambaPwdLastSet: Timestamp of the last password update
927      */
928     if($sambaPwdLastSet == "unset" || empty($sambaPwdLastSet)){
929       $sambaPwdLastSet = "<i>("._("unset").")</i>";
930     }else{
931       $sambaPwdLastSet = date("d.m.Y H:i:s",$sambaPwdLastSet);
932     }
934     /* sambaLogonTime: Timestamp of last logon
935      */
936     if($sambaLogonTime == "unset" || empty($sambaLogonTime)){
937       $sambaLogonTime = "<i>("._("unset").")</i>";
938     }else{
939       $sambaLogonTime = date("d.m.Y H:i:s",$sambaLogonTime);
940     }
942     /* sambaLogoffTime: Timestamp of last logoff
943      */
944     if($sambaLogoffTime == "unset" || empty($sambaLogoffTime)){
945       $sambaLogoffTime = "<i>("._("unset").")</i>";
946     }else{
947       $sambaLogoffTime = date("d.m.Y H:i:s",$sambaLogoffTime);
948     }
949    
950     /* sambaKickoffTime: Timestamp of when the user will be logged off automatically
951      */
952     if($sambaKickoffTime == "unset" || empty($sambaKickoffTime)){
953       $sambaKickoffTime = "<i>("._("unset").")</i>";
954     }else{
955       $sambaKickoffTime = date("d.m.Y H:i:s",$sambaKickoffTime);
956     }
958     /* sambaPwdMustChange: Timestamp of when the password will expire
959      */
960     if($sambaPwdMustChange == "unset" || empty($sambaPwdMustChange)){
961       $sambaPwdMustChange = "<i>("._("unset").")</i>";
962     }else{
963       $sambaPwdMustChange = date("d.m.Y H:i:s",$sambaPwdMustChange);
964     }
966     /* sambaPwdCanChange: Timestamp of when the user is allowed to update the password
967      */
968     if($sambaPwdCanChange == "unset" || empty($sambaPwdCanChange)){
969       $sambaPwdCanChange = "<i>("._("unset").")</i>";
970     }elseif($sambaPwdCanChange != "unset" && time() > $sambaPwdCanChange){
971       $sambaPwdCanChange = _("immediately") ;
972     }else{
973       $days     = floor((($sambaPwdCanChange - time()) / 60 / 60 / 24)) ;
974       $hours    = floor((($sambaPwdCanChange - time()) / 60 / 60) % 24) ;
975       $minutes  = floor((($sambaPwdCanChange - time()) / 60 ) % 60) ;
976     
977       $sambaPwdCanChange = " ".$days." "._("days");
978       $sambaPwdCanChange.= " ".$hours." "._("hours");
979       $sambaPwdCanChange.= " ".$minutes." "._("minutes");
980     }
982     $str =
983       "\n<table style='width:100%;'><tr><td style='width:50%; border-right: solid 1px #B0B0B0;'>".
984       "\n<table>".
985       "\n<tr><td><b>"._("Domain attributes")."</b></td></tr>". 
986       "\n<tr><td>"._("Min password length").":           </td><td>".$sambaMinPwdLength."</td></tr>". 
987       "\n<tr><td>"._("Min password length").":           </td><td>".$sambaMinPwdLength."</td></tr>". 
988       "\n<tr><td>"._("Password history").":              </td><td>".$sambaPwdHistoryLength."</td></tr>".
989       "\n<tr><td>"._("Force password change").":         </td><td>".$sambaLogonToChgPwd."</td></tr>".
990       "\n<tr><td>"._("Maximum password age").":          </td><td>".$sambaMaxPwdAge."</td></tr>".
991       "\n<tr><td>"._("Minimum password age").":          </td><td>".$sambaMinPwdAge."</td></tr>".
992       "\n<tr><td>"._("Lockout duration").":              </td><td>".$sambaLockoutDuration."</td></tr>".
993       "\n<tr><td>"._("Bad lockout attempt").":           </td><td>".$sambaLockoutThreshold."</td></tr>".
994       "\n<tr><td>"._("Disconnect time").":               </td><td>".$sambaForceLogoff."</td></tr>".
995       "\n<tr><td>"._("Refuse machine password change").":</td><td>".$sambaRefuseMachinePwdChange."</td></tr>".
996       "\n</table></td><td style='vertical-align: top;'><table>".
997       "\n<tr><td><b>"._("User attributes")."</b></td></tr>". 
998       "\n<tr><td>"._("Last failed login").":             </td><td>".$sambaBadPasswordTime."</td></tr>".
999       "\n<tr><td>"._("Logon attempts").":                </td><td>".$sambaBadPasswordCount."</td></tr>".
1000       "\n<tr><td>"._("Last password update").":          </td><td>".$sambaPwdLastSet."</td></tr>".
1001       "\n<tr><td>"._("Last logon").":                    </td><td>".$sambaLogonTime."</td></tr>".
1002       "\n<tr><td>"._("Last logoff").":                   </td><td>".$sambaLogoffTime."</td></tr>".
1003       "\n<tr><td>"._("Automatic logoff").":              </td><td>".$sambaKickoffTime."</td></tr>".
1004       "\n<tr><td>"._("Password expires").":              </td><td>".$sambaPwdMustChange."</td></tr>".
1005       "\n<tr><td>"._("Password change available").":     </td><td>".$sambaPwdCanChange."</td></tr>".
1006       "\n</table></td></tr></table>";
1007     return($str);
1008   }
1011   function remove_from_parent()
1012   {
1013     /* Cancel if there's nothing to do here */
1014    if (!$this->initially_was_account){
1015      return;
1016    }
1017     
1018     /* include global link_info */
1019     $ldap= $this->config->get_ldap_link();
1021     plugin::remove_from_parent();
1023     /* Keep uid attribute for gosaAccount */
1024     unset($this->attrs['uid']);
1025     unset($this->attrs['uidNumber']);
1026     unset($this->attrs['gidNumber']);
1028     /* Remove objectClass for sambaIdmapEntry */
1029     $tmp= array();
1030     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1031       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1032         $tmp[]= $this->attrs['objectClass'][$i];
1033       }
1034     }
1035     $this->attrs['objectClass']= $tmp;
1037     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1038         $this->attributes, "Save");
1039     $ldap->cd($this->dn);
1040     $this->cleanup();
1041     $ldap->modify ($this->attrs); 
1043     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1045     if (!$ldap->success()){
1046       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
1047     }
1049     /* Optionally execute a command after we're done */
1050     $this->handle_post_events("remove", array("uid" => $this->uid));
1051   }
1054   /* Check for input problems */
1055   function check()
1056   {
1057     /* Call common method to give check the hook */
1058     $message= plugin::check();
1060     if ($this->samba3){
1062       /* sambaHomePath requires sambaHomeDrive and vice versa */
1063       if(!empty($this->sambaHomePath) && empty($this->sambaHomeDrive)){
1064         $message[]= msgPool::required(_("Home drive"));
1065       }
1066       if(!empty($this->sambaHomeDrive) && empty($this->sambaHomePath)){
1067         $message[]= msgPool::required(_("Home path"));
1068       }
1070       /* Strings */
1071       foreach (array( "sambaHomePath" => _("Home directory"),
1072             "sambaProfilePath" => _("Profile path")) as $key => $val){
1073         if (!$this->mungedObject->is_samba_path($this->$key)){
1074           $message[]= msgPool::invalid($val);
1075         }
1076       }
1078       /* Numeric values */
1079       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
1080             "CtxMaxDisconnectionTime" => _("Disconnection"),
1081             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
1083         if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1084           $message[]= msgPool::invalid($val);
1085         }
1086       }
1088       /* Too many workstations? Windows usrmgr only supports eight */
1089       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1090         $message[]= _("The windows usermanager allows eight clients at maximum!");
1091       }
1092     }
1094     return ($message);
1095   }
1098   /* Save data to object */
1099   function save_object()
1100   {
1102     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
1104     /* We only care if we are on the sambaTab... */
1105     if (isset($_POST['sambaTab'])){
1106       plugin::save_object();
1108       if(isset($_POST['display_information'])){
1109         $this->display_information = !$this->display_information;
1110       }
1112       /* Take care about access options */
1113       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1114         if ($this->samba3){
1115           $attrname= "sambaPwdCanChange";
1116         } else {
1117           $attrname= "pwdCanChange";
1118         }
1119         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
1120           $tmp= 1;
1121         } else {
1122           $tmp= 0;
1123         }
1124         if ($this->$attrname != $tmp){
1125           $this->is_modified= TRUE;
1126         }
1127         $this->pwdCanChange= $tmp;
1128         $this->sambaPwdCanChange= $tmp;
1129       }
1130       $tmp= "UX";
1131       $this->no_password_required = FALSE;
1132       if (isset($_POST["no_password_required"])){
1133         if ($_POST["no_password_required"] == 1){
1134           $tmp.= "N";
1135           $this->no_password_required = TRUE;
1136         }
1137       }
1138       if (isset($_POST["password_expires"])){
1139         if ($_POST["password_expires"] == 1){
1140           $this->password_expires= 1;
1141         }
1142       } else {
1143         $this->password_expires= 0;
1144       }
1145       $this->temporary_disable = FALSE;
1146       if (isset($_POST["temporary_disable"])){
1147         if ($_POST["temporary_disable"] == 1){
1148           $this->temporary_disable = TRUE;
1149           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
1150             $tmp.= "L";
1151           } else {
1152             $tmp.= "D";
1153           }
1154         }
1155       }
1156       if (isset($_POST["logon_time_set"])){
1157         if ($_POST["logon_time_set"] == 1){
1158           $this->logon_time_set= 1;
1159         }
1160       } else {
1161         $this->logon_time_set= 0;
1162       }
1163       if (isset($_POST["logoff_time_set"])){
1164         if ($_POST["logoff_time_set"] == 1){
1165           $this->logoff_time_set= 1;
1166         }
1167       } else {
1168         $this->logoff_time_set= 0;
1169       }
1170       if (isset($_POST["kickoff_time_set"])){
1171         if ($_POST["kickoff_time_set"] == 1){
1172           $this->kickoff_time_set= 1;
1173         }
1174       } else {
1175         $this->kickoff_time_set= 0;
1176       }
1177       
1178       $fill= "";
1179       for ($i= strlen($tmp); $i<12; $i++){
1180         $fill.= " ";
1181       }
1183       $tmp= "[$tmp$fill]";
1185       /* Only save if acl's are set */
1186       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1187         if ($this->samba3){
1188           $attrname= "sambaAcctFlags";
1189         } else {
1190           $attrname= "acctFlags";
1191         }
1192         if ($this->$attrname != $tmp){
1193           $this->is_modified= TRUE;
1194         }
1195         $this->$attrname= $tmp;
1196       }
1198       /* Save sambaDomain attribute */
1199       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
1200         $this->sambaDomainName= validate($_POST['sambaDomainName']);
1201       }
1203       /* Save CTX values */
1204       if ($this->samba3){
1206         /* Save obvious values */
1207         foreach($this->ctxattributes as $val){
1208           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
1209             if (get_magic_quotes_gpc()) {
1210               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
1211             } else {
1212               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
1213             }
1214           }
1215         }
1217         /* Save checkbox states. */
1218         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
1219                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1220         // Need to do some index checking to avoid messages like "index ... not found"
1221         if(isset($_POST['brokenconn'])) {
1222           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
1223                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1224         }
1225         if(isset($_POST['reconn'])) {
1226           $this->mungedObject->setReConn($_POST['reconn'] == '1'
1227                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1228         }
1229         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
1230                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1231         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
1232                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1233         $this->mungedObject->setCtxMaxDisconnectionTimeF(
1234                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
1235                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1236         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
1237                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1238         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
1239                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1240         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
1241                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1242         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
1243                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1245         /* Save combo boxes. Takes two values */
1246         if(isset($_POST['reconn'])) {
1247           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
1248         }
1250         /* Check for changes */
1251         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
1252           $this->is_modified= TRUE;
1253         }
1254       }
1255     }
1256   }
1259   /* Save to LDAP */
1260   function save()
1261   {
1262     /* Load uid and gid of this 'dn' */
1263     $ldap= $this->config->get_ldap_link();
1264     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
1265     $tmp= $ldap->fetch();
1266     $this->uidNumber= $tmp['uidNumber'][0];
1267     $this->gidNumber= $tmp['gidNumber'][0];
1269     plugin::save();
1271     /* Remove objectClass for sambaIdmapEntry */
1272     $tmp= array();
1273     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1274       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1275         $tmp[]= $this->attrs['objectClass'][$i];
1276       }
1277     }
1278     $this->attrs['objectClass']= $tmp;
1280     /* Generate rid / primaryGroupId */
1281     if ($this->samba3){
1282       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
1283         msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
1284       } else {
1285         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
1286         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
1287       }
1289       /* Need to generate a new uniqe uid/gid combination? */
1290       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
1291         $uidNumber= $this->uidNumber;
1292         while(TRUE){
1293           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
1294           $ldap->cd($this->config->current['BASE']);
1295           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
1296           if ($ldap->count() == 0){
1297             break;
1298           }
1299           $uidNumber++;
1300         }
1301         $this->attrs['sambaSID']= $sid;
1303         /* Check for users primary group */
1304         $ldap->cd($this->config->current['BASE']);
1305         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
1306         if ($ldap->count() != 1){
1307           msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
1308         } else {
1309           $attrs= $ldap->fetch();
1310           $g= new group($this->config, $ldap->getDN());
1311           if ($g->sambaSID == ""){
1312             $g->sambaDomainName= $this->sambaDomainName;
1313             $g->smbgroup= TRUE;
1314             $g->save ();
1315           }
1316           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
1317         }
1318       }
1320       if ($this->sambaHomeDrive == ""){
1321         $this->attrs["sambaHomeDrive"]= array();
1322       }
1324       /* Generate munged dial value */
1325       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1327       /* User wants me to fake the idMappings? This is useful for
1328          making winbind resolve the user names in a reasonable amount
1329          of time in combination with larger databases. */
1330       if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1331         $this->attrs['objectClass'][]= "sambaIdmapEntry";
1332       }
1335       /* Password expiery */
1336       if ($this->password_expires == "1"){
1337         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1338       } else {
1339         $this->attrs['sambaPwdMustChange']= array();
1340       }
1341       /* Make sure not to save zero in sambaPwdLastset */
1342       if ($this->sambaPwdLastSet != "0"){
1343         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1344       } else {
1345         $this->attrs['sambaPwdLastSet']= array();
1346       }
1347       /* Account expiery */
1348       if ($this->logon_time_set == "1"){
1349         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1350       } else {
1351         $this->attrs['sambaLogonTime']= array();
1352       }
1353       if ($this->logoff_time_set == "1"){
1354         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1355       } else {
1356         $this->attrs['sambaLogoffTime']= array();
1357       }
1358       if ($this->kickoff_time_set == "1"){
1359         # Add one day in unixtime format to be compatible with usrmgr
1360         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1361         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1362       } else {
1363         $this->attrs['sambaKickoffTime']= array();
1364       }
1365     } else {
1366     /* Not samba3 */
1367       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1368       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1370       if ($this->homeDrive == ""){
1371         $this->attrs["homeDrive"]= array();
1372       }
1374       /* Password expiery */
1375       if ($this->password_expires == "1"){
1376         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1377       } else {
1378         $this->attrs['pwdMustChange']= 2147483647;
1379       }
1380       /* Make sure not to save zero in pwdLastset */
1381       if ($this->pwdLastSet != "0"){
1382         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1383       } else {
1384         $this->attrs['pwdLastSet']= array();
1385       }
1386       /* Account expiery */
1387       if ($this->logon_time_set == "1"){
1388         $this->attrs['logonTime']= $this->logonTime;
1389       } else {
1390         $this->attrs['logonTime']= array();
1391       }
1392       if ($this->logoff_time_set == "1"){
1393         $this->attrs['logoffTime']= $this->logoffTime;
1394       } else {
1395         $this->attrs['logoffTime']= array();
1396       }
1397       if ($this->kickoff_time_set == "1"){
1398         # Add one day in unixtime format to be compatible with usrmgr
1399         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1400       } else {
1401         $this->attrs['kickoffTime']= array();
1402       }
1403     }
1405     /* Write back to ldap */
1406     $ldap->cd($this->dn);
1407     $this->cleanup();
1408     $ldap->modify ($this->attrs); 
1410     if($this->initially_was_account){
1411       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1412     }else{
1413       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1414     }
1416     if (!$ldap->success()){
1417       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1418     }
1420     /* Optionally execute a command after we're done */
1421     if ($this->initially_was_account == $this->is_account){
1422       if ($this->is_modified){
1423         $this->handle_post_events("modify", array("uid" => $this->uid));
1424       }
1425     } else {
1426       $this->handle_post_events("add", array("uid" => $this->uid));
1427     }
1428   }
1431   /* Force password set, if this account doesn't have any samba passwords  */
1432   function password_change_needed()
1433   {
1434     if(!$this->initially_was_account && $this->is_account){
1435       $ldap = $this->config->get_ldap_link();
1436       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1437       $attrs = $ldap->fetch();
1438       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1439         return(TRUE);
1440       }
1441     }
1442     return(FALSE);
1443   }
1446   function adapt_from_template($dn, $skip= array())
1447   {
1448     plugin::adapt_from_template($dn, $skip);
1451     $this->sambaSID= "";
1452     $this->sambaPrimaryGroupSID= "";
1454     /* Fill mungedDial field */
1455     if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1456       $this->mungedObject->load($this->sambaMungedDial);
1457     }
1459     /* Adapt munged attributes */
1460     foreach($this->ctxattributes as $attr){
1461       if(isset($this->mungedObject->ctx[$attr]))
1462         $val = $this->mungedObject->ctx[$attr];
1464       foreach (array("sn", "givenName", "uid") as $repl){
1465         if (preg_match("/%$repl/i", $val)){
1466           $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1467         }
1468       }
1469       $this->mungedObject->ctx[$attr] = $val;
1470     }
1472     /* Password expiery */
1473     if(isset($this->attrs['sambaPwdMustChange']) &&
1474         $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1475       $this->password_expires= 1;
1476     }
1478     if(isset($this->attrs['sambaLogonTime']) && ! (
1479         $this->attrs['sambaLogonTime'][0] == 0 ||
1480         $this->attrs['sambaLogonTime'][0] == 2147483647
1481       ) && !in_array('sambaLogonTime', $skip)){
1482       $this->logon_time_set= 1;
1483     }
1484     if(isset($this->attrs['sambaLogoffTime']) && ! (
1485         $this->attrs['sambaLogoffTime'][0] == 0 ||
1486         $this->attrs['sambaLogoffTime'][0] == 2147483647
1487       ) && !in_array('sambaLogonTime', $skip)){
1488       $this->logoff_time_set= 1;
1489     }
1491     /* Account expiery */
1492     if(isset($this->attrs['sambaKickoffTime']) && ! (
1493         $this->attrs['sambaKickoffTime'][0] == 0 ||
1494         $this->attrs['sambaKickoffTime'][0] == 2147483647
1495       ) && !in_array('sambaKickoffTime', $skip)){
1496       $this->kickoff_time_set= 1;
1497     }
1499     /* Get global filter config */
1500     if (!session::is_set("sambafilter")){
1501       $ui= get_userinfo();
1502       $base= get_base_from_people($ui->dn);
1503       $sambafilter= array( "depselect" => $base, "regex" => "*");
1504       session::set("sambafilter", $sambafilter);
1505     }
1506   }
1508   
1509   static function plInfo()
1510   {
1511     return (array(
1512           "plShortName"     => _("Samba"),
1513           "plDescription"   => _("Samba settings"),
1514           "plSelfModify"    => TRUE,
1515           "plDepends"       => array("user"),
1516           "plPriority"      => 5,
1517           "plSection"     => array("personal" => _("My account")),
1518           "plCategory"    => array("users"),
1519           "plOptions"       => array(),
1521           "plProvidedAcls"  => array(
1523             "sambaHomePath"               => _("Generic home directory") ,
1524             "sambaHomeDrive"              => _("Generic samba home drive") ,
1525             "sambaDomainName"             => _("Domain") ,
1526             "sambaLogonScript"            => _("Generic script path") ,
1527             "sambaProfilePath"            => _("Generic profile path") ,
1528             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1529             "InheritClientConfig"         => _("Inherit client config"),
1530             "sambaPwdCanChange"           => _("Allow user to change password") ,
1531             "sambaAcctFlagsN"             => _("Login from windows client requires no password"),
1532             "sambaAcctFlagsL"             => _("Lock samba account"),
1533             "sambaKickoffTime"            => _("Account expires") ,
1534             "sambaPwdMustChange"          => _("Password expires") ,
1535             "sambaLogonTime"              => _("Limit Logon Time") ,
1536             "sambaLogoffTime"             => _("Limit Logoff Time") ,
1537             "sambaLogonHours"             => _("Logon hours") ,
1538             "sambaUserWorkstations"       => _("Allow connection from"))
1539           ));
1540   }    
1542   function enable_multiple_support()
1543   {
1544     plugin::enable_multiple_support();
1545     if($this->samba3){
1546       $this->multiple_support_active = TRUE;
1547     }else{
1548       $this->multiple_support_active = FALSE;
1549     }
1550   } 
1552   function multiple_save_object()
1553   {
1554     if (isset($_POST['sambaTab'])){
1555       $this->save_object();
1556       plugin::multiple_save_object();
1557       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1558             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1559             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1560             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1561             "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1562             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1563             "workstation_list") as $attr){
1564         if(isset($_POST["use_".$attr])){
1565           $this->multi_boxes[] = $attr;
1566         }
1567       }
1568     }
1569   }
1572   function multiple_check()
1573   {
1574     $message = plugin::multiple_check();
1576     /* Strings */
1577     foreach (array( "sambaHomePath" => _("Home directory"),
1578           "sambaProfilePath" => _("Profile path")) as $key => $val){
1579       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1580         $message[]= msgPool::invalid($val);
1581       }
1582     }
1584     /* Numeric values */
1585     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1586                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1587                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1588       if (in_array($key,$this->multi_boxes) && 
1589           isset($this->mungedObject->ctx[$key]) && 
1590           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1591         $message[]=msgPool::invalid($val);
1592       }
1593     }
1595     /* Too many workstations? Windows usrmgr only supports eight */
1596     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1597       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1598     }
1599     return($message);
1600   }
1602   
1603   function get_multi_init_values()
1604   {
1605     $ret = plugin::get_multi_init_values();
1607     /* Parse given sambaUserWorkstations into array
1608      *  to allow "init_multiple_support()" to detect multiple used workstations.
1609      *  Those workstations will be displayed in light grey.
1610      */
1611     $tmp2 = array("count" => 0);
1612     $tmp = split(",", $this->sambaUserWorkstations);
1613     foreach($tmp as $station){
1614       $station = trim($station);
1615       if(!empty($station)){
1616         $tmp2[] = $station;
1617         $tmp2['count'] ++;
1618       }
1619     } 
1620     $ret['sambaUserWorkstations'] = $tmp2;
1621     return($ret);
1622   }
1626   function init_multiple_support($attrs,$all)
1627   {
1628     plugin::init_multiple_support($attrs,$all);
1630     $this->multiple_sambaUserWorkstations = array();
1631     if(isset($all['sambaUserWorkstations'])){
1632       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1633         $station = trim($all['sambaUserWorkstations'][$i]);
1634         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1635       }
1636     }
1637     if(isset($attrs['sambaUserWorkstations'])){
1638       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1639         $station = trim($attrs['sambaUserWorkstations'][$i]);
1640         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1641       }
1642     }
1643   }
1645   function multiple_execute()
1646   {
1647     return($this->execute());
1648   } 
1650   function get_multi_edit_values()
1651   {
1652     $ret = plugin::get_multi_edit_values();
1654     /* Terminal Server  */
1655     if(in_array("tslogin",$this->multi_boxes)){
1656       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1657     }
1658     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1659       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1660     }
1661     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1662       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1663     }
1664     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1665       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1666     }
1668     if(in_array("inherit",$this->multi_boxes)){
1669       $ret['inherit'] = $this->mungedObject->getInheritMode();
1670     }       
1671     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1672       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1673     } 
1674     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1675       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1676     } 
1678     /* Time Limits. Be careful here, there are some negations  */
1679     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1680       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1681       if(!$ret["CtxMaxConnectionTimeF"]){
1682         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1683       }
1684     }
1685     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1686       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1687       if(!$ret["CtxMaxDisconnectionTimeF"]){
1688         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1689       }
1690     }
1691     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1692       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1693       if(!$ret["CtxMaxIdleTimeF"]){
1694         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1695       }
1696     }
1698     /* Client Devices */
1699     if(in_array("connectclientdrives",$this->multi_boxes)){
1700       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1701     }
1702     if(in_array("connectclientprinters",$this->multi_boxes)){
1703       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1704     }
1705     if(in_array("defaultprinter",$this->multi_boxes)){
1706       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1707     }
1709     /* Misc */
1710     if(in_array("shadow",$this->multi_boxes)){
1711       $ret["shadow"]    =$this->mungedObject->getShadow();
1712     }
1713     if(in_array("brokenconn",$this->multi_boxes)){
1714       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1715     }
1716     if(in_array("reconn",$this->multi_boxes)){
1717       $ret["reconn"]    =$this->mungedObject->getReConn();
1718     }
1720     /* Flags */
1721     if(in_array("allow_pwchange",$this->multi_boxes)){
1722       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1723       $ret['pwdCanChange']      = $this->pwdCanChange;
1724     }
1725   
1726     if(in_array("password_expires",$this->multi_boxes)){
1727       $ret['password_expires']  = $this->password_expires;
1728       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1729     }
1730     if(in_array("logon_time_set",$this->multi_boxes)){
1731       $ret['logon_time_set'] = $this->logon_time_set;
1732       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1733     }
1734     if(in_array("logoff_time_set",$this->multi_boxes)){
1735       $ret['logoff_time_set'] = $this->logoff_time_set;
1736       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1737     }
1738     if(in_array("kickoff_time_set",$this->multi_boxes)){
1739       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1740       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1741     }
1743     if(in_array("no_password_required",$this->multi_boxes)){
1744       $ret['no_password_required'] = $this->no_password_required;
1745     }
1747     if(in_array("temporary_disable",$this->multi_boxes)){
1748       $ret['temporary_disable'] = $this->temporary_disable;
1749     }
1750     
1751     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1752       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1753     }
1755     if(in_array("workstation_list",$this->multi_boxes)){
1756       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1757     }
1758     return($ret);
1759   }
1761   function set_multi_edit_values($values)
1762   {
1763     plugin::set_multi_edit_values($values);
1765     /* Prepare current workstation settings to be merged 
1766      *  with multiple edit settings.
1767      */
1768     if(isset($values['multiple_sambaUserWorkstations'])){
1769       $cur_ws = array();
1770       $m_ws = $values['multiple_sambaUserWorkstations'];
1772       /* Prepare current settings to be merged */
1773       if(isset($this->sambaUserWorkstations)){
1774         $ttmp = split(",",$this->sambaUserWorkstations);
1775         foreach($ttmp as $station){
1776           $station = trim($station);
1777           if(!empty($station)){
1778             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1779           }
1780         }
1781       }
1783       /* Unset removed workstations */
1784       foreach($cur_ws as $cur_name => $cur_station){
1785         if(!isset($m_ws[$cur_name])){
1786           unset($cur_ws[$cur_name]);
1787         }
1788       }
1790       /* Add all added workstations */
1791       foreach($m_ws as $name => $station){
1792         if($station['UsedByAllUsers']){
1793           $cur_ws[$name] = $station;
1794         }
1795       }
1797       $this->sambaUserWorkstations = "";
1798       foreach($cur_ws as $name => $ws){
1799         $this->sambaUserWorkstations .= $name.",";
1800       }
1801       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1802     }
1804     /* Enable disabled terminal login, this is inverted somehow */
1805     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1806   
1807     /* Imherit client configuration */
1808     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1809   
1810     /* Get all ctx values posted */
1811     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1812                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1813     foreach($ctx as $attr){
1814       if(isset($values[$attr])){
1815         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1816       }
1817     }
1819     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1820     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1821     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1823     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1824     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1825     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1827     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1828     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1829     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1831   
1832     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1833     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1835     
1836     
1838     if(isset($values['password_expires'])){
1839       $this->password_expires = $values['password_expires'];
1840       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1841     }
1842     if(isset($values['logon_time_set'])){
1843       $this->logon_time_set = $values['logon_time_set'];
1844       $this->sambaLogonTime = $values['sambaLogonTime'];
1845     }
1846     if(isset($values['logoff_time_set'])){
1847       $this->logoff_time_set = $values['logoff_time_set'];
1848       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1849     }
1850     if(isset($values['kickoff_time_set'])){
1851       $this->kickoff_time_set = $values['kickoff_time_set'];
1852       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1853     }
1855     if(isset($values['no_password_required'])){
1856       if($values['no_password_required']){
1857         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1858           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1859         }
1860       }else{
1861         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1862       }
1863     }      
1865     if(isset($values['temporary_disable'])){
1866       if($values['temporary_disable']){
1867         if(preg_match("/L/",$this->sambaAcctFlags)) {
1868           // Keep L
1869         }else{
1870           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1871         }
1872       }else{
1873         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1874       }
1875     }
1876   }
1879   function PrepareForCopyPaste($source)
1880   {
1881     plugin::PrepareForCopyPaste($source);
1883     /* Set a new SID */
1884     $this->sambaSID = "";
1885   }
1889 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1890 ?>