Code

Skip redirect to login, if configuration file permissions are wrong
[gosa.git] / plugins / personal / samba / class_sambaAccount.inc
1 <?php
2 /*
3    This code is part of GOsa (https://gosa.gonicus.de)
4    Copyright (C) 2004-2005 Cajus Pollmeier
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2 of the License, or
9    (at your option) any later version.
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
21 class sambaAccount extends plugin
22 {
23   /* Definitions */
24   var $plHeadline= "Samba";
25   var $plDescription= "This does something";
27   /* CLI vars */
28   var $cli_summary= "Manage users samba account";
29   var $cli_description= "Some longer text\nfor help";
30   var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
32   /* Switch for Samba version */
33   var $samba3= FALSE;
34   var $uidNumber= 65535;
35   var $gidNumber= 65535;
37   /* Samba 2 attributes */
38   var $pwdLastSet= "0";
39   var $logonTime= "0";
40   var $logoffTime= "2147483647";
41   var $kickoffTime= "2147483647";
42   var $pwdCanChange= "0";
43   var $pwdMustChange= "0";
44   var $password_expires= 0;
45   var $acctFlags= "[UX        ]";
46   var $smbHome= "";
47   var $homeDrive= "";
48   var $scriptPath= "";
49   var $profilePath= "";
50   var $rid= "";
51   var $primaryGroupID= "";
53   /* Samba 3 attributes */
54   var $SID= "";
55   var $ridBase= 0;
56   var $sambaSID= "";
57   var $sambaPwdLastSet= "0";
58   var $sambaLogonTime= "0";
59   var $sambaLogoffTime= "2147483647";
60   var $sambaKickoffTime= "2147483647";
61   var $sambaPwdCanChange= "";
62   var $sambaPwdMustChange= "0";
63   var $sambaAcctFlags= "[UX        ]";
64   var $sambaHomePath= "";
65   var $sambaHomeDrive= "";
66   var $sambaLogonScript= "";
67   var $sambaProfilePath= "";
68   var $sambaPrimaryGroupSID= "";
69   var $sambaDomainName= "";
70   var $sambaUserWorkstations= "";
71   var $sambaBadPasswordCount= "";
72   var $sambaBadPasswordTime= "";
73   var $sambaPasswordHistory= "";
74   var $sambaLogonHours= "";
75   var $orig_sambaDomainName= "";
76   var $sambaMungedDial= "";
77   var $mungedObject;
79   /* Helper */
80   var $show_ws_dialog= FALSE;
81   var $logon_time_set= 0;
82   var $logoff_time_set= 0;
83   var $kickoff_time_set= 0;
85   /* attribute list for save action */
86   var $ctxattributes= array();
87   var $attributes= array();
88   var $objectclasses= array();
89   
90   var $uid= "";
91   var $dialog = NULL;
92   var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
94   function sambaAccount ($config, $dn= NULL)
95   {
96     /* Load attributes depending on the samba version */
97     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
99     if ($this->samba3){
100       $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
101           "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
102           "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
103           "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
104           "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
105           "sambaUserWorkstations", "sambaPasswordHistory",
106           "sambaLogonHours", "sambaBadPasswordTime",
107           "sambaBadPasswordCount");
108       $this->objectclasses= array ("sambaSamAccount");
109       $this->mungedObject= new sambaMungedDial;
110       $this->ctxattributes= $this->mungedObject->ctxattributes;
111     } else {
112       $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
113           "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
114           "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
115       $this->objectclasses= array ("sambaAccount");
116     }
118     plugin::plugin ($config, $dn);
120     /* Setting uid to default */
121     if(isset($this->attrs['uid'][0])){
122       $this->uid = $this->attrs['uid'][0];
123     }
125     /* Get samba Domain in case of samba 3 */
126     if ($this->samba3 && $this->sambaSID != ""){
127       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
128       $ldap= $this->config->get_ldap_link();
129       $ldap->cd($this->config->current['BASE']);
130       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
131       if ($ldap->count() != 0){
132         $attrs= $ldap->fetch();
133         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
134         if ($this->sambaDomainName == ""){
135           $this->sambaDomainName= $attrs['sambaDomainName'][0];
136         }
137       } else {
138         if ($this->sambaDomainName == ""){
139           $this->sambaDomainName= "DEFAULT";
140         }
141         $this->ridBase= $this->config->current['RIDBASE'];
142         $this->SID= $this->config->current['SID'];
143       }
145       /* Save in order to compare later on */
146       $this->orig_sambaDomainName= $this->sambaDomainName;
147     }
149     /* Fill mungedDial field */
150     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
151       $this->mungedObject->load($this->sambaMungedDial);
152     }
154     /* Password expiery */
155     if(isset($this->attrs['sambaPwdMustChange']) &&
156         $this->attrs['sambaPwdMustChange'][0] != 0){
157       $this->password_expires= 1;
158     }
160     if(isset($this->attrs['sambaLogonTime']) && ! (
161         $this->attrs['sambaLogonTime'][0] == 0 ||
162         $this->attrs['sambaLogonTime'][0] == 2147483647
163       )){
164       $this->logon_time_set= 1;
165     }
166     if(isset($this->attrs['sambaLogoffTime']) && ! (
167         $this->attrs['sambaLogoffTime'][0] == 0 ||
168         $this->attrs['sambaLogoffTime'][0] == 2147483647
169       )){
170       $this->logoff_time_set= 1;
171     }
172     
173     /* Account expiery */
174     if(isset($this->attrs['sambaKickoffTime']) && ! (
175         $this->attrs['sambaKickoffTime'][0] == 0 ||
176         $this->attrs['sambaKickoffTime'][0] == 2147483647
177       )){
178       $this->kickoff_time_set= 1;
179     }
181     /* Get global filter config */
182     if (!is_global("sambafilter")){
183       $ui= get_userinfo();
184       $base= get_base_from_people($ui->dn);
185       $sambafilter= array( "depselect" => $base, "regex" => "*");
186       register_global("sambafilter", $sambafilter);
187     }
189     /* Save initial account state */
190     $this->initially_was_account= $this->is_account;
191   }
193   function execute()
194   {
195         /* Call parent execute */
196         plugin::execute();
198     /* Do we need to flip is_account state? */
199     if (isset($_POST['modify_state'])){
200       $this->is_account= !$this->is_account;
201     }
202     /* Do we represent a valid account? */
203     if (!$this->is_account && $this->parent == NULL){
204       $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
205         _("This account has no samba extensions.")."</b>";
206       $display.= back_to_main();
207       return ($display);
208     }
210     /* Show tab dialog headers */
211     $display= "";
212     if ($this->parent != NULL){
213       if ($this->is_account){
214         $display= $this->show_disable_header(_("Remove samba account"),
215             _("This account has samba features enabled. You can disable them by clicking below."));
216       } else {
217         $obj= $this->parent->by_object['posixAccount'];
219         /* Samba3 dependency on posix accounts are enabled
220            in the moment, because I need to rely on unique
221            uidNumbers. There'll be a better solution later
222            on. */
223         if ($obj->is_account){
225           $display= $this->show_enable_header(_("Create samba account"),
226               _("This account has samba features disabled. You can enable them by clicking below."));
227         } else {
228           $display= $this->show_enable_header(_("Create samba account"),
229               _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
230         }
231         return ($display);
232       }
233     }
235     $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
237     /* Open Samaba Logong hours dialog */
238     if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
239       $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
240     }
242     /* Cancel dialog */
243     if(isset($_POST['cancel_logonHours'])){
244       $this->dialog = NULL;
245     }
247     /* Save selected logon hours */
248     if(isset($_POST['save_logonHours'])){
249       $this->dialog->save_object();
250       if($this->acl_is_writeable("sambaLogonHours")){
251         $this->sambaLogonHours = $this->dialog->save();
252       }
253       $this->dialog = NULL;
254     }
256     /* Display dialog */
257     if((isset($this->dialog)) && (is_object($this->dialog))){
258       $this->dialog->save_object();
259       return($this->dialog->execute());
260     }
263     /* Prepare templating */
264     $smarty= get_smarty();
266     $tmp = $this->plInfo();
267     foreach($tmp['plProvidedAcls'] as $var => $rest){
268       $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
269     }
271     if ($this->sambaPwdMustChange=="0"){
272       $date= getdate();
273     } else {
274       $date= getdate($this->sambaPwdMustChange);
275     }
277     if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
278       $sambaLogonTime_date= getdate();
279     } else {
280       $sambaLogonTime_date= getdate($this->sambaLogonTime);
281     }
282     
283     if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
284       $sambaLogoffTime_date= getdate();
285     } else {
286       $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
287     }
288     
289     if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
290       $sambaKickoffTime_date= getdate();
291     } else {
292       $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
293     }
295     /* Remove user workstations? */
296     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
298       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
300         $tmp= $this->sambaUserWorkstations;
301         foreach($_POST['workstation_list'] as $name){
302           $tmp= preg_replace("/$name/", '', $tmp);
303           $this->is_modified= TRUE;
304         }
305         $tmp= preg_replace('/,+/', ',', $tmp);
306         $this->sambaUserWorkstations= trim($tmp, ',');
307       }
308     }
310     /* Add user workstation? */
311     if (isset($_POST["add_ws"])){
312       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
313         $this->show_ws_dialog= TRUE;
314         $this->dialog= TRUE;
315       }
316     }
318     /* Add user workstation finished? */
319     if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
320       $this->show_ws_dialog= FALSE;
321       $this->dialog= FALSE;
322     }
324     /* Add user workstation? */
325     if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
326       $tmp= $this->sambaUserWorkstations;
327       foreach($_POST['wslist'] as $ws){
328         $tmp.= ",$ws";
329       }
330       $tmp= preg_replace('/,+/', ',', $tmp);
331       $this->sambaUserWorkstations= trim($tmp, ',');
332       $this->is_modified= TRUE;
333     }
335     /* Show ws dialog */
336     if ($this->show_ws_dialog){
338       /* Save data */
339       $sambafilter= get_global("sambafilter");
340       foreach( array("depselect", "regex") as $type){
341         if (isset($_POST[$type])){
342           $sambafilter[$type]= $_POST[$type];
343         }
344       }
345       if (isset($_GET['search'])){
346         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
347         if ($s == "**"){
348           $s= "*";
349         }
350         $sambafilter['regex']= $s;
351       }
352       register_global("sambafilter", $sambafilter);
354       /* Get workstation list */
355       $exclude= "";
356       foreach(split(',', $this->sambaUserWorkstations) as $ws){
357         $exclude.= "(cn=$ws$)";
358       }
359       if ($exclude != ""){
360         $exclude= "(!(|$exclude))";
361       }
362       $regex= $sambafilter['regex'];
363       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
364       $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
365         
366       $wslist= array();
367       foreach ($res as $attrs){
368         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
369       }
370       asort($wslist);
372       $smarty->assign("search_image", get_template_path('images/search.png'));
373       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
374       $smarty->assign("tree_image", get_template_path('images/tree.png'));
375       $smarty->assign("deplist", $this->config->idepartments);
376       $smarty->assign("alphabet", generate_alphabet());
377       foreach( array("depselect", "regex") as $type){
378         $smarty->assign("$type", $sambafilter[$type]);
379       }
380       $smarty->assign("hint", print_sizelimit_warning());
381       $smarty->assign("wslist", $wslist);
382       $smarty->assign("apply", apply_filter());
383       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
384                                 dirname(__FILE__)));
385       return ($display);
386     }
388     /* Fill calendar */
389     $days= array();
390     for($d= 1; $d<32; $d++){
391       $days[]= $d;
392     }
393     $years= array();
394     for($y= $date['year']-4; $y<$date['year']+4; $y++){
395       $years[]= $y;
396     }
397     $months= array(_("January"), _("February"), _("March"), _("April"),
398         _("May"), _("June"), _("July"), _("August"), _("September"),
399         _("October"), _("November"), _("December"));
400     $smarty->assign("day", $date["mday"]);
401     $smarty->assign("days", $days);
402     $smarty->assign("months", $months);
403     $smarty->assign("month", $date["mon"]-1);
404     $smarty->assign("years", $years);
405     $smarty->assign("year", $date["year"]);
406     
407     $sambaLogonTime_days= array();
408     for($d= 1; $d<32; $d++){
409       $sambaLogonTime_days[]= $d;
410     }
411     $sambaLogonTime_years= array();
412     for($y= $date['year']-4; $y<$date['year']+4; $y++){
413       $sambaLogonTime_years[]= $y;
414     }
415     $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
416         _("May"), _("June"), _("July"), _("August"), _("September"),
417         _("October"), _("November"), _("December"));
418     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
419     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
420     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
421     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
422     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
423     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
424     
425     $sambaLogoffTime_days= array();
426     for($d= 1; $d<32; $d++){
427       $sambaLogoffTime_days[]= $d;
428     }
429     $sambaLogoffTime_years= array();
430     for($y= $date['year']-4; $y<$date['year']+4; $y++){
431       $sambaLogoffTime_years[]= $y;
432     }
433     $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
434         _("May"), _("June"), _("July"), _("August"), _("September"),
435         _("October"), _("November"), _("December"));
436     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
437     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
438     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
439     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
440     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
441     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
442     
443     $sambaKickoffTime_days= array();
444     for($d= 1; $d<32; $d++){
445       $sambaKickoffTime_days[]= $d;
446     }
447     $sambaKickoffTime_years= array();
448     for($y= $date['year']-4; $y<$date['year']+4; $y++){
449       $sambaKickoffTime_years[]= $y;
450     }
451     $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
452         _("May"), _("June"), _("July"), _("August"), _("September"),
453         _("October"), _("November"), _("December"));
454     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
455     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
456     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
457     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
458     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
459     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
460     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
461      
462     /* Fill boxes */
463     if ($this->samba3){
464       $domains= array();
465       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
466         $domains[]= $name;
467       }
468       $smarty->assign("domains", $domains);
469     }
470     $letters= array();
471     for ($i= 68; $i<91; $i++){
472       $letters[]= chr($i).":";
473     }
474     $smarty->assign("drives", $letters);
476     /* Fill terminal server settings */
477     if ($this->samba3){
478       foreach ($this->ctxattributes as $attr){
479         /* Fill common attributes */
480         if (isset($this->mungedObject->ctx[$attr])){
481           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
482           // Set field  to blank if value is 0
483           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
484             if($this->mungedObject->ctx[$attr] == 0) {
485               $smarty->assign("$attr", "");
486             }
487           }
488         } else {
489           $smarty->assign("$attr", "");
490         }
491       }
493       /* Assign enum values for preset items */
494       $shadowModeVals= array( "0" => _("disabled"),
495           "1" => _("input on, notify on"),
496           "2" => _("input on, notify off"),
497           "3" => _("input off, notify on"),
498           "4" => _("input off, nofify off"));
500       $brokenConnModeVals= array(       "0" => _("disconnect"),
501           "1" => _("reset"));
503       $reConnModeVals= array( "0" => _("from any client"),
504           "1" => _("from previous client only"));
506       /* Fill preset items */
507       $smarty->assign("shadow", $shadowModeVals);
508       $smarty->assign("brokenconn", $brokenConnModeVals);
509       $smarty->assign("reconn", $reConnModeVals);
511       /* Fill preset items with values */
512       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
513       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
514       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
516       if($_SESSION['js']){
517         /* Set form elements to disabled/enable state */
518         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
520         $smarty->assign("inheritstate", "");
521         if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
522           $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
523         }
524   
526   
527       }else{
528         $smarty->assign("tsloginstate", "");
529         $smarty->assign("inheritstate", "");
530       }      
532       /* Set checkboxes to checked or unchecked state */
533       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
534       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
535       $smarty->assign("connectclientdrives",
536                       $this->mungedObject->getConnectClientDrives()?"checked":"");
537       $smarty->assign("connectclientprinters",
538                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
539       $smarty->assign("defaultprinter",
540                       $this->mungedObject->getDefaultPrinter()?"checked":"");
541       $smarty->assign("CtxMaxConnectionTimeF",
542                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
543       $smarty->assign("CtxMaxDisconnectionTimeF",
544                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
545       $smarty->assign("CtxMaxIdleTimeF",
546                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
548       /* Fill sambaUserWorkstations */
549       $ws= split(",", $this->sambaUserWorkstations);
550       sort($ws);
551       
552       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
553       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
556       $smarty->assign("workstations", $ws);
557     }
559     /* Variables */
560     foreach($this->attributes as $val){
561       $smarty->assign("$val", $this->$val);
562     }
564     /* 'sambaAcctFlags' checkboxes */
565     /* Check for 'lock-account'-flag: 'D' or 'L' */
566     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
567         is_integer(strpos($this->sambaAcctFlags, "L"))) {
568         $smarty->assign("flagsD", "checked");
569     } else {
570         $smarty->assign("flagsD", "");
571     }
572     
573     /* Check for no_password_required flag 'N' */
574     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
575         $smarty->assign("flagsN", "checked");
576     } else {
577         $smarty->assign("flagsN", "");
578     }
580     if($this->samba3){
581       if ($this->sambaPwdCanChange=="1"){
582         $smarty->assign("flagsP", "checked");
583       } else {
584         $smarty->assign("flagsP", "");
585       }
586     }else{
587       if ($this->pwdCanChange=="1"){
588         $smarty->assign("flagsP", "checked");
589       } else {
590         $smarty->assign("flagsP", "");
591       }
592     }
594     if ($this->password_expires=="1"){
595       $smarty->assign("flagsC", "checked");
596     } else {
597       $smarty->assign("flagsC", "");
598     }
599     if ($this->logon_time_set=="1"){
600       $smarty->assign("flagsT", "checked");
601     } else {
602       $smarty->assign("flagsT", "");
603     }
604     if ($this->logoff_time_set=="1"){
605       $smarty->assign("flagsO", "checked");
606     } else {
607       $smarty->assign("flagsO", "");
608     }
609     if ($this->kickoff_time_set=="1"){
610       $smarty->assign("flagsK", "checked");
611     } else {
612       $smarty->assign("flagsK", "");
613     }
614    
616     /* In case of javascript, disable some fields on demand */
617     if ($this->samba3){
618       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
619         $smarty->assign("$key", "$value");
620       }
621     }
623     /* Show main page */
624     if ($this->samba3){
625       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
626     } else {
627       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
628     }
630     return ($display);
631   }
633   function remove_from_parent()
634   {
635     /* Cancel if there's nothing to do here */
636    if (!$this->initially_was_account){
637      return;
638    }
639     
640     /* include global link_info */
641     $ldap= $this->config->get_ldap_link();
643     plugin::remove_from_parent();
645     /* Keep uid attribute for gosaAccount */
646     unset($this->attrs['uid']);
647     unset($this->attrs['uidNumber']);
648     unset($this->attrs['gidNumber']);
650     /* Remove objectClass for sambaIdmapEntry */
651     $tmp= array();
652     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
653       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
654         $tmp[]= $this->attrs['objectClass'][$i];
655       }
656     }
657     $this->attrs['objectClass']= $tmp;
659     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
660         $this->attributes, "Save");
661     $ldap->cd($this->dn);
662     $this->cleanup();
663     $ldap->modify ($this->attrs); 
665     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
667     /* Optionally execute a command after we're done */
668     $this->handle_post_events("remove", array("uid" => $this->uid));
669   }
672   /* Check for input problems */
673   function check()
674   {
675     /* Call common method to give check the hook */
676     $message= plugin::check();
678     if ($this->samba3){
680       /* Strings */
681       foreach (array( "sambaHomePath" => _("Home directory"),
682             "sambaProfilePath" => _("Profile path")) as $key => $val){
683         if (!$this->mungedObject->is_samba_path($this->$key)){
684           $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
685         }
686       }
688       /* Numeric values */
689       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
690             "CtxMaxDisconnectionTime" => _("Disconnection"),
691             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
693         if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
694           $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
695         }
696       }
698       /* Too many workstations? Windows usrmgr only supports eight */
699       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
700         $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
701       }
702     }
704     return ($message);
705   }
708   /* Save data to object */
709   function save_object()
710   {
712     $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
714     /* We only care if we are on the sambaTab... */
715     if (isset($_POST['sambaTab'])){
716       plugin::save_object();
718       /* Take care about access options */
719       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
720         if ($this->samba3){
721           $attrname= "sambaPwdCanChange";
722         } else {
723           $attrname= "pwdCanChange";
724         }
725         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
726           $tmp= 1;
727         } else {
728           $tmp= 0;
729         }
730         if ($this->$attrname != $tmp){
731           $this->is_modified= TRUE;
732         }
733         $this->pwdCanChange= $tmp;
734         $this->sambaPwdCanChange= $tmp;
735       }
736       $tmp= "UX";
737       if (isset($_POST["no_password_required"])){
738         if ($_POST["no_password_required"] == 1){
739           $tmp.= "N";
740         }
741       }
742       if (isset($_POST["password_expires"])){
743         if ($_POST["password_expires"] == 1){
744           $this->password_expires= 1;
745         }
746       } else {
747         $this->password_expires= 0;
748       }
749       if (isset($_POST["temporary_disable"])){
750         if ($_POST["temporary_disable"] == 1){
751           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
752             $tmp.= "L";
753           } else {
754             $tmp.= "D";
755           }
756         }
757       }
758       if (isset($_POST["logon_time_set"])){
759         if ($_POST["logon_time_set"] == 1){
760           $this->logon_time_set= 1;
761         }
762       } else {
763         $this->logon_time_set= 0;
764       }
765       if (isset($_POST["logoff_time_set"])){
766         if ($_POST["logoff_time_set"] == 1){
767           $this->logoff_time_set= 1;
768         }
769       } else {
770         $this->logoff_time_set= 0;
771       }
772       if (isset($_POST["kickoff_time_set"])){
773         if ($_POST["kickoff_time_set"] == 1){
774           $this->kickoff_time_set= 1;
775         }
776       } else {
777         $this->kickoff_time_set= 0;
778       }
779       
780       $fill= "";
781       for ($i= strlen($tmp); $i<12; $i++){
782         $fill.= " ";
783       }
785       $tmp= "[$tmp$fill]";
787       /* Only save if acl's are set */
788       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
789         if ($this->samba3){
790           $attrname= "sambaAcctFlags";
791         } else {
792           $attrname= "acctFlags";
793         }
794         if ($this->$attrname != $tmp){
795           $this->is_modified= TRUE;
796         }
797         $this->$attrname= $tmp;
798       }
800       /* Save sambaDomain attribute */
801       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
802         $this->sambaDomainName= validate($_POST['sambaDomainName']);
803       }
805       /* Save CTX values */
806       if ($this->samba3){
808         /* Save obvious values */
809         foreach($this->ctxattributes as $val){
810           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
811             if (get_magic_quotes_gpc()) {
812               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
813             } else {
814               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
815             }
816           }
817         }
819         /* Save checkbox states. */
820         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
821                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
822         // Need to do some index checking to avoid messages like "index ... not found"
823         if(isset($_POST['brokenconn'])) {
824           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
825                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
826         }
827         if(isset($_POST['reconn'])) {
828           $this->mungedObject->setReConn($_POST['reconn'] == '1'
829                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
830         }
831         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
832                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
833         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
834                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
835         $this->mungedObject->setCtxMaxDisconnectionTimeF(
836                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
837                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
838         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
839                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
840         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
841                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
842         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
843                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
844         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
845                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
847         /* Save combo boxes. Takes two values */
848         if(isset($_POST['reconn'])) {
849           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
850         }
852         /* Check for changes */
853         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
854           $this->is_modified= TRUE;
855         }
856       }
857     }
858   }
861   /* Save to LDAP */
862   function save()
863   {
864     /* Load uid and gid of this 'dn' */
865     $ldap= $this->config->get_ldap_link();
866     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
867     $tmp= $ldap->fetch();
868     $this->uidNumber= $tmp['uidNumber'][0];
869     $this->gidNumber= $tmp['gidNumber'][0];
871     plugin::save();
873     /* Remove objectClass for sambaIdmapEntry */
874     $tmp= array();
875     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
876       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
877         $tmp[]= $this->attrs['objectClass'][$i];
878       }
879     }
880     $this->attrs['objectClass']= $tmp;
882     /* Generate rid / primaryGroupId */
883     if ($this->samba3){
884       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
885         print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
886       } else {
887         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
888         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
889       }
891       /* Need to generate a new uniqe uid/gid combination? */
892       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
893         $uidNumber= $this->uidNumber;
894         while(TRUE){
895           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
896           $ldap->cd($this->config->current['BASE']);
897           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
898           if ($ldap->count() == 0){
899             break;
900           }
901           $uidNumber++;
902         }
903         $this->attrs['sambaSID']= $sid;
905         /* Check for users primary group */
906         $ldap->cd($this->config->current['BASE']);
907         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
908         if ($ldap->count() != 1){
909           print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
910         } else {
911           $attrs= $ldap->fetch();
912           $g= new group($this->config, $ldap->getDN());
913           if ($g->sambaSID == ""){
914             $g->sambaDomainName= $this->sambaDomainName;
915             $g->smbgroup= TRUE;
916             $g->save ();
917           }
918           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
919         }
920       }
922       if ($this->sambaHomeDrive == ""){
923         $this->attrs["sambaHomeDrive"]= array();
924       }
926       /* Generate munged dial value */
927       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
929       /* User wants me to fake the idMappings? This is useful for
930          making winbind resolve the user names in a reasonable amount
931          of time in combination with larger databases. */
932       if (isset($this->config->current['SAMBAIDMAPPING']) &&
933           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
934         $this->attrs['objectClass'][]= "sambaIdmapEntry";
935       }
938       /* Password expiery */
939       if ($this->password_expires == "1"){
940         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
941       } else {
942         $this->attrs['sambaPwdMustChange']= array();
943       }
944       /* Make sure not to save zero in sambaPwdLastset */
945       if ($this->sambaPwdLastSet != "0"){
946         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
947       } else {
948         $this->attrs['sambaPwdLastSet']= array();
949       }
950       /* Account expiery */
951       if ($this->logon_time_set == "1"){
952         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
953       } else {
954         $this->attrs['sambaLogonTime']= array();
955       }
956       if ($this->logoff_time_set == "1"){
957         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
958       } else {
959         $this->attrs['sambaLogoffTime']= array();
960       }
961       if ($this->kickoff_time_set == "1"){
962         # Add one day in unixtime format to be compatible with usrmgr
963         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
964         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
965       } else {
966         $this->attrs['sambaKickoffTime']= array();
967       }
968     } else {
969     /* Not samba3 */
970       $this->attrs['rid']= $this->uidNumber*2 + 1000;
971       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
973       if ($this->homeDrive == ""){
974         $this->attrs["homeDrive"]= array();
975       }
977       /* Password expiery */
978       if ($this->password_expires == "1"){
979         $this->attrs['pwdMustChange']= $this->pwdMustChange;
980       } else {
981         $this->attrs['pwdMustChange']= 2147483647;
982       }
983       /* Make sure not to save zero in pwdLastset */
984       if ($this->pwdLastSet != "0"){
985         $this->attrs['pwdLastSet']= $this->pwdLastSet;
986       } else {
987         $this->attrs['pwdLastSet']= array();
988       }
989       /* Account expiery */
990       if ($this->logon_time_set == "1"){
991         $this->attrs['logonTime']= $this->logonTime;
992       } else {
993         $this->attrs['logonTime']= array();
994       }
995       if ($this->logoff_time_set == "1"){
996         $this->attrs['logoffTime']= $this->logoffTime;
997       } else {
998         $this->attrs['logoffTime']= array();
999       }
1000       if ($this->kickoff_time_set == "1"){
1001         # Add one day in unixtime format to be compatible with usrmgr
1002         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1003       } else {
1004         $this->attrs['kickoffTime']= array();
1005       }
1006     }
1008     /* Write back to ldap */
1009     $ldap->cd($this->dn);
1010     $this->cleanup();
1011     $ldap->modify ($this->attrs); 
1013     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
1015     /* Optionally execute a command after we're done */
1016     if ($this->initially_was_account == $this->is_account){
1017       if ($this->is_modified){
1018         $this->handle_post_events("modify", array("uid" => $this->uid));
1019       }
1020     } else {
1021       $this->handle_post_events("add", array("uid" => $this->uid));
1022     }
1024   }
1026   function adapt_from_template($dn)
1027   {
1028     plugin::adapt_from_template($dn);
1029     $this->sambaSID= "";
1030     $this->sambaPrimaryGroupSID= "";
1032       /* Fill mungedDial field */
1033     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1034       $this->mungedObject->load($this->sambaMungedDial);
1035     }
1037     /* Password expiery */
1038     if(isset($this->attrs['sambaPwdMustChange']) &&
1039         $this->attrs['sambaPwdMustChange'][0] != 0){
1040       $this->password_expires= 1;
1041     }
1043     if(isset($this->attrs['sambaLogonTime']) && ! (
1044         $this->attrs['sambaLogonTime'][0] == 0 ||
1045         $this->attrs['sambaLogonTime'][0] == 2147483647
1046       )){
1047       $this->logon_time_set= 1;
1048     }
1049     if(isset($this->attrs['sambaLogoffTime']) && ! (
1050         $this->attrs['sambaLogoffTime'][0] == 0 ||
1051         $this->attrs['sambaLogoffTime'][0] == 2147483647
1052       )){
1053       $this->logoff_time_set= 1;
1054     }
1056     /* Account expiery */
1057     if(isset($this->attrs['sambaKickoffTime']) && ! (
1058         $this->attrs['sambaKickoffTime'][0] == 0 ||
1059         $this->attrs['sambaKickoffTime'][0] == 2147483647
1060       )){
1061       $this->kickoff_time_set= 1;
1062     }
1064     /* Get global filter config */
1065     if (!is_global("sambafilter")){
1066       $ui= get_userinfo();
1067       $base= get_base_from_people($ui->dn);
1068       $sambafilter= array( "depselect" => $base, "regex" => "*");
1069       register_global("sambafilter", $sambafilter);
1070     }
1071   }
1073   
1074   function plInfo()
1075   {
1076     return (array(
1077           "plShortName"     => _("Samba"),
1078           "plDescription"   => _("Samba settings"),
1079           "plSelfModify"    => TRUE,
1080           "plDepends"       => array("user"),
1081           "plPriority"      => 5,
1082           "plSection"     => array("personal" => _("My account")),
1083           "plCategory"    => array("users"),
1084           "plOptions"       => array(),
1086           "plProvidedAcls"  => array(
1087             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1088             "InheritClientConfig"         => _("Inherit client config"),
1090             "sambaPwdCanChange"     => _("Allow user to change password") ,
1091             "sambaAcctFlagsN"            => _("Login from windows client requires no password"),
1092             "sambaAcctFlagsL"            => _("Lock samba account"),
1095             "sambaKickoffTime"      => _("Account expires") ,
1096             "sambaPwdMustChange"    => _("Password expires") ,
1098             "sambaLogonTime"        => _("Limit Logon Time") ,
1099             "sambaLogoffTime"       => _("Limit Logoff Time") ,
1100             "sambaLogonHours"       => _("Logon hours") ,
1102             "sambaHomePath"         => _("Generic home directory") ,
1103             "sambaHomeDrive"        => _("Generic samba home drive") ,
1104             "sambaLogonScript"      => _("Generic script path") ,
1105             "sambaProfilePath"      => _("Generic profile path") ,
1106             "sambaDomainName"       => _("Domain") ,
1107             "sambaUserWorkstations" => _("Allow connection from")))
1108               );
1109   }    
1112 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1113 ?>