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 $gotoProfileFlagC = ""; // 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 $gotoProfileFlagL = ""; // 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","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn");
66 var $attributes = array("uid","gotoProfileServer","gotoProfileFlags",
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)
78 {
79 plugin::plugin ($config, $dn);
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];
117 /* Produkt ID */
118 if(!isset($tmp[3])){
119 $tmp[3] = "";
120 }
121 /* Vendor ID */
122 if(!isset($tmp[4])){
123 $tmp[4] = "";
124 }
126 $tmp2['produkt'] = $tmp[3];
127 $tmp2['vendor'] = $tmp[4];
129 $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
130 }
131 }
133 /* prepare LogonScripts */
134 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
135 unset($this->attrs['gotoLogonScript']['count']);
136 foreach($this->attrs['gotoLogonScript'] as $device){
137 $tmp = $tmp2 = array();
138 $tmp = split("\|",$device);
139 $tmp2['LogonName'] = $tmp[0];
140 $tmp2['LogonPriority'] = $tmp[2];
141 if(preg_match("/O/i",$tmp[1])){
142 $tmp2['LogonOverload'] = "O";
143 }else{
144 $tmp2['LogonOverload'] = "";
145 }
146 if(preg_match("/L/i",$tmp[1])){
147 $tmp2['LogonLast'] = "L";
148 }else{
149 $tmp2['LogonLast'] = "";
150 }
151 $tmp2['LogonData'] = base64_decode($tmp[3]);
152 $tmp2['LogonDescription'] = $tmp[4];
153 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
154 }
155 }
157 /* Prepare Shares */
158 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
159 unset($this->attrs['gotoShare']['count']);
160 foreach($this->attrs['gotoShare'] as $share){
161 $tmp = $tmp2 = array();
162 $tmp = split("\|",$share);
163 $tmp2['server'] =$tmp[0];
164 $tmp2['name'] =$tmp[1];
166 /* Decode base64 if needed */
167 if (!preg_match('%/%', $tmp[2])){
168 $tmp2['mountPoint'] =base64_decode($tmp[2]);
169 } else {
170 $tmp2['mountPoint'] =$tmp[2];
171 }
173 if(isset($tmp[3])){
174 $tmp2['PwdHash'] =$tmp[3];
175 }else{
176 $tmp2['PwdHash'] ="";
177 }
178 if(isset($tmp[4])){
179 $tmp2['Username'] =$tmp[4];
180 }else{
181 $tmp2['Username'] ="";
182 }
183 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
184 }
185 }
187 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
188 $chr = $this->gotoProfileFlags[$i];
189 $name = "gotoProfileFlag".$chr;
190 $this->$name=$chr;
191 }
193 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
194 $this->useProfile = true;
195 }else{
196 $this->useProfile = false;
197 }
199 /* Set to group environment if we editing a group */
200 if(!isset($this->parent)){
201 $this->is_group = true;
202 }
204 /* Set resolutions */
205 $this->gotoXResolutions = array("auto"=>_("auto"),
206 "640x480" => "640x480",
207 "800x600" => "800x600",
208 "1024x768" => "1024x768",
209 "1152x864" => "1152x864",
210 "1280x768" => "1280x768",
211 "1280x1024" => "1280x1024");
213 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
214 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
216 if(is_readable($file)){
217 $str = file_get_contents($file);
218 $lines = split("\n",$str);
219 foreach($lines as $line){
220 $line = trim($line);
221 if(!empty($line)){
222 $this->gotoXResolutions[$line]=$line;
223 }
224 }
225 //natcasesort($this->gotoXResolutions);
226 }else{
227 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
228 }
229 }
232 $this->gotoProfileServers= $config->getShareServerList() ;
233 $this->gotoShareSelections= $config->getShareList(true);
234 $this->gotoAvailableShares= $config->getShareList(false);
236 }
238 function execute()
239 {
240 /* Call parent execute */
241 plugin::execute();
243 /* Fill templating stuff */
244 $smarty= get_smarty();
245 $display= "";
247 /* Prepare all variables for smarty */
248 foreach($this->attributes as $s_attr){
249 /* Set value*/
250 $smarty->assign($s_attr,$this->$s_attr);
252 /* Set checkbox state*/
253 if(empty($this->$s_attr)){
254 $smarty->assign($s_attr."CHK","");
255 }else{
256 $smarty->assign($s_attr."CHK"," checked ");
257 }
259 /* Prepare ACL settings*/
260 $smarty->assign($s_attr."ACL",$this->getacl($s_attr));
261 }
263 /* Is accout enabled | are we editing from usermenu or admin menu
264 All these tab management is done here
265 */
267 /* Working from Usermenu an the Account is currently disbled
268 * this->parent : is only set if we are working in a list of tabs
269 * is_account : is only true if the needed objectClass is given
270 */
271 if((!isset($this->parent))&&(!$this->is_account)){
272 /* We are currently editing this tab from usermenu, but this account is not enabled */
273 $smarty->assign("is_account",$this->is_account);
274 /* Load template */
275 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
276 /* Avoid the "You are currently editing ...." message when you leave this tab */
277 $display .= back_to_main();
278 /* Display our message to the user */
279 return $display;
282 /* We are currently editing from group tabs, because
283 * $this->parent is set
284 * posixAccount is not set, so we are not in usertabs.
285 */
286 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
287 $smarty->assign("is_account","true");
288 $this->is_group = true;
289 $this->uid = $this->cn;
290 $this->attrs['uid'] = $this->cn;
292 /* Change state if needed */
293 if (isset($_POST['modify_state'])){
294 $this->is_account= !$this->is_account;
295 }
297 /* Group Dialog with enabled environment options */
298 if ($this->is_account){
299 $display= $this->show_enable_header(_("Remove environment extension"),
300 _("Environment extension enabled. You can disable it by clicking below."));
301 } else {
303 /* Environment is disabled
304 If theres is no posixAccount enabled, you won't be able to enable
305 environment extensions
306 */
307 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
308 // 4. There is a PosixAccount
309 $display= $this->show_enable_header(_("Add environment extension"),
310 _("Environment extension disabled. You can enable it by clicking below."));
311 return $display;
312 }else{
313 // 4. There is no PosixAccount
314 $display= $this->show_enable_header(_("Add environment extension"),
315 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
316 return $display;
317 }
318 }
319 }else{
320 /* Editing from Usermenu
321 * Tell smarty that this accoutn is enabled
322 */
323 $smarty->assign("is_account","true");
325 $this->is_group = false;
327 /* Do we need to flip is_account state? */
328 if (isset($_POST['modify_state'])){
329 $this->is_account= !$this->is_account;
330 }
332 if(isset($this->parent)){
334 // 3. Account enabled . Editing from adminmenu
335 if ($this->is_account){
336 $display= $this->show_disable_header(_("Remove environment extension"),
337 _("Environment extension enabled. You can disable it by clicking below."));
338 } else {
340 if($this->parent->by_object['posixAccount']->is_account==true){
341 // 4. There is a PosixAccount
342 $display= $this->show_disable_header(_("Add environment extension"),
343 _("Environment extension disabled. You can enable it by clicking below."));
344 return $display;
345 }else{
346 // 4. There is a PosixAccount
347 $display= $this->show_disable_header(_("Add environment extension"),
348 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
349 return $display;
350 }
351 }
352 }
353 }
354 /* Account is Account : is_accounbt=true.
355 * Else we won't reach this.
356 */
358 /* Prepare all variables for smarty */
359 foreach($this->attributes as $s_attr){
360 /* Set value*/
361 $smarty->assign($s_attr,$this->$s_attr);
363 /* Set checkbox state*/
364 if(empty($this->$s_attr)){
365 $smarty->assign($s_attr."CHK","");
366 }else{
367 $smarty->assign($s_attr."CHK"," checked ");
368 }
370 /* Prepare ACL settings*/
371 $smarty->assign($s_attr."ACL",$this->getacl($s_attr));
373 }
375 foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
376 $smarty->assign($s_attr."ACL",$this->getacl($s_attr));
377 }
379 if(empty($this->useProfile)){
380 $smarty->assign("useProfileCHK","");
381 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer")));
382 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota")));
383 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC")));
384 }else{
385 $smarty->assign("useProfileCHK"," checked ");
386 }
389 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer").$this->getacl("gotoProfileQuota"));
391 /* HANDLE Profile Settings here
392 * Assign available Quota and resolution settings
393 * Get all available profile server
394 * Get cache checkbox
395 * Assign this all to Smarty
396 */
398 if(empty($this->gotoProfileFlagL)){
399 $smarty->assign("gotoProfileFlagLCHK"," ");
400 }else{
401 $smarty->assign("gotoProfileFlagLCHK"," checked ");
402 }
404 if(empty($this->gotoProfileFlagC)){
405 $smarty->assign("gotoProfileFlagCCHK"," ");
406 }else{
407 $smarty->assign("gotoProfileFlagCCHK"," checked ");
408 }
411 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
412 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
414 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
415 if(!is_array($this->gotoProfileServers)){
416 $this->gotoProfileServers =array();
417 }
418 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
420 /* Handle kiosk profiles
421 * Read available from filesystem
422 * Open management if post is transmitted
423 */
425 /* Save */
426 if(isset($_POST['KioskClose'])){
427 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
429 unset($this->dialog);
430 $this->dialog=NULL;
431 $this->is_dialog = false;
432 }
434 /* Reassign help class */
435 $_SESSION['current_class_for_help'] = get_class($this);
437 /* Open Management Dialog */
438 if(isset($_POST['KioskManagementDialog'])){
439 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
440 $this->dialog->parent= $this;
441 $this->dialog->acl = $this->acl;
442 $this->is_dialog = true;
443 }
444 $tmp = new kioskManagementDialog($this->config,$this->dn);
445 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
446 $list['none']=_("None");
447 $list = array_reverse($list);
448 $smarty->assign("gotoKioskProfiles",$list);
449 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
451 /* Logonscript Management
452 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
453 * Perform add Delete edit Posts
454 */
456 /* Dialog Save */
457 if(isset($_POST['LogonSave'])){
458 $this->dialog->save_object();
459 if(count($this->dialog->check())!=0){
460 foreach($this->dialog->check() as $msg){
461 print_red($msg);
462 }
463 }else{
464 $tmp = $this->dialog->save();
465 unset($this->dialog);
466 $this->dialog=NULL;
467 $this->is_dialog=false;
468 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
469 }
470 }
472 /* Dialog Quit without saving */
473 if(isset($_POST['LogonCancel'])){
474 $this->is_dialog= false;
475 unset($this->dialog);
476 $this->dialog= NULL;
477 }
479 /* Check Edit Del New Posts for a selected LogonScript */
480 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
482 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
483 * In this case we create a new Logon Script.
484 */
485 if(isset($_POST['gotoLogonScriptNew'])){
486 $this->is_dialog = true;
487 $this->dialog = new logonManagementDialog($this->config,$this->dn);
488 }
490 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
491 * We only can delete if there is an entry selected.
492 */
493 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
494 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
495 }
497 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
498 * There must be an entry selected to perform edit request.
499 */
500 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
501 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
502 $this->is_dialog = true;
503 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
504 }
505 }
507 /* Append List to smarty*/
508 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
509 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
511 /* In this section server shares will be defined
512 * A user can select one of the given shares and a mount point
513 * and attach this combination to his setup.
514 */
516 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
517 if(!is_array($this->gotoShareSelections)){
518 print $this->gotoShareSelections;
519 $this->gotoShareSelections = array();
520 }
521 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
523 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
524 * This entry will be, a combination of mountPoint and sharedefinitions
525 */
526 if(isset($_POST['gotoShareAdd'])){
527 /* We assign a share to this user, if we don't know where to mount the share */
528 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
529 print_red(_("You must specify a valid mount point."));
530 }elseif(!(
531 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
532 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
533 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
534 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
535 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
536 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
537 preg_match("/^%/",$_POST['gotoShareMountPoint'])
538 )
539 ){
540 print_red(_("You must specify a valid mount point."));
541 }else{
542 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
543 $s_mount = $_POST['gotoShareMountPoint'];
544 $s_user = $_POST['ShareUser'];
545 /* Preparing the new assignment */
546 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
547 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
548 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
549 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
550 }
551 }
553 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
554 * If there is no defined share selected, we will abort the deletion without any message
555 */
556 $once = true;
557 foreach($_POST as $name => $value){
558 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
559 $once = false;
560 $key = preg_replace("/^gotoShareDel_/","",$name);
561 $key = preg_replace("/_+[xy]$/","",$key);
562 $key = base64_decode($key);
563 if(isset($this->gotoShares[$key])) {
564 unset($this->gotoShares[$key]);
565 }
567 /* Remove corresponding password entry, too. This is a workaround
568 to get rid of old-style entries. */
569 $key= preg_replace("/\|/", "|!", $key);
570 if(isset($this->gotoShares[$key])) {
571 unset($this->gotoShares[$key]);
572 }
573 }
574 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
575 $once = false;
576 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
577 $key = preg_replace("/_+[xy]$/","",$key);
578 $key = base64_decode($key);
579 $this->gotoShares[$key]['PwdHash'] = "";
580 }
581 }
583 $divlistShares = new divSelectBox("gotoShares");
584 $divlistShares->SetHeight(100);
585 $tmp = $this->printOutAssignedShares();
587 foreach($tmp as $key => $value){
588 $img = "";
590 /* Check if entry starts with an ! */
591 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
593 /* If we are currently editing groups environment, skip those ! entries */
594 if($this->is_group) continue;
596 /* Create pwd reset images */
597 if($this->gotoShares[$key]['PwdHash'] != ""){
598 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
599 title='"._("Reset password hash")."'>";
600 }
601 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
602 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
603 }else{
605 /* Create pwd reset img && delete image */
606 if($this->gotoShares[$key]['PwdHash'] != ""){
607 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
608 title='"._("Reset password hash")."'>";
609 $img.= " ";
610 }
611 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."'
612 title='"._("Delete share entry")."'>";
613 $field1 = array("string" => $value);
614 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
615 }
616 $divlistShares->AddEntry(array($field1,$field2));
617 }
618 $smarty->assign("divlistShares",$divlistShares->DrawList());
620 /* Hotplug devices will be handled here
621 * There are 3 possible methods for this feature
622 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
623 * Delete will erase an entry, the entry must be selcted in the ListBox first
624 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
625 */
627 /* If there is a new entry wanted, open a new entry by initilising the dialog */
628 if(isset($_POST['gotoHotplugDeviceNew'])){
629 $this->dialog = new hotplugDialog($this->config,$this->dn);
630 $this->is_dialog = true;
631 }
633 /* We have to delete the selected hotplug from the list*/
634 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
635 foreach($_POST['gotoHotplugDevice'] as $name){
636 unset($this->gotoHotplugDevices[$name]);
637 }
638 }
640 /* There are already defined hotplugs from other users we could use */
641 if(isset($_POST['gotoHotplugDeviceUse'])){
642 $tmp =array();
643 foreach($this->gotoHotplugDevices as $plugs){
644 $tmp[] = $plugs['name'];
645 }
646 $this->dialog = new hotplugDialog($this->config,$this->dn,true,$tmp);
647 $this->is_dialog = true;
648 }
650 /* Dialog Aborted */
651 if(isset($_POST['HotPlugCancel'])){
652 unset($this->dialog);
653 $this->dialog= NULL;
654 $this->is_dialog = false;
655 }
657 /* Dialod saved */
658 if(isset($_POST['HotPlugSave'])){
659 $this->dialog->save_object();
660 if(count($this->dialog->check())!=0){
661 foreach($this->dialog->check() as $msg){
662 print_red($msg);
663 }
664 }else{
665 $this->dialog->save_object();
666 $a_tmp = $this->dialog->save();
668 if(is_array($a_tmp)){
669 foreach($a_tmp as $name => $hotplug){
670 $this->gotoHotplugDevices[$name]= $hotplug;
671 }
672 }
673 unset($this->dialog);
674 $this->dialog= NULL;
675 $this->is_dialog = false;
676 }
677 }
679 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
680 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
682 /* Printer Assignment will managed below
683 * A printer can be assigned in two different ways and two different types
684 * There are 2 types of users assigned to a printer : user and admin
685 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
686 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
687 */
689 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
690 if(isset($_POST['gotoPrinterAdd'])){
691 $this->is_dialog=true;
692 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
693 }
695 if(isset($_POST['PrinterCancel'])){
696 $this->is_dialog=false;
697 unset($this->dialog);
698 $this->dialog=NULL;
699 }
701 if(isset($_POST['PrinterSave'])){
702 if(count($this->dialog->check())!=0){
703 $tmp = $this->dialog->check();
704 foreach($tmp as $msg){
705 print_red($msg);
706 }
707 }else{
708 $this->dialog->save_object();
709 $tmp = $this->dialog->save();
710 $tmp2= $this->dialog->getPrinter(true);
712 foreach($tmp as $pname){
713 $this->gotoPrinter[$pname]=$tmp2[$pname];
714 $this->gotoPrinter[$pname]['mode']="user";
715 }
717 $this->is_dialog=false;
718 unset($this->dialog);
719 $this->dialog =NULL;
720 }
721 }
723 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
724 $printer = $_POST['gotoPrinterSel'];
725 foreach($printer as $pname){
726 unset($this->gotoPrinter[$pname]);
727 }
728 }
730 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
733 $printers = $_POST['gotoPrinterSel'];
735 foreach($printers as $printer){
736 if($this->gotoPrinter[$printer]['mode']=="user"){
737 $this->gotoPrinter[$printer]['mode']="admin";
738 }else{
739 $this->gotoPrinter[$printer]['mode']="user";
740 }
741 }
742 }
744 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
745 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
746 $this->gosaDefaultPrinter= "";
747 } else {
748 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
749 }
750 }
752 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
753 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
755 /* General behavior */
756 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
757 $this->dialog->save_object();
758 $disp =$this->dialog->execute();
760 $tmp = new kioskManagementDialog($this->config,$this->dn);
761 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
762 $list['none']=_("None");
763 $list = array_reverse($list);
764 if(!isset($list[$this->gotoKioskProfile])){
765 print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
766 $this->gotoKioskProfile = 'none';
767 }
768 return($disp);
769 }
771 /* Als smarty vars are set. Get smarty template and generate output */
772 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
773 return($display);
774 }
776 function remove_from_parent()
777 {
778 /* only if it was an account*/
779 if (!$this->initially_was_account){
780 return;
781 }
783 /* include global link_info */
784 $ldap= $this->config->get_ldap_link();
786 /* Remove and write to LDAP */
787 plugin::remove_from_parent();
789 /* Don't save our template variables */
790 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
792 /* Skip all these attributes */
793 foreach($skip as $del){
794 unset($this->attrs[$del]);
795 }
797 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
799 $ldap->cd($this->dn);
800 $this->cleanup();
801 $ldap->modify ($this->attrs);
803 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
805 /* Optionally execute a command after we're done */
806 $this->handle_post_events("remove");
807 }
810 /* Save data to object */
811 function save_object()
812 {
813 /* Get all Posted vars
814 * Setup checkboxes
815 */
817 if(isset($_POST['iamposted'])){
818 if(isset($_POST['useProfile'])){
819 $this->useProfile = true;
820 }else{
821 $this->useProfile = false;
822 }
823 if(isset($_POST['gotoProfileFlagC'])){
824 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
825 }else{
826 $this->gotoProfileFlagC = false;
827 }
828 if(isset($_POST['gotoProfileFlagL'])){
829 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
830 }else{
831 $this->gotoProfileFlagL = false;
832 }
834 $tmp= $this->gosaDefaultPrinter;
835 plugin::save_object();
836 foreach($this->attributes as $s_attr){
837 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
838 if(isset($_POST[$s_attr])){
839 $this->$s_attr = $_POST[$s_attr];
840 }else{
841 $this->$s_attr = false;
842 }
843 }
844 $this->gosaDefaultPrinter= $tmp;
845 }
846 }
849 /* Check supplied data */
850 function check()
851 {
852 /* Call common method to give check the hook */
853 $message= plugin::check();
855 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
856 $message[]=_("Please set a valid profile quota size.");
857 }
858 if(!isset($this->attrs['objectClass'])){
859 $this->attrs['objectClass']=array();
860 }
861 if(!$this->is_group){
862 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
863 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
864 }
865 }
866 return ($message);
867 }
870 /* Save to LDAP */
871 function save()
872 {
873 /* If group was renamed, all printer settings get lost
874 */
875 /* only save changed variables ....*/
876 if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
877 if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
878 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
879 $method="https://";
880 }else{
881 $method="http://";
882 }
884 $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
885 $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
886 }else{
887 $this->gotoKioskProfile= array();
888 }
890 plugin::save();
891 $ldap= $this->config->get_ldap_link();
893 $realyUsedAttrs= array();
895 $path = search_config($this->config->data,"environment", "KIOSKPATH");
896 /* Creating Kiosk Profiles */
897 foreach($this->newKioskProfiles as $file){
898 $contents = $file['contents'];
899 $fp = @fopen($path."/".$file['name'],"w");
900 if(!$fp){
901 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
902 }else{
903 fwrite($fp,$contents,strlen($contents));
904 }
905 @unlink($file['tmp_name']);
906 }
908 /* Save already used objectClasses */
909 $ocs = $this->attrs['objectClass'];
910 unset($ocs['count']);
911 $this->attrs = array();
912 $this->attrs['objectClass']= $ocs;
913 foreach($this->objectclasses as $objc){
914 if(!in_array($objc,$this->attrs['objectClass'])){
915 $this->attrs['objectClass'][]=$objc;
916 }
917 }
919 /* 1. Search all printers that have our uid/cn as member
920 * 2. Delete this uid/cn from every single entry and save it again.
921 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
922 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
923 */
924 $types = array( "gotoUserPrinter" => "AddUser",
925 "gotoGroupPrinter" => "AddGroup",
926 "gotoUserAdminPrinter" => "AddAdminUser",
927 "gotoGroupAdminPrinter" => "AddAdminGroup");
929 if($this->is_group){
930 $s_suffix = "Group";
931 $useVar = "cn";
932 }else{
933 $useVar = "uid";
934 $s_suffix = "User";
935 }
937 /* Remove old entries */
938 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
939 while($attr = $ldap->fetch()){
940 $printerObj = NULL;
941 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
942 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
943 $printerObj->by_object['printgeneric']->save();
944 }
946 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
947 while($attr = $ldap->fetch()){
948 $printerObj = NULL;
949 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
950 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
951 $printerObj->by_object['printgeneric']->save();
952 }
954 foreach($this->gotoPrinter as $printer){
955 $printerObj = NULL;
956 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
958 if($printer['mode'] == "admin") {
959 $attribute = "goto".$s_suffix."AdminPrinter";
960 }else{
961 $attribute = "goto".$s_suffix."Printer";
962 }
964 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
965 $printerObj->by_object['printgeneric']->save();
966 }
968 /* Prepare HotPlug devices */
969 $this->attrs['gotoHotplugDevice'] = array();
970 foreach($this->gotoHotplugDevices as $name => $device){
971 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'].
972 "|".$device['produkt']."|".$device['vendor'];
973 }
975 /* Prepare LogonScripts */
976 $this->attrs['gotoLogonScript'] = array();
977 foreach($this->gotoLogonScripts as $name => $script){
978 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
979 $script['LogonOverload'].$script['LogonLast']."|".
980 $script['LogonPriority']."|".
981 base64_encode($script['LogonData'])."|".
982 $script['LogonDescription'];
983 }
985 /* Prepare Shares */
986 $this->attrs['gotoShare']=array();
987 foreach($this->gotoShares as $name => $share){
988 $mntp= $share['mountPoint'];
989 if (!preg_match('=^[a-z0-9+_/%-]+$=i', $mntp)){
990 $mntp= base64_encode($mntp);
991 }
992 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
993 }
996 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
997 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
999 foreach($saveThis as $tosave){
1000 if(!empty($this->$tosave)){
1001 $this->attrs[$tosave]=$this->$tosave;
1002 }else{
1003 $this->attrs[$tosave]=array();
1004 }
1005 }
1007 /* Prepare Flags */
1008 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1009 if(empty($this->attrs['gotoProfileFlags'][0])){
1010 $this->attrs['gotoProfileFlags']=array();
1011 }
1013 if($this->useProfile == false){
1014 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1015 $this->attrs['gotoProfileServer']= array();
1016 }
1018 $ldap->cat ($this->dn, array('dn'));
1019 if ($ldap->fetch()){
1020 $mode= "modify";
1021 } else {
1022 $mode= "add";
1023 $ldap->cd($this->config->current['BASE']);
1024 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1025 }
1027 $ldap->cd($this->dn);
1028 $this->cleanup();
1029 $ldap->$mode($this->attrs);
1030 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1031 $this->handle_post_events($mode);
1032 }
1034 /* Generate ListBox frindly output for the defined shares
1035 * Possibly Add or remove an attribute here,
1036 */
1037 function printOutAssignedShares()
1038 {
1039 $a_return = array();
1040 if(is_array($this->gotoShares)){
1041 foreach($this->gotoShares as $share){
1042 if(preg_match("/^!/",$share['server'])){
1043 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1044 }else{
1045 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1046 }
1047 }
1048 natcasesort($a_return);
1049 }
1050 return($a_return);
1051 }
1053 /* Generate ListBox frindly output for the definedhotplugs
1054 * Possibly Add or remove an attribute here,
1055 */
1056 function printOutHotPlugDevices()
1057 {
1058 $a_return= array();
1059 if(is_array($this->gotoHotplugDevices)){
1060 foreach($this->gotoHotplugDevices as $key=>$device){
1061 $a_return[$key] = $device['name']." - ".$device['id'];
1062 }
1063 }
1064 return($a_return);
1065 }
1067 /* Generates ListBox frienly output of used printer devices
1068 * Append ' - admin' if printer is used in admin mode
1069 */
1070 function printOutPrinterDevices()
1071 {
1072 $a_return = array();
1073 if(is_array($this->gotoPrinter)){
1074 foreach($this->gotoPrinter as $printer){
1075 if($printer['mode'] == "admin"){
1076 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1077 }else{
1078 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1079 }
1080 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1081 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1082 }
1083 }
1084 }
1085 return($a_return);
1086 }
1088 /* Generates ListBox frienly output of used logonscripts
1089 */
1090 function printOutLogonScripts()
1091 {
1092 $a_return = array();
1093 if(is_array($this->gotoLogonScripts)){
1094 foreach($this->gotoLogonScripts as $script){
1095 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1096 }
1097 }
1098 return($a_return);
1099 }
1102 /* Return plugin informations for acl handling
1103 #FIXME these ACLs should work for groups too */
1104 function plInfo()
1105 {
1106 return (array("plShortName" => _("Environment"),
1107 "plDescription" => _("Environment settings"), // Description
1108 "plSelfModify" => TRUE,
1109 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1110 "plPriority" => 2, // Position in tabs
1111 "plSection" => "personal", // This belongs to personal
1112 "plCategory" => array("users", "groups"), // Add to following categories
1113 "plOptions" => array("resolution_hook" => array("type" => "string",
1114 "description" => _("Command to extend the list of possible screen resolutions"))),
1116 "plProvidedAcls" => array(
1118 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1119 "gotoProfileFlagC" => _("Cache profile localy") ,
1121 "gotoProfileQuota" => _("Profile quota") ,
1122 "gotoProfileServer" => _("Profile server") ,
1124 "gotoXResolution" => _("Resolution") ,
1125 "gotoKioskProfile" => _("Kiosk profile") ,
1127 "gosaDefaultPrinter" => _("Default printer") ,
1128 "gotoLogonScript" => _("Logon script") ,
1129 "gotoHotplugDevice" => _("Hotplug devices"),
1130 "gotoShare" => _("Shares"))
1131 ));
1132 }
1133 }
1135 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1136 ?>