Code

Prepared group Generic & Template for new acls .... not tested & not complete
[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();
90   var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
92   function sambaAccount ($config, $dn= NULL)
93   {
94     /* Load attributes depending on the samba version */
95     $this->samba3= ($config->current['SAMBAVERSION'] == 3);
97     if ($this->samba3){
98       $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
99           "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
100           "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
101           "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
102           "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
103           "sambaUserWorkstations", "sambaPasswordHistory",
104           "sambaLogonHours", "sambaBadPasswordTime",
105           "sambaBadPasswordCount");
106       $this->objectclasses= array ("sambaSamAccount");
107       $this->mungedObject= new sambaMungedDial;
108       $this->ctxattributes= $this->mungedObject->ctxattributes;
109     } else {
110       $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
111           "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
112           "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
113       $this->objectclasses= array ("sambaAccount");
114     }
116     plugin::plugin ($config, $dn);
118     /* Get samba Domain in case of samba 3 */
119     if ($this->samba3 && $this->sambaSID != ""){
120       $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
121       $ldap= $this->config->get_ldap_link();
122       $ldap->cd($this->config->current['BASE']);
123       $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
124       if ($ldap->count() != 0){
125         $attrs= $ldap->fetch();
126         $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
127         if ($this->sambaDomainName == ""){
128           $this->sambaDomainName= $attrs['sambaDomainName'][0];
129         }
130       } else {
131         if ($this->sambaDomainName == ""){
132           $this->sambaDomainName= "DEFAULT";
133         }
134         $this->ridBase= $this->config->current['RIDBASE'];
135         $this->SID= $this->config->current['SID'];
136       }
138       /* Save in order to compare later on */
139       $this->orig_sambaDomainName= $this->sambaDomainName;
140     }
142     /* Fill mungedDial field */
143     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
144       $this->mungedObject->load($this->sambaMungedDial);
145     }
147     /* Password expiery */
148     if(isset($this->attrs['sambaPwdMustChange']) &&
149         $this->attrs['sambaPwdMustChange'][0] != 0){
150       $this->password_expires= 1;
151     }
153     if(isset($this->attrs['sambaLogonTime']) && ! (
154         $this->attrs['sambaLogonTime'][0] == 0 ||
155         $this->attrs['sambaLogonTime'][0] == 2147483647
156       )){
157       $this->logon_time_set= 1;
158     }
159     if(isset($this->attrs['sambaLogoffTime']) && ! (
160         $this->attrs['sambaLogoffTime'][0] == 0 ||
161         $this->attrs['sambaLogoffTime'][0] == 2147483647
162       )){
163       $this->logoff_time_set= 1;
164     }
165     
166     /* Account expiery */
167     if(isset($this->attrs['sambaKickoffTime']) && ! (
168         $this->attrs['sambaKickoffTime'][0] == 0 ||
169         $this->attrs['sambaKickoffTime'][0] == 2147483647
170       )){
171       $this->kickoff_time_set= 1;
172     }
174     /* Get global filter config */
175     if (!is_global("sambafilter")){
176       $ui= get_userinfo();
177       $base= get_base_from_people($ui->dn);
178       $sambafilter= array( "depselect" => $base, "regex" => "*");
179       register_global("sambafilter", $sambafilter);
180     }
182     /* Save initial account state */
183     $this->initially_was_account= $this->is_account;
184   }
186   function execute()
187   {
188         /* Call parent execute */
189         plugin::execute();
191     /* Do we need to flip is_account state? */
192     if (isset($_POST['modify_state'])){
193       $this->is_account= !$this->is_account;
194     }
195     /* Do we represent a valid account? */
196     if (!$this->is_account && $this->parent == NULL){
197       $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
198         _("This account has no samba extensions.")."</b>";
199       $display.= back_to_main();
200       return ($display);
201     }
203     /* Show tab dialog headers */
204     $display= "";
205     if ($this->parent != NULL){
206       if ($this->is_account){
207         $display= $this->show_disable_header(_("Remove samba account"),
208             _("This account has samba features enabled. You can disable them by clicking below."));
209       } else {
210         $obj= $this->parent->by_object['posixAccount'];
212         /* Samba3 dependency on posix accounts are enabled
213            in the moment, because I need to rely on unique
214            uidNumbers. There'll be a better solution later
215            on. */
216         if ($obj->is_account){
218           $display= $this->show_enable_header(_("Create samba account"),
219               _("This account has samba features disabled. You can enable them by clicking below."));
220         } else {
221           $display= $this->show_enable_header(_("Create samba account"),
222               _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
223         }
224         return ($display);
225       }
226     }
228     $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
230     /* Prepare templating */
231     $smarty= get_smarty();
233     $tmp = $this->plInfo();
234     foreach($tmp['plProvidedAcls'] as $var => $rest){
235       $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
236     }
238     if ($this->sambaPwdMustChange=="0"){
239       $date= getdate();
240     } else {
241       $date= getdate($this->sambaPwdMustChange);
242     }
244     if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
245       $sambaLogonTime_date= getdate();
246     } else {
247       $sambaLogonTime_date= getdate($this->sambaLogonTime);
248     }
249     
250     if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
251       $sambaLogoffTime_date= getdate();
252     } else {
253       $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
254     }
255     
256     if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
257       $sambaKickoffTime_date= getdate();
258     } else {
259       $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
260     }
262     /* Remove user workstations? */
263     if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
265       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
267         $tmp= $this->sambaUserWorkstations;
268         foreach($_POST['workstation_list'] as $name){
269           $tmp= preg_replace("/$name/", '', $tmp);
270           $this->is_modified= TRUE;
271         }
272         $tmp= preg_replace('/,+/', ',', $tmp);
273         $this->sambaUserWorkstations= trim($tmp, ',');
274       }
275     }
277     /* Add user workstation? */
278     if (isset($_POST["add_ws"])){
279       if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
280         $this->show_ws_dialog= TRUE;
281         $this->dialog= TRUE;
282       }
283     }
285     /* Add user workstation finished? */
286     if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
287       $this->show_ws_dialog= FALSE;
288       $this->dialog= FALSE;
289     }
291     /* Add user workstation? */
292     if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
293       $tmp= $this->sambaUserWorkstations;
294       foreach($_POST['wslist'] as $ws){
295         $tmp.= ",$ws";
296       }
297       $tmp= preg_replace('/,+/', ',', $tmp);
298       $this->sambaUserWorkstations= trim($tmp, ',');
299       $this->is_modified= TRUE;
300     }
302     /* Show ws dialog */
303     if ($this->show_ws_dialog){
305       /* Save data */
306       $sambafilter= get_global("sambafilter");
307       foreach( array("depselect", "regex") as $type){
308         if (isset($_POST[$type])){
309           $sambafilter[$type]= $_POST[$type];
310         }
311       }
312       if (isset($_GET['search'])){
313         $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
314         if ($s == "**"){
315           $s= "*";
316         }
317         $sambafilter['regex']= $s;
318       }
319       register_global("sambafilter", $sambafilter);
321       /* Get workstation list */
322       $exclude= "";
323       foreach(split(',', $this->sambaUserWorkstations) as $ws){
324         $exclude.= "(cn=$ws$)";
325       }
326       if ($exclude != ""){
327         $exclude= "(!(|$exclude))";
328       }
329       $regex= $sambafilter['regex'];
330       $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
331       $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
332         
333       $wslist= array();
334       foreach ($res as $attrs){
335         $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
336       }
337       asort($wslist);
339       $smarty->assign("search_image", get_template_path('images/search.png'));
340       $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
341       $smarty->assign("tree_image", get_template_path('images/tree.png'));
342       $smarty->assign("deplist", $this->config->idepartments);
343       $smarty->assign("alphabet", generate_alphabet());
344       foreach( array("depselect", "regex") as $type){
345         $smarty->assign("$type", $sambafilter[$type]);
346       }
347       $smarty->assign("hint", print_sizelimit_warning());
348       $smarty->assign("wslist", $wslist);
349       $smarty->assign("apply", apply_filter());
350       $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
351                                 dirname(__FILE__)));
352       return ($display);
353     }
355     /* Fill calendar */
356     $days= array();
357     for($d= 1; $d<32; $d++){
358       $days[]= $d;
359     }
360     $years= array();
361     for($y= $date['year']-4; $y<$date['year']+4; $y++){
362       $years[]= $y;
363     }
364     $months= array(_("January"), _("February"), _("March"), _("April"),
365         _("May"), _("June"), _("July"), _("August"), _("September"),
366         _("October"), _("November"), _("December"));
367     $smarty->assign("day", $date["mday"]);
368     $smarty->assign("days", $days);
369     $smarty->assign("months", $months);
370     $smarty->assign("month", $date["mon"]-1);
371     $smarty->assign("years", $years);
372     $smarty->assign("year", $date["year"]);
373     
374     $sambaLogonTime_days= array();
375     for($d= 1; $d<32; $d++){
376       $sambaLogonTime_days[]= $d;
377     }
378     $sambaLogonTime_years= array();
379     for($y= $date['year']-4; $y<$date['year']+4; $y++){
380       $sambaLogonTime_years[]= $y;
381     }
382     $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
383         _("May"), _("June"), _("July"), _("August"), _("September"),
384         _("October"), _("November"), _("December"));
385     $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
386     $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
387     $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
388     $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
389     $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
390     $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
391     
392     $sambaLogoffTime_days= array();
393     for($d= 1; $d<32; $d++){
394       $sambaLogoffTime_days[]= $d;
395     }
396     $sambaLogoffTime_years= array();
397     for($y= $date['year']-4; $y<$date['year']+4; $y++){
398       $sambaLogoffTime_years[]= $y;
399     }
400     $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
401         _("May"), _("June"), _("July"), _("August"), _("September"),
402         _("October"), _("November"), _("December"));
403     $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
404     $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
405     $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
406     $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
407     $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
408     $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
409     
410     $sambaKickoffTime_days= array();
411     for($d= 1; $d<32; $d++){
412       $sambaKickoffTime_days[]= $d;
413     }
414     $sambaKickoffTime_years= array();
415     for($y= $date['year']-4; $y<$date['year']+4; $y++){
416       $sambaKickoffTime_years[]= $y;
417     }
418     $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
419         _("May"), _("June"), _("July"), _("August"), _("September"),
420         _("October"), _("November"), _("December"));
421     //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
422     $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
423     $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
424     $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
425     $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
426     $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
427     $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
428      
429     /* Fill boxes */
430     if ($this->samba3){
431       $domains= array();
432       foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
433         $domains[]= $name;
434       }
435       $smarty->assign("domains", $domains);
436     }
437     $letters= array();
438     for ($i= 68; $i<91; $i++){
439       $letters[]= chr($i).":";
440     }
441     $smarty->assign("drives", $letters);
443     /* Fill terminal server settings */
444     if ($this->samba3){
445       foreach ($this->ctxattributes as $attr){
446         /* Fill common attributes */
447         if (isset($this->mungedObject->ctx[$attr])){
448           $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
449           // Set field  to blank if value is 0
450           if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
451             if($this->mungedObject->ctx[$attr] == 0) {
452               $smarty->assign("$attr", "");
453             }
454           }
455         } else {
456           $smarty->assign("$attr", "");
457         }
458       }
460       /* Assign enum values for preset items */
461       $shadowModeVals= array( "0" => _("disabled"),
462           "1" => _("input on, notify on"),
463           "2" => _("input on, notify off"),
464           "3" => _("input off, notify on"),
465           "4" => _("input off, nofify off"));
467       $brokenConnModeVals= array(       "0" => _("disconnect"),
468           "1" => _("reset"));
470       $reConnModeVals= array( "0" => _("from any client"),
471           "1" => _("from previous client only"));
473       /* Fill preset items */
474       $smarty->assign("shadow", $shadowModeVals);
475       $smarty->assign("brokenconn", $brokenConnModeVals);
476       $smarty->assign("reconn", $reConnModeVals);
478       /* Fill preset items with values */
479       $smarty->assign("shadowmode", $this->mungedObject->getShadow());
480       $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
481       $smarty->assign("reconnmode", $this->mungedObject->getReConn());
483       if($_SESSION['js']){
484         /* Set form elements to disabled/enable state */
485         $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
487         $smarty->assign("inheritstate", "");
488         if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
489           $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
490         }
491   
493   
494       }else{
495         $smarty->assign("tsloginstate", "");
496         $smarty->assign("inheritstate", "");
497       }      
499       /* Set checkboxes to checked or unchecked state */
500       $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
501       $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
502       $smarty->assign("connectclientdrives",
503                       $this->mungedObject->getConnectClientDrives()?"checked":"");
504       $smarty->assign("connectclientprinters",
505                       $this->mungedObject->getConnectClientPrinters()?"checked":"");
506       $smarty->assign("defaultprinter",
507                       $this->mungedObject->getDefaultPrinter()?"checked":"");
508       $smarty->assign("CtxMaxConnectionTimeF",
509                       $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
510       $smarty->assign("CtxMaxDisconnectionTimeF",
511                       $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
512       $smarty->assign("CtxMaxIdleTimeF",
513                       $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
515       /* Fill sambaUserWorkstations */
516       $ws= split(",", $this->sambaUserWorkstations);
517       sort($ws);
518       
519       /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
520       if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
523       $smarty->assign("workstations", $ws);
524     }
526     /* Variables */
527     foreach($this->attributes as $val){
528       $smarty->assign("$val", $this->$val);
529     }
531     /* 'sambaAcctFlags' checkboxes */
532     /* Check for 'lock-account'-flag: 'D' or 'L' */
533     if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
534         is_integer(strpos($this->sambaAcctFlags, "L"))) {
535         $smarty->assign("flagsD", "checked");
536     } else {
537         $smarty->assign("flagsD", "");
538     }
539     
540     /* Check for no_password_required flag 'N' */
541     if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
542         $smarty->assign("flagsN", "checked");
543     } else {
544         $smarty->assign("flagsN", "");
545     }
547     /* 'normal' Checkboxes */
548     if ($this->pwdCanChange=="1"){
549       $smarty->assign("flagsP", "checked");
550     } else {
551       $smarty->assign("flagsP", "");
552     }
553     if ($this->password_expires=="1"){
554       $smarty->assign("flagsC", "checked");
555     } else {
556       $smarty->assign("flagsC", "");
557     }
558     if ($this->logon_time_set=="1"){
559       $smarty->assign("flagsT", "checked");
560     } else {
561       $smarty->assign("flagsT", "");
562     }
563     if ($this->logoff_time_set=="1"){
564       $smarty->assign("flagsO", "checked");
565     } else {
566       $smarty->assign("flagsO", "");
567     }
568     if ($this->kickoff_time_set=="1"){
569       $smarty->assign("flagsK", "checked");
570     } else {
571       $smarty->assign("flagsK", "");
572     }
573    
575     /* In case of javascript, disable some fields on demand */
576     if ($this->samba3){
577       foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
578         $smarty->assign("$key", "$value");
579       }
580     }
582     /* Show main page */
583     if ($this->samba3){
584       $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
585     } else {
586       $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
587     }
589     return ($display);
590   }
592   function remove_from_parent()
593   {
594     /* Cancel if there's nothing to do here */
595    if (!$this->initially_was_account){
596      return;
597    }
598     
599     /* include global link_info */
600     $ldap= $this->config->get_ldap_link();
602     plugin::remove_from_parent();
604     /* Keep uid attribute for gosaAccount */
605     unset($this->attrs['uid']);
606     unset($this->attrs['uidNumber']);
607     unset($this->attrs['gidNumber']);
608     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
609         $this->attributes, "Save");
610     $ldap->cd($this->dn);
611     $this->cleanup();
612     $ldap->modify ($this->attrs); 
614     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
616     /* Optionally execute a command after we're done */
617     $this->handle_post_events("remove");
618   }
621   /* Check for input problems */
622   function check()
623   {
624     /* Call common method to give check the hook */
625     $message= plugin::check();
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   {
661     $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
663     /* We only care if we are on the sambaTab... */
664     if (isset($_POST['sambaTab'])){
665       plugin::save_object();
667       /* Take care about access options */
668       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
669         if ($this->samba3){
670           $attrname= "sambaPwdCanChange";
671         } else {
672           $attrname= "pwdCanChange";
673         }
674         if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
675           $tmp= 1;
676         } else {
677           $tmp= 0;
678         }
679         if ($this->$attrname != $tmp){
680           $this->is_modified= TRUE;
681         }
682         $this->pwdCanChange= $tmp;
683         $this->sambaPwdCanChange= $tmp;
684       }
685       $tmp= "UX";
686       if (isset($_POST["no_password_required"])){
687         if ($_POST["no_password_required"] == 1){
688           $tmp.= "N";
689         }
690       }
691       if (isset($_POST["password_expires"])){
692         if ($_POST["password_expires"] == 1){
693           $this->password_expires= 1;
694         }
695       } else {
696         $this->password_expires= 0;
697       }
698       if (isset($_POST["temporary_disable"])){
699         if ($_POST["temporary_disable"] == 1){
700           if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
701             $tmp.= "L";
702           } else {
703             $tmp.= "D";
704           }
705         }
706       }
707       if (isset($_POST["logon_time_set"])){
708         if ($_POST["logon_time_set"] == 1){
709           $this->logon_time_set= 1;
710         }
711       } else {
712         $this->logon_time_set= 0;
713       }
714       if (isset($_POST["logoff_time_set"])){
715         if ($_POST["logoff_time_set"] == 1){
716           $this->logoff_time_set= 1;
717         }
718       } else {
719         $this->logoff_time_set= 0;
720       }
721       if (isset($_POST["kickoff_time_set"])){
722         if ($_POST["kickoff_time_set"] == 1){
723           $this->kickoff_time_set= 1;
724         }
725       } else {
726         $this->kickoff_time_set= 0;
727       }
728       
729       $fill= "";
730       for ($i= strlen($tmp); $i<12; $i++){
731         $fill.= " ";
732       }
734       $tmp= "[$tmp$fill]";
736       /* Only save if acl's are set */
737       if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
738         if ($this->samba3){
739           $attrname= "sambaAcctFlags";
740         } else {
741           $attrname= "acctFlags";
742         }
743         if ($this->$attrname != $tmp){
744           $this->is_modified= TRUE;
745         }
746         $this->$attrname= $tmp;
747       }
749       /* Save sambaDomain attribute */
750       if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
751         $this->sambaDomainName= validate($_POST['sambaDomainName']);
752       }
754       /* Save CTX values */
755       if ($this->samba3){
757         /* Save obvious values */
758         foreach($this->ctxattributes as $val){
759           if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
760             if (get_magic_quotes_gpc()) {
761               $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
762             } else {
763               $this->mungedObject->ctx[$val]= validate($_POST[$val]);
764             }
765           }
766         }
768         /* Save checkbox states. */
769         $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
770                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
771         // Need to do some index checking to avoid messages like "index ... not found"
772         if(isset($_POST['brokenconn'])) {
773           $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
774                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
775         }
776         if(isset($_POST['reconn'])) {
777           $this->mungedObject->setReConn($_POST['reconn'] == '1'
778                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
779         }
780         $this->mungedObject->setInheritMode(isset($_POST['inherit'])
781                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
782         $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
783                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
784         $this->mungedObject->setCtxMaxDisconnectionTimeF(
785                         !isset($_POST['CtxMaxDisconnectionTimeF']) 
786                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
787         $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
788                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
789         $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
790                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
791         $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])  
792                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
793         $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
794                         && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
796         /* Save combo boxes. Takes two values */
797         if(isset($_POST['reconn'])) {
798           $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
799         }
801         /* Check for changes */
802         if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
803           $this->is_modified= TRUE;
804         }
805       }
806     }
807   }
810   /* Save to LDAP */
811   function save()
812   {
813     /* Load uid and gid of this 'dn' */
814     $ldap= $this->config->get_ldap_link();
815     $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
816     $tmp= $ldap->fetch();
817     $this->uidNumber= $tmp['uidNumber'][0];
818     $this->gidNumber= $tmp['gidNumber'][0];
820     plugin::save();
822     /* Remove objectClass for sambaIdmapEntry */
823     $tmp= array();
824     for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
825       if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
826         $tmp[]= $this->attrs['objectClass'][$i];
827       }
828     }
829     $this->attrs['objectClass']= $tmp;
831     /* Generate rid / primaryGroupId */
832     if ($this->samba3){
833       if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
834         print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
835       } else {
836         $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
837         $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
838       }
840       /* Need to generate a new uniqe uid/gid combination? */
841       if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
842         $uidNumber= $this->uidNumber;
843         while(TRUE){
844           $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
845           $ldap->cd($this->config->current['BASE']);
846           $ldap->search("(sambaSID=$sid)", array("sambaSID"));
847           if ($ldap->count() == 0){
848             break;
849           }
850           $uidNumber++;
851         }
852         $this->attrs['sambaSID']= $sid;
854         /* Check for users primary group */
855         $ldap->cd($this->config->current['BASE']);
856         $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", 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     $this->cleanup();
960     $ldap->modify ($this->attrs); 
962     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
964     /* Optionally execute a command after we're done */
965     if ($this->initially_was_account == $this->is_account){
966       if ($this->is_modified){
967         $this->handle_post_events("modify");
968       }
969     } else {
970       $this->handle_post_events("add");
971     }
973   }
975   function adapt_from_template($dn)
976   {
977     plugin::adapt_from_template($dn);
978     $this->sambaSID= "";
979     $this->sambaPrimaryGroupSID= "";
981       /* Fill mungedDial field */
982     if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
983       $this->mungedObject->load($this->sambaMungedDial);
984     }
986     /* Password expiery */
987     if(isset($this->attrs['sambaPwdMustChange']) &&
988         $this->attrs['sambaPwdMustChange'][0] != 0){
989       $this->password_expires= 1;
990     }
992     if(isset($this->attrs['sambaLogonTime']) && ! (
993         $this->attrs['sambaLogonTime'][0] == 0 ||
994         $this->attrs['sambaLogonTime'][0] == 2147483647
995       )){
996       $this->logon_time_set= 1;
997     }
998     if(isset($this->attrs['sambaLogoffTime']) && ! (
999         $this->attrs['sambaLogoffTime'][0] == 0 ||
1000         $this->attrs['sambaLogoffTime'][0] == 2147483647
1001       )){
1002       $this->logoff_time_set= 1;
1003     }
1005     /* Account expiery */
1006     if(isset($this->attrs['sambaKickoffTime']) && ! (
1007         $this->attrs['sambaKickoffTime'][0] == 0 ||
1008         $this->attrs['sambaKickoffTime'][0] == 2147483647
1009       )){
1010       $this->kickoff_time_set= 1;
1011     }
1013     /* Get global filter config */
1014     if (!is_global("sambafilter")){
1015       $ui= get_userinfo();
1016       $base= get_base_from_people($ui->dn);
1017       $sambafilter= array( "depselect" => $base, "regex" => "*");
1018       register_global("sambafilter", $sambafilter);
1019     }
1020   }
1022   
1023   function plInfo()
1024   {
1025     return (array(
1026           "plShortName"     => _("Samba"),
1027           "plDescription"   => _("Samba settings"),
1028           "plSelfModify"    => TRUE,
1029           "plDepends"       => array("user"),
1030           "plPriority"      => 5,                                 // Position in tabs
1031           "plSection"       => "personal",                        // This belongs to personal
1032           "plCategory"      => array("users"),                    // Add to following categories
1033           "plOptions"       => array(),
1035           "plProvidedAcls"  => array(
1036             "AllowLoginOnTerminalServer"  => _("Allow login on terminal server"),
1037             "InheritClientConfig"         => _("Inherit client config"),
1039             "sambaPwdCanChange"     => _("Allow user to change password") ,
1040             "sambaAcctFlagsN"            => _("Login from windows client requires no password"),
1041             "sambaAcctFlagsL"            => _("Lock samba account"),
1044             "sambaKickoffTime"      => _("Account expires") ,
1045             "sambaPwdMustChange"    => _("Password expires") ,
1047             "sambaLogonTime"        => _("Limit Logon Time") ,
1048             "sambaLogoffTime"       => _("Limit Logoff Time") ,
1050             "sambaHomePath"         => _("Generic home directory") ,
1051             "sambaHomeDrive"        => _("Generic samba home drive") ,
1052             "sambaLogonScript"      => _("Generic script path") ,
1053             "sambaProfilePath"      => _("Generic profile path") ,
1054             "sambaDomainName"       => _("Domain") ,
1055             "sambaUserWorkstations" => _("Allow connection from")))
1056               );
1057   }    
1060 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1061 ?>