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 "1154x864" => "1154x864",
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 /* Prepare all variables for smarty */
248 foreach($this->attributes as $s_attr){
249 /* Set value*/
250 $smarty->assign($s_attr,$this->$s_attr);
252 /* Set checkbox state*/
253 if(empty($this->$s_attr)){
254 $smarty->assign($s_attr."CHK","");
255 }else{
256 $smarty->assign($s_attr."CHK"," checked ");
257 }
259 /* Prepare ACL settings*/
260 if(chkacl($this->acl,$s_attr)=="") {
261 $smarty->assign($s_attr."ACL","");
262 }else{
263 $smarty->assign($s_attr."ACL"," disabled ");
264 }
266 }
268 /* Is accout enabled | are we editing from usermenu or admin menu
269 All these tab management is done here
270 */
272 /* Working from Usermenu an the Account is currently disbled
273 * this->parent : is only set if we are working in a list of tabs
274 * is_account : is only true if the needed objectClass is given
275 */
276 if((!isset($this->parent))&&(!$this->is_account)){
277 /* We are currently editing this tab from usermenu, but this account is not enabled */
278 $smarty->assign("is_account",$this->is_account);
279 /* Load template */
280 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
281 /* Avoid the "You are currently editing ...." message when you leave this tab */
282 $display .= back_to_main();
283 /* Display our message to the user */
284 return $display;
287 /* We are currently editing from group tabs, because
288 * $this->parent is set
289 * posixAccount is not set, so we are not in usertabs.
290 */
291 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
292 $smarty->assign("is_account","true");
293 $this->is_group = true;
294 $this->uid = $this->cn;
295 $this->attrs['uid'] = $this->cn;
297 /* Change state if needed */
298 if (isset($_POST['modify_state'])){
299 $this->is_account= !$this->is_account;
300 }
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 /* Do we need to flip is_account state? */
333 if (isset($_POST['modify_state'])){
334 $this->is_account= !$this->is_account;
335 }
337 if(isset($this->parent)){
339 // 3. Account enabled . Editing from adminmenu
340 if ($this->is_account){
341 $display= $this->show_disable_header(_("Remove environment extension"),
342 _("Environment extension enabled. You can disable it by clicking below."));
343 } else {
345 if($this->parent->by_object['posixAccount']->is_account==true){
346 // 4. There is a PosixAccount
347 $display= $this->show_disable_header(_("Add environment extension"),
348 _("Environment extension disabled. You can enable it by clicking below."));
349 return $display;
350 }else{
351 // 4. There is a PosixAccount
352 $display= $this->show_disable_header(_("Add environment extension"),
353 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
354 return $display;
355 }
356 }
357 }
358 }
359 /* Account is Account : is_accounbt=true.
360 * Else we won't reach this.
361 */
363 /* Prepare all variables for smarty */
364 foreach($this->attributes as $s_attr){
365 /* Set value*/
366 $smarty->assign($s_attr,$this->$s_attr);
368 /* Set checkbox state*/
369 if(empty($this->$s_attr)){
370 $smarty->assign($s_attr."CHK","");
371 }else{
372 $smarty->assign($s_attr."CHK"," checked ");
373 }
375 /* Prepare ACL settings*/
376 if(chkacl($this->acl,$s_attr)=="") {
377 $smarty->assign($s_attr."ACL","");
378 }else{
379 $smarty->assign($s_attr."ACL"," disabled ");
380 }
382 }
384 foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
385 if(chkacl($this->acl,$s_attr)=="") {
386 $smarty->assign($s_attr."ACL","");
387 }else{
388 $smarty->assign($s_attr."ACL"," disabled ");
389 }
390 }
392 if(empty($this->useProfile)){
393 $smarty->assign("gotoProfileACL","disabled");
394 $smarty->assign("useProfileCHK","");
395 }else{
396 $smarty->assign("gotoProfileACL","");
397 $smarty->assign("useProfileCHK"," checked ");
398 }
401 $smarty->assign("useProfileACL","");
402 if($this->acl != "#none#"){
403 $smarty->assign("useProfileACL","");
404 $smarty->assign("gotoProfileFlagCACL"," ");
405 $smarty->assign("gotoProfileQuotaACL"," ");
406 }else{
407 $smarty->assign("gotoProfileFlagCACL"," disabled ");
408 $smarty->assign("useProfileACL","disabled");
409 $smarty->assign("gotoProfileServer"," disabled ");
410 $smarty->assign("gotoProfileQuotaACL"," disabled ");
411 }
413 /* HANDLE Profile Settings here
414 * Assign available Quota and resolution settings
415 * Get all available profile server
416 * Get cache checkbox
417 * Assign this all to Smarty
418 */
420 if(empty($this->gotoProfileFlagL)){
421 $smarty->assign("gotoProfileFlagLCHK"," ");
422 }else{
423 $smarty->assign("gotoProfileFlagLCHK"," checked ");
424 }
426 if(empty($this->gotoProfileFlagC)){
427 $smarty->assign("gotoProfileFlagCCHK"," ");
428 }else{
429 $smarty->assign("gotoProfileFlagCCHK"," checked ");
430 }
433 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
434 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
436 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
437 if(!is_array($this->gotoProfileServers)){
438 $this->gotoProfileServers =array();
439 }
440 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
442 /* Handle kiosk profiles
443 * Read available from filesystem
444 * Open management if post is transmitted
445 */
447 /* Save */
448 if(isset($_POST['KioskClose'])){
449 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
451 unset($this->dialog);
452 $this->dialog=NULL;
453 $this->is_dialog = false;
454 }
456 /* Reassign help class */
457 $_SESSION['current_class_for_help'] = get_class($this);
459 /* Open Management Dialog */
460 if(isset($_POST['KioskManagementDialog'])){
461 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
462 $this->dialog->parent= $this;
463 $this->dialog->acl = $this->acl;
464 $this->is_dialog = true;
465 }
466 $tmp = new kioskManagementDialog($this->config,$this->dn);
467 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
468 $list['none']=_("None");
469 $list = array_reverse($list);
470 $smarty->assign("gotoKioskProfiles",$list);
471 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
473 /* Logonscript Management
474 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
475 * Perform add Delete edit Posts
476 */
478 /* Dialog Save */
479 if(isset($_POST['LogonSave'])){
480 $this->dialog->save_object();
481 if(count($this->dialog->check())!=0){
482 foreach($this->dialog->check() as $msg){
483 print_red($msg);
484 }
485 }else{
486 $tmp = $this->dialog->save();
487 unset($this->dialog);
488 $this->dialog=NULL;
489 $this->is_dialog=false;
490 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
491 }
492 }
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(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
504 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
505 * In this case we create a new Logon Script.
506 */
507 if(isset($_POST['gotoLogonScriptNew'])){
508 $this->is_dialog = true;
509 $this->dialog = new logonManagementDialog($this->config,$this->dn);
510 }
512 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
513 * We only can delete if there is an entry selected.
514 */
515 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
516 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
517 }
519 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
520 * There must be an entry selected to perform edit request.
521 */
522 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
523 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
524 $this->is_dialog = true;
525 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
526 }
527 }
529 /* Append List to smarty*/
530 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
531 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
533 /* In this section server shares will be defined
534 * A user can select one of the given shares and a mount point
535 * and attach this combination to his setup.
536 */
538 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
539 if(!is_array($this->gotoShareSelections)){
540 print $this->gotoShareSelections;
541 $this->gotoShareSelections = array();
542 }
543 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
545 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
546 * This entry will be, a combination of mountPoint and sharedefinitions
547 */
548 if(isset($_POST['gotoShareAdd'])){
549 /* We assign a share to this user, if we don't know where to mount the share */
550 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
551 print_red(_("You must specify a valid mount point."));
552 }elseif(!(
553 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
554 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
555 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
556 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
557 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
558 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
559 preg_match("/^%/",$_POST['gotoShareMountPoint'])
560 )
561 ){
562 print_red(_("You must specify a valid mount point."));
563 }else{
564 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
565 $s_mount = $_POST['gotoShareMountPoint'];
566 $s_user = $_POST['ShareUser'];
567 /* Preparing the new assignment */
568 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
569 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
570 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
571 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
572 }
573 }
575 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
576 * If there is no defined share selected, we will abort the deletion without any message
577 */
578 $once = true;
579 foreach($_POST as $name => $value){
580 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
581 $once = false;
582 $key = preg_replace("/^gotoShareDel_/","",$name);
583 $key = preg_replace("/_+[xy]$/","",$key);
584 $key = base64_decode($key);
585 if(isset($this->gotoShares[$key])) {
586 unset($this->gotoShares[$key]);
587 }
589 /* Remove corresponding password entry, too. This is a workaround
590 to get rid of old-style entries. */
591 $key= preg_replace("/\|/", "|!", $key);
592 if(isset($this->gotoShares[$key])) {
593 unset($this->gotoShares[$key]);
594 }
595 }
596 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
597 $once = false;
598 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
599 $key = preg_replace("/_+[xy]$/","",$key);
600 $key = base64_decode($key);
601 $this->gotoShares[$key]['PwdHash'] = "";
602 }
603 }
605 $divlistShares = new divSelectBox("gotoShares");
606 $divlistShares->SetHeight(100);
607 $tmp = $this->printOutAssignedShares();
609 foreach($tmp as $key => $value){
610 $img = "";
612 /* Check if entry starts with an ! */
613 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
615 /* If we are currently editing groups environment, skip those ! entries */
616 if($this->is_group) continue;
618 /* Create pwd reset images */
619 if($this->gotoShares[$key]['PwdHash'] != ""){
620 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
621 title='"._("Reset password hash")."'>";
622 }
623 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
624 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
625 }else{
627 /* Create pwd reset img && delete image */
628 if($this->gotoShares[$key]['PwdHash'] != ""){
629 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
630 title='"._("Reset password hash")."'>";
631 $img.= " ";
632 }
633 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."'
634 title='"._("Delete share entry")."'>";
635 $field1 = array("string" => $value);
636 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
637 }
638 $divlistShares->AddEntry(array($field1,$field2));
639 }
640 $smarty->assign("divlistShares",$divlistShares->DrawList());
642 /* Hotplug devices will be handled here
643 * There are 3 possible methods for this feature
644 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
645 * Delete will erase an entry, the entry must be selcted in the ListBox first
646 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
647 */
649 /* If there is a new entry wanted, open a new entry by initilising the dialog */
650 if(isset($_POST['gotoHotplugDeviceNew'])){
651 $this->dialog = new hotplugDialog($this->config,$this->dn);
652 $this->is_dialog = true;
653 }
655 /* We have to delete the selected hotplug from the list*/
656 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
657 foreach($_POST['gotoHotplugDevice'] as $name){
658 unset($this->gotoHotplugDevices[$name]);
659 }
660 }
662 /* There are already defined hotplugs from other users we could use */
663 if(isset($_POST['gotoHotplugDeviceUse'])){
664 $tmp =array();
665 foreach($this->gotoHotplugDevices as $plugs){
666 $tmp[] = $plugs['name'];
667 }
668 $this->dialog = new hotplugDialog($this->config,$this->dn,true,$tmp);
669 $this->is_dialog = true;
670 }
672 /* Dialog Aborted */
673 if(isset($_POST['HotPlugCancel'])){
674 unset($this->dialog);
675 $this->dialog= NULL;
676 $this->is_dialog = false;
677 }
679 /* Dialod saved */
680 if(isset($_POST['HotPlugSave'])){
681 $this->dialog->save_object();
682 if(count($this->dialog->check())!=0){
683 foreach($this->dialog->check() as $msg){
684 print_red($msg);
685 }
686 }else{
687 $this->dialog->save_object();
688 $a_tmp = $this->dialog->save();
690 if(is_array($a_tmp)){
691 foreach($a_tmp as $name => $hotplug){
692 $this->gotoHotplugDevices[$name]= $hotplug;
693 }
694 }
695 unset($this->dialog);
696 $this->dialog= NULL;
697 $this->is_dialog = false;
698 }
699 }
701 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
702 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
704 /* Printer Assignment will managed below
705 * A printer can be assigned in two different ways and two different types
706 * There are 2 types of users assigned to a printer : user and admin
707 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
708 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
709 */
711 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
712 if(isset($_POST['gotoPrinterAdd'])){
713 $this->is_dialog=true;
714 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
715 }
717 if(isset($_POST['PrinterCancel'])){
718 $this->is_dialog=false;
719 unset($this->dialog);
720 $this->dialog=NULL;
721 }
723 if(isset($_POST['PrinterSave'])){
724 if(count($this->dialog->check())!=0){
725 $tmp = $this->dialog->check();
726 foreach($tmp as $msg){
727 print_red($msg);
728 }
729 }else{
730 $this->dialog->save_object();
731 $tmp = $this->dialog->save();
732 $tmp2= $this->dialog->getPrinter(true);
734 foreach($tmp as $pname){
735 $this->gotoPrinter[$pname]=$tmp2[$pname];
736 $this->gotoPrinter[$pname]['mode']="user";
737 }
739 $this->is_dialog=false;
740 unset($this->dialog);
741 $this->dialog =NULL;
742 }
743 }
745 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
746 $printer = $_POST['gotoPrinterSel'];
747 foreach($printer as $pname){
748 unset($this->gotoPrinter[$pname]);
749 }
750 }
752 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
755 $printers = $_POST['gotoPrinterSel'];
757 foreach($printers as $printer){
758 if($this->gotoPrinter[$printer]['mode']=="user"){
759 $this->gotoPrinter[$printer]['mode']="admin";
760 }else{
761 $this->gotoPrinter[$printer]['mode']="user";
762 }
763 }
764 }
766 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
767 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
768 $this->gosaDefaultPrinter= "";
769 } else {
770 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
771 }
772 }
774 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
775 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
777 /* General behavior */
778 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
779 $this->dialog->save_object();
780 $disp =$this->dialog->execute();
782 $tmp = new kioskManagementDialog($this->config,$this->dn);
783 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
784 $list['none']=_("None");
785 $list = array_reverse($list);
786 if(!isset($list[$this->gotoKioskProfile])){
787 print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
788 $this->gotoKioskProfile = 'none';
789 }
790 return($disp);
791 }
792 if($this->acl != "#none#"){
793 $smarty->assign("useProfileACL","");
794 }else{
795 $smarty->assign("gotoProfileFlagCACL"," disabled ");
796 $smarty->assign("gotoProfileServerACL"," disabled ");
797 $smarty->assign("gotoProfileQuotaACL"," disabled ");
798 }
800 if(!$this->useProfile){
801 $smarty->assign("gotoProfileFlagCACL"," disabled ");
802 $smarty->assign("gotoProfileServerACL"," disabled ");
803 $smarty->assign("gotoProfileQuotaACL"," disabled ");
804 }
806 /* Als smarty vars are set. Get smarty template and generate output */
807 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
808 return($display);
809 }
811 function remove_from_parent()
812 {
813 /* only if it was an account*/
814 if (!$this->initially_was_account){
815 return;
816 }
818 /* include global link_info */
819 $ldap= $this->config->get_ldap_link();
821 /* Remove and write to LDAP */
822 plugin::remove_from_parent();
824 /* Don't save our template variables */
825 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
827 /* Skip all these attributes */
828 foreach($skip as $del){
829 unset($this->attrs[$del]);
830 }
832 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
834 $ldap->cd($this->dn);
835 $this->cleanup();
836 $ldap->modify ($this->attrs);
838 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
840 /* Optionally execute a command after we're done */
841 $this->handle_post_events("remove");
842 }
845 /* Save data to object */
846 function save_object()
847 {
848 /* Get all Posted vars
849 * Setup checkboxes
850 */
852 if(isset($_POST['iamposted'])){
853 if(isset($_POST['useProfile'])){
854 $this->useProfile = true;
855 }else{
856 $this->useProfile = false;
857 }
858 if(isset($_POST['gotoProfileFlagC'])){
859 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
860 }else{
861 $this->gotoProfileFlagC = false;
862 }
863 if(isset($_POST['gotoProfileFlagL'])){
864 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
865 }else{
866 $this->gotoProfileFlagL = false;
867 }
869 $tmp= $this->gosaDefaultPrinter;
870 plugin::save_object();
871 foreach($this->attributes as $s_attr){
872 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
873 if(isset($_POST[$s_attr])){
874 $this->$s_attr = $_POST[$s_attr];
875 }else{
876 $this->$s_attr = false;
877 }
878 }
879 $this->gosaDefaultPrinter= $tmp;
880 }
881 }
884 /* Check supplied data */
885 function check()
886 {
887 /* Call common method to give check the hook */
888 $message= plugin::check();
890 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
891 $message[]=_("Please set a valid profile quota size.");
892 }
893 if(!isset($this->attrs['objectClass'])){
894 $this->attrs['objectClass']=array();
895 }
896 if(!$this->is_group){
897 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
898 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
899 }
900 }
901 return ($message);
902 }
905 /* Save to LDAP */
906 function save()
907 {
908 /* If group was renamed, all printer settings get lost
909 */
910 /* only save changed variables ....*/
911 if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
912 if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
913 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
914 $method="https://";
915 }else{
916 $method="http://";
917 }
919 $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
920 $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
921 }else{
922 $this->gotoKioskProfile= array();
923 }
925 plugin::save();
926 $ldap= $this->config->get_ldap_link();
928 $realyUsedAttrs= array();
930 $path = search_config($this->config->data,"environment", "KIOSKPATH");
931 /* Creating Kiosk Profiles */
932 foreach($this->newKioskProfiles as $file){
933 $contents = $file['contents'];
934 $fp = @fopen($path."/".$file['name'],"w");
935 if(!$fp){
936 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
937 }else{
938 fwrite($fp,$contents,strlen($contents));
939 }
940 @unlink($file['tmp_name']);
941 }
943 /* Save already used objectClasses */
944 $ocs = $this->attrs['objectClass'];
945 unset($ocs['count']);
946 $this->attrs = array();
947 $this->attrs['objectClass']= $ocs;
948 foreach($this->objectclasses as $objc){
949 if(!in_array($objc,$this->attrs['objectClass'])){
950 $this->attrs['objectClass'][]=$objc;
951 }
952 }
955 /* Save usersettings to Printer */
956 if(chkacl($this->acl,"gotoPrinter")!=""){
957 $this->gotoPrinter = array();
958 }
960 /* 1. Search all printers that have our uid/cn as member
961 * 2. Delete this uid/cn from every single entry and save it again.
962 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
963 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
964 */
965 $types = array( "gotoUserPrinter" => "AddUser",
966 "gotoGroupPrinter" => "AddGroup",
967 "gotoUserAdminPrinter" => "AddAdminUser",
968 "gotoGroupAdminPrinter" => "AddAdminGroup");
970 if($this->is_group){
971 $s_suffix = "Group";
972 $useVar = "cn";
973 }else{
974 $useVar = "uid";
975 $s_suffix = "User";
976 }
978 /* Remove old entries */
979 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->uid."))",array("*"));
980 while($attr = $ldap->fetch()){
981 $printerObj = NULL;
982 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
983 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->uid);
984 $printerObj->by_object['printgeneric']->save();
985 }
987 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->uid."))",array("*"));
988 while($attr = $ldap->fetch()){
989 $printerObj = NULL;
990 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn']);
991 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->uid);
992 $printerObj->by_object['printgeneric']->save();
993 }
995 foreach($this->gotoPrinter as $printer){
996 $printerObj = NULL;
997 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn']);
999 if($printer['mode'] == "admin") {
1000 $attribute = "goto".$s_suffix."AdminPrinter";
1001 }else{
1002 $attribute = "goto".$s_suffix."Printer";
1003 }
1005 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1006 $printerObj->by_object['printgeneric']->save();
1007 }
1009 /* Prepare HotPlug devices */
1010 $this->attrs['gotoHotplugDevice'] = array();
1011 foreach($this->gotoHotplugDevices as $name => $device){
1012 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'].
1013 "|".$device['produkt']."|".$device['vendor'];
1014 }
1016 /* Prepare LogonScripts */
1017 $this->attrs['gotoLogonScript'] = array();
1018 foreach($this->gotoLogonScripts as $name => $script){
1019 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1020 $script['LogonOverload'].$script['LogonLast']."|".
1021 $script['LogonPriority']."|".
1022 base64_encode($script['LogonData'])."|".
1023 $script['LogonDescription'];
1024 }
1026 /* Prepare Shares */
1027 $this->attrs['gotoShare']=array();
1028 foreach($this->gotoShares as $name => $share){
1029 $mntp= $share['mountPoint'];
1030 if (!preg_match('=^[a-z0-9+_/%-]+$=i', $mntp)){
1031 $mntp= base64_encode($mntp);
1032 }
1033 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1034 }
1037 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1038 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1040 foreach($saveThis as $tosave){
1041 if(!empty($this->$tosave)){
1042 $this->attrs[$tosave]=$this->$tosave;
1043 }else{
1044 $this->attrs[$tosave]=array();
1045 }
1046 }
1048 /* Prepare Flags */
1049 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1050 if(empty($this->attrs['gotoProfileFlags'][0])){
1051 $this->attrs['gotoProfileFlags']=array();
1052 }
1054 if($this->useProfile == false){
1055 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1056 $this->attrs['gotoProfileServer']= array();
1057 }
1059 foreach($this->attributes as $s_attr){
1060 if(chkacl($this->acl,$s_attr)!="") {
1061 if(isset($this->attrs[$s_attr])){
1062 unset($this->attrs[$s_attr]);
1063 }
1064 }
1065 }
1067 $ldap->cat ($this->dn, array('dn'));
1068 if ($ldap->fetch()){
1069 $mode= "modify";
1070 } else {
1071 $mode= "add";
1072 $ldap->cd($this->config->current['BASE']);
1073 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1074 }
1076 $ldap->cd($this->dn);
1077 $this->cleanup();
1078 $ldap->$mode($this->attrs);
1079 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1080 $this->handle_post_events($mode);
1081 }
1083 /* Generate ListBox frindly output for the defined shares
1084 * Possibly Add or remove an attribute here,
1085 */
1086 function printOutAssignedShares()
1087 {
1088 $a_return = array();
1089 if(is_array($this->gotoShares)){
1090 foreach($this->gotoShares as $share){
1091 if(preg_match("/^!/",$share['server'])){
1092 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1093 }else{
1094 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1095 }
1096 }
1097 natcasesort($a_return);
1098 }
1099 return($a_return);
1100 }
1102 /* Generate ListBox frindly output for the definedhotplugs
1103 * Possibly Add or remove an attribute here,
1104 */
1105 function printOutHotPlugDevices()
1106 {
1107 $a_return= array();
1108 if(is_array($this->gotoHotplugDevices)){
1109 foreach($this->gotoHotplugDevices as $key=>$device){
1110 $a_return[$key] = $device['name']." - ".$device['id'];
1111 }
1112 }
1113 return($a_return);
1114 }
1116 /* Generates ListBox frienly output of used printer devices
1117 * Append ' - admin' if printer is used in admin mode
1118 */
1119 function printOutPrinterDevices()
1120 {
1121 $a_return = array();
1122 if(is_array($this->gotoPrinter)){
1123 foreach($this->gotoPrinter as $printer){
1124 if($printer['mode'] == "admin"){
1125 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1126 }else{
1127 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1128 }
1129 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1130 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1131 }
1132 }
1133 }
1134 return($a_return);
1135 }
1137 /* Generates ListBox frienly output of used logonscripts
1138 */
1139 function printOutLogonScripts()
1140 {
1141 $a_return = array();
1142 if(is_array($this->gotoLogonScripts)){
1143 foreach($this->gotoLogonScripts as $script){
1144 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1145 }
1146 }
1147 return($a_return);
1148 }
1151 /* Return plugin informations for acl handling
1152 #FIXME these ACLs should work for groups too */
1153 function plInfo()
1154 {
1155 return (array("plShortName" => _("Environment"),
1156 "plDescription" => _("Environment settings"), // Description
1157 "plSelfModify" => TRUE,
1158 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1159 "plPriority" => 2, // Position in tabs
1160 "plSection" => "personal", // This belongs to personal
1161 "plCategory" => array("users", "groups"), // Add to following categories
1162 "plOptions" => array("resolution_hook" => array("type" => "string",
1163 "description" => _("Command to extend the list of possible screen resolutions"))),
1165 "plProvidedAcls" => array(
1167 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1168 "gotoProfileFlagC" => _("Cache profile localy") ,
1170 "gotoProfileQuota" => _("Profile quota") ,
1171 "gotoProfileServer" => _("Profile server") ,
1173 "gotoXResolution" => _("Resolution") ,
1174 "gotoKioskProfile" => _("Kiosk profile") ,
1176 "gosaDefaultPrinter" => _("Default printer") ,
1177 "gotoLogonScript" => _("Logon script") ,
1178 "gotoHotplugDevice" => _("Hotplug devices"),
1179 "gotoShare" => _("Shares"))
1180 ));
1181 }
1182 }
1184 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1185 ?>