Code

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