1 <?php
3 class environment extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary = "Manage server basic objects";
7 var $cli_description = "Some longer text\nfor help";
8 var $cli_parameters = array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* attribute list for save action */
11 var $ignore_account = FALSE;
12 var $plHeadline = "Environment";
13 var $plDescription = "This does something";
14 var $dialog = false; // Indicates that we are currently editing in an seperate dialog
16 var $in_dialog = false;
17 var $uid = "";
19 var $is_group = false;
21 /* Attribute definition
22 */
24 /* profile management */
25 var $useProfile = false; // Specifies if we want to use a Server
26 var $gotoProfileServer = ""; // Specifies the selected profile server
27 var $gotoProfileServers = array();// Specifies all available and selectable servers
28 var $gotoProfileFlags = ""; // Flags enabled ? only used to set ACL and save
29 var $gotoProfileFlag_C = ""; // Flag is set to C if we have the profile caching fucntion enabled
31 var $gotoXResolution = "auto"; // The selected resolution eg: 1024x768
32 var $gotoXResolutions = array();// Contains all available resolutions for this account
33 var $gotoProfileFlag_L = ""; // Flag is set to L to enable runtime resolution change
34 var $gotoProfileQuota = ""; // User Quota Settings
36 /* Logon script section*/
37 var $gotoLogonScripts = array();// Contains all available Logon Scripts
38 var $gotoLogonScript = ""; // The selected Logon Script
40 /* Printer */
41 var $gotoPrinter = array();// All available Printer, with their configurations
42 var $gotoPrinterSel = ""; // The selected Printer
43 var $gosaDefaultPrinter = ""; // Default printer
45 /* Share */
46 var $gotoShares = array();// Current Share Options
47 var $gotoShare = ""; // currently selected Share Option
48 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
49 var $gotoAvailableShares= array();// Available Shares for this account
51 /* Kiosk profile */
52 var $gotoKioskProfile = "none"; // The selected Kiosk Profile
53 var $gotoKioskProfiles = array();// All available Kiosk profiles
54 var $newKioskProfiles = array();
56 /* Hotplug Devices */
57 var $gotoHotplugDevice = array(); // Selected hotplug
58 var $gotoHotplugDevices = array();// Already configured hotplug devices
61 /* general settings */
62 // Sets the attributes which will kept on page reload, which will be saved, ...
64 var $CopyPasteVars = array("gotoHotplugDevices","newKioskProfiles","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlag_L","gotoXResolutions","gotoProfileFlag_C","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn");
66 var $attributes = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDevice",
67 "gotoXResolution","gotoProfileQuota",
68 "gotoLogonScripts","gotoLogonScript",
69 "gotoPrinter", "gosaDefaultPrinter",
70 "gotoShares","gotoShare",
71 "gotoKioskProfile","gotoKioskProfiles"
72 );
73 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
74 var $cn;
75 var $OrigCn;
77 function environment ($config, $dn= NULL, $parent= NULL)
78 {
79 plugin::plugin ($config, $dn, $parent);
81 /* Check : Are we currently editing a group or user dialog */
82 if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
83 $suffix="Group";
84 $this->uid = $this->attrs['cn'][0];
85 $this->attrs['uid'] = $this->attrs['cn'][0];
86 $this->OrigCn = $this->attrs['cn'][0];
87 }else{
88 $suffix="User";
89 }
91 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
93 /* Get all Printer assignments */
94 $ldap = $this->config->get_ldap_link();
95 $ldap->cd($this->config->current['BASE']);
96 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
97 while($printer = $ldap->fetch()){
98 $this->gotoPrinter[$printer['cn'][0]]=$printer;
99 $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
100 }
101 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
102 while($printer = $ldap->fetch()){
103 $this->gotoPrinter[$printer['cn'][0]]=$printer;
104 $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
105 }
107 /* prepare hotplugs */
108 if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
109 unset($this->attrs['gotoHotplugDevice']['count']);
110 foreach($this->attrs['gotoHotplugDevice'] as $device){
111 $tmp = $tmp2 = array();
112 $tmp = split("\|",$device);
113 $tmp2['name'] = $tmp[0];
114 $tmp2['description'] = $tmp[1];
115 $tmp2['id'] = $tmp[2];
116 $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
117 }
118 }
120 /* prepare LogonScripts */
121 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
122 unset($this->attrs['gotoLogonScript']['count']);
123 foreach($this->attrs['gotoLogonScript'] as $device){
124 $tmp = $tmp2 = array();
125 $tmp = split("\|",$device);
126 $tmp2['LogonName'] = $tmp[0];
127 $tmp2['LogonPriority'] = $tmp[2];
128 if(preg_match("/O/i",$tmp[1])){
129 $tmp2['LogonOverload'] = "O";
130 }else{
131 $tmp2['LogonOverload'] = "";
132 }
133 if(preg_match("/L/i",$tmp[1])){
134 $tmp2['LogonLast'] = "L";
135 }else{
136 $tmp2['LogonLast'] = "";
137 }
138 $tmp2['LogonData'] = base64_decode($tmp[3]);
139 $tmp2['LogonDescription'] = $tmp[4];
140 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
141 }
142 }
144 /* Prepare Shares */
145 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
146 unset($this->attrs['gotoShare']['count']);
147 foreach($this->attrs['gotoShare'] as $share){
148 $tmp = $tmp2 = array();
149 $tmp = split("\|",$share);
150 $tmp2['server'] =$tmp[0];
151 $tmp2['name'] =$tmp[1];
153 /* Decode base64 if needed */
154 if (!preg_match('%/%', $tmp[2])){
155 $tmp2['mountPoint'] =base64_decode($tmp[2]);
156 } else {
157 $tmp2['mountPoint'] =$tmp[2];
158 }
160 if(isset($tmp[3])){
161 $tmp2['PwdHash'] =$tmp[3];
162 }else{
163 $tmp2['PwdHash'] ="";
164 }
165 if(isset($tmp[4])){
166 $tmp2['Username'] =$tmp[4];
167 }else{
168 $tmp2['Username'] ="";
169 }
170 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
171 }
172 }
174 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
175 $chr = $this->gotoProfileFlags[$i];
176 $name = "gotoProfileFlag_".$chr;
177 $this->$name=$chr;
178 }
180 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
181 $this->useProfile = true;
182 }else{
183 $this->useProfile = false;
184 }
186 /* Set resolutions */
187 $this->gotoXResolutions = array("auto"=>_("auto"),
188 "640x480" => "640x480",
189 "800x600" => "800x600",
190 "1024x768" => "1024x768",
191 "1152x864" => "1152x864",
192 "1280x768" => "1280x768",
193 "1280x1024" => "1280x1024");
195 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
196 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
198 if(is_readable($file)){
199 $str = file_get_contents($file);
200 $lines = split("\n",$str);
201 foreach($lines as $line){
202 $line = trim($line);
203 if(!empty($line)){
204 $this->gotoXResolutions[$line]=$line;
205 }
206 }
207 //natcasesort($this->gotoXResolutions);
208 }else{
209 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
210 }
211 }
214 $this->gotoProfileServers= $config->getShareServerList() ;
215 $this->gotoShareSelections= $config->getShareList(true);
216 $this->gotoAvailableShares= $config->getShareList(false);
218 }
221 /* Detect type of edited object (user|group)*/
222 function detect_grouptype()
223 {
224 if((!isset($this->parent))&&(!$this->is_account)){
225 $this->is_group = false;
226 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
227 $this->is_group = true;
228 }else{
229 $this->is_group = false;
230 }
231 }
234 function execute()
235 {
236 /* Call parent execute */
237 plugin::execute();
239 /* Fill templating stuff */
240 $smarty= get_smarty();
241 $display= "";
243 /* Prepare all variables for smarty */
244 foreach($this->attributes as $s_attr){
245 /* Set value*/
246 $smarty->assign($s_attr,$this->$s_attr);
248 /* Set checkbox state*/
249 if(empty($this->$s_attr)){
250 $smarty->assign($s_attr."CHK","");
251 }else{
252 $smarty->assign($s_attr."CHK"," checked ");
253 }
255 /* Prepare ACL settings*/
256 if(chkacl($this->acl,$s_attr)=="") {
257 $smarty->assign($s_attr."ACL","");
258 }else{
259 $smarty->assign($s_attr."ACL"," disabled ");
260 }
262 }
264 /* Is accout enabled | are we editing from usermenu or admin menu
265 All these tab management is done here
266 */
268 $this->detect_grouptype();
270 /* Working from Usermenu an the Account is currently disbled
271 * this->parent : is only set if we are working in a list of tabs
272 * is_account : is only true if the needed objectClass is given
273 */
274 if((!isset($this->parent))&&(!$this->is_account)){
275 /* We are currently editing this tab from usermenu, but this account is not enabled */
276 $smarty->assign("is_account",$this->is_account);
277 /* Load template */
278 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
279 /* Avoid the "You are currently editing ...." message when you leave this tab */
280 $display .= back_to_main();
281 /* Display our message to the user */
282 return $display;
285 /* We are currently editing from group tabs, because
286 * $this->parent is set
287 * posixAccount is not set, so we are not in usertabs.
288 */
289 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
290 $smarty->assign("is_account","true");
291 $this->uid = $this->cn;
292 $this->attrs['uid'] = $this->cn;
294 /* Change state if needed */
295 if (isset($_POST['modify_state'])){
296 $this->is_account= !$this->is_account;
297 }
299 /* Group Dialog with enabled environment options */
300 if ($this->is_account){
301 $display= $this->show_header(_("Remove environment extension"),
302 _("Environment extension enabled. You can disable it by clicking below."));
303 } else {
305 /* Environment is disabled
306 If theres is no posixAccount enabled, you won't be able to enable
307 environment extensions
308 */
309 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
310 // 4. There is a PosixAccount
311 $display= $this->show_header(_("Add environment extension"),
312 _("Environment extension disabled. You can enable it by clicking below."));
313 return $display;
314 }else{
315 // 4. There is no PosixAccount
316 $display= $this->show_header(_("Add environment extension"),
317 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
318 return $display;
319 }
320 }
321 }else{
322 /* Editing from Usermenu
323 * Tell smarty that this accoutn is enabled
324 */
325 $smarty->assign("is_account","true");
328 /* Do we need to flip is_account state? */
329 if (isset($_POST['modify_state'])){
330 $this->is_account= !$this->is_account;
331 }
333 if(isset($this->parent)){
335 // 3. Account enabled . Editing from adminmenu
336 if ($this->is_account){
337 $display= $this->show_header(_("Remove environment extension"),
338 _("Environment extension enabled. You can disable it by clicking below."));
339 } else {
341 if($this->parent->by_object['posixAccount']->is_account==true){
342 // 4. There is a PosixAccount
343 $display= $this->show_header(_("Add environment extension"),
344 _("Environment extension disabled. You can enable it by clicking below."));
345 return $display;
346 }else{
347 // 4. There is a PosixAccount
348 $display= $this->show_header(_("Add environment extension"),
349 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
350 return $display;
351 }
352 }
353 }
354 }
355 /* Account is Account : is_accounbt=true.
356 * Else we won't reach this.
357 */
359 /* Prepare all variables for smarty */
360 foreach($this->attributes as $s_attr){
361 /* Set value*/
362 $smarty->assign($s_attr,$this->$s_attr);
364 /* Set checkbox state*/
365 if(empty($this->$s_attr)){
366 $smarty->assign($s_attr."CHK","");
367 }else{
368 $smarty->assign($s_attr."CHK"," checked ");
369 }
371 /* Prepare ACL settings*/
372 if(chkacl($this->acl,$s_attr)=="") {
373 $smarty->assign($s_attr."ACL","");
374 }else{
375 $smarty->assign($s_attr."ACL"," disabled ");
376 }
378 }
380 foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
381 if(chkacl($this->acl,$s_attr)=="") {
382 $smarty->assign($s_attr."ACL","");
383 }else{
384 $smarty->assign($s_attr."ACL"," disabled ");
385 }
386 }
388 if(empty($this->useProfile)){
389 $smarty->assign("gotoProfileACL","disabled");
390 $smarty->assign("useProfileCHK","");
391 }else{
392 $smarty->assign("gotoProfileACL","");
393 $smarty->assign("useProfileCHK"," checked ");
394 }
397 $smarty->assign("useProfileACL","");
398 if($this->acl != "#none#"){
399 $smarty->assign("useProfileACL","");
400 $smarty->assign("gotoProfileFlag_CACL"," ");
401 $smarty->assign("gotoProfileQuotaACL"," ");
402 }else{
403 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
404 $smarty->assign("useProfileACL","disabled");
405 $smarty->assign("gotoProfileServer"," disabled ");
406 $smarty->assign("gotoProfileQuotaACL"," disabled ");
407 }
409 /* HANDLE Profile Settings here
410 * Assign available Quota and resolution settings
411 * Get all available profile server
412 * Get cache checkbox
413 * Assign this all to Smarty
414 */
416 if(empty($this->gotoProfileFlag_L)){
417 $smarty->assign("gotoProfileFlag_LCHK"," ");
418 }else{
419 $smarty->assign("gotoProfileFlag_LCHK"," checked ");
420 }
422 if(empty($this->gotoProfileFlag_C)){
423 $smarty->assign("gotoProfileFlag_CCHK"," ");
424 }else{
425 $smarty->assign("gotoProfileFlag_CCHK"," checked ");
426 }
429 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
430 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
432 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
433 if(!is_array($this->gotoProfileServers)){
434 $this->gotoProfileServers =array();
435 }
436 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
438 /* Handle kiosk profiles
439 * Read available from filesystem
440 * Open management if post is transmitted
441 */
443 /* Save */
444 if(isset($_POST['KioskClose'])){
445 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
447 unset($this->dialog);
448 $this->dialog=NULL;
449 $this->is_dialog = false;
450 }
452 /* Reassign help class */
453 $_SESSION['current_class_for_help'] = get_class($this);
455 /* Open Management Dialog */
456 if(isset($_POST['KioskManagementDialog'])){
457 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
458 $this->dialog->parent= $this;
459 $this->dialog->acl = $this->acl;
460 $this->is_dialog = true;
461 }
462 $tmp = new kioskManagementDialog($this->config,$this->dn);
463 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
464 $list['none']=_("None");
465 $list = array_reverse($list);
466 $smarty->assign("gotoKioskProfiles",$list);
467 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
469 /* Logonscript Management
470 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
471 * Perform add Delete edit Posts
472 */
474 /* Dialog Save */
475 if(isset($_POST['LogonSave'])){
476 $this->dialog->save_object();
477 if(count($this->dialog->check())!=0){
478 foreach($this->dialog->check() as $msg){
479 print_red($msg);
480 }
481 }else{
482 $tmp = $this->dialog->save();
483 unset($this->dialog);
484 $this->dialog=NULL;
485 $this->is_dialog=false;
486 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
487 }
488 }
490 /* Dialog Quit without saving */
491 if(isset($_POST['LogonCancel'])){
492 $this->is_dialog= false;
493 unset($this->dialog);
494 $this->dialog= NULL;
495 }
497 /* Check Edit Del New Posts for a selected LogonScript */
498 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
500 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
501 * In this case we create a new Logon Script.
502 */
503 if(isset($_POST['gotoLogonScriptNew'])){
504 $this->is_dialog = true;
505 $this->dialog = new logonManagementDialog($this->config,$this->dn);
506 }
508 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
509 * We only can delete if there is an entry selected.
510 */
511 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
512 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
513 }
515 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
516 * There must be an entry selected to perform edit request.
517 */
518 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
519 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
520 $this->is_dialog = true;
521 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
522 }
523 }
525 /* Append List to smarty*/
526 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
527 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
529 /* In this section server shares will be defined
530 * A user can select one of the given shares and a mount point
531 * and attach this combination to his setup.
532 */
534 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
535 if(!is_array($this->gotoShareSelections)){
536 print $this->gotoShareSelections;
537 $this->gotoShareSelections = array();
538 }
539 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
541 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
542 * This entry will be, a combination of mountPoint and sharedefinitions
543 */
544 if(isset($_POST['gotoShareAdd'])){
545 /* We assign a share to this user, if we don't know where to mount the share */
546 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
547 print_red(_("You must specify a valid mount point."));
548 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
549 print_red(_("Spaces are not allowed in the mount path!"));
550 }elseif(!(
551 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
552 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
553 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
554 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
555 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
556 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
557 preg_match("/^%/",$_POST['gotoShareMountPoint'])
558 )
559 ){
560 print_red(_("You must specify a valid mount point."));
561 }else{
562 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
563 $s_mount = $_POST['gotoShareMountPoint'];
564 $s_user = $_POST['ShareUser'];
565 /* Preparing the new assignment */
566 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
567 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
568 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
569 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
570 }
571 }
573 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
574 * If there is no defined share selected, we will abort the deletion without any message
575 */
576 $once = true;
577 foreach($_POST as $name => $value){
578 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
579 $once = false;
580 $key = preg_replace("/^gotoShareDel_/","",$name);
581 $key = preg_replace("/_+[xy]$/","",$key);
582 $key = base64_decode($key);
583 if(isset($this->gotoShares[$key])) {
584 unset($this->gotoShares[$key]);
585 }
587 /* Remove corresponding password entry, too. This is a workaround
588 to get rid of old-style entries. */
589 $key= base64_decode($key);
590 if(isset($this->gotoShares[$key])) {
591 unset($this->gotoShares[$key]);
592 }
594 }
595 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
596 $once = false;
597 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
598 $key = preg_replace("/_+[xy]$/","",$key);
599 $key = base64_decode($key);
600 $this->gotoShares[$key]['PwdHash'] = "";
601 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
602 unset($this->gotoShares[$key]);
603 }
604 }
605 }
607 $divlistShares = new divSelectBox("gotoShares");
608 $divlistShares->SetHeight(100);
609 $tmp = $this->printOutAssignedShares();
611 foreach($tmp as $key => $value){
612 $img = "";
614 /* Check if entry starts with an ! */
615 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
617 /* If we are currently editing groups environment, skip those ! entries */
618 if($this->is_group) continue;
620 /* Create pwd reset images */
621 if($this->gotoShares[$key]['PwdHash'] != ""){
622 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
623 title='"._("Reset password hash")."'>";
624 }
625 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
626 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
627 }else{
629 /* Create pwd reset img && delete image */
630 if($this->gotoShares[$key]['PwdHash'] != ""){
631 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
632 title='"._("Reset password hash")."'>";
633 $img.= " ";
634 }
635 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."'
636 title='"._("Delete share entry")."'>";
637 $field1 = array("string" => $value);
638 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
639 }
640 $divlistShares->AddEntry(array($field1,$field2));
641 }
642 $smarty->assign("divlistShares",$divlistShares->DrawList());
644 /* Hotplug devices will be handled here
645 * There are 3 possible methods for this feature
646 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
647 * Delete will erase an entry, the entry must be selcted in the ListBox first
648 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
649 */
651 /* If there is a new entry wanted, open a new entry by initilising the dialog */
652 if(isset($_POST['gotoHotplugDeviceNew'])){
653 $this->dialog = new hotplugDialog($this->config,$this->dn);
654 $this->is_dialog = true;
655 }
657 /* We have to delete the selected hotplug from the list*/
658 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
659 foreach($_POST['gotoHotplugDevice'] as $name){
660 unset($this->gotoHotplugDevices[$name]);
661 }
662 }
664 /* There are already defined hotplugs from other users we could use */
665 if(isset($_POST['gotoHotplugDeviceUse'])){
666 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
667 $this->is_dialog = true;
668 }
670 /* Dialog Aborted */
671 if(isset($_POST['HotPlugCancel'])){
672 unset($this->dialog);
673 $this->dialog= NULL;
674 $this->is_dialog = false;
675 }
677 /* Dialod saved */
678 if(isset($_POST['HotPlugSave'])){
679 $this->dialog->save_object();
680 if(count($this->dialog->check())!=0){
681 foreach($this->dialog->check() as $msg){
682 print_red($msg);
683 }
684 }else{
685 $this->dialog->save_object();
686 $a_tmp = $this->dialog->save();
688 if(is_array($a_tmp)){
689 foreach($a_tmp as $name => $hotplug){
690 $this->gotoHotplugDevices[$name]= $hotplug;
691 }
692 }
693 unset($this->dialog);
694 $this->dialog= NULL;
695 $this->is_dialog = false;
696 }
697 }
699 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
700 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
702 /* Printer Assignment will managed below
703 * A printer can be assigned in two different ways and two different types
704 * There are 2 types of users assigned to a printer : user and admin
705 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
706 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
707 */
709 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
710 if(isset($_POST['gotoPrinterAdd'])){
711 $this->is_dialog=true;
712 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
713 }
715 if(isset($_POST['PrinterCancel'])){
716 $this->is_dialog=false;
717 unset($this->dialog);
718 $this->dialog=NULL;
719 }
721 if(isset($_POST['PrinterSave'])){
722 if(count($this->dialog->check())!=0){
723 $tmp = $this->dialog->check();
724 foreach($tmp as $msg){
725 print_red($msg);
726 }
727 }else{
728 $this->dialog->save_object();
729 $tmp = $this->dialog->save();
730 $tmp2= $this->dialog->getPrinter(true);
732 foreach($tmp as $pname){
733 $this->gotoPrinter[$pname]=$tmp2[$pname];
734 $this->gotoPrinter[$pname]['mode']="user";
735 }
737 $this->is_dialog=false;
738 unset($this->dialog);
739 $this->dialog =NULL;
740 }
741 }
743 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
744 $printer = $_POST['gotoPrinterSel'];
745 foreach($printer as $pname){
746 unset($this->gotoPrinter[$pname]);
747 }
748 }
750 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
753 $printers = $_POST['gotoPrinterSel'];
755 foreach($printers as $printer){
756 if($this->gotoPrinter[$printer]['mode']=="user"){
757 $this->gotoPrinter[$printer]['mode']="admin";
758 }else{
759 $this->gotoPrinter[$printer]['mode']="user";
760 }
761 }
762 }
764 if(!$this->is_group){
765 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
766 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
767 $this->gosaDefaultPrinter= "";
768 } else {
769 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
770 }
771 }
772 }
774 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
775 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
777 /* General behavior */
778 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
779 $this->dialog->save_object();
780 $disp =$this->dialog->execute();
782 $tmp = new kioskManagementDialog($this->config,$this->dn);
783 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
784 $list['none']=_("None");
785 $list = array_reverse($list);
786 if(!isset($list[$this->gotoKioskProfile])){
787 print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
788 $this->gotoKioskProfile = 'none';
789 }
790 return($disp);
791 }
792 if($this->acl != "#none#"){
793 $smarty->assign("useProfileACL","");
794 }else{
795 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
796 $smarty->assign("gotoProfileServerACL"," disabled ");
797 $smarty->assign("gotoProfileQuotaACL"," disabled ");
798 }
800 if(!$this->useProfile){
801 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
802 $smarty->assign("gotoProfileServerACL"," disabled ");
803 $smarty->assign("gotoProfileQuotaACL"," disabled ");
804 }
806 $smarty->assign("is_group",$this->is_group);
808 /* Als smarty vars are set. Get smarty template and generate output */
809 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
810 return($display);
811 }
813 function remove_from_parent()
814 {
815 /* only if it was an account*/
816 if (!$this->initially_was_account){
817 return;
818 }
820 /* include global link_info */
821 $ldap= $this->config->get_ldap_link();
823 /* Remove and write to LDAP */
824 plugin::remove_from_parent();
826 /* Don't save our template variables */
827 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
829 /* Skip all these attributes */
830 foreach($skip as $del){
831 unset($this->attrs[$del]);
832 }
834 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
836 $ldap->cd($this->dn);
837 $this->cleanup();
838 $ldap->modify ($this->attrs);
840 show_ldap_error($ldap->get_error(), _("Removing environment information failed"));
842 /* Optionally execute a command after we're done */
843 $this->handle_post_events("remove",array("uid" => $this->uid));
844 }
847 /* Save data to object */
848 function save_object()
849 {
850 /* Get all Posted vars
851 * Setup checkboxes
852 */
854 if(isset($_POST['iamposted'])){
855 if(isset($_POST['useProfile'])){
856 $this->useProfile = true;
857 }else{
858 $this->useProfile = false;
859 }
860 if(isset($_POST['gotoProfileFlag_C'])){
861 $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
862 }else{
863 $this->gotoProfileFlag_C = false;
864 }
865 if(isset($_POST['gotoProfileFlag_L'])){
866 $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
867 }else{
868 $this->gotoProfileFlag_L = false;
869 }
871 $tmp= $this->gosaDefaultPrinter;
872 plugin::save_object();
873 foreach($this->attributes as $s_attr){
874 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
875 if(isset($_POST[$s_attr])){
876 $this->$s_attr = $_POST[$s_attr];
877 }else{
878 $this->$s_attr = false;
879 }
880 }
881 $this->gosaDefaultPrinter= $tmp;
882 }
883 }
886 /* Check supplied data */
887 function check()
888 {
889 /* Call common method to give check the hook */
890 $this->detect_grouptype();
891 $message= plugin::check();
893 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
894 $message[]=_("Please set a valid profile quota size.");
895 }
896 if(!isset($this->attrs['objectClass'])){
897 $this->attrs['objectClass']=array();
898 }
899 if(!$this->is_group){
900 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
901 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
902 }
903 }
904 return ($message);
905 }
908 /* Save to LDAP */
909 function save()
910 {
911 /* If group was renamed, all printer settings get lost
912 */
913 /* only save changed variables ....*/
914 if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
915 if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
916 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
917 $method="https://";
918 }else{
919 $method="http://";
920 }
922 $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
923 $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
924 }else{
925 $this->gotoKioskProfile= array();
926 }
928 plugin::save();
929 $ldap= $this->config->get_ldap_link();
931 $realyUsedAttrs= array();
933 $path = search_config($this->config->data,"environment", "KIOSKPATH");
934 /* Creating Kiosk Profiles */
935 foreach($this->newKioskProfiles as $file){
936 $contents = $file['contents'];
937 $fp = @fopen($path."/".$file['name'],"w");
938 if(!$fp){
939 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
940 }else{
941 fwrite($fp,$contents,strlen($contents));
942 }
943 @unlink($file['tmp_name']);
944 }
946 /* Save already used objectClasses */
947 $ocs = $this->attrs['objectClass'];
948 unset($ocs['count']);
949 $this->attrs = array();
950 $this->attrs['objectClass']= $ocs;
951 foreach($this->objectclasses as $objc){
952 if(!in_array($objc,$this->attrs['objectClass'])){
953 $this->attrs['objectClass'][]=$objc;
954 }
955 }
958 /* Save usersettings to Printer */
959 $skip_printer_changes = false;
960 if(chkacl($this->acl,"gotoPrinter")!=""){
961 $this->gotoPrinter = array();
962 $skip_printer_changes = true;
963 }
965 if(!$skip_printer_changes){
966 /* 1. Search all printers that have our uid/cn as member
967 * 2. Delete this uid/cn from every single entry and save it again.
968 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
969 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
970 */
971 $types = array( "gotoUserPrinter" => "AddUser",
972 "gotoGroupPrinter" => "AddGroup",
973 "gotoUserAdminPrinter" => "AddAdminUser",
974 "gotoGroupAdminPrinter" => "AddAdminGroup");
976 /* Detect type of edited object, sometimes this wasn't set correctly ... */
977 $this->detect_grouptype();
979 if($this->is_group){
980 $s_suffix = "Group";
981 $useVar = "cn";
982 }else{
983 $useVar = "uid";
984 $s_suffix = "User";
985 }
987 /* Remove old entries */
988 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
989 while($attr = $ldap->fetch()){
990 $printerObj = NULL;
991 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
992 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
993 $printerObj->by_object['printgeneric']->save();
994 }
996 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
997 while($attr = $ldap->fetch()){
998 $printerObj = NULL;
999 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
1000 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
1001 $printerObj->by_object['printgeneric']->save();
1002 }
1004 foreach($this->gotoPrinter as $printer){
1005 $printerObj = NULL;
1006 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
1008 if($printer['mode'] == "admin") {
1009 $attribute = "goto".$s_suffix."AdminPrinter";
1010 }else{
1011 $attribute = "goto".$s_suffix."Printer";
1012 }
1014 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1015 $printerObj->by_object['printgeneric']->save();
1016 }
1017 }
1019 /* Prepare HotPlug devices */
1020 $this->attrs['gotoHotplugDevice'] = array();
1021 foreach($this->gotoHotplugDevices as $name => $device){
1022 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
1023 }
1025 /* Prepare LogonScripts */
1026 $this->attrs['gotoLogonScript'] = array();
1027 foreach($this->gotoLogonScripts as $name => $script){
1028 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1029 $script['LogonOverload'].$script['LogonLast']."|".
1030 $script['LogonPriority']."|".
1031 base64_encode($script['LogonData'])."|".
1032 $script['LogonDescription'];
1033 }
1035 /* Prepare Shares */
1036 $this->attrs['gotoShare']=array();
1037 foreach($this->gotoShares as $name => $share){
1038 $mntp= $share['mountPoint'];
1039 if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1040 $mntp= base64_encode($mntp);
1041 }
1042 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1043 }
1046 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1047 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1049 foreach($saveThis as $tosave){
1050 if(!empty($this->$tosave)){
1051 $this->attrs[$tosave]=$this->$tosave;
1052 }else{
1053 $this->attrs[$tosave]=array();
1054 }
1055 }
1057 /* Prepare Flags */
1058 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
1059 if(empty($this->attrs['gotoProfileFlags'][0])){
1060 $this->attrs['gotoProfileFlags']=array();
1061 }
1063 if($this->useProfile == false){
1064 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1065 $this->attrs['gotoProfileServer']= array();
1066 }
1068 foreach($this->attributes as $s_attr){
1069 if(chkacl($this->acl,$s_attr)!="") {
1070 if(isset($this->attrs[$s_attr])){
1071 unset($this->attrs[$s_attr]);
1072 }
1073 }
1074 }
1076 $ldap->cat ($this->dn, array('dn'));
1077 if ($ldap->fetch()){
1078 $mode= "modify";
1079 } else {
1080 $mode= "add";
1081 $ldap->cd($this->config->current['BASE']);
1082 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1083 }
1085 $ldap->cd($this->dn);
1086 $this->cleanup();
1087 $ldap->$mode($this->attrs);
1088 show_ldap_error($ldap->get_error(), _("Adding environment information failed"));
1089 $this->handle_post_events($mode,array("uid"=>$this->uid));
1090 }
1092 /* Generate ListBox frindly output for the defined shares
1093 * Possibly Add or remove an attribute here,
1094 */
1095 function printOutAssignedShares()
1096 {
1097 $a_return = array();
1098 if(is_array($this->gotoShares)){
1099 foreach($this->gotoShares as $share){
1100 if(preg_match("/^!/",$share['server'])){
1101 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1102 }else{
1103 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1104 }
1105 }
1106 }
1107 return($a_return);
1108 }
1110 /* Generate ListBox frindly output for the definedhotplugs
1111 * Possibly Add or remove an attribute here,
1112 */
1113 function printOutHotPlugDevices()
1114 {
1115 $a_return= array();
1116 if(is_array($this->gotoHotplugDevices)){
1117 foreach($this->gotoHotplugDevices as $key=>$device){
1118 $a_return[$key] = $device['name']." - ".$device['id'];
1119 }
1120 }
1121 return($a_return);
1122 }
1124 /* Generates ListBox frienly output of used printer devices
1125 * Append ' - admin' if printer is used in admin mode
1126 */
1127 function printOutPrinterDevices()
1128 {
1129 $a_return = array();
1130 if(is_array($this->gotoPrinter)){
1131 foreach($this->gotoPrinter as $printer){
1132 if($printer['mode'] == "admin"){
1133 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1134 }else{
1135 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1136 }
1137 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1138 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1139 }
1140 }
1141 }
1142 return($a_return);
1143 }
1145 /* Generates ListBox frienly output of used logonscripts
1146 */
1147 function printOutLogonScripts()
1148 {
1149 $a_return = array();
1150 if(is_array($this->gotoLogonScripts)){
1151 foreach($this->gotoLogonScripts as $script){
1152 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1153 }
1154 }
1155 return($a_return);
1156 }
1157 }
1162 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1163 ?>