Code

Fixed printer acls
[gosa.git] / plugins / personal / environment / class_environment.inc
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
15   
16   var $in_dialog            = false;
17   var $uid                  = "";
19   var $is_group             = false;
20   
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 
30   
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;
76   var $add_del_printer_member_was_called = false;
78   function environment ($config, $dn= NULL)
79   {
80     plugin::plugin ($config, $dn);
82     /* Check : Are we currently editing a group or user dialog */
83     if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
84       $suffix="Group";
85       $this->uid          = $this->attrs['cn'][0];
86       $this->attrs['uid'] = $this->attrs['cn'][0];
87       $this->OrigCn = $this->attrs['cn'][0];
88     }else{
89       $suffix="User";
90     }
92     $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
94     /* Get all Printer assignments */
95     $ldap = $this->config->get_ldap_link();
96     $ldap->cd($this->config->current['BASE']);
97     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
98     while($printer = $ldap->fetch()){
99       $this->gotoPrinter[$printer['cn'][0]]=$printer;
100       $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
101     }
102     $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
103     while($printer = $ldap->fetch()){
104       $this->gotoPrinter[$printer['cn'][0]]=$printer;
105       $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
106     }
108     /* prepare hotplugs */
109     if((isset($this->attrs['gotoHotplugDevice']))&&(is_array($this->attrs['gotoHotplugDevice']))){
110       unset($this->attrs['gotoHotplugDevice']['count']);
111       foreach($this->attrs['gotoHotplugDevice'] as $device){
112         $tmp = $tmp2 = array();
113         $tmp = split("\|",$device);
114         $tmp2['name']        = $tmp[0]; 
115         $tmp2['description'] = $tmp[1]; 
116         $tmp2['id']          = $tmp[2]; 
118         /* Produkt ID */
119         if(!isset($tmp[3])){
120           $tmp[3] = "";
121         }
122         /* Vendor ID */
123         if(!isset($tmp[4])){
124           $tmp[4] = "";
125         }
127         $tmp2['produkt']     = $tmp[3]; 
128         $tmp2['vendor']      = $tmp[4];
130         $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
131       }
132     }
134     /* prepare LogonScripts */
135     if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
136       unset($this->attrs['gotoLogonScript']['count']);
137       foreach($this->attrs['gotoLogonScript'] as $device){
138         $tmp = $tmp2 = array();
139         $tmp = split("\|",$device);
140         $tmp2['LogonName']        = $tmp[0]; 
141         $tmp2['LogonPriority']    = $tmp[2]; 
142         if(preg_match("/O/i",$tmp[1])){
143           $tmp2['LogonOverload'] = "O";
144         }else{
145           $tmp2['LogonOverload'] = "";
146         }
147         if(preg_match("/L/i",$tmp[1])){
148           $tmp2['LogonLast'] = "L";
149         }else{
150           $tmp2['LogonLast'] = "";
151         }
152         $tmp2['LogonData']        = base64_decode($tmp[3]); 
153         $tmp2['LogonDescription'] = $tmp[4];
154         $this->gotoLogonScripts[$tmp[0]]=$tmp2;
155       }
156     }
158     /* Prepare Shares */
159     if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
160       unset($this->attrs['gotoShare']['count']);
161       foreach($this->attrs['gotoShare'] as $share){
162         $tmp = $tmp2 = array();
163         $tmp = split("\|",$share);
164         $tmp2['server']      =$tmp[0];
165         $tmp2['name']        =$tmp[1];
167         /* Decode base64 if needed */
168         if (!preg_match('%/%', $tmp[2])){
169           $tmp2['mountPoint']  =base64_decode($tmp[2]);
170         } else {
171           $tmp2['mountPoint']  =$tmp[2];
172         }
174         if(isset($tmp[3])){
175           $tmp2['PwdHash']  =$tmp[3];
176         }else{
177           $tmp2['PwdHash']  ="";
178         }
179         if(isset($tmp[4])){
180           $tmp2['Username']  =$tmp[4];
181         }else{
182           $tmp2['Username']  ="";
183         }
184         $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
185       }
186     }
188     for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
189       $chr = $this->gotoProfileFlags[$i];
190       $name = "gotoProfileFlag".$chr;
191       $this->$name=$chr;
192     }
194     if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
195       $this->useProfile = true;
196     }else{
197       $this->useProfile = false;
198     }
200     /* Set resolutions */
201     $this->gotoXResolutions = array("auto"=>_("auto"),
202                                     "640x480"   =>  "640x480",
203                                     "800x600"   =>  "800x600",
204                                     "1024x768"  =>  "1024x768",
205                                     "1152x864"  =>  "1152x864",
206                                     "1280x768"  =>  "1280x768",
207                                     "1280x1024" =>  "1280x1024");
209     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
210       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
212       if(is_readable($file)){
213         $str = file_get_contents($file);
214         $lines = split("\n",$str);
215         foreach($lines as $line){
216           $line = trim($line);
217           if(!empty($line)){
218             $this->gotoXResolutions[$line]=$line;
219           }
220         }
221         //natcasesort($this->gotoXResolutions);
222       }else{
223         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
224       }
225     }
227     $this->gotoProfileServers= $config->getShareServerList() ;
228     $this->gotoShareSelections= $config->getShareList(true);
229     $this->gotoAvailableShares= $config->getShareList(false);  
231   }
234   /* Detect type of edited object (user|group)*/
235   function detect_grouptype()
236   {
237     if((!isset($this->parent))&&(!$this->is_account)){
238       $this->is_group     = false;
239     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
240       $this->is_group     = true;
241     }else{
242       $this->is_group     = false;
243     }
244   }
247   function execute()
248   {
249     /* Call parent execute */
250     plugin::execute();
252     $this->detect_grouptype();
254     /* Fill templating stuff */
255     $smarty= get_smarty();
256     $display= "";
258     /* Are we editing from MyAccount and not editing a user */
259     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
261     /* Prepare all variables for smarty */
262     foreach($this->attributes as $s_attr){
263       /* Set value*/
264       $smarty->assign($s_attr,$this->$s_attr);
266       /* Set checkbox state*/
267       if(empty($this->$s_attr)){
268         $smarty->assign($s_attr."CHK","");
269       }else{
270         $smarty->assign($s_attr."CHK"," checked ");
271       }
273       /* Prepare ACL settings*/
274       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
275     }
277     /* Is accout enabled | are we editing from usermenu or admin menu 
278        All these tab management is done here
279      */
282     /* Working from Usermenu an the Account is currently disbled
283      * this->parent :  is only set if we are working in a list of tabs
284      * is_account   :  is only true if the needed objectClass is given
285      */
286     if((!isset($this->parent))&&(!$this->is_account)){
287       /* We are currently editing this tab from usermenu, but this account is not enabled */
288       $smarty->assign("is_account",$this->is_account);
289       /* Load template */
290       $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
291       /* Avoid the "You are currently editing ...." message when you leave this tab */
292       $display .= back_to_main(); 
293       /* Display our message to the user */
294       return $display;
297       /* We are currently editing from group tabs, because 
298        * $this->parent is set
299        * posixAccount is not set, so we are not in usertabs.
300        */
301     }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
302       $smarty->assign("is_account","true");
303       $this->uid          = $this->cn;
304       $this->attrs['uid'] = $this->cn;
306       /* Change state if needed */
307       if (isset($_POST['modify_state'])){
308         if(($this->acl_is_createable() && !$this->is_account) || 
309             ($this->acl_is_removeable() &&  $this->is_account)){
310           $this->is_account= !$this->is_account;
311         }
312       }
313       /* Group Dialog with enabled environment options */
314       if ($this->is_account){
315         $display= $this->show_enable_header(_("Remove environment extension"),
316             _("Environment extension enabled. You can disable it by clicking below."));
317       } else {
319         /* Environment is disabled 
320            If theres is no posixAccount enabled, you won't be able to enable 
321            environment extensions
322          */
323         if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
324           // 4. There is a PosixAccount
325           $display= $this->show_enable_header(_("Add environment extension"),
326               _("Environment extension disabled. You can enable it by clicking below."));
327           return $display;
328         }else{
329           // 4. There is no PosixAccount
330           $display= $this->show_enable_header(_("Add environment extension"),
331               _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
332           return $display;
333         }
334       }
335     }else{
336       /* Editing from Usermenu 
337        *  Tell smarty that this accoutn is enabled 
338        */
339       $smarty->assign("is_account","true");
341       /* Change state if needed */
342       if (isset($_POST['modify_state'])){
343         if(($this->acl_is_createable() && !$this->is_account) || 
344             ($this->acl_is_removeable() &&  $this->is_account)){
345           $this->is_account= !$this->is_account;
346         }
347       }
349       if(isset($this->parent)){
351         // 3. Account enabled . Editing from adminmenu
352         if ($this->is_account){
353           $display= $this->show_disable_header(_("Remove environment extension"),
354               _("Environment extension enabled. You can disable it by clicking below."));
355         } else {
357           if($this->parent->by_object['posixAccount']->is_account==true){
358             // 4. There is a PosixAccount
359             $display= $this->show_disable_header(_("Add environment extension"),
360                 _("Environment extension disabled. You can enable it by clicking below."));
361             return $display;
362           }else{
363             // 4. There is a PosixAccount
364             $display= $this->show_disable_header(_("Add environment extension"),
365                 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
366             return $display;
367           }
368         }
369       }
370     }
371     /* Account is Account : is_accounbt=true.
372      * Else we won't reach this. 
373      */
375     /* Prepare all variables for smarty */
376     foreach($this->attributes as $s_attr){
377       /* Set value*/
378       $smarty->assign($s_attr,$this->$s_attr);
380       /* Set checkbox state*/
381       if(empty($this->$s_attr)){
382         $smarty->assign($s_attr."CHK","");
383       }else{
384         $smarty->assign($s_attr."CHK"," checked ");
385       }
387       /* Prepare ACL settings*/
388       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
389     }
391     foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
392       $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
393     }
395     if($WriteOnly) {
396       $smarty->assign("gotoPrinterACL","r");
397     }else{
398       $smarty->assign("gotoPrinterACL","rw");
399     }
401     if(empty($this->useProfile)){
402       $smarty->assign("useProfileCHK","");
403       $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
404       $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
405       $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
406     }else{
407       $smarty->assign("useProfileCHK"," checked ");
408     }
411     $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
413     /* HANDLE Profile Settings here 
414      * Assign available Quota and resolution settings
415      * Get all available profile server
416      * Get cache checkbox
417      * Assign this all to Smarty 
418      */
420     if(empty($this->gotoProfileFlagL)){
421       $smarty->assign("gotoProfileFlagLCHK"," ");
422     }else{
423       $smarty->assign("gotoProfileFlagLCHK"," checked ");
424     }
426     if(empty($this->gotoProfileFlagC)){
427       $smarty->assign("gotoProfileFlagCCHK"," ");
428     }else{
429       $smarty->assign("gotoProfileFlagCCHK"," checked ");
430     }
433     $smarty->assign("gotoXResolutions"    , $this->gotoXResolutions);
434     $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
436     $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
437     if(!is_array($this->gotoProfileServers)){
438       $this->gotoProfileServers =array();
439     }
440     $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
442     /* Handle kiosk profiles 
443      * Read available from filesystem
444      * Open management if post is transmitted
445      */
447     /* Save */
448     if(isset($_POST['KioskClose'])){
449       $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
451       unset($this->dialog);
452       $this->dialog=NULL;
453       $this->is_dialog = false;
454     }
456     /* Reassign help class */
457     $_SESSION['current_class_for_help'] = get_class($this);
459     /* Open Management Dialog */
460     if(isset($_POST['KioskManagementDialog'])){
461       $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles); 
462       $this->dialog->parent= $this;
463       $this->dialog->acl = $this->acl;
464       $this->is_dialog = true;
465     }
466     $tmp = new kioskManagementDialog($this->config,$this->dn);
467     $list = $tmp->getKioskProfiles($this->newKioskProfiles);
468     $list['none']=_("None");
469     $list = array_reverse($list);
470     $smarty->assign("gotoKioskProfiles",$list);
471     $smarty->assign("gotoKioskProfileKeys",array_flip($list));
473     /* Logonscript Management
474      * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group) 
475      * Perform add Delete edit Posts 
476      */
478     /* Dialog Save */
479     if(isset($_POST['LogonSave'])){
481       if(!$this->acl_is_writeable("gotoLogonScript")){
482         print_red(_("You are not allowed to write Logon scripts."));
483         unset($this->dialog);
484         $this->dialog=NULL;
485         $this->is_dialog=false;
486       }else{
487         $this->dialog->save_object();
488         if(count($this->dialog->check())!=0){
489           foreach($this->dialog->check() as $msg){
490             print_red($msg);
491           }
492         }else{
493           $tmp = $this->dialog->save();
494           unset($this->dialog);
495           $this->dialog=NULL;
496           $this->is_dialog=false;
497           $this->gotoLogonScripts[$tmp['LogonName']]=$tmp; 
498         }
499       }
500     }
501     
503     /* Dialog Quit without saving */
504     if(isset($_POST['LogonCancel'])){
505       $this->is_dialog= false;
506       unset($this->dialog);
507       $this->dialog= NULL;
508     }
510     /* Check Edit Del New Posts for a selected LogonScript */ 
511     if($this->acl_is_writeable("gotoLogonScript") && 
512         (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
514       /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
515        * In this case we create a new Logon Script.
516        */
517       if(isset($_POST['gotoLogonScriptNew'])){
518         $this->is_dialog = true;
519         $this->dialog = new logonManagementDialog($this->config,$this->dn);
520       }
522       /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
523        * We only can delete if there is an entry selected.
524        */
525       if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
526         unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
527       }
529       /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
530        * There must be an entry selected to perform edit request.
531        */
532       if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
533         $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
534         $this->is_dialog = true;
535         $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
536       }
537     }
539     /* Append List to smarty*/
540     $smarty->assign("gotoLogonScripts",   $this->printOutLogonScripts());
541     $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
543     /* In this section server shares will be defined 
544      * A user can select one of the given shares and a mount point
545      *  and attach this combination to his setup.
546      */
548     $smarty->assign("gotoShareSelections",    $this->gotoShareSelections);
549     if(!is_array($this->gotoShareSelections)){
550       print $this->gotoShareSelections;
551       $this->gotoShareSelections = array();
552     }
553     $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
555     /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry 
556      * This entry will be, a combination of mountPoint and sharedefinitions 
557      */
558     if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
559       /* We assign a share to this user, if we don't know where to mount the share */
560       if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
561         print_red(_("You must specify a valid mount point."));
562       }elseif(!(
563             preg_match("/^\//",$_POST['gotoShareMountPoint'])  ||
564             preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
565             preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
566             preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
567             preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
568             preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
569             preg_match("/^%/",$_POST['gotoShareMountPoint'])
570             )
571           ){
572         print_red(_("You must specify a valid mount point.")); 
573       }else{
574         $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
575         $s_mount = $_POST['gotoShareMountPoint'];
576         $s_user  = $_POST['ShareUser'];
577         /* Preparing the new assignment */ 
578         $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
579         $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
580         $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
581         $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
582       }
583     }  
585     /* if the Post  gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
586      * If there is no defined share selected, we will abort the deletion without any message 
587      */
588     $once = true;
589     if($this->acl_is_writeable("gotoShare")){
590       foreach($_POST as $name => $value){
591         if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
592           $once = false;  
593           $key  = preg_replace("/^gotoShareDel_/","",$name);
594           $key  = preg_replace("/_+[xy]$/","",$key);
595           $key  = base64_decode($key);
596           if(isset($this->gotoShares[$key])) {
597             unset($this->gotoShares[$key]);
598           }
600           /* Remove corresponding password entry, too. This is a workaround
601              to get rid of old-style entries. */
602           $key= preg_replace("/\|/", "|!", $key);
603           if(isset($this->gotoShares[$key])) {
604             unset($this->gotoShares[$key]);
605           }
606         }
607         if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
608           $once = false;
609           $key  = preg_replace("/^gotoShareResetPwd_/","",$name);
610           $key  = preg_replace("/_+[xy]$/","",$key);
611           $key  = base64_decode($key);
612           $this->gotoShares[$key]['PwdHash'] = "";
613           if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
614             unset($this->gotoShares[$key]);
615           }
616         }
617       }
618     }
619     $divlistShares = new divSelectBox("gotoShares");
620     $divlistShares->SetHeight(100);
621     $tmp = $this->printOutAssignedShares();
623     foreach($tmp as $key => $value){
624       $img = "";
626       /* Check if entry starts with an ! */
627       if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
629         /* If we are currently editing groups environment, skip those ! entries */ 
630         if($this->is_group) continue;
632         /* Create pwd reset images */
633         if($this->gotoShares[$key]['PwdHash'] != ""){
634           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
635             title='"._("Reset password hash")."'>";
636         }
637         $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
638         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
639       }else{
641         /* Create pwd reset img && delete image */
642         if($this->gotoShares[$key]['PwdHash'] != ""){
643           $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."' 
644             title='"._("Reset password hash")."'>";
645           $img.= "&nbsp;";
646         }
647         $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."' 
648           title='"._("Delete share entry")."'>";
649         $field1 = array("string" => $value);
650         $field2 = array("string" => $img   , "attach" => "style='border-right:0px;'");
651       }
652       $divlistShares->AddEntry(array($field1,$field2));
653     }
654     $smarty->assign("divlistShares",$divlistShares->DrawList());
656     /* Hotplug devices will be handled here 
657      * There are 3 possible methods for this feature
658      * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
659      * Delete will erase an entry, the entry must be selcted in the ListBox first
660      * Editing an entry will open a dialog where the informations about the selcted entry can be changed
661      */
663     /* If there is a new entry wanted, open a new entry by initilising the dialog */
664     if((isset($_POST['gotoHotplugDeviceNew'])) && ($this->acl_is_writeable("gotoHotplugDevice"))){
665       $this->dialog = new hotplugDialog($this->config,$this->dn);
666       $this->is_dialog = true;
667     }
669     /* We have to delete the selected hotplug from the list*/
670     if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice'])) && $this->acl_is_writeable("gotoHotplugDevice")){
671       if($this->acl_is_writeable("gotoHotplugDevice")){
672         foreach($_POST['gotoHotplugDevice'] as $name){
673           unset($this->gotoHotplugDevices[$name]);
674         }
675       }
676     }
678     /* There are already defined hotplugs from other users we could use */
679     if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
680       $tmp  =array();
681       foreach($this->gotoHotplugDevices as $plugs){
682         $tmp[] = $plugs['name'];
683       }
684       $this->dialog = new hotplugDialog($this->config,$this->dn,true,$tmp);
685       $this->is_dialog = true;
686     }
688     /* Dialog Aborted */
689     if(isset($_POST['HotPlugCancel'])){
690       unset($this->dialog);
691       $this->dialog= NULL;
692       $this->is_dialog = false;
693     }
695     /* Dialod saved */
696     if(isset($_POST['HotPlugSave'])){
698       $this->dialog->save_object();
699       if(count($this->dialog->check())!=0){
700         foreach($this->dialog->check() as $msg){
701           print_red($msg);
702         }
703       }else{
704         $this->dialog->save_object();
705         $a_tmp = $this->dialog->save();
707         if(is_array($a_tmp)){
708           foreach($a_tmp as $name => $hotplug){
709             $this->gotoHotplugDevices[$name]= $hotplug; 
710           }
711         }
712         unset($this->dialog);
713         $this->dialog= NULL;
714         $this->is_dialog = false;
715       }
716     }
717     $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
718     $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
720     /* Printer Assignment will managed below 
721      * A printer can be assigned in two different ways and two different types
722      * There are 2 types of users assigned to a printer : user and admin
723      * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
724      * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
725      */ 
727     /* First handle Add Post. Open a dialog that allows us to select a printer or two */ 
728     if(isset($_POST['gotoPrinterAdd'])){
730       $this->is_dialog=true;
731       $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
732     }
734     if(isset($_POST['PrinterCancel'])){
735       $this->is_dialog=false;
736       unset($this->dialog);
737       $this->dialog=NULL;
738     }
740     if(isset($_POST['PrinterSave'])){
741       if(count($this->dialog->check())!=0){
742         $tmp = $this->dialog->check();
743         foreach($tmp as $msg){
744           print_red($msg);
745         } 
746       }else{
747         $this->dialog->save_object();
748         $tmp = $this->dialog->save();
749         $tmp2= $this->dialog->getPrinter(true);
751         foreach($tmp as $pname){
752         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
753         $printerObj->set_acl_base($tmp2[$pname]['dn']);
755         if($this->is_group){
756           if($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
757             $this->gotoPrinter[$pname]=$tmp2[$pname];
758             $this->gotoPrinter[$pname]['mode']="user";
759             $this->add_del_printer_member_was_called = true;
760           }
761         }else{
762           if($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
763             $this->gotoPrinter[$pname]=$tmp2[$pname];
764             $this->gotoPrinter[$pname]['mode']="user";
765             $this->add_del_printer_member_was_called = true;
766           }
767         }
769         }
771         $this->is_dialog=false;
772         unset($this->dialog);
773         $this->dialog   =NULL;
774       }
775     }
777     if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
778       $printer = $_POST['gotoPrinterSel'];
779       foreach($printer as $pname){
781         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn']);
782         if($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->dn)){
783           unset($this->gotoPrinter[$pname]);
784           $this->add_del_printer_member_was_called = true;
785         }
786       }
787     }
789     if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
792       $printers = $_POST['gotoPrinterSel'];
794       foreach($printers as $printer){
795         if($this->gotoPrinter[$printer]['mode']=="user"){
796           $this->gotoPrinter[$printer]['mode']="admin";
797         }else{
798           $this->gotoPrinter[$printer]['mode']="user";
799         }
800       }
801     }
803     if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
804       if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
805         $this->gosaDefaultPrinter= "";
806       } else {
807         $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
808       }
809     }
811     $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
812     $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
814     /* General behavior */
815     if($this->acl_is_writeable("gotoKioskProfile")){
816     if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
817       $this->dialog->save_object();
818       $disp =$this->dialog->execute();
820       $tmp = new kioskManagementDialog($this->config,$this->dn);
821       $list = $tmp->getKioskProfiles($this->newKioskProfiles);
822       $list['none']=_("None");
823       $list = array_reverse($list);
824       if(!isset($list[$this->gotoKioskProfile])){
825         print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
826         $this->gotoKioskProfile = 'none';
827       }
828       return($disp);
829       }
830     }
832     /* Als smarty vars are set. Get smarty template and generate output */
833     $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
834     return($display);
835   }
837   function remove_from_parent()
838   {
839     /* only if it was an account*/
840     if (!$this->initially_was_account){
841       return;
842     }
844     /* include global link_info */
845     $ldap= $this->config->get_ldap_link();
847     /* Remove and write to LDAP */
848     plugin::remove_from_parent();
850     /* Don't save our template variables */
851     $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
853     /* Skip all these attributes */
854     foreach($skip as $del){
855       unset($this->attrs[$del]);
856     }
858     @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
860     $ldap->cd($this->dn);
861     $this->cleanup();
862     $ldap->modify ($this->attrs); 
864     show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
866     /* Optionally execute a command after we're done */
867     $this->handle_post_events("remove");
868   }
871   /* Save data to object */
872   function save_object()
873   {
874     /* Get all Posted vars 
875      * Setup checkboxes 
876      */
877     $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
878     if(isset($_POST['iamposted'])){
880       $PACL =  $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
882       if(preg_match("/w/",$PACL)){
883         if(isset($_POST['useProfile'])){
884           $this->useProfile = true;
885         }else{
886           $this->useProfile = false;
887         }
888       }
890       if($this->acl_is_writeable("gotoProfileFlagC")){
891         if(isset($_POST['gotoProfileFlagC'])){
892           $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
893         }else{
894           $this->gotoProfileFlagC = false;
895         }
896       }
898       if($this->acl_is_writeable("gotoProfileFlagL")){
899         if(isset($_POST['gotoProfileFlagL'])){
900           $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
901         }else{
902           $this->gotoProfileFlagL = false;
903         }
904       }
906       plugin::save_object();
907       foreach($this->attributes as $s_attr){
908         if((!isset($_POST[$s_attr])) || 
909             in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
910         if(!$this->acl_is_writeable($s_attr)){
911           continue;
912         }else{ 
913           if(isset($_POST[$s_attr])){
914             $this->$s_attr = $_POST[$s_attr];
915           }else{
916             $this->$s_attr = false;
917           }
918         }
919       }
920     }
921   }
924   /* Check supplied data */
925   function check()
926   {
927     /* Call common method to give check the hook */
928     $message= plugin::check();
930     $this->detect_grouptype();
932     if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
933       $message[]=_("Please set a valid profile quota size.");
934     } 
935     if(!isset($this->attrs['objectClass'])){
936       $this->attrs['objectClass']=array();
937     } 
938     if(!$this->is_group){
939       if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
940         $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));  
941       }
942     }
943     return ($message);
944   }
947   /* Save to LDAP */
948   function save()
949   {
950     /* If group was renamed, all printer settings get lost
951      */ 
952     /* only save changed variables ....*/
953     if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
954     if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
955       if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
956         $method="https://";
957       }else{
958         $method="http://";
959       }
961       $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
962       $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
963     }else{
964       $this->gotoKioskProfile= array();
965     }
967     plugin::save();
968     $ldap= $this->config->get_ldap_link();
970     $realyUsedAttrs= array();
972     $path = search_config($this->config->data,"environment", "KIOSKPATH"); 
973     /* Creating Kiosk Profiles */
974     foreach($this->newKioskProfiles as $file){
975       $contents = $file['contents'];
976       $fp = @fopen($path."/".$file['name'],"w");
977       if(!$fp){
978         print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
979       }else{
980         fwrite($fp,$contents,strlen($contents));
981       }
982       @unlink($file['tmp_name']);
983     }
985     /* Save already used objectClasses */
986     $ocs        = $this->attrs['objectClass'];
987     unset($ocs['count']);
988     $this->attrs = array();
989     $this->attrs['objectClass']= $ocs;
990     foreach($this->objectclasses as $objc){
991       if(!in_array($objc,$this->attrs['objectClass'])){
992         $this->attrs['objectClass'][]=$objc;
993       }
994     }
996     /* 1. Search all printers that have our uid/cn as member 
997      * 2. Delete this uid/cn from every single entry and save it again.
998      * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
999      * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal 
1000      */
1001     
1002     $this->detect_grouptype();
1004     if($this->add_del_printer_member_was_called){
1006       $types = array( "gotoUserPrinter"       => "AddUser",
1007           "gotoGroupPrinter"      => "AddGroup",
1008           "gotoUserAdminPrinter"  => "AddAdminUser",
1009           "gotoGroupAdminPrinter" => "AddAdminGroup");
1011       if($this->is_group){
1012         $s_suffix = "Group";
1013         $useVar   = "cn";
1014       }else{
1015         $useVar   = "uid";
1016         $s_suffix = "User";
1017       }
1019       /* Remove old entries */
1020       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
1021       while($attr = $ldap->fetch()){
1022         $printerObj = NULL;
1023         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
1024         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
1025         $printerObj->by_object['printgeneric']->save();
1026       }
1028       $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
1029       while($attr = $ldap->fetch()){
1030         $printerObj = NULL;
1031         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
1032         $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
1033         $printerObj->by_object['printgeneric']->save();
1034       }
1036       foreach($this->gotoPrinter as $printer){
1037         $printerObj = NULL;
1038         $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
1040         if($printer['mode'] == "admin") {
1041           $attribute = "goto".$s_suffix."AdminPrinter";
1042         }else{
1043           $attribute = "goto".$s_suffix."Printer";
1044         }
1046         $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1047         $printerObj->by_object['printgeneric']->save();
1048       }
1049     }    
1051     /* Prepare HotPlug devices */
1052     $this->attrs['gotoHotplugDevice'] = array();
1053     foreach($this->gotoHotplugDevices as $name => $device){
1054       $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'].
1055         "|".$device['produkt']."|".$device['vendor'];
1056     }
1058     /* Prepare LogonScripts */
1059     $this->attrs['gotoLogonScript'] = array();
1060     foreach($this->gotoLogonScripts as $name => $script){
1061       $this->attrs['gotoLogonScript'][] =   $script['LogonName']."|".
1062         $script['LogonOverload'].$script['LogonLast']."|".
1063         $script['LogonPriority']."|".
1064         base64_encode($script['LogonData'])."|".
1065         $script['LogonDescription'];
1066     }
1068     /* Prepare Shares */
1069     $this->attrs['gotoShare']=array();
1070     foreach($this->gotoShares as $name => $share){
1071       $mntp= $share['mountPoint'];
1072       if (!preg_match('=^[a-z0-9+_/%-]+$=i', $mntp)){
1073         $mntp= base64_encode($mntp);
1074       }
1075       $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1076     }
1079     if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1080     $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1082     foreach($saveThis as $tosave){
1083       if(!empty($this->$tosave)){
1084         $this->attrs[$tosave]=$this->$tosave;
1085       }else{
1086         $this->attrs[$tosave]=array();
1087       }
1088     }
1090     /* Prepare Flags */
1091     $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1092     if(empty($this->attrs['gotoProfileFlags'][0])){
1093       $this->attrs['gotoProfileFlags']=array();
1094     }
1096     if($this->useProfile == false){
1097       $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1098       $this->attrs['gotoProfileServer']= array(); 
1099     }
1101     $ldap->cat ($this->dn, array('dn'));
1102     if ($ldap->fetch()){
1103       $mode= "modify";
1104     } else {
1105       $mode= "add";
1106       $ldap->cd($this->config->current['BASE']);
1107       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1108     }
1110     $ldap->cd($this->dn);
1111     $this->cleanup();
1112     $ldap->$mode($this->attrs);
1113     show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1114     $this->handle_post_events($mode);
1115   }
1117   /* Generate ListBox frindly output for the defined shares 
1118    * Possibly Add or remove an attribute here, 
1119    */
1120   function printOutAssignedShares()
1121   {
1122     $a_return = array();
1123     if(is_array($this->gotoShares)){
1124       foreach($this->gotoShares as $share){
1125         if(preg_match("/^!/",$share['server'])){
1126           $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share"); 
1127         }else{
1128           $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1129         }
1130       }
1131       natcasesort($a_return);
1132     }
1133     return($a_return);
1134   }
1136   /* Generate ListBox frindly output for the definedhotplugs 
1137    * Possibly Add or remove an attribute here,
1138    */
1139   function printOutHotPlugDevices()
1140   {
1141     $a_return= array();
1142     if(is_array($this->gotoHotplugDevices)){
1143       foreach($this->gotoHotplugDevices as $key=>$device){
1144         $a_return[$key] = $device['name']." - ".$device['id'];
1145       }
1146     }
1147     return($a_return);
1148   }
1150   /* Generates ListBox frienly output of used printer devices 
1151    * Append ' - admin' if printer is used in admin mode
1152    */
1153   function printOutPrinterDevices()
1154   {
1155     $a_return = array();
1156     if(is_array($this->gotoPrinter)){
1157       foreach($this->gotoPrinter as $printer){
1158         if($printer['mode'] == "admin"){
1159           $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1160         }else{
1161           $a_return[$printer['cn'][0]]= $printer['cn'][0]; 
1162         }
1163         if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1164           $a_return[$printer['cn'][0]].=" - "._("Default printer");
1165         }
1166       }
1167     }
1168     return($a_return);
1169   }
1171   /* Generates ListBox frienly output of used logonscripts 
1172    */
1173   function printOutLogonScripts()
1174   {
1175     $a_return = array();
1176     if(is_array($this->gotoLogonScripts)){
1177       foreach($this->gotoLogonScripts as $script){
1178         $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName']; 
1179       }
1180     }
1181     return($a_return);
1182   }
1185   /* Return plugin informations for acl handling 
1186 #FIXME these ACLs should work for groups too */ 
1187   function plInfo()
1188   {
1189     return (array("plShortName"     => _("Environment"),
1190           "plDescription"   => _("Environment settings"),         // Description
1191           "plSelfModify"    => TRUE,                              
1192           "plDepends"       => array("user", "posixAccount"),     // This plugin depends on 
1193           "plPriority"      => 2,                                 // Position in tabs 
1194           "plSection"       => "personal",                        // This belongs to personal
1195           "plCategory"      => array("users", "groups"),          // Add to following categories 
1196           "plOptions"       => array("resolution_hook" => array("type" => "string",
1197               "description" => _("Command to extend the list of possible screen resolutions"))),
1199           "plProvidedAcls"  => array(
1201             "gotoProfileFlagL"    => _("Resolution changeable during session") ,
1202             "gotoProfileFlagC"    => _("Cache profile localy") ,
1204             "gotoProfileQuota"    => _("Profile quota") ,
1205             "gotoProfileServer"   => _("Profile server") ,
1207             "gotoXResolution"     => _("Resolution") ,
1208             "gotoKioskProfile"    => _("Kiosk profile") ,
1210             "gosaDefaultPrinter"  => _("Default printer") ,
1211             "gotoLogonScript"     => _("Logon script") ,
1212             "gotoHotplugDevice"   => _("Hotplug devices"),
1213             "gotoShare"           => _("Shares"))
1214             ));
1215   }
1218 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1219 ?>