Code

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