239090344bccb6c8241ec5e18db024f700580f07
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 $CopyPasteVars = array("kickoff_time_set","logoff_time_set","logon_time_set","mungedObject","orig_sambaDomainName");
92 function sambaAccount ($config, $dn= NULL)
93 {
94 /* Load attributes depending on the samba version */
95 $this->samba3= ($config->current['SAMBAVERSION'] == 3);
97 if ($this->samba3){
98 $this->attributes= array ("sambaSID", "sambaPwdLastSet", "sambaLogonTime",
99 "sambaLogoffTime", "sambaKickoffTime", "sambaPwdCanChange",
100 "sambaPwdMustChange", "sambaAcctFlags", "uid", "sambaMungedDial",
101 "sambaHomePath", "sambaHomeDrive", "sambaLogonScript",
102 "sambaProfilePath", "sambaPrimaryGroupSID", "sambaDomainName",
103 "sambaUserWorkstations", "sambaPasswordHistory",
104 "sambaLogonHours", "sambaBadPasswordTime",
105 "sambaBadPasswordCount");
106 $this->objectclasses= array ("sambaSamAccount");
107 $this->mungedObject= new sambaMungedDial;
108 $this->ctxattributes= $this->mungedObject->ctxattributes;
109 } else {
110 $this->attributes= array ("pwdLastSet", "logonTime", "logoffTime", "kickoffTime",
111 "pwdCanChange", "pwdMustChange", "acctFlags", "profilePath", "uid",
112 "smbHome", "homeDrive", "scriptPath", "rid", "primaryGroupID");
113 $this->objectclasses= array ("sambaAccount");
114 }
116 plugin::plugin ($config, $dn);
118 /* Get samba Domain in case of samba 3 */
119 if ($this->samba3 && $this->sambaSID != ""){
120 $this->SID= preg_replace ("/-[^-]+$/", "", $this->sambaSID);
121 $ldap= $this->config->get_ldap_link();
122 $ldap->cd($this->config->current['BASE']);
123 $ldap->search ("(&(objectClass=sambaDomain)(sambaSID=$this->SID))",array("sambaAlgorithmicRidBase","sambaDomainName"));
124 if ($ldap->count() != 0){
125 $attrs= $ldap->fetch();
126 $this->ridBase= $attrs['sambaAlgorithmicRidBase'][0];
127 if ($this->sambaDomainName == ""){
128 $this->sambaDomainName= $attrs['sambaDomainName'][0];
129 }
130 } else {
131 if ($this->sambaDomainName == ""){
132 $this->sambaDomainName= "DEFAULT";
133 }
134 $this->ridBase= $this->config->current['RIDBASE'];
135 $this->SID= $this->config->current['SID'];
136 }
138 /* Save in order to compare later on */
139 $this->orig_sambaDomainName= $this->sambaDomainName;
140 }
142 /* Fill mungedDial field */
143 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
144 $this->mungedObject->load($this->sambaMungedDial);
145 }
147 /* Password expiery */
148 if(isset($this->attrs['sambaPwdMustChange']) &&
149 $this->attrs['sambaPwdMustChange'][0] != 0){
150 $this->password_expires= 1;
151 }
153 if(isset($this->attrs['sambaLogonTime']) && ! (
154 $this->attrs['sambaLogonTime'][0] == 0 ||
155 $this->attrs['sambaLogonTime'][0] == 2147483647
156 )){
157 $this->logon_time_set= 1;
158 }
159 if(isset($this->attrs['sambaLogoffTime']) && ! (
160 $this->attrs['sambaLogoffTime'][0] == 0 ||
161 $this->attrs['sambaLogoffTime'][0] == 2147483647
162 )){
163 $this->logoff_time_set= 1;
164 }
166 /* Account expiery */
167 if(isset($this->attrs['sambaKickoffTime']) && ! (
168 $this->attrs['sambaKickoffTime'][0] == 0 ||
169 $this->attrs['sambaKickoffTime'][0] == 2147483647
170 )){
171 $this->kickoff_time_set= 1;
172 }
174 /* Get global filter config */
175 if (!is_global("sambafilter")){
176 $ui= get_userinfo();
177 $base= get_base_from_people($ui->dn);
178 $sambafilter= array( "depselect" => $base, "regex" => "*");
179 register_global("sambafilter", $sambafilter);
180 }
182 /* Save initial account state */
183 $this->initially_was_account= $this->is_account;
184 }
186 function execute()
187 {
188 /* Call parent execute */
189 plugin::execute();
191 /* Do we need to flip is_account state? */
192 if (isset($_POST['modify_state'])){
193 $this->is_account= !$this->is_account;
194 }
195 /* Do we represent a valid account? */
196 if (!$this->is_account && $this->parent == NULL){
197 $display= "<img alt=\"\"src=\"images/stop.png\" align=\"middle\"> <b>".
198 _("This account has no samba extensions.")."</b>";
199 $display.= back_to_main();
200 return ($display);
201 }
203 /* Show tab dialog headers */
204 $display= "";
205 if ($this->parent != NULL){
206 if ($this->is_account){
207 $display= $this->show_header(_("Remove samba account"),
208 _("This account has samba features enabled. You can disable them by clicking below."));
209 } else {
210 $obj= $this->parent->by_object['posixAccount'];
212 /* Samba3 dependency on posix accounts are enabled
213 in the moment, because I need to rely on unique
214 uidNumbers. There'll be a better solution later
215 on. */
216 if ($obj->is_account){
218 $display= $this->show_header(_("Create samba account"),
219 _("This account has samba features disabled. You can enable them by clicking below."));
220 } else {
221 $display= $this->show_header(_("Create samba account"),
222 _("This account has samba features disabled. Posix features are needed for samba accounts, enable them first."), TRUE);
223 }
224 return ($display);
225 }
226 }
228 /* Prepare templating */
229 $smarty= get_smarty();
231 /* PHP Fehler "Undefined index: sambaPwdMustChangeACL" */
232 #hickert test
233 $smarty->assign("sambaPwdMustChangeACL", chkacl($this->acl, "sambaPwdMustChangeACL"));
234 #hickert test
235 $smarty->assign("sambaPwdMustChange",$this->sambaPwdMustChange);
237 if ($this->sambaPwdMustChange=="0"){
238 $date= getdate();
239 } else {
240 $date= getdate($this->sambaPwdMustChange);
241 }
243 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
244 $sambaLogonTime_date= getdate();
245 } else {
246 $sambaLogonTime_date= getdate($this->sambaLogonTime);
247 }
249 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
250 $sambaLogoffTime_date= getdate();
251 } else {
252 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
253 }
255 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
256 $sambaKickoffTime_date= getdate();
257 } else {
258 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
259 }
261 /* Remove user workstations? */
262 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
263 $tmp= $this->sambaUserWorkstations;
264 foreach($_POST['workstation_list'] as $name){
265 $tmp= preg_replace("/$name/", '', $tmp);
266 $this->is_modified= TRUE;
267 }
268 $tmp= preg_replace('/,+/', ',', $tmp);
269 $this->sambaUserWorkstations= trim($tmp, ',');
270 }
272 /* Add user workstation? */
273 if (isset($_POST["add_ws"])){
274 $this->show_ws_dialog= TRUE;
275 $this->dialog= TRUE;
276 }
278 /* Add user workstation finished? */
279 if (isset($_POST["add_ws_finish"]) || isset($_POST["add_ws_cancel"])){
280 $this->show_ws_dialog= FALSE;
281 $this->dialog= FALSE;
282 }
284 /* Add user workstation? */
285 if (isset($_POST["add_ws_finish"]) && isset($_POST['wslist'])){
286 $tmp= $this->sambaUserWorkstations;
287 foreach($_POST['wslist'] as $ws){
288 $tmp.= ",$ws";
289 }
290 $tmp= preg_replace('/,+/', ',', $tmp);
291 $this->sambaUserWorkstations= trim($tmp, ',');
292 $this->is_modified= TRUE;
293 }
295 /* Show ws dialog */
296 if ($this->show_ws_dialog){
298 /* Save data */
299 $sambafilter= get_global("sambafilter");
300 foreach( array("depselect", "regex") as $type){
301 if (isset($_POST[$type])){
302 $sambafilter[$type]= $_POST[$type];
303 }
304 }
305 if (isset($_GET['search'])){
306 $s= mb_substr($_GET['search'], 0, 1, "UTF8")."*";
307 if ($s == "**"){
308 $s= "*";
309 }
310 $sambafilter['regex']= $s;
311 }
312 register_global("sambafilter", $sambafilter);
314 /* Get workstation list */
315 $exclude= "";
316 foreach(split(',', $this->sambaUserWorkstations) as $ws){
317 $exclude.= "(cn=$ws$)";
318 }
319 if ($exclude != ""){
320 $exclude= "(!(|$exclude))";
321 }
322 $acl= array($this->config->current['BASE'] => ":all");
323 $regex= $sambafilter['regex'];
324 $filter= "(&(objectClass=sambaSAMAccount)$exclude(uid=*$)(|(uid=$regex)(cn=$regex)))";
325 $res= get_list($acl, "$filter", TRUE, $sambafilter['depselect'], array("uid"), TRUE);
326 $wslist= array();
327 foreach ($res as $attrs){
328 $wslist[]= preg_replace('/\$/', '', $attrs['uid'][0]);
329 }
330 asort($wslist);
332 $smarty->assign("search_image", get_template_path('images/search.png'));
333 $smarty->assign("launchimage", get_template_path('images/small_filter.png'));
334 $smarty->assign("tree_image", get_template_path('images/tree.png'));
335 $smarty->assign("deplist", $this->config->idepartments);
336 $smarty->assign("alphabet", generate_alphabet());
337 foreach( array("depselect", "regex") as $type){
338 $smarty->assign("$type", $sambafilter[$type]);
339 }
340 $smarty->assign("hint", print_sizelimit_warning());
341 $smarty->assign("wslist", $wslist);
342 $smarty->assign("apply", apply_filter());
343 $display= $smarty->fetch (get_template_path('samba3_workstations.tpl', TRUE,
344 dirname(__FILE__)));
345 return ($display);
346 }
348 /* Fill calendar */
349 $days= array();
350 for($d= 1; $d<32; $d++){
351 $days[]= $d;
352 }
353 $years= array();
354 for($y= $date['year']-4; $y<$date['year']+4; $y++){
355 $years[]= $y;
356 }
357 $months= array(_("January"), _("February"), _("March"), _("April"),
358 _("May"), _("June"), _("July"), _("August"), _("September"),
359 _("October"), _("November"), _("December"));
360 $smarty->assign("day", $date["mday"]);
361 $smarty->assign("days", $days);
362 $smarty->assign("months", $months);
363 $smarty->assign("month", $date["mon"]-1);
364 $smarty->assign("years", $years);
365 $smarty->assign("year", $date["year"]);
367 $sambaLogonTime_days= array();
368 for($d= 1; $d<32; $d++){
369 $sambaLogonTime_days[]= $d;
370 }
371 $sambaLogonTime_years= array();
372 for($y= $date['year']-4; $y<$date['year']+4; $y++){
373 $sambaLogonTime_years[]= $y;
374 }
375 $sambaLogonTime_months= array(_("January"), _("February"), _("March"), _("April"),
376 _("May"), _("June"), _("July"), _("August"), _("September"),
377 _("October"), _("November"), _("December"));
378 $smarty->assign("sambaLogonTime_day", $sambaLogonTime_date["mday"]);
379 $smarty->assign("sambaLogonTime_days", $sambaLogonTime_days);
380 $smarty->assign("sambaLogonTime_months", $sambaLogonTime_months);
381 $smarty->assign("sambaLogonTime_month", $sambaLogonTime_date["mon"]-1);
382 $smarty->assign("sambaLogonTime_years", $sambaLogonTime_years);
383 $smarty->assign("sambaLogonTime_year", $sambaLogonTime_date["year"]);
385 $sambaLogoffTime_days= array();
386 for($d= 1; $d<32; $d++){
387 $sambaLogoffTime_days[]= $d;
388 }
389 $sambaLogoffTime_years= array();
390 for($y= $date['year']-4; $y<$date['year']+4; $y++){
391 $sambaLogoffTime_years[]= $y;
392 }
393 $sambaLogoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
394 _("May"), _("June"), _("July"), _("August"), _("September"),
395 _("October"), _("November"), _("December"));
396 $smarty->assign("sambaLogoffTime_day", $sambaLogoffTime_date["mday"]);
397 $smarty->assign("sambaLogoffTime_days", $sambaLogoffTime_days);
398 $smarty->assign("sambaLogoffTime_months", $sambaLogoffTime_months);
399 $smarty->assign("sambaLogoffTime_month", $sambaLogoffTime_date["mon"]-1);
400 $smarty->assign("sambaLogoffTime_years", $sambaLogoffTime_years);
401 $smarty->assign("sambaLogoffTime_year", $sambaLogoffTime_date["year"]);
403 $sambaKickoffTime_days= array();
404 for($d= 1; $d<32; $d++){
405 $sambaKickoffTime_days[]= $d;
406 }
407 $sambaKickoffTime_years= array();
408 for($y= $date['year']-4; $y<$date['year']+4; $y++){
409 $sambaKickoffTime_years[]= $y;
410 }
411 $sambaKickoffTime_months= array(_("January"), _("February"), _("March"), _("April"),
412 _("May"), _("June"), _("July"), _("August"), _("September"),
413 _("October"), _("November"), _("December"));
414 //$smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]-1);
415 $smarty->assign("sambaKickoffTime_day", $sambaKickoffTime_date["mday"]); // hickert
416 $smarty->assign("sambaKickoffTime_days", $sambaKickoffTime_days);
417 $smarty->assign("sambaKickoffTime_months", $sambaKickoffTime_months);
418 $smarty->assign("sambaKickoffTime_month", $sambaKickoffTime_date["mon"]-1);
419 $smarty->assign("sambaKickoffTime_years", $sambaKickoffTime_years);
420 $smarty->assign("sambaKickoffTime_year", $sambaKickoffTime_date["year"]);
422 /* Fill boxes */
423 if ($this->samba3){
424 $domains= array();
425 foreach($this->config->data['SERVERS']['SAMBA'] as $name => $content){
426 $domains[]= $name;
427 }
428 $smarty->assign("domains", $domains);
429 }
430 $letters= array();
431 for ($i= 68; $i<91; $i++){
432 $letters[]= chr($i).":";
433 }
434 $smarty->assign("drives", $letters);
436 /* Fill terminal server settings */
437 if ($this->samba3){
438 foreach ($this->ctxattributes as $attr){
439 /* Fill common attributes */
440 if (isset($this->mungedObject->ctx[$attr])){
441 $smarty->assign("$attr", $this->mungedObject->ctx[$attr]);
442 // Set field to blank if value is 0
443 if(in_array($attr, array("CtxMaxConnectionTime", "CtxMaxDisconnectionTime", "CtxMaxIdleTime"))) {
444 if($this->mungedObject->ctx[$attr] == 0) {
445 $smarty->assign("$attr", "");
446 }
447 }
448 } else {
449 $smarty->assign("$attr", "");
450 }
451 $smarty->assign("$attr"."ACL", chkacl($this->acl, $attr));
452 }
454 /* Assign enum values for preset items */
455 $shadowModeVals= array( "0" => _("disabled"),
456 "1" => _("input on, notify on"),
457 "2" => _("input on, notify off"),
458 "3" => _("input off, notify on"),
459 "4" => _("input off, nofify off"));
461 $brokenConnModeVals= array( "0" => _("disconnect"),
462 "1" => _("reset"));
464 $reConnModeVals= array( "0" => _("from any client"),
465 "1" => _("from previous client only"));
467 /* Fill preset items */
468 $smarty->assign("shadow", $shadowModeVals);
469 $smarty->assign("brokenconn", $brokenConnModeVals);
470 $smarty->assign("reconn", $reConnModeVals);
472 /* Fill preset items with values */
473 $smarty->assign("shadowmode", $this->mungedObject->getShadow());
474 $smarty->assign("shadowACL", chkacl($this->acl,"shadow"));
475 $smarty->assign("brokenconnmode", $this->mungedObject->getBrokenConn());
476 $smarty->assign("brokenconnACL", chkacl($this->acl,"brokenconn"));
477 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
478 $smarty->assign("reconnACL", chkacl($this->acl,"reconn"));
480 if($_SESSION['js']){
481 /* Set form elements to disabled/enable state */
482 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
483 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
484 }else{
485 $smarty->assign("tsloginstate", "");
486 $smarty->assign("inheritstate", "");
487 }
489 /* Set checkboxes to checked or unchecked state */
490 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
491 $smarty->assign("tsloginACL", chkacl($this->acl,"tslogin"));
493 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
494 $smarty->assign("inheritACL", chkacl($this->acl,"inherit"));
497 $smarty->assign("connectclientdrives",
498 $this->mungedObject->getConnectClientDrives()?"checked":"");
499 $smarty->assign("connectclientdrivesACL", chkacl($this->acl,"connectclientdrives"));
500 $smarty->assign("connectclientprinters",
501 $this->mungedObject->getConnectClientPrinters()?"checked":"");
502 $smarty->assign("connectclientprintersACL", chkacl($this->acl,"connectclientprinters"));
503 $smarty->assign("defaultprinter",
504 $this->mungedObject->getDefaultPrinter()?"checked":"");
505 $smarty->assign("defaultprinterACL", chkacl($this->acl,"defaultprinter"));
506 $smarty->assign("CtxMaxConnectionTimeF",
507 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
508 $smarty->assign("CtxMaxDisconnectionTimeF",
509 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
510 $smarty->assign("CtxMaxIdleTimeF",
511 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
513 /* Fill sambaUserWorkstations */
514 $ws= split(",", $this->sambaUserWorkstations);
515 sort($ws);
517 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
518 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
521 $smarty->assign("workstations", $ws);
522 $smarty->assign("sambaUserWorkstationACL", chkacl($this->acl,"sambaUserWorkstation"));
523 }
525 /* Variables */
526 foreach($this->attributes as $val){
527 $smarty->assign("$val", $this->$val);
528 $smarty->assign("$val"."ACL", chkacl($this->acl,$val));
529 }
532 /* 'sambaAcctFlags' checkboxes */
533 /* Check for 'lock-account'-flag: 'D' or 'L' */
534 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
535 is_integer(strpos($this->sambaAcctFlags, "L"))) {
536 $smarty->assign("flagsD", "checked");
537 } else {
538 $smarty->assign("flagsD", "");
539 }
541 /* Check for no_password_required flag 'N' */
542 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
543 $smarty->assign("flagsN", "checked");
544 } else {
545 $smarty->assign("flagsN", "");
546 }
548 /* 'normal' Checkboxes */
549 if ($this->pwdCanChange=="1"){
550 $smarty->assign("flagsP", "checked");
551 } else {
552 $smarty->assign("flagsP", "");
553 }
554 if ($this->password_expires=="1"){
555 $smarty->assign("flagsC", "checked");
556 } else {
557 $smarty->assign("flagsC", "");
558 }
559 if ($this->logon_time_set=="1"){
560 $smarty->assign("flagsT", "checked");
561 } else {
562 $smarty->assign("flagsT", "");
563 }
564 if ($this->logoff_time_set=="1"){
565 $smarty->assign("flagsO", "checked");
566 } else {
567 $smarty->assign("flagsO", "");
568 }
569 if ($this->kickoff_time_set=="1"){
570 $smarty->assign("flagsK", "checked");
571 } else {
572 $smarty->assign("flagsK", "");
573 }
575 $smarty->assign("allow_pwchangeACL", chkacl($this->acl, "allow_pwchange"));
576 $smarty->assign("password_expiresACL", chkacl($this->acl, "password_expires"));
577 $smarty->assign("no_password_requiredACL", chkacl($this->acl, "no_password_required"));
578 $smarty->assign("temporary_disableACL", chkacl($this->acl, "temporary_disable"));
579 $smarty->assign("sambaDomainNameACL", chkacl($this->acl, "sambaDomainName"));
580 $smarty->assign("logon_time_setACL", chkacl($this->acl, "logon_time_set"));
581 $smarty->assign("logoff_time_setACL", chkacl($this->acl, "logoff_time_set"));
582 $smarty->assign("kickoff_time_setACL", chkacl($this->acl, "kickoff_time_set"));
583 $smarty->assign("sambaLogonTimeACL", chkacl($this->acl, "sambaLogonTime"));
584 $smarty->assign("sambaLogoffTimeACL", chkacl($this->acl, "sambaLogoffTime"));
585 $smarty->assign("sambaKickoffTimeACL", chkacl($this->acl, "sambaKickoffTime"));
588 /* In case of javascript, disable some fields on demand */
589 if ($this->samba3){
590 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
591 $smarty->assign("$key", "$value");
592 }
593 }
595 /* Show main page */
596 if ($this->samba3){
597 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
598 } else {
599 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
600 }
602 return ($display);
603 }
605 function remove_from_parent()
606 {
607 /* Cancel if there's nothing to do here */
608 if (!$this->initially_was_account){
609 return;
610 }
612 /* include global link_info */
613 $ldap= $this->config->get_ldap_link();
615 plugin::remove_from_parent();
617 /* Keep uid attribute for gosaAccount */
618 unset($this->attrs['uid']);
619 unset($this->attrs['uidNumber']);
620 unset($this->attrs['gidNumber']);
621 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
622 $this->attributes, "Save");
623 $ldap->cd($this->dn);
624 $this->cleanup();
625 $ldap->modify ($this->attrs);
627 show_ldap_error($ldap->get_error());
629 /* Optionally execute a command after we're done */
630 $this->handle_post_events("remove");
631 }
634 /* Check for input problems */
635 function check()
636 {
637 $message= array();
639 if ($this->samba3){
641 /* Strings */
642 foreach (array( "sambaHomePath" => _("Home directory"),
643 "sambaProfilePath" => _("Profile path")) as $key => $val){
644 if (!$this->mungedObject->is_samba_path($this->$key)){
645 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
646 }
647 }
649 /* Numeric values */
650 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
651 "CtxMaxDisconnectionTime" => _("Disconnection"),
652 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
654 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
655 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
656 }
657 }
659 /* Too many workstations? Windows usrmgr only supports eight */
660 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
661 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
662 }
663 }
665 return ($message);
666 }
669 /* Save data to object */
670 function save_object()
671 {
672 /* We only care if we are on the sambaTab... */
673 if (isset($_POST['sambaTab'])){
674 plugin::save_object();
676 /* Take care about access options */
677 if (chkacl ($this->acl, "acctFlags") == ""){
678 if ($this->samba3){
679 $attrname= "sambaPwdCanChange";
680 } else {
681 $attrname= "pwdCanChange";
682 }
683 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
684 $tmp= 1;
685 } else {
686 $tmp= 0;
687 }
688 if ($this->$attrname != $tmp){
689 $this->is_modified= TRUE;
690 }
691 $this->pwdCanChange= $tmp;
692 $this->sambaPwdCanChange= $tmp;
693 }
694 $tmp= "UX";
695 if (isset($_POST["no_password_required"])){
696 if ($_POST["no_password_required"] == 1){
697 $tmp.= "N";
698 }
699 }
700 if (isset($_POST["password_expires"])){
701 if ($_POST["password_expires"] == 1){
702 $this->password_expires= 1;
703 }
704 } else {
705 $this->password_expires= 0;
706 }
707 if (isset($_POST["temporary_disable"])){
708 if ($_POST["temporary_disable"] == 1){
709 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
710 $tmp.= "L";
711 } else {
712 $tmp.= "D";
713 }
714 }
715 }
716 if (isset($_POST["logon_time_set"])){
717 if ($_POST["logon_time_set"] == 1){
718 $this->logon_time_set= 1;
719 }
720 } else {
721 $this->logon_time_set= 0;
722 }
723 if (isset($_POST["logoff_time_set"])){
724 if ($_POST["logoff_time_set"] == 1){
725 $this->logoff_time_set= 1;
726 }
727 } else {
728 $this->logoff_time_set= 0;
729 }
730 if (isset($_POST["kickoff_time_set"])){
731 if ($_POST["kickoff_time_set"] == 1){
732 $this->kickoff_time_set= 1;
733 }
734 } else {
735 $this->kickoff_time_set= 0;
736 }
738 $fill= "";
739 for ($i= strlen($tmp); $i<12; $i++){
740 $fill.= " ";
741 }
743 $tmp= "[$tmp$fill]";
745 /* Only save if acl's are set */
746 if (chkacl ($this->acl, "acctFlags") == ""){
747 if ($this->samba3){
748 $attrname= "sambaAcctFlags";
749 } else {
750 $attrname= "acctFlags";
751 }
752 if ($this->$attrname != $tmp){
753 $this->is_modified= TRUE;
754 }
755 $this->$attrname= $tmp;
756 }
758 /* Save sambaDomain attribute */
759 if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
760 isset ($_POST['sambaDomainName'])){
762 $this->sambaDomainName= validate($_POST['sambaDomainName']);
763 }
765 /* Save CTX values */
766 if ($this->samba3){
767 /* Save obvious values */
768 foreach($this->ctxattributes as $val){
769 if (isset($_POST[$val]) && chkacl($this->acl, "$val") == ""){
770 if (get_magic_quotes_gpc()) {
771 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
772 } else {
773 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
774 }
775 }
776 }
778 /* Save checkbox states. */
779 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
780 && chkacl($this->acl, "tslogin") == "");
781 // Need to do some index checking to avoid messages like "index ... not found"
782 if(isset($_POST['brokenconn'])) {
783 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
784 && chkacl($this->acl, "brokenconn") == "");
785 }
786 if(isset($_POST['reconn'])) {
787 $this->mungedObject->setReConn($_POST['reconn'] == '1'
788 && chkacl($this->acl, "reconn") == "");
789 }
790 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
791 && chkacl($this->acl, "inherit") == "");
792 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
793 && chkacl($this->acl, "CtxMaxConnectionTime") == "");
794 $this->mungedObject->setCtxMaxDisconnectionTimeF(
795 !isset($_POST['CtxMaxDisconnectionTimeF'])
796 && chkacl($this->acl, "CtxMaxDisconnectionTime") == "");
797 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
798 && chkacl($this->acl, "CtxMaxIdleTime") == "");
799 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
800 && chkacl($this->acl, "connectclientdrives") == "");
801 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
802 && chkacl($this->acl, "connectclientprinters") == "");
803 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
804 && chkacl($this->acl, "defaultprinter") == "");
806 /* Save combo boxes. Takes two values */
807 if(isset($_POST['reconn'])) {
808 $this->mungedObject->setShadow((isset($_POST['shadow'])
809 && chkacl($this->acl, "shadow") == ""), $_POST['shadow']);
810 }
812 /* Check for changes */
813 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
814 $this->is_modified= TRUE;
815 }
816 }
817 }
818 }
821 /* Save to LDAP */
822 function save()
823 {
824 /* Load uid and gid of this 'dn' */
825 $ldap= $this->config->get_ldap_link();
826 $ldap->cat($this->dn);
827 $tmp= $ldap->fetch();
828 $this->uidNumber= $tmp['uidNumber'][0];
829 $this->gidNumber= $tmp['gidNumber'][0];
831 plugin::save();
833 /* Remove objectClass for sambaIdmapEntry */
834 $tmp= array();
835 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
836 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
837 $tmp[]= $this->attrs['objectClass'][$i];
838 }
839 }
840 $this->attrs['objectClass']= $tmp;
842 /* Generate rid / primaryGroupId */
843 if ($this->samba3){
844 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
845 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
846 } else {
847 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
848 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
849 }
851 /* Need to generate a new uniqe uid/gid combination? */
852 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
853 $uidNumber= $this->uidNumber;
854 while(TRUE){
855 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
856 $ldap->cd($this->config->current['BASE']);
857 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
858 if ($ldap->count() == 0){
859 break;
860 }
861 $uidNumber++;
862 }
863 $this->attrs['sambaSID']= $sid;
865 /* Check for users primary group */
866 $ldap->cd($this->config->current['BASE']);
867 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
868 if ($ldap->count() != 1){
869 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
870 } else {
871 $attrs= $ldap->fetch();
872 $g= new group($this->config, $ldap->getDN());
873 if ($g->sambaSID == ""){
874 $g->sambaDomainName= $this->sambaDomainName;
875 $g->smbgroup= TRUE;
876 $g->save ();
877 }
878 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
879 }
880 }
882 if ($this->sambaHomeDrive == ""){
883 $this->attrs["sambaHomeDrive"]= array();
884 }
886 /* Generate munged dial value */
887 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
889 /* User wants me to fake the idMappings? This is useful for
890 making winbind resolve the user names in a reasonable amount
891 of time in combination with larger databases. */
892 if (isset($this->config->current['SAMBAIDMAPPING']) &&
893 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
894 $this->attrs['objectClass'][]= "sambaIdmapEntry";
895 }
898 /* Password expiery */
899 if ($this->password_expires == "1"){
900 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
901 } else {
902 $this->attrs['sambaPwdMustChange']= array();
903 }
904 /* Make sure not to save zero in sambaPwdLastset */
905 if ($this->sambaPwdLastSet != "0"){
906 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
907 } else {
908 $this->attrs['sambaPwdLastSet']= array();
909 }
910 /* Account expiery */
911 if ($this->logon_time_set == "1"){
912 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
913 } else {
914 $this->attrs['sambaLogonTime']= array();
915 }
916 if ($this->logoff_time_set == "1"){
917 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
918 } else {
919 $this->attrs['sambaLogoffTime']= array();
920 }
921 if ($this->kickoff_time_set == "1"){
922 # Add one day in unixtime format to be compatible with usrmgr
923 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
924 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
925 } else {
926 $this->attrs['sambaKickoffTime']= array();
927 }
928 } else {
929 /* Not samba3 */
930 $this->attrs['rid']= $this->uidNumber*2 + 1000;
931 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
933 if ($this->homeDrive == ""){
934 $this->attrs["homeDrive"]= array();
935 }
937 /* Password expiery */
938 if ($this->password_expires == "1"){
939 $this->attrs['pwdMustChange']= $this->pwdMustChange;
940 } else {
941 $this->attrs['pwdMustChange']= 2147483647;
942 }
943 /* Make sure not to save zero in pwdLastset */
944 if ($this->pwdLastSet != "0"){
945 $this->attrs['pwdLastSet']= $this->pwdLastSet;
946 } else {
947 $this->attrs['pwdLastSet']= array();
948 }
949 /* Account expiery */
950 if ($this->logon_time_set == "1"){
951 $this->attrs['logonTime']= $this->logonTime;
952 } else {
953 $this->attrs['logonTime']= array();
954 }
955 if ($this->logoff_time_set == "1"){
956 $this->attrs['logoffTime']= $this->logoffTime;
957 } else {
958 $this->attrs['logoffTime']= array();
959 }
960 if ($this->kickoff_time_set == "1"){
961 # Add one day in unixtime format to be compatible with usrmgr
962 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
963 } else {
964 $this->attrs['kickoffTime']= array();
965 }
966 }
968 /* Write back to ldap */
969 $ldap->cd($this->dn);
970 $this->cleanup();
971 $ldap->modify ($this->attrs);
973 show_ldap_error($ldap->get_error());
975 /* Optionally execute a command after we're done */
976 if ($this->initially_was_account == $this->is_account){
977 if ($this->is_modified){
978 $this->handle_post_events("modify");
979 }
980 } else {
981 $this->handle_post_events("add");
982 }
984 }
986 function adapt_from_template($dn)
987 {
988 plugin::adapt_from_template($dn);
989 $this->sambaSID= "";
990 $this->sambaPrimaryGroupSID= "";
992 /* Fill mungedDial field */
993 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
994 $this->mungedObject->load($this->sambaMungedDial);
995 }
997 /* Password expiery */
998 if(isset($this->attrs['sambaPwdMustChange']) &&
999 $this->attrs['sambaPwdMustChange'][0] != 0){
1000 $this->password_expires= 1;
1001 }
1003 if(isset($this->attrs['sambaLogonTime']) && ! (
1004 $this->attrs['sambaLogonTime'][0] == 0 ||
1005 $this->attrs['sambaLogonTime'][0] == 2147483647
1006 )){
1007 $this->logon_time_set= 1;
1008 }
1009 if(isset($this->attrs['sambaLogoffTime']) && ! (
1010 $this->attrs['sambaLogoffTime'][0] == 0 ||
1011 $this->attrs['sambaLogoffTime'][0] == 2147483647
1012 )){
1013 $this->logoff_time_set= 1;
1014 }
1016 /* Account expiery */
1017 if(isset($this->attrs['sambaKickoffTime']) && ! (
1018 $this->attrs['sambaKickoffTime'][0] == 0 ||
1019 $this->attrs['sambaKickoffTime'][0] == 2147483647
1020 )){
1021 $this->kickoff_time_set= 1;
1022 }
1024 /* Get global filter config */
1025 if (!is_global("sambafilter")){
1026 $ui= get_userinfo();
1027 $base= get_base_from_people($ui->dn);
1028 $sambafilter= array( "depselect" => $base, "regex" => "*");
1029 register_global("sambafilter", $sambafilter);
1030 }
1033 }
1035 }
1037 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1038 ?>