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 2 attributes */
34 var $pwdLastSet= "0";
35 var $logonTime= "0";
36 var $logoffTime= "2147483647";
37 var $kickoffTime= "2147483647";
38 var $pwdCanChange= "0";
39 var $pwdMustChange= "0";
40 var $password_expires= 0;
41 var $acctFlags= "[UX ]";
42 var $smbHome= "";
43 var $homeDrive= "";
44 var $scriptPath= "";
45 var $profilePath= "";
46 var $rid= "";
47 var $primaryGroupID= "";
49 /* Samba 3 attributes */
50 var $SID= "";
51 var $ridBase= 0;
52 var $sambaSID= "";
53 var $sambaPwdLastSet= "0";
54 var $sambaLogonTime= "0";
55 var $sambaLogoffTime= "2147483647";
56 var $sambaKickoffTime= "2147483647";
57 var $sambaPwdCanChange= "";
58 var $sambaPwdMustChange= "0";
59 var $sambaAcctFlags= "[UX ]";
60 var $sambaHomePath= "";
61 var $sambaHomeDrive= "";
62 var $sambaLogonScript= "";
63 var $sambaProfilePath= "";
64 var $sambaPrimaryGroupSID= "";
65 var $sambaDomainName= "";
66 var $sambaUserWorkstations= "";
67 var $sambaBadPasswordCount= "";
68 var $sambaBadPasswordTime= "";
69 var $sambaPasswordHistory= "";
70 var $sambaLogonHours= "";
71 var $orig_sambaDomainName= "";
72 var $sambaMungedDial= "";
73 var $mungedObject;
75 /* Helper */
76 var $cache = array();
77 var $show_ws_dialog= FALSE;
78 var $logon_time_set= 0;
79 var $logoff_time_set= 0;
80 var $kickoff_time_set= 0;
82 /* attribute list for save action */
83 var $ctxattributes= array();
84 var $attributes= array();
85 var $objectclasses= array();
87 var $uid= "";
88 var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
90 var $multiple_support = TRUE;
92 /* Only used for multiple edit */
93 var $temporary_disable = FALSE;
94 var $no_password_required = FALSE;
95 var $no_expiry = FALSE;
96 var $multiple_sambaUserWorkstations = array();
98 function sambaAccount (&$config, $dn= NULL)
99 {
100 /* Load attributes depending on the samba version */
101 $this->samba3= ($config->get_cfg_value("sambaversion") == 3);
103 if ($this->samba3){
104 $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
105 "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
106 "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
107 "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
108 "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
109 "sambaUserWorkstations", "sambaPasswordHistory",
110 "sambaLogonHours", "sambaBadPasswordTime",
111 "sambaBadPasswordCount");
112 $this->objectclasses= array ("sambaSamAccount");
113 $this->mungedObject= new sambaMungedDial;
114 $this->ctxattributes= $this->mungedObject->ctxattributes;
115 } else {
116 $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
117 "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
118 "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
119 $this->objectclasses= array ("sambaAccount");
120 }
122 plugin::plugin ($config, $dn);
124 /* Setting uid to default */
125 if(isset($this->attrs['uid'][0])){
126 $this->uid = $this->attrs['uid'][0];
127 }
129 /* Get samba Domain in case of samba 3 */
130 if ($this->samba3 && $this->sambaSID != ""){
131 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
132 $ldap= $this->config->get_ldap_link();
133 $ldap->cd($this->config->current['BASE']);
134 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
135 if ($ldap->count() != 0){
136 $attrs= $ldap->fetch();
137 if(isset($attrs['sambaAlgorithmicRidBase'])){
138 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
139 } else {
140 $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
141 }
142 if ($this->sambaDomainName == ""){
143 $this->sambaDomainName= $attrs['sambaDomainName'][0];
144 }
145 } else {
146 if ($this->sambaDomainName == ""){
147 $this->sambaDomainName= "DEFAULT";
148 }
149 $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
150 $this->SID= $this->config->get_cfg_value("sambaSid");
151 }
153 /* Save in order to compare later on */
154 $this->orig_sambaDomainName= $this->sambaDomainName;
155 }
157 /* Fill mungedDial field */
158 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
159 $this->mungedObject->load($this->sambaMungedDial);
160 }
162 /* Password expiery */
163 if(isset($this->attrs['sambaPwdMustChange']) &&
164 $this->attrs['sambaPwdMustChange'][0] != 0){
165 $this->password_expires= 1;
166 }
168 if(isset($this->attrs['sambaLogonTime']) && ! (
169 $this->attrs['sambaLogonTime'][0] == 0 ||
170 $this->attrs['sambaLogonTime'][0] == 2147483647
171 )){
172 $this->logon_time_set= 1;
173 }
174 if(isset($this->attrs['sambaLogoffTime']) && ! (
175 $this->attrs['sambaLogoffTime'][0] == 0 ||
176 $this->attrs['sambaLogoffTime'][0] == 2147483647
177 )){
178 $this->logoff_time_set= 1;
179 }
181 /* Account expiery */
182 if(isset($this->attrs['sambaKickoffTime']) && ! (
183 $this->attrs['sambaKickoffTime'][0] == 0 ||
184 $this->attrs['sambaKickoffTime'][0] == 2147483647
185 )){
186 $this->kickoff_time_set= 1;
187 }
189 /* Get global filter config */
190 if (!session::is_set("sambafilter")){
191 $ui= get_userinfo();
192 $base= get_base_from_people($ui->dn);
193 $sambafilter= array( "depselect" => $base, "regex" => "*");
194 session::set("sambafilter", $sambafilter);
195 }
197 /* Save initial account state */
198 $this->initially_was_account= $this->is_account;
199 }
201 function execute()
202 {
203 /* Call parent execute */
204 plugin::execute();
206 /* Log view */
207 if($this->is_account && !$this->view_logged){
208 $this->view_logged = TRUE;
209 new log("view","users/".get_class($this),$this->dn);
210 }
212 /* Do we need to flip is_account state? */
213 if (isset($_POST['modify_state'])){
214 $this->is_account= !$this->is_account;
215 }
216 /* Do we represent a valid account? */
217 if (!$this->is_account && $this->parent === NULL){
218 $display= "<img alt=\"\"src=\"images/small-error.png\" align=\"middle\"> <b>".
219 msgPool::noValidExtension(_("Samba"))."</b>";
220 $display.= back_to_main();
221 return ($display);
222 }
224 $display ="";
225 if(!$this->multiple_support_active){
227 /* Show tab dialog headers */
228 $display= "";
229 if ($this->parent !== NULL){
230 if ($this->is_account){
231 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Samba")),
232 msgPool::featuresEnabled(_("Samba")));
233 } else {
234 $obj= $this->parent->by_object['posixAccount'];
236 /* Samba3 dependency on posix accounts are enabled
237 in the moment, because I need to rely on unique
238 uidNumbers. There'll be a better solution later
239 on. */
240 if ($obj->is_account){
241 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
242 msgPool::featuresDisabled(_("Samba")));
243 } else {
244 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
245 msgPool::featuresDisabled(_("Samba"), _("POSIX")), TRUE);
246 }
247 return ($display);
248 }
249 }
250 }
252 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
254 /* Open Samaba Logong hours dialog */
255 if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_readable("sambaLogonHours")){
256 $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
257 }
259 /* Cancel dialog */
260 if(isset($_POST['cancel_logonHours'])){
261 $this->dialog = FALSE;
262 }
264 /* Save selected logon hours */
265 if(isset($_POST['save_logonHours'])){
266 $this->dialog->save_object();
267 if($this->acl_is_writeable("sambaLogonHours")){
268 $this->sambaLogonHours = $this->dialog->save();
269 }
270 $this->dialog = FALSE;
271 }
273 /* Display dialog */
274 if((isset($this->dialog)) && (is_object($this->dialog))){
275 $this->dialog->save_object();
276 return($this->dialog->execute());
277 }
279 /* Prepare templating */
280 $smarty= get_smarty();
282 $tmp = $this->plInfo();
283 foreach($tmp['plProvidedAcls'] as $var => $rest){
284 $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
285 }
287 if(!session::is_set('edit') && !isset($this->parent)){
288 $smarty->assign("sambaLogonHoursACL","");
289 }
291 if ($this->sambaPwdMustChange=="0"){
292 $date= getdate();
293 } else {
294 $date= getdate($this->sambaPwdMustChange);
295 }
297 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
298 $sambaLogonTime_date= getdate();
299 } else {
300 $sambaLogonTime_date= getdate($this->sambaLogonTime);
301 }
303 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
304 $sambaLogoffTime_date= getdate();
305 } else {
306 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
307 }
309 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
310 $sambaKickoffTime_date= getdate();
311 } else {
312 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
313 }
315 /* Remove user workstations? */
316 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
318 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
320 if($this->multiple_support_active){
321 foreach($_POST['workstation_list'] as $name){
322 if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
323 unset($this->multiple_sambaUserWorkstations[trim($name)]);
324 }
325 }
326 }else{
327 $tmp= $this->sambaUserWorkstations;
328 foreach($_POST['workstation_list'] as $name){
329 $tmp= preg_replace("/$name/", '', $tmp);
330 $this->is_modified= TRUE;
331 }
332 $tmp= preg_replace('/,+/', ',', $tmp);
333 $this->sambaUserWorkstations= trim($tmp, ',');
334 }
335 }
336 }
338 /* Add user workstation? */
339 if (isset($_POST["add_ws"])){
340 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
341 $this->show_ws_dialog= TRUE;
342 $this->dialog= TRUE;
343 }
344 }
346 /* Add user workstation finished? */
347 if (isset($_POST["add_ws_cancel"])){
348 $this->show_ws_dialog= FALSE;
349 $this->dialog= FALSE;
350 }
352 /* Add user workstation? */
353 if (isset($_POST["add_ws_finish"])){
355 if (isset($_POST['wslist'])){
356 if($this->multiple_support_active){
357 foreach($_POST['wslist'] as $ws){
358 $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
359 }
360 }else{
361 $tmp= $this->sambaUserWorkstations;
362 foreach($_POST['wslist'] as $ws){
363 $tmp.= ",$ws";
364 }
365 $tmp= preg_replace('/,+/', ',', $tmp);
366 $this->sambaUserWorkstations= trim($tmp, ',');
367 }
368 $this->is_modified= TRUE;
370 $this->show_ws_dialog= FALSE;
371 $this->dialog= FALSE;
372 } else {
373 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
374 }
375 }
377 /* Show ws dialog */
378 if ($this->show_ws_dialog){
380 /* Save data */
381 $sambafilter= session::get("sambafilter");
382 foreach( array("depselect", "regex") as $type){
383 if (isset($_POST[$type])){
384 $sambafilter[$type]= $_POST[$type];
385 }
386 }
387 if (isset($_GET['search'])){
388 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
389 if ($s == "**"){
390 $s= "*";
391 }
392 $sambafilter['regex']= $s;
393 }
394 session::set("sambafilter", $sambafilter);
396 /* Get workstation list */
397 $exclude= "";
399 if($this->multiple_support_active){
400 foreach($this->multiple_sambaUserWorkstations as $ws){
401 if($ws['UsedByAllUsers']){
402 $exclude.= "(cn=".$ws['Name']."$)";
403 }
404 }
405 }else{
406 foreach(split(',', $this->sambaUserWorkstations) as $ws){
407 $exclude.= "(cn=$ws$)";
408 }
409 }
410 if ($exclude != ""){
411 $exclude= "(!(|$exclude))";
412 }
413 $regex= $sambafilter['regex'];
414 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
415 $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
417 $wslist= array();
418 foreach ($res as $attrs){
419 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
420 }
421 asort($wslist);
423 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
424 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
425 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
426 $smarty->assign("deplist", $this->config->idepartments);
427 $smarty->assign("alphabet", generate_alphabet());
428 foreach( array("depselect", "regex") as $type){
429 $smarty->assign("$type", $sambafilter[$type]);
430 }
431 $smarty->assign("hint", print_sizelimit_warning());
432 $smarty->assign("wslist", $wslist);
433 $smarty->assign("apply", apply_filter());
434 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
435 dirname(__FILE__)));
436 return ($display);
437 }
439 /* Fill calendar */
440 $days= array();
441 for($d= 1; $d<32; $d++){
442 $days[]= $d;
443 }
444 $years= array();
445 for($y= $date['year']-4; $y<$date['year']+4; $y++){
446 $years[]= $y;
447 }
448 $months= msgPool::months();
449 $smarty->assign("day", $date["mday"]);
450 $smarty->assign("days", $days);
451 $smarty->assign("months", $months);
452 $smarty->assign("month", $date["mon"]-1);
453 $smarty->assign("years", $years);
454 $smarty->assign("year", $date["year"]);
456 $sambaLogonTime_days= array();
457 for($d= 1; $d<32; $d++){
458 $sambaLogonTime_days[]= $d;
459 }
460 $sambaLogonTime_years= array();
461 for($y= $date['year']-4; $y<$date['year']+4; $y++){
462 $sambaLogonTime_years[]= $y;
463 }
464 $sambaLogonTime_months= msgPool::months();
465 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
466 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
467 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
468 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
469 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
470 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
472 $sambaLogoffTime_days= array();
473 for($d= 1; $d<32; $d++){
474 $sambaLogoffTime_days[]= $d;
475 }
476 $sambaLogoffTime_years= array();
477 for($y= $date['year']-4; $y<$date['year']+4; $y++){
478 $sambaLogoffTime_years[]= $y;
479 }
480 $sambaLogoffTime_months= msgPool::months();
481 $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
482 $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
483 $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
484 $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
485 $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
486 $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
488 $sambaKickoffTime_days= array();
489 for($d= 1; $d<32; $d++){
490 $sambaKickoffTime_days[]= $d;
491 }
492 $sambaKickoffTime_years= array();
493 for($y= $date['year']-4; $y<$date['year']+4; $y++){
494 $sambaKickoffTime_years[]= $y;
495 }
496 $sambaKickoffTime_months= msgPool::months();
497 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
498 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
499 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
500 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
501 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
502 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
503 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
505 /* Fill boxes */
506 if ($this->samba3){
507 $domains= array();
508 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
509 $domains[]= $name;
510 }
511 $smarty->assign("domains", $domains);
512 }
513 $letters= array("");
514 for ($i= 68; $i<91; $i++){
515 $letters[]= chr($i).":";
516 }
517 $smarty->assign("drives", $letters);
519 /* Fill terminal server settings */
520 if ($this->samba3){
521 foreach ($this->ctxattributes as $attr){
522 /* Fill common attributes */
523 if (isset($this->mungedObject->ctx[$attr])){
524 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
525 // Set field to blank if value is 0
526 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
527 if($this->mungedObject->ctx[$attr] == 0) {
528 $smarty->assign("$attr", "");
529 }
530 }
531 } else {
532 $smarty->assign("$attr", "");
533 }
534 }
536 /* Assign enum values for preset items */
537 $shadowModeVals= array( "0" => _("disabled"),
538 "1" => _("input on, notify on"),
539 "2" => _("input on, notify off"),
540 "3" => _("input off, notify on"),
541 "4" => _("input off, nofify off"));
543 $brokenConnModeVals= array( "0" => _("disconnect"),
544 "1" => _("reset"));
546 $reConnModeVals= array( "0" => _("from any client"),
547 "1" => _("from previous client only"));
549 /* Fill preset items */
550 $smarty->assign("shadow", $shadowModeVals);
551 $smarty->assign("brokenconn", $brokenConnModeVals);
552 $smarty->assign("reconn", $reConnModeVals);
554 /* Fill preset items with values */
555 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
556 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
557 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
559 if(session::get('js')){
560 /* Set form elements to disabled/enable state */
561 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
563 $smarty->assign("inheritstate", "");
564 if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
565 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
566 }
567 }else{
568 $smarty->assign("tsloginstate", "");
569 $smarty->assign("inheritstate", "");
570 }
572 /* Set checkboxes to checked or unchecked state */
573 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
574 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
575 $smarty->assign("connectclientdrives",
576 $this->mungedObject->getConnectClientDrives()?"checked":"");
577 $smarty->assign("connectclientprinters",
578 $this->mungedObject->getConnectClientPrinters()?"checked":"");
579 $smarty->assign("defaultprinter",
580 $this->mungedObject->getDefaultPrinter()?"checked":"");
581 $smarty->assign("CtxMaxConnectionTimeF",
582 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
583 $smarty->assign("CtxMaxDisconnectionTimeF",
584 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
585 $smarty->assign("CtxMaxIdleTimeF",
586 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
589 /* Fill sambaUserWorkstations */
590 $ws= split(",", $this->sambaUserWorkstations);
591 sort($ws);
593 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
594 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
596 if($this->multiple_support_active){
597 $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
598 }
600 $smarty->assign("workstations", $ws);
601 }
603 /* Variables */
604 foreach($this->attributes as $val){
605 $smarty->assign("$val", $this->$val);
606 }
608 /* 'sambaAcctFlags' checkboxes */
609 /* Check for 'lock-account'-flag: 'D' or 'L' */
610 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
611 is_integer(strpos($this->sambaAcctFlags, "L"))) {
612 $smarty->assign("flagsD", "checked");
613 } else {
614 $smarty->assign("flagsD", "");
615 }
617 /* Check for no_password_required flag 'N' */
618 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
619 $smarty->assign("flagsN", "checked");
620 } else {
621 $smarty->assign("flagsN", "");
622 }
624 // check if password never expires
625 if (is_integer(strpos($this->sambaAcctFlags, "X"))) {
626 $smarty->assign("flagsX", "checked");
627 } else {
628 $smarty->assign("flagsX", "");
629 }
631 if($this->samba3){
632 if ($this->sambaPwdCanChange=="1"){
633 $smarty->assign("flagsP", "checked");
634 } else {
635 $smarty->assign("flagsP", "");
636 }
637 }else{
638 if ($this->pwdCanChange=="1"){
639 $smarty->assign("flagsP", "checked");
640 } else {
641 $smarty->assign("flagsP", "");
642 }
643 }
645 if ($this->password_expires=="1"){
646 $smarty->assign("flagsC", "checked");
647 } else {
648 $smarty->assign("flagsC", "");
649 }
650 if ($this->logon_time_set=="1"){
651 $smarty->assign("flagsT", "checked");
652 } else {
653 $smarty->assign("flagsT", "");
654 }
655 if ($this->logoff_time_set=="1"){
656 $smarty->assign("flagsO", "checked");
657 } else {
658 $smarty->assign("flagsO", "");
659 }
660 if ($this->kickoff_time_set=="1"){
661 $smarty->assign("flagsK", "checked");
662 } else {
663 $smarty->assign("flagsK", "");
664 }
667 /* In case of javascript, disable some fields on demand */
668 if ($this->samba3){
669 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
670 $smarty->assign("$key", "$value");
671 }
672 }
675 foreach($this->attributes as $attr){
676 if(in_array($attr,$this->multi_boxes)){
677 $smarty->assign("use_".$attr,TRUE);
678 }else{
679 $smarty->assign("use_".$attr,FALSE);
680 }
681 }
682 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
683 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
684 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
685 "onnectclientprinters","defaultprinter","shadow","brokenconn",
686 "reconn","allow_pwchange","connectclientprinters","no_expiry","no_password_required","temporary_disable",
687 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
688 "workstation_list") as $attr){
689 if(in_array($attr,$this->multi_boxes)){
690 $smarty->assign("use_".$attr,TRUE);
691 }else{
692 $smarty->assign("use_".$attr,FALSE);
693 }
694 }
696 if($this->multiple_support_active){
697 $smarty->assign("tsloginstate","");
698 }
700 /* Create additional info for sambaKickOffTime and sambaPwdMustChange.
701 e.g. Display effective kickoff time. Domain policy + user settings.
702 */
703 $additional_info_PwdMustChange = "";
705 /* Calculate effective max Password Age
706 This can only be calculated if sambaPwdLastSet ist set.
707 */
708 if(isset($this->attrs['sambaPwdLastSet'][0])){
709 $last = $this->attrs['sambaPwdLastSet'][0];
711 $sid = $this->get_domain_info();
712 if(isset($sid['sambaMaxPwdAge'][0])){
713 $d = ($last + $sid['sambaMaxPwdAge'][0]) - time();
715 /* A negative value means the password is outdated
716 */
717 if($d < 0){
718 $additional_info_PwdMustChange = sprintf(_("The password is outdated since %s, by domain policy."),
719 date("d.m.Y H:i:s",$last + $sid['sambaMaxPwdAge'][0]));
720 }else{
721 if($this->password_expires && ($last + $sid['sambaMaxPwdAge'][0]) > $this->sambaPwdMustChange){
722 $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by user policy."),
723 date("d.m.Y H:i:s", $this->sambaPwdMustChange));
724 }else{
725 $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by domain policy."),
726 date("d.m.Y H:i:s", ($last + $sid['sambaMaxPwdAge'][0])));
727 }
728 }
729 }
730 }
731 $smarty->assign("additional_info_PwdMustChange",$additional_info_PwdMustChange);
732 $smarty->assign("no_expiry",$this->no_expiry);
734 /* Show main page */
735 $smarty->assign("multiple_support",$this->multiple_support_active);
736 if ($this->samba3){
737 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
738 } else {
739 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
740 }
742 return ($display);
743 }
746 /*! \brief Returns the samba Domain object, selected in the samba tab.
747 */
748 function get_domain_info()
749 {
750 /* Only search once, return last result if available
751 */
752 if(!isset($this->cache['DOMAIN'][$this->sambaDomainName])){
753 $this->cache['DOMAIN'][$this->sambaDomainName] = array();
754 if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
755 $cfg = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName];
756 $ldap = $this->config->get_ldap_link();
757 $ldap->cd($this->config->current['BASE']);
758 $ldap->search("(&(objectClass=sambaDomain)(sambaSID=".$cfg['SID']."))",array("*"));
759 if($ldap->count()){
760 $this->cache['DOMAIN'][$this->sambaDomainName] = $ldap->fetch();
761 }
762 }
763 }
764 return($this->cache['DOMAIN'][$this->sambaDomainName]);
765 }
769 function get_samba_information()
770 {
772 /* Defaults
773 */
774 $sambaMinPwdLength = "unset";
775 $sambaPwdHistoryLength = "unset";
776 $sambaLogonToChgPwd = "unset";
777 $sambaMaxPwdAge = "unset";
778 $sambaMinPwdAge = "unset";
779 $sambaLockoutDuration = "unset";
780 $sambaLockoutThreshold = "unset";
781 $sambaForceLogoff = "unset";
782 $sambaRefuseMachinePwdChange = "unset";
783 $sambaPwdLastSet = "unset";
784 $sambaLogonTime = "unset";
785 $sambaLogoffTime = "unset";
787 $sambaKickoffTime = "unset";
788 $sambaPwdCanChange = "unset";
789 $sambaPwdMustChange = "unset";
790 $sambaBadPasswordCount = "unset";
791 $sambaBadPasswordTime = "unset";
793 /* Domain attributes
794 */
795 $domain_attributes = array("sambaMinPwdLength","sambaPwdHistoryLength","sambaMaxPwdAge",
796 "sambaMinPwdAge","sambaLockoutDuration","sambaRefuseMachinePwdChange",
797 "sambaLogonToChgPwd","sambaLockoutThreshold","sambaForceLogoff");
799 /* User attributes
800 */
801 $user_attributes = array("sambaBadPasswordTime","sambaPwdLastSet","sambaLogonTime","sambaLogoffTime",
802 "sambaKickoffTime","sambaPwdCanChange","sambaPwdMustChange","sambaBadPasswordCount");
804 /* Get samba SID object and parse settings.
805 */
806 $ldap = $this->config->get_ldap_link();
807 $ldap->cd($this->config->current['BASE']);
808 if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
809 $attrs = $this->get_domain_info();
810 foreach($domain_attributes as $attr){
811 if(isset($attrs[$attr])){
812 $$attr = $attrs[$attr][0];
813 }
814 }
815 }
817 /* Get user infos
818 */
819 foreach($user_attributes as $attr){
820 if(isset($this->attrs[$attr])){
821 $$attr = $this->attrs[$attr][0];
822 }
823 }
824 if($this->password_expires){
825 $sambaPwdMustChange = $this->sambaPwdMustChange;
826 }
827 if($this->kickoff_time_set){
828 $sambaKickoffTime = $this->sambaKickoffTime;
829 }
830 $sambaPwdCanChange = $this->sambaPwdCanChange;
833 /* DOMAIN Attributes
834 */
836 /* sambaMinPwdLength: Password length has a default of 5
837 */
838 if($sambaMinPwdLength == "unset" || $sambaMinPwdLength == 5){
839 $sambaMinPwdLength = "5 <i>("._("default").")</i>";
840 }
842 /* sambaPwdHistoryLength: Length of Password History Entries (default: 0 => off)
843 */
844 if($sambaPwdHistoryLength == "unset" || $sambaPwdHistoryLength == 0){
845 $sambaPwdHistoryLength = _("Off")." <i>("._("default").")</i>";
846 }
848 /* sambaLogonToChgPwd: Force Users to logon for password change (default: 0 => off, 2 => on)
849 */
850 if($sambaLogonToChgPwd == "unset" || $sambaLogonToChgPwd == 0){
851 $sambaLogonToChgPwd = _("Off")." <i>("._("default").")</i>";
852 }else{
853 $sambaLogonToChgPwd = _("On");
854 }
856 /* sambaMaxPwdAge: Maximum password age, in seconds (default: -1 => never expire passwords)'
857 */
858 if($sambaMaxPwdAge == "unset" || $sambaMaxPwdAge == "-1"){
859 $sambaMaxPwdAge = _("disabled")." <i>("._("default").")</i>";
860 }else{
861 $sambaMaxPwdAge .= " "._("seconds");
862 }
864 /* sambaMinPwdAge: Minimum password age, in seconds (default: 0 => allow immediate password change
865 */
866 if($sambaMinPwdAge == "unset" || $sambaMinPwdAge == 0){
867 $sambaMinPwdAge = _("disabled")." <i>("._("default").")</i>";
868 }else{
869 $sambaMinPwdAge .= " "._("seconds");
870 }
872 /* sambaLockoutDuration: Lockout duration in minutes (default: 30, -1 => forever)
873 */
874 if($sambaLockoutDuration == "unset" || $sambaLockoutDuration == 30){
875 $sambaLockoutDuration = "30 "._("minutes")." <i>("._("default").")</i>";
876 }elseif($sambaLockoutDuration == -1){
877 $sambaLockoutDuration = _("forever");
878 }else{
879 $sambaLockoutDuration .= " "._("minutes");
880 }
882 /* sambaLockoutThreshold: Lockout users after bad logon attempts (default: 0 => off
883 */
884 if($sambaLockoutThreshold == "unset" || $sambaLockoutThreshold == 0){
885 $sambaLockoutThreshold = _("disabled")." <i>("._("default").")</i>";
886 }
888 /* sambaForceLogoff: Disconnect Users outside logon hours (default: -1 => off, 0 => on
889 */
890 if($sambaForceLogoff == "unset" || $sambaForceLogoff == -1){
891 $sambaForceLogoff = _("off")." <i>("._("default").")</i>";
892 }else{
893 $sambaForceLogoff = _("on");
894 }
896 /* sambaRefuseMachinePwdChange: Allow Machine Password changes (default: 0 => off
897 */
898 if($sambaRefuseMachinePwdChange == "none" || $sambaRefuseMachinePwdChange == 0){
899 $sambaRefuseMachinePwdChange = _("off")." <i>("._("default").")</i>";
900 }else{
901 $sambaRefuseMachinePwdChange = _("on");
902 }
904 /* USER Attributes
905 */
906 /* sambaBadPasswordTime: Time of the last bad password attempt
907 */
908 if($sambaBadPasswordTime == "unset" || empty($sambaBadPasswordTime)){
909 $sambaBadPasswordTime = "<i>("._("unset").")</i>";
910 }else{
911 $sambaBadPasswordTime = date("d.m.Y H:i:s",$sambaBadPasswordTime);
912 }
914 /* sambaBadPasswordCount: Bad password attempt count
915 */
916 if($sambaBadPasswordCount == "unset" || empty($sambaBadPasswordCount)){
917 $sambaBadPasswordCount = "<i>("._("unset").")</i>";
918 }else{
919 $sambaBadPasswordCount = date("d.m.Y H:i:s",$sambaBadPasswordCount);
920 }
922 /* sambaPwdLastSet: Timestamp of the last password update
923 */
924 if($sambaPwdLastSet == "unset" || empty($sambaPwdLastSet)){
925 $sambaPwdLastSet = "<i>("._("unset").")</i>";
926 }else{
927 $sambaPwdLastSet = date("d.m.Y H:i:s",$sambaPwdLastSet);
928 }
930 /* sambaLogonTime: Timestamp of last logon
931 */
932 if($sambaLogonTime == "unset" || empty($sambaLogonTime)){
933 $sambaLogonTime = "<i>("._("unset").")</i>";
934 }else{
935 $sambaLogonTime = date("d.m.Y H:i:s",$sambaLogonTime);
936 }
938 /* sambaLogoffTime: Timestamp of last logoff
939 */
940 if($sambaLogoffTime == "unset" || empty($sambaLogoffTime)){
941 $sambaLogoffTime = "<i>("._("unset").")</i>";
942 }else{
943 $sambaLogoffTime = date("d.m.Y H:i:s",$sambaLogoffTime);
944 }
946 /* sambaKickoffTime: Timestamp of when the user will be logged off automatically
947 */
948 if($sambaKickoffTime == "unset" || empty($sambaKickoffTime)){
949 $sambaKickoffTime = "<i>("._("unset").")</i>";
950 }else{
951 $sambaKickoffTime = date("d.m.Y H:i:s",$sambaKickoffTime);
952 }
954 /* sambaPwdMustChange: Timestamp of when the password will expire
955 */
956 if($sambaPwdMustChange == "unset" || empty($sambaPwdMustChange)){
957 $sambaPwdMustChange = "<i>("._("unset").")</i>";
958 }else{
959 $sambaPwdMustChange = date("d.m.Y H:i:s",$sambaPwdMustChange);
960 }
962 /* sambaPwdCanChange: Timestamp of when the user is allowed to update the password
963 */
964 if($sambaPwdCanChange == "unset" || empty($sambaPwdCanChange)){
965 $sambaPwdCanChange = "<i>("._("unset").")</i>";
966 }elseif($sambaPwdCanChange != "unset" && time() > $sambaPwdCanChange){
967 $sambaPwdCanChange = _("immediately") ;
968 }else{
969 $days = floor((($sambaPwdCanChange - time()) / 60 / 60 / 24)) ;
970 $hours = floor((($sambaPwdCanChange - time()) / 60 / 60) % 24) ;
971 $minutes = floor((($sambaPwdCanChange - time()) / 60 ) % 60) ;
973 $sambaPwdCanChange = " ".$days." "._("days");
974 $sambaPwdCanChange.= " ".$hours." "._("hours");
975 $sambaPwdCanChange.= " ".$minutes." "._("minutes");
976 }
978 $str =
979 "\n<div style='height:200px; overflow: auto;'>".
980 "\n<table style='width:100%;'>".
981 "\n<tr><td><b>"._("Domain attributes")."</b></td></tr>".
982 "\n<tr><td>"._("Min password length").": </td><td>".$sambaMinPwdLength."</td></tr>".
983 "\n<tr><td>"._("Min password length").": </td><td>".$sambaMinPwdLength."</td></tr>".
984 "\n<tr><td>"._("Password history").": </td><td>".$sambaPwdHistoryLength."</td></tr>".
985 "\n<tr><td>"._("Force password change").": </td><td>".$sambaLogonToChgPwd."</td></tr>".
986 "\n<tr><td>"._("Maximum password age").": </td><td>".$sambaMaxPwdAge."</td></tr>".
987 "\n<tr><td>"._("Minimum password age").": </td><td>".$sambaMinPwdAge."</td></tr>".
988 "\n<tr><td>"._("Lockout duration").": </td><td>".$sambaLockoutDuration."</td></tr>".
989 "\n<tr><td>"._("Bad lockout attempt").": </td><td>".$sambaLockoutThreshold."</td></tr>".
990 "\n<tr><td>"._("Disconnect time").": </td><td>".$sambaForceLogoff."</td></tr>".
991 "\n<tr><td>"._("Refuse machine password change").":</td><td>".$sambaRefuseMachinePwdChange."</td></tr>".
992 "\n<tr><td> </td></tr>".
993 "\n<tr><td><b>"._("User attributes")."</b></td></tr>".
994 "\n<tr><td>"._("Last failed login").": </td><td>".$sambaBadPasswordTime."</td></tr>".
995 "\n<tr><td>"._("Logon attempts").": </td><td>".$sambaBadPasswordCount."</td></tr>".
996 "\n<tr><td>"._("Last password update").": </td><td>".$sambaPwdLastSet."</td></tr>".
997 "\n<tr><td>"._("Last logon").": </td><td>".$sambaLogonTime."</td></tr>".
998 "\n<tr><td>"._("Last logoff").": </td><td>".$sambaLogoffTime."</td></tr>".
999 "\n<tr><td>"._("Automatic logoff").": </td><td>".$sambaKickoffTime."</td></tr>";
1001 if($this->no_expiry){
1002 $str .= "\n<tr><td>"._("Password expires").": </td><td>"._("No")."</td></tr>";
1003 $str .= "\n<tr><td colspan='2'><font color='gray'>".
1004 sprintf(_("The password would expire on %s, but the password expiry is disabled."),$sambaPwdMustChange).
1005 "</font></td></tr>";
1006 }else{
1007 $str .= "\n<tr><td>"._("Password expires").": </td><td>".$sambaPwdMustChange."</td></tr>";
1008 }
1010 $str .= "\n<tr><td>"._("Password change available").": </td><td>".$sambaPwdCanChange."</td></tr>".
1011 "\n</table>";
1012 "\n</div>";
1013 return($str);
1014 }
1017 function remove_from_parent()
1018 {
1019 /* Cancel if there's nothing to do here */
1020 if (!$this->initially_was_account){
1021 return;
1022 }
1024 /* include global link_info */
1025 $ldap= $this->config->get_ldap_link();
1027 plugin::remove_from_parent();
1029 /* Keep uid attribute for gosaAccount */
1030 unset($this->attrs['uid']);
1031 unset($this->attrs['uidNumber']);
1032 unset($this->attrs['gidNumber']);
1034 /* Remove objectClass for sambaIdmapEntry */
1035 $tmp= array();
1036 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1037 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1038 $tmp[]= $this->attrs['objectClass'][$i];
1039 }
1040 }
1041 $this->attrs['objectClass']= $tmp;
1043 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
1044 $this->attributes, "Save");
1045 $ldap->cd($this->dn);
1046 $this->cleanup();
1047 $ldap->modify ($this->attrs);
1049 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1051 if (!$ldap->success()){
1052 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
1053 }
1055 /* Optionally execute a command after we're done */
1056 $this->handle_post_events("remove", array("uid" => $this->uid));
1057 }
1060 /* Check for input problems */
1061 function check()
1062 {
1063 /* Call common method to give check the hook */
1064 $message= plugin::check();
1066 if ($this->samba3){
1068 /* sambaHomePath requires sambaHomeDrive and vice versa */
1069 if(!empty($this->sambaHomePath) && empty($this->sambaHomeDrive)){
1070 $message[]= msgPool::required(_("Home drive"));
1071 }
1072 if(!empty($this->sambaHomeDrive) && empty($this->sambaHomePath)){
1073 $message[]= msgPool::required(_("Home path"));
1074 }
1076 /* Strings */
1077 foreach (array( "sambaHomePath" => _("Home directory"),
1078 "sambaProfilePath" => _("Profile path")) as $key => $val){
1079 if (!$this->mungedObject->is_samba_path($this->$key)){
1080 $message[]= msgPool::invalid($val);
1081 }
1082 }
1084 /* Numeric values */
1085 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
1086 "CtxMaxDisconnectionTime" => _("Disconnection"),
1087 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
1089 if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1090 $message[]= msgPool::invalid($val);
1091 }
1092 }
1094 /* Too many workstations? Windows usrmgr only supports eight */
1095 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1096 $message[]= _("The windows usermanager allows eight clients at maximum!");
1097 }
1098 }
1100 return ($message);
1101 }
1104 /* Save data to object */
1105 function save_object()
1106 {
1108 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
1110 /* We only care if we are on the sambaTab... */
1111 if (isset($_POST['sambaTab'])){
1112 plugin::save_object();
1114 if(isset($_POST['display_information'])){
1115 msg_dialog::display(_("Information"),
1116 $this->get_samba_information(),
1117 INFO_DIALOG);
1118 }
1120 /* Take care about access options */
1121 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1122 if ($this->samba3){
1123 $attrname= "sambaPwdCanChange";
1124 } else {
1125 $attrname= "pwdCanChange";
1126 }
1127 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
1128 $tmp= 1;
1129 } else {
1130 $tmp= 0;
1131 }
1132 if ($this->$attrname != $tmp){
1133 $this->is_modified= TRUE;
1134 }
1135 $this->pwdCanChange= $tmp;
1136 $this->sambaPwdCanChange= $tmp;
1137 }
1138 $tmp= "U";
1140 $this->no_expiry = FALSE;
1141 if (isset($_POST["no_expiry"])){
1142 if ($_POST["no_expiry"] == 1){
1143 $tmp.= "X";
1144 $this->no_expiry = TRUE;
1145 }
1146 }
1148 $this->no_password_required = FALSE;
1149 if (isset($_POST["no_password_required"])){
1150 if ($_POST["no_password_required"] == 1){
1151 $tmp.= "N";
1152 $this->no_password_required = TRUE;
1153 }
1154 }
1155 if (isset($_POST["password_expires"])){
1156 if ($_POST["password_expires"] == 1){
1157 $this->password_expires= 1;
1158 }
1159 } else {
1160 $this->password_expires= 0;
1161 }
1162 $this->temporary_disable = FALSE;
1163 if (isset($_POST["temporary_disable"])){
1164 if ($_POST["temporary_disable"] == 1){
1165 $this->temporary_disable = TRUE;
1166 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
1167 $tmp.= "L";
1168 } else {
1169 $tmp.= "D";
1170 }
1171 }
1172 }
1173 if (isset($_POST["logon_time_set"])){
1174 if ($_POST["logon_time_set"] == 1){
1175 $this->logon_time_set= 1;
1176 }
1177 } else {
1178 $this->logon_time_set= 0;
1179 }
1180 if (isset($_POST["logoff_time_set"])){
1181 if ($_POST["logoff_time_set"] == 1){
1182 $this->logoff_time_set= 1;
1183 }
1184 } else {
1185 $this->logoff_time_set= 0;
1186 }
1187 if (isset($_POST["kickoff_time_set"])){
1188 if ($_POST["kickoff_time_set"] == 1){
1189 $this->kickoff_time_set= 1;
1190 }
1191 } else {
1192 $this->kickoff_time_set= 0;
1193 }
1195 $fill= "";
1196 for ($i= strlen($tmp); $i<12; $i++){
1197 $fill.= " ";
1198 }
1200 $tmp= "[$tmp$fill]";
1202 /* Only save if acl's are set */
1203 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1204 if ($this->samba3){
1205 $attrname= "sambaAcctFlags";
1206 } else {
1207 $attrname= "acctFlags";
1208 }
1209 if ($this->$attrname != $tmp){
1210 $this->is_modified= TRUE;
1211 }
1212 $this->$attrname= $tmp;
1213 }
1215 /* Save sambaDomain attribute */
1216 if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
1217 $this->sambaDomainName= validate($_POST['sambaDomainName']);
1218 }
1220 /* Save CTX values */
1221 if ($this->samba3){
1223 /* Save obvious values */
1224 foreach($this->ctxattributes as $val){
1225 if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
1226 if (get_magic_quotes_gpc()) {
1227 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
1228 } else {
1229 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
1230 }
1231 }
1232 }
1234 /* Save checkbox states. */
1235 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
1236 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1237 // Need to do some index checking to avoid messages like "index ... not found"
1238 if(isset($_POST['brokenconn'])) {
1239 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
1240 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1241 }
1242 if(isset($_POST['reconn'])) {
1243 $this->mungedObject->setReConn($_POST['reconn'] == '1'
1244 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1245 }
1246 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
1247 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1248 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
1249 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1250 $this->mungedObject->setCtxMaxDisconnectionTimeF(
1251 !isset($_POST['CtxMaxDisconnectionTimeF'])
1252 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1253 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
1254 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1255 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
1256 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1257 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
1258 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1259 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
1260 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1262 /* Save combo boxes. Takes two values */
1263 if(isset($_POST['reconn'])) {
1264 $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
1265 }
1267 /* Check for changes */
1268 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
1269 $this->is_modified= TRUE;
1270 }
1271 }
1272 }
1273 }
1276 /* Save to LDAP */
1277 function save()
1278 {
1279 /* Load uid and gid of this 'dn' */
1280 $ldap= $this->config->get_ldap_link();
1281 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
1282 $tmp= $ldap->fetch();
1283 $this->uidNumber= $tmp['uidNumber'][0];
1284 $this->gidNumber= $tmp['gidNumber'][0];
1286 plugin::save();
1288 /* Remove objectClass for sambaIdmapEntry */
1289 $tmp= array();
1290 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1291 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1292 $tmp[]= $this->attrs['objectClass'][$i];
1293 }
1294 }
1295 $this->attrs['objectClass']= $tmp;
1297 /* Generate rid / primaryGroupId */
1298 if ($this->samba3){
1299 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
1300 msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
1301 } else {
1302 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
1303 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
1304 }
1306 /* Need to generate a new uniqe uid/gid combination? */
1307 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
1308 $uidNumber= $this->uidNumber;
1309 while(TRUE){
1310 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
1311 $ldap->cd($this->config->current['BASE']);
1312 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
1313 if ($ldap->count() == 0){
1314 break;
1315 }
1316 $uidNumber++;
1317 }
1318 $this->attrs['sambaSID']= $sid;
1320 /* Check for users primary group */
1321 $ldap->cd($this->config->current['BASE']);
1322 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
1323 if ($ldap->count() != 1){
1324 msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
1325 } else {
1326 $attrs= $ldap->fetch();
1327 $g= new group($this->config, $ldap->getDN());
1328 if ($g->sambaSID == ""){
1329 $g->sambaDomainName= $this->sambaDomainName;
1330 $g->smbgroup= TRUE;
1331 $g->save ();
1332 }
1333 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
1334 }
1335 }
1337 if ($this->sambaHomeDrive == ""){
1338 $this->attrs["sambaHomeDrive"]= array();
1339 }
1341 /* Generate munged dial value */
1342 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1344 /* User wants me to fake the idMappings? This is useful for
1345 making winbind resolve the user names in a reasonable amount
1346 of time in combination with larger databases. */
1347 if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1348 $this->attrs['objectClass'][]= "sambaIdmapEntry";
1349 }
1352 /* Password expiery */
1353 if ($this->password_expires == "1"){
1354 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1355 } else {
1356 $this->attrs['sambaPwdMustChange']= array();
1357 }
1358 /* Make sure not to save zero in sambaPwdLastset */
1359 if ($this->sambaPwdLastSet != "0"){
1360 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1361 } else {
1362 $this->attrs['sambaPwdLastSet']= array();
1363 }
1364 /* Account expiery */
1365 if ($this->logon_time_set == "1"){
1366 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1367 } else {
1368 $this->attrs['sambaLogonTime']= array();
1369 }
1370 if ($this->logoff_time_set == "1"){
1371 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1372 } else {
1373 $this->attrs['sambaLogoffTime']= array();
1374 }
1375 if ($this->kickoff_time_set == "1"){
1376 # Add one day in unixtime format to be compatible with usrmgr
1377 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
1378 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
1379 } else {
1380 $this->attrs['sambaKickoffTime']= array();
1381 }
1382 } else {
1383 /* Not samba3 */
1384 $this->attrs['rid']= $this->uidNumber*2 + 1000;
1385 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1387 if ($this->homeDrive == ""){
1388 $this->attrs["homeDrive"]= array();
1389 }
1391 /* Password expiery */
1392 if ($this->password_expires == "1"){
1393 $this->attrs['pwdMustChange']= $this->pwdMustChange;
1394 } else {
1395 $this->attrs['pwdMustChange']= 2147483647;
1396 }
1397 /* Make sure not to save zero in pwdLastset */
1398 if ($this->pwdLastSet != "0"){
1399 $this->attrs['pwdLastSet']= $this->pwdLastSet;
1400 } else {
1401 $this->attrs['pwdLastSet']= array();
1402 }
1403 /* Account expiery */
1404 if ($this->logon_time_set == "1"){
1405 $this->attrs['logonTime']= $this->logonTime;
1406 } else {
1407 $this->attrs['logonTime']= array();
1408 }
1409 if ($this->logoff_time_set == "1"){
1410 $this->attrs['logoffTime']= $this->logoffTime;
1411 } else {
1412 $this->attrs['logoffTime']= array();
1413 }
1414 if ($this->kickoff_time_set == "1"){
1415 # Add one day in unixtime format to be compatible with usrmgr
1416 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1417 } else {
1418 $this->attrs['kickoffTime']= array();
1419 }
1420 }
1422 /* Write back to ldap */
1423 $ldap->cd($this->dn);
1424 $this->cleanup();
1425 $ldap->modify ($this->attrs);
1427 if($this->initially_was_account){
1428 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1429 }else{
1430 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1431 }
1433 if (!$ldap->success()){
1434 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1435 }
1437 /* Optionally execute a command after we're done */
1438 if ($this->initially_was_account == $this->is_account){
1439 if ($this->is_modified){
1440 $this->handle_post_events("modify", array("uid" => $this->uid));
1441 }
1442 } else {
1443 $this->handle_post_events("add", array("uid" => $this->uid));
1444 }
1445 }
1448 /* Force password set, if this account doesn't have any samba passwords */
1449 function password_change_needed()
1450 {
1451 if(!$this->initially_was_account && $this->is_account){
1452 $ldap = $this->config->get_ldap_link();
1453 $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1454 $attrs = $ldap->fetch();
1455 if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1456 return(TRUE);
1457 }
1458 }
1459 return(FALSE);
1460 }
1463 function adapt_from_template($dn, $skip= array())
1464 {
1465 plugin::adapt_from_template($dn, $skip);
1468 $this->sambaSID= "";
1469 $this->sambaPrimaryGroupSID= "";
1471 /* Fill mungedDial field */
1472 if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1473 $this->mungedObject->load($this->sambaMungedDial);
1474 }
1476 /* Adapt munged attributes */
1477 foreach($this->ctxattributes as $attr){
1478 if(isset($this->mungedObject->ctx[$attr]))
1479 $val = $this->mungedObject->ctx[$attr];
1481 foreach (array("sn", "givenName", "uid") as $repl){
1482 if (preg_match("/%$repl/i", $val)){
1483 $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1484 }
1485 }
1486 $this->mungedObject->ctx[$attr] = $val;
1487 }
1489 /* Password expiery */
1490 if(isset($this->attrs['sambaPwdMustChange']) &&
1491 $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1492 $this->password_expires= 1;
1493 }
1495 if(isset($this->attrs['sambaLogonTime']) && ! (
1496 $this->attrs['sambaLogonTime'][0] == 0 ||
1497 $this->attrs['sambaLogonTime'][0] == 2147483647
1498 ) && !in_array('sambaLogonTime', $skip)){
1499 $this->logon_time_set= 1;
1500 }
1501 if(isset($this->attrs['sambaLogoffTime']) && ! (
1502 $this->attrs['sambaLogoffTime'][0] == 0 ||
1503 $this->attrs['sambaLogoffTime'][0] == 2147483647
1504 ) && !in_array('sambaLogonTime', $skip)){
1505 $this->logoff_time_set= 1;
1506 }
1508 /* Account expiery */
1509 if(isset($this->attrs['sambaKickoffTime']) && ! (
1510 $this->attrs['sambaKickoffTime'][0] == 0 ||
1511 $this->attrs['sambaKickoffTime'][0] == 2147483647
1512 ) && !in_array('sambaKickoffTime', $skip)){
1513 $this->kickoff_time_set= 1;
1514 }
1516 /* Get global filter config */
1517 if (!session::is_set("sambafilter")){
1518 $ui= get_userinfo();
1519 $base= get_base_from_people($ui->dn);
1520 $sambafilter= array( "depselect" => $base, "regex" => "*");
1521 session::set("sambafilter", $sambafilter);
1522 }
1523 }
1526 static function plInfo()
1527 {
1528 return (array(
1529 "plShortName" => _("Samba"),
1530 "plDescription" => _("Samba settings"),
1531 "plSelfModify" => TRUE,
1532 "plDepends" => array("user"),
1533 "plPriority" => 5,
1534 "plSection" => array("personal" => _("My account")),
1535 "plCategory" => array("users"),
1536 "plOptions" => array(),
1538 "plProvidedAcls" => array(
1540 "sambaHomePath" => _("Generic home directory") ,
1541 "sambaHomeDrive" => _("Generic samba home drive") ,
1542 "sambaDomainName" => _("Domain") ,
1543 "sambaLogonScript" => _("Generic script path") ,
1544 "sambaProfilePath" => _("Generic profile path") ,
1545 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1546 "InheritClientConfig" => _("Inherit client config"),
1547 "sambaPwdCanChange" => _("Allow user to change password") ,
1548 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1549 "sambaAcctFlagsX" => _("Password never expires"),
1550 "sambaAcctFlagsL" => _("Lock samba account"),
1551 "sambaKickoffTime" => _("Account expires") ,
1552 "sambaPwdMustChange" => _("Password expires") ,
1553 "sambaLogonTime" => _("Limit Logon Time") ,
1554 "sambaLogoffTime" => _("Limit Logoff Time") ,
1555 "sambaLogonHours" => _("Logon hours") ,
1556 "sambaUserWorkstations" => _("Allow connection from"))
1557 ));
1558 }
1560 function enable_multiple_support()
1561 {
1562 plugin::enable_multiple_support();
1563 if($this->samba3){
1564 $this->multiple_support_active = TRUE;
1565 }else{
1566 $this->multiple_support_active = FALSE;
1567 }
1568 }
1570 function multiple_save_object()
1571 {
1572 if (isset($_POST['sambaTab'])){
1573 $this->save_object();
1574 plugin::multiple_save_object();
1575 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1576 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1577 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1578 "onnectclientprinters","defaultprinter","shadow","brokenconn",
1579 "reconn","allow_pwchange","connectclientprinters","no_expiry","no_password_required","temporary_disable",
1580 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1581 "workstation_list") as $attr){
1582 if(isset($_POST["use_".$attr])){
1583 $this->multi_boxes[] = $attr;
1584 }
1585 }
1586 }
1587 }
1590 function multiple_check()
1591 {
1592 $message = plugin::multiple_check();
1594 /* Strings */
1595 foreach (array( "sambaHomePath" => _("Home directory"),
1596 "sambaProfilePath" => _("Profile path")) as $key => $val){
1597 if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1598 $message[]= msgPool::invalid($val);
1599 }
1600 }
1602 /* Numeric values */
1603 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
1604 "CtxMaxDisconnectionTime" => _("Disconnection"),
1605 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
1606 if (in_array($key,$this->multi_boxes) &&
1607 isset($this->mungedObject->ctx[$key]) &&
1608 !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1609 $message[]=msgPool::invalid($val);
1610 }
1611 }
1613 /* Too many workstations? Windows usrmgr only supports eight */
1614 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1615 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1616 }
1617 return($message);
1618 }
1621 function get_multi_init_values()
1622 {
1623 $ret = plugin::get_multi_init_values();
1625 /* Parse given sambaUserWorkstations into array
1626 * to allow "init_multiple_support()" to detect multiple used workstations.
1627 * Those workstations will be displayed in light grey.
1628 */
1629 $tmp2 = array("count" => 0);
1630 $tmp = split(",", $this->sambaUserWorkstations);
1631 foreach($tmp as $station){
1632 $station = trim($station);
1633 if(!empty($station)){
1634 $tmp2[] = $station;
1635 $tmp2['count'] ++;
1636 }
1637 }
1638 $ret['sambaUserWorkstations'] = $tmp2;
1639 return($ret);
1640 }
1644 function init_multiple_support($attrs,$all)
1645 {
1646 plugin::init_multiple_support($attrs,$all);
1648 $this->multiple_sambaUserWorkstations = array();
1649 if(isset($all['sambaUserWorkstations'])){
1650 for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1651 $station = trim($all['sambaUserWorkstations'][$i]);
1652 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1653 }
1654 }
1655 if(isset($attrs['sambaUserWorkstations'])){
1656 for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1657 $station = trim($attrs['sambaUserWorkstations'][$i]);
1658 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1659 }
1660 }
1661 }
1663 function multiple_execute()
1664 {
1665 return($this->execute());
1666 }
1668 function get_multi_edit_values()
1669 {
1670 $ret = plugin::get_multi_edit_values();
1672 /* Terminal Server */
1673 if(in_array("tslogin",$this->multi_boxes)){
1674 $ret['tslogin'] = $this->mungedObject->getTsLogin();
1675 }
1676 if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1677 $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1678 }
1679 if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1680 $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1681 }
1682 if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1683 $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1684 }
1686 if(in_array("inherit",$this->multi_boxes)){
1687 $ret['inherit'] = $this->mungedObject->getInheritMode();
1688 }
1689 if(in_array("CtxInitialProgram",$this->multi_boxes)){
1690 $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1691 }
1692 if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1693 $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1694 }
1696 /* Time Limits. Be careful here, there are some negations */
1697 if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1698 $ret["CtxMaxConnectionTimeF"] = !$this->mungedObject->getCtxMaxConnectionTimeF();
1699 if(!$ret["CtxMaxConnectionTimeF"]){
1700 $ret["CtxMaxConnectionTime"] = $this->mungedObject->ctx['CtxMaxConnectionTime'];
1701 }
1702 }
1703 if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1704 $ret["CtxMaxDisconnectionTimeF"]= !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1705 if(!$ret["CtxMaxDisconnectionTimeF"]){
1706 $ret["CtxMaxDisconnectionTime"]= $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1707 }
1708 }
1709 if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1710 $ret["CtxMaxIdleTimeF"] = !$this->mungedObject->getCtxMaxIdleTimeF();
1711 if(!$ret["CtxMaxIdleTimeF"]){
1712 $ret["CtxMaxIdleTime"] = $this->mungedObject->ctx['CtxMaxIdleTime'];
1713 }
1714 }
1716 /* Client Devices */
1717 if(in_array("connectclientdrives",$this->multi_boxes)){
1718 $ret["connectclientdrives"] = $this->mungedObject->getConnectClientDrives();
1719 }
1720 if(in_array("connectclientprinters",$this->multi_boxes)){
1721 $ret["connectclientprinters"] = $this->mungedObject->getConnectClientPrinters();
1722 }
1723 if(in_array("defaultprinter",$this->multi_boxes)){
1724 $ret["defaultprinter"] = $this->mungedObject->getDefaultPrinter();
1725 }
1727 /* Misc */
1728 if(in_array("shadow",$this->multi_boxes)){
1729 $ret["shadow"] =$this->mungedObject->getShadow();
1730 }
1731 if(in_array("brokenconn",$this->multi_boxes)){
1732 $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1733 }
1734 if(in_array("reconn",$this->multi_boxes)){
1735 $ret["reconn"] =$this->mungedObject->getReConn();
1736 }
1738 /* Flags */
1739 if(in_array("allow_pwchange",$this->multi_boxes)){
1740 $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1741 $ret['pwdCanChange'] = $this->pwdCanChange;
1742 }
1744 if(in_array("password_expires",$this->multi_boxes)){
1745 $ret['password_expires'] = $this->password_expires;
1746 $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1747 }
1748 if(in_array("logon_time_set",$this->multi_boxes)){
1749 $ret['logon_time_set'] = $this->logon_time_set;
1750 $ret['sambaLogonTime'] = $this->sambaLogonTime;
1751 }
1752 if(in_array("logoff_time_set",$this->multi_boxes)){
1753 $ret['logoff_time_set'] = $this->logoff_time_set;
1754 $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1755 }
1756 if(in_array("kickoff_time_set",$this->multi_boxes)){
1757 $ret['kickoff_time_set'] = $this->kickoff_time_set;
1758 $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1759 }
1761 if(in_array("no_password_required",$this->multi_boxes)){
1762 $ret['no_password_required'] = $this->no_password_required;
1763 }
1765 if(in_array("no_expiry",$this->multi_boxes)){
1766 $ret['no_expiry'] = $this->no_expiry;
1767 }
1769 if(in_array("temporary_disable",$this->multi_boxes)){
1770 $ret['temporary_disable'] = $this->temporary_disable;
1771 }
1773 if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1774 $ret['sambaLogonHours'] = $this->sambaLogonHours;
1775 }
1777 if(in_array("workstation_list",$this->multi_boxes)){
1778 $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1779 }
1780 return($ret);
1781 }
1783 function set_multi_edit_values($values)
1784 {
1785 plugin::set_multi_edit_values($values);
1787 /* Prepare current workstation settings to be merged
1788 * with multiple edit settings.
1789 */
1790 if(isset($values['multiple_sambaUserWorkstations'])){
1791 $cur_ws = array();
1792 $m_ws = $values['multiple_sambaUserWorkstations'];
1794 /* Prepare current settings to be merged */
1795 if(isset($this->sambaUserWorkstations)){
1796 $ttmp = split(",",$this->sambaUserWorkstations);
1797 foreach($ttmp as $station){
1798 $station = trim($station);
1799 if(!empty($station)){
1800 $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1801 }
1802 }
1803 }
1805 /* Unset removed workstations */
1806 foreach($cur_ws as $cur_name => $cur_station){
1807 if(!isset($m_ws[$cur_name])){
1808 unset($cur_ws[$cur_name]);
1809 }
1810 }
1812 /* Add all added workstations */
1813 foreach($m_ws as $name => $station){
1814 if($station['UsedByAllUsers']){
1815 $cur_ws[$name] = $station;
1816 }
1817 }
1819 $this->sambaUserWorkstations = "";
1820 foreach($cur_ws as $name => $ws){
1821 $this->sambaUserWorkstations .= $name.",";
1822 }
1823 $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1824 }
1826 /* Enable disabled terminal login, this is inverted somehow */
1827 if(isset($values['tslogin'])) $this->mungedObject->setTsLogin(!$values['tslogin']);
1829 /* Imherit client configuration */
1830 if(isset($values['inherit'])) $this->mungedObject->setInheritMode($values['inherit']);
1832 /* Get all ctx values posted */
1833 $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1834 "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1835 foreach($ctx as $attr){
1836 if(isset($values[$attr])){
1837 $this->mungedObject->ctx[$attr] = $values[$attr] ;
1838 }
1839 }
1841 if(isset($values['CtxMaxConnectionTimeF'])) $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1842 if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1843 if(isset($values['CtxMaxIdleTimeF'])) $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1845 if(isset($values['connectclientdrives'])) $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1846 if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1847 if(isset($values['defaultprinter'])) $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1849 if(isset($values['shadow'])) $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1850 if(isset($values['brokenconn'])) $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1851 if(isset($values['reconn'])) $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1854 if(isset($values['sambaPwdCanChange'])) $this->sambaPwdCanChange = $values['sambaPwdCanChange'];
1855 if(isset($values['pwdCanChange'])) $this->pwdCanChange = $values['pwdCanChange'];
1860 if(isset($values['password_expires'])){
1861 $this->password_expires = $values['password_expires'];
1862 $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1863 }
1864 if(isset($values['logon_time_set'])){
1865 $this->logon_time_set = $values['logon_time_set'];
1866 $this->sambaLogonTime = $values['sambaLogonTime'];
1867 }
1868 if(isset($values['logoff_time_set'])){
1869 $this->logoff_time_set = $values['logoff_time_set'];
1870 $this->sambaLogoffTime = $values['sambaLogoffTime'];
1871 }
1872 if(isset($values['kickoff_time_set'])){
1873 $this->kickoff_time_set = $values['kickoff_time_set'];
1874 $this->sambaKickoffTime = $values['sambaKickoffTime'];
1875 }
1877 if(isset($values['no_password_required'])){
1878 if($values['no_password_required']){
1879 if(!preg_match("/N/",$this->sambaAcctFlags)) {
1880 $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1881 }
1882 }else{
1883 $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1884 }
1885 }
1887 if(isset($values['no_expiry'])){
1888 if($values['no_expiry']){
1889 if(!preg_match("/N/",$this->sambaAcctFlags)) {
1890 $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1891 }
1892 }else{
1893 $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1894 }
1895 }
1897 if(isset($values['temporary_disable'])){
1898 if($values['temporary_disable']){
1899 if(preg_match("/L/",$this->sambaAcctFlags)) {
1900 // Keep L
1901 }else{
1902 $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1903 }
1904 }else{
1905 $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1906 }
1907 }
1908 }
1911 function PrepareForCopyPaste($source)
1912 {
1913 plugin::PrepareForCopyPaste($source);
1915 /* Set a new SID */
1916 $this->sambaSID = "";
1917 }
1919 }
1921 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1922 ?>