Code

Updated msgPools
[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 $show_ws_dialog= FALSE;
77   var $logon_time_set= 0;
78   var $logoff_time_set= 0;
79   var $kickoff_time_set= 0;
81   /* attribute list for save action */
82   var $ctxattributes= array();
83   var $attributes= array();
84   var $objectclasses= array();
85   
86   var $uid= "";
87   var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
89   var $multiple_support = TRUE;
91   /* Only used  for multiple edit */
92   var $temporary_disable = FALSE;
93   var $no_password_required = FALSE;
94   var $multiple_sambaUserWorkstations = array();
96   function sambaAccount (&$config, $dn= NULL)
97   {
98     /* Load attributes depending on the samba version */
99     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
101     if ($this->samba3){
102       $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
103           "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
104           "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
105           "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
106           "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
107           "sambaUserWorkstations", "sambaPasswordHistory",
108           "sambaLogonHours", "sambaBadPasswordTime",
109           "sambaBadPasswordCount");
110       $this->objectclasses= array ("sambaSamAccount");
111       $this->mungedObject= new sambaMungedDial;
112       $this->ctxattributes= $this->mungedObject->ctxattributes;
113     } else {
114       $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
115           "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
116           "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
117       $this->objectclasses= array ("sambaAccount");
118     }
120     plugin::plugin ($config, $dn);
122     /* Setting uid to default */
123     if(isset($this->attrs['uid'][0])){
124       $this->uid = $this->attrs['uid'][0];
125     }
127     /* Get samba Domain in case of samba 3 */
128     if ($this->samba3 && $this->sambaSID != ""){
129       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
130       $ldap= $this->config->get_ldap_link();
131       $ldap->cd($this->config->current['BASE']);
132       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
133       if ($ldap->count() != 0){
134         $attrs= $ldap->fetch();
135         if(isset($attrs['sambaAlgorithmicRidBase'])){
136           $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
137         } else {
138           $this->ridBase= $this->config->current['RIDBASE'];
139         }
140         if ($this->sambaDomainName == ""){
141           $this->sambaDomainName= $attrs['sambaDomainName'][0];
142         }
143       } else {
144         if ($this->sambaDomainName == ""){
145           $this->sambaDomainName= "DEFAULT";
146         }
147         $this->ridBase= $this->config->current['RIDBASE'];
148         $this->SID= $this->config->current['SID'];
149       }
151       /* Save in order to compare later on */
152       $this->orig_sambaDomainName= $this->sambaDomainName;
153     }
155     /* Fill mungedDial field */
156     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
157       $this->mungedObject->load($this->sambaMungedDial);
158     }
160     /* Password expiery */
161     if(isset($this->attrs['sambaPwdMustChange']) &&
162         $this->attrs['sambaPwdMustChange'][0] != 0){
163       $this->password_expires= 1;
164     }
166     if(isset($this->attrs['sambaLogonTime']) && ! (
167         $this->attrs['sambaLogonTime'][0] == 0 ||
168         $this->attrs['sambaLogonTime'][0] == 2147483647
169       )){
170       $this->logon_time_set= 1;
171     }
172     if(isset($this->attrs['sambaLogoffTime']) && ! (
173         $this->attrs['sambaLogoffTime'][0] == 0 ||
174         $this->attrs['sambaLogoffTime'][0] == 2147483647
175       )){
176       $this->logoff_time_set= 1;
177     }
178     
179     /* Account expiery */
180     if(isset($this->attrs['sambaKickoffTime']) && ! (
181         $this->attrs['sambaKickoffTime'][0] == 0 ||
182         $this->attrs['sambaKickoffTime'][0] == 2147483647
183       )){
184       $this->kickoff_time_set= 1;
185     }
187     /* Get global filter config */
188     if (!session::is_set("sambafilter")){
189       $ui= get_userinfo();
190       $base= get_base_from_people($ui->dn);
191       $sambafilter= array( "depselect" => $base, "regex" => "*");
192       session::set("sambafilter", $sambafilter);
193     }
195     /* Save initial account state */
196     $this->initially_was_account= $this->is_account;
197   }
199   function execute()
200   {
201     /* Call parent execute */
202     plugin::execute();
204     /* Log view */
205     if($this->is_account && !$this->view_logged){
206       $this->view_logged = TRUE;
207       new log("view","users/".get_class($this),$this->dn);
208     }
210     /* Do we need to flip is_account state? */
211     if (isset($_POST['modify_state'])){
212       $this->is_account= !$this->is_account;
213     }
214     /* Do we represent a valid account? */
215     if (!$this->is_account && $this->parent === NULL){
216       $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
217         msgPool::noValidExtension(_("Samba"))."</b>";
218       $display.= back_to_main();
219       return ($display);
220     }
222     $display ="";
223     if(!$this->multiple_support_active){
225       /* Show tab dialog headers */
226       $display= "";
227       if ($this->parent !== NULL){
228         if ($this->is_account){
229           $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Samba")),
230               msgPool::featuresEnabled(_("Samba")));
231         } else {
232           $obj= $this->parent->by_object['posixAccount'];
234           /* Samba3 dependency on posix accounts are enabled
235              in the moment, because I need to rely on unique
236              uidNumbers. There'll be a better solution later
237              on. */
238           if ($obj->is_account){
239             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
240                 msgPool::featuresDisabled(_("Samba")));
241           } else {
242             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
243                 msgPool::featuresDisabled(_("Samba"), _("POSIX")), TRUE);
244           }
245           return ($display);
246         }
247       }
248     }
250     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
252     /* Open Samaba Logong hours dialog */
253     if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
254       $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
255     }
257     /* Cancel dialog */
258     if(isset($_POST['cancel_logonHours'])){
259       $this->dialog = FALSE;
260     }
262     /* Save selected logon hours */
263     if(isset($_POST['save_logonHours'])){
264       $this->dialog->save_object();
265       if($this->acl_is_writeable("sambaLogonHours")){
266         $this->sambaLogonHours = $this->dialog->save();
267       }
268       $this->dialog = FALSE;
269     }
271     /* Display dialog */
272     if((isset($this->dialog)) && (is_object($this->dialog))){
273       $this->dialog->save_object();
274       return($this->dialog->execute());
275     }
277     /* Prepare templating */
278     $smarty= get_smarty();
280     $tmp = $this->plInfo();
281     foreach($tmp['plProvidedAcls'] as $var => $rest){
282       $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
283     }
285     if ($this->sambaPwdMustChange=="0"){
286       $date= getdate();
287     } else {
288       $date= getdate($this->sambaPwdMustChange);
289     }
291     if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
292       $sambaLogonTime_date= getdate();
293     } else {
294       $sambaLogonTime_date= getdate($this->sambaLogonTime);
295     }
296     
297     if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
298       $sambaLogoffTime_date= getdate();
299     } else {
300       $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
301     }
302     
303     if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
304       $sambaKickoffTime_date= getdate();
305     } else {
306       $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
307     }
309     /* Remove user workstations? */
310     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
312       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
314         if($this->multiple_support_active){
315           foreach($_POST['workstation_list'] as $name){
316             if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
317               unset($this->multiple_sambaUserWorkstations[trim($name)]);
318             }
319           } 
320         }else{
321           $tmp= $this->sambaUserWorkstations;
322           foreach($_POST['workstation_list'] as $name){
323             $tmp= preg_replace("/$name/", '', $tmp);
324             $this->is_modified= TRUE;
325           }
326           $tmp= preg_replace('/,+/', ',', $tmp);
327           $this->sambaUserWorkstations= trim($tmp, ',');
328         }
329       }
330     }
332     /* Add user workstation? */
333     if (isset($_POST["add_ws"])){
334       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
335         $this->show_ws_dialog= TRUE;
336         $this->dialog= TRUE;
337       }
338     }
340     /* Add user workstation finished? */
341     if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
342       $this->show_ws_dialog= FALSE;
343       $this->dialog= FALSE;
344     }
346     /* Add user workstation? */
347     if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
349       if($this->multiple_support_active){
350         foreach($_POST['wslist'] as $ws){
351           $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
352         }
353       }else{
354         $tmp= $this->sambaUserWorkstations;
355         foreach($_POST['wslist'] as $ws){
356           $tmp.= ",$ws";
357         }
358         $tmp= preg_replace('/,+/', ',', $tmp);
359         $this->sambaUserWorkstations= trim($tmp, ',');
360       }
361       $this->is_modified= TRUE;
362     }
364     /* Show ws dialog */
365     if ($this->show_ws_dialog){
367       /* Save data */
368       $sambafilter= session::get("sambafilter");
369       foreach( array("depselect", "regex") as $type){
370         if (isset($_POST[$type])){
371           $sambafilter[$type]= $_POST[$type];
372         }
373       }
374       if (isset($_GET['search'])){
375         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
376         if ($s == "**"){
377           $s= "*";
378         }
379         $sambafilter['regex']= $s;
380       }
381       session::set("sambafilter", $sambafilter);
383       /* Get workstation list */
384       $exclude= "";
386       if($this->multiple_support_active){
387         foreach($this->multiple_sambaUserWorkstations as $ws){
388           if($ws['UsedByAllUsers']){
389             $exclude.= "(cn=".$ws['Name']."$)";
390           }
391         }
392       }else{
393         foreach(split(',', $this->sambaUserWorkstations) as $ws){
394           $exclude.= "(cn=$ws$)";
395         }
396       }
397       if ($exclude != ""){
398         $exclude= "(!(|$exclude))";
399       }
400       $regex= $sambafilter['regex'];
401       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
402       $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
403         
404       $wslist= array();
405       foreach ($res as $attrs){
406         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
407       }
408       asort($wslist);
410       $smarty->assign("search_image", get_template_path('images/search.png'));
411       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
412       $smarty->assign("tree_image", get_template_path('images/tree.png'));
413       $smarty->assign("deplist", $this->config->idepartments);
414       $smarty->assign("alphabet", generate_alphabet());
415       foreach( array("depselect", "regex") as $type){
416         $smarty->assign("$type", $sambafilter[$type]);
417       }
418       $smarty->assign("hint", print_sizelimit_warning());
419       $smarty->assign("wslist", $wslist);
420       $smarty->assign("apply", apply_filter());
421       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
422                                 dirname(__FILE__)));
423       return ($display);
424     }
426     /* Fill calendar */
427     $days= array();
428     for($d= 1; $d<32; $d++){
429       $days[]= $d;
430     }
431     $years= array();
432     for($y= $date['year']-4; $y<$date['year']+4; $y++){
433       $years[]= $y;
434     }
435     $months= msgPool::months();
436     $smarty->assign("day", $date["mday"]);
437     $smarty->assign("days", $days);
438     $smarty->assign("months", $months);
439     $smarty->assign("month", $date["mon"]-1);
440     $smarty->assign("years", $years);
441     $smarty->assign("year", $date["year"]);
442     
443     $sambaLogonTime_days= array();
444     for($d= 1; $d<32; $d++){
445       $sambaLogonTime_days[]= $d;
446     }
447     $sambaLogonTime_years= array();
448     for($y= $date['year']-4; $y<$date['year']+4; $y++){
449       $sambaLogonTime_years[]= $y;
450     }
451     $sambaLogonTime_months= msgPool::months;
452     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
453     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
454     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
455     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
456     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
457     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
458     
459     $sambaLogoffTime_days= array();
460     for($d= 1; $d<32; $d++){
461       $sambaLogoffTime_days[]= $d;
462     }
463     $sambaLogoffTime_years= array();
464     for($y= $date['year']-4; $y<$date['year']+4; $y++){
465       $sambaLogoffTime_years[]= $y;
466     }
467     $sambaLogoffTime_months= msgPool::months();
468     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
469     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
470     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
471     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
472     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
473     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
474     
475     $sambaKickoffTime_days= array();
476     for($d= 1; $d<32; $d++){
477       $sambaKickoffTime_days[]= $d;
478     }
479     $sambaKickoffTime_years= array();
480     for($y= $date['year']-4; $y<$date['year']+4; $y++){
481       $sambaKickoffTime_years[]= $y;
482     }
483     $sambaKickoffTime_months= msgPool::months();
484     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
485     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
486     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
487     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
488     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
489     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
490     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
491      
492     /* Fill boxes */
493     if ($this->samba3){
494       $domains= array();
495       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
496         $domains[]= $name;
497       }
498       $smarty->assign("domains", $domains);
499     }
500     $letters= array();
501     for ($i= 68; $i<91; $i++){
502       $letters[]= chr($i).":";
503     }
504     $smarty->assign("drives", $letters);
506     /* Fill terminal server settings */
507     if ($this->samba3){
508       foreach ($this->ctxattributes as $attr){
509         /* Fill common attributes */
510         if (isset($this->mungedObject->ctx[$attr])){
511           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
512           // Set field  to blank if value is 0
513           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
514             if($this->mungedObject->ctx[$attr] == 0) {
515               $smarty->assign("$attr", "");
516             }
517           }
518         } else {
519           $smarty->assign("$attr", "");
520         }
521       }
523       /* Assign enum values for preset items */
524       $shadowModeVals= array( "0" => _("disabled"),
525           "1" => _("input on, notify on"),
526           "2" => _("input on, notify off"),
527           "3" => _("input off, notify on"),
528           "4" => _("input off, nofify off"));
530       $brokenConnModeVals= array(       "0" => _("disconnect"),
531           "1" => _("reset"));
533       $reConnModeVals= array( "0" => _("from any client"),
534           "1" => _("from previous client only"));
536       /* Fill preset items */
537       $smarty->assign("shadow", $shadowModeVals);
538       $smarty->assign("brokenconn", $brokenConnModeVals);
539       $smarty->assign("reconn", $reConnModeVals);
541       /* Fill preset items with values */
542       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
543       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
544       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
546       if(session::get('js')){
547         /* Set form elements to disabled/enable state */
548         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
550         $smarty->assign("inheritstate", "");
551         if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
552           $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
553         }
554       }else{
555         $smarty->assign("tsloginstate", "");
556         $smarty->assign("inheritstate", "");
557       }      
559       /* Set checkboxes to checked or unchecked state */
560       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
561       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
562       $smarty->assign("connectclientdrives",
563                       $this->mungedObject->getConnectClientDrives()?"checked":"");
564       $smarty->assign("connectclientprinters",
565                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
566       $smarty->assign("defaultprinter",
567                       $this->mungedObject->getDefaultPrinter()?"checked":"");
568       $smarty->assign("CtxMaxConnectionTimeF",
569                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
570       $smarty->assign("CtxMaxDisconnectionTimeF",
571                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
572       $smarty->assign("CtxMaxIdleTimeF",
573                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
575       
576       /* Fill sambaUserWorkstations */
577       $ws= split(",", $this->sambaUserWorkstations);
578       sort($ws);
579       
580       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
581       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
583       if($this->multiple_support_active){
584         $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
585       }  
587       $smarty->assign("workstations", $ws);
588     }
590     /* Variables */
591     foreach($this->attributes as $val){
592       $smarty->assign("$val", $this->$val);
593     }
595     /* 'sambaAcctFlags' checkboxes */
596     /* Check for 'lock-account'-flag: 'D' or 'L' */
597     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
598         is_integer(strpos($this->sambaAcctFlags, "L"))) {
599         $smarty->assign("flagsD", "checked");
600     } else {
601         $smarty->assign("flagsD", "");
602     }
603     
604     /* Check for no_password_required flag 'N' */
605     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
606         $smarty->assign("flagsN", "checked");
607     } else {
608         $smarty->assign("flagsN", "");
609     }
611     if($this->samba3){
612       if ($this->sambaPwdCanChange=="1"){
613         $smarty->assign("flagsP", "checked");
614       } else {
615         $smarty->assign("flagsP", "");
616       }
617     }else{
618       if ($this->pwdCanChange=="1"){
619         $smarty->assign("flagsP", "checked");
620       } else {
621         $smarty->assign("flagsP", "");
622       }
623     }
625     if ($this->password_expires=="1"){
626       $smarty->assign("flagsC", "checked");
627     } else {
628       $smarty->assign("flagsC", "");
629     }
630     if ($this->logon_time_set=="1"){
631       $smarty->assign("flagsT", "checked");
632     } else {
633       $smarty->assign("flagsT", "");
634     }
635     if ($this->logoff_time_set=="1"){
636       $smarty->assign("flagsO", "checked");
637     } else {
638       $smarty->assign("flagsO", "");
639     }
640     if ($this->kickoff_time_set=="1"){
641       $smarty->assign("flagsK", "checked");
642     } else {
643       $smarty->assign("flagsK", "");
644     }
645    
647     /* In case of javascript, disable some fields on demand */
648     if ($this->samba3){
649       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
650         $smarty->assign("$key", "$value");
651       }
652     }
655     foreach($this->attributes as $attr){
656       if(in_array($attr,$this->multi_boxes)){
657         $smarty->assign("use_".$attr,TRUE);
658       }else{
659         $smarty->assign("use_".$attr,FALSE);
660       }
661     }
662     foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
663           "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
664           "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
665           "onnectclientprinters","defaultprinter","shadow","brokenconn",
666           "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable", 
667           "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
668           "workstation_list") as $attr){
669       if(in_array($attr,$this->multi_boxes)){
670         $smarty->assign("use_".$attr,TRUE);
671       }else{
672         $smarty->assign("use_".$attr,FALSE);
673       }
674     }
676     if($this->multiple_support_active){
677       $smarty->assign("tsloginstate","");
678     }
680     /* Show main page */
681     $smarty->assign("multiple_support",$this->multiple_support_active);
682     if ($this->samba3){
683       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
684     } else {
685       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
686     }
688     return ($display);
689   }
691   function remove_from_parent()
692   {
693     /* Cancel if there's nothing to do here */
694    if (!$this->initially_was_account){
695      return;
696    }
697     
698     /* include global link_info */
699     $ldap= $this->config->get_ldap_link();
701     plugin::remove_from_parent();
703     /* Keep uid attribute for gosaAccount */
704     unset($this->attrs['uid']);
705     unset($this->attrs['uidNumber']);
706     unset($this->attrs['gidNumber']);
708     /* Remove objectClass for sambaIdmapEntry */
709     $tmp= array();
710     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
711       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
712         $tmp[]= $this->attrs['objectClass'][$i];
713       }
714     }
715     $this->attrs['objectClass']= $tmp;
717     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
718         $this->attributes, "Save");
719     $ldap->cd($this->dn);
720     $this->cleanup();
721     $ldap->modify ($this->attrs); 
723     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
725     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
727     /* Optionally execute a command after we're done */
728     $this->handle_post_events("remove", array("uid" => $this->uid));
729   }
732   /* Check for input problems */
733   function check()
734   {
735     /* Call common method to give check the hook */
736     $message= plugin::check();
738     if ($this->samba3){
740       /* Strings */
741       foreach (array( "sambaHomePath" => _("Home directory"),
742             "sambaProfilePath" => _("Profile path")) as $key => $val){
743         if (!$this->mungedObject->is_samba_path($this->$key)){
744           $message[]= msgPool::invalid($val);
745         }
746       }
748       /* Numeric values */
749       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
750             "CtxMaxDisconnectionTime" => _("Disconnection"),
751             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
753         if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
754           $message[]= msgPool::invalid($val);
755         }
756       }
758       /* Too many workstations? Windows usrmgr only supports eight */
759       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
760         $message[]= _("The windows usermanager allows eight clients at maximum!");
761       }
762     }
764     return ($message);
765   }
768   /* Save data to object */
769   function save_object()
770   {
772     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
774     /* We only care if we are on the sambaTab... */
775     if (isset($_POST['sambaTab'])){
776       plugin::save_object();
778       /* Take care about access options */
779       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
780         if ($this->samba3){
781           $attrname= "sambaPwdCanChange";
782         } else {
783           $attrname= "pwdCanChange";
784         }
785         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
786           $tmp= 1;
787         } else {
788           $tmp= 0;
789         }
790         if ($this->$attrname != $tmp){
791           $this->is_modified= TRUE;
792         }
793         $this->pwdCanChange= $tmp;
794         $this->sambaPwdCanChange= $tmp;
795       }
796       $tmp= "UX";
797       $this->no_password_required = FALSE;
798       if (isset($_POST["no_password_required"])){
799         if ($_POST["no_password_required"] == 1){
800           $tmp.= "N";
801           $this->no_password_required = TRUE;
802         }
803       }
804       if (isset($_POST["password_expires"])){
805         if ($_POST["password_expires"] == 1){
806           $this->password_expires= 1;
807         }
808       } else {
809         $this->password_expires= 0;
810       }
811       $this->temporary_disable = FALSE;
812       if (isset($_POST["temporary_disable"])){
813         if ($_POST["temporary_disable"] == 1){
814           $this->temporary_disable = TRUE;
815           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
816             $tmp.= "L";
817           } else {
818             $tmp.= "D";
819           }
820         }
821       }
822       if (isset($_POST["logon_time_set"])){
823         if ($_POST["logon_time_set"] == 1){
824           $this->logon_time_set= 1;
825         }
826       } else {
827         $this->logon_time_set= 0;
828       }
829       if (isset($_POST["logoff_time_set"])){
830         if ($_POST["logoff_time_set"] == 1){
831           $this->logoff_time_set= 1;
832         }
833       } else {
834         $this->logoff_time_set= 0;
835       }
836       if (isset($_POST["kickoff_time_set"])){
837         if ($_POST["kickoff_time_set"] == 1){
838           $this->kickoff_time_set= 1;
839         }
840       } else {
841         $this->kickoff_time_set= 0;
842       }
843       
844       $fill= "";
845       for ($i= strlen($tmp); $i<12; $i++){
846         $fill.= " ";
847       }
849       $tmp= "[$tmp$fill]";
851       /* Only save if acl's are set */
852       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
853         if ($this->samba3){
854           $attrname= "sambaAcctFlags";
855         } else {
856           $attrname= "acctFlags";
857         }
858         if ($this->$attrname != $tmp){
859           $this->is_modified= TRUE;
860         }
861         $this->$attrname= $tmp;
862       }
864       /* Save sambaDomain attribute */
865       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
866         $this->sambaDomainName= validate($_POST['sambaDomainName']);
867       }
869       /* Save CTX values */
870       if ($this->samba3){
872         /* Save obvious values */
873         foreach($this->ctxattributes as $val){
874           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
875             if (get_magic_quotes_gpc()) {
876               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
877             } else {
878               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
879             }
880           }
881         }
883         /* Save checkbox states. */
884         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
885                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
886         // Need to do some index checking to avoid messages like "index ... not found"
887         if(isset($_POST['brokenconn'])) {
888           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
889                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
890         }
891         if(isset($_POST['reconn'])) {
892           $this->mungedObject->setReConn($_POST['reconn'] == '1'
893                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
894         }
895         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
896                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
897         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
898                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
899         $this->mungedObject->setCtxMaxDisconnectionTimeF(
900                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
901                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
902         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
903                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
904         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
905                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
906         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
907                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
908         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
909                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
911         /* Save combo boxes. Takes two values */
912         if(isset($_POST['reconn'])) {
913           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
914         }
916         /* Check for changes */
917         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
918           $this->is_modified= TRUE;
919         }
920       }
921     }
922   }
925   /* Save to LDAP */
926   function save()
927   {
928     /* Load uid and gid of this 'dn' */
929     $ldap= $this->config->get_ldap_link();
930     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
931     $tmp= $ldap->fetch();
932     $this->uidNumber= $tmp['uidNumber'][0];
933     $this->gidNumber= $tmp['gidNumber'][0];
935     plugin::save();
937     /* Remove objectClass for sambaIdmapEntry */
938     $tmp= array();
939     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
940       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
941         $tmp[]= $this->attrs['objectClass'][$i];
942       }
943     }
944     $this->attrs['objectClass']= $tmp;
946     /* Generate rid / primaryGroupId */
947     if ($this->samba3){
948       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
949         msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
950       } else {
951         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
952         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
953       }
955       /* Need to generate a new uniqe uid/gid combination? */
956       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
957         $uidNumber= $this->uidNumber;
958         while(TRUE){
959           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
960           $ldap->cd($this->config->current['BASE']);
961           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
962           if ($ldap->count() == 0){
963             break;
964           }
965           $uidNumber++;
966         }
967         $this->attrs['sambaSID']= $sid;
969         /* Check for users primary group */
970         $ldap->cd($this->config->current['BASE']);
971         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
972         if ($ldap->count() != 1){
973           msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
974         } else {
975           $attrs= $ldap->fetch();
976           $g= new group($this->config, $ldap->getDN());
977           if ($g->sambaSID == ""){
978             $g->sambaDomainName= $this->sambaDomainName;
979             $g->smbgroup= TRUE;
980             $g->save ();
981           }
982           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
983         }
984       }
986       if ($this->sambaHomeDrive == ""){
987         $this->attrs["sambaHomeDrive"]= array();
988       }
990       /* Generate munged dial value */
991       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
993       /* User wants me to fake the idMappings? This is useful for
994          making winbind resolve the user names in a reasonable amount
995          of time in combination with larger databases. */
996       if (isset($this->config->current['SAMBAIDMAPPING']) &&
997           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
998         $this->attrs['objectClass'][]= "sambaIdmapEntry";
999       }
1002       /* Password expiery */
1003       if ($this->password_expires == "1"){
1004         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1005       } else {
1006         $this->attrs['sambaPwdMustChange']= array();
1007       }
1008       /* Make sure not to save zero in sambaPwdLastset */
1009       if ($this->sambaPwdLastSet != "0"){
1010         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1011       } else {
1012         $this->attrs['sambaPwdLastSet']= array();
1013       }
1014       /* Account expiery */
1015       if ($this->logon_time_set == "1"){
1016         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1017       } else {
1018         $this->attrs['sambaLogonTime']= array();
1019       }
1020       if ($this->logoff_time_set == "1"){
1021         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1022       } else {
1023         $this->attrs['sambaLogoffTime']= array();
1024       }
1025       if ($this->kickoff_time_set == "1"){
1026         # Add one day in unixtime format to be compatible with usrmgr
1027         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1028         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1029       } else {
1030         $this->attrs['sambaKickoffTime']= array();
1031       }
1032     } else {
1033     /* Not samba3 */
1034       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1035       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1037       if ($this->homeDrive == ""){
1038         $this->attrs["homeDrive"]= array();
1039       }
1041       /* Password expiery */
1042       if ($this->password_expires == "1"){
1043         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1044       } else {
1045         $this->attrs['pwdMustChange']= 2147483647;
1046       }
1047       /* Make sure not to save zero in pwdLastset */
1048       if ($this->pwdLastSet != "0"){
1049         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1050       } else {
1051         $this->attrs['pwdLastSet']= array();
1052       }
1053       /* Account expiery */
1054       if ($this->logon_time_set == "1"){
1055         $this->attrs['logonTime']= $this->logonTime;
1056       } else {
1057         $this->attrs['logonTime']= array();
1058       }
1059       if ($this->logoff_time_set == "1"){
1060         $this->attrs['logoffTime']= $this->logoffTime;
1061       } else {
1062         $this->attrs['logoffTime']= array();
1063       }
1064       if ($this->kickoff_time_set == "1"){
1065         # Add one day in unixtime format to be compatible with usrmgr
1066         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1067       } else {
1068         $this->attrs['kickoffTime']= array();
1069       }
1070     }
1072     /* Write back to ldap */
1073     $ldap->cd($this->dn);
1074     $this->cleanup();
1075     $ldap->modify ($this->attrs); 
1077     if($this->initially_was_account){
1078       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1079     }else{
1080       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1081     }
1083     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
1085     /* Optionally execute a command after we're done */
1086     if ($this->initially_was_account == $this->is_account){
1087       if ($this->is_modified){
1088         $this->handle_post_events("modify", array("uid" => $this->uid));
1089       }
1090     } else {
1091       $this->handle_post_events("add", array("uid" => $this->uid));
1092     }
1093   }
1096   /* Force password set, if this account doesn't have any samba passwords  */
1097   function password_change_needed()
1098   {
1099     if(!$this->initially_was_account && $this->is_account){
1100       $ldap = $this->config->get_ldap_link();
1101       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1102       $attrs = $ldap->fetch();
1103       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1104         return(TRUE);
1105       }
1106     }
1107     return(FALSE);
1108   }
1111   function adapt_from_template($dn)
1112   {
1113     plugin::adapt_from_template($dn);
1114     $this->sambaSID= "";
1115     $this->sambaPrimaryGroupSID= "";
1117       /* Fill mungedDial field */
1118     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1119       $this->mungedObject->load($this->sambaMungedDial);
1120     }
1122     /* Password expiery */
1123     if(isset($this->attrs['sambaPwdMustChange']) &&
1124         $this->attrs['sambaPwdMustChange'][0] != 0){
1125       $this->password_expires= 1;
1126     }
1128     if(isset($this->attrs['sambaLogonTime']) && ! (
1129         $this->attrs['sambaLogonTime'][0] == 0 ||
1130         $this->attrs['sambaLogonTime'][0] == 2147483647
1131       )){
1132       $this->logon_time_set= 1;
1133     }
1134     if(isset($this->attrs['sambaLogoffTime']) && ! (
1135         $this->attrs['sambaLogoffTime'][0] == 0 ||
1136         $this->attrs['sambaLogoffTime'][0] == 2147483647
1137       )){
1138       $this->logoff_time_set= 1;
1139     }
1141     /* Account expiery */
1142     if(isset($this->attrs['sambaKickoffTime']) && ! (
1143         $this->attrs['sambaKickoffTime'][0] == 0 ||
1144         $this->attrs['sambaKickoffTime'][0] == 2147483647
1145       )){
1146       $this->kickoff_time_set= 1;
1147     }
1149     /* Get global filter config */
1150     if (!session::is_set("sambafilter")){
1151       $ui= get_userinfo();
1152       $base= get_base_from_people($ui->dn);
1153       $sambafilter= array( "depselect" => $base, "regex" => "*");
1154       session::set("sambafilter", $sambafilter);
1155     }
1156   }
1158   
1159   static function plInfo()
1160   {
1161     return (array(
1162           "plShortName"     => _("Samba"),
1163           "plDescription"   => _("Samba settings"),
1164           "plSelfModify"    => TRUE,
1165           "plDepends"       => array("user"),
1166           "plPriority"      => 5,
1167           "plSection"     => array("personal" => _("My account")),
1168           "plCategory"    => array("users"),
1169           "plOptions"       => array(),
1171           "plProvidedAcls"  => array(
1172             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1173             "InheritClientConfig"         => _("Inherit client config"),
1175             "sambaPwdCanChange"     => _("Allow user to change password") ,
1176             "sambaAcctFlagsN"            => _("Login from windows client requires no password"),
1177             "sambaAcctFlagsL"            => _("Lock samba account"),
1180             "sambaKickoffTime"      => _("Account expires") ,
1181             "sambaPwdMustChange"    => _("Password expires") ,
1183             "sambaLogonTime"        => _("Limit Logon Time") ,
1184             "sambaLogoffTime"       => _("Limit Logoff Time") ,
1185             "sambaLogonHours"       => _("Logon hours") ,
1187             "sambaHomePath"         => _("Generic home directory") ,
1188             "sambaHomeDrive"        => _("Generic samba home drive") ,
1189             "sambaLogonScript"      => _("Generic script path") ,
1190             "sambaProfilePath"      => _("Generic profile path") ,
1191             "sambaDomainName"       => _("Domain") ,
1192             "sambaUserWorkstations" => _("Allow connection from")))
1193               );
1194   }    
1196   function enable_multiple_support()
1197   {
1198     plugin::enable_multiple_support();
1199     if($this->samba3){
1200       $this->multiple_support_active = TRUE;
1201     }else{
1202       $this->multiple_support_active = FALSE;
1203     }
1204   } 
1206   function multiple_save_object()
1207   {
1208     if (isset($_POST['sambaTab'])){
1209       $this->save_object();
1210       plugin::multiple_save_object();
1211       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1212             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1213             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1214             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1215             "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1216             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1217             "workstation_list") as $attr){
1218         if(isset($_POST["use_".$attr])){
1219           $this->multi_boxes[] = $attr;
1220         }
1221       }
1222     }
1223   }
1226   function multiple_check()
1227   {
1228     $message = plugin::multiple_check();
1230     /* Strings */
1231     foreach (array( "sambaHomePath" => _("Home directory"),
1232           "sambaProfilePath" => _("Profile path")) as $key => $val){
1233       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1234         $message[]= msgPool::invalid($val);
1235       }
1236     }
1238     /* Numeric values */
1239     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1240                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1241                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1242       if (in_array($key,$this->multi_boxes) && 
1243           isset($this->mungedObject->ctx[$key]) && 
1244           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1245         $message[]=msgPool::invalid($val);
1246       }
1247     }
1249     /* Too many workstations? Windows usrmgr only supports eight */
1250     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1251       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1252     }
1253     return($message);
1254   }
1256   
1257   function get_multi_init_values()
1258   {
1259     $ret = plugin::get_multi_init_values();
1261     /* Parse given sambaUserWorkstations into array
1262      *  to allow "init_multiple_support()" to detect multiple used workstations.
1263      *  Those workstations will be displayed in light grey.
1264      */
1265     $tmp2 = array("count" => 0);
1266     $tmp = split(",", $this->sambaUserWorkstations);
1267     foreach($tmp as $station){
1268       $station = trim($station);
1269       if(!empty($station)){
1270         $tmp2[] = $station;
1271         $tmp2['count'] ++;
1272       }
1273     } 
1274     $ret['sambaUserWorkstations'] = $tmp2;
1275     return($ret);
1276   }
1280   function init_multiple_support($attrs,$all)
1281   {
1282     plugin::init_multiple_support($attrs,$all);
1284     $this->multiple_sambaUserWorkstations = array();
1285     if(isset($all['sambaUserWorkstations'])){
1286       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1287         $station = trim($all['sambaUserWorkstations'][$i]);
1288         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1289       }
1290     }
1291     if(isset($attrs['sambaUserWorkstations'])){
1292       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1293         $station = trim($attrs['sambaUserWorkstations'][$i]);
1294         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1295       }
1296     }
1297   }
1299   function multiple_execute()
1300   {
1301     return($this->execute());
1302   } 
1304   function get_multi_edit_values()
1305   {
1306     $ret = plugin::get_multi_edit_values();
1308     /* Terminal Server  */
1309     if(in_array("tslogin",$this->multi_boxes)){
1310       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1311     }
1312     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1313       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1314     }
1315     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1316       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1317     }
1318     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1319       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1320     }
1322     if(in_array("inherit",$this->multi_boxes)){
1323       $ret['inherit'] = $this->mungedObject->getInheritMode();
1324     }       
1325     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1326       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1327     } 
1328     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1329       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1330     } 
1332     /* Time Limits. Be careful here, there are some negations  */
1333     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1334       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1335       if(!$ret["CtxMaxConnectionTimeF"]){
1336         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1337       }
1338     }
1339     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1340       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1341       if(!$ret["CtxMaxDisconnectionTimeF"]){
1342         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1343       }
1344     }
1345     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1346       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1347       if(!$ret["CtxMaxIdleTimeF"]){
1348         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1349       }
1350     }
1352     /* Client Devices */
1353     if(in_array("connectclientdrives",$this->multi_boxes)){
1354       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1355     }
1356     if(in_array("connectclientprinters",$this->multi_boxes)){
1357       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1358     }
1359     if(in_array("defaultprinter",$this->multi_boxes)){
1360       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1361     }
1363     /* Misc */
1364     if(in_array("shadow",$this->multi_boxes)){
1365       $ret["shadow"]    =$this->mungedObject->getShadow();
1366     }
1367     if(in_array("brokenconn",$this->multi_boxes)){
1368       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1369     }
1370     if(in_array("reconn",$this->multi_boxes)){
1371       $ret["reconn"]    =$this->mungedObject->getReConn();
1372     }
1374     /* Flags */
1375     if(in_array("allow_pwchange",$this->multi_boxes)){
1376       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1377       $ret['pwdCanChange']      = $this->pwdCanChange;
1378     }
1379   
1380     if(in_array("password_expires",$this->multi_boxes)){
1381       $ret['password_expires']  = $this->password_expires;
1382       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1383     }
1384     if(in_array("logon_time_set",$this->multi_boxes)){
1385       $ret['logon_time_set'] = $this->logon_time_set;
1386       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1387     }
1388     if(in_array("logoff_time_set",$this->multi_boxes)){
1389       $ret['logoff_time_set'] = $this->logoff_time_set;
1390       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1391     }
1392     if(in_array("kickoff_time_set",$this->multi_boxes)){
1393       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1394       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1395     }
1397     if(in_array("no_password_required",$this->multi_boxes)){
1398       $ret['no_password_required'] = $this->no_password_required;
1399     }
1401     if(in_array("temporary_disable",$this->multi_boxes)){
1402       $ret['temporary_disable'] = $this->temporary_disable;
1403     }
1404     
1405     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1406       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1407     }
1409     if(in_array("workstation_list",$this->multi_boxes)){
1410       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1411     }
1412     return($ret);
1413   }
1415   function set_multi_edit_values($values)
1416   {
1417     plugin::set_multi_edit_values($values);
1419     /* Prepare current workstation settings to be merged 
1420      *  with multiple edit settings.
1421      */
1422     if(isset($values['multiple_sambaUserWorkstations'])){
1423       $cur_ws = array();
1424       $m_ws = $values['multiple_sambaUserWorkstations'];
1426       /* Prepare current settings to be merged */
1427       if(isset($this->sambaUserWorkstations)){
1428         $ttmp = split(",",$this->sambaUserWorkstations);
1429         foreach($ttmp as $station){
1430           $station = trim($station);
1431           if(!empty($station)){
1432             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1433           }
1434         }
1435       }
1437       /* Unset removed workstations */
1438       foreach($cur_ws as $cur_name => $cur_station){
1439         if(!isset($m_ws[$cur_name])){
1440           unset($cur_ws[$cur_name]);
1441         }
1442       }
1444       /* Add all added workstations */
1445       foreach($m_ws as $name => $station){
1446         if($station['UsedByAllUsers']){
1447           $cur_ws[$name] = $station;
1448         }
1449       }
1451       $this->sambaUserWorkstations = "";
1452       foreach($cur_ws as $name => $ws){
1453         $this->sambaUserWorkstations .= $name.",";
1454       }
1455       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1456     }
1458     /* Enable disabled terminal login, this is inverted somehow */
1459     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1460   
1461     /* Imherit client configuration */
1462     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1463   
1464     /* Get all ctx values posted */
1465     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1466                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1467     foreach($ctx as $attr){
1468       if(isset($values[$attr])){
1469         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1470       }
1471     }
1473     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1474     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1475     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1477     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1478     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1479     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1481     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1482     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1483     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1485   
1486     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1487     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1489     
1490     
1492     if(isset($values['password_expires'])){
1493       $this->password_expires = $values['password_expires'];
1494       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1495     }
1496     if(isset($values['logon_time_set'])){
1497       $this->logon_time_set = $values['logon_time_set'];
1498       $this->sambaLogonTime = $values['sambaLogonTime'];
1499     }
1500     if(isset($values['logoff_time_set'])){
1501       $this->logoff_time_set = $values['logoff_time_set'];
1502       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1503     }
1504     if(isset($values['kickoff_time_set'])){
1505       $this->kickoff_time_set = $values['kickoff_time_set'];
1506       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1507     }
1509     if(isset($values['no_password_required'])){
1510       if($values['no_password_required']){
1511         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1512           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1513         }
1514       }else{
1515         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1516       }
1517     }      
1519     if(isset($values['temporary_disable'])){
1520       if($values['temporary_disable']){
1521         if(preg_match("/L/",$this->sambaAcctFlags)) {
1522           // Keep L
1523         }else{
1524           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1525         }
1526       }else{
1527         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1528       }
1529     }
1530   }
1533   function PrepareForCopyPaste($source)
1534   {
1535     plugin::PrepareForCopyPaste($source);
1537     /* Set a new SID */
1538     $this->sambaSID = "";
1539   }
1543 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1544 ?>