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 if(isset($attrs['sambaAlgorithmicRidBase'])){
141 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
142 } else {
143 $this->ridBase= $this->config->current['RIDBASE'];
144 }
145 if ($this->sambaDomainName == ""){
146 $this->sambaDomainName= $attrs['sambaDomainName'][0];
147 }
148 } else {
149 if ($this->sambaDomainName == ""){
150 $this->sambaDomainName= "DEFAULT";
151 }
152 $this->ridBase= $this->config->current['RIDBASE'];
153 $this->SID= $this->config->current['SID'];
154 }
156 /* Save in order to compare later on */
157 $this->orig_sambaDomainName= $this->sambaDomainName;
158 }
160 /* Fill mungedDial field */
161 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
162 $this->mungedObject->load($this->sambaMungedDial);
163 }
165 /* Password expiery */
166 if(isset($this->attrs['sambaPwdMustChange']) &&
167 $this->attrs['sambaPwdMustChange'][0] != 0){
168 $this->password_expires= 1;
169 }
171 if(isset($this->attrs['sambaLogonTime']) && ! (
172 $this->attrs['sambaLogonTime'][0] == 0 ||
173 $this->attrs['sambaLogonTime'][0] == 2147483647
174 )){
175 $this->logon_time_set= 1;
176 }
177 if(isset($this->attrs['sambaLogoffTime']) && ! (
178 $this->attrs['sambaLogoffTime'][0] == 0 ||
179 $this->attrs['sambaLogoffTime'][0] == 2147483647
180 )){
181 $this->logoff_time_set= 1;
182 }
184 /* Account expiery */
185 if(isset($this->attrs['sambaKickoffTime']) && ! (
186 $this->attrs['sambaKickoffTime'][0] == 0 ||
187 $this->attrs['sambaKickoffTime'][0] == 2147483647
188 )){
189 $this->kickoff_time_set= 1;
190 }
192 /* Get global filter config */
193 if (!session::is_set("sambafilter")){
194 $ui= get_userinfo();
195 $base= get_base_from_people($ui->dn);
196 $sambafilter= array( "depselect" => $base, "regex" => "*");
197 session::set("sambafilter", $sambafilter);
198 }
200 /* Save initial account state */
201 $this->initially_was_account= $this->is_account;
202 }
204 function execute()
205 {
206 /* Call parent execute */
207 plugin::execute();
209 /* Log view */
210 if($this->is_account && !$this->view_logged){
211 $this->view_logged = TRUE;
212 new log("view","users/".get_class($this),$this->dn);
213 }
215 /* Do we need to flip is_account state? */
216 if (isset($_POST['modify_state'])){
217 $this->is_account= !$this->is_account;
218 }
219 /* Do we represent a valid account? */
220 if (!$this->is_account && $this->parent === NULL){
221 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
222 _("This account has no samba extensions.")."</b>";
223 $display.= back_to_main();
224 return ($display);
225 }
227 $display ="";
228 if(!$this->multiple_support_active){
230 /* Show tab dialog headers */
231 $display= "";
232 if ($this->parent !== NULL){
233 if ($this->is_account){
234 $display= $this->show_disable_header(_("Remove samba account"),
235 _("This account has samba features enabled. You can disable them by clicking below."));
236 } else {
237 $obj= $this->parent->by_object['posixAccount'];
239 /* Samba3 dependency on posix accounts are enabled
240 in the moment, because I need to rely on unique
241 uidNumbers. There'll be a better solution later
242 on. */
243 if ($obj->is_account){
244 $display= $this->show_enable_header(_("Create samba account"),
245 _("This account has samba features disabled. You can enable them by clicking below."));
246 } else {
247 $display= $this->show_enable_header(_("Create samba account"),
248 _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
249 }
250 return ($display);
251 }
252 }
253 }
255 $SkipWrite = (!isset($this->parent) || !$this->parent) && !session::is_set('edit');
257 /* Open Samaba Logong hours dialog */
258 if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
259 $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
260 }
262 /* Cancel dialog */
263 if(isset($_POST['cancel_logonHours'])){
264 $this->dialog = FALSE;
265 }
267 /* Save selected logon hours */
268 if(isset($_POST['save_logonHours'])){
269 $this->dialog->save_object();
270 if($this->acl_is_writeable("sambaLogonHours")){
271 $this->sambaLogonHours = $this->dialog->save();
272 }
273 $this->dialog = FALSE;
274 }
276 /* Display dialog */
277 if((isset($this->dialog)) && (is_object($this->dialog))){
278 $this->dialog->save_object();
279 return($this->dialog->execute());
280 }
282 /* Prepare templating */
283 $smarty= get_smarty();
285 $tmp = $this->plInfo();
286 foreach($tmp['plProvidedAcls'] as $var => $rest){
287 $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
288 }
290 if ($this->sambaPwdMustChange=="0"){
291 $date= getdate();
292 } else {
293 $date= getdate($this->sambaPwdMustChange);
294 }
296 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
297 $sambaLogonTime_date= getdate();
298 } else {
299 $sambaLogonTime_date= getdate($this->sambaLogonTime);
300 }
302 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
303 $sambaLogoffTime_date= getdate();
304 } else {
305 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
306 }
308 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
309 $sambaKickoffTime_date= getdate();
310 } else {
311 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
312 }
314 /* Remove user workstations? */
315 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
317 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
319 if($this->multiple_support_active){
320 foreach($_POST['workstation_list'] as $name){
321 if(isset($this->multiple_sambaUserWorkstations[trim($name)])){
322 unset($this->multiple_sambaUserWorkstations[trim($name)]);
323 }
324 }
325 }else{
326 $tmp= $this->sambaUserWorkstations;
327 foreach($_POST['workstation_list'] as $name){
328 $tmp= preg_replace("/$name/", '', $tmp);
329 $this->is_modified= TRUE;
330 }
331 $tmp= preg_replace('/,+/', ',', $tmp);
332 $this->sambaUserWorkstations= trim($tmp, ',');
333 }
334 }
335 }
337 /* Add user workstation? */
338 if (isset($_POST["add_ws"])){
339 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
340 $this->show_ws_dialog= TRUE;
341 $this->dialog= TRUE;
342 }
343 }
345 /* Add user workstation finished? */
346 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
347 $this->show_ws_dialog= FALSE;
348 $this->dialog= FALSE;
349 }
351 /* Add user workstation? */
352 if (isset($_POST["add_ws_finish"]) && 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;
367 }
369 /* Show ws dialog */
370 if ($this->show_ws_dialog){
372 /* Save data */
373 $sambafilter= session::get("sambafilter");
374 foreach( array("depselect", "regex") as $type){
375 if (isset($_POST[$type])){
376 $sambafilter[$type]= $_POST[$type];
377 }
378 }
379 if (isset($_GET['search'])){
380 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
381 if ($s == "**"){
382 $s= "*";
383 }
384 $sambafilter['regex']= $s;
385 }
386 session::set("sambafilter", $sambafilter);
388 /* Get workstation list */
389 $exclude= "";
391 if($this->multiple_support_active){
392 foreach($this->multiple_sambaUserWorkstations as $ws){
393 if($ws['UsedByAllUsers']){
394 $exclude.= "(cn=".$ws['Name']."$)";
395 }
396 }
397 }else{
398 foreach(split(',', $this->sambaUserWorkstations) as $ws){
399 $exclude.= "(cn=$ws$)";
400 }
401 }
402 if ($exclude != ""){
403 $exclude= "(!(|$exclude))";
404 }
405 $regex= $sambafilter['regex'];
406 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
407 $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
409 $wslist= array();
410 foreach ($res as $attrs){
411 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
412 }
413 asort($wslist);
415 $smarty->assign("search_image", get_template_path('images/search.png'));
416 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
417 $smarty->assign("tree_image", get_template_path('images/tree.png'));
418 $smarty->assign("deplist", $this->config->idepartments);
419 $smarty->assign("alphabet", generate_alphabet());
420 foreach( array("depselect", "regex") as $type){
421 $smarty->assign("$type", $sambafilter[$type]);
422 }
423 $smarty->assign("hint", print_sizelimit_warning());
424 $smarty->assign("wslist", $wslist);
425 $smarty->assign("apply", apply_filter());
426 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
427 dirname(__FILE__)));
428 return ($display);
429 }
431 /* Fill calendar */
432 $days= array();
433 for($d= 1; $d<32; $d++){
434 $days[]= $d;
435 }
436 $years= array();
437 for($y= $date['year']-4; $y<$date['year']+4; $y++){
438 $years[]= $y;
439 }
440 $months= array(_("January"), _("February"), _("March"), _("April"),
441 _("May"), _("June"), _("July"), _("August"), _("September"),
442 _("October"), _("November"), _("December"));
443 $smarty->assign("day", $date["mday"]);
444 $smarty->assign("days", $days);
445 $smarty->assign("months", $months);
446 $smarty->assign("month", $date["mon"]-1);
447 $smarty->assign("years", $years);
448 $smarty->assign("year", $date["year"]);
450 $sambaLogonTime_days= array();
451 for($d= 1; $d<32; $d++){
452 $sambaLogonTime_days[]= $d;
453 }
454 $sambaLogonTime_years= array();
455 for($y= $date['year']-4; $y<$date['year']+4; $y++){
456 $sambaLogonTime_years[]= $y;
457 }
458 $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
459 _("May"), _("June"), _("July"), _("August"), _("September"),
460 _("October"), _("November"), _("December"));
461 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
462 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
463 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
464 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
465 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
466 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
468 $sambaLogoffTime_days= array();
469 for($d= 1; $d<32; $d++){
470 $sambaLogoffTime_days[]= $d;
471 }
472 $sambaLogoffTime_years= array();
473 for($y= $date['year']-4; $y<$date['year']+4; $y++){
474 $sambaLogoffTime_years[]= $y;
475 }
476 $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
477 _("May"), _("June"), _("July"), _("August"), _("September"),
478 _("October"), _("November"), _("December"));
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= array(_("January"), _("February"), _("March"), _("April"),
495 _("May"), _("June"), _("July"), _("August"), _("September"),
496 _("October"), _("November"), _("December"));
497 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
498 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
499 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
500 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
501 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
502 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
503 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
505 /* Fill boxes */
506 if ($this->samba3){
507 $domains= array();
508 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
509 $domains[]= $name;
510 }
511 $smarty->assign("domains", $domains);
512 }
513 $letters= array();
514 for ($i= 68; $i<91; $i++){
515 $letters[]= chr($i).":";
516 }
517 $smarty->assign("drives", $letters);
519 /* Fill terminal server settings */
520 if ($this->samba3){
521 foreach ($this->ctxattributes as $attr){
522 /* Fill common attributes */
523 if (isset($this->mungedObject->ctx[$attr])){
524 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
525 // Set field to blank if value is 0
526 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
527 if($this->mungedObject->ctx[$attr] == 0) {
528 $smarty->assign("$attr", "");
529 }
530 }
531 } else {
532 $smarty->assign("$attr", "");
533 }
534 }
536 /* Assign enum values for preset items */
537 $shadowModeVals= array( "0" => _("disabled"),
538 "1" => _("input on, notify on"),
539 "2" => _("input on, notify off"),
540 "3" => _("input off, notify on"),
541 "4" => _("input off, nofify off"));
543 $brokenConnModeVals= array( "0" => _("disconnect"),
544 "1" => _("reset"));
546 $reConnModeVals= array( "0" => _("from any client"),
547 "1" => _("from previous client only"));
549 /* Fill preset items */
550 $smarty->assign("shadow", $shadowModeVals);
551 $smarty->assign("brokenconn", $brokenConnModeVals);
552 $smarty->assign("reconn", $reConnModeVals);
554 /* Fill preset items with values */
555 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
556 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
557 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
559 if(session::get('js')){
560 /* Set form elements to disabled/enable state */
561 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
563 $smarty->assign("inheritstate", "");
564 if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
565 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
566 }
567 }else{
568 $smarty->assign("tsloginstate", "");
569 $smarty->assign("inheritstate", "");
570 }
572 /* Set checkboxes to checked or unchecked state */
573 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
574 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
575 $smarty->assign("connectclientdrives",
576 $this->mungedObject->getConnectClientDrives()?"checked":"");
577 $smarty->assign("connectclientprinters",
578 $this->mungedObject->getConnectClientPrinters()?"checked":"");
579 $smarty->assign("defaultprinter",
580 $this->mungedObject->getDefaultPrinter()?"checked":"");
581 $smarty->assign("CtxMaxConnectionTimeF",
582 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
583 $smarty->assign("CtxMaxDisconnectionTimeF",
584 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
585 $smarty->assign("CtxMaxIdleTimeF",
586 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
589 /* Fill sambaUserWorkstations */
590 $ws= split(",", $this->sambaUserWorkstations);
591 sort($ws);
593 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
594 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
596 if($this->multiple_support_active){
597 $smarty->assign("multiple_workstations",$this->multiple_sambaUserWorkstations);
598 }
600 $smarty->assign("workstations", $ws);
601 }
603 /* Variables */
604 foreach($this->attributes as $val){
605 $smarty->assign("$val", $this->$val);
606 }
608 /* 'sambaAcctFlags' checkboxes */
609 /* Check for 'lock-account'-flag: 'D' or 'L' */
610 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
611 is_integer(strpos($this->sambaAcctFlags, "L"))) {
612 $smarty->assign("flagsD", "checked");
613 } else {
614 $smarty->assign("flagsD", "");
615 }
617 /* Check for no_password_required flag 'N' */
618 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
619 $smarty->assign("flagsN", "checked");
620 } else {
621 $smarty->assign("flagsN", "");
622 }
624 if($this->samba3){
625 if ($this->sambaPwdCanChange=="1"){
626 $smarty->assign("flagsP", "checked");
627 } else {
628 $smarty->assign("flagsP", "");
629 }
630 }else{
631 if ($this->pwdCanChange=="1"){
632 $smarty->assign("flagsP", "checked");
633 } else {
634 $smarty->assign("flagsP", "");
635 }
636 }
638 if ($this->password_expires=="1"){
639 $smarty->assign("flagsC", "checked");
640 } else {
641 $smarty->assign("flagsC", "");
642 }
643 if ($this->logon_time_set=="1"){
644 $smarty->assign("flagsT", "checked");
645 } else {
646 $smarty->assign("flagsT", "");
647 }
648 if ($this->logoff_time_set=="1"){
649 $smarty->assign("flagsO", "checked");
650 } else {
651 $smarty->assign("flagsO", "");
652 }
653 if ($this->kickoff_time_set=="1"){
654 $smarty->assign("flagsK", "checked");
655 } else {
656 $smarty->assign("flagsK", "");
657 }
660 /* In case of javascript, disable some fields on demand */
661 if ($this->samba3){
662 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
663 $smarty->assign("$key", "$value");
664 }
665 }
668 foreach($this->attributes as $attr){
669 if(in_array($attr,$this->multi_boxes)){
670 $smarty->assign("use_".$attr,TRUE);
671 }else{
672 $smarty->assign("use_".$attr,FALSE);
673 }
674 }
675 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
676 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
677 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
678 "onnectclientprinters","defaultprinter","shadow","brokenconn",
679 "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
680 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
681 "workstation_list") as $attr){
682 if(in_array($attr,$this->multi_boxes)){
683 $smarty->assign("use_".$attr,TRUE);
684 }else{
685 $smarty->assign("use_".$attr,FALSE);
686 }
687 }
689 if($this->multiple_support_active){
690 $smarty->assign("tsloginstate","");
691 }
693 /* Show main page */
694 $smarty->assign("multiple_support",$this->multiple_support_active);
695 if ($this->samba3){
696 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
697 } else {
698 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
699 }
701 return ($display);
702 }
704 function remove_from_parent()
705 {
706 /* Cancel if there's nothing to do here */
707 if (!$this->initially_was_account){
708 return;
709 }
711 /* include global link_info */
712 $ldap= $this->config->get_ldap_link();
714 plugin::remove_from_parent();
716 /* Keep uid attribute for gosaAccount */
717 unset($this->attrs['uid']);
718 unset($this->attrs['uidNumber']);
719 unset($this->attrs['gidNumber']);
721 /* Remove objectClass for sambaIdmapEntry */
722 $tmp= array();
723 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
724 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
725 $tmp[]= $this->attrs['objectClass'][$i];
726 }
727 }
728 $this->attrs['objectClass']= $tmp;
730 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
731 $this->attributes, "Save");
732 $ldap->cd($this->dn);
733 $this->cleanup();
734 $ldap->modify ($this->attrs);
736 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
738 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
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[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $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[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
768 }
769 }
771 /* Too many workstations? Windows usrmgr only supports eight */
772 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
773 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
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 (isset($this->config->current['SAMBAIDMAPPING']) &&
1010 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
1011 $this->attrs['objectClass'][]= "sambaIdmapEntry";
1012 }
1015 /* Password expiery */
1016 if ($this->password_expires == "1"){
1017 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
1018 } else {
1019 $this->attrs['sambaPwdMustChange']= array();
1020 }
1021 /* Make sure not to save zero in sambaPwdLastset */
1022 if ($this->sambaPwdLastSet != "0"){
1023 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
1024 } else {
1025 $this->attrs['sambaPwdLastSet']= array();
1026 }
1027 /* Account expiery */
1028 if ($this->logon_time_set == "1"){
1029 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
1030 } else {
1031 $this->attrs['sambaLogonTime']= array();
1032 }
1033 if ($this->logoff_time_set == "1"){
1034 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
1035 } else {
1036 $this->attrs['sambaLogoffTime']= array();
1037 }
1038 if ($this->kickoff_time_set == "1"){
1039 # Add one day in unixtime format to be compatible with usrmgr
1040 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
1041 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
1042 } else {
1043 $this->attrs['sambaKickoffTime']= array();
1044 }
1045 } else {
1046 /* Not samba3 */
1047 $this->attrs['rid']= $this->uidNumber*2 + 1000;
1048 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
1050 if ($this->homeDrive == ""){
1051 $this->attrs["homeDrive"]= array();
1052 }
1054 /* Password expiery */
1055 if ($this->password_expires == "1"){
1056 $this->attrs['pwdMustChange']= $this->pwdMustChange;
1057 } else {
1058 $this->attrs['pwdMustChange']= 2147483647;
1059 }
1060 /* Make sure not to save zero in pwdLastset */
1061 if ($this->pwdLastSet != "0"){
1062 $this->attrs['pwdLastSet']= $this->pwdLastSet;
1063 } else {
1064 $this->attrs['pwdLastSet']= array();
1065 }
1066 /* Account expiery */
1067 if ($this->logon_time_set == "1"){
1068 $this->attrs['logonTime']= $this->logonTime;
1069 } else {
1070 $this->attrs['logonTime']= array();
1071 }
1072 if ($this->logoff_time_set == "1"){
1073 $this->attrs['logoffTime']= $this->logoffTime;
1074 } else {
1075 $this->attrs['logoffTime']= array();
1076 }
1077 if ($this->kickoff_time_set == "1"){
1078 # Add one day in unixtime format to be compatible with usrmgr
1079 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1080 } else {
1081 $this->attrs['kickoffTime']= array();
1082 }
1083 }
1085 /* Write back to ldap */
1086 $ldap->cd($this->dn);
1087 $this->cleanup();
1088 $ldap->modify ($this->attrs);
1090 if($this->initially_was_account){
1091 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1092 }else{
1093 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1094 }
1096 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
1098 /* Optionally execute a command after we're done */
1099 if ($this->initially_was_account == $this->is_account){
1100 if ($this->is_modified){
1101 $this->handle_post_events("modify", array("uid" => $this->uid));
1102 }
1103 } else {
1104 $this->handle_post_events("add", array("uid" => $this->uid));
1105 }
1106 }
1109 /* Force password set, if this account doesn't have any samba passwords */
1110 function password_change_needed()
1111 {
1112 if(!$this->initially_was_account && $this->is_account){
1113 $ldap = $this->config->get_ldap_link();
1114 $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1115 $attrs = $ldap->fetch();
1116 if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1117 return(TRUE);
1118 }
1119 }
1120 return(FALSE);
1121 }
1124 function adapt_from_template($dn)
1125 {
1126 plugin::adapt_from_template($dn);
1127 $this->sambaSID= "";
1128 $this->sambaPrimaryGroupSID= "";
1130 /* Fill mungedDial field */
1131 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1132 $this->mungedObject->load($this->sambaMungedDial);
1133 }
1135 /* Password expiery */
1136 if(isset($this->attrs['sambaPwdMustChange']) &&
1137 $this->attrs['sambaPwdMustChange'][0] != 0){
1138 $this->password_expires= 1;
1139 }
1141 if(isset($this->attrs['sambaLogonTime']) && ! (
1142 $this->attrs['sambaLogonTime'][0] == 0 ||
1143 $this->attrs['sambaLogonTime'][0] == 2147483647
1144 )){
1145 $this->logon_time_set= 1;
1146 }
1147 if(isset($this->attrs['sambaLogoffTime']) && ! (
1148 $this->attrs['sambaLogoffTime'][0] == 0 ||
1149 $this->attrs['sambaLogoffTime'][0] == 2147483647
1150 )){
1151 $this->logoff_time_set= 1;
1152 }
1154 /* Account expiery */
1155 if(isset($this->attrs['sambaKickoffTime']) && ! (
1156 $this->attrs['sambaKickoffTime'][0] == 0 ||
1157 $this->attrs['sambaKickoffTime'][0] == 2147483647
1158 )){
1159 $this->kickoff_time_set= 1;
1160 }
1162 /* Get global filter config */
1163 if (!session::is_set("sambafilter")){
1164 $ui= get_userinfo();
1165 $base= get_base_from_people($ui->dn);
1166 $sambafilter= array( "depselect" => $base, "regex" => "*");
1167 session::set("sambafilter", $sambafilter);
1168 }
1169 }
1172 static function plInfo()
1173 {
1174 return (array(
1175 "plShortName" => _("Samba"),
1176 "plDescription" => _("Samba settings"),
1177 "plSelfModify" => TRUE,
1178 "plDepends" => array("user"),
1179 "plPriority" => 5,
1180 "plSection" => array("personal" => _("My account")),
1181 "plCategory" => array("users"),
1182 "plOptions" => array(),
1184 "plProvidedAcls" => array(
1185 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1186 "InheritClientConfig" => _("Inherit client config"),
1188 "sambaPwdCanChange" => _("Allow user to change password") ,
1189 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1190 "sambaAcctFlagsL" => _("Lock samba account"),
1193 "sambaKickoffTime" => _("Account expires") ,
1194 "sambaPwdMustChange" => _("Password expires") ,
1196 "sambaLogonTime" => _("Limit Logon Time") ,
1197 "sambaLogoffTime" => _("Limit Logoff Time") ,
1198 "sambaLogonHours" => _("Logon hours") ,
1200 "sambaHomePath" => _("Generic home directory") ,
1201 "sambaHomeDrive" => _("Generic samba home drive") ,
1202 "sambaLogonScript" => _("Generic script path") ,
1203 "sambaProfilePath" => _("Generic profile path") ,
1204 "sambaDomainName" => _("Domain") ,
1205 "sambaUserWorkstations" => _("Allow connection from")))
1206 );
1207 }
1209 function enable_multiple_support()
1210 {
1211 plugin::enable_multiple_support();
1212 if($this->samba3){
1213 $this->multiple_support_active = TRUE;
1214 }else{
1215 $this->multiple_support_active = FALSE;
1216 }
1217 }
1219 function multiple_save_object()
1220 {
1221 if (isset($_POST['sambaTab'])){
1222 $this->save_object();
1223 plugin::multiple_save_object();
1224 foreach(array("allow_pwchange","tslogin","CtxWFHomeDir","CtxWFHomeDirDrive","CtxWFProfilePath",
1225 "inherit","CtxWorkDirectory","CtxInitialProgram","CtxMaxConnectionTimeF","CtxMaxConnectionTime","CtxMaxDisconnectionTimeF",
1226 "CtxMaxDisconnectionTime","CtxMaxIdleTimeF","CtxMaxIdleTime","connectclientdrives",
1227 "onnectclientprinters","defaultprinter","shadow","brokenconn",
1228 "reconn","allow_pwchange","connectclientprinters","no_password_required","temporary_disable",
1229 "password_expires","logon_time_set","logoff_time_set","kickoff_time_set","SetSambaLogonHours",
1230 "workstation_list") as $attr){
1231 if(isset($_POST["use_".$attr])){
1232 $this->multi_boxes[] = $attr;
1233 }
1234 }
1235 }
1236 }
1239 function multiple_check()
1240 {
1241 $message = plugin::multiple_check();
1243 /* Strings */
1244 foreach (array( "sambaHomePath" => _("Home directory"),
1245 "sambaProfilePath" => _("Profile path")) as $key => $val){
1246 if (in_array($key,$this->multi_boxes) && !$this->mungedObject->is_samba_path($this->$key)){
1247 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
1248 }
1249 }
1251 /* Numeric values */
1252 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
1253 "CtxMaxDisconnectionTime" => _("Disconnection"),
1254 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
1255 if (in_array($key,$this->multi_boxes) &&
1256 isset($this->mungedObject->ctx[$key]) &&
1257 !tests::is_id($this->mungedObject->ctx[$key]) && $val != 0){
1258 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
1259 }
1260 }
1262 /* Too many workstations? Windows usrmgr only supports eight */
1263 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
1264 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
1265 }
1266 return($message);
1267 }
1270 function get_multi_init_values()
1271 {
1272 $ret = plugin::get_multi_init_values();
1274 /* Parse given sambaUserWorkstations into array
1275 * to allow "init_multiple_support()" to detect multiple used workstations.
1276 * Those workstations will be displayed in light grey.
1277 */
1278 $tmp2 = array("count" => 0);
1279 $tmp = split(",", $this->sambaUserWorkstations);
1280 foreach($tmp as $station){
1281 $station = trim($station);
1282 if(!empty($station)){
1283 $tmp2[] = $station;
1284 $tmp2['count'] ++;
1285 }
1286 }
1287 $ret['sambaUserWorkstations'] = $tmp2;
1288 return($ret);
1289 }
1293 function init_multiple_support($attrs,$all)
1294 {
1295 plugin::init_multiple_support($attrs,$all);
1297 $this->multiple_sambaUserWorkstations = array();
1298 if(isset($all['sambaUserWorkstations'])){
1299 for($i = 0 ; $i < $all['sambaUserWorkstations']['count'] ; $i++){
1300 $station = trim($all['sambaUserWorkstations'][$i]);
1301 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => FALSE);
1302 }
1303 }
1304 if(isset($attrs['sambaUserWorkstations'])){
1305 for($i = 0 ; $i < $attrs['sambaUserWorkstations']['count'] ; $i++){
1306 $station = trim($attrs['sambaUserWorkstations'][$i]);
1307 $this->multiple_sambaUserWorkstations[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1308 }
1309 }
1310 }
1312 function multiple_execute()
1313 {
1314 return($this->execute());
1315 }
1317 function get_multi_edit_values()
1318 {
1319 $ret = plugin::get_multi_edit_values();
1321 /* Terminal Server */
1322 if(in_array("tslogin",$this->multi_boxes)){
1323 $ret['tslogin'] = $this->mungedObject->getTsLogin();
1324 }
1325 if(in_array("CtxWFHomeDirDrive",$this->multi_boxes)){
1326 $ret['CtxWFHomeDirDrive'] = $this->mungedObject->ctx['CtxWFHomeDirDrive'];
1327 }
1328 if(in_array("CtxWFHomeDir",$this->multi_boxes)){
1329 $ret['CtxWFHomeDir'] = $this->mungedObject->ctx['CtxWFHomeDir'];
1330 }
1331 if(in_array("CtxWFProfilePath",$this->multi_boxes)){
1332 $ret['CtxWFProfilePath'] = $this->mungedObject->ctx['CtxWFProfilePath'];
1333 }
1335 if(in_array("inherit",$this->multi_boxes)){
1336 $ret['inherit'] = $this->mungedObject->getInheritMode();
1337 }
1338 if(in_array("CtxInitialProgram",$this->multi_boxes)){
1339 $ret['CtxInitialProgram'] = $this->mungedObject->ctx['CtxInitialProgram'];
1340 }
1341 if(in_array("CtxWorkDirectory",$this->multi_boxes)){
1342 $ret['CtxWorkDirectory'] = $this->mungedObject->ctx['CtxWorkDirectory'];
1343 }
1345 /* Time Limits. Be careful here, there are some negations */
1346 if(in_array("CtxMaxConnectionTimeF",$this->multi_boxes)){
1347 $ret["CtxMaxConnectionTimeF"] = !$this->mungedObject->getCtxMaxConnectionTimeF();
1348 if(!$ret["CtxMaxConnectionTimeF"]){
1349 $ret["CtxMaxConnectionTime"] = $this->mungedObject->ctx['CtxMaxConnectionTime'];
1350 }
1351 }
1352 if(in_array("CtxMaxDisconnectionTimeF",$this->multi_boxes)){
1353 $ret["CtxMaxDisconnectionTimeF"]= !$this->mungedObject->getCtxMaxDisconnectionTimeF();
1354 if(!$ret["CtxMaxDisconnectionTimeF"]){
1355 $ret["CtxMaxDisconnectionTime"]= $this->mungedObject->ctx['CtxMaxDisconnectionTime'];
1356 }
1357 }
1358 if(in_array("CtxMaxIdleTimeF",$this->multi_boxes)){
1359 $ret["CtxMaxIdleTimeF"] = !$this->mungedObject->getCtxMaxIdleTimeF();
1360 if(!$ret["CtxMaxIdleTimeF"]){
1361 $ret["CtxMaxIdleTime"] = $this->mungedObject->ctx['CtxMaxIdleTime'];
1362 }
1363 }
1365 /* Client Devices */
1366 if(in_array("connectclientdrives",$this->multi_boxes)){
1367 $ret["connectclientdrives"] = $this->mungedObject->getConnectClientDrives();
1368 }
1369 if(in_array("connectclientprinters",$this->multi_boxes)){
1370 $ret["connectclientprinters"] = $this->mungedObject->getConnectClientPrinters();
1371 }
1372 if(in_array("defaultprinter",$this->multi_boxes)){
1373 $ret["defaultprinter"] = $this->mungedObject->getDefaultPrinter();
1374 }
1376 /* Misc */
1377 if(in_array("shadow",$this->multi_boxes)){
1378 $ret["shadow"] =$this->mungedObject->getShadow();
1379 }
1380 if(in_array("brokenconn",$this->multi_boxes)){
1381 $ret["brokenconn"]=$this->mungedObject->getBrokenConn();
1382 }
1383 if(in_array("reconn",$this->multi_boxes)){
1384 $ret["reconn"] =$this->mungedObject->getReConn();
1385 }
1387 /* Flags */
1388 if(in_array("allow_pwchange",$this->multi_boxes)){
1389 $ret['sambaPwdCanChange'] = $this->sambaPwdCanChange;
1390 $ret['pwdCanChange'] = $this->pwdCanChange;
1391 }
1393 if(in_array("password_expires",$this->multi_boxes)){
1394 $ret['password_expires'] = $this->password_expires;
1395 $ret['sambaPwdMustChange']= $this->sambaPwdMustChange;
1396 }
1397 if(in_array("logon_time_set",$this->multi_boxes)){
1398 $ret['logon_time_set'] = $this->logon_time_set;
1399 $ret['sambaLogonTime'] = $this->sambaLogonTime;
1400 }
1401 if(in_array("logoff_time_set",$this->multi_boxes)){
1402 $ret['logoff_time_set'] = $this->logoff_time_set;
1403 $ret['sambaLogoffTime'] = $this->sambaLogoffTime;
1404 }
1405 if(in_array("kickoff_time_set",$this->multi_boxes)){
1406 $ret['kickoff_time_set'] = $this->kickoff_time_set;
1407 $ret['sambaKickoffTime'] = $this->sambaKickoffTime;
1408 }
1410 if(in_array("no_password_required",$this->multi_boxes)){
1411 $ret['no_password_required'] = $this->no_password_required;
1412 }
1414 if(in_array("temporary_disable",$this->multi_boxes)){
1415 $ret['temporary_disable'] = $this->temporary_disable;
1416 }
1418 if(in_array("SetSambaLogonHours",$this->multi_boxes)){
1419 $ret['sambaLogonHours'] = $this->sambaLogonHours;
1420 }
1422 if(in_array("workstation_list",$this->multi_boxes)){
1423 $ret['multiple_sambaUserWorkstations'] = $this->multiple_sambaUserWorkstations;
1424 }
1425 return($ret);
1426 }
1428 function set_multi_edit_values($values)
1429 {
1430 plugin::set_multi_edit_values($values);
1432 /* Prepare current workstation settings to be merged
1433 * with multiple edit settings.
1434 */
1435 if(isset($values['multiple_sambaUserWorkstations'])){
1436 $cur_ws = array();
1437 $m_ws = $values['multiple_sambaUserWorkstations'];
1439 /* Prepare current settings to be merged */
1440 if(isset($this->sambaUserWorkstations)){
1441 $ttmp = split(",",$this->sambaUserWorkstations);
1442 foreach($ttmp as $station){
1443 $station = trim($station);
1444 if(!empty($station)){
1445 $cur_ws[$station] = array("Name" => $station, "UsedByAllUsers" => TRUE);
1446 }
1447 }
1448 }
1450 /* Unset removed workstations */
1451 foreach($cur_ws as $cur_name => $cur_station){
1452 if(!isset($m_ws[$cur_name])){
1453 unset($cur_ws[$cur_name]);
1454 }
1455 }
1457 /* Add all added workstations */
1458 foreach($m_ws as $name => $station){
1459 if($station['UsedByAllUsers']){
1460 $cur_ws[$name] = $station;
1461 }
1462 }
1464 $this->sambaUserWorkstations = "";
1465 foreach($cur_ws as $name => $ws){
1466 $this->sambaUserWorkstations .= $name.",";
1467 }
1468 $this->sambaUserWorkstations=preg_replace("/,$/","",$this->sambaUserWorkstations);
1469 }
1471 /* Enable disabled terminal login, this is inverted somehow */
1472 if(isset($values['tslogin'])) $this->mungedObject->setTsLogin(!$values['tslogin']);
1474 /* Imherit client configuration */
1475 if(isset($values['inherit'])) $this->mungedObject->setInheritMode($values['inherit']);
1477 /* Get all ctx values posted */
1478 $ctx = array("CtxWFHomeDirDrive","CtxWFHomeDir","CtxWFProfilePath","CtxInitialProgram","CtxWorkDirectory",
1479 "CtxMaxConnectionTime","CtxMaxDisconnectionTime","CtxMaxIdleTime");
1480 foreach($ctx as $attr){
1481 if(isset($values[$attr])){
1482 $this->mungedObject->ctx[$attr] = $values[$attr] ;
1483 }
1484 }
1486 if(isset($values['CtxMaxConnectionTimeF'])) $this->mungedObject->setCtxMaxConnectionTimeF($values['CtxMaxConnectionTimeF']);
1487 if(isset($values['CtxMaxDisconnectionTimeF']))$this->mungedObject->setCtxMaxDisconnectionTimeF($values['CtxMaxDisconnectionTimeF']);
1488 if(isset($values['CtxMaxIdleTimeF'])) $this->mungedObject->setCtxMaxIdleTimeF($values['CtxMaxIdleTimeF']);
1490 if(isset($values['connectclientdrives'])) $this->mungedObject->setConnectClientDrives($values['connectclientdrives']);
1491 if(isset($values['connectclientprinters'])) $this->mungedObject->setConnectClientPrinters($values['connectclientprinters']);
1492 if(isset($values['defaultprinter'])) $this->mungedObject->setDefaultPrinter($values['defaultprinter']);
1494 if(isset($values['shadow'])) $this->mungedObject->setShadow($values['shadow'],$values['shadow']);
1495 if(isset($values['brokenconn'])) $this->mungedObject->setBrokenConn($values['brokenconn'],$values['brokenconn']);
1496 if(isset($values['reconn'])) $this->mungedObject->setReConn($values['reconn'],$values['reconn']);
1499 if(isset($values['sambaPwdCanChange'])) $this->sambaPwdCanChange = $values['sambaPwdCanChange'];
1500 if(isset($values['pwdCanChange'])) $this->pwdCanChange = $values['pwdCanChange'];
1505 if(isset($values['password_expires'])){
1506 $this->password_expires = $values['password_expires'];
1507 $this->sambaPwdMustChange = $values['sambaPwdMustChange'];
1508 }
1509 if(isset($values['logon_time_set'])){
1510 $this->logon_time_set = $values['logon_time_set'];
1511 $this->sambaLogonTime = $values['sambaLogonTime'];
1512 }
1513 if(isset($values['logoff_time_set'])){
1514 $this->logoff_time_set = $values['logoff_time_set'];
1515 $this->sambaLogoffTime = $values['sambaLogoffTime'];
1516 }
1517 if(isset($values['kickoff_time_set'])){
1518 $this->kickoff_time_set = $values['kickoff_time_set'];
1519 $this->sambaKickoffTime = $values['sambaKickoffTime'];
1520 }
1522 if(isset($values['no_password_required'])){
1523 if($values['no_password_required']){
1524 if(!preg_match("/N/",$this->sambaAcctFlags)) {
1525 $this->sambaAcctFlags = preg_replace("/ /","N",$this->sambaAcctFlags,1);
1526 }
1527 }else{
1528 $this->sambaAcctFlags = preg_replace("/N/"," ",$this->sambaAcctFlags,1);
1529 }
1530 }
1532 if(isset($values['temporary_disable'])){
1533 if($values['temporary_disable']){
1534 if(preg_match("/L/",$this->sambaAcctFlags)) {
1535 // Keep L
1536 }else{
1537 $this->sambaAcctFlags = preg_replace("/ /","D",$this->sambaAcctFlags,1);
1538 }
1539 }else{
1540 $this->sambaAcctFlags = preg_replace("/D/"," ",$this->sambaAcctFlags,1);
1541 }
1542 }
1543 }
1546 function PrepareForCopyPaste($source)
1547 {
1548 plugin::PrepareForCopyPaste($source);
1550 /* Set a new SID */
1551 $this->sambaSID = "";
1552 }
1554 }
1556 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1557 ?>