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";
26 var $view_logged = FALSE;
28 /* Switch for Samba version */
29 var $samba3= FALSE;
30 var $uidNumber= 65535;
31 var $gidNumber= 65535;
33 /* Samba 3 infos */
34 var $display_informations = FALSE;
36 /* Samba 2 attributes */
37 var $pwdLastSet= "0";
38 var $logonTime= "0";
39 var $logoffTime= "2147483647";
40 var $kickoffTime= "2147483647";
41 var $pwdCanChange= "0";
42 var $pwdMustChange= "0";
43 var $password_expires= 0;
44 var $acctFlags= "[UX ]";
45 var $smbHome= "";
46 var $homeDrive= "";
47 var $scriptPath= "";
48 var $profilePath= "";
49 var $rid= "";
50 var $primaryGroupID= "";
52 /* Samba 3 attributes */
53 var $SID= "";
54 var $ridBase= 0;
55 var $sambaSID= "";
56 var $sambaPwdLastSet= "0";
57 var $sambaLogonTime= "0";
58 var $sambaLogoffTime= "2147483647";
59 var $sambaKickoffTime= "2147483647";
60 var $sambaPwdCanChange= "";
61 var $sambaPwdMustChange= "0";
62 var $sambaAcctFlags= "[UX ]";
63 var $sambaHomePath= "";
64 var $sambaHomeDrive= "";
65 var $sambaLogonScript= "";
66 var $sambaProfilePath= "";
67 var $sambaPrimaryGroupSID= "";
68 var $sambaDomainName= "";
69 var $sambaUserWorkstations= "";
70 var $sambaBadPasswordCount= "";
71 var $sambaBadPasswordTime= "";
72 var $sambaPasswordHistory= "";
73 var $sambaLogonHours= "";
74 var $orig_sambaDomainName= "";
75 var $sambaMungedDial= "";
76 var $mungedObject;
78 /* Helper */
79 var $show_ws_dialog= FALSE;
80 var $logon_time_set= 0;
81 var $logoff_time_set= 0;
82 var $kickoff_time_set= 0;
84 /* attribute list for save action */
85 var $ctxattributes= array();
86 var $attributes= array();
87 var $objectclasses= array();
89 var $uid= "";
90 var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
92 var $multiple_support = TRUE;
94 /* Only used for multiple edit */
95 var $temporary_disable = FALSE;
96 var $no_password_required = FALSE;
97 var $multiple_sambaUserWorkstations = array();
99 function sambaAccount (&$config, $dn= NULL)
100 {
101 /* Load attributes depending on the samba version */
102 $this->samba3= ($config->get_cfg_value("sambaversion") == 3);
104 if ($this->samba3){
105 $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
106 "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
107 "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
108 "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
109 "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
110 "sambaUserWorkstations", "sambaPasswordHistory",
111 "sambaLogonHours", "sambaBadPasswordTime",
112 "sambaBadPasswordCount");
113 $this->objectclasses= array ("sambaSamAccount");
114 $this->mungedObject= new sambaMungedDial;
115 $this->ctxattributes= $this->mungedObject->ctxattributes;
116 } else {
117 $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
118 "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
119 "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
120 $this->objectclasses= array ("sambaAccount");
121 }
123 plugin::plugin ($config, $dn);
125 /* Setting uid to default */
126 if(isset($this->attrs['uid'][0])){
127 $this->uid = $this->attrs['uid'][0];
128 }
130 /* Get samba Domain in case of samba 3 */
131 if ($this->samba3 && $this->sambaSID != ""){
132 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
133 $ldap= $this->config->get_ldap_link();
134 $ldap->cd($this->config->current['BASE']);
135 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
136 if ($ldap->count() != 0){
137 $attrs= $ldap->fetch();
138 if(isset($attrs['sambaAlgorithmicRidBase'])){
139 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
140 } else {
141 $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
142 }
143 if ($this->sambaDomainName == ""){
144 $this->sambaDomainName= $attrs['sambaDomainName'][0];
145 }
146 } else {
147 if ($this->sambaDomainName == ""){
148 $this->sambaDomainName= "DEFAULT";
149 }
150 $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
151 $this->SID= $this->config->get_cfg_value("sambaSid");
152 }
154 /* Save in order to compare later on */
155 $this->orig_sambaDomainName= $this->sambaDomainName;
156 }
158 /* Fill mungedDial field */
159 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
160 $this->mungedObject->load($this->sambaMungedDial);
161 }
163 /* Password expiery */
164 if(isset($this->attrs['sambaPwdMustChange']) &&
165 $this->attrs['sambaPwdMustChange'][0] != 0){
166 $this->password_expires= 1;
167 }
169 if(isset($this->attrs['sambaLogonTime']) && ! (
170 $this->attrs['sambaLogonTime'][0] == 0 ||
171 $this->attrs['sambaLogonTime'][0] == 2147483647
172 )){
173 $this->logon_time_set= 1;
174 }
175 if(isset($this->attrs['sambaLogoffTime']) && ! (
176 $this->attrs['sambaLogoffTime'][0] == 0 ||
177 $this->attrs['sambaLogoffTime'][0] == 2147483647
178 )){
179 $this->logoff_time_set= 1;
180 }
182 /* Account expiery */
183 if(isset($this->attrs['sambaKickoffTime']) && ! (
184 $this->attrs['sambaKickoffTime'][0] == 0 ||
185 $this->attrs['sambaKickoffTime'][0] == 2147483647
186 )){
187 $this->kickoff_time_set= 1;
188 }
190 /* Get global filter config */
191 if (!session::is_set("sambafilter")){
192 $ui= get_userinfo();
193 $base= get_base_from_people($ui->dn);
194 $sambafilter= array( "depselect" => $base, "regex" => "*");
195 session::set("sambafilter", $sambafilter);
196 }
198 /* Save initial account state */
199 $this->initially_was_account= $this->is_account;
200 }
202 function execute()
203 {
204 /* Call parent execute */
205 plugin::execute();
207 /* Log view */
208 if($this->is_account && !$this->view_logged){
209 $this->view_logged = TRUE;
210 new log("view","users/".get_class($this),$this->dn);
211 }
213 /* Do we need to flip is_account state? */
214 if (isset($_POST['modify_state'])){
215 $this->is_account= !$this->is_account;
216 }
217 /* Do we represent a valid account? */
218 if (!$this->is_account && $this->parent === NULL){
219 $display= "<img alt=\"\"src=\"images/small-error.png\" align=\"middle\"> <b>".
220 msgPool::noValidExtension(_("Samba"))."</b>";
221 $display.= back_to_main();
222 return ($display);
223 }
225 $display ="";
226 if(!$this->multiple_support_active){
228 /* Show tab dialog headers */
229 $display= "";
230 if ($this->parent !== NULL){
231 if ($this->is_account){
232 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Samba")),
233 msgPool::featuresEnabled(_("Samba")));
234 } else {
235 $obj= $this->parent->by_object['posixAccount'];
237 /* Samba3 dependency on posix accounts are enabled
238 in the moment, because I need to rely on unique
239 uidNumbers. There'll be a better solution later
240 on. */
241 if ($obj->is_account){
242 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
243 msgPool::featuresDisabled(_("Samba")));
244 } else {
245 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
246 msgPool::featuresDisabled(_("Samba"), _("POSIX")), TRUE);
247 }
248 return ($display);
249 }
250 }
251 }
253 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
255 /* Open Samaba Logong hours dialog */
256 if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_readable("sambaLogonHours")){
257 $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
258 }
260 /* Cancel dialog */
261 if(isset($_POST['cancel_logonHours'])){
262 $this->dialog = FALSE;
263 }
265 /* Save selected logon hours */
266 if(isset($_POST['save_logonHours'])){
267 $this->dialog->save_object();
268 if($this->acl_is_writeable("sambaLogonHours")){
269 $this->sambaLogonHours = $this->dialog->save();
270 }
271 $this->dialog = FALSE;
272 }
274 /* Display dialog */
275 if((isset($this->dialog)) && (is_object($this->dialog))){
276 $this->dialog->save_object();
277 return($this->dialog->execute());
278 }
280 /* Prepare templating */
281 $smarty= get_smarty();
283 $tmp = $this->plInfo();
284 foreach($tmp['plProvidedAcls'] as $var => $rest){
285 $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
286 }
288 if(!session::is_set('edit') && !isset($this->parent)){
289 $smarty->assign("sambaLogonHoursACL","");
290 }
292 if ($this->sambaPwdMustChange=="0"){
293 $date= getdate();
294 } else {
295 $date= getdate($this->sambaPwdMustChange);
296 }
298 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
299 $sambaLogonTime_date= getdate();
300 } else {
301 $sambaLogonTime_date= getdate($this->sambaLogonTime);
302 }
304 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
305 $sambaLogoffTime_date= getdate();
306 } else {
307 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
308 }
310 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
311 $sambaKickoffTime_date= getdate();
312 } else {
313 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
314 }
316 /* Remove user workstations? */
317 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
319 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
321 if($this->multiple_support_active){
322 foreach($_POST['workstation_list'] as $name){
323 if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
324 unset($this->multiple_sambaUserWorkstations[trim($name)]);
325 }
326 }
327 }else{
328 $tmp= $this->sambaUserWorkstations;
329 foreach($_POST['workstation_list'] as $name){
330 $tmp= preg_replace("/$name/", '', $tmp);
331 $this->is_modified= TRUE;
332 }
333 $tmp= preg_replace('/,+/', ',', $tmp);
334 $this->sambaUserWorkstations= trim($tmp, ',');
335 }
336 }
337 }
339 /* Add user workstation? */
340 if (isset($_POST["add_ws"])){
341 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
342 $this->show_ws_dialog= TRUE;
343 $this->dialog= TRUE;
344 }
345 }
347 /* Add user workstation finished? */
348 if (isset($_POST["add_ws_cancel"])){
349 $this->show_ws_dialog= FALSE;
350 $this->dialog= FALSE;
351 }
353 /* Add user workstation? */
354 if (isset($_POST["add_ws_finish"])){
356 if (isset($_POST['wslist'])){
357 if($this->multiple_support_active){
358 foreach($_POST['wslist'] as $ws){
359 $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
360 }
361 }else{
362 $tmp= $this->sambaUserWorkstations;
363 foreach($_POST['wslist'] as $ws){
364 $tmp.= ",$ws";
365 }
366 $tmp= preg_replace('/,+/', ',', $tmp);
367 $this->sambaUserWorkstations= trim($tmp, ',');
368 }
369 $this->is_modified= TRUE;
371 $this->show_ws_dialog= FALSE;
372 $this->dialog= FALSE;
373 } else {
374 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
375 }
376 }
378 /* Show ws dialog */
379 if ($this->show_ws_dialog){
381 /* Save data */
382 $sambafilter= session::get("sambafilter");
383 foreach( array("depselect", "regex") as $type){
384 if (isset($_POST[$type])){
385 $sambafilter[$type]= $_POST[$type];
386 }
387 }
388 if (isset($_GET['search'])){
389 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
390 if ($s == "**"){
391 $s= "*";
392 }
393 $sambafilter['regex']= $s;
394 }
395 session::set("sambafilter", $sambafilter);
397 /* Get workstation list */
398 $exclude= "";
400 if($this->multiple_support_active){
401 foreach($this->multiple_sambaUserWorkstations as $ws){
402 if($ws['UsedByAllUsers']){
403 $exclude.= "(cn=".$ws['Name']."$)";
404 }
405 }
406 }else{
407 foreach(split(',', $this->sambaUserWorkstations) as $ws){
408 $exclude.= "(cn=$ws$)";
409 }
410 }
411 if ($exclude != ""){
412 $exclude= "(!(|$exclude))";
413 }
414 $regex= $sambafilter['regex'];
415 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
416 $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
418 $wslist= array();
419 foreach ($res as $attrs){
420 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
421 }
422 asort($wslist);
424 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
425 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
426 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
427 $smarty->assign("deplist", $this->config->idepartments);
428 $smarty->assign("alphabet", generate_alphabet());
429 foreach( array("depselect", "regex") as $type){
430 $smarty->assign("$type", $sambafilter[$type]);
431 }
432 $smarty->assign("hint", print_sizelimit_warning());
433 $smarty->assign("wslist", $wslist);
434 $smarty->assign("apply", apply_filter());
435 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
436 dirname(__FILE__)));
437 return ($display);
438 }
440 /* Fill calendar */
441 $days= array();
442 for($d= 1; $d<32; $d++){
443 $days[]= $d;
444 }
445 $years= array();
446 for($y= $date['year']-4; $y<$date['year']+4; $y++){
447 $years[]= $y;
448 }
449 $months= msgPool::months();
450 $smarty->assign("day", $date["mday"]);
451 $smarty->assign("days", $days);
452 $smarty->assign("months", $months);
453 $smarty->assign("month", $date["mon"]-1);
454 $smarty->assign("years", $years);
455 $smarty->assign("year", $date["year"]);
457 $sambaLogonTime_days= array();
458 for($d= 1; $d<32; $d++){
459 $sambaLogonTime_days[]= $d;
460 }
461 $sambaLogonTime_years= array();
462 for($y= $date['year']-4; $y<$date['year']+4; $y++){
463 $sambaLogonTime_years[]= $y;
464 }
465 $sambaLogonTime_months= msgPool::months();
466 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
467 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
468 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
469 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
470 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
471 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
473 $sambaLogoffTime_days= array();
474 for($d= 1; $d<32; $d++){
475 $sambaLogoffTime_days[]= $d;
476 }
477 $sambaLogoffTime_years= array();
478 for($y= $date['year']-4; $y<$date['year']+4; $y++){
479 $sambaLogoffTime_years[]= $y;
480 }
481 $sambaLogoffTime_months= msgPool::months();
482 $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
483 $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
484 $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
485 $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
486 $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
487 $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
489 $sambaKickoffTime_days= array();
490 for($d= 1; $d<32; $d++){
491 $sambaKickoffTime_days[]= $d;
492 }
493 $sambaKickoffTime_years= array();
494 for($y= $date['year']-4; $y<$date['year']+4; $y++){
495 $sambaKickoffTime_years[]= $y;
496 }
497 $sambaKickoffTime_months= msgPool::months();
498 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
499 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
500 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
501 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
502 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
503 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
504 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
506 /* Fill boxes */
507 if ($this->samba3){
508 $domains= array();
509 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
510 $domains[]= $name;
511 }
512 $smarty->assign("domains", $domains);
513 }
514 $letters= array("");
515 for ($i= 68; $i<91; $i++){
516 $letters[]= chr($i).":";
517 }
518 $smarty->assign("drives", $letters);
520 /* Fill terminal server settings */
521 if ($this->samba3){
522 foreach ($this->ctxattributes as $attr){
523 /* Fill common attributes */
524 if (isset($this->mungedObject->ctx[$attr])){
525 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
526 // Set field to blank if value is 0
527 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
528 if($this->mungedObject->ctx[$attr] == 0) {
529 $smarty->assign("$attr", "");
530 }
531 }
532 } else {
533 $smarty->assign("$attr", "");
534 }
535 }
537 /* Assign enum values for preset items */
538 $shadowModeVals= array( "0" => _("disabled"),
539 "1" => _("input on, notify on"),
540 "2" => _("input on, notify off"),
541 "3" => _("input off, notify on"),
542 "4" => _("input off, nofify off"));
544 $brokenConnModeVals= array( "0" => _("disconnect"),
545 "1" => _("reset"));
547 $reConnModeVals= array( "0" => _("from any client"),
548 "1" => _("from previous client only"));
550 /* Fill preset items */
551 $smarty->assign("shadow", $shadowModeVals);
552 $smarty->assign("brokenconn", $brokenConnModeVals);
553 $smarty->assign("reconn", $reConnModeVals);
555 /* Fill preset items with values */
556 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
557 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
558 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
560 if(session::get('js')){
561 /* Set form elements to disabled/enable state */
562 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
564 $smarty->assign("inheritstate", "");
565 if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
566 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
567 }
568 }else{
569 $smarty->assign("tsloginstate", "");
570 $smarty->assign("inheritstate", "");
571 }
573 /* Set checkboxes to checked or unchecked state */
574 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
575 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
576 $smarty->assign("connectclientdrives",
577 $this->mungedObject->getConnectClientDrives()?"checked":"");
578 $smarty->assign("connectclientprinters",
579 $this->mungedObject->getConnectClientPrinters()?"checked":"");
580 $smarty->assign("defaultprinter",
581 $this->mungedObject->getDefaultPrinter()?"checked":"");
582 $smarty->assign("CtxMaxConnectionTimeF",
583 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
584 $smarty->assign("CtxMaxDisconnectionTimeF",
585 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
586 $smarty->assign("CtxMaxIdleTimeF",
587 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
590 /* Fill sambaUserWorkstations */
591 $ws= split(",", $this->sambaUserWorkstations);
592 sort($ws);
594 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
595 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
597 if($this->multiple_support_active){
598 $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
599 }
601 $smarty->assign("workstations", $ws);
602 }
604 /* Variables */
605 foreach($this->attributes as $val){
606 $smarty->assign("$val", $this->$val);
607 }
609 /* 'sambaAcctFlags' checkboxes */
610 /* Check for 'lock-account'-flag: 'D' or 'L' */
611 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
612 is_integer(strpos($this->sambaAcctFlags, "L"))) {
613 $smarty->assign("flagsD", "checked");
614 } else {
615 $smarty->assign("flagsD", "");
616 }
618 /* Check for no_password_required flag 'N' */
619 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
620 $smarty->assign("flagsN", "checked");
621 } else {
622 $smarty->assign("flagsN", "");
623 }
625 if($this->samba3){
626 if ($this->sambaPwdCanChange=="1"){
627 $smarty->assign("flagsP", "checked");
628 } else {
629 $smarty->assign("flagsP", "");
630 }
631 }else{
632 if ($this->pwdCanChange=="1"){
633 $smarty->assign("flagsP", "checked");
634 } else {
635 $smarty->assign("flagsP", "");
636 }
637 }
639 if ($this->password_expires=="1"){
640 $smarty->assign("flagsC", "checked");
641 } else {
642 $smarty->assign("flagsC", "");
643 }
644 if ($this->logon_time_set=="1"){
645 $smarty->assign("flagsT", "checked");
646 } else {
647 $smarty->assign("flagsT", "");
648 }
649 if ($this->logoff_time_set=="1"){
650 $smarty->assign("flagsO", "checked");
651 } else {
652 $smarty->assign("flagsO", "");
653 }
654 if ($this->kickoff_time_set=="1"){
655 $smarty->assign("flagsK", "checked");
656 } else {
657 $smarty->assign("flagsK", "");
658 }
661 /* In case of javascript, disable some fields on demand */
662 if ($this->samba3){
663 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
664 $smarty->assign("$key", "$value");
665 }
666 }
669 foreach($this->attributes as $attr){
670 if(in_array($attr,$this->multi_boxes)){
671 $smarty->assign("use_".$attr,TRUE);
672 }else{
673 $smarty->assign("use_".$attr,FALSE);
674 }
675 }
676 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
677 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
678 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
679 "onnectclientprinters","defaultprinter","shadow","brokenconn",
680 "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
681 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
682 "workstation_list") as $attr){
683 if(in_array($attr,$this->multi_boxes)){
684 $smarty->assign("use_".$attr,TRUE);
685 }else{
686 $smarty->assign("use_".$attr,FALSE);
687 }
688 }
690 if($this->multiple_support_active){
691 $smarty->assign("tsloginstate","");
692 }
694 /* Show main page */
695 $smarty->assign("multiple_support",$this->multiple_support_active);
696 if ($this->samba3){
698 $smarty->assign("samba_informations","");
699 $smarty->assign("display_informations",$this->display_informations);
700 if($this->display_informations){
701 $smarty->assign("samba_informations",$this->get_samba_informations());
702 }
704 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
705 } else {
706 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
707 }
709 return ($display);
710 }
713 function get_samba_informations()
714 {
716 /* Defaults
717 */
718 $sambaMinPwdLength = "unset";
719 $sambaPwdHistoryLength = "unset";
720 $sambaLogonToChgPwd = "unset";
721 $sambaMaxPwdAge = "unset";
722 $sambaMinPwdAge = "unset";
723 $sambaLockoutDuration = "unset";
724 $sambaBadPasswordTime = "unset";
725 $sambaLockoutThreshold = "unset";
726 $sambaForceLogoff = "unset";
727 $sambaRefuseMachinePwdChange = "unset";
730 /* Get samba SID object and parse settings.
731 */
732 $ldap = $this->config->get_ldap_link();
733 $ldap->cd($this->config->current['BASE']);
734 if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
735 $cfg = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName];
736 $ldap->search("(&(objectClass=sambaDomain)(sambaSID=".$cfg['SID']."))",array("*"));
737 if($ldap->count() >= 1){
738 $attrs = $ldap->fetch();
739 $attributes = array("sambaMinPwdLength","sambaPwdHistoryLength","sambaMaxPwdAge","sambaMinPwdAge","sambaLockoutDuration","sambaRefuseMachinePwdChange","sambaLogonToChgPwd","sambaBadPasswordTime","sambaLockoutThreshold","sambaForceLogoff");
740 foreach($attributes as $attr){
741 if(isset($this->$attr) && $this->$attr != ""){
742 $$attr = $this->$attr;
743 }elseif(isset($this->attrs[$attr])){
744 $$attr = $this->attrs[$attr][0];
745 }elseif(isset($attrs[$attr])){
746 $$attr = $attrs[$attr][0];
747 }
748 }
749 }
750 }
752 /* Password length has a default of 5
753 */
754 if($sambaMinPwdLength == "unset" || $sambaMinPwdLength == 5){
755 $sambaMinPwdLength = "5 <i>("._("default").")</i>";
756 }
758 /* Length of Password History Entries (default: 0 => off)
759 */
760 if($sambaPwdHistoryLength == "unset" || $sambaPwdHistoryLength == 0){
761 $sambaPwdHistoryLength = _("Off")." <i>("._("default").")</i>";
762 }
764 /* Force Users to logon for password change (default: 0 => off, 2 => on)
765 */
766 if($sambaLogonToChgPwd == "unset" || $sambaLogonToChgPwd == 0){
767 $sambaLogonToChgPwd = _("Off")." <i>("._("default").")</i>";
768 }else{
769 $sambaLogonToChgPwd = _("On");
770 }
772 /* Maximum password age, in seconds (default: -1 => never expire passwords)'
773 */
774 if($sambaMaxPwdAge == "unset" || $sambaMaxPwdAge == "-1"){
775 $sambaMaxPwdAge = _("disabled")." <i>("._("default").")</i>";
776 }else{
777 $sambaMaxPwdAge .= " "._("seconds");
778 }
780 /* Minimum password age, in seconds (default: 0 => allow immediate password change
781 */
782 if($sambaMinPwdAge == "unset" || $sambaMinPwdAge == 0){
783 $sambaMinPwdAge = _("disabled")." <i>("._("default").")</i>";
784 }else{
785 $sambaMinPwdAge .= " "._("seconds");
786 }
788 /* Lockout duration in minutes (default: 30, -1 => forever)
789 */
790 if($sambaLockoutDuration == "unset" || $sambaLockoutDuration == 30){
791 $sambaLockoutDuration = "30 "._("minutes")." <i>("._("default").")</i>";
792 }elseif($sambaLockoutDuration == -1){
793 $sambaLockoutDuration = _("forever");
794 }else{
795 $sambaLockoutDuration .= _("minutes");
796 }
798 /* Time of the last bad password attempt
799 */
800 if($sambaBadPasswordTime == "none" || empty($sambaBadPasswordTime)){
801 $sambaBadPasswordTime = "<i>("._("unset").")</i>";
802 }else{
803 $sambaBadPasswordTime = date("d.m.Y H:i:s",$sambaBadPasswordTime);
804 }
806 /* Lockout users after bad logon attempts (default: 0 => off
807 */
808 if($sambaLockoutThreshold == "unset" || $sambaLockoutThreshold == 0){
809 $sambaLockoutThreshold = _("disabled")." <i>("._("default").")</i>";
810 }
812 /* Disconnect Users outside logon hours (default: -1 => off, 0 => on
813 */
814 if($sambaForceLogoff == "unset" || $sambaForceLogoff == -1){
815 $sambaForceLogoff = _("off")." <i>("._("default").")</i>";
816 }else{
817 $sambaForceLogoff = _("on");
818 }
820 /* Allow Machine Password changes (default: 0 => off
821 */
822 if($sambaRefuseMachinePwdChange == "none" || $sambaRefuseMachinePwdChange == 0){
823 $sambaRefuseMachinePwdChange = _("off")." <i>("._("default").")</i>";
824 }else{
825 $sambaRefuseMachinePwdChange = _("on");
826 }
829 $str =
830 "\n<table>".
831 "\n<tr><td>"._("Min password length").": </td><td>".$sambaMinPwdLength."</td></tr>".
832 "\n<tr><td>"._("Password history").": </td><td>".$sambaPwdHistoryLength."</td></tr>".
833 "\n<tr><td>"._("Force password change").": </td><td>".$sambaLogonToChgPwd."</td></tr>".
834 "\n<tr><td>"._("Maximum password age").": </td><td>".$sambaMaxPwdAge."</td></tr>".
835 "\n<tr><td>"._("Minimum password age").": </td><td>".$sambaMinPwdAge."</td></tr>".
836 "\n<tr><td>"._("Lockout duration").": </td><td>".$sambaLockoutDuration."</td></tr>".
837 "\n<tr><td>"._("Reset count minutes").": </td><td>".$sambaBadPasswordTime."</td></tr>".
838 "\n<tr><td>"._("Bad lockout attempt").": </td><td>".$sambaLockoutThreshold."</td></tr>".
839 "\n<tr><td>"._("Disconnect time").": </td><td>".$sambaForceLogoff."</td></tr>".
840 "\n<tr><td>"._("Refuse machine password change").":</td><td>".$sambaRefuseMachinePwdChange."</td></tr>".
841 "\n</table>";
842 return($str);
843 }
846 function remove_from_parent()
847 {
848 /* Cancel if there's nothing to do here */
849 if (!$this->initially_was_account){
850 return;
851 }
853 /* include global link_info */
854 $ldap= $this->config->get_ldap_link();
856 plugin::remove_from_parent();
858 /* Keep uid attribute for gosaAccount */
859 unset($this->attrs['uid']);
860 unset($this->attrs['uidNumber']);
861 unset($this->attrs['gidNumber']);
863 /* Remove objectClass for sambaIdmapEntry */
864 $tmp= array();
865 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
866 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
867 $tmp[]= $this->attrs['objectClass'][$i];
868 }
869 }
870 $this->attrs['objectClass']= $tmp;
872 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
873 $this->attributes, "Save");
874 $ldap->cd($this->dn);
875 $this->cleanup();
876 $ldap->modify ($this->attrs);
878 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
880 if (!$ldap->success()){
881 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
882 }
884 /* Optionally execute a command after we're done */
885 $this->handle_post_events("remove", array("uid" => $this->uid));
886 }
889 /* Check for input problems */
890 function check()
891 {
892 /* Call common method to give check the hook */
893 $message= plugin::check();
895 if ($this->samba3){
897 /* sambaHomePath requires sambaHomeDrive and vice versa */
898 if(!empty($this->sambaHomePath) && empty($this->sambaHomeDrive)){
899 $message[]= msgPool::required(_("Home drive"));
900 }
901 if(!empty($this->sambaHomeDrive) && empty($this->sambaHomePath)){
902 $message[]= msgPool::required(_("Home path"));
903 }
905 /* Strings */
906 foreach (array( "sambaHomePath" => _("Home directory"),
907 "sambaProfilePath" => _("Profile path")) as $key => $val){
908 if (!$this->mungedObject->is_samba_path($this->$key)){
909 $message[]= msgPool::invalid($val);
910 }
911 }
913 /* Numeric values */
914 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
915 "CtxMaxDisconnectionTime" => _("Disconnection"),
916 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
918 if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
919 $message[]= msgPool::invalid($val);
920 }
921 }
923 /* Too many workstations? Windows usrmgr only supports eight */
924 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
925 $message[]= _("The windows usermanager allows eight clients at maximum!");
926 }
927 }
929 return ($message);
930 }
933 /* Save data to object */
934 function save_object()
935 {
937 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
939 /* We only care if we are on the sambaTab... */
940 if (isset($_POST['sambaTab'])){
941 plugin::save_object();
943 if(isset($_POST['display_informations'])){
944 $this->display_informations = !$this->display_informations;
945 }
947 /* Take care about access options */
948 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
949 if ($this->samba3){
950 $attrname= "sambaPwdCanChange";
951 } else {
952 $attrname= "pwdCanChange";
953 }
954 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
955 $tmp= 1;
956 } else {
957 $tmp= 0;
958 }
959 if ($this->$attrname != $tmp){
960 $this->is_modified= TRUE;
961 }
962 $this->pwdCanChange= $tmp;
963 $this->sambaPwdCanChange= $tmp;
964 }
965 $tmp= "UX";
966 $this->no_password_required = FALSE;
967 if (isset($_POST["no_password_required"])){
968 if ($_POST["no_password_required"] == 1){
969 $tmp.= "N";
970 $this->no_password_required = TRUE;
971 }
972 }
973 if (isset($_POST["password_expires"])){
974 if ($_POST["password_expires"] == 1){
975 $this->password_expires= 1;
976 }
977 } else {
978 $this->password_expires= 0;
979 }
980 $this->temporary_disable = FALSE;
981 if (isset($_POST["temporary_disable"])){
982 if ($_POST["temporary_disable"] == 1){
983 $this->temporary_disable = TRUE;
984 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
985 $tmp.= "L";
986 } else {
987 $tmp.= "D";
988 }
989 }
990 }
991 if (isset($_POST["logon_time_set"])){
992 if ($_POST["logon_time_set"] == 1){
993 $this->logon_time_set= 1;
994 }
995 } else {
996 $this->logon_time_set= 0;
997 }
998 if (isset($_POST["logoff_time_set"])){
999 if ($_POST["logoff_time_set"] == 1){
1000 $this->logoff_time_set= 1;
1001 }
1002 } else {
1003 $this->logoff_time_set= 0;
1004 }
1005 if (isset($_POST["kickoff_time_set"])){
1006 if ($_POST["kickoff_time_set"] == 1){
1007 $this->kickoff_time_set= 1;
1008 }
1009 } else {
1010 $this->kickoff_time_set= 0;
1011 }
1013 $fill= "";
1014 for ($i= strlen($tmp); $i<12; $i++){
1015 $fill.= " ";
1016 }
1018 $tmp= "[$tmp$fill]";
1020 /* Only save if acl's are set */
1021 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1022 if ($this->samba3){
1023 $attrname= "sambaAcctFlags";
1024 } else {
1025 $attrname= "acctFlags";
1026 }
1027 if ($this->$attrname != $tmp){
1028 $this->is_modified= TRUE;
1029 }
1030 $this->$attrname= $tmp;
1031 }
1033 /* Save sambaDomain attribute */
1034 if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
1035 $this->sambaDomainName= validate($_POST['sambaDomainName']);
1036 }
1038 /* Save CTX values */
1039 if ($this->samba3){
1041 /* Save obvious values */
1042 foreach($this->ctxattributes as $val){
1043 if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
1044 if (get_magic_quotes_gpc()) {
1045 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
1046 } else {
1047 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
1048 }
1049 }
1050 }
1052 /* Save checkbox states. */
1053 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
1054 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1055 // Need to do some index checking to avoid messages like "index ... not found"
1056 if(isset($_POST['brokenconn'])) {
1057 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
1058 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1059 }
1060 if(isset($_POST['reconn'])) {
1061 $this->mungedObject->setReConn($_POST['reconn'] == '1'
1062 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1063 }
1064 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
1065 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1066 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
1067 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1068 $this->mungedObject->setCtxMaxDisconnectionTimeF(
1069 !isset($_POST['CtxMaxDisconnectionTimeF'])
1070 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1071 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
1072 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1073 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
1074 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1075 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
1076 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1077 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
1078 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1080 /* Save combo boxes. Takes two values */
1081 if(isset($_POST['reconn'])) {
1082 $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
1083 }
1085 /* Check for changes */
1086 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
1087 $this->is_modified= TRUE;
1088 }
1089 }
1090 }
1091 }
1094 /* Save to LDAP */
1095 function save()
1096 {
1097 /* Load uid and gid of this 'dn' */
1098 $ldap= $this->config->get_ldap_link();
1099 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
1100 $tmp= $ldap->fetch();
1101 $this->uidNumber= $tmp['uidNumber'][0];
1102 $this->gidNumber= $tmp['gidNumber'][0];
1104 plugin::save();
1106 /* Remove objectClass for sambaIdmapEntry */
1107 $tmp= array();
1108 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1109 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1110 $tmp[]= $this->attrs['objectClass'][$i];
1111 }
1112 }
1113 $this->attrs['objectClass']= $tmp;
1115 /* Generate rid / primaryGroupId */
1116 if ($this->samba3){
1117 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
1118 msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
1119 } else {
1120 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
1121 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
1122 }
1124 /* Need to generate a new uniqe uid/gid combination? */
1125 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
1126 $uidNumber= $this->uidNumber;
1127 while(TRUE){
1128 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
1129 $ldap->cd($this->config->current['BASE']);
1130 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
1131 if ($ldap->count() == 0){
1132 break;
1133 }
1134 $uidNumber++;
1135 }
1136 $this->attrs['sambaSID']= $sid;
1138 /* Check for users primary group */
1139 $ldap->cd($this->config->current['BASE']);
1140 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
1141 if ($ldap->count() != 1){
1142 msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
1143 } else {
1144 $attrs= $ldap->fetch();
1145 $g= new group($this->config, $ldap->getDN());
1146 if ($g->sambaSID == ""){
1147 $g->sambaDomainName= $this->sambaDomainName;
1148 $g->smbgroup= TRUE;
1149 $g->save ();
1150 }
1151 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
1152 }
1153 }
1155 if ($this->sambaHomeDrive == ""){
1156 $this->attrs["sambaHomeDrive"]= array();
1157 }
1159 /* Generate munged dial value */
1160 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1162 /* User wants me to fake the idMappings? This is useful for
1163 making winbind resolve the user names in a reasonable amount
1164 of time in combination with larger databases. */
1165 if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1166 $this->attrs['objectClass'][]= "sambaIdmapEntry";
1167 }
1170 /* Password expiery */
1171 if ($this->password_expires == "1"){
1172 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1173 } else {
1174 $this->attrs['sambaPwdMustChange']= array();
1175 }
1176 /* Make sure not to save zero in sambaPwdLastset */
1177 if ($this->sambaPwdLastSet != "0"){
1178 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1179 } else {
1180 $this->attrs['sambaPwdLastSet']= array();
1181 }
1182 /* Account expiery */
1183 if ($this->logon_time_set == "1"){
1184 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1185 } else {
1186 $this->attrs['sambaLogonTime']= array();
1187 }
1188 if ($this->logoff_time_set == "1"){
1189 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1190 } else {
1191 $this->attrs['sambaLogoffTime']= array();
1192 }
1193 if ($this->kickoff_time_set == "1"){
1194 # Add one day in unixtime format to be compatible with usrmgr
1195 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
1196 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
1197 } else {
1198 $this->attrs['sambaKickoffTime']= array();
1199 }
1200 } else {
1201 /* Not samba3 */
1202 $this->attrs['rid']= $this->uidNumber*2 + 1000;
1203 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1205 if ($this->homeDrive == ""){
1206 $this->attrs["homeDrive"]= array();
1207 }
1209 /* Password expiery */
1210 if ($this->password_expires == "1"){
1211 $this->attrs['pwdMustChange']= $this->pwdMustChange;
1212 } else {
1213 $this->attrs['pwdMustChange']= 2147483647;
1214 }
1215 /* Make sure not to save zero in pwdLastset */
1216 if ($this->pwdLastSet != "0"){
1217 $this->attrs['pwdLastSet']= $this->pwdLastSet;
1218 } else {
1219 $this->attrs['pwdLastSet']= array();
1220 }
1221 /* Account expiery */
1222 if ($this->logon_time_set == "1"){
1223 $this->attrs['logonTime']= $this->logonTime;
1224 } else {
1225 $this->attrs['logonTime']= array();
1226 }
1227 if ($this->logoff_time_set == "1"){
1228 $this->attrs['logoffTime']= $this->logoffTime;
1229 } else {
1230 $this->attrs['logoffTime']= array();
1231 }
1232 if ($this->kickoff_time_set == "1"){
1233 # Add one day in unixtime format to be compatible with usrmgr
1234 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1235 } else {
1236 $this->attrs['kickoffTime']= array();
1237 }
1238 }
1240 /* Write back to ldap */
1241 $ldap->cd($this->dn);
1242 $this->cleanup();
1243 $ldap->modify ($this->attrs);
1245 if($this->initially_was_account){
1246 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1247 }else{
1248 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1249 }
1251 if (!$ldap->success()){
1252 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1253 }
1255 /* Optionally execute a command after we're done */
1256 if ($this->initially_was_account == $this->is_account){
1257 if ($this->is_modified){
1258 $this->handle_post_events("modify", array("uid" => $this->uid));
1259 }
1260 } else {
1261 $this->handle_post_events("add", array("uid" => $this->uid));
1262 }
1263 }
1266 /* Force password set, if this account doesn't have any samba passwords */
1267 function password_change_needed()
1268 {
1269 if(!$this->initially_was_account && $this->is_account){
1270 $ldap = $this->config->get_ldap_link();
1271 $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1272 $attrs = $ldap->fetch();
1273 if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1274 return(TRUE);
1275 }
1276 }
1277 return(FALSE);
1278 }
1281 function adapt_from_template($dn, $skip= array())
1282 {
1283 plugin::adapt_from_template($dn, $skip);
1286 $this->sambaSID= "";
1287 $this->sambaPrimaryGroupSID= "";
1289 /* Fill mungedDial field */
1290 if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1291 $this->mungedObject->load($this->sambaMungedDial);
1292 }
1294 /* Adapt munged attributes */
1295 foreach($this->ctxattributes as $attr){
1296 if(isset($this->mungedObject->ctx[$attr]))
1297 $val = $this->mungedObject->ctx[$attr];
1299 foreach (array("sn", "givenName", "uid") as $repl){
1300 if (preg_match("/%$repl/i", $val)){
1301 $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1302 }
1303 }
1304 $this->mungedObject->ctx[$attr] = $val;
1305 }
1307 /* Password expiery */
1308 if(isset($this->attrs['sambaPwdMustChange']) &&
1309 $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1310 $this->password_expires= 1;
1311 }
1313 if(isset($this->attrs['sambaLogonTime']) && ! (
1314 $this->attrs['sambaLogonTime'][0] == 0 ||
1315 $this->attrs['sambaLogonTime'][0] == 2147483647
1316 ) && !in_array('sambaLogonTime', $skip)){
1317 $this->logon_time_set= 1;
1318 }
1319 if(isset($this->attrs['sambaLogoffTime']) && ! (
1320 $this->attrs['sambaLogoffTime'][0] == 0 ||
1321 $this->attrs['sambaLogoffTime'][0] == 2147483647
1322 ) && !in_array('sambaLogonTime', $skip)){
1323 $this->logoff_time_set= 1;
1324 }
1326 /* Account expiery */
1327 if(isset($this->attrs['sambaKickoffTime']) && ! (
1328 $this->attrs['sambaKickoffTime'][0] == 0 ||
1329 $this->attrs['sambaKickoffTime'][0] == 2147483647
1330 ) && !in_array('sambaKickoffTime', $skip)){
1331 $this->kickoff_time_set= 1;
1332 }
1334 /* Get global filter config */
1335 if (!session::is_set("sambafilter")){
1336 $ui= get_userinfo();
1337 $base= get_base_from_people($ui->dn);
1338 $sambafilter= array( "depselect" => $base, "regex" => "*");
1339 session::set("sambafilter", $sambafilter);
1340 }
1341 }
1344 static function plInfo()
1345 {
1346 return (array(
1347 "plShortName" => _("Samba"),
1348 "plDescription" => _("Samba settings"),
1349 "plSelfModify" => TRUE,
1350 "plDepends" => array("user"),
1351 "plPriority" => 5,
1352 "plSection" => array("personal" => _("My account")),
1353 "plCategory" => array("users"),
1354 "plOptions" => array(),
1356 "plProvidedAcls" => array(
1358 "sambaHomePath" => _("Generic home directory") ,
1359 "sambaHomeDrive" => _("Generic samba home drive") ,
1360 "sambaDomainName" => _("Domain") ,
1361 "sambaLogonScript" => _("Generic script path") ,
1362 "sambaProfilePath" => _("Generic profile path") ,
1363 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1364 "InheritClientConfig" => _("Inherit client config"),
1365 "sambaPwdCanChange" => _("Allow user to change password") ,
1366 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1367 "sambaAcctFlagsL" => _("Lock samba account"),
1368 "sambaKickoffTime" => _("Account expires") ,
1369 "sambaPwdMustChange" => _("Password expires") ,
1370 "sambaLogonTime" => _("Limit Logon Time") ,
1371 "sambaLogoffTime" => _("Limit Logoff Time") ,
1372 "sambaLogonHours" => _("Logon hours") ,
1373 "sambaUserWorkstations" => _("Allow connection from"))
1374 ));
1375 }
1377 function enable_multiple_support()
1378 {
1379 plugin::enable_multiple_support();
1380 if($this->samba3){
1381 $this->multiple_support_active = TRUE;
1382 }else{
1383 $this->multiple_support_active = FALSE;
1384 }
1385 }
1387 function multiple_save_object()
1388 {
1389 if (isset($_POST['sambaTab'])){
1390 $this->save_object();
1391 plugin::multiple_save_object();
1392 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1393 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1394 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1395 "onnectclientprinters","defaultprinter","shadow","brokenconn",
1396 "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1397 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1398 "workstation_list") as $attr){
1399 if(isset($_POST["use_".$attr])){
1400 $this->multi_boxes[] = $attr;
1401 }
1402 }
1403 }
1404 }
1407 function multiple_check()
1408 {
1409 $message = plugin::multiple_check();
1411 /* Strings */
1412 foreach (array( "sambaHomePath" => _("Home directory"),
1413 "sambaProfilePath" => _("Profile path")) as $key => $val){
1414 if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1415 $message[]= msgPool::invalid($val);
1416 }
1417 }
1419 /* Numeric values */
1420 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
1421 "CtxMaxDisconnectionTime" => _("Disconnection"),
1422 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
1423 if (in_array($key,$this->multi_boxes) &&
1424 isset($this->mungedObject->ctx[$key]) &&
1425 !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1426 $message[]=msgPool::invalid($val);
1427 }
1428 }
1430 /* Too many workstations? Windows usrmgr only supports eight */
1431 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1432 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1433 }
1434 return($message);
1435 }
1438 function get_multi_init_values()
1439 {
1440 $ret = plugin::get_multi_init_values();
1442 /* Parse given sambaUserWorkstations into array
1443 * to allow "init_multiple_support()" to detect multiple used workstations.
1444 * Those workstations will be displayed in light grey.
1445 */
1446 $tmp2 = array("count" => 0);
1447 $tmp = split(",", $this->sambaUserWorkstations);
1448 foreach($tmp as $station){
1449 $station = trim($station);
1450 if(!empty($station)){
1451 $tmp2[] = $station;
1452 $tmp2['count'] ++;
1453 }
1454 }
1455 $ret['sambaUserWorkstations'] = $tmp2;
1456 return($ret);
1457 }
1461 function init_multiple_support($attrs,$all)
1462 {
1463 plugin::init_multiple_support($attrs,$all);
1465 $this->multiple_sambaUserWorkstations = array();
1466 if(isset($all['sambaUserWorkstations'])){
1467 for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1468 $station = trim($all['sambaUserWorkstations'][$i]);
1469 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1470 }
1471 }
1472 if(isset($attrs['sambaUserWorkstations'])){
1473 for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1474 $station = trim($attrs['sambaUserWorkstations'][$i]);
1475 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1476 }
1477 }
1478 }
1480 function multiple_execute()
1481 {
1482 return($this->execute());
1483 }
1485 function get_multi_edit_values()
1486 {
1487 $ret = plugin::get_multi_edit_values();
1489 /* Terminal Server */
1490 if(in_array("tslogin",$this->multi_boxes)){
1491 $ret['tslogin'] = $this->mungedObject->getTsLogin();
1492 }
1493 if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1494 $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1495 }
1496 if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1497 $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1498 }
1499 if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1500 $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1501 }
1503 if(in_array("inherit",$this->multi_boxes)){
1504 $ret['inherit'] = $this->mungedObject->getInheritMode();
1505 }
1506 if(in_array("CtxInitialProgram",$this->multi_boxes)){
1507 $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1508 }
1509 if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1510 $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1511 }
1513 /* Time Limits. Be careful here, there are some negations */
1514 if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1515 $ret["CtxMaxConnectionTimeF"] = !$this->mungedObject->getCtxMaxConnectionTimeF();
1516 if(!$ret["CtxMaxConnectionTimeF"]){
1517 $ret["CtxMaxConnectionTime"] = $this->mungedObject->ctx['CtxMaxConnectionTime'];
1518 }
1519 }
1520 if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1521 $ret["CtxMaxDisconnectionTimeF"]= !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1522 if(!$ret["CtxMaxDisconnectionTimeF"]){
1523 $ret["CtxMaxDisconnectionTime"]= $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1524 }
1525 }
1526 if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1527 $ret["CtxMaxIdleTimeF"] = !$this->mungedObject->getCtxMaxIdleTimeF();
1528 if(!$ret["CtxMaxIdleTimeF"]){
1529 $ret["CtxMaxIdleTime"] = $this->mungedObject->ctx['CtxMaxIdleTime'];
1530 }
1531 }
1533 /* Client Devices */
1534 if(in_array("connectclientdrives",$this->multi_boxes)){
1535 $ret["connectclientdrives"] = $this->mungedObject->getConnectClientDrives();
1536 }
1537 if(in_array("connectclientprinters",$this->multi_boxes)){
1538 $ret["connectclientprinters"] = $this->mungedObject->getConnectClientPrinters();
1539 }
1540 if(in_array("defaultprinter",$this->multi_boxes)){
1541 $ret["defaultprinter"] = $this->mungedObject->getDefaultPrinter();
1542 }
1544 /* Misc */
1545 if(in_array("shadow",$this->multi_boxes)){
1546 $ret["shadow"] =$this->mungedObject->getShadow();
1547 }
1548 if(in_array("brokenconn",$this->multi_boxes)){
1549 $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1550 }
1551 if(in_array("reconn",$this->multi_boxes)){
1552 $ret["reconn"] =$this->mungedObject->getReConn();
1553 }
1555 /* Flags */
1556 if(in_array("allow_pwchange",$this->multi_boxes)){
1557 $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1558 $ret['pwdCanChange'] = $this->pwdCanChange;
1559 }
1561 if(in_array("password_expires",$this->multi_boxes)){
1562 $ret['password_expires'] = $this->password_expires;
1563 $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1564 }
1565 if(in_array("logon_time_set",$this->multi_boxes)){
1566 $ret['logon_time_set'] = $this->logon_time_set;
1567 $ret['sambaLogonTime'] = $this->sambaLogonTime;
1568 }
1569 if(in_array("logoff_time_set",$this->multi_boxes)){
1570 $ret['logoff_time_set'] = $this->logoff_time_set;
1571 $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1572 }
1573 if(in_array("kickoff_time_set",$this->multi_boxes)){
1574 $ret['kickoff_time_set'] = $this->kickoff_time_set;
1575 $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1576 }
1578 if(in_array("no_password_required",$this->multi_boxes)){
1579 $ret['no_password_required'] = $this->no_password_required;
1580 }
1582 if(in_array("temporary_disable",$this->multi_boxes)){
1583 $ret['temporary_disable'] = $this->temporary_disable;
1584 }
1586 if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1587 $ret['sambaLogonHours'] = $this->sambaLogonHours;
1588 }
1590 if(in_array("workstation_list",$this->multi_boxes)){
1591 $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1592 }
1593 return($ret);
1594 }
1596 function set_multi_edit_values($values)
1597 {
1598 plugin::set_multi_edit_values($values);
1600 /* Prepare current workstation settings to be merged
1601 * with multiple edit settings.
1602 */
1603 if(isset($values['multiple_sambaUserWorkstations'])){
1604 $cur_ws = array();
1605 $m_ws = $values['multiple_sambaUserWorkstations'];
1607 /* Prepare current settings to be merged */
1608 if(isset($this->sambaUserWorkstations)){
1609 $ttmp = split(",",$this->sambaUserWorkstations);
1610 foreach($ttmp as $station){
1611 $station = trim($station);
1612 if(!empty($station)){
1613 $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1614 }
1615 }
1616 }
1618 /* Unset removed workstations */
1619 foreach($cur_ws as $cur_name => $cur_station){
1620 if(!isset($m_ws[$cur_name])){
1621 unset($cur_ws[$cur_name]);
1622 }
1623 }
1625 /* Add all added workstations */
1626 foreach($m_ws as $name => $station){
1627 if($station['UsedByAllUsers']){
1628 $cur_ws[$name] = $station;
1629 }
1630 }
1632 $this->sambaUserWorkstations = "";
1633 foreach($cur_ws as $name => $ws){
1634 $this->sambaUserWorkstations .= $name.",";
1635 }
1636 $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1637 }
1639 /* Enable disabled terminal login, this is inverted somehow */
1640 if(isset($values['tslogin'])) $this->mungedObject->setTsLogin(!$values['tslogin']);
1642 /* Imherit client configuration */
1643 if(isset($values['inherit'])) $this->mungedObject->setInheritMode($values['inherit']);
1645 /* Get all ctx values posted */
1646 $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1647 "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1648 foreach($ctx as $attr){
1649 if(isset($values[$attr])){
1650 $this->mungedObject->ctx[$attr] = $values[$attr] ;
1651 }
1652 }
1654 if(isset($values['CtxMaxConnectionTimeF'])) $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1655 if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1656 if(isset($values['CtxMaxIdleTimeF'])) $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1658 if(isset($values['connectclientdrives'])) $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1659 if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1660 if(isset($values['defaultprinter'])) $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1662 if(isset($values['shadow'])) $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1663 if(isset($values['brokenconn'])) $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1664 if(isset($values['reconn'])) $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1667 if(isset($values['sambaPwdCanChange'])) $this->sambaPwdCanChange = $values['sambaPwdCanChange'];
1668 if(isset($values['pwdCanChange'])) $this->pwdCanChange = $values['pwdCanChange'];
1673 if(isset($values['password_expires'])){
1674 $this->password_expires = $values['password_expires'];
1675 $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1676 }
1677 if(isset($values['logon_time_set'])){
1678 $this->logon_time_set = $values['logon_time_set'];
1679 $this->sambaLogonTime = $values['sambaLogonTime'];
1680 }
1681 if(isset($values['logoff_time_set'])){
1682 $this->logoff_time_set = $values['logoff_time_set'];
1683 $this->sambaLogoffTime = $values['sambaLogoffTime'];
1684 }
1685 if(isset($values['kickoff_time_set'])){
1686 $this->kickoff_time_set = $values['kickoff_time_set'];
1687 $this->sambaKickoffTime = $values['sambaKickoffTime'];
1688 }
1690 if(isset($values['no_password_required'])){
1691 if($values['no_password_required']){
1692 if(!preg_match("/N/",$this->sambaAcctFlags)) {
1693 $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1694 }
1695 }else{
1696 $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1697 }
1698 }
1700 if(isset($values['temporary_disable'])){
1701 if($values['temporary_disable']){
1702 if(preg_match("/L/",$this->sambaAcctFlags)) {
1703 // Keep L
1704 }else{
1705 $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1706 }
1707 }else{
1708 $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1709 }
1710 }
1711 }
1714 function PrepareForCopyPaste($source)
1715 {
1716 plugin::PrepareForCopyPaste($source);
1718 /* Set a new SID */
1719 $this->sambaSID = "";
1720 }
1722 }
1724 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1725 ?>