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 /* Switch for Samba version */
28 var $samba3= FALSE;
29 var $uidNumber= 65535;
30 var $gidNumber= 65535;
32 /* Samba 2 attributes */
33 var $pwdLastSet= "0";
34 var $logonTime= "0";
35 var $logoffTime= "2147483647";
36 var $kickoffTime= "2147483647";
37 var $pwdCanChange= "0";
38 var $pwdMustChange= "0";
39 var $password_expires= 0;
40 var $acctFlags= "[UX ]";
41 var $smbHome= "";
42 var $homeDrive= "";
43 var $scriptPath= "";
44 var $profilePath= "";
45 var $rid= "";
46 var $primaryGroupID= "";
48 /* Samba 3 attributes */
49 var $SID= "";
50 var $ridBase= 0;
51 var $sambaSID= "";
52 var $sambaPwdLastSet= "0";
53 var $sambaLogonTime= "0";
54 var $sambaLogoffTime= "2147483647";
55 var $sambaKickoffTime= "2147483647";
56 var $sambaPwdCanChange= "";
57 var $sambaPwdMustChange= "0";
58 var $sambaAcctFlags= "[UX ]";
59 var $sambaHomePath= "";
60 var $sambaHomeDrive= "";
61 var $sambaLogonScript= "";
62 var $sambaProfilePath= "";
63 var $sambaPrimaryGroupSID= "";
64 var $sambaDomainName= "";
65 var $sambaUserWorkstations= "";
66 var $sambaBadPasswordCount= "";
67 var $sambaBadPasswordTime= "";
68 var $sambaPasswordHistory= "";
69 var $sambaLogonHours= "";
70 var $orig_sambaDomainName= "";
71 var $sambaMungedDial= "";
72 var $mungedObject;
74 /* Helper */
75 var $dialog;
76 var $show_ws_dialog= FALSE;
77 var $logon_time_set= 0;
78 var $logoff_time_set= 0;
79 var $kickoff_time_set= 0;
81 /* attribute list for save action */
82 var $ctxattributes= array();
83 var $attributes= array();
84 var $objectclasses= array();
86 var $uid = "";
88 var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
90 function sambaAccount ($config, $dn= NULL, $parent= 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, $parent);
116 /* set user id */
117 if(isset($this->attrs['uid'])){
118 $this->uid = $this->attrs['uid'][0];
119 }
121 /* Get samba Domain in case of samba 3 */
122 if ($this->samba3 && $this->sambaSID != ""){
123 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
124 $ldap= $this->config->get_ldap_link();
125 $ldap->cd($this->config->current['BASE']);
126 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
127 if ($ldap->count() != 0){
128 $attrs= $ldap->fetch();
129 if(isset($attrs['sambaAlgorithmicRidBase'])){
130 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
131 } else {
132 $this->ridBase= $this->config->current['RIDBASE'];
133 }
134 if ($this->sambaDomainName == ""){
135 $this->sambaDomainName= $attrs['sambaDomainName'][0];
136 }
137 } else {
138 if ($this->sambaDomainName == ""){
139 $this->sambaDomainName= "DEFAULT";
140 }
141 $this->ridBase= $this->config->current['RIDBASE'];
142 $this->SID= $this->config->current['SID'];
143 }
145 /* Save in order to compare later on */
146 $this->orig_sambaDomainName= $this->sambaDomainName;
147 }
149 /* Fill mungedDial field */
150 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
151 $this->mungedObject->load($this->sambaMungedDial);
152 }
154 /* Password expiery */
155 if(isset($this->attrs['sambaPwdMustChange']) &&
156 $this->attrs['sambaPwdMustChange'][0] != 0){
157 $this->password_expires= 1;
158 }
160 if(isset($this->attrs['sambaLogonTime']) && ! (
161 $this->attrs['sambaLogonTime'][0] == 0 ||
162 $this->attrs['sambaLogonTime'][0] == 2147483647
163 )){
164 $this->logon_time_set= 1;
165 }
166 if(isset($this->attrs['sambaLogoffTime']) && ! (
167 $this->attrs['sambaLogoffTime'][0] == 0 ||
168 $this->attrs['sambaLogoffTime'][0] == 2147483647
169 )){
170 $this->logoff_time_set= 1;
171 }
173 /* Account expiery */
174 if(isset($this->attrs['sambaKickoffTime']) && ! (
175 $this->attrs['sambaKickoffTime'][0] == 0 ||
176 $this->attrs['sambaKickoffTime'][0] == 2147483647
177 )){
178 $this->kickoff_time_set= 1;
179 }
181 /* Get global filter config */
182 if (!is_global("sambafilter")){
183 $ui= get_userinfo();
184 $base= get_base_from_people($ui->dn);
185 $sambafilter= array( "depselect" => $base, "regex" => "*");
186 register_global("sambafilter", $sambafilter);
187 }
189 /* Save initial account state */
190 $this->initially_was_account= $this->is_account;
191 }
193 function execute()
194 {
195 /* Call parent execute */
196 plugin::execute();
199 /* Do we need to flip is_account state? */
200 if (isset($_POST['modify_state'])){
202 /* Only change account state if allowed */
203 if($this->is_account && $this->acl == "#all#"){
204 $this->is_account= !$this->is_account;
205 }elseif(!$this->is_account && chkacl($this->acl,"create") == ""){
206 $this->is_account= !$this->is_account;
207 }
208 }
210 /* Do we represent a valid account? */
211 if (!$this->is_account && $this->parent == NULL){
212 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
213 _("This account has no samba extensions.")."</b>";
214 $display.= back_to_main();
215 return ($display);
216 }
218 /* Show tab dialog headers */
219 $display= "";
220 if ($this->parent != NULL){
221 if ($this->is_account){
222 $display= $this->show_header(_("Remove samba account"),
223 _("This account has samba features enabled. You can disable them by clicking below."));
224 } else {
225 $obj= $this->parent->by_object['posixAccount'];
227 /* Samba3 dependency on posix accounts are enabled
228 in the moment, because I need to rely on unique
229 uidNumbers. There'll be a better solution later
230 on. */
231 if ($obj->is_account){
233 $display= $this->show_header(_("Create samba account"),
234 _("This account has samba features disabled. You can enable them by clicking below."));
235 } else {
236 $display= $this->show_header(_("Create samba account"),
237 _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
238 }
239 return ($display);
240 }
241 }
244 /* Open Samaba Logong hours dialog */
245 if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && chkacl($this->acl,"sambaLogonHours") == ""){
246 $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
247 }
249 /* Cancel dialog */
250 if(isset($_POST['cancel_logonHours'])){
251 $this->dialog = NULL;
252 }
254 /* Save selected logon hours */
255 if(isset($_POST['save_logonHours'])){
256 $this->dialog->save_object();
257 $this->sambaLogonHours = $this->dialog->save();
258 $this->dialog = NULL;
259 }
261 /* Display dialog */
262 if((isset($this->dialog)) && (is_object($this->dialog))){
263 $this->dialog->save_object();
264 return($this->dialog->execute());
265 }
268 /* Prepare templating */
269 $smarty= get_smarty();
271 /* PHP Fehler "Undefined index: sambaPwdMustChangeACL" */
272 #hickert test
273 $smarty->assign("sambaPwdMustChangeACL", chkacl($this->acl, "sambaPwdMustChangeACL"));
274 #hickert test
275 $smarty->assign("sambaPwdMustChange",$this->sambaPwdMustChange);
277 if ($this->sambaPwdMustChange=="0"){
278 $date= getdate();
279 } else {
280 $date= getdate($this->sambaPwdMustChange);
281 }
283 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
284 $sambaLogonTime_date= getdate();
285 } else {
286 $sambaLogonTime_date= getdate($this->sambaLogonTime);
287 }
289 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
290 $sambaLogoffTime_date= getdate();
291 } else {
292 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
293 }
295 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
296 $sambaKickoffTime_date= getdate();
297 } else {
298 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
299 }
301 /* Remove user workstations? */
302 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
303 $tmp= $this->sambaUserWorkstations;
304 foreach($_POST['workstation_list'] as $name){
305 $tmp= preg_replace("/$name/", '', $tmp);
306 $this->is_modified= TRUE;
307 }
308 $tmp= preg_replace('/,+/', ',', $tmp);
309 $this->sambaUserWorkstations= trim($tmp, ',');
310 }
312 /* Add user workstation? */
313 if (isset($_POST["add_ws"])){
314 $this->show_ws_dialog= TRUE;
315 $this->dialog= TRUE;
316 }
318 /* Add user workstation finished? */
319 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
320 $this->show_ws_dialog= FALSE;
321 $this->dialog= FALSE;
322 }
324 /* Add user workstation? */
325 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
326 $tmp= $this->sambaUserWorkstations;
327 foreach($_POST['wslist'] as $ws){
328 $tmp.= ",$ws";
329 }
330 $tmp= preg_replace('/,+/', ',', $tmp);
331 $this->sambaUserWorkstations= trim($tmp, ',');
332 $this->is_modified= TRUE;
333 }
335 /* Show ws dialog */
336 if ($this->show_ws_dialog){
338 /* Save data */
339 $sambafilter= get_global("sambafilter");
340 foreach( array("depselect", "regex") as $type){
341 if (isset($_POST[$type])){
342 $sambafilter[$type]= $_POST[$type];
343 }
344 }
345 if (isset($_GET['search'])){
346 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
347 if ($s == "**"){
348 $s= "*";
349 }
350 $sambafilter['regex']= $s;
351 }
352 register_global("sambafilter", $sambafilter);
354 /* Get workstation list */
355 $exclude= "";
356 foreach(split(',', $this->sambaUserWorkstations) as $ws){
357 $exclude.= "(cn=$ws$)";
358 }
359 if ($exclude != ""){
360 $exclude= "(!(|$exclude))";
361 }
362 $acl= array($this->config->current['BASE'] => ":all");
363 $regex= $sambafilter['regex'];
364 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
365 $res= get_list($filter, $acl, $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
366 $wslist= array();
367 foreach ($res as $attrs){
368 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
369 }
370 asort($wslist);
372 $smarty->assign("search_image", get_template_path('images/search.png'));
373 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
374 $smarty->assign("tree_image", get_template_path('images/tree.png'));
375 $smarty->assign("deplist", $this->config->idepartments);
376 $smarty->assign("alphabet", generate_alphabet());
377 foreach( array("depselect", "regex") as $type){
378 $smarty->assign("$type", $sambafilter[$type]);
379 }
380 $smarty->assign("hint", print_sizelimit_warning());
381 $smarty->assign("wslist", $wslist);
382 $smarty->assign("apply", apply_filter());
383 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
384 dirname(__FILE__)));
385 return ($display);
386 }
388 /* Fill calendar */
389 $days= array();
390 for($d= 1; $d<32; $d++){
391 $days[]= $d;
392 }
393 $years= array();
394 for($y= $date['year']-4; $y<$date['year']+4; $y++){
395 $years[]= $y;
396 }
397 $months= array(_("January"), _("February"), _("March"), _("April"),
398 _("May"), _("June"), _("July"), _("August"), _("September"),
399 _("October"), _("November"), _("December"));
400 $smarty->assign("day", $date["mday"]);
401 $smarty->assign("days", $days);
402 $smarty->assign("months", $months);
403 $smarty->assign("month", $date["mon"]-1);
404 $smarty->assign("years", $years);
405 $smarty->assign("year", $date["year"]);
407 $sambaLogonTime_days= array();
408 for($d= 1; $d<32; $d++){
409 $sambaLogonTime_days[]= $d;
410 }
411 $sambaLogonTime_years= array();
412 for($y= $date['year']-4; $y<$date['year']+4; $y++){
413 $sambaLogonTime_years[]= $y;
414 }
415 $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
416 _("May"), _("June"), _("July"), _("August"), _("September"),
417 _("October"), _("November"), _("December"));
418 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
419 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
420 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
421 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
422 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
423 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
425 $sambaLogoffTime_days= array();
426 for($d= 1; $d<32; $d++){
427 $sambaLogoffTime_days[]= $d;
428 }
429 $sambaLogoffTime_years= array();
430 for($y= $date['year']-4; $y<$date['year']+4; $y++){
431 $sambaLogoffTime_years[]= $y;
432 }
433 $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
434 _("May"), _("June"), _("July"), _("August"), _("September"),
435 _("October"), _("November"), _("December"));
436 $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
437 $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
438 $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
439 $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
440 $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
441 $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
443 $sambaKickoffTime_days= array();
444 for($d= 1; $d<32; $d++){
445 $sambaKickoffTime_days[]= $d;
446 }
447 $sambaKickoffTime_years= array();
448 for($y= $date['year']-4; $y<$date['year']+4; $y++){
449 $sambaKickoffTime_years[]= $y;
450 }
451 $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
452 _("May"), _("June"), _("July"), _("August"), _("September"),
453 _("October"), _("November"), _("December"));
454 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
455 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
456 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
457 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
458 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
459 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
460 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
462 /* Fill boxes */
463 if ($this->samba3){
464 $domains= array();
465 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
466 $domains[]= $name;
467 }
468 $smarty->assign("domains", $domains);
469 }
470 $letters= array();
471 for ($i= 68; $i<91; $i++){
472 $letters[]= chr($i).":";
473 }
474 $smarty->assign("drives", $letters);
476 /* Fill terminal server settings */
477 if ($this->samba3){
478 foreach ($this->ctxattributes as $attr){
479 /* Fill common attributes */
480 if (isset($this->mungedObject->ctx[$attr])){
481 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
482 // Set field to blank if value is 0
483 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
484 if($this->mungedObject->ctx[$attr] == 0) {
485 $smarty->assign("$attr", "");
486 }
487 }
488 } else {
489 $smarty->assign("$attr", "");
490 }
491 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
492 }
494 /* Assign enum values for preset items */
495 $shadowModeVals= array( "0" => _("disabled"),
496 "1" => _("input on, notify on"),
497 "2" => _("input on, notify off"),
498 "3" => _("input off, notify on"),
499 "4" => _("input off, nofify off"));
501 $brokenConnModeVals= array( "0" => _("disconnect"),
502 "1" => _("reset"));
504 $reConnModeVals= array( "0" => _("from any client"),
505 "1" => _("from previous client only"));
507 /* Fill preset items */
508 $smarty->assign("shadow", $shadowModeVals);
509 $smarty->assign("brokenconn", $brokenConnModeVals);
510 $smarty->assign("reconn", $reConnModeVals);
512 /* Fill preset items with values */
513 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
514 $smarty->assign("shadowACL", chkacl($this->acl,"shadow"));
515 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
516 $smarty->assign("brokenconnACL", chkacl($this->acl,"brokenconn"));
517 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
518 $smarty->assign("reconnACL", chkacl($this->acl,"reconn"));
520 if($_SESSION['js']){
521 /* Set form elements to disabled/enable state */
522 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
523 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
524 }else{
525 $smarty->assign("tsloginstate", "");
526 $smarty->assign("inheritstate", "");
527 }
529 /* Set checkboxes to checked or unchecked state */
530 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
531 $smarty->assign("tsloginACL", chkacl($this->acl,"tslogin"));
533 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
534 $smarty->assign("inheritACL", chkacl($this->acl,"inherit"));
537 $smarty->assign("connectclientdrives",
538 $this->mungedObject->getConnectClientDrives()?"checked":"");
539 $smarty->assign("connectclientdrivesACL", chkacl($this->acl,"connectclientdrives"));
540 $smarty->assign("connectclientprinters",
541 $this->mungedObject->getConnectClientPrinters()?"checked":"");
542 $smarty->assign("connectclientprintersACL", chkacl($this->acl,"connectclientprinters"));
543 $smarty->assign("defaultprinter",
544 $this->mungedObject->getDefaultPrinter()?"checked":"");
545 $smarty->assign("defaultprinterACL", chkacl($this->acl,"defaultprinter"));
546 $smarty->assign("CtxMaxConnectionTimeF",
547 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
548 $smarty->assign("CtxMaxDisconnectionTimeF",
549 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
550 $smarty->assign("CtxMaxIdleTimeF",
551 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
553 /* Fill sambaUserWorkstations */
554 $ws= split(",", $this->sambaUserWorkstations);
555 sort($ws);
557 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
558 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
561 $smarty->assign("workstations", $ws);
562 $smarty->assign("sambaUserWorkstationACL", chkacl($this->acl,"sambaUserWorkstation"));
563 }
565 /* Variables */
566 foreach($this->attributes as $val){
567 $smarty->assign("$val", $this->$val);
568 $smarty->assign("$val"."ACL", chkacl($this->acl,$val));
569 }
572 /* 'sambaAcctFlags' checkboxes */
573 /* Check for 'lock-account'-flag: 'D' or 'L' */
574 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
575 is_integer(strpos($this->sambaAcctFlags, "L"))) {
576 $smarty->assign("flagsD", "checked");
577 } else {
578 $smarty->assign("flagsD", "");
579 }
581 /* Check for no_password_required flag 'N' */
582 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
583 $smarty->assign("flagsN", "checked");
584 } else {
585 $smarty->assign("flagsN", "");
586 }
588 /* 'normal' Checkboxes */
589 if($this->samba3){
590 if ($this->sambaPwdCanChange=="1"){
591 $smarty->assign("flagsP", "checked");
592 } else {
593 $smarty->assign("flagsP", "");
594 }
595 }else{
596 if ($this->pwdCanChange=="1"){
597 $smarty->assign("flagsP", "checked");
598 } else {
599 $smarty->assign("flagsP", "");
600 }
601 }
602 if ($this->password_expires=="1"){
603 $smarty->assign("flagsC", "checked");
604 } else {
605 $smarty->assign("flagsC", "");
606 }
607 if ($this->logon_time_set=="1"){
608 $smarty->assign("flagsT", "checked");
609 } else {
610 $smarty->assign("flagsT", "");
611 }
612 if ($this->logoff_time_set=="1"){
613 $smarty->assign("flagsO", "checked");
614 } else {
615 $smarty->assign("flagsO", "");
616 }
617 if ($this->kickoff_time_set=="1"){
618 $smarty->assign("flagsK", "checked");
619 } else {
620 $smarty->assign("flagsK", "");
621 }
623 $smarty->assign("allow_pwchangeACL", chkacl($this->acl, "allow_pwchange"));
624 $smarty->assign("password_expiresACL", chkacl($this->acl, "password_expires"));
625 $smarty->assign("no_password_requiredACL", chkacl($this->acl, "no_password_required"));
626 $smarty->assign("temporary_disableACL", chkacl($this->acl, "temporary_disable"));
627 $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
628 $smarty->assign("logon_time_setACL", chkacl($this->acl, "logon_time_set"));
629 $smarty->assign("logoff_time_setACL", chkacl($this->acl, "logoff_time_set"));
630 $smarty->assign("kickoff_time_setACL", chkacl($this->acl, "kickoff_time_set"));
631 $smarty->assign("sambaLogonTimeACL", chkacl($this->acl, "sambaLogonTime"));
632 $smarty->assign("sambaLogoffTimeACL", chkacl($this->acl, "sambaLogoffTime"));
633 $smarty->assign("sambaKickoffTimeACL", chkacl($this->acl, "sambaKickoffTime"));
635 $smarty->assign("sambaLogonHoursACL", chkacl($this->acl, "sambaLogonHours"));
637 /* In case of javascript, disable some fields on demand */
638 if ($this->samba3){
639 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
640 $smarty->assign("$key", "$value");
641 }
642 }
644 /* Show main page */
645 if ($this->samba3){
646 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
647 } else {
648 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
649 }
651 return ($display);
652 }
654 function remove_from_parent()
655 {
656 /* Cancel if there's nothing to do here */
657 if (!$this->initially_was_account){
658 return;
659 }
661 /* include global link_info */
662 $ldap= $this->config->get_ldap_link();
664 plugin::remove_from_parent();
666 /* Keep uid attribute for gosaAccount */
667 unset($this->attrs['uid']);
668 unset($this->attrs['uidNumber']);
669 unset($this->attrs['gidNumber']);
671 /* Remove objectClass for sambaIdmapEntry */
672 $tmp= array();
673 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
674 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
675 $tmp[]= $this->attrs['objectClass'][$i];
676 }
677 }
678 $this->attrs['objectClass']= $tmp;
680 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
681 $this->attributes, "Save");
682 $ldap->cd($this->dn);
683 $this->cleanup();
684 $ldap->modify ($this->attrs);
686 show_ldap_error($ldap->get_error(), _("Removing Samba account failed"));
688 /* Optionally execute a command after we're done */
689 $this->handle_post_events("remove",array("uid"=>$this->uid));
690 }
693 /* Check for input problems */
694 function check()
695 {
696 /* Call common method to give check the hook */
697 $message= plugin::check();
699 if ($this->samba3){
701 /* Strings */
702 foreach (array( "sambaHomePath" => _("Home directory"),
703 "sambaProfilePath" => _("Profile path")) as $key => $val){
704 if (!$this->mungedObject->is_samba_path($this->$key)){
705 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
706 }
707 }
709 /* Numeric values */
710 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
711 "CtxMaxDisconnectionTime" => _("Disconnection"),
712 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
714 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
715 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
716 }
717 }
719 /* Too many workstations? Windows usrmgr only supports eight */
720 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
721 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
722 }
723 }
725 return ($message);
726 }
729 /* Force password set, if this account doesn't have any samba passwords */
730 function password_change_needed()
731 {
732 if(!$this->initially_was_account && $this->is_account){
733 $ldap = $this->config->get_ldap_link();
734 $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
735 $attrs = $ldap->fetch();
736 if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
737 return(TRUE);
738 }
739 }
740 return(FALSE);
741 }
744 /* Save data to object */
745 function save_object()
746 {
747 /* We only care if we are on the sambaTab... */
748 if (isset($_POST['sambaTab'])){
749 plugin::save_object();
751 /* Take care about access options */
752 if (chkacl ($this->acl, "acctFlags") == ""){
753 if ($this->samba3){
754 $attrname= "sambaPwdCanChange";
755 } else {
756 $attrname= "pwdCanChange";
757 }
758 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
759 $tmp= 1;
760 } else {
761 $tmp= 0;
762 }
763 if ($this->$attrname != $tmp){
764 $this->is_modified= TRUE;
765 }
766 $this->pwdCanChange= $tmp;
767 $this->sambaPwdCanChange= $tmp;
768 }
769 $tmp= "UX";
770 if (isset($_POST["no_password_required"])){
771 if ($_POST["no_password_required"] == 1){
772 $tmp.= "N";
773 }
774 }
776 if(chkacl($this->acl,"sambaPwdMustChange") == ""){
777 if (isset($_POST["password_expires"])){
778 if ($_POST["password_expires"] == 1){
779 $this->password_expires= 1;
780 }
781 } else {
782 $this->password_expires= 0;
783 }
784 }
786 if (isset($_POST["temporary_disable"])){
787 if ($_POST["temporary_disable"] == 1){
788 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
789 $tmp.= "L";
790 } else {
791 $tmp.= "D";
792 }
793 }
794 }
796 if(chkacl($this->acl,"sambaLogonTime") ==""){
797 if (isset($_POST["logon_time_set"])){
798 if ($_POST["logon_time_set"] == 1){
799 $this->logon_time_set= 1;
800 }
801 } else {
802 $this->logon_time_set= 0;
803 }
804 }
806 if(chkacl($this->acl,"sambaLogoffTime") == ""){
807 if (isset($_POST["logoff_time_set"])){
808 if ($_POST["logoff_time_set"] == 1){
809 $this->logoff_time_set= 1;
810 }
811 } else {
812 $this->logoff_time_set= 0;
813 }
814 }
816 if(chkacl($this->acl,"sambaKickoffTime") == ""){
817 if (isset($_POST["kickoff_time_set"])){
818 if ($_POST["kickoff_time_set"] == 1){
819 $this->kickoff_time_set= 1;
820 }
821 } else {
822 $this->kickoff_time_set= 0;
823 }
824 }
826 $fill= "";
827 for ($i= strlen($tmp); $i<12; $i++){
828 $fill.= " ";
829 }
831 $tmp= "[$tmp$fill]";
833 /* Only save if acl's are set */
834 if (chkacl ($this->acl, "acctFlags") == ""){
835 if ($this->samba3){
836 $attrname= "sambaAcctFlags";
837 } else {
838 $attrname= "acctFlags";
839 }
840 if ($this->$attrname != $tmp){
841 $this->is_modified= TRUE;
842 }
843 $this->$attrname= $tmp;
844 }
846 /* Save sambaDomain attribute */
847 if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
848 isset ($_POST['sambaDomainName'])){
850 $this->sambaDomainName= validate($_POST['sambaDomainName']);
851 }
853 /* Save CTX values */
854 if ($this->samba3){
855 /* Save obvious values */
856 foreach($this->ctxattributes as $val){
857 if (isset($_POST[$val]) && chkacl($this->acl, "$val") == ""){
858 if (get_magic_quotes_gpc()) {
859 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
860 } else {
861 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
862 }
863 }
864 }
866 /* Save checkbox states. */
867 if (chkacl($this->acl, "tslogin") == ""){
868 $this->mungedObject->setTsLogin(!isset($_POST['tslogin']));
869 }
870 // Need to do some index checking to avoid messages like "index ... not found"
871 if(isset($_POST['brokenconn'])) {
872 if (chkacl($this->acl, "brokenconn") == ""){
873 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1');
874 }
875 }
876 if(isset($_POST['reconn'])) {
877 if (chkacl($this->acl, "reconn") == ""){
878 $this->mungedObject->setReConn($_POST['reconn'] == '1');
879 }
880 }
881 if (chkacl($this->acl, "inherit") == "") {
882 $this->mungedObject->setInheritMode(isset($_POST['inherit']));
883 }
884 if (chkacl($this->acl, "CtxMaxConnectionTime") == "") {
885 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF']));
886 }
887 if (chkacl($this->acl, "CtxMaxDisconnectionTime") == ""){
888 $this->mungedObject->setCtxMaxDisconnectionTimeF(
889 !isset($_POST['CtxMaxDisconnectionTimeF']));
890 }
891 if (chkacl($this->acl, "CtxMaxIdleTime") == ""){
892 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF']));
893 }
894 if (chkacl($this->acl, "connectclientdrives") == ""){
895 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives']));
896 }
897 if (chkacl($this->acl, "connectclientprinters") == ""){
898 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters']));
899 }
900 if (chkacl($this->acl, "defaultprinter") == ""){
901 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter']));
902 }
904 /* Save combo boxes. Takes two values */
905 if(isset($_POST['reconn'])) {
906 $this->mungedObject->setShadow((isset($_POST['shadow'])
907 && chkacl($this->acl, "shadow") == ""), $_POST['shadow']);
908 }
910 /* Check for changes */
911 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
912 $this->is_modified= TRUE;
913 }
914 }
915 }
916 }
919 /* Save to LDAP */
920 function save()
921 {
922 /* Load uid and gid of this 'dn' */
923 $ldap= $this->config->get_ldap_link();
924 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
925 $tmp= $ldap->fetch();
926 $this->uidNumber= $tmp['uidNumber'][0];
927 $this->gidNumber= $tmp['gidNumber'][0];
929 plugin::save();
931 /* Remove objectClass for sambaIdmapEntry */
932 $tmp= array();
933 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
934 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
935 $tmp[]= $this->attrs['objectClass'][$i];
936 }
937 }
938 $this->attrs['objectClass']= $tmp;
940 /* Generate rid / primaryGroupId */
941 if ($this->samba3){
942 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
943 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
944 } else {
945 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
946 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
947 }
949 /* Need to generate a new uniqe uid/gid combination? */
950 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
951 $uidNumber= $this->uidNumber;
952 while(TRUE){
953 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
954 $ldap->cd($this->config->current['BASE']);
955 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
956 if ($ldap->count() == 0){
957 break;
958 }
959 $uidNumber++;
960 }
961 $this->attrs['sambaSID']= $sid;
963 /* Check for users primary group */
964 $ldap->cd($this->config->current['BASE']);
965 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
966 if ($ldap->count() != 1){
967 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
968 } else {
969 $attrs= $ldap->fetch();
970 $g= new group($this->config, $ldap->getDN());
971 if ($g->sambaSID == ""){
972 $g->sambaDomainName= $this->sambaDomainName;
973 $g->smbgroup= TRUE;
974 $g->save ();
975 }
976 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
977 }
978 }
980 if ($this->sambaHomeDrive == ""){
981 $this->attrs["sambaHomeDrive"]= array();
982 }
984 /* Generate munged dial value */
985 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
987 /* User wants me to fake the idMappings? This is useful for
988 making winbind resolve the user names in a reasonable amount
989 of time in combination with larger databases. */
990 if (isset($this->config->current['SAMBAIDMAPPING']) &&
991 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
992 $this->attrs['objectClass'][]= "sambaIdmapEntry";
993 }
996 /* Password expiery */
997 if ($this->password_expires == "1"){
998 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
999 } else {
1000 $this->attrs['sambaPwdMustChange']= array();
1001 }
1002 /* Make sure not to save zero in sambaPwdLastset */
1003 if ($this->sambaPwdLastSet != "0"){
1004 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1005 } else {
1006 $this->attrs['sambaPwdLastSet']= array();
1007 }
1008 /* Account expiery */
1009 if ($this->logon_time_set == "1"){
1010 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1011 } else {
1012 $this->attrs['sambaLogonTime']= array();
1013 }
1014 if ($this->logoff_time_set == "1"){
1015 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1016 } else {
1017 $this->attrs['sambaLogoffTime']= array();
1018 }
1019 if ($this->kickoff_time_set == "1"){
1020 # Add one day in unixtime format to be compatible with usrmgr
1021 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
1022 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
1023 } else {
1024 $this->attrs['sambaKickoffTime']= array();
1025 }
1026 } else {
1027 /* Not samba3 */
1028 $this->attrs['rid']= $this->uidNumber*2 + 1000;
1029 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1031 if ($this->homeDrive == ""){
1032 $this->attrs["homeDrive"]= array();
1033 }
1035 /* Password expiery */
1036 if ($this->password_expires == "1"){
1037 $this->attrs['pwdMustChange']= $this->pwdMustChange;
1038 } else {
1039 $this->attrs['pwdMustChange']= 2147483647;
1040 }
1041 /* Make sure not to save zero in pwdLastset */
1042 if ($this->pwdLastSet != "0"){
1043 $this->attrs['pwdLastSet']= $this->pwdLastSet;
1044 } else {
1045 $this->attrs['pwdLastSet']= array();
1046 }
1047 /* Account expiery */
1048 if ($this->logon_time_set == "1"){
1049 $this->attrs['logonTime']= $this->logonTime;
1050 } else {
1051 $this->attrs['logonTime']= array();
1052 }
1053 if ($this->logoff_time_set == "1"){
1054 $this->attrs['logoffTime']= $this->logoffTime;
1055 } else {
1056 $this->attrs['logoffTime']= array();
1057 }
1058 if ($this->kickoff_time_set == "1"){
1059 # Add one day in unixtime format to be compatible with usrmgr
1060 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1061 } else {
1062 $this->attrs['kickoffTime']= array();
1063 }
1064 }
1066 /* Write back to ldap */
1067 $ldap->cd($this->dn);
1068 $this->cleanup();
1069 $ldap->modify ($this->attrs);
1071 show_ldap_error($ldap->get_error(), _("Saving Samba account failed"));
1073 /* Optionally execute a command after we're done */
1074 if ($this->initially_was_account == $this->is_account){
1075 if ($this->is_modified){
1076 $this->handle_post_events("modify",array("uid" => $this->uid));
1077 }
1078 } else {
1079 $this->handle_post_events("add",array("uid" => $this->uid));
1080 }
1082 }
1084 function adapt_from_template($dn)
1085 {
1086 plugin::adapt_from_template($dn);
1087 $this->sambaSID= "";
1088 $this->sambaPrimaryGroupSID= "";
1090 /* Fill mungedDial field */
1091 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1092 $this->mungedObject->load($this->sambaMungedDial);
1093 }
1095 /* Password expiery */
1096 if(isset($this->attrs['sambaPwdMustChange']) &&
1097 $this->attrs['sambaPwdMustChange'][0] != 0){
1098 $this->password_expires= 1;
1099 }
1101 if(isset($this->attrs['sambaLogonTime']) && ! (
1102 $this->attrs['sambaLogonTime'][0] == 0 ||
1103 $this->attrs['sambaLogonTime'][0] == 2147483647
1104 )){
1105 $this->logon_time_set= 1;
1106 }
1107 if(isset($this->attrs['sambaLogoffTime']) && ! (
1108 $this->attrs['sambaLogoffTime'][0] == 0 ||
1109 $this->attrs['sambaLogoffTime'][0] == 2147483647
1110 )){
1111 $this->logoff_time_set= 1;
1112 }
1114 /* Account expiery */
1115 if(isset($this->attrs['sambaKickoffTime']) && ! (
1116 $this->attrs['sambaKickoffTime'][0] == 0 ||
1117 $this->attrs['sambaKickoffTime'][0] == 2147483647
1118 )){
1119 $this->kickoff_time_set= 1;
1120 }
1122 /* Get global filter config */
1123 if (!is_global("sambafilter")){
1124 $ui= get_userinfo();
1125 $base= get_base_from_people($ui->dn);
1126 $sambafilter= array( "depselect" => $base, "regex" => "*");
1127 register_global("sambafilter", $sambafilter);
1128 }
1129 }
1131 function PrepareForCopyPaste($source)
1132 {
1133 plugin::PrepareForCopyPaste($source);
1135 /* Set a new SID */
1136 $this->sambaSID = "";
1137 }
1138 }
1139 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1140 ?>