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 /* CLI vars */
29 var $cli_summary= "Manage users samba account";
30 var $cli_description= "Some longer text\nfor help";
31 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
33 /* Switch for Samba version */
34 var $samba3= FALSE;
35 var $uidNumber= 65535;
36 var $gidNumber= 65535;
38 /* Samba 2 attributes */
39 var $pwdLastSet= "0";
40 var $logonTime= "0";
41 var $logoffTime= "2147483647";
42 var $kickoffTime= "2147483647";
43 var $pwdCanChange= "0";
44 var $pwdMustChange= "0";
45 var $password_expires= 0;
46 var $acctFlags= "[UX ]";
47 var $smbHome= "";
48 var $homeDrive= "";
49 var $scriptPath= "";
50 var $profilePath= "";
51 var $rid= "";
52 var $primaryGroupID= "";
54 /* Samba 3 attributes */
55 var $SID= "";
56 var $ridBase= 0;
57 var $sambaSID= "";
58 var $sambaPwdLastSet= "0";
59 var $sambaLogonTime= "0";
60 var $sambaLogoffTime= "2147483647";
61 var $sambaKickoffTime= "2147483647";
62 var $sambaPwdCanChange= "";
63 var $sambaPwdMustChange= "0";
64 var $sambaAcctFlags= "[UX ]";
65 var $sambaHomePath= "";
66 var $sambaHomeDrive= "";
67 var $sambaLogonScript= "";
68 var $sambaProfilePath= "";
69 var $sambaPrimaryGroupSID= "";
70 var $sambaDomainName= "";
71 var $sambaUserWorkstations= "";
72 var $sambaBadPasswordCount= "";
73 var $sambaBadPasswordTime= "";
74 var $sambaPasswordHistory= "";
75 var $sambaLogonHours= "";
76 var $orig_sambaDomainName= "";
77 var $sambaMungedDial= "";
78 var $mungedObject;
80 /* Helper */
81 var $show_ws_dialog= FALSE;
82 var $logon_time_set= 0;
83 var $logoff_time_set= 0;
84 var $kickoff_time_set= 0;
86 /* attribute list for save action */
87 var $ctxattributes= array();
88 var $attributes= array();
89 var $objectclasses= array();
91 var $uid= "";
92 var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
94 var $multiple_support = TRUE;
96 /* Only used for multiple edit */
97 var $temporary_disable = FALSE;
98 var $no_password_required = FALSE;
99 var $multiple_sambaUserWorkstations = array();
101 function sambaAccount (&$config, $dn= NULL)
102 {
103 /* Load attributes depending on the samba version */
104 $this->samba3= ($config->current['SAMBAVERSION'] == 3);
106 if ($this->samba3){
107 $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
108 "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
109 "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
110 "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
111 "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
112 "sambaUserWorkstations", "sambaPasswordHistory",
113 "sambaLogonHours", "sambaBadPasswordTime",
114 "sambaBadPasswordCount");
115 $this->objectclasses= array ("sambaSamAccount");
116 $this->mungedObject= new sambaMungedDial;
117 $this->ctxattributes= $this->mungedObject->ctxattributes;
118 } else {
119 $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
120 "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
121 "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
122 $this->objectclasses= array ("sambaAccount");
123 }
125 plugin::plugin ($config, $dn);
127 /* Setting uid to default */
128 if(isset($this->attrs['uid'][0])){
129 $this->uid = $this->attrs['uid'][0];
130 }
132 /* Get samba Domain in case of samba 3 */
133 if ($this->samba3 && $this->sambaSID != ""){
134 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
135 $ldap= $this->config->get_ldap_link();
136 $ldap->cd($this->config->current['BASE']);
137 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
138 if ($ldap->count() != 0){
139 $attrs= $ldap->fetch();
140 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
141 if ($this->sambaDomainName == ""){
142 $this->sambaDomainName= $attrs['sambaDomainName'][0];
143 }
144 } else {
145 if ($this->sambaDomainName == ""){
146 $this->sambaDomainName= "DEFAULT";
147 }
148 $this->ridBase= $this->config->current['RIDBASE'];
149 $this->SID= $this->config->current['SID'];
150 }
152 /* Save in order to compare later on */
153 $this->orig_sambaDomainName= $this->sambaDomainName;
154 }
156 /* Fill mungedDial field */
157 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
158 $this->mungedObject->load($this->sambaMungedDial);
159 }
161 /* Password expiery */
162 if(isset($this->attrs['sambaPwdMustChange']) &&
163 $this->attrs['sambaPwdMustChange'][0] != 0){
164 $this->password_expires= 1;
165 }
167 if(isset($this->attrs['sambaLogonTime']) && ! (
168 $this->attrs['sambaLogonTime'][0] == 0 ||
169 $this->attrs['sambaLogonTime'][0] == 2147483647
170 )){
171 $this->logon_time_set= 1;
172 }
173 if(isset($this->attrs['sambaLogoffTime']) && ! (
174 $this->attrs['sambaLogoffTime'][0] == 0 ||
175 $this->attrs['sambaLogoffTime'][0] == 2147483647
176 )){
177 $this->logoff_time_set= 1;
178 }
180 /* Account expiery */
181 if(isset($this->attrs['sambaKickoffTime']) && ! (
182 $this->attrs['sambaKickoffTime'][0] == 0 ||
183 $this->attrs['sambaKickoffTime'][0] == 2147483647
184 )){
185 $this->kickoff_time_set= 1;
186 }
188 /* Get global filter config */
189 if (!is_global("sambafilter")){
190 $ui= get_userinfo();
191 $base= get_base_from_people($ui->dn);
192 $sambafilter= array( "depselect" => $base, "regex" => "*");
193 register_global("sambafilter", $sambafilter);
194 }
196 /* Save initial account state */
197 $this->initially_was_account= $this->is_account;
198 }
200 function execute()
201 {
202 /* Call parent execute */
203 plugin::execute();
205 /* Log view */
206 if($this->is_account && !$this->view_logged){
207 $this->view_logged = TRUE;
208 new log("view","users/".get_class($this),$this->dn);
209 }
211 /* Do we need to flip is_account state? */
212 if (isset($_POST['modify_state'])){
213 $this->is_account= !$this->is_account;
214 }
215 /* Do we represent a valid account? */
216 if (!$this->is_account && $this->parent === NULL){
217 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
218 _("This account has no samba extensions.")."</b>";
219 $display.= back_to_main();
220 return ($display);
221 }
223 $display ="";
224 if(!$this->multiple_support_active){
226 /* Show tab dialog headers */
227 $display= "";
228 if ($this->parent !== NULL){
229 if ($this->is_account){
230 $display= $this->show_disable_header(_("Remove samba account"),
231 _("This account has samba features enabled. You can disable them by clicking below."));
232 } else {
233 $obj= $this->parent->by_object['posixAccount'];
235 /* Samba3 dependency on posix accounts are enabled
236 in the moment, because I need to rely on unique
237 uidNumbers. There'll be a better solution later
238 on. */
239 if ($obj->is_account){
240 $display= $this->show_enable_header(_("Create samba account"),
241 _("This account has samba features disabled. You can enable them by clicking below."));
242 } else {
243 $display= $this->show_enable_header(_("Create samba account"),
244 _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
245 }
246 return ($display);
247 }
248 }
249 }
251 $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
253 /* Open Samaba Logong hours dialog */
254 if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
255 $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
256 }
258 /* Cancel dialog */
259 if(isset($_POST['cancel_logonHours'])){
260 $this->dialog = FALSE;
261 }
263 /* Save selected logon hours */
264 if(isset($_POST['save_logonHours'])){
265 $this->dialog->save_object();
266 if($this->acl_is_writeable("sambaLogonHours")){
267 $this->sambaLogonHours = $this->dialog->save();
268 }
269 $this->dialog = FALSE;
270 }
272 /* Display dialog */
273 if((isset($this->dialog)) && (is_object($this->dialog))){
274 $this->dialog->save_object();
275 return($this->dialog->execute());
276 }
278 /* Prepare templating */
279 $smarty= get_smarty();
281 $tmp = $this->plInfo();
282 foreach($tmp['plProvidedAcls'] as $var => $rest){
283 $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
284 }
286 if ($this->sambaPwdMustChange=="0"){
287 $date= getdate();
288 } else {
289 $date= getdate($this->sambaPwdMustChange);
290 }
292 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
293 $sambaLogonTime_date= getdate();
294 } else {
295 $sambaLogonTime_date= getdate($this->sambaLogonTime);
296 }
298 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
299 $sambaLogoffTime_date= getdate();
300 } else {
301 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
302 }
304 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
305 $sambaKickoffTime_date= getdate();
306 } else {
307 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
308 }
310 /* Remove user workstations? */
311 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
313 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
315 if($this->multiple_support_active){
316 foreach($_POST['workstation_list'] as $name){
317 if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
318 unset($this->multiple_sambaUserWorkstations[trim($name)]);
319 }
320 }
321 }else{
322 $tmp= $this->sambaUserWorkstations;
323 foreach($_POST['workstation_list'] as $name){
324 $tmp= preg_replace("/$name/", '', $tmp);
325 $this->is_modified= TRUE;
326 }
327 $tmp= preg_replace('/,+/', ',', $tmp);
328 $this->sambaUserWorkstations= trim($tmp, ',');
329 }
330 }
331 }
333 /* Add user workstation? */
334 if (isset($_POST["add_ws"])){
335 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
336 $this->show_ws_dialog= TRUE;
337 $this->dialog= TRUE;
338 }
339 }
341 /* Add user workstation finished? */
342 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
343 $this->show_ws_dialog= FALSE;
344 $this->dialog= FALSE;
345 }
347 /* Add user workstation? */
348 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
350 if($this->multiple_support_active){
351 foreach($_POST['wslist'] as $ws){
352 $this->multiple_sambaUserWorkstations[trim($we)] = array("Name" => trim($ws), "UsedByAllUsers" => TRUE);
353 }
354 }else{
355 $tmp= $this->sambaUserWorkstations;
356 foreach($_POST['wslist'] as $ws){
357 $tmp.= ",$ws";
358 }
359 $tmp= preg_replace('/,+/', ',', $tmp);
360 $this->sambaUserWorkstations= trim($tmp, ',');
361 }
362 $this->is_modified= TRUE;
363 }
365 /* Show ws dialog */
366 if ($this->show_ws_dialog){
368 /* Save data */
369 $sambafilter= get_global("sambafilter");
370 foreach( array("depselect", "regex") as $type){
371 if (isset($_POST[$type])){
372 $sambafilter[$type]= $_POST[$type];
373 }
374 }
375 if (isset($_GET['search'])){
376 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
377 if ($s == "**"){
378 $s= "*";
379 }
380 $sambafilter['regex']= $s;
381 }
382 register_global("sambafilter", $sambafilter);
384 /* Get workstation list */
385 $exclude= "";
387 if($this->multiple_support_active){
388 foreach($this->multiple_sambaUserWorkstations as $ws){
389 if($ws['UsedByAllUsers']){
390 $exclude.= "(cn=".$ws['Name']."$)";
391 }
392 }
393 }else{
394 foreach(split(',', $this->sambaUserWorkstations) as $ws){
395 $exclude.= "(cn=$ws$)";
396 }
397 }
398 if ($exclude != ""){
399 $exclude= "(!(|$exclude))";
400 }
401 $regex= $sambafilter['regex'];
402 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
403 $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
405 $wslist= array();
406 foreach ($res as $attrs){
407 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
408 }
409 asort($wslist);
411 $smarty->assign("search_image", get_template_path('images/search.png'));
412 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
413 $smarty->assign("tree_image", get_template_path('images/tree.png'));
414 $smarty->assign("deplist", $this->config->idepartments);
415 $smarty->assign("alphabet", generate_alphabet());
416 foreach( array("depselect", "regex") as $type){
417 $smarty->assign("$type", $sambafilter[$type]);
418 }
419 $smarty->assign("hint", print_sizelimit_warning());
420 $smarty->assign("wslist", $wslist);
421 $smarty->assign("apply", apply_filter());
422 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
423 dirname(__FILE__)));
424 return ($display);
425 }
427 /* Fill calendar */
428 $days= array();
429 for($d= 1; $d<32; $d++){
430 $days[]= $d;
431 }
432 $years= array();
433 for($y= $date['year']-4; $y<$date['year']+4; $y++){
434 $years[]= $y;
435 }
436 $months= array(_("January"), _("February"), _("March"), _("April"),
437 _("May"), _("June"), _("July"), _("August"), _("September"),
438 _("October"), _("November"), _("December"));
439 $smarty->assign("day", $date["mday"]);
440 $smarty->assign("days", $days);
441 $smarty->assign("months", $months);
442 $smarty->assign("month", $date["mon"]-1);
443 $smarty->assign("years", $years);
444 $smarty->assign("year", $date["year"]);
446 $sambaLogonTime_days= array();
447 for($d= 1; $d<32; $d++){
448 $sambaLogonTime_days[]= $d;
449 }
450 $sambaLogonTime_years= array();
451 for($y= $date['year']-4; $y<$date['year']+4; $y++){
452 $sambaLogonTime_years[]= $y;
453 }
454 $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
455 _("May"), _("June"), _("July"), _("August"), _("September"),
456 _("October"), _("November"), _("December"));
457 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
458 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
459 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
460 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
461 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
462 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
464 $sambaLogoffTime_days= array();
465 for($d= 1; $d<32; $d++){
466 $sambaLogoffTime_days[]= $d;
467 }
468 $sambaLogoffTime_years= array();
469 for($y= $date['year']-4; $y<$date['year']+4; $y++){
470 $sambaLogoffTime_years[]= $y;
471 }
472 $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
473 _("May"), _("June"), _("July"), _("August"), _("September"),
474 _("October"), _("November"), _("December"));
475 $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
476 $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
477 $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
478 $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
479 $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
480 $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
482 $sambaKickoffTime_days= array();
483 for($d= 1; $d<32; $d++){
484 $sambaKickoffTime_days[]= $d;
485 }
486 $sambaKickoffTime_years= array();
487 for($y= $date['year']-4; $y<$date['year']+4; $y++){
488 $sambaKickoffTime_years[]= $y;
489 }
490 $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
491 _("May"), _("June"), _("July"), _("August"), _("September"),
492 _("October"), _("November"), _("December"));
493 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
494 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
495 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
496 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
497 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
498 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
499 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
501 /* Fill boxes */
502 if ($this->samba3){
503 $domains= array();
504 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
505 $domains[]= $name;
506 }
507 $smarty->assign("domains", $domains);
508 }
509 $letters= array();
510 for ($i= 68; $i<91; $i++){
511 $letters[]= chr($i).":";
512 }
513 $smarty->assign("drives", $letters);
515 /* Fill terminal server settings */
516 if ($this->samba3){
517 foreach ($this->ctxattributes as $attr){
518 /* Fill common attributes */
519 if (isset($this->mungedObject->ctx[$attr])){
520 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
521 // Set field to blank if value is 0
522 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
523 if($this->mungedObject->ctx[$attr] == 0) {
524 $smarty->assign("$attr", "");
525 }
526 }
527 } else {
528 $smarty->assign("$attr", "");
529 }
530 }
532 /* Assign enum values for preset items */
533 $shadowModeVals= array( "0" => _("disabled"),
534 "1" => _("input on, notify on"),
535 "2" => _("input on, notify off"),
536 "3" => _("input off, notify on"),
537 "4" => _("input off, nofify off"));
539 $brokenConnModeVals= array( "0" => _("disconnect"),
540 "1" => _("reset"));
542 $reConnModeVals= array( "0" => _("from any client"),
543 "1" => _("from previous client only"));
545 /* Fill preset items */
546 $smarty->assign("shadow", $shadowModeVals);
547 $smarty->assign("brokenconn", $brokenConnModeVals);
548 $smarty->assign("reconn", $reConnModeVals);
550 /* Fill preset items with values */
551 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
552 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
553 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
555 if($_SESSION['js']){
556 /* Set form elements to disabled/enable state */
557 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
559 $smarty->assign("inheritstate", "");
560 if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
561 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
562 }
566 }else{
567 $smarty->assign("tsloginstate", "");
568 $smarty->assign("inheritstate", "");
569 }
571 /* Set checkboxes to checked or unchecked state */
572 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
573 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
574 $smarty->assign("connectclientdrives",
575 $this->mungedObject->getConnectClientDrives()?"checked":"");
576 $smarty->assign("connectclientprinters",
577 $this->mungedObject->getConnectClientPrinters()?"checked":"");
578 $smarty->assign("defaultprinter",
579 $this->mungedObject->getDefaultPrinter()?"checked":"");
580 $smarty->assign("CtxMaxConnectionTimeF",
581 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
582 $smarty->assign("CtxMaxDisconnectionTimeF",
583 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
584 $smarty->assign("CtxMaxIdleTimeF",
585 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
588 /* Fill sambaUserWorkstations */
589 $ws= split(",", $this->sambaUserWorkstations);
590 sort($ws);
592 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
593 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
595 if($this->multiple_support_active){
596 $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
597 }
599 $smarty->assign("workstations", $ws);
600 }
602 /* Variables */
603 foreach($this->attributes as $val){
604 $smarty->assign("$val", $this->$val);
605 }
607 /* 'sambaAcctFlags' checkboxes */
608 /* Check for 'lock-account'-flag: 'D' or 'L' */
609 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
610 is_integer(strpos($this->sambaAcctFlags, "L"))) {
611 $smarty->assign("flagsD", "checked");
612 } else {
613 $smarty->assign("flagsD", "");
614 }
616 /* Check for no_password_required flag 'N' */
617 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
618 $smarty->assign("flagsN", "checked");
619 } else {
620 $smarty->assign("flagsN", "");
621 }
623 if($this->samba3){
624 if ($this->sambaPwdCanChange=="1"){
625 $smarty->assign("flagsP", "checked");
626 } else {
627 $smarty->assign("flagsP", "");
628 }
629 }else{
630 if ($this->pwdCanChange=="1"){
631 $smarty->assign("flagsP", "checked");
632 } else {
633 $smarty->assign("flagsP", "");
634 }
635 }
637 if ($this->password_expires=="1"){
638 $smarty->assign("flagsC", "checked");
639 } else {
640 $smarty->assign("flagsC", "");
641 }
642 if ($this->logon_time_set=="1"){
643 $smarty->assign("flagsT", "checked");
644 } else {
645 $smarty->assign("flagsT", "");
646 }
647 if ($this->logoff_time_set=="1"){
648 $smarty->assign("flagsO", "checked");
649 } else {
650 $smarty->assign("flagsO", "");
651 }
652 if ($this->kickoff_time_set=="1"){
653 $smarty->assign("flagsK", "checked");
654 } else {
655 $smarty->assign("flagsK", "");
656 }
659 /* In case of javascript, disable some fields on demand */
660 if ($this->samba3){
661 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
662 $smarty->assign("$key", "$value");
663 }
664 }
667 foreach($this->attributes as $attr){
668 if(in_array($attr,$this->multi_boxes)){
669 $smarty->assign("use_".$attr,TRUE);
670 }else{
671 $smarty->assign("use_".$attr,FALSE);
672 }
673 }
674 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
675 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
676 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
677 "onnectclientprinters","defaultprinter","shadow","brokenconn",
678 "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
679 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
680 "workstation_list") as $attr){
681 if(in_array($attr,$this->multi_boxes)){
682 $smarty->assign("use_".$attr,TRUE);
683 }else{
684 $smarty->assign("use_".$attr,FALSE);
685 }
686 }
688 /* Show main page */
689 $smarty->assign("multiple_support",$this->multiple_support_active);
690 if ($this->samba3){
691 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
692 } else {
693 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
694 }
696 return ($display);
697 }
699 function remove_from_parent()
700 {
701 /* Cancel if there's nothing to do here */
702 if (!$this->initially_was_account){
703 return;
704 }
706 /* include global link_info */
707 $ldap= $this->config->get_ldap_link();
709 plugin::remove_from_parent();
711 /* Keep uid attribute for gosaAccount */
712 unset($this->attrs['uid']);
713 unset($this->attrs['uidNumber']);
714 unset($this->attrs['gidNumber']);
716 /* Remove objectClass for sambaIdmapEntry */
717 $tmp= array();
718 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
719 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
720 $tmp[]= $this->attrs['objectClass'][$i];
721 }
722 }
723 $this->attrs['objectClass']= $tmp;
725 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
726 $this->attributes, "Save");
727 $ldap->cd($this->dn);
728 $this->cleanup();
729 $ldap->modify ($this->attrs);
731 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
733 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
735 /* Optionally execute a command after we're done */
736 $this->handle_post_events("remove", array("uid" => $this->uid));
737 }
740 /* Check for input problems */
741 function check()
742 {
743 /* Call common method to give check the hook */
744 $message= plugin::check();
746 if ($this->samba3){
748 /* Strings */
749 foreach (array( "sambaHomePath" => _("Home directory"),
750 "sambaProfilePath" => _("Profile path")) as $key => $val){
751 if (!$this->mungedObject->is_samba_path($this->$key)){
752 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
753 }
754 }
756 /* Numeric values */
757 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
758 "CtxMaxDisconnectionTime" => _("Disconnection"),
759 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
761 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
762 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
763 }
764 }
766 /* Too many workstations? Windows usrmgr only supports eight */
767 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
768 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
769 }
770 }
772 return ($message);
773 }
776 /* Save data to object */
777 function save_object()
778 {
780 $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
782 /* We only care if we are on the sambaTab... */
783 if (isset($_POST['sambaTab'])){
784 plugin::save_object();
786 /* Take care about access options */
787 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
788 if ($this->samba3){
789 $attrname= "sambaPwdCanChange";
790 } else {
791 $attrname= "pwdCanChange";
792 }
793 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
794 $tmp= 1;
795 } else {
796 $tmp= 0;
797 }
798 if ($this->$attrname != $tmp){
799 $this->is_modified= TRUE;
800 }
801 $this->pwdCanChange= $tmp;
802 $this->sambaPwdCanChange= $tmp;
803 }
804 $tmp= "UX";
805 $this->no_password_required = FALSE;
806 if (isset($_POST["no_password_required"])){
807 if ($_POST["no_password_required"] == 1){
808 $tmp.= "N";
809 $this->no_password_required = TRUE;
810 }
811 }
812 if (isset($_POST["password_expires"])){
813 if ($_POST["password_expires"] == 1){
814 $this->password_expires= 1;
815 }
816 } else {
817 $this->password_expires= 0;
818 }
819 $this->temporary_disable = FALSE;
820 if (isset($_POST["temporary_disable"])){
821 if ($_POST["temporary_disable"] == 1){
822 $this->temporary_disable = TRUE;
823 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
824 $tmp.= "L";
825 } else {
826 $tmp.= "D";
827 }
828 }
829 }
830 if (isset($_POST["logon_time_set"])){
831 if ($_POST["logon_time_set"] == 1){
832 $this->logon_time_set= 1;
833 }
834 } else {
835 $this->logon_time_set= 0;
836 }
837 if (isset($_POST["logoff_time_set"])){
838 if ($_POST["logoff_time_set"] == 1){
839 $this->logoff_time_set= 1;
840 }
841 } else {
842 $this->logoff_time_set= 0;
843 }
844 if (isset($_POST["kickoff_time_set"])){
845 if ($_POST["kickoff_time_set"] == 1){
846 $this->kickoff_time_set= 1;
847 }
848 } else {
849 $this->kickoff_time_set= 0;
850 }
852 $fill= "";
853 for ($i= strlen($tmp); $i<12; $i++){
854 $fill.= " ";
855 }
857 $tmp= "[$tmp$fill]";
859 /* Only save if acl's are set */
860 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
861 if ($this->samba3){
862 $attrname= "sambaAcctFlags";
863 } else {
864 $attrname= "acctFlags";
865 }
866 if ($this->$attrname != $tmp){
867 $this->is_modified= TRUE;
868 }
869 $this->$attrname= $tmp;
870 }
872 /* Save sambaDomain attribute */
873 if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
874 $this->sambaDomainName= validate($_POST['sambaDomainName']);
875 }
877 /* Save CTX values */
878 if ($this->samba3){
880 /* Save obvious values */
881 foreach($this->ctxattributes as $val){
882 if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
883 if (get_magic_quotes_gpc()) {
884 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
885 } else {
886 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
887 }
888 }
889 }
891 /* Save checkbox states. */
892 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
893 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
894 // Need to do some index checking to avoid messages like "index ... not found"
895 if(isset($_POST['brokenconn'])) {
896 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
897 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
898 }
899 if(isset($_POST['reconn'])) {
900 $this->mungedObject->setReConn($_POST['reconn'] == '1'
901 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
902 }
903 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
904 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
905 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
906 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
907 $this->mungedObject->setCtxMaxDisconnectionTimeF(
908 !isset($_POST['CtxMaxDisconnectionTimeF'])
909 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
910 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
911 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
912 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
913 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
914 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
915 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
916 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
917 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
919 /* Save combo boxes. Takes two values */
920 if(isset($_POST['reconn'])) {
921 $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
922 }
924 /* Check for changes */
925 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
926 $this->is_modified= TRUE;
927 }
928 }
929 }
930 }
933 /* Save to LDAP */
934 function save()
935 {
936 /* Load uid and gid of this 'dn' */
937 $ldap= $this->config->get_ldap_link();
938 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
939 $tmp= $ldap->fetch();
940 $this->uidNumber= $tmp['uidNumber'][0];
941 $this->gidNumber= $tmp['gidNumber'][0];
943 plugin::save();
945 /* Remove objectClass for sambaIdmapEntry */
946 $tmp= array();
947 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
948 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
949 $tmp[]= $this->attrs['objectClass'][$i];
950 }
951 }
952 $this->attrs['objectClass']= $tmp;
954 /* Generate rid / primaryGroupId */
955 if ($this->samba3){
956 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
957 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
958 } else {
959 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
960 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
961 }
963 /* Need to generate a new uniqe uid/gid combination? */
964 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
965 $uidNumber= $this->uidNumber;
966 while(TRUE){
967 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
968 $ldap->cd($this->config->current['BASE']);
969 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
970 if ($ldap->count() == 0){
971 break;
972 }
973 $uidNumber++;
974 }
975 $this->attrs['sambaSID']= $sid;
977 /* Check for users primary group */
978 $ldap->cd($this->config->current['BASE']);
979 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
980 if ($ldap->count() != 1){
981 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
982 } else {
983 $attrs= $ldap->fetch();
984 $g= new group($this->config, $ldap->getDN());
985 if ($g->sambaSID == ""){
986 $g->sambaDomainName= $this->sambaDomainName;
987 $g->smbgroup= TRUE;
988 $g->save ();
989 }
990 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
991 }
992 }
994 if ($this->sambaHomeDrive == ""){
995 $this->attrs["sambaHomeDrive"]= array();
996 }
998 /* Generate munged dial value */
999 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1001 /* User wants me to fake the idMappings? This is useful for
1002 making winbind resolve the user names in a reasonable amount
1003 of time in combination with larger databases. */
1004 if (isset($this->config->current['SAMBAIDMAPPING']) &&
1005 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
1006 $this->attrs['objectClass'][]= "sambaIdmapEntry";
1007 }
1010 /* Password expiery */
1011 if ($this->password_expires == "1"){
1012 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1013 } else {
1014 $this->attrs['sambaPwdMustChange']= array();
1015 }
1016 /* Make sure not to save zero in sambaPwdLastset */
1017 if ($this->sambaPwdLastSet != "0"){
1018 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1019 } else {
1020 $this->attrs['sambaPwdLastSet']= array();
1021 }
1022 /* Account expiery */
1023 if ($this->logon_time_set == "1"){
1024 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1025 } else {
1026 $this->attrs['sambaLogonTime']= array();
1027 }
1028 if ($this->logoff_time_set == "1"){
1029 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1030 } else {
1031 $this->attrs['sambaLogoffTime']= array();
1032 }
1033 if ($this->kickoff_time_set == "1"){
1034 # Add one day in unixtime format to be compatible with usrmgr
1035 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
1036 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
1037 } else {
1038 $this->attrs['sambaKickoffTime']= array();
1039 }
1040 } else {
1041 /* Not samba3 */
1042 $this->attrs['rid']= $this->uidNumber*2 + 1000;
1043 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1045 if ($this->homeDrive == ""){
1046 $this->attrs["homeDrive"]= array();
1047 }
1049 /* Password expiery */
1050 if ($this->password_expires == "1"){
1051 $this->attrs['pwdMustChange']= $this->pwdMustChange;
1052 } else {
1053 $this->attrs['pwdMustChange']= 2147483647;
1054 }
1055 /* Make sure not to save zero in pwdLastset */
1056 if ($this->pwdLastSet != "0"){
1057 $this->attrs['pwdLastSet']= $this->pwdLastSet;
1058 } else {
1059 $this->attrs['pwdLastSet']= array();
1060 }
1061 /* Account expiery */
1062 if ($this->logon_time_set == "1"){
1063 $this->attrs['logonTime']= $this->logonTime;
1064 } else {
1065 $this->attrs['logonTime']= array();
1066 }
1067 if ($this->logoff_time_set == "1"){
1068 $this->attrs['logoffTime']= $this->logoffTime;
1069 } else {
1070 $this->attrs['logoffTime']= array();
1071 }
1072 if ($this->kickoff_time_set == "1"){
1073 # Add one day in unixtime format to be compatible with usrmgr
1074 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1075 } else {
1076 $this->attrs['kickoffTime']= array();
1077 }
1078 }
1080 /* Write back to ldap */
1081 $ldap->cd($this->dn);
1082 $this->cleanup();
1083 $ldap->modify ($this->attrs);
1085 if($this->initially_was_account){
1086 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1087 }else{
1088 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1089 }
1091 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
1093 /* Optionally execute a command after we're done */
1094 if ($this->initially_was_account == $this->is_account){
1095 if ($this->is_modified){
1096 $this->handle_post_events("modify", array("uid" => $this->uid));
1097 }
1098 } else {
1099 $this->handle_post_events("add", array("uid" => $this->uid));
1100 }
1101 }
1104 /* Force password set, if this account doesn't have any samba passwords */
1105 function password_change_needed()
1106 {
1107 if(!$this->initially_was_account && $this->is_account){
1108 $ldap = $this->config->get_ldap_link();
1109 $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1110 $attrs = $ldap->fetch();
1111 if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1112 return(TRUE);
1113 }
1114 }
1115 return(FALSE);
1116 }
1119 function adapt_from_template($dn)
1120 {
1121 plugin::adapt_from_template($dn);
1122 $this->sambaSID= "";
1123 $this->sambaPrimaryGroupSID= "";
1125 /* Fill mungedDial field */
1126 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1127 $this->mungedObject->load($this->sambaMungedDial);
1128 }
1130 /* Password expiery */
1131 if(isset($this->attrs['sambaPwdMustChange']) &&
1132 $this->attrs['sambaPwdMustChange'][0] != 0){
1133 $this->password_expires= 1;
1134 }
1136 if(isset($this->attrs['sambaLogonTime']) && ! (
1137 $this->attrs['sambaLogonTime'][0] == 0 ||
1138 $this->attrs['sambaLogonTime'][0] == 2147483647
1139 )){
1140 $this->logon_time_set= 1;
1141 }
1142 if(isset($this->attrs['sambaLogoffTime']) && ! (
1143 $this->attrs['sambaLogoffTime'][0] == 0 ||
1144 $this->attrs['sambaLogoffTime'][0] == 2147483647
1145 )){
1146 $this->logoff_time_set= 1;
1147 }
1149 /* Account expiery */
1150 if(isset($this->attrs['sambaKickoffTime']) && ! (
1151 $this->attrs['sambaKickoffTime'][0] == 0 ||
1152 $this->attrs['sambaKickoffTime'][0] == 2147483647
1153 )){
1154 $this->kickoff_time_set= 1;
1155 }
1157 /* Get global filter config */
1158 if (!is_global("sambafilter")){
1159 $ui= get_userinfo();
1160 $base= get_base_from_people($ui->dn);
1161 $sambafilter= array( "depselect" => $base, "regex" => "*");
1162 register_global("sambafilter", $sambafilter);
1163 }
1164 }
1167 static function plInfo()
1168 {
1169 return (array(
1170 "plShortName" => _("Samba"),
1171 "plDescription" => _("Samba settings"),
1172 "plSelfModify" => TRUE,
1173 "plDepends" => array("user"),
1174 "plPriority" => 5,
1175 "plSection" => array("personal" => _("My account")),
1176 "plCategory" => array("users"),
1177 "plOptions" => array(),
1179 "plProvidedAcls" => array(
1180 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1181 "InheritClientConfig" => _("Inherit client config"),
1183 "sambaPwdCanChange" => _("Allow user to change password") ,
1184 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1185 "sambaAcctFlagsL" => _("Lock samba account"),
1188 "sambaKickoffTime" => _("Account expires") ,
1189 "sambaPwdMustChange" => _("Password expires") ,
1191 "sambaLogonTime" => _("Limit Logon Time") ,
1192 "sambaLogoffTime" => _("Limit Logoff Time") ,
1193 "sambaLogonHours" => _("Logon hours") ,
1195 "sambaHomePath" => _("Generic home directory") ,
1196 "sambaHomeDrive" => _("Generic samba home drive") ,
1197 "sambaLogonScript" => _("Generic script path") ,
1198 "sambaProfilePath" => _("Generic profile path") ,
1199 "sambaDomainName" => _("Domain") ,
1200 "sambaUserWorkstations" => _("Allow connection from")))
1201 );
1202 }
1204 function enable_multiple_support()
1205 {
1206 plugin::enable_multiple_support();
1207 if($this->samba3){
1208 $this->multiple_support_active = TRUE;
1209 }else{
1210 $this->multiple_support_active = FALSE;
1211 }
1212 }
1214 function multiple_save_object()
1215 {
1216 if (isset($_POST['sambaTab'])){
1217 $this->save_object();
1218 plugin::multiple_save_object();
1219 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1220 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1221 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1222 "onnectclientprinters","defaultprinter","shadow","brokenconn",
1223 "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1224 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1225 "workstation_list") as $attr){
1226 if(isset($_POST["use_".$attr])){
1227 $this->multi_boxes[] = $attr;
1228 }
1229 }
1230 }
1231 }
1234 function get_multi_init_values()
1235 {
1236 $ret = plugin::get_multi_init_values();
1238 /* Parse given sambaUserWorkstations into array
1239 * to allow "init_multiple_support()" to detect multiple used workstations.
1240 * Those workstations will be displayed in light grey.
1241 */
1242 $tmp2 = array("count" => 0);
1243 $tmp = split(",", $this->sambaUserWorkstations);
1244 foreach($tmp as $station){
1245 $station = trim($station);
1246 if(!empty($station)){
1247 $tmp2[] = $station;
1248 $tmp2['count'] ++;
1249 }
1250 }
1251 $ret['sambaUserWorkstations'] = $tmp2;
1252 return($ret);
1253 }
1257 function init_multiple_support($attrs,$all)
1258 {
1259 plugin::init_multiple_support($attrs,$all);
1261 $this->multiple_sambaUserWorkstations = array();
1262 if(isset($all['sambaUserWorkstations'])){
1263 for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1264 $station = trim($all['sambaUserWorkstations'][$i]);
1265 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1266 }
1267 }
1268 if(isset($attrs['sambaUserWorkstations'])){
1269 for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1270 $station = trim($attrs['sambaUserWorkstations'][$i]);
1271 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1272 }
1273 }
1274 }
1276 function multiple_execute()
1277 {
1278 return($this->execute());
1279 }
1281 function get_multi_edit_values()
1282 {
1283 $ret = plugin::get_multi_edit_values();
1285 /* Terminal Server */
1286 if(in_array("tslogin",$this->multi_boxes)){
1287 $ret['tslogin'] = $this->mungedObject->getTsLogin();
1288 }
1289 if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1290 $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1291 }
1292 if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1293 $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1294 }
1295 if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1296 $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1297 }
1299 if(in_array("inherit",$this->multi_boxes)){
1300 $ret['inherit'] = $this->mungedObject->getInheritMode();
1301 }
1302 if(in_array("CtxInitialProgram",$this->multi_boxes)){
1303 $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1304 }
1305 if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1306 $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1307 }
1309 /* Time Limits. Be careful here, there are some negations */
1310 if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1311 $ret["CtxMaxConnectionTimeF"] = !$this->mungedObject->getCtxMaxConnectionTimeF();
1312 if(!$ret["CtxMaxConnectionTimeF"]){
1313 $ret["CtxMaxConnectionTime"] = $this->mungedObject->ctx['CtxMaxConnectionTime'];
1314 }
1315 }
1316 if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1317 $ret["CtxMaxDisconnectionTimeF"]= !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1318 if(!$ret["CtxMaxDisconnectionTimeF"]){
1319 $ret["CtxMaxDisconnectionTime"]= $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1320 }
1321 }
1322 if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1323 $ret["CtxMaxIdleTimeF"] = !$this->mungedObject->getCtxMaxIdleTimeF();
1324 if(!$ret["CtxMaxIdleTimeF"]){
1325 $ret["CtxMaxIdleTime"] = $this->mungedObject->ctx['CtxMaxIdleTime'];
1326 }
1327 }
1329 /* Client Devices */
1330 if(in_array("connectclientdrives",$this->multi_boxes)){
1331 $ret["connectclientdrives"] = $this->mungedObject->getConnectClientDrives();
1332 }
1333 if(in_array("connectclientprinters",$this->multi_boxes)){
1334 $ret["connectclientprinters"] = $this->mungedObject->getConnectClientPrinters();
1335 }
1336 if(in_array("defaultprinter",$this->multi_boxes)){
1337 $ret["defaultprinter"] = $this->mungedObject->getDefaultPrinter();
1338 }
1340 /* Misc */
1341 if(in_array("shadow",$this->multi_boxes)){
1342 $ret["shadow"] =$this->mungedObject->getShadow();
1343 }
1344 if(in_array("brokenconn",$this->multi_boxes)){
1345 $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1346 }
1347 if(in_array("reconn",$this->multi_boxes)){
1348 $ret["reconn"] =$this->mungedObject->getReConn();
1349 }
1351 /* Flags */
1352 if(in_array("allow_pwchange",$this->multi_boxes)){
1353 $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1354 $ret['pwdCanChange'] = $this->pwdCanChange;
1355 }
1357 if(in_array("password_expires",$this->multi_boxes)){
1358 $ret['password_expires'] = $this->password_expires;
1359 $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1360 }
1361 if(in_array("logon_time_set",$this->multi_boxes)){
1362 $ret['logon_time_set'] = $this->logon_time_set;
1363 $ret['sambaLogonTime'] = $this->sambaLogonTime;
1364 }
1365 if(in_array("logoff_time_set",$this->multi_boxes)){
1366 $ret['logoff_time_set'] = $this->logoff_time_set;
1367 $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1368 }
1369 if(in_array("kickoff_time_set",$this->multi_boxes)){
1370 $ret['kickoff_time_set'] = $this->kickoff_time_set;
1371 $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1372 }
1374 if(in_array("no_password_required",$this->multi_boxes)){
1375 $ret['no_password_required'] = $this->no_password_required;
1376 }
1378 if(in_array("temporary_disable",$this->multi_boxes)){
1379 $ret['temporary_disable'] = $this->temporary_disable;
1380 }
1382 if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1383 $ret['sambaLogonHours'] = $this->sambaLogonHours;
1384 }
1386 if(in_array("workstation_list",$this->multi_boxes)){
1387 $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1388 }
1389 return($ret);
1390 }
1392 function set_multi_edit_values($values)
1393 {
1394 plugin::set_multi_edit_values($values);
1396 /* Prepare current workstation settings to be merged
1397 * with multiple edit settings.
1398 */
1399 if(isset($values['multiple_sambaUserWorkstations'])){
1400 $cur_ws = array();
1401 $m_ws = $values['multiple_sambaUserWorkstations'];
1403 /* Prepare current settings to be merged */
1404 if(isset($this->sambaUserWorkstations)){
1405 $ttmp = split(",",$this->sambaUserWorkstations);
1406 foreach($ttmp as $station){
1407 $station = trim($station);
1408 if(!empty($station)){
1409 $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1410 }
1411 }
1412 }
1414 /* Unset removed workstations */
1415 foreach($cur_ws as $cur_name => $cur_station){
1416 if(!isset($m_ws[$cur_name])){
1417 unset($cur_ws[$cur_name]);
1418 }
1419 }
1421 /* Add all added workstations */
1422 foreach($m_ws as $name => $station){
1423 if($station['UsedByAllUsers']){
1424 $cur_ws[$name] = $station;
1425 }
1426 }
1428 $this->sambaUserWorkstations = "";
1429 foreach($cur_ws as $name => $ws){
1430 $this->sambaUserWorkstations .= $name.",";
1431 }
1432 $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1433 }
1435 /* Enable disabled terminal login, this is inverted somehow */
1436 if(isset($values['tslogin'])) $this->mungedObject->setTsLogin(!$values['tslogin']);
1438 /* Imherit client configuration */
1439 if(isset($values['inherit'])) $this->mungedObject->setInheritMode($values['inherit']);
1441 /* Get all ctx values posted */
1442 $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1443 "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1444 foreach($ctx as $attr){
1445 if(isset($values[$attr])){
1446 $this->mungedObject->ctx[$attr] = $values[$attr] ;
1447 }
1448 }
1450 if(isset($values['CtxMaxConnectionTimeF'])) $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1451 if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1452 if(isset($values['CtxMaxIdleTimeF'])) $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1454 if(isset($values['connectclientdrives'])) $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1455 if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1456 if(isset($values['defaultprinter'])) $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1458 if(isset($values['shadow'])) $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1459 if(isset($values['brokenconn'])) $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1460 if(isset($values['reconn'])) $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1463 if(isset($values['sambaPwdCanChange'])) $this->sambaPwdCanChange = $values['sambaPwdCanChange'];
1464 if(isset($values['pwdCanChange'])) $this->pwdCanChange = $values['pwdCanChange'];
1469 if(isset($values['password_expires'])){
1470 $this->password_expires = $values['password_expires'];
1471 $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1472 }
1473 if(isset($values['logon_time_set'])){
1474 $this->logon_time_set = $values['logon_time_set'];
1475 $this->sambaLogonTime = $values['sambaLogonTime'];
1476 }
1477 if(isset($values['logoff_time_set'])){
1478 $this->logoff_time_set = $values['logoff_time_set'];
1479 $this->sambaLogoffTime = $values['sambaLogoffTime'];
1480 }
1481 if(isset($values['kickoff_time_set'])){
1482 $this->kickoff_time_set = $values['kickoff_time_set'];
1483 $this->sambaKickoffTime = $values['sambaKickoffTime'];
1484 }
1486 if(isset($values['no_password_required'])){
1487 if($values['no_password_required']){
1488 if(!preg_match("/N/",$this->sambaAcctFlags)) {
1489 $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1490 }
1491 }else{
1492 $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1493 }
1494 }
1496 if(isset($values['temporary_disable'])){
1497 if($values['temporary_disable']){
1498 if(preg_match("/L/",$this->sambaAcctFlags)) {
1499 // Keep L
1500 }else{
1501 $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1502 }
1503 }else{
1504 $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1505 }
1506 }
1507 }
1508 }
1510 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1511 ?>