d66ec57e0eee7796dca618e4a392132f742d3302
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 $dialog = NULL;
93 var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
95 function sambaAccount (&$config, $dn= NULL)
96 {
97 /* Load attributes depending on the samba version */
98 $this->samba3= ($config->current['SAMBAVERSION'] == 3);
100 if ($this->samba3){
101 $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
102 "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
103 "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
104 "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
105 "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
106 "sambaUserWorkstations", "sambaPasswordHistory",
107 "sambaLogonHours", "sambaBadPasswordTime",
108 "sambaBadPasswordCount");
109 $this->objectclasses= array ("sambaSamAccount");
110 $this->mungedObject= new sambaMungedDial;
111 $this->ctxattributes= $this->mungedObject->ctxattributes;
112 } else {
113 $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
114 "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
115 "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
116 $this->objectclasses= array ("sambaAccount");
117 }
119 plugin::plugin ($config, $dn);
121 /* Setting uid to default */
122 if(isset($this->attrs['uid'][0])){
123 $this->uid = $this->attrs['uid'][0];
124 }
126 /* Get samba Domain in case of samba 3 */
127 if ($this->samba3 && $this->sambaSID != ""){
128 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
129 $ldap= $this->config->get_ldap_link();
130 $ldap->cd($this->config->current['BASE']);
131 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
132 if ($ldap->count() != 0){
133 $attrs= $ldap->fetch();
134 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
135 if ($this->sambaDomainName == ""){
136 $this->sambaDomainName= $attrs['sambaDomainName'][0];
137 }
138 } else {
139 if ($this->sambaDomainName == ""){
140 $this->sambaDomainName= "DEFAULT";
141 }
142 $this->ridBase= $this->config->current['RIDBASE'];
143 $this->SID= $this->config->current['SID'];
144 }
146 /* Save in order to compare later on */
147 $this->orig_sambaDomainName= $this->sambaDomainName;
148 }
150 /* Fill mungedDial field */
151 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
152 $this->mungedObject->load($this->sambaMungedDial);
153 }
155 /* Password expiery */
156 if(isset($this->attrs['sambaPwdMustChange']) &&
157 $this->attrs['sambaPwdMustChange'][0] != 0){
158 $this->password_expires= 1;
159 }
161 if(isset($this->attrs['sambaLogonTime']) && ! (
162 $this->attrs['sambaLogonTime'][0] == 0 ||
163 $this->attrs['sambaLogonTime'][0] == 2147483647
164 )){
165 $this->logon_time_set= 1;
166 }
167 if(isset($this->attrs['sambaLogoffTime']) && ! (
168 $this->attrs['sambaLogoffTime'][0] == 0 ||
169 $this->attrs['sambaLogoffTime'][0] == 2147483647
170 )){
171 $this->logoff_time_set= 1;
172 }
174 /* Account expiery */
175 if(isset($this->attrs['sambaKickoffTime']) && ! (
176 $this->attrs['sambaKickoffTime'][0] == 0 ||
177 $this->attrs['sambaKickoffTime'][0] == 2147483647
178 )){
179 $this->kickoff_time_set= 1;
180 }
182 /* Get global filter config */
183 if (!is_global("sambafilter")){
184 $ui= get_userinfo();
185 $base= get_base_from_people($ui->dn);
186 $sambafilter= array( "depselect" => $base, "regex" => "*");
187 register_global("sambafilter", $sambafilter);
188 }
190 /* Save initial account state */
191 $this->initially_was_account= $this->is_account;
192 }
194 function execute()
195 {
196 /* Call parent execute */
197 plugin::execute();
199 /* Log view */
200 if($this->is_account && !$this->view_logged){
201 $this->view_logged = TRUE;
202 new log("view","users/".get_class($this),$this->dn);
203 }
205 /* Do we need to flip is_account state? */
206 if (isset($_POST['modify_state'])){
207 $this->is_account= !$this->is_account;
208 }
209 /* Do we represent a valid account? */
210 if (!$this->is_account && $this->parent == NULL){
211 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
212 _("This account has no samba extensions.")."</b>";
213 $display.= back_to_main();
214 return ($display);
215 }
217 /* Show tab dialog headers */
218 $display= "";
219 if ($this->parent != NULL){
220 if ($this->is_account){
221 $display= $this->show_disable_header(_("Remove samba account"),
222 _("This account has samba features enabled. You can disable them by clicking below."));
223 } else {
224 $obj= $this->parent->by_object['posixAccount'];
226 /* Samba3 dependency on posix accounts are enabled
227 in the moment, because I need to rely on unique
228 uidNumbers. There'll be a better solution later
229 on. */
230 if ($obj->is_account){
232 $display= $this->show_enable_header(_("Create samba account"),
233 _("This account has samba features disabled. You can enable them by clicking below."));
234 } else {
235 $display= $this->show_enable_header(_("Create samba account"),
236 _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
237 }
238 return ($display);
239 }
240 }
242 $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
244 /* Open Samaba Logong hours dialog */
245 if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
246 $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
247 }
249 /* Cancel dialog */
250 if(isset($_POST['cancel_logonHours'])){
251 $this->dialog = NULL;
252 }
254 /* Save selected logon hours */
255 if(isset($_POST['save_logonHours'])){
256 $this->dialog->save_object();
257 if($this->acl_is_writeable("sambaLogonHours")){
258 $this->sambaLogonHours = $this->dialog->save();
259 }
260 $this->dialog = NULL;
261 }
263 /* Display dialog */
264 if((isset($this->dialog)) && (is_object($this->dialog))){
265 $this->dialog->save_object();
266 return($this->dialog->execute());
267 }
270 /* Prepare templating */
271 $smarty= get_smarty();
273 $tmp = $this->plInfo();
274 foreach($tmp['plProvidedAcls'] as $var => $rest){
275 $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
276 }
278 if ($this->sambaPwdMustChange=="0"){
279 $date= getdate();
280 } else {
281 $date= getdate($this->sambaPwdMustChange);
282 }
284 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
285 $sambaLogonTime_date= getdate();
286 } else {
287 $sambaLogonTime_date= getdate($this->sambaLogonTime);
288 }
290 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
291 $sambaLogoffTime_date= getdate();
292 } else {
293 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
294 }
296 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
297 $sambaKickoffTime_date= getdate();
298 } else {
299 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
300 }
302 /* Remove user workstations? */
303 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
305 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
307 $tmp= $this->sambaUserWorkstations;
308 foreach($_POST['workstation_list'] as $name){
309 $tmp= preg_replace("/$name/", '', $tmp);
310 $this->is_modified= TRUE;
311 }
312 $tmp= preg_replace('/,+/', ',', $tmp);
313 $this->sambaUserWorkstations= trim($tmp, ',');
314 }
315 }
317 /* Add user workstation? */
318 if (isset($_POST["add_ws"])){
319 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
320 $this->show_ws_dialog= TRUE;
321 $this->dialog= TRUE;
322 }
323 }
325 /* Add user workstation finished? */
326 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
327 $this->show_ws_dialog= FALSE;
328 $this->dialog= FALSE;
329 }
331 /* Add user workstation? */
332 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
333 $tmp= $this->sambaUserWorkstations;
334 foreach($_POST['wslist'] as $ws){
335 $tmp.= ",$ws";
336 }
337 $tmp= preg_replace('/,+/', ',', $tmp);
338 $this->sambaUserWorkstations= trim($tmp, ',');
339 $this->is_modified= TRUE;
340 }
342 /* Show ws dialog */
343 if ($this->show_ws_dialog){
345 /* Save data */
346 $sambafilter= get_global("sambafilter");
347 foreach( array("depselect", "regex") as $type){
348 if (isset($_POST[$type])){
349 $sambafilter[$type]= $_POST[$type];
350 }
351 }
352 if (isset($_GET['search'])){
353 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
354 if ($s == "**"){
355 $s= "*";
356 }
357 $sambafilter['regex']= $s;
358 }
359 register_global("sambafilter", $sambafilter);
361 /* Get workstation list */
362 $exclude= "";
363 foreach(split(',', $this->sambaUserWorkstations) as $ws){
364 $exclude.= "(cn=$ws$)";
365 }
366 if ($exclude != ""){
367 $exclude= "(!(|$exclude))";
368 }
369 $regex= $sambafilter['regex'];
370 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
371 $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
373 $wslist= array();
374 foreach ($res as $attrs){
375 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
376 }
377 asort($wslist);
379 $smarty->assign("search_image", get_template_path('images/search.png'));
380 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
381 $smarty->assign("tree_image", get_template_path('images/tree.png'));
382 $smarty->assign("deplist", $this->config->idepartments);
383 $smarty->assign("alphabet", generate_alphabet());
384 foreach( array("depselect", "regex") as $type){
385 $smarty->assign("$type", $sambafilter[$type]);
386 }
387 $smarty->assign("hint", print_sizelimit_warning());
388 $smarty->assign("wslist", $wslist);
389 $smarty->assign("apply", apply_filter());
390 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
391 dirname(__FILE__)));
392 return ($display);
393 }
395 /* Fill calendar */
396 $days= array();
397 for($d= 1; $d<32; $d++){
398 $days[]= $d;
399 }
400 $years= array();
401 for($y= $date['year']-4; $y<$date['year']+4; $y++){
402 $years[]= $y;
403 }
404 $months= array(_("January"), _("February"), _("March"), _("April"),
405 _("May"), _("June"), _("July"), _("August"), _("September"),
406 _("October"), _("November"), _("December"));
407 $smarty->assign("day", $date["mday"]);
408 $smarty->assign("days", $days);
409 $smarty->assign("months", $months);
410 $smarty->assign("month", $date["mon"]-1);
411 $smarty->assign("years", $years);
412 $smarty->assign("year", $date["year"]);
414 $sambaLogonTime_days= array();
415 for($d= 1; $d<32; $d++){
416 $sambaLogonTime_days[]= $d;
417 }
418 $sambaLogonTime_years= array();
419 for($y= $date['year']-4; $y<$date['year']+4; $y++){
420 $sambaLogonTime_years[]= $y;
421 }
422 $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
423 _("May"), _("June"), _("July"), _("August"), _("September"),
424 _("October"), _("November"), _("December"));
425 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
426 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
427 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
428 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
429 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
430 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
432 $sambaLogoffTime_days= array();
433 for($d= 1; $d<32; $d++){
434 $sambaLogoffTime_days[]= $d;
435 }
436 $sambaLogoffTime_years= array();
437 for($y= $date['year']-4; $y<$date['year']+4; $y++){
438 $sambaLogoffTime_years[]= $y;
439 }
440 $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
441 _("May"), _("June"), _("July"), _("August"), _("September"),
442 _("October"), _("November"), _("December"));
443 $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
444 $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
445 $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
446 $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
447 $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
448 $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
450 $sambaKickoffTime_days= array();
451 for($d= 1; $d<32; $d++){
452 $sambaKickoffTime_days[]= $d;
453 }
454 $sambaKickoffTime_years= array();
455 for($y= $date['year']-4; $y<$date['year']+4; $y++){
456 $sambaKickoffTime_years[]= $y;
457 }
458 $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
459 _("May"), _("June"), _("July"), _("August"), _("September"),
460 _("October"), _("November"), _("December"));
461 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
462 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
463 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
464 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
465 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
466 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
467 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
469 /* Fill boxes */
470 if ($this->samba3){
471 $domains= array();
472 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
473 $domains[]= $name;
474 }
475 $smarty->assign("domains", $domains);
476 }
477 $letters= array();
478 for ($i= 68; $i<91; $i++){
479 $letters[]= chr($i).":";
480 }
481 $smarty->assign("drives", $letters);
483 /* Fill terminal server settings */
484 if ($this->samba3){
485 foreach ($this->ctxattributes as $attr){
486 /* Fill common attributes */
487 if (isset($this->mungedObject->ctx[$attr])){
488 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
489 // Set field to blank if value is 0
490 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
491 if($this->mungedObject->ctx[$attr] == 0) {
492 $smarty->assign("$attr", "");
493 }
494 }
495 } else {
496 $smarty->assign("$attr", "");
497 }
498 }
500 /* Assign enum values for preset items */
501 $shadowModeVals= array( "0" => _("disabled"),
502 "1" => _("input on, notify on"),
503 "2" => _("input on, notify off"),
504 "3" => _("input off, notify on"),
505 "4" => _("input off, nofify off"));
507 $brokenConnModeVals= array( "0" => _("disconnect"),
508 "1" => _("reset"));
510 $reConnModeVals= array( "0" => _("from any client"),
511 "1" => _("from previous client only"));
513 /* Fill preset items */
514 $smarty->assign("shadow", $shadowModeVals);
515 $smarty->assign("brokenconn", $brokenConnModeVals);
516 $smarty->assign("reconn", $reConnModeVals);
518 /* Fill preset items with values */
519 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
520 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
521 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
523 if($_SESSION['js']){
524 /* Set form elements to disabled/enable state */
525 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
527 $smarty->assign("inheritstate", "");
528 if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
529 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
530 }
534 }else{
535 $smarty->assign("tsloginstate", "");
536 $smarty->assign("inheritstate", "");
537 }
539 /* Set checkboxes to checked or unchecked state */
540 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
541 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
542 $smarty->assign("connectclientdrives",
543 $this->mungedObject->getConnectClientDrives()?"checked":"");
544 $smarty->assign("connectclientprinters",
545 $this->mungedObject->getConnectClientPrinters()?"checked":"");
546 $smarty->assign("defaultprinter",
547 $this->mungedObject->getDefaultPrinter()?"checked":"");
548 $smarty->assign("CtxMaxConnectionTimeF",
549 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
550 $smarty->assign("CtxMaxDisconnectionTimeF",
551 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
552 $smarty->assign("CtxMaxIdleTimeF",
553 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
555 /* Fill sambaUserWorkstations */
556 $ws= split(",", $this->sambaUserWorkstations);
557 sort($ws);
559 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
560 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
563 $smarty->assign("workstations", $ws);
564 }
566 /* Variables */
567 foreach($this->attributes as $val){
568 $smarty->assign("$val", $this->$val);
569 }
571 /* 'sambaAcctFlags' checkboxes */
572 /* Check for 'lock-account'-flag: 'D' or 'L' */
573 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
574 is_integer(strpos($this->sambaAcctFlags, "L"))) {
575 $smarty->assign("flagsD", "checked");
576 } else {
577 $smarty->assign("flagsD", "");
578 }
580 /* Check for no_password_required flag 'N' */
581 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
582 $smarty->assign("flagsN", "checked");
583 } else {
584 $smarty->assign("flagsN", "");
585 }
587 if($this->samba3){
588 if ($this->sambaPwdCanChange=="1"){
589 $smarty->assign("flagsP", "checked");
590 } else {
591 $smarty->assign("flagsP", "");
592 }
593 }else{
594 if ($this->pwdCanChange=="1"){
595 $smarty->assign("flagsP", "checked");
596 } else {
597 $smarty->assign("flagsP", "");
598 }
599 }
601 if ($this->password_expires=="1"){
602 $smarty->assign("flagsC", "checked");
603 } else {
604 $smarty->assign("flagsC", "");
605 }
606 if ($this->logon_time_set=="1"){
607 $smarty->assign("flagsT", "checked");
608 } else {
609 $smarty->assign("flagsT", "");
610 }
611 if ($this->logoff_time_set=="1"){
612 $smarty->assign("flagsO", "checked");
613 } else {
614 $smarty->assign("flagsO", "");
615 }
616 if ($this->kickoff_time_set=="1"){
617 $smarty->assign("flagsK", "checked");
618 } else {
619 $smarty->assign("flagsK", "");
620 }
623 /* In case of javascript, disable some fields on demand */
624 if ($this->samba3){
625 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
626 $smarty->assign("$key", "$value");
627 }
628 }
630 /* Show main page */
631 if ($this->samba3){
632 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
633 } else {
634 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
635 }
637 return ($display);
638 }
640 function remove_from_parent()
641 {
642 /* Cancel if there's nothing to do here */
643 if (!$this->initially_was_account){
644 return;
645 }
647 /* include global link_info */
648 $ldap= $this->config->get_ldap_link();
650 plugin::remove_from_parent();
652 /* Keep uid attribute for gosaAccount */
653 unset($this->attrs['uid']);
654 unset($this->attrs['uidNumber']);
655 unset($this->attrs['gidNumber']);
657 /* Remove objectClass for sambaIdmapEntry */
658 $tmp= array();
659 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
660 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
661 $tmp[]= $this->attrs['objectClass'][$i];
662 }
663 }
664 $this->attrs['objectClass']= $tmp;
666 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
667 $this->attributes, "Save");
668 $ldap->cd($this->dn);
669 $this->cleanup();
670 $ldap->modify ($this->attrs);
672 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
674 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
676 /* Optionally execute a command after we're done */
677 $this->handle_post_events("remove", array("uid" => $this->uid));
678 }
681 /* Check for input problems */
682 function check()
683 {
684 /* Call common method to give check the hook */
685 $message= plugin::check();
687 if ($this->samba3){
689 /* Strings */
690 foreach (array( "sambaHomePath" => _("Home directory"),
691 "sambaProfilePath" => _("Profile path")) as $key => $val){
692 if (!$this->mungedObject->is_samba_path($this->$key)){
693 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
694 }
695 }
697 /* Numeric values */
698 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
699 "CtxMaxDisconnectionTime" => _("Disconnection"),
700 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
702 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
703 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
704 }
705 }
707 /* Too many workstations? Windows usrmgr only supports eight */
708 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
709 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
710 }
711 }
713 return ($message);
714 }
717 /* Save data to object */
718 function save_object()
719 {
721 $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
723 /* We only care if we are on the sambaTab... */
724 if (isset($_POST['sambaTab'])){
725 plugin::save_object();
727 /* Take care about access options */
728 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
729 if ($this->samba3){
730 $attrname= "sambaPwdCanChange";
731 } else {
732 $attrname= "pwdCanChange";
733 }
734 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
735 $tmp= 1;
736 } else {
737 $tmp= 0;
738 }
739 if ($this->$attrname != $tmp){
740 $this->is_modified= TRUE;
741 }
742 $this->pwdCanChange= $tmp;
743 $this->sambaPwdCanChange= $tmp;
744 }
745 $tmp= "UX";
746 if (isset($_POST["no_password_required"])){
747 if ($_POST["no_password_required"] == 1){
748 $tmp.= "N";
749 }
750 }
751 if (isset($_POST["password_expires"])){
752 if ($_POST["password_expires"] == 1){
753 $this->password_expires= 1;
754 }
755 } else {
756 $this->password_expires= 0;
757 }
758 if (isset($_POST["temporary_disable"])){
759 if ($_POST["temporary_disable"] == 1){
760 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
761 $tmp.= "L";
762 } else {
763 $tmp.= "D";
764 }
765 }
766 }
767 if (isset($_POST["logon_time_set"])){
768 if ($_POST["logon_time_set"] == 1){
769 $this->logon_time_set= 1;
770 }
771 } else {
772 $this->logon_time_set= 0;
773 }
774 if (isset($_POST["logoff_time_set"])){
775 if ($_POST["logoff_time_set"] == 1){
776 $this->logoff_time_set= 1;
777 }
778 } else {
779 $this->logoff_time_set= 0;
780 }
781 if (isset($_POST["kickoff_time_set"])){
782 if ($_POST["kickoff_time_set"] == 1){
783 $this->kickoff_time_set= 1;
784 }
785 } else {
786 $this->kickoff_time_set= 0;
787 }
789 $fill= "";
790 for ($i= strlen($tmp); $i<12; $i++){
791 $fill.= " ";
792 }
794 $tmp= "[$tmp$fill]";
796 /* Only save if acl's are set */
797 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
798 if ($this->samba3){
799 $attrname= "sambaAcctFlags";
800 } else {
801 $attrname= "acctFlags";
802 }
803 if ($this->$attrname != $tmp){
804 $this->is_modified= TRUE;
805 }
806 $this->$attrname= $tmp;
807 }
809 /* Save sambaDomain attribute */
810 if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
811 $this->sambaDomainName= validate($_POST['sambaDomainName']);
812 }
814 /* Save CTX values */
815 if ($this->samba3){
817 /* Save obvious values */
818 foreach($this->ctxattributes as $val){
819 if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
820 if (get_magic_quotes_gpc()) {
821 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
822 } else {
823 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
824 }
825 }
826 }
828 /* Save checkbox states. */
829 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
830 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
831 // Need to do some index checking to avoid messages like "index ... not found"
832 if(isset($_POST['brokenconn'])) {
833 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
834 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
835 }
836 if(isset($_POST['reconn'])) {
837 $this->mungedObject->setReConn($_POST['reconn'] == '1'
838 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
839 }
840 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
841 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
842 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
843 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
844 $this->mungedObject->setCtxMaxDisconnectionTimeF(
845 !isset($_POST['CtxMaxDisconnectionTimeF'])
846 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
847 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
848 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
849 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
850 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
851 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
852 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
853 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
854 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
856 /* Save combo boxes. Takes two values */
857 if(isset($_POST['reconn'])) {
858 $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
859 }
861 /* Check for changes */
862 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
863 $this->is_modified= TRUE;
864 }
865 }
866 }
867 }
870 /* Save to LDAP */
871 function save()
872 {
873 /* Load uid and gid of this 'dn' */
874 $ldap= $this->config->get_ldap_link();
875 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
876 $tmp= $ldap->fetch();
877 $this->uidNumber= $tmp['uidNumber'][0];
878 $this->gidNumber= $tmp['gidNumber'][0];
880 plugin::save();
882 /* Remove objectClass for sambaIdmapEntry */
883 $tmp= array();
884 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
885 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
886 $tmp[]= $this->attrs['objectClass'][$i];
887 }
888 }
889 $this->attrs['objectClass']= $tmp;
891 /* Generate rid / primaryGroupId */
892 if ($this->samba3){
893 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
894 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
895 } else {
896 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
897 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
898 }
900 /* Need to generate a new uniqe uid/gid combination? */
901 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
902 $uidNumber= $this->uidNumber;
903 while(TRUE){
904 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
905 $ldap->cd($this->config->current['BASE']);
906 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
907 if ($ldap->count() == 0){
908 break;
909 }
910 $uidNumber++;
911 }
912 $this->attrs['sambaSID']= $sid;
914 /* Check for users primary group */
915 $ldap->cd($this->config->current['BASE']);
916 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
917 if ($ldap->count() != 1){
918 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
919 } else {
920 $attrs= $ldap->fetch();
921 $g= new group($this->config, $ldap->getDN());
922 if ($g->sambaSID == ""){
923 $g->sambaDomainName= $this->sambaDomainName;
924 $g->smbgroup= TRUE;
925 $g->save ();
926 }
927 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
928 }
929 }
931 if ($this->sambaHomeDrive == ""){
932 $this->attrs["sambaHomeDrive"]= array();
933 }
935 /* Generate munged dial value */
936 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
938 /* User wants me to fake the idMappings? This is useful for
939 making winbind resolve the user names in a reasonable amount
940 of time in combination with larger databases. */
941 if (isset($this->config->current['SAMBAIDMAPPING']) &&
942 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
943 $this->attrs['objectClass'][]= "sambaIdmapEntry";
944 }
947 /* Password expiery */
948 if ($this->password_expires == "1"){
949 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
950 } else {
951 $this->attrs['sambaPwdMustChange']= array();
952 }
953 /* Make sure not to save zero in sambaPwdLastset */
954 if ($this->sambaPwdLastSet != "0"){
955 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
956 } else {
957 $this->attrs['sambaPwdLastSet']= array();
958 }
959 /* Account expiery */
960 if ($this->logon_time_set == "1"){
961 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
962 } else {
963 $this->attrs['sambaLogonTime']= array();
964 }
965 if ($this->logoff_time_set == "1"){
966 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
967 } else {
968 $this->attrs['sambaLogoffTime']= array();
969 }
970 if ($this->kickoff_time_set == "1"){
971 # Add one day in unixtime format to be compatible with usrmgr
972 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
973 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
974 } else {
975 $this->attrs['sambaKickoffTime']= array();
976 }
977 } else {
978 /* Not samba3 */
979 $this->attrs['rid']= $this->uidNumber*2 + 1000;
980 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
982 if ($this->homeDrive == ""){
983 $this->attrs["homeDrive"]= array();
984 }
986 /* Password expiery */
987 if ($this->password_expires == "1"){
988 $this->attrs['pwdMustChange']= $this->pwdMustChange;
989 } else {
990 $this->attrs['pwdMustChange']= 2147483647;
991 }
992 /* Make sure not to save zero in pwdLastset */
993 if ($this->pwdLastSet != "0"){
994 $this->attrs['pwdLastSet']= $this->pwdLastSet;
995 } else {
996 $this->attrs['pwdLastSet']= array();
997 }
998 /* Account expiery */
999 if ($this->logon_time_set == "1"){
1000 $this->attrs['logonTime']= $this->logonTime;
1001 } else {
1002 $this->attrs['logonTime']= array();
1003 }
1004 if ($this->logoff_time_set == "1"){
1005 $this->attrs['logoffTime']= $this->logoffTime;
1006 } else {
1007 $this->attrs['logoffTime']= array();
1008 }
1009 if ($this->kickoff_time_set == "1"){
1010 # Add one day in unixtime format to be compatible with usrmgr
1011 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1012 } else {
1013 $this->attrs['kickoffTime']= array();
1014 }
1015 }
1017 /* Write back to ldap */
1018 $ldap->cd($this->dn);
1019 $this->cleanup();
1020 $ldap->modify ($this->attrs);
1022 if($this->initially_was_account){
1023 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1024 }else{
1025 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1026 }
1028 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
1030 /* Optionally execute a command after we're done */
1031 if ($this->initially_was_account == $this->is_account){
1032 if ($this->is_modified){
1033 $this->handle_post_events("modify", array("uid" => $this->uid));
1034 }
1035 } else {
1036 $this->handle_post_events("add", array("uid" => $this->uid));
1037 }
1038 }
1041 /* Force password set, if this account doesn't have any samba passwords */
1042 function password_change_needed()
1043 {
1044 if(!$this->initially_was_account && $this->is_account){
1045 $ldap = $this->config->get_ldap_link();
1046 $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1047 $attrs = $ldap->fetch();
1048 if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1049 return(TRUE);
1050 }
1051 }
1052 return(FALSE);
1053 }
1056 function adapt_from_template($dn)
1057 {
1058 plugin::adapt_from_template($dn);
1059 $this->sambaSID= "";
1060 $this->sambaPrimaryGroupSID= "";
1062 /* Fill mungedDial field */
1063 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1064 $this->mungedObject->load($this->sambaMungedDial);
1065 }
1067 /* Password expiery */
1068 if(isset($this->attrs['sambaPwdMustChange']) &&
1069 $this->attrs['sambaPwdMustChange'][0] != 0){
1070 $this->password_expires= 1;
1071 }
1073 if(isset($this->attrs['sambaLogonTime']) && ! (
1074 $this->attrs['sambaLogonTime'][0] == 0 ||
1075 $this->attrs['sambaLogonTime'][0] == 2147483647
1076 )){
1077 $this->logon_time_set= 1;
1078 }
1079 if(isset($this->attrs['sambaLogoffTime']) && ! (
1080 $this->attrs['sambaLogoffTime'][0] == 0 ||
1081 $this->attrs['sambaLogoffTime'][0] == 2147483647
1082 )){
1083 $this->logoff_time_set= 1;
1084 }
1086 /* Account expiery */
1087 if(isset($this->attrs['sambaKickoffTime']) && ! (
1088 $this->attrs['sambaKickoffTime'][0] == 0 ||
1089 $this->attrs['sambaKickoffTime'][0] == 2147483647
1090 )){
1091 $this->kickoff_time_set= 1;
1092 }
1094 /* Get global filter config */
1095 if (!is_global("sambafilter")){
1096 $ui= get_userinfo();
1097 $base= get_base_from_people($ui->dn);
1098 $sambafilter= array( "depselect" => $base, "regex" => "*");
1099 register_global("sambafilter", $sambafilter);
1100 }
1101 }
1104 function plInfo()
1105 {
1106 return (array(
1107 "plShortName" => _("Samba"),
1108 "plDescription" => _("Samba settings"),
1109 "plSelfModify" => TRUE,
1110 "plDepends" => array("user"),
1111 "plPriority" => 5,
1112 "plSection" => array("personal" => _("My account")),
1113 "plCategory" => array("users"),
1114 "plOptions" => array(),
1116 "plProvidedAcls" => array(
1117 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1118 "InheritClientConfig" => _("Inherit client config"),
1120 "sambaPwdCanChange" => _("Allow user to change password") ,
1121 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1122 "sambaAcctFlagsL" => _("Lock samba account"),
1125 "sambaKickoffTime" => _("Account expires") ,
1126 "sambaPwdMustChange" => _("Password expires") ,
1128 "sambaLogonTime" => _("Limit Logon Time") ,
1129 "sambaLogoffTime" => _("Limit Logoff Time") ,
1130 "sambaLogonHours" => _("Logon hours") ,
1132 "sambaHomePath" => _("Generic home directory") ,
1133 "sambaHomeDrive" => _("Generic samba home drive") ,
1134 "sambaLogonScript" => _("Generic script path") ,
1135 "sambaProfilePath" => _("Generic profile path") ,
1136 "sambaDomainName" => _("Domain") ,
1137 "sambaUserWorkstations" => _("Allow connection from")))
1138 );
1139 }
1140 }
1142 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1143 ?>