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 }
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\"> <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 }
244 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
245 $sambaLogoffTime_date= getdate();
246 } else {
247 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
248 }
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"]);
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"]);
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"]);
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"]);
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 checkboxes to checked or unchecked state */
476 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
477 $smarty->assign("tsloginACL", chkacl($this->acl,"tslogin"));
479 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
480 $smarty->assign("inheritACL", chkacl($this->acl,"inherit"));
483 $smarty->assign("connectclientdrives",
484 $this->mungedObject->getConnectClientDrives()?"checked":"");
485 $smarty->assign("connectclientdrivesACL", chkacl($this->acl,"connectclientdrives"));
486 $smarty->assign("connectclientprinters",
487 $this->mungedObject->getConnectClientPrinters()?"checked":"");
488 $smarty->assign("connectclientprintersACL", chkacl($this->acl,"connectclientprinters"));
489 $smarty->assign("defaultprinter",
490 $this->mungedObject->getDefaultPrinter()?"checked":"");
491 $smarty->assign("defaultprinterACL", chkacl($this->acl,"defaultprinter"));
492 $smarty->assign("CtxMaxConnectionTimeF",
493 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
494 $smarty->assign("CtxMaxDisconnectionTimeF",
495 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
496 $smarty->assign("CtxMaxIdleTimeF",
497 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
499 /* Fill sambaUserWorkstations */
500 $ws= split(",", $this->sambaUserWorkstations);
501 sort($ws);
503 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
504 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
507 $smarty->assign("workstations", $ws);
508 $smarty->assign("sambaUserWorkstationACL", chkacl($this->acl,"sambauserworkstation"));
509 }
511 /* Variables */
512 foreach($this->attributes as $val){
513 $smarty->assign("$val", $this->$val);
514 $smarty->assign("$val"."ACL", chkacl($this->acl,$val));
515 }
518 /* 'sambaAcctFlags' checkboxes */
519 /* Check for 'lock-account'-flag: 'D' or 'L' */
520 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
521 is_integer(strpos($this->sambaAcctFlags, "L"))) {
522 $smarty->assign("flagsD", "checked");
523 } else {
524 $smarty->assign("flagsD", "");
525 }
527 /* Check for no_password_required flag 'N' */
528 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
529 $smarty->assign("flagsN", "checked");
530 } else {
531 $smarty->assign("flagsN", "");
532 }
534 /* 'normal' Checkboxes */
535 if ($this->pwdCanChange=="1"){
536 $smarty->assign("flagsP", "checked");
537 } else {
538 $smarty->assign("flagsP", "");
539 }
540 if ($this->password_expires=="1"){
541 $smarty->assign("flagsC", "checked");
542 } else {
543 $smarty->assign("flagsC", "");
544 }
545 if ($this->logon_time_set=="1"){
546 $smarty->assign("flagsT", "checked");
547 } else {
548 $smarty->assign("flagsT", "");
549 }
550 if ($this->logoff_time_set=="1"){
551 $smarty->assign("flagsO", "checked");
552 } else {
553 $smarty->assign("flagsO", "");
554 }
555 if ($this->kickoff_time_set=="1"){
556 $smarty->assign("flagsK", "checked");
557 } else {
558 $smarty->assign("flagsK", "");
559 }
561 $smarty->assign("allow_pwchangeACL", chkacl($this->acl, "allow_pwchange"));
562 $smarty->assign("password_expiresACL", chkacl($this->acl, "password_expires"));
563 $smarty->assign("no_password_requiredACL", chkacl($this->acl, "no_password_required"));
564 $smarty->assign("temporary_disableACL", chkacl($this->acl, "temporary_disable"));
565 $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
566 $smarty->assign("logon_time_setACL", chkacl($this->acl, "logon_time_set"));
567 $smarty->assign("logoff_time_setACL", chkacl($this->acl, "logoff_time_set"));
568 $smarty->assign("kickoff_time_setACL", chkacl($this->acl, "kickoff_time_set"));
569 $smarty->assign("sambaLogonTimeACL", chkacl($this->acl, "sambaLogonTime"));
570 $smarty->assign("sambaLogoffTimeACL", chkacl($this->acl, "sambaLogoffTime"));
571 $smarty->assign("sambaKickoffTimeACL", chkacl($this->acl, "sambaKickoffTime"));
574 /* In case of javascript, disable some fields on demand */
575 if ($this->samba3 && $_SESSION['js']){
576 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
577 $smarty->assign("$key", "$value");
578 }
579 }
581 /* Show main page */
582 if ($this->samba3){
583 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
584 } else {
585 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
586 }
588 return ($display);
589 }
591 function remove_from_parent()
592 {
593 /* Cancel if there's nothing to do here */
594 if (!$this->initially_was_account){
595 return;
596 }
598 /* include global link_info */
599 $ldap= $this->config->get_ldap_link();
601 plugin::remove_from_parent();
603 /* Keep uid attribute for gosaAccount */
604 unset($this->attrs['uid']);
605 unset($this->attrs['uidNumber']);
606 unset($this->attrs['gidNumber']);
607 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
608 $this->attributes, "Save");
609 $ldap->cd($this->dn);
610 $ldap->modify($this->attrs);
611 show_ldap_error($ldap->get_error());
613 /* Optionally execute a command after we're done */
614 $this->handle_post_events("remove");
615 }
618 /* Check for input problems */
619 function check()
620 {
621 $message= array();
623 if ($this->samba3){
625 /* Strings */
626 foreach (array( "sambaHomePath" => _("Home directory"),
627 "sambaProfilePath" => _("Profile path")) as $key => $val){
628 if (!$this->mungedObject->is_samba_path($this->$key)){
629 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
630 }
631 }
633 /* Numeric values */
634 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
635 "CtxMaxDisconnectionTime" => _("Disconnection"),
636 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
638 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
639 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
640 }
641 }
643 /* Too many workstations? Windows usrmgr only supports eight */
644 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
645 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
646 }
647 }
649 return ($message);
650 }
653 /* Save data to object */
654 function save_object()
655 {
656 /* We only care if we are on the sambaTab... */
657 if (isset($_POST['sambaTab'])){
658 plugin::save_object();
660 /* Take care about access options */
661 if (chkacl ($this->acl, "acctFlags") == ""){
662 if ($this->samba3){
663 $attrname= "sambaPwdCanChange";
664 } else {
665 $attrname= "pwdCanChange";
666 }
667 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
668 $tmp= 1;
669 } else {
670 $tmp= 0;
671 }
672 if ($this->$attrname != $tmp){
673 $this->is_modified= TRUE;
674 }
675 $this->pwdCanChange= $tmp;
676 $this->sambaPwdCanChange= $tmp;
677 }
678 $tmp= "UX";
679 if (isset($_POST["no_password_required"])){
680 if ($_POST["no_password_required"] == 1){
681 $tmp.= "N";
682 }
683 }
684 if (isset($_POST["password_expires"])){
685 if ($_POST["password_expires"] == 1){
686 $this->password_expires= 1;
687 }
688 } else {
689 $this->password_expires= 0;
690 }
691 if (isset($_POST["temporary_disable"])){
692 if ($_POST["temporary_disable"] == 1){
693 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
694 $tmp.= "L";
695 } else {
696 $tmp.= "D";
697 }
698 }
699 }
700 if (isset($_POST["logon_time_set"])){
701 if ($_POST["logon_time_set"] == 1){
702 $this->logon_time_set= 1;
703 }
704 } else {
705 $this->logon_time_set= 0;
706 }
707 if (isset($_POST["logoff_time_set"])){
708 if ($_POST["logoff_time_set"] == 1){
709 $this->logoff_time_set= 1;
710 }
711 } else {
712 $this->logoff_time_set= 0;
713 }
714 if (isset($_POST["kickoff_time_set"])){
715 if ($_POST["kickoff_time_set"] == 1){
716 $this->kickoff_time_set= 1;
717 }
718 } else {
719 $this->kickoff_time_set= 0;
720 }
722 $fill= "";
723 for ($i= strlen($tmp); $i<12; $i++){
724 $fill.= " ";
725 }
727 $tmp= "[$tmp$fill]";
729 /* Only save if acl's are set */
730 if (chkacl ($this->acl, "acctFlags") == ""){
731 if ($this->samba3){
732 $attrname= "sambaAcctFlags";
733 } else {
734 $attrname= "acctFlags";
735 }
736 if ($this->$attrname != $tmp){
737 $this->is_modified= TRUE;
738 }
739 $this->$attrname= $tmp;
740 }
742 /* Save sambaDomain attribute */
743 if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
744 isset ($_POST['sambaDomainName'])){
746 $this->sambaDomainName= validate($_POST['sambaDomainName']);
747 }
749 /* Save CTX values */
750 if ($this->samba3){
751 /* Save obvious values */
752 foreach($this->ctxattributes as $val){
753 if (isset($_POST[$val]) && chkacl($this->acl, "$val") == ""){
754 if (get_magic_quotes_gpc()) {
755 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
756 } else {
757 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
758 }
759 }
760 }
762 /* Save checkbox states. */
763 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
764 && chkacl($this->acl, "tslogin") == "");
765 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
766 && chkacl($this->acl, "brokenconn") == "");
767 $this->mungedObject->setReConn($_POST['reconn'] == '1'
768 && chkacl($this->acl, "reconn") == "");
769 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
770 && chkacl($this->acl, "inherit") == "");
771 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
772 && chkacl($this->acl, "CtxMaxConnectionTime") == "");
773 $this->mungedObject->setCtxMaxDisconnectionTimeF(
774 !isset($_POST['CtxMaxDisconnectionTimeF'])
775 && chkacl($this->acl, "CtxMaxDisconnectionTime") == "");
776 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
777 && chkacl($this->acl, "CtxMaxIdleTime") == "");
778 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
779 && chkacl($this->acl, "connectclientdrives") == "");
780 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
781 && chkacl($this->acl, "connectclientprinters") == "");
782 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
783 && chkacl($this->acl, "defaultprinter") == "");
785 /* Save combo boxes. Takes two values */
786 $this->mungedObject->setShadow((isset($_POST['shadow'])
787 && chkacl($this->acl, "shadow") == ""), $_POST['shadow']);
789 /* Check for changes */
790 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
791 $this->is_modified= TRUE;
792 }
793 }
794 }
795 }
798 /* Save to LDAP */
799 function save()
800 {
801 /* Load uid and gid of this 'dn' */
802 $ldap= $this->config->get_ldap_link();
803 $ldap->cat($this->dn);
804 $tmp= $ldap->fetch();
805 $this->uidNumber= $tmp['uidNumber'][0];
806 $this->gidNumber= $tmp['gidNumber'][0];
808 plugin::save();
810 /* Remove objectClass for sambaIdmapEntry */
811 $tmp= array();
812 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
813 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
814 $tmp[]= $this->attrs['objectClass'][$i];
815 }
816 }
817 $this->attrs['objectClass']= $tmp;
819 /* Generate rid / primaryGroupId */
820 if ($this->samba3){
821 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
822 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
823 } else {
824 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
825 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
826 }
828 /* Need to generate a new uniqe uid/gid combination? */
829 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
830 $uidNumber= $this->uidNumber;
831 while(TRUE){
832 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
833 $ldap->cd($this->config->current['BASE']);
834 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
835 if ($ldap->count() == 0){
836 break;
837 }
838 $uidNumber++;
839 }
840 $this->attrs['sambaSID']= $sid;
842 /* Check for users primary group */
843 $ldap->cd($this->config->current['BASE']);
844 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))",
845 array("cn"));
846 if ($ldap->count() != 1){
847 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
848 } else {
849 $attrs= $ldap->fetch();
850 $g= new group($this->config, $ldap->getDN());
851 if ($g->sambaSID == ""){
852 $g->sambaDomainName= $this->sambaDomainName;
853 $g->smbgroup= TRUE;
854 $g->save ();
855 }
856 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
857 }
858 }
860 if ($this->sambaHomeDrive == ""){
861 $this->attrs["sambaHomeDrive"]= array();
862 }
864 /* Generate munged dial value */
865 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
867 /* User wants me to fake the idMappings? This is useful for
868 making winbind resolve the user names in a reasonable amount
869 of time in combination with larger databases. */
870 if (isset($this->config->current['SAMBAIDMAPPING']) &&
871 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
872 $this->attrs['objectClass'][]= "sambaIdmapEntry";
873 }
876 /* Password expiery */
877 if ($this->password_expires == "1"){
878 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
879 } else {
880 $this->attrs['sambaPwdMustChange']= array();
881 }
882 /* Account expiery */
883 if ($this->logon_time_set == "1"){
884 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
885 } else {
886 # $this->attrs['sambaLogonTime']= array();
887 # Set more useful default setting
888 $this->attrs['sambaLogonTime']= 0;
889 }
890 if ($this->logoff_time_set == "1"){
891 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
892 } else {
893 # $this->attrs['sambaLogoffTime']= array();
894 # Set more useful default setting
895 $this->attrs['sambaLogoffTime']= 2147483647;
896 }
897 if ($this->kickoff_time_set == "1"){
898 # Add one day in unixtime format to be compatible with usrmgr
899 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
900 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
901 } else {
902 # $this->attrs['sambaKickoffTime']= array();
903 # Set more useful default setting
904 $this->attrs['sambaKickoffTime']= 2147483647;
905 }
906 } else {
907 /* Not samba3 */
908 $this->attrs['rid']= $this->uidNumber*2 + 1000;
909 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
911 if ($this->homeDrive == ""){
912 $this->attrs["homeDrive"]= array();
913 }
915 /* Password expiery */
916 if ($this->password_expires == "1"){
917 $this->attrs['pwdMustChange']= $this->pwdMustChange;
918 } else {
919 $this->attrs['pwdMustChange']= 2147483647;
920 }
921 /* Account expiery */
922 if ($this->logon_time_set == "1"){
923 $this->attrs['logonTime']= $this->logonTime;
924 } else {
925 $this->attrs['logonTime']= 0;
926 }
927 if ($this->logoff_time_set == "1"){
928 $this->attrs['logoffTime']= $this->logoffTime;
929 } else {
930 $this->attrs['logoffTime']= 2147483647;
931 }
932 if ($this->kickoff_time_set == "1"){
933 # Add one day in unixtime format to be compatible with usrmgr
934 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
935 } else {
936 $this->attrs['kickoffTime']= 2147483647;
937 }
938 }
940 /* Write back to ldap */
941 $ldap->cd($this->dn);
942 $ldap->modify($this->attrs);
943 show_ldap_error($ldap->get_error());
945 /* Optionally execute a command after we're done */
946 if ($this->initially_was_account == $this->is_account){
947 if ($this->is_modified){
948 $this->handle_post_events("modify");
949 }
950 } else {
951 $this->handle_post_events("add");
952 }
954 }
956 function adapt_from_template($dn)
957 {
958 plugin::adapt_from_template($dn);
959 $this->sambaSID= "";
960 $this->sambaPrimaryGroupSID= "";
961 }
963 }
965 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
966 ?>