Code

Updated samba tab
[gosa.git] / gosa-plugins / samba / personal / samba / class_sambaAccount.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2004-2005 Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 class sambaAccount extends plugin
22 {
23   /* Definitions */
24   var $plHeadline= "Samba";
25   var $plDescription= "This does something";
26   var $view_logged = FALSE;
28   /* Switch for Samba version */
29   var $samba3= FALSE;
30   var $uidNumber= 65535;
31   var $gidNumber= 65535;
33   /* Samba 3 infos */
34   var $display_information = FALSE;
36   /* Samba 2 attributes */
37   var $pwdLastSet= "0";
38   var $logonTime= "0";
39   var $logoffTime= "2147483647";
40   var $kickoffTime= "2147483647";
41   var $pwdCanChange= "0";
42   var $pwdMustChange= "0";
43   var $password_expires= 0;
44   var $acctFlags= "[UX        ]";
45   var $smbHome= "";
46   var $homeDrive= "";
47   var $scriptPath= "";
48   var $profilePath= "";
49   var $rid= "";
50   var $primaryGroupID= "";
52   /* Samba 3 attributes */
53   var $SID= "";
54   var $ridBase= 0;
55   var $sambaSID= "";
56   var $sambaPwdLastSet= "0";
57   var $sambaLogonTime= "0";
58   var $sambaLogoffTime= "2147483647";
59   var $sambaKickoffTime= "2147483647";
60   var $sambaPwdCanChange= "";
61   var $sambaPwdMustChange= "0";
62   var $sambaAcctFlags= "[UX        ]";
63   var $sambaHomePath= "";
64   var $sambaHomeDrive= "";
65   var $sambaLogonScript= "";
66   var $sambaProfilePath= "";
67   var $sambaPrimaryGroupSID= "";
68   var $sambaDomainName= "";
69   var $sambaUserWorkstations= "";
70   var $sambaBadPasswordCount= "";
71   var $sambaBadPasswordTime= "";
72   var $sambaPasswordHistory= "";
73   var $sambaLogonHours= "";
74   var $orig_sambaDomainName= "";
75   var $sambaMungedDial= "";
76   var $mungedObject;
78   /* Helper */
79   var $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%;'><tr><td style='width:50%; border-right: solid 1px #B0B0B0;'>".
981       "\n<table>".
982       "\n<tr><td><b>"._("Domain attributes")."</b></td></tr>". 
983       "\n<tr><td>"._("Min password length").":           </td><td>".$sambaMinPwdLength."</td></tr>". 
984       "\n<tr><td>"._("Min password length").":           </td><td>".$sambaMinPwdLength."</td></tr>". 
985       "\n<tr><td>"._("Password history").":              </td><td>".$sambaPwdHistoryLength."</td></tr>".
986       "\n<tr><td>"._("Force password change").":         </td><td>".$sambaLogonToChgPwd."</td></tr>".
987       "\n<tr><td>"._("Maximum password age").":          </td><td>".$sambaMaxPwdAge."</td></tr>".
988       "\n<tr><td>"._("Minimum password age").":          </td><td>".$sambaMinPwdAge."</td></tr>".
989       "\n<tr><td>"._("Lockout duration").":              </td><td>".$sambaLockoutDuration."</td></tr>".
990       "\n<tr><td>"._("Bad lockout attempt").":           </td><td>".$sambaLockoutThreshold."</td></tr>".
991       "\n<tr><td>"._("Disconnect time").":               </td><td>".$sambaForceLogoff."</td></tr>".
992       "\n<tr><td>"._("Refuse machine password change").":</td><td>".$sambaRefuseMachinePwdChange."</td></tr>".
993       "\n</table></td><td style='vertical-align: top;'><table>".
994       "\n<tr><td><b>"._("User attributes")."</b></td></tr>". 
995       "\n<tr><td>"._("Last failed login").":             </td><td>".$sambaBadPasswordTime."</td></tr>".
996       "\n<tr><td>"._("Logon attempts").":                </td><td>".$sambaBadPasswordCount."</td></tr>".
997       "\n<tr><td>"._("Last password update").":          </td><td>".$sambaPwdLastSet."</td></tr>".
998       "\n<tr><td>"._("Last logon").":                    </td><td>".$sambaLogonTime."</td></tr>".
999       "\n<tr><td>"._("Last logoff").":                   </td><td>".$sambaLogoffTime."</td></tr>".
1000       "\n<tr><td>"._("Automatic logoff").":              </td><td>".$sambaKickoffTime."</td></tr>".
1001       "\n<tr><td>"._("Password expires").":              </td><td>".$sambaPwdMustChange."</td></tr>".
1002       "\n<tr><td>"._("Password change available").":     </td><td>".$sambaPwdCanChange."</td></tr>".
1003       "\n</table></td></tr></table>";
1004     return($str);
1005   }
1008   function remove_from_parent()
1009   {
1010     /* Cancel if there's nothing to do here */
1011    if (!$this->initially_was_account){
1012      return;
1013    }
1014     
1015     /* include global link_info */
1016     $ldap= $this->config->get_ldap_link();
1018     plugin::remove_from_parent();
1020     /* Keep uid attribute for gosaAccount */
1021     unset($this->attrs['uid']);
1022     unset($this->attrs['uidNumber']);
1023     unset($this->attrs['gidNumber']);
1025     /* Remove objectClass for sambaIdmapEntry */
1026     $tmp= array();
1027     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1028       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1029         $tmp[]= $this->attrs['objectClass'][$i];
1030       }
1031     }
1032     $this->attrs['objectClass']= $tmp;
1034     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1035         $this->attributes, "Save");
1036     $ldap->cd($this->dn);
1037     $this->cleanup();
1038     $ldap->modify ($this->attrs); 
1040     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1042     if (!$ldap->success()){
1043       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
1044     }
1046     /* Optionally execute a command after we're done */
1047     $this->handle_post_events("remove", array("uid" => $this->uid));
1048   }
1051   /* Check for input problems */
1052   function check()
1053   {
1054     /* Call common method to give check the hook */
1055     $message= plugin::check();
1057     if ($this->samba3){
1059       /* sambaHomePath requires sambaHomeDrive and vice versa */
1060       if(!empty($this->sambaHomePath) && empty($this->sambaHomeDrive)){
1061         $message[]= msgPool::required(_("Home drive"));
1062       }
1063       if(!empty($this->sambaHomeDrive) && empty($this->sambaHomePath)){
1064         $message[]= msgPool::required(_("Home path"));
1065       }
1067       /* Strings */
1068       foreach (array( "sambaHomePath" => _("Home directory"),
1069             "sambaProfilePath" => _("Profile path")) as $key => $val){
1070         if (!$this->mungedObject->is_samba_path($this->$key)){
1071           $message[]= msgPool::invalid($val);
1072         }
1073       }
1075       /* Numeric values */
1076       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
1077             "CtxMaxDisconnectionTime" => _("Disconnection"),
1078             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
1080         if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1081           $message[]= msgPool::invalid($val);
1082         }
1083       }
1085       /* Too many workstations? Windows usrmgr only supports eight */
1086       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1087         $message[]= _("The windows usermanager allows eight clients at maximum!");
1088       }
1089     }
1091     return ($message);
1092   }
1095   /* Save data to object */
1096   function save_object()
1097   {
1099     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
1101     /* We only care if we are on the sambaTab... */
1102     if (isset($_POST['sambaTab'])){
1103       plugin::save_object();
1105       if(isset($_POST['display_information'])){
1106         $this->display_information = !$this->display_information;
1107       }
1109       /* Take care about access options */
1110       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1111         if ($this->samba3){
1112           $attrname= "sambaPwdCanChange";
1113         } else {
1114           $attrname= "pwdCanChange";
1115         }
1116         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
1117           $tmp= 1;
1118         } else {
1119           $tmp= 0;
1120         }
1121         if ($this->$attrname != $tmp){
1122           $this->is_modified= TRUE;
1123         }
1124         $this->pwdCanChange= $tmp;
1125         $this->sambaPwdCanChange= $tmp;
1126       }
1127       $tmp= "UX";
1128       $this->no_password_required = FALSE;
1129       if (isset($_POST["no_password_required"])){
1130         if ($_POST["no_password_required"] == 1){
1131           $tmp.= "N";
1132           $this->no_password_required = TRUE;
1133         }
1134       }
1135       if (isset($_POST["password_expires"])){
1136         if ($_POST["password_expires"] == 1){
1137           $this->password_expires= 1;
1138         }
1139       } else {
1140         $this->password_expires= 0;
1141       }
1142       $this->temporary_disable = FALSE;
1143       if (isset($_POST["temporary_disable"])){
1144         if ($_POST["temporary_disable"] == 1){
1145           $this->temporary_disable = TRUE;
1146           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
1147             $tmp.= "L";
1148           } else {
1149             $tmp.= "D";
1150           }
1151         }
1152       }
1153       if (isset($_POST["logon_time_set"])){
1154         if ($_POST["logon_time_set"] == 1){
1155           $this->logon_time_set= 1;
1156         }
1157       } else {
1158         $this->logon_time_set= 0;
1159       }
1160       if (isset($_POST["logoff_time_set"])){
1161         if ($_POST["logoff_time_set"] == 1){
1162           $this->logoff_time_set= 1;
1163         }
1164       } else {
1165         $this->logoff_time_set= 0;
1166       }
1167       if (isset($_POST["kickoff_time_set"])){
1168         if ($_POST["kickoff_time_set"] == 1){
1169           $this->kickoff_time_set= 1;
1170         }
1171       } else {
1172         $this->kickoff_time_set= 0;
1173       }
1174       
1175       $fill= "";
1176       for ($i= strlen($tmp); $i<12; $i++){
1177         $fill.= " ";
1178       }
1180       $tmp= "[$tmp$fill]";
1182       /* Only save if acl's are set */
1183       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1184         if ($this->samba3){
1185           $attrname= "sambaAcctFlags";
1186         } else {
1187           $attrname= "acctFlags";
1188         }
1189         if ($this->$attrname != $tmp){
1190           $this->is_modified= TRUE;
1191         }
1192         $this->$attrname= $tmp;
1193       }
1195       /* Save sambaDomain attribute */
1196       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
1197         $this->sambaDomainName= validate($_POST['sambaDomainName']);
1198       }
1200       /* Save CTX values */
1201       if ($this->samba3){
1203         /* Save obvious values */
1204         foreach($this->ctxattributes as $val){
1205           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
1206             if (get_magic_quotes_gpc()) {
1207               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
1208             } else {
1209               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
1210             }
1211           }
1212         }
1214         /* Save checkbox states. */
1215         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
1216                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1217         // Need to do some index checking to avoid messages like "index ... not found"
1218         if(isset($_POST['brokenconn'])) {
1219           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
1220                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1221         }
1222         if(isset($_POST['reconn'])) {
1223           $this->mungedObject->setReConn($_POST['reconn'] == '1'
1224                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1225         }
1226         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
1227                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1228         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
1229                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1230         $this->mungedObject->setCtxMaxDisconnectionTimeF(
1231                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
1232                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1233         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
1234                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1235         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
1236                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1237         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
1238                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1239         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
1240                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1242         /* Save combo boxes. Takes two values */
1243         if(isset($_POST['reconn'])) {
1244           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
1245         }
1247         /* Check for changes */
1248         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
1249           $this->is_modified= TRUE;
1250         }
1251       }
1252     }
1253   }
1256   /* Save to LDAP */
1257   function save()
1258   {
1259     /* Load uid and gid of this 'dn' */
1260     $ldap= $this->config->get_ldap_link();
1261     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
1262     $tmp= $ldap->fetch();
1263     $this->uidNumber= $tmp['uidNumber'][0];
1264     $this->gidNumber= $tmp['gidNumber'][0];
1266     plugin::save();
1268     /* Remove objectClass for sambaIdmapEntry */
1269     $tmp= array();
1270     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1271       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1272         $tmp[]= $this->attrs['objectClass'][$i];
1273       }
1274     }
1275     $this->attrs['objectClass']= $tmp;
1277     /* Generate rid / primaryGroupId */
1278     if ($this->samba3){
1279       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
1280         msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
1281       } else {
1282         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
1283         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
1284       }
1286       /* Need to generate a new uniqe uid/gid combination? */
1287       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
1288         $uidNumber= $this->uidNumber;
1289         while(TRUE){
1290           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
1291           $ldap->cd($this->config->current['BASE']);
1292           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
1293           if ($ldap->count() == 0){
1294             break;
1295           }
1296           $uidNumber++;
1297         }
1298         $this->attrs['sambaSID']= $sid;
1300         /* Check for users primary group */
1301         $ldap->cd($this->config->current['BASE']);
1302         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
1303         if ($ldap->count() != 1){
1304           msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
1305         } else {
1306           $attrs= $ldap->fetch();
1307           $g= new group($this->config, $ldap->getDN());
1308           if ($g->sambaSID == ""){
1309             $g->sambaDomainName= $this->sambaDomainName;
1310             $g->smbgroup= TRUE;
1311             $g->save ();
1312           }
1313           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
1314         }
1315       }
1317       if ($this->sambaHomeDrive == ""){
1318         $this->attrs["sambaHomeDrive"]= array();
1319       }
1321       /* Generate munged dial value */
1322       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1324       /* User wants me to fake the idMappings? This is useful for
1325          making winbind resolve the user names in a reasonable amount
1326          of time in combination with larger databases. */
1327       if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1328         $this->attrs['objectClass'][]= "sambaIdmapEntry";
1329       }
1332       /* Password expiery */
1333       if ($this->password_expires == "1"){
1334         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1335       } else {
1336         $this->attrs['sambaPwdMustChange']= array();
1337       }
1338       /* Make sure not to save zero in sambaPwdLastset */
1339       if ($this->sambaPwdLastSet != "0"){
1340         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1341       } else {
1342         $this->attrs['sambaPwdLastSet']= array();
1343       }
1344       /* Account expiery */
1345       if ($this->logon_time_set == "1"){
1346         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1347       } else {
1348         $this->attrs['sambaLogonTime']= array();
1349       }
1350       if ($this->logoff_time_set == "1"){
1351         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1352       } else {
1353         $this->attrs['sambaLogoffTime']= array();
1354       }
1355       if ($this->kickoff_time_set == "1"){
1356         # Add one day in unixtime format to be compatible with usrmgr
1357         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1358         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1359       } else {
1360         $this->attrs['sambaKickoffTime']= array();
1361       }
1362     } else {
1363     /* Not samba3 */
1364       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1365       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1367       if ($this->homeDrive == ""){
1368         $this->attrs["homeDrive"]= array();
1369       }
1371       /* Password expiery */
1372       if ($this->password_expires == "1"){
1373         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1374       } else {
1375         $this->attrs['pwdMustChange']= 2147483647;
1376       }
1377       /* Make sure not to save zero in pwdLastset */
1378       if ($this->pwdLastSet != "0"){
1379         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1380       } else {
1381         $this->attrs['pwdLastSet']= array();
1382       }
1383       /* Account expiery */
1384       if ($this->logon_time_set == "1"){
1385         $this->attrs['logonTime']= $this->logonTime;
1386       } else {
1387         $this->attrs['logonTime']= array();
1388       }
1389       if ($this->logoff_time_set == "1"){
1390         $this->attrs['logoffTime']= $this->logoffTime;
1391       } else {
1392         $this->attrs['logoffTime']= array();
1393       }
1394       if ($this->kickoff_time_set == "1"){
1395         # Add one day in unixtime format to be compatible with usrmgr
1396         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1397       } else {
1398         $this->attrs['kickoffTime']= array();
1399       }
1400     }
1402     /* Write back to ldap */
1403     $ldap->cd($this->dn);
1404     $this->cleanup();
1405     $ldap->modify ($this->attrs); 
1407     if($this->initially_was_account){
1408       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1409     }else{
1410       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1411     }
1413     if (!$ldap->success()){
1414       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1415     }
1417     /* Optionally execute a command after we're done */
1418     if ($this->initially_was_account == $this->is_account){
1419       if ($this->is_modified){
1420         $this->handle_post_events("modify", array("uid" => $this->uid));
1421       }
1422     } else {
1423       $this->handle_post_events("add", array("uid" => $this->uid));
1424     }
1425   }
1428   /* Force password set, if this account doesn't have any samba passwords  */
1429   function password_change_needed()
1430   {
1431     if(!$this->initially_was_account && $this->is_account){
1432       $ldap = $this->config->get_ldap_link();
1433       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1434       $attrs = $ldap->fetch();
1435       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1436         return(TRUE);
1437       }
1438     }
1439     return(FALSE);
1440   }
1443   function adapt_from_template($dn, $skip= array())
1444   {
1445     plugin::adapt_from_template($dn, $skip);
1448     $this->sambaSID= "";
1449     $this->sambaPrimaryGroupSID= "";
1451     /* Fill mungedDial field */
1452     if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1453       $this->mungedObject->load($this->sambaMungedDial);
1454     }
1456     /* Adapt munged attributes */
1457     foreach($this->ctxattributes as $attr){
1458       if(isset($this->mungedObject->ctx[$attr]))
1459         $val = $this->mungedObject->ctx[$attr];
1461       foreach (array("sn", "givenName", "uid") as $repl){
1462         if (preg_match("/%$repl/i", $val)){
1463           $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1464         }
1465       }
1466       $this->mungedObject->ctx[$attr] = $val;
1467     }
1469     /* Password expiery */
1470     if(isset($this->attrs['sambaPwdMustChange']) &&
1471         $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1472       $this->password_expires= 1;
1473     }
1475     if(isset($this->attrs['sambaLogonTime']) && ! (
1476         $this->attrs['sambaLogonTime'][0] == 0 ||
1477         $this->attrs['sambaLogonTime'][0] == 2147483647
1478       ) && !in_array('sambaLogonTime', $skip)){
1479       $this->logon_time_set= 1;
1480     }
1481     if(isset($this->attrs['sambaLogoffTime']) && ! (
1482         $this->attrs['sambaLogoffTime'][0] == 0 ||
1483         $this->attrs['sambaLogoffTime'][0] == 2147483647
1484       ) && !in_array('sambaLogonTime', $skip)){
1485       $this->logoff_time_set= 1;
1486     }
1488     /* Account expiery */
1489     if(isset($this->attrs['sambaKickoffTime']) && ! (
1490         $this->attrs['sambaKickoffTime'][0] == 0 ||
1491         $this->attrs['sambaKickoffTime'][0] == 2147483647
1492       ) && !in_array('sambaKickoffTime', $skip)){
1493       $this->kickoff_time_set= 1;
1494     }
1496     /* Get global filter config */
1497     if (!session::is_set("sambafilter")){
1498       $ui= get_userinfo();
1499       $base= get_base_from_people($ui->dn);
1500       $sambafilter= array( "depselect" => $base, "regex" => "*");
1501       session::set("sambafilter", $sambafilter);
1502     }
1503   }
1505   
1506   static function plInfo()
1507   {
1508     return (array(
1509           "plShortName"     => _("Samba"),
1510           "plDescription"   => _("Samba settings"),
1511           "plSelfModify"    => TRUE,
1512           "plDepends"       => array("user"),
1513           "plPriority"      => 5,
1514           "plSection"     => array("personal" => _("My account")),
1515           "plCategory"    => array("users"),
1516           "plOptions"       => array(),
1518           "plProvidedAcls"  => array(
1520             "sambaHomePath"               => _("Generic home directory") ,
1521             "sambaHomeDrive"              => _("Generic samba home drive") ,
1522             "sambaDomainName"             => _("Domain") ,
1523             "sambaLogonScript"            => _("Generic script path") ,
1524             "sambaProfilePath"            => _("Generic profile path") ,
1525             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1526             "InheritClientConfig"         => _("Inherit client config"),
1527             "sambaPwdCanChange"           => _("Allow user to change password") ,
1528             "sambaAcctFlagsN"             => _("Login from windows client requires no password"),
1529             "sambaAcctFlagsL"             => _("Lock samba account"),
1530             "sambaKickoffTime"            => _("Account expires") ,
1531             "sambaPwdMustChange"          => _("Password expires") ,
1532             "sambaLogonTime"              => _("Limit Logon Time") ,
1533             "sambaLogoffTime"             => _("Limit Logoff Time") ,
1534             "sambaLogonHours"             => _("Logon hours") ,
1535             "sambaUserWorkstations"       => _("Allow connection from"))
1536           ));
1537   }    
1539   function enable_multiple_support()
1540   {
1541     plugin::enable_multiple_support();
1542     if($this->samba3){
1543       $this->multiple_support_active = TRUE;
1544     }else{
1545       $this->multiple_support_active = FALSE;
1546     }
1547   } 
1549   function multiple_save_object()
1550   {
1551     if (isset($_POST['sambaTab'])){
1552       $this->save_object();
1553       plugin::multiple_save_object();
1554       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1555             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1556             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1557             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1558             "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1559             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1560             "workstation_list") as $attr){
1561         if(isset($_POST["use_".$attr])){
1562           $this->multi_boxes[] = $attr;
1563         }
1564       }
1565     }
1566   }
1569   function multiple_check()
1570   {
1571     $message = plugin::multiple_check();
1573     /* Strings */
1574     foreach (array( "sambaHomePath" => _("Home directory"),
1575           "sambaProfilePath" => _("Profile path")) as $key => $val){
1576       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1577         $message[]= msgPool::invalid($val);
1578       }
1579     }
1581     /* Numeric values */
1582     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1583                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1584                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1585       if (in_array($key,$this->multi_boxes) && 
1586           isset($this->mungedObject->ctx[$key]) && 
1587           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1588         $message[]=msgPool::invalid($val);
1589       }
1590     }
1592     /* Too many workstations? Windows usrmgr only supports eight */
1593     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1594       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1595     }
1596     return($message);
1597   }
1599   
1600   function get_multi_init_values()
1601   {
1602     $ret = plugin::get_multi_init_values();
1604     /* Parse given sambaUserWorkstations into array
1605      *  to allow "init_multiple_support()" to detect multiple used workstations.
1606      *  Those workstations will be displayed in light grey.
1607      */
1608     $tmp2 = array("count" => 0);
1609     $tmp = split(",", $this->sambaUserWorkstations);
1610     foreach($tmp as $station){
1611       $station = trim($station);
1612       if(!empty($station)){
1613         $tmp2[] = $station;
1614         $tmp2['count'] ++;
1615       }
1616     } 
1617     $ret['sambaUserWorkstations'] = $tmp2;
1618     return($ret);
1619   }
1623   function init_multiple_support($attrs,$all)
1624   {
1625     plugin::init_multiple_support($attrs,$all);
1627     $this->multiple_sambaUserWorkstations = array();
1628     if(isset($all['sambaUserWorkstations'])){
1629       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1630         $station = trim($all['sambaUserWorkstations'][$i]);
1631         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1632       }
1633     }
1634     if(isset($attrs['sambaUserWorkstations'])){
1635       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1636         $station = trim($attrs['sambaUserWorkstations'][$i]);
1637         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1638       }
1639     }
1640   }
1642   function multiple_execute()
1643   {
1644     return($this->execute());
1645   } 
1647   function get_multi_edit_values()
1648   {
1649     $ret = plugin::get_multi_edit_values();
1651     /* Terminal Server  */
1652     if(in_array("tslogin",$this->multi_boxes)){
1653       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1654     }
1655     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1656       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1657     }
1658     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1659       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1660     }
1661     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1662       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1663     }
1665     if(in_array("inherit",$this->multi_boxes)){
1666       $ret['inherit'] = $this->mungedObject->getInheritMode();
1667     }       
1668     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1669       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1670     } 
1671     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1672       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1673     } 
1675     /* Time Limits. Be careful here, there are some negations  */
1676     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1677       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1678       if(!$ret["CtxMaxConnectionTimeF"]){
1679         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1680       }
1681     }
1682     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1683       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1684       if(!$ret["CtxMaxDisconnectionTimeF"]){
1685         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1686       }
1687     }
1688     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1689       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1690       if(!$ret["CtxMaxIdleTimeF"]){
1691         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1692       }
1693     }
1695     /* Client Devices */
1696     if(in_array("connectclientdrives",$this->multi_boxes)){
1697       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1698     }
1699     if(in_array("connectclientprinters",$this->multi_boxes)){
1700       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1701     }
1702     if(in_array("defaultprinter",$this->multi_boxes)){
1703       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1704     }
1706     /* Misc */
1707     if(in_array("shadow",$this->multi_boxes)){
1708       $ret["shadow"]    =$this->mungedObject->getShadow();
1709     }
1710     if(in_array("brokenconn",$this->multi_boxes)){
1711       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1712     }
1713     if(in_array("reconn",$this->multi_boxes)){
1714       $ret["reconn"]    =$this->mungedObject->getReConn();
1715     }
1717     /* Flags */
1718     if(in_array("allow_pwchange",$this->multi_boxes)){
1719       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1720       $ret['pwdCanChange']      = $this->pwdCanChange;
1721     }
1722   
1723     if(in_array("password_expires",$this->multi_boxes)){
1724       $ret['password_expires']  = $this->password_expires;
1725       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1726     }
1727     if(in_array("logon_time_set",$this->multi_boxes)){
1728       $ret['logon_time_set'] = $this->logon_time_set;
1729       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1730     }
1731     if(in_array("logoff_time_set",$this->multi_boxes)){
1732       $ret['logoff_time_set'] = $this->logoff_time_set;
1733       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1734     }
1735     if(in_array("kickoff_time_set",$this->multi_boxes)){
1736       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1737       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1738     }
1740     if(in_array("no_password_required",$this->multi_boxes)){
1741       $ret['no_password_required'] = $this->no_password_required;
1742     }
1744     if(in_array("temporary_disable",$this->multi_boxes)){
1745       $ret['temporary_disable'] = $this->temporary_disable;
1746     }
1747     
1748     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1749       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1750     }
1752     if(in_array("workstation_list",$this->multi_boxes)){
1753       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1754     }
1755     return($ret);
1756   }
1758   function set_multi_edit_values($values)
1759   {
1760     plugin::set_multi_edit_values($values);
1762     /* Prepare current workstation settings to be merged 
1763      *  with multiple edit settings.
1764      */
1765     if(isset($values['multiple_sambaUserWorkstations'])){
1766       $cur_ws = array();
1767       $m_ws = $values['multiple_sambaUserWorkstations'];
1769       /* Prepare current settings to be merged */
1770       if(isset($this->sambaUserWorkstations)){
1771         $ttmp = split(",",$this->sambaUserWorkstations);
1772         foreach($ttmp as $station){
1773           $station = trim($station);
1774           if(!empty($station)){
1775             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1776           }
1777         }
1778       }
1780       /* Unset removed workstations */
1781       foreach($cur_ws as $cur_name => $cur_station){
1782         if(!isset($m_ws[$cur_name])){
1783           unset($cur_ws[$cur_name]);
1784         }
1785       }
1787       /* Add all added workstations */
1788       foreach($m_ws as $name => $station){
1789         if($station['UsedByAllUsers']){
1790           $cur_ws[$name] = $station;
1791         }
1792       }
1794       $this->sambaUserWorkstations = "";
1795       foreach($cur_ws as $name => $ws){
1796         $this->sambaUserWorkstations .= $name.",";
1797       }
1798       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1799     }
1801     /* Enable disabled terminal login, this is inverted somehow */
1802     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1803   
1804     /* Imherit client configuration */
1805     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1806   
1807     /* Get all ctx values posted */
1808     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1809                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1810     foreach($ctx as $attr){
1811       if(isset($values[$attr])){
1812         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1813       }
1814     }
1816     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1817     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1818     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1820     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1821     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1822     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1824     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1825     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1826     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1828   
1829     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1830     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1832     
1833     
1835     if(isset($values['password_expires'])){
1836       $this->password_expires = $values['password_expires'];
1837       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1838     }
1839     if(isset($values['logon_time_set'])){
1840       $this->logon_time_set = $values['logon_time_set'];
1841       $this->sambaLogonTime = $values['sambaLogonTime'];
1842     }
1843     if(isset($values['logoff_time_set'])){
1844       $this->logoff_time_set = $values['logoff_time_set'];
1845       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1846     }
1847     if(isset($values['kickoff_time_set'])){
1848       $this->kickoff_time_set = $values['kickoff_time_set'];
1849       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1850     }
1852     if(isset($values['no_password_required'])){
1853       if($values['no_password_required']){
1854         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1855           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1856         }
1857       }else{
1858         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1859       }
1860     }      
1862     if(isset($values['temporary_disable'])){
1863       if($values['temporary_disable']){
1864         if(preg_match("/L/",$this->sambaAcctFlags)) {
1865           // Keep L
1866         }else{
1867           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1868         }
1869       }else{
1870         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1871       }
1872     }
1873   }
1876   function PrepareForCopyPaste($source)
1877   {
1878     plugin::PrepareForCopyPaste($source);
1880     /* Set a new SID */
1881     $this->sambaSID = "";
1882   }
1886 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1887 ?>