Code

Moved samba to the samba plugin part
[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   /* 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;
96   /* Only used  for multiple edit */
97   var $temporary_disable = FALSE;
98   var $no_password_required = FALSE;
99   var $multiple_sambaUserWorkstations = array();
101   function sambaAccount (&$config, $dn= NULL)
102   {
103     /* Load attributes depending on the samba version */
104     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
106     if ($this->samba3){
107       $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
108           "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
109           "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
110           "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
111           "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
112           "sambaUserWorkstations", "sambaPasswordHistory",
113           "sambaLogonHours", "sambaBadPasswordTime",
114           "sambaBadPasswordCount");
115       $this->objectclasses= array ("sambaSamAccount");
116       $this->mungedObject= new sambaMungedDial;
117       $this->ctxattributes= $this->mungedObject->ctxattributes;
118     } else {
119       $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
120           "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
121           "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
122       $this->objectclasses= array ("sambaAccount");
123     }
125     plugin::plugin ($config, $dn);
127     /* Setting uid to default */
128     if(isset($this->attrs['uid'][0])){
129       $this->uid = $this->attrs['uid'][0];
130     }
132     /* Get samba Domain in case of samba 3 */
133     if ($this->samba3 && $this->sambaSID != ""){
134       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
135       $ldap= $this->config->get_ldap_link();
136       $ldap->cd($this->config->current['BASE']);
137       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
138       if ($ldap->count() != 0){
139         $attrs= $ldap->fetch();
140         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
141         if ($this->sambaDomainName == ""){
142           $this->sambaDomainName= $attrs['sambaDomainName'][0];
143         }
144       } else {
145         if ($this->sambaDomainName == ""){
146           $this->sambaDomainName= "DEFAULT";
147         }
148         $this->ridBase= $this->config->current['RIDBASE'];
149         $this->SID= $this->config->current['SID'];
150       }
152       /* Save in order to compare later on */
153       $this->orig_sambaDomainName= $this->sambaDomainName;
154     }
156     /* Fill mungedDial field */
157     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
158       $this->mungedObject->load($this->sambaMungedDial);
159     }
161     /* Password expiery */
162     if(isset($this->attrs['sambaPwdMustChange']) &&
163         $this->attrs['sambaPwdMustChange'][0] != 0){
164       $this->password_expires= 1;
165     }
167     if(isset($this->attrs['sambaLogonTime']) && ! (
168         $this->attrs['sambaLogonTime'][0] == 0 ||
169         $this->attrs['sambaLogonTime'][0] == 2147483647
170       )){
171       $this->logon_time_set= 1;
172     }
173     if(isset($this->attrs['sambaLogoffTime']) && ! (
174         $this->attrs['sambaLogoffTime'][0] == 0 ||
175         $this->attrs['sambaLogoffTime'][0] == 2147483647
176       )){
177       $this->logoff_time_set= 1;
178     }
179     
180     /* Account expiery */
181     if(isset($this->attrs['sambaKickoffTime']) && ! (
182         $this->attrs['sambaKickoffTime'][0] == 0 ||
183         $this->attrs['sambaKickoffTime'][0] == 2147483647
184       )){
185       $this->kickoff_time_set= 1;
186     }
188     /* Get global filter config */
189     if (!session::is_set("sambafilter")){
190       $ui= get_userinfo();
191       $base= get_base_from_people($ui->dn);
192       $sambafilter= array( "depselect" => $base, "regex" => "*");
193       session::set("sambafilter", $sambafilter);
194     }
196     /* Save initial account state */
197     $this->initially_was_account= $this->is_account;
198   }
200   function execute()
201   {
202     /* Call parent execute */
203     plugin::execute();
205     /* Log view */
206     if($this->is_account && !$this->view_logged){
207       $this->view_logged = TRUE;
208       new log("view","users/".get_class($this),$this->dn);
209     }
211     /* Do we need to flip is_account state? */
212     if (isset($_POST['modify_state'])){
213       $this->is_account= !$this->is_account;
214     }
215     /* Do we represent a valid account? */
216     if (!$this->is_account && $this->parent === NULL){
217       $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
218         _("This account has no samba extensions.")."</b>";
219       $display.= back_to_main();
220       return ($display);
221     }
223     $display ="";
224     if(!$this->multiple_support_active){
226       /* Show tab dialog headers */
227       $display= "";
228       if ($this->parent !== NULL){
229         if ($this->is_account){
230           $display= $this->show_disable_header(_("Remove samba account"),
231               _("This account has samba features enabled. You can disable them by clicking below."));
232         } else {
233           $obj= $this->parent->by_object['posixAccount'];
235           /* Samba3 dependency on posix accounts are enabled
236              in the moment, because I need to rely on unique
237              uidNumbers. There'll be a better solution later
238              on. */
239           if ($obj->is_account){
240             $display= $this->show_enable_header(_("Create samba account"),
241                 _("This account has samba features disabled. You can enable them by clicking below."));
242           } else {
243             $display= $this->show_enable_header(_("Create samba account"),
244                 _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
245           }
246           return ($display);
247         }
248       }
249     }
251     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
253     /* Open Samaba Logong hours dialog */
254     if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
255       $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
256     }
258     /* Cancel dialog */
259     if(isset($_POST['cancel_logonHours'])){
260       $this->dialog = FALSE;
261     }
263     /* Save selected logon hours */
264     if(isset($_POST['save_logonHours'])){
265       $this->dialog->save_object();
266       if($this->acl_is_writeable("sambaLogonHours")){
267         $this->sambaLogonHours = $this->dialog->save();
268       }
269       $this->dialog = FALSE;
270     }
272     /* Display dialog */
273     if((isset($this->dialog)) && (is_object($this->dialog))){
274       $this->dialog->save_object();
275       return($this->dialog->execute());
276     }
278     /* Prepare templating */
279     $smarty= get_smarty();
281     $tmp = $this->plInfo();
282     foreach($tmp['plProvidedAcls'] as $var => $rest){
283       $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
284     }
286     if ($this->sambaPwdMustChange=="0"){
287       $date= getdate();
288     } else {
289       $date= getdate($this->sambaPwdMustChange);
290     }
292     if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
293       $sambaLogonTime_date= getdate();
294     } else {
295       $sambaLogonTime_date= getdate($this->sambaLogonTime);
296     }
297     
298     if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
299       $sambaLogoffTime_date= getdate();
300     } else {
301       $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
302     }
303     
304     if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
305       $sambaKickoffTime_date= getdate();
306     } else {
307       $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
308     }
310     /* Remove user workstations? */
311     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
313       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
315         if($this->multiple_support_active){
316           foreach($_POST['workstation_list'] as $name){
317             if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
318               unset($this->multiple_sambaUserWorkstations[trim($name)]);
319             }
320           } 
321         }else{
322           $tmp= $this->sambaUserWorkstations;
323           foreach($_POST['workstation_list'] as $name){
324             $tmp= preg_replace("/$name/", '', $tmp);
325             $this->is_modified= TRUE;
326           }
327           $tmp= preg_replace('/,+/', ',', $tmp);
328           $this->sambaUserWorkstations= trim($tmp, ',');
329         }
330       }
331     }
333     /* Add user workstation? */
334     if (isset($_POST["add_ws"])){
335       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
336         $this->show_ws_dialog= TRUE;
337         $this->dialog= TRUE;
338       }
339     }
341     /* Add user workstation finished? */
342     if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
343       $this->show_ws_dialog= FALSE;
344       $this->dialog= FALSE;
345     }
347     /* Add user workstation? */
348     if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
350       if($this->multiple_support_active){
351         foreach($_POST['wslist'] as $ws){
352           $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
353         }
354       }else{
355         $tmp= $this->sambaUserWorkstations;
356         foreach($_POST['wslist'] as $ws){
357           $tmp.= ",$ws";
358         }
359         $tmp= preg_replace('/,+/', ',', $tmp);
360         $this->sambaUserWorkstations= trim($tmp, ',');
361       }
362       $this->is_modified= TRUE;
363     }
365     /* Show ws dialog */
366     if ($this->show_ws_dialog){
368       /* Save data */
369       $sambafilter= session::get("sambafilter");
370       foreach( array("depselect", "regex") as $type){
371         if (isset($_POST[$type])){
372           $sambafilter[$type]= $_POST[$type];
373         }
374       }
375       if (isset($_GET['search'])){
376         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
377         if ($s == "**"){
378           $s= "*";
379         }
380         $sambafilter['regex']= $s;
381       }
382       session::set("sambafilter", $sambafilter);
384       /* Get workstation list */
385       $exclude= "";
387       if($this->multiple_support_active){
388         foreach($this->multiple_sambaUserWorkstations as $ws){
389           if($ws['UsedByAllUsers']){
390             $exclude.= "(cn=".$ws['Name']."$)";
391           }
392         }
393       }else{
394         foreach(split(',', $this->sambaUserWorkstations) as $ws){
395           $exclude.= "(cn=$ws$)";
396         }
397       }
398       if ($exclude != ""){
399         $exclude= "(!(|$exclude))";
400       }
401       $regex= $sambafilter['regex'];
402       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
403       $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
404         
405       $wslist= array();
406       foreach ($res as $attrs){
407         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
408       }
409       asort($wslist);
411       $smarty->assign("search_image", get_template_path('images/search.png'));
412       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
413       $smarty->assign("tree_image", get_template_path('images/tree.png'));
414       $smarty->assign("deplist", $this->config->idepartments);
415       $smarty->assign("alphabet", generate_alphabet());
416       foreach( array("depselect", "regex") as $type){
417         $smarty->assign("$type", $sambafilter[$type]);
418       }
419       $smarty->assign("hint", print_sizelimit_warning());
420       $smarty->assign("wslist", $wslist);
421       $smarty->assign("apply", apply_filter());
422       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
423                                 dirname(__FILE__)));
424       return ($display);
425     }
427     /* Fill calendar */
428     $days= array();
429     for($d= 1; $d<32; $d++){
430       $days[]= $d;
431     }
432     $years= array();
433     for($y= $date['year']-4; $y<$date['year']+4; $y++){
434       $years[]= $y;
435     }
436     $months= array(_("January"), _("February"), _("March"), _("April"),
437         _("May"), _("June"), _("July"), _("August"), _("September"),
438         _("October"), _("November"), _("December"));
439     $smarty->assign("day", $date["mday"]);
440     $smarty->assign("days", $days);
441     $smarty->assign("months", $months);
442     $smarty->assign("month", $date["mon"]-1);
443     $smarty->assign("years", $years);
444     $smarty->assign("year", $date["year"]);
445     
446     $sambaLogonTime_days= array();
447     for($d= 1; $d<32; $d++){
448       $sambaLogonTime_days[]= $d;
449     }
450     $sambaLogonTime_years= array();
451     for($y= $date['year']-4; $y<$date['year']+4; $y++){
452       $sambaLogonTime_years[]= $y;
453     }
454     $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
455         _("May"), _("June"), _("July"), _("August"), _("September"),
456         _("October"), _("November"), _("December"));
457     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
458     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
459     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
460     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
461     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
462     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
463     
464     $sambaLogoffTime_days= array();
465     for($d= 1; $d<32; $d++){
466       $sambaLogoffTime_days[]= $d;
467     }
468     $sambaLogoffTime_years= array();
469     for($y= $date['year']-4; $y<$date['year']+4; $y++){
470       $sambaLogoffTime_years[]= $y;
471     }
472     $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
473         _("May"), _("June"), _("July"), _("August"), _("September"),
474         _("October"), _("November"), _("December"));
475     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
476     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
477     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
478     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
479     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
480     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
481     
482     $sambaKickoffTime_days= array();
483     for($d= 1; $d<32; $d++){
484       $sambaKickoffTime_days[]= $d;
485     }
486     $sambaKickoffTime_years= array();
487     for($y= $date['year']-4; $y<$date['year']+4; $y++){
488       $sambaKickoffTime_years[]= $y;
489     }
490     $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
491         _("May"), _("June"), _("July"), _("August"), _("September"),
492         _("October"), _("November"), _("December"));
493     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
494     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
495     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
496     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
497     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
498     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
499     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
500      
501     /* Fill boxes */
502     if ($this->samba3){
503       $domains= array();
504       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
505         $domains[]= $name;
506       }
507       $smarty->assign("domains", $domains);
508     }
509     $letters= array();
510     for ($i= 68; $i<91; $i++){
511       $letters[]= chr($i).":";
512     }
513     $smarty->assign("drives", $letters);
515     /* Fill terminal server settings */
516     if ($this->samba3){
517       foreach ($this->ctxattributes as $attr){
518         /* Fill common attributes */
519         if (isset($this->mungedObject->ctx[$attr])){
520           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
521           // Set field  to blank if value is 0
522           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
523             if($this->mungedObject->ctx[$attr] == 0) {
524               $smarty->assign("$attr", "");
525             }
526           }
527         } else {
528           $smarty->assign("$attr", "");
529         }
530       }
532       /* Assign enum values for preset items */
533       $shadowModeVals= array( "0" => _("disabled"),
534           "1" => _("input on, notify on"),
535           "2" => _("input on, notify off"),
536           "3" => _("input off, notify on"),
537           "4" => _("input off, nofify off"));
539       $brokenConnModeVals= array(       "0" => _("disconnect"),
540           "1" => _("reset"));
542       $reConnModeVals= array( "0" => _("from any client"),
543           "1" => _("from previous client only"));
545       /* Fill preset items */
546       $smarty->assign("shadow", $shadowModeVals);
547       $smarty->assign("brokenconn", $brokenConnModeVals);
548       $smarty->assign("reconn", $reConnModeVals);
550       /* Fill preset items with values */
551       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
552       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
553       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
555       if(session::get('js')){
556         /* Set form elements to disabled/enable state */
557         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
559         $smarty->assign("inheritstate", "");
560         if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
561           $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
562         }
563       }else{
564         $smarty->assign("tsloginstate", "");
565         $smarty->assign("inheritstate", "");
566       }      
568       /* Set checkboxes to checked or unchecked state */
569       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
570       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
571       $smarty->assign("connectclientdrives",
572                       $this->mungedObject->getConnectClientDrives()?"checked":"");
573       $smarty->assign("connectclientprinters",
574                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
575       $smarty->assign("defaultprinter",
576                       $this->mungedObject->getDefaultPrinter()?"checked":"");
577       $smarty->assign("CtxMaxConnectionTimeF",
578                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
579       $smarty->assign("CtxMaxDisconnectionTimeF",
580                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
581       $smarty->assign("CtxMaxIdleTimeF",
582                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
584       
585       /* Fill sambaUserWorkstations */
586       $ws= split(",", $this->sambaUserWorkstations);
587       sort($ws);
588       
589       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
590       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
592       if($this->multiple_support_active){
593         $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
594       }  
596       $smarty->assign("workstations", $ws);
597     }
599     /* Variables */
600     foreach($this->attributes as $val){
601       $smarty->assign("$val", $this->$val);
602     }
604     /* 'sambaAcctFlags' checkboxes */
605     /* Check for 'lock-account'-flag: 'D' or 'L' */
606     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
607         is_integer(strpos($this->sambaAcctFlags, "L"))) {
608         $smarty->assign("flagsD", "checked");
609     } else {
610         $smarty->assign("flagsD", "");
611     }
612     
613     /* Check for no_password_required flag 'N' */
614     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
615         $smarty->assign("flagsN", "checked");
616     } else {
617         $smarty->assign("flagsN", "");
618     }
620     if($this->samba3){
621       if ($this->sambaPwdCanChange=="1"){
622         $smarty->assign("flagsP", "checked");
623       } else {
624         $smarty->assign("flagsP", "");
625       }
626     }else{
627       if ($this->pwdCanChange=="1"){
628         $smarty->assign("flagsP", "checked");
629       } else {
630         $smarty->assign("flagsP", "");
631       }
632     }
634     if ($this->password_expires=="1"){
635       $smarty->assign("flagsC", "checked");
636     } else {
637       $smarty->assign("flagsC", "");
638     }
639     if ($this->logon_time_set=="1"){
640       $smarty->assign("flagsT", "checked");
641     } else {
642       $smarty->assign("flagsT", "");
643     }
644     if ($this->logoff_time_set=="1"){
645       $smarty->assign("flagsO", "checked");
646     } else {
647       $smarty->assign("flagsO", "");
648     }
649     if ($this->kickoff_time_set=="1"){
650       $smarty->assign("flagsK", "checked");
651     } else {
652       $smarty->assign("flagsK", "");
653     }
654    
656     /* In case of javascript, disable some fields on demand */
657     if ($this->samba3){
658       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
659         $smarty->assign("$key", "$value");
660       }
661     }
664     foreach($this->attributes as $attr){
665       if(in_array($attr,$this->multi_boxes)){
666         $smarty->assign("use_".$attr,TRUE);
667       }else{
668         $smarty->assign("use_".$attr,FALSE);
669       }
670     }
671     foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
672           "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
673           "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
674           "onnectclientprinters","defaultprinter","shadow","brokenconn",
675           "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable", 
676           "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
677           "workstation_list") as $attr){
678       if(in_array($attr,$this->multi_boxes)){
679         $smarty->assign("use_".$attr,TRUE);
680       }else{
681         $smarty->assign("use_".$attr,FALSE);
682       }
683     }
685     if($this->multiple_support_active){
686       $smarty->assign("tsloginstate","");
687     }
689     /* Show main page */
690     $smarty->assign("multiple_support",$this->multiple_support_active);
691     if ($this->samba3){
692       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
693     } else {
694       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
695     }
697     return ($display);
698   }
700   function remove_from_parent()
701   {
702     /* Cancel if there's nothing to do here */
703    if (!$this->initially_was_account){
704      return;
705    }
706     
707     /* include global link_info */
708     $ldap= $this->config->get_ldap_link();
710     plugin::remove_from_parent();
712     /* Keep uid attribute for gosaAccount */
713     unset($this->attrs['uid']);
714     unset($this->attrs['uidNumber']);
715     unset($this->attrs['gidNumber']);
717     /* Remove objectClass for sambaIdmapEntry */
718     $tmp= array();
719     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
720       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
721         $tmp[]= $this->attrs['objectClass'][$i];
722       }
723     }
724     $this->attrs['objectClass']= $tmp;
726     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
727         $this->attributes, "Save");
728     $ldap->cd($this->dn);
729     $this->cleanup();
730     $ldap->modify ($this->attrs); 
732     new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
734     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
736     /* Optionally execute a command after we're done */
737     $this->handle_post_events("remove", array("uid" => $this->uid));
738   }
741   /* Check for input problems */
742   function check()
743   {
744     /* Call common method to give check the hook */
745     $message= plugin::check();
747     if ($this->samba3){
749       /* Strings */
750       foreach (array( "sambaHomePath" => _("Home directory"),
751             "sambaProfilePath" => _("Profile path")) as $key => $val){
752         if (!$this->mungedObject->is_samba_path($this->$key)){
753           $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
754         }
755       }
757       /* Numeric values */
758       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
759             "CtxMaxDisconnectionTime" => _("Disconnection"),
760             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
762         if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
763           $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
764         }
765       }
767       /* Too many workstations? Windows usrmgr only supports eight */
768       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
769         $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
770       }
771     }
773     return ($message);
774   }
777   /* Save data to object */
778   function save_object()
779   {
781     $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
783     /* We only care if we are on the sambaTab... */
784     if (isset($_POST['sambaTab'])){
785       plugin::save_object();
787       /* Take care about access options */
788       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
789         if ($this->samba3){
790           $attrname= "sambaPwdCanChange";
791         } else {
792           $attrname= "pwdCanChange";
793         }
794         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
795           $tmp= 1;
796         } else {
797           $tmp= 0;
798         }
799         if ($this->$attrname != $tmp){
800           $this->is_modified= TRUE;
801         }
802         $this->pwdCanChange= $tmp;
803         $this->sambaPwdCanChange= $tmp;
804       }
805       $tmp= "UX";
806       $this->no_password_required = FALSE;
807       if (isset($_POST["no_password_required"])){
808         if ($_POST["no_password_required"] == 1){
809           $tmp.= "N";
810           $this->no_password_required = TRUE;
811         }
812       }
813       if (isset($_POST["password_expires"])){
814         if ($_POST["password_expires"] == 1){
815           $this->password_expires= 1;
816         }
817       } else {
818         $this->password_expires= 0;
819       }
820       $this->temporary_disable = FALSE;
821       if (isset($_POST["temporary_disable"])){
822         if ($_POST["temporary_disable"] == 1){
823           $this->temporary_disable = TRUE;
824           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
825             $tmp.= "L";
826           } else {
827             $tmp.= "D";
828           }
829         }
830       }
831       if (isset($_POST["logon_time_set"])){
832         if ($_POST["logon_time_set"] == 1){
833           $this->logon_time_set= 1;
834         }
835       } else {
836         $this->logon_time_set= 0;
837       }
838       if (isset($_POST["logoff_time_set"])){
839         if ($_POST["logoff_time_set"] == 1){
840           $this->logoff_time_set= 1;
841         }
842       } else {
843         $this->logoff_time_set= 0;
844       }
845       if (isset($_POST["kickoff_time_set"])){
846         if ($_POST["kickoff_time_set"] == 1){
847           $this->kickoff_time_set= 1;
848         }
849       } else {
850         $this->kickoff_time_set= 0;
851       }
852       
853       $fill= "";
854       for ($i= strlen($tmp); $i<12; $i++){
855         $fill.= " ";
856       }
858       $tmp= "[$tmp$fill]";
860       /* Only save if acl's are set */
861       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
862         if ($this->samba3){
863           $attrname= "sambaAcctFlags";
864         } else {
865           $attrname= "acctFlags";
866         }
867         if ($this->$attrname != $tmp){
868           $this->is_modified= TRUE;
869         }
870         $this->$attrname= $tmp;
871       }
873       /* Save sambaDomain attribute */
874       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
875         $this->sambaDomainName= validate($_POST['sambaDomainName']);
876       }
878       /* Save CTX values */
879       if ($this->samba3){
881         /* Save obvious values */
882         foreach($this->ctxattributes as $val){
883           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
884             if (get_magic_quotes_gpc()) {
885               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
886             } else {
887               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
888             }
889           }
890         }
892         /* Save checkbox states. */
893         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
894                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
895         // Need to do some index checking to avoid messages like "index ... not found"
896         if(isset($_POST['brokenconn'])) {
897           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
898                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
899         }
900         if(isset($_POST['reconn'])) {
901           $this->mungedObject->setReConn($_POST['reconn'] == '1'
902                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
903         }
904         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
905                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
906         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
907                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
908         $this->mungedObject->setCtxMaxDisconnectionTimeF(
909                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
910                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
911         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
912                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
913         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
914                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
915         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
916                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
917         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
918                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
920         /* Save combo boxes. Takes two values */
921         if(isset($_POST['reconn'])) {
922           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
923         }
925         /* Check for changes */
926         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
927           $this->is_modified= TRUE;
928         }
929       }
930     }
931   }
934   /* Save to LDAP */
935   function save()
936   {
937     /* Load uid and gid of this 'dn' */
938     $ldap= $this->config->get_ldap_link();
939     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
940     $tmp= $ldap->fetch();
941     $this->uidNumber= $tmp['uidNumber'][0];
942     $this->gidNumber= $tmp['gidNumber'][0];
944     plugin::save();
946     /* Remove objectClass for sambaIdmapEntry */
947     $tmp= array();
948     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
949       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
950         $tmp[]= $this->attrs['objectClass'][$i];
951       }
952     }
953     $this->attrs['objectClass']= $tmp;
955     /* Generate rid / primaryGroupId */
956     if ($this->samba3){
957       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
958         msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
959       } else {
960         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
961         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
962       }
964       /* Need to generate a new uniqe uid/gid combination? */
965       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
966         $uidNumber= $this->uidNumber;
967         while(TRUE){
968           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
969           $ldap->cd($this->config->current['BASE']);
970           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
971           if ($ldap->count() == 0){
972             break;
973           }
974           $uidNumber++;
975         }
976         $this->attrs['sambaSID']= $sid;
978         /* Check for users primary group */
979         $ldap->cd($this->config->current['BASE']);
980         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
981         if ($ldap->count() != 1){
982           msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
983         } else {
984           $attrs= $ldap->fetch();
985           $g= new group($this->config, $ldap->getDN());
986           if ($g->sambaSID == ""){
987             $g->sambaDomainName= $this->sambaDomainName;
988             $g->smbgroup= TRUE;
989             $g->save ();
990           }
991           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
992         }
993       }
995       if ($this->sambaHomeDrive == ""){
996         $this->attrs["sambaHomeDrive"]= array();
997       }
999       /* Generate munged dial value */
1000       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1002       /* User wants me to fake the idMappings? This is useful for
1003          making winbind resolve the user names in a reasonable amount
1004          of time in combination with larger databases. */
1005       if (isset($this->config->current['SAMBAIDMAPPING']) &&
1006           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
1007         $this->attrs['objectClass'][]= "sambaIdmapEntry";
1008       }
1011       /* Password expiery */
1012       if ($this->password_expires == "1"){
1013         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1014       } else {
1015         $this->attrs['sambaPwdMustChange']= array();
1016       }
1017       /* Make sure not to save zero in sambaPwdLastset */
1018       if ($this->sambaPwdLastSet != "0"){
1019         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1020       } else {
1021         $this->attrs['sambaPwdLastSet']= array();
1022       }
1023       /* Account expiery */
1024       if ($this->logon_time_set == "1"){
1025         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1026       } else {
1027         $this->attrs['sambaLogonTime']= array();
1028       }
1029       if ($this->logoff_time_set == "1"){
1030         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1031       } else {
1032         $this->attrs['sambaLogoffTime']= array();
1033       }
1034       if ($this->kickoff_time_set == "1"){
1035         # Add one day in unixtime format to be compatible with usrmgr
1036         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
1037         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
1038       } else {
1039         $this->attrs['sambaKickoffTime']= array();
1040       }
1041     } else {
1042     /* Not samba3 */
1043       $this->attrs['rid']= $this->uidNumber*2 + 1000;
1044       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1046       if ($this->homeDrive == ""){
1047         $this->attrs["homeDrive"]= array();
1048       }
1050       /* Password expiery */
1051       if ($this->password_expires == "1"){
1052         $this->attrs['pwdMustChange']= $this->pwdMustChange;
1053       } else {
1054         $this->attrs['pwdMustChange']= 2147483647;
1055       }
1056       /* Make sure not to save zero in pwdLastset */
1057       if ($this->pwdLastSet != "0"){
1058         $this->attrs['pwdLastSet']= $this->pwdLastSet;
1059       } else {
1060         $this->attrs['pwdLastSet']= array();
1061       }
1062       /* Account expiery */
1063       if ($this->logon_time_set == "1"){
1064         $this->attrs['logonTime']= $this->logonTime;
1065       } else {
1066         $this->attrs['logonTime']= array();
1067       }
1068       if ($this->logoff_time_set == "1"){
1069         $this->attrs['logoffTime']= $this->logoffTime;
1070       } else {
1071         $this->attrs['logoffTime']= array();
1072       }
1073       if ($this->kickoff_time_set == "1"){
1074         # Add one day in unixtime format to be compatible with usrmgr
1075         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1076       } else {
1077         $this->attrs['kickoffTime']= array();
1078       }
1079     }
1081     /* Write back to ldap */
1082     $ldap->cd($this->dn);
1083     $this->cleanup();
1084     $ldap->modify ($this->attrs); 
1086     if($this->initially_was_account){
1087       new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1088     }else{
1089       new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1090     }
1092     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
1094     /* Optionally execute a command after we're done */
1095     if ($this->initially_was_account == $this->is_account){
1096       if ($this->is_modified){
1097         $this->handle_post_events("modify", array("uid" => $this->uid));
1098       }
1099     } else {
1100       $this->handle_post_events("add", array("uid" => $this->uid));
1101     }
1102   }
1105   /* Force password set, if this account doesn't have any samba passwords  */
1106   function password_change_needed()
1107   {
1108     if(!$this->initially_was_account && $this->is_account){
1109       $ldap = $this->config->get_ldap_link();
1110       $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1111       $attrs = $ldap->fetch();
1112       if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1113         return(TRUE);
1114       }
1115     }
1116     return(FALSE);
1117   }
1120   function adapt_from_template($dn)
1121   {
1122     plugin::adapt_from_template($dn);
1123     $this->sambaSID= "";
1124     $this->sambaPrimaryGroupSID= "";
1126       /* Fill mungedDial field */
1127     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1128       $this->mungedObject->load($this->sambaMungedDial);
1129     }
1131     /* Password expiery */
1132     if(isset($this->attrs['sambaPwdMustChange']) &&
1133         $this->attrs['sambaPwdMustChange'][0] != 0){
1134       $this->password_expires= 1;
1135     }
1137     if(isset($this->attrs['sambaLogonTime']) && ! (
1138         $this->attrs['sambaLogonTime'][0] == 0 ||
1139         $this->attrs['sambaLogonTime'][0] == 2147483647
1140       )){
1141       $this->logon_time_set= 1;
1142     }
1143     if(isset($this->attrs['sambaLogoffTime']) && ! (
1144         $this->attrs['sambaLogoffTime'][0] == 0 ||
1145         $this->attrs['sambaLogoffTime'][0] == 2147483647
1146       )){
1147       $this->logoff_time_set= 1;
1148     }
1150     /* Account expiery */
1151     if(isset($this->attrs['sambaKickoffTime']) && ! (
1152         $this->attrs['sambaKickoffTime'][0] == 0 ||
1153         $this->attrs['sambaKickoffTime'][0] == 2147483647
1154       )){
1155       $this->kickoff_time_set= 1;
1156     }
1158     /* Get global filter config */
1159     if (!session::is_set("sambafilter")){
1160       $ui= get_userinfo();
1161       $base= get_base_from_people($ui->dn);
1162       $sambafilter= array( "depselect" => $base, "regex" => "*");
1163       session::set("sambafilter", $sambafilter);
1164     }
1165   }
1167   
1168   static function plInfo()
1169   {
1170     return (array(
1171           "plShortName"     => _("Samba"),
1172           "plDescription"   => _("Samba settings"),
1173           "plSelfModify"    => TRUE,
1174           "plDepends"       => array("user"),
1175           "plPriority"      => 5,
1176           "plSection"     => array("personal" => _("My account")),
1177           "plCategory"    => array("users"),
1178           "plOptions"       => array(),
1180           "plProvidedAcls"  => array(
1181             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1182             "InheritClientConfig"         => _("Inherit client config"),
1184             "sambaPwdCanChange"     => _("Allow user to change password") ,
1185             "sambaAcctFlagsN"            => _("Login from windows client requires no password"),
1186             "sambaAcctFlagsL"            => _("Lock samba account"),
1189             "sambaKickoffTime"      => _("Account expires") ,
1190             "sambaPwdMustChange"    => _("Password expires") ,
1192             "sambaLogonTime"        => _("Limit Logon Time") ,
1193             "sambaLogoffTime"       => _("Limit Logoff Time") ,
1194             "sambaLogonHours"       => _("Logon hours") ,
1196             "sambaHomePath"         => _("Generic home directory") ,
1197             "sambaHomeDrive"        => _("Generic samba home drive") ,
1198             "sambaLogonScript"      => _("Generic script path") ,
1199             "sambaProfilePath"      => _("Generic profile path") ,
1200             "sambaDomainName"       => _("Domain") ,
1201             "sambaUserWorkstations" => _("Allow connection from")))
1202               );
1203   }    
1205   function enable_multiple_support()
1206   {
1207     plugin::enable_multiple_support();
1208     if($this->samba3){
1209       $this->multiple_support_active = TRUE;
1210     }else{
1211       $this->multiple_support_active = FALSE;
1212     }
1213   } 
1215   function multiple_save_object()
1216   {
1217     if (isset($_POST['sambaTab'])){
1218       $this->save_object();
1219       plugin::multiple_save_object();
1220       foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1221             "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1222             "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1223             "onnectclientprinters","defaultprinter","shadow","brokenconn",
1224             "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1225             "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1226             "workstation_list") as $attr){
1227         if(isset($_POST["use_".$attr])){
1228           $this->multi_boxes[] = $attr;
1229         }
1230       }
1231     }
1232   }
1235   function multiple_check()
1236   {
1237     $message = plugin::multiple_check();
1239     /* Strings */
1240     foreach (array( "sambaHomePath" => _("Home directory"),
1241           "sambaProfilePath" => _("Profile path")) as $key => $val){
1242       if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1243         $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
1244       }
1245     }
1247     /* Numeric values */
1248     foreach (array( "CtxMaxConnectionTime"    => _("Connection"),
1249                     "CtxMaxDisconnectionTime" => _("Disconnection"),
1250                     "CtxMaxIdleTime"          => _("IDLE")) as $key => $val){
1251       if (in_array($key,$this->multi_boxes) && 
1252           isset($this->mungedObject->ctx[$key]) && 
1253           !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1254         $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
1255       }
1256     }
1258     /* Too many workstations? Windows usrmgr only supports eight */
1259     if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1260       $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1261     }
1262     return($message);
1263   }
1265   
1266   function get_multi_init_values()
1267   {
1268     $ret = plugin::get_multi_init_values();
1270     /* Parse given sambaUserWorkstations into array
1271      *  to allow "init_multiple_support()" to detect multiple used workstations.
1272      *  Those workstations will be displayed in light grey.
1273      */
1274     $tmp2 = array("count" => 0);
1275     $tmp = split(",", $this->sambaUserWorkstations);
1276     foreach($tmp as $station){
1277       $station = trim($station);
1278       if(!empty($station)){
1279         $tmp2[] = $station;
1280         $tmp2['count'] ++;
1281       }
1282     } 
1283     $ret['sambaUserWorkstations'] = $tmp2;
1284     return($ret);
1285   }
1289   function init_multiple_support($attrs,$all)
1290   {
1291     plugin::init_multiple_support($attrs,$all);
1293     $this->multiple_sambaUserWorkstations = array();
1294     if(isset($all['sambaUserWorkstations'])){
1295       for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1296         $station = trim($all['sambaUserWorkstations'][$i]);
1297         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1298       }
1299     }
1300     if(isset($attrs['sambaUserWorkstations'])){
1301       for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1302         $station = trim($attrs['sambaUserWorkstations'][$i]);
1303         $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1304       }
1305     }
1306   }
1308   function multiple_execute()
1309   {
1310     return($this->execute());
1311   } 
1313   function get_multi_edit_values()
1314   {
1315     $ret = plugin::get_multi_edit_values();
1317     /* Terminal Server  */
1318     if(in_array("tslogin",$this->multi_boxes)){
1319       $ret['tslogin'] = $this->mungedObject->getTsLogin();
1320     }
1321     if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1322       $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1323     }
1324     if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1325       $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1326     }
1327     if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1328       $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1329     }
1331     if(in_array("inherit",$this->multi_boxes)){
1332       $ret['inherit'] = $this->mungedObject->getInheritMode();
1333     }       
1334     if(in_array("CtxInitialProgram",$this->multi_boxes)){
1335       $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1336     } 
1337     if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1338       $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1339     } 
1341     /* Time Limits. Be careful here, there are some negations  */
1342     if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1343       $ret["CtxMaxConnectionTimeF"]   =  !$this->mungedObject->getCtxMaxConnectionTimeF();
1344       if(!$ret["CtxMaxConnectionTimeF"]){
1345         $ret["CtxMaxConnectionTime"]   =  $this->mungedObject->ctx['CtxMaxConnectionTime'];
1346       }
1347     }
1348     if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1349       $ret["CtxMaxDisconnectionTimeF"]=  !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1350       if(!$ret["CtxMaxDisconnectionTimeF"]){
1351         $ret["CtxMaxDisconnectionTime"]=  $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1352       }
1353     }
1354     if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1355       $ret["CtxMaxIdleTimeF"]         =  !$this->mungedObject->getCtxMaxIdleTimeF();
1356       if(!$ret["CtxMaxIdleTimeF"]){
1357         $ret["CtxMaxIdleTime"]         =  $this->mungedObject->ctx['CtxMaxIdleTime'];
1358       }
1359     }
1361     /* Client Devices */
1362     if(in_array("connectclientdrives",$this->multi_boxes)){
1363       $ret["connectclientdrives"]     =  $this->mungedObject->getConnectClientDrives();
1364     }
1365     if(in_array("connectclientprinters",$this->multi_boxes)){
1366       $ret["connectclientprinters"]   =  $this->mungedObject->getConnectClientPrinters();
1367     }
1368     if(in_array("defaultprinter",$this->multi_boxes)){
1369       $ret["defaultprinter"]          =  $this->mungedObject->getDefaultPrinter();
1370     }
1372     /* Misc */
1373     if(in_array("shadow",$this->multi_boxes)){
1374       $ret["shadow"]    =$this->mungedObject->getShadow();
1375     }
1376     if(in_array("brokenconn",$this->multi_boxes)){
1377       $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1378     }
1379     if(in_array("reconn",$this->multi_boxes)){
1380       $ret["reconn"]    =$this->mungedObject->getReConn();
1381     }
1383     /* Flags */
1384     if(in_array("allow_pwchange",$this->multi_boxes)){
1385       $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1386       $ret['pwdCanChange']      = $this->pwdCanChange;
1387     }
1388   
1389     if(in_array("password_expires",$this->multi_boxes)){
1390       $ret['password_expires']  = $this->password_expires;
1391       $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1392     }
1393     if(in_array("logon_time_set",$this->multi_boxes)){
1394       $ret['logon_time_set'] = $this->logon_time_set;
1395       $ret['sambaLogonTime'] = $this->sambaLogonTime;
1396     }
1397     if(in_array("logoff_time_set",$this->multi_boxes)){
1398       $ret['logoff_time_set'] = $this->logoff_time_set;
1399       $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1400     }
1401     if(in_array("kickoff_time_set",$this->multi_boxes)){
1402       $ret['kickoff_time_set'] = $this->kickoff_time_set;
1403       $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1404     }
1406     if(in_array("no_password_required",$this->multi_boxes)){
1407       $ret['no_password_required'] = $this->no_password_required;
1408     }
1410     if(in_array("temporary_disable",$this->multi_boxes)){
1411       $ret['temporary_disable'] = $this->temporary_disable;
1412     }
1413     
1414     if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1415       $ret['sambaLogonHours'] = $this->sambaLogonHours;
1416     }
1418     if(in_array("workstation_list",$this->multi_boxes)){
1419       $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1420     }
1421     return($ret);
1422   }
1424   function set_multi_edit_values($values)
1425   {
1426     plugin::set_multi_edit_values($values);
1428     /* Prepare current workstation settings to be merged 
1429      *  with multiple edit settings.
1430      */
1431     if(isset($values['multiple_sambaUserWorkstations'])){
1432       $cur_ws = array();
1433       $m_ws = $values['multiple_sambaUserWorkstations'];
1435       /* Prepare current settings to be merged */
1436       if(isset($this->sambaUserWorkstations)){
1437         $ttmp = split(",",$this->sambaUserWorkstations);
1438         foreach($ttmp as $station){
1439           $station = trim($station);
1440           if(!empty($station)){
1441             $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1442           }
1443         }
1444       }
1446       /* Unset removed workstations */
1447       foreach($cur_ws as $cur_name => $cur_station){
1448         if(!isset($m_ws[$cur_name])){
1449           unset($cur_ws[$cur_name]);
1450         }
1451       }
1453       /* Add all added workstations */
1454       foreach($m_ws as $name => $station){
1455         if($station['UsedByAllUsers']){
1456           $cur_ws[$name] = $station;
1457         }
1458       }
1460       $this->sambaUserWorkstations = "";
1461       foreach($cur_ws as $name => $ws){
1462         $this->sambaUserWorkstations .= $name.",";
1463       }
1464       $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1465     }
1467     /* Enable disabled terminal login, this is inverted somehow */
1468     if(isset($values['tslogin']))   $this->mungedObject->setTsLogin(!$values['tslogin']);
1469   
1470     /* Imherit client configuration */
1471     if(isset($values['inherit']))   $this->mungedObject->setInheritMode($values['inherit']);
1472   
1473     /* Get all ctx values posted */
1474     $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1475                  "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1476     foreach($ctx as $attr){
1477       if(isset($values[$attr])){
1478         $this->mungedObject->ctx[$attr] = $values[$attr] ;
1479       }
1480     }
1482     if(isset($values['CtxMaxConnectionTimeF']))   $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1483     if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1484     if(isset($values['CtxMaxIdleTimeF']))         $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1486     if(isset($values['connectclientdrives']))   $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1487     if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1488     if(isset($values['defaultprinter']))        $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1490     if(isset($values['shadow']))        $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1491     if(isset($values['brokenconn']))    $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1492     if(isset($values['reconn']))        $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1494   
1495     if(isset($values['sambaPwdCanChange']))  $this->sambaPwdCanChange  = $values['sambaPwdCanChange'];
1496     if(isset($values['pwdCanChange']))       $this->pwdCanChange       = $values['pwdCanChange'];
1498     
1499     
1501     if(isset($values['password_expires'])){
1502       $this->password_expires = $values['password_expires'];
1503       $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1504     }
1505     if(isset($values['logon_time_set'])){
1506       $this->logon_time_set = $values['logon_time_set'];
1507       $this->sambaLogonTime = $values['sambaLogonTime'];
1508     }
1509     if(isset($values['logoff_time_set'])){
1510       $this->logoff_time_set = $values['logoff_time_set'];
1511       $this->sambaLogoffTime = $values['sambaLogoffTime'];
1512     }
1513     if(isset($values['kickoff_time_set'])){
1514       $this->kickoff_time_set = $values['kickoff_time_set'];
1515       $this->sambaKickoffTime = $values['sambaKickoffTime'];
1516     }
1518     if(isset($values['no_password_required'])){
1519       if($values['no_password_required']){
1520         if(!preg_match("/N/",$this->sambaAcctFlags)) {
1521           $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1522         }
1523       }else{
1524         $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1525       }
1526     }      
1528     if(isset($values['temporary_disable'])){
1529       if($values['temporary_disable']){
1530         if(preg_match("/L/",$this->sambaAcctFlags)) {
1531           // Keep L
1532         }else{
1533           $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1534         }
1535       }else{
1536         $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1537       }
1538     }
1539   }
1542 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1543 ?>