Code

Multiple edit
[gosa.git] / gosa-core / plugins / 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   /* CLI vars */
29   var $cli_summary= "Manage users samba account";
30   var $cli_description= "Some longer text\nfor help";
31   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
33   /* Switch for Samba version */
34   var $samba3= FALSE;
35   var $uidNumber= 65535;
36   var $gidNumber= 65535;
38   /* Samba 2 attributes */
39   var $pwdLastSet= "0";
40   var $logonTime= "0";
41   var $logoffTime= "2147483647";
42   var $kickoffTime= "2147483647";
43   var $pwdCanChange= "0";
44   var $pwdMustChange= "0";
45   var $password_expires= 0;
46   var $acctFlags= "[UX        ]";
47   var $smbHome= "";
48   var $homeDrive= "";
49   var $scriptPath= "";
50   var $profilePath= "";
51   var $rid= "";
52   var $primaryGroupID= "";
54   /* Samba 3 attributes */
55   var $SID= "";
56   var $ridBase= 0;
57   var $sambaSID= "";
58   var $sambaPwdLastSet= "0";
59   var $sambaLogonTime= "0";
60   var $sambaLogoffTime= "2147483647";
61   var $sambaKickoffTime= "2147483647";
62   var $sambaPwdCanChange= "";
63   var $sambaPwdMustChange= "0";
64   var $sambaAcctFlags= "[UX        ]";
65   var $sambaHomePath= "";
66   var $sambaHomeDrive= "";
67   var $sambaLogonScript= "";
68   var $sambaProfilePath= "";
69   var $sambaPrimaryGroupSID= "";
70   var $sambaDomainName= "";
71   var $sambaUserWorkstations= "";
72   var $sambaBadPasswordCount= "";
73   var $sambaBadPasswordTime= "";
74   var $sambaPasswordHistory= "";
75   var $sambaLogonHours= "";
76   var $orig_sambaDomainName= "";
77   var $sambaMungedDial= "";
78   var $mungedObject;
80   /* Helper */
81   var $show_ws_dialog= FALSE;
82   var $logon_time_set= 0;
83   var $logoff_time_set= 0;
84   var $kickoff_time_set= 0;
86   /* attribute list for save action */
87   var $ctxattributes= array();
88   var $attributes= array();
89   var $objectclasses= array();
90   
91   var $uid= "";
92   var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
94   var $multiple_support = TRUE;
95   /* Only used  for multiple edit */
96   var $temporary_disable = FALSE;
97   var $no_password_required = FALSE;
99   function sambaAccount (&$config, $dn= NULL)
100   {
101     /* Load attributes depending on the samba version */
102     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
104     if ($this->samba3){
105       $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
106           "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
107           "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
108           "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
109           "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
110           "sambaUserWorkstations", "sambaPasswordHistory",
111           "sambaLogonHours", "sambaBadPasswordTime",
112           "sambaBadPasswordCount");
113       $this->objectclasses= array ("sambaSamAccount");
114       $this->mungedObject= new sambaMungedDial;
115       $this->ctxattributes= $this->mungedObject->ctxattributes;
116     } else {
117       $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
118           "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
119           "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
120       $this->objectclasses= array ("sambaAccount");
121     }
123     plugin::plugin ($config, $dn);
125     /* Setting uid to default */
126     if(isset($this->attrs['uid'][0])){
127       $this->uid = $this->attrs['uid'][0];
128     }
130     /* Get samba Domain in case of samba 3 */
131     if ($this->samba3 && $this->sambaSID != ""){
132       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
133       $ldap= $this->config->get_ldap_link();
134       $ldap->cd($this->config->current['BASE']);
135       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
136       if ($ldap->count() != 0){
137         $attrs= $ldap->fetch();
138         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
139         if ($this->sambaDomainName == ""){
140           $this->sambaDomainName= $attrs['sambaDomainName'][0];
141         }
142       } else {
143         if ($this->sambaDomainName == ""){
144           $this->sambaDomainName= "DEFAULT";
145         }
146         $this->ridBase= $this->config->current['RIDBASE'];
147         $this->SID= $this->config->current['SID'];
148       }
150       /* Save in order to compare later on */
151       $this->orig_sambaDomainName= $this->sambaDomainName;
152     }
154     /* Fill mungedDial field */
155     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
156       $this->mungedObject->load($this->sambaMungedDial);
157     }
159     /* Password expiery */
160     if(isset($this->attrs['sambaPwdMustChange']) &&
161         $this->attrs['sambaPwdMustChange'][0] != 0){
162       $this->password_expires= 1;
163     }
165     if(isset($this->attrs['sambaLogonTime']) && ! (
166         $this->attrs['sambaLogonTime'][0] == 0 ||
167         $this->attrs['sambaLogonTime'][0] == 2147483647
168       )){
169       $this->logon_time_set= 1;
170     }
171     if(isset($this->attrs['sambaLogoffTime']) && ! (
172         $this->attrs['sambaLogoffTime'][0] == 0 ||
173         $this->attrs['sambaLogoffTime'][0] == 2147483647
174       )){
175       $this->logoff_time_set= 1;
176     }
177     
178     /* Account expiery */
179     if(isset($this->attrs['sambaKickoffTime']) && ! (
180         $this->attrs['sambaKickoffTime'][0] == 0 ||
181         $this->attrs['sambaKickoffTime'][0] == 2147483647
182       )){
183       $this->kickoff_time_set= 1;
184     }
186     /* Get global filter config */
187     if (!is_global("sambafilter")){
188       $ui= get_userinfo();
189       $base= get_base_from_people($ui->dn);
190       $sambafilter= array( "depselect" => $base, "regex" => "*");
191       register_global("sambafilter", $sambafilter);
192     }
194     /* Save initial account state */
195     $this->initially_was_account= $this->is_account;
196   }
198   function execute()
199   {
200     /* Call parent execute */
201     plugin::execute();
203     /* Log view */
204     if($this->is_account && !$this->view_logged){
205       $this->view_logged = TRUE;
206       new log("view","users/".get_class($this),$this->dn);
207     }
209     /* Do we need to flip is_account state? */
210     if (isset($_POST['modify_state'])){
211       $this->is_account= !$this->is_account;
212     }
213     /* Do we represent a valid account? */
214     if (!$this->is_account && $this->parent === NULL){
215       $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
216         _("This account has no samba extensions.")."</b>";
217       $display.= back_to_main();
218       return ($display);
219     }
221     $display ="";
222     if(!$this->multiple_support_active){
224       /* Show tab dialog headers */
225       $display= "";
226       if ($this->parent !== NULL){
227         if ($this->is_account){
228           $display= $this->show_disable_header(_("Remove samba account"),
229               _("This account has samba features enabled. You can disable them by clicking below."));
230         } else {
231           $obj= $this->parent->by_object['posixAccount'];
233           /* Samba3 dependency on posix accounts are enabled
234              in the moment, because I need to rely on unique
235              uidNumbers. There'll be a better solution later
236              on. */
237           if ($obj->is_account){
238             $display= $this->show_enable_header(_("Create samba account"),
239                 _("This account has samba features disabled. You can enable them by clicking below."));
240           } else {
241             $display= $this->show_enable_header(_("Create samba account"),
242                 _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
243           }
244           return ($display);
245         }
246       }
247     }
249     $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
251     /* Open Samaba Logong hours dialog */
252     if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
253       $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
254     }
256     /* Cancel dialog */
257     if(isset($_POST['cancel_logonHours'])){
258       $this->dialog = FALSE;
259     }
261     /* Save selected logon hours */
262     if(isset($_POST['save_logonHours'])){
263       $this->dialog->save_object();
264       if($this->acl_is_writeable("sambaLogonHours")){
265         $this->sambaLogonHours = $this->dialog->save();
266       }
267       $this->dialog = FALSE;
268     }
270     /* Display dialog */
271     if((isset($this->dialog)) && (is_object($this->dialog))){
272       $this->dialog->save_object();
273       return($this->dialog->execute());
274     }
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         $tmp= $this->sambaUserWorkstations;
315         foreach($_POST['workstation_list'] as $name){
316           $tmp= preg_replace("/$name/", '', $tmp);
317           $this->is_modified= TRUE;
318         }
319         $tmp= preg_replace('/,+/', ',', $tmp);
320         $this->sambaUserWorkstations= trim($tmp, ',');
321       }
322     }
324     /* Add user workstation? */
325     if (isset($_POST["add_ws"])){
326       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
327         $this->show_ws_dialog= TRUE;
328         $this->dialog= TRUE;
329       }
330     }
332     /* Add user workstation finished? */
333     if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
334       $this->show_ws_dialog= FALSE;
335       $this->dialog= FALSE;
336     }
338     /* Add user workstation? */
339     if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
340       $tmp= $this->sambaUserWorkstations;
341       foreach($_POST['wslist'] as $ws){
342         $tmp.= ",$ws";
343       }
344       $tmp= preg_replace('/,+/', ',', $tmp);
345       $this->sambaUserWorkstations= trim($tmp, ',');
346       $this->is_modified= TRUE;
347     }
349     /* Show ws dialog */
350     if ($this->show_ws_dialog){
352       /* Save data */
353       $sambafilter= get_global("sambafilter");
354       foreach( array("depselect", "regex") as $type){
355         if (isset($_POST[$type])){
356           $sambafilter[$type]= $_POST[$type];
357         }
358       }
359       if (isset($_GET['search'])){
360         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
361         if ($s == "**"){
362           $s= "*";
363         }
364         $sambafilter['regex']= $s;
365       }
366       register_global("sambafilter", $sambafilter);
368       /* Get workstation list */
369       $exclude= "";
370       foreach(split(',', $this->sambaUserWorkstations) as $ws){
371         $exclude.= "(cn=$ws$)";
372       }
373       if ($exclude != ""){
374         $exclude= "(!(|$exclude))";
375       }
376       $regex= $sambafilter['regex'];
377       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
378       $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
379         
380       $wslist= array();
381       foreach ($res as $attrs){
382         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
383       }
384       asort($wslist);
386       $smarty->assign("search_image", get_template_path('images/search.png'));
387       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
388       $smarty->assign("tree_image", get_template_path('images/tree.png'));
389       $smarty->assign("deplist", $this->config->idepartments);
390       $smarty->assign("alphabet", generate_alphabet());
391       foreach( array("depselect", "regex") as $type){
392         $smarty->assign("$type", $sambafilter[$type]);
393       }
394       $smarty->assign("hint", print_sizelimit_warning());
395       $smarty->assign("wslist", $wslist);
396       $smarty->assign("apply", apply_filter());
397       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
398                                 dirname(__FILE__)));
399       return ($display);
400     }
402     /* Fill calendar */
403     $days= array();
404     for($d= 1; $d<32; $d++){
405       $days[]= $d;
406     }
407     $years= array();
408     for($y= $date['year']-4; $y<$date['year']+4; $y++){
409       $years[]= $y;
410     }
411     $months= array(_("January"), _("February"), _("March"), _("April"),
412         _("May"), _("June"), _("July"), _("August"), _("September"),
413         _("October"), _("November"), _("December"));
414     $smarty->assign("day", $date["mday"]);
415     $smarty->assign("days", $days);
416     $smarty->assign("months", $months);
417     $smarty->assign("month", $date["mon"]-1);
418     $smarty->assign("years", $years);
419     $smarty->assign("year", $date["year"]);
420     
421     $sambaLogonTime_days= array();
422     for($d= 1; $d<32; $d++){
423       $sambaLogonTime_days[]= $d;
424     }
425     $sambaLogonTime_years= array();
426     for($y= $date['year']-4; $y<$date['year']+4; $y++){
427       $sambaLogonTime_years[]= $y;
428     }
429     $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
430         _("May"), _("June"), _("July"), _("August"), _("September"),
431         _("October"), _("November"), _("December"));
432     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
433     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
434     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
435     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
436     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
437     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
438     
439     $sambaLogoffTime_days= array();
440     for($d= 1; $d<32; $d++){
441       $sambaLogoffTime_days[]= $d;
442     }
443     $sambaLogoffTime_years= array();
444     for($y= $date['year']-4; $y<$date['year']+4; $y++){
445       $sambaLogoffTime_years[]= $y;
446     }
447     $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
448         _("May"), _("June"), _("July"), _("August"), _("September"),
449         _("October"), _("November"), _("December"));
450     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
451     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
452     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
453     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
454     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
455     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
456     
457     $sambaKickoffTime_days= array();
458     for($d= 1; $d<32; $d++){
459       $sambaKickoffTime_days[]= $d;
460     }
461     $sambaKickoffTime_years= array();
462     for($y= $date['year']-4; $y<$date['year']+4; $y++){
463       $sambaKickoffTime_years[]= $y;
464     }
465     $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
466         _("May"), _("June"), _("July"), _("August"), _("September"),
467         _("October"), _("November"), _("December"));
468     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
469     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
470     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
471     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
472     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
473     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
474     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
475      
476     /* Fill boxes */
477     if ($this->samba3){
478       $domains= array();
479       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
480         $domains[]= $name;
481       }
482       $smarty->assign("domains", $domains);
483     }
484     $letters= array();
485     for ($i= 68; $i<91; $i++){
486       $letters[]= chr($i).":";
487     }
488     $smarty->assign("drives", $letters);
490     /* Fill terminal server settings */
491     if ($this->samba3){
492       foreach ($this->ctxattributes as $attr){
493         /* Fill common attributes */
494         if (isset($this->mungedObject->ctx[$attr])){
495           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
496           // Set field  to blank if value is 0
497           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
498             if($this->mungedObject->ctx[$attr] == 0) {
499               $smarty->assign("$attr", "");
500             }
501           }
502         } else {
503           $smarty->assign("$attr", "");
504         }
505       }
507       /* Assign enum values for preset items */
508       $shadowModeVals= array( "0" => _("disabled"),
509           "1" => _("input on, notify on"),
510           "2" => _("input on, notify off"),
511           "3" => _("input off, notify on"),
512           "4" => _("input off, nofify off"));
514       $brokenConnModeVals= array(       "0" => _("disconnect"),
515           "1" => _("reset"));
517       $reConnModeVals= array( "0" => _("from any client"),
518           "1" => _("from previous client only"));
520       /* Fill preset items */
521       $smarty->assign("shadow", $shadowModeVals);
522       $smarty->assign("brokenconn", $brokenConnModeVals);
523       $smarty->assign("reconn", $reConnModeVals);
525       /* Fill preset items with values */
526       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
527       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
528       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
530       if($_SESSION['js']){
531         /* Set form elements to disabled/enable state */
532         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
534         $smarty->assign("inheritstate", "");
535         if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
536           $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
537         }
538   
540   
541       }else{
542         $smarty->assign("tsloginstate", "");
543         $smarty->assign("inheritstate", "");
544       }      
546       /* Set checkboxes to checked or unchecked state */
547       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
548       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
549       $smarty->assign("connectclientdrives",
550                       $this->mungedObject->getConnectClientDrives()?"checked":"");
551       $smarty->assign("connectclientprinters",
552                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
553       $smarty->assign("defaultprinter",
554                       $this->mungedObject->getDefaultPrinter()?"checked":"");
555       $smarty->assign("CtxMaxConnectionTimeF",
556                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
557       $smarty->assign("CtxMaxDisconnectionTimeF",
558                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
559       $smarty->assign("CtxMaxIdleTimeF",
560                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
562       /* Fill sambaUserWorkstations */
563       $ws= split(",", $this->sambaUserWorkstations);
564       sort($ws);
565       
566       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
567       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
570       $smarty->assign("workstations", $ws);
571     }
573     /* Variables */
574     foreach($this->attributes as $val){
575       $smarty->assign("$val", $this->$val);
576     }
578     /* 'sambaAcctFlags' checkboxes */
579     /* Check for 'lock-account'-flag: 'D' or 'L' */
580     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
581         is_integer(strpos($this->sambaAcctFlags, "L"))) {
582         $smarty->assign("flagsD", "checked");
583     } else {
584         $smarty->assign("flagsD", "");
585     }
586     
587     /* Check for no_password_required flag 'N' */
588     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
589         $smarty->assign("flagsN", "checked");
590     } else {
591         $smarty->assign("flagsN", "");
592     }
594     if($this->samba3){
595       if ($this->sambaPwdCanChange=="1"){
596         $smarty->assign("flagsP", "checked");
597       } else {
598         $smarty->assign("flagsP", "");
599       }
600     }else{
601       if ($this->pwdCanChange=="1"){
602         $smarty->assign("flagsP", "checked");
603       } else {
604         $smarty->assign("flagsP", "");
605       }
606     }
608     if ($this->password_expires=="1"){
609       $smarty->assign("flagsC", "checked");
610     } else {
611       $smarty->assign("flagsC", "");
612     }
613     if ($this->logon_time_set=="1"){
614       $smarty->assign("flagsT", "checked");
615     } else {
616       $smarty->assign("flagsT", "");
617     }
618     if ($this->logoff_time_set=="1"){
619       $smarty->assign("flagsO", "checked");
620     } else {
621       $smarty->assign("flagsO", "");
622     }
623     if ($this->kickoff_time_set=="1"){
624       $smarty->assign("flagsK", "checked");
625     } else {
626       $smarty->assign("flagsK", "");
627     }
628    
630     /* In case of javascript, disable some fields on demand */
631     if ($this->samba3){
632       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
633         $smarty->assign("$key", "$value");
634       }
635     }
638     foreach($this->attributes as $attr){
639       if(in_array($attr,$this->multi_boxes)){
640         $smarty->assign("use_".$attr,TRUE);
641       }else{
642         $smarty->assign("use_".$attr,FALSE);
643       }
644     }
645     foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
646           "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
647           "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
648           "onnectclientprinters","defaultprinter","shadow","brokenconn",
649           "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable", 
650           "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
651           "workstation_list") as $attr){
652       if(in_array($attr,$this->multi_boxes)){
653         $smarty->assign("use_".$attr,TRUE);
654       }else{
655         $smarty->assign("use_".$attr,FALSE);
656       }
657     }
659     /* Show main page */
660     $smarty->assign("multiple_support",$this->multiple_support_active);
661     if ($this->samba3){
662       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
663     } else {
664       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
665     }
667     return ($display);
668   }
670   function remove_from_parent()
671   {
672     /* Cancel if there's nothing to do here */
673    if (!$this->initially_was_account){
674      return;
675    }
676     
677     /* include global link_info */
678     $ldap= $this->config->get_ldap_link();
680     plugin::remove_from_parent();
682     /* Keep uid attribute for gosaAccount */
683     unset($this->attrs['uid']);
684     unset($this->attrs['uidNumber']);
685     unset($this->attrs['gidNumber']);
687     /* Remove objectClass for sambaIdmapEntry */
688     $tmp= array();
689     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
690       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
691         $tmp[]= $this->attrs['objectClass'][$i];
692       }
693     }
694     $this->attrs['objectClass']= $tmp;
696     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
697         $this->attributes, "Save");
698     $ldap->cd($this->dn);
699     $this->cleanup();
700     $ldap->modify ($this->attrs); 
702     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
704     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
706     /* Optionally execute a command after we're done */
707     $this->handle_post_events("remove", array("uid" => $this->uid));
708   }
711   /* Check for input problems */
712   function check()
713   {
714     /* Call common method to give check the hook */
715     $message= plugin::check();
717     if ($this->samba3){
719       /* Strings */
720       foreach (array( "sambaHomePath" => _("Home directory"),
721             "sambaProfilePath" => _("Profile path")) as $key => $val){
722         if (!$this->mungedObject->is_samba_path($this->$key)){
723           $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
724         }
725       }
727       /* Numeric values */
728       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
729             "CtxMaxDisconnectionTime" => _("Disconnection"),
730             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
732         if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
733           $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
734         }
735       }
737       /* Too many workstations? Windows usrmgr only supports eight */
738       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
739         $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
740       }
741     }
743     return ($message);
744   }
747   /* Save data to object */
748   function save_object()
749   {
751     $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
753     /* We only care if we are on the sambaTab... */
754     if (isset($_POST['sambaTab'])){
755       plugin::save_object();
757       /* Take care about access options */
758       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
759         if ($this->samba3){
760           $attrname= "sambaPwdCanChange";
761         } else {
762           $attrname= "pwdCanChange";
763         }
764         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
765           $tmp= 1;
766         } else {
767           $tmp= 0;
768         }
769         if ($this->$attrname != $tmp){
770           $this->is_modified= TRUE;
771         }
772         $this->pwdCanChange= $tmp;
773         $this->sambaPwdCanChange= $tmp;
774       }
775       $tmp= "UX";
776       $this->no_password_required = FALSE;
777       if (isset($_POST["no_password_required"])){
778         if ($_POST["no_password_required"] == 1){
779           $tmp.= "N";
780           $this->no_password_required = TRUE;
781         }
782       }
783       if (isset($_POST["password_expires"])){
784         if ($_POST["password_expires"] == 1){
785           $this->password_expires= 1;
786         }
787       } else {
788         $this->password_expires= 0;
789       }
790       $this->temporary_disable = FALSE;
791       if (isset($_POST["temporary_disable"])){
792         if ($_POST["temporary_disable"] == 1){
793           $this->temporary_disable = TRUE;
794           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
795             $tmp.= "L";
796           } else {
797             $tmp.= "D";
798           }
799         }
800       }
801       if (isset($_POST["logon_time_set"])){
802         if ($_POST["logon_time_set"] == 1){
803           $this->logon_time_set= 1;
804         }
805       } else {
806         $this->logon_time_set= 0;
807       }
808       if (isset($_POST["logoff_time_set"])){
809         if ($_POST["logoff_time_set"] == 1){
810           $this->logoff_time_set= 1;
811         }
812       } else {
813         $this->logoff_time_set= 0;
814       }
815       if (isset($_POST["kickoff_time_set"])){
816         if ($_POST["kickoff_time_set"] == 1){
817           $this->kickoff_time_set= 1;
818         }
819       } else {
820         $this->kickoff_time_set= 0;
821       }
822       
823       $fill= "";
824       for ($i= strlen($tmp); $i<12; $i++){
825         $fill.= " ";
826       }
828       $tmp= "[$tmp$fill]";
830       /* Only save if acl's are set */
831       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
832         if ($this->samba3){
833           $attrname= "sambaAcctFlags";
834         } else {
835           $attrname= "acctFlags";
836         }
837         if ($this->$attrname != $tmp){
838           $this->is_modified= TRUE;
839         }
840         $this->$attrname= $tmp;
841       }
843       /* Save sambaDomain attribute */
844       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
845         $this->sambaDomainName= validate($_POST['sambaDomainName']);
846       }
848       /* Save CTX values */
849       if ($this->samba3){
851         /* Save obvious values */
852         foreach($this->ctxattributes as $val){
853           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
854             if (get_magic_quotes_gpc()) {
855               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
856             } else {
857               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
858             }
859           }
860         }
862         /* Save checkbox states. */
863         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
864                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
865         // Need to do some index checking to avoid messages like "index ... not found"
866         if(isset($_POST['brokenconn'])) {
867           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
868                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
869         }
870         if(isset($_POST['reconn'])) {
871           $this->mungedObject->setReConn($_POST['reconn'] == '1'
872                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
873         }
874         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
875                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
876         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
877                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
878         $this->mungedObject->setCtxMaxDisconnectionTimeF(
879                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
880                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
881         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
882                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
883         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
884                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
885         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
886                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
887         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
888                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
890         /* Save combo boxes. Takes two values */
891         if(isset($_POST['reconn'])) {
892           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
893         }
895         /* Check for changes */
896         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
897           $this->is_modified= TRUE;
898         }
899       }
900     }
901   }
904   /* Save to LDAP */
905   function save()
906   {
907     /* Load uid and gid of this 'dn' */
908     $ldap= $this->config->get_ldap_link();
909     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
910     $tmp= $ldap->fetch();
911     $this->uidNumber= $tmp['uidNumber'][0];
912     $this->gidNumber= $tmp['gidNumber'][0];
914     plugin::save();
916     /* Remove objectClass for sambaIdmapEntry */
917     $tmp= array();
918     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
919       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
920         $tmp[]= $this->attrs['objectClass'][$i];
921       }
922     }
923     $this->attrs['objectClass']= $tmp;
925     /* Generate rid / primaryGroupId */
926     if ($this->samba3){
927       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
928         print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
929       } else {
930         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
931         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
932       }
934       /* Need to generate a new uniqe uid/gid combination? */
935       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
936         $uidNumber= $this->uidNumber;
937         while(TRUE){
938           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
939           $ldap->cd($this->config->current['BASE']);
940           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
941           if ($ldap->count() == 0){
942             break;
943           }
944           $uidNumber++;
945         }
946         $this->attrs['sambaSID']= $sid;
948         /* Check for users primary group */
949         $ldap->cd($this->config->current['BASE']);
950         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
951         if ($ldap->count() != 1){
952           print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
953         } else {
954           $attrs= $ldap->fetch();
955           $g= new group($this->config, $ldap->getDN());
956           if ($g->sambaSID == ""){
957             $g->sambaDomainName= $this->sambaDomainName;
958             $g->smbgroup= TRUE;
959             $g->save ();
960           }
961           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
962         }
963       }
965       if ($this->sambaHomeDrive == ""){
966         $this->attrs["sambaHomeDrive"]= array();
967       }
969       /* Generate munged dial value */
970       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
972       /* User wants me to fake the idMappings? This is useful for
973          making winbind resolve the user names in a reasonable amount
974          of time in combination with larger databases. */
975       if (isset($this->config->current['SAMBAIDMAPPING']) &&
976           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
977         $this->attrs['objectClass'][]= "sambaIdmapEntry";
978       }
981       /* Password expiery */
982       if ($this->password_expires == "1"){
983         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
984       } else {
985         $this->attrs['sambaPwdMustChange']= array();
986       }
987       /* Make sure not to save zero in sambaPwdLastset */
988       if ($this->sambaPwdLastSet != "0"){
989         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
990       } else {
991         $this->attrs['sambaPwdLastSet']= array();
992       }
993       /* Account expiery */
994       if ($this->logon_time_set == "1"){
995         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
996       } else {
997         $this->attrs['sambaLogonTime']= array();
998       }
999       if ($this->logoff_time_set == "1"){
1000         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1001       } else {
1002         $this->attrs['sambaLogoffTime']= array();
1003       }
1004       if ($this->kickoff_time_set == "1"){
1005         # Add one day in unixtime format to be compatible with usrmgr
1006         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1007         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1008       } else {
1009         $this->attrs['sambaKickoffTime']= array();
1010       }
1011     } else {
1012     /* Not samba3 */
1013       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1014       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1016       if ($this->homeDrive == ""){
1017         $this->attrs["homeDrive"]= array();
1018       }
1020       /* Password expiery */
1021       if ($this->password_expires == "1"){
1022         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1023       } else {
1024         $this->attrs['pwdMustChange']= 2147483647;
1025       }
1026       /* Make sure not to save zero in pwdLastset */
1027       if ($this->pwdLastSet != "0"){
1028         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1029       } else {
1030         $this->attrs['pwdLastSet']= array();
1031       }
1032       /* Account expiery */
1033       if ($this->logon_time_set == "1"){
1034         $this->attrs['logonTime']= $this->logonTime;
1035       } else {
1036         $this->attrs['logonTime']= array();
1037       }
1038       if ($this->logoff_time_set == "1"){
1039         $this->attrs['logoffTime']= $this->logoffTime;
1040       } else {
1041         $this->attrs['logoffTime']= array();
1042       }
1043       if ($this->kickoff_time_set == "1"){
1044         # Add one day in unixtime format to be compatible with usrmgr
1045         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1046       } else {
1047         $this->attrs['kickoffTime']= array();
1048       }
1049     }
1051     /* Write back to ldap */
1052     $ldap->cd($this->dn);
1053     $this->cleanup();
1054     $ldap->modify ($this->attrs); 
1056     if($this->initially_was_account){
1057       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1058     }else{
1059       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1060     }
1062     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
1064     /* Optionally execute a command after we're done */
1065     if ($this->initially_was_account == $this->is_account){
1066       if ($this->is_modified){
1067         $this->handle_post_events("modify", array("uid" => $this->uid));
1068       }
1069     } else {
1070       $this->handle_post_events("add", array("uid" => $this->uid));
1071     }
1072   }
1075   /* Force password set, if this account doesn't have any samba passwords  */
1076   function password_change_needed()
1077   {
1078     if(!$this->initially_was_account && $this->is_account){
1079       $ldap = $this->config->get_ldap_link();
1080       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1081       $attrs = $ldap->fetch();
1082       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1083         return(TRUE);
1084       }
1085     }
1086     return(FALSE);
1087   }
1090   function adapt_from_template($dn)
1091   {
1092     plugin::adapt_from_template($dn);
1093     $this->sambaSID= "";
1094     $this->sambaPrimaryGroupSID= "";
1096       /* Fill mungedDial field */
1097     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1098       $this->mungedObject->load($this->sambaMungedDial);
1099     }
1101     /* Password expiery */
1102     if(isset($this->attrs['sambaPwdMustChange']) &&
1103         $this->attrs['sambaPwdMustChange'][0] != 0){
1104       $this->password_expires= 1;
1105     }
1107     if(isset($this->attrs['sambaLogonTime']) && ! (
1108         $this->attrs['sambaLogonTime'][0] == 0 ||
1109         $this->attrs['sambaLogonTime'][0] == 2147483647
1110       )){
1111       $this->logon_time_set= 1;
1112     }
1113     if(isset($this->attrs['sambaLogoffTime']) && ! (
1114         $this->attrs['sambaLogoffTime'][0] == 0 ||
1115         $this->attrs['sambaLogoffTime'][0] == 2147483647
1116       )){
1117       $this->logoff_time_set= 1;
1118     }
1120     /* Account expiery */
1121     if(isset($this->attrs['sambaKickoffTime']) && ! (
1122         $this->attrs['sambaKickoffTime'][0] == 0 ||
1123         $this->attrs['sambaKickoffTime'][0] == 2147483647
1124       )){
1125       $this->kickoff_time_set= 1;
1126     }
1128     /* Get global filter config */
1129     if (!is_global("sambafilter")){
1130       $ui= get_userinfo();
1131       $base= get_base_from_people($ui->dn);
1132       $sambafilter= array( "depselect" => $base, "regex" => "*");
1133       register_global("sambafilter", $sambafilter);
1134     }
1135   }
1137   
1138   static function plInfo()
1139   {
1140     return (array(
1141           "plShortName"     => _("Samba"),
1142           "plDescription"   => _("Samba settings"),
1143           "plSelfModify"    => TRUE,
1144           "plDepends"       => array("user"),
1145           "plPriority"      => 5,
1146           "plSection"     => array("personal" => _("My account")),
1147           "plCategory"    => array("users"),
1148           "plOptions"       => array(),
1150           "plProvidedAcls"  => array(
1151             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1152             "InheritClientConfig"         => _("Inherit client config"),
1154             "sambaPwdCanChange"     => _("Allow user to change password") ,
1155             "sambaAcctFlagsN"            => _("Login from windows client requires no password"),
1156             "sambaAcctFlagsL"            => _("Lock samba account"),
1159             "sambaKickoffTime"      => _("Account expires") ,
1160             "sambaPwdMustChange"    => _("Password expires") ,
1162             "sambaLogonTime"        => _("Limit Logon Time") ,
1163             "sambaLogoffTime"       => _("Limit Logoff Time") ,
1164             "sambaLogonHours"       => _("Logon hours") ,
1166             "sambaHomePath"         => _("Generic home directory") ,
1167             "sambaHomeDrive"        => _("Generic samba home drive") ,
1168             "sambaLogonScript"      => _("Generic script path") ,
1169             "sambaProfilePath"      => _("Generic profile path") ,
1170             "sambaDomainName"       => _("Domain") ,
1171             "sambaUserWorkstations" => _("Allow connection from")))
1172               );
1173   }    
1175   function enable_multiple_support()
1176   {
1177     plugin::enable_multiple_support();
1178     if($this->samba3){
1179       $this->multiple_support_active = TRUE;
1180     }else{
1181       $this->multiple_support_active = FALSE;
1182     }
1183   } 
1185   function multiple_save_object()
1186   {
1187     $this->save_object();
1188     plugin::multiple_save_object();
1189     foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1190           "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1191           "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1192           "onnectclientprinters","defaultprinter","shadow","brokenconn",
1193           "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1194           "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1195           "workstation_list") as $attr){
1196       if(isset($_POST["use_".$attr])){
1197         $this->multi_boxes[] = $attr;
1198       }
1199     }
1200   }
1202   function multiple_execute()
1203   {
1204     return($this->execute());
1205   } 
1207   function get_multi_edit_values()
1208   {
1209     $ret = plugin::get_multi_edit_values();
1211     /* Terminal Server  */
1212     if(in_array("tslogin",$this->multi_boxes)){
1213       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1214     }
1215     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1216       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1217     }
1218     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1219       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1220     }
1221     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1222       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1223     }
1225     if(in_array("inherit",$this->multi_boxes)){
1226       $ret['inherit'] = $this->mungedObject->getInheritMode();
1227     }       
1228     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1229       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1230     } 
1231     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1232       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1233     } 
1235     /* Time Limits. Be careful here, there are some negations  */
1236     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1237       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1238       if(!$ret["CtxMaxConnectionTimeF"]){
1239         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1240       }
1241     }
1242     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1243       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1244       if(!$ret["CtxMaxDisconnectionTimeF"]){
1245         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1246       }
1247     }
1248     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1249       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1250       if(!$ret["CtxMaxIdleTimeF"]){
1251         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1252       }
1253     }
1255     /* Client Devices */
1256     if(in_array("connectclientdrives",$this->multi_boxes)){
1257       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1258     }
1259     if(in_array("connectclientprinters",$this->multi_boxes)){
1260       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1261     }
1262     if(in_array("defaultprinter",$this->multi_boxes)){
1263       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1264     }
1266     /* Misc */
1267     if(in_array("shadow",$this->multi_boxes)){
1268       $ret["shadow"]    =$this->mungedObject->getShadow();
1269     }
1270     if(in_array("brokenconn",$this->multi_boxes)){
1271       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1272     }
1273     if(in_array("reconn",$this->multi_boxes)){
1274       $ret["reconn"]    =$this->mungedObject->getReConn();
1275     }
1277     /* Flags */
1278     if(in_array("allow_pwchange",$this->multi_boxes)){
1279       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1280       $ret['pwdCanChange']      = $this->pwdCanChange;
1281     }
1282   
1283     if(in_array("password_expires",$this->multi_boxes)){
1284       $ret['password_expires']  = $this->password_expires;
1285       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1286     }
1287     if(in_array("logon_time_set",$this->multi_boxes)){
1288       $ret['logon_time_set'] = $this->logon_time_set;
1289       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1290     }
1291     if(in_array("logoff_time_set",$this->multi_boxes)){
1292       $ret['logoff_time_set'] = $this->logoff_time_set;
1293       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1294     }
1295     if(in_array("kickoff_time_set",$this->multi_boxes)){
1296       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1297       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1298     }
1300     if(in_array("no_password_required",$this->multi_boxes)){
1301       $ret['no_password_required'] = $this->no_password_required;
1302     }
1304     if(in_array("temporary_disable",$this->multi_boxes)){
1305       $ret['temporary_disable'] = $this->temporary_disable;
1306     }
1308     return($ret);
1309   }
1311   function set_multi_edit_values($values)
1312   {
1313     plugin::set_multi_edit_values($values);
1315     /* Enable disabled terminal login, this is inverted somehow */
1316     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1317   
1318     /* Imherit client configuration */
1319     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1320   
1321     /* Get all ctx values posted */
1322     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1323                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1324     foreach($ctx as $attr){
1325       if(isset($values[$attr])){
1326         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1327       }
1328     }
1330     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1331     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1332     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1334     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1335     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1336     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1338     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1339     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1340     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1342   
1343     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1344     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1346     
1347     
1349     if(isset($values['password_expires'])){
1350       $this->password_expires = $values['password_expires'];
1351       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1352     }
1353     if(isset($values['logon_time_set'])){
1354       $this->logon_time_set = $values['logon_time_set'];
1355       $this->sambaLogonTime = $values['sambaLogonTime'];
1356     }
1357     if(isset($values['logoff_time_set'])){
1358       $this->logoff_time_set = $values['logoff_time_set'];
1359       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1360     }
1361     if(isset($values['kickoff_time_set'])){
1362       $this->kickoff_time_set = $values['kickoff_time_set'];
1363       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1364     }
1366     if(isset($values['no_password_required'])){
1367       if($values['no_password_required']){
1368         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1369           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1370         }
1371       }else{
1372         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1373       }
1374     }      
1376     if(isset($values['temporary_disable'])){
1377       if($values['temporary_disable']){
1378         if(preg_match("/L/",$this->sambaAcctFlags)) {
1379           // Keep L
1380         }else{
1381           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1382         }
1383       }else{
1384         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1385       }
1386     }
1387   }
1390 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1391 ?>