8a7f5ab8808efb015f70cd881be772f1c3e003dc
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->pwdCanChange=="1"){
557 $smarty->assign("flagsP", "checked");
558 } else {
559 $smarty->assign("flagsP", "");
560 }
561 if ($this->password_expires=="1"){
562 $smarty->assign("flagsC", "checked");
563 } else {
564 $smarty->assign("flagsC", "");
565 }
566 if ($this->logon_time_set=="1"){
567 $smarty->assign("flagsT", "checked");
568 } else {
569 $smarty->assign("flagsT", "");
570 }
571 if ($this->logoff_time_set=="1"){
572 $smarty->assign("flagsO", "checked");
573 } else {
574 $smarty->assign("flagsO", "");
575 }
576 if ($this->kickoff_time_set=="1"){
577 $smarty->assign("flagsK", "checked");
578 } else {
579 $smarty->assign("flagsK", "");
580 }
582 $smarty->assign("allow_pwchangeACL", chkacl($this->acl, "allow_pwchange"));
583 $smarty->assign("password_expiresACL", chkacl($this->acl, "password_expires"));
584 $smarty->assign("no_password_requiredACL", chkacl($this->acl, "no_password_required"));
585 $smarty->assign("temporary_disableACL", chkacl($this->acl, "temporary_disable"));
586 $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
587 $smarty->assign("logon_time_setACL", chkacl($this->acl, "logon_time_set"));
588 $smarty->assign("logoff_time_setACL", chkacl($this->acl, "logoff_time_set"));
589 $smarty->assign("kickoff_time_setACL", chkacl($this->acl, "kickoff_time_set"));
590 $smarty->assign("sambaLogonTimeACL", chkacl($this->acl, "sambaLogonTime"));
591 $smarty->assign("sambaLogoffTimeACL", chkacl($this->acl, "sambaLogoffTime"));
592 $smarty->assign("sambaKickoffTimeACL", chkacl($this->acl, "sambaKickoffTime"));
595 /* In case of javascript, disable some fields on demand */
596 if ($this->samba3){
597 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
598 $smarty->assign("$key", "$value");
599 }
600 }
602 /* Show main page */
603 if ($this->samba3){
604 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
605 } else {
606 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
607 }
609 return ($display);
610 }
612 function remove_from_parent()
613 {
614 /* Cancel if there's nothing to do here */
615 if (!$this->initially_was_account){
616 return;
617 }
619 /* include global link_info */
620 $ldap= $this->config->get_ldap_link();
622 plugin::remove_from_parent();
624 /* Keep uid attribute for gosaAccount */
625 unset($this->attrs['uid']);
626 unset($this->attrs['uidNumber']);
627 unset($this->attrs['gidNumber']);
628 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
629 $this->attributes, "Save");
630 $ldap->cd($this->dn);
631 $this->cleanup();
632 $ldap->modify ($this->attrs);
634 show_ldap_error($ldap->get_error(), _("Removing Samba account failed"));
636 /* Optionally execute a command after we're done */
637 $this->handle_post_events("remove",array("uid"=>$this->uid));
638 }
641 /* Check for input problems */
642 function check()
643 {
644 /* Call common method to give check the hook */
645 $message= plugin::check();
647 if ($this->samba3){
649 /* Strings */
650 foreach (array( "sambaHomePath" => _("Home directory"),
651 "sambaProfilePath" => _("Profile path")) as $key => $val){
652 if (!$this->mungedObject->is_samba_path($this->$key)){
653 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
654 }
655 }
657 /* Numeric values */
658 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
659 "CtxMaxDisconnectionTime" => _("Disconnection"),
660 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
662 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
663 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
664 }
665 }
667 /* Too many workstations? Windows usrmgr only supports eight */
668 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
669 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
670 }
671 }
673 return ($message);
674 }
677 /* Save data to object */
678 function save_object()
679 {
680 /* We only care if we are on the sambaTab... */
681 if (isset($_POST['sambaTab'])){
682 plugin::save_object();
684 /* Take care about access options */
685 if (chkacl ($this->acl, "acctFlags") == ""){
686 if ($this->samba3){
687 $attrname= "sambaPwdCanChange";
688 } else {
689 $attrname= "pwdCanChange";
690 }
691 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
692 $tmp= 1;
693 } else {
694 $tmp= 0;
695 }
696 if ($this->$attrname != $tmp){
697 $this->is_modified= TRUE;
698 }
699 $this->pwdCanChange= $tmp;
700 $this->sambaPwdCanChange= $tmp;
701 }
702 $tmp= "UX";
703 if (isset($_POST["no_password_required"])){
704 if ($_POST["no_password_required"] == 1){
705 $tmp.= "N";
706 }
707 }
708 if (isset($_POST["password_expires"])){
709 if ($_POST["password_expires"] == 1){
710 $this->password_expires= 1;
711 }
712 } else {
713 $this->password_expires= 0;
714 }
715 if (isset($_POST["temporary_disable"])){
716 if ($_POST["temporary_disable"] == 1){
717 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
718 $tmp.= "L";
719 } else {
720 $tmp.= "D";
721 }
722 }
723 }
724 if (isset($_POST["logon_time_set"])){
725 if ($_POST["logon_time_set"] == 1){
726 $this->logon_time_set= 1;
727 }
728 } else {
729 $this->logon_time_set= 0;
730 }
731 if (isset($_POST["logoff_time_set"])){
732 if ($_POST["logoff_time_set"] == 1){
733 $this->logoff_time_set= 1;
734 }
735 } else {
736 $this->logoff_time_set= 0;
737 }
738 if (isset($_POST["kickoff_time_set"])){
739 if ($_POST["kickoff_time_set"] == 1){
740 $this->kickoff_time_set= 1;
741 }
742 } else {
743 $this->kickoff_time_set= 0;
744 }
746 $fill= "";
747 for ($i= strlen($tmp); $i<12; $i++){
748 $fill.= " ";
749 }
751 $tmp= "[$tmp$fill]";
753 /* Only save if acl's are set */
754 if (chkacl ($this->acl, "acctFlags") == ""){
755 if ($this->samba3){
756 $attrname= "sambaAcctFlags";
757 } else {
758 $attrname= "acctFlags";
759 }
760 if ($this->$attrname != $tmp){
761 $this->is_modified= TRUE;
762 }
763 $this->$attrname= $tmp;
764 }
766 /* Save sambaDomain attribute */
767 if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
768 isset ($_POST['sambaDomainName'])){
770 $this->sambaDomainName= validate($_POST['sambaDomainName']);
771 }
773 /* Save CTX values */
774 if ($this->samba3){
775 /* Save obvious values */
776 foreach($this->ctxattributes as $val){
777 if (isset($_POST[$val]) && chkacl($this->acl, "$val") == ""){
778 if (get_magic_quotes_gpc()) {
779 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
780 } else {
781 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
782 }
783 }
784 }
786 /* Save checkbox states. */
787 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
788 && chkacl($this->acl, "tslogin") == "");
789 // Need to do some index checking to avoid messages like "index ... not found"
790 if(isset($_POST['brokenconn'])) {
791 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
792 && chkacl($this->acl, "brokenconn") == "");
793 }
794 if(isset($_POST['reconn'])) {
795 $this->mungedObject->setReConn($_POST['reconn'] == '1'
796 && chkacl($this->acl, "reconn") == "");
797 }
798 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
799 && chkacl($this->acl, "inherit") == "");
800 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
801 && chkacl($this->acl, "CtxMaxConnectionTime") == "");
802 $this->mungedObject->setCtxMaxDisconnectionTimeF(
803 !isset($_POST['CtxMaxDisconnectionTimeF'])
804 && chkacl($this->acl, "CtxMaxDisconnectionTime") == "");
805 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
806 && chkacl($this->acl, "CtxMaxIdleTime") == "");
807 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
808 && chkacl($this->acl, "connectclientdrives") == "");
809 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
810 && chkacl($this->acl, "connectclientprinters") == "");
811 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
812 && chkacl($this->acl, "defaultprinter") == "");
814 /* Save combo boxes. Takes two values */
815 if(isset($_POST['reconn'])) {
816 $this->mungedObject->setShadow((isset($_POST['shadow'])
817 && chkacl($this->acl, "shadow") == ""), $_POST['shadow']);
818 }
820 /* Check for changes */
821 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
822 $this->is_modified= TRUE;
823 }
824 }
825 }
826 }
829 /* Save to LDAP */
830 function save()
831 {
832 /* Load uid and gid of this 'dn' */
833 $ldap= $this->config->get_ldap_link();
834 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
835 $tmp= $ldap->fetch();
836 $this->uidNumber= $tmp['uidNumber'][0];
837 $this->gidNumber= $tmp['gidNumber'][0];
839 plugin::save();
841 /* Remove objectClass for sambaIdmapEntry */
842 $tmp= array();
843 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
844 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
845 $tmp[]= $this->attrs['objectClass'][$i];
846 }
847 }
848 $this->attrs['objectClass']= $tmp;
850 /* Generate rid / primaryGroupId */
851 if ($this->samba3){
852 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
853 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
854 } else {
855 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
856 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
857 }
859 /* Need to generate a new uniqe uid/gid combination? */
860 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
861 $uidNumber= $this->uidNumber;
862 while(TRUE){
863 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
864 $ldap->cd($this->config->current['BASE']);
865 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
866 if ($ldap->count() == 0){
867 break;
868 }
869 $uidNumber++;
870 }
871 $this->attrs['sambaSID']= $sid;
873 /* Check for users primary group */
874 $ldap->cd($this->config->current['BASE']);
875 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
876 if ($ldap->count() != 1){
877 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
878 } else {
879 $attrs= $ldap->fetch();
880 $g= new group($this->config, $ldap->getDN());
881 if ($g->sambaSID == ""){
882 $g->sambaDomainName= $this->sambaDomainName;
883 $g->smbgroup= TRUE;
884 $g->save ();
885 }
886 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
887 }
888 }
890 if ($this->sambaHomeDrive == ""){
891 $this->attrs["sambaHomeDrive"]= array();
892 }
894 /* Generate munged dial value */
895 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
897 /* User wants me to fake the idMappings? This is useful for
898 making winbind resolve the user names in a reasonable amount
899 of time in combination with larger databases. */
900 if (isset($this->config->current['SAMBAIDMAPPING']) &&
901 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
902 $this->attrs['objectClass'][]= "sambaIdmapEntry";
903 }
906 /* Password expiery */
907 if ($this->password_expires == "1"){
908 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
909 } else {
910 $this->attrs['sambaPwdMustChange']= array();
911 }
912 /* Make sure not to save zero in sambaPwdLastset */
913 if ($this->sambaPwdLastSet != "0"){
914 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
915 } else {
916 $this->attrs['sambaPwdLastSet']= array();
917 }
918 /* Account expiery */
919 if ($this->logon_time_set == "1"){
920 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
921 } else {
922 $this->attrs['sambaLogonTime']= array();
923 }
924 if ($this->logoff_time_set == "1"){
925 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
926 } else {
927 $this->attrs['sambaLogoffTime']= array();
928 }
929 if ($this->kickoff_time_set == "1"){
930 # Add one day in unixtime format to be compatible with usrmgr
931 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
932 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
933 } else {
934 $this->attrs['sambaKickoffTime']= array();
935 }
936 } else {
937 /* Not samba3 */
938 $this->attrs['rid']= $this->uidNumber*2 + 1000;
939 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
941 if ($this->homeDrive == ""){
942 $this->attrs["homeDrive"]= array();
943 }
945 /* Password expiery */
946 if ($this->password_expires == "1"){
947 $this->attrs['pwdMustChange']= $this->pwdMustChange;
948 } else {
949 $this->attrs['pwdMustChange']= 2147483647;
950 }
951 /* Make sure not to save zero in pwdLastset */
952 if ($this->pwdLastSet != "0"){
953 $this->attrs['pwdLastSet']= $this->pwdLastSet;
954 } else {
955 $this->attrs['pwdLastSet']= array();
956 }
957 /* Account expiery */
958 if ($this->logon_time_set == "1"){
959 $this->attrs['logonTime']= $this->logonTime;
960 } else {
961 $this->attrs['logonTime']= array();
962 }
963 if ($this->logoff_time_set == "1"){
964 $this->attrs['logoffTime']= $this->logoffTime;
965 } else {
966 $this->attrs['logoffTime']= array();
967 }
968 if ($this->kickoff_time_set == "1"){
969 # Add one day in unixtime format to be compatible with usrmgr
970 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
971 } else {
972 $this->attrs['kickoffTime']= array();
973 }
974 }
976 /* Write back to ldap */
977 $ldap->cd($this->dn);
978 $this->cleanup();
979 $ldap->modify ($this->attrs);
981 show_ldap_error($ldap->get_error(), _("Saving Samba account failed"));
983 /* Optionally execute a command after we're done */
984 if ($this->initially_was_account == $this->is_account){
985 if ($this->is_modified){
986 $this->handle_post_events("modify",array("uid" => $this->uid));
987 }
988 } else {
989 $this->handle_post_events("add",array("uid" => $this>uid));
990 }
992 }
994 function adapt_from_template($dn)
995 {
996 plugin::adapt_from_template($dn);
997 $this->sambaSID= "";
998 $this->sambaPrimaryGroupSID= "";
1000 /* Fill mungedDial field */
1001 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
1002 $this->mungedObject->load($this->sambaMungedDial);
1003 }
1005 /* Password expiery */
1006 if(isset($this->attrs['sambaPwdMustChange']) &&
1007 $this->attrs['sambaPwdMustChange'][0] != 0){
1008 $this->password_expires= 1;
1009 }
1011 if(isset($this->attrs['sambaLogonTime']) && ! (
1012 $this->attrs['sambaLogonTime'][0] == 0 ||
1013 $this->attrs['sambaLogonTime'][0] == 2147483647
1014 )){
1015 $this->logon_time_set= 1;
1016 }
1017 if(isset($this->attrs['sambaLogoffTime']) && ! (
1018 $this->attrs['sambaLogoffTime'][0] == 0 ||
1019 $this->attrs['sambaLogoffTime'][0] == 2147483647
1020 )){
1021 $this->logoff_time_set= 1;
1022 }
1024 /* Account expiery */
1025 if(isset($this->attrs['sambaKickoffTime']) && ! (
1026 $this->attrs['sambaKickoffTime'][0] == 0 ||
1027 $this->attrs['sambaKickoffTime'][0] == 2147483647
1028 )){
1029 $this->kickoff_time_set= 1;
1030 }
1032 /* Get global filter config */
1033 if (!is_global("sambafilter")){
1034 $ui= get_userinfo();
1035 $base= get_base_from_people($ui->dn);
1036 $sambafilter= array( "depselect" => $base, "regex" => "*");
1037 register_global("sambafilter", $sambafilter);
1038 }
1041 }
1043 }
1045 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1046 ?>