Code

Removed CLI
[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         _("This account has no samba extensions.")."</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(_("Remove samba account"),
230               _("This account has samba features enabled. You can disable them by clicking below."));
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(_("Create samba account"),
240                 _("This account has samba features disabled. You can enable them by clicking below."));
241           } else {
242             $display= $this->show_enable_header(_("Create samba account"),
243                 _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
244           }
245           return ($display);
246         }
247       }
248     }
250     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
252     /* Open Samaba Logong hours dialog */
253     if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
254       $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
255     }
257     /* Cancel dialog */
258     if(isset($_POST['cancel_logonHours'])){
259       $this->dialog = FALSE;
260     }
262     /* Save selected logon hours */
263     if(isset($_POST['save_logonHours'])){
264       $this->dialog->save_object();
265       if($this->acl_is_writeable("sambaLogonHours")){
266         $this->sambaLogonHours = $this->dialog->save();
267       }
268       $this->dialog = FALSE;
269     }
271     /* Display dialog */
272     if((isset($this->dialog)) && (is_object($this->dialog))){
273       $this->dialog->save_object();
274       return($this->dialog->execute());
275     }
277     /* Prepare templating */
278     $smarty= get_smarty();
280     $tmp = $this->plInfo();
281     foreach($tmp['plProvidedAcls'] as $var => $rest){
282       $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
283     }
285     if ($this->sambaPwdMustChange=="0"){
286       $date= getdate();
287     } else {
288       $date= getdate($this->sambaPwdMustChange);
289     }
291     if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
292       $sambaLogonTime_date= getdate();
293     } else {
294       $sambaLogonTime_date= getdate($this->sambaLogonTime);
295     }
296     
297     if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
298       $sambaLogoffTime_date= getdate();
299     } else {
300       $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
301     }
302     
303     if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
304       $sambaKickoffTime_date= getdate();
305     } else {
306       $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
307     }
309     /* Remove user workstations? */
310     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
312       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
314         if($this->multiple_support_active){
315           foreach($_POST['workstation_list'] as $name){
316             if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
317               unset($this->multiple_sambaUserWorkstations[trim($name)]);
318             }
319           } 
320         }else{
321           $tmp= $this->sambaUserWorkstations;
322           foreach($_POST['workstation_list'] as $name){
323             $tmp= preg_replace("/$name/", '', $tmp);
324             $this->is_modified= TRUE;
325           }
326           $tmp= preg_replace('/,+/', ',', $tmp);
327           $this->sambaUserWorkstations= trim($tmp, ',');
328         }
329       }
330     }
332     /* Add user workstation? */
333     if (isset($_POST["add_ws"])){
334       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
335         $this->show_ws_dialog= TRUE;
336         $this->dialog= TRUE;
337       }
338     }
340     /* Add user workstation finished? */
341     if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
342       $this->show_ws_dialog= FALSE;
343       $this->dialog= FALSE;
344     }
346     /* Add user workstation? */
347     if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
349       if($this->multiple_support_active){
350         foreach($_POST['wslist'] as $ws){
351           $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
352         }
353       }else{
354         $tmp= $this->sambaUserWorkstations;
355         foreach($_POST['wslist'] as $ws){
356           $tmp.= ",$ws";
357         }
358         $tmp= preg_replace('/,+/', ',', $tmp);
359         $this->sambaUserWorkstations= trim($tmp, ',');
360       }
361       $this->is_modified= TRUE;
362     }
364     /* Show ws dialog */
365     if ($this->show_ws_dialog){
367       /* Save data */
368       $sambafilter= session::get("sambafilter");
369       foreach( array("depselect", "regex") as $type){
370         if (isset($_POST[$type])){
371           $sambafilter[$type]= $_POST[$type];
372         }
373       }
374       if (isset($_GET['search'])){
375         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
376         if ($s == "**"){
377           $s= "*";
378         }
379         $sambafilter['regex']= $s;
380       }
381       session::set("sambafilter", $sambafilter);
383       /* Get workstation list */
384       $exclude= "";
386       if($this->multiple_support_active){
387         foreach($this->multiple_sambaUserWorkstations as $ws){
388           if($ws['UsedByAllUsers']){
389             $exclude.= "(cn=".$ws['Name']."$)";
390           }
391         }
392       }else{
393         foreach(split(',', $this->sambaUserWorkstations) as $ws){
394           $exclude.= "(cn=$ws$)";
395         }
396       }
397       if ($exclude != ""){
398         $exclude= "(!(|$exclude))";
399       }
400       $regex= $sambafilter['regex'];
401       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
402       $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
403         
404       $wslist= array();
405       foreach ($res as $attrs){
406         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
407       }
408       asort($wslist);
410       $smarty->assign("search_image", get_template_path('images/search.png'));
411       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
412       $smarty->assign("tree_image", get_template_path('images/tree.png'));
413       $smarty->assign("deplist", $this->config->idepartments);
414       $smarty->assign("alphabet", generate_alphabet());
415       foreach( array("depselect", "regex") as $type){
416         $smarty->assign("$type", $sambafilter[$type]);
417       }
418       $smarty->assign("hint", print_sizelimit_warning());
419       $smarty->assign("wslist", $wslist);
420       $smarty->assign("apply", apply_filter());
421       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
422                                 dirname(__FILE__)));
423       return ($display);
424     }
426     /* Fill calendar */
427     $days= array();
428     for($d= 1; $d<32; $d++){
429       $days[]= $d;
430     }
431     $years= array();
432     for($y= $date['year']-4; $y<$date['year']+4; $y++){
433       $years[]= $y;
434     }
435     $months= array(_("January"), _("February"), _("March"), _("April"),
436         _("May"), _("June"), _("July"), _("August"), _("September"),
437         _("October"), _("November"), _("December"));
438     $smarty->assign("day", $date["mday"]);
439     $smarty->assign("days", $days);
440     $smarty->assign("months", $months);
441     $smarty->assign("month", $date["mon"]-1);
442     $smarty->assign("years", $years);
443     $smarty->assign("year", $date["year"]);
444     
445     $sambaLogonTime_days= array();
446     for($d= 1; $d<32; $d++){
447       $sambaLogonTime_days[]= $d;
448     }
449     $sambaLogonTime_years= array();
450     for($y= $date['year']-4; $y<$date['year']+4; $y++){
451       $sambaLogonTime_years[]= $y;
452     }
453     $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
454         _("May"), _("June"), _("July"), _("August"), _("September"),
455         _("October"), _("November"), _("December"));
456     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
457     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
458     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
459     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
460     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
461     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
462     
463     $sambaLogoffTime_days= array();
464     for($d= 1; $d<32; $d++){
465       $sambaLogoffTime_days[]= $d;
466     }
467     $sambaLogoffTime_years= array();
468     for($y= $date['year']-4; $y<$date['year']+4; $y++){
469       $sambaLogoffTime_years[]= $y;
470     }
471     $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
472         _("May"), _("June"), _("July"), _("August"), _("September"),
473         _("October"), _("November"), _("December"));
474     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
475     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
476     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
477     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
478     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
479     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
480     
481     $sambaKickoffTime_days= array();
482     for($d= 1; $d<32; $d++){
483       $sambaKickoffTime_days[]= $d;
484     }
485     $sambaKickoffTime_years= array();
486     for($y= $date['year']-4; $y<$date['year']+4; $y++){
487       $sambaKickoffTime_years[]= $y;
488     }
489     $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
490         _("May"), _("June"), _("July"), _("August"), _("September"),
491         _("October"), _("November"), _("December"));
492     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
493     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
494     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
495     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
496     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
497     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
498     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
499      
500     /* Fill boxes */
501     if ($this->samba3){
502       $domains= array();
503       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
504         $domains[]= $name;
505       }
506       $smarty->assign("domains", $domains);
507     }
508     $letters= array();
509     for ($i= 68; $i<91; $i++){
510       $letters[]= chr($i).":";
511     }
512     $smarty->assign("drives", $letters);
514     /* Fill terminal server settings */
515     if ($this->samba3){
516       foreach ($this->ctxattributes as $attr){
517         /* Fill common attributes */
518         if (isset($this->mungedObject->ctx[$attr])){
519           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
520           // Set field  to blank if value is 0
521           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
522             if($this->mungedObject->ctx[$attr] == 0) {
523               $smarty->assign("$attr", "");
524             }
525           }
526         } else {
527           $smarty->assign("$attr", "");
528         }
529       }
531       /* Assign enum values for preset items */
532       $shadowModeVals= array( "0" => _("disabled"),
533           "1" => _("input on, notify on"),
534           "2" => _("input on, notify off"),
535           "3" => _("input off, notify on"),
536           "4" => _("input off, nofify off"));
538       $brokenConnModeVals= array(       "0" => _("disconnect"),
539           "1" => _("reset"));
541       $reConnModeVals= array( "0" => _("from any client"),
542           "1" => _("from previous client only"));
544       /* Fill preset items */
545       $smarty->assign("shadow", $shadowModeVals);
546       $smarty->assign("brokenconn", $brokenConnModeVals);
547       $smarty->assign("reconn", $reConnModeVals);
549       /* Fill preset items with values */
550       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
551       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
552       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
554       if(session::get('js')){
555         /* Set form elements to disabled/enable state */
556         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
558         $smarty->assign("inheritstate", "");
559         if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
560           $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
561         }
562       }else{
563         $smarty->assign("tsloginstate", "");
564         $smarty->assign("inheritstate", "");
565       }      
567       /* Set checkboxes to checked or unchecked state */
568       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
569       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
570       $smarty->assign("connectclientdrives",
571                       $this->mungedObject->getConnectClientDrives()?"checked":"");
572       $smarty->assign("connectclientprinters",
573                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
574       $smarty->assign("defaultprinter",
575                       $this->mungedObject->getDefaultPrinter()?"checked":"");
576       $smarty->assign("CtxMaxConnectionTimeF",
577                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
578       $smarty->assign("CtxMaxDisconnectionTimeF",
579                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
580       $smarty->assign("CtxMaxIdleTimeF",
581                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
583       
584       /* Fill sambaUserWorkstations */
585       $ws= split(",", $this->sambaUserWorkstations);
586       sort($ws);
587       
588       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
589       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
591       if($this->multiple_support_active){
592         $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
593       }  
595       $smarty->assign("workstations", $ws);
596     }
598     /* Variables */
599     foreach($this->attributes as $val){
600       $smarty->assign("$val", $this->$val);
601     }
603     /* 'sambaAcctFlags' checkboxes */
604     /* Check for 'lock-account'-flag: 'D' or 'L' */
605     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
606         is_integer(strpos($this->sambaAcctFlags, "L"))) {
607         $smarty->assign("flagsD", "checked");
608     } else {
609         $smarty->assign("flagsD", "");
610     }
611     
612     /* Check for no_password_required flag 'N' */
613     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
614         $smarty->assign("flagsN", "checked");
615     } else {
616         $smarty->assign("flagsN", "");
617     }
619     if($this->samba3){
620       if ($this->sambaPwdCanChange=="1"){
621         $smarty->assign("flagsP", "checked");
622       } else {
623         $smarty->assign("flagsP", "");
624       }
625     }else{
626       if ($this->pwdCanChange=="1"){
627         $smarty->assign("flagsP", "checked");
628       } else {
629         $smarty->assign("flagsP", "");
630       }
631     }
633     if ($this->password_expires=="1"){
634       $smarty->assign("flagsC", "checked");
635     } else {
636       $smarty->assign("flagsC", "");
637     }
638     if ($this->logon_time_set=="1"){
639       $smarty->assign("flagsT", "checked");
640     } else {
641       $smarty->assign("flagsT", "");
642     }
643     if ($this->logoff_time_set=="1"){
644       $smarty->assign("flagsO", "checked");
645     } else {
646       $smarty->assign("flagsO", "");
647     }
648     if ($this->kickoff_time_set=="1"){
649       $smarty->assign("flagsK", "checked");
650     } else {
651       $smarty->assign("flagsK", "");
652     }
653    
655     /* In case of javascript, disable some fields on demand */
656     if ($this->samba3){
657       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
658         $smarty->assign("$key", "$value");
659       }
660     }
663     foreach($this->attributes as $attr){
664       if(in_array($attr,$this->multi_boxes)){
665         $smarty->assign("use_".$attr,TRUE);
666       }else{
667         $smarty->assign("use_".$attr,FALSE);
668       }
669     }
670     foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
671           "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
672           "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
673           "onnectclientprinters","defaultprinter","shadow","brokenconn",
674           "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable", 
675           "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
676           "workstation_list") as $attr){
677       if(in_array($attr,$this->multi_boxes)){
678         $smarty->assign("use_".$attr,TRUE);
679       }else{
680         $smarty->assign("use_".$attr,FALSE);
681       }
682     }
684     if($this->multiple_support_active){
685       $smarty->assign("tsloginstate","");
686     }
688     /* Show main page */
689     $smarty->assign("multiple_support",$this->multiple_support_active);
690     if ($this->samba3){
691       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
692     } else {
693       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
694     }
696     return ($display);
697   }
699   function remove_from_parent()
700   {
701     /* Cancel if there's nothing to do here */
702    if (!$this->initially_was_account){
703      return;
704    }
705     
706     /* include global link_info */
707     $ldap= $this->config->get_ldap_link();
709     plugin::remove_from_parent();
711     /* Keep uid attribute for gosaAccount */
712     unset($this->attrs['uid']);
713     unset($this->attrs['uidNumber']);
714     unset($this->attrs['gidNumber']);
716     /* Remove objectClass for sambaIdmapEntry */
717     $tmp= array();
718     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
719       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
720         $tmp[]= $this->attrs['objectClass'][$i];
721       }
722     }
723     $this->attrs['objectClass']= $tmp;
725     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
726         $this->attributes, "Save");
727     $ldap->cd($this->dn);
728     $this->cleanup();
729     $ldap->modify ($this->attrs); 
731     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
733     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
735     /* Optionally execute a command after we're done */
736     $this->handle_post_events("remove", array("uid" => $this->uid));
737   }
740   /* Check for input problems */
741   function check()
742   {
743     /* Call common method to give check the hook */
744     $message= plugin::check();
746     if ($this->samba3){
748       /* Strings */
749       foreach (array( "sambaHomePath" => _("Home directory"),
750             "sambaProfilePath" => _("Profile path")) as $key => $val){
751         if (!$this->mungedObject->is_samba_path($this->$key)){
752           $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
753         }
754       }
756       /* Numeric values */
757       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
758             "CtxMaxDisconnectionTime" => _("Disconnection"),
759             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
761         if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
762           $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
763         }
764       }
766       /* Too many workstations? Windows usrmgr only supports eight */
767       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
768         $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
769       }
770     }
772     return ($message);
773   }
776   /* Save data to object */
777   function save_object()
778   {
780     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
782     /* We only care if we are on the sambaTab... */
783     if (isset($_POST['sambaTab'])){
784       plugin::save_object();
786       /* Take care about access options */
787       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
788         if ($this->samba3){
789           $attrname= "sambaPwdCanChange";
790         } else {
791           $attrname= "pwdCanChange";
792         }
793         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
794           $tmp= 1;
795         } else {
796           $tmp= 0;
797         }
798         if ($this->$attrname != $tmp){
799           $this->is_modified= TRUE;
800         }
801         $this->pwdCanChange= $tmp;
802         $this->sambaPwdCanChange= $tmp;
803       }
804       $tmp= "UX";
805       $this->no_password_required = FALSE;
806       if (isset($_POST["no_password_required"])){
807         if ($_POST["no_password_required"] == 1){
808           $tmp.= "N";
809           $this->no_password_required = TRUE;
810         }
811       }
812       if (isset($_POST["password_expires"])){
813         if ($_POST["password_expires"] == 1){
814           $this->password_expires= 1;
815         }
816       } else {
817         $this->password_expires= 0;
818       }
819       $this->temporary_disable = FALSE;
820       if (isset($_POST["temporary_disable"])){
821         if ($_POST["temporary_disable"] == 1){
822           $this->temporary_disable = TRUE;
823           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
824             $tmp.= "L";
825           } else {
826             $tmp.= "D";
827           }
828         }
829       }
830       if (isset($_POST["logon_time_set"])){
831         if ($_POST["logon_time_set"] == 1){
832           $this->logon_time_set= 1;
833         }
834       } else {
835         $this->logon_time_set= 0;
836       }
837       if (isset($_POST["logoff_time_set"])){
838         if ($_POST["logoff_time_set"] == 1){
839           $this->logoff_time_set= 1;
840         }
841       } else {
842         $this->logoff_time_set= 0;
843       }
844       if (isset($_POST["kickoff_time_set"])){
845         if ($_POST["kickoff_time_set"] == 1){
846           $this->kickoff_time_set= 1;
847         }
848       } else {
849         $this->kickoff_time_set= 0;
850       }
851       
852       $fill= "";
853       for ($i= strlen($tmp); $i<12; $i++){
854         $fill.= " ";
855       }
857       $tmp= "[$tmp$fill]";
859       /* Only save if acl's are set */
860       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
861         if ($this->samba3){
862           $attrname= "sambaAcctFlags";
863         } else {
864           $attrname= "acctFlags";
865         }
866         if ($this->$attrname != $tmp){
867           $this->is_modified= TRUE;
868         }
869         $this->$attrname= $tmp;
870       }
872       /* Save sambaDomain attribute */
873       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
874         $this->sambaDomainName= validate($_POST['sambaDomainName']);
875       }
877       /* Save CTX values */
878       if ($this->samba3){
880         /* Save obvious values */
881         foreach($this->ctxattributes as $val){
882           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
883             if (get_magic_quotes_gpc()) {
884               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
885             } else {
886               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
887             }
888           }
889         }
891         /* Save checkbox states. */
892         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
893                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
894         // Need to do some index checking to avoid messages like "index ... not found"
895         if(isset($_POST['brokenconn'])) {
896           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
897                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
898         }
899         if(isset($_POST['reconn'])) {
900           $this->mungedObject->setReConn($_POST['reconn'] == '1'
901                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
902         }
903         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
904                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
905         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
906                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
907         $this->mungedObject->setCtxMaxDisconnectionTimeF(
908                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
909                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
910         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
911                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
912         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
913                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
914         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
915                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
916         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
917                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
919         /* Save combo boxes. Takes two values */
920         if(isset($_POST['reconn'])) {
921           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
922         }
924         /* Check for changes */
925         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
926           $this->is_modified= TRUE;
927         }
928       }
929     }
930   }
933   /* Save to LDAP */
934   function save()
935   {
936     /* Load uid and gid of this 'dn' */
937     $ldap= $this->config->get_ldap_link();
938     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
939     $tmp= $ldap->fetch();
940     $this->uidNumber= $tmp['uidNumber'][0];
941     $this->gidNumber= $tmp['gidNumber'][0];
943     plugin::save();
945     /* Remove objectClass for sambaIdmapEntry */
946     $tmp= array();
947     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
948       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
949         $tmp[]= $this->attrs['objectClass'][$i];
950       }
951     }
952     $this->attrs['objectClass']= $tmp;
954     /* Generate rid / primaryGroupId */
955     if ($this->samba3){
956       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
957         msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
958       } else {
959         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
960         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
961       }
963       /* Need to generate a new uniqe uid/gid combination? */
964       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
965         $uidNumber= $this->uidNumber;
966         while(TRUE){
967           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
968           $ldap->cd($this->config->current['BASE']);
969           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
970           if ($ldap->count() == 0){
971             break;
972           }
973           $uidNumber++;
974         }
975         $this->attrs['sambaSID']= $sid;
977         /* Check for users primary group */
978         $ldap->cd($this->config->current['BASE']);
979         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
980         if ($ldap->count() != 1){
981           msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
982         } else {
983           $attrs= $ldap->fetch();
984           $g= new group($this->config, $ldap->getDN());
985           if ($g->sambaSID == ""){
986             $g->sambaDomainName= $this->sambaDomainName;
987             $g->smbgroup= TRUE;
988             $g->save ();
989           }
990           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
991         }
992       }
994       if ($this->sambaHomeDrive == ""){
995         $this->attrs["sambaHomeDrive"]= array();
996       }
998       /* Generate munged dial value */
999       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1001       /* User wants me to fake the idMappings? This is useful for
1002          making winbind resolve the user names in a reasonable amount
1003          of time in combination with larger databases. */
1004       if (isset($this->config->current['SAMBAIDMAPPING']) &&
1005           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
1006         $this->attrs['objectClass'][]= "sambaIdmapEntry";
1007       }
1010       /* Password expiery */
1011       if ($this->password_expires == "1"){
1012         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1013       } else {
1014         $this->attrs['sambaPwdMustChange']= array();
1015       }
1016       /* Make sure not to save zero in sambaPwdLastset */
1017       if ($this->sambaPwdLastSet != "0"){
1018         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1019       } else {
1020         $this->attrs['sambaPwdLastSet']= array();
1021       }
1022       /* Account expiery */
1023       if ($this->logon_time_set == "1"){
1024         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1025       } else {
1026         $this->attrs['sambaLogonTime']= array();
1027       }
1028       if ($this->logoff_time_set == "1"){
1029         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1030       } else {
1031         $this->attrs['sambaLogoffTime']= array();
1032       }
1033       if ($this->kickoff_time_set == "1"){
1034         # Add one day in unixtime format to be compatible with usrmgr
1035         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1036         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1037       } else {
1038         $this->attrs['sambaKickoffTime']= array();
1039       }
1040     } else {
1041     /* Not samba3 */
1042       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1043       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1045       if ($this->homeDrive == ""){
1046         $this->attrs["homeDrive"]= array();
1047       }
1049       /* Password expiery */
1050       if ($this->password_expires == "1"){
1051         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1052       } else {
1053         $this->attrs['pwdMustChange']= 2147483647;
1054       }
1055       /* Make sure not to save zero in pwdLastset */
1056       if ($this->pwdLastSet != "0"){
1057         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1058       } else {
1059         $this->attrs['pwdLastSet']= array();
1060       }
1061       /* Account expiery */
1062       if ($this->logon_time_set == "1"){
1063         $this->attrs['logonTime']= $this->logonTime;
1064       } else {
1065         $this->attrs['logonTime']= array();
1066       }
1067       if ($this->logoff_time_set == "1"){
1068         $this->attrs['logoffTime']= $this->logoffTime;
1069       } else {
1070         $this->attrs['logoffTime']= array();
1071       }
1072       if ($this->kickoff_time_set == "1"){
1073         # Add one day in unixtime format to be compatible with usrmgr
1074         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1075       } else {
1076         $this->attrs['kickoffTime']= array();
1077       }
1078     }
1080     /* Write back to ldap */
1081     $ldap->cd($this->dn);
1082     $this->cleanup();
1083     $ldap->modify ($this->attrs); 
1085     if($this->initially_was_account){
1086       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1087     }else{
1088       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1089     }
1091     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
1093     /* Optionally execute a command after we're done */
1094     if ($this->initially_was_account == $this->is_account){
1095       if ($this->is_modified){
1096         $this->handle_post_events("modify", array("uid" => $this->uid));
1097       }
1098     } else {
1099       $this->handle_post_events("add", array("uid" => $this->uid));
1100     }
1101   }
1104   /* Force password set, if this account doesn't have any samba passwords  */
1105   function password_change_needed()
1106   {
1107     if(!$this->initially_was_account && $this->is_account){
1108       $ldap = $this->config->get_ldap_link();
1109       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1110       $attrs = $ldap->fetch();
1111       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1112         return(TRUE);
1113       }
1114     }
1115     return(FALSE);
1116   }
1119   function adapt_from_template($dn)
1120   {
1121     plugin::adapt_from_template($dn);
1122     $this->sambaSID= "";
1123     $this->sambaPrimaryGroupSID= "";
1125       /* Fill mungedDial field */
1126     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1127       $this->mungedObject->load($this->sambaMungedDial);
1128     }
1130     /* Password expiery */
1131     if(isset($this->attrs['sambaPwdMustChange']) &&
1132         $this->attrs['sambaPwdMustChange'][0] != 0){
1133       $this->password_expires= 1;
1134     }
1136     if(isset($this->attrs['sambaLogonTime']) && ! (
1137         $this->attrs['sambaLogonTime'][0] == 0 ||
1138         $this->attrs['sambaLogonTime'][0] == 2147483647
1139       )){
1140       $this->logon_time_set= 1;
1141     }
1142     if(isset($this->attrs['sambaLogoffTime']) && ! (
1143         $this->attrs['sambaLogoffTime'][0] == 0 ||
1144         $this->attrs['sambaLogoffTime'][0] == 2147483647
1145       )){
1146       $this->logoff_time_set= 1;
1147     }
1149     /* Account expiery */
1150     if(isset($this->attrs['sambaKickoffTime']) && ! (
1151         $this->attrs['sambaKickoffTime'][0] == 0 ||
1152         $this->attrs['sambaKickoffTime'][0] == 2147483647
1153       )){
1154       $this->kickoff_time_set= 1;
1155     }
1157     /* Get global filter config */
1158     if (!session::is_set("sambafilter")){
1159       $ui= get_userinfo();
1160       $base= get_base_from_people($ui->dn);
1161       $sambafilter= array( "depselect" => $base, "regex" => "*");
1162       session::set("sambafilter", $sambafilter);
1163     }
1164   }
1166   
1167   static function plInfo()
1168   {
1169     return (array(
1170           "plShortName"     => _("Samba"),
1171           "plDescription"   => _("Samba settings"),
1172           "plSelfModify"    => TRUE,
1173           "plDepends"       => array("user"),
1174           "plPriority"      => 5,
1175           "plSection"     => array("personal" => _("My account")),
1176           "plCategory"    => array("users"),
1177           "plOptions"       => array(),
1179           "plProvidedAcls"  => array(
1180             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1181             "InheritClientConfig"         => _("Inherit client config"),
1183             "sambaPwdCanChange"     => _("Allow user to change password") ,
1184             "sambaAcctFlagsN"            => _("Login from windows client requires no password"),
1185             "sambaAcctFlagsL"            => _("Lock samba account"),
1188             "sambaKickoffTime"      => _("Account expires") ,
1189             "sambaPwdMustChange"    => _("Password expires") ,
1191             "sambaLogonTime"        => _("Limit Logon Time") ,
1192             "sambaLogoffTime"       => _("Limit Logoff Time") ,
1193             "sambaLogonHours"       => _("Logon hours") ,
1195             "sambaHomePath"         => _("Generic home directory") ,
1196             "sambaHomeDrive"        => _("Generic samba home drive") ,
1197             "sambaLogonScript"      => _("Generic script path") ,
1198             "sambaProfilePath"      => _("Generic profile path") ,
1199             "sambaDomainName"       => _("Domain") ,
1200             "sambaUserWorkstations" => _("Allow connection from")))
1201               );
1202   }    
1204   function enable_multiple_support()
1205   {
1206     plugin::enable_multiple_support();
1207     if($this->samba3){
1208       $this->multiple_support_active = TRUE;
1209     }else{
1210       $this->multiple_support_active = FALSE;
1211     }
1212   } 
1214   function multiple_save_object()
1215   {
1216     if (isset($_POST['sambaTab'])){
1217       $this->save_object();
1218       plugin::multiple_save_object();
1219       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1220             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1221             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1222             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1223             "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1224             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1225             "workstation_list") as $attr){
1226         if(isset($_POST["use_".$attr])){
1227           $this->multi_boxes[] = $attr;
1228         }
1229       }
1230     }
1231   }
1234   function multiple_check()
1235   {
1236     $message = plugin::multiple_check();
1238     /* Strings */
1239     foreach (array( "sambaHomePath" => _("Home directory"),
1240           "sambaProfilePath" => _("Profile path")) as $key => $val){
1241       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1242         $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
1243       }
1244     }
1246     /* Numeric values */
1247     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1248                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1249                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1250       if (in_array($key,$this->multi_boxes) && 
1251           isset($this->mungedObject->ctx[$key]) && 
1252           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1253         $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
1254       }
1255     }
1257     /* Too many workstations? Windows usrmgr only supports eight */
1258     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1259       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1260     }
1261     return($message);
1262   }
1264   
1265   function get_multi_init_values()
1266   {
1267     $ret = plugin::get_multi_init_values();
1269     /* Parse given sambaUserWorkstations into array
1270      *  to allow "init_multiple_support()" to detect multiple used workstations.
1271      *  Those workstations will be displayed in light grey.
1272      */
1273     $tmp2 = array("count" => 0);
1274     $tmp = split(",", $this->sambaUserWorkstations);
1275     foreach($tmp as $station){
1276       $station = trim($station);
1277       if(!empty($station)){
1278         $tmp2[] = $station;
1279         $tmp2['count'] ++;
1280       }
1281     } 
1282     $ret['sambaUserWorkstations'] = $tmp2;
1283     return($ret);
1284   }
1288   function init_multiple_support($attrs,$all)
1289   {
1290     plugin::init_multiple_support($attrs,$all);
1292     $this->multiple_sambaUserWorkstations = array();
1293     if(isset($all['sambaUserWorkstations'])){
1294       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1295         $station = trim($all['sambaUserWorkstations'][$i]);
1296         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1297       }
1298     }
1299     if(isset($attrs['sambaUserWorkstations'])){
1300       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1301         $station = trim($attrs['sambaUserWorkstations'][$i]);
1302         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1303       }
1304     }
1305   }
1307   function multiple_execute()
1308   {
1309     return($this->execute());
1310   } 
1312   function get_multi_edit_values()
1313   {
1314     $ret = plugin::get_multi_edit_values();
1316     /* Terminal Server  */
1317     if(in_array("tslogin",$this->multi_boxes)){
1318       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1319     }
1320     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1321       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1322     }
1323     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1324       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1325     }
1326     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1327       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1328     }
1330     if(in_array("inherit",$this->multi_boxes)){
1331       $ret['inherit'] = $this->mungedObject->getInheritMode();
1332     }       
1333     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1334       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1335     } 
1336     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1337       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1338     } 
1340     /* Time Limits. Be careful here, there are some negations  */
1341     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1342       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1343       if(!$ret["CtxMaxConnectionTimeF"]){
1344         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1345       }
1346     }
1347     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1348       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1349       if(!$ret["CtxMaxDisconnectionTimeF"]){
1350         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1351       }
1352     }
1353     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1354       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1355       if(!$ret["CtxMaxIdleTimeF"]){
1356         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1357       }
1358     }
1360     /* Client Devices */
1361     if(in_array("connectclientdrives",$this->multi_boxes)){
1362       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1363     }
1364     if(in_array("connectclientprinters",$this->multi_boxes)){
1365       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1366     }
1367     if(in_array("defaultprinter",$this->multi_boxes)){
1368       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1369     }
1371     /* Misc */
1372     if(in_array("shadow",$this->multi_boxes)){
1373       $ret["shadow"]    =$this->mungedObject->getShadow();
1374     }
1375     if(in_array("brokenconn",$this->multi_boxes)){
1376       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1377     }
1378     if(in_array("reconn",$this->multi_boxes)){
1379       $ret["reconn"]    =$this->mungedObject->getReConn();
1380     }
1382     /* Flags */
1383     if(in_array("allow_pwchange",$this->multi_boxes)){
1384       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1385       $ret['pwdCanChange']      = $this->pwdCanChange;
1386     }
1387   
1388     if(in_array("password_expires",$this->multi_boxes)){
1389       $ret['password_expires']  = $this->password_expires;
1390       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1391     }
1392     if(in_array("logon_time_set",$this->multi_boxes)){
1393       $ret['logon_time_set'] = $this->logon_time_set;
1394       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1395     }
1396     if(in_array("logoff_time_set",$this->multi_boxes)){
1397       $ret['logoff_time_set'] = $this->logoff_time_set;
1398       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1399     }
1400     if(in_array("kickoff_time_set",$this->multi_boxes)){
1401       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1402       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1403     }
1405     if(in_array("no_password_required",$this->multi_boxes)){
1406       $ret['no_password_required'] = $this->no_password_required;
1407     }
1409     if(in_array("temporary_disable",$this->multi_boxes)){
1410       $ret['temporary_disable'] = $this->temporary_disable;
1411     }
1412     
1413     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1414       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1415     }
1417     if(in_array("workstation_list",$this->multi_boxes)){
1418       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1419     }
1420     return($ret);
1421   }
1423   function set_multi_edit_values($values)
1424   {
1425     plugin::set_multi_edit_values($values);
1427     /* Prepare current workstation settings to be merged 
1428      *  with multiple edit settings.
1429      */
1430     if(isset($values['multiple_sambaUserWorkstations'])){
1431       $cur_ws = array();
1432       $m_ws = $values['multiple_sambaUserWorkstations'];
1434       /* Prepare current settings to be merged */
1435       if(isset($this->sambaUserWorkstations)){
1436         $ttmp = split(",",$this->sambaUserWorkstations);
1437         foreach($ttmp as $station){
1438           $station = trim($station);
1439           if(!empty($station)){
1440             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1441           }
1442         }
1443       }
1445       /* Unset removed workstations */
1446       foreach($cur_ws as $cur_name => $cur_station){
1447         if(!isset($m_ws[$cur_name])){
1448           unset($cur_ws[$cur_name]);
1449         }
1450       }
1452       /* Add all added workstations */
1453       foreach($m_ws as $name => $station){
1454         if($station['UsedByAllUsers']){
1455           $cur_ws[$name] = $station;
1456         }
1457       }
1459       $this->sambaUserWorkstations = "";
1460       foreach($cur_ws as $name => $ws){
1461         $this->sambaUserWorkstations .= $name.",";
1462       }
1463       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1464     }
1466     /* Enable disabled terminal login, this is inverted somehow */
1467     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1468   
1469     /* Imherit client configuration */
1470     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1471   
1472     /* Get all ctx values posted */
1473     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1474                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1475     foreach($ctx as $attr){
1476       if(isset($values[$attr])){
1477         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1478       }
1479     }
1481     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1482     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1483     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1485     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1486     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1487     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1489     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1490     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1491     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1493   
1494     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1495     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1497     
1498     
1500     if(isset($values['password_expires'])){
1501       $this->password_expires = $values['password_expires'];
1502       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1503     }
1504     if(isset($values['logon_time_set'])){
1505       $this->logon_time_set = $values['logon_time_set'];
1506       $this->sambaLogonTime = $values['sambaLogonTime'];
1507     }
1508     if(isset($values['logoff_time_set'])){
1509       $this->logoff_time_set = $values['logoff_time_set'];
1510       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1511     }
1512     if(isset($values['kickoff_time_set'])){
1513       $this->kickoff_time_set = $values['kickoff_time_set'];
1514       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1515     }
1517     if(isset($values['no_password_required'])){
1518       if($values['no_password_required']){
1519         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1520           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1521         }
1522       }else{
1523         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1524       }
1525     }      
1527     if(isset($values['temporary_disable'])){
1528       if($values['temporary_disable']){
1529         if(preg_match("/L/",$this->sambaAcctFlags)) {
1530           // Keep L
1531         }else{
1532           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1533         }
1534       }else{
1535         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1536       }
1537     }
1538   }
1541   function PrepareForCopyPaste($source)
1542   {
1543     plugin::PrepareForCopyPaste($source);
1545     /* Set a new SID */
1546     $this->sambaSID = "";
1547   }
1551 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1552 ?>