Code

Updated sambaAccount
[gosa.git] / gosa-plugins / samba / personal / samba / class_sambaAccount.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2004-2005 Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 class sambaAccount extends plugin
22 {
23   /* Definitions */
24   var $plHeadline= "Samba";
25   var $plDescription= "This does something";
26   var $view_logged = FALSE;
28   /* Switch for Samba version */
29   var $samba3= FALSE;
30   var $uidNumber= 65535;
31   var $gidNumber= 65535;
33   /* Samba 2 attributes */
34   var $pwdLastSet= "0";
35   var $logonTime= "0";
36   var $logoffTime= "2147483647";
37   var $kickoffTime= "2147483647";
38   var $pwdCanChange= "0";
39   var $pwdMustChange= "0";
40   var $password_expires= 0;
41   var $acctFlags= "[UX        ]";
42   var $smbHome= "";
43   var $homeDrive= "";
44   var $scriptPath= "";
45   var $profilePath= "";
46   var $rid= "";
47   var $primaryGroupID= "";
49   /* Samba 3 attributes */
50   var $SID= "";
51   var $ridBase= 0;
52   var $sambaSID= "";
53   var $sambaPwdLastSet= "0";
54   var $sambaLogonTime= "0";
55   var $sambaLogoffTime= "2147483647";
56   var $sambaKickoffTime= "2147483647";
57   var $sambaPwdCanChange= "";
58   var $sambaPwdMustChange= "0";
59   var $sambaAcctFlags= "[UX        ]";
60   var $sambaHomePath= "";
61   var $sambaHomeDrive= "";
62   var $sambaLogonScript= "";
63   var $sambaProfilePath= "";
64   var $sambaPrimaryGroupSID= "";
65   var $sambaDomainName= "";
66   var $sambaUserWorkstations= "";
67   var $sambaBadPasswordCount= "";
68   var $sambaBadPasswordTime= "";
69   var $sambaPasswordHistory= "";
70   var $sambaLogonHours= "";
71   var $orig_sambaDomainName= "";
72   var $sambaMungedDial= "";
73   var $mungedObject;
75   /* Helper */
76   var $show_ws_dialog= FALSE;
77   var $logon_time_set= 0;
78   var $logoff_time_set= 0;
79   var $kickoff_time_set= 0;
81   /* attribute list for save action */
82   var $ctxattributes= array();
83   var $attributes= array();
84   var $objectclasses= array();
85   
86   var $uid= "";
87   var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
89   var $multiple_support = TRUE;
91   /* Only used  for multiple edit */
92   var $temporary_disable = FALSE;
93   var $no_password_required = FALSE;
94   var $multiple_sambaUserWorkstations = array();
96   function sambaAccount (&$config, $dn= NULL)
97   {
98     /* Load attributes depending on the samba version */
99     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
101     if ($this->samba3){
102       $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
103           "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
104           "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
105           "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
106           "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
107           "sambaUserWorkstations", "sambaPasswordHistory",
108           "sambaLogonHours", "sambaBadPasswordTime",
109           "sambaBadPasswordCount");
110       $this->objectclasses= array ("sambaSamAccount");
111       $this->mungedObject= new sambaMungedDial;
112       $this->ctxattributes= $this->mungedObject->ctxattributes;
113     } else {
114       $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
115           "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
116           "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
117       $this->objectclasses= array ("sambaAccount");
118     }
120     plugin::plugin ($config, $dn);
122     /* Setting uid to default */
123     if(isset($this->attrs['uid'][0])){
124       $this->uid = $this->attrs['uid'][0];
125     }
127     /* Get samba Domain in case of samba 3 */
128     if ($this->samba3 && $this->sambaSID != ""){
129       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
130       $ldap= $this->config->get_ldap_link();
131       $ldap->cd($this->config->current['BASE']);
132       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
133       if ($ldap->count() != 0){
134         $attrs= $ldap->fetch();
135         if(isset($attrs['sambaAlgorithmicRidBase'])){
136           $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
137         } else {
138           $this->ridBase= $this->config->current['RIDBASE'];
139         }
140         if ($this->sambaDomainName == ""){
141           $this->sambaDomainName= $attrs['sambaDomainName'][0];
142         }
143       } else {
144         if ($this->sambaDomainName == ""){
145           $this->sambaDomainName= "DEFAULT";
146         }
147         $this->ridBase= $this->config->current['RIDBASE'];
148         $this->SID= $this->config->current['SID'];
149       }
151       /* Save in order to compare later on */
152       $this->orig_sambaDomainName= $this->sambaDomainName;
153     }
155     /* Fill mungedDial field */
156     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
157       $this->mungedObject->load($this->sambaMungedDial);
158     }
160     /* Password expiery */
161     if(isset($this->attrs['sambaPwdMustChange']) &&
162         $this->attrs['sambaPwdMustChange'][0] != 0){
163       $this->password_expires= 1;
164     }
166     if(isset($this->attrs['sambaLogonTime']) && ! (
167         $this->attrs['sambaLogonTime'][0] == 0 ||
168         $this->attrs['sambaLogonTime'][0] == 2147483647
169       )){
170       $this->logon_time_set= 1;
171     }
172     if(isset($this->attrs['sambaLogoffTime']) && ! (
173         $this->attrs['sambaLogoffTime'][0] == 0 ||
174         $this->attrs['sambaLogoffTime'][0] == 2147483647
175       )){
176       $this->logoff_time_set= 1;
177     }
178     
179     /* Account expiery */
180     if(isset($this->attrs['sambaKickoffTime']) && ! (
181         $this->attrs['sambaKickoffTime'][0] == 0 ||
182         $this->attrs['sambaKickoffTime'][0] == 2147483647
183       )){
184       $this->kickoff_time_set= 1;
185     }
187     /* Get global filter config */
188     if (!session::is_set("sambafilter")){
189       $ui= get_userinfo();
190       $base= get_base_from_people($ui->dn);
191       $sambafilter= array( "depselect" => $base, "regex" => "*");
192       session::set("sambafilter", $sambafilter);
193     }
195     /* Save initial account state */
196     $this->initially_was_account= $this->is_account;
197   }
199   function execute()
200   {
201     /* Call parent execute */
202     plugin::execute();
204     /* Log view */
205     if($this->is_account && !$this->view_logged){
206       $this->view_logged = TRUE;
207       new log("view","users/".get_class($this),$this->dn);
208     }
210     /* Do we need to flip is_account state? */
211     if (isset($_POST['modify_state'])){
212       $this->is_account= !$this->is_account;
213     }
214     /* Do we represent a valid account? */
215     if (!$this->is_account && $this->parent === NULL){
216       $display= "<img alt=\"\"src=\"images/small-error.png\" align=\"middle\">&nbsp;<b>".
217         msgPool::noValidExtension(_("Samba"))."</b>";
218       $display.= back_to_main();
219       return ($display);
220     }
222     $display ="";
223     if(!$this->multiple_support_active){
225       /* Show tab dialog headers */
226       $display= "";
227       if ($this->parent !== NULL){
228         if ($this->is_account){
229           $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Samba")),
230               msgPool::featuresEnabled(_("Samba")));
231         } else {
232           $obj= $this->parent->by_object['posixAccount'];
234           /* Samba3 dependency on posix accounts are enabled
235              in the moment, because I need to rely on unique
236              uidNumbers. There'll be a better solution later
237              on. */
238           if ($obj->is_account){
239             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
240                 msgPool::featuresDisabled(_("Samba")));
241           } else {
242             $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
243                 msgPool::featuresDisabled(_("Samba"), _("POSIX")), TRUE);
244           }
245           return ($display);
246         }
247       }
248     }
250     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
252     /* Open Samaba Logong hours dialog */
253     if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_readable("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(!session::is_set('edit')){
286       $smarty->assign("sambaLogonHoursACL","");
287     }
289     if ($this->sambaPwdMustChange=="0"){
290       $date= getdate();
291     } else {
292       $date= getdate($this->sambaPwdMustChange);
293     }
295     if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
296       $sambaLogonTime_date= getdate();
297     } else {
298       $sambaLogonTime_date= getdate($this->sambaLogonTime);
299     }
300     
301     if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
302       $sambaLogoffTime_date= getdate();
303     } else {
304       $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
305     }
306     
307     if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
308       $sambaKickoffTime_date= getdate();
309     } else {
310       $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
311     }
313     /* Remove user workstations? */
314     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
316       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
318         if($this->multiple_support_active){
319           foreach($_POST['workstation_list'] as $name){
320             if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
321               unset($this->multiple_sambaUserWorkstations[trim($name)]);
322             }
323           } 
324         }else{
325           $tmp= $this->sambaUserWorkstations;
326           foreach($_POST['workstation_list'] as $name){
327             $tmp= preg_replace("/$name/", '', $tmp);
328             $this->is_modified= TRUE;
329           }
330           $tmp= preg_replace('/,+/', ',', $tmp);
331           $this->sambaUserWorkstations= trim($tmp, ',');
332         }
333       }
334     }
336     /* Add user workstation? */
337     if (isset($_POST["add_ws"])){
338       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
339         $this->show_ws_dialog= TRUE;
340         $this->dialog= TRUE;
341       }
342     }
344     /* Add user workstation finished? */
345     if (isset($_POST["add_ws_cancel"])){
346       $this->show_ws_dialog= FALSE;
347       $this->dialog= FALSE;
348     }
350     /* Add user workstation? */
351     if (isset($_POST["add_ws_finish"])){
353       if (isset($_POST['wslist'])){
354         if($this->multiple_support_active){
355           foreach($_POST['wslist'] as $ws){
356             $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
357           }
358         }else{
359           $tmp= $this->sambaUserWorkstations;
360           foreach($_POST['wslist'] as $ws){
361             $tmp.= ",$ws";
362           }
363           $tmp= preg_replace('/,+/', ',', $tmp);
364           $this->sambaUserWorkstations= trim($tmp, ',');
365         }
366         $this->is_modified= TRUE;
368         $this->show_ws_dialog= FALSE;
369         $this->dialog= FALSE;
370       } else {
371         msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
372       }
373     }
375     /* Show ws dialog */
376     if ($this->show_ws_dialog){
378       /* Save data */
379       $sambafilter= session::get("sambafilter");
380       foreach( array("depselect", "regex") as $type){
381         if (isset($_POST[$type])){
382           $sambafilter[$type]= $_POST[$type];
383         }
384       }
385       if (isset($_GET['search'])){
386         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
387         if ($s == "**"){
388           $s= "*";
389         }
390         $sambafilter['regex']= $s;
391       }
392       session::set("sambafilter", $sambafilter);
394       /* Get workstation list */
395       $exclude= "";
397       if($this->multiple_support_active){
398         foreach($this->multiple_sambaUserWorkstations as $ws){
399           if($ws['UsedByAllUsers']){
400             $exclude.= "(cn=".$ws['Name']."$)";
401           }
402         }
403       }else{
404         foreach(split(',', $this->sambaUserWorkstations) as $ws){
405           $exclude.= "(cn=$ws$)";
406         }
407       }
408       if ($exclude != ""){
409         $exclude= "(!(|$exclude))";
410       }
411       $regex= $sambafilter['regex'];
412       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
413       $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
414         
415       $wslist= array();
416       foreach ($res as $attrs){
417         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
418       }
419       asort($wslist);
421       $smarty->assign("search_image", get_template_path('images/lists/search.png'));
422       $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
423       $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
424       $smarty->assign("deplist", $this->config->idepartments);
425       $smarty->assign("alphabet", generate_alphabet());
426       foreach( array("depselect", "regex") as $type){
427         $smarty->assign("$type", $sambafilter[$type]);
428       }
429       $smarty->assign("hint", print_sizelimit_warning());
430       $smarty->assign("wslist", $wslist);
431       $smarty->assign("apply", apply_filter());
432       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
433                                 dirname(__FILE__)));
434       return ($display);
435     }
437     /* Fill calendar */
438     $days= array();
439     for($d= 1; $d<32; $d++){
440       $days[]= $d;
441     }
442     $years= array();
443     for($y= $date['year']-4; $y<$date['year']+4; $y++){
444       $years[]= $y;
445     }
446     $months= msgPool::months();
447     $smarty->assign("day", $date["mday"]);
448     $smarty->assign("days", $days);
449     $smarty->assign("months", $months);
450     $smarty->assign("month", $date["mon"]-1);
451     $smarty->assign("years", $years);
452     $smarty->assign("year", $date["year"]);
453     
454     $sambaLogonTime_days= array();
455     for($d= 1; $d<32; $d++){
456       $sambaLogonTime_days[]= $d;
457     }
458     $sambaLogonTime_years= array();
459     for($y= $date['year']-4; $y<$date['year']+4; $y++){
460       $sambaLogonTime_years[]= $y;
461     }
462     $sambaLogonTime_months= msgPool::months();
463     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
464     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
465     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
466     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
467     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
468     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
469     
470     $sambaLogoffTime_days= array();
471     for($d= 1; $d<32; $d++){
472       $sambaLogoffTime_days[]= $d;
473     }
474     $sambaLogoffTime_years= array();
475     for($y= $date['year']-4; $y<$date['year']+4; $y++){
476       $sambaLogoffTime_years[]= $y;
477     }
478     $sambaLogoffTime_months= msgPool::months();
479     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
480     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
481     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
482     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
483     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
484     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
485     
486     $sambaKickoffTime_days= array();
487     for($d= 1; $d<32; $d++){
488       $sambaKickoffTime_days[]= $d;
489     }
490     $sambaKickoffTime_years= array();
491     for($y= $date['year']-4; $y<$date['year']+4; $y++){
492       $sambaKickoffTime_years[]= $y;
493     }
494     $sambaKickoffTime_months= msgPool::months();
495     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
496     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
497     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
498     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
499     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
500     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
501     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
502      
503     /* Fill boxes */
504     if ($this->samba3){
505       $domains= array();
506       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
507         $domains[]= $name;
508       }
509       $smarty->assign("domains", $domains);
510     }
511     $letters= array();
512     for ($i= 68; $i<91; $i++){
513       $letters[]= chr($i).":";
514     }
515     $smarty->assign("drives", $letters);
517     /* Fill terminal server settings */
518     if ($this->samba3){
519       foreach ($this->ctxattributes as $attr){
520         /* Fill common attributes */
521         if (isset($this->mungedObject->ctx[$attr])){
522           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
523           // Set field  to blank if value is 0
524           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
525             if($this->mungedObject->ctx[$attr] == 0) {
526               $smarty->assign("$attr", "");
527             }
528           }
529         } else {
530           $smarty->assign("$attr", "");
531         }
532       }
534       /* Assign enum values for preset items */
535       $shadowModeVals= array( "0" => _("disabled"),
536           "1" => _("input on, notify on"),
537           "2" => _("input on, notify off"),
538           "3" => _("input off, notify on"),
539           "4" => _("input off, nofify off"));
541       $brokenConnModeVals= array(       "0" => _("disconnect"),
542           "1" => _("reset"));
544       $reConnModeVals= array( "0" => _("from any client"),
545           "1" => _("from previous client only"));
547       /* Fill preset items */
548       $smarty->assign("shadow", $shadowModeVals);
549       $smarty->assign("brokenconn", $brokenConnModeVals);
550       $smarty->assign("reconn", $reConnModeVals);
552       /* Fill preset items with values */
553       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
554       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
555       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
557       if(session::get('js')){
558         /* Set form elements to disabled/enable state */
559         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
561         $smarty->assign("inheritstate", "");
562         if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
563           $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
564         }
565       }else{
566         $smarty->assign("tsloginstate", "");
567         $smarty->assign("inheritstate", "");
568       }      
570       /* Set checkboxes to checked or unchecked state */
571       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
572       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
573       $smarty->assign("connectclientdrives",
574                       $this->mungedObject->getConnectClientDrives()?"checked":"");
575       $smarty->assign("connectclientprinters",
576                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
577       $smarty->assign("defaultprinter",
578                       $this->mungedObject->getDefaultPrinter()?"checked":"");
579       $smarty->assign("CtxMaxConnectionTimeF",
580                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
581       $smarty->assign("CtxMaxDisconnectionTimeF",
582                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
583       $smarty->assign("CtxMaxIdleTimeF",
584                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
586       
587       /* Fill sambaUserWorkstations */
588       $ws= split(",", $this->sambaUserWorkstations);
589       sort($ws);
590       
591       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
592       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
594       if($this->multiple_support_active){
595         $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
596       }  
598       $smarty->assign("workstations", $ws);
599     }
601     /* Variables */
602     foreach($this->attributes as $val){
603       $smarty->assign("$val", $this->$val);
604     }
606     /* 'sambaAcctFlags' checkboxes */
607     /* Check for 'lock-account'-flag: 'D' or 'L' */
608     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
609         is_integer(strpos($this->sambaAcctFlags, "L"))) {
610         $smarty->assign("flagsD", "checked");
611     } else {
612         $smarty->assign("flagsD", "");
613     }
614     
615     /* Check for no_password_required flag 'N' */
616     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
617         $smarty->assign("flagsN", "checked");
618     } else {
619         $smarty->assign("flagsN", "");
620     }
622     if($this->samba3){
623       if ($this->sambaPwdCanChange=="1"){
624         $smarty->assign("flagsP", "checked");
625       } else {
626         $smarty->assign("flagsP", "");
627       }
628     }else{
629       if ($this->pwdCanChange=="1"){
630         $smarty->assign("flagsP", "checked");
631       } else {
632         $smarty->assign("flagsP", "");
633       }
634     }
636     if ($this->password_expires=="1"){
637       $smarty->assign("flagsC", "checked");
638     } else {
639       $smarty->assign("flagsC", "");
640     }
641     if ($this->logon_time_set=="1"){
642       $smarty->assign("flagsT", "checked");
643     } else {
644       $smarty->assign("flagsT", "");
645     }
646     if ($this->logoff_time_set=="1"){
647       $smarty->assign("flagsO", "checked");
648     } else {
649       $smarty->assign("flagsO", "");
650     }
651     if ($this->kickoff_time_set=="1"){
652       $smarty->assign("flagsK", "checked");
653     } else {
654       $smarty->assign("flagsK", "");
655     }
656    
658     /* In case of javascript, disable some fields on demand */
659     if ($this->samba3){
660       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
661         $smarty->assign("$key", "$value");
662       }
663     }
666     foreach($this->attributes as $attr){
667       if(in_array($attr,$this->multi_boxes)){
668         $smarty->assign("use_".$attr,TRUE);
669       }else{
670         $smarty->assign("use_".$attr,FALSE);
671       }
672     }
673     foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
674           "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
675           "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
676           "onnectclientprinters","defaultprinter","shadow","brokenconn",
677           "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable", 
678           "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
679           "workstation_list") as $attr){
680       if(in_array($attr,$this->multi_boxes)){
681         $smarty->assign("use_".$attr,TRUE);
682       }else{
683         $smarty->assign("use_".$attr,FALSE);
684       }
685     }
687     if($this->multiple_support_active){
688       $smarty->assign("tsloginstate","");
689     }
691     /* Show main page */
692     $smarty->assign("multiple_support",$this->multiple_support_active);
693     if ($this->samba3){
694       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
695     } else {
696       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
697     }
699     return ($display);
700   }
702   function remove_from_parent()
703   {
704     /* Cancel if there's nothing to do here */
705    if (!$this->initially_was_account){
706      return;
707    }
708     
709     /* include global link_info */
710     $ldap= $this->config->get_ldap_link();
712     plugin::remove_from_parent();
714     /* Keep uid attribute for gosaAccount */
715     unset($this->attrs['uid']);
716     unset($this->attrs['uidNumber']);
717     unset($this->attrs['gidNumber']);
719     /* Remove objectClass for sambaIdmapEntry */
720     $tmp= array();
721     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
722       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
723         $tmp[]= $this->attrs['objectClass'][$i];
724       }
725     }
726     $this->attrs['objectClass']= $tmp;
728     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
729         $this->attributes, "Save");
730     $ldap->cd($this->dn);
731     $this->cleanup();
732     $ldap->modify ($this->attrs); 
734     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
736     if (!$ldap->success()){
737       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
738     }
740     /* Optionally execute a command after we're done */
741     $this->handle_post_events("remove", array("uid" => $this->uid));
742   }
745   /* Check for input problems */
746   function check()
747   {
748     /* Call common method to give check the hook */
749     $message= plugin::check();
751     if ($this->samba3){
753       /* Strings */
754       foreach (array( "sambaHomePath" => _("Home directory"),
755             "sambaProfilePath" => _("Profile path")) as $key => $val){
756         if (!$this->mungedObject->is_samba_path($this->$key)){
757           $message[]= msgPool::invalid($val);
758         }
759       }
761       /* Numeric values */
762       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
763             "CtxMaxDisconnectionTime" => _("Disconnection"),
764             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
766         if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
767           $message[]= msgPool::invalid($val);
768         }
769       }
771       /* Too many workstations? Windows usrmgr only supports eight */
772       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
773         $message[]= _("The windows usermanager allows eight clients at maximum!");
774       }
775     }
777     return ($message);
778   }
781   /* Save data to object */
782   function save_object()
783   {
785     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
787     /* We only care if we are on the sambaTab... */
788     if (isset($_POST['sambaTab'])){
789       plugin::save_object();
791       /* Take care about access options */
792       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
793         if ($this->samba3){
794           $attrname= "sambaPwdCanChange";
795         } else {
796           $attrname= "pwdCanChange";
797         }
798         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
799           $tmp= 1;
800         } else {
801           $tmp= 0;
802         }
803         if ($this->$attrname != $tmp){
804           $this->is_modified= TRUE;
805         }
806         $this->pwdCanChange= $tmp;
807         $this->sambaPwdCanChange= $tmp;
808       }
809       $tmp= "UX";
810       $this->no_password_required = FALSE;
811       if (isset($_POST["no_password_required"])){
812         if ($_POST["no_password_required"] == 1){
813           $tmp.= "N";
814           $this->no_password_required = TRUE;
815         }
816       }
817       if (isset($_POST["password_expires"])){
818         if ($_POST["password_expires"] == 1){
819           $this->password_expires= 1;
820         }
821       } else {
822         $this->password_expires= 0;
823       }
824       $this->temporary_disable = FALSE;
825       if (isset($_POST["temporary_disable"])){
826         if ($_POST["temporary_disable"] == 1){
827           $this->temporary_disable = TRUE;
828           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
829             $tmp.= "L";
830           } else {
831             $tmp.= "D";
832           }
833         }
834       }
835       if (isset($_POST["logon_time_set"])){
836         if ($_POST["logon_time_set"] == 1){
837           $this->logon_time_set= 1;
838         }
839       } else {
840         $this->logon_time_set= 0;
841       }
842       if (isset($_POST["logoff_time_set"])){
843         if ($_POST["logoff_time_set"] == 1){
844           $this->logoff_time_set= 1;
845         }
846       } else {
847         $this->logoff_time_set= 0;
848       }
849       if (isset($_POST["kickoff_time_set"])){
850         if ($_POST["kickoff_time_set"] == 1){
851           $this->kickoff_time_set= 1;
852         }
853       } else {
854         $this->kickoff_time_set= 0;
855       }
856       
857       $fill= "";
858       for ($i= strlen($tmp); $i<12; $i++){
859         $fill.= " ";
860       }
862       $tmp= "[$tmp$fill]";
864       /* Only save if acl's are set */
865       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
866         if ($this->samba3){
867           $attrname= "sambaAcctFlags";
868         } else {
869           $attrname= "acctFlags";
870         }
871         if ($this->$attrname != $tmp){
872           $this->is_modified= TRUE;
873         }
874         $this->$attrname= $tmp;
875       }
877       /* Save sambaDomain attribute */
878       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
879         $this->sambaDomainName= validate($_POST['sambaDomainName']);
880       }
882       /* Save CTX values */
883       if ($this->samba3){
885         /* Save obvious values */
886         foreach($this->ctxattributes as $val){
887           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
888             if (get_magic_quotes_gpc()) {
889               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
890             } else {
891               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
892             }
893           }
894         }
896         /* Save checkbox states. */
897         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
898                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
899         // Need to do some index checking to avoid messages like "index ... not found"
900         if(isset($_POST['brokenconn'])) {
901           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
902                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
903         }
904         if(isset($_POST['reconn'])) {
905           $this->mungedObject->setReConn($_POST['reconn'] == '1'
906                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
907         }
908         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
909                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
910         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
911                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
912         $this->mungedObject->setCtxMaxDisconnectionTimeF(
913                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
914                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
915         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
916                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
917         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
918                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
919         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
920                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
921         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
922                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
924         /* Save combo boxes. Takes two values */
925         if(isset($_POST['reconn'])) {
926           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
927         }
929         /* Check for changes */
930         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
931           $this->is_modified= TRUE;
932         }
933       }
934     }
935   }
938   /* Save to LDAP */
939   function save()
940   {
941     /* Load uid and gid of this 'dn' */
942     $ldap= $this->config->get_ldap_link();
943     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
944     $tmp= $ldap->fetch();
945     $this->uidNumber= $tmp['uidNumber'][0];
946     $this->gidNumber= $tmp['gidNumber'][0];
948     plugin::save();
950     /* Remove objectClass for sambaIdmapEntry */
951     $tmp= array();
952     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
953       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
954         $tmp[]= $this->attrs['objectClass'][$i];
955       }
956     }
957     $this->attrs['objectClass']= $tmp;
959     /* Generate rid / primaryGroupId */
960     if ($this->samba3){
961       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
962         msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
963       } else {
964         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
965         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
966       }
968       /* Need to generate a new uniqe uid/gid combination? */
969       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
970         $uidNumber= $this->uidNumber;
971         while(TRUE){
972           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
973           $ldap->cd($this->config->current['BASE']);
974           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
975           if ($ldap->count() == 0){
976             break;
977           }
978           $uidNumber++;
979         }
980         $this->attrs['sambaSID']= $sid;
982         /* Check for users primary group */
983         $ldap->cd($this->config->current['BASE']);
984         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
985         if ($ldap->count() != 1){
986           msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
987         } else {
988           $attrs= $ldap->fetch();
989           $g= new group($this->config, $ldap->getDN());
990           if ($g->sambaSID == ""){
991             $g->sambaDomainName= $this->sambaDomainName;
992             $g->smbgroup= TRUE;
993             $g->save ();
994           }
995           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
996         }
997       }
999       if ($this->sambaHomeDrive == ""){
1000         $this->attrs["sambaHomeDrive"]= array();
1001       }
1003       /* Generate munged dial value */
1004       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1006       /* User wants me to fake the idMappings? This is useful for
1007          making winbind resolve the user names in a reasonable amount
1008          of time in combination with larger databases. */
1009       if (isset($this->config->current['SAMBAIDMAPPING']) &&
1010           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
1011         $this->attrs['objectClass'][]= "sambaIdmapEntry";
1012       }
1015       /* Password expiery */
1016       if ($this->password_expires == "1"){
1017         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1018       } else {
1019         $this->attrs['sambaPwdMustChange']= array();
1020       }
1021       /* Make sure not to save zero in sambaPwdLastset */
1022       if ($this->sambaPwdLastSet != "0"){
1023         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1024       } else {
1025         $this->attrs['sambaPwdLastSet']= array();
1026       }
1027       /* Account expiery */
1028       if ($this->logon_time_set == "1"){
1029         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1030       } else {
1031         $this->attrs['sambaLogonTime']= array();
1032       }
1033       if ($this->logoff_time_set == "1"){
1034         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1035       } else {
1036         $this->attrs['sambaLogoffTime']= array();
1037       }
1038       if ($this->kickoff_time_set == "1"){
1039         # Add one day in unixtime format to be compatible with usrmgr
1040         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1041         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1042       } else {
1043         $this->attrs['sambaKickoffTime']= array();
1044       }
1045     } else {
1046     /* Not samba3 */
1047       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1048       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1050       if ($this->homeDrive == ""){
1051         $this->attrs["homeDrive"]= array();
1052       }
1054       /* Password expiery */
1055       if ($this->password_expires == "1"){
1056         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1057       } else {
1058         $this->attrs['pwdMustChange']= 2147483647;
1059       }
1060       /* Make sure not to save zero in pwdLastset */
1061       if ($this->pwdLastSet != "0"){
1062         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1063       } else {
1064         $this->attrs['pwdLastSet']= array();
1065       }
1066       /* Account expiery */
1067       if ($this->logon_time_set == "1"){
1068         $this->attrs['logonTime']= $this->logonTime;
1069       } else {
1070         $this->attrs['logonTime']= array();
1071       }
1072       if ($this->logoff_time_set == "1"){
1073         $this->attrs['logoffTime']= $this->logoffTime;
1074       } else {
1075         $this->attrs['logoffTime']= array();
1076       }
1077       if ($this->kickoff_time_set == "1"){
1078         # Add one day in unixtime format to be compatible with usrmgr
1079         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1080       } else {
1081         $this->attrs['kickoffTime']= array();
1082       }
1083     }
1085     /* Write back to ldap */
1086     $ldap->cd($this->dn);
1087     $this->cleanup();
1088     $ldap->modify ($this->attrs); 
1090     if($this->initially_was_account){
1091       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1092     }else{
1093       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1094     }
1096     if (!$ldap->success()){
1097       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1098     }
1100     /* Optionally execute a command after we're done */
1101     if ($this->initially_was_account == $this->is_account){
1102       if ($this->is_modified){
1103         $this->handle_post_events("modify", array("uid" => $this->uid));
1104       }
1105     } else {
1106       $this->handle_post_events("add", array("uid" => $this->uid));
1107     }
1108   }
1111   /* Force password set, if this account doesn't have any samba passwords  */
1112   function password_change_needed()
1113   {
1114     if(!$this->initially_was_account && $this->is_account){
1115       $ldap = $this->config->get_ldap_link();
1116       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1117       $attrs = $ldap->fetch();
1118       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1119         return(TRUE);
1120       }
1121     }
1122     return(FALSE);
1123   }
1126   function adapt_from_template($dn, $skip= array())
1127   {
1128     plugin::adapt_from_template($dn, $skip);
1131     $this->sambaSID= "";
1132     $this->sambaPrimaryGroupSID= "";
1134     /* Fill mungedDial field */
1135     if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1136       $this->mungedObject->load($this->sambaMungedDial);
1137     }
1139     /* Adapt munged attributes */
1140     foreach($this->ctxattributes as $attr){
1141       if(isset($this->mungedObject->ctx[$attr]))
1142         $val = $this->mungedObject->ctx[$attr];
1144       foreach (array("sn", "givenName", "uid") as $repl){
1145         if (preg_match("/%$repl/i", $val)){
1146           $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1147         }
1148       }
1149       $this->mungedObject->ctx[$attr] = $val;
1150     }
1152     /* Password expiery */
1153     if(isset($this->attrs['sambaPwdMustChange']) &&
1154         $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1155       $this->password_expires= 1;
1156     }
1158     if(isset($this->attrs['sambaLogonTime']) && ! (
1159         $this->attrs['sambaLogonTime'][0] == 0 ||
1160         $this->attrs['sambaLogonTime'][0] == 2147483647
1161       ) && !in_array('sambaLogonTime', $skip)){
1162       $this->logon_time_set= 1;
1163     }
1164     if(isset($this->attrs['sambaLogoffTime']) && ! (
1165         $this->attrs['sambaLogoffTime'][0] == 0 ||
1166         $this->attrs['sambaLogoffTime'][0] == 2147483647
1167       ) && !in_array('sambaLogonTime', $skip)){
1168       $this->logoff_time_set= 1;
1169     }
1171     /* Account expiery */
1172     if(isset($this->attrs['sambaKickoffTime']) && ! (
1173         $this->attrs['sambaKickoffTime'][0] == 0 ||
1174         $this->attrs['sambaKickoffTime'][0] == 2147483647
1175       ) && !in_array('sambaKickoffTime', $skip)){
1176       $this->kickoff_time_set= 1;
1177     }
1179     /* Get global filter config */
1180     if (!session::is_set("sambafilter")){
1181       $ui= get_userinfo();
1182       $base= get_base_from_people($ui->dn);
1183       $sambafilter= array( "depselect" => $base, "regex" => "*");
1184       session::set("sambafilter", $sambafilter);
1185     }
1186   }
1188   
1189   static function plInfo()
1190   {
1191     return (array(
1192           "plShortName"     => _("Samba"),
1193           "plDescription"   => _("Samba settings"),
1194           "plSelfModify"    => TRUE,
1195           "plDepends"       => array("user"),
1196           "plPriority"      => 5,
1197           "plSection"     => array("personal" => _("My account")),
1198           "plCategory"    => array("users"),
1199           "plOptions"       => array(),
1201           "plProvidedAcls"  => array(
1203             "sambaHomePath"               => _("Generic home directory") ,
1204             "sambaHomeDrive"              => _("Generic samba home drive") ,
1205             "sambaDomainName"             => _("Domain") ,
1206             "sambaLogonScript"            => _("Generic script path") ,
1207             "sambaProfilePath"            => _("Generic profile path") ,
1208             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1209             "InheritClientConfig"         => _("Inherit client config"),
1210             "sambaPwdCanChange"           => _("Allow user to change password") ,
1211             "sambaAcctFlagsN"             => _("Login from windows client requires no password"),
1212             "sambaAcctFlagsL"             => _("Lock samba account"),
1213             "sambaKickoffTime"            => _("Account expires") ,
1214             "sambaPwdMustChange"          => _("Password expires") ,
1215             "sambaLogonTime"              => _("Limit Logon Time") ,
1216             "sambaLogoffTime"             => _("Limit Logoff Time") ,
1217             "sambaLogonHours"             => _("Logon hours") ,
1218             "sambaUserWorkstations"       => _("Allow connection from"))
1219           ));
1220   }    
1222   function enable_multiple_support()
1223   {
1224     plugin::enable_multiple_support();
1225     if($this->samba3){
1226       $this->multiple_support_active = TRUE;
1227     }else{
1228       $this->multiple_support_active = FALSE;
1229     }
1230   } 
1232   function multiple_save_object()
1233   {
1234     if (isset($_POST['sambaTab'])){
1235       $this->save_object();
1236       plugin::multiple_save_object();
1237       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1238             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1239             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1240             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1241             "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1242             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1243             "workstation_list") as $attr){
1244         if(isset($_POST["use_".$attr])){
1245           $this->multi_boxes[] = $attr;
1246         }
1247       }
1248     }
1249   }
1252   function multiple_check()
1253   {
1254     $message = plugin::multiple_check();
1256     /* Strings */
1257     foreach (array( "sambaHomePath" => _("Home directory"),
1258           "sambaProfilePath" => _("Profile path")) as $key => $val){
1259       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1260         $message[]= msgPool::invalid($val);
1261       }
1262     }
1264     /* Numeric values */
1265     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1266                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1267                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1268       if (in_array($key,$this->multi_boxes) && 
1269           isset($this->mungedObject->ctx[$key]) && 
1270           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1271         $message[]=msgPool::invalid($val);
1272       }
1273     }
1275     /* Too many workstations? Windows usrmgr only supports eight */
1276     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1277       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1278     }
1279     return($message);
1280   }
1282   
1283   function get_multi_init_values()
1284   {
1285     $ret = plugin::get_multi_init_values();
1287     /* Parse given sambaUserWorkstations into array
1288      *  to allow "init_multiple_support()" to detect multiple used workstations.
1289      *  Those workstations will be displayed in light grey.
1290      */
1291     $tmp2 = array("count" => 0);
1292     $tmp = split(",", $this->sambaUserWorkstations);
1293     foreach($tmp as $station){
1294       $station = trim($station);
1295       if(!empty($station)){
1296         $tmp2[] = $station;
1297         $tmp2['count'] ++;
1298       }
1299     } 
1300     $ret['sambaUserWorkstations'] = $tmp2;
1301     return($ret);
1302   }
1306   function init_multiple_support($attrs,$all)
1307   {
1308     plugin::init_multiple_support($attrs,$all);
1310     $this->multiple_sambaUserWorkstations = array();
1311     if(isset($all['sambaUserWorkstations'])){
1312       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1313         $station = trim($all['sambaUserWorkstations'][$i]);
1314         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1315       }
1316     }
1317     if(isset($attrs['sambaUserWorkstations'])){
1318       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1319         $station = trim($attrs['sambaUserWorkstations'][$i]);
1320         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1321       }
1322     }
1323   }
1325   function multiple_execute()
1326   {
1327     return($this->execute());
1328   } 
1330   function get_multi_edit_values()
1331   {
1332     $ret = plugin::get_multi_edit_values();
1334     /* Terminal Server  */
1335     if(in_array("tslogin",$this->multi_boxes)){
1336       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1337     }
1338     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1339       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1340     }
1341     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1342       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1343     }
1344     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1345       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1346     }
1348     if(in_array("inherit",$this->multi_boxes)){
1349       $ret['inherit'] = $this->mungedObject->getInheritMode();
1350     }       
1351     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1352       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1353     } 
1354     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1355       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1356     } 
1358     /* Time Limits. Be careful here, there are some negations  */
1359     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1360       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1361       if(!$ret["CtxMaxConnectionTimeF"]){
1362         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1363       }
1364     }
1365     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1366       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1367       if(!$ret["CtxMaxDisconnectionTimeF"]){
1368         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1369       }
1370     }
1371     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1372       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1373       if(!$ret["CtxMaxIdleTimeF"]){
1374         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1375       }
1376     }
1378     /* Client Devices */
1379     if(in_array("connectclientdrives",$this->multi_boxes)){
1380       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1381     }
1382     if(in_array("connectclientprinters",$this->multi_boxes)){
1383       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1384     }
1385     if(in_array("defaultprinter",$this->multi_boxes)){
1386       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1387     }
1389     /* Misc */
1390     if(in_array("shadow",$this->multi_boxes)){
1391       $ret["shadow"]    =$this->mungedObject->getShadow();
1392     }
1393     if(in_array("brokenconn",$this->multi_boxes)){
1394       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1395     }
1396     if(in_array("reconn",$this->multi_boxes)){
1397       $ret["reconn"]    =$this->mungedObject->getReConn();
1398     }
1400     /* Flags */
1401     if(in_array("allow_pwchange",$this->multi_boxes)){
1402       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1403       $ret['pwdCanChange']      = $this->pwdCanChange;
1404     }
1405   
1406     if(in_array("password_expires",$this->multi_boxes)){
1407       $ret['password_expires']  = $this->password_expires;
1408       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1409     }
1410     if(in_array("logon_time_set",$this->multi_boxes)){
1411       $ret['logon_time_set'] = $this->logon_time_set;
1412       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1413     }
1414     if(in_array("logoff_time_set",$this->multi_boxes)){
1415       $ret['logoff_time_set'] = $this->logoff_time_set;
1416       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1417     }
1418     if(in_array("kickoff_time_set",$this->multi_boxes)){
1419       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1420       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1421     }
1423     if(in_array("no_password_required",$this->multi_boxes)){
1424       $ret['no_password_required'] = $this->no_password_required;
1425     }
1427     if(in_array("temporary_disable",$this->multi_boxes)){
1428       $ret['temporary_disable'] = $this->temporary_disable;
1429     }
1430     
1431     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1432       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1433     }
1435     if(in_array("workstation_list",$this->multi_boxes)){
1436       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1437     }
1438     return($ret);
1439   }
1441   function set_multi_edit_values($values)
1442   {
1443     plugin::set_multi_edit_values($values);
1445     /* Prepare current workstation settings to be merged 
1446      *  with multiple edit settings.
1447      */
1448     if(isset($values['multiple_sambaUserWorkstations'])){
1449       $cur_ws = array();
1450       $m_ws = $values['multiple_sambaUserWorkstations'];
1452       /* Prepare current settings to be merged */
1453       if(isset($this->sambaUserWorkstations)){
1454         $ttmp = split(",",$this->sambaUserWorkstations);
1455         foreach($ttmp as $station){
1456           $station = trim($station);
1457           if(!empty($station)){
1458             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1459           }
1460         }
1461       }
1463       /* Unset removed workstations */
1464       foreach($cur_ws as $cur_name => $cur_station){
1465         if(!isset($m_ws[$cur_name])){
1466           unset($cur_ws[$cur_name]);
1467         }
1468       }
1470       /* Add all added workstations */
1471       foreach($m_ws as $name => $station){
1472         if($station['UsedByAllUsers']){
1473           $cur_ws[$name] = $station;
1474         }
1475       }
1477       $this->sambaUserWorkstations = "";
1478       foreach($cur_ws as $name => $ws){
1479         $this->sambaUserWorkstations .= $name.",";
1480       }
1481       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1482     }
1484     /* Enable disabled terminal login, this is inverted somehow */
1485     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1486   
1487     /* Imherit client configuration */
1488     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1489   
1490     /* Get all ctx values posted */
1491     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1492                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1493     foreach($ctx as $attr){
1494       if(isset($values[$attr])){
1495         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1496       }
1497     }
1499     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1500     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1501     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1503     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1504     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1505     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1507     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1508     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1509     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1511   
1512     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1513     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1515     
1516     
1518     if(isset($values['password_expires'])){
1519       $this->password_expires = $values['password_expires'];
1520       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1521     }
1522     if(isset($values['logon_time_set'])){
1523       $this->logon_time_set = $values['logon_time_set'];
1524       $this->sambaLogonTime = $values['sambaLogonTime'];
1525     }
1526     if(isset($values['logoff_time_set'])){
1527       $this->logoff_time_set = $values['logoff_time_set'];
1528       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1529     }
1530     if(isset($values['kickoff_time_set'])){
1531       $this->kickoff_time_set = $values['kickoff_time_set'];
1532       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1533     }
1535     if(isset($values['no_password_required'])){
1536       if($values['no_password_required']){
1537         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1538           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1539         }
1540       }else{
1541         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1542       }
1543     }      
1545     if(isset($values['temporary_disable'])){
1546       if($values['temporary_disable']){
1547         if(preg_match("/L/",$this->sambaAcctFlags)) {
1548           // Keep L
1549         }else{
1550           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1551         }
1552       }else{
1553         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1554       }
1555     }
1556   }
1559   function PrepareForCopyPaste($source)
1560   {
1561     plugin::PrepareForCopyPaste($source);
1563     /* Set a new SID */
1564     $this->sambaSID = "";
1565   }
1569 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1570 ?>