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