1 <?php
2 /*
3 This code is part of GOsa (https://gosa.gonicus.de)
4 Copyright (C) 2004-2005 Cajus Pollmeier
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 class sambaAccount extends plugin
22 {
23 /* Definitions */
24 var $plHeadline= "Samba";
25 var $plDescription= "This does something";
26 var $view_logged = FALSE;
28 /* CLI vars */
29 var $cli_summary= "Manage users samba account";
30 var $cli_description= "Some longer text\nfor help";
31 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
33 /* Switch for Samba version */
34 var $samba3= FALSE;
35 var $uidNumber= 65535;
36 var $gidNumber= 65535;
38 /* Samba 2 attributes */
39 var $pwdLastSet= "0";
40 var $logonTime= "0";
41 var $logoffTime= "2147483647";
42 var $kickoffTime= "2147483647";
43 var $pwdCanChange= "0";
44 var $pwdMustChange= "0";
45 var $password_expires= 0;
46 var $acctFlags= "[UX ]";
47 var $smbHome= "";
48 var $homeDrive= "";
49 var $scriptPath= "";
50 var $profilePath= "";
51 var $rid= "";
52 var $primaryGroupID= "";
54 /* Samba 3 attributes */
55 var $SID= "";
56 var $ridBase= 0;
57 var $sambaSID= "";
58 var $sambaPwdLastSet= "0";
59 var $sambaLogonTime= "0";
60 var $sambaLogoffTime= "2147483647";
61 var $sambaKickoffTime= "2147483647";
62 var $sambaPwdCanChange= "";
63 var $sambaPwdMustChange= "0";
64 var $sambaAcctFlags= "[UX ]";
65 var $sambaHomePath= "";
66 var $sambaHomeDrive= "";
67 var $sambaLogonScript= "";
68 var $sambaProfilePath= "";
69 var $sambaPrimaryGroupSID= "";
70 var $sambaDomainName= "";
71 var $sambaUserWorkstations= "";
72 var $sambaBadPasswordCount= "";
73 var $sambaBadPasswordTime= "";
74 var $sambaPasswordHistory= "";
75 var $sambaLogonHours= "";
76 var $orig_sambaDomainName= "";
77 var $sambaMungedDial= "";
78 var $mungedObject;
80 /* Helper */
81 var $show_ws_dialog= FALSE;
82 var $logon_time_set= 0;
83 var $logoff_time_set= 0;
84 var $kickoff_time_set= 0;
86 /* attribute list for save action */
87 var $ctxattributes= array();
88 var $attributes= array();
89 var $objectclasses= array();
91 var $uid= "";
92 var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
94 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 /* Log view */
199 if($this->is_account && !$this->view_logged){
200 $this->view_logged = TRUE;
201 new log("view","users/".get_class($this),$this->dn);
202 }
204 /* Do we need to flip is_account state? */
205 if (isset($_POST['modify_state'])){
206 $this->is_account= !$this->is_account;
207 }
208 /* Do we represent a valid account? */
209 if (!$this->is_account && $this->parent === NULL){
210 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
211 _("This account has no samba extensions.")."</b>";
212 $display.= back_to_main();
213 return ($display);
214 }
216 /* Show tab dialog headers */
217 $display= "";
218 if ($this->parent !== NULL){
219 if ($this->is_account){
220 $display= $this->show_disable_header(_("Remove samba account"),
221 _("This account has samba features enabled. You can disable them by clicking below."));
222 } else {
223 $obj= $this->parent->by_object['posixAccount'];
225 /* Samba3 dependency on posix accounts are enabled
226 in the moment, because I need to rely on unique
227 uidNumbers. There'll be a better solution later
228 on. */
229 if ($obj->is_account){
231 $display= $this->show_enable_header(_("Create samba account"),
232 _("This account has samba features disabled. You can enable them by clicking below."));
233 } else {
234 $display= $this->show_enable_header(_("Create samba account"),
235 _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
236 }
237 return ($display);
238 }
239 }
241 $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
243 /* Open Samaba Logong hours dialog */
244 if(isset($_POST['SetSambaLogonHours']) && $this->samba3 && $this->acl_is_writeable("sambaLogonHours")){
245 $this->dialog = new sambaLogonHours($this->config,$this->dn,$this->sambaLogonHours);
246 }
248 /* Cancel dialog */
249 if(isset($_POST['cancel_logonHours'])){
250 $this->dialog = FALSE;
251 }
253 /* Save selected logon hours */
254 if(isset($_POST['save_logonHours'])){
255 $this->dialog->save_object();
256 if($this->acl_is_writeable("sambaLogonHours")){
257 $this->sambaLogonHours = $this->dialog->save();
258 }
259 $this->dialog = FALSE;
260 }
262 /* Display dialog */
263 if((isset($this->dialog)) && (is_object($this->dialog))){
264 $this->dialog->save_object();
265 return($this->dialog->execute());
266 }
269 /* Prepare templating */
270 $smarty= get_smarty();
272 $tmp = $this->plInfo();
273 foreach($tmp['plProvidedAcls'] as $var => $rest){
274 $smarty->assign($var."ACL",$this->getacl($var,$SkipWrite));
275 }
277 if ($this->sambaPwdMustChange=="0"){
278 $date= getdate();
279 } else {
280 $date= getdate($this->sambaPwdMustChange);
281 }
283 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
284 $sambaLogonTime_date= getdate();
285 } else {
286 $sambaLogonTime_date= getdate($this->sambaLogonTime);
287 }
289 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
290 $sambaLogoffTime_date= getdate();
291 } else {
292 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
293 }
295 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
296 $sambaKickoffTime_date= getdate();
297 } else {
298 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
299 }
301 /* Remove user workstations? */
302 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
304 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
306 $tmp= $this->sambaUserWorkstations;
307 foreach($_POST['workstation_list'] as $name){
308 $tmp= preg_replace("/$name/", '', $tmp);
309 $this->is_modified= TRUE;
310 }
311 $tmp= preg_replace('/,+/', ',', $tmp);
312 $this->sambaUserWorkstations= trim($tmp, ',');
313 }
314 }
316 /* Add user workstation? */
317 if (isset($_POST["add_ws"])){
318 if($this->acl_is_writeable("sambaUserWorkstations",$SkipWrite)){
319 $this->show_ws_dialog= TRUE;
320 $this->dialog= TRUE;
321 }
322 }
324 /* Add user workstation finished? */
325 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
326 $this->show_ws_dialog= FALSE;
327 $this->dialog= FALSE;
328 }
330 /* Add user workstation? */
331 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
332 $tmp= $this->sambaUserWorkstations;
333 foreach($_POST['wslist'] as $ws){
334 $tmp.= ",$ws";
335 }
336 $tmp= preg_replace('/,+/', ',', $tmp);
337 $this->sambaUserWorkstations= trim($tmp, ',');
338 $this->is_modified= TRUE;
339 }
341 /* Show ws dialog */
342 if ($this->show_ws_dialog){
344 /* Save data */
345 $sambafilter= get_global("sambafilter");
346 foreach( array("depselect", "regex") as $type){
347 if (isset($_POST[$type])){
348 $sambafilter[$type]= $_POST[$type];
349 }
350 }
351 if (isset($_GET['search'])){
352 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
353 if ($s == "**"){
354 $s= "*";
355 }
356 $sambafilter['regex']= $s;
357 }
358 register_global("sambafilter", $sambafilter);
360 /* Get workstation list */
361 $exclude= "";
362 foreach(split(',', $this->sambaUserWorkstations) as $ws){
363 $exclude.= "(cn=$ws$)";
364 }
365 if ($exclude != ""){
366 $exclude= "(!(|$exclude))";
367 }
368 $regex= $sambafilter['regex'];
369 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
370 $res= get_list($filter, "winworkstation", $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
372 $wslist= array();
373 foreach ($res as $attrs){
374 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
375 }
376 asort($wslist);
378 $smarty->assign("search_image", get_template_path('images/search.png'));
379 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
380 $smarty->assign("tree_image", get_template_path('images/tree.png'));
381 $smarty->assign("deplist", $this->config->idepartments);
382 $smarty->assign("alphabet", generate_alphabet());
383 foreach( array("depselect", "regex") as $type){
384 $smarty->assign("$type", $sambafilter[$type]);
385 }
386 $smarty->assign("hint", print_sizelimit_warning());
387 $smarty->assign("wslist", $wslist);
388 $smarty->assign("apply", apply_filter());
389 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
390 dirname(__FILE__)));
391 return ($display);
392 }
394 /* Fill calendar */
395 $days= array();
396 for($d= 1; $d<32; $d++){
397 $days[]= $d;
398 }
399 $years= array();
400 for($y= $date['year']-4; $y<$date['year']+4; $y++){
401 $years[]= $y;
402 }
403 $months= array(_("January"), _("February"), _("March"), _("April"),
404 _("May"), _("June"), _("July"), _("August"), _("September"),
405 _("October"), _("November"), _("December"));
406 $smarty->assign("day", $date["mday"]);
407 $smarty->assign("days", $days);
408 $smarty->assign("months", $months);
409 $smarty->assign("month", $date["mon"]-1);
410 $smarty->assign("years", $years);
411 $smarty->assign("year", $date["year"]);
413 $sambaLogonTime_days= array();
414 for($d= 1; $d<32; $d++){
415 $sambaLogonTime_days[]= $d;
416 }
417 $sambaLogonTime_years= array();
418 for($y= $date['year']-4; $y<$date['year']+4; $y++){
419 $sambaLogonTime_years[]= $y;
420 }
421 $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
422 _("May"), _("June"), _("July"), _("August"), _("September"),
423 _("October"), _("November"), _("December"));
424 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
425 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
426 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
427 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
428 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
429 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
431 $sambaLogoffTime_days= array();
432 for($d= 1; $d<32; $d++){
433 $sambaLogoffTime_days[]= $d;
434 }
435 $sambaLogoffTime_years= array();
436 for($y= $date['year']-4; $y<$date['year']+4; $y++){
437 $sambaLogoffTime_years[]= $y;
438 }
439 $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
440 _("May"), _("June"), _("July"), _("August"), _("September"),
441 _("October"), _("November"), _("December"));
442 $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
443 $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
444 $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
445 $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
446 $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
447 $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
449 $sambaKickoffTime_days= array();
450 for($d= 1; $d<32; $d++){
451 $sambaKickoffTime_days[]= $d;
452 }
453 $sambaKickoffTime_years= array();
454 for($y= $date['year']-4; $y<$date['year']+4; $y++){
455 $sambaKickoffTime_years[]= $y;
456 }
457 $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
458 _("May"), _("June"), _("July"), _("August"), _("September"),
459 _("October"), _("November"), _("December"));
460 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
461 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
462 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
463 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
464 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
465 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
466 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
468 /* Fill boxes */
469 if ($this->samba3){
470 $domains= array();
471 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
472 $domains[]= $name;
473 }
474 $smarty->assign("domains", $domains);
475 }
476 $letters= array();
477 for ($i= 68; $i<91; $i++){
478 $letters[]= chr($i).":";
479 }
480 $smarty->assign("drives", $letters);
482 /* Fill terminal server settings */
483 if ($this->samba3){
484 foreach ($this->ctxattributes as $attr){
485 /* Fill common attributes */
486 if (isset($this->mungedObject->ctx[$attr])){
487 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
488 // Set field to blank if value is 0
489 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
490 if($this->mungedObject->ctx[$attr] == 0) {
491 $smarty->assign("$attr", "");
492 }
493 }
494 } else {
495 $smarty->assign("$attr", "");
496 }
497 }
499 /* Assign enum values for preset items */
500 $shadowModeVals= array( "0" => _("disabled"),
501 "1" => _("input on, notify on"),
502 "2" => _("input on, notify off"),
503 "3" => _("input off, notify on"),
504 "4" => _("input off, nofify off"));
506 $brokenConnModeVals= array( "0" => _("disconnect"),
507 "1" => _("reset"));
509 $reConnModeVals= array( "0" => _("from any client"),
510 "1" => _("from previous client only"));
512 /* Fill preset items */
513 $smarty->assign("shadow", $shadowModeVals);
514 $smarty->assign("brokenconn", $brokenConnModeVals);
515 $smarty->assign("reconn", $reConnModeVals);
517 /* Fill preset items with values */
518 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
519 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
520 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
522 if($_SESSION['js']){
523 /* Set form elements to disabled/enable state */
524 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
526 $smarty->assign("inheritstate", "");
527 if($this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
528 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
529 }
533 }else{
534 $smarty->assign("tsloginstate", "");
535 $smarty->assign("inheritstate", "");
536 }
538 /* Set checkboxes to checked or unchecked state */
539 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
540 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
541 $smarty->assign("connectclientdrives",
542 $this->mungedObject->getConnectClientDrives()?"checked":"");
543 $smarty->assign("connectclientprinters",
544 $this->mungedObject->getConnectClientPrinters()?"checked":"");
545 $smarty->assign("defaultprinter",
546 $this->mungedObject->getDefaultPrinter()?"checked":"");
547 $smarty->assign("CtxMaxConnectionTimeF",
548 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
549 $smarty->assign("CtxMaxDisconnectionTimeF",
550 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
551 $smarty->assign("CtxMaxIdleTimeF",
552 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
554 /* Fill sambaUserWorkstations */
555 $ws= split(",", $this->sambaUserWorkstations);
556 sort($ws);
558 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
559 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
562 $smarty->assign("workstations", $ws);
563 }
565 /* Variables */
566 foreach($this->attributes as $val){
567 $smarty->assign("$val", $this->$val);
568 }
570 /* 'sambaAcctFlags' checkboxes */
571 /* Check for 'lock-account'-flag: 'D' or 'L' */
572 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
573 is_integer(strpos($this->sambaAcctFlags, "L"))) {
574 $smarty->assign("flagsD", "checked");
575 } else {
576 $smarty->assign("flagsD", "");
577 }
579 /* Check for no_password_required flag 'N' */
580 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
581 $smarty->assign("flagsN", "checked");
582 } else {
583 $smarty->assign("flagsN", "");
584 }
586 if($this->samba3){
587 if ($this->sambaPwdCanChange=="1"){
588 $smarty->assign("flagsP", "checked");
589 } else {
590 $smarty->assign("flagsP", "");
591 }
592 }else{
593 if ($this->pwdCanChange=="1"){
594 $smarty->assign("flagsP", "checked");
595 } else {
596 $smarty->assign("flagsP", "");
597 }
598 }
600 if ($this->password_expires=="1"){
601 $smarty->assign("flagsC", "checked");
602 } else {
603 $smarty->assign("flagsC", "");
604 }
605 if ($this->logon_time_set=="1"){
606 $smarty->assign("flagsT", "checked");
607 } else {
608 $smarty->assign("flagsT", "");
609 }
610 if ($this->logoff_time_set=="1"){
611 $smarty->assign("flagsO", "checked");
612 } else {
613 $smarty->assign("flagsO", "");
614 }
615 if ($this->kickoff_time_set=="1"){
616 $smarty->assign("flagsK", "checked");
617 } else {
618 $smarty->assign("flagsK", "");
619 }
622 /* In case of javascript, disable some fields on demand */
623 if ($this->samba3){
624 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
625 $smarty->assign("$key", "$value");
626 }
627 }
629 /* Show main page */
630 if ($this->samba3){
631 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
632 } else {
633 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
634 }
636 return ($display);
637 }
639 function remove_from_parent()
640 {
641 /* Cancel if there's nothing to do here */
642 if (!$this->initially_was_account){
643 return;
644 }
646 /* include global link_info */
647 $ldap= $this->config->get_ldap_link();
649 plugin::remove_from_parent();
651 /* Keep uid attribute for gosaAccount */
652 unset($this->attrs['uid']);
653 unset($this->attrs['uidNumber']);
654 unset($this->attrs['gidNumber']);
656 /* Remove objectClass for sambaIdmapEntry */
657 $tmp= array();
658 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
659 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
660 $tmp[]= $this->attrs['objectClass'][$i];
661 }
662 }
663 $this->attrs['objectClass']= $tmp;
665 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
666 $this->attributes, "Save");
667 $ldap->cd($this->dn);
668 $this->cleanup();
669 $ldap->modify ($this->attrs);
671 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
673 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
675 /* Optionally execute a command after we're done */
676 $this->handle_post_events("remove", array("uid" => $this->uid));
677 }
680 /* Check for input problems */
681 function check()
682 {
683 /* Call common method to give check the hook */
684 $message= plugin::check();
686 if ($this->samba3){
688 /* Strings */
689 foreach (array( "sambaHomePath" => _("Home directory"),
690 "sambaProfilePath" => _("Profile path")) as $key => $val){
691 if (!$this->mungedObject->is_samba_path($this->$key)){
692 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
693 }
694 }
696 /* Numeric values */
697 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
698 "CtxMaxDisconnectionTime" => _("Disconnection"),
699 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
701 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
702 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
703 }
704 }
706 /* Too many workstations? Windows usrmgr only supports eight */
707 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
708 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
709 }
710 }
712 return ($message);
713 }
716 /* Save data to object */
717 function save_object()
718 {
720 $SkipWrite = (!isset($this->parent) || !$this->parent) && !isset($_SESSION['edit']);
722 /* We only care if we are on the sambaTab... */
723 if (isset($_POST['sambaTab'])){
724 plugin::save_object();
726 /* Take care about access options */
727 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
728 if ($this->samba3){
729 $attrname= "sambaPwdCanChange";
730 } else {
731 $attrname= "pwdCanChange";
732 }
733 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
734 $tmp= 1;
735 } else {
736 $tmp= 0;
737 }
738 if ($this->$attrname != $tmp){
739 $this->is_modified= TRUE;
740 }
741 $this->pwdCanChange= $tmp;
742 $this->sambaPwdCanChange= $tmp;
743 }
744 $tmp= "UX";
745 if (isset($_POST["no_password_required"])){
746 if ($_POST["no_password_required"] == 1){
747 $tmp.= "N";
748 }
749 }
750 if (isset($_POST["password_expires"])){
751 if ($_POST["password_expires"] == 1){
752 $this->password_expires= 1;
753 }
754 } else {
755 $this->password_expires= 0;
756 }
757 if (isset($_POST["temporary_disable"])){
758 if ($_POST["temporary_disable"] == 1){
759 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
760 $tmp.= "L";
761 } else {
762 $tmp.= "D";
763 }
764 }
765 }
766 if (isset($_POST["logon_time_set"])){
767 if ($_POST["logon_time_set"] == 1){
768 $this->logon_time_set= 1;
769 }
770 } else {
771 $this->logon_time_set= 0;
772 }
773 if (isset($_POST["logoff_time_set"])){
774 if ($_POST["logoff_time_set"] == 1){
775 $this->logoff_time_set= 1;
776 }
777 } else {
778 $this->logoff_time_set= 0;
779 }
780 if (isset($_POST["kickoff_time_set"])){
781 if ($_POST["kickoff_time_set"] == 1){
782 $this->kickoff_time_set= 1;
783 }
784 } else {
785 $this->kickoff_time_set= 0;
786 }
788 $fill= "";
789 for ($i= strlen($tmp); $i<12; $i++){
790 $fill.= " ";
791 }
793 $tmp= "[$tmp$fill]";
795 /* Only save if acl's are set */
796 if ($this->acl_is_writeable("sambaAcctFlagsL",$SkipWrite) || ($this->acl_is_writeable("sambaAcctFlagsN",$SkipWrite))){
797 if ($this->samba3){
798 $attrname= "sambaAcctFlags";
799 } else {
800 $attrname= "acctFlags";
801 }
802 if ($this->$attrname != $tmp){
803 $this->is_modified= TRUE;
804 }
805 $this->$attrname= $tmp;
806 }
808 /* Save sambaDomain attribute */
809 if ($this->acl_is_writeable("sambaDomainName",$SkipWrite) && $this->samba3 && isset ($_POST['sambaDomainName'],$SkipWrite)){
810 $this->sambaDomainName= validate($_POST['sambaDomainName']);
811 }
813 /* Save CTX values */
814 if ($this->samba3){
816 /* Save obvious values */
817 foreach($this->ctxattributes as $val){
818 if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite)){
819 if (get_magic_quotes_gpc()) {
820 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
821 } else {
822 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
823 }
824 }
825 }
827 /* Save checkbox states. */
828 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
829 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
830 // Need to do some index checking to avoid messages like "index ... not found"
831 if(isset($_POST['brokenconn'])) {
832 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
833 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
834 }
835 if(isset($_POST['reconn'])) {
836 $this->mungedObject->setReConn($_POST['reconn'] == '1'
837 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
838 }
839 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
840 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
841 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
842 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
843 $this->mungedObject->setCtxMaxDisconnectionTimeF(
844 !isset($_POST['CtxMaxDisconnectionTimeF'])
845 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
846 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
847 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
848 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
849 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
850 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
851 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
852 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
853 && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite));
855 /* Save combo boxes. Takes two values */
856 if(isset($_POST['reconn'])) {
857 $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer",$SkipWrite),$_POST['shadow']);
858 }
860 /* Check for changes */
861 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
862 $this->is_modified= TRUE;
863 }
864 }
865 }
866 }
869 /* Save to LDAP */
870 function save()
871 {
872 /* Load uid and gid of this 'dn' */
873 $ldap= $this->config->get_ldap_link();
874 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
875 $tmp= $ldap->fetch();
876 $this->uidNumber= $tmp['uidNumber'][0];
877 $this->gidNumber= $tmp['gidNumber'][0];
879 plugin::save();
881 /* Remove objectClass for sambaIdmapEntry */
882 $tmp= array();
883 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
884 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
885 $tmp[]= $this->attrs['objectClass'][$i];
886 }
887 }
888 $this->attrs['objectClass']= $tmp;
890 /* Generate rid / primaryGroupId */
891 if ($this->samba3){
892 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
893 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
894 } else {
895 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
896 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
897 }
899 /* Need to generate a new uniqe uid/gid combination? */
900 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
901 $uidNumber= $this->uidNumber;
902 while(TRUE){
903 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
904 $ldap->cd($this->config->current['BASE']);
905 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
906 if ($ldap->count() == 0){
907 break;
908 }
909 $uidNumber++;
910 }
911 $this->attrs['sambaSID']= $sid;
913 /* Check for users primary group */
914 $ldap->cd($this->config->current['BASE']);
915 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
916 if ($ldap->count() != 1){
917 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
918 } else {
919 $attrs= $ldap->fetch();
920 $g= new group($this->config, $ldap->getDN());
921 if ($g->sambaSID == ""){
922 $g->sambaDomainName= $this->sambaDomainName;
923 $g->smbgroup= TRUE;
924 $g->save ();
925 }
926 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
927 }
928 }
930 if ($this->sambaHomeDrive == ""){
931 $this->attrs["sambaHomeDrive"]= array();
932 }
934 /* Generate munged dial value */
935 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
937 /* User wants me to fake the idMappings? This is useful for
938 making winbind resolve the user names in a reasonable amount
939 of time in combination with larger databases. */
940 if (isset($this->config->current['SAMBAIDMAPPING']) &&
941 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
942 $this->attrs['objectClass'][]= "sambaIdmapEntry";
943 }
946 /* Password expiery */
947 if ($this->password_expires == "1"){
948 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
949 } else {
950 $this->attrs['sambaPwdMustChange']= array();
951 }
952 /* Make sure not to save zero in sambaPwdLastset */
953 if ($this->sambaPwdLastSet != "0"){
954 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
955 } else {
956 $this->attrs['sambaPwdLastSet']= array();
957 }
958 /* Account expiery */
959 if ($this->logon_time_set == "1"){
960 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
961 } else {
962 $this->attrs['sambaLogonTime']= array();
963 }
964 if ($this->logoff_time_set == "1"){
965 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
966 } else {
967 $this->attrs['sambaLogoffTime']= array();
968 }
969 if ($this->kickoff_time_set == "1"){
970 # Add one day in unixtime format to be compatible with usrmgr
971 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
972 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
973 } else {
974 $this->attrs['sambaKickoffTime']= array();
975 }
976 } else {
977 /* Not samba3 */
978 $this->attrs['rid']= $this->uidNumber*2 + 1000;
979 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
981 if ($this->homeDrive == ""){
982 $this->attrs["homeDrive"]= array();
983 }
985 /* Password expiery */
986 if ($this->password_expires == "1"){
987 $this->attrs['pwdMustChange']= $this->pwdMustChange;
988 } else {
989 $this->attrs['pwdMustChange']= 2147483647;
990 }
991 /* Make sure not to save zero in pwdLastset */
992 if ($this->pwdLastSet != "0"){
993 $this->attrs['pwdLastSet']= $this->pwdLastSet;
994 } else {
995 $this->attrs['pwdLastSet']= array();
996 }
997 /* Account expiery */
998 if ($this->logon_time_set == "1"){
999 $this->attrs['logonTime']= $this->logonTime;
1000 } else {
1001 $this->attrs['logonTime']= array();
1002 }
1003 if ($this->logoff_time_set == "1"){
1004 $this->attrs['logoffTime']= $this->logoffTime;
1005 } else {
1006 $this->attrs['logoffTime']= array();
1007 }
1008 if ($this->kickoff_time_set == "1"){
1009 # Add one day in unixtime format to be compatible with usrmgr
1010 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
1011 } else {
1012 $this->attrs['kickoffTime']= array();
1013 }
1014 }
1016 /* Write back to ldap */
1017 $ldap->cd($this->dn);
1018 $this->cleanup();
1019 $ldap->modify ($this->attrs);
1021 if($this->initially_was_account){
1022 new log("modify","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1023 }else{
1024 new log("create","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1025 }
1027 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
1029 /* Optionally execute a command after we're done */
1030 if ($this->initially_was_account == $this->is_account){
1031 if ($this->is_modified){
1032 $this->handle_post_events("modify", array("uid" => $this->uid));
1033 }
1034 } else {
1035 $this->handle_post_events("add", array("uid" => $this->uid));
1036 }
1037 }
1040 /* Force password set, if this account doesn't have any samba passwords */
1041 function password_change_needed()
1042 {
1043 if(!$this->initially_was_account && $this->is_account){
1044 $ldap = $this->config->get_ldap_link();
1045 $ldap->cat($this->dn,array("sambaLMPassword","sambaNTPassword"));
1046 $attrs = $ldap->fetch();
1047 if(!isset($attrs['sambaLMPassword']) || !isset($attrs['sambaNTPassword'])){
1048 return(TRUE);
1049 }
1050 }
1051 return(FALSE);
1052 }
1055 function adapt_from_template($dn)
1056 {
1057 plugin::adapt_from_template($dn);
1058 $this->sambaSID= "";
1059 $this->sambaPrimaryGroupSID= "";
1061 /* Fill mungedDial field */
1062 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1063 $this->mungedObject->load($this->sambaMungedDial);
1064 }
1066 /* Password expiery */
1067 if(isset($this->attrs['sambaPwdMustChange']) &&
1068 $this->attrs['sambaPwdMustChange'][0] != 0){
1069 $this->password_expires= 1;
1070 }
1072 if(isset($this->attrs['sambaLogonTime']) && ! (
1073 $this->attrs['sambaLogonTime'][0] == 0 ||
1074 $this->attrs['sambaLogonTime'][0] == 2147483647
1075 )){
1076 $this->logon_time_set= 1;
1077 }
1078 if(isset($this->attrs['sambaLogoffTime']) && ! (
1079 $this->attrs['sambaLogoffTime'][0] == 0 ||
1080 $this->attrs['sambaLogoffTime'][0] == 2147483647
1081 )){
1082 $this->logoff_time_set= 1;
1083 }
1085 /* Account expiery */
1086 if(isset($this->attrs['sambaKickoffTime']) && ! (
1087 $this->attrs['sambaKickoffTime'][0] == 0 ||
1088 $this->attrs['sambaKickoffTime'][0] == 2147483647
1089 )){
1090 $this->kickoff_time_set= 1;
1091 }
1093 /* Get global filter config */
1094 if (!is_global("sambafilter")){
1095 $ui= get_userinfo();
1096 $base= get_base_from_people($ui->dn);
1097 $sambafilter= array( "depselect" => $base, "regex" => "*");
1098 register_global("sambafilter", $sambafilter);
1099 }
1100 }
1103 function plInfo()
1104 {
1105 return (array(
1106 "plShortName" => _("Samba"),
1107 "plDescription" => _("Samba settings"),
1108 "plSelfModify" => TRUE,
1109 "plDepends" => array("user"),
1110 "plPriority" => 5,
1111 "plSection" => array("personal" => _("My account")),
1112 "plCategory" => array("users"),
1113 "plOptions" => array(),
1115 "plProvidedAcls" => array(
1116 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1117 "InheritClientConfig" => _("Inherit client config"),
1119 "sambaPwdCanChange" => _("Allow user to change password") ,
1120 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1121 "sambaAcctFlagsL" => _("Lock samba account"),
1124 "sambaKickoffTime" => _("Account expires") ,
1125 "sambaPwdMustChange" => _("Password expires") ,
1127 "sambaLogonTime" => _("Limit Logon Time") ,
1128 "sambaLogoffTime" => _("Limit Logoff Time") ,
1129 "sambaLogonHours" => _("Logon hours") ,
1131 "sambaHomePath" => _("Generic home directory") ,
1132 "sambaHomeDrive" => _("Generic samba home drive") ,
1133 "sambaLogonScript" => _("Generic script path") ,
1134 "sambaProfilePath" => _("Generic profile path") ,
1135 "sambaDomainName" => _("Domain") ,
1136 "sambaUserWorkstations" => _("Allow connection from")))
1137 );
1138 }
1139 }
1141 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1142 ?>