Code

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