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_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_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_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_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_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_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 = preg_replace("/_/", ".", $key);
579 if(isset($this->gotoShares[$key])) {
580 unset($this->gotoShares[$key]);
581 }
583 /* Remove corresponding password entry, too. This is a workaround
584 to get rid of old-style entries. */
585 $key= preg_replace("/\|/", "|!", $key);
586 if(isset($this->gotoShares[$key])) {
587 unset($this->gotoShares[$key]);
588 }
589 }
590 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
591 $once = false;
592 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
593 $key = preg_replace("/_+[xy]$/","",$key);
594 $key = preg_replace("/_/", ".", $key);
595 $this->gotoShares[$key]['PwdHash'] = "";
596 }
597 }
599 $divlistShares = new divSelectBox("gotoShares");
600 $divlistShares->SetHeight(100);
601 $tmp = $this->printOutAssignedShares();
603 foreach($tmp as $key => $value){
604 $img = "";
606 /* Check if entry starts with an ! */
607 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
609 /* If we are currently editing groups environment, skip those ! entries */
610 if($this->is_group) continue;
612 /* Create pwd reset images */
613 if($this->gotoShares[$key]['PwdHash'] != ""){
614 $img.= "<input type='image' name='gotoShareResetPwd_".$key." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
615 title='"._("Reset password hash")."'>";
616 }
617 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
618 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
619 }else{
621 /* Create pwd reset img && delete image */
622 if($this->gotoShares[$key]['PwdHash'] != ""){
623 $img.= "<input type='image' name='gotoShareResetPwd_".$key." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
624 title='"._("Reset password hash")."'>";
625 $img.= " ";
626 }
627 $img.= "<input type='image' name='gotoShareDel_".$key." 'src='images/edittrash.png' alt='"._("Delete")."'
628 title='"._("Delete share entry")."'>";
629 $field1 = array("string" => $value);
630 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
631 }
632 $divlistShares->AddEntry(array($field1,$field2));
633 }
634 $smarty->assign("divlistShares",$divlistShares->DrawList());
636 /* Hotplug devices will be handled here
637 * There are 3 possible methods for this feature
638 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
639 * Delete will erase an entry, the entry must be selcted in the ListBox first
640 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
641 */
643 /* If there is a new entry wanted, open a new entry by initilising the dialog */
644 if(isset($_POST['gotoHotplugDeviceNew'])){
645 $this->dialog = new hotplugDialog($this->config,$this->dn);
646 $this->is_dialog = true;
647 }
649 /* We have to delete the selected hotplug from the list*/
650 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
651 foreach($_POST['gotoHotplugDevice'] as $name){
652 unset($this->gotoHotplugDevices[$name]);
653 }
654 }
656 /* There are already defined hotplugs from other users we could use */
657 if(isset($_POST['gotoHotplugDeviceUse'])){
658 $tmp =array();
659 foreach($this->gotoHotplugDevices as $plugs){
660 $tmp[] = $plugs['name'];
661 }
662 $this->dialog = new hotplugDialog($this->config,$this->dn,true,$tmp);
663 $this->is_dialog = true;
664 }
666 /* Dialog Aborted */
667 if(isset($_POST['HotPlugCancel'])){
668 unset($this->dialog);
669 $this->dialog= NULL;
670 $this->is_dialog = false;
671 }
673 /* Dialod saved */
674 if(isset($_POST['HotPlugSave'])){
675 $this->dialog->save_object();
676 if(count($this->dialog->check())!=0){
677 foreach($this->dialog->check() as $msg){
678 print_red($msg);
679 }
680 }else{
681 $this->dialog->save_object();
682 $a_tmp = $this->dialog->save();
684 if(is_array($a_tmp)){
685 foreach($a_tmp as $name => $hotplug){
686 $this->gotoHotplugDevices[$name]= $hotplug;
687 }
688 }
689 unset($this->dialog);
690 $this->dialog= NULL;
691 $this->is_dialog = false;
692 }
693 }
695 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
696 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
698 /* Printer Assignment will managed below
699 * A printer can be assigned in two different ways and two different types
700 * There are 2 types of users assigned to a printer : user and admin
701 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
702 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
703 */
705 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
706 if(isset($_POST['gotoPrinterAdd'])){
707 $this->is_dialog=true;
708 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
709 }
711 if(isset($_POST['PrinterCancel'])){
712 $this->is_dialog=false;
713 unset($this->dialog);
714 $this->dialog=NULL;
715 }
717 if(isset($_POST['PrinterSave'])){
718 if(count($this->dialog->check())!=0){
719 $tmp = $this->dialog->check();
720 foreach($tmp as $msg){
721 print_red($msg);
722 }
723 }else{
724 $this->dialog->save_object();
725 $tmp = $this->dialog->save();
726 $tmp2= $this->dialog->getPrinter(true);
728 foreach($tmp as $pname){
729 $this->gotoPrinter[$pname]=$tmp2[$pname];
730 $this->gotoPrinter[$pname]['mode']="user";
731 }
733 $this->is_dialog=false;
734 unset($this->dialog);
735 $this->dialog =NULL;
736 }
737 }
739 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
740 $printer = $_POST['gotoPrinterSel'];
741 foreach($printer as $pname){
742 unset($this->gotoPrinter[$pname]);
743 }
744 }
746 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
749 $printers = $_POST['gotoPrinterSel'];
751 foreach($printers as $printer){
752 if($this->gotoPrinter[$printer]['mode']=="user"){
753 $this->gotoPrinter[$printer]['mode']="admin";
754 }else{
755 $this->gotoPrinter[$printer]['mode']="user";
756 }
757 }
758 }
760 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
761 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
762 $this->gosaDefaultPrinter= "";
763 } else {
764 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
765 }
766 }
768 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
769 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
771 /* General behavior */
772 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
773 $this->dialog->save_object();
774 $disp =$this->dialog->execute();
776 $tmp = new kioskManagementDialog($this->config,$this->dn);
777 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
778 $list['none']=_("None");
779 $list = array_reverse($list);
780 if(!isset($list[$this->gotoKioskProfile])){
781 print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
782 $this->gotoKioskProfile = 'none';
783 }
784 return($disp);
785 }
786 if($this->acl != "#none#"){
787 $smarty->assign("useProfileACL","");
788 }else{
789 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
790 $smarty->assign("gotoProfileServerACL"," disabled ");
791 $smarty->assign("gotoProfileQuotaACL"," disabled ");
792 }
794 if(!$this->useProfile){
795 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
796 $smarty->assign("gotoProfileServerACL"," disabled ");
797 $smarty->assign("gotoProfileQuotaACL"," disabled ");
798 }
800 /* Als smarty vars are set. Get smarty template and generate output */
801 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
802 return($display);
803 }
805 function remove_from_parent()
806 {
807 /* only if it was an account*/
808 if (!$this->initially_was_account){
809 return;
810 }
812 /* include global link_info */
813 $ldap= $this->config->get_ldap_link();
815 /* Remove and write to LDAP */
816 plugin::remove_from_parent();
818 /* Don't save our template variables */
819 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
821 /* Skip all these attributes */
822 foreach($skip as $del){
823 unset($this->attrs[$del]);
824 }
826 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
828 $ldap->cd($this->dn);
829 $this->cleanup();
830 $ldap->modify ($this->attrs);
832 show_ldap_error($ldap->get_error(), _("Removing environment information failed"));
834 /* Optionally execute a command after we're done */
835 $this->handle_post_events("remove");
836 }
839 /* Save data to object */
840 function save_object()
841 {
842 /* Get all Posted vars
843 * Setup checkboxes
844 */
846 if(isset($_POST['iamposted'])){
847 if(isset($_POST['useProfile'])){
848 $this->useProfile = true;
849 }else{
850 $this->useProfile = false;
851 }
852 if(isset($_POST['gotoProfileFlag_C'])){
853 $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
854 }else{
855 $this->gotoProfileFlag_C = false;
856 }
857 if(isset($_POST['gotoProfileFlag_L'])){
858 $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
859 }else{
860 $this->gotoProfileFlag_L = false;
861 }
863 $tmp= $this->gosaDefaultPrinter;
864 plugin::save_object();
865 foreach($this->attributes as $s_attr){
866 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
867 if(isset($_POST[$s_attr])){
868 $this->$s_attr = $_POST[$s_attr];
869 }else{
870 $this->$s_attr = false;
871 }
872 }
873 $this->gosaDefaultPrinter= $tmp;
874 }
875 }
878 /* Check supplied data */
879 function check()
880 {
881 /* Call common method to give check the hook */
882 $message= plugin::check();
884 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
885 $message[]=_("Please set a valid profile quota size.");
886 }
887 if(!isset($this->attrs['objectClass'])){
888 $this->attrs['objectClass']=array();
889 }
890 if(!$this->is_group){
891 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
892 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
893 }
894 }
895 return ($message);
896 }
899 /* Save to LDAP */
900 function save()
901 {
902 /* If group was renamed, all printer settings get lost
903 */
904 /* only save changed variables ....*/
905 if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
906 if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
907 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
908 $method="https://";
909 }else{
910 $method="http://";
911 }
913 $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
914 $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
915 }else{
916 $this->gotoKioskProfile= array();
917 }
919 plugin::save();
920 $ldap= $this->config->get_ldap_link();
922 $realyUsedAttrs= array();
924 $path = search_config($this->config->data,"environment", "KIOSKPATH");
925 /* Creating Kiosk Profiles */
926 foreach($this->newKioskProfiles as $file){
927 $contents = $file['contents'];
928 $fp = @fopen($path."/".$file['name'],"w");
929 if(!$fp){
930 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
931 }else{
932 fwrite($fp,$contents,strlen($contents));
933 }
934 @unlink($file['tmp_name']);
935 }
937 /* Save already used objectClasses */
938 $ocs = $this->attrs['objectClass'];
939 unset($ocs['count']);
940 $this->attrs = array();
941 $this->attrs['objectClass']= $ocs;
942 foreach($this->objectclasses as $objc){
943 if(!in_array($objc,$this->attrs['objectClass'])){
944 $this->attrs['objectClass'][]=$objc;
945 }
946 }
949 /* Save usersettings to Printer */
951 if(chkacl($this->acl,"gotoPrinter")!=""){
952 $this->gotoPrinter = array();
953 }
955 if($this->is_group){
956 $s_suffix = "Group";
957 }else{
958 $s_suffix = "User";
959 }
962 /* 1. Search all printers that have our uid/cn as member
963 * 2. Delete this uid/cn from every single entry and save it again.
964 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
965 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
966 */
967 $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
968 while($attr = $ldap->fetch()){
970 /* Walk trough all printers and check if our user id used, if so remove it.
971 * Later we will insert our uid at the right place.
972 */
974 /* Remove normal entries (User)*/
975 if(isset($attr['goto'.$s_suffix.'Printer'])) {
976 foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
977 if($this->uid==$user){
978 unset($attr['goto'.$s_suffix.'Printer'][$key]);
979 }
980 }
981 $tmp = array();
982 foreach($attr['goto'.$s_suffix.'Printer'] as $user){
983 $tmp[] = $user;
984 }
985 $attr['goto'.$s_suffix.'Printer'] = array();
986 $attr['goto'.$s_suffix.'Printer'] = $tmp;
987 }
989 /* Remove administrational entries (Admin)*/
990 if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
991 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
992 if($this->uid==$user){
993 unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
994 }
995 }
996 $tmp = array();
997 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $user){
998 $tmp[] = $user;
999 }
1000 $attr['goto'.$s_suffix.'AdminPrinter'] = array();
1001 $attr['goto'.$s_suffix.'AdminPrinter'] = $tmp;
1002 }
1004 /* Extract useable tags, to be able to save all changes
1005 */
1006 $attrs_used = array();
1007 foreach($attr as $key=>$val){
1009 /* If index is numeric, skip it ...*/
1010 if((!is_numeric($key))&&($key!="count")){
1012 /* If entry contains 'count' remove it */
1013 if(is_array($val)&&isset($val['count'])){
1014 unset($val['count']);
1015 }
1016 $attrs_used[$key]=$val;
1017 }
1018 }
1019 /* the result of cleaning the entry is
1020 * to be able to directly save this again,
1021 * if all changes are made
1022 */
1023 $attr= $attrs_used;
1025 #fix : Id don't know why such an entry was set ...
1026 if(isset($attr['GOTOADMINPRINTER'])){
1027 unset($attr['GOTOADMINPRINTER']);
1028 }
1030 /* Save changes */
1031 $ldap->cd($attr['dn']);
1032 unset($attr['dn']);
1033 $ldap->modify ($attr);
1035 if($ldap->get_error()!="Success"){
1036 print_red(_("Error while writing printer")." : ".$ldap->get_error());
1037 }
1038 }
1040 /* All printers are cleaned, (our cn/uid removed)
1041 * now we must add our uid / cn
1042 * to the new configured printers.
1043 */
1044 foreach($this->gotoPrinter as $printer) {
1045 $ldap->cat($printer['dn']);
1046 $attrs= $ldap->fetch();
1047 $attrs_used = array();
1048 foreach($attrs as $key=>$val){
1049 if((!is_numeric($key))&&($key!="count")){
1050 if(is_array($val)&&isset($val['count'])){
1051 unset($val['count']);
1052 }
1053 $attrs_used[$key]=$val;
1054 }
1055 }
1056 /* $attrs contains all values
1057 * we need, to save the entry lateron
1058 */
1059 $attrs= $attrs_used;
1061 /* Depending on the type (User/Admin)
1062 * switch these attributes, that makes it easier
1063 */
1064 if($printer['mode'] == "user"){
1065 $attribute = "goto".$s_suffix."Printer";
1066 $attribute2 = "goto".$s_suffix."AdminPrinter";
1067 }else{
1068 $attribute = "goto".$s_suffix."AdminPrinter";
1069 $attribute2 = "goto".$s_suffix."Printer";
1070 }
1072 /* If this user is already assigned to $attribute2
1073 * delete user from $attribute2, to be albe to attach him to $attribute
1074 * A user can't be admin and normal user for one printer
1075 */
1076 if(!isset($printer[$attribute2])){
1077 $printer[$attribute2]=array();
1078 }else{
1079 if(in_array($this->uid,$printer[$attribute2])){
1080 $tmp = array_flip($printer[$attribute2]);
1081 unset($tmp[$this->uid]);
1082 $attrs[$attribute2]=array_flip($tmp);
1083 }
1084 /* If Last entry removed, clear attribute*/
1085 if(empty($attrs[$attribute2])){
1086 $attrs[$attribute2]=array();
1087 }
1088 }
1090 /* Attach user to the $attribute, if he is'nt already attached
1091 */
1092 if(!isset($attrs[$attribute])){
1093 $attrs[$attribute]=array($this->uid);
1094 }else{
1095 unset($attrs[$attribute]['count']);
1096 if(!in_array($this->uid,$attrs[$attribute])){
1097 $attrs[$attribute][]=$this->uid;
1098 }
1099 }
1101 $ldap->cd($attrs['dn']);
1102 unset($attrs['dn']);
1103 $ldap->modify ($attrs);
1105 if($ldap->get_error()!="Success"){
1106 print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
1107 }
1108 }
1110 /* Prepare HotPlug devices */
1111 $this->attrs['gotoHotplugDevice'] = array();
1112 foreach($this->gotoHotplugDevices as $name => $device){
1113 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'].
1114 "|".$device['produkt']."|".$device['vendor'];
1115 }
1117 /* Prepare LogonScripts */
1118 $this->attrs['gotoLogonScript'] = array();
1119 foreach($this->gotoLogonScripts as $name => $script){
1120 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1121 $script['LogonOverload'].$script['LogonLast']."|".
1122 $script['LogonPriority']."|".
1123 base64_encode($script['LogonData'])."|".
1124 $script['LogonDescription'];
1125 }
1127 /* Prepare Shares */
1128 $this->attrs['gotoShare']=array();
1129 foreach($this->gotoShares as $name => $share){
1130 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint']."|".$share['PwdHash']."|".$share['Username'];
1131 }
1134 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1135 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1137 foreach($saveThis as $tosave){
1138 if(!empty($this->$tosave)){
1139 $this->attrs[$tosave]=$this->$tosave;
1140 }else{
1141 $this->attrs[$tosave]=array();
1142 }
1143 }
1145 /* Prepare Flags */
1146 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
1147 if(empty($this->attrs['gotoProfileFlags'][0])){
1148 $this->attrs['gotoProfileFlags']=array();
1149 }
1151 if($this->useProfile == false){
1152 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1153 $this->attrs['gotoProfileServer']= array();
1154 }
1156 foreach($this->attributes as $s_attr){
1157 if(chkacl($this->acl,$s_attr)!="") {
1158 if(isset($this->attrs[$s_attr])){
1159 unset($this->attrs[$s_attr]);
1160 }
1161 }
1162 }
1164 $ldap->cat ($this->dn, array('dn'));
1165 if ($ldap->fetch()){
1166 $mode= "modify";
1167 } else {
1168 $mode= "add";
1169 $ldap->cd($this->config->current['BASE']);
1170 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1171 }
1173 $ldap->cd($this->dn);
1174 $this->cleanup();
1175 $ldap->$mode($this->attrs);
1176 show_ldap_error($ldap->get_error(), _("Adding environment information failed"));
1177 $this->handle_post_events($mode);
1178 }
1180 /* Generate ListBox frindly output for the defined shares
1181 * Possibly Add or remove an attribute here,
1182 */
1183 function printOutAssignedShares()
1184 {
1185 $a_return = array();
1186 if(is_array($this->gotoShares)){
1187 foreach($this->gotoShares as $share){
1188 if(preg_match("/^!/",$share['server'])){
1189 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1190 }else{
1191 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1192 }
1193 }
1194 }
1195 return($a_return);
1196 }
1198 /* Generate ListBox frindly output for the definedhotplugs
1199 * Possibly Add or remove an attribute here,
1200 */
1201 function printOutHotPlugDevices()
1202 {
1203 $a_return= array();
1204 if(is_array($this->gotoHotplugDevices)){
1205 foreach($this->gotoHotplugDevices as $key=>$device){
1206 $a_return[$key] = $device['name']." - ".$device['id'];
1207 }
1208 }
1209 return($a_return);
1210 }
1212 /* Generates ListBox frienly output of used printer devices
1213 * Append ' - admin' if printer is used in admin mode
1214 */
1215 function printOutPrinterDevices()
1216 {
1217 $a_return = array();
1218 if(is_array($this->gotoPrinter)){
1219 foreach($this->gotoPrinter as $printer){
1220 if($printer['mode'] == "admin"){
1221 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1222 }else{
1223 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1224 }
1225 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1226 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1227 }
1228 }
1229 }
1230 return($a_return);
1231 }
1233 /* Generates ListBox frienly output of used logonscripts
1234 */
1235 function printOutLogonScripts()
1236 {
1237 $a_return = array();
1238 if(is_array($this->gotoLogonScripts)){
1239 foreach($this->gotoLogonScripts as $script){
1240 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1241 }
1242 }
1243 return($a_return);
1244 }
1245 }
1250 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1251 ?>