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 if ($this->sambaPwdMustChange=="0"){
237 $date= getdate();
238 } else {
239 $date= getdate($this->sambaPwdMustChange);
240 }
242 if ($this->sambaLogonTime=="2147483647" || $this->sambaLogonTime=="0"){
243 $sambaLogonTime_date= getdate();
244 } else {
245 $sambaLogonTime_date= getdate($this->sambaLogonTime);
246 }
248 if ($this->sambaLogoffTime=="2147483647" || $this->sambaLogoffTime=="0"){
249 $sambaLogoffTime_date= getdate();
250 } else {
251 $sambaLogoffTime_date= getdate($this->sambaLogoffTime);
252 }
254 if ($this->sambaKickoffTime=="2147483647" || $this->sambaKickoffTime=="0"){
255 $sambaKickoffTime_date= getdate();
256 } else {
257 $sambaKickoffTime_date= getdate($this->sambaKickoffTime);
258 }
260 /* Remove user workstations? */
261 if (isset($_POST["delete_ws"]) && isset($_POST['workstation_list'])){
263 if($this->acl_is_writeable("sambaUserWorkstations")){
265 $tmp= $this->sambaUserWorkstations;
266 foreach($_POST['workstation_list'] as $name){
267 $tmp= preg_replace("/$name/", '', $tmp);
268 $this->is_modified= TRUE;
269 }
270 $tmp= preg_replace('/,+/', ',', $tmp);
271 $this->sambaUserWorkstations= trim($tmp, ',');
272 }
273 }
275 /* Add user workstation? */
276 if (isset($_POST["add_ws"])){
277 if($this->acl_is_writeable("sambaUserWorkstations")){
278 $this->show_ws_dialog= TRUE;
279 $this->dialog= TRUE;
280 }
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("brokenconnmode", $this->mungedObject->getBrokenConn());
479 $smarty->assign("reconnmode", $this->mungedObject->getReConn());
481 if($_SESSION['js']){
482 /* Set form elements to disabled/enable state */
483 $smarty->assign("tsloginstate", $this->mungedObject->getTsLogin()?"":"disabled");
484 $smarty->assign("inheritstate", $this->mungedObject->getInheritMode()?"disabled":"");
485 }else{
486 $smarty->assign("tsloginstate", "");
487 $smarty->assign("inheritstate", "");
488 }
490 /* Set checkboxes to checked or unchecked state */
491 $smarty->assign("tslogin", $this->mungedObject->getTsLogin()?"checked":"");
492 $smarty->assign("inherit", $this->mungedObject->getInheritMode()?"checked":"");
493 $smarty->assign("connectclientdrives",
494 $this->mungedObject->getConnectClientDrives()?"checked":"");
495 $smarty->assign("connectclientprinters",
496 $this->mungedObject->getConnectClientPrinters()?"checked":"");
497 $smarty->assign("defaultprinter",
498 $this->mungedObject->getDefaultPrinter()?"checked":"");
499 $smarty->assign("CtxMaxConnectionTimeF",
500 $this->mungedObject->getCtxMaxConnectionTimeF()?"checked":"");
501 $smarty->assign("CtxMaxDisconnectionTimeF",
502 $this->mungedObject->getCtxMaxDisconnectionTimeF()?"checked":"");
503 $smarty->assign("CtxMaxIdleTimeF",
504 $this->mungedObject->getCtxMaxIdleTimeF()?"checked":"");
506 /* Fill sambaUserWorkstations */
507 $ws= split(",", $this->sambaUserWorkstations);
508 sort($ws);
510 /* Tidy checks for empty option, and smarty will produce one if array[0]="" */
511 if(($ws[0]=="")&&(count($ws)==1)) $ws=array();
514 $smarty->assign("workstations", $ws);
515 }
517 /* Variables */
518 foreach($this->attributes as $val){
519 $smarty->assign("$val", $this->$val);
520 }
522 /* 'sambaAcctFlags' checkboxes */
523 /* Check for 'lock-account'-flag: 'D' or 'L' */
524 if (is_integer(strpos($this->sambaAcctFlags, "D")) ||
525 is_integer(strpos($this->sambaAcctFlags, "L"))) {
526 $smarty->assign("flagsD", "checked");
527 } else {
528 $smarty->assign("flagsD", "");
529 }
531 /* Check for no_password_required flag 'N' */
532 if (is_integer(strpos($this->sambaAcctFlags, "N"))) {
533 $smarty->assign("flagsN", "checked");
534 } else {
535 $smarty->assign("flagsN", "");
536 }
538 /* 'normal' Checkboxes */
539 if ($this->pwdCanChange=="1"){
540 $smarty->assign("flagsP", "checked");
541 } else {
542 $smarty->assign("flagsP", "");
543 }
544 if ($this->password_expires=="1"){
545 $smarty->assign("flagsC", "checked");
546 } else {
547 $smarty->assign("flagsC", "");
548 }
549 if ($this->logon_time_set=="1"){
550 $smarty->assign("flagsT", "checked");
551 } else {
552 $smarty->assign("flagsT", "");
553 }
554 if ($this->logoff_time_set=="1"){
555 $smarty->assign("flagsO", "checked");
556 } else {
557 $smarty->assign("flagsO", "");
558 }
559 if ($this->kickoff_time_set=="1"){
560 $smarty->assign("flagsK", "checked");
561 } else {
562 $smarty->assign("flagsK", "");
563 }
566 /* In case of javascript, disable some fields on demand */
567 if ($this->samba3){
568 foreach($this->mungedObject->getOnDemandFlags() as $key => $value) {
569 $smarty->assign("$key", "$value");
570 }
571 }
573 /* Show main page */
574 if ($this->samba3){
575 $display.= $smarty->fetch (get_template_path('samba3.tpl', TRUE, dirname(__FILE__)));
576 } else {
577 $display.= $smarty->fetch (get_template_path('samba2.tpl', TRUE, dirname(__FILE__)));
578 }
580 return ($display);
581 }
583 function remove_from_parent()
584 {
585 /* Cancel if there's nothing to do here */
586 if (!$this->initially_was_account){
587 return;
588 }
590 /* include global link_info */
591 $ldap= $this->config->get_ldap_link();
593 plugin::remove_from_parent();
595 /* Keep uid attribute for gosaAccount */
596 unset($this->attrs['uid']);
597 unset($this->attrs['uidNumber']);
598 unset($this->attrs['gidNumber']);
599 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,
600 $this->attributes, "Save");
601 $ldap->cd($this->dn);
602 $this->cleanup();
603 $ldap->modify ($this->attrs);
605 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/samba account with dn '%s' failed."),$this->dn));
607 /* Optionally execute a command after we're done */
608 $this->handle_post_events("remove");
609 }
612 /* Check for input problems */
613 function check()
614 {
615 /* Call common method to give check the hook */
616 $message= plugin::check();
618 if ($this->samba3){
620 /* Strings */
621 foreach (array( "sambaHomePath" => _("Home directory"),
622 "sambaProfilePath" => _("Profile path")) as $key => $val){
623 if (!$this->mungedObject->is_samba_path($this->$key)){
624 $message[]= sprintf(_("The value specified as '%s' contains invalid characters!"), $val);
625 }
626 }
628 /* Numeric values */
629 foreach (array( "CtxMaxConnectionTime" => _("Connection"),
630 "CtxMaxDisconnectionTime" => _("Disconnection"),
631 "CtxMaxIdleTime" => _("IDLE")) as $key => $val){
633 if (isset($this->mungedObject->ctx[$key]) && !is_id($this->mungedObject->ctx[$key]) && $val != 0){
634 $message[]= sprintf(_("The timeout property '%s' is checked and contains invalid or no characters!"), $val);
635 }
636 }
638 /* Too many workstations? Windows usrmgr only supports eight */
639 if (substr_count($this->sambaUserWorkstations, ",") >= 8){
640 $message[]= _("The windows user manager only allows eight clients. You've specified more than eight.");
641 }
642 }
644 return ($message);
645 }
648 /* Save data to object */
649 function save_object()
650 {
653 /* We only care if we are on the sambaTab... */
654 if (isset($_POST['sambaTab'])){
655 plugin::save_object();
657 /* Take care about access options */
658 if ($this->acl_is_writeable("sambaAcctFlagsL") || ($this->acl_is_writeable("sambaAcctFlagsN"))){
659 if ($this->samba3){
660 $attrname= "sambaPwdCanChange";
661 } else {
662 $attrname= "pwdCanChange";
663 }
664 if (isset($_POST["allow_pwchange"]) && $_POST["allow_pwchange"] == 1){
665 $tmp= 1;
666 } else {
667 $tmp= 0;
668 }
669 if ($this->$attrname != $tmp){
670 $this->is_modified= TRUE;
671 }
672 $this->pwdCanChange= $tmp;
673 $this->sambaPwdCanChange= $tmp;
674 }
675 $tmp= "UX";
676 if (isset($_POST["no_password_required"])){
677 if ($_POST["no_password_required"] == 1){
678 $tmp.= "N";
679 }
680 }
681 if (isset($_POST["password_expires"])){
682 if ($_POST["password_expires"] == 1){
683 $this->password_expires= 1;
684 }
685 } else {
686 $this->password_expires= 0;
687 }
688 if (isset($_POST["temporary_disable"])){
689 if ($_POST["temporary_disable"] == 1){
690 if (is_integer(strpos($this->sambaAcctFlags, "L"))) {
691 $tmp.= "L";
692 } else {
693 $tmp.= "D";
694 }
695 }
696 }
697 if (isset($_POST["logon_time_set"])){
698 if ($_POST["logon_time_set"] == 1){
699 $this->logon_time_set= 1;
700 }
701 } else {
702 $this->logon_time_set= 0;
703 }
704 if (isset($_POST["logoff_time_set"])){
705 if ($_POST["logoff_time_set"] == 1){
706 $this->logoff_time_set= 1;
707 }
708 } else {
709 $this->logoff_time_set= 0;
710 }
711 if (isset($_POST["kickoff_time_set"])){
712 if ($_POST["kickoff_time_set"] == 1){
713 $this->kickoff_time_set= 1;
714 }
715 } else {
716 $this->kickoff_time_set= 0;
717 }
719 $fill= "";
720 for ($i= strlen($tmp); $i<12; $i++){
721 $fill.= " ";
722 }
724 $tmp= "[$tmp$fill]";
726 /* Only save if acl's are set */
727 if ($this->acl_is_writeable("sambaAcctFlagsL") || ($this->acl_is_writeable("sambaAcctFlagsN"))){
728 if ($this->samba3){
729 $attrname= "sambaAcctFlags";
730 } else {
731 $attrname= "acctFlags";
732 }
733 if ($this->$attrname != $tmp){
734 $this->is_modified= TRUE;
735 }
736 $this->$attrname= $tmp;
737 }
739 /* Save sambaDomain attribute */
740 if ($this->acl_is_writeable("sambaDomainName") && $this->samba3 && isset ($_POST['sambaDomainName'])){
741 $this->sambaDomainName= validate($_POST['sambaDomainName']);
742 }
744 /* Save CTX values */
745 if ($this->samba3){
747 /* Save obvious values */
748 foreach($this->ctxattributes as $val){
749 if (isset($_POST[$val]) && $this->acl_is_writeable("AllowLoginOnTerminalServer")){
750 if (get_magic_quotes_gpc()) {
751 $this->mungedObject->ctx[$val]= stripcslashes(validate($_POST[$val]));
752 } else {
753 $this->mungedObject->ctx[$val]= validate($_POST[$val]);
754 }
755 }
756 }
758 /* Save checkbox states. */
759 $this->mungedObject->setTsLogin(!isset($_POST['tslogin'])
760 && $this->acl_is_writeable("AllowLoginOnTerminalServer"));
761 // Need to do some index checking to avoid messages like "index ... not found"
762 if(isset($_POST['brokenconn'])) {
763 $this->mungedObject->setBrokenConn($_POST['brokenconn'] == '1'
764 && $this->acl_is_writeable("AllowLoginOnTerminalServer"));
765 }
766 if(isset($_POST['reconn'])) {
767 $this->mungedObject->setReConn($_POST['reconn'] == '1'
768 && $this->acl_is_writeable("AllowLoginOnTerminalServer"));
769 }
770 $this->mungedObject->setInheritMode(isset($_POST['inherit'])
771 && $this->acl_is_writeable("AllowLoginOnTerminalServer"));
772 $this->mungedObject->setCtxMaxConnectionTimeF(!isset($_POST['CtxMaxConnectionTimeF'])
773 && $this->acl_is_writeable("AllowLoginOnTerminalServer"));
774 $this->mungedObject->setCtxMaxDisconnectionTimeF(
775 !isset($_POST['CtxMaxDisconnectionTimeF'])
776 && $this->acl_is_writeable("AllowLoginOnTerminalServer"));
777 $this->mungedObject->setCtxMaxIdleTimeF(!isset($_POST['CtxMaxIdleTimeF'])
778 && $this->acl_is_writeable("AllowLoginOnTerminalServer"));
779 $this->mungedObject->setConnectClientDrives(isset($_POST['connectclientdrives'])
780 && $this->acl_is_writeable("AllowLoginOnTerminalServer"));
781 $this->mungedObject->setConnectClientPrinters(isset($_POST['connectclientprinters'])
782 && $this->acl_is_writeable("AllowLoginOnTerminalServer"));
783 $this->mungedObject->setDefaultPrinter(isset($_POST['defaultprinter'])
784 && $this->acl_is_writeable("AllowLoginOnTerminalServer"));
786 /* Save combo boxes. Takes two values */
787 if(isset($_POST['reconn'])) {
788 $this->mungedObject->setShadow(isset($_POST['shadow']) && $this->acl_is_writeable("AllowLoginOnTerminalServer"),$_POST['shadow']);
789 }
791 /* Check for changes */
792 if ($this->sambaMungedDial != $this->mungedObject->getMunged()){
793 $this->is_modified= TRUE;
794 }
795 }
796 }
797 }
800 /* Save to LDAP */
801 function save()
802 {
803 /* Load uid and gid of this 'dn' */
804 $ldap= $this->config->get_ldap_link();
805 $ldap->cat($this->dn, array('uidNumber', 'gidNumber'));
806 $tmp= $ldap->fetch();
807 $this->uidNumber= $tmp['uidNumber'][0];
808 $this->gidNumber= $tmp['gidNumber'][0];
810 plugin::save();
812 /* Remove objectClass for sambaIdmapEntry */
813 $tmp= array();
814 for ($i= 0; $i<count($this->attrs["objectClass"]); $i++){
815 if ($this->attrs['objectClass'][$i] != 'sambaIdmapEntry'){
816 $tmp[]= $this->attrs['objectClass'][$i];
817 }
818 }
819 $this->attrs['objectClass']= $tmp;
821 /* Generate rid / primaryGroupId */
822 if ($this->samba3){
823 if (!isset($this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'])){
824 print_red (_("Warning: This account has an undefined samba SID assigned. The problem can not be fixed by GOsa!"));
825 } else {
826 $this->SID= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['SID'];
827 $this->ridBase= $this->config->data['SERVERS']['SAMBA'][$this->sambaDomainName]['RIDBASE'];
828 }
830 /* Need to generate a new uniqe uid/gid combination? */
831 if ($this->sambaSID == "" || $this->orig_sambaDomainName != $this->sambaDomainName){
832 $uidNumber= $this->uidNumber;
833 while(TRUE){
834 $sid= $this->SID."-".($uidNumber*2 + $this->ridBase);
835 $ldap->cd($this->config->current['BASE']);
836 $ldap->search("(sambaSID=$sid)", array("sambaSID"));
837 if ($ldap->count() == 0){
838 break;
839 }
840 $uidNumber++;
841 }
842 $this->attrs['sambaSID']= $sid;
844 /* Check for users primary group */
845 $ldap->cd($this->config->current['BASE']);
846 $ldap->search("(&(objectClass=posixGroup)(gidNumber=".$this->gidNumber."))", array("cn"));
847 if ($ldap->count() != 1){
848 print_red(_("Warning: Can't identify users primary group - no conversion to a samba group possible!"));
849 } else {
850 $attrs= $ldap->fetch();
851 $g= new group($this->config, $ldap->getDN());
852 if ($g->sambaSID == ""){
853 $g->sambaDomainName= $this->sambaDomainName;
854 $g->smbgroup= TRUE;
855 $g->save ();
856 }
857 $this->attrs['sambaPrimaryGroupSID']= $g->sambaSID;
858 }
859 }
861 if ($this->sambaHomeDrive == ""){
862 $this->attrs["sambaHomeDrive"]= array();
863 }
865 /* Generate munged dial value */
866 $this->attrs["sambaMungedDial"]= $this->mungedObject->getMunged();
868 /* User wants me to fake the idMappings? This is useful for
869 making winbind resolve the user names in a reasonable amount
870 of time in combination with larger databases. */
871 if (isset($this->config->current['SAMBAIDMAPPING']) &&
872 preg_match('/true/i', $this->config->current['SAMBAIDMAPPING'])){
873 $this->attrs['objectClass'][]= "sambaIdmapEntry";
874 }
877 /* Password expiery */
878 if ($this->password_expires == "1"){
879 $this->attrs['sambaPwdMustChange']= $this->sambaPwdMustChange;
880 } else {
881 $this->attrs['sambaPwdMustChange']= array();
882 }
883 /* Make sure not to save zero in sambaPwdLastset */
884 if ($this->sambaPwdLastSet != "0"){
885 $this->attrs['sambaPwdLastSet']= $this->sambaPwdLastSet;
886 } else {
887 $this->attrs['sambaPwdLastSet']= array();
888 }
889 /* Account expiery */
890 if ($this->logon_time_set == "1"){
891 $this->attrs['sambaLogonTime']= $this->sambaLogonTime;
892 } else {
893 $this->attrs['sambaLogonTime']= array();
894 }
895 if ($this->logoff_time_set == "1"){
896 $this->attrs['sambaLogoffTime']= $this->sambaLogoffTime;
897 } else {
898 $this->attrs['sambaLogoffTime']= array();
899 }
900 if ($this->kickoff_time_set == "1"){
901 # Add one day in unixtime format to be compatible with usrmgr
902 //$this->attrs['sambaKickoffTime']= $this->sambaKickoffTime + 86400;
903 $this->attrs['sambaKickoffTime']= $this->sambaKickoffTime; //hickert
904 } else {
905 $this->attrs['sambaKickoffTime']= array();
906 }
907 } else {
908 /* Not samba3 */
909 $this->attrs['rid']= $this->uidNumber*2 + 1000;
910 $this->attrs['primaryGroupID']= $this->gidNumber*2 +1001;
912 if ($this->homeDrive == ""){
913 $this->attrs["homeDrive"]= array();
914 }
916 /* Password expiery */
917 if ($this->password_expires == "1"){
918 $this->attrs['pwdMustChange']= $this->pwdMustChange;
919 } else {
920 $this->attrs['pwdMustChange']= 2147483647;
921 }
922 /* Make sure not to save zero in pwdLastset */
923 if ($this->pwdLastSet != "0"){
924 $this->attrs['pwdLastSet']= $this->pwdLastSet;
925 } else {
926 $this->attrs['pwdLastSet']= array();
927 }
928 /* Account expiery */
929 if ($this->logon_time_set == "1"){
930 $this->attrs['logonTime']= $this->logonTime;
931 } else {
932 $this->attrs['logonTime']= array();
933 }
934 if ($this->logoff_time_set == "1"){
935 $this->attrs['logoffTime']= $this->logoffTime;
936 } else {
937 $this->attrs['logoffTime']= array();
938 }
939 if ($this->kickoff_time_set == "1"){
940 # Add one day in unixtime format to be compatible with usrmgr
941 $this->attrs['kickoffTime']= $this->kickoffTime + 86400;
942 } else {
943 $this->attrs['kickoffTime']= array();
944 }
945 }
947 /* Write back to ldap */
948 $ldap->cd($this->dn);
949 $this->cleanup();
950 $ldap->modify ($this->attrs);
952 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/samba account with dn '%s' failed."),$this->dn));
954 /* Optionally execute a command after we're done */
955 if ($this->initially_was_account == $this->is_account){
956 if ($this->is_modified){
957 $this->handle_post_events("modify");
958 }
959 } else {
960 $this->handle_post_events("add");
961 }
963 }
965 function adapt_from_template($dn)
966 {
967 plugin::adapt_from_template($dn);
968 $this->sambaSID= "";
969 $this->sambaPrimaryGroupSID= "";
971 /* Fill mungedDial field */
972 if ($this->samba3 && isset($this->attrs['sambaMungedDial'])){
973 $this->mungedObject->load($this->sambaMungedDial);
974 }
976 /* Password expiery */
977 if(isset($this->attrs['sambaPwdMustChange']) &&
978 $this->attrs['sambaPwdMustChange'][0] != 0){
979 $this->password_expires= 1;
980 }
982 if(isset($this->attrs['sambaLogonTime']) && ! (
983 $this->attrs['sambaLogonTime'][0] == 0 ||
984 $this->attrs['sambaLogonTime'][0] == 2147483647
985 )){
986 $this->logon_time_set= 1;
987 }
988 if(isset($this->attrs['sambaLogoffTime']) && ! (
989 $this->attrs['sambaLogoffTime'][0] == 0 ||
990 $this->attrs['sambaLogoffTime'][0] == 2147483647
991 )){
992 $this->logoff_time_set= 1;
993 }
995 /* Account expiery */
996 if(isset($this->attrs['sambaKickoffTime']) && ! (
997 $this->attrs['sambaKickoffTime'][0] == 0 ||
998 $this->attrs['sambaKickoffTime'][0] == 2147483647
999 )){
1000 $this->kickoff_time_set= 1;
1001 }
1003 /* Get global filter config */
1004 if (!is_global("sambafilter")){
1005 $ui= get_userinfo();
1006 $base= get_base_from_people($ui->dn);
1007 $sambafilter= array( "depselect" => $base, "regex" => "*");
1008 register_global("sambafilter", $sambafilter);
1009 }
1010 }
1013 function plInfo()
1014 {
1015 return (array(
1016 "plShortName" => _("Samba"),
1017 "plDescription" => _("Samba settings"),
1018 "plSelfModify" => TRUE,
1019 "plDepends" => array("user"),
1020 "plPriority" => 5, // Position in tabs
1021 "plSection" => "personal", // This belongs to personal
1022 "plCategory" => array("users"), // Add to following categories
1023 "plOptions" => array(),
1025 "plProvidedAcls" => array(
1026 "AllowLoginOnTerminalServer" => _("Allow login on terminal server"),
1027 "InheritClientConfig" => _("Inherit client config"),
1029 "sambaPwdCanChange" => _("Allow user to change password") ,
1030 "sambaAcctFlagsN" => _("Login from windows client requires no password"),
1031 "sambaAcctFlagsL" => _("Lock samba account"),
1034 "sambaKickoffTime" => _("Account expires") ,
1035 "sambaPwdMustChange" => _("Password expires") ,
1037 "sambaLogonTime" => _("Limit Logon Time") ,
1038 "sambaLogoffTime" => _("Limit Logoff Time") ,
1040 "sambaHomePath" => _("Generic home directory") ,
1041 "sambaHomeDrive" => _("Generic samba home drive") ,
1042 "sambaLogonScript" => _("Generic script path") ,
1043 "sambaProfilePath" => _("Generic profile path") ,
1044 "sambaDomainName" => _("Domain") ,
1045 "sambaUserWorkstations" => _("Allow connection from")))
1046 );
1047 }
1048 }
1050 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1051 ?>