a03d61c23e85844a6aa97acc6036f9ac7be0c8cb
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 = "";
92 var $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
94 function sambaAccount ($config, $dn= NULL, $parent= 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, $parent);
120 /* set user id */
121 if(isset($this->attrs['uid'])){
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_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_header(_("Create samba account"),
226 _("This account has samba features disabled. You can enable them by clicking below."));
227 } else {
228 $display= $this->show_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 /* Prepare templating */
236 $smarty= get_smarty();
238 /* PHP Fehler "Undefined index: sambaPwdMustChangeACL" */
239 #hickert test
240 $smarty->assign("sambaPwdMustChangeACL", chkacl($this->acl, "sambaPwdMustChangeACL"));
241 #hickert test
242 $smarty->assign("sambaPwdMustChange",$this->sambaPwdMustChange);
244 if ($this->sambaPwdMustChange=="0"){
245 $date= getdate();
246 } else {
247 $date= getdate($this->sambaPwdMustChange);
248 }
250 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
251 $sambaLogonTime_date= getdate();
252 } else {
253 $sambaLogonTime_date= getdate($this->sambaLogonTime);
254 }
256 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
257 $sambaLogoffTime_date= getdate();
258 } else {
259 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
260 }
262 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
263 $sambaKickoffTime_date= getdate();
264 } else {
265 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
266 }
268 /* Remove user workstations? */
269 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
270 $tmp= $this->sambaUserWorkstations;
271 foreach($_POST['workstation_list'] as $name){
272 $tmp= preg_replace("/$name/", '', $tmp);
273 $this->is_modified= TRUE;
274 }
275 $tmp= preg_replace('/,+/', ',', $tmp);
276 $this->sambaUserWorkstations= trim($tmp, ',');
277 }
279 /* Add user workstation? */
280 if (isset($_POST["add_ws"])){
281 $this->show_ws_dialog= TRUE;
282 $this->dialog= TRUE;
283 }
285 /* Add user workstation finished? */
286 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
287 $this->show_ws_dialog= FALSE;
288 $this->dialog= FALSE;
289 }
291 /* Add user workstation? */
292 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
293 $tmp= $this->sambaUserWorkstations;
294 foreach($_POST['wslist'] as $ws){
295 $tmp.= ",$ws";
296 }
297 $tmp= preg_replace('/,+/', ',', $tmp);
298 $this->sambaUserWorkstations= trim($tmp, ',');
299 $this->is_modified= TRUE;
300 }
302 /* Show ws dialog */
303 if ($this->show_ws_dialog){
305 /* Save data */
306 $sambafilter= get_global("sambafilter");
307 foreach( array("depselect", "regex") as $type){
308 if (isset($_POST[$type])){
309 $sambafilter[$type]= $_POST[$type];
310 }
311 }
312 if (isset($_GET['search'])){
313 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
314 if ($s == "**"){
315 $s= "*";
316 }
317 $sambafilter['regex']= $s;
318 }
319 register_global("sambafilter", $sambafilter);
321 /* Get workstation list */
322 $exclude= "";
323 foreach(split(',', $this->sambaUserWorkstations) as $ws){
324 $exclude.= "(cn=$ws$)";
325 }
326 if ($exclude != ""){
327 $exclude= "(!(|$exclude))";
328 }
329 $acl= array($this->config->current['BASE'] => ":all");
330 $regex= $sambafilter['regex'];
331 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
332 $res= get_list($filter, $acl, $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
333 $wslist= array();
334 foreach ($res as $attrs){
335 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
336 }
337 asort($wslist);
339 $smarty->assign("search_image", get_template_path('images/search.png'));
340 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
341 $smarty->assign("tree_image", get_template_path('images/tree.png'));
342 $smarty->assign("deplist", $this->config->idepartments);
343 $smarty->assign("alphabet", generate_alphabet());
344 foreach( array("depselect", "regex") as $type){
345 $smarty->assign("$type", $sambafilter[$type]);
346 }
347 $smarty->assign("hint", print_sizelimit_warning());
348 $smarty->assign("wslist", $wslist);
349 $smarty->assign("apply", apply_filter());
350 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
351 dirname(__FILE__)));
352 return ($display);
353 }
355 /* Fill calendar */
356 $days= array();
357 for($d= 1; $d<32; $d++){
358 $days[]= $d;
359 }
360 $years= array();
361 for($y= $date['year']-4; $y<$date['year']+4; $y++){
362 $years[]= $y;
363 }
364 $months= array(_("January"), _("February"), _("March"), _("April"),
365 _("May"), _("June"), _("July"), _("August"), _("September"),
366 _("October"), _("November"), _("December"));
367 $smarty->assign("day", $date["mday"]);
368 $smarty->assign("days", $days);
369 $smarty->assign("months", $months);
370 $smarty->assign("month", $date["mon"]-1);
371 $smarty->assign("years", $years);
372 $smarty->assign("year", $date["year"]);
374 $sambaLogonTime_days= array();
375 for($d= 1; $d<32; $d++){
376 $sambaLogonTime_days[]= $d;
377 }
378 $sambaLogonTime_years= array();
379 for($y= $date['year']-4; $y<$date['year']+4; $y++){
380 $sambaLogonTime_years[]= $y;
381 }
382 $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
383 _("May"), _("June"), _("July"), _("August"), _("September"),
384 _("October"), _("November"), _("December"));
385 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
386 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
387 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
388 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
389 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
390 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
392 $sambaLogoffTime_days= array();
393 for($d= 1; $d<32; $d++){
394 $sambaLogoffTime_days[]= $d;
395 }
396 $sambaLogoffTime_years= array();
397 for($y= $date['year']-4; $y<$date['year']+4; $y++){
398 $sambaLogoffTime_years[]= $y;
399 }
400 $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
401 _("May"), _("June"), _("July"), _("August"), _("September"),
402 _("October"), _("November"), _("December"));
403 $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
404 $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
405 $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
406 $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
407 $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
408 $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
410 $sambaKickoffTime_days= array();
411 for($d= 1; $d<32; $d++){
412 $sambaKickoffTime_days[]= $d;
413 }
414 $sambaKickoffTime_years= array();
415 for($y= $date['year']-4; $y<$date['year']+4; $y++){
416 $sambaKickoffTime_years[]= $y;
417 }
418 $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
419 _("May"), _("June"), _("July"), _("August"), _("September"),
420 _("October"), _("November"), _("December"));
421 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
422 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
423 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
424 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
425 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
426 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
427 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
429 /* Fill boxes */
430 if ($this->samba3){
431 $domains= array();
432 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
433 $domains[]= $name;
434 }
435 $smarty->assign("domains", $domains);
436 }
437 $letters= array();
438 for ($i= 68; $i<91; $i++){
439 $letters[]= chr($i).":";
440 }
441 $smarty->assign("drives", $letters);
443 /* Fill terminal server settings */
444 if ($this->samba3){
445 foreach ($this->ctxattributes as $attr){
446 /* Fill common attributes */
447 if (isset($this->mungedObject->ctx[$attr])){
448 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
449 // Set field to blank if value is 0
450 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
451 if($this->mungedObject->ctx[$attr] == 0) {
452 $smarty->assign("$attr", "");
453 }
454 }
455 } else {
456 $smarty->assign("$attr", "");
457 }
458 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
459 }
461 /* Assign enum values for preset items */
462 $shadowModeVals= array( "0" => _("disabled"),
463 "1" => _("input on, notify on"),
464 "2" => _("input on, notify off"),
465 "3" => _("input off, notify on"),
466 "4" => _("input off, nofify off"));
468 $brokenConnModeVals= array( "0" => _("disconnect"),
469 "1" => _("reset"));
471 $reConnModeVals= array( "0" => _("from any client"),
472 "1" => _("from previous client only"));
474 /* Fill preset items */
475 $smarty->assign("shadow", $shadowModeVals);
476 $smarty->assign("brokenconn", $brokenConnModeVals);
477 $smarty->assign("reconn", $reConnModeVals);
479 /* Fill preset items with values */
480 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
481 $smarty->assign("shadowACL", chkacl($this->acl,"shadow"));
482 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
483 $smarty->assign("brokenconnACL", chkacl($this->acl,"brokenconn"));
484 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
485 $smarty->assign("reconnACL", chkacl($this->acl,"reconn"));
487 if($_SESSION['js']){
488 /* Set form elements to disabled/enable state */
489 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
490 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
491 }else{
492 $smarty->assign("tsloginstate", "");
493 $smarty->assign("inheritstate", "");
494 }
496 /* Set checkboxes to checked or unchecked state */
497 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
498 $smarty->assign("tsloginACL", chkacl($this->acl,"tslogin"));
500 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
501 $smarty->assign("inheritACL", chkacl($this->acl,"inherit"));
504 $smarty->assign("connectclientdrives",
505 $this->mungedObject->getConnectClientDrives()?"checked":"");
506 $smarty->assign("connectclientdrivesACL", chkacl($this->acl,"connectclientdrives"));
507 $smarty->assign("connectclientprinters",
508 $this->mungedObject->getConnectClientPrinters()?"checked":"");
509 $smarty->assign("connectclientprintersACL", chkacl($this->acl,"connectclientprinters"));
510 $smarty->assign("defaultprinter",
511 $this->mungedObject->getDefaultPrinter()?"checked":"");
512 $smarty->assign("defaultprinterACL", chkacl($this->acl,"defaultprinter"));
513 $smarty->assign("CtxMaxConnectionTimeF",
514 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
515 $smarty->assign("CtxMaxDisconnectionTimeF",
516 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
517 $smarty->assign("CtxMaxIdleTimeF",
518 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
520 /* Fill sambaUserWorkstations */
521 $ws= split(",", $this->sambaUserWorkstations);
522 sort($ws);
524 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
525 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
528 $smarty->assign("workstations", $ws);
529 $smarty->assign("sambaUserWorkstationACL", chkacl($this->acl,"sambaUserWorkstation"));
530 }
532 /* Variables */
533 foreach($this->attributes as $val){
534 $smarty->assign("$val", $this->$val);
535 $smarty->assign("$val"."ACL", chkacl($this->acl,$val));
536 }
539 /* 'sambaAcctFlags' checkboxes */
540 /* Check for 'lock-account'-flag: 'D' or 'L' */
541 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
542 is_integer(strpos($this->sambaAcctFlags, "L"))) {
543 $smarty->assign("flagsD", "checked");
544 } else {
545 $smarty->assign("flagsD", "");
546 }
548 /* Check for no_password_required flag 'N' */
549 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
550 $smarty->assign("flagsN", "checked");
551 } else {
552 $smarty->assign("flagsN", "");
553 }
555 /* 'normal' Checkboxes */
556 if($this->samba3){
557 if ($this->sambaPwdCanChange=="1"){
558 $smarty->assign("flagsP", "checked");
559 } else {
560 $smarty->assign("flagsP", "");
561 }
562 }else{
563 if ($this->pwdCanChange=="1"){
564 $smarty->assign("flagsP", "checked");
565 } else {
566 $smarty->assign("flagsP", "");
567 }
568 }
569 if ($this->password_expires=="1"){
570 $smarty->assign("flagsC", "checked");
571 } else {
572 $smarty->assign("flagsC", "");
573 }
574 if ($this->logon_time_set=="1"){
575 $smarty->assign("flagsT", "checked");
576 } else {
577 $smarty->assign("flagsT", "");
578 }
579 if ($this->logoff_time_set=="1"){
580 $smarty->assign("flagsO", "checked");
581 } else {
582 $smarty->assign("flagsO", "");
583 }
584 if ($this->kickoff_time_set=="1"){
585 $smarty->assign("flagsK", "checked");
586 } else {
587 $smarty->assign("flagsK", "");
588 }
590 $smarty->assign("allow_pwchangeACL", chkacl($this->acl, "allow_pwchange"));
591 $smarty->assign("password_expiresACL", chkacl($this->acl, "password_expires"));
592 $smarty->assign("no_password_requiredACL", chkacl($this->acl, "no_password_required"));
593 $smarty->assign("temporary_disableACL", chkacl($this->acl, "temporary_disable"));
594 $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
595 $smarty->assign("logon_time_setACL", chkacl($this->acl, "logon_time_set"));
596 $smarty->assign("logoff_time_setACL", chkacl($this->acl, "logoff_time_set"));
597 $smarty->assign("kickoff_time_setACL", chkacl($this->acl, "kickoff_time_set"));
598 $smarty->assign("sambaLogonTimeACL", chkacl($this->acl, "sambaLogonTime"));
599 $smarty->assign("sambaLogoffTimeACL", chkacl($this->acl, "sambaLogoffTime"));
600 $smarty->assign("sambaKickoffTimeACL", chkacl($this->acl, "sambaKickoffTime"));
603 /* In case of javascript, disable some fields on demand */
604 if ($this->samba3){
605 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
606 $smarty->assign("$key", "$value");
607 }
608 }
610 /* Show main page */
611 if ($this->samba3){
612 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
613 } else {
614 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
615 }
617 return ($display);
618 }
620 function remove_from_parent()
621 {
622 /* Cancel if there's nothing to do here */
623 if (!$this->initially_was_account){
624 return;
625 }
627 /* include global link_info */
628 $ldap= $this->config->get_ldap_link();
630 plugin::remove_from_parent();
632 /* Keep uid attribute for gosaAccount */
633 unset($this->attrs['uid']);
634 unset($this->attrs['uidNumber']);
635 unset($this->attrs['gidNumber']);
636 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
637 $this->attributes, "Save");
638 $ldap->cd($this->dn);
639 $this->cleanup();
640 $ldap->modify ($this->attrs);
642 show_ldap_error($ldap->get_error(), _("Removing Samba account failed"));
644 /* Optionally execute a command after we're done */
645 $this->handle_post_events("remove",array("uid"=>$this->uid));
646 }
649 /* Check for input problems */
650 function check()
651 {
652 /* Call common method to give check the hook */
653 $message= plugin::check();
655 if ($this->samba3){
657 /* Strings */
658 foreach (array( "sambaHomePath" => _("Home directory"),
659 "sambaProfilePath" => _("Profile path")) as $key => $val){
660 if (!$this->mungedObject->is_samba_path($this->$key)){
661 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
662 }
663 }
665 /* Numeric values */
666 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
667 "CtxMaxDisconnectionTime" => _("Disconnection"),
668 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
670 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
671 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
672 }
673 }
675 /* Too many workstations? Windows usrmgr only supports eight */
676 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
677 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
678 }
679 }
681 return ($message);
682 }
685 /* Save data to object */
686 function save_object()
687 {
688 /* We only care if we are on the sambaTab... */
689 if (isset($_POST['sambaTab'])){
690 plugin::save_object();
692 /* Take care about access options */
693 if (chkacl ($this->acl, "acctFlags") == ""){
694 if ($this->samba3){
695 $attrname= "sambaPwdCanChange";
696 } else {
697 $attrname= "pwdCanChange";
698 }
699 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
700 $tmp= 1;
701 } else {
702 $tmp= 0;
703 }
704 if ($this->$attrname != $tmp){
705 $this->is_modified= TRUE;
706 }
707 $this->pwdCanChange= $tmp;
708 $this->sambaPwdCanChange= $tmp;
709 }
710 $tmp= "UX";
711 if (isset($_POST["no_password_required"])){
712 if ($_POST["no_password_required"] == 1){
713 $tmp.= "N";
714 }
715 }
716 if (isset($_POST["password_expires"])){
717 if ($_POST["password_expires"] == 1){
718 $this->password_expires= 1;
719 }
720 } else {
721 $this->password_expires= 0;
722 }
723 if (isset($_POST["temporary_disable"])){
724 if ($_POST["temporary_disable"] == 1){
725 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
726 $tmp.= "L";
727 } else {
728 $tmp.= "D";
729 }
730 }
731 }
732 if (isset($_POST["logon_time_set"])){
733 if ($_POST["logon_time_set"] == 1){
734 $this->logon_time_set= 1;
735 }
736 } else {
737 $this->logon_time_set= 0;
738 }
739 if (isset($_POST["logoff_time_set"])){
740 if ($_POST["logoff_time_set"] == 1){
741 $this->logoff_time_set= 1;
742 }
743 } else {
744 $this->logoff_time_set= 0;
745 }
746 if (isset($_POST["kickoff_time_set"])){
747 if ($_POST["kickoff_time_set"] == 1){
748 $this->kickoff_time_set= 1;
749 }
750 } else {
751 $this->kickoff_time_set= 0;
752 }
754 $fill= "";
755 for ($i= strlen($tmp); $i<12; $i++){
756 $fill.= " ";
757 }
759 $tmp= "[$tmp$fill]";
761 /* Only save if acl's are set */
762 if (chkacl ($this->acl, "acctFlags") == ""){
763 if ($this->samba3){
764 $attrname= "sambaAcctFlags";
765 } else {
766 $attrname= "acctFlags";
767 }
768 if ($this->$attrname != $tmp){
769 $this->is_modified= TRUE;
770 }
771 $this->$attrname= $tmp;
772 }
774 /* Save sambaDomain attribute */
775 if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
776 isset ($_POST['sambaDomainName'])){
778 $this->sambaDomainName= validate($_POST['sambaDomainName']);
779 }
781 /* Save CTX values */
782 if ($this->samba3){
783 /* Save obvious values */
784 foreach($this->ctxattributes as $val){
785 if (isset($_POST[$val]) && chkacl($this->acl, "$val") == ""){
786 if (get_magic_quotes_gpc()) {
787 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
788 } else {
789 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
790 }
791 }
792 }
794 /* Save checkbox states. */
795 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
796 && chkacl($this->acl, "tslogin") == "");
797 // Need to do some index checking to avoid messages like "index ... not found"
798 if(isset($_POST['brokenconn'])) {
799 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
800 && chkacl($this->acl, "brokenconn") == "");
801 }
802 if(isset($_POST['reconn'])) {
803 $this->mungedObject->setReConn($_POST['reconn'] == '1'
804 && chkacl($this->acl, "reconn") == "");
805 }
806 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
807 && chkacl($this->acl, "inherit") == "");
808 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
809 && chkacl($this->acl, "CtxMaxConnectionTime") == "");
810 $this->mungedObject->setCtxMaxDisconnectionTimeF(
811 !isset($_POST['CtxMaxDisconnectionTimeF'])
812 && chkacl($this->acl, "CtxMaxDisconnectionTime") == "");
813 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
814 && chkacl($this->acl, "CtxMaxIdleTime") == "");
815 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
816 && chkacl($this->acl, "connectclientdrives") == "");
817 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
818 && chkacl($this->acl, "connectclientprinters") == "");
819 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
820 && chkacl($this->acl, "defaultprinter") == "");
822 /* Save combo boxes. Takes two values */
823 if(isset($_POST['reconn'])) {
824 $this->mungedObject->setShadow((isset($_POST['shadow'])
825 && chkacl($this->acl, "shadow") == ""), $_POST['shadow']);
826 }
828 /* Check for changes */
829 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
830 $this->is_modified= TRUE;
831 }
832 }
833 }
834 }
837 /* Save to LDAP */
838 function save()
839 {
840 /* Load uid and gid of this 'dn' */
841 $ldap= $this->config->get_ldap_link();
842 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
843 $tmp= $ldap->fetch();
844 $this->uidNumber= $tmp['uidNumber'][0];
845 $this->gidNumber= $tmp['gidNumber'][0];
847 plugin::save();
849 /* Remove objectClass for sambaIdmapEntry */
850 $tmp= array();
851 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
852 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
853 $tmp[]= $this->attrs['objectClass'][$i];
854 }
855 }
856 $this->attrs['objectClass']= $tmp;
858 /* Generate rid / primaryGroupId */
859 if ($this->samba3){
860 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
861 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
862 } else {
863 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
864 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
865 }
867 /* Need to generate a new uniqe uid/gid combination? */
868 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
869 $uidNumber= $this->uidNumber;
870 while(TRUE){
871 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
872 $ldap->cd($this->config->current['BASE']);
873 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
874 if ($ldap->count() == 0){
875 break;
876 }
877 $uidNumber++;
878 }
879 $this->attrs['sambaSID']= $sid;
881 /* Check for users primary group */
882 $ldap->cd($this->config->current['BASE']);
883 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
884 if ($ldap->count() != 1){
885 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
886 } else {
887 $attrs= $ldap->fetch();
888 $g= new group($this->config, $ldap->getDN());
889 if ($g->sambaSID == ""){
890 $g->sambaDomainName= $this->sambaDomainName;
891 $g->smbgroup= TRUE;
892 $g->save ();
893 }
894 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
895 }
896 }
898 if ($this->sambaHomeDrive == ""){
899 $this->attrs["sambaHomeDrive"]= array();
900 }
902 /* Generate munged dial value */
903 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
905 /* User wants me to fake the idMappings? This is useful for
906 making winbind resolve the user names in a reasonable amount
907 of time in combination with larger databases. */
908 if (isset($this->config->current['SAMBAIDMAPPING']) &&
909 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
910 $this->attrs['objectClass'][]= "sambaIdmapEntry";
911 }
914 /* Password expiery */
915 if ($this->password_expires == "1"){
916 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
917 } else {
918 $this->attrs['sambaPwdMustChange']= array();
919 }
920 /* Make sure not to save zero in sambaPwdLastset */
921 if ($this->sambaPwdLastSet != "0"){
922 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
923 } else {
924 $this->attrs['sambaPwdLastSet']= array();
925 }
926 /* Account expiery */
927 if ($this->logon_time_set == "1"){
928 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
929 } else {
930 $this->attrs['sambaLogonTime']= array();
931 }
932 if ($this->logoff_time_set == "1"){
933 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
934 } else {
935 $this->attrs['sambaLogoffTime']= array();
936 }
937 if ($this->kickoff_time_set == "1"){
938 # Add one day in unixtime format to be compatible with usrmgr
939 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
940 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
941 } else {
942 $this->attrs['sambaKickoffTime']= array();
943 }
944 } else {
945 /* Not samba3 */
946 $this->attrs['rid']= $this->uidNumber*2 + 1000;
947 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
949 if ($this->homeDrive == ""){
950 $this->attrs["homeDrive"]= array();
951 }
953 /* Password expiery */
954 if ($this->password_expires == "1"){
955 $this->attrs['pwdMustChange']= $this->pwdMustChange;
956 } else {
957 $this->attrs['pwdMustChange']= 2147483647;
958 }
959 /* Make sure not to save zero in pwdLastset */
960 if ($this->pwdLastSet != "0"){
961 $this->attrs['pwdLastSet']= $this->pwdLastSet;
962 } else {
963 $this->attrs['pwdLastSet']= array();
964 }
965 /* Account expiery */
966 if ($this->logon_time_set == "1"){
967 $this->attrs['logonTime']= $this->logonTime;
968 } else {
969 $this->attrs['logonTime']= array();
970 }
971 if ($this->logoff_time_set == "1"){
972 $this->attrs['logoffTime']= $this->logoffTime;
973 } else {
974 $this->attrs['logoffTime']= array();
975 }
976 if ($this->kickoff_time_set == "1"){
977 # Add one day in unixtime format to be compatible with usrmgr
978 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
979 } else {
980 $this->attrs['kickoffTime']= array();
981 }
982 }
984 /* Write back to ldap */
985 $ldap->cd($this->dn);
986 $this->cleanup();
987 $ldap->modify ($this->attrs);
989 show_ldap_error($ldap->get_error(), _("Saving Samba account failed"));
991 /* Optionally execute a command after we're done */
992 if ($this->initially_was_account == $this->is_account){
993 if ($this->is_modified){
994 $this->handle_post_events("modify",array("uid" => $this->uid));
995 }
996 } else {
997 $this->handle_post_events("add",array("uid" => $this->uid));
998 }
1000 }
1002 function adapt_from_template($dn)
1003 {
1004 plugin::adapt_from_template($dn);
1005 $this->sambaSID= "";
1006 $this->sambaPrimaryGroupSID= "";
1008 /* Fill mungedDial field */
1009 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1010 $this->mungedObject->load($this->sambaMungedDial);
1011 }
1013 /* Password expiery */
1014 if(isset($this->attrs['sambaPwdMustChange']) &&
1015 $this->attrs['sambaPwdMustChange'][0] != 0){
1016 $this->password_expires= 1;
1017 }
1019 if(isset($this->attrs['sambaLogonTime']) && ! (
1020 $this->attrs['sambaLogonTime'][0] == 0 ||
1021 $this->attrs['sambaLogonTime'][0] == 2147483647
1022 )){
1023 $this->logon_time_set= 1;
1024 }
1025 if(isset($this->attrs['sambaLogoffTime']) && ! (
1026 $this->attrs['sambaLogoffTime'][0] == 0 ||
1027 $this->attrs['sambaLogoffTime'][0] == 2147483647
1028 )){
1029 $this->logoff_time_set= 1;
1030 }
1032 /* Account expiery */
1033 if(isset($this->attrs['sambaKickoffTime']) && ! (
1034 $this->attrs['sambaKickoffTime'][0] == 0 ||
1035 $this->attrs['sambaKickoffTime'][0] == 2147483647
1036 )){
1037 $this->kickoff_time_set= 1;
1038 }
1040 /* Get global filter config */
1041 if (!is_global("sambafilter")){
1042 $ui= get_userinfo();
1043 $base= get_base_from_people($ui->dn);
1044 $sambafilter= array( "depselect" => $base, "regex" => "*");
1045 register_global("sambafilter", $sambafilter);
1046 }
1049 }
1051 }
1053 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1054 ?>