Code

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