1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2004-2005 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 class sambaAccount extends plugin
22 {
23 /* Definitions */
24 var $plHeadline= "Samba";
25 var $plDescription= "This does something";
26 var $view_logged = FALSE;
28 /* Switch for Samba version */
29 var $samba3= FALSE;
30 var $uidNumber= 65535;
31 var $gidNumber= 65535;
33 /* Samba 2 attributes */
34 var $pwdLastSet= "0";
35 var $logonTime= "0";
36 var $logoffTime= "2147483647";
37 var $kickoffTime= "2147483647";
38 var $pwdCanChange= "0";
39 var $pwdMustChange= "0";
40 var $password_expires= 0;
41 var $acctFlags= "[UX ]";
42 var $smbHome= "";
43 var $homeDrive= "";
44 var $scriptPath= "";
45 var $profilePath= "";
46 var $rid= "";
47 var $primaryGroupID= "";
49 /* Samba 3 attributes */
50 var $SID= "";
51 var $ridBase= 0;
52 var $sambaSID= "";
53 var $sambaPwdLastSet= "0";
54 var $sambaLogonTime= "0";
55 var $sambaLogoffTime= "2147483647";
56 var $sambaKickoffTime= "2147483647";
57 var $sambaPwdCanChange= "";
58 var $sambaPwdMustChange= "0";
59 var $sambaAcctFlags= "[UX ]";
60 var $sambaHomePath= "";
61 var $sambaHomeDrive= "";
62 var $sambaLogonScript= "";
63 var $sambaProfilePath= "";
64 var $sambaPrimaryGroupSID= "";
65 var $sambaDomainName= "";
66 var $sambaUserWorkstations= "";
67 var $sambaBadPasswordCount= "";
68 var $sambaBadPasswordTime= "";
69 var $sambaPasswordHistory= "";
70 var $sambaLogonHours= "";
71 var $orig_sambaDomainName= "";
72 var $sambaMungedDial= "";
73 var $mungedObject;
75 /* Helper */
76 var $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 $multiple_sambaUserWorkstations = array();
96 function sambaAccount (&$config, $dn= NULL)
97 {
98 /* Load attributes depending on the samba version */
99 $this->samba3= ($config->get_cfg_value("sambaversion") == 3);
101 if ($this->samba3){
102 $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
103 "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
104 "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
105 "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
106 "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
107 "sambaUserWorkstations", "sambaPasswordHistory",
108 "sambaLogonHours", "sambaBadPasswordTime",
109 "sambaBadPasswordCount");
110 $this->objectclasses= array ("sambaSamAccount");
111 $this->mungedObject= new sambaMungedDial;
112 $this->ctxattributes= $this->mungedObject->ctxattributes;
113 } else {
114 $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
115 "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
116 "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
117 $this->objectclasses= array ("sambaAccount");
118 }
120 plugin::plugin ($config, $dn);
122 /* Setting uid to default */
123 if(isset($this->attrs['uid'][0])){
124 $this->uid = $this->attrs['uid'][0];
125 }
127 /* Get samba Domain in case of samba 3 */
128 if ($this->samba3 && $this->sambaSID != ""){
129 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
130 $ldap= $this->config->get_ldap_link();
131 $ldap->cd($this->config->current['BASE']);
132 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
133 if ($ldap->count() != 0){
134 $attrs= $ldap->fetch();
135 if(isset($attrs['sambaAlgorithmicRidBase'])){
136 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
137 } else {
138 $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
139 }
140 if ($this->sambaDomainName == ""){
141 $this->sambaDomainName= $attrs['sambaDomainName'][0];
142 }
143 } else {
144 if ($this->sambaDomainName == ""){
145 $this->sambaDomainName= "DEFAULT";
146 }
147 $this->ridBase= $this->config->get_cfg_value("sambaRidBase");
148 $this->SID= $this->config->get_cfg_value("sambaSid");
149 }
151 /* Save in order to compare later on */
152 $this->orig_sambaDomainName= $this->sambaDomainName;
153 }
155 /* Fill mungedDial field */
156 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
157 $this->mungedObject->load($this->sambaMungedDial);
158 }
160 /* Password expiery */
161 if(isset($this->attrs['sambaPwdMustChange']) &&
162 $this->attrs['sambaPwdMustChange'][0] != 0){
163 $this->password_expires= 1;
164 }
166 if(isset($this->attrs['sambaLogonTime']) && ! (
167 $this->attrs['sambaLogonTime'][0] == 0 ||
168 $this->attrs['sambaLogonTime'][0] == 2147483647
169 )){
170 $this->logon_time_set= 1;
171 }
172 if(isset($this->attrs['sambaLogoffTime']) && ! (
173 $this->attrs['sambaLogoffTime'][0] == 0 ||
174 $this->attrs['sambaLogoffTime'][0] == 2147483647
175 )){
176 $this->logoff_time_set= 1;
177 }
179 /* Account expiery */
180 if(isset($this->attrs['sambaKickoffTime']) && ! (
181 $this->attrs['sambaKickoffTime'][0] == 0 ||
182 $this->attrs['sambaKickoffTime'][0] == 2147483647
183 )){
184 $this->kickoff_time_set= 1;
185 }
187 /* Get global filter config */
188 if (!session::is_set("sambafilter")){
189 $ui= get_userinfo();
190 $base= get_base_from_people($ui->dn);
191 $sambafilter= array( "depselect" => $base, "regex" => "*");
192 session::set("sambafilter", $sambafilter);
193 }
195 /* Save initial account state */
196 $this->initially_was_account= $this->is_account;
197 }
199 function execute()
200 {
201 /* Call parent execute */
202 plugin::execute();
204 /* Log view */
205 if($this->is_account && !$this->view_logged){
206 $this->view_logged = TRUE;
207 new log("view","users/".get_class($this),$this->dn);
208 }
210 /* Do we need to flip is_account state? */
211 if (isset($_POST['modify_state'])){
212 $this->is_account= !$this->is_account;
213 }
214 /* Do we represent a valid account? */
215 if (!$this->is_account && $this->parent === NULL){
216 $display= "<img alt=\"\"src=\"images/small-error.png\" align=\"middle\"> <b>".
217 msgPool::noValidExtension(_("Samba"))."</b>";
218 $display.= back_to_main();
219 return ($display);
220 }
222 $display ="";
223 if(!$this->multiple_support_active){
225 /* Show tab dialog headers */
226 $display= "";
227 if ($this->parent !== NULL){
228 if ($this->is_account){
229 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Samba")),
230 msgPool::featuresEnabled(_("Samba")));
231 } else {
232 $obj= $this->parent->by_object['posixAccount'];
234 /* Samba3 dependency on posix accounts are enabled
235 in the moment, because I need to rely on unique
236 uidNumbers. There'll be a better solution later
237 on. */
238 if ($obj->is_account){
239 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
240 msgPool::featuresDisabled(_("Samba")));
241 } else {
242 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Samba")),
243 msgPool::featuresDisabled(_("Samba"), _("POSIX")), TRUE);
244 }
245 return ($display);
246 }
247 }
248 }
250 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
252 /* Open Samaba Logong hours dialog */
253 if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_readable("sambaLogonHours")){
254 $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
255 }
257 /* Cancel dialog */
258 if(isset($_POST['cancel_logonHours'])){
259 $this->dialog = FALSE;
260 }
262 /* Save selected logon hours */
263 if(isset($_POST['save_logonHours'])){
264 $this->dialog->save_object();
265 if($this->acl_is_writeable("sambaLogonHours")){
266 $this->sambaLogonHours = $this->dialog->save();
267 }
268 $this->dialog = FALSE;
269 }
271 /* Display dialog */
272 if((isset($this->dialog)) && (is_object($this->dialog))){
273 $this->dialog->save_object();
274 return($this->dialog->execute());
275 }
277 /* Prepare templating */
278 $smarty= get_smarty();
280 $tmp = $this->plInfo();
281 foreach($tmp['plProvidedAcls'] as $var => $rest){
282 $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
283 }
285 if(!session::is_set('edit') && !isset($this->parent)){
286 $smarty->assign("sambaLogonHoursACL","");
287 }
289 if ($this->sambaPwdMustChange=="0"){
290 $date= getdate();
291 } else {
292 $date= getdate($this->sambaPwdMustChange);
293 }
295 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
296 $sambaLogonTime_date= getdate();
297 } else {
298 $sambaLogonTime_date= getdate($this->sambaLogonTime);
299 }
301 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
302 $sambaLogoffTime_date= getdate();
303 } else {
304 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
305 }
307 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
308 $sambaKickoffTime_date= getdate();
309 } else {
310 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
311 }
313 /* Remove user workstations? */
314 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
316 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
318 if($this->multiple_support_active){
319 foreach($_POST['workstation_list'] as $name){
320 if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
321 unset($this->multiple_sambaUserWorkstations[trim($name)]);
322 }
323 }
324 }else{
325 $tmp= $this->sambaUserWorkstations;
326 foreach($_POST['workstation_list'] as $name){
327 $tmp= preg_replace("/$name/", '', $tmp);
328 $this->is_modified= TRUE;
329 }
330 $tmp= preg_replace('/,+/', ',', $tmp);
331 $this->sambaUserWorkstations= trim($tmp, ',');
332 }
333 }
334 }
336 /* Add user workstation? */
337 if (isset($_POST["add_ws"])){
338 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
339 $this->show_ws_dialog= TRUE;
340 $this->dialog= TRUE;
341 }
342 }
344 /* Add user workstation finished? */
345 if (isset($_POST["add_ws_cancel"])){
346 $this->show_ws_dialog= FALSE;
347 $this->dialog= FALSE;
348 }
350 /* Add user workstation? */
351 if (isset($_POST["add_ws_finish"])){
353 if (isset($_POST['wslist'])){
354 if($this->multiple_support_active){
355 foreach($_POST['wslist'] as $ws){
356 $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
357 }
358 }else{
359 $tmp= $this->sambaUserWorkstations;
360 foreach($_POST['wslist'] as $ws){
361 $tmp.= ",$ws";
362 }
363 $tmp= preg_replace('/,+/', ',', $tmp);
364 $this->sambaUserWorkstations= trim($tmp, ',');
365 }
366 $this->is_modified= TRUE;
368 $this->show_ws_dialog= FALSE;
369 $this->dialog= FALSE;
370 } else {
371 msg_dialog::display(_("Error"), _("Please select an entry!"), ERROR_DIALOG);
372 }
373 }
375 /* Show ws dialog */
376 if ($this->show_ws_dialog){
378 /* Save data */
379 $sambafilter= session::get("sambafilter");
380 foreach( array("depselect", "regex") as $type){
381 if (isset($_POST[$type])){
382 $sambafilter[$type]= $_POST[$type];
383 }
384 }
385 if (isset($_GET['search'])){
386 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
387 if ($s == "**"){
388 $s= "*";
389 }
390 $sambafilter['regex']= $s;
391 }
392 session::set("sambafilter", $sambafilter);
394 /* Get workstation list */
395 $exclude= "";
397 if($this->multiple_support_active){
398 foreach($this->multiple_sambaUserWorkstations as $ws){
399 if($ws['UsedByAllUsers']){
400 $exclude.= "(cn=".$ws['Name']."$)";
401 }
402 }
403 }else{
404 foreach(split(',', $this->sambaUserWorkstations) as $ws){
405 $exclude.= "(cn=$ws$)";
406 }
407 }
408 if ($exclude != ""){
409 $exclude= "(!(|$exclude))";
410 }
411 $regex= $sambafilter['regex'];
412 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
413 $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
415 $wslist= array();
416 foreach ($res as $attrs){
417 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
418 }
419 asort($wslist);
421 $smarty->assign("search_image", get_template_path('images/lists/search.png'));
422 $smarty->assign("launchimage", get_template_path('images/lists/action.png'));
423 $smarty->assign("tree_image", get_template_path('images/lists/search-subtree.png'));
424 $smarty->assign("deplist", $this->config->idepartments);
425 $smarty->assign("alphabet", generate_alphabet());
426 foreach( array("depselect", "regex") as $type){
427 $smarty->assign("$type", $sambafilter[$type]);
428 }
429 $smarty->assign("hint", print_sizelimit_warning());
430 $smarty->assign("wslist", $wslist);
431 $smarty->assign("apply", apply_filter());
432 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
433 dirname(__FILE__)));
434 return ($display);
435 }
437 /* Fill calendar */
438 $days= array();
439 for($d= 1; $d<32; $d++){
440 $days[]= $d;
441 }
442 $years= array();
443 for($y= $date['year']-4; $y<$date['year']+4; $y++){
444 $years[]= $y;
445 }
446 $months= msgPool::months();
447 $smarty->assign("day", $date["mday"]);
448 $smarty->assign("days", $days);
449 $smarty->assign("months", $months);
450 $smarty->assign("month", $date["mon"]-1);
451 $smarty->assign("years", $years);
452 $smarty->assign("year", $date["year"]);
454 $sambaLogonTime_days= array();
455 for($d= 1; $d<32; $d++){
456 $sambaLogonTime_days[]= $d;
457 }
458 $sambaLogonTime_years= array();
459 for($y= $date['year']-4; $y<$date['year']+4; $y++){
460 $sambaLogonTime_years[]= $y;
461 }
462 $sambaLogonTime_months= msgPool::months();
463 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
464 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
465 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
466 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
467 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
468 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
470 $sambaLogoffTime_days= array();
471 for($d= 1; $d<32; $d++){
472 $sambaLogoffTime_days[]= $d;
473 }
474 $sambaLogoffTime_years= array();
475 for($y= $date['year']-4; $y<$date['year']+4; $y++){
476 $sambaLogoffTime_years[]= $y;
477 }
478 $sambaLogoffTime_months= msgPool::months();
479 $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
480 $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
481 $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
482 $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
483 $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
484 $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
486 $sambaKickoffTime_days= array();
487 for($d= 1; $d<32; $d++){
488 $sambaKickoffTime_days[]= $d;
489 }
490 $sambaKickoffTime_years= array();
491 for($y= $date['year']-4; $y<$date['year']+4; $y++){
492 $sambaKickoffTime_years[]= $y;
493 }
494 $sambaKickoffTime_months= msgPool::months();
495 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
496 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
497 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
498 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
499 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
500 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
501 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
503 /* Fill boxes */
504 if ($this->samba3){
505 $domains= array();
506 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
507 $domains[]= $name;
508 }
509 $smarty->assign("domains", $domains);
510 }
511 $letters= array("");
512 for ($i= 68; $i<91; $i++){
513 $letters[]= chr($i).":";
514 }
515 $smarty->assign("drives", $letters);
517 /* Fill terminal server settings */
518 if ($this->samba3){
519 foreach ($this->ctxattributes as $attr){
520 /* Fill common attributes */
521 if (isset($this->mungedObject->ctx[$attr])){
522 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
523 // Set field to blank if value is 0
524 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
525 if($this->mungedObject->ctx[$attr] == 0) {
526 $smarty->assign("$attr", "");
527 }
528 }
529 } else {
530 $smarty->assign("$attr", "");
531 }
532 }
534 /* Assign enum values for preset items */
535 $shadowModeVals= array( "0" => _("disabled"),
536 "1" => _("input on, notify on"),
537 "2" => _("input on, notify off"),
538 "3" => _("input off, notify on"),
539 "4" => _("input off, nofify off"));
541 $brokenConnModeVals= array( "0" => _("disconnect"),
542 "1" => _("reset"));
544 $reConnModeVals= array( "0" => _("from any client"),
545 "1" => _("from previous client only"));
547 /* Fill preset items */
548 $smarty->assign("shadow", $shadowModeVals);
549 $smarty->assign("brokenconn", $brokenConnModeVals);
550 $smarty->assign("reconn", $reConnModeVals);
552 /* Fill preset items with values */
553 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
554 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
555 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
557 if(session::get('js')){
558 /* Set form elements to disabled/enable state */
559 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
561 $smarty->assign("inheritstate", "");
562 if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
563 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
564 }
565 }else{
566 $smarty->assign("tsloginstate", "");
567 $smarty->assign("inheritstate", "");
568 }
570 /* Set checkboxes to checked or unchecked state */
571 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
572 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
573 $smarty->assign("connectclientdrives",
574 $this->mungedObject->getConnectClientDrives()?"checked":"");
575 $smarty->assign("connectclientprinters",
576 $this->mungedObject->getConnectClientPrinters()?"checked":"");
577 $smarty->assign("defaultprinter",
578 $this->mungedObject->getDefaultPrinter()?"checked":"");
579 $smarty->assign("CtxMaxConnectionTimeF",
580 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
581 $smarty->assign("CtxMaxDisconnectionTimeF",
582 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
583 $smarty->assign("CtxMaxIdleTimeF",
584 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
587 /* Fill sambaUserWorkstations */
588 $ws= split(",", $this->sambaUserWorkstations);
589 sort($ws);
591 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
592 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
594 if($this->multiple_support_active){
595 $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
596 }
598 $smarty->assign("workstations", $ws);
599 }
601 /* Variables */
602 foreach($this->attributes as $val){
603 $smarty->assign("$val", $this->$val);
604 }
606 /* 'sambaAcctFlags' checkboxes */
607 /* Check for 'lock-account'-flag: 'D' or 'L' */
608 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
609 is_integer(strpos($this->sambaAcctFlags, "L"))) {
610 $smarty->assign("flagsD", "checked");
611 } else {
612 $smarty->assign("flagsD", "");
613 }
615 /* Check for no_password_required flag 'N' */
616 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
617 $smarty->assign("flagsN", "checked");
618 } else {
619 $smarty->assign("flagsN", "");
620 }
622 if($this->samba3){
623 if ($this->sambaPwdCanChange=="1"){
624 $smarty->assign("flagsP", "checked");
625 } else {
626 $smarty->assign("flagsP", "");
627 }
628 }else{
629 if ($this->pwdCanChange=="1"){
630 $smarty->assign("flagsP", "checked");
631 } else {
632 $smarty->assign("flagsP", "");
633 }
634 }
636 if ($this->password_expires=="1"){
637 $smarty->assign("flagsC", "checked");
638 } else {
639 $smarty->assign("flagsC", "");
640 }
641 if ($this->logon_time_set=="1"){
642 $smarty->assign("flagsT", "checked");
643 } else {
644 $smarty->assign("flagsT", "");
645 }
646 if ($this->logoff_time_set=="1"){
647 $smarty->assign("flagsO", "checked");
648 } else {
649 $smarty->assign("flagsO", "");
650 }
651 if ($this->kickoff_time_set=="1"){
652 $smarty->assign("flagsK", "checked");
653 } else {
654 $smarty->assign("flagsK", "");
655 }
658 /* In case of javascript, disable some fields on demand */
659 if ($this->samba3){
660 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
661 $smarty->assign("$key", "$value");
662 }
663 }
666 foreach($this->attributes as $attr){
667 if(in_array($attr,$this->multi_boxes)){
668 $smarty->assign("use_".$attr,TRUE);
669 }else{
670 $smarty->assign("use_".$attr,FALSE);
671 }
672 }
673 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
674 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
675 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
676 "onnectclientprinters","defaultprinter","shadow","brokenconn",
677 "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
678 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
679 "workstation_list") as $attr){
680 if(in_array($attr,$this->multi_boxes)){
681 $smarty->assign("use_".$attr,TRUE);
682 }else{
683 $smarty->assign("use_".$attr,FALSE);
684 }
685 }
687 if($this->multiple_support_active){
688 $smarty->assign("tsloginstate","");
689 }
691 /* Show main page */
692 $smarty->assign("multiple_support",$this->multiple_support_active);
693 if ($this->samba3){
694 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
695 } else {
696 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
697 }
699 return ($display);
700 }
702 function remove_from_parent()
703 {
704 /* Cancel if there's nothing to do here */
705 if (!$this->initially_was_account){
706 return;
707 }
709 /* include global link_info */
710 $ldap= $this->config->get_ldap_link();
712 plugin::remove_from_parent();
714 /* Keep uid attribute for gosaAccount */
715 unset($this->attrs['uid']);
716 unset($this->attrs['uidNumber']);
717 unset($this->attrs['gidNumber']);
719 /* Remove objectClass for sambaIdmapEntry */
720 $tmp= array();
721 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
722 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
723 $tmp[]= $this->attrs['objectClass'][$i];
724 }
725 }
726 $this->attrs['objectClass']= $tmp;
728 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
729 $this->attributes, "Save");
730 $ldap->cd($this->dn);
731 $this->cleanup();
732 $ldap->modify ($this->attrs);
734 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
736 if (!$ldap->success()){
737 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
738 }
740 /* Optionally execute a command after we're done */
741 $this->handle_post_events("remove", array("uid" => $this->uid));
742 }
745 /* Check for input problems */
746 function check()
747 {
748 /* Call common method to give check the hook */
749 $message= plugin::check();
751 if ($this->samba3){
753 /* sambaHomePath requires sambaHomeDrive and vice versa */
754 if(!empty($this->sambaHomePath) && empty($this->sambaHomeDrive)){
755 $message[]= msgPool::required(_("Home drive"));
756 }
757 if(!empty($this->sambaHomeDrive) && empty($this->sambaHomePath)){
758 $message[]= msgPool::required(_("Home path"));
759 }
761 /* Strings */
762 foreach (array( "sambaHomePath" => _("Home directory"),
763 "sambaProfilePath" => _("Profile path")) as $key => $val){
764 if (!$this->mungedObject->is_samba_path($this->$key)){
765 $message[]= msgPool::invalid($val);
766 }
767 }
769 /* Numeric values */
770 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
771 "CtxMaxDisconnectionTime" => _("Disconnection"),
772 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
774 if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
775 $message[]= msgPool::invalid($val);
776 }
777 }
779 /* Too many workstations? Windows usrmgr only supports eight */
780 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
781 $message[]= _("The windows usermanager allows eight clients at maximum!");
782 }
783 }
785 return ($message);
786 }
789 /* Save data to object */
790 function save_object()
791 {
793 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
795 /* We only care if we are on the sambaTab... */
796 if (isset($_POST['sambaTab'])){
797 plugin::save_object();
799 /* Take care about access options */
800 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
801 if ($this->samba3){
802 $attrname= "sambaPwdCanChange";
803 } else {
804 $attrname= "pwdCanChange";
805 }
806 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
807 $tmp= 1;
808 } else {
809 $tmp= 0;
810 }
811 if ($this->$attrname != $tmp){
812 $this->is_modified= TRUE;
813 }
814 $this->pwdCanChange= $tmp;
815 $this->sambaPwdCanChange= $tmp;
816 }
817 $tmp= "UX";
818 $this->no_password_required = FALSE;
819 if (isset($_POST["no_password_required"])){
820 if ($_POST["no_password_required"] == 1){
821 $tmp.= "N";
822 $this->no_password_required = TRUE;
823 }
824 }
825 if (isset($_POST["password_expires"])){
826 if ($_POST["password_expires"] == 1){
827 $this->password_expires= 1;
828 }
829 } else {
830 $this->password_expires= 0;
831 }
832 $this->temporary_disable = FALSE;
833 if (isset($_POST["temporary_disable"])){
834 if ($_POST["temporary_disable"] == 1){
835 $this->temporary_disable = TRUE;
836 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
837 $tmp.= "L";
838 } else {
839 $tmp.= "D";
840 }
841 }
842 }
843 if (isset($_POST["logon_time_set"])){
844 if ($_POST["logon_time_set"] == 1){
845 $this->logon_time_set= 1;
846 }
847 } else {
848 $this->logon_time_set= 0;
849 }
850 if (isset($_POST["logoff_time_set"])){
851 if ($_POST["logoff_time_set"] == 1){
852 $this->logoff_time_set= 1;
853 }
854 } else {
855 $this->logoff_time_set= 0;
856 }
857 if (isset($_POST["kickoff_time_set"])){
858 if ($_POST["kickoff_time_set"] == 1){
859 $this->kickoff_time_set= 1;
860 }
861 } else {
862 $this->kickoff_time_set= 0;
863 }
865 $fill= "";
866 for ($i= strlen($tmp); $i<12; $i++){
867 $fill.= " ";
868 }
870 $tmp= "[$tmp$fill]";
872 /* Only save if acl's are set */
873 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
874 if ($this->samba3){
875 $attrname= "sambaAcctFlags";
876 } else {
877 $attrname= "acctFlags";
878 }
879 if ($this->$attrname != $tmp){
880 $this->is_modified= TRUE;
881 }
882 $this->$attrname= $tmp;
883 }
885 /* Save sambaDomain attribute */
886 if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
887 $this->sambaDomainName= validate($_POST['sambaDomainName']);
888 }
890 /* Save CTX values */
891 if ($this->samba3){
893 /* Save obvious values */
894 foreach($this->ctxattributes as $val){
895 if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
896 if (get_magic_quotes_gpc()) {
897 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
898 } else {
899 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
900 }
901 }
902 }
904 /* Save checkbox states. */
905 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
906 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
907 // Need to do some index checking to avoid messages like "index ... not found"
908 if(isset($_POST['brokenconn'])) {
909 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
910 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
911 }
912 if(isset($_POST['reconn'])) {
913 $this->mungedObject->setReConn($_POST['reconn'] == '1'
914 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
915 }
916 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
917 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
918 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
919 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
920 $this->mungedObject->setCtxMaxDisconnectionTimeF(
921 !isset($_POST['CtxMaxDisconnectionTimeF'])
922 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
923 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
924 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
925 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
926 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
927 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
928 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
929 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
930 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
932 /* Save combo boxes. Takes two values */
933 if(isset($_POST['reconn'])) {
934 $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
935 }
937 /* Check for changes */
938 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
939 $this->is_modified= TRUE;
940 }
941 }
942 }
943 }
946 /* Save to LDAP */
947 function save()
948 {
949 /* Load uid and gid of this 'dn' */
950 $ldap= $this->config->get_ldap_link();
951 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
952 $tmp= $ldap->fetch();
953 $this->uidNumber= $tmp['uidNumber'][0];
954 $this->gidNumber= $tmp['gidNumber'][0];
956 plugin::save();
958 /* Remove objectClass for sambaIdmapEntry */
959 $tmp= array();
960 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
961 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
962 $tmp[]= $this->attrs['objectClass'][$i];
963 }
964 }
965 $this->attrs['objectClass']= $tmp;
967 /* Generate rid / primaryGroupId */
968 if ($this->samba3){
969 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
970 msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
971 } else {
972 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
973 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
974 }
976 /* Need to generate a new uniqe uid/gid combination? */
977 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
978 $uidNumber= $this->uidNumber;
979 while(TRUE){
980 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
981 $ldap->cd($this->config->current['BASE']);
982 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
983 if ($ldap->count() == 0){
984 break;
985 }
986 $uidNumber++;
987 }
988 $this->attrs['sambaSID']= $sid;
990 /* Check for users primary group */
991 $ldap->cd($this->config->current['BASE']);
992 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
993 if ($ldap->count() != 1){
994 msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
995 } else {
996 $attrs= $ldap->fetch();
997 $g= new group($this->config, $ldap->getDN());
998 if ($g->sambaSID == ""){
999 $g->sambaDomainName= $this->sambaDomainName;
1000 $g->smbgroup= TRUE;
1001 $g->save ();
1002 }
1003 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
1004 }
1005 }
1007 if ($this->sambaHomeDrive == ""){
1008 $this->attrs["sambaHomeDrive"]= array();
1009 }
1011 /* Generate munged dial value */
1012 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1014 /* User wants me to fake the idMappings? This is useful for
1015 making winbind resolve the user names in a reasonable amount
1016 of time in combination with larger databases. */
1017 if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1018 $this->attrs['objectClass'][]= "sambaIdmapEntry";
1019 }
1022 /* Password expiery */
1023 if ($this->password_expires == "1"){
1024 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1025 } else {
1026 $this->attrs['sambaPwdMustChange']= array();
1027 }
1028 /* Make sure not to save zero in sambaPwdLastset */
1029 if ($this->sambaPwdLastSet != "0"){
1030 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1031 } else {
1032 $this->attrs['sambaPwdLastSet']= array();
1033 }
1034 /* Account expiery */
1035 if ($this->logon_time_set == "1"){
1036 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1037 } else {
1038 $this->attrs['sambaLogonTime']= array();
1039 }
1040 if ($this->logoff_time_set == "1"){
1041 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1042 } else {
1043 $this->attrs['sambaLogoffTime']= array();
1044 }
1045 if ($this->kickoff_time_set == "1"){
1046 # Add one day in unixtime format to be compatible with usrmgr
1047 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
1048 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
1049 } else {
1050 $this->attrs['sambaKickoffTime']= array();
1051 }
1052 } else {
1053 /* Not samba3 */
1054 $this->attrs['rid']= $this->uidNumber*2 + 1000;
1055 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1057 if ($this->homeDrive == ""){
1058 $this->attrs["homeDrive"]= array();
1059 }
1061 /* Password expiery */
1062 if ($this->password_expires == "1"){
1063 $this->attrs['pwdMustChange']= $this->pwdMustChange;
1064 } else {
1065 $this->attrs['pwdMustChange']= 2147483647;
1066 }
1067 /* Make sure not to save zero in pwdLastset */
1068 if ($this->pwdLastSet != "0"){
1069 $this->attrs['pwdLastSet']= $this->pwdLastSet;
1070 } else {
1071 $this->attrs['pwdLastSet']= array();
1072 }
1073 /* Account expiery */
1074 if ($this->logon_time_set == "1"){
1075 $this->attrs['logonTime']= $this->logonTime;
1076 } else {
1077 $this->attrs['logonTime']= array();
1078 }
1079 if ($this->logoff_time_set == "1"){
1080 $this->attrs['logoffTime']= $this->logoffTime;
1081 } else {
1082 $this->attrs['logoffTime']= array();
1083 }
1084 if ($this->kickoff_time_set == "1"){
1085 # Add one day in unixtime format to be compatible with usrmgr
1086 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1087 } else {
1088 $this->attrs['kickoffTime']= array();
1089 }
1090 }
1092 /* Write back to ldap */
1093 $ldap->cd($this->dn);
1094 $this->cleanup();
1095 $ldap->modify ($this->attrs);
1097 if($this->initially_was_account){
1098 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1099 }else{
1100 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1101 }
1103 if (!$ldap->success()){
1104 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1105 }
1107 /* Optionally execute a command after we're done */
1108 if ($this->initially_was_account == $this->is_account){
1109 if ($this->is_modified){
1110 $this->handle_post_events("modify", array("uid" => $this->uid));
1111 }
1112 } else {
1113 $this->handle_post_events("add", array("uid" => $this->uid));
1114 }
1115 }
1118 /* Force password set, if this account doesn't have any samba passwords */
1119 function password_change_needed()
1120 {
1121 if(!$this->initially_was_account && $this->is_account){
1122 $ldap = $this->config->get_ldap_link();
1123 $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1124 $attrs = $ldap->fetch();
1125 if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1126 return(TRUE);
1127 }
1128 }
1129 return(FALSE);
1130 }
1133 function adapt_from_template($dn, $skip= array())
1134 {
1135 plugin::adapt_from_template($dn, $skip);
1138 $this->sambaSID= "";
1139 $this->sambaPrimaryGroupSID= "";
1141 /* Fill mungedDial field */
1142 if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1143 $this->mungedObject->load($this->sambaMungedDial);
1144 }
1146 /* Adapt munged attributes */
1147 foreach($this->ctxattributes as $attr){
1148 if(isset($this->mungedObject->ctx[$attr]))
1149 $val = $this->mungedObject->ctx[$attr];
1151 foreach (array("sn", "givenName", "uid") as $repl){
1152 if (preg_match("/%$repl/i", $val)){
1153 $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1154 }
1155 }
1156 $this->mungedObject->ctx[$attr] = $val;
1157 }
1159 /* Password expiery */
1160 if(isset($this->attrs['sambaPwdMustChange']) &&
1161 $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1162 $this->password_expires= 1;
1163 }
1165 if(isset($this->attrs['sambaLogonTime']) && ! (
1166 $this->attrs['sambaLogonTime'][0] == 0 ||
1167 $this->attrs['sambaLogonTime'][0] == 2147483647
1168 ) && !in_array('sambaLogonTime', $skip)){
1169 $this->logon_time_set= 1;
1170 }
1171 if(isset($this->attrs['sambaLogoffTime']) && ! (
1172 $this->attrs['sambaLogoffTime'][0] == 0 ||
1173 $this->attrs['sambaLogoffTime'][0] == 2147483647
1174 ) && !in_array('sambaLogonTime', $skip)){
1175 $this->logoff_time_set= 1;
1176 }
1178 /* Account expiery */
1179 if(isset($this->attrs['sambaKickoffTime']) && ! (
1180 $this->attrs['sambaKickoffTime'][0] == 0 ||
1181 $this->attrs['sambaKickoffTime'][0] == 2147483647
1182 ) && !in_array('sambaKickoffTime', $skip)){
1183 $this->kickoff_time_set= 1;
1184 }
1186 /* Get global filter config */
1187 if (!session::is_set("sambafilter")){
1188 $ui= get_userinfo();
1189 $base= get_base_from_people($ui->dn);
1190 $sambafilter= array( "depselect" => $base, "regex" => "*");
1191 session::set("sambafilter", $sambafilter);
1192 }
1193 }
1196 static function plInfo()
1197 {
1198 return (array(
1199 "plShortName" => _("Samba"),
1200 "plDescription" => _("Samba settings"),
1201 "plSelfModify" => TRUE,
1202 "plDepends" => array("user"),
1203 "plPriority" => 5,
1204 "plSection" => array("personal" => _("My account")),
1205 "plCategory" => array("users"),
1206 "plOptions" => array(),
1208 "plProvidedAcls" => array(
1210 "sambaHomePath" => _("Generic home directory") ,
1211 "sambaHomeDrive" => _("Generic samba home drive") ,
1212 "sambaDomainName" => _("Domain") ,
1213 "sambaLogonScript" => _("Generic script path") ,
1214 "sambaProfilePath" => _("Generic profile path") ,
1215 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1216 "InheritClientConfig" => _("Inherit client config"),
1217 "sambaPwdCanChange" => _("Allow user to change password") ,
1218 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1219 "sambaAcctFlagsL" => _("Lock samba account"),
1220 "sambaKickoffTime" => _("Account expires") ,
1221 "sambaPwdMustChange" => _("Password expires") ,
1222 "sambaLogonTime" => _("Limit Logon Time") ,
1223 "sambaLogoffTime" => _("Limit Logoff Time") ,
1224 "sambaLogonHours" => _("Logon hours") ,
1225 "sambaUserWorkstations" => _("Allow connection from"))
1226 ));
1227 }
1229 function enable_multiple_support()
1230 {
1231 plugin::enable_multiple_support();
1232 if($this->samba3){
1233 $this->multiple_support_active = TRUE;
1234 }else{
1235 $this->multiple_support_active = FALSE;
1236 }
1237 }
1239 function multiple_save_object()
1240 {
1241 if (isset($_POST['sambaTab'])){
1242 $this->save_object();
1243 plugin::multiple_save_object();
1244 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1245 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1246 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1247 "onnectclientprinters","defaultprinter","shadow","brokenconn",
1248 "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1249 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1250 "workstation_list") as $attr){
1251 if(isset($_POST["use_".$attr])){
1252 $this->multi_boxes[] = $attr;
1253 }
1254 }
1255 }
1256 }
1259 function multiple_check()
1260 {
1261 $message = plugin::multiple_check();
1263 /* Strings */
1264 foreach (array( "sambaHomePath" => _("Home directory"),
1265 "sambaProfilePath" => _("Profile path")) as $key => $val){
1266 if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1267 $message[]= msgPool::invalid($val);
1268 }
1269 }
1271 /* Numeric values */
1272 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
1273 "CtxMaxDisconnectionTime" => _("Disconnection"),
1274 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
1275 if (in_array($key,$this->multi_boxes) &&
1276 isset($this->mungedObject->ctx[$key]) &&
1277 !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1278 $message[]=msgPool::invalid($val);
1279 }
1280 }
1282 /* Too many workstations? Windows usrmgr only supports eight */
1283 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1284 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1285 }
1286 return($message);
1287 }
1290 function get_multi_init_values()
1291 {
1292 $ret = plugin::get_multi_init_values();
1294 /* Parse given sambaUserWorkstations into array
1295 * to allow "init_multiple_support()" to detect multiple used workstations.
1296 * Those workstations will be displayed in light grey.
1297 */
1298 $tmp2 = array("count" => 0);
1299 $tmp = split(",", $this->sambaUserWorkstations);
1300 foreach($tmp as $station){
1301 $station = trim($station);
1302 if(!empty($station)){
1303 $tmp2[] = $station;
1304 $tmp2['count'] ++;
1305 }
1306 }
1307 $ret['sambaUserWorkstations'] = $tmp2;
1308 return($ret);
1309 }
1313 function init_multiple_support($attrs,$all)
1314 {
1315 plugin::init_multiple_support($attrs,$all);
1317 $this->multiple_sambaUserWorkstations = array();
1318 if(isset($all['sambaUserWorkstations'])){
1319 for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1320 $station = trim($all['sambaUserWorkstations'][$i]);
1321 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1322 }
1323 }
1324 if(isset($attrs['sambaUserWorkstations'])){
1325 for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1326 $station = trim($attrs['sambaUserWorkstations'][$i]);
1327 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1328 }
1329 }
1330 }
1332 function multiple_execute()
1333 {
1334 return($this->execute());
1335 }
1337 function get_multi_edit_values()
1338 {
1339 $ret = plugin::get_multi_edit_values();
1341 /* Terminal Server */
1342 if(in_array("tslogin",$this->multi_boxes)){
1343 $ret['tslogin'] = $this->mungedObject->getTsLogin();
1344 }
1345 if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1346 $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1347 }
1348 if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1349 $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1350 }
1351 if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1352 $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1353 }
1355 if(in_array("inherit",$this->multi_boxes)){
1356 $ret['inherit'] = $this->mungedObject->getInheritMode();
1357 }
1358 if(in_array("CtxInitialProgram",$this->multi_boxes)){
1359 $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1360 }
1361 if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1362 $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1363 }
1365 /* Time Limits. Be careful here, there are some negations */
1366 if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1367 $ret["CtxMaxConnectionTimeF"] = !$this->mungedObject->getCtxMaxConnectionTimeF();
1368 if(!$ret["CtxMaxConnectionTimeF"]){
1369 $ret["CtxMaxConnectionTime"] = $this->mungedObject->ctx['CtxMaxConnectionTime'];
1370 }
1371 }
1372 if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1373 $ret["CtxMaxDisconnectionTimeF"]= !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1374 if(!$ret["CtxMaxDisconnectionTimeF"]){
1375 $ret["CtxMaxDisconnectionTime"]= $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1376 }
1377 }
1378 if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1379 $ret["CtxMaxIdleTimeF"] = !$this->mungedObject->getCtxMaxIdleTimeF();
1380 if(!$ret["CtxMaxIdleTimeF"]){
1381 $ret["CtxMaxIdleTime"] = $this->mungedObject->ctx['CtxMaxIdleTime'];
1382 }
1383 }
1385 /* Client Devices */
1386 if(in_array("connectclientdrives",$this->multi_boxes)){
1387 $ret["connectclientdrives"] = $this->mungedObject->getConnectClientDrives();
1388 }
1389 if(in_array("connectclientprinters",$this->multi_boxes)){
1390 $ret["connectclientprinters"] = $this->mungedObject->getConnectClientPrinters();
1391 }
1392 if(in_array("defaultprinter",$this->multi_boxes)){
1393 $ret["defaultprinter"] = $this->mungedObject->getDefaultPrinter();
1394 }
1396 /* Misc */
1397 if(in_array("shadow",$this->multi_boxes)){
1398 $ret["shadow"] =$this->mungedObject->getShadow();
1399 }
1400 if(in_array("brokenconn",$this->multi_boxes)){
1401 $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1402 }
1403 if(in_array("reconn",$this->multi_boxes)){
1404 $ret["reconn"] =$this->mungedObject->getReConn();
1405 }
1407 /* Flags */
1408 if(in_array("allow_pwchange",$this->multi_boxes)){
1409 $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1410 $ret['pwdCanChange'] = $this->pwdCanChange;
1411 }
1413 if(in_array("password_expires",$this->multi_boxes)){
1414 $ret['password_expires'] = $this->password_expires;
1415 $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1416 }
1417 if(in_array("logon_time_set",$this->multi_boxes)){
1418 $ret['logon_time_set'] = $this->logon_time_set;
1419 $ret['sambaLogonTime'] = $this->sambaLogonTime;
1420 }
1421 if(in_array("logoff_time_set",$this->multi_boxes)){
1422 $ret['logoff_time_set'] = $this->logoff_time_set;
1423 $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1424 }
1425 if(in_array("kickoff_time_set",$this->multi_boxes)){
1426 $ret['kickoff_time_set'] = $this->kickoff_time_set;
1427 $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1428 }
1430 if(in_array("no_password_required",$this->multi_boxes)){
1431 $ret['no_password_required'] = $this->no_password_required;
1432 }
1434 if(in_array("temporary_disable",$this->multi_boxes)){
1435 $ret['temporary_disable'] = $this->temporary_disable;
1436 }
1438 if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1439 $ret['sambaLogonHours'] = $this->sambaLogonHours;
1440 }
1442 if(in_array("workstation_list",$this->multi_boxes)){
1443 $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1444 }
1445 return($ret);
1446 }
1448 function set_multi_edit_values($values)
1449 {
1450 plugin::set_multi_edit_values($values);
1452 /* Prepare current workstation settings to be merged
1453 * with multiple edit settings.
1454 */
1455 if(isset($values['multiple_sambaUserWorkstations'])){
1456 $cur_ws = array();
1457 $m_ws = $values['multiple_sambaUserWorkstations'];
1459 /* Prepare current settings to be merged */
1460 if(isset($this->sambaUserWorkstations)){
1461 $ttmp = split(",",$this->sambaUserWorkstations);
1462 foreach($ttmp as $station){
1463 $station = trim($station);
1464 if(!empty($station)){
1465 $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1466 }
1467 }
1468 }
1470 /* Unset removed workstations */
1471 foreach($cur_ws as $cur_name => $cur_station){
1472 if(!isset($m_ws[$cur_name])){
1473 unset($cur_ws[$cur_name]);
1474 }
1475 }
1477 /* Add all added workstations */
1478 foreach($m_ws as $name => $station){
1479 if($station['UsedByAllUsers']){
1480 $cur_ws[$name] = $station;
1481 }
1482 }
1484 $this->sambaUserWorkstations = "";
1485 foreach($cur_ws as $name => $ws){
1486 $this->sambaUserWorkstations .= $name.",";
1487 }
1488 $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1489 }
1491 /* Enable disabled terminal login, this is inverted somehow */
1492 if(isset($values['tslogin'])) $this->mungedObject->setTsLogin(!$values['tslogin']);
1494 /* Imherit client configuration */
1495 if(isset($values['inherit'])) $this->mungedObject->setInheritMode($values['inherit']);
1497 /* Get all ctx values posted */
1498 $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1499 "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1500 foreach($ctx as $attr){
1501 if(isset($values[$attr])){
1502 $this->mungedObject->ctx[$attr] = $values[$attr] ;
1503 }
1504 }
1506 if(isset($values['CtxMaxConnectionTimeF'])) $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1507 if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1508 if(isset($values['CtxMaxIdleTimeF'])) $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1510 if(isset($values['connectclientdrives'])) $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1511 if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1512 if(isset($values['defaultprinter'])) $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1514 if(isset($values['shadow'])) $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1515 if(isset($values['brokenconn'])) $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1516 if(isset($values['reconn'])) $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1519 if(isset($values['sambaPwdCanChange'])) $this->sambaPwdCanChange = $values['sambaPwdCanChange'];
1520 if(isset($values['pwdCanChange'])) $this->pwdCanChange = $values['pwdCanChange'];
1525 if(isset($values['password_expires'])){
1526 $this->password_expires = $values['password_expires'];
1527 $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1528 }
1529 if(isset($values['logon_time_set'])){
1530 $this->logon_time_set = $values['logon_time_set'];
1531 $this->sambaLogonTime = $values['sambaLogonTime'];
1532 }
1533 if(isset($values['logoff_time_set'])){
1534 $this->logoff_time_set = $values['logoff_time_set'];
1535 $this->sambaLogoffTime = $values['sambaLogoffTime'];
1536 }
1537 if(isset($values['kickoff_time_set'])){
1538 $this->kickoff_time_set = $values['kickoff_time_set'];
1539 $this->sambaKickoffTime = $values['sambaKickoffTime'];
1540 }
1542 if(isset($values['no_password_required'])){
1543 if($values['no_password_required']){
1544 if(!preg_match("/N/",$this->sambaAcctFlags)) {
1545 $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1546 }
1547 }else{
1548 $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1549 }
1550 }
1552 if(isset($values['temporary_disable'])){
1553 if($values['temporary_disable']){
1554 if(preg_match("/L/",$this->sambaAcctFlags)) {
1555 // Keep L
1556 }else{
1557 $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1558 }
1559 }else{
1560 $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1561 }
1562 }
1563 }
1566 function PrepareForCopyPaste($source)
1567 {
1568 plugin::PrepareForCopyPaste($source);
1570 /* Set a new SID */
1571 $this->sambaSID = "";
1572 }
1574 }
1576 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1577 ?>