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