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')){
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 /* Strings */
754 foreach (array( "sambaHomePath" => _("Home directory"),
755 "sambaProfilePath" => _("Profile path")) as $key => $val){
756 if (!$this->mungedObject->is_samba_path($this->$key)){
757 $message[]= msgPool::invalid($val);
758 }
759 }
761 /* Numeric values */
762 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
763 "CtxMaxDisconnectionTime" => _("Disconnection"),
764 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
766 if (isset($this->mungedObject->ctx[$key]) && !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
767 $message[]= msgPool::invalid($val);
768 }
769 }
771 /* Too many workstations? Windows usrmgr only supports eight */
772 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
773 $message[]= _("The windows usermanager allows eight clients at maximum!");
774 }
775 }
777 return ($message);
778 }
781 /* Save data to object */
782 function save_object()
783 {
785 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
787 /* We only care if we are on the sambaTab... */
788 if (isset($_POST['sambaTab'])){
789 plugin::save_object();
791 /* Take care about access options */
792 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
793 if ($this->samba3){
794 $attrname= "sambaPwdCanChange";
795 } else {
796 $attrname= "pwdCanChange";
797 }
798 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
799 $tmp= 1;
800 } else {
801 $tmp= 0;
802 }
803 if ($this->$attrname != $tmp){
804 $this->is_modified= TRUE;
805 }
806 $this->pwdCanChange= $tmp;
807 $this->sambaPwdCanChange= $tmp;
808 }
809 $tmp= "UX";
810 $this->no_password_required = FALSE;
811 if (isset($_POST["no_password_required"])){
812 if ($_POST["no_password_required"] == 1){
813 $tmp.= "N";
814 $this->no_password_required = TRUE;
815 }
816 }
817 if (isset($_POST["password_expires"])){
818 if ($_POST["password_expires"] == 1){
819 $this->password_expires= 1;
820 }
821 } else {
822 $this->password_expires= 0;
823 }
824 $this->temporary_disable = FALSE;
825 if (isset($_POST["temporary_disable"])){
826 if ($_POST["temporary_disable"] == 1){
827 $this->temporary_disable = TRUE;
828 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
829 $tmp.= "L";
830 } else {
831 $tmp.= "D";
832 }
833 }
834 }
835 if (isset($_POST["logon_time_set"])){
836 if ($_POST["logon_time_set"] == 1){
837 $this->logon_time_set= 1;
838 }
839 } else {
840 $this->logon_time_set= 0;
841 }
842 if (isset($_POST["logoff_time_set"])){
843 if ($_POST["logoff_time_set"] == 1){
844 $this->logoff_time_set= 1;
845 }
846 } else {
847 $this->logoff_time_set= 0;
848 }
849 if (isset($_POST["kickoff_time_set"])){
850 if ($_POST["kickoff_time_set"] == 1){
851 $this->kickoff_time_set= 1;
852 }
853 } else {
854 $this->kickoff_time_set= 0;
855 }
857 $fill= "";
858 for ($i= strlen($tmp); $i<12; $i++){
859 $fill.= " ";
860 }
862 $tmp= "[$tmp$fill]";
864 /* Only save if acl's are set */
865 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
866 if ($this->samba3){
867 $attrname= "sambaAcctFlags";
868 } else {
869 $attrname= "acctFlags";
870 }
871 if ($this->$attrname != $tmp){
872 $this->is_modified= TRUE;
873 }
874 $this->$attrname= $tmp;
875 }
877 /* Save sambaDomain attribute */
878 if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
879 $this->sambaDomainName= validate($_POST['sambaDomainName']);
880 }
882 /* Save CTX values */
883 if ($this->samba3){
885 /* Save obvious values */
886 foreach($this->ctxattributes as $val){
887 if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
888 if (get_magic_quotes_gpc()) {
889 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
890 } else {
891 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
892 }
893 }
894 }
896 /* Save checkbox states. */
897 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
898 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
899 // Need to do some index checking to avoid messages like "index ... not found"
900 if(isset($_POST['brokenconn'])) {
901 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
902 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
903 }
904 if(isset($_POST['reconn'])) {
905 $this->mungedObject->setReConn($_POST['reconn'] == '1'
906 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
907 }
908 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
909 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
910 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
911 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
912 $this->mungedObject->setCtxMaxDisconnectionTimeF(
913 !isset($_POST['CtxMaxDisconnectionTimeF'])
914 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
915 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
916 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
917 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
918 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
919 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
920 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
921 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
922 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
924 /* Save combo boxes. Takes two values */
925 if(isset($_POST['reconn'])) {
926 $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
927 }
929 /* Check for changes */
930 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
931 $this->is_modified= TRUE;
932 }
933 }
934 }
935 }
938 /* Save to LDAP */
939 function save()
940 {
941 /* Load uid and gid of this 'dn' */
942 $ldap= $this->config->get_ldap_link();
943 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
944 $tmp= $ldap->fetch();
945 $this->uidNumber= $tmp['uidNumber'][0];
946 $this->gidNumber= $tmp['gidNumber'][0];
948 plugin::save();
950 /* Remove objectClass for sambaIdmapEntry */
951 $tmp= array();
952 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
953 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
954 $tmp[]= $this->attrs['objectClass'][$i];
955 }
956 }
957 $this->attrs['objectClass']= $tmp;
959 /* Generate rid / primaryGroupId */
960 if ($this->samba3){
961 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
962 msg_dialog::display(_("Warning"), _("Undefined Samba SID detected. Please fix this problem manually!"), WARNING_DIALOG);
963 } else {
964 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
965 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
966 }
968 /* Need to generate a new uniqe uid/gid combination? */
969 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
970 $uidNumber= $this->uidNumber;
971 while(TRUE){
972 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
973 $ldap->cd($this->config->current['BASE']);
974 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
975 if ($ldap->count() == 0){
976 break;
977 }
978 $uidNumber++;
979 }
980 $this->attrs['sambaSID']= $sid;
982 /* Check for users primary group */
983 $ldap->cd($this->config->current['BASE']);
984 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
985 if ($ldap->count() != 1){
986 msg_dialog::display(_("Warning"), _("Cannot convert primary group to samba group: group cannot be identified!"), WARNING_DIALOG);
987 } else {
988 $attrs= $ldap->fetch();
989 $g= new group($this->config, $ldap->getDN());
990 if ($g->sambaSID == ""){
991 $g->sambaDomainName= $this->sambaDomainName;
992 $g->smbgroup= TRUE;
993 $g->save ();
994 }
995 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
996 }
997 }
999 if ($this->sambaHomeDrive == ""){
1000 $this->attrs["sambaHomeDrive"]= array();
1001 }
1003 /* Generate munged dial value */
1004 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
1006 /* User wants me to fake the idMappings? This is useful for
1007 making winbind resolve the user names in a reasonable amount
1008 of time in combination with larger databases. */
1009 if ($this->config->get_cfg_value("sambaidmapping") == "true"){
1010 $this->attrs['objectClass'][]= "sambaIdmapEntry";
1011 }
1014 /* Password expiery */
1015 if ($this->password_expires == "1"){
1016 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1017 } else {
1018 $this->attrs['sambaPwdMustChange']= array();
1019 }
1020 /* Make sure not to save zero in sambaPwdLastset */
1021 if ($this->sambaPwdLastSet != "0"){
1022 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1023 } else {
1024 $this->attrs['sambaPwdLastSet']= array();
1025 }
1026 /* Account expiery */
1027 if ($this->logon_time_set == "1"){
1028 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1029 } else {
1030 $this->attrs['sambaLogonTime']= array();
1031 }
1032 if ($this->logoff_time_set == "1"){
1033 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1034 } else {
1035 $this->attrs['sambaLogoffTime']= array();
1036 }
1037 if ($this->kickoff_time_set == "1"){
1038 # Add one day in unixtime format to be compatible with usrmgr
1039 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
1040 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
1041 } else {
1042 $this->attrs['sambaKickoffTime']= array();
1043 }
1044 } else {
1045 /* Not samba3 */
1046 $this->attrs['rid']= $this->uidNumber*2 + 1000;
1047 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1049 if ($this->homeDrive == ""){
1050 $this->attrs["homeDrive"]= array();
1051 }
1053 /* Password expiery */
1054 if ($this->password_expires == "1"){
1055 $this->attrs['pwdMustChange']= $this->pwdMustChange;
1056 } else {
1057 $this->attrs['pwdMustChange']= 2147483647;
1058 }
1059 /* Make sure not to save zero in pwdLastset */
1060 if ($this->pwdLastSet != "0"){
1061 $this->attrs['pwdLastSet']= $this->pwdLastSet;
1062 } else {
1063 $this->attrs['pwdLastSet']= array();
1064 }
1065 /* Account expiery */
1066 if ($this->logon_time_set == "1"){
1067 $this->attrs['logonTime']= $this->logonTime;
1068 } else {
1069 $this->attrs['logonTime']= array();
1070 }
1071 if ($this->logoff_time_set == "1"){
1072 $this->attrs['logoffTime']= $this->logoffTime;
1073 } else {
1074 $this->attrs['logoffTime']= array();
1075 }
1076 if ($this->kickoff_time_set == "1"){
1077 # Add one day in unixtime format to be compatible with usrmgr
1078 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1079 } else {
1080 $this->attrs['kickoffTime']= array();
1081 }
1082 }
1084 /* Write back to ldap */
1085 $ldap->cd($this->dn);
1086 $this->cleanup();
1087 $ldap->modify ($this->attrs);
1089 if($this->initially_was_account){
1090 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1091 }else{
1092 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1093 }
1095 if (!$ldap->success()){
1096 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1097 }
1099 /* Optionally execute a command after we're done */
1100 if ($this->initially_was_account == $this->is_account){
1101 if ($this->is_modified){
1102 $this->handle_post_events("modify", array("uid" => $this->uid));
1103 }
1104 } else {
1105 $this->handle_post_events("add", array("uid" => $this->uid));
1106 }
1107 }
1110 /* Force password set, if this account doesn't have any samba passwords */
1111 function password_change_needed()
1112 {
1113 if(!$this->initially_was_account && $this->is_account){
1114 $ldap = $this->config->get_ldap_link();
1115 $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1116 $attrs = $ldap->fetch();
1117 if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1118 return(TRUE);
1119 }
1120 }
1121 return(FALSE);
1122 }
1125 function adapt_from_template($dn, $skip= array())
1126 {
1127 plugin::adapt_from_template($dn, $skip);
1130 $this->sambaSID= "";
1131 $this->sambaPrimaryGroupSID= "";
1133 /* Fill mungedDial field */
1134 if ($this->samba3 && isset($this->attrs['sambaMungedDial']) && !in_array('sambaMungedDial', $skip)){
1135 $this->mungedObject->load($this->sambaMungedDial);
1136 }
1138 /* Adapt munged attributes */
1139 foreach($this->ctxattributes as $attr){
1140 if(isset($this->mungedObject->ctx[$attr]))
1141 $val = $this->mungedObject->ctx[$attr];
1143 foreach (array("sn", "givenName", "uid") as $repl){
1144 if (preg_match("/%$repl/i", $val)){
1145 $val= preg_replace ("/%$repl/i", $this->parent->$repl, $val);
1146 }
1147 }
1148 $this->mungedObject->ctx[$attr] = $val;
1149 }
1151 /* Password expiery */
1152 if(isset($this->attrs['sambaPwdMustChange']) &&
1153 $this->attrs['sambaPwdMustChange'][0] != 0 && !in_array('sambaPwdMustChange', $skip)){
1154 $this->password_expires= 1;
1155 }
1157 if(isset($this->attrs['sambaLogonTime']) && ! (
1158 $this->attrs['sambaLogonTime'][0] == 0 ||
1159 $this->attrs['sambaLogonTime'][0] == 2147483647
1160 ) && !in_array('sambaLogonTime', $skip)){
1161 $this->logon_time_set= 1;
1162 }
1163 if(isset($this->attrs['sambaLogoffTime']) && ! (
1164 $this->attrs['sambaLogoffTime'][0] == 0 ||
1165 $this->attrs['sambaLogoffTime'][0] == 2147483647
1166 ) && !in_array('sambaLogonTime', $skip)){
1167 $this->logoff_time_set= 1;
1168 }
1170 /* Account expiery */
1171 if(isset($this->attrs['sambaKickoffTime']) && ! (
1172 $this->attrs['sambaKickoffTime'][0] == 0 ||
1173 $this->attrs['sambaKickoffTime'][0] == 2147483647
1174 ) && !in_array('sambaKickoffTime', $skip)){
1175 $this->kickoff_time_set= 1;
1176 }
1178 /* Get global filter config */
1179 if (!session::is_set("sambafilter")){
1180 $ui= get_userinfo();
1181 $base= get_base_from_people($ui->dn);
1182 $sambafilter= array( "depselect" => $base, "regex" => "*");
1183 session::set("sambafilter", $sambafilter);
1184 }
1185 }
1188 static function plInfo()
1189 {
1190 return (array(
1191 "plShortName" => _("Samba"),
1192 "plDescription" => _("Samba settings"),
1193 "plSelfModify" => TRUE,
1194 "plDepends" => array("user"),
1195 "plPriority" => 5,
1196 "plSection" => array("personal" => _("My account")),
1197 "plCategory" => array("users"),
1198 "plOptions" => array(),
1200 "plProvidedAcls" => array(
1202 "sambaHomePath" => _("Generic home directory") ,
1203 "sambaHomeDrive" => _("Generic samba home drive") ,
1204 "sambaDomainName" => _("Domain") ,
1205 "sambaLogonScript" => _("Generic script path") ,
1206 "sambaProfilePath" => _("Generic profile path") ,
1207 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1208 "InheritClientConfig" => _("Inherit client config"),
1209 "sambaPwdCanChange" => _("Allow user to change password") ,
1210 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1211 "sambaAcctFlagsL" => _("Lock samba account"),
1212 "sambaKickoffTime" => _("Account expires") ,
1213 "sambaPwdMustChange" => _("Password expires") ,
1214 "sambaLogonTime" => _("Limit Logon Time") ,
1215 "sambaLogoffTime" => _("Limit Logoff Time") ,
1216 "sambaLogonHours" => _("Logon hours") ,
1217 "sambaUserWorkstations" => _("Allow connection from"))
1218 ));
1219 }
1221 function enable_multiple_support()
1222 {
1223 plugin::enable_multiple_support();
1224 if($this->samba3){
1225 $this->multiple_support_active = TRUE;
1226 }else{
1227 $this->multiple_support_active = FALSE;
1228 }
1229 }
1231 function multiple_save_object()
1232 {
1233 if (isset($_POST['sambaTab'])){
1234 $this->save_object();
1235 plugin::multiple_save_object();
1236 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1237 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1238 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1239 "onnectclientprinters","defaultprinter","shadow","brokenconn",
1240 "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1241 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1242 "workstation_list") as $attr){
1243 if(isset($_POST["use_".$attr])){
1244 $this->multi_boxes[] = $attr;
1245 }
1246 }
1247 }
1248 }
1251 function multiple_check()
1252 {
1253 $message = plugin::multiple_check();
1255 /* Strings */
1256 foreach (array( "sambaHomePath" => _("Home directory"),
1257 "sambaProfilePath" => _("Profile path")) as $key => $val){
1258 if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1259 $message[]= msgPool::invalid($val);
1260 }
1261 }
1263 /* Numeric values */
1264 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
1265 "CtxMaxDisconnectionTime" => _("Disconnection"),
1266 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
1267 if (in_array($key,$this->multi_boxes) &&
1268 isset($this->mungedObject->ctx[$key]) &&
1269 !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1270 $message[]=msgPool::invalid($val);
1271 }
1272 }
1274 /* Too many workstations? Windows usrmgr only supports eight */
1275 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1276 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1277 }
1278 return($message);
1279 }
1282 function get_multi_init_values()
1283 {
1284 $ret = plugin::get_multi_init_values();
1286 /* Parse given sambaUserWorkstations into array
1287 * to allow "init_multiple_support()" to detect multiple used workstations.
1288 * Those workstations will be displayed in light grey.
1289 */
1290 $tmp2 = array("count" => 0);
1291 $tmp = split(",", $this->sambaUserWorkstations);
1292 foreach($tmp as $station){
1293 $station = trim($station);
1294 if(!empty($station)){
1295 $tmp2[] = $station;
1296 $tmp2['count'] ++;
1297 }
1298 }
1299 $ret['sambaUserWorkstations'] = $tmp2;
1300 return($ret);
1301 }
1305 function init_multiple_support($attrs,$all)
1306 {
1307 plugin::init_multiple_support($attrs,$all);
1309 $this->multiple_sambaUserWorkstations = array();
1310 if(isset($all['sambaUserWorkstations'])){
1311 for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1312 $station = trim($all['sambaUserWorkstations'][$i]);
1313 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1314 }
1315 }
1316 if(isset($attrs['sambaUserWorkstations'])){
1317 for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1318 $station = trim($attrs['sambaUserWorkstations'][$i]);
1319 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1320 }
1321 }
1322 }
1324 function multiple_execute()
1325 {
1326 return($this->execute());
1327 }
1329 function get_multi_edit_values()
1330 {
1331 $ret = plugin::get_multi_edit_values();
1333 /* Terminal Server */
1334 if(in_array("tslogin",$this->multi_boxes)){
1335 $ret['tslogin'] = $this->mungedObject->getTsLogin();
1336 }
1337 if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1338 $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1339 }
1340 if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1341 $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1342 }
1343 if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1344 $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1345 }
1347 if(in_array("inherit",$this->multi_boxes)){
1348 $ret['inherit'] = $this->mungedObject->getInheritMode();
1349 }
1350 if(in_array("CtxInitialProgram",$this->multi_boxes)){
1351 $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1352 }
1353 if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1354 $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1355 }
1357 /* Time Limits. Be careful here, there are some negations */
1358 if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1359 $ret["CtxMaxConnectionTimeF"] = !$this->mungedObject->getCtxMaxConnectionTimeF();
1360 if(!$ret["CtxMaxConnectionTimeF"]){
1361 $ret["CtxMaxConnectionTime"] = $this->mungedObject->ctx['CtxMaxConnectionTime'];
1362 }
1363 }
1364 if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1365 $ret["CtxMaxDisconnectionTimeF"]= !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1366 if(!$ret["CtxMaxDisconnectionTimeF"]){
1367 $ret["CtxMaxDisconnectionTime"]= $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1368 }
1369 }
1370 if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1371 $ret["CtxMaxIdleTimeF"] = !$this->mungedObject->getCtxMaxIdleTimeF();
1372 if(!$ret["CtxMaxIdleTimeF"]){
1373 $ret["CtxMaxIdleTime"] = $this->mungedObject->ctx['CtxMaxIdleTime'];
1374 }
1375 }
1377 /* Client Devices */
1378 if(in_array("connectclientdrives",$this->multi_boxes)){
1379 $ret["connectclientdrives"] = $this->mungedObject->getConnectClientDrives();
1380 }
1381 if(in_array("connectclientprinters",$this->multi_boxes)){
1382 $ret["connectclientprinters"] = $this->mungedObject->getConnectClientPrinters();
1383 }
1384 if(in_array("defaultprinter",$this->multi_boxes)){
1385 $ret["defaultprinter"] = $this->mungedObject->getDefaultPrinter();
1386 }
1388 /* Misc */
1389 if(in_array("shadow",$this->multi_boxes)){
1390 $ret["shadow"] =$this->mungedObject->getShadow();
1391 }
1392 if(in_array("brokenconn",$this->multi_boxes)){
1393 $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1394 }
1395 if(in_array("reconn",$this->multi_boxes)){
1396 $ret["reconn"] =$this->mungedObject->getReConn();
1397 }
1399 /* Flags */
1400 if(in_array("allow_pwchange",$this->multi_boxes)){
1401 $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1402 $ret['pwdCanChange'] = $this->pwdCanChange;
1403 }
1405 if(in_array("password_expires",$this->multi_boxes)){
1406 $ret['password_expires'] = $this->password_expires;
1407 $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1408 }
1409 if(in_array("logon_time_set",$this->multi_boxes)){
1410 $ret['logon_time_set'] = $this->logon_time_set;
1411 $ret['sambaLogonTime'] = $this->sambaLogonTime;
1412 }
1413 if(in_array("logoff_time_set",$this->multi_boxes)){
1414 $ret['logoff_time_set'] = $this->logoff_time_set;
1415 $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1416 }
1417 if(in_array("kickoff_time_set",$this->multi_boxes)){
1418 $ret['kickoff_time_set'] = $this->kickoff_time_set;
1419 $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1420 }
1422 if(in_array("no_password_required",$this->multi_boxes)){
1423 $ret['no_password_required'] = $this->no_password_required;
1424 }
1426 if(in_array("temporary_disable",$this->multi_boxes)){
1427 $ret['temporary_disable'] = $this->temporary_disable;
1428 }
1430 if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1431 $ret['sambaLogonHours'] = $this->sambaLogonHours;
1432 }
1434 if(in_array("workstation_list",$this->multi_boxes)){
1435 $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1436 }
1437 return($ret);
1438 }
1440 function set_multi_edit_values($values)
1441 {
1442 plugin::set_multi_edit_values($values);
1444 /* Prepare current workstation settings to be merged
1445 * with multiple edit settings.
1446 */
1447 if(isset($values['multiple_sambaUserWorkstations'])){
1448 $cur_ws = array();
1449 $m_ws = $values['multiple_sambaUserWorkstations'];
1451 /* Prepare current settings to be merged */
1452 if(isset($this->sambaUserWorkstations)){
1453 $ttmp = split(",",$this->sambaUserWorkstations);
1454 foreach($ttmp as $station){
1455 $station = trim($station);
1456 if(!empty($station)){
1457 $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1458 }
1459 }
1460 }
1462 /* Unset removed workstations */
1463 foreach($cur_ws as $cur_name => $cur_station){
1464 if(!isset($m_ws[$cur_name])){
1465 unset($cur_ws[$cur_name]);
1466 }
1467 }
1469 /* Add all added workstations */
1470 foreach($m_ws as $name => $station){
1471 if($station['UsedByAllUsers']){
1472 $cur_ws[$name] = $station;
1473 }
1474 }
1476 $this->sambaUserWorkstations = "";
1477 foreach($cur_ws as $name => $ws){
1478 $this->sambaUserWorkstations .= $name.",";
1479 }
1480 $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1481 }
1483 /* Enable disabled terminal login, this is inverted somehow */
1484 if(isset($values['tslogin'])) $this->mungedObject->setTsLogin(!$values['tslogin']);
1486 /* Imherit client configuration */
1487 if(isset($values['inherit'])) $this->mungedObject->setInheritMode($values['inherit']);
1489 /* Get all ctx values posted */
1490 $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1491 "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1492 foreach($ctx as $attr){
1493 if(isset($values[$attr])){
1494 $this->mungedObject->ctx[$attr] = $values[$attr] ;
1495 }
1496 }
1498 if(isset($values['CtxMaxConnectionTimeF'])) $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1499 if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1500 if(isset($values['CtxMaxIdleTimeF'])) $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1502 if(isset($values['connectclientdrives'])) $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1503 if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1504 if(isset($values['defaultprinter'])) $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1506 if(isset($values['shadow'])) $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1507 if(isset($values['brokenconn'])) $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1508 if(isset($values['reconn'])) $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1511 if(isset($values['sambaPwdCanChange'])) $this->sambaPwdCanChange = $values['sambaPwdCanChange'];
1512 if(isset($values['pwdCanChange'])) $this->pwdCanChange = $values['pwdCanChange'];
1517 if(isset($values['password_expires'])){
1518 $this->password_expires = $values['password_expires'];
1519 $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1520 }
1521 if(isset($values['logon_time_set'])){
1522 $this->logon_time_set = $values['logon_time_set'];
1523 $this->sambaLogonTime = $values['sambaLogonTime'];
1524 }
1525 if(isset($values['logoff_time_set'])){
1526 $this->logoff_time_set = $values['logoff_time_set'];
1527 $this->sambaLogoffTime = $values['sambaLogoffTime'];
1528 }
1529 if(isset($values['kickoff_time_set'])){
1530 $this->kickoff_time_set = $values['kickoff_time_set'];
1531 $this->sambaKickoffTime = $values['sambaKickoffTime'];
1532 }
1534 if(isset($values['no_password_required'])){
1535 if($values['no_password_required']){
1536 if(!preg_match("/N/",$this->sambaAcctFlags)) {
1537 $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1538 }
1539 }else{
1540 $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1541 }
1542 }
1544 if(isset($values['temporary_disable'])){
1545 if($values['temporary_disable']){
1546 if(preg_match("/L/",$this->sambaAcctFlags)) {
1547 // Keep L
1548 }else{
1549 $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1550 }
1551 }else{
1552 $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1553 }
1554 }
1555 }
1558 function PrepareForCopyPaste($source)
1559 {
1560 plugin::PrepareForCopyPaste($source);
1562 /* Set a new SID */
1563 $this->sambaSID = "";
1564 }
1566 }
1568 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1569 ?>