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