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