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];
116 $this->gotoHotplugDevices[$tmp[0]]=$tmp2;
117 }
118 }
120 /* prepare LogonScripts */
121 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
122 unset($this->attrs['gotoLogonScript']['count']);
123 foreach($this->attrs['gotoLogonScript'] as $device){
124 $tmp = $tmp2 = array();
125 $tmp = split("\|",$device);
126 $tmp2['LogonName'] = $tmp[0];
127 $tmp2['LogonPriority'] = $tmp[2];
128 if(preg_match("/O/i",$tmp[1])){
129 $tmp2['LogonOverload'] = "O";
130 }else{
131 $tmp2['LogonOverload'] = "";
132 }
133 if(preg_match("/L/i",$tmp[1])){
134 $tmp2['LogonLast'] = "L";
135 }else{
136 $tmp2['LogonLast'] = "";
137 }
138 $tmp2['LogonData'] = base64_decode($tmp[3]);
139 $tmp2['LogonDescription'] = $tmp[4];
140 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
141 }
142 }
144 /* Prepare Shares */
145 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
146 unset($this->attrs['gotoShare']['count']);
147 foreach($this->attrs['gotoShare'] as $share){
148 $tmp = $tmp2 = array();
149 $tmp = split("\|",$share);
150 $tmp2['server'] =$tmp[0];
151 $tmp2['name'] =$tmp[1];
153 /* Decode base64 if needed */
154 if (!preg_match('%/%', $tmp[2])){
155 $tmp2['mountPoint'] =base64_decode($tmp[2]);
156 } else {
157 $tmp2['mountPoint'] =$tmp[2];
158 }
160 if(isset($tmp[3])){
161 $tmp2['PwdHash'] =$tmp[3];
162 }else{
163 $tmp2['PwdHash'] ="";
164 }
165 if(isset($tmp[4])){
166 $tmp2['Username'] =$tmp[4];
167 }else{
168 $tmp2['Username'] ="";
169 }
170 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
171 }
172 }
174 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
175 $chr = $this->gotoProfileFlags[$i];
176 $name = "gotoProfileFlag_".$chr;
177 $this->$name=$chr;
178 }
180 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
181 $this->useProfile = true;
182 }else{
183 $this->useProfile = false;
184 }
186 /* Set to group environment if we editing a group */
187 if(!isset($this->parent)){
188 $this->is_group = true;
189 }
191 /* Set resolutions */
192 $this->gotoXResolutions = array("auto"=>_("auto"),
193 "640x480" => "640x480",
194 "800x600" => "800x600",
195 "1024x768" => "1024x768",
196 "1154x864" => "1154x864",
197 "1280x768" => "1280x768",
198 "1280x1024" => "1280x1024");
200 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
201 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
203 if(is_readable($file)){
204 $str = file_get_contents($file);
205 $lines = split("\n",$str);
206 foreach($lines as $line){
207 $line = trim($line);
208 if(!empty($line)){
209 $this->gotoXResolutions[$line]=$line;
210 }
211 }
212 //natcasesort($this->gotoXResolutions);
213 }else{
214 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
215 }
216 }
219 $this->gotoProfileServers= $config->getShareServerList() ;
220 $this->gotoShareSelections= $config->getShareList(true);
221 $this->gotoAvailableShares= $config->getShareList(false);
223 }
225 function execute()
226 {
227 /* Call parent execute */
228 plugin::execute();
230 /* Fill templating stuff */
231 $smarty= get_smarty();
232 $display= "";
234 /* Prepare all variables for smarty */
235 foreach($this->attributes as $s_attr){
236 /* Set value*/
237 $smarty->assign($s_attr,$this->$s_attr);
239 /* Set checkbox state*/
240 if(empty($this->$s_attr)){
241 $smarty->assign($s_attr."CHK","");
242 }else{
243 $smarty->assign($s_attr."CHK"," checked ");
244 }
246 /* Prepare ACL settings*/
247 if(chkacl($this->acl,$s_attr)=="") {
248 $smarty->assign($s_attr."ACL","");
249 }else{
250 $smarty->assign($s_attr."ACL"," disabled ");
251 }
253 }
255 /* Is accout enabled | are we editing from usermenu or admin menu
256 All these tab management is done here
257 */
259 /* Working from Usermenu an the Account is currently disbled
260 * this->parent : is only set if we are working in a list of tabs
261 * is_account : is only true if the needed objectClass is given
262 */
263 if((!isset($this->parent))&&(!$this->is_account)){
264 /* We are currently editing this tab from usermenu, but this account is not enabled */
265 $smarty->assign("is_account",$this->is_account);
266 /* Load template */
267 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
268 /* Avoid the "You are currently editing ...." message when you leave this tab */
269 $display .= back_to_main();
270 /* Display our message to the user */
271 return $display;
274 /* We are currently editing from group tabs, because
275 * $this->parent is set
276 * posixAccount is not set, so we are not in usertabs.
277 */
278 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
279 $smarty->assign("is_account","true");
280 $this->is_group = true;
281 $this->uid = $this->cn;
282 $this->attrs['uid'] = $this->cn;
284 /* Change state if needed */
285 if (isset($_POST['modify_state'])){
286 $this->is_account= !$this->is_account;
287 }
289 /* Group Dialog with enabled environment options */
290 if ($this->is_account){
291 $display= $this->show_header(_("Remove environment extension"),
292 _("Environment extension enabled. You can disable it by clicking below."));
293 } else {
295 /* Environment is disabled
296 If theres is no posixAccount enabled, you won't be able to enable
297 environment extensions
298 */
299 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
300 // 4. There is a PosixAccount
301 $display= $this->show_header(_("Add environment extension"),
302 _("Environment extension disabled. You can enable it by clicking below."));
303 return $display;
304 }else{
305 // 4. There is no PosixAccount
306 $display= $this->show_header(_("Add environment extension"),
307 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
308 return $display;
309 }
310 }
311 }else{
312 /* Editing from Usermenu
313 * Tell smarty that this accoutn is enabled
314 */
315 $smarty->assign("is_account","true");
317 $this->is_group = false;
319 /* Do we need to flip is_account state? */
320 if (isset($_POST['modify_state'])){
321 $this->is_account= !$this->is_account;
322 }
324 if(isset($this->parent)){
326 // 3. Account enabled . Editing from adminmenu
327 if ($this->is_account){
328 $display= $this->show_header(_("Remove environment extension"),
329 _("Environment extension enabled. You can disable it by clicking below."));
330 } else {
332 if($this->parent->by_object['posixAccount']->is_account==true){
333 // 4. There is a PosixAccount
334 $display= $this->show_header(_("Add environment extension"),
335 _("Environment extension disabled. You can enable it by clicking below."));
336 return $display;
337 }else{
338 // 4. There is a PosixAccount
339 $display= $this->show_header(_("Add environment extension"),
340 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
341 return $display;
342 }
343 }
344 }
345 }
346 /* Account is Account : is_accounbt=true.
347 * Else we won't reach this.
348 */
350 /* Prepare all variables for smarty */
351 foreach($this->attributes as $s_attr){
352 /* Set value*/
353 $smarty->assign($s_attr,$this->$s_attr);
355 /* Set checkbox state*/
356 if(empty($this->$s_attr)){
357 $smarty->assign($s_attr."CHK","");
358 }else{
359 $smarty->assign($s_attr."CHK"," checked ");
360 }
362 /* Prepare ACL settings*/
363 if(chkacl($this->acl,$s_attr)=="") {
364 $smarty->assign($s_attr."ACL","");
365 }else{
366 $smarty->assign($s_attr."ACL"," disabled ");
367 }
369 }
371 foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
372 if(chkacl($this->acl,$s_attr)=="") {
373 $smarty->assign($s_attr."ACL","");
374 }else{
375 $smarty->assign($s_attr."ACL"," disabled ");
376 }
377 }
379 if(empty($this->useProfile)){
380 $smarty->assign("gotoProfileACL","disabled");
381 $smarty->assign("useProfileCHK","");
382 }else{
383 $smarty->assign("gotoProfileACL","");
384 $smarty->assign("useProfileCHK"," checked ");
385 }
388 $smarty->assign("useProfileACL","");
389 if($this->acl != "#none#"){
390 $smarty->assign("useProfileACL","");
391 $smarty->assign("gotoProfileFlag_CACL"," ");
392 $smarty->assign("gotoProfileQuotaACL"," ");
393 }else{
394 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
395 $smarty->assign("useProfileACL","disabled");
396 $smarty->assign("gotoProfileServer"," disabled ");
397 $smarty->assign("gotoProfileQuotaACL"," disabled ");
398 }
400 /* HANDLE Profile Settings here
401 * Assign available Quota and resolution settings
402 * Get all available profile server
403 * Get cache checkbox
404 * Assign this all to Smarty
405 */
407 if(empty($this->gotoProfileFlag_L)){
408 $smarty->assign("gotoProfileFlag_LCHK"," ");
409 }else{
410 $smarty->assign("gotoProfileFlag_LCHK"," checked ");
411 }
413 if(empty($this->gotoProfileFlag_C)){
414 $smarty->assign("gotoProfileFlag_CCHK"," ");
415 }else{
416 $smarty->assign("gotoProfileFlag_CCHK"," checked ");
417 }
420 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
421 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
423 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
424 if(!is_array($this->gotoProfileServers)){
425 $this->gotoProfileServers =array();
426 }
427 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
429 /* Handle kiosk profiles
430 * Read available from filesystem
431 * Open management if post is transmitted
432 */
434 /* Save */
435 if(isset($_POST['KioskClose'])){
436 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
438 unset($this->dialog);
439 $this->dialog=NULL;
440 $this->is_dialog = false;
441 }
443 /* Reassign help class */
444 $_SESSION['current_class_for_help'] = get_class($this);
446 /* Open Management Dialog */
447 if(isset($_POST['KioskManagementDialog'])){
448 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
449 $this->dialog->parent= $this;
450 $this->dialog->acl = $this->acl;
451 $this->is_dialog = true;
452 }
453 $tmp = new kioskManagementDialog($this->config,$this->dn);
454 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
455 $list['none']=_("None");
456 $list = array_reverse($list);
457 $smarty->assign("gotoKioskProfiles",$list);
458 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
460 /* Logonscript Management
461 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
462 * Perform add Delete edit Posts
463 */
465 /* Dialog Save */
466 if(isset($_POST['LogonSave'])){
467 $this->dialog->save_object();
468 if(count($this->dialog->check())!=0){
469 foreach($this->dialog->check() as $msg){
470 print_red($msg);
471 }
472 }else{
473 $tmp = $this->dialog->save();
474 unset($this->dialog);
475 $this->dialog=NULL;
476 $this->is_dialog=false;
477 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
478 }
479 }
481 /* Dialog Quit without saving */
482 if(isset($_POST['LogonCancel'])){
483 $this->is_dialog= false;
484 unset($this->dialog);
485 $this->dialog= NULL;
486 }
488 /* Check Edit Del New Posts for a selected LogonScript */
489 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
491 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
492 * In this case we create a new Logon Script.
493 */
494 if(isset($_POST['gotoLogonScriptNew'])){
495 $this->is_dialog = true;
496 $this->dialog = new logonManagementDialog($this->config,$this->dn);
497 }
499 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
500 * We only can delete if there is an entry selected.
501 */
502 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
503 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
504 }
506 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
507 * There must be an entry selected to perform edit request.
508 */
509 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
510 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
511 $this->is_dialog = true;
512 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
513 }
514 }
516 /* Append List to smarty*/
517 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
518 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
520 /* In this section server shares will be defined
521 * A user can select one of the given shares and a mount point
522 * and attach this combination to his setup.
523 */
525 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
526 if(!is_array($this->gotoShareSelections)){
527 print $this->gotoShareSelections;
528 $this->gotoShareSelections = array();
529 }
530 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
532 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
533 * This entry will be, a combination of mountPoint and sharedefinitions
534 */
535 if(isset($_POST['gotoShareAdd'])){
536 /* We assign a share to this user, if we don't know where to mount the share */
537 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
538 print_red(_("You must specify a valid mount point."));
539 }elseif(!(
540 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
541 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
542 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
543 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
544 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
545 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
546 preg_match("/^%/",$_POST['gotoShareMountPoint'])
547 )
548 ){
549 print_red(_("You must specify a valid mount point."));
550 }else{
551 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
552 $s_mount = $_POST['gotoShareMountPoint'];
553 $s_user = $_POST['ShareUser'];
554 /* Preparing the new assignment */
555 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
556 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
557 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
558 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
559 }
560 }
562 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
563 * If there is no defined share selected, we will abort the deletion without any message
564 */
565 $once = true;
566 foreach($_POST as $name => $value){
567 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
568 $once = false;
569 $key = preg_replace("/^gotoShareDel_/","",$name);
570 $key = preg_replace("/_+[xy]$/","",$key);
571 $key = base64_decode($key);
572 if(isset($this->gotoShares[$key])) {
573 unset($this->gotoShares[$key]);
574 }
576 /* Remove corresponding password entry, too. This is a workaround
577 to get rid of old-style entries. */
578 $key= base64_decode($key);
579 if(isset($this->gotoShares[$key])) {
580 unset($this->gotoShares[$key]);
581 }
583 }
584 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
585 $once = false;
586 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
587 $key = preg_replace("/_+[xy]$/","",$key);
588 $key = base64_decode($key);
589 $this->gotoShares[$key]['PwdHash'] = "";
590 }
591 }
593 $divlistShares = new divSelectBox("gotoShares");
594 $divlistShares->SetHeight(100);
595 $tmp = $this->printOutAssignedShares();
597 foreach($tmp as $key => $value){
598 $img = "";
600 /* Check if entry starts with an ! */
601 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
603 /* If we are currently editing groups environment, skip those ! entries */
604 if($this->is_group) continue;
606 /* Create pwd reset images */
607 if($this->gotoShares[$key]['PwdHash'] != ""){
608 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
609 title='"._("Reset password hash")."'>";
610 }
611 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
612 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
613 }else{
615 /* Create pwd reset img && delete image */
616 if($this->gotoShares[$key]['PwdHash'] != ""){
617 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
618 title='"._("Reset password hash")."'>";
619 $img.= " ";
620 }
621 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."'
622 title='"._("Delete share entry")."'>";
623 $field1 = array("string" => $value);
624 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
625 }
626 $divlistShares->AddEntry(array($field1,$field2));
627 }
628 $smarty->assign("divlistShares",$divlistShares->DrawList());
630 /* Hotplug devices will be handled here
631 * There are 3 possible methods for this feature
632 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
633 * Delete will erase an entry, the entry must be selcted in the ListBox first
634 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
635 */
637 /* If there is a new entry wanted, open a new entry by initilising the dialog */
638 if(isset($_POST['gotoHotplugDeviceNew'])){
639 $this->dialog = new hotplugDialog($this->config,$this->dn);
640 $this->is_dialog = true;
641 }
643 /* We have to delete the selected hotplug from the list*/
644 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
645 foreach($_POST['gotoHotplugDevice'] as $name){
646 unset($this->gotoHotplugDevices[$name]);
647 }
648 }
650 /* There are already defined hotplugs from other users we could use */
651 if(isset($_POST['gotoHotplugDeviceUse'])){
652 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
653 $this->is_dialog = true;
654 }
656 /* Dialog Aborted */
657 if(isset($_POST['HotPlugCancel'])){
658 unset($this->dialog);
659 $this->dialog= NULL;
660 $this->is_dialog = false;
661 }
663 /* Dialod saved */
664 if(isset($_POST['HotPlugSave'])){
665 $this->dialog->save_object();
666 if(count($this->dialog->check())!=0){
667 foreach($this->dialog->check() as $msg){
668 print_red($msg);
669 }
670 }else{
671 $this->dialog->save_object();
672 $a_tmp = $this->dialog->save();
674 if(is_array($a_tmp)){
675 foreach($a_tmp as $name => $hotplug){
676 $this->gotoHotplugDevices[$name]= $hotplug;
677 }
678 }
679 unset($this->dialog);
680 $this->dialog= NULL;
681 $this->is_dialog = false;
682 }
683 }
685 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
686 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
688 /* Printer Assignment will managed below
689 * A printer can be assigned in two different ways and two different types
690 * There are 2 types of users assigned to a printer : user and admin
691 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
692 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
693 */
695 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
696 if(isset($_POST['gotoPrinterAdd'])){
697 $this->is_dialog=true;
698 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
699 }
701 if(isset($_POST['PrinterCancel'])){
702 $this->is_dialog=false;
703 unset($this->dialog);
704 $this->dialog=NULL;
705 }
707 if(isset($_POST['PrinterSave'])){
708 if(count($this->dialog->check())!=0){
709 $tmp = $this->dialog->check();
710 foreach($tmp as $msg){
711 print_red($msg);
712 }
713 }else{
714 $this->dialog->save_object();
715 $tmp = $this->dialog->save();
716 $tmp2= $this->dialog->getPrinter(true);
718 foreach($tmp as $pname){
719 $this->gotoPrinter[$pname]=$tmp2[$pname];
720 $this->gotoPrinter[$pname]['mode']="user";
721 }
723 $this->is_dialog=false;
724 unset($this->dialog);
725 $this->dialog =NULL;
726 }
727 }
729 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
730 $printer = $_POST['gotoPrinterSel'];
731 foreach($printer as $pname){
732 unset($this->gotoPrinter[$pname]);
733 }
734 }
736 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
739 $printers = $_POST['gotoPrinterSel'];
741 foreach($printers as $printer){
742 if($this->gotoPrinter[$printer]['mode']=="user"){
743 $this->gotoPrinter[$printer]['mode']="admin";
744 }else{
745 $this->gotoPrinter[$printer]['mode']="user";
746 }
747 }
748 }
750 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
751 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
752 $this->gosaDefaultPrinter= "";
753 } else {
754 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
755 }
756 }
758 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
759 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
761 /* General behavior */
762 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
763 $this->dialog->save_object();
764 $disp =$this->dialog->execute();
766 $tmp = new kioskManagementDialog($this->config,$this->dn);
767 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
768 $list['none']=_("None");
769 $list = array_reverse($list);
770 if(!isset($list[$this->gotoKioskProfile])){
771 print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
772 $this->gotoKioskProfile = 'none';
773 }
774 return($disp);
775 }
776 if($this->acl != "#none#"){
777 $smarty->assign("useProfileACL","");
778 }else{
779 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
780 $smarty->assign("gotoProfileServerACL"," disabled ");
781 $smarty->assign("gotoProfileQuotaACL"," disabled ");
782 }
784 if(!$this->useProfile){
785 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
786 $smarty->assign("gotoProfileServerACL"," disabled ");
787 $smarty->assign("gotoProfileQuotaACL"," disabled ");
788 }
790 /* Als smarty vars are set. Get smarty template and generate output */
791 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
792 return($display);
793 }
795 function remove_from_parent()
796 {
797 /* only if it was an account*/
798 if (!$this->initially_was_account){
799 return;
800 }
802 /* include global link_info */
803 $ldap= $this->config->get_ldap_link();
805 /* Remove and write to LDAP */
806 plugin::remove_from_parent();
808 /* Don't save our template variables */
809 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
811 /* Skip all these attributes */
812 foreach($skip as $del){
813 unset($this->attrs[$del]);
814 }
816 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
818 $ldap->cd($this->dn);
819 $this->cleanup();
820 $ldap->modify ($this->attrs);
822 show_ldap_error($ldap->get_error(), _("Removing environment information failed"));
824 /* Optionally execute a command after we're done */
825 $this->handle_post_events("remove");
826 }
829 /* Save data to object */
830 function save_object()
831 {
832 /* Get all Posted vars
833 * Setup checkboxes
834 */
836 if(isset($_POST['iamposted'])){
837 if(isset($_POST['useProfile'])){
838 $this->useProfile = true;
839 }else{
840 $this->useProfile = false;
841 }
842 if(isset($_POST['gotoProfileFlag_C'])){
843 $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
844 }else{
845 $this->gotoProfileFlag_C = false;
846 }
847 if(isset($_POST['gotoProfileFlag_L'])){
848 $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
849 }else{
850 $this->gotoProfileFlag_L = false;
851 }
853 $tmp= $this->gosaDefaultPrinter;
854 plugin::save_object();
855 foreach($this->attributes as $s_attr){
856 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
857 if(isset($_POST[$s_attr])){
858 $this->$s_attr = $_POST[$s_attr];
859 }else{
860 $this->$s_attr = false;
861 }
862 }
863 $this->gosaDefaultPrinter= $tmp;
864 }
865 }
868 /* Check supplied data */
869 function check()
870 {
871 /* Call common method to give check the hook */
872 $message= plugin::check();
874 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
875 $message[]=_("Please set a valid profile quota size.");
876 }
877 if(!isset($this->attrs['objectClass'])){
878 $this->attrs['objectClass']=array();
879 }
880 if(!$this->is_group){
881 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
882 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
883 }
884 }
885 return ($message);
886 }
889 /* Save to LDAP */
890 function save()
891 {
892 /* If group was renamed, all printer settings get lost
893 */
894 /* only save changed variables ....*/
895 if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
896 if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
897 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
898 $method="https://";
899 }else{
900 $method="http://";
901 }
903 $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
904 $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
905 }else{
906 $this->gotoKioskProfile= array();
907 }
909 plugin::save();
910 $ldap= $this->config->get_ldap_link();
912 $realyUsedAttrs= array();
914 $path = search_config($this->config->data,"environment", "KIOSKPATH");
915 /* Creating Kiosk Profiles */
916 foreach($this->newKioskProfiles as $file){
917 $contents = $file['contents'];
918 $fp = @fopen($path."/".$file['name'],"w");
919 if(!$fp){
920 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
921 }else{
922 fwrite($fp,$contents,strlen($contents));
923 }
924 @unlink($file['tmp_name']);
925 }
927 /* Save already used objectClasses */
928 $ocs = $this->attrs['objectClass'];
929 unset($ocs['count']);
930 $this->attrs = array();
931 $this->attrs['objectClass']= $ocs;
932 foreach($this->objectclasses as $objc){
933 if(!in_array($objc,$this->attrs['objectClass'])){
934 $this->attrs['objectClass'][]=$objc;
935 }
936 }
939 /* Save usersettings to Printer */
940 if(chkacl($this->acl,"gotoPrinter")!=""){
941 $this->gotoPrinter = array();
942 }
944 /* 1. Search all printers that have our uid/cn as member
945 * 2. Delete this uid/cn from every single entry and save it again.
946 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
947 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
948 */
949 $types = array( "gotoUserPrinter" => "AddUser",
950 "gotoGroupPrinter" => "AddGroup",
951 "gotoUserAdminPrinter" => "AddAdminUser",
952 "gotoGroupAdminPrinter" => "AddAdminGroup");
954 if($this->is_group){
955 $s_suffix = "Group";
956 $useVar = "cn";
957 }else{
958 $useVar = "uid";
959 $s_suffix = "User";
960 }
962 /* Remove old entries */
963 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
964 while($attr = $ldap->fetch()){
965 $printerObj = NULL;
966 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
967 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
968 $printerObj->by_object['printgeneric']->save();
969 }
971 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
972 while($attr = $ldap->fetch()){
973 $printerObj = NULL;
974 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
975 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
976 $printerObj->by_object['printgeneric']->save();
977 }
979 foreach($this->gotoPrinter as $printer){
980 $printerObj = NULL;
981 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
983 if($printer['mode'] == "admin") {
984 $attribute = "goto".$s_suffix."AdminPrinter";
985 }else{
986 $attribute = "goto".$s_suffix."Printer";
987 }
989 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
990 $printerObj->by_object['printgeneric']->save();
991 }
995 /* Prepare HotPlug devices */
996 $this->attrs['gotoHotplugDevice'] = array();
997 foreach($this->gotoHotplugDevices as $name => $device){
998 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
999 }
1001 /* Prepare LogonScripts */
1002 $this->attrs['gotoLogonScript'] = array();
1003 foreach($this->gotoLogonScripts as $name => $script){
1004 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1005 $script['LogonOverload'].$script['LogonLast']."|".
1006 $script['LogonPriority']."|".
1007 base64_encode($script['LogonData'])."|".
1008 $script['LogonDescription'];
1009 }
1011 /* Prepare Shares */
1012 $this->attrs['gotoShare']=array();
1013 foreach($this->gotoShares as $name => $share){
1014 $mntp= $share['mountPoint'];
1015 if (!preg_match('=^[a-z0-9+_/%-]+$=i', $mntp)){
1016 $mntp= base64_encode($mntp);
1017 }
1018 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1019 }
1022 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1023 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1025 foreach($saveThis as $tosave){
1026 if(!empty($this->$tosave)){
1027 $this->attrs[$tosave]=$this->$tosave;
1028 }else{
1029 $this->attrs[$tosave]=array();
1030 }
1031 }
1033 /* Prepare Flags */
1034 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
1035 if(empty($this->attrs['gotoProfileFlags'][0])){
1036 $this->attrs['gotoProfileFlags']=array();
1037 }
1039 if($this->useProfile == false){
1040 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1041 $this->attrs['gotoProfileServer']= array();
1042 }
1044 foreach($this->attributes as $s_attr){
1045 if(chkacl($this->acl,$s_attr)!="") {
1046 if(isset($this->attrs[$s_attr])){
1047 unset($this->attrs[$s_attr]);
1048 }
1049 }
1050 }
1052 $ldap->cat ($this->dn, array('dn'));
1053 if ($ldap->fetch()){
1054 $mode= "modify";
1055 } else {
1056 $mode= "add";
1057 $ldap->cd($this->config->current['BASE']);
1058 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1059 }
1061 $ldap->cd($this->dn);
1062 $this->cleanup();
1063 $ldap->$mode($this->attrs);
1064 show_ldap_error($ldap->get_error(), _("Adding environment information failed"));
1065 $this->handle_post_events($mode);
1066 }
1068 /* Generate ListBox frindly output for the defined shares
1069 * Possibly Add or remove an attribute here,
1070 */
1071 function printOutAssignedShares()
1072 {
1073 $a_return = array();
1074 if(is_array($this->gotoShares)){
1075 foreach($this->gotoShares as $share){
1076 if(preg_match("/^!/",$share['server'])){
1077 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1078 }else{
1079 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1080 }
1081 }
1082 }
1083 return($a_return);
1084 }
1086 /* Generate ListBox frindly output for the definedhotplugs
1087 * Possibly Add or remove an attribute here,
1088 */
1089 function printOutHotPlugDevices()
1090 {
1091 $a_return= array();
1092 if(is_array($this->gotoHotplugDevices)){
1093 foreach($this->gotoHotplugDevices as $key=>$device){
1094 $a_return[$key] = $device['name']." - ".$device['id'];
1095 }
1096 }
1097 return($a_return);
1098 }
1100 /* Generates ListBox frienly output of used printer devices
1101 * Append ' - admin' if printer is used in admin mode
1102 */
1103 function printOutPrinterDevices()
1104 {
1105 $a_return = array();
1106 if(is_array($this->gotoPrinter)){
1107 foreach($this->gotoPrinter as $printer){
1108 if($printer['mode'] == "admin"){
1109 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1110 }else{
1111 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1112 }
1113 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1114 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1115 }
1116 }
1117 }
1118 return($a_return);
1119 }
1121 /* Generates ListBox frienly output of used logonscripts
1122 */
1123 function printOutLogonScripts()
1124 {
1125 $a_return = array();
1126 if(is_array($this->gotoLogonScripts)){
1127 foreach($this->gotoLogonScripts as $script){
1128 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1129 }
1130 }
1131 return($a_return);
1132 }
1133 }
1138 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1139 ?>