Code

Added skip to plugins
[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_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/search.png'));
418       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
419       $smarty->assign("tree_image", get_template_path('images/tree.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);
1125     $this->sambaSID= "";
1126     $this->sambaPrimaryGroupSID= "";
1128       /* Fill mungedDial field */
1129     if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1130       $this->mungedObject->load($this->sambaMungedDial);
1131     }
1133     /* Password expiery */
1134     if(isset($this->attrs['sambaPwdMustChange']) &&
1135         $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1136       $this->password_expires= 1;
1137     }
1139     if(isset($this->attrs['sambaLogonTime']) && ! (
1140         $this->attrs['sambaLogonTime'][0] == 0 ||
1141         $this->attrs['sambaLogonTime'][0] == 2147483647
1142       ) && !in_array('sambaLogonTime', $skip)){
1143       $this->logon_time_set= 1;
1144     }
1145     if(isset($this->attrs['sambaLogoffTime']) && ! (
1146         $this->attrs['sambaLogoffTime'][0] == 0 ||
1147         $this->attrs['sambaLogoffTime'][0] == 2147483647
1148       ) && !in_array('sambaLogonTime', $skip)){
1149       $this->logoff_time_set= 1;
1150     }
1152     /* Account expiery */
1153     if(isset($this->attrs['sambaKickoffTime']) && ! (
1154         $this->attrs['sambaKickoffTime'][0] == 0 ||
1155         $this->attrs['sambaKickoffTime'][0] == 2147483647
1156       ) && !in_array('sambaKickoffTime', $skip)){
1157       $this->kickoff_time_set= 1;
1158     }
1160     /* Get global filter config */
1161     if (!session::is_set("sambafilter")){
1162       $ui= get_userinfo();
1163       $base= get_base_from_people($ui->dn);
1164       $sambafilter= array( "depselect" => $base, "regex" => "*");
1165       session::set("sambafilter", $sambafilter);
1166     }
1167   }
1169   
1170   static function plInfo()
1171   {
1172     return (array(
1173           "plShortName"     => _("Samba"),
1174           "plDescription"   => _("Samba settings"),
1175           "plSelfModify"    => TRUE,
1176           "plDepends"       => array("user"),
1177           "plPriority"      => 5,
1178           "plSection"     => array("personal" => _("My account")),
1179           "plCategory"    => array("users"),
1180           "plOptions"       => array(),
1182           "plProvidedAcls"  => array(
1183             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1184             "InheritClientConfig"         => _("Inherit client config"),
1186             "sambaPwdCanChange"     => _("Allow user to change password") ,
1187             "sambaAcctFlagsN"            => _("Login from windows client requires no password"),
1188             "sambaAcctFlagsL"            => _("Lock samba account"),
1191             "sambaKickoffTime"      => _("Account expires") ,
1192             "sambaPwdMustChange"    => _("Password expires") ,
1194             "sambaLogonTime"        => _("Limit Logon Time") ,
1195             "sambaLogoffTime"       => _("Limit Logoff Time") ,
1196             "sambaLogonHours"       => _("Logon hours") ,
1198             "sambaHomePath"         => _("Generic home directory") ,
1199             "sambaHomeDrive"        => _("Generic samba home drive") ,
1200             "sambaLogonScript"      => _("Generic script path") ,
1201             "sambaProfilePath"      => _("Generic profile path") ,
1202             "sambaDomainName"       => _("Domain") ,
1203             "sambaUserWorkstations" => _("Allow connection from")))
1204               );
1205   }    
1207   function enable_multiple_support()
1208   {
1209     plugin::enable_multiple_support();
1210     if($this->samba3){
1211       $this->multiple_support_active = TRUE;
1212     }else{
1213       $this->multiple_support_active = FALSE;
1214     }
1215   } 
1217   function multiple_save_object()
1218   {
1219     if (isset($_POST['sambaTab'])){
1220       $this->save_object();
1221       plugin::multiple_save_object();
1222       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1223             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1224             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1225             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1226             "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1227             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1228             "workstation_list") as $attr){
1229         if(isset($_POST["use_".$attr])){
1230           $this->multi_boxes[] = $attr;
1231         }
1232       }
1233     }
1234   }
1237   function multiple_check()
1238   {
1239     $message = plugin::multiple_check();
1241     /* Strings */
1242     foreach (array( "sambaHomePath" => _("Home directory"),
1243           "sambaProfilePath" => _("Profile path")) as $key => $val){
1244       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1245         $message[]= msgPool::invalid($val);
1246       }
1247     }
1249     /* Numeric values */
1250     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1251                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1252                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1253       if (in_array($key,$this->multi_boxes) && 
1254           isset($this->mungedObject->ctx[$key]) && 
1255           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1256         $message[]=msgPool::invalid($val);
1257       }
1258     }
1260     /* Too many workstations? Windows usrmgr only supports eight */
1261     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1262       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1263     }
1264     return($message);
1265   }
1267   
1268   function get_multi_init_values()
1269   {
1270     $ret = plugin::get_multi_init_values();
1272     /* Parse given sambaUserWorkstations into array
1273      *  to allow "init_multiple_support()" to detect multiple used workstations.
1274      *  Those workstations will be displayed in light grey.
1275      */
1276     $tmp2 = array("count" => 0);
1277     $tmp = split(",", $this->sambaUserWorkstations);
1278     foreach($tmp as $station){
1279       $station = trim($station);
1280       if(!empty($station)){
1281         $tmp2[] = $station;
1282         $tmp2['count'] ++;
1283       }
1284     } 
1285     $ret['sambaUserWorkstations'] = $tmp2;
1286     return($ret);
1287   }
1291   function init_multiple_support($attrs,$all)
1292   {
1293     plugin::init_multiple_support($attrs,$all);
1295     $this->multiple_sambaUserWorkstations = array();
1296     if(isset($all['sambaUserWorkstations'])){
1297       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1298         $station = trim($all['sambaUserWorkstations'][$i]);
1299         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1300       }
1301     }
1302     if(isset($attrs['sambaUserWorkstations'])){
1303       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1304         $station = trim($attrs['sambaUserWorkstations'][$i]);
1305         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1306       }
1307     }
1308   }
1310   function multiple_execute()
1311   {
1312     return($this->execute());
1313   } 
1315   function get_multi_edit_values()
1316   {
1317     $ret = plugin::get_multi_edit_values();
1319     /* Terminal Server  */
1320     if(in_array("tslogin",$this->multi_boxes)){
1321       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1322     }
1323     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1324       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1325     }
1326     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1327       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1328     }
1329     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1330       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1331     }
1333     if(in_array("inherit",$this->multi_boxes)){
1334       $ret['inherit'] = $this->mungedObject->getInheritMode();
1335     }       
1336     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1337       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1338     } 
1339     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1340       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1341     } 
1343     /* Time Limits. Be careful here, there are some negations  */
1344     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1345       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1346       if(!$ret["CtxMaxConnectionTimeF"]){
1347         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1348       }
1349     }
1350     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1351       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1352       if(!$ret["CtxMaxDisconnectionTimeF"]){
1353         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1354       }
1355     }
1356     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1357       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1358       if(!$ret["CtxMaxIdleTimeF"]){
1359         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1360       }
1361     }
1363     /* Client Devices */
1364     if(in_array("connectclientdrives",$this->multi_boxes)){
1365       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1366     }
1367     if(in_array("connectclientprinters",$this->multi_boxes)){
1368       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1369     }
1370     if(in_array("defaultprinter",$this->multi_boxes)){
1371       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1372     }
1374     /* Misc */
1375     if(in_array("shadow",$this->multi_boxes)){
1376       $ret["shadow"]    =$this->mungedObject->getShadow();
1377     }
1378     if(in_array("brokenconn",$this->multi_boxes)){
1379       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1380     }
1381     if(in_array("reconn",$this->multi_boxes)){
1382       $ret["reconn"]    =$this->mungedObject->getReConn();
1383     }
1385     /* Flags */
1386     if(in_array("allow_pwchange",$this->multi_boxes)){
1387       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1388       $ret['pwdCanChange']      = $this->pwdCanChange;
1389     }
1390   
1391     if(in_array("password_expires",$this->multi_boxes)){
1392       $ret['password_expires']  = $this->password_expires;
1393       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1394     }
1395     if(in_array("logon_time_set",$this->multi_boxes)){
1396       $ret['logon_time_set'] = $this->logon_time_set;
1397       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1398     }
1399     if(in_array("logoff_time_set",$this->multi_boxes)){
1400       $ret['logoff_time_set'] = $this->logoff_time_set;
1401       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1402     }
1403     if(in_array("kickoff_time_set",$this->multi_boxes)){
1404       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1405       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1406     }
1408     if(in_array("no_password_required",$this->multi_boxes)){
1409       $ret['no_password_required'] = $this->no_password_required;
1410     }
1412     if(in_array("temporary_disable",$this->multi_boxes)){
1413       $ret['temporary_disable'] = $this->temporary_disable;
1414     }
1415     
1416     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1417       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1418     }
1420     if(in_array("workstation_list",$this->multi_boxes)){
1421       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1422     }
1423     return($ret);
1424   }
1426   function set_multi_edit_values($values)
1427   {
1428     plugin::set_multi_edit_values($values);
1430     /* Prepare current workstation settings to be merged 
1431      *  with multiple edit settings.
1432      */
1433     if(isset($values['multiple_sambaUserWorkstations'])){
1434       $cur_ws = array();
1435       $m_ws = $values['multiple_sambaUserWorkstations'];
1437       /* Prepare current settings to be merged */
1438       if(isset($this->sambaUserWorkstations)){
1439         $ttmp = split(",",$this->sambaUserWorkstations);
1440         foreach($ttmp as $station){
1441           $station = trim($station);
1442           if(!empty($station)){
1443             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1444           }
1445         }
1446       }
1448       /* Unset removed workstations */
1449       foreach($cur_ws as $cur_name => $cur_station){
1450         if(!isset($m_ws[$cur_name])){
1451           unset($cur_ws[$cur_name]);
1452         }
1453       }
1455       /* Add all added workstations */
1456       foreach($m_ws as $name => $station){
1457         if($station['UsedByAllUsers']){
1458           $cur_ws[$name] = $station;
1459         }
1460       }
1462       $this->sambaUserWorkstations = "";
1463       foreach($cur_ws as $name => $ws){
1464         $this->sambaUserWorkstations .= $name.",";
1465       }
1466       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1467     }
1469     /* Enable disabled terminal login, this is inverted somehow */
1470     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1471   
1472     /* Imherit client configuration */
1473     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1474   
1475     /* Get all ctx values posted */
1476     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1477                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1478     foreach($ctx as $attr){
1479       if(isset($values[$attr])){
1480         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1481       }
1482     }
1484     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1485     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1486     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1488     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1489     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1490     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1492     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1493     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1494     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1496   
1497     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1498     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1500     
1501     
1503     if(isset($values['password_expires'])){
1504       $this->password_expires = $values['password_expires'];
1505       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1506     }
1507     if(isset($values['logon_time_set'])){
1508       $this->logon_time_set = $values['logon_time_set'];
1509       $this->sambaLogonTime = $values['sambaLogonTime'];
1510     }
1511     if(isset($values['logoff_time_set'])){
1512       $this->logoff_time_set = $values['logoff_time_set'];
1513       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1514     }
1515     if(isset($values['kickoff_time_set'])){
1516       $this->kickoff_time_set = $values['kickoff_time_set'];
1517       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1518     }
1520     if(isset($values['no_password_required'])){
1521       if($values['no_password_required']){
1522         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1523           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1524         }
1525       }else{
1526         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1527       }
1528     }      
1530     if(isset($values['temporary_disable'])){
1531       if($values['temporary_disable']){
1532         if(preg_match("/L/",$this->sambaAcctFlags)) {
1533           // Keep L
1534         }else{
1535           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1536         }
1537       }else{
1538         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1539       }
1540     }
1541   }
1544   function PrepareForCopyPaste($source)
1545   {
1546     plugin::PrepareForCopyPaste($source);
1548     /* Set a new SID */
1549     $this->sambaSID = "";
1550   }
1554 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1555 ?>