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