Code

Re-added sambaAcctFlag X - Which tells us the password never expires.
[gosa.git] / gosa-plugins / samba / personal / samba / class_sambaAccount.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2004-2005 Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 class sambaAccount extends plugin
22 {
23   /* Definitions */
24   var $plHeadline= "Samba";
25   var $plDescription= "This does something";
26   var $view_logged = FALSE;
28   /* Switch for Samba version */
29   var $samba3= FALSE;
30   var $uidNumber= 65535;
31   var $gidNumber= 65535;
33   /* Samba 2 attributes */
34   var $pwdLastSet= "0";
35   var $logonTime= "0";
36   var $logoffTime= "2147483647";
37   var $kickoffTime= "2147483647";
38   var $pwdCanChange= "0";
39   var $pwdMustChange= "0";
40   var $password_expires= 0;
41   var $acctFlags= "[UX        ]";
42   var $smbHome= "";
43   var $homeDrive= "";
44   var $scriptPath= "";
45   var $profilePath= "";
46   var $rid= "";
47   var $primaryGroupID= "";
49   /* Samba 3 attributes */
50   var $SID= "";
51   var $ridBase= 0;
52   var $sambaSID= "";
53   var $sambaPwdLastSet= "0";
54   var $sambaLogonTime= "0";
55   var $sambaLogoffTime= "2147483647";
56   var $sambaKickoffTime= "2147483647";
57   var $sambaPwdCanChange= "";
58   var $sambaPwdMustChange= "0";
59   var $sambaAcctFlags= "[UX        ]";
60   var $sambaHomePath= "";
61   var $sambaHomeDrive= "";
62   var $sambaLogonScript= "";
63   var $sambaProfilePath= "";
64   var $sambaPrimaryGroupSID= "";
65   var $sambaDomainName= "";
66   var $sambaUserWorkstations= "";
67   var $sambaBadPasswordCount= "";
68   var $sambaBadPasswordTime= "";
69   var $sambaPasswordHistory= "";
70   var $sambaLogonHours= "";
71   var $orig_sambaDomainName= "";
72   var $sambaMungedDial= "";
73   var $mungedObject;
75   /* Helper */
76   var $cache = array();
77   var $show_ws_dialog= FALSE;
78   var $logon_time_set= 0;
79   var $logoff_time_set= 0;
80   var $kickoff_time_set= 0;
82   /* attribute list for save action */
83   var $ctxattributes= array();
84   var $attributes= array();
85   var $objectclasses= array();
86   
87   var $uid= "";
88   var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
90   var $multiple_support = TRUE;
92   /* Only used  for multiple edit */
93   var $temporary_disable = FALSE;
94   var $no_password_required = FALSE;
95   var $no_expiry = FALSE;
96   var $multiple_sambaUserWorkstations = array();
98   function sambaAccount (&$config, $dn= NULL)
99   {
100     /* Load attributes depending on the samba version */
101     $this->samba3= ($config->get_cfg_value("sambaversion") == 3);
103     if ($this->samba3){
104       $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
105           "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
106           "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
107           "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
108           "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
109           "sambaUserWorkstations", "sambaPasswordHistory",
110           "sambaLogonHours", "sambaBadPasswordTime",
111           "sambaBadPasswordCount");
112       $this->objectclasses= array ("sambaSamAccount");
113       $this->mungedObject= new sambaMungedDial;
114       $this->ctxattributes= $this->mungedObject->ctxattributes;
115     } else {
116       $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
117           "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
118           "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
119       $this->objectclasses= array ("sambaAccount");
120     }
122     plugin::plugin ($config, $dn);
124     /* Setting uid to default */
125     if(isset($this->attrs['uid'][0])){
126       $this->uid = $this->attrs['uid'][0];
127     }
129     /* Get samba Domain in case of samba 3 */
130     if ($this->samba3 && $this->sambaSID != ""){
131       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
132       $ldap= $this->config->get_ldap_link();
133       $ldap->cd($this->config->current['BASE']);
134       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
135       if ($ldap->count() != 0){
136         $attrs= $ldap->fetch();
137         if(isset($attrs['sambaAlgorithmicRidBase'])){
138           $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
139         } else {
140           $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
141         }
142         if ($this->sambaDomainName == ""){
143           $this->sambaDomainName= $attrs['sambaDomainName'][0];
144         }
145       } else {
146         if ($this->sambaDomainName == ""){
147           $this->sambaDomainName= "DEFAULT";
148         }
149         $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
150         $this->SID= $this->config->get_cfg_value("sambaSid");
151       }
153       /* Save in order to compare later on */
154       $this->orig_sambaDomainName= $this->sambaDomainName;
155     }
157     /* Fill mungedDial field */
158     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
159       $this->mungedObject->load($this->sambaMungedDial);
160     }
162     /* Password expiery */
163     if(isset($this->attrs['sambaPwdMustChange']) &&
164         $this->attrs['sambaPwdMustChange'][0] != 0){
165       $this->password_expires= 1;
166     }
168     if(isset($this->attrs['sambaLogonTime']) && ! (
169         $this->attrs['sambaLogonTime'][0] == 0 ||
170         $this->attrs['sambaLogonTime'][0] == 2147483647
171       )){
172       $this->logon_time_set= 1;
173     }
174     if(isset($this->attrs['sambaLogoffTime']) && ! (
175         $this->attrs['sambaLogoffTime'][0] == 0 ||
176         $this->attrs['sambaLogoffTime'][0] == 2147483647
177       )){
178       $this->logoff_time_set= 1;
179     }
180     
181     /* Account expiery */
182     if(isset($this->attrs['sambaKickoffTime']) && ! (
183         $this->attrs['sambaKickoffTime'][0] == 0 ||
184         $this->attrs['sambaKickoffTime'][0] == 2147483647
185       )){
186       $this->kickoff_time_set= 1;
187     }
189     /* Get global filter config */
190     if (!session::is_set("sambafilter")){
191       $ui= get_userinfo();
192       $base= get_base_from_people($ui->dn);
193       $sambafilter= array( "depselect" => $base, "regex" => "*");
194       session::set("sambafilter", $sambafilter);
195     }
197     /* Save initial account state */
198     $this->initially_was_account= $this->is_account;
199   }
201   function execute()
202   {
203     /* Call parent execute */
204     plugin::execute();
206     /* Log view */
207     if($this->is_account && !$this->view_logged){
208       $this->view_logged = TRUE;
209       new log("view","users/".get_class($this),$this->dn);
210     }
212     /* Do we need to flip is_account state? */
213     if (isset($_POST['modify_state'])){
214       $this->is_account= !$this->is_account;
215     }
216     /* Do we represent a valid account? */
217     if (!$this->is_account && $this->parent === NULL){
218       $display= "<img alt=\"\"src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
219         msgPool::noValidExtension(_("Samba"))."</b>";
220       $display.= back_to_main();
221       return ($display);
222     }
224     $display ="";
225     if(!$this->multiple_support_active){
227       /* Show tab dialog headers */
228       $display= "";
229       if ($this->parent !== NULL){
230         if ($this->is_account){
231           $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Samba")),
232               msgPool::featuresEnabled(_("Samba")));
233         } else {
234           $obj= $this->parent->by_object['posixAccount'];
236           /* Samba3 dependency on posix accounts are enabled
237              in the moment, because I need to rely on unique
238              uidNumbers. There'll be a better solution later
239              on. */
240           if ($obj->is_account){
241             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
242                 msgPool::featuresDisabled(_("Samba")));
243           } else {
244             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
245                 msgPool::featuresDisabled(_("Samba"), _("POSIX")), TRUE);
246           }
247           return ($display);
248         }
249       }
250     }
252     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
254     /* Open Samaba Logong hours dialog */
255     if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_readable("sambaLogonHours")){
256       $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
257     }
259     /* Cancel dialog */
260     if(isset($_POST['cancel_logonHours'])){
261       $this->dialog = FALSE;
262     }
264     /* Save selected logon hours */
265     if(isset($_POST['save_logonHours'])){
266       $this->dialog->save_object();
267       if($this->acl_is_writeable("sambaLogonHours")){
268         $this->sambaLogonHours = $this->dialog->save();
269       }
270       $this->dialog = FALSE;
271     }
273     /* Display dialog */
274     if((isset($this->dialog)) && (is_object($this->dialog))){
275       $this->dialog->save_object();
276       return($this->dialog->execute());
277     }
279     /* Prepare templating */
280     $smarty= get_smarty();
282     $tmp = $this->plInfo();
283     foreach($tmp['plProvidedAcls'] as $var => $rest){
284       $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
285     }
287     if(!session::is_set('edit') && !isset($this->parent)){
288       $smarty->assign("sambaLogonHoursACL","");
289     }
291     if ($this->sambaPwdMustChange=="0"){
292       $date= getdate();
293     } else {
294       $date= getdate($this->sambaPwdMustChange);
295     }
297     if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
298       $sambaLogonTime_date= getdate();
299     } else {
300       $sambaLogonTime_date= getdate($this->sambaLogonTime);
301     }
302     
303     if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
304       $sambaLogoffTime_date= getdate();
305     } else {
306       $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
307     }
308     
309     if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
310       $sambaKickoffTime_date= getdate();
311     } else {
312       $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
313     }
315     /* Remove user workstations? */
316     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
318       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
320         if($this->multiple_support_active){
321           foreach($_POST['workstation_list'] as $name){
322             if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
323               unset($this->multiple_sambaUserWorkstations[trim($name)]);
324             }
325           } 
326         }else{
327           $tmp= $this->sambaUserWorkstations;
328           foreach($_POST['workstation_list'] as $name){
329             $tmp= preg_replace("/$name/", '', $tmp);
330             $this->is_modified= TRUE;
331           }
332           $tmp= preg_replace('/,+/', ',', $tmp);
333           $this->sambaUserWorkstations= trim($tmp, ',');
334         }
335       }
336     }
338     /* Add user workstation? */
339     if (isset($_POST["add_ws"])){
340       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
341         $this->show_ws_dialog= TRUE;
342         $this->dialog= TRUE;
343       }
344     }
346     /* Add user workstation finished? */
347     if (isset($_POST["add_ws_cancel"])){
348       $this->show_ws_dialog= FALSE;
349       $this->dialog= FALSE;
350     }
352     /* Add user workstation? */
353     if (isset($_POST["add_ws_finish"])){
355       if (isset($_POST['wslist'])){
356         if($this->multiple_support_active){
357           foreach($_POST['wslist'] as $ws){
358             $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
359           }
360         }else{
361           $tmp= $this->sambaUserWorkstations;
362           foreach($_POST['wslist'] as $ws){
363             $tmp.= ",$ws";
364           }
365           $tmp= preg_replace('/,+/', ',', $tmp);
366           $this->sambaUserWorkstations= trim($tmp, ',');
367         }
368         $this->is_modified= TRUE;
370         $this->show_ws_dialog= FALSE;
371         $this->dialog= FALSE;
372       } else {
373         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
374       }
375     }
377     /* Show ws dialog */
378     if ($this->show_ws_dialog){
380       /* Save data */
381       $sambafilter= session::get("sambafilter");
382       foreach( array("depselect", "regex") as $type){
383         if (isset($_POST[$type])){
384           $sambafilter[$type]= $_POST[$type];
385         }
386       }
387       if (isset($_GET['search'])){
388         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
389         if ($s == "**"){
390           $s= "*";
391         }
392         $sambafilter['regex']= $s;
393       }
394       session::set("sambafilter", $sambafilter);
396       /* Get workstation list */
397       $exclude= "";
399       if($this->multiple_support_active){
400         foreach($this->multiple_sambaUserWorkstations as $ws){
401           if($ws['UsedByAllUsers']){
402             $exclude.= "(cn=".$ws['Name']."$)";
403           }
404         }
405       }else{
406         foreach(split(',', $this->sambaUserWorkstations) as $ws){
407           $exclude.= "(cn=$ws$)";
408         }
409       }
410       if ($exclude != ""){
411         $exclude= "(!(|$exclude))";
412       }
413       $regex= $sambafilter['regex'];
414       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
415       $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
416         
417       $wslist= array();
418       foreach ($res as $attrs){
419         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
420       }
421       asort($wslist);
423       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
424       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
425       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
426       $smarty->assign("deplist", $this->config->idepartments);
427       $smarty->assign("alphabet", generate_alphabet());
428       foreach( array("depselect", "regex") as $type){
429         $smarty->assign("$type", $sambafilter[$type]);
430       }
431       $smarty->assign("hint", print_sizelimit_warning());
432       $smarty->assign("wslist", $wslist);
433       $smarty->assign("apply", apply_filter());
434       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
435                                 dirname(__FILE__)));
436       return ($display);
437     }
439     /* Fill calendar */
440     $days= array();
441     for($d= 1; $d<32; $d++){
442       $days[]= $d;
443     }
444     $years= array();
445     for($y= $date['year']-4; $y<$date['year']+4; $y++){
446       $years[]= $y;
447     }
448     $months= msgPool::months();
449     $smarty->assign("day", $date["mday"]);
450     $smarty->assign("days", $days);
451     $smarty->assign("months", $months);
452     $smarty->assign("month", $date["mon"]-1);
453     $smarty->assign("years", $years);
454     $smarty->assign("year", $date["year"]);
455     
456     $sambaLogonTime_days= array();
457     for($d= 1; $d<32; $d++){
458       $sambaLogonTime_days[]= $d;
459     }
460     $sambaLogonTime_years= array();
461     for($y= $date['year']-4; $y<$date['year']+4; $y++){
462       $sambaLogonTime_years[]= $y;
463     }
464     $sambaLogonTime_months= msgPool::months();
465     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
466     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
467     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
468     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
469     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
470     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
471     
472     $sambaLogoffTime_days= array();
473     for($d= 1; $d<32; $d++){
474       $sambaLogoffTime_days[]= $d;
475     }
476     $sambaLogoffTime_years= array();
477     for($y= $date['year']-4; $y<$date['year']+4; $y++){
478       $sambaLogoffTime_years[]= $y;
479     }
480     $sambaLogoffTime_months= msgPool::months();
481     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
482     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
483     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
484     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
485     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
486     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
487     
488     $sambaKickoffTime_days= array();
489     for($d= 1; $d<32; $d++){
490       $sambaKickoffTime_days[]= $d;
491     }
492     $sambaKickoffTime_years= array();
493     for($y= $date['year']-4; $y<$date['year']+4; $y++){
494       $sambaKickoffTime_years[]= $y;
495     }
496     $sambaKickoffTime_months= msgPool::months();
497     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
498     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
499     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
500     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
501     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
502     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
503     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
504      
505     /* Fill boxes */
506     if ($this->samba3){
507       $domains= array();
508       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
509         $domains[]= $name;
510       }
511       $smarty->assign("domains", $domains);
512     }
513     $letters= array("");
514     for ($i= 68; $i<91; $i++){
515       $letters[]= chr($i).":";
516     }
517     $smarty->assign("drives", $letters);
519     /* Fill terminal server settings */
520     if ($this->samba3){
521       foreach ($this->ctxattributes as $attr){
522         /* Fill common attributes */
523         if (isset($this->mungedObject->ctx[$attr])){
524           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
525           // Set field  to blank if value is 0
526           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
527             if($this->mungedObject->ctx[$attr] == 0) {
528               $smarty->assign("$attr", "");
529             }
530           }
531         } else {
532           $smarty->assign("$attr", "");
533         }
534       }
536       /* Assign enum values for preset items */
537       $shadowModeVals= array( "0" => _("disabled"),
538           "1" => _("input on, notify on"),
539           "2" => _("input on, notify off"),
540           "3" => _("input off, notify on"),
541           "4" => _("input off, nofify off"));
543       $brokenConnModeVals= array(       "0" => _("disconnect"),
544           "1" => _("reset"));
546       $reConnModeVals= array( "0" => _("from any client"),
547           "1" => _("from previous client only"));
549       /* Fill preset items */
550       $smarty->assign("shadow", $shadowModeVals);
551       $smarty->assign("brokenconn", $brokenConnModeVals);
552       $smarty->assign("reconn", $reConnModeVals);
554       /* Fill preset items with values */
555       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
556       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
557       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
559       if(session::get('js')){
560         /* Set form elements to disabled/enable state */
561         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
563         $smarty->assign("inheritstate", "");
564         if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
565           $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
566         }
567       }else{
568         $smarty->assign("tsloginstate", "");
569         $smarty->assign("inheritstate", "");
570       }      
572       /* Set checkboxes to checked or unchecked state */
573       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
574       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
575       $smarty->assign("connectclientdrives",
576                       $this->mungedObject->getConnectClientDrives()?"checked":"");
577       $smarty->assign("connectclientprinters",
578                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
579       $smarty->assign("defaultprinter",
580                       $this->mungedObject->getDefaultPrinter()?"checked":"");
581       $smarty->assign("CtxMaxConnectionTimeF",
582                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
583       $smarty->assign("CtxMaxDisconnectionTimeF",
584                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
585       $smarty->assign("CtxMaxIdleTimeF",
586                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
588       
589       /* Fill sambaUserWorkstations */
590       $ws= split(",", $this->sambaUserWorkstations);
591       sort($ws);
592       
593       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
594       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
596       if($this->multiple_support_active){
597         $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
598       }  
600       $smarty->assign("workstations", $ws);
601     }
603     /* Variables */
604     foreach($this->attributes as $val){
605       $smarty->assign("$val", $this->$val);
606     }
608     /* 'sambaAcctFlags' checkboxes */
609     /* Check for 'lock-account'-flag: 'D' or 'L' */
610     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
611         is_integer(strpos($this->sambaAcctFlags, "L"))) {
612         $smarty->assign("flagsD", "checked");
613     } else {
614         $smarty->assign("flagsD", "");
615     }
616     
617     /* Check for no_password_required flag 'N' */
618     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
619         $smarty->assign("flagsN", "checked");
620     } else {
621         $smarty->assign("flagsN", "");
622     }
624     // check if password never expires
625     if (is_integer(strpos($this->sambaAcctFlags, "X"))) {
626         $smarty->assign("flagsX", "checked");
627     } else {
628         $smarty->assign("flagsX", "");
629     }
631     if($this->samba3){
632       if ($this->sambaPwdCanChange=="1"){
633         $smarty->assign("flagsP", "checked");
634       } else {
635         $smarty->assign("flagsP", "");
636       }
637     }else{
638       if ($this->pwdCanChange=="1"){
639         $smarty->assign("flagsP", "checked");
640       } else {
641         $smarty->assign("flagsP", "");
642       }
643     }
645     if ($this->password_expires=="1"){
646       $smarty->assign("flagsC", "checked");
647     } else {
648       $smarty->assign("flagsC", "");
649     }
650     if ($this->logon_time_set=="1"){
651       $smarty->assign("flagsT", "checked");
652     } else {
653       $smarty->assign("flagsT", "");
654     }
655     if ($this->logoff_time_set=="1"){
656       $smarty->assign("flagsO", "checked");
657     } else {
658       $smarty->assign("flagsO", "");
659     }
660     if ($this->kickoff_time_set=="1"){
661       $smarty->assign("flagsK", "checked");
662     } else {
663       $smarty->assign("flagsK", "");
664     }
665    
667     /* In case of javascript, disable some fields on demand */
668     if ($this->samba3){
669       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
670         $smarty->assign("$key", "$value");
671       }
672     }
675     foreach($this->attributes as $attr){
676       if(in_array($attr,$this->multi_boxes)){
677         $smarty->assign("use_".$attr,TRUE);
678       }else{
679         $smarty->assign("use_".$attr,FALSE);
680       }
681     }
682     foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
683           "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
684           "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
685           "onnectclientprinters","defaultprinter","shadow","brokenconn",
686           "reconn","allow_pwchange","connectclientprinters","no_expiry","no_password_required","temporary_disable", 
687           "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
688           "workstation_list") as $attr){
689       if(in_array($attr,$this->multi_boxes)){
690         $smarty->assign("use_".$attr,TRUE);
691       }else{
692         $smarty->assign("use_".$attr,FALSE);
693       }
694     }
696     if($this->multiple_support_active){
697       $smarty->assign("tsloginstate","");
698     }
700     /* Create additional info for sambaKickOffTime and sambaPwdMustChange. 
701        e.g. Display effective kickoff time. Domain policy + user settings. 
702      */
703     $additional_info_PwdMustChange = "";
705     /* Calculate effective max Password Age 
706         This can only be calculated if sambaPwdLastSet ist set. 
707      */
708     if(isset($this->attrs['sambaPwdLastSet'][0])){
709       $last = $this->attrs['sambaPwdLastSet'][0];
711       $sid = $this->get_domain_info();
712       if(isset($sid['sambaMaxPwdAge'][0])){
713         $d = ($last + $sid['sambaMaxPwdAge'][0]) - time();
715         /* A negative value means the password is outdated 
716          */
717         if($d < 0){
718           $additional_info_PwdMustChange = sprintf(_("The password is outdated since %s, by domain policy."),
719               date("d.m.Y H:i:s",$last + $sid['sambaMaxPwdAge'][0]));
720         }else{
721           if($this->password_expires && ($last + $sid['sambaMaxPwdAge'][0]) > $this->sambaPwdMustChange){
722             $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by user policy."),
723                 date("d.m.Y H:i:s",  $this->sambaPwdMustChange));
724           }else{
725              $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by domain policy."),
726                 date("d.m.Y H:i:s",  ($last + $sid['sambaMaxPwdAge'][0])));
727           }
728         }
729       }
730     }
731     $smarty->assign("additional_info_PwdMustChange",$additional_info_PwdMustChange);
733     /* Show main page */
734     $smarty->assign("multiple_support",$this->multiple_support_active);
735     if ($this->samba3){
736       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
737     } else {
738       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
739     }
741     return ($display);
742   }
745   /*! \brief  Returns the samba Domain object, selected in the samba tab.   
746    */
747   function get_domain_info()
748   {
749     /* Only search once, return last result if available
750      */
751     if(!isset($this->cache['DOMAIN'][$this->sambaDomainName])){
752       $this->cache['DOMAIN'][$this->sambaDomainName] = array();
753       if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
754         $cfg = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName];
755         $ldap = $this->config->get_ldap_link();
756         $ldap->cd($this->config->current['BASE']);
757         $ldap->search("(&(objectClass=sambaDomain)(sambaSID=".$cfg['SID']."))",array("*"));
758         if($ldap->count()){
759           $this->cache['DOMAIN'][$this->sambaDomainName] = $ldap->fetch();
760         }
761       }
762     }
763     return($this->cache['DOMAIN'][$this->sambaDomainName]);
764   }
768   function get_samba_information()
769   {
771     /* Defaults 
772      */
773     $sambaMinPwdLength = "unset";
774     $sambaPwdHistoryLength = "unset";
775     $sambaLogonToChgPwd = "unset";
776     $sambaMaxPwdAge = "unset";
777     $sambaMinPwdAge = "unset";
778     $sambaLockoutDuration = "unset";
779     $sambaLockoutThreshold = "unset";
780     $sambaForceLogoff = "unset";
781     $sambaRefuseMachinePwdChange = "unset";
782     $sambaPwdLastSet = "unset";
783     $sambaLogonTime = "unset";
784     $sambaLogoffTime = "unset";
786     $sambaKickoffTime = "unset"; 
787     $sambaPwdCanChange = "unset";
788     $sambaPwdMustChange = "unset";
789     $sambaBadPasswordCount = "unset";
790     $sambaBadPasswordTime = "unset";
792     /* Domain attributes 
793      */
794     $domain_attributes = array("sambaMinPwdLength","sambaPwdHistoryLength","sambaMaxPwdAge",
795         "sambaMinPwdAge","sambaLockoutDuration","sambaRefuseMachinePwdChange",
796         "sambaLogonToChgPwd","sambaLockoutThreshold","sambaForceLogoff");
798     /* User attributes 
799      */
800     $user_attributes = array("sambaBadPasswordTime","sambaPwdLastSet","sambaLogonTime","sambaLogoffTime",
801         "sambaKickoffTime","sambaPwdCanChange","sambaPwdMustChange","sambaBadPasswordCount");
803     /* Get samba SID object and parse settings.
804      */  
805     $ldap = $this->config->get_ldap_link();
806     $ldap->cd($this->config->current['BASE']);
807     if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
808       $attrs = $this->get_domain_info();
809       foreach($domain_attributes as $attr){
810         if(isset($attrs[$attr])){
811           $$attr = $attrs[$attr][0];
812         }
813       }
814     }
815   
816     /* Get user infos
817      */
818     foreach($user_attributes as $attr){
819       if(isset($this->attrs[$attr])){
820         $$attr = $this->attrs[$attr][0];
821       }
822     }
823     if($this->password_expires){
824       $sambaPwdMustChange = $this->sambaPwdMustChange;
825     }
826     if($this->kickoff_time_set){
827       $sambaKickoffTime = $this->sambaKickoffTime;
828     }
829     $sambaPwdCanChange = $this->sambaPwdCanChange;
832     /* DOMAIN Attributes 
833      */
835     /* sambaMinPwdLength: Password length has a default of 5 
836      */
837     if($sambaMinPwdLength == "unset" || $sambaMinPwdLength == 5){
838       $sambaMinPwdLength  = "5 <i>("._("default").")</i>";
839     }
841     /* sambaPwdHistoryLength: Length of Password History Entries (default: 0 => off)
842      */
843     if($sambaPwdHistoryLength == "unset" || $sambaPwdHistoryLength == 0){
844       $sambaPwdHistoryLength = _("Off")." <i>("._("default").")</i>";
845     }
847     /* sambaLogonToChgPwd: Force Users to logon for password change (default: 0 => off, 2 => on) 
848      */
849     if($sambaLogonToChgPwd == "unset" || $sambaLogonToChgPwd == 0){
850       $sambaLogonToChgPwd = _("Off")." <i>("._("default").")</i>";
851     }else{
852       $sambaLogonToChgPwd = _("On");
853     }
854     
855     /* sambaMaxPwdAge: Maximum password age, in seconds (default: -1 => never expire passwords)'
856      */
857     if($sambaMaxPwdAge == "unset" || $sambaMaxPwdAge == "-1"){
858       $sambaMaxPwdAge = _("disabled")." <i>("._("default").")</i>";
859     }else{
860       $sambaMaxPwdAge .= " "._("seconds"); 
861     }
863     /* sambaMinPwdAge: Minimum password age, in seconds (default: 0 => allow immediate password change
864      */
865     if($sambaMinPwdAge == "unset" || $sambaMinPwdAge == 0){
866       $sambaMinPwdAge = _("disabled")." <i>("._("default").")</i>";
867     }else{
868       $sambaMinPwdAge .= " "._("seconds"); 
869     }
871     /* sambaLockoutDuration: Lockout duration in minutes (default: 30, -1 => forever)
872      */
873     if($sambaLockoutDuration == "unset" || $sambaLockoutDuration == 30){
874       $sambaLockoutDuration = "30 "._("minutes")." <i>("._("default").")</i>";
875     }elseif($sambaLockoutDuration == -1){
876       $sambaLockoutDuration = _("forever");
877     }else{
878       $sambaLockoutDuration .= " "._("minutes");
879     }
881     /* sambaLockoutThreshold: Lockout users after bad logon attempts (default: 0 => off
882      */
883     if($sambaLockoutThreshold == "unset" || $sambaLockoutThreshold == 0){
884       $sambaLockoutThreshold = _("disabled")." <i>("._("default").")</i>";
885     }
887     /* sambaForceLogoff: Disconnect Users outside logon hours (default: -1 => off, 0 => on 
888      */
889     if($sambaForceLogoff == "unset" || $sambaForceLogoff == -1){
890       $sambaForceLogoff = _("off")." <i>("._("default").")</i>";
891     }else{
892       $sambaForceLogoff = _("on");
893     }
895     /* sambaRefuseMachinePwdChange: Allow Machine Password changes (default: 0 => off
896      */
897     if($sambaRefuseMachinePwdChange == "none" || $sambaRefuseMachinePwdChange == 0){
898       $sambaRefuseMachinePwdChange = _("off")." <i>("._("default").")</i>";
899     }else{
900       $sambaRefuseMachinePwdChange = _("on");
901     }
902    
903     /* USER Attributes 
904      */
905     /* sambaBadPasswordTime: Time of the last bad password attempt
906      */
907     if($sambaBadPasswordTime == "unset" || empty($sambaBadPasswordTime)){
908       $sambaBadPasswordTime = "<i>("._("unset").")</i>";
909     }else{
910       $sambaBadPasswordTime = date("d.m.Y H:i:s",$sambaBadPasswordTime);
911     }
913     /* sambaBadPasswordCount: Bad password attempt count 
914      */
915     if($sambaBadPasswordCount == "unset" || empty($sambaBadPasswordCount)){
916       $sambaBadPasswordCount = "<i>("._("unset").")</i>";
917     }else{
918       $sambaBadPasswordCount = date("d.m.Y H:i:s",$sambaBadPasswordCount);
919     }
921     /* sambaPwdLastSet: Timestamp of the last password update
922      */
923     if($sambaPwdLastSet == "unset" || empty($sambaPwdLastSet)){
924       $sambaPwdLastSet = "<i>("._("unset").")</i>";
925     }else{
926       $sambaPwdLastSet = date("d.m.Y H:i:s",$sambaPwdLastSet);
927     }
929     /* sambaLogonTime: Timestamp of last logon
930      */
931     if($sambaLogonTime == "unset" || empty($sambaLogonTime)){
932       $sambaLogonTime = "<i>("._("unset").")</i>";
933     }else{
934       $sambaLogonTime = date("d.m.Y H:i:s",$sambaLogonTime);
935     }
937     /* sambaLogoffTime: Timestamp of last logoff
938      */
939     if($sambaLogoffTime == "unset" || empty($sambaLogoffTime)){
940       $sambaLogoffTime = "<i>("._("unset").")</i>";
941     }else{
942       $sambaLogoffTime = date("d.m.Y H:i:s",$sambaLogoffTime);
943     }
944    
945     /* sambaKickoffTime: Timestamp of when the user will be logged off automatically
946      */
947     if($sambaKickoffTime == "unset" || empty($sambaKickoffTime)){
948       $sambaKickoffTime = "<i>("._("unset").")</i>";
949     }else{
950       $sambaKickoffTime = date("d.m.Y H:i:s",$sambaKickoffTime);
951     }
953     /* sambaPwdMustChange: Timestamp of when the password will expire
954      */
955     if($sambaPwdMustChange == "unset" || empty($sambaPwdMustChange)){
956       $sambaPwdMustChange = "<i>("._("unset").")</i>";
957     }else{
958       $sambaPwdMustChange = date("d.m.Y H:i:s",$sambaPwdMustChange);
959     }
961     /* sambaPwdCanChange: Timestamp of when the user is allowed to update the password
962      */
963     if($sambaPwdCanChange == "unset" || empty($sambaPwdCanChange)){
964       $sambaPwdCanChange = "<i>("._("unset").")</i>";
965     }elseif($sambaPwdCanChange != "unset" && time() > $sambaPwdCanChange){
966       $sambaPwdCanChange = _("immediately") ;
967     }else{
968       $days     = floor((($sambaPwdCanChange - time()) / 60 / 60 / 24)) ;
969       $hours    = floor((($sambaPwdCanChange - time()) / 60 / 60) % 24) ;
970       $minutes  = floor((($sambaPwdCanChange - time()) / 60 ) % 60) ;
971     
972       $sambaPwdCanChange = " ".$days." "._("days");
973       $sambaPwdCanChange.= " ".$hours." "._("hours");
974       $sambaPwdCanChange.= " ".$minutes." "._("minutes");
975     }
977     $str =
978       "\n<div style='height:200px; overflow: auto;'>".
979       "\n<table style='width:100%;'>".
980       "\n<tr><td><b>"._("Domain attributes")."</b></td></tr>". 
981       "\n<tr><td>"._("Min password length").":           </td><td>".$sambaMinPwdLength."</td></tr>". 
982       "\n<tr><td>"._("Min password length").":           </td><td>".$sambaMinPwdLength."</td></tr>". 
983       "\n<tr><td>"._("Password history").":              </td><td>".$sambaPwdHistoryLength."</td></tr>".
984       "\n<tr><td>"._("Force password change").":         </td><td>".$sambaLogonToChgPwd."</td></tr>".
985       "\n<tr><td>"._("Maximum password age").":          </td><td>".$sambaMaxPwdAge."</td></tr>".
986       "\n<tr><td>"._("Minimum password age").":          </td><td>".$sambaMinPwdAge."</td></tr>".
987       "\n<tr><td>"._("Lockout duration").":              </td><td>".$sambaLockoutDuration."</td></tr>".
988       "\n<tr><td>"._("Bad lockout attempt").":           </td><td>".$sambaLockoutThreshold."</td></tr>".
989       "\n<tr><td>"._("Disconnect time").":               </td><td>".$sambaForceLogoff."</td></tr>".
990       "\n<tr><td>"._("Refuse machine password change").":</td><td>".$sambaRefuseMachinePwdChange."</td></tr>".
991       "\n<tr><td>&nbsp;</td></tr>". 
992       "\n<tr><td><b>"._("User attributes")."</b></td></tr>". 
993       "\n<tr><td>"._("Last failed login").":             </td><td>".$sambaBadPasswordTime."</td></tr>".
994       "\n<tr><td>"._("Logon attempts").":                </td><td>".$sambaBadPasswordCount."</td></tr>".
995       "\n<tr><td>"._("Last password update").":          </td><td>".$sambaPwdLastSet."</td></tr>".
996       "\n<tr><td>"._("Last logon").":                    </td><td>".$sambaLogonTime."</td></tr>".
997       "\n<tr><td>"._("Last logoff").":                   </td><td>".$sambaLogoffTime."</td></tr>".
998       "\n<tr><td>"._("Automatic logoff").":              </td><td>".$sambaKickoffTime."</td></tr>".
999       "\n<tr><td>"._("Password expires").":              </td><td>".$sambaPwdMustChange."</td></tr>".
1000       "\n<tr><td>"._("Password change available").":     </td><td>".$sambaPwdCanChange."</td></tr>".
1001       "\n</table>";
1002       "\n</div>";
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= "U";
1130       $this->no_expiry = FALSE;
1131       if (isset($_POST["no_expiry"])){
1132         if ($_POST["no_expiry"] == 1){
1133           $tmp.= "X";
1134           $this->no_expiry = TRUE;
1135         }
1136       }
1138       $this->no_password_required = FALSE;
1139       if (isset($_POST["no_password_required"])){
1140         if ($_POST["no_password_required"] == 1){
1141           $tmp.= "N";
1142           $this->no_password_required = TRUE;
1143         }
1144       }
1145       if (isset($_POST["password_expires"])){
1146         if ($_POST["password_expires"] == 1){
1147           $this->password_expires= 1;
1148         }
1149       } else {
1150         $this->password_expires= 0;
1151       }
1152       $this->temporary_disable = FALSE;
1153       if (isset($_POST["temporary_disable"])){
1154         if ($_POST["temporary_disable"] == 1){
1155           $this->temporary_disable = TRUE;
1156           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
1157             $tmp.= "L";
1158           } else {
1159             $tmp.= "D";
1160           }
1161         }
1162       }
1163       if (isset($_POST["logon_time_set"])){
1164         if ($_POST["logon_time_set"] == 1){
1165           $this->logon_time_set= 1;
1166         }
1167       } else {
1168         $this->logon_time_set= 0;
1169       }
1170       if (isset($_POST["logoff_time_set"])){
1171         if ($_POST["logoff_time_set"] == 1){
1172           $this->logoff_time_set= 1;
1173         }
1174       } else {
1175         $this->logoff_time_set= 0;
1176       }
1177       if (isset($_POST["kickoff_time_set"])){
1178         if ($_POST["kickoff_time_set"] == 1){
1179           $this->kickoff_time_set= 1;
1180         }
1181       } else {
1182         $this->kickoff_time_set= 0;
1183       }
1184       
1185       $fill= "";
1186       for ($i= strlen($tmp); $i<12; $i++){
1187         $fill.= " ";
1188       }
1190       $tmp= "[$tmp$fill]";
1192       /* Only save if acl's are set */
1193       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1194         if ($this->samba3){
1195           $attrname= "sambaAcctFlags";
1196         } else {
1197           $attrname= "acctFlags";
1198         }
1199         if ($this->$attrname != $tmp){
1200           $this->is_modified= TRUE;
1201         }
1202         $this->$attrname= $tmp;
1203       }
1205       /* Save sambaDomain attribute */
1206       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
1207         $this->sambaDomainName= validate($_POST['sambaDomainName']);
1208       }
1210       /* Save CTX values */
1211       if ($this->samba3){
1213         /* Save obvious values */
1214         foreach($this->ctxattributes as $val){
1215           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
1216             if (get_magic_quotes_gpc()) {
1217               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
1218             } else {
1219               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
1220             }
1221           }
1222         }
1224         /* Save checkbox states. */
1225         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
1226                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1227         // Need to do some index checking to avoid messages like "index ... not found"
1228         if(isset($_POST['brokenconn'])) {
1229           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
1230                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1231         }
1232         if(isset($_POST['reconn'])) {
1233           $this->mungedObject->setReConn($_POST['reconn'] == '1'
1234                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1235         }
1236         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
1237                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1238         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
1239                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1240         $this->mungedObject->setCtxMaxDisconnectionTimeF(
1241                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
1242                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1243         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
1244                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1245         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
1246                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1247         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
1248                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1249         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
1250                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1252         /* Save combo boxes. Takes two values */
1253         if(isset($_POST['reconn'])) {
1254           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
1255         }
1257         /* Check for changes */
1258         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
1259           $this->is_modified= TRUE;
1260         }
1261       }
1262     }
1263   }
1266   /* Save to LDAP */
1267   function save()
1268   {
1269     /* Load uid and gid of this 'dn' */
1270     $ldap= $this->config->get_ldap_link();
1271     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
1272     $tmp= $ldap->fetch();
1273     $this->uidNumber= $tmp['uidNumber'][0];
1274     $this->gidNumber= $tmp['gidNumber'][0];
1276     plugin::save();
1278     /* Remove objectClass for sambaIdmapEntry */
1279     $tmp= array();
1280     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1281       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1282         $tmp[]= $this->attrs['objectClass'][$i];
1283       }
1284     }
1285     $this->attrs['objectClass']= $tmp;
1287     /* Generate rid / primaryGroupId */
1288     if ($this->samba3){
1289       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
1290         msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
1291       } else {
1292         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
1293         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
1294       }
1296       /* Need to generate a new uniqe uid/gid combination? */
1297       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
1298         $uidNumber= $this->uidNumber;
1299         while(TRUE){
1300           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
1301           $ldap->cd($this->config->current['BASE']);
1302           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
1303           if ($ldap->count() == 0){
1304             break;
1305           }
1306           $uidNumber++;
1307         }
1308         $this->attrs['sambaSID']= $sid;
1310         /* Check for users primary group */
1311         $ldap->cd($this->config->current['BASE']);
1312         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
1313         if ($ldap->count() != 1){
1314           msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
1315         } else {
1316           $attrs= $ldap->fetch();
1317           $g= new group($this->config, $ldap->getDN());
1318           if ($g->sambaSID == ""){
1319             $g->sambaDomainName= $this->sambaDomainName;
1320             $g->smbgroup= TRUE;
1321             $g->save ();
1322           }
1323           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
1324         }
1325       }
1327       if ($this->sambaHomeDrive == ""){
1328         $this->attrs["sambaHomeDrive"]= array();
1329       }
1331       /* Generate munged dial value */
1332       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1334       /* User wants me to fake the idMappings? This is useful for
1335          making winbind resolve the user names in a reasonable amount
1336          of time in combination with larger databases. */
1337       if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1338         $this->attrs['objectClass'][]= "sambaIdmapEntry";
1339       }
1342       /* Password expiery */
1343       if ($this->password_expires == "1"){
1344         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1345       } else {
1346         $this->attrs['sambaPwdMustChange']= array();
1347       }
1348       /* Make sure not to save zero in sambaPwdLastset */
1349       if ($this->sambaPwdLastSet != "0"){
1350         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1351       } else {
1352         $this->attrs['sambaPwdLastSet']= array();
1353       }
1354       /* Account expiery */
1355       if ($this->logon_time_set == "1"){
1356         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1357       } else {
1358         $this->attrs['sambaLogonTime']= array();
1359       }
1360       if ($this->logoff_time_set == "1"){
1361         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1362       } else {
1363         $this->attrs['sambaLogoffTime']= array();
1364       }
1365       if ($this->kickoff_time_set == "1"){
1366         # Add one day in unixtime format to be compatible with usrmgr
1367         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1368         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1369       } else {
1370         $this->attrs['sambaKickoffTime']= array();
1371       }
1372     } else {
1373     /* Not samba3 */
1374       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1375       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1377       if ($this->homeDrive == ""){
1378         $this->attrs["homeDrive"]= array();
1379       }
1381       /* Password expiery */
1382       if ($this->password_expires == "1"){
1383         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1384       } else {
1385         $this->attrs['pwdMustChange']= 2147483647;
1386       }
1387       /* Make sure not to save zero in pwdLastset */
1388       if ($this->pwdLastSet != "0"){
1389         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1390       } else {
1391         $this->attrs['pwdLastSet']= array();
1392       }
1393       /* Account expiery */
1394       if ($this->logon_time_set == "1"){
1395         $this->attrs['logonTime']= $this->logonTime;
1396       } else {
1397         $this->attrs['logonTime']= array();
1398       }
1399       if ($this->logoff_time_set == "1"){
1400         $this->attrs['logoffTime']= $this->logoffTime;
1401       } else {
1402         $this->attrs['logoffTime']= array();
1403       }
1404       if ($this->kickoff_time_set == "1"){
1405         # Add one day in unixtime format to be compatible with usrmgr
1406         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1407       } else {
1408         $this->attrs['kickoffTime']= array();
1409       }
1410     }
1412     /* Write back to ldap */
1413     $ldap->cd($this->dn);
1414     $this->cleanup();
1415     $ldap->modify ($this->attrs); 
1417     if($this->initially_was_account){
1418       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1419     }else{
1420       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1421     }
1423     if (!$ldap->success()){
1424       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1425     }
1427     /* Optionally execute a command after we're done */
1428     if ($this->initially_was_account == $this->is_account){
1429       if ($this->is_modified){
1430         $this->handle_post_events("modify", array("uid" => $this->uid));
1431       }
1432     } else {
1433       $this->handle_post_events("add", array("uid" => $this->uid));
1434     }
1435   }
1438   /* Force password set, if this account doesn't have any samba passwords  */
1439   function password_change_needed()
1440   {
1441     if(!$this->initially_was_account && $this->is_account){
1442       $ldap = $this->config->get_ldap_link();
1443       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1444       $attrs = $ldap->fetch();
1445       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1446         return(TRUE);
1447       }
1448     }
1449     return(FALSE);
1450   }
1453   function adapt_from_template($dn, $skip= array())
1454   {
1455     plugin::adapt_from_template($dn, $skip);
1458     $this->sambaSID= "";
1459     $this->sambaPrimaryGroupSID= "";
1461     /* Fill mungedDial field */
1462     if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1463       $this->mungedObject->load($this->sambaMungedDial);
1464     }
1466     /* Adapt munged attributes */
1467     foreach($this->ctxattributes as $attr){
1468       if(isset($this->mungedObject->ctx[$attr]))
1469         $val = $this->mungedObject->ctx[$attr];
1471       foreach (array("sn", "givenName", "uid") as $repl){
1472         if (preg_match("/%$repl/i", $val)){
1473           $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1474         }
1475       }
1476       $this->mungedObject->ctx[$attr] = $val;
1477     }
1479     /* Password expiery */
1480     if(isset($this->attrs['sambaPwdMustChange']) &&
1481         $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1482       $this->password_expires= 1;
1483     }
1485     if(isset($this->attrs['sambaLogonTime']) && ! (
1486         $this->attrs['sambaLogonTime'][0] == 0 ||
1487         $this->attrs['sambaLogonTime'][0] == 2147483647
1488       ) && !in_array('sambaLogonTime', $skip)){
1489       $this->logon_time_set= 1;
1490     }
1491     if(isset($this->attrs['sambaLogoffTime']) && ! (
1492         $this->attrs['sambaLogoffTime'][0] == 0 ||
1493         $this->attrs['sambaLogoffTime'][0] == 2147483647
1494       ) && !in_array('sambaLogonTime', $skip)){
1495       $this->logoff_time_set= 1;
1496     }
1498     /* Account expiery */
1499     if(isset($this->attrs['sambaKickoffTime']) && ! (
1500         $this->attrs['sambaKickoffTime'][0] == 0 ||
1501         $this->attrs['sambaKickoffTime'][0] == 2147483647
1502       ) && !in_array('sambaKickoffTime', $skip)){
1503       $this->kickoff_time_set= 1;
1504     }
1506     /* Get global filter config */
1507     if (!session::is_set("sambafilter")){
1508       $ui= get_userinfo();
1509       $base= get_base_from_people($ui->dn);
1510       $sambafilter= array( "depselect" => $base, "regex" => "*");
1511       session::set("sambafilter", $sambafilter);
1512     }
1513   }
1515   
1516   static function plInfo()
1517   {
1518     return (array(
1519           "plShortName"     => _("Samba"),
1520           "plDescription"   => _("Samba settings"),
1521           "plSelfModify"    => TRUE,
1522           "plDepends"       => array("user"),
1523           "plPriority"      => 5,
1524           "plSection"     => array("personal" => _("My account")),
1525           "plCategory"    => array("users"),
1526           "plOptions"       => array(),
1528           "plProvidedAcls"  => array(
1530             "sambaHomePath"               => _("Generic home directory") ,
1531             "sambaHomeDrive"              => _("Generic samba home drive") ,
1532             "sambaDomainName"             => _("Domain") ,
1533             "sambaLogonScript"            => _("Generic script path") ,
1534             "sambaProfilePath"            => _("Generic profile path") ,
1535             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1536             "InheritClientConfig"         => _("Inherit client config"),
1537             "sambaPwdCanChange"           => _("Allow user to change password") ,
1538             "sambaAcctFlagsN"             => _("Login from windows client requires no password"),
1539             "sambaAcctFlagsX"             => _("Password never expires"),
1540             "sambaAcctFlagsL"             => _("Lock samba account"),
1541             "sambaKickoffTime"            => _("Account expires") ,
1542             "sambaPwdMustChange"          => _("Password expires") ,
1543             "sambaLogonTime"              => _("Limit Logon Time") ,
1544             "sambaLogoffTime"             => _("Limit Logoff Time") ,
1545             "sambaLogonHours"             => _("Logon hours") ,
1546             "sambaUserWorkstations"       => _("Allow connection from"))
1547           ));
1548   }    
1550   function enable_multiple_support()
1551   {
1552     plugin::enable_multiple_support();
1553     if($this->samba3){
1554       $this->multiple_support_active = TRUE;
1555     }else{
1556       $this->multiple_support_active = FALSE;
1557     }
1558   } 
1560   function multiple_save_object()
1561   {
1562     if (isset($_POST['sambaTab'])){
1563       $this->save_object();
1564       plugin::multiple_save_object();
1565       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1566             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1567             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1568             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1569             "reconn","allow_pwchange","connectclientprinters","no_expiry","no_password_required","temporary_disable",
1570             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1571             "workstation_list") as $attr){
1572         if(isset($_POST["use_".$attr])){
1573           $this->multi_boxes[] = $attr;
1574         }
1575       }
1576     }
1577   }
1580   function multiple_check()
1581   {
1582     $message = plugin::multiple_check();
1584     /* Strings */
1585     foreach (array( "sambaHomePath" => _("Home directory"),
1586           "sambaProfilePath" => _("Profile path")) as $key => $val){
1587       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1588         $message[]= msgPool::invalid($val);
1589       }
1590     }
1592     /* Numeric values */
1593     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1594                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1595                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1596       if (in_array($key,$this->multi_boxes) && 
1597           isset($this->mungedObject->ctx[$key]) && 
1598           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1599         $message[]=msgPool::invalid($val);
1600       }
1601     }
1603     /* Too many workstations? Windows usrmgr only supports eight */
1604     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1605       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1606     }
1607     return($message);
1608   }
1610   
1611   function get_multi_init_values()
1612   {
1613     $ret = plugin::get_multi_init_values();
1615     /* Parse given sambaUserWorkstations into array
1616      *  to allow "init_multiple_support()" to detect multiple used workstations.
1617      *  Those workstations will be displayed in light grey.
1618      */
1619     $tmp2 = array("count" => 0);
1620     $tmp = split(",", $this->sambaUserWorkstations);
1621     foreach($tmp as $station){
1622       $station = trim($station);
1623       if(!empty($station)){
1624         $tmp2[] = $station;
1625         $tmp2['count'] ++;
1626       }
1627     } 
1628     $ret['sambaUserWorkstations'] = $tmp2;
1629     return($ret);
1630   }
1634   function init_multiple_support($attrs,$all)
1635   {
1636     plugin::init_multiple_support($attrs,$all);
1638     $this->multiple_sambaUserWorkstations = array();
1639     if(isset($all['sambaUserWorkstations'])){
1640       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1641         $station = trim($all['sambaUserWorkstations'][$i]);
1642         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1643       }
1644     }
1645     if(isset($attrs['sambaUserWorkstations'])){
1646       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1647         $station = trim($attrs['sambaUserWorkstations'][$i]);
1648         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1649       }
1650     }
1651   }
1653   function multiple_execute()
1654   {
1655     return($this->execute());
1656   } 
1658   function get_multi_edit_values()
1659   {
1660     $ret = plugin::get_multi_edit_values();
1662     /* Terminal Server  */
1663     if(in_array("tslogin",$this->multi_boxes)){
1664       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1665     }
1666     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1667       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1668     }
1669     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1670       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1671     }
1672     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1673       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1674     }
1676     if(in_array("inherit",$this->multi_boxes)){
1677       $ret['inherit'] = $this->mungedObject->getInheritMode();
1678     }       
1679     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1680       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1681     } 
1682     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1683       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1684     } 
1686     /* Time Limits. Be careful here, there are some negations  */
1687     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1688       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1689       if(!$ret["CtxMaxConnectionTimeF"]){
1690         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1691       }
1692     }
1693     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1694       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1695       if(!$ret["CtxMaxDisconnectionTimeF"]){
1696         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1697       }
1698     }
1699     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1700       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1701       if(!$ret["CtxMaxIdleTimeF"]){
1702         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1703       }
1704     }
1706     /* Client Devices */
1707     if(in_array("connectclientdrives",$this->multi_boxes)){
1708       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1709     }
1710     if(in_array("connectclientprinters",$this->multi_boxes)){
1711       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1712     }
1713     if(in_array("defaultprinter",$this->multi_boxes)){
1714       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1715     }
1717     /* Misc */
1718     if(in_array("shadow",$this->multi_boxes)){
1719       $ret["shadow"]    =$this->mungedObject->getShadow();
1720     }
1721     if(in_array("brokenconn",$this->multi_boxes)){
1722       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1723     }
1724     if(in_array("reconn",$this->multi_boxes)){
1725       $ret["reconn"]    =$this->mungedObject->getReConn();
1726     }
1728     /* Flags */
1729     if(in_array("allow_pwchange",$this->multi_boxes)){
1730       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1731       $ret['pwdCanChange']      = $this->pwdCanChange;
1732     }
1733   
1734     if(in_array("password_expires",$this->multi_boxes)){
1735       $ret['password_expires']  = $this->password_expires;
1736       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1737     }
1738     if(in_array("logon_time_set",$this->multi_boxes)){
1739       $ret['logon_time_set'] = $this->logon_time_set;
1740       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1741     }
1742     if(in_array("logoff_time_set",$this->multi_boxes)){
1743       $ret['logoff_time_set'] = $this->logoff_time_set;
1744       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1745     }
1746     if(in_array("kickoff_time_set",$this->multi_boxes)){
1747       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1748       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1749     }
1751     if(in_array("no_password_required",$this->multi_boxes)){
1752       $ret['no_password_required'] = $this->no_password_required;
1753     }
1755     if(in_array("no_expiry",$this->multi_boxes)){
1756       $ret['no_expiry'] = $this->no_expiry;
1757     }
1759     if(in_array("temporary_disable",$this->multi_boxes)){
1760       $ret['temporary_disable'] = $this->temporary_disable;
1761     }
1762     
1763     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1764       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1765     }
1767     if(in_array("workstation_list",$this->multi_boxes)){
1768       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1769     }
1770     return($ret);
1771   }
1773   function set_multi_edit_values($values)
1774   {
1775     plugin::set_multi_edit_values($values);
1777     /* Prepare current workstation settings to be merged 
1778      *  with multiple edit settings.
1779      */
1780     if(isset($values['multiple_sambaUserWorkstations'])){
1781       $cur_ws = array();
1782       $m_ws = $values['multiple_sambaUserWorkstations'];
1784       /* Prepare current settings to be merged */
1785       if(isset($this->sambaUserWorkstations)){
1786         $ttmp = split(",",$this->sambaUserWorkstations);
1787         foreach($ttmp as $station){
1788           $station = trim($station);
1789           if(!empty($station)){
1790             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1791           }
1792         }
1793       }
1795       /* Unset removed workstations */
1796       foreach($cur_ws as $cur_name => $cur_station){
1797         if(!isset($m_ws[$cur_name])){
1798           unset($cur_ws[$cur_name]);
1799         }
1800       }
1802       /* Add all added workstations */
1803       foreach($m_ws as $name => $station){
1804         if($station['UsedByAllUsers']){
1805           $cur_ws[$name] = $station;
1806         }
1807       }
1809       $this->sambaUserWorkstations = "";
1810       foreach($cur_ws as $name => $ws){
1811         $this->sambaUserWorkstations .= $name.",";
1812       }
1813       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1814     }
1816     /* Enable disabled terminal login, this is inverted somehow */
1817     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1818   
1819     /* Imherit client configuration */
1820     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1821   
1822     /* Get all ctx values posted */
1823     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1824                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1825     foreach($ctx as $attr){
1826       if(isset($values[$attr])){
1827         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1828       }
1829     }
1831     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1832     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1833     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1835     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1836     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1837     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1839     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1840     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1841     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1843   
1844     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1845     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1847     
1848     
1850     if(isset($values['password_expires'])){
1851       $this->password_expires = $values['password_expires'];
1852       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1853     }
1854     if(isset($values['logon_time_set'])){
1855       $this->logon_time_set = $values['logon_time_set'];
1856       $this->sambaLogonTime = $values['sambaLogonTime'];
1857     }
1858     if(isset($values['logoff_time_set'])){
1859       $this->logoff_time_set = $values['logoff_time_set'];
1860       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1861     }
1862     if(isset($values['kickoff_time_set'])){
1863       $this->kickoff_time_set = $values['kickoff_time_set'];
1864       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1865     }
1867     if(isset($values['no_password_required'])){
1868       if($values['no_password_required']){
1869         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1870           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1871         }
1872       }else{
1873         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1874       }
1875     }      
1877     if(isset($values['no_expiry'])){
1878       if($values['no_expiry']){
1879         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1880           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1881         }
1882       }else{
1883         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1884       }
1885     }      
1887     if(isset($values['temporary_disable'])){
1888       if($values['temporary_disable']){
1889         if(preg_match("/L/",$this->sambaAcctFlags)) {
1890           // Keep L
1891         }else{
1892           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1893         }
1894       }else{
1895         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1896       }
1897     }
1898   }
1901   function PrepareForCopyPaste($source)
1902   {
1903     plugin::PrepareForCopyPaste($source);
1905     /* Set a new SID */
1906     $this->sambaSID = "";
1907   }
1911 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1912 ?>