Code

Fixed typo
[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     if (!$ldap->success()){
726       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
727     }
729     /* Optionally execute a command after we're done */
730     $this->handle_post_events("remove", array("uid" => $this->uid));
731   }
734   /* Check for input problems */
735   function check()
736   {
737     /* Call common method to give check the hook */
738     $message= plugin::check();
740     if ($this->samba3){
742       /* Strings */
743       foreach (array( "sambaHomePath" => _("Home directory"),
744             "sambaProfilePath" => _("Profile path")) as $key => $val){
745         if (!$this->mungedObject->is_samba_path($this->$key)){
746           $message[]= msgPool::invalid($val);
747         }
748       }
750       /* Numeric values */
751       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
752             "CtxMaxDisconnectionTime" => _("Disconnection"),
753             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
755         if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
756           $message[]= msgPool::invalid($val);
757         }
758       }
760       /* Too many workstations? Windows usrmgr only supports eight */
761       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
762         $message[]= _("The windows usermanager allows eight clients at maximum!");
763       }
764     }
766     return ($message);
767   }
770   /* Save data to object */
771   function save_object()
772   {
774     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
776     /* We only care if we are on the sambaTab... */
777     if (isset($_POST['sambaTab'])){
778       plugin::save_object();
780       /* Take care about access options */
781       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
782         if ($this->samba3){
783           $attrname= "sambaPwdCanChange";
784         } else {
785           $attrname= "pwdCanChange";
786         }
787         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
788           $tmp= 1;
789         } else {
790           $tmp= 0;
791         }
792         if ($this->$attrname != $tmp){
793           $this->is_modified= TRUE;
794         }
795         $this->pwdCanChange= $tmp;
796         $this->sambaPwdCanChange= $tmp;
797       }
798       $tmp= "UX";
799       $this->no_password_required = FALSE;
800       if (isset($_POST["no_password_required"])){
801         if ($_POST["no_password_required"] == 1){
802           $tmp.= "N";
803           $this->no_password_required = TRUE;
804         }
805       }
806       if (isset($_POST["password_expires"])){
807         if ($_POST["password_expires"] == 1){
808           $this->password_expires= 1;
809         }
810       } else {
811         $this->password_expires= 0;
812       }
813       $this->temporary_disable = FALSE;
814       if (isset($_POST["temporary_disable"])){
815         if ($_POST["temporary_disable"] == 1){
816           $this->temporary_disable = TRUE;
817           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
818             $tmp.= "L";
819           } else {
820             $tmp.= "D";
821           }
822         }
823       }
824       if (isset($_POST["logon_time_set"])){
825         if ($_POST["logon_time_set"] == 1){
826           $this->logon_time_set= 1;
827         }
828       } else {
829         $this->logon_time_set= 0;
830       }
831       if (isset($_POST["logoff_time_set"])){
832         if ($_POST["logoff_time_set"] == 1){
833           $this->logoff_time_set= 1;
834         }
835       } else {
836         $this->logoff_time_set= 0;
837       }
838       if (isset($_POST["kickoff_time_set"])){
839         if ($_POST["kickoff_time_set"] == 1){
840           $this->kickoff_time_set= 1;
841         }
842       } else {
843         $this->kickoff_time_set= 0;
844       }
845       
846       $fill= "";
847       for ($i= strlen($tmp); $i<12; $i++){
848         $fill.= " ";
849       }
851       $tmp= "[$tmp$fill]";
853       /* Only save if acl's are set */
854       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
855         if ($this->samba3){
856           $attrname= "sambaAcctFlags";
857         } else {
858           $attrname= "acctFlags";
859         }
860         if ($this->$attrname != $tmp){
861           $this->is_modified= TRUE;
862         }
863         $this->$attrname= $tmp;
864       }
866       /* Save sambaDomain attribute */
867       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
868         $this->sambaDomainName= validate($_POST['sambaDomainName']);
869       }
871       /* Save CTX values */
872       if ($this->samba3){
874         /* Save obvious values */
875         foreach($this->ctxattributes as $val){
876           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
877             if (get_magic_quotes_gpc()) {
878               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
879             } else {
880               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
881             }
882           }
883         }
885         /* Save checkbox states. */
886         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
887                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
888         // Need to do some index checking to avoid messages like "index ... not found"
889         if(isset($_POST['brokenconn'])) {
890           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
891                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
892         }
893         if(isset($_POST['reconn'])) {
894           $this->mungedObject->setReConn($_POST['reconn'] == '1'
895                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
896         }
897         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
898                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
899         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
900                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
901         $this->mungedObject->setCtxMaxDisconnectionTimeF(
902                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
903                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
904         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
905                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
906         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
907                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
908         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
909                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
910         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
911                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
913         /* Save combo boxes. Takes two values */
914         if(isset($_POST['reconn'])) {
915           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
916         }
918         /* Check for changes */
919         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
920           $this->is_modified= TRUE;
921         }
922       }
923     }
924   }
927   /* Save to LDAP */
928   function save()
929   {
930     /* Load uid and gid of this 'dn' */
931     $ldap= $this->config->get_ldap_link();
932     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
933     $tmp= $ldap->fetch();
934     $this->uidNumber= $tmp['uidNumber'][0];
935     $this->gidNumber= $tmp['gidNumber'][0];
937     plugin::save();
939     /* Remove objectClass for sambaIdmapEntry */
940     $tmp= array();
941     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
942       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
943         $tmp[]= $this->attrs['objectClass'][$i];
944       }
945     }
946     $this->attrs['objectClass']= $tmp;
948     /* Generate rid / primaryGroupId */
949     if ($this->samba3){
950       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
951         msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
952       } else {
953         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
954         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
955       }
957       /* Need to generate a new uniqe uid/gid combination? */
958       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
959         $uidNumber= $this->uidNumber;
960         while(TRUE){
961           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
962           $ldap->cd($this->config->current['BASE']);
963           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
964           if ($ldap->count() == 0){
965             break;
966           }
967           $uidNumber++;
968         }
969         $this->attrs['sambaSID']= $sid;
971         /* Check for users primary group */
972         $ldap->cd($this->config->current['BASE']);
973         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
974         if ($ldap->count() != 1){
975           msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
976         } else {
977           $attrs= $ldap->fetch();
978           $g= new group($this->config, $ldap->getDN());
979           if ($g->sambaSID == ""){
980             $g->sambaDomainName= $this->sambaDomainName;
981             $g->smbgroup= TRUE;
982             $g->save ();
983           }
984           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
985         }
986       }
988       if ($this->sambaHomeDrive == ""){
989         $this->attrs["sambaHomeDrive"]= array();
990       }
992       /* Generate munged dial value */
993       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
995       /* User wants me to fake the idMappings? This is useful for
996          making winbind resolve the user names in a reasonable amount
997          of time in combination with larger databases. */
998       if (isset($this->config->current['SAMBAIDMAPPING']) &&
999           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
1000         $this->attrs['objectClass'][]= "sambaIdmapEntry";
1001       }
1004       /* Password expiery */
1005       if ($this->password_expires == "1"){
1006         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1007       } else {
1008         $this->attrs['sambaPwdMustChange']= array();
1009       }
1010       /* Make sure not to save zero in sambaPwdLastset */
1011       if ($this->sambaPwdLastSet != "0"){
1012         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1013       } else {
1014         $this->attrs['sambaPwdLastSet']= array();
1015       }
1016       /* Account expiery */
1017       if ($this->logon_time_set == "1"){
1018         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1019       } else {
1020         $this->attrs['sambaLogonTime']= array();
1021       }
1022       if ($this->logoff_time_set == "1"){
1023         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1024       } else {
1025         $this->attrs['sambaLogoffTime']= array();
1026       }
1027       if ($this->kickoff_time_set == "1"){
1028         # Add one day in unixtime format to be compatible with usrmgr
1029         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1030         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1031       } else {
1032         $this->attrs['sambaKickoffTime']= array();
1033       }
1034     } else {
1035     /* Not samba3 */
1036       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1037       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1039       if ($this->homeDrive == ""){
1040         $this->attrs["homeDrive"]= array();
1041       }
1043       /* Password expiery */
1044       if ($this->password_expires == "1"){
1045         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1046       } else {
1047         $this->attrs['pwdMustChange']= 2147483647;
1048       }
1049       /* Make sure not to save zero in pwdLastset */
1050       if ($this->pwdLastSet != "0"){
1051         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1052       } else {
1053         $this->attrs['pwdLastSet']= array();
1054       }
1055       /* Account expiery */
1056       if ($this->logon_time_set == "1"){
1057         $this->attrs['logonTime']= $this->logonTime;
1058       } else {
1059         $this->attrs['logonTime']= array();
1060       }
1061       if ($this->logoff_time_set == "1"){
1062         $this->attrs['logoffTime']= $this->logoffTime;
1063       } else {
1064         $this->attrs['logoffTime']= array();
1065       }
1066       if ($this->kickoff_time_set == "1"){
1067         # Add one day in unixtime format to be compatible with usrmgr
1068         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1069       } else {
1070         $this->attrs['kickoffTime']= array();
1071       }
1072     }
1074     /* Write back to ldap */
1075     $ldap->cd($this->dn);
1076     $this->cleanup();
1077     $ldap->modify ($this->attrs); 
1079     if($this->initially_was_account){
1080       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1081     }else{
1082       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1083     }
1085     if (!$ldap->success()){
1086       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1087     }
1089     /* Optionally execute a command after we're done */
1090     if ($this->initially_was_account == $this->is_account){
1091       if ($this->is_modified){
1092         $this->handle_post_events("modify", array("uid" => $this->uid));
1093       }
1094     } else {
1095       $this->handle_post_events("add", array("uid" => $this->uid));
1096     }
1097   }
1100   /* Force password set, if this account doesn't have any samba passwords  */
1101   function password_change_needed()
1102   {
1103     if(!$this->initially_was_account && $this->is_account){
1104       $ldap = $this->config->get_ldap_link();
1105       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1106       $attrs = $ldap->fetch();
1107       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1108         return(TRUE);
1109       }
1110     }
1111     return(FALSE);
1112   }
1115   function adapt_from_template($dn)
1116   {
1117     plugin::adapt_from_template($dn);
1118     $this->sambaSID= "";
1119     $this->sambaPrimaryGroupSID= "";
1121       /* Fill mungedDial field */
1122     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1123       $this->mungedObject->load($this->sambaMungedDial);
1124     }
1126     /* Password expiery */
1127     if(isset($this->attrs['sambaPwdMustChange']) &&
1128         $this->attrs['sambaPwdMustChange'][0] != 0){
1129       $this->password_expires= 1;
1130     }
1132     if(isset($this->attrs['sambaLogonTime']) && ! (
1133         $this->attrs['sambaLogonTime'][0] == 0 ||
1134         $this->attrs['sambaLogonTime'][0] == 2147483647
1135       )){
1136       $this->logon_time_set= 1;
1137     }
1138     if(isset($this->attrs['sambaLogoffTime']) && ! (
1139         $this->attrs['sambaLogoffTime'][0] == 0 ||
1140         $this->attrs['sambaLogoffTime'][0] == 2147483647
1141       )){
1142       $this->logoff_time_set= 1;
1143     }
1145     /* Account expiery */
1146     if(isset($this->attrs['sambaKickoffTime']) && ! (
1147         $this->attrs['sambaKickoffTime'][0] == 0 ||
1148         $this->attrs['sambaKickoffTime'][0] == 2147483647
1149       )){
1150       $this->kickoff_time_set= 1;
1151     }
1153     /* Get global filter config */
1154     if (!session::is_set("sambafilter")){
1155       $ui= get_userinfo();
1156       $base= get_base_from_people($ui->dn);
1157       $sambafilter= array( "depselect" => $base, "regex" => "*");
1158       session::set("sambafilter", $sambafilter);
1159     }
1160   }
1162   
1163   static function plInfo()
1164   {
1165     return (array(
1166           "plShortName"     => _("Samba"),
1167           "plDescription"   => _("Samba settings"),
1168           "plSelfModify"    => TRUE,
1169           "plDepends"       => array("user"),
1170           "plPriority"      => 5,
1171           "plSection"     => array("personal" => _("My account")),
1172           "plCategory"    => array("users"),
1173           "plOptions"       => array(),
1175           "plProvidedAcls"  => array(
1176             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1177             "InheritClientConfig"         => _("Inherit client config"),
1179             "sambaPwdCanChange"     => _("Allow user to change password") ,
1180             "sambaAcctFlagsN"            => _("Login from windows client requires no password"),
1181             "sambaAcctFlagsL"            => _("Lock samba account"),
1184             "sambaKickoffTime"      => _("Account expires") ,
1185             "sambaPwdMustChange"    => _("Password expires") ,
1187             "sambaLogonTime"        => _("Limit Logon Time") ,
1188             "sambaLogoffTime"       => _("Limit Logoff Time") ,
1189             "sambaLogonHours"       => _("Logon hours") ,
1191             "sambaHomePath"         => _("Generic home directory") ,
1192             "sambaHomeDrive"        => _("Generic samba home drive") ,
1193             "sambaLogonScript"      => _("Generic script path") ,
1194             "sambaProfilePath"      => _("Generic profile path") ,
1195             "sambaDomainName"       => _("Domain") ,
1196             "sambaUserWorkstations" => _("Allow connection from")))
1197               );
1198   }    
1200   function enable_multiple_support()
1201   {
1202     plugin::enable_multiple_support();
1203     if($this->samba3){
1204       $this->multiple_support_active = TRUE;
1205     }else{
1206       $this->multiple_support_active = FALSE;
1207     }
1208   } 
1210   function multiple_save_object()
1211   {
1212     if (isset($_POST['sambaTab'])){
1213       $this->save_object();
1214       plugin::multiple_save_object();
1215       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1216             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1217             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1218             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1219             "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1220             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1221             "workstation_list") as $attr){
1222         if(isset($_POST["use_".$attr])){
1223           $this->multi_boxes[] = $attr;
1224         }
1225       }
1226     }
1227   }
1230   function multiple_check()
1231   {
1232     $message = plugin::multiple_check();
1234     /* Strings */
1235     foreach (array( "sambaHomePath" => _("Home directory"),
1236           "sambaProfilePath" => _("Profile path")) as $key => $val){
1237       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1238         $message[]= msgPool::invalid($val);
1239       }
1240     }
1242     /* Numeric values */
1243     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1244                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1245                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1246       if (in_array($key,$this->multi_boxes) && 
1247           isset($this->mungedObject->ctx[$key]) && 
1248           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1249         $message[]=msgPool::invalid($val);
1250       }
1251     }
1253     /* Too many workstations? Windows usrmgr only supports eight */
1254     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1255       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1256     }
1257     return($message);
1258   }
1260   
1261   function get_multi_init_values()
1262   {
1263     $ret = plugin::get_multi_init_values();
1265     /* Parse given sambaUserWorkstations into array
1266      *  to allow "init_multiple_support()" to detect multiple used workstations.
1267      *  Those workstations will be displayed in light grey.
1268      */
1269     $tmp2 = array("count" => 0);
1270     $tmp = split(",", $this->sambaUserWorkstations);
1271     foreach($tmp as $station){
1272       $station = trim($station);
1273       if(!empty($station)){
1274         $tmp2[] = $station;
1275         $tmp2['count'] ++;
1276       }
1277     } 
1278     $ret['sambaUserWorkstations'] = $tmp2;
1279     return($ret);
1280   }
1284   function init_multiple_support($attrs,$all)
1285   {
1286     plugin::init_multiple_support($attrs,$all);
1288     $this->multiple_sambaUserWorkstations = array();
1289     if(isset($all['sambaUserWorkstations'])){
1290       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1291         $station = trim($all['sambaUserWorkstations'][$i]);
1292         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1293       }
1294     }
1295     if(isset($attrs['sambaUserWorkstations'])){
1296       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1297         $station = trim($attrs['sambaUserWorkstations'][$i]);
1298         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1299       }
1300     }
1301   }
1303   function multiple_execute()
1304   {
1305     return($this->execute());
1306   } 
1308   function get_multi_edit_values()
1309   {
1310     $ret = plugin::get_multi_edit_values();
1312     /* Terminal Server  */
1313     if(in_array("tslogin",$this->multi_boxes)){
1314       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1315     }
1316     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1317       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1318     }
1319     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1320       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1321     }
1322     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1323       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1324     }
1326     if(in_array("inherit",$this->multi_boxes)){
1327       $ret['inherit'] = $this->mungedObject->getInheritMode();
1328     }       
1329     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1330       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1331     } 
1332     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1333       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1334     } 
1336     /* Time Limits. Be careful here, there are some negations  */
1337     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1338       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1339       if(!$ret["CtxMaxConnectionTimeF"]){
1340         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1341       }
1342     }
1343     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1344       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1345       if(!$ret["CtxMaxDisconnectionTimeF"]){
1346         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1347       }
1348     }
1349     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1350       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1351       if(!$ret["CtxMaxIdleTimeF"]){
1352         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1353       }
1354     }
1356     /* Client Devices */
1357     if(in_array("connectclientdrives",$this->multi_boxes)){
1358       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1359     }
1360     if(in_array("connectclientprinters",$this->multi_boxes)){
1361       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1362     }
1363     if(in_array("defaultprinter",$this->multi_boxes)){
1364       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1365     }
1367     /* Misc */
1368     if(in_array("shadow",$this->multi_boxes)){
1369       $ret["shadow"]    =$this->mungedObject->getShadow();
1370     }
1371     if(in_array("brokenconn",$this->multi_boxes)){
1372       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1373     }
1374     if(in_array("reconn",$this->multi_boxes)){
1375       $ret["reconn"]    =$this->mungedObject->getReConn();
1376     }
1378     /* Flags */
1379     if(in_array("allow_pwchange",$this->multi_boxes)){
1380       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1381       $ret['pwdCanChange']      = $this->pwdCanChange;
1382     }
1383   
1384     if(in_array("password_expires",$this->multi_boxes)){
1385       $ret['password_expires']  = $this->password_expires;
1386       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1387     }
1388     if(in_array("logon_time_set",$this->multi_boxes)){
1389       $ret['logon_time_set'] = $this->logon_time_set;
1390       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1391     }
1392     if(in_array("logoff_time_set",$this->multi_boxes)){
1393       $ret['logoff_time_set'] = $this->logoff_time_set;
1394       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1395     }
1396     if(in_array("kickoff_time_set",$this->multi_boxes)){
1397       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1398       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1399     }
1401     if(in_array("no_password_required",$this->multi_boxes)){
1402       $ret['no_password_required'] = $this->no_password_required;
1403     }
1405     if(in_array("temporary_disable",$this->multi_boxes)){
1406       $ret['temporary_disable'] = $this->temporary_disable;
1407     }
1408     
1409     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1410       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1411     }
1413     if(in_array("workstation_list",$this->multi_boxes)){
1414       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1415     }
1416     return($ret);
1417   }
1419   function set_multi_edit_values($values)
1420   {
1421     plugin::set_multi_edit_values($values);
1423     /* Prepare current workstation settings to be merged 
1424      *  with multiple edit settings.
1425      */
1426     if(isset($values['multiple_sambaUserWorkstations'])){
1427       $cur_ws = array();
1428       $m_ws = $values['multiple_sambaUserWorkstations'];
1430       /* Prepare current settings to be merged */
1431       if(isset($this->sambaUserWorkstations)){
1432         $ttmp = split(",",$this->sambaUserWorkstations);
1433         foreach($ttmp as $station){
1434           $station = trim($station);
1435           if(!empty($station)){
1436             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1437           }
1438         }
1439       }
1441       /* Unset removed workstations */
1442       foreach($cur_ws as $cur_name => $cur_station){
1443         if(!isset($m_ws[$cur_name])){
1444           unset($cur_ws[$cur_name]);
1445         }
1446       }
1448       /* Add all added workstations */
1449       foreach($m_ws as $name => $station){
1450         if($station['UsedByAllUsers']){
1451           $cur_ws[$name] = $station;
1452         }
1453       }
1455       $this->sambaUserWorkstations = "";
1456       foreach($cur_ws as $name => $ws){
1457         $this->sambaUserWorkstations .= $name.",";
1458       }
1459       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1460     }
1462     /* Enable disabled terminal login, this is inverted somehow */
1463     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1464   
1465     /* Imherit client configuration */
1466     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1467   
1468     /* Get all ctx values posted */
1469     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1470                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1471     foreach($ctx as $attr){
1472       if(isset($values[$attr])){
1473         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1474       }
1475     }
1477     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1478     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1479     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1481     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1482     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1483     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1485     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1486     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1487     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1489   
1490     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1491     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1493     
1494     
1496     if(isset($values['password_expires'])){
1497       $this->password_expires = $values['password_expires'];
1498       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1499     }
1500     if(isset($values['logon_time_set'])){
1501       $this->logon_time_set = $values['logon_time_set'];
1502       $this->sambaLogonTime = $values['sambaLogonTime'];
1503     }
1504     if(isset($values['logoff_time_set'])){
1505       $this->logoff_time_set = $values['logoff_time_set'];
1506       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1507     }
1508     if(isset($values['kickoff_time_set'])){
1509       $this->kickoff_time_set = $values['kickoff_time_set'];
1510       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1511     }
1513     if(isset($values['no_password_required'])){
1514       if($values['no_password_required']){
1515         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1516           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1517         }
1518       }else{
1519         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1520       }
1521     }      
1523     if(isset($values['temporary_disable'])){
1524       if($values['temporary_disable']){
1525         if(preg_match("/L/",$this->sambaAcctFlags)) {
1526           // Keep L
1527         }else{
1528           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1529         }
1530       }else{
1531         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1532       }
1533     }
1534   }
1537   function PrepareForCopyPaste($source)
1538   {
1539     plugin::PrepareForCopyPaste($source);
1541     /* Set a new SID */
1542     $this->sambaSID = "";
1543   }
1547 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1548 ?>