Code

Samba- Updated image dependencies.
[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/small-error.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_cancel"])){
342       $this->show_ws_dialog= FALSE;
343       $this->dialog= FALSE;
344     }
346     /* Add user workstation? */
347     if (isset($_POST["add_ws_finish"])){
349       if (isset($_POST['wslist'])){
350         if($this->multiple_support_active){
351           foreach($_POST['wslist'] as $ws){
352             $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
353           }
354         }else{
355           $tmp= $this->sambaUserWorkstations;
356           foreach($_POST['wslist'] as $ws){
357             $tmp.= ",$ws";
358           }
359           $tmp= preg_replace('/,+/', ',', $tmp);
360           $this->sambaUserWorkstations= trim($tmp, ',');
361         }
362         $this->is_modified= TRUE;
364         $this->show_ws_dialog= FALSE;
365         $this->dialog= FALSE;
366       } else {
367         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
368       }
369     }
371     /* Show ws dialog */
372     if ($this->show_ws_dialog){
374       /* Save data */
375       $sambafilter= session::get("sambafilter");
376       foreach( array("depselect", "regex") as $type){
377         if (isset($_POST[$type])){
378           $sambafilter[$type]= $_POST[$type];
379         }
380       }
381       if (isset($_GET['search'])){
382         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
383         if ($s == "**"){
384           $s= "*";
385         }
386         $sambafilter['regex']= $s;
387       }
388       session::set("sambafilter", $sambafilter);
390       /* Get workstation list */
391       $exclude= "";
393       if($this->multiple_support_active){
394         foreach($this->multiple_sambaUserWorkstations as $ws){
395           if($ws['UsedByAllUsers']){
396             $exclude.= "(cn=".$ws['Name']."$)";
397           }
398         }
399       }else{
400         foreach(split(',', $this->sambaUserWorkstations) as $ws){
401           $exclude.= "(cn=$ws$)";
402         }
403       }
404       if ($exclude != ""){
405         $exclude= "(!(|$exclude))";
406       }
407       $regex= $sambafilter['regex'];
408       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
409       $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
410         
411       $wslist= array();
412       foreach ($res as $attrs){
413         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
414       }
415       asort($wslist);
417       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
418       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
419       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
420       $smarty->assign("deplist", $this->config->idepartments);
421       $smarty->assign("alphabet", generate_alphabet());
422       foreach( array("depselect", "regex") as $type){
423         $smarty->assign("$type", $sambafilter[$type]);
424       }
425       $smarty->assign("hint", print_sizelimit_warning());
426       $smarty->assign("wslist", $wslist);
427       $smarty->assign("apply", apply_filter());
428       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
429                                 dirname(__FILE__)));
430       return ($display);
431     }
433     /* Fill calendar */
434     $days= array();
435     for($d= 1; $d<32; $d++){
436       $days[]= $d;
437     }
438     $years= array();
439     for($y= $date['year']-4; $y<$date['year']+4; $y++){
440       $years[]= $y;
441     }
442     $months= msgPool::months();
443     $smarty->assign("day", $date["mday"]);
444     $smarty->assign("days", $days);
445     $smarty->assign("months", $months);
446     $smarty->assign("month", $date["mon"]-1);
447     $smarty->assign("years", $years);
448     $smarty->assign("year", $date["year"]);
449     
450     $sambaLogonTime_days= array();
451     for($d= 1; $d<32; $d++){
452       $sambaLogonTime_days[]= $d;
453     }
454     $sambaLogonTime_years= array();
455     for($y= $date['year']-4; $y<$date['year']+4; $y++){
456       $sambaLogonTime_years[]= $y;
457     }
458     $sambaLogonTime_months= msgPool::months();
459     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
460     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
461     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
462     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
463     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
464     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
465     
466     $sambaLogoffTime_days= array();
467     for($d= 1; $d<32; $d++){
468       $sambaLogoffTime_days[]= $d;
469     }
470     $sambaLogoffTime_years= array();
471     for($y= $date['year']-4; $y<$date['year']+4; $y++){
472       $sambaLogoffTime_years[]= $y;
473     }
474     $sambaLogoffTime_months= msgPool::months();
475     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
476     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
477     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
478     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
479     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
480     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
481     
482     $sambaKickoffTime_days= array();
483     for($d= 1; $d<32; $d++){
484       $sambaKickoffTime_days[]= $d;
485     }
486     $sambaKickoffTime_years= array();
487     for($y= $date['year']-4; $y<$date['year']+4; $y++){
488       $sambaKickoffTime_years[]= $y;
489     }
490     $sambaKickoffTime_months= msgPool::months();
491     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
492     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
493     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
494     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
495     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
496     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
497     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
498      
499     /* Fill boxes */
500     if ($this->samba3){
501       $domains= array();
502       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
503         $domains[]= $name;
504       }
505       $smarty->assign("domains", $domains);
506     }
507     $letters= array();
508     for ($i= 68; $i<91; $i++){
509       $letters[]= chr($i).":";
510     }
511     $smarty->assign("drives", $letters);
513     /* Fill terminal server settings */
514     if ($this->samba3){
515       foreach ($this->ctxattributes as $attr){
516         /* Fill common attributes */
517         if (isset($this->mungedObject->ctx[$attr])){
518           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
519           // Set field  to blank if value is 0
520           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
521             if($this->mungedObject->ctx[$attr] == 0) {
522               $smarty->assign("$attr", "");
523             }
524           }
525         } else {
526           $smarty->assign("$attr", "");
527         }
528       }
530       /* Assign enum values for preset items */
531       $shadowModeVals= array( "0" => _("disabled"),
532           "1" => _("input on, notify on"),
533           "2" => _("input on, notify off"),
534           "3" => _("input off, notify on"),
535           "4" => _("input off, nofify off"));
537       $brokenConnModeVals= array(       "0" => _("disconnect"),
538           "1" => _("reset"));
540       $reConnModeVals= array( "0" => _("from any client"),
541           "1" => _("from previous client only"));
543       /* Fill preset items */
544       $smarty->assign("shadow", $shadowModeVals);
545       $smarty->assign("brokenconn", $brokenConnModeVals);
546       $smarty->assign("reconn", $reConnModeVals);
548       /* Fill preset items with values */
549       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
550       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
551       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
553       if(session::get('js')){
554         /* Set form elements to disabled/enable state */
555         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
557         $smarty->assign("inheritstate", "");
558         if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
559           $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
560         }
561       }else{
562         $smarty->assign("tsloginstate", "");
563         $smarty->assign("inheritstate", "");
564       }      
566       /* Set checkboxes to checked or unchecked state */
567       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
568       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
569       $smarty->assign("connectclientdrives",
570                       $this->mungedObject->getConnectClientDrives()?"checked":"");
571       $smarty->assign("connectclientprinters",
572                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
573       $smarty->assign("defaultprinter",
574                       $this->mungedObject->getDefaultPrinter()?"checked":"");
575       $smarty->assign("CtxMaxConnectionTimeF",
576                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
577       $smarty->assign("CtxMaxDisconnectionTimeF",
578                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
579       $smarty->assign("CtxMaxIdleTimeF",
580                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
582       
583       /* Fill sambaUserWorkstations */
584       $ws= split(",", $this->sambaUserWorkstations);
585       sort($ws);
586       
587       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
588       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
590       if($this->multiple_support_active){
591         $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
592       }  
594       $smarty->assign("workstations", $ws);
595     }
597     /* Variables */
598     foreach($this->attributes as $val){
599       $smarty->assign("$val", $this->$val);
600     }
602     /* 'sambaAcctFlags' checkboxes */
603     /* Check for 'lock-account'-flag: 'D' or 'L' */
604     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
605         is_integer(strpos($this->sambaAcctFlags, "L"))) {
606         $smarty->assign("flagsD", "checked");
607     } else {
608         $smarty->assign("flagsD", "");
609     }
610     
611     /* Check for no_password_required flag 'N' */
612     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
613         $smarty->assign("flagsN", "checked");
614     } else {
615         $smarty->assign("flagsN", "");
616     }
618     if($this->samba3){
619       if ($this->sambaPwdCanChange=="1"){
620         $smarty->assign("flagsP", "checked");
621       } else {
622         $smarty->assign("flagsP", "");
623       }
624     }else{
625       if ($this->pwdCanChange=="1"){
626         $smarty->assign("flagsP", "checked");
627       } else {
628         $smarty->assign("flagsP", "");
629       }
630     }
632     if ($this->password_expires=="1"){
633       $smarty->assign("flagsC", "checked");
634     } else {
635       $smarty->assign("flagsC", "");
636     }
637     if ($this->logon_time_set=="1"){
638       $smarty->assign("flagsT", "checked");
639     } else {
640       $smarty->assign("flagsT", "");
641     }
642     if ($this->logoff_time_set=="1"){
643       $smarty->assign("flagsO", "checked");
644     } else {
645       $smarty->assign("flagsO", "");
646     }
647     if ($this->kickoff_time_set=="1"){
648       $smarty->assign("flagsK", "checked");
649     } else {
650       $smarty->assign("flagsK", "");
651     }
652    
654     /* In case of javascript, disable some fields on demand */
655     if ($this->samba3){
656       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
657         $smarty->assign("$key", "$value");
658       }
659     }
662     foreach($this->attributes as $attr){
663       if(in_array($attr,$this->multi_boxes)){
664         $smarty->assign("use_".$attr,TRUE);
665       }else{
666         $smarty->assign("use_".$attr,FALSE);
667       }
668     }
669     foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
670           "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
671           "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
672           "onnectclientprinters","defaultprinter","shadow","brokenconn",
673           "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable", 
674           "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
675           "workstation_list") as $attr){
676       if(in_array($attr,$this->multi_boxes)){
677         $smarty->assign("use_".$attr,TRUE);
678       }else{
679         $smarty->assign("use_".$attr,FALSE);
680       }
681     }
683     if($this->multiple_support_active){
684       $smarty->assign("tsloginstate","");
685     }
687     /* Show main page */
688     $smarty->assign("multiple_support",$this->multiple_support_active);
689     if ($this->samba3){
690       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
691     } else {
692       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
693     }
695     return ($display);
696   }
698   function remove_from_parent()
699   {
700     /* Cancel if there's nothing to do here */
701    if (!$this->initially_was_account){
702      return;
703    }
704     
705     /* include global link_info */
706     $ldap= $this->config->get_ldap_link();
708     plugin::remove_from_parent();
710     /* Keep uid attribute for gosaAccount */
711     unset($this->attrs['uid']);
712     unset($this->attrs['uidNumber']);
713     unset($this->attrs['gidNumber']);
715     /* Remove objectClass for sambaIdmapEntry */
716     $tmp= array();
717     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
718       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
719         $tmp[]= $this->attrs['objectClass'][$i];
720       }
721     }
722     $this->attrs['objectClass']= $tmp;
724     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
725         $this->attributes, "Save");
726     $ldap->cd($this->dn);
727     $this->cleanup();
728     $ldap->modify ($this->attrs); 
730     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
732     if (!$ldap->success()){
733       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
734     }
736     /* Optionally execute a command after we're done */
737     $this->handle_post_events("remove", array("uid" => $this->uid));
738   }
741   /* Check for input problems */
742   function check()
743   {
744     /* Call common method to give check the hook */
745     $message= plugin::check();
747     if ($this->samba3){
749       /* Strings */
750       foreach (array( "sambaHomePath" => _("Home directory"),
751             "sambaProfilePath" => _("Profile path")) as $key => $val){
752         if (!$this->mungedObject->is_samba_path($this->$key)){
753           $message[]= msgPool::invalid($val);
754         }
755       }
757       /* Numeric values */
758       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
759             "CtxMaxDisconnectionTime" => _("Disconnection"),
760             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
762         if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
763           $message[]= msgPool::invalid($val);
764         }
765       }
767       /* Too many workstations? Windows usrmgr only supports eight */
768       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
769         $message[]= _("The windows usermanager allows eight clients at maximum!");
770       }
771     }
773     return ($message);
774   }
777   /* Save data to object */
778   function save_object()
779   {
781     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
783     /* We only care if we are on the sambaTab... */
784     if (isset($_POST['sambaTab'])){
785       plugin::save_object();
787       /* Take care about access options */
788       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
789         if ($this->samba3){
790           $attrname= "sambaPwdCanChange";
791         } else {
792           $attrname= "pwdCanChange";
793         }
794         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
795           $tmp= 1;
796         } else {
797           $tmp= 0;
798         }
799         if ($this->$attrname != $tmp){
800           $this->is_modified= TRUE;
801         }
802         $this->pwdCanChange= $tmp;
803         $this->sambaPwdCanChange= $tmp;
804       }
805       $tmp= "UX";
806       $this->no_password_required = FALSE;
807       if (isset($_POST["no_password_required"])){
808         if ($_POST["no_password_required"] == 1){
809           $tmp.= "N";
810           $this->no_password_required = TRUE;
811         }
812       }
813       if (isset($_POST["password_expires"])){
814         if ($_POST["password_expires"] == 1){
815           $this->password_expires= 1;
816         }
817       } else {
818         $this->password_expires= 0;
819       }
820       $this->temporary_disable = FALSE;
821       if (isset($_POST["temporary_disable"])){
822         if ($_POST["temporary_disable"] == 1){
823           $this->temporary_disable = TRUE;
824           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
825             $tmp.= "L";
826           } else {
827             $tmp.= "D";
828           }
829         }
830       }
831       if (isset($_POST["logon_time_set"])){
832         if ($_POST["logon_time_set"] == 1){
833           $this->logon_time_set= 1;
834         }
835       } else {
836         $this->logon_time_set= 0;
837       }
838       if (isset($_POST["logoff_time_set"])){
839         if ($_POST["logoff_time_set"] == 1){
840           $this->logoff_time_set= 1;
841         }
842       } else {
843         $this->logoff_time_set= 0;
844       }
845       if (isset($_POST["kickoff_time_set"])){
846         if ($_POST["kickoff_time_set"] == 1){
847           $this->kickoff_time_set= 1;
848         }
849       } else {
850         $this->kickoff_time_set= 0;
851       }
852       
853       $fill= "";
854       for ($i= strlen($tmp); $i<12; $i++){
855         $fill.= " ";
856       }
858       $tmp= "[$tmp$fill]";
860       /* Only save if acl's are set */
861       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
862         if ($this->samba3){
863           $attrname= "sambaAcctFlags";
864         } else {
865           $attrname= "acctFlags";
866         }
867         if ($this->$attrname != $tmp){
868           $this->is_modified= TRUE;
869         }
870         $this->$attrname= $tmp;
871       }
873       /* Save sambaDomain attribute */
874       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
875         $this->sambaDomainName= validate($_POST['sambaDomainName']);
876       }
878       /* Save CTX values */
879       if ($this->samba3){
881         /* Save obvious values */
882         foreach($this->ctxattributes as $val){
883           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
884             if (get_magic_quotes_gpc()) {
885               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
886             } else {
887               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
888             }
889           }
890         }
892         /* Save checkbox states. */
893         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
894                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
895         // Need to do some index checking to avoid messages like "index ... not found"
896         if(isset($_POST['brokenconn'])) {
897           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
898                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
899         }
900         if(isset($_POST['reconn'])) {
901           $this->mungedObject->setReConn($_POST['reconn'] == '1'
902                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
903         }
904         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
905                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
906         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
907                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
908         $this->mungedObject->setCtxMaxDisconnectionTimeF(
909                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
910                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
911         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
912                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
913         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
914                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
915         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
916                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
917         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
918                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
920         /* Save combo boxes. Takes two values */
921         if(isset($_POST['reconn'])) {
922           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
923         }
925         /* Check for changes */
926         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
927           $this->is_modified= TRUE;
928         }
929       }
930     }
931   }
934   /* Save to LDAP */
935   function save()
936   {
937     /* Load uid and gid of this 'dn' */
938     $ldap= $this->config->get_ldap_link();
939     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
940     $tmp= $ldap->fetch();
941     $this->uidNumber= $tmp['uidNumber'][0];
942     $this->gidNumber= $tmp['gidNumber'][0];
944     plugin::save();
946     /* Remove objectClass for sambaIdmapEntry */
947     $tmp= array();
948     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
949       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
950         $tmp[]= $this->attrs['objectClass'][$i];
951       }
952     }
953     $this->attrs['objectClass']= $tmp;
955     /* Generate rid / primaryGroupId */
956     if ($this->samba3){
957       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
958         msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
959       } else {
960         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
961         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
962       }
964       /* Need to generate a new uniqe uid/gid combination? */
965       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
966         $uidNumber= $this->uidNumber;
967         while(TRUE){
968           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
969           $ldap->cd($this->config->current['BASE']);
970           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
971           if ($ldap->count() == 0){
972             break;
973           }
974           $uidNumber++;
975         }
976         $this->attrs['sambaSID']= $sid;
978         /* Check for users primary group */
979         $ldap->cd($this->config->current['BASE']);
980         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
981         if ($ldap->count() != 1){
982           msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
983         } else {
984           $attrs= $ldap->fetch();
985           $g= new group($this->config, $ldap->getDN());
986           if ($g->sambaSID == ""){
987             $g->sambaDomainName= $this->sambaDomainName;
988             $g->smbgroup= TRUE;
989             $g->save ();
990           }
991           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
992         }
993       }
995       if ($this->sambaHomeDrive == ""){
996         $this->attrs["sambaHomeDrive"]= array();
997       }
999       /* Generate munged dial value */
1000       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1002       /* User wants me to fake the idMappings? This is useful for
1003          making winbind resolve the user names in a reasonable amount
1004          of time in combination with larger databases. */
1005       if (isset($this->config->current['SAMBAIDMAPPING']) &&
1006           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
1007         $this->attrs['objectClass'][]= "sambaIdmapEntry";
1008       }
1011       /* Password expiery */
1012       if ($this->password_expires == "1"){
1013         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1014       } else {
1015         $this->attrs['sambaPwdMustChange']= array();
1016       }
1017       /* Make sure not to save zero in sambaPwdLastset */
1018       if ($this->sambaPwdLastSet != "0"){
1019         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1020       } else {
1021         $this->attrs['sambaPwdLastSet']= array();
1022       }
1023       /* Account expiery */
1024       if ($this->logon_time_set == "1"){
1025         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1026       } else {
1027         $this->attrs['sambaLogonTime']= array();
1028       }
1029       if ($this->logoff_time_set == "1"){
1030         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1031       } else {
1032         $this->attrs['sambaLogoffTime']= array();
1033       }
1034       if ($this->kickoff_time_set == "1"){
1035         # Add one day in unixtime format to be compatible with usrmgr
1036         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1037         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1038       } else {
1039         $this->attrs['sambaKickoffTime']= array();
1040       }
1041     } else {
1042     /* Not samba3 */
1043       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1044       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1046       if ($this->homeDrive == ""){
1047         $this->attrs["homeDrive"]= array();
1048       }
1050       /* Password expiery */
1051       if ($this->password_expires == "1"){
1052         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1053       } else {
1054         $this->attrs['pwdMustChange']= 2147483647;
1055       }
1056       /* Make sure not to save zero in pwdLastset */
1057       if ($this->pwdLastSet != "0"){
1058         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1059       } else {
1060         $this->attrs['pwdLastSet']= array();
1061       }
1062       /* Account expiery */
1063       if ($this->logon_time_set == "1"){
1064         $this->attrs['logonTime']= $this->logonTime;
1065       } else {
1066         $this->attrs['logonTime']= array();
1067       }
1068       if ($this->logoff_time_set == "1"){
1069         $this->attrs['logoffTime']= $this->logoffTime;
1070       } else {
1071         $this->attrs['logoffTime']= array();
1072       }
1073       if ($this->kickoff_time_set == "1"){
1074         # Add one day in unixtime format to be compatible with usrmgr
1075         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1076       } else {
1077         $this->attrs['kickoffTime']= array();
1078       }
1079     }
1081     /* Write back to ldap */
1082     $ldap->cd($this->dn);
1083     $this->cleanup();
1084     $ldap->modify ($this->attrs); 
1086     if($this->initially_was_account){
1087       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1088     }else{
1089       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1090     }
1092     if (!$ldap->success()){
1093       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1094     }
1096     /* Optionally execute a command after we're done */
1097     if ($this->initially_was_account == $this->is_account){
1098       if ($this->is_modified){
1099         $this->handle_post_events("modify", array("uid" => $this->uid));
1100       }
1101     } else {
1102       $this->handle_post_events("add", array("uid" => $this->uid));
1103     }
1104   }
1107   /* Force password set, if this account doesn't have any samba passwords  */
1108   function password_change_needed()
1109   {
1110     if(!$this->initially_was_account && $this->is_account){
1111       $ldap = $this->config->get_ldap_link();
1112       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1113       $attrs = $ldap->fetch();
1114       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1115         return(TRUE);
1116       }
1117     }
1118     return(FALSE);
1119   }
1122   function adapt_from_template($dn, $skip= array())
1123   {
1124     plugin::adapt_from_template($dn, $skip);
1127     $this->sambaSID= "";
1128     $this->sambaPrimaryGroupSID= "";
1130     /* Fill mungedDial field */
1131     if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1132       $this->mungedObject->load($this->sambaMungedDial);
1133     }
1135     /* Adapt munged attributes */
1136     foreach($this->ctxattributes as $attr){
1137       if(isset($this->mungedObject->ctx[$attr]))
1138         $val = $this->mungedObject->ctx[$attr];
1140       foreach (array("sn", "givenName", "uid") as $repl){
1141         if (preg_match("/%$repl/i", $val)){
1142           $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1143         }
1144       }
1145       $this->mungedObject->ctx[$attr] = $val;
1146     }
1148     /* Password expiery */
1149     if(isset($this->attrs['sambaPwdMustChange']) &&
1150         $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1151       $this->password_expires= 1;
1152     }
1154     if(isset($this->attrs['sambaLogonTime']) && ! (
1155         $this->attrs['sambaLogonTime'][0] == 0 ||
1156         $this->attrs['sambaLogonTime'][0] == 2147483647
1157       ) && !in_array('sambaLogonTime', $skip)){
1158       $this->logon_time_set= 1;
1159     }
1160     if(isset($this->attrs['sambaLogoffTime']) && ! (
1161         $this->attrs['sambaLogoffTime'][0] == 0 ||
1162         $this->attrs['sambaLogoffTime'][0] == 2147483647
1163       ) && !in_array('sambaLogonTime', $skip)){
1164       $this->logoff_time_set= 1;
1165     }
1167     /* Account expiery */
1168     if(isset($this->attrs['sambaKickoffTime']) && ! (
1169         $this->attrs['sambaKickoffTime'][0] == 0 ||
1170         $this->attrs['sambaKickoffTime'][0] == 2147483647
1171       ) && !in_array('sambaKickoffTime', $skip)){
1172       $this->kickoff_time_set= 1;
1173     }
1175     /* Get global filter config */
1176     if (!session::is_set("sambafilter")){
1177       $ui= get_userinfo();
1178       $base= get_base_from_people($ui->dn);
1179       $sambafilter= array( "depselect" => $base, "regex" => "*");
1180       session::set("sambafilter", $sambafilter);
1181     }
1182   }
1184   
1185   static function plInfo()
1186   {
1187     return (array(
1188           "plShortName"     => _("Samba"),
1189           "plDescription"   => _("Samba settings"),
1190           "plSelfModify"    => TRUE,
1191           "plDepends"       => array("user"),
1192           "plPriority"      => 5,
1193           "plSection"     => array("personal" => _("My account")),
1194           "plCategory"    => array("users"),
1195           "plOptions"       => array(),
1197           "plProvidedAcls"  => array(
1199             "sambaHomePath"               => _("Generic home directory") ,
1200             "sambaHomeDrive"              => _("Generic samba home drive") ,
1201             "sambaDomainName"             => _("Domain") ,
1202             "sambaLogonScript"            => _("Generic script path") ,
1203             "sambaProfilePath"            => _("Generic profile path") ,
1204             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1205             "InheritClientConfig"         => _("Inherit client config"),
1206             "sambaPwdCanChange"           => _("Allow user to change password") ,
1207             "sambaAcctFlagsN"             => _("Login from windows client requires no password"),
1208             "sambaAcctFlagsL"             => _("Lock samba account"),
1209             "sambaKickoffTime"            => _("Account expires") ,
1210             "sambaPwdMustChange"          => _("Password expires") ,
1211             "sambaLogonTime"              => _("Limit Logon Time") ,
1212             "sambaLogoffTime"             => _("Limit Logoff Time") ,
1213             "sambaLogonHours"             => _("Logon hours") ,
1214             "sambaUserWorkstations"       => _("Allow connection from"))
1215           ));
1216   }    
1218   function enable_multiple_support()
1219   {
1220     plugin::enable_multiple_support();
1221     if($this->samba3){
1222       $this->multiple_support_active = TRUE;
1223     }else{
1224       $this->multiple_support_active = FALSE;
1225     }
1226   } 
1228   function multiple_save_object()
1229   {
1230     if (isset($_POST['sambaTab'])){
1231       $this->save_object();
1232       plugin::multiple_save_object();
1233       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1234             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1235             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1236             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1237             "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1238             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1239             "workstation_list") as $attr){
1240         if(isset($_POST["use_".$attr])){
1241           $this->multi_boxes[] = $attr;
1242         }
1243       }
1244     }
1245   }
1248   function multiple_check()
1249   {
1250     $message = plugin::multiple_check();
1252     /* Strings */
1253     foreach (array( "sambaHomePath" => _("Home directory"),
1254           "sambaProfilePath" => _("Profile path")) as $key => $val){
1255       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1256         $message[]= msgPool::invalid($val);
1257       }
1258     }
1260     /* Numeric values */
1261     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1262                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1263                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1264       if (in_array($key,$this->multi_boxes) && 
1265           isset($this->mungedObject->ctx[$key]) && 
1266           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1267         $message[]=msgPool::invalid($val);
1268       }
1269     }
1271     /* Too many workstations? Windows usrmgr only supports eight */
1272     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1273       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1274     }
1275     return($message);
1276   }
1278   
1279   function get_multi_init_values()
1280   {
1281     $ret = plugin::get_multi_init_values();
1283     /* Parse given sambaUserWorkstations into array
1284      *  to allow "init_multiple_support()" to detect multiple used workstations.
1285      *  Those workstations will be displayed in light grey.
1286      */
1287     $tmp2 = array("count" => 0);
1288     $tmp = split(",", $this->sambaUserWorkstations);
1289     foreach($tmp as $station){
1290       $station = trim($station);
1291       if(!empty($station)){
1292         $tmp2[] = $station;
1293         $tmp2['count'] ++;
1294       }
1295     } 
1296     $ret['sambaUserWorkstations'] = $tmp2;
1297     return($ret);
1298   }
1302   function init_multiple_support($attrs,$all)
1303   {
1304     plugin::init_multiple_support($attrs,$all);
1306     $this->multiple_sambaUserWorkstations = array();
1307     if(isset($all['sambaUserWorkstations'])){
1308       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1309         $station = trim($all['sambaUserWorkstations'][$i]);
1310         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1311       }
1312     }
1313     if(isset($attrs['sambaUserWorkstations'])){
1314       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1315         $station = trim($attrs['sambaUserWorkstations'][$i]);
1316         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1317       }
1318     }
1319   }
1321   function multiple_execute()
1322   {
1323     return($this->execute());
1324   } 
1326   function get_multi_edit_values()
1327   {
1328     $ret = plugin::get_multi_edit_values();
1330     /* Terminal Server  */
1331     if(in_array("tslogin",$this->multi_boxes)){
1332       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1333     }
1334     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1335       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1336     }
1337     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1338       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1339     }
1340     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1341       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1342     }
1344     if(in_array("inherit",$this->multi_boxes)){
1345       $ret['inherit'] = $this->mungedObject->getInheritMode();
1346     }       
1347     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1348       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1349     } 
1350     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1351       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1352     } 
1354     /* Time Limits. Be careful here, there are some negations  */
1355     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1356       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1357       if(!$ret["CtxMaxConnectionTimeF"]){
1358         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1359       }
1360     }
1361     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1362       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1363       if(!$ret["CtxMaxDisconnectionTimeF"]){
1364         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1365       }
1366     }
1367     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1368       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1369       if(!$ret["CtxMaxIdleTimeF"]){
1370         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1371       }
1372     }
1374     /* Client Devices */
1375     if(in_array("connectclientdrives",$this->multi_boxes)){
1376       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1377     }
1378     if(in_array("connectclientprinters",$this->multi_boxes)){
1379       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1380     }
1381     if(in_array("defaultprinter",$this->multi_boxes)){
1382       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1383     }
1385     /* Misc */
1386     if(in_array("shadow",$this->multi_boxes)){
1387       $ret["shadow"]    =$this->mungedObject->getShadow();
1388     }
1389     if(in_array("brokenconn",$this->multi_boxes)){
1390       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1391     }
1392     if(in_array("reconn",$this->multi_boxes)){
1393       $ret["reconn"]    =$this->mungedObject->getReConn();
1394     }
1396     /* Flags */
1397     if(in_array("allow_pwchange",$this->multi_boxes)){
1398       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1399       $ret['pwdCanChange']      = $this->pwdCanChange;
1400     }
1401   
1402     if(in_array("password_expires",$this->multi_boxes)){
1403       $ret['password_expires']  = $this->password_expires;
1404       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1405     }
1406     if(in_array("logon_time_set",$this->multi_boxes)){
1407       $ret['logon_time_set'] = $this->logon_time_set;
1408       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1409     }
1410     if(in_array("logoff_time_set",$this->multi_boxes)){
1411       $ret['logoff_time_set'] = $this->logoff_time_set;
1412       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1413     }
1414     if(in_array("kickoff_time_set",$this->multi_boxes)){
1415       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1416       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1417     }
1419     if(in_array("no_password_required",$this->multi_boxes)){
1420       $ret['no_password_required'] = $this->no_password_required;
1421     }
1423     if(in_array("temporary_disable",$this->multi_boxes)){
1424       $ret['temporary_disable'] = $this->temporary_disable;
1425     }
1426     
1427     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1428       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1429     }
1431     if(in_array("workstation_list",$this->multi_boxes)){
1432       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1433     }
1434     return($ret);
1435   }
1437   function set_multi_edit_values($values)
1438   {
1439     plugin::set_multi_edit_values($values);
1441     /* Prepare current workstation settings to be merged 
1442      *  with multiple edit settings.
1443      */
1444     if(isset($values['multiple_sambaUserWorkstations'])){
1445       $cur_ws = array();
1446       $m_ws = $values['multiple_sambaUserWorkstations'];
1448       /* Prepare current settings to be merged */
1449       if(isset($this->sambaUserWorkstations)){
1450         $ttmp = split(",",$this->sambaUserWorkstations);
1451         foreach($ttmp as $station){
1452           $station = trim($station);
1453           if(!empty($station)){
1454             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1455           }
1456         }
1457       }
1459       /* Unset removed workstations */
1460       foreach($cur_ws as $cur_name => $cur_station){
1461         if(!isset($m_ws[$cur_name])){
1462           unset($cur_ws[$cur_name]);
1463         }
1464       }
1466       /* Add all added workstations */
1467       foreach($m_ws as $name => $station){
1468         if($station['UsedByAllUsers']){
1469           $cur_ws[$name] = $station;
1470         }
1471       }
1473       $this->sambaUserWorkstations = "";
1474       foreach($cur_ws as $name => $ws){
1475         $this->sambaUserWorkstations .= $name.",";
1476       }
1477       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1478     }
1480     /* Enable disabled terminal login, this is inverted somehow */
1481     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1482   
1483     /* Imherit client configuration */
1484     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1485   
1486     /* Get all ctx values posted */
1487     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1488                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1489     foreach($ctx as $attr){
1490       if(isset($values[$attr])){
1491         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1492       }
1493     }
1495     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1496     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1497     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1499     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1500     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1501     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1503     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1504     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1505     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1507   
1508     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1509     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1511     
1512     
1514     if(isset($values['password_expires'])){
1515       $this->password_expires = $values['password_expires'];
1516       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1517     }
1518     if(isset($values['logon_time_set'])){
1519       $this->logon_time_set = $values['logon_time_set'];
1520       $this->sambaLogonTime = $values['sambaLogonTime'];
1521     }
1522     if(isset($values['logoff_time_set'])){
1523       $this->logoff_time_set = $values['logoff_time_set'];
1524       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1525     }
1526     if(isset($values['kickoff_time_set'])){
1527       $this->kickoff_time_set = $values['kickoff_time_set'];
1528       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1529     }
1531     if(isset($values['no_password_required'])){
1532       if($values['no_password_required']){
1533         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1534           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1535         }
1536       }else{
1537         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1538       }
1539     }      
1541     if(isset($values['temporary_disable'])){
1542       if($values['temporary_disable']){
1543         if(preg_match("/L/",$this->sambaAcctFlags)) {
1544           // Keep L
1545         }else{
1546           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1547         }
1548       }else{
1549         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1550       }
1551     }
1552   }
1555   function PrepareForCopyPaste($source)
1556   {
1557     plugin::PrepareForCopyPaste($source);
1559     /* Set a new SID */
1560     $this->sambaSID = "";
1561   }
1565 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1566 ?>