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;
191 }
193 function execute()
194 {
195 /* Call parent execute */
196 plugin::execute();
198 /* Do we need to flip is_account state? */
199 if (isset($_POST['modify_state'])){
200 $this->is_account= !$this->is_account;
201 }
202 /* Do we represent a valid account? */
203 if (!$this->is_account && $this->parent == NULL){
204 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
205 _("This account has no samba extensions.")."</b>";
206 $display.= back_to_main();
207 return ($display);
208 }
210 /* Show tab dialog headers */
211 $display= "";
212 if ($this->parent != NULL){
213 if ($this->is_account){
214 $display= $this->show_disable_header(_("Remove samba account"),
215 _("This account has samba features enabled. You can disable them by clicking below."));
216 } else {
217 $obj= $this->parent->by_object['posixAccount'];
219 /* Samba3 dependency on posix accounts are enabled
220 in the moment, because I need to rely on unique
221 uidNumbers. There'll be a better solution later
222 on. */
223 if ($obj->is_account){
225 $display= $this->show_enable_header(_("Create samba account"),
226 _("This account has samba features disabled. You can enable them by clicking below."));
227 } else {
228 $display= $this->show_enable_header(_("Create samba account"),
229 _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
230 }
231 return ($display);
232 }
233 }
235 $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
237 /* Open Samaba Logong hours dialog */
238 if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
239 $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
240 }
242 /* Cancel dialog */
243 if(isset($_POST['cancel_logonHours'])){
244 $this->dialog = NULL;
245 }
247 /* Save selected logon hours */
248 if(isset($_POST['save_logonHours'])){
249 $this->dialog->save_object();
250 if($this->acl_is_writeable("sambaLogonHours")){
251 $this->sambaLogonHours = $this->dialog->save();
252 }
253 $this->dialog = NULL;
254 }
256 /* Display dialog */
257 if((isset($this->dialog)) && (is_object($this->dialog))){
258 $this->dialog->save_object();
259 return($this->dialog->execute());
260 }
263 /* Prepare templating */
264 $smarty= get_smarty();
266 $tmp = $this->plInfo();
267 foreach($tmp['plProvidedAcls'] as $var => $rest){
268 $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
269 }
271 if ($this->sambaPwdMustChange=="0"){
272 $date= getdate();
273 } else {
274 $date= getdate($this->sambaPwdMustChange);
275 }
277 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
278 $sambaLogonTime_date= getdate();
279 } else {
280 $sambaLogonTime_date= getdate($this->sambaLogonTime);
281 }
283 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
284 $sambaLogoffTime_date= getdate();
285 } else {
286 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
287 }
289 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
290 $sambaKickoffTime_date= getdate();
291 } else {
292 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
293 }
295 /* Remove user workstations? */
296 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
298 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
300 $tmp= $this->sambaUserWorkstations;
301 foreach($_POST['workstation_list'] as $name){
302 $tmp= preg_replace("/$name/", '', $tmp);
303 $this->is_modified= TRUE;
304 }
305 $tmp= preg_replace('/,+/', ',', $tmp);
306 $this->sambaUserWorkstations= trim($tmp, ',');
307 }
308 }
310 /* Add user workstation? */
311 if (isset($_POST["add_ws"])){
312 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
313 $this->show_ws_dialog= TRUE;
314 $this->dialog= TRUE;
315 }
316 }
318 /* Add user workstation finished? */
319 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
320 $this->show_ws_dialog= FALSE;
321 $this->dialog= FALSE;
322 }
324 /* Add user workstation? */
325 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
326 $tmp= $this->sambaUserWorkstations;
327 foreach($_POST['wslist'] as $ws){
328 $tmp.= ",$ws";
329 }
330 $tmp= preg_replace('/,+/', ',', $tmp);
331 $this->sambaUserWorkstations= trim($tmp, ',');
332 $this->is_modified= TRUE;
333 }
335 /* Show ws dialog */
336 if ($this->show_ws_dialog){
338 /* Save data */
339 $sambafilter= get_global("sambafilter");
340 foreach( array("depselect", "regex") as $type){
341 if (isset($_POST[$type])){
342 $sambafilter[$type]= $_POST[$type];
343 }
344 }
345 if (isset($_GET['search'])){
346 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
347 if ($s == "**"){
348 $s= "*";
349 }
350 $sambafilter['regex']= $s;
351 }
352 register_global("sambafilter", $sambafilter);
354 /* Get workstation list */
355 $exclude= "";
356 foreach(split(',', $this->sambaUserWorkstations) as $ws){
357 $exclude.= "(cn=$ws$)";
358 }
359 if ($exclude != ""){
360 $exclude= "(!(|$exclude))";
361 }
362 $regex= $sambafilter['regex'];
363 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
364 $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
366 $wslist= array();
367 foreach ($res as $attrs){
368 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
369 }
370 asort($wslist);
372 $smarty->assign("search_image", get_template_path('images/search.png'));
373 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
374 $smarty->assign("tree_image", get_template_path('images/tree.png'));
375 $smarty->assign("deplist", $this->config->idepartments);
376 $smarty->assign("alphabet", generate_alphabet());
377 foreach( array("depselect", "regex") as $type){
378 $smarty->assign("$type", $sambafilter[$type]);
379 }
380 $smarty->assign("hint", print_sizelimit_warning());
381 $smarty->assign("wslist", $wslist);
382 $smarty->assign("apply", apply_filter());
383 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
384 dirname(__FILE__)));
385 return ($display);
386 }
388 /* Fill calendar */
389 $days= array();
390 for($d= 1; $d<32; $d++){
391 $days[]= $d;
392 }
393 $years= array();
394 for($y= $date['year']-4; $y<$date['year']+4; $y++){
395 $years[]= $y;
396 }
397 $months= array(_("January"), _("February"), _("March"), _("April"),
398 _("May"), _("June"), _("July"), _("August"), _("September"),
399 _("October"), _("November"), _("December"));
400 $smarty->assign("day", $date["mday"]);
401 $smarty->assign("days", $days);
402 $smarty->assign("months", $months);
403 $smarty->assign("month", $date["mon"]-1);
404 $smarty->assign("years", $years);
405 $smarty->assign("year", $date["year"]);
407 $sambaLogonTime_days= array();
408 for($d= 1; $d<32; $d++){
409 $sambaLogonTime_days[]= $d;
410 }
411 $sambaLogonTime_years= array();
412 for($y= $date['year']-4; $y<$date['year']+4; $y++){
413 $sambaLogonTime_years[]= $y;
414 }
415 $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
416 _("May"), _("June"), _("July"), _("August"), _("September"),
417 _("October"), _("November"), _("December"));
418 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
419 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
420 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
421 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
422 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
423 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
425 $sambaLogoffTime_days= array();
426 for($d= 1; $d<32; $d++){
427 $sambaLogoffTime_days[]= $d;
428 }
429 $sambaLogoffTime_years= array();
430 for($y= $date['year']-4; $y<$date['year']+4; $y++){
431 $sambaLogoffTime_years[]= $y;
432 }
433 $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
434 _("May"), _("June"), _("July"), _("August"), _("September"),
435 _("October"), _("November"), _("December"));
436 $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
437 $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
438 $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
439 $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
440 $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
441 $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
443 $sambaKickoffTime_days= array();
444 for($d= 1; $d<32; $d++){
445 $sambaKickoffTime_days[]= $d;
446 }
447 $sambaKickoffTime_years= array();
448 for($y= $date['year']-4; $y<$date['year']+4; $y++){
449 $sambaKickoffTime_years[]= $y;
450 }
451 $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
452 _("May"), _("June"), _("July"), _("August"), _("September"),
453 _("October"), _("November"), _("December"));
454 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
455 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
456 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
457 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
458 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
459 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
460 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
462 /* Fill boxes */
463 if ($this->samba3){
464 $domains= array();
465 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
466 $domains[]= $name;
467 }
468 $smarty->assign("domains", $domains);
469 }
470 $letters= array();
471 for ($i= 68; $i<91; $i++){
472 $letters[]= chr($i).":";
473 }
474 $smarty->assign("drives", $letters);
476 /* Fill terminal server settings */
477 if ($this->samba3){
478 foreach ($this->ctxattributes as $attr){
479 /* Fill common attributes */
480 if (isset($this->mungedObject->ctx[$attr])){
481 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
482 // Set field to blank if value is 0
483 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
484 if($this->mungedObject->ctx[$attr] == 0) {
485 $smarty->assign("$attr", "");
486 }
487 }
488 } else {
489 $smarty->assign("$attr", "");
490 }
491 }
493 /* Assign enum values for preset items */
494 $shadowModeVals= array( "0" => _("disabled"),
495 "1" => _("input on, notify on"),
496 "2" => _("input on, notify off"),
497 "3" => _("input off, notify on"),
498 "4" => _("input off, nofify off"));
500 $brokenConnModeVals= array( "0" => _("disconnect"),
501 "1" => _("reset"));
503 $reConnModeVals= array( "0" => _("from any client"),
504 "1" => _("from previous client only"));
506 /* Fill preset items */
507 $smarty->assign("shadow", $shadowModeVals);
508 $smarty->assign("brokenconn", $brokenConnModeVals);
509 $smarty->assign("reconn", $reConnModeVals);
511 /* Fill preset items with values */
512 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
513 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
514 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
516 if($_SESSION['js']){
517 /* Set form elements to disabled/enable state */
518 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
520 $smarty->assign("inheritstate", "");
521 if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
522 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
523 }
527 }else{
528 $smarty->assign("tsloginstate", "");
529 $smarty->assign("inheritstate", "");
530 }
532 /* Set checkboxes to checked or unchecked state */
533 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
534 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
535 $smarty->assign("connectclientdrives",
536 $this->mungedObject->getConnectClientDrives()?"checked":"");
537 $smarty->assign("connectclientprinters",
538 $this->mungedObject->getConnectClientPrinters()?"checked":"");
539 $smarty->assign("defaultprinter",
540 $this->mungedObject->getDefaultPrinter()?"checked":"");
541 $smarty->assign("CtxMaxConnectionTimeF",
542 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
543 $smarty->assign("CtxMaxDisconnectionTimeF",
544 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
545 $smarty->assign("CtxMaxIdleTimeF",
546 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
548 /* Fill sambaUserWorkstations */
549 $ws= split(",", $this->sambaUserWorkstations);
550 sort($ws);
552 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
553 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
556 $smarty->assign("workstations", $ws);
557 }
559 /* Variables */
560 foreach($this->attributes as $val){
561 $smarty->assign("$val", $this->$val);
562 }
564 /* 'sambaAcctFlags' checkboxes */
565 /* Check for 'lock-account'-flag: 'D' or 'L' */
566 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
567 is_integer(strpos($this->sambaAcctFlags, "L"))) {
568 $smarty->assign("flagsD", "checked");
569 } else {
570 $smarty->assign("flagsD", "");
571 }
573 /* Check for no_password_required flag 'N' */
574 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
575 $smarty->assign("flagsN", "checked");
576 } else {
577 $smarty->assign("flagsN", "");
578 }
580 if($this->samba3){
581 if ($this->sambaPwdCanChange=="1"){
582 $smarty->assign("flagsP", "checked");
583 } else {
584 $smarty->assign("flagsP", "");
585 }
586 }else{
587 if ($this->pwdCanChange=="1"){
588 $smarty->assign("flagsP", "checked");
589 } else {
590 $smarty->assign("flagsP", "");
591 }
592 }
594 if ($this->password_expires=="1"){
595 $smarty->assign("flagsC", "checked");
596 } else {
597 $smarty->assign("flagsC", "");
598 }
599 if ($this->logon_time_set=="1"){
600 $smarty->assign("flagsT", "checked");
601 } else {
602 $smarty->assign("flagsT", "");
603 }
604 if ($this->logoff_time_set=="1"){
605 $smarty->assign("flagsO", "checked");
606 } else {
607 $smarty->assign("flagsO", "");
608 }
609 if ($this->kickoff_time_set=="1"){
610 $smarty->assign("flagsK", "checked");
611 } else {
612 $smarty->assign("flagsK", "");
613 }
616 /* In case of javascript, disable some fields on demand */
617 if ($this->samba3){
618 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
619 $smarty->assign("$key", "$value");
620 }
621 }
623 /* Show main page */
624 if ($this->samba3){
625 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
626 } else {
627 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
628 }
630 return ($display);
631 }
633 function remove_from_parent()
634 {
635 /* Cancel if there's nothing to do here */
636 if (!$this->initially_was_account){
637 return;
638 }
640 /* include global link_info */
641 $ldap= $this->config->get_ldap_link();
643 plugin::remove_from_parent();
645 /* Keep uid attribute for gosaAccount */
646 unset($this->attrs['uid']);
647 unset($this->attrs['uidNumber']);
648 unset($this->attrs['gidNumber']);
649 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
650 $this->attributes, "Save");
651 $ldap->cd($this->dn);
652 $this->cleanup();
653 $ldap->modify ($this->attrs);
655 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
657 /* Optionally execute a command after we're done */
658 $this->handle_post_events("remove", array("uid" => $this->uid));
659 }
662 /* Check for input problems */
663 function check()
664 {
665 /* Call common method to give check the hook */
666 $message= plugin::check();
668 if ($this->samba3){
670 /* Strings */
671 foreach (array( "sambaHomePath" => _("Home directory"),
672 "sambaProfilePath" => _("Profile path")) as $key => $val){
673 if (!$this->mungedObject->is_samba_path($this->$key)){
674 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
675 }
676 }
678 /* Numeric values */
679 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
680 "CtxMaxDisconnectionTime" => _("Disconnection"),
681 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
683 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
684 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
685 }
686 }
688 /* Too many workstations? Windows usrmgr only supports eight */
689 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
690 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
691 }
692 }
694 return ($message);
695 }
698 /* Save data to object */
699 function save_object()
700 {
702 $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
704 /* We only care if we are on the sambaTab... */
705 if (isset($_POST['sambaTab'])){
706 plugin::save_object();
708 /* Take care about access options */
709 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
710 if ($this->samba3){
711 $attrname= "sambaPwdCanChange";
712 } else {
713 $attrname= "pwdCanChange";
714 }
715 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
716 $tmp= 1;
717 } else {
718 $tmp= 0;
719 }
720 if ($this->$attrname != $tmp){
721 $this->is_modified= TRUE;
722 }
723 $this->pwdCanChange= $tmp;
724 $this->sambaPwdCanChange= $tmp;
725 }
726 $tmp= "UX";
727 if (isset($_POST["no_password_required"])){
728 if ($_POST["no_password_required"] == 1){
729 $tmp.= "N";
730 }
731 }
732 if (isset($_POST["password_expires"])){
733 if ($_POST["password_expires"] == 1){
734 $this->password_expires= 1;
735 }
736 } else {
737 $this->password_expires= 0;
738 }
739 if (isset($_POST["temporary_disable"])){
740 if ($_POST["temporary_disable"] == 1){
741 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
742 $tmp.= "L";
743 } else {
744 $tmp.= "D";
745 }
746 }
747 }
748 if (isset($_POST["logon_time_set"])){
749 if ($_POST["logon_time_set"] == 1){
750 $this->logon_time_set= 1;
751 }
752 } else {
753 $this->logon_time_set= 0;
754 }
755 if (isset($_POST["logoff_time_set"])){
756 if ($_POST["logoff_time_set"] == 1){
757 $this->logoff_time_set= 1;
758 }
759 } else {
760 $this->logoff_time_set= 0;
761 }
762 if (isset($_POST["kickoff_time_set"])){
763 if ($_POST["kickoff_time_set"] == 1){
764 $this->kickoff_time_set= 1;
765 }
766 } else {
767 $this->kickoff_time_set= 0;
768 }
770 $fill= "";
771 for ($i= strlen($tmp); $i<12; $i++){
772 $fill.= " ";
773 }
775 $tmp= "[$tmp$fill]";
777 /* Only save if acl's are set */
778 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
779 if ($this->samba3){
780 $attrname= "sambaAcctFlags";
781 } else {
782 $attrname= "acctFlags";
783 }
784 if ($this->$attrname != $tmp){
785 $this->is_modified= TRUE;
786 }
787 $this->$attrname= $tmp;
788 }
790 /* Save sambaDomain attribute */
791 if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
792 $this->sambaDomainName= validate($_POST['sambaDomainName']);
793 }
795 /* Save CTX values */
796 if ($this->samba3){
798 /* Save obvious values */
799 foreach($this->ctxattributes as $val){
800 if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
801 if (get_magic_quotes_gpc()) {
802 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
803 } else {
804 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
805 }
806 }
807 }
809 /* Save checkbox states. */
810 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
811 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
812 // Need to do some index checking to avoid messages like "index ... not found"
813 if(isset($_POST['brokenconn'])) {
814 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
815 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
816 }
817 if(isset($_POST['reconn'])) {
818 $this->mungedObject->setReConn($_POST['reconn'] == '1'
819 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
820 }
821 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
822 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
823 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
824 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
825 $this->mungedObject->setCtxMaxDisconnectionTimeF(
826 !isset($_POST['CtxMaxDisconnectionTimeF'])
827 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
828 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
829 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
830 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
831 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
832 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
833 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
834 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
835 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
837 /* Save combo boxes. Takes two values */
838 if(isset($_POST['reconn'])) {
839 $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
840 }
842 /* Check for changes */
843 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
844 $this->is_modified= TRUE;
845 }
846 }
847 }
848 }
851 /* Save to LDAP */
852 function save()
853 {
854 /* Load uid and gid of this 'dn' */
855 $ldap= $this->config->get_ldap_link();
856 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
857 $tmp= $ldap->fetch();
858 $this->uidNumber= $tmp['uidNumber'][0];
859 $this->gidNumber= $tmp['gidNumber'][0];
861 plugin::save();
863 /* Remove objectClass for sambaIdmapEntry */
864 $tmp= array();
865 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
866 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
867 $tmp[]= $this->attrs['objectClass'][$i];
868 }
869 }
870 $this->attrs['objectClass']= $tmp;
872 /* Generate rid / primaryGroupId */
873 if ($this->samba3){
874 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
875 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
876 } else {
877 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
878 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
879 }
881 /* Need to generate a new uniqe uid/gid combination? */
882 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
883 $uidNumber= $this->uidNumber;
884 while(TRUE){
885 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
886 $ldap->cd($this->config->current['BASE']);
887 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
888 if ($ldap->count() == 0){
889 break;
890 }
891 $uidNumber++;
892 }
893 $this->attrs['sambaSID']= $sid;
895 /* Check for users primary group */
896 $ldap->cd($this->config->current['BASE']);
897 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
898 if ($ldap->count() != 1){
899 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
900 } else {
901 $attrs= $ldap->fetch();
902 $g= new group($this->config, $ldap->getDN());
903 if ($g->sambaSID == ""){
904 $g->sambaDomainName= $this->sambaDomainName;
905 $g->smbgroup= TRUE;
906 $g->save ();
907 }
908 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
909 }
910 }
912 if ($this->sambaHomeDrive == ""){
913 $this->attrs["sambaHomeDrive"]= array();
914 }
916 /* Generate munged dial value */
917 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
919 /* User wants me to fake the idMappings? This is useful for
920 making winbind resolve the user names in a reasonable amount
921 of time in combination with larger databases. */
922 if (isset($this->config->current['SAMBAIDMAPPING']) &&
923 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
924 $this->attrs['objectClass'][]= "sambaIdmapEntry";
925 }
928 /* Password expiery */
929 if ($this->password_expires == "1"){
930 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
931 } else {
932 $this->attrs['sambaPwdMustChange']= array();
933 }
934 /* Make sure not to save zero in sambaPwdLastset */
935 if ($this->sambaPwdLastSet != "0"){
936 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
937 } else {
938 $this->attrs['sambaPwdLastSet']= array();
939 }
940 /* Account expiery */
941 if ($this->logon_time_set == "1"){
942 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
943 } else {
944 $this->attrs['sambaLogonTime']= array();
945 }
946 if ($this->logoff_time_set == "1"){
947 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
948 } else {
949 $this->attrs['sambaLogoffTime']= array();
950 }
951 if ($this->kickoff_time_set == "1"){
952 # Add one day in unixtime format to be compatible with usrmgr
953 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
954 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
955 } else {
956 $this->attrs['sambaKickoffTime']= array();
957 }
958 } else {
959 /* Not samba3 */
960 $this->attrs['rid']= $this->uidNumber*2 + 1000;
961 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
963 if ($this->homeDrive == ""){
964 $this->attrs["homeDrive"]= array();
965 }
967 /* Password expiery */
968 if ($this->password_expires == "1"){
969 $this->attrs['pwdMustChange']= $this->pwdMustChange;
970 } else {
971 $this->attrs['pwdMustChange']= 2147483647;
972 }
973 /* Make sure not to save zero in pwdLastset */
974 if ($this->pwdLastSet != "0"){
975 $this->attrs['pwdLastSet']= $this->pwdLastSet;
976 } else {
977 $this->attrs['pwdLastSet']= array();
978 }
979 /* Account expiery */
980 if ($this->logon_time_set == "1"){
981 $this->attrs['logonTime']= $this->logonTime;
982 } else {
983 $this->attrs['logonTime']= array();
984 }
985 if ($this->logoff_time_set == "1"){
986 $this->attrs['logoffTime']= $this->logoffTime;
987 } else {
988 $this->attrs['logoffTime']= array();
989 }
990 if ($this->kickoff_time_set == "1"){
991 # Add one day in unixtime format to be compatible with usrmgr
992 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
993 } else {
994 $this->attrs['kickoffTime']= array();
995 }
996 }
998 /* Write back to ldap */
999 $ldap->cd($this->dn);
1000 $this->cleanup();
1001 $ldap->modify ($this->attrs);
1003 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
1005 /* Optionally execute a command after we're done */
1006 if ($this->initially_was_account == $this->is_account){
1007 if ($this->is_modified){
1008 $this->handle_post_events("modify", array("uid" => $this->uid));
1009 }
1010 } else {
1011 $this->handle_post_events("add", array("uid" => $this->uid));
1012 }
1014 }
1016 function adapt_from_template($dn)
1017 {
1018 plugin::adapt_from_template($dn);
1019 $this->sambaSID= "";
1020 $this->sambaPrimaryGroupSID= "";
1022 /* Fill mungedDial field */
1023 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1024 $this->mungedObject->load($this->sambaMungedDial);
1025 }
1027 /* Password expiery */
1028 if(isset($this->attrs['sambaPwdMustChange']) &&
1029 $this->attrs['sambaPwdMustChange'][0] != 0){
1030 $this->password_expires= 1;
1031 }
1033 if(isset($this->attrs['sambaLogonTime']) && ! (
1034 $this->attrs['sambaLogonTime'][0] == 0 ||
1035 $this->attrs['sambaLogonTime'][0] == 2147483647
1036 )){
1037 $this->logon_time_set= 1;
1038 }
1039 if(isset($this->attrs['sambaLogoffTime']) && ! (
1040 $this->attrs['sambaLogoffTime'][0] == 0 ||
1041 $this->attrs['sambaLogoffTime'][0] == 2147483647
1042 )){
1043 $this->logoff_time_set= 1;
1044 }
1046 /* Account expiery */
1047 if(isset($this->attrs['sambaKickoffTime']) && ! (
1048 $this->attrs['sambaKickoffTime'][0] == 0 ||
1049 $this->attrs['sambaKickoffTime'][0] == 2147483647
1050 )){
1051 $this->kickoff_time_set= 1;
1052 }
1054 /* Get global filter config */
1055 if (!is_global("sambafilter")){
1056 $ui= get_userinfo();
1057 $base= get_base_from_people($ui->dn);
1058 $sambafilter= array( "depselect" => $base, "regex" => "*");
1059 register_global("sambafilter", $sambafilter);
1060 }
1061 }
1064 function plInfo()
1065 {
1066 return (array(
1067 "plShortName" => _("Samba"),
1068 "plDescription" => _("Samba settings"),
1069 "plSelfModify" => TRUE,
1070 "plDepends" => array("user"),
1071 "plPriority" => 5,
1072 "plSection" => array("personal" => _("My account")),
1073 "plCategory" => array("users"),
1074 "plOptions" => array(),
1076 "plProvidedAcls" => array(
1077 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1078 "InheritClientConfig" => _("Inherit client config"),
1080 "sambaPwdCanChange" => _("Allow user to change password") ,
1081 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1082 "sambaAcctFlagsL" => _("Lock samba account"),
1085 "sambaKickoffTime" => _("Account expires") ,
1086 "sambaPwdMustChange" => _("Password expires") ,
1088 "sambaLogonTime" => _("Limit Logon Time") ,
1089 "sambaLogoffTime" => _("Limit Logoff Time") ,
1090 "sambaLogonHours" => _("Logon hours") ,
1092 "sambaHomePath" => _("Generic home directory") ,
1093 "sambaHomeDrive" => _("Generic samba home drive") ,
1094 "sambaLogonScript" => _("Generic script path") ,
1095 "sambaProfilePath" => _("Generic profile path") ,
1096 "sambaDomainName" => _("Domain") ,
1097 "sambaUserWorkstations" => _("Allow connection from")))
1098 );
1099 }
1100 }
1102 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1103 ?>