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];
152 $tmp2['mountPoint'] =$tmp[2];
153 if(isset($tmp[3])){
154 $tmp2['PwdHash'] =$tmp[3];
155 }else{
156 $tmp2['PwdHash'] ="";
157 }
158 if(isset($tmp[4])){
159 $tmp2['Username'] =$tmp[4];
160 }else{
161 $tmp2['Username'] ="";
162 }
163 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
164 }
165 }
167 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
168 $chr = $this->gotoProfileFlags[$i];
169 $name = "gotoProfileFlag_".$chr;
170 $this->$name=$chr;
171 }
173 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlag_C=="C")){
174 $this->useProfile = true;
175 }else{
176 $this->useProfile = false;
177 }
179 /* Set to group environment if we editing a group */
180 if(!isset($this->parent)){
181 $this->is_group = true;
182 }
184 /* Set resolutions */
185 $this->gotoXResolutions = array("auto"=>_("auto"),
186 "640x480" => "640x480",
187 "800x600" => "800x600",
188 "1024x768" => "1024x768",
189 "1154x864" => "1154x864",
190 "1280x768" => "1280x768",
191 "1280x1024" => "1280x1024");
193 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
194 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
196 if(is_readable($file)){
197 $str = file_get_contents($file);
198 $lines = split("\n",$str);
199 foreach($lines as $line){
200 $line = trim($line);
201 if(!empty($line)){
202 $this->gotoXResolutions[$line]=$line;
203 }
204 }
205 //natcasesort($this->gotoXResolutions);
206 }else{
207 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
208 }
209 }
212 $this->gotoProfileServers= $config->getShareServerList() ;
213 $this->gotoShareSelections= $config->getShareList(true);
214 $this->gotoAvailableShares= $config->getShareList(false);
216 }
218 function execute()
219 {
220 /* Call parent execute */
221 plugin::execute();
223 /* Fill templating stuff */
224 $smarty= get_smarty();
225 $display= "";
227 /* Prepare all variables for smarty */
228 foreach($this->attributes as $s_attr){
229 /* Set value*/
230 $smarty->assign($s_attr,$this->$s_attr);
232 /* Set checkbox state*/
233 if(empty($this->$s_attr)){
234 $smarty->assign($s_attr."CHK","");
235 }else{
236 $smarty->assign($s_attr."CHK"," checked ");
237 }
239 /* Prepare ACL settings*/
240 if(chkacl($this->acl,$s_attr)=="") {
241 $smarty->assign($s_attr."ACL","");
242 }else{
243 $smarty->assign($s_attr."ACL"," disabled ");
244 }
246 }
248 /* Is accout enabled | are we editing from usermenu or admin menu
249 All these tab management is done here
250 */
252 /* Working from Usermenu an the Account is currently disbled
253 * this->parent : is only set if we are working in a list of tabs
254 * is_account : is only true if the needed objectClass is given
255 */
256 if((!isset($this->parent))&&(!$this->is_account)){
257 /* We are currently editing this tab from usermenu, but this account is not enabled */
258 $smarty->assign("is_account",$this->is_account);
259 /* Load template */
260 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
261 /* Avoid the "You are currently editing ...." message when you leave this tab */
262 $display .= back_to_main();
263 /* Display our message to the user */
264 return $display;
267 /* We are currently editing from group tabs, because
268 * $this->parent is set
269 * posixAccount is not set, so we are not in usertabs.
270 */
271 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
272 $smarty->assign("is_account","true");
273 $this->is_group = true;
274 $this->uid = $this->cn;
275 $this->attrs['uid'] = $this->cn;
277 /* Change state if needed */
278 if (isset($_POST['modify_state'])){
279 $this->is_account= !$this->is_account;
280 }
282 /* Group Dialog with enabled environment options */
283 if ($this->is_account){
284 $display= $this->show_header(_("Remove environment extension"),
285 _("Environment extension enabled. You can disable it by clicking below."));
286 } else {
288 /* Environment is disabled
289 If theres is no posixAccount enabled, you won't be able to enable
290 environment extensions
291 */
292 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
293 // 4. There is a PosixAccount
294 $display= $this->show_header(_("Add environment extension"),
295 _("Environment extension disabled. You can enable it by clicking below."));
296 return $display;
297 }else{
298 // 4. There is no PosixAccount
299 $display= $this->show_header(_("Add environment extension"),
300 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
301 return $display;
302 }
303 }
304 }else{
305 /* Editing from Usermenu
306 * Tell smarty that this accoutn is enabled
307 */
308 $smarty->assign("is_account","true");
310 $this->is_group = false;
312 /* Do we need to flip is_account state? */
313 if (isset($_POST['modify_state'])){
314 $this->is_account= !$this->is_account;
315 }
317 if(isset($this->parent)){
319 // 3. Account enabled . Editing from adminmenu
320 if ($this->is_account){
321 $display= $this->show_header(_("Remove environment extension"),
322 _("Environment extension enabled. You can disable it by clicking below."));
323 } else {
325 if($this->parent->by_object['posixAccount']->is_account==true){
326 // 4. There is a PosixAccount
327 $display= $this->show_header(_("Add environment extension"),
328 _("Environment extension disabled. You can enable it by clicking below."));
329 return $display;
330 }else{
331 // 4. There is a PosixAccount
332 $display= $this->show_header(_("Add environment extension"),
333 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
334 return $display;
335 }
336 }
337 }
338 }
339 /* Account is Account : is_accounbt=true.
340 * Else we won't reach this.
341 */
343 /* Prepare all variables for smarty */
344 foreach($this->attributes as $s_attr){
345 /* Set value*/
346 $smarty->assign($s_attr,$this->$s_attr);
348 /* Set checkbox state*/
349 if(empty($this->$s_attr)){
350 $smarty->assign($s_attr."CHK","");
351 }else{
352 $smarty->assign($s_attr."CHK"," checked ");
353 }
355 /* Prepare ACL settings*/
356 if(chkacl($this->acl,$s_attr)=="") {
357 $smarty->assign($s_attr."ACL","");
358 }else{
359 $smarty->assign($s_attr."ACL"," disabled ");
360 }
362 }
364 foreach(array("gotoHotplugDevice","gotoPrinterSel") as $s_attr){
365 if(chkacl($this->acl,$s_attr)=="") {
366 $smarty->assign($s_attr."ACL","");
367 }else{
368 $smarty->assign($s_attr."ACL"," disabled ");
369 }
370 }
372 if(empty($this->useProfile)){
373 $smarty->assign("gotoProfileACL","disabled");
374 $smarty->assign("useProfileCHK","");
375 }else{
376 $smarty->assign("gotoProfileACL","");
377 $smarty->assign("useProfileCHK"," checked ");
378 }
381 $smarty->assign("useProfileACL","");
382 if($this->acl != "#none#"){
383 $smarty->assign("useProfileACL","");
384 $smarty->assign("gotoProfileFlag_CACL"," ");
385 $smarty->assign("gotoProfileQuotaACL"," ");
386 }else{
387 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
388 $smarty->assign("useProfileACL","disabled");
389 $smarty->assign("gotoProfileServer"," disabled ");
390 $smarty->assign("gotoProfileQuotaACL"," disabled ");
391 }
393 /* HANDLE Profile Settings here
394 * Assign available Quota and resolution settings
395 * Get all available profile server
396 * Get cache checkbox
397 * Assign this all to Smarty
398 */
400 if(empty($this->gotoProfileFlag_L)){
401 $smarty->assign("gotoProfileFlag_LCHK"," ");
402 }else{
403 $smarty->assign("gotoProfileFlag_LCHK"," checked ");
404 }
406 if(empty($this->gotoProfileFlag_C)){
407 $smarty->assign("gotoProfileFlag_CCHK"," ");
408 }else{
409 $smarty->assign("gotoProfileFlag_CCHK"," checked ");
410 }
413 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
414 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
416 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
417 if(!is_array($this->gotoProfileServers)){
418 $this->gotoProfileServers =array();
419 }
420 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
422 /* Handle kiosk profiles
423 * Read available from filesystem
424 * Open management if post is transmitted
425 */
427 /* Save */
428 if(isset($_POST['KioskClose'])){
429 $this->newKioskProfiles = array_merge($this->newKioskProfiles,$this->dialog->save());
431 unset($this->dialog);
432 $this->dialog=NULL;
433 $this->is_dialog = false;
434 }
436 /* Reassign help class */
437 $_SESSION['current_class_for_help'] = get_class($this);
439 /* Open Management Dialog */
440 if(isset($_POST['KioskManagementDialog'])){
441 $this->dialog = new kioskManagementDialog($this->config,$this->dn,$this->newKioskProfiles);
442 $this->dialog->parent= $this;
443 $this->dialog->acl = $this->acl;
444 $this->is_dialog = true;
445 }
446 $tmp = new kioskManagementDialog($this->config,$this->dn);
447 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
448 $list['none']=_("None");
449 $list = array_reverse($list);
450 $smarty->assign("gotoKioskProfiles",$list);
451 $smarty->assign("gotoKioskProfileKeys",array_flip($list));
453 /* Logonscript Management
454 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
455 * Perform add Delete edit Posts
456 */
458 /* Dialog Save */
459 if(isset($_POST['LogonSave'])){
460 $this->dialog->save_object();
461 if(count($this->dialog->check())!=0){
462 foreach($this->dialog->check() as $msg){
463 print_red($msg);
464 }
465 }else{
466 $tmp = $this->dialog->save();
467 unset($this->dialog);
468 $this->dialog=NULL;
469 $this->is_dialog=false;
470 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
471 }
472 }
474 /* Dialog Quit without saving */
475 if(isset($_POST['LogonCancel'])){
476 $this->is_dialog= false;
477 unset($this->dialog);
478 $this->dialog= NULL;
479 }
481 /* Check Edit Del New Posts for a selected LogonScript */
482 if(isset($_POST['gotoLogonScriptNew'])||isset($_POST['gotoLogonScriptEdit'])||isset($_POST['gotoLogonScriptDel'])){
484 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
485 * In this case we create a new Logon Script.
486 */
487 if(isset($_POST['gotoLogonScriptNew'])){
488 $this->is_dialog = true;
489 $this->dialog = new logonManagementDialog($this->config,$this->dn);
490 }
492 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
493 * We only can delete if there is an entry selected.
494 */
495 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
496 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
497 }
499 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
500 * There must be an entry selected to perform edit request.
501 */
502 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
503 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
504 $this->is_dialog = true;
505 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
506 }
507 }
509 /* Append List to smarty*/
510 $smarty->assign("gotoLogonScripts", $this->printOutLogonScripts());
511 $smarty->assign("gotoLogonScriptKeys",array_flip($this->printOutLogonScripts()));
513 /* In this section server shares will be defined
514 * A user can select one of the given shares and a mount point
515 * and attach this combination to his setup.
516 */
518 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
519 if(!is_array($this->gotoShareSelections)){
520 print $this->gotoShareSelections;
521 $this->gotoShareSelections = array();
522 }
523 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
525 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
526 * This entry will be, a combination of mountPoint and sharedefinitions
527 */
528 if(isset($_POST['gotoShareAdd'])){
529 /* We assign a share to this user, if we don't know where to mount the share */
530 if((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
531 print_red(_("You must specify a valid mount point."));
532 }elseif(!(
533 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
534 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
535 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
536 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
537 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
538 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
539 preg_match("/^%/",$_POST['gotoShareMountPoint'])
540 )
541 ){
542 print_red(_("You must specify a valid mount point."));
543 }else{
544 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
545 $s_mount = $_POST['gotoShareMountPoint'];
546 $s_user = $_POST['ShareUser'];
547 /* Preparing the new assignment */
548 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
549 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
550 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
551 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
552 }
553 }
555 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
556 * If there is no defined share selected, we will abort the deletion without any message
557 */
558 $once = true;
559 foreach($_POST as $name => $value){
560 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
561 $once = false;
562 $key = preg_replace("/^gotoShareDel_/","",$name);
563 $key = preg_replace("/_+[xy]$/","",$key);
564 $key = preg_replace("/_/", ".", $key);
565 if(isset($this->gotoShares[$key])) {
566 unset($this->gotoShares[$key]);
567 }
569 /* Remove corresponding password entry, too. This is a workaround
570 to get rid of old-style entries. */
571 $key= preg_replace("/\|/", "|!", $key);
572 if(isset($this->gotoShares[$key])) {
573 unset($this->gotoShares[$key]);
574 }
576 }
577 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
578 $once = false;
579 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
580 $key = preg_replace("/_+[xy]$/","",$key);
581 $key = preg_replace("/_/", ".", $key);
582 $this->gotoShares[$key]['PwdHash'] = "";
583 }
584 }
586 $divlistShares = new divSelectBox("gotoShares");
587 $divlistShares->SetHeight(100);
588 $tmp = $this->printOutAssignedShares();
590 foreach($tmp as $key => $value){
591 $img = "";
593 /* Check if entry starts with an ! */
594 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
596 /* If we are currently editing groups environment, skip those ! entries */
597 if($this->is_group) continue;
599 /* Create pwd reset images */
600 if($this->gotoShares[$key]['PwdHash'] != ""){
601 $img.= "<input type='image' name='gotoShareResetPwd_".$key." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
602 title='"._("Reset password hash")."'>";
603 }
604 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" );
605 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
606 }else{
608 /* Create pwd reset img && delete image */
609 if($this->gotoShares[$key]['PwdHash'] != ""){
610 $img.= "<input type='image' name='gotoShareResetPwd_".$key." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
611 title='"._("Reset password hash")."'>";
612 $img.= " ";
613 }
614 $img.= "<input type='image' name='gotoShareDel_".$key." 'src='images/edittrash.png' alt='"._("Delete")."'
615 title='"._("Delete share entry")."'>";
616 $field1 = array("string" => $value);
617 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
618 }
619 $divlistShares->AddEntry(array($field1,$field2));
620 }
621 $smarty->assign("divlistShares",$divlistShares->DrawList());
623 /* Hotplug devices will be handled here
624 * There are 3 possible methods for this feature
625 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
626 * Delete will erase an entry, the entry must be selcted in the ListBox first
627 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
628 */
630 /* If there is a new entry wanted, open a new entry by initilising the dialog */
631 if(isset($_POST['gotoHotplugDeviceNew'])){
632 $this->dialog = new hotplugDialog($this->config,$this->dn);
633 $this->is_dialog = true;
634 }
636 /* We have to delete the selected hotplug from the list*/
637 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice']))){
638 foreach($_POST['gotoHotplugDevice'] as $name){
639 unset($this->gotoHotplugDevices[$name]);
640 }
641 }
643 /* There are already defined hotplugs from other users we could use */
644 if(isset($_POST['gotoHotplugDeviceUse'])){
645 $this->dialog = new hotplugDialog($this->config,$this->dn,true);
646 $this->is_dialog = true;
647 }
649 /* Dialog Aborted */
650 if(isset($_POST['HotPlugCancel'])){
651 unset($this->dialog);
652 $this->dialog= NULL;
653 $this->is_dialog = false;
654 }
656 /* Dialod saved */
657 if(isset($_POST['HotPlugSave'])){
658 $this->dialog->save_object();
659 if(count($this->dialog->check())!=0){
660 foreach($this->dialog->check() as $msg){
661 print_red($msg);
662 }
663 }else{
664 $this->dialog->save_object();
665 $a_tmp = $this->dialog->save();
667 if(is_array($a_tmp)){
668 foreach($a_tmp as $name => $hotplug){
669 $this->gotoHotplugDevices[$name]= $hotplug;
670 }
671 }
672 unset($this->dialog);
673 $this->dialog= NULL;
674 $this->is_dialog = false;
675 }
676 }
678 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
679 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
681 /* Printer Assignment will managed below
682 * A printer can be assigned in two different ways and two different types
683 * There are 2 types of users assigned to a printer : user and admin
684 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
685 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
686 */
688 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
689 if(isset($_POST['gotoPrinterAdd'])){
690 $this->is_dialog=true;
691 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
692 }
694 if(isset($_POST['PrinterCancel'])){
695 $this->is_dialog=false;
696 unset($this->dialog);
697 $this->dialog=NULL;
698 }
700 if(isset($_POST['PrinterSave'])){
701 if(count($this->dialog->check())!=0){
702 $tmp = $this->dialog->check();
703 foreach($tmp as $msg){
704 print_red($msg);
705 }
706 }else{
707 $this->dialog->save_object();
708 $tmp = $this->dialog->save();
709 $tmp2= $this->dialog->getPrinter(true);
711 foreach($tmp as $pname){
712 $this->gotoPrinter[$pname]=$tmp2[$pname];
713 $this->gotoPrinter[$pname]['mode']="user";
714 }
716 $this->is_dialog=false;
717 unset($this->dialog);
718 $this->dialog =NULL;
719 }
720 }
722 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
723 $printer = $_POST['gotoPrinterSel'];
724 foreach($printer as $pname){
725 unset($this->gotoPrinter[$pname]);
726 }
727 }
729 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
732 $printers = $_POST['gotoPrinterSel'];
734 foreach($printers as $printer){
735 if($this->gotoPrinter[$printer]['mode']=="user"){
736 $this->gotoPrinter[$printer]['mode']="admin";
737 }else{
738 $this->gotoPrinter[$printer]['mode']="user";
739 }
740 }
741 }
743 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
744 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
745 $this->gosaDefaultPrinter= "";
746 } else {
747 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
748 }
749 }
751 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
752 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
754 /* General behavior */
755 if((isset($this->dialog))&&($this->dialog!=NULL)&&(!empty($this->dialog))){
756 $this->dialog->save_object();
757 $disp =$this->dialog->execute();
759 $tmp = new kioskManagementDialog($this->config,$this->dn);
760 $list = $tmp->getKioskProfiles($this->newKioskProfiles);
761 $list['none']=_("None");
762 $list = array_reverse($list);
763 if(!isset($list[$this->gotoKioskProfile])){
764 print_red(sprintf(_("The selected kiosk profile '%s' is no longer available, setting current profile to 'none'."),$this->gotoKioskProfile));
765 $this->gotoKioskProfile = 'none';
766 }
767 return($disp);
768 }
769 if($this->acl != "#none#"){
770 $smarty->assign("useProfileACL","");
771 }else{
772 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
773 $smarty->assign("gotoProfileServerACL"," disabled ");
774 $smarty->assign("gotoProfileQuotaACL"," disabled ");
775 }
777 if(!$this->useProfile){
778 $smarty->assign("gotoProfileFlag_CACL"," disabled ");
779 $smarty->assign("gotoProfileServerACL"," disabled ");
780 $smarty->assign("gotoProfileQuotaACL"," disabled ");
781 }
783 /* Als smarty vars are set. Get smarty template and generate output */
784 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
785 return($display);
786 }
788 function remove_from_parent()
789 {
790 /* only if it was an account*/
791 if (!$this->initially_was_account){
792 return;
793 }
795 /* include global link_info */
796 $ldap= $this->config->get_ldap_link();
798 /* Remove and write to LDAP */
799 plugin::remove_from_parent();
801 /* Don't save our template variables */
802 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoKioskProfiles","gotoHotplugDevices" );
804 /* Skip all these attributes */
805 foreach($skip as $del){
806 unset($this->attrs[$del]);
807 }
809 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
811 $ldap->cd($this->dn);
812 $this->cleanup();
813 $ldap->modify ($this->attrs);
815 show_ldap_error($ldap->get_error(), _("Removing environment information failed"));
817 /* Optionally execute a command after we're done */
818 $this->handle_post_events("remove");
819 }
822 /* Save data to object */
823 function save_object()
824 {
825 /* Get all Posted vars
826 * Setup checkboxes
827 */
829 if(isset($_POST['iamposted'])){
830 if(isset($_POST['useProfile'])){
831 $this->useProfile = true;
832 }else{
833 $this->useProfile = false;
834 }
835 if(isset($_POST['gotoProfileFlag_C'])){
836 $this->gotoProfileFlag_C = $_POST['gotoProfileFlag_C'];
837 }else{
838 $this->gotoProfileFlag_C = false;
839 }
840 if(isset($_POST['gotoProfileFlag_L'])){
841 $this->gotoProfileFlag_L = $_POST['gotoProfileFlag_L'];
842 }else{
843 $this->gotoProfileFlag_L = false;
844 }
846 $tmp= $this->gosaDefaultPrinter;
847 plugin::save_object();
848 foreach($this->attributes as $s_attr){
849 if(in_array($s_attr,array("gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
850 if(isset($_POST[$s_attr])){
851 $this->$s_attr = $_POST[$s_attr];
852 }else{
853 $this->$s_attr = false;
854 }
855 }
856 $this->gosaDefaultPrinter= $tmp;
857 }
858 }
861 /* Check supplied data */
862 function check()
863 {
864 /* Call common method to give check the hook */
865 $message= plugin::check();
867 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
868 $message[]=_("Please set a valid profile quota size.");
869 }
870 if(!isset($this->attrs['objectClass'])){
871 $this->attrs['objectClass']=array();
872 }
873 if(!$this->is_group){
874 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
875 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
876 }
877 }
878 return ($message);
879 }
882 /* Save to LDAP */
883 function save()
884 {
885 /* If group was renamed, all printer settings get lost
886 */
887 /* only save changed variables ....*/
888 if ($this->gotoKioskProfile =="none") $this->gotoKioskProfile ="";
889 if((!empty($this->gotoKioskProfile))&&($this->gotoKioskProfile != "none")){
890 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
891 $method="https://";
892 }else{
893 $method="http://";
894 }
896 $str = $method.str_replace("//","/",$_SERVER['SERVER_NAME']."/kiosk/");
897 $this->gotoKioskProfile= $str.$this->gotoKioskProfile;
898 }else{
899 $this->gotoKioskProfile= array();
900 }
902 plugin::save();
903 $ldap= $this->config->get_ldap_link();
905 $realyUsedAttrs= array();
907 $path = search_config($this->config->data,"environment", "KIOSKPATH");
908 /* Creating Kiosk Profiles */
909 foreach($this->newKioskProfiles as $file){
910 $contents = $file['contents'];
911 $fp = @fopen($path."/".$file['name'],"w");
912 if(!$fp){
913 print_red(_("Can't save new kiosk profiles, possibly permission denied for folder")." : ",$path);
914 }else{
915 fwrite($fp,$contents,strlen($contents));
916 }
917 @unlink($file['tmp_name']);
918 }
920 /* Save already used objectClasses */
921 $ocs = $this->attrs['objectClass'];
922 unset($ocs['count']);
923 $this->attrs = array();
924 $this->attrs['objectClass']= $ocs;
925 foreach($this->objectclasses as $objc){
926 if(!in_array($objc,$this->attrs['objectClass'])){
927 $this->attrs['objectClass'][]=$objc;
928 }
929 }
932 /* Save usersettings to Printer */
934 if(chkacl($this->acl,"gotoPrinter")!=""){
935 $this->gotoPrinter = array();
936 }
938 if($this->is_group){
939 $s_suffix = "Group";
940 }else{
941 $s_suffix = "User";
942 }
945 /* 1. Search all printers that have our uid/cn as member
946 * 2. Delete this uid/cn from every single entry and save it again.
947 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
948 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
949 */
950 $ldap->search("(&(objectClass=gotoPrinter)(|(goto".$s_suffix."Printer=".$this->uid.")(goto".$s_suffix."AdminPrinter=".$this->uid.")))",array("*"));
951 while($attr = $ldap->fetch()){
953 /* Walk trough all printers and check if our user id used, if so remove it.
954 * Later we will insert our uid at the right place.
955 */
957 /* Remove normal entries (User)*/
958 if(isset($attr['goto'.$s_suffix.'Printer'])) {
959 foreach($attr['goto'.$s_suffix.'Printer'] as $key => $user){
960 if($this->uid==$user){
961 unset($attr['goto'.$s_suffix.'Printer'][$key]);
962 }
963 }
964 $tmp = array();
965 foreach($attr['goto'.$s_suffix.'Printer'] as $user){
966 $tmp[] = $user;
967 }
968 $attr['goto'.$s_suffix.'Printer'] = array();
969 $attr['goto'.$s_suffix.'Printer'] = $tmp;
970 }
972 /* Remove administrational entries (Admin)*/
973 if(isset($attr['goto'.$s_suffix.'AdminPrinter'])){
974 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $key => $user){
975 if($this->uid==$user){
976 unset($attr['goto'.$s_suffix.'AdminPrinter'][$key]);
977 }
978 }
979 $tmp = array();
980 foreach($attr['goto'.$s_suffix.'AdminPrinter'] as $user){
981 $tmp[] = $user;
982 }
983 $attr['goto'.$s_suffix.'AdminPrinter'] = array();
984 $attr['goto'.$s_suffix.'AdminPrinter'] = $tmp;
985 }
987 /* Extract useable tags, to be able to save all changes
988 */
989 $attrs_used = array();
990 foreach($attr as $key=>$val){
992 /* If index is numeric, skip it ...*/
993 if((!is_numeric($key))&&($key!="count")){
995 /* If entry contains 'count' remove it */
996 if(is_array($val)&&isset($val['count'])){
997 unset($val['count']);
998 }
999 $attrs_used[$key]=$val;
1000 }
1001 }
1002 /* the result of cleaning the entry is
1003 * to be able to directly save this again,
1004 * if all changes are made
1005 */
1006 $attr= $attrs_used;
1008 #fix : Id don't know why such an entry was set ...
1009 if(isset($attr['GOTOADMINPRINTER'])){
1010 unset($attr['GOTOADMINPRINTER']);
1011 }
1013 /* Save changes */
1014 $ldap->cd($attr['dn']);
1015 unset($attr['dn']);
1016 $ldap->modify ($attr);
1018 if($ldap->get_error()!="Success"){
1019 print_red(_("Error while writing printer")." : ".$ldap->get_error());
1020 }
1021 }
1023 /* All printers are cleaned, (our cn/uid removed)
1024 * now we must add our uid / cn
1025 * to the new configured printers.
1026 */
1027 foreach($this->gotoPrinter as $printer) {
1028 $ldap->cat($printer['dn']);
1029 $attrs= $ldap->fetch();
1030 $attrs_used = array();
1031 foreach($attrs as $key=>$val){
1032 if((!is_numeric($key))&&($key!="count")){
1033 if(is_array($val)&&isset($val['count'])){
1034 unset($val['count']);
1035 }
1036 $attrs_used[$key]=$val;
1037 }
1038 }
1039 /* $attrs contains all values
1040 * we need, to save the entry lateron
1041 */
1042 $attrs= $attrs_used;
1044 /* Depending on the type (User/Admin)
1045 * switch these attributes, that makes it easier
1046 */
1047 if($printer['mode'] == "user"){
1048 $attribute = "goto".$s_suffix."Printer";
1049 $attribute2 = "goto".$s_suffix."AdminPrinter";
1050 }else{
1051 $attribute = "goto".$s_suffix."AdminPrinter";
1052 $attribute2 = "goto".$s_suffix."Printer";
1053 }
1055 /* If this user is already assigned to $attribute2
1056 * delete user from $attribute2, to be albe to attach him to $attribute
1057 * A user can't be admin and normal user for one printer
1058 */
1059 if(!isset($printer[$attribute2])){
1060 $printer[$attribute2]=array();
1061 }else{
1062 if(in_array($this->uid,$printer[$attribute2])){
1063 $tmp = array_flip($printer[$attribute2]);
1064 unset($tmp[$this->uid]);
1065 $attrs[$attribute2]=array_flip($tmp);
1066 }
1067 /* If Last entry removed, clear attribute*/
1068 if(empty($attrs[$attribute2])){
1069 $attrs[$attribute2]=array();
1070 }
1071 }
1073 /* Attach user to the $attribute, if he is'nt already attached
1074 */
1075 if(!isset($attrs[$attribute])){
1076 $attrs[$attribute]=array($this->uid);
1077 }else{
1078 unset($attrs[$attribute]['count']);
1079 if(!in_array($this->uid,$attrs[$attribute])){
1080 $attrs[$attribute][]=$this->uid;
1081 }
1082 }
1084 $ldap->cd($attrs['dn']);
1085 unset($attrs['dn']);
1086 $ldap->modify ($attrs);
1088 if($ldap->get_error()!="Success"){
1089 print_red(_("Error while writing printer settings")." : ".$ldap->get_error());
1090 }
1091 }
1093 /* Prepare HotPlug devices */
1094 $this->attrs['gotoHotplugDevice'] = array();
1095 foreach($this->gotoHotplugDevices as $name => $device){
1096 $this->attrs['gotoHotplugDevice'][] = $device['name']."|".$device['description']."|".$device['id'];
1097 }
1099 /* Prepare LogonScripts */
1100 $this->attrs['gotoLogonScript'] = array();
1101 foreach($this->gotoLogonScripts as $name => $script){
1102 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1103 $script['LogonOverload'].$script['LogonLast']."|".
1104 $script['LogonPriority']."|".
1105 base64_encode($script['LogonData'])."|".
1106 $script['LogonDescription'];
1107 }
1109 /* Prepare Shares */
1110 $this->attrs['gotoShare']=array();
1111 foreach($this->gotoShares as $name => $share){
1112 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$share['mountPoint']."|".$share['PwdHash']."|".$share['Username'];
1113 }
1116 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1117 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1119 foreach($saveThis as $tosave){
1120 if(!empty($this->$tosave)){
1121 $this->attrs[$tosave]=$this->$tosave;
1122 }else{
1123 $this->attrs[$tosave]=array();
1124 }
1125 }
1127 /* Prepare Flags */
1128 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlag_C.$this->gotoProfileFlag_L);
1129 if(empty($this->attrs['gotoProfileFlags'][0])){
1130 $this->attrs['gotoProfileFlags']=array();
1131 }
1133 if($this->useProfile == false){
1134 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1135 $this->attrs['gotoProfileServer']= array();
1136 }
1138 foreach($this->attributes as $s_attr){
1139 if(chkacl($this->acl,$s_attr)!="") {
1140 if(isset($this->attrs[$s_attr])){
1141 unset($this->attrs[$s_attr]);
1142 }
1143 }
1144 }
1146 $ldap->cat ($this->dn, array('dn'));
1147 if ($ldap->fetch()){
1148 $mode= "modify";
1149 } else {
1150 $mode= "add";
1151 $ldap->cd($this->config->current['BASE']);
1152 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1153 }
1155 $ldap->cd($this->dn);
1156 $this->cleanup();
1157 $ldap->$mode($this->attrs);
1158 show_ldap_error($ldap->get_error(), _("Adding environment information failed"));
1159 $this->handle_post_events($mode);
1160 }
1162 /* Generate ListBox frindly output for the defined shares
1163 * Possibly Add or remove an attribute here,
1164 */
1165 function printOutAssignedShares()
1166 {
1167 $a_return = array();
1168 if(is_array($this->gotoShares)){
1169 foreach($this->gotoShares as $share){
1170 if(preg_match("/^!/",$share['server'])){
1171 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1172 }else{
1173 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1174 }
1175 }
1176 }
1177 return($a_return);
1178 }
1180 /* Generate ListBox frindly output for the definedhotplugs
1181 * Possibly Add or remove an attribute here,
1182 */
1183 function printOutHotPlugDevices()
1184 {
1185 $a_return= array();
1186 if(is_array($this->gotoHotplugDevices)){
1187 foreach($this->gotoHotplugDevices as $key=>$device){
1188 $a_return[$key] = $device['name']." - ".$device['id'];
1189 }
1190 }
1191 return($a_return);
1192 }
1194 /* Generates ListBox frienly output of used printer devices
1195 * Append ' - admin' if printer is used in admin mode
1196 */
1197 function printOutPrinterDevices()
1198 {
1199 $a_return = array();
1200 if(is_array($this->gotoPrinter)){
1201 foreach($this->gotoPrinter as $printer){
1202 if($printer['mode'] == "admin"){
1203 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1204 }else{
1205 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1206 }
1207 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1208 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1209 }
1210 }
1211 }
1212 return($a_return);
1213 }
1215 /* Generates ListBox frienly output of used logonscripts
1216 */
1217 function printOutLogonScripts()
1218 {
1219 $a_return = array();
1220 if(is_array($this->gotoLogonScripts)){
1221 foreach($this->gotoLogonScripts as $script){
1222 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1223 }
1224 }
1225 return($a_return);
1226 }
1227 }
1232 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1233 ?>