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 $uidNumber= 65535;
30 var $gidNumber= 65535;
32 /* Samba 2 attributes */
33 var $pwdLastSet= "0";
34 var $logonTime= "0";
35 var $logoffTime= "2147483647";
36 var $kickoffTime= "2147483647";
37 var $pwdCanChange= "0";
38 var $pwdMustChange= "0";
39 var $password_expires= 0;
40 var $acctFlags= "[UX ]";
41 var $smbHome= "";
42 var $homeDrive= "";
43 var $scriptPath= "";
44 var $profilePath= "";
45 var $rid= "";
46 var $primaryGroupID= "";
48 /* Samba 3 attributes */
49 var $SID= "";
50 var $ridBase= 0;
51 var $sambaSID= "";
52 var $sambaPwdLastSet= "0";
53 var $sambaLogonTime= "0";
54 var $sambaLogoffTime= "2147483647";
55 var $sambaKickoffTime= "2147483647";
56 var $sambaPwdCanChange= "";
57 var $sambaPwdMustChange= "0";
58 var $sambaAcctFlags= "[UX ]";
59 var $sambaHomePath= "";
60 var $sambaHomeDrive= "";
61 var $sambaLogonScript= "";
62 var $sambaProfilePath= "";
63 var $sambaPrimaryGroupSID= "";
64 var $sambaDomainName= "";
65 var $sambaUserWorkstations= "";
66 var $sambaBadPasswordCount= "";
67 var $sambaBadPasswordTime= "";
68 var $sambaPasswordHistory= "";
69 var $sambaLogonHours= "";
70 var $orig_sambaDomainName= "";
71 var $sambaMungedDial= "";
72 var $mungedObject;
74 /* Helper */
75 var $cache = array();
76 var $show_ws_dialog= FALSE;
77 var $logon_time_set= 0;
78 var $logoff_time_set= 0;
79 var $kickoff_time_set= 0;
81 /* attribute list for save action */
82 var $ctxattributes= array();
83 var $attributes= array();
84 var $objectclasses= array();
86 var $uid= "";
87 var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
89 var $multiple_support = TRUE;
91 /* Only used for multiple edit */
92 var $temporary_disable = FALSE;
93 var $no_password_required = FALSE;
94 var $no_expiry = FALSE;
95 var $multiple_sambaUserWorkstations = array();
97 function sambaAccount (&$config, $dn= NULL)
98 {
99 /* Load attributes depending on the samba version */
100 $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
101 "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
102 "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
103 "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
104 "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
105 "sambaUserWorkstations", "sambaPasswordHistory",
106 "sambaLogonHours", "sambaBadPasswordTime",
107 "sambaBadPasswordCount");
108 $this->objectclasses= array ("sambaSamAccount");
109 $this->mungedObject= new sambaMungedDial;
110 $this->ctxattributes= $this->mungedObject->ctxattributes;
112 plugin::plugin ($config, $dn);
114 /* Setting uid to default */
115 if(isset($this->attrs['uid'][0])){
116 $this->uid = $this->attrs['uid'][0];
117 }
119 /* Get samba Domain in case of samba 3 */
120 if ($this->sambaSID != ""){
121 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
122 $ldap= $this->config->get_ldap_link();
123 $ldap->cd($this->config->current['BASE']);
124 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
125 if ($ldap->count() != 0){
126 $attrs= $ldap->fetch();
127 if(isset($attrs['sambaAlgorithmicRidBase'])){
128 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
129 } else {
130 $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
131 }
132 if ($this->sambaDomainName == ""){
133 $this->sambaDomainName= $attrs['sambaDomainName'][0];
134 }
135 } else {
136 if ($this->sambaDomainName == ""){
137 $this->sambaDomainName= "DEFAULT";
138 }
139 $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
140 $this->SID= $this->config->get_cfg_value("sambaSid");
141 }
143 /* Save in order to compare later on */
144 $this->orig_sambaDomainName= $this->sambaDomainName;
145 }
147 /* Fill mungedDial field */
148 if (isset($this->attrs['sambaMungedDial'])){
149 $this->mungedObject->load($this->sambaMungedDial);
150 }
152 /* Password expiery */
153 if(isset($this->attrs['sambaPwdMustChange']) &&
154 $this->attrs['sambaPwdMustChange'][0] != 0){
155 $this->password_expires= 1;
156 }
158 if(isset($this->attrs['sambaLogonTime']) && ! (
159 $this->attrs['sambaLogonTime'][0] == 0 ||
160 $this->attrs['sambaLogonTime'][0] == 2147483647
161 )){
162 $this->logon_time_set= 1;
163 }
164 if(isset($this->attrs['sambaLogoffTime']) && ! (
165 $this->attrs['sambaLogoffTime'][0] == 0 ||
166 $this->attrs['sambaLogoffTime'][0] == 2147483647
167 )){
168 $this->logoff_time_set= 1;
169 }
171 /* Account expiery */
172 if(isset($this->attrs['sambaKickoffTime']) && ! (
173 $this->attrs['sambaKickoffTime'][0] == 0 ||
174 $this->attrs['sambaKickoffTime'][0] == 2147483647
175 )){
176 $this->kickoff_time_set= 1;
177 }
179 /* Get global filter config */
180 if (!session::is_set("sambafilter")){
181 $ui= get_userinfo();
182 $base= get_base_from_people($ui->dn);
183 $sambafilter= array( "depselect" => $base, "regex" => "*");
184 session::set("sambafilter", $sambafilter);
185 }
187 /* Save initial account state */
188 $this->initially_was_account= $this->is_account;
190 /* Convert kickoff */
191 #TODO: use date format
192 $this->sambaKickoffTime= $this->sambaKickoffTime == 0?"":date('d.m.Y', $this->sambaKickoffTime);
193 $this->sambaPwdMustChange= $this->sambaPwdMustChange == 2147483647?"":date('d.m.Y', $this->sambaPwdMustChange);
194 }
196 function execute()
197 {
198 /* Call parent execute */
199 plugin::execute();
201 /* Log view */
202 if($this->is_account && !$this->view_logged){
203 $this->view_logged = TRUE;
204 new log("view","users/".get_class($this),$this->dn);
205 }
207 /* Do we need to flip is_account state? */
208 if (isset($_POST['modify_state'])){
209 $this->is_account= !$this->is_account;
210 }
211 /* Do we represent a valid account? */
212 if (!$this->is_account && $this->parent === NULL){
213 $display= "<img alt=\"\"src=\"images/small-error.png\" align=\"middle\"> <b>".
214 msgPool::noValidExtension(_("Samba"))."</b>";
215 $display.= back_to_main();
216 return ($display);
217 }
219 $display ="";
220 if(!$this->multiple_support_active){
222 /* Show tab dialog headers */
223 $display= "";
224 if ($this->parent !== NULL){
225 if ($this->is_account){
226 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Samba")),
227 msgPool::featuresEnabled(_("Samba")));
228 } else {
229 $obj= $this->parent->by_object['posixAccount'];
231 /* Samba3 dependency on posix accounts are enabled
232 in the moment, because I need to rely on unique
233 uidNumbers. There'll be a better solution later
234 on. */
235 if ($obj->is_account){
236 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
237 msgPool::featuresDisabled(_("Samba")));
238 } else {
239 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
240 msgPool::featuresDisabled(_("Samba"), _("POSIX")), TRUE);
241 }
242 return ($display);
243 }
244 }
245 }
247 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
249 /* Open Samaba Logong hours dialog */
250 if(isset($_POST['SetSambaLogonHours']) && $this->acl_is_readable("sambaLogonHours")){
251 $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
252 }
254 /* Cancel dialog */
255 if(isset($_POST['cancel_logonHours'])){
256 $this->dialog = FALSE;
257 }
259 /* Save selected logon hours */
260 if(isset($_POST['save_logonHours'])){
261 $this->dialog->save_object();
262 if($this->acl_is_writeable("sambaLogonHours")){
263 $this->sambaLogonHours = $this->dialog->save();
264 }
265 $this->dialog = FALSE;
266 }
268 /* Display dialog */
269 if((isset($this->dialog)) && (is_object($this->dialog))){
270 $this->dialog->save_object();
271 return($this->dialog->execute());
272 }
274 /* Prepare templating */
275 $smarty= get_smarty();
276 $smarty->assign("usePrototype", "true");
278 $tmp = $this->plInfo();
279 foreach($tmp['plProvidedAcls'] as $var => $rest){
280 $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
281 }
283 if(!session::is_set('edit') && !isset($this->parent)){
284 $smarty->assign("sambaLogonHoursACL","");
285 }
287 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
288 $sambaLogonTime_date= getdate();
289 } else {
290 $sambaLogonTime_date= getdate($this->sambaLogonTime);
291 }
293 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
294 $sambaLogoffTime_date= getdate();
295 } else {
296 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
297 }
299 /* Remove user workstations? */
300 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
302 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
304 if($this->multiple_support_active){
305 foreach($_POST['workstation_list'] as $name){
306 if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
307 unset($this->multiple_sambaUserWorkstations[trim($name)]);
308 }
309 }
310 }else{
311 $tmp= $this->sambaUserWorkstations;
312 foreach($_POST['workstation_list'] as $name){
313 $tmp= preg_replace("/$name/", '', $tmp);
314 $this->is_modified= TRUE;
315 }
316 $tmp= preg_replace('/,+/', ',', $tmp);
317 $this->sambaUserWorkstations= trim($tmp, ',');
318 }
319 }
320 }
322 /* Add user workstation? */
323 if (isset($_POST["add_ws"])){
324 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
325 $this->show_ws_dialog= TRUE;
326 $this->dialog= TRUE;
327 }
328 }
330 /* Add user workstation finished? */
331 if (isset($_POST["add_ws_cancel"])){
332 $this->show_ws_dialog= FALSE;
333 $this->dialog= FALSE;
334 }
336 /* Add user workstation? */
337 if (isset($_POST["add_ws_finish"])){
339 if (isset($_POST['wslist'])){
340 if($this->multiple_support_active){
341 foreach($_POST['wslist'] as $ws){
342 $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
343 }
344 }else{
345 $tmp= $this->sambaUserWorkstations;
346 foreach($_POST['wslist'] as $ws){
347 $tmp.= ",$ws";
348 }
349 $tmp= preg_replace('/,+/', ',', $tmp);
350 $this->sambaUserWorkstations= trim($tmp, ',');
351 }
352 $this->is_modified= TRUE;
354 $this->show_ws_dialog= FALSE;
355 $this->dialog= FALSE;
356 } else {
357 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
358 }
359 }
361 /* Show ws dialog */
362 if ($this->show_ws_dialog){
364 /* Save data */
365 $sambafilter= session::get("sambafilter");
366 foreach( array("depselect", "regex") as $type){
367 if (isset($_POST[$type])){
368 $sambafilter[$type]= $_POST[$type];
369 }
370 }
371 if (isset($_GET['search'])){
372 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
373 if ($s == "**"){
374 $s= "*";
375 }
376 $sambafilter['regex']= $s;
377 }
378 session::set("sambafilter", $sambafilter);
380 /* Get workstation list */
381 $exclude= "";
383 if($this->multiple_support_active){
384 foreach($this->multiple_sambaUserWorkstations as $ws){
385 if($ws['UsedByAllUsers']){
386 $exclude.= "(cn=".$ws['Name']."$)";
387 }
388 }
389 }else{
390 foreach(split(',', $this->sambaUserWorkstations) as $ws){
391 $exclude.= "(cn=$ws$)";
392 }
393 }
394 if ($exclude != ""){
395 $exclude= "(!(|$exclude))";
396 }
397 $regex= $sambafilter['regex'];
398 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
399 $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
401 $wslist= array();
402 foreach ($res as $attrs){
403 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
404 }
405 asort($wslist);
407 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
408 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
409 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
410 $smarty->assign("deplist", $this->config->idepartments);
411 $smarty->assign("alphabet", generate_alphabet());
412 foreach( array("depselect", "regex") as $type){
413 $smarty->assign("$type", $sambafilter[$type]);
414 }
415 $smarty->assign("hint", print_sizelimit_warning());
416 $smarty->assign("wslist", $wslist);
417 $smarty->assign("apply", apply_filter());
418 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
419 dirname(__FILE__)));
420 return ($display);
421 }
423 /* Fill boxes */
424 $domains= array();
425 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
426 $domains[]= $name;
427 }
428 $smarty->assign("domains", $domains);
429 $letters= array("");
430 for ($i= 68; $i<91; $i++){
431 $letters[]= chr($i).":";
432 }
433 $smarty->assign("drives", $letters);
435 /* Fill terminal server settings */
436 foreach ($this->ctxattributes as $attr){
437 /* Fill common attributes */
438 if (isset($this->mungedObject->ctx[$attr])){
439 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
440 // Set field to blank if value is 0
441 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
442 if($this->mungedObject->ctx[$attr] == 0) {
443 $smarty->assign("$attr", "");
444 }
445 }
446 } else {
447 $smarty->assign("$attr", "");
448 }
449 }
451 /* Assign enum values for preset items */
452 $shadowModeVals= array( "0" => _("disabled"),
453 "1" => _("input on, notify on"),
454 "2" => _("input on, notify off"),
455 "3" => _("input off, notify on"),
456 "4" => _("input off, nofify off"));
458 $brokenConnModeVals= array( "0" => _("disconnect"),
459 "1" => _("reset"));
461 $reConnModeVals= array( "0" => _("from any client"),
462 "1" => _("from previous client only"));
464 /* Fill preset items */
465 $smarty->assign("shadow", $shadowModeVals);
466 $smarty->assign("brokenconn", $brokenConnModeVals);
467 $smarty->assign("reconn", $reConnModeVals);
469 /* Fill preset items with values */
470 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
471 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
472 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
474 if(session::get('js')){
475 /* Set form elements to disabled/enable state */
476 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
478 $smarty->assign("inheritstate", "");
479 if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
480 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
481 }
482 }else{
483 $smarty->assign("tsloginstate", "");
484 $smarty->assign("inheritstate", "");
485 }
487 /* Set checkboxes to checked or unchecked state */
488 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
489 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
490 $smarty->assign("connectclientdrives",
491 $this->mungedObject->getConnectClientDrives()?"checked":"");
492 $smarty->assign("connectclientprinters",
493 $this->mungedObject->getConnectClientPrinters()?"checked":"");
494 $smarty->assign("defaultprinter",
495 $this->mungedObject->getDefaultPrinter()?"checked":"");
496 $smarty->assign("CtxMaxConnectionTimeF",
497 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
498 $smarty->assign("CtxMaxDisconnectionTimeF",
499 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
500 $smarty->assign("CtxMaxIdleTimeF",
501 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
504 /* Fill sambaUserWorkstations */
505 $ws= split(",", $this->sambaUserWorkstations);
506 sort($ws);
508 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
509 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
511 if($this->multiple_support_active){
512 $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
513 }
515 $smarty->assign("workstations", $ws);
518 /* Variables */
519 foreach($this->attributes as $val){
520 $smarty->assign("$val", $this->$val);
521 }
523 /* 'sambaAcctFlags' checkboxes */
524 /* Check for 'lock-account'-flag: 'D' or 'L' */
525 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
526 is_integer(strpos($this->sambaAcctFlags, "L"))) {
527 $smarty->assign("flagsD", "checked");
528 } else {
529 $smarty->assign("flagsD", "");
530 }
532 /* Check for no_password_required flag 'N' */
533 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
534 $smarty->assign("flagsN", "checked");
535 } else {
536 $smarty->assign("flagsN", "");
537 }
539 // check if password never expires
540 if (is_integer(strpos($this->sambaAcctFlags, "X"))) {
541 $smarty->assign("flagsX", "checked");
542 } else {
543 $smarty->assign("flagsX", "");
544 }
546 if ($this->sambaPwdCanChange=="1"){
547 $smarty->assign("flagsP", "checked");
548 } else {
549 $smarty->assign("flagsP", "");
550 }
552 if ($this->password_expires=="1"){
553 $smarty->assign("flagsC", "checked");
554 } else {
555 $smarty->assign("flagsC", "");
556 }
557 if ($this->logon_time_set=="1"){
558 $smarty->assign("flagsT", "checked");
559 } else {
560 $smarty->assign("flagsT", "");
561 }
562 if ($this->logoff_time_set=="1"){
563 $smarty->assign("flagsO", "checked");
564 } else {
565 $smarty->assign("flagsO", "");
566 }
567 if ($this->kickoff_time_set=="1"){
568 $smarty->assign("flagsK", "checked");
569 } else {
570 $smarty->assign("flagsK", "");
571 }
574 /* In case of javascript, disable some fields on demand */
575 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
576 $smarty->assign("$key", "$value");
577 }
580 foreach($this->attributes as $attr){
581 if(in_array($attr,$this->multi_boxes)){
582 $smarty->assign("use_".$attr,TRUE);
583 }else{
584 $smarty->assign("use_".$attr,FALSE);
585 }
586 }
587 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
588 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
589 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
590 "onnectclientprinters","defaultprinter","shadow","brokenconn",
591 "reconn","allow_pwchange","connectclientprinters","no_expiry","no_password_required","temporary_disable",
592 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
593 "workstation_list") as $attr){
594 if(in_array($attr,$this->multi_boxes)){
595 $smarty->assign("use_".$attr,TRUE);
596 }else{
597 $smarty->assign("use_".$attr,FALSE);
598 }
599 }
601 if($this->multiple_support_active){
602 $smarty->assign("tsloginstate","");
603 }
605 /* Create additional info for sambaKickOffTime and sambaPwdMustChange.
606 e.g. Display effective kickoff time. Domain policy + user settings.
607 */
608 $additional_info_PwdMustChange = "";
610 /* Calculate effective max Password Age
611 This can only be calculated if sambaPwdLastSet ist set.
612 */
613 if(isset($this->attrs['sambaPwdLastSet'][0])){
614 $last = $this->attrs['sambaPwdLastSet'][0];
616 $sid = $this->get_domain_info();
617 if(isset($sid['sambaMaxPwdAge'][0])){
618 $d = ($last + $sid['sambaMaxPwdAge'][0]) - time();
620 /* A negative value means the password is outdated
621 */
622 if($d < 0){
623 $additional_info_PwdMustChange = sprintf(_("The password is outdated since %s, by domain policy."),
624 date("d.m.Y H:i:s",$last + $sid['sambaMaxPwdAge'][0]));
625 }else{
626 if($this->password_expires && ($last + $sid['sambaMaxPwdAge'][0]) > $this->sambaPwdMustChange){
627 $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by user policy."),
628 date("d.m.Y H:i:s", $this->sambaPwdMustChange));
629 }else{
630 $additional_info_PwdMustChange = sprintf(_("The password is valid till %s, by domain policy."),
631 date("d.m.Y H:i:s", ($last + $sid['sambaMaxPwdAge'][0])));
632 }
633 }
634 }
635 }
636 $smarty->assign("additional_info_PwdMustChange",$additional_info_PwdMustChange);
637 $smarty->assign("no_expiry",$this->no_expiry);
639 /* Show main page */
640 $smarty->assign("multiple_support",$this->multiple_support_active);
641 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
643 return ($display);
644 }
647 /*! \brief Returns the samba Domain object, selected in the samba tab.
648 */
649 function get_domain_info()
650 {
651 /* Only search once, return last result if available
652 */
653 if(!isset($this->cache['DOMAIN'][$this->sambaDomainName])){
654 $this->cache['DOMAIN'][$this->sambaDomainName] = array();
655 if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
656 $cfg = $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName];
657 $ldap = $this->config->get_ldap_link();
658 $ldap->cd($this->config->current['BASE']);
659 $ldap->search("(&(objectClass=sambaDomain)(sambaSID=".$cfg['SID']."))",array("*"));
660 if($ldap->count()){
661 $this->cache['DOMAIN'][$this->sambaDomainName] = $ldap->fetch();
662 }
663 }
664 }
665 return($this->cache['DOMAIN'][$this->sambaDomainName]);
666 }
670 function get_samba_information()
671 {
673 /* Defaults
674 */
675 $sambaMinPwdLength = "unset";
676 $sambaPwdHistoryLength = "unset";
677 $sambaLogonToChgPwd = "unset";
678 $sambaMaxPwdAge = "unset";
679 $sambaMinPwdAge = "unset";
680 $sambaLockoutDuration = "unset";
681 $sambaLockoutThreshold = "unset";
682 $sambaForceLogoff = "unset";
683 $sambaRefuseMachinePwdChange = "unset";
684 $sambaPwdLastSet = "unset";
685 $sambaLogonTime = "unset";
686 $sambaLogoffTime = "unset";
688 $sambaKickoffTime = "unset";
689 $sambaPwdCanChange = "unset";
690 $sambaPwdMustChange = "unset";
691 $sambaBadPasswordCount = "unset";
692 $sambaBadPasswordTime = "unset";
694 /* Domain attributes
695 */
696 $domain_attributes = array("sambaMinPwdLength","sambaPwdHistoryLength","sambaMaxPwdAge",
697 "sambaMinPwdAge","sambaLockoutDuration","sambaRefuseMachinePwdChange",
698 "sambaLogonToChgPwd","sambaLockoutThreshold","sambaForceLogoff");
700 /* User attributes
701 */
702 $user_attributes = array("sambaBadPasswordTime","sambaPwdLastSet","sambaLogonTime","sambaLogoffTime",
703 "sambaKickoffTime","sambaPwdCanChange","sambaPwdMustChange","sambaBadPasswordCount", "sambaSID");
705 /* Get samba SID object and parse settings.
706 */
707 $ldap = $this->config->get_ldap_link();
708 $ldap->cd($this->config->current['BASE']);
709 if(!empty($this->sambaDomainName) && isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName])){
710 $attrs = $this->get_domain_info();
711 foreach($domain_attributes as $attr){
712 if(isset($attrs[$attr])){
713 $$attr = $attrs[$attr][0];
714 }
715 }
716 }
718 /* Get user infos
719 */
720 foreach($user_attributes as $attr){
721 if(isset($this->attrs[$attr])){
722 $$attr = $this->attrs[$attr][0];
723 }
724 }
725 if($this->password_expires){
726 $sambaPwdMustChange = $this->sambaPwdMustChange;
727 } else {
728 if (is_numeric($sambaPwdMustChange)) {
729 $sambaPwdMustChange= date('d.m.Y', $sambaPwdMustChange);
730 }
731 }
732 if($this->kickoff_time_set){
733 $sambaKickoffTime = $this->sambaKickoffTime;
734 } else {
735 if (is_numeric($sambaKickoffTime)) {
736 $sambaKickoffTime= date('d.m.Y', $sambaKickoffTime);
737 }
738 }
739 $sambaPwdCanChange = $this->sambaPwdCanChange;
742 /* DOMAIN Attributes
743 */
745 /* sambaMinPwdLength: Password length has a default of 5
746 */
747 if($sambaMinPwdLength == "unset" || $sambaMinPwdLength == 5){
748 $sambaMinPwdLength = "5 <i>("._("default").")</i>";
749 }
751 /* sambaPwdHistoryLength: Length of Password History Entries (default: 0 => off)
752 */
753 if($sambaPwdHistoryLength == "unset" || $sambaPwdHistoryLength == 0){
754 $sambaPwdHistoryLength = _("Off")." <i>("._("default").")</i>";
755 }
757 /* sambaLogonToChgPwd: Force Users to logon for password change (default: 0 => off, 2 => on)
758 */
759 if($sambaLogonToChgPwd == "unset" || $sambaLogonToChgPwd == 0){
760 $sambaLogonToChgPwd = _("Off")." <i>("._("default").")</i>";
761 }else{
762 $sambaLogonToChgPwd = _("On");
763 }
765 /* sambaMaxPwdAge: Maximum password age, in seconds (default: -1 => never expire passwords)'
766 */
767 if($sambaMaxPwdAge == "unset" || $sambaMaxPwdAge == "-1"){
768 $sambaMaxPwdAge = _("disabled")." <i>("._("default").")</i>";
769 }else{
770 $sambaMaxPwdAge .= " "._("seconds");
771 }
773 /* sambaMinPwdAge: Minimum password age, in seconds (default: 0 => allow immediate password change
774 */
775 if($sambaMinPwdAge == "unset" || $sambaMinPwdAge == 0){
776 $sambaMinPwdAge = _("disabled")." <i>("._("default").")</i>";
777 }else{
778 $sambaMinPwdAge .= " "._("seconds");
779 }
781 /* sambaLockoutDuration: Lockout duration in minutes (default: 30, -1 => forever)
782 */
783 if($sambaLockoutDuration == "unset" || $sambaLockoutDuration == 30){
784 $sambaLockoutDuration = "30 "._("minutes")." <i>("._("default").")</i>";
785 }elseif($sambaLockoutDuration == -1){
786 $sambaLockoutDuration = _("forever");
787 }else{
788 $sambaLockoutDuration .= " "._("minutes");
789 }
791 /* sambaLockoutThreshold: Lockout users after bad logon attempts (default: 0 => off
792 */
793 if($sambaLockoutThreshold == "unset" || $sambaLockoutThreshold == 0){
794 $sambaLockoutThreshold = _("disabled")." <i>("._("default").")</i>";
795 }
797 /* sambaForceLogoff: Disconnect Users outside logon hours (default: -1 => off, 0 => on
798 */
799 if($sambaForceLogoff == "unset" || $sambaForceLogoff == -1){
800 $sambaForceLogoff = _("off")." <i>("._("default").")</i>";
801 }else{
802 $sambaForceLogoff = _("on");
803 }
805 /* sambaRefuseMachinePwdChange: Allow Machine Password changes (default: 0 => off
806 */
807 if($sambaRefuseMachinePwdChange == "none" || $sambaRefuseMachinePwdChange == 0){
808 $sambaRefuseMachinePwdChange = _("off")." <i>("._("default").")</i>";
809 }else{
810 $sambaRefuseMachinePwdChange = _("on");
811 }
813 /* USER Attributes
814 */
815 /* sambaBadPasswordTime: Time of the last bad password attempt
816 */
817 if($sambaBadPasswordTime == "unset" || empty($sambaBadPasswordTime)){
818 $sambaBadPasswordTime = "<i>("._("unset").")</i>";
819 }else{
820 $sambaBadPasswordTime = date("d.m.Y H:i:s",$sambaBadPasswordTime);
821 }
823 /* sambaBadPasswordCount: Bad password attempt count
824 */
825 if($sambaBadPasswordCount == "unset" || empty($sambaBadPasswordCount)){
826 $sambaBadPasswordCount = "<i>("._("unset").")</i>";
827 }else{
828 $sambaBadPasswordCount = date("d.m.Y H:i:s",$sambaBadPasswordCount);
829 }
831 /* sambaPwdLastSet: Timestamp of the last password update
832 */
833 if($sambaPwdLastSet == "unset" || empty($sambaPwdLastSet)){
834 $sambaPwdLastSet = "<i>("._("unset").")</i>";
835 }else{
836 $sambaPwdLastSet = date("d.m.Y H:i:s",$sambaPwdLastSet);
837 }
839 /* sambaLogonTime: Timestamp of last logon
840 */
841 if($sambaLogonTime == "unset" || empty($sambaLogonTime)){
842 $sambaLogonTime = "<i>("._("unset").")</i>";
843 }else{
844 $sambaLogonTime = date("d.m.Y H:i:s",$sambaLogonTime);
845 }
847 /* sambaLogoffTime: Timestamp of last logoff
848 */
849 if($sambaLogoffTime == "unset" || empty($sambaLogoffTime)){
850 $sambaLogoffTime = "<i>("._("unset").")</i>";
851 }else{
852 $sambaLogoffTime = date("d.m.Y H:i:s",$sambaLogoffTime);
853 }
855 /* sambaKickoffTime: Timestamp of when the user will be logged off automatically
856 */
857 if($sambaKickoffTime == "unset" || empty($sambaKickoffTime)){
858 $sambaKickoffTime = "<i>("._("unset").")</i>";
859 }
861 /* sambaPwdMustChange: Timestamp of when the password will expire
862 */
863 if($sambaPwdMustChange == "unset" || empty($sambaPwdMustChange)){
864 $sambaPwdMustChange = "<i>("._("unset").")</i>";
865 }
867 /* sambaPwdCanChange: Timestamp of when the user is allowed to update the password
868 */
869 if($sambaPwdCanChange == "unset" || empty($sambaPwdCanChange)){
870 $sambaPwdCanChange = "<i>("._("unset").")</i>";
871 }elseif($sambaPwdCanChange != "unset" && time() > $sambaPwdCanChange){
872 $sambaPwdCanChange = _("immediately") ;
873 }else{
874 $days = floor((($sambaPwdCanChange - time()) / 60 / 60 / 24)) ;
875 $hours = floor((($sambaPwdCanChange - time()) / 60 / 60) % 24) ;
876 $minutes = floor((($sambaPwdCanChange - time()) / 60 ) % 60) ;
878 $sambaPwdCanChange = " ".$days." "._("days");
879 $sambaPwdCanChange.= " ".$hours." "._("hours");
880 $sambaPwdCanChange.= " ".$minutes." "._("minutes");
881 }
883 $str =
884 "\n<div style='height:200px; overflow: auto;'>".
885 "\n<table style='width:100%;'>".
886 "\n<tr><td><b>"._("Domain attributes")."</b></td></tr>".
887 "\n<tr><td>"._("Min password length").": </td><td>".$sambaMinPwdLength."</td></tr>".
888 "\n<tr><td>"._("Min password length").": </td><td>".$sambaMinPwdLength."</td></tr>".
889 "\n<tr><td>"._("Password history").": </td><td>".$sambaPwdHistoryLength."</td></tr>".
890 "\n<tr><td>"._("Force password change").": </td><td>".$sambaLogonToChgPwd."</td></tr>".
891 "\n<tr><td>"._("Maximum password age").": </td><td>".$sambaMaxPwdAge."</td></tr>".
892 "\n<tr><td>"._("Minimum password age").": </td><td>".$sambaMinPwdAge."</td></tr>".
893 "\n<tr><td>"._("Lockout duration").": </td><td>".$sambaLockoutDuration."</td></tr>".
894 "\n<tr><td>"._("Bad lockout attempt").": </td><td>".$sambaLockoutThreshold."</td></tr>".
895 "\n<tr><td>"._("Disconnect time").": </td><td>".$sambaForceLogoff."</td></tr>".
896 "\n<tr><td>"._("Refuse machine password change").":</td><td>".$sambaRefuseMachinePwdChange."</td></tr>".
897 "\n<tr><td> </td></tr>".
898 "\n<tr><td><b>"._("User attributes")."</b></td></tr>".
899 "\n<tr><td>"._("SID").": </td><td>".$sambaSID."</td></tr>".
900 "\n<tr><td>"._("Last failed login").": </td><td>".$sambaBadPasswordTime."</td></tr>".
901 "\n<tr><td>"._("Logon attempts").": </td><td>".$sambaBadPasswordCount."</td></tr>".
902 "\n<tr><td>"._("Last password update").": </td><td>".$sambaPwdLastSet."</td></tr>".
903 "\n<tr><td>"._("Last logon").": </td><td>".$sambaLogonTime."</td></tr>".
904 "\n<tr><td>"._("Last logoff").": </td><td>".$sambaLogoffTime."</td></tr>".
905 "\n<tr><td>"._("Automatic logoff").": </td><td>".$sambaKickoffTime."</td></tr>";
907 if($this->no_expiry){
908 $str .= "\n<tr><td>"._("Password expires").": </td><td>"._("No")."</td></tr>";
909 $str .= "\n<tr><td colspan='2'><font color='gray'>".
910 sprintf(_("The password would expire on %s, but the password expiry is disabled."),$sambaPwdMustChange).
911 "</font></td></tr>";
912 }else{
913 $str .= "\n<tr><td>"._("Password expires").": </td><td>".$sambaPwdMustChange."</td></tr>";
914 }
916 $str .= "\n<tr><td>"._("Password change available").": </td><td>".$sambaPwdCanChange."</td></tr>".
917 "\n</table>";
918 "\n</div>";
919 return($str);
920 }
923 function remove_from_parent()
924 {
925 /* Cancel if there's nothing to do here */
926 if (!$this->initially_was_account){
927 return;
928 }
930 /* include global link_info */
931 $ldap= $this->config->get_ldap_link();
933 plugin::remove_from_parent();
935 /* Keep uid attribute for gosaAccount */
936 unset($this->attrs['uid']);
937 unset($this->attrs['uidNumber']);
938 unset($this->attrs['gidNumber']);
940 /* Remove objectClass for sambaIdmapEntry */
941 $tmp= array();
942 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
943 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
944 $tmp[]= $this->attrs['objectClass'][$i];
945 }
946 }
947 $this->attrs['objectClass']= $tmp;
949 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
950 $this->attributes, "Save");
951 $ldap->cd($this->dn);
952 $this->cleanup();
953 $ldap->modify ($this->attrs);
955 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
957 if (!$ldap->success()){
958 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
959 }
961 /* Optionally execute a command after we're done */
962 $this->handle_post_events("remove", array("uid" => $this->uid));
963 }
966 /* Check for input problems */
967 function check()
968 {
969 /* Call common method to give check the hook */
970 $message= plugin::check();
972 /* sambaHomePath requires sambaHomeDrive and vice versa */
973 if(!empty($this->sambaHomePath) && empty($this->sambaHomeDrive)){
974 $message[]= msgPool::required(_("Home drive"));
975 }
976 if(!empty($this->sambaHomeDrive) && empty($this->sambaHomePath)){
977 $message[]= msgPool::required(_("Home path"));
978 }
980 /* Strings */
981 foreach (array( "sambaHomePath" => _("Home directory"),
982 "sambaProfilePath" => _("Profile path")) as $key => $val){
983 if (!$this->mungedObject->is_samba_path($this->$key)){
984 $message[]= msgPool::invalid($val);
985 }
986 }
988 /* Numeric values */
989 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
990 "CtxMaxDisconnectionTime" => _("Disconnection"),
991 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
993 if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
994 $message[]= msgPool::invalid($val);
995 }
996 }
998 /* Check dates */
999 if (!tests::is_date($this->sambaKickoffTime)){
1000 $message[]= msgPool::invalid(_("Account expires after"), $this->sambaKickoffTime,"" ,"23.02.2009");
1001 }
1002 if (!tests::is_date($this->sambaPwdMustChange)){
1003 $message[]= msgPool::invalid(_("Password expires on"), $this->sambaPwdMustChange,"" ,"23.02.2009");
1004 }
1006 /* Too many workstations? Windows usrmgr only supports eight */
1007 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1008 $message[]= _("The windows usermanager allows eight clients at maximum!");
1009 }
1011 return ($message);
1012 }
1015 /* Save data to object */
1016 function save_object()
1017 {
1019 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
1021 /* We only care if we are on the sambaTab... */
1022 if (isset($_POST['sambaTab'])){
1023 plugin::save_object();
1025 if(isset($_POST['display_information'])){
1026 msg_dialog::display(_("Information"),
1027 $this->get_samba_information(),
1028 INFO_DIALOG);
1029 }
1031 /* Take care about access options */
1032 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1033 $attrname= "sambaPwdCanChange";
1034 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
1035 $tmp= 1;
1036 } else {
1037 $tmp= 0;
1038 }
1039 if ($this->$attrname != $tmp){
1040 $this->is_modified= TRUE;
1041 }
1042 $this->pwdCanChange= $tmp;
1043 $this->sambaPwdCanChange= $tmp;
1044 }
1045 $tmp= "U";
1047 $this->no_expiry = FALSE;
1048 if (isset($_POST["no_expiry"])){
1049 if ($_POST["no_expiry"] == 1){
1050 $tmp.= "X";
1051 $this->no_expiry = TRUE;
1052 }
1053 }
1055 $this->no_password_required = FALSE;
1056 if (isset($_POST["no_password_required"])){
1057 if ($_POST["no_password_required"] == 1){
1058 $tmp.= "N";
1059 $this->no_password_required = TRUE;
1060 }
1061 }
1062 if (isset($_POST["password_expires"])){
1063 if ($_POST["password_expires"] == 1){
1064 $this->password_expires= 1;
1065 }
1066 } else {
1067 $this->password_expires= 0;
1068 }
1069 $this->temporary_disable = FALSE;
1070 if (isset($_POST["temporary_disable"])){
1071 if ($_POST["temporary_disable"] == 1){
1072 $this->temporary_disable = TRUE;
1073 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
1074 $tmp.= "L";
1075 } else {
1076 $tmp.= "D";
1077 }
1078 }
1079 }
1080 if (isset($_POST["logon_time_set"])){
1081 if ($_POST["logon_time_set"] == 1){
1082 $this->logon_time_set= 1;
1083 }
1084 } else {
1085 $this->logon_time_set= 0;
1086 }
1087 if (isset($_POST["logoff_time_set"])){
1088 if ($_POST["logoff_time_set"] == 1){
1089 $this->logoff_time_set= 1;
1090 }
1091 } else {
1092 $this->logoff_time_set= 0;
1093 }
1094 if (isset($_POST["kickoff_time_set"])){
1095 if ($_POST["kickoff_time_set"] == 1){
1096 $this->kickoff_time_set= 1;
1097 }
1098 } else {
1099 $this->kickoff_time_set= 0;
1100 }
1102 $fill= "";
1103 for ($i= strlen($tmp); $i<12; $i++){
1104 $fill.= " ";
1105 }
1107 $tmp= "[$tmp$fill]";
1109 /* Only save if acl's are set */
1110 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
1111 $attrname= "sambaAcctFlags";
1112 if ($this->$attrname != $tmp){
1113 $this->is_modified= TRUE;
1114 }
1115 $this->$attrname= $tmp;
1116 }
1118 /* Save sambaDomain attribute */
1119 if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && isset ($_POST['sambaDomainName'],$SkipWrite)){
1120 $this->sambaDomainName= validate($_POST['sambaDomainName']);
1121 }
1123 /* Save CTX values */
1124 /* Save obvious values */
1125 foreach($this->ctxattributes as $val){
1126 if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
1127 if (get_magic_quotes_gpc()) {
1128 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
1129 } else {
1130 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
1131 }
1132 }
1133 }
1135 /* Save checkbox states. */
1136 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
1137 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1138 // Need to do some index checking to avoid messages like "index ... not found"
1139 if(isset($_POST['brokenconn'])) {
1140 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
1141 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1142 }
1143 if(isset($_POST['reconn'])) {
1144 $this->mungedObject->setReConn($_POST['reconn'] == '1'
1145 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1146 }
1147 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
1148 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1149 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
1150 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1151 $this->mungedObject->setCtxMaxDisconnectionTimeF(
1152 !isset($_POST['CtxMaxDisconnectionTimeF'])
1153 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1154 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
1155 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1156 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
1157 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1158 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
1159 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1160 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
1161 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
1163 /* Save combo boxes. Takes two values */
1164 if(isset($_POST['reconn'])) {
1165 $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
1166 }
1168 /* Check for changes */
1169 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
1170 $this->is_modified= TRUE;
1171 }
1173 }
1174 }
1177 /* Save to LDAP */
1178 function save()
1179 {
1180 /* Load uid and gid of this 'dn' */
1181 $ldap= $this->config->get_ldap_link();
1182 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
1183 $tmp= $ldap->fetch();
1184 $this->uidNumber= $tmp['uidNumber'][0];
1185 $this->gidNumber= $tmp['gidNumber'][0];
1187 plugin::save();
1189 /* Remove objectClass for sambaIdmapEntry */
1190 $tmp= array();
1191 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
1192 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
1193 $tmp[]= $this->attrs['objectClass'][$i];
1194 }
1195 }
1196 $this->attrs['objectClass']= $tmp;
1198 /* Generate rid / primaryGroupId */
1199 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
1200 msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
1201 } else {
1202 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
1203 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
1204 }
1206 /* Need to generate a new uniqe uid/gid combination? */
1207 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
1208 $uidNumber= $this->uidNumber;
1209 while(TRUE){
1210 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
1211 $ldap->cd($this->config->current['BASE']);
1212 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
1213 if ($ldap->count() == 0){
1214 break;
1215 }
1216 $uidNumber++;
1217 }
1218 $this->attrs['sambaSID']= $sid;
1220 /* Check for users primary group */
1221 $ldap->cd($this->config->current['BASE']);
1222 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
1223 if ($ldap->count() != 1){
1224 msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
1225 } else {
1226 $attrs= $ldap->fetch();
1227 $g= new group($this->config, $ldap->getDN());
1228 if ($g->sambaSID == ""){
1229 $g->sambaDomainName= $this->sambaDomainName;
1230 $g->smbgroup= TRUE;
1231 $g->save ();
1232 }
1233 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
1234 }
1235 }
1237 if ($this->sambaHomeDrive == ""){
1238 $this->attrs["sambaHomeDrive"]= array();
1239 }
1241 /* Generate munged dial value */
1242 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1244 /* User wants me to fake the idMappings? This is useful for
1245 making winbind resolve the user names in a reasonable amount
1246 of time in combination with larger databases. */
1247 if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1248 $this->attrs['objectClass'][]= "sambaIdmapEntry";
1249 }
1252 /* Password expiery */
1253 if ($this->password_expires == "1"){
1254 #TODO: check for date format
1255 if ($this->attrs['sambaPwdMustChange'] == ""){
1256 $this->attrs['sambaPwdMustChange']= 0;
1257 } else {
1258 list($day, $month, $year)= split('\.', $this->sambaPwdMustChange);
1259 $this->attrs['sambaPwdMustChange']= mktime(0,0,0,$month, $day, $year);
1260 }
1261 } else {
1262 $this->attrs['sambaPwdMustChange']= array();
1263 }
1264 /* Make sure not to save zero in sambaPwdLastset */
1265 if ($this->sambaPwdLastSet != "0"){
1266 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1267 } else {
1268 $this->attrs['sambaPwdLastSet']= array();
1269 }
1270 /* Account expiery */
1271 if ($this->logon_time_set == "1"){
1272 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1273 } else {
1274 $this->attrs['sambaLogonTime']= array();
1275 }
1276 if ($this->logoff_time_set == "1"){
1277 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1278 } else {
1279 $this->attrs['sambaLogoffTime']= array();
1280 }
1281 if ($this->kickoff_time_set == "1"){
1282 /* Adapt values to be timestamps */
1283 #TODO: check for date format
1284 if ($this->attrs['sambaKickoffTime'] == ""){
1285 $this->attrs['sambaKickoffTime']= 2147483647;
1286 } else {
1287 list($day, $month, $year)= split('\.', $this->sambaKickoffTime);
1288 $this->attrs['sambaKickoffTime']= mktime(0,0,0,$month, $day, $year);
1289 }
1290 } else {
1291 $this->attrs['sambaKickoffTime']= array();
1292 }
1294 /* Write back to ldap */
1295 $ldap->cd($this->dn);
1296 $this->cleanup();
1297 $ldap->modify ($this->attrs);
1299 if($this->initially_was_account){
1300 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1301 }else{
1302 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1303 }
1305 if (!$ldap->success()){
1306 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1307 }
1309 /* Optionally execute a command after we're done */
1310 if ($this->initially_was_account == $this->is_account){
1311 if ($this->is_modified){
1312 $this->handle_post_events("modify", array("uid" => $this->uid));
1313 }
1314 } else {
1315 $this->handle_post_events("add", array("uid" => $this->uid));
1316 }
1317 }
1320 /* Force password set, if this account doesn't have any samba passwords */
1321 function password_change_needed()
1322 {
1323 if(!$this->initially_was_account && $this->is_account){
1324 $ldap = $this->config->get_ldap_link();
1325 $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1326 $attrs = $ldap->fetch();
1327 if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1328 return(TRUE);
1329 }
1330 }
1331 return(FALSE);
1332 }
1335 function adapt_from_template($dn, $skip= array())
1336 {
1337 plugin::adapt_from_template($dn, $skip);
1340 $this->sambaSID= "";
1341 $this->sambaPrimaryGroupSID= "";
1343 /* Fill mungedDial field */
1344 if (isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1345 $this->mungedObject->load($this->sambaMungedDial);
1346 }
1348 /* Adapt munged attributes */
1349 foreach($this->ctxattributes as $attr){
1350 if(isset($this->mungedObject->ctx[$attr]))
1351 $val = $this->mungedObject->ctx[$attr];
1353 foreach (array("sn", "givenName", "uid") as $repl){
1354 if (preg_match("/%$repl/i", $val)){
1355 $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1356 }
1357 }
1358 $this->mungedObject->ctx[$attr] = $val;
1359 }
1361 /* Password expiery */
1362 if(isset($this->attrs['sambaPwdMustChange']) &&
1363 $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1364 $this->password_expires= 1;
1365 }
1367 if(isset($this->attrs['sambaLogonTime']) && ! (
1368 $this->attrs['sambaLogonTime'][0] == 0 ||
1369 $this->attrs['sambaLogonTime'][0] == 2147483647
1370 ) && !in_array('sambaLogonTime', $skip)){
1371 $this->logon_time_set= 1;
1372 }
1373 if(isset($this->attrs['sambaLogoffTime']) && ! (
1374 $this->attrs['sambaLogoffTime'][0] == 0 ||
1375 $this->attrs['sambaLogoffTime'][0] == 2147483647
1376 ) && !in_array('sambaLogonTime', $skip)){
1377 $this->logoff_time_set= 1;
1378 }
1380 /* Account expiery */
1381 if(isset($this->attrs['sambaKickoffTime']) && ! (
1382 $this->attrs['sambaKickoffTime'][0] == 0 ||
1383 $this->attrs['sambaKickoffTime'][0] == 2147483647
1384 ) && !in_array('sambaKickoffTime', $skip)){
1385 $this->kickoff_time_set= 1;
1386 }
1388 /* Get global filter config */
1389 if (!session::is_set("sambafilter")){
1390 $ui= get_userinfo();
1391 $base= get_base_from_people($ui->dn);
1392 $sambafilter= array( "depselect" => $base, "regex" => "*");
1393 session::set("sambafilter", $sambafilter);
1394 }
1395 }
1398 static function plInfo()
1399 {
1400 return (array(
1401 "plShortName" => _("Samba"),
1402 "plDescription" => _("Samba settings"),
1403 "plSelfModify" => TRUE,
1404 "plDepends" => array("user"),
1405 "plPriority" => 5,
1406 "plSection" => array("personal" => _("My account")),
1407 "plCategory" => array("users"),
1408 "plOptions" => array(),
1410 "plProvidedAcls" => array(
1412 "sambaHomePath" => _("Generic home directory") ,
1413 "sambaHomeDrive" => _("Generic samba home drive") ,
1414 "sambaDomainName" => _("Domain") ,
1415 "sambaLogonScript" => _("Generic script path") ,
1416 "sambaProfilePath" => _("Generic profile path") ,
1417 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1418 "InheritClientConfig" => _("Inherit client config"),
1419 "sambaPwdCanChange" => _("Allow user to change password") ,
1420 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1421 "sambaAcctFlagsX" => _("Password never expires"),
1422 "sambaAcctFlagsL" => _("Lock samba account"),
1423 "sambaKickoffTime" => _("Account expires") ,
1424 "sambaPwdMustChange" => _("Password expires") ,
1425 "sambaLogonTime" => _("Limit Logon Time") ,
1426 "sambaLogoffTime" => _("Limit Logoff Time") ,
1427 "sambaLogonHours" => _("Logon hours") ,
1428 "sambaUserWorkstations" => _("Allow connection from"))
1429 ));
1430 }
1432 function enable_multiple_support()
1433 {
1434 plugin::enable_multiple_support();
1435 $this->multiple_support_active = TRUE;
1436 }
1438 function multiple_save_object()
1439 {
1440 if (isset($_POST['sambaTab'])){
1441 $this->save_object();
1442 plugin::multiple_save_object();
1443 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1444 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1445 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1446 "onnectclientprinters","defaultprinter","shadow","brokenconn",
1447 "reconn","allow_pwchange","connectclientprinters","no_expiry","no_password_required","temporary_disable",
1448 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1449 "workstation_list") as $attr){
1450 if(isset($_POST["use_".$attr])){
1451 $this->multi_boxes[] = $attr;
1452 }
1453 }
1454 }
1455 }
1458 function multiple_check()
1459 {
1460 $message = plugin::multiple_check();
1462 /* Strings */
1463 foreach (array( "sambaHomePath" => _("Home directory"),
1464 "sambaProfilePath" => _("Profile path")) as $key => $val){
1465 if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1466 $message[]= msgPool::invalid($val);
1467 }
1468 }
1470 /* Numeric values */
1471 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
1472 "CtxMaxDisconnectionTime" => _("Disconnection"),
1473 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
1474 if (in_array($key,$this->multi_boxes) &&
1475 isset($this->mungedObject->ctx[$key]) &&
1476 !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1477 $message[]=msgPool::invalid($val);
1478 }
1479 }
1481 /* Too many workstations? Windows usrmgr only supports eight */
1482 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1483 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1484 }
1485 return($message);
1486 }
1489 function get_multi_init_values()
1490 {
1491 $ret = plugin::get_multi_init_values();
1493 /* Parse given sambaUserWorkstations into array
1494 * to allow "init_multiple_support()" to detect multiple used workstations.
1495 * Those workstations will be displayed in light grey.
1496 */
1497 $tmp2 = array("count" => 0);
1498 $tmp = split(",", $this->sambaUserWorkstations);
1499 foreach($tmp as $station){
1500 $station = trim($station);
1501 if(!empty($station)){
1502 $tmp2[] = $station;
1503 $tmp2['count'] ++;
1504 }
1505 }
1506 $ret['sambaUserWorkstations'] = $tmp2;
1507 return($ret);
1508 }
1512 function init_multiple_support($attrs,$all)
1513 {
1514 plugin::init_multiple_support($attrs,$all);
1516 $this->multiple_sambaUserWorkstations = array();
1517 if(isset($all['sambaUserWorkstations'])){
1518 for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1519 $station = trim($all['sambaUserWorkstations'][$i]);
1520 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1521 }
1522 }
1523 if(isset($attrs['sambaUserWorkstations'])){
1524 for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1525 $station = trim($attrs['sambaUserWorkstations'][$i]);
1526 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1527 }
1528 }
1529 }
1531 function multiple_execute()
1532 {
1533 return($this->execute());
1534 }
1536 function get_multi_edit_values()
1537 {
1538 $ret = plugin::get_multi_edit_values();
1540 /* Terminal Server */
1541 if(in_array("tslogin",$this->multi_boxes)){
1542 $ret['tslogin'] = $this->mungedObject->getTsLogin();
1543 }
1544 if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1545 $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1546 }
1547 if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1548 $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1549 }
1550 if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1551 $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1552 }
1554 if(in_array("inherit",$this->multi_boxes)){
1555 $ret['inherit'] = $this->mungedObject->getInheritMode();
1556 }
1557 if(in_array("CtxInitialProgram",$this->multi_boxes)){
1558 $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1559 }
1560 if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1561 $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1562 }
1564 /* Time Limits. Be careful here, there are some negations */
1565 if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1566 $ret["CtxMaxConnectionTimeF"] = !$this->mungedObject->getCtxMaxConnectionTimeF();
1567 if(!$ret["CtxMaxConnectionTimeF"]){
1568 $ret["CtxMaxConnectionTime"] = $this->mungedObject->ctx['CtxMaxConnectionTime'];
1569 }
1570 }
1571 if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1572 $ret["CtxMaxDisconnectionTimeF"]= !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1573 if(!$ret["CtxMaxDisconnectionTimeF"]){
1574 $ret["CtxMaxDisconnectionTime"]= $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1575 }
1576 }
1577 if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1578 $ret["CtxMaxIdleTimeF"] = !$this->mungedObject->getCtxMaxIdleTimeF();
1579 if(!$ret["CtxMaxIdleTimeF"]){
1580 $ret["CtxMaxIdleTime"] = $this->mungedObject->ctx['CtxMaxIdleTime'];
1581 }
1582 }
1584 /* Client Devices */
1585 if(in_array("connectclientdrives",$this->multi_boxes)){
1586 $ret["connectclientdrives"] = $this->mungedObject->getConnectClientDrives();
1587 }
1588 if(in_array("connectclientprinters",$this->multi_boxes)){
1589 $ret["connectclientprinters"] = $this->mungedObject->getConnectClientPrinters();
1590 }
1591 if(in_array("defaultprinter",$this->multi_boxes)){
1592 $ret["defaultprinter"] = $this->mungedObject->getDefaultPrinter();
1593 }
1595 /* Misc */
1596 if(in_array("shadow",$this->multi_boxes)){
1597 $ret["shadow"] =$this->mungedObject->getShadow();
1598 }
1599 if(in_array("brokenconn",$this->multi_boxes)){
1600 $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1601 }
1602 if(in_array("reconn",$this->multi_boxes)){
1603 $ret["reconn"] =$this->mungedObject->getReConn();
1604 }
1606 /* Flags */
1607 if(in_array("allow_pwchange",$this->multi_boxes)){
1608 $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1609 $ret['pwdCanChange'] = $this->pwdCanChange;
1610 }
1612 if(in_array("password_expires",$this->multi_boxes)){
1613 $ret['password_expires'] = $this->password_expires;
1614 $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1615 }
1616 if(in_array("logon_time_set",$this->multi_boxes)){
1617 $ret['logon_time_set'] = $this->logon_time_set;
1618 $ret['sambaLogonTime'] = $this->sambaLogonTime;
1619 }
1620 if(in_array("logoff_time_set",$this->multi_boxes)){
1621 $ret['logoff_time_set'] = $this->logoff_time_set;
1622 $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1623 }
1624 if(in_array("kickoff_time_set",$this->multi_boxes)){
1625 $ret['kickoff_time_set'] = $this->kickoff_time_set;
1626 $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1627 }
1629 if(in_array("no_password_required",$this->multi_boxes)){
1630 $ret['no_password_required'] = $this->no_password_required;
1631 }
1633 if(in_array("no_expiry",$this->multi_boxes)){
1634 $ret['no_expiry'] = $this->no_expiry;
1635 }
1637 if(in_array("temporary_disable",$this->multi_boxes)){
1638 $ret['temporary_disable'] = $this->temporary_disable;
1639 }
1641 if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1642 $ret['sambaLogonHours'] = $this->sambaLogonHours;
1643 }
1645 if(in_array("workstation_list",$this->multi_boxes)){
1646 $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1647 }
1648 return($ret);
1649 }
1651 function set_multi_edit_values($values)
1652 {
1653 plugin::set_multi_edit_values($values);
1655 /* Prepare current workstation settings to be merged
1656 * with multiple edit settings.
1657 */
1658 if(isset($values['multiple_sambaUserWorkstations'])){
1659 $cur_ws = array();
1660 $m_ws = $values['multiple_sambaUserWorkstations'];
1662 /* Prepare current settings to be merged */
1663 if(isset($this->sambaUserWorkstations)){
1664 $ttmp = split(",",$this->sambaUserWorkstations);
1665 foreach($ttmp as $station){
1666 $station = trim($station);
1667 if(!empty($station)){
1668 $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1669 }
1670 }
1671 }
1673 /* Unset removed workstations */
1674 foreach($cur_ws as $cur_name => $cur_station){
1675 if(!isset($m_ws[$cur_name])){
1676 unset($cur_ws[$cur_name]);
1677 }
1678 }
1680 /* Add all added workstations */
1681 foreach($m_ws as $name => $station){
1682 if($station['UsedByAllUsers']){
1683 $cur_ws[$name] = $station;
1684 }
1685 }
1687 $this->sambaUserWorkstations = "";
1688 foreach($cur_ws as $name => $ws){
1689 $this->sambaUserWorkstations .= $name.",";
1690 }
1691 $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1692 }
1694 /* Enable disabled terminal login, this is inverted somehow */
1695 if(isset($values['tslogin'])) $this->mungedObject->setTsLogin(!$values['tslogin']);
1697 /* Imherit client configuration */
1698 if(isset($values['inherit'])) $this->mungedObject->setInheritMode($values['inherit']);
1700 /* Get all ctx values posted */
1701 $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1702 "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1703 foreach($ctx as $attr){
1704 if(isset($values[$attr])){
1705 $this->mungedObject->ctx[$attr] = $values[$attr] ;
1706 }
1707 }
1709 if(isset($values['CtxMaxConnectionTimeF'])) $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1710 if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1711 if(isset($values['CtxMaxIdleTimeF'])) $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1713 if(isset($values['connectclientdrives'])) $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1714 if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1715 if(isset($values['defaultprinter'])) $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1717 if(isset($values['shadow'])) $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1718 if(isset($values['brokenconn'])) $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1719 if(isset($values['reconn'])) $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1722 if(isset($values['sambaPwdCanChange'])) $this->sambaPwdCanChange = $values['sambaPwdCanChange'];
1723 if(isset($values['pwdCanChange'])) $this->pwdCanChange = $values['pwdCanChange'];
1728 if(isset($values['password_expires'])){
1729 $this->password_expires = $values['password_expires'];
1730 $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1731 }
1732 if(isset($values['logon_time_set'])){
1733 $this->logon_time_set = $values['logon_time_set'];
1734 $this->sambaLogonTime = $values['sambaLogonTime'];
1735 }
1736 if(isset($values['logoff_time_set'])){
1737 $this->logoff_time_set = $values['logoff_time_set'];
1738 $this->sambaLogoffTime = $values['sambaLogoffTime'];
1739 }
1740 if(isset($values['kickoff_time_set'])){
1741 $this->kickoff_time_set = $values['kickoff_time_set'];
1742 $this->sambaKickoffTime = $values['sambaKickoffTime'];
1743 }
1745 if(isset($values['no_password_required'])){
1746 if($values['no_password_required']){
1747 if(!preg_match("/N/",$this->sambaAcctFlags)) {
1748 $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1749 }
1750 }else{
1751 $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1752 }
1753 }
1755 if(isset($values['no_expiry'])){
1756 if($values['no_expiry']){
1757 if(!preg_match("/N/",$this->sambaAcctFlags)) {
1758 $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1759 }
1760 }else{
1761 $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1762 }
1763 }
1765 if(isset($values['temporary_disable'])){
1766 if($values['temporary_disable']){
1767 if(preg_match("/L/",$this->sambaAcctFlags)) {
1768 // Keep L
1769 }else{
1770 $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1771 }
1772 }else{
1773 $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1774 }
1775 }
1776 }
1779 function PrepareForCopyPaste($source)
1780 {
1781 plugin::PrepareForCopyPaste($source);
1783 /* Set a new SID */
1784 $this->sambaSID = "";
1785 }
1787 }
1789 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1790 ?>