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