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($filter, $acl, $sambafilter['depselect'], array("uid"), GL_SUBSEARCH | GL_SIZELIMIT);
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(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
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 /* Call common method to give check the hook */
638 $message= plugin::check();
640 if ($this->samba3){
642 /* Strings */
643 foreach (array( "sambaHomePath" => _("Home directory"),
644 "sambaProfilePath" => _("Profile path")) as $key => $val){
645 if (!$this->mungedObject->is_samba_path($this->$key)){
646 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
647 }
648 }
650 /* Numeric values */
651 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
652 "CtxMaxDisconnectionTime" => _("Disconnection"),
653 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
655 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
656 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
657 }
658 }
660 /* Too many workstations? Windows usrmgr only supports eight */
661 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
662 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
663 }
664 }
666 return ($message);
667 }
670 /* Save data to object */
671 function save_object()
672 {
673 /* We only care if we are on the sambaTab... */
674 if (isset($_POST['sambaTab'])){
675 plugin::save_object();
677 /* Take care about access options */
678 if (chkacl ($this->acl, "acctFlags") == ""){
679 if ($this->samba3){
680 $attrname= "sambaPwdCanChange";
681 } else {
682 $attrname= "pwdCanChange";
683 }
684 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
685 $tmp= 1;
686 } else {
687 $tmp= 0;
688 }
689 if ($this->$attrname != $tmp){
690 $this->is_modified= TRUE;
691 }
692 $this->pwdCanChange= $tmp;
693 $this->sambaPwdCanChange= $tmp;
694 }
695 $tmp= "UX";
696 if (isset($_POST["no_password_required"])){
697 if ($_POST["no_password_required"] == 1){
698 $tmp.= "N";
699 }
700 }
701 if (isset($_POST["password_expires"])){
702 if ($_POST["password_expires"] == 1){
703 $this->password_expires= 1;
704 }
705 } else {
706 $this->password_expires= 0;
707 }
708 if (isset($_POST["temporary_disable"])){
709 if ($_POST["temporary_disable"] == 1){
710 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
711 $tmp.= "L";
712 } else {
713 $tmp.= "D";
714 }
715 }
716 }
717 if (isset($_POST["logon_time_set"])){
718 if ($_POST["logon_time_set"] == 1){
719 $this->logon_time_set= 1;
720 }
721 } else {
722 $this->logon_time_set= 0;
723 }
724 if (isset($_POST["logoff_time_set"])){
725 if ($_POST["logoff_time_set"] == 1){
726 $this->logoff_time_set= 1;
727 }
728 } else {
729 $this->logoff_time_set= 0;
730 }
731 if (isset($_POST["kickoff_time_set"])){
732 if ($_POST["kickoff_time_set"] == 1){
733 $this->kickoff_time_set= 1;
734 }
735 } else {
736 $this->kickoff_time_set= 0;
737 }
739 $fill= "";
740 for ($i= strlen($tmp); $i<12; $i++){
741 $fill.= " ";
742 }
744 $tmp= "[$tmp$fill]";
746 /* Only save if acl's are set */
747 if (chkacl ($this->acl, "acctFlags") == ""){
748 if ($this->samba3){
749 $attrname= "sambaAcctFlags";
750 } else {
751 $attrname= "acctFlags";
752 }
753 if ($this->$attrname != $tmp){
754 $this->is_modified= TRUE;
755 }
756 $this->$attrname= $tmp;
757 }
759 /* Save sambaDomain attribute */
760 if (chkacl ($this->acl, "sambaDomainName") == "" && $this->samba3 &&
761 isset ($_POST['sambaDomainName'])){
763 $this->sambaDomainName= validate($_POST['sambaDomainName']);
764 }
766 /* Save CTX values */
767 if ($this->samba3){
768 /* Save obvious values */
769 foreach($this->ctxattributes as $val){
770 if (isset($_POST[$val]) && chkacl($this->acl, "$val") == ""){
771 if (get_magic_quotes_gpc()) {
772 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
773 } else {
774 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
775 }
776 }
777 }
779 /* Save checkbox states. */
780 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
781 && chkacl($this->acl, "tslogin") == "");
782 // Need to do some index checking to avoid messages like "index ... not found"
783 if(isset($_POST['brokenconn'])) {
784 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
785 && chkacl($this->acl, "brokenconn") == "");
786 }
787 if(isset($_POST['reconn'])) {
788 $this->mungedObject->setReConn($_POST['reconn'] == '1'
789 && chkacl($this->acl, "reconn") == "");
790 }
791 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
792 && chkacl($this->acl, "inherit") == "");
793 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
794 && chkacl($this->acl, "CtxMaxConnectionTime") == "");
795 $this->mungedObject->setCtxMaxDisconnectionTimeF(
796 !isset($_POST['CtxMaxDisconnectionTimeF'])
797 && chkacl($this->acl, "CtxMaxDisconnectionTime") == "");
798 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
799 && chkacl($this->acl, "CtxMaxIdleTime") == "");
800 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
801 && chkacl($this->acl, "connectclientdrives") == "");
802 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
803 && chkacl($this->acl, "connectclientprinters") == "");
804 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
805 && chkacl($this->acl, "defaultprinter") == "");
807 /* Save combo boxes. Takes two values */
808 if(isset($_POST['reconn'])) {
809 $this->mungedObject->setShadow((isset($_POST['shadow'])
810 && chkacl($this->acl, "shadow") == ""), $_POST['shadow']);
811 }
813 /* Check for changes */
814 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
815 $this->is_modified= TRUE;
816 }
817 }
818 }
819 }
822 /* Save to LDAP */
823 function save()
824 {
825 /* Load uid and gid of this 'dn' */
826 $ldap= $this->config->get_ldap_link();
827 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
828 $tmp= $ldap->fetch();
829 $this->uidNumber= $tmp['uidNumber'][0];
830 $this->gidNumber= $tmp['gidNumber'][0];
832 plugin::save();
834 /* Remove objectClass for sambaIdmapEntry */
835 $tmp= array();
836 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
837 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
838 $tmp[]= $this->attrs['objectClass'][$i];
839 }
840 }
841 $this->attrs['objectClass']= $tmp;
843 /* Generate rid / primaryGroupId */
844 if ($this->samba3){
845 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
846 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
847 } else {
848 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
849 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
850 }
852 /* Need to generate a new uniqe uid/gid combination? */
853 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
854 $uidNumber= $this->uidNumber;
855 while(TRUE){
856 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
857 $ldap->cd($this->config->current['BASE']);
858 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
859 if ($ldap->count() == 0){
860 break;
861 }
862 $uidNumber++;
863 }
864 $this->attrs['sambaSID']= $sid;
866 /* Check for users primary group */
867 $ldap->cd($this->config->current['BASE']);
868 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
869 if ($ldap->count() != 1){
870 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
871 } else {
872 $attrs= $ldap->fetch();
873 $g= new group($this->config, $ldap->getDN());
874 if ($g->sambaSID == ""){
875 $g->sambaDomainName= $this->sambaDomainName;
876 $g->smbgroup= TRUE;
877 $g->save ();
878 }
879 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
880 }
881 }
883 if ($this->sambaHomeDrive == ""){
884 $this->attrs["sambaHomeDrive"]= array();
885 }
887 /* Generate munged dial value */
888 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
890 /* User wants me to fake the idMappings? This is useful for
891 making winbind resolve the user names in a reasonable amount
892 of time in combination with larger databases. */
893 if (isset($this->config->current['SAMBAIDMAPPING']) &&
894 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
895 $this->attrs['objectClass'][]= "sambaIdmapEntry";
896 }
899 /* Password expiery */
900 if ($this->password_expires == "1"){
901 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
902 } else {
903 $this->attrs['sambaPwdMustChange']= array();
904 }
905 /* Make sure not to save zero in sambaPwdLastset */
906 if ($this->sambaPwdLastSet != "0"){
907 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
908 } else {
909 $this->attrs['sambaPwdLastSet']= array();
910 }
911 /* Account expiery */
912 if ($this->logon_time_set == "1"){
913 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
914 } else {
915 $this->attrs['sambaLogonTime']= array();
916 }
917 if ($this->logoff_time_set == "1"){
918 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
919 } else {
920 $this->attrs['sambaLogoffTime']= array();
921 }
922 if ($this->kickoff_time_set == "1"){
923 # Add one day in unixtime format to be compatible with usrmgr
924 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
925 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
926 } else {
927 $this->attrs['sambaKickoffTime']= array();
928 }
929 } else {
930 /* Not samba3 */
931 $this->attrs['rid']= $this->uidNumber*2 + 1000;
932 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
934 if ($this->homeDrive == ""){
935 $this->attrs["homeDrive"]= array();
936 }
938 /* Password expiery */
939 if ($this->password_expires == "1"){
940 $this->attrs['pwdMustChange']= $this->pwdMustChange;
941 } else {
942 $this->attrs['pwdMustChange']= 2147483647;
943 }
944 /* Make sure not to save zero in pwdLastset */
945 if ($this->pwdLastSet != "0"){
946 $this->attrs['pwdLastSet']= $this->pwdLastSet;
947 } else {
948 $this->attrs['pwdLastSet']= array();
949 }
950 /* Account expiery */
951 if ($this->logon_time_set == "1"){
952 $this->attrs['logonTime']= $this->logonTime;
953 } else {
954 $this->attrs['logonTime']= array();
955 }
956 if ($this->logoff_time_set == "1"){
957 $this->attrs['logoffTime']= $this->logoffTime;
958 } else {
959 $this->attrs['logoffTime']= array();
960 }
961 if ($this->kickoff_time_set == "1"){
962 # Add one day in unixtime format to be compatible with usrmgr
963 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
964 } else {
965 $this->attrs['kickoffTime']= array();
966 }
967 }
969 /* Write back to ldap */
970 $ldap->cd($this->dn);
971 $this->cleanup();
972 $ldap->modify ($this->attrs);
974 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
976 /* Optionally execute a command after we're done */
977 if ($this->initially_was_account == $this->is_account){
978 if ($this->is_modified){
979 $this->handle_post_events("modify");
980 }
981 } else {
982 $this->handle_post_events("add");
983 }
985 }
987 function adapt_from_template($dn)
988 {
989 plugin::adapt_from_template($dn);
990 $this->sambaSID= "";
991 $this->sambaPrimaryGroupSID= "";
993 /* Fill mungedDial field */
994 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
995 $this->mungedObject->load($this->sambaMungedDial);
996 }
998 /* Password expiery */
999 if(isset($this->attrs['sambaPwdMustChange']) &&
1000 $this->attrs['sambaPwdMustChange'][0] != 0){
1001 $this->password_expires= 1;
1002 }
1004 if(isset($this->attrs['sambaLogonTime']) && ! (
1005 $this->attrs['sambaLogonTime'][0] == 0 ||
1006 $this->attrs['sambaLogonTime'][0] == 2147483647
1007 )){
1008 $this->logon_time_set= 1;
1009 }
1010 if(isset($this->attrs['sambaLogoffTime']) && ! (
1011 $this->attrs['sambaLogoffTime'][0] == 0 ||
1012 $this->attrs['sambaLogoffTime'][0] == 2147483647
1013 )){
1014 $this->logoff_time_set= 1;
1015 }
1017 /* Account expiery */
1018 if(isset($this->attrs['sambaKickoffTime']) && ! (
1019 $this->attrs['sambaKickoffTime'][0] == 0 ||
1020 $this->attrs['sambaKickoffTime'][0] == 2147483647
1021 )){
1022 $this->kickoff_time_set= 1;
1023 }
1025 /* Get global filter config */
1026 if (!is_global("sambafilter")){
1027 $ui= get_userinfo();
1028 $base= get_base_from_people($ui->dn);
1029 $sambafilter= array( "depselect" => $base, "regex" => "*");
1030 register_global("sambafilter", $sambafilter);
1031 }
1032 }
1035 function plInfo()
1036 {
1037 return (array("plDescription" => _("Samba settings"),
1038 "plSelfModify" => TRUE,
1039 "plDepends" => array("objectClass" => "gosaAccount"),
1041 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1042 "InheritClientConfig" => _("Inherit client config"),
1043 "sambaAcctFlags_N" => _("Login from windows client requires no password"),
1044 "sambaAcctFlags_L" => _("Lock samba account"),
1046 "sambaLogonTime" => _("Limit Logon Time") ,
1047 "sambaLogoffTime" => _("Limit Logoff Time") ,
1048 "sambaKickoffTime" => _("Account expires") ,
1049 "sambaPwdCanChange" => _("Allow user to change password") ,
1050 "sambaPwdMustChange" => _("Password expires") ,
1051 "sambaHomePath" => _("Generic home directory") ,
1052 "sambaHomeDrive" => _("Generic samba home drive") ,
1053 "sambaLogonScript" => _("Generic script path") ,
1054 "sambaProfilePath" => _("Generic profile path") ,
1055 "sambaDomainName" => _("Domain") ,
1056 "sambaUserWorkstations" => _("Allow connection from") ));
1057 }
1058 }
1060 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1061 ?>