Code

Removed uid check
[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= "0";
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();
90   function sambaAccount ($config, $dn= NULL)
91   {
92     /* Load attributes depending on the samba version */
93     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
95     if ($this->samba3){
96       $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
97           "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
98           "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
99           "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
100           "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
101           "sambaUserWorkstations", "sambaPasswordHistory",
102           "sambaLogonHours", "sambaBadPasswordTime",
103           "sambaBadPasswordCount");
104       $this->objectclasses= array ("sambaSamAccount");
105       $this->mungedObject= new sambaMungedDial;
106       $this->ctxattributes= $this->mungedObject->ctxattributes;
107     } else {
108       $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
109           "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
110           "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
111       $this->objectclasses= array ("sambaAccount");
112     }
114     plugin::plugin ($config, $dn);
116     /* Get samba Domain in case of samba 3 */
117     if ($this->samba3 && $this->sambaSID != ""){
118       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
119       $ldap= $this->config->get_ldap_link();
120       $ldap->cd($this->config->current['BASE']);
121       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))");
122       if ($ldap->count() != 0){
123         $attrs= $ldap->fetch();
124         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
125         if ($this->sambaDomainName == ""){
126           $this->sambaDomainName= $attrs['sambaDomainName'][0];
127         }
128       } else {
129         if ($this->sambaDomainName == ""){
130           $this->sambaDomainName= "DEFAULT";
131         }
132         $this->ridBase= $this->config->current['RIDBASE'];
133         $this->SID= $this->config->current['SID'];
134       }
136       /* Save in order to compare later on */
137       $this->orig_sambaDomainName= $this->sambaDomainName;
138     }
140     /* Fill mungedDial field */
141     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
142       $this->mungedObject->load($this->sambaMungedDial);
143     }
145     /* Password expiery */
146     if(isset($this->attrs['sambaPwdMustChange']) &&
147         $this->attrs['sambaPwdMustChange'][0] != 0){
148       $this->password_expires= 1;
149     }
151     if(isset($this->attrs['sambaLogonTime']) && ! (
152         $this->attrs['sambaLogonTime'][0] == 0 ||
153         $this->attrs['sambaLogonTime'][0] == 2147483647
154       )){
155       $this->logon_time_set= 1;
156     }
157     if(isset($this->attrs['sambaLogoffTime']) && ! (
158         $this->attrs['sambaLogoffTime'][0] == 0 ||
159         $this->attrs['sambaLogoffTime'][0] == 2147483647
160       )){
161       $this->logoff_time_set= 1;
162     }
163     
164     /* Account expiery */
165     if(isset($this->attrs['sambaKickoffTime']) && ! (
166         $this->attrs['sambaKickoffTime'][0] == 0 ||
167         $this->attrs['sambaKickoffTime'][0] == 2147483647
168       )){
169       $this->kickoff_time_set= 1;
170     }
172     /* Get global filter config */
173     if (!is_global("sambafilter")){
174       $ui= get_userinfo();
175       $base= get_base_from_people($ui->dn);
176       $sambafilter= array( "depselect" => $base, "regex" => "*");
177       register_global("sambafilter", $sambafilter);
178     }
180     /* Save initial account state */
181     $this->initially_was_account= $this->is_account;
182   }
184   function execute()
185   {
186         /* Call parent execute */
187         plugin::execute();
189     /* Do we need to flip is_account state? */
190     if (isset($_POST['modify_state'])){
191       $this->is_account= !$this->is_account;
192     }
193     /* Do we represent a valid account? */
194     if (!$this->is_account && $this->parent == NULL){
195       $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
196         _("This account has no samba extensions.")."</b>";
197       $display.= back_to_main();
198       return ($display);
199     }
201     /* Show tab dialog headers */
202     $display= "";
203     if ($this->parent != NULL){
204       if ($this->is_account){
205         $display= $this->show_header(_("Remove samba account"),
206             _("This account has samba features enabled. You can disable them by clicking below."));
207       } else {
208         $obj= $this->parent->by_object['posixAccount'];
210         /* Samba3 dependency on posix accounts are enabled
211            in the moment, because I need to rely on unique
212            uidNumbers. There'll be a better solution later
213            on. */
214         if ($obj->is_account){
216           $display= $this->show_header(_("Create samba account"),
217               _("This account has samba features disabled. You can enable them by clicking below."));
218         } else {
219           $display= $this->show_header(_("Create samba account"),
220               _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
221         }
222         return ($display);
223       }
224     }
226     /* Prepare templating */
227     $smarty= get_smarty();
229 /* PHP Fehler "Undefined index: sambaPwdMustChangeACL" */
230     #hickert test
231     $smarty->assign("sambaPwdMustChangeACL", chkacl($this->acl, "sambaPwdMustChangeACL"));
232     #hickert test
233     $smarty->assign("sambaPwdMustChange",$this->sambaPwdMustChange);
235     if ($this->sambaPwdMustChange=="0"){
236       $date= getdate();
237     } else {
238       $date= getdate($this->sambaPwdMustChange);
239     }
241     if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
242       $sambaLogonTime_date= getdate();
243     } else {
244       $sambaLogonTime_date= getdate($this->sambaLogonTime);
245     }
246     
247     if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
248       $sambaLogoffTime_date= getdate();
249     } else {
250       $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
251     }
252     
253     if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
254       $sambaKickoffTime_date= getdate();
255     } else {
256       $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
257     }
259     /* Remove user workstations? */
260     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
261       $tmp= $this->sambaUserWorkstations;
262       foreach($_POST['workstation_list'] as $name){
263         $tmp= preg_replace("/$name/", '', $tmp);
264         $this->is_modified= TRUE;
265       }
266       $tmp= preg_replace('/,+/', ',', $tmp);
267       $this->sambaUserWorkstations= trim($tmp, ',');
268     }
270     /* Add user workstation? */
271     if (isset($_POST["add_ws"])){
272       $this->show_ws_dialog= TRUE;
273       $this->dialog= TRUE;
274     }
276     /* Add user workstation finished? */
277     if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
278       $this->show_ws_dialog= FALSE;
279       $this->dialog= FALSE;
280     }
282     /* Add user workstation? */
283     if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
284       $tmp= $this->sambaUserWorkstations;
285       foreach($_POST['wslist'] as $ws){
286         $tmp.= ",$ws";
287       }
288       $tmp= preg_replace('/,+/', ',', $tmp);
289       $this->sambaUserWorkstations= trim($tmp, ',');
290       $this->is_modified= TRUE;
291     }
293     /* Show ws dialog */
294     if ($this->show_ws_dialog){
296       /* Save data */
297       $sambafilter= get_global("sambafilter");
298       foreach( array("depselect", "regex") as $type){
299         if (isset($_POST[$type])){
300           $sambafilter[$type]= $_POST[$type];
301         }
302       }
303       if (isset($_GET['search'])){
304         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
305         if ($s == "**"){
306           $s= "*";
307         }
308         $sambafilter['regex']= $s;
309       }
310       register_global("sambafilter", $sambafilter);
312       /* Get workstation list */
313       $exclude= "";
314       foreach(split(',', $this->sambaUserWorkstations) as $ws){
315         $exclude.= "(cn=$ws$)";
316       }
317       if ($exclude != ""){
318         $exclude= "(!(|$exclude))";
319       }
320       $acl= array($this->config->current['BASE'] => ":all");
321       $regex= $sambafilter['regex'];
322       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
323       $res= get_list($acl, "$filter", TRUE, $sambafilter['depselect'], array("uid"), TRUE);
324       $wslist= array();
325       foreach ($res as $attrs){
326         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
327       }
328       asort($wslist);
330       $smarty->assign("search_image", get_template_path('images/search.png'));
331       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
332       $smarty->assign("tree_image", get_template_path('images/tree.png'));
333       $smarty->assign("deplist", $this->config->idepartments);
334       $smarty->assign("alphabet", generate_alphabet());
335       foreach( array("depselect", "regex") as $type){
336         $smarty->assign("$type", $sambafilter[$type]);
337       }
338       $smarty->assign("hint", print_sizelimit_warning());
339       $smarty->assign("wslist", $wslist);
340       $smarty->assign("apply", apply_filter());
341       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
342                                 dirname(__FILE__)));
343       return ($display);
344     }
346     /* Fill calendar */
347     $days= array();
348     for($d= 1; $d<32; $d++){
349       $days[]= $d;
350     }
351     $years= array();
352     for($y= $date['year']-4; $y<$date['year']+4; $y++){
353       $years[]= $y;
354     }
355     $months= array(_("January"), _("February"), _("March"), _("April"),
356         _("May"), _("June"), _("July"), _("August"), _("September"),
357         _("October"), _("November"), _("December"));
358     $smarty->assign("day", $date["mday"]);
359     $smarty->assign("days", $days);
360     $smarty->assign("months", $months);
361     $smarty->assign("month", $date["mon"]-1);
362     $smarty->assign("years", $years);
363     $smarty->assign("year", $date["year"]);
364     
365     $sambaLogonTime_days= array();
366     for($d= 1; $d<32; $d++){
367       $sambaLogonTime_days[]= $d;
368     }
369     $sambaLogonTime_years= array();
370     for($y= $date['year']-4; $y<$date['year']+4; $y++){
371       $sambaLogonTime_years[]= $y;
372     }
373     $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
374         _("May"), _("June"), _("July"), _("August"), _("September"),
375         _("October"), _("November"), _("December"));
376     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
377     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
378     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
379     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
380     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
381     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
382     
383     $sambaLogoffTime_days= array();
384     for($d= 1; $d<32; $d++){
385       $sambaLogoffTime_days[]= $d;
386     }
387     $sambaLogoffTime_years= array();
388     for($y= $date['year']-4; $y<$date['year']+4; $y++){
389       $sambaLogoffTime_years[]= $y;
390     }
391     $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
392         _("May"), _("June"), _("July"), _("August"), _("September"),
393         _("October"), _("November"), _("December"));
394     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
395     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
396     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
397     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
398     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
399     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
400     
401     $sambaKickoffTime_days= array();
402     for($d= 1; $d<32; $d++){
403       $sambaKickoffTime_days[]= $d;
404     }
405     $sambaKickoffTime_years= array();
406     for($y= $date['year']-4; $y<$date['year']+4; $y++){
407       $sambaKickoffTime_years[]= $y;
408     }
409     $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
410         _("May"), _("June"), _("July"), _("August"), _("September"),
411         _("October"), _("November"), _("December"));
412     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
413     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
414     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
415     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
416     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
417     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
418     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
419      
420     /* Fill boxes */
421     if ($this->samba3){
422       $domains= array();
423       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
424         $domains[]= $name;
425       }
426       $smarty->assign("domains", $domains);
427     }
428     $letters= array();
429     for ($i= 68; $i<91; $i++){
430       $letters[]= chr($i).":";
431     }
432     $smarty->assign("drives", $letters);
434     /* Fill terminal server settings */
435     if ($this->samba3){
436       foreach ($this->ctxattributes as $attr){
437         /* Fill common attributes */
438         if (isset($this->mungedObject->ctx[$attr])){
439           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
440           // Set field  to blank if value is 0
441           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
442             if($this->mungedObject->ctx[$attr] == 0) {
443               $smarty->assign("$attr", "");
444             }
445           }
446         } else {
447           $smarty->assign("$attr", "");
448         }
449         $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
450       }
452       /* Assign enum values for preset items */
453       $shadowModeVals= array( "0" => _("disabled"),
454           "1" => _("input on, notify on"),
455           "2" => _("input on, notify off"),
456           "3" => _("input off, notify on"),
457           "4" => _("input off, nofify off"));
459       $brokenConnModeVals= array(       "0" => _("disconnect"),
460           "1" => _("reset"));
462       $reConnModeVals= array( "0" => _("from any client"),
463           "1" => _("from previous client only"));
465       /* Fill preset items */
466       $smarty->assign("shadow", $shadowModeVals);
467       $smarty->assign("brokenconn", $brokenConnModeVals);
468       $smarty->assign("reconn", $reConnModeVals);
470       /* Fill preset items with values */
471       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
472       $smarty->assign("shadowACL", chkacl($this->acl,"shadow"));
473       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
474       $smarty->assign("brokenconnACL", chkacl($this->acl,"brokenconn"));
475       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
476       $smarty->assign("reconnACL", chkacl($this->acl,"reconn"));
478       if($_SESSION['js']){
479         /* Set form elements to disabled/enable state */
480         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
481         $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
482       }else{
483         $smarty->assign("tsloginstate", "");
484         $smarty->assign("inheritstate", "");
485       }      
487       /* Set checkboxes to checked or unchecked state */
488       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
489       $smarty->assign("tsloginACL", chkacl($this->acl,"tslogin"));
491       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
492       $smarty->assign("inheritACL", chkacl($this->acl,"inherit"));
495       $smarty->assign("connectclientdrives",
496                       $this->mungedObject->getConnectClientDrives()?"checked":"");
497       $smarty->assign("connectclientdrivesACL", chkacl($this->acl,"connectclientdrives"));
498       $smarty->assign("connectclientprinters",
499                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
500       $smarty->assign("connectclientprintersACL", chkacl($this->acl,"connectclientprinters"));
501       $smarty->assign("defaultprinter",
502                       $this->mungedObject->getDefaultPrinter()?"checked":"");
503       $smarty->assign("defaultprinterACL", chkacl($this->acl,"defaultprinter"));
504       $smarty->assign("CtxMaxConnectionTimeF",
505                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
506       $smarty->assign("CtxMaxDisconnectionTimeF",
507                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
508       $smarty->assign("CtxMaxIdleTimeF",
509                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
511       /* Fill sambaUserWorkstations */
512       $ws= split(",", $this->sambaUserWorkstations);
513       sort($ws);
514       
515       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
516       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
519       $smarty->assign("workstations", $ws);
520       $smarty->assign("sambaUserWorkstationACL", chkacl($this->acl,"sambaUserWorkstation"));
521     }
523     /* Variables */
524     foreach($this->attributes as $val){
525       $smarty->assign("$val", $this->$val);
526       $smarty->assign("$val"."ACL", chkacl($this->acl,$val));
527     }
529     
530     /* 'sambaAcctFlags' checkboxes */
531     /* Check for 'lock-account'-flag: 'D' or 'L' */
532     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
533         is_integer(strpos($this->sambaAcctFlags, "L"))) {
534         $smarty->assign("flagsD", "checked");
535     } else {
536         $smarty->assign("flagsD", "");
537     }
538     
539     /* Check for no_password_required flag 'N' */
540     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
541         $smarty->assign("flagsN", "checked");
542     } else {
543         $smarty->assign("flagsN", "");
544     }
546     /* 'normal' Checkboxes */
547     if ($this->pwdCanChange=="1"){
548       $smarty->assign("flagsP", "checked");
549     } else {
550       $smarty->assign("flagsP", "");
551     }
552     if ($this->password_expires=="1"){
553       $smarty->assign("flagsC", "checked");
554     } else {
555       $smarty->assign("flagsC", "");
556     }
557     if ($this->logon_time_set=="1"){
558       $smarty->assign("flagsT", "checked");
559     } else {
560       $smarty->assign("flagsT", "");
561     }
562     if ($this->logoff_time_set=="1"){
563       $smarty->assign("flagsO", "checked");
564     } else {
565       $smarty->assign("flagsO", "");
566     }
567     if ($this->kickoff_time_set=="1"){
568       $smarty->assign("flagsK", "checked");
569     } else {
570       $smarty->assign("flagsK", "");
571     }
572     
573     $smarty->assign("allow_pwchangeACL",        chkacl($this->acl, "allow_pwchange"));
574     $smarty->assign("password_expiresACL",      chkacl($this->acl, "password_expires"));
575     $smarty->assign("no_password_requiredACL",  chkacl($this->acl, "no_password_required"));
576     $smarty->assign("temporary_disableACL",     chkacl($this->acl, "temporary_disable"));
577     $smarty->assign("sambaDomainNameACL",       chkacl($this->acl, "sambaDomainName"));
578     $smarty->assign("logon_time_setACL",        chkacl($this->acl, "logon_time_set"));
579     $smarty->assign("logoff_time_setACL",       chkacl($this->acl, "logoff_time_set"));
580     $smarty->assign("kickoff_time_setACL",      chkacl($this->acl, "kickoff_time_set"));
581     $smarty->assign("sambaLogonTimeACL",        chkacl($this->acl, "sambaLogonTime"));
582     $smarty->assign("sambaLogoffTimeACL",       chkacl($this->acl, "sambaLogoffTime"));
583     $smarty->assign("sambaKickoffTimeACL",      chkacl($this->acl, "sambaKickoffTime"));
586     /* In case of javascript, disable some fields on demand */
587     if ($this->samba3){
588       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
589         $smarty->assign("$key", "$value");
590       }
591     }
593     /* Show main page */
594     if ($this->samba3){
595       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
596     } else {
597       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
598     }
600     return ($display);
601   }
603   function remove_from_parent()
604   {
605     /* Cancel if there's nothing to do here */
606    if (!$this->initially_was_account){
607      return;
608    }
609     
610     /* include global link_info */
611     $ldap= $this->config->get_ldap_link();
613     plugin::remove_from_parent();
615     /* Keep uid attribute for gosaAccount */
616     unset($this->attrs['uid']);
617     unset($this->attrs['uidNumber']);
618     unset($this->attrs['gidNumber']);
619     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
620         $this->attributes, "Save");
621     $ldap->cd($this->dn);
622     $ldap->modify($this->attrs);
623     show_ldap_error($ldap->get_error());
625     /* Optionally execute a command after we're done */
626     $this->handle_post_events("remove");
627   }
630   /* Check for input problems */
631   function check()
632   {
633     $message= array();
635     if ($this->samba3){
637       /* Strings */
638       foreach (array( "sambaHomePath" => _("Home directory"),
639             "sambaProfilePath" => _("Profile path")) as $key => $val){
640         if (!$this->mungedObject->is_samba_path($this->$key)){
641           $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
642         }
643       }
645       /* Numeric values */
646       foreach (array(   "CtxMaxConnectionTime" => _("Connection"),
647             "CtxMaxDisconnectionTime" => _("Disconnection"),
648             "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
650         if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
651           $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
652         }
653       }
655       /* Too many workstations? Windows usrmgr only supports eight */
656       if (substr_count($this->sambaUserWorkstations, ",") >= 8){
657         $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
658       }
659     }
661     return ($message);
662   }
665   /* Save data to object */
666   function save_object()
667   {
668     /* We only care if we are on the sambaTab... */
669     if (isset($_POST['sambaTab'])){
670       plugin::save_object();
672       /* Take care about access options */
673       if (chkacl ($this->acl, "acctFlags") == ""){
674         if ($this->samba3){
675           $attrname= "sambaPwdCanChange";
676         } else {
677           $attrname= "pwdCanChange";
678         }
679         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
680           $tmp= 1;
681         } else {
682           $tmp= 0;
683         }
684         if ($this->$attrname != $tmp){
685           $this->is_modified= TRUE;
686         }
687         $this->pwdCanChange= $tmp;
688         $this->sambaPwdCanChange= $tmp;
689       }
690       $tmp= "UX";
691       if (isset($_POST["no_password_required"])){
692         if ($_POST["no_password_required"] == 1){
693           $tmp.= "N";
694         }
695       }
696       if (isset($_POST["password_expires"])){
697         if ($_POST["password_expires"] == 1){
698           $this->password_expires= 1;
699         }
700       } else {
701         $this->password_expires= 0;
702       }
703       if (isset($_POST["temporary_disable"])){
704         if ($_POST["temporary_disable"] == 1){
705           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
706             $tmp.= "L";
707           } else {
708             $tmp.= "D";
709           }
710         }
711       }
712       if (isset($_POST["logon_time_set"])){
713         if ($_POST["logon_time_set"] == 1){
714           $this->logon_time_set= 1;
715         }
716       } else {
717         $this->logon_time_set= 0;
718       }
719       if (isset($_POST["logoff_time_set"])){
720         if ($_POST["logoff_time_set"] == 1){
721           $this->logoff_time_set= 1;
722         }
723       } else {
724         $this->logoff_time_set= 0;
725       }
726       if (isset($_POST["kickoff_time_set"])){
727         if ($_POST["kickoff_time_set"] == 1){
728           $this->kickoff_time_set= 1;
729         }
730       } else {
731         $this->kickoff_time_set= 0;
732       }
733       
734       $fill= "";
735       for ($i= strlen($tmp); $i<12; $i++){
736         $fill.= " ";
737       }
739       $tmp= "[$tmp$fill]";
741       /* Only save if acl's are set */
742       if (chkacl ($this->acl, "acctFlags") == ""){
743         if ($this->samba3){
744           $attrname= "sambaAcctFlags";
745         } else {
746           $attrname= "acctFlags";
747         }
748         if ($this->$attrname != $tmp){
749           $this->is_modified= TRUE;
750         }
751         $this->$attrname= $tmp;
752       }
754       /* Save sambaDomain attribute */
755       if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
756           isset ($_POST['sambaDomainName'])){
758         $this->sambaDomainName= validate($_POST['sambaDomainName']);
759       }
761       /* Save CTX values */
762       if ($this->samba3){
763         /* Save obvious values */
764         foreach($this->ctxattributes as $val){
765           if (isset($_POST[$val]) && chkacl($this->acl, "$val") == ""){
766             if (get_magic_quotes_gpc()) {
767               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
768             } else {
769               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
770             }
771           }
772         }
774         /* Save checkbox states. */
775         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
776                         && chkacl($this->acl, "tslogin") == "");
777         // Need to do some index checking to avoid messages like "index ... not found"
778         if(isset($_POST['brokenconn'])) {
779           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
780                           && chkacl($this->acl, "brokenconn") == "");
781         }
782         if(isset($_POST['reconn'])) {
783           $this->mungedObject->setReConn($_POST['reconn'] == '1'
784                           && chkacl($this->acl, "reconn") == "");
785         }
786         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
787                         && chkacl($this->acl, "inherit") == "");
788         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
789                         && chkacl($this->acl, "CtxMaxConnectionTime") == "");
790         $this->mungedObject->setCtxMaxDisconnectionTimeF(
791                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
792                         && chkacl($this->acl, "CtxMaxDisconnectionTime") == "");
793         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
794                         && chkacl($this->acl, "CtxMaxIdleTime") == "");
795         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
796                         && chkacl($this->acl, "connectclientdrives") == "");
797         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
798                         && chkacl($this->acl, "connectclientprinters") == "");
799         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
800                         && chkacl($this->acl, "defaultprinter") == "");
802         /* Save combo boxes. Takes two values */
803         if(isset($_POST['reconn'])) {
804           $this->mungedObject->setShadow((isset($_POST['shadow'])
805                           && chkacl($this->acl, "shadow") == ""), $_POST['shadow']);
806         }
808         /* Check for changes */
809         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
810           $this->is_modified= TRUE;
811         }
812       }
813     }
814   }
817   /* Save to LDAP */
818   function save()
819   {
820     /* Load uid and gid of this 'dn' */
821     $ldap= $this->config->get_ldap_link();
822     $ldap->cat($this->dn);
823     $tmp= $ldap->fetch();
824     $this->uidNumber= $tmp['uidNumber'][0];
825     $this->gidNumber= $tmp['gidNumber'][0];
827     plugin::save();
829     /* Remove objectClass for sambaIdmapEntry */
830     $tmp= array();
831     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
832       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
833         $tmp[]= $this->attrs['objectClass'][$i];
834       }
835     }
836     $this->attrs['objectClass']= $tmp;
838     /* Generate rid / primaryGroupId */
839     if ($this->samba3){
840       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
841         print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
842       } else {
843         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
844         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
845       }
847       /* Need to generate a new uniqe uid/gid combination? */
848       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
849         $uidNumber= $this->uidNumber;
850         while(TRUE){
851           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
852           $ldap->cd($this->config->current['BASE']);
853           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
854           if ($ldap->count() == 0){
855             break;
856           }
857           $uidNumber++;
858         }
859         $this->attrs['sambaSID']= $sid;
861         /* Check for users primary group */
862         $ldap->cd($this->config->current['BASE']);
863         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))",
864                       array("cn"));
865         if ($ldap->count() != 1){
866           print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
867         } else {
868           $attrs= $ldap->fetch();
869           $g= new group($this->config, $ldap->getDN());
870           if ($g->sambaSID == ""){
871             $g->sambaDomainName= $this->sambaDomainName;
872             $g->smbgroup= TRUE;
873             $g->save ();
874           }
875           $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
876         }
877       }
879       if ($this->sambaHomeDrive == ""){
880         $this->attrs["sambaHomeDrive"]= array();
881       }
883       /* Generate munged dial value */
884       $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
886       /* User wants me to fake the idMappings? This is useful for
887          making winbind resolve the user names in a reasonable amount
888          of time in combination with larger databases. */
889       if (isset($this->config->current['SAMBAIDMAPPING']) &&
890           preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
891         $this->attrs['objectClass'][]= "sambaIdmapEntry";
892       }
895       /* Password expiery */
896       if ($this->password_expires == "1"){
897         $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
898       } else {
899         $this->attrs['sambaPwdMustChange']= array();
900       }
901       /* Make sure not to save zero in sambaPwdLastset */
902       if ($this->sambaPwdLastSet != "0"){
903         $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
904       } else {
905         $this->attrs['sambaPwdLastSet']= array();
906       }
907       /* Account expiery */
908       if ($this->logon_time_set == "1"){
909         $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
910       } else {
911         $this->attrs['sambaLogonTime']= array();
912       }
913       if ($this->logoff_time_set == "1"){
914         $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
915       } else {
916         $this->attrs['sambaLogoffTime']= array();
917       }
918       if ($this->kickoff_time_set == "1"){
919         # Add one day in unixtime format to be compatible with usrmgr
920         //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400; 
921         $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert 
922       } else {
923         $this->attrs['sambaKickoffTime']= array();
924       }
925     } else {
926     /* Not samba3 */
927       $this->attrs['rid']= $this->uidNumber*2 + 1000;
928       $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
930       if ($this->homeDrive == ""){
931         $this->attrs["homeDrive"]= array();
932       }
934       /* Password expiery */
935       if ($this->password_expires == "1"){
936         $this->attrs['pwdMustChange']= $this->pwdMustChange;
937       } else {
938         $this->attrs['pwdMustChange']= 2147483647;
939       }
940       /* Make sure not to save zero in pwdLastset */
941       if ($this->pwdLastSet != "0"){
942         $this->attrs['pwdLastSet']= $this->pwdLastSet;
943       } else {
944         $this->attrs['pwdLastSet']= array();
945       }
946       /* Account expiery */
947       if ($this->logon_time_set == "1"){
948         $this->attrs['logonTime']= $this->logonTime;
949       } else {
950         $this->attrs['logonTime']= array();
951       }
952       if ($this->logoff_time_set == "1"){
953         $this->attrs['logoffTime']= $this->logoffTime;
954       } else {
955         $this->attrs['logoffTime']= array();
956       }
957       if ($this->kickoff_time_set == "1"){
958         # Add one day in unixtime format to be compatible with usrmgr
959         $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
960       } else {
961         $this->attrs['kickoffTime']= array();
962       }
963     }
965     /* Write back to ldap */
966     $ldap->cd($this->dn);
967     $ldap->modify($this->attrs);
968     show_ldap_error($ldap->get_error());
970     /* Optionally execute a command after we're done */
971     if ($this->initially_was_account == $this->is_account){
972       if ($this->is_modified){
973         $this->handle_post_events("modify");
974       }
975     } else {
976       $this->handle_post_events("add");
977     }
979   }
981   function adapt_from_template($dn)
982   {
983     plugin::adapt_from_template($dn);
984     $this->sambaSID= "";
985     $this->sambaPrimaryGroupSID= "";
987       /* Fill mungedDial field */
988     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
989       $this->mungedObject->load($this->sambaMungedDial);
990     }
992     /* Password expiery */
993     if(isset($this->attrs['sambaPwdMustChange']) &&
994         $this->attrs['sambaPwdMustChange'][0] != 0){
995       $this->password_expires= 1;
996     }
998     if(isset($this->attrs['sambaLogonTime']) && ! (
999         $this->attrs['sambaLogonTime'][0] == 0 ||
1000         $this->attrs['sambaLogonTime'][0] == 2147483647
1001       )){
1002       $this->logon_time_set= 1;
1003     }
1004     if(isset($this->attrs['sambaLogoffTime']) && ! (
1005         $this->attrs['sambaLogoffTime'][0] == 0 ||
1006         $this->attrs['sambaLogoffTime'][0] == 2147483647
1007       )){
1008       $this->logoff_time_set= 1;
1009     }
1011     /* Account expiery */
1012     if(isset($this->attrs['sambaKickoffTime']) && ! (
1013         $this->attrs['sambaKickoffTime'][0] == 0 ||
1014         $this->attrs['sambaKickoffTime'][0] == 2147483647
1015       )){
1016       $this->kickoff_time_set= 1;
1017     }
1019     /* Get global filter config */
1020     if (!is_global("sambafilter")){
1021       $ui= get_userinfo();
1022       $base= get_base_from_people($ui->dn);
1023       $sambafilter= array( "depselect" => $base, "regex" => "*");
1024       register_global("sambafilter", $sambafilter);
1025     }
1028   }
1032 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1033 ?>