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;
20 var $view_logged = FALSE;
22 /* Attribute definition
23 */
25 /* profile management */
26 var $useProfile = false; // Specifies if we want to use a Server
27 var $gotoProfileServer = ""; // Specifies the selected profile server
28 var $gotoProfileServers = array();// Specifies all available and selectable servers
29 var $gotoProfileFlags = ""; // Flags enabled ? only used to set ACL and save
30 var $gotoProfileFlagC = ""; // Flag is set to C if we have the profile caching fucntion enabled
32 var $gotoXResolution = "auto"; // The selected resolution eg: 1024x768
33 var $gotoXResolutions = array();// Contains all available resolutions for this account
34 var $gotoProfileFlagL = ""; // Flag is set to L to enable runtime resolution change
35 var $gotoProfileQuota = ""; // User Quota Settings
37 /* Logon script section*/
38 var $gotoLogonScripts = array();// Contains all available Logon Scripts
39 var $gotoLogonScript = ""; // The selected Logon Script
41 /* Printer */
42 var $gotoPrinter = array();// All available Printer, with their configurations
43 var $gotoPrinterSel = ""; // The selected Printer
44 var $gosaDefaultPrinter = ""; // Default printer
46 /* Share */
47 var $gotoShares = array();// Current Share Options
48 var $gotoShare = ""; // currently selected Share Option
49 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
50 var $gotoAvailableShares= array();// Available Shares for this account
52 /* Kiosk profile */
53 var $kiosk_enabled = FALSE;
54 var $gotoKioskProfile = ""; // The selected Kiosk Profile
55 var $gotoKioskProfile_Server = ""; // The selected Kiosk Profile
56 var $gotoKioskProfile_Profile = ""; // The selected Kiosk Profile
57 var $gotoKioskProfiles = array();// All available Kiosk profiles
59 /* Hotplug Devices */
60 var $gotoHotplugDevice = array(); // Selected hotplug
61 var $gotoHotplugDevices = array();// Already configured hotplug devices
62 var $gotoHotplugDeviceDN= array();
64 var $NewAddedPrinters = array();
65 var $NewDeletedPrinters = array();
67 /* general settings */
68 // Sets the attributes which will kept on page reload, which will be saved, ...
70 var $CopyPasteVars = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn","gotoKioskProfile_Server","gotoKioskProfile_Profile");
72 var $attributes = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
73 "gotoXResolution","gotoProfileQuota",
74 "gotoLogonScripts","gotoLogonScript",
75 "gotoPrinter", "gosaDefaultPrinter",
76 "gotoShares","gotoShare",
77 "gotoKioskProfile");
78 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
79 var $cn;
80 var $OrigCn;
81 var $add_del_printer_member_was_called = false;
83 var $multiple_support =TRUE;
85 var $use_gotoPrinter;
87 function environment (&$config, $dn= NULL)
88 {
89 plugin::plugin ($config, $dn);
91 /* Setting uid to default */
92 if(isset($this->attrs['uid'][0])){
93 $this->uid = $this->attrs['uid'][0];
94 }
96 /* Check : Are we currently editing a group or user dialog */
97 if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
98 $suffix="Group";
99 $this->uid = $this->attrs['cn'][0];
100 $this->attrs['uid'] = $this->attrs['cn'][0];
101 $this->OrigCn = $this->attrs['cn'][0];
102 }else{
103 $suffix="User";
104 }
106 /* Get all Printer assignments */
107 $ldap = $this->config->get_ldap_link();
108 $ldap->cd($this->config->current['BASE']);
109 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
110 while($printer = $ldap->fetch()){
111 $this->gotoPrinter[$printer['cn'][0]]=$printer;
112 $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
113 }
114 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
115 while($printer = $ldap->fetch()){
116 $this->gotoPrinter[$printer['cn'][0]]=$printer;
117 $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
118 }
121 /* Prepare hotplugs */
122 if(isset($this->attrs['gotoHotplugDeviceDN']) && is_array($this->attrs['gotoHotplugDeviceDN'])){
123 $ldap = $this->config->get_ldap_link();
124 $ldap->cd($this->config->current['BASE']);
125 for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
126 $ldap->cat($this->attrs['gotoHotplugDeviceDN'][$i]);
127 if($ldap->count()){
128 $attrs = $ldap->fetch();
130 if(isset($attrs['gotoHotplugDevice'][0])){
131 $tmp = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
132 $tmp2 = array();
133 $tmp2['name'] = $attrs['cn'][0];
134 $tmp2['description'] = $tmp[0];
135 $tmp2['id'] = $tmp[1];
136 $tmp2['produkt'] = $tmp[2];
137 $tmp2['vendor'] = $tmp[3];
138 $tmp2['dn'] = $attrs['dn'];
139 $this->gotoHotplugDevices[] = $tmp2;
140 }
141 }else{
142 print_red(sprintf(_("The selected hotplug device %s is no longer available, it will be removed when you save this account."),$this->attrs['gotoHotplugDeviceDN'][$i]));
143 }
144 }
145 }
148 /* prepare LogonScripts */
149 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
150 unset($this->attrs['gotoLogonScript']['count']);
151 foreach($this->attrs['gotoLogonScript'] as $device){
152 $tmp = $tmp2 = array();
153 $tmp = split("\|",$device);
154 $tmp2['LogonName'] = $tmp[0];
155 $tmp2['LogonPriority'] = $tmp[2];
156 if(preg_match("/O/i",$tmp[1])){
157 $tmp2['LogonOverload'] = "O";
158 }else{
159 $tmp2['LogonOverload'] = "";
160 }
161 if(preg_match("/L/i",$tmp[1])){
162 $tmp2['LogonLast'] = "L";
163 }else{
164 $tmp2['LogonLast'] = "";
165 }
166 $tmp2['LogonData'] = base64_decode($tmp[3]);
167 $tmp2['LogonDescription'] = $tmp[4];
168 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
169 }
170 }
172 /* Prepare Shares */
173 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
174 unset($this->attrs['gotoShare']['count']);
175 foreach($this->attrs['gotoShare'] as $share){
176 $tmp = $tmp2 = array();
177 $tmp = split("\|",$share);
178 $tmp2['server'] =$tmp[0];
179 $tmp2['name'] =$tmp[1];
181 /* Decode base64 if needed */
182 if (!preg_match('%/%', $tmp[2])){
183 $tmp2['mountPoint'] =base64_decode($tmp[2]);
184 } else {
185 $tmp2['mountPoint'] =$tmp[2];
186 }
188 if(isset($tmp[3])){
189 $tmp2['PwdHash'] =$tmp[3];
190 }else{
191 $tmp2['PwdHash'] ="";
192 }
193 if(isset($tmp[4])){
194 $tmp2['Username'] =$tmp[4];
195 }else{
196 $tmp2['Username'] ="";
197 }
198 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
199 }
200 }
202 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
203 $chr = $this->gotoProfileFlags[$i];
204 $name = "gotoProfileFlag".$chr;
205 $this->$name=$chr;
206 }
208 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
209 $this->useProfile = true;
210 }else{
211 $this->useProfile = false;
212 }
214 /* Set resolutions */
215 $this->gotoXResolutions = array("auto"=>_("auto"),
216 "640x480" => "640x480",
217 "800x600" => "800x600",
218 "1024x768" => "1024x768",
219 "1152x864" => "1152x864",
220 "1280x768" => "1280x768",
221 "1280x1024" => "1280x1024");
223 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
224 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
226 if(is_readable($file)){
227 $str = file_get_contents($file);
228 $lines = split("\n",$str);
229 foreach($lines as $line){
230 $line = trim($line);
231 if(!empty($line)){
232 $this->gotoXResolutions[$line]=$line;
233 }
234 }
235 //natcasesort($this->gotoXResolutions);
236 }else{
237 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
238 }
239 }
241 $this->gotoProfileServers= $config->getShareServerList() ;
242 $this->gotoShareSelections= $config->getShareList(true);
243 $this->gotoAvailableShares= $config->getShareList(false);
245 $this->update_kiosk_profiles();
247 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
248 }
251 function update_kiosk_profiles()
252 {
253 $tmp1 = array("none" => array(_("disabled")));
254 $tmp2 = array("none" => _("disabled"));
255 $ldap = $this->config->get_ldap_link();
256 $ldap->cd($this->config->current['BASE']);
257 $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
258 $cnt = 0;
259 while($attrs = $ldap->fetch()){
260 for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
261 $name = preg_replace("/^.*kiosk\//","",$attrs['gotoKioskProfile'][$i]);
262 $tmp1[$attrs['cn'][0]][] = $name;
263 }
264 $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
265 $cnt ++;
266 }
268 if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
269 $this->kiosk_enabled = TRUE;
270 }
272 $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
273 $this->gotoKioskProfiles['SERVERS'] = $tmp2;
275 $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
276 $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
278 $error = false;
279 if(!in_array($this->gotoKioskProfile_Server, $this->gotoKioskProfiles['SERVERS'])){
280 $this->gotoKioskProfile_Server = key($this->gotoKioskProfiles['SERVERS']);
281 $error = true;
282 }
283 if(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
284 $this->gotoKioskProfile_Profile = $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server][0];
285 $error = true;
286 }
287 if($error && !empty($this->gotoKioskProfile)){
288 print_red(sprintf(_("The selected kiosk profile wasn't available anymore. The current profile is now 'none'."),
289 $this->gotoKioskProfile_Server,$this->gotoKioskProfile_Profile));
290 }
291 }
294 /* Detect type of edited object (user|group)*/
295 function detect_grouptype()
296 {
297 if((!isset($this->parent))&&(!$this->is_account)){
298 $this->is_group = false;
299 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
300 $this->is_group = true;
301 }else{
302 $this->is_group = false;
303 }
304 }
307 function execute()
308 {
310 /* Call parent execute */
311 plugin::execute();
312 /* Log view */
313 if($this->is_account && !$this->view_logged){
314 $this->view_logged = TRUE;
315 if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
316 new log("view","users/".get_class($this),$this->dn);
317 }else{
318 new log("view","groups/".get_class($this),$this->dn);
319 }
320 }
322 /* Are we editing from MyAccount and not editing a user */
323 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
325 /* Check profile server */
326 if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
327 if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
328 if(count($this->gotoProfileServers)){
330 /* Get First Profile */
331 $new = key($this->gotoProfileServers);
333 /* Another profile server found */
334 print_red(sprintf(_("Your selected profile server '%s' is no longer available. Setting profile server to '%s'."),
335 $this->gotoProfileServer,$new));
336 }else{
338 /* No other profile servers found */
339 print_red(sprintf(_("Your selected profile server '%s' is no longer available. Profile server configuration is resetted."),
340 $this->gotoProfileServer));
341 $this->gotoProfileServer = "";
342 }
343 }
344 }
346 $this->detect_grouptype();
348 /* Fill templating stuff */
349 $smarty= get_smarty();
350 $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
351 $display= "";
353 $smarty->assign("is_group",$this->is_group);
355 /* Prepare all variables for smarty */
356 foreach($this->attributes as $s_attr){
357 /* Set value*/
358 $smarty->assign($s_attr,$this->$s_attr);
360 /* Set checkbox state*/
361 if(empty($this->$s_attr)){
362 $smarty->assign($s_attr."CHK","");
363 }else{
364 $smarty->assign($s_attr."CHK"," checked ");
365 }
367 /* Prepare ACL settings*/
368 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
369 }
371 /* Is accout enabled | are we editing from usermenu or admin menu
372 All these tab management is done here
373 */
376 /* Working from Usermenu an the Account is currently disbled
377 * this->parent : is only set if we are working in a list of tabs
378 * is_account : is only true if the needed objectClass is given
379 */
380 if((!isset($this->parent))&&(!$this->is_account)){
381 /* We are currently editing this tab from usermenu, but this account is not enabled */
382 $smarty->assign("is_account",$this->is_account);
383 /* Load template */
384 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
385 /* Avoid the "You are currently editing ...." message when you leave this tab */
386 $display .= back_to_main();
387 /* Display our message to the user */
388 return $display;
391 /* We are currently editing from group tabs, because
392 * $this->parent is set
393 * posixAccount is not set, so we are not in usertabs.
394 */
395 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
396 $smarty->assign("is_account","true");
397 $this->uid = $this->cn;
398 $this->attrs['uid'] = $this->cn;
400 /* Change state if needed */
401 if (isset($_POST['modify_state'])){
402 if(($this->acl_is_createable() && !$this->is_account) ||
403 ($this->acl_is_removeable() && $this->is_account)){
404 $this->is_account= !$this->is_account;
405 }
406 }
407 /* Group Dialog with enabled environment options */
408 if ($this->is_account){
409 $display= $this->show_enable_header(_("Remove environment extension"),
410 _("Environment extension enabled. You can disable it by clicking below."));
411 } else {
413 /* Environment is disabled
414 If theres is no posixAccount enabled, you won't be able to enable
415 environment extensions
416 */
417 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
418 // 4. There is a PosixAccount
419 $display= $this->show_enable_header(_("Add environment extension"),
420 _("Environment extension disabled. You can enable it by clicking below."));
421 return $display;
422 }else{
423 // 4. There is no PosixAccount
424 $display= $this->show_enable_header(_("Add environment extension"),
425 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
426 return $display;
427 }
428 }
429 }else{
430 /* Editing from Usermenu
431 * Tell smarty that this accoutn is enabled
432 */
433 $smarty->assign("is_account","true");
435 /* Change state if needed */
436 if (isset($_POST['modify_state'])){
437 if(($this->acl_is_createable() && !$this->is_account) ||
438 ($this->acl_is_removeable() && $this->is_account)){
439 $this->is_account= !$this->is_account;
440 }
441 }
443 if(isset($this->parent)){
445 // 3. Account enabled . Editing from adminmenu
446 if ($this->is_account){
447 $display= $this->show_disable_header(_("Remove environment extension"),
448 _("Environment extension enabled. You can disable it by clicking below."));
449 } else {
451 if($this->parent->by_object['posixAccount']->is_account==true){
452 // 4. There is a PosixAccount
453 $display= $this->show_disable_header(_("Add environment extension"),
454 _("Environment extension disabled. You can enable it by clicking below."));
455 return $display;
456 }else{
457 // 4. There is a PosixAccount
458 $display= $this->show_disable_header(_("Add environment extension"),
459 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
460 return $display;
461 }
462 }
463 }
464 }
466 /* Reset header toggle */
467 if($this->multiple_support_active){
468 $display = "";
469 }
471 /* Account is Account : is_accounbt=true.
472 * Else we won't reach this.
473 */
475 /* Prepare all variables for smarty */
476 foreach($this->attributes as $s_attr){
477 /* Set value*/
478 $smarty->assign($s_attr,$this->$s_attr);
480 /* Set checkbox state*/
481 if(empty($this->$s_attr)){
482 $smarty->assign($s_attr."CHK","");
483 }else{
484 $smarty->assign($s_attr."CHK"," checked ");
485 }
487 /* Prepare ACL settings*/
488 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
489 }
491 foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
492 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
493 }
495 if($WriteOnly) {
496 $smarty->assign("gotoPrinterACL","r");
497 }else{
498 $smarty->assign("gotoPrinterACL","rw");
499 }
502 $smarty->assign("useProfile",$this->useProfile);
503 if(empty($this->useProfile) && !$this->multiple_support_active){
504 $smarty->assign("useProfileCHK","");
505 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
506 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
507 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
508 }else{
509 $smarty->assign("useProfileCHK"," checked ");
510 }
512 $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
513 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
515 /* HANDLE Profile Settings here
516 * Assign available Quota and resolution settings
517 * Get all available profile server
518 * Get cache checkbox
519 * Assign this all to Smarty
520 */
522 if(empty($this->gotoProfileFlagL)){
523 $smarty->assign("gotoProfileFlagLCHK"," ");
524 }else{
525 $smarty->assign("gotoProfileFlagLCHK"," checked ");
526 }
528 if(empty($this->gotoProfileFlagC)){
529 $smarty->assign("gotoProfileFlagCCHK"," ");
530 }else{
531 $smarty->assign("gotoProfileFlagCCHK"," checked ");
532 }
535 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
536 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
538 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
539 if(!is_array($this->gotoProfileServers)){
540 $this->gotoProfileServers =array();
541 }
542 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
544 /* Handle kiosk profiles*/
545 $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
546 $smarty->assign("kiosk_server" , $this->gotoKioskProfile_Server);
547 $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
548 $smarty->assign("kiosk_profile" , $this->gotoKioskProfile_Profile);
551 /* Logonscript Management
552 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
553 * Perform add Delete edit Posts
554 */
556 /* Dialog Save */
557 if(isset($_POST['LogonSave'])){
559 if(!$this->acl_is_writeable("gotoLogonScript")){
560 print_red(_("You are not allowed to write Logon scripts."));
561 unset($this->dialog);
562 $this->dialog=FALSE;
563 $this->is_dialog=false;
564 }else{
565 $this->dialog->save_object();
566 if(count($this->dialog->check())!=0){
567 foreach($this->dialog->check() as $msg){
568 print_red($msg);
569 }
570 }else{
571 $tmp = $this->dialog->save();
572 unset($this->dialog);
573 $this->dialog=FALSE;
574 $this->is_dialog=false;
576 if($this->multiple_support_active){
577 $tmp['UsedByAllUsers'] = TRUE;
578 }
579 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
580 }
581 }
582 }
585 /* Dialog Quit without saving */
586 if(isset($_POST['LogonCancel'])){
587 $this->is_dialog= false;
588 unset($this->dialog);
589 $this->dialog= FALSE;
590 }
592 /* Check Edit Del New Posts for a selected LogonScript */
593 if($this->acl_is_writeable("gotoLogonScript") &&
594 (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
596 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
597 * In this case we create a new Logon Script.
598 */
599 if(isset($_POST['gotoLogonScriptNew'])){
600 $this->is_dialog = true;
601 $this->dialog = new logonManagementDialog($this->config,$this->dn);
602 }
604 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
605 * We only can delete if there is an entry selected.
606 */
607 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
608 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
609 }
611 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
612 * There must be an entry selected to perform edit request.
613 */
614 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
615 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
616 $this->is_dialog = true;
617 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
618 }
619 }
621 /* Append List to smarty*/
622 if($this->multiple_support_active){
623 $smarty->assign("gotoLogonScripts", $this->gotoLogonScripts);
624 $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
625 }else{
626 $ls = $this->printOutLogonScripts();
627 $smarty->assign("gotoLogonScripts", $ls);
628 $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
629 $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
630 }
632 /* In this section server shares will be defined
633 * A user can select one of the given shares and a mount point
634 * and attach this combination to his setup.
635 */
637 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
638 if(!is_array($this->gotoShareSelections)){
639 $this->gotoShareSelections = array();
640 }
641 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
643 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
644 * This entry will be, a combination of mountPoint and sharedefinitions
645 */
646 if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
648 /* We assign a share to this user, if we don't know where to mount the share */
649 if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
650 print_red(_("You must select a valid share."));
651 }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
652 print_red(_("You must specify a valid mount point."));
653 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
654 print_red(_("Spaces are not allowed in the mount path!"));
655 }elseif(!(
656 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
657 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
658 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
659 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
660 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
661 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
662 preg_match("/^%/",$_POST['gotoShareMountPoint'])
663 )
664 ){
665 print_red(_("You must specify a valid mount point."));
666 }else{
667 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
668 $s_mount = $_POST['gotoShareMountPoint'];
669 $s_user = $_POST['ShareUser'];
670 /* Preparing the new assignment */
671 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
672 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
673 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
674 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
676 if($this->multiple_support_active){
677 $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
678 }
679 }
680 }
682 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
683 * If there is no defined share selected, we will abort the deletion without any message
684 */
685 $once = true;
686 if($this->acl_is_writeable("gotoShare")){
687 foreach($_POST as $name => $value){
688 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
689 $once = false;
690 $key = preg_replace("/^gotoShareDel_/","",$name);
691 $key = preg_replace("/_+[xy]$/","",$key);
692 $key = base64_decode($key);
693 if(isset($this->gotoShares[$key])) {
694 unset($this->gotoShares[$key]);
695 }
697 /* Remove corresponding password entry, too. This is a workaround
698 to get rid of old-style entries. */
699 $key= preg_replace("/\|/", "|!", $key);
700 if(isset($this->gotoShares[$key])) {
701 unset($this->gotoShares[$key]);
702 }
703 }
704 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
705 $once = false;
706 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
707 $key = preg_replace("/_+[xy]$/","",$key);
708 $key = base64_decode($key);
709 $this->gotoShares[$key]['PwdHash'] = "";
710 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
711 unset($this->gotoShares[$key]);
712 }
713 }
714 }
715 }
716 $divlistShares = new divSelectBox("gotoShares");
717 $divlistShares->SetHeight(100);
720 $tmp = array();
721 if($this->acl_is_readable("gotoShares")){
722 $tmp = $this->printOutAssignedShares();
723 }
726 foreach($tmp as $key => $value){
727 $img = "";
729 /* Skip apssword only entries */
730 if( empty($this->gotoShares[$key]['server']) &&
731 empty($this->gotoShares[$key]['name']) &&
732 empty($this->gotoShares[$key]['mountPoint']) &&
733 empty($this->gotoShares[$key]['Username'])){
734 continue;
735 }
737 $color = "";
738 if($this->multiple_support_active){
739 if($this->gotoShares[$key]['UsedByAllUsers']){
740 $value .= " (<b>"._("Used by all users")."</b>)";
741 }else{
742 $color = "color: #999999;";
743 $value .= " (<b>"._("Used by some users")."</b>)";
744 }
745 }
747 /* Check if entry starts with an ! */
748 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
750 /* If we are currently editing groups environment, skip those ! entries */
751 if($this->is_group) continue;
753 /* Create pwd reset images */
754 if($this->gotoShares[$key]['PwdHash'] != ""){
755 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
756 title='"._("Reset password hash")."'>";
757 }
758 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
759 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
760 }else{
762 /* Create pwd reset img && delete image */
763 if($this->gotoShares[$key]['PwdHash'] != ""){
764 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
765 title='"._("Reset password hash")."'>";
766 $img.= " ";
767 }
768 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."'
769 title='"._("Delete share entry")."'>";
770 $field1 = array("string" => $value , "attach" => "style='".$color."'");
771 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
772 }
773 $divlistShares->AddEntry(array($field1,$field2));
774 }
775 $smarty->assign("divlistShares",$divlistShares->DrawList());
777 /* Hotplug devices will be handled here
778 * There are 3 possible methods for this feature
779 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
780 * Delete will erase an entry, the entry must be selcted in the ListBox first
781 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
782 */
784 /* We have to delete the selected hotplug from the list*/
785 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
786 if($this->acl_is_writeable("gotoHotplugDevice")){
787 foreach($_POST['gotoHotplugDevice_post'] as $name){
788 unset($this->gotoHotplugDevices[$name]);
789 }
790 }
791 }
793 /* There are already defined hotplugs from other users we could use */
794 if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
795 $tmp =array();
796 foreach($this->gotoHotplugDevices as $plugs){
797 $tmp[] = $plugs['name'];
798 }
799 $this->dialog = new hotplugDialog($this->config,$tmp);
800 $this->is_dialog = true;
801 }
803 /* Dialog Aborted */
804 if(isset($_POST['HotPlugCancel'])){
805 unset($this->dialog);
806 $this->dialog= FALSE;
807 $this->is_dialog = false;
808 }
810 /* Dialod saved */
811 if(isset($_POST['HotPlugSave'])){
813 $this->dialog->save_object();
814 if(count($this->dialog->check())!=0){
815 foreach($this->dialog->check() as $msg){
816 print_red($msg);
817 }
818 }else{
819 $this->dialog->save_object();
820 $a_tmp = $this->dialog->save();
822 if(is_array($a_tmp)){
823 foreach($a_tmp as $name => $hotplug){
824 if($this->multiple_support_active){
825 $hotplug['UsedByAllUsers'] = TRUE;
826 }
827 $this->gotoHotplugDevices[$name]= $hotplug;
828 }
829 }
830 unset($this->dialog);
831 $this->dialog= FALSE;
832 $this->is_dialog = false;
833 }
834 }
836 if($this->multiple_support_active){
837 $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
838 }else{
839 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
840 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
841 }
843 /* Printer Assignment will managed below
844 * A printer can be assigned in two different ways and two different types
845 * There are 2 types of users assigned to a printer : user and admin
846 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
847 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
848 */
850 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
851 if(isset($_POST['gotoPrinterAdd'])){
853 $this->is_dialog=true;
854 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
855 }
857 if(isset($_POST['PrinterCancel'])){
858 $this->is_dialog=false;
859 unset($this->dialog);
860 $this->dialog=FALSE;
861 }
863 if(isset($_POST['PrinterSave'])){
864 if(count($this->dialog->check())!=0){
865 $tmp = $this->dialog->check();
866 foreach($tmp as $msg){
867 print_red($msg);
868 }
869 }else{
870 $this->dialog->save_object();
871 $tmp = $this->dialog->save();
872 $tmp2= $this->dialog->getPrinter(true);
874 foreach($tmp as $pname){
875 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
876 $printerObj->set_acl_base($tmp2[$pname]['dn']);
878 $type = false;
880 if($this->is_group){
881 if($this->dn == "new"){
882 $type = "AddGroup";
883 }elseif(isset($this->NewDeletedPrinters[$pname])){
884 $type = "AddGroup";
885 }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
886 $type = "AddGroup";
887 }
888 }else{
889 if($this->multiple_support_active){
890 $type = "AddUser";
891 }elseif(isset($this->NewDeletedPrinters[$pname])){
892 $type = "AddUser";
893 }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
894 $type = "AddUser";
895 }
896 }
898 if($type){
899 $this->gotoPrinter[$pname]=$tmp2[$pname];
900 $this->gotoPrinter[$pname]['mode']="user";
901 $this->add_del_printer_member_was_called = true;
903 $this->NewAddedPrinters[$pname] = $pname;
904 if(isset($this->NewDeletedPrinters[$pname])){
905 unset($this->NewDeletedPrinters[$pname]);
906 }
907 }
908 }
910 $this->is_dialog=false;
911 unset($this->dialog);
912 $this->dialog =FALSE;
913 }
914 }
916 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
917 $printer = $_POST['gotoPrinterSel'];
918 foreach($printer as $pname){
920 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
921 $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
923 $type = false;
924 if($this->is_group){
925 if(isset($this->NewAddedPrinters[$pname])){
926 $type = "Group";
927 }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
928 $type = "Group";
929 }
930 }else{
931 if(isset($this->NewAddedPrinters[$pname])){
932 $type = "User";
933 }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
934 $type = "User";
935 }
936 }
937 if($type){
938 $this->add_del_printer_member_was_called = true;
939 unset($this->gotoPrinter[$pname]);
941 $this->NewDeletedPrinters[$pname] = $pname;
942 if(isset($this->NewAddedPrinters[$pname])){
943 UNSET($this->NewAddedPrinters[$pname]);
944 }
945 }
946 }
947 }
949 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
950 $printers = $_POST['gotoPrinterSel'];
951 $this->add_del_printer_member_was_called = true;
952 foreach($printers as $printer){
953 if($this->gotoPrinter[$printer]['mode']=="user"){
954 $this->gotoPrinter[$printer]['mode']="admin";
955 }else{
956 $this->gotoPrinter[$printer]['mode']="user";
957 }
958 }
959 }
961 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
962 if($this->is_group){
963 print_red(_("GOsa default printer flag is not allowed within groups."));
964 }else{
965 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
966 $this->gosaDefaultPrinter= "";
967 } else {
968 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
969 }
970 }
971 }
973 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
974 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
976 /* General behavior */
977 if(is_object($this->dialog)){
978 $this->dialog->save_object();
979 $disp =$this->dialog->execute();
980 return($disp);
981 }
983 /* Assign used attributes for multiple edit */
984 foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
985 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
986 $ubox ="use_".$box;
987 if(in_array($box,$this->multi_boxes)){
988 $smarty->assign($ubox,TRUE);
989 }else{
990 $smarty->assign($ubox,FALSE);
991 }
992 }
994 /* Als smarty vars are set. Get smarty template and generate output */
995 $smarty->assign("multiple_support",$this->multiple_support_active);
996 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
997 return($display);
998 }
1000 function remove_from_parent()
1001 {
1002 /* only if it was an account*/
1003 if (!$this->initially_was_account){
1004 return;
1005 }
1007 /* include global link_info */
1008 $ldap= $this->config->get_ldap_link();
1010 /* Remove and write to LDAP */
1011 plugin::remove_from_parent();
1013 /* Don't save our template variables */
1014 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1016 /* Skip all these attributes */
1017 foreach($skip as $del){
1018 unset($this->attrs[$del]);
1019 }
1021 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1023 $ldap->cd($this->dn);
1024 $this->cleanup();
1025 $ldap->modify ($this->attrs);
1027 if($this->is_group){
1028 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1029 }else{
1030 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1031 }
1033 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
1035 /* Optionally execute a command after we're done */
1036 $this->handle_post_events("remove",array("uid" => $this->uid));
1037 }
1040 /* Save data to object */
1041 function save_object()
1042 {
1043 /* Get all Posted vars
1044 * Setup checkboxes
1045 */
1046 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !isset($_SESSION['edit']);
1047 if(isset($_POST['iamposted'])){
1049 $PACL = $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1051 if(isset($_POST['kiosk_server'])){
1052 $tmp = $_POST['kiosk_server'];
1053 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1054 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1055 }
1056 }
1057 if(isset($_POST['kiosk_profile'])){
1058 $tmp = $_POST['kiosk_profile'];
1059 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1060 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1061 }
1062 }
1064 if(preg_match("/w/",$PACL)){
1065 if(isset($_POST['useProfile'])){
1066 $this->useProfile = true;
1067 }else{
1068 $this->useProfile = false;
1069 }
1070 }
1072 if($this->acl_is_writeable("gotoProfileFlagC")){
1073 if(isset($_POST['gotoProfileFlagC'])){
1074 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1075 }else{
1076 $this->gotoProfileFlagC = false;
1077 }
1078 }
1080 if($this->acl_is_writeable("gotoProfileFlagL")){
1081 if(isset($_POST['gotoProfileFlagL'])){
1082 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1083 }else{
1084 $this->gotoProfileFlagL = false;
1085 }
1086 }
1088 plugin::save_object();
1089 foreach($this->attributes as $s_attr){
1090 if((!isset($_POST[$s_attr])) ||
1091 in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1092 if(!$this->acl_is_writeable($s_attr)){
1093 continue;
1094 }else{
1095 if(isset($_POST[$s_attr])){
1096 $this->$s_attr = $_POST[$s_attr];
1097 }else{
1098 $this->$s_attr = false;
1099 }
1100 }
1101 }
1102 }
1103 }
1106 /* Check supplied data */
1107 function check()
1108 {
1109 /* Call common method to give check the hook */
1110 $message= plugin::check();
1112 $this->detect_grouptype();
1114 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1115 $message[]=_("Please set a valid profile quota size.");
1116 }
1117 if(!isset($this->attrs['objectClass'])){
1118 $this->attrs['objectClass']=array();
1119 }
1120 if(!$this->is_group){
1121 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1122 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
1123 }
1124 }
1125 return ($message);
1126 }
1129 /* Save to LDAP */
1130 function save()
1131 {
1132 /* If group was renamed, all printer settings get lost
1133 */
1134 /* only save changed variables ....*/
1135 if ($this->gotoKioskProfile_Server != "none"){
1136 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
1137 $method="https://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1138 }else{
1139 $method="http://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1140 }
1141 $this->gotoKioskProfile= $method;
1142 }else{
1143 $this->gotoKioskProfile= array();
1144 }
1146 plugin::save();
1147 $ldap= $this->config->get_ldap_link();
1149 $realyUsedAttrs= array();
1151 /* Save already used objectClasses */
1152 $ocs = $this->attrs['objectClass'];
1153 unset($ocs['count']);
1154 $this->attrs = array();
1155 $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1157 /* 1. Search all printers that have our uid/cn as member
1158 * 2. Delete this uid/cn from every single entry and save it again.
1159 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1160 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
1161 */
1163 $this->detect_grouptype();
1165 if($this->add_del_printer_member_was_called){
1167 $types = array( "gotoUserPrinter" => "AddUser",
1168 "gotoGroupPrinter" => "AddGroup",
1169 "gotoUserAdminPrinter" => "AddAdminUser",
1170 "gotoGroupAdminPrinter" => "AddAdminGroup");
1172 if($this->is_group){
1173 $s_suffix = "Group";
1174 $useVar = "cn";
1175 }else{
1176 $useVar = "uid";
1177 $s_suffix = "User";
1178 }
1180 /* Remove old entries */
1181 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1182 while($attr = $ldap->fetch()){
1183 $printerObj = NULL;
1184 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1185 $printerObj->set_acl_base($attr['dn']);
1186 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1187 $printerObj->by_object['printgeneric']->save();
1188 }
1190 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1191 while($attr = $ldap->fetch()){
1192 $printerObj = NULL;
1193 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1194 $printerObj->set_acl_base($attr['dn']);
1195 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1196 $printerObj->by_object['printgeneric']->save();
1197 }
1199 foreach($this->gotoPrinter as $printer){
1200 $printerObj = NULL;
1201 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1202 $printerObj->set_acl_base($printer['dn']);
1205 if($printer['mode'] == "admin") {
1206 $attribute = "goto".$s_suffix."AdminPrinter";
1207 }else{
1208 $attribute = "goto".$s_suffix."Printer";
1209 }
1211 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1212 $printerObj->by_object['printgeneric']->save();
1213 }
1214 }
1216 /* Prepare HotPlug devices */
1217 $this->attrs['gotoHotplugDeviceDN'] = array();
1218 foreach($this->gotoHotplugDevices as $name => $device){
1219 $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1220 }
1222 /* Prepare LogonScripts */
1223 $this->attrs['gotoLogonScript'] = array();
1224 foreach($this->gotoLogonScripts as $name => $script){
1225 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1226 $script['LogonOverload'].$script['LogonLast']."|".
1227 $script['LogonPriority']."|".
1228 base64_encode($script['LogonData'])."|".
1229 $script['LogonDescription'];
1230 }
1232 /* Prepare Shares */
1233 $this->attrs['gotoShare']=array();
1234 foreach($this->gotoShares as $name => $share){
1235 $mntp= $share['mountPoint'];
1236 if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1237 $mntp= base64_encode($mntp);
1238 }
1239 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1240 }
1243 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1244 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1246 foreach($saveThis as $tosave){
1247 if(!empty($this->$tosave)){
1248 $this->attrs[$tosave]=$this->$tosave;
1249 }else{
1250 $this->attrs[$tosave]=array();
1251 }
1252 }
1254 /* Prepare Flags */
1255 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1256 if(empty($this->attrs['gotoProfileFlags'][0])){
1257 $this->attrs['gotoProfileFlags']=array();
1258 }
1260 if($this->useProfile == false){
1261 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1262 $this->attrs['gotoProfileServer']= array();
1263 }
1265 $ldap->cat ($this->dn, array('dn'));
1266 if ($ldap->fetch()){
1267 $mode= "modify";
1268 } else {
1269 $mode= "add";
1270 $ldap->cd($this->config->current['BASE']);
1271 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1272 }
1274 $ldap->cd($this->dn);
1275 $this->cleanup();
1276 $ldap->$mode($this->attrs);
1278 $cat = "users";
1279 if($this->is_group){
1280 $cat = "groups";
1281 }
1283 /* Log last action */
1284 if($this->initially_was_account){
1285 new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1286 }else{
1287 new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1288 }
1290 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1291 $this->handle_post_events($mode,array("uid"=>$this->uid));
1292 }
1294 /* Generate ListBox frindly output for the defined shares
1295 * Possibly Add or remove an attribute here,
1296 */
1297 function printOutAssignedShares()
1298 {
1299 $a_return = array();
1300 if(is_array($this->gotoShares)){
1301 foreach($this->gotoShares as $share){
1302 if(preg_match("/^!/",$share['server'])){
1303 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1304 }else{
1305 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1306 }
1307 }
1308 natcasesort($a_return);
1309 }
1310 return($a_return);
1311 }
1313 /* Generate ListBox frindly output for the definedhotplugs
1314 * Possibly Add or remove an attribute here,
1315 */
1316 function printOutHotPlugDevices()
1317 {
1318 $a_return= array();
1319 if(is_array($this->gotoHotplugDevices)){
1320 foreach($this->gotoHotplugDevices as $key=>$device){
1321 $a_return[$key] = $device['name']." - ".$device['id'];
1322 }
1323 }
1324 return($a_return);
1325 }
1327 /* Generates ListBox frienly output of used printer devices
1328 * Append ' - admin' if printer is used in admin mode
1329 */
1330 function printOutPrinterDevices()
1331 {
1332 $a_return = array();
1334 if($this->acl_is_readable("gotoPrinter")){
1336 if(is_array($this->gotoPrinter)){
1337 foreach($this->gotoPrinter as $printer){
1338 if($printer['mode'] == "admin"){
1339 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1340 }else{
1341 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1342 }
1343 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1344 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1345 }
1346 }
1347 }
1348 }
1349 return($a_return);
1350 }
1353 function PrepareForCopyPaste($source)
1354 {
1355 plugin::PrepareForCopyPaste($source);
1357 $class= get_class($this);
1358 $o_source = new $class($this->config,$source['dn']);
1359 foreach($this->CopyPasteVars as $attr){
1360 $this->$attr = $o_source->$attr;
1361 }
1362 }
1365 function saveCopyDialog()
1366 {
1367 if(isset($_POST['cn'])){
1368 $this->cn = $_POST['cn'];
1369 $this->uid = $_POST['cn'];
1370 }
1371 }
1374 /* Generates ListBox frienly output of used logonscripts
1375 */
1376 function printOutLogonScripts()
1377 {
1378 $a_return = array();
1379 if(is_array($this->gotoLogonScripts)){
1380 foreach($this->gotoLogonScripts as $script){
1381 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1382 }
1383 }
1384 return($a_return);
1385 }
1388 function multiple_execute()
1389 {
1390 /* Reset header toggle */
1391 $this->is_account = TRUE;
1392 return($this->execute());
1393 }
1396 /* Initialize plugin with given atribute arrays
1397 */
1398 function init_multiple_support($attrs,$all)
1399 {
1400 plugin::init_multiple_support($attrs,$all);
1402 /* Prepare Shares */
1403 if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1404 unset($this->multi_attrs_all['gotoShare']['count']);
1405 foreach($this->multi_attrs_all['gotoShare'] as $share){
1406 $tmp = $tmp2 = array();
1407 $tmp = split("\|",$share);
1408 $tmp2['server'] =$tmp[0];
1409 $tmp2['name'] =$tmp[1];
1411 /* Decode base64 if needed */
1412 if (!preg_match('%/%', $tmp[2])){
1413 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1414 } else {
1415 $tmp2['mountPoint'] =$tmp[2];
1416 }
1418 if(isset($tmp[3])){
1419 $tmp2['PwdHash'] =$tmp[3];
1420 }else{
1421 $tmp2['PwdHash'] ="";
1422 }
1423 if(isset($tmp[4])){
1424 $tmp2['Username'] =$tmp[4];
1425 }else{
1426 $tmp2['Username'] ="";
1427 }
1428 $tmp2['UsedByAllUsers'] = FALSE;
1429 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1430 }
1431 }
1433 /* Prepare Shares */
1434 if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1435 unset($this->multi_attrs['gotoShare']['count']);
1436 foreach($this->multi_attrs['gotoShare'] as $share){
1437 $tmp = $tmp2 = array();
1438 $tmp = split("\|",$share);
1439 $tmp2['server'] =$tmp[0];
1440 $tmp2['name'] =$tmp[1];
1442 /* Decode base64 if needed */
1443 if (!preg_match('%/%', $tmp[2])){
1444 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1445 } else {
1446 $tmp2['mountPoint'] =$tmp[2];
1447 }
1449 if(isset($tmp[3])){
1450 $tmp2['PwdHash'] =$tmp[3];
1451 }else{
1452 $tmp2['PwdHash'] ="";
1453 }
1454 if(isset($tmp[4])){
1455 $tmp2['Username'] =$tmp[4];
1456 }else{
1457 $tmp2['Username'] ="";
1458 }
1459 $tmp2['UsedByAllUsers'] = TRUE;
1460 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1461 }
1462 }
1465 /* prepare LogonScripts */
1466 if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1467 unset($this->multi_attrs_all['gotoLogonScript']['count']);
1468 foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1469 $tmp = $tmp2 = array();
1470 $tmp = split("\|",$device);
1471 $tmp2['LogonName'] = $tmp[0];
1472 $tmp2['LogonPriority'] = $tmp[2];
1473 if(preg_match("/O/i",$tmp[1])){
1474 $tmp2['LogonOverload'] = "O";
1475 }else{
1476 $tmp2['LogonOverload'] = "";
1477 }
1478 if(preg_match("/L/i",$tmp[1])){
1479 $tmp2['LogonLast'] = "L";
1480 }else{
1481 $tmp2['LogonLast'] = "";
1482 }
1483 $tmp2['LogonData'] = base64_decode($tmp[3]);
1484 $tmp2['LogonDescription'] = $tmp[4];
1485 $tmp2['UsedByAllUsers'] = FALSE;
1486 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1487 }
1488 }
1490 /* prepare LogonScripts */
1491 if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1492 unset($this->multi_attrs['gotoLogonScript']['count']);
1493 foreach($this->multi_attrs['gotoLogonScript'] as $device){
1494 $tmp = $tmp2 = array();
1495 $tmp = split("\|",$device);
1496 $tmp2['LogonName'] = $tmp[0];
1497 $tmp2['LogonPriority'] = $tmp[2];
1498 if(preg_match("/O/i",$tmp[1])){
1499 $tmp2['LogonOverload'] = "O";
1500 }else{
1501 $tmp2['LogonOverload'] = "";
1502 }
1503 if(preg_match("/L/i",$tmp[1])){
1504 $tmp2['LogonLast'] = "L";
1505 }else{
1506 $tmp2['LogonLast'] = "";
1507 }
1508 $tmp2['LogonData'] = base64_decode($tmp[3]);
1509 $tmp2['LogonDescription'] = $tmp[4];
1510 $tmp2['UsedByAllUsers'] = TRUE;
1511 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1512 }
1513 }
1515 /* Prepare hotplugs */
1516 if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1517 $ldap = $this->config->get_ldap_link();
1518 $ldap->cd($this->config->current['BASE']);
1519 for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1520 $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1521 if($ldap->count()){
1522 $multi_attrs_all = $ldap->fetch();
1524 if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1525 $tmp = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1526 $tmp2 = array();
1527 $tmp2['name'] = $multi_attrs_all['cn'][0];
1528 $tmp2['description'] = $tmp[0];
1529 $tmp2['id'] = $tmp[1];
1530 $tmp2['produkt'] = $tmp[2];
1531 $tmp2['vendor'] = $tmp[3];
1532 $tmp2['dn'] = $multi_attrs_all['dn'];
1533 $tmp2['UsedByAllUsers'] = FALSE;
1534 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1535 }
1536 }
1537 }
1538 }
1540 /* Prepare hotplugs */
1541 if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1542 $ldap = $this->config->get_ldap_link();
1543 $ldap->cd($this->config->current['BASE']);
1544 for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1545 $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1546 if($ldap->count()){
1547 $multi_attrs = $ldap->fetch();
1549 if(isset($multi_attrs['gotoHotplugDevice'][0])){
1550 $tmp = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1551 $tmp2 = array();
1552 $tmp2['name'] = $multi_attrs['cn'][0];
1553 $tmp2['description'] = $tmp[0];
1554 $tmp2['id'] = $tmp[1];
1555 $tmp2['produkt'] = $tmp[2];
1556 $tmp2['vendor'] = $tmp[3];
1557 $tmp2['dn'] = $multi_attrs['dn'];
1558 $tmp2['UsedByAllUsers'] = TRUE;
1559 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1560 }
1561 }
1562 }
1563 }
1564 $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1565 $this->gotoHotplugDevices = array_values($tmp);
1566 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1567 $chr = $this->gotoProfileFlags[$i];
1568 $name = "gotoProfileFlag".$chr;
1569 $this->$name=$chr;
1570 }
1571 $this->update_kiosk_profiles();
1572 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1574 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1575 $this->useProfile = true;
1576 }else{
1577 $this->useProfile = false;
1578 }
1580 }
1583 function set_multi_edit_values($attrs)
1584 {
1585 $shares = $this->gotoShares;
1586 $scripts= $this->gotoLogonScripts;
1587 $plugs= $this->gotoHotplugDevices;
1588 plugin::set_multi_edit_values($attrs);
1590 $this->gotoShares = $shares;
1591 $this->gotoLogonScripts = $scripts;
1592 $this->gotoHotplugDevices = $plugs;
1594 foreach($attrs['gotoShares'] as $name => $share){
1595 if($share['UsedByAllUsers'] == TRUE){
1596 $this->gotoShares[$name] = $share;
1597 }
1598 }
1599 foreach($this->gotoShares as $name => $share){
1600 if(!isset($attrs['gotoShares'][$name])){
1601 unset($this->gotoShares[$name]);
1602 }
1603 }
1604 foreach($attrs['gotoLogonScripts'] as $name => $script){
1605 if($script['UsedByAllUsers'] == TRUE){
1606 $this->gotoLogonScripts[$name] = $script;
1607 }
1608 }
1609 foreach($this->gotoLogonScripts as $name => $script){
1610 if(!isset($attrs['gotoLogonScripts'][$name])){
1611 unset($this->gotoLogonScripts[$name]);
1612 }
1613 }
1614 $tmp = array();
1615 foreach($this->gotoHotplugDevices as $entry){
1616 $tmp[$entry['dn']] = $entry;
1617 }
1619 foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1620 if($plug['UsedByAllUsers'] == TRUE){
1621 $tmp[$plug['dn']] = $plug;
1622 }
1623 }
1624 foreach($tmp as $name => $plug){
1625 $found = false;
1626 foreach($attrs['gotoHotplugDevices'] as $test){
1627 if($test['dn'] == $name){
1628 $found = true;
1629 }
1630 }
1631 if(!$found){
1632 unset($tmp[$name]);
1633 }
1634 }
1635 }
1638 /* Return selected values for multiple edit */
1639 function get_multi_edit_values()
1640 {
1641 $ret = plugin::get_multi_edit_values();
1642 $ret['gotoShares'] = $this->gotoShares;
1643 $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1644 $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1646 if(in_array("gotoPrinter",$this->multi_boxes)){
1647 $ret['gotoPrinter'] = $this->gotoPrinter;
1648 $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1649 $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1651 /* Force printer reset */
1652 $ret['add_del_printer_member_was_called'] = TRUE;
1653 }
1655 if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1656 $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1657 }
1659 if(in_array("useProfile",$this->multi_boxes)){
1660 $ret['useProfile']=$this->useProfile;
1661 if(in_array("gotoProfileServer",$this->multi_boxes)){
1662 $ret['gotoProfileServer']=$this->gotoProfileServer;
1663 }
1664 if(in_array("gotoProfileQuota",$this->multi_boxes)){
1665 $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1666 }
1667 if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1668 $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1669 }
1670 }
1671 if(in_array("gotoXResolution",$this->multi_boxes)){
1672 $ret['gotoXResolution'] = $this->gotoXResolution;
1673 }
1674 if(in_array("kiosk_server",$this->multi_boxes)){
1675 $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1676 $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1677 }
1678 return($ret);
1679 }
1682 function multiple_save_object()
1683 {
1684 if(isset($_POST['environment_multiple_posted'])){
1685 plugin::multiple_save_object();
1688 if(isset($_POST['useProfile'])){
1689 $this->useProfile = true;
1690 }else{
1691 $this->useProfile = false;
1692 }
1693 if(isset($_POST['gotoProfileFlagC'])){
1694 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1695 }else{
1696 $this->gotoProfileFlagC = false;
1697 }
1699 if(isset($_POST['gotoProfileFlagL'])){
1700 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1701 }else{
1702 $this->gotoProfileFlagL = false;
1703 }
1705 foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1706 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1707 $uattr = "use_".$attr;
1708 if(isset($_POST[$uattr])){
1709 $this->multi_boxes[] = $attr;
1710 }
1711 }
1712 if(isset($_POST['kiosk_server'])){
1713 $tmp = $_POST['kiosk_server'];
1714 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1715 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1716 }
1717 }
1718 if(isset($_POST['kiosk_profile'])){
1719 $tmp = $_POST['kiosk_profile'];
1720 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1721 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1722 }
1723 }
1725 }
1726 }
1728 /* Return plugin informations for acl handling
1729 #FIXME these ACLs should work for groups too */
1730 static function plInfo()
1731 {
1732 return (array("plShortName" => _("Environment"),
1733 "plDescription" => _("Environment settings"), // Description
1734 "plSelfModify" => TRUE,
1735 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1736 "plPriority" => 3, // Position in tabs
1737 "plSection" => array("personal" => _("My account")),
1738 "plCategory" => array("users",
1739 "groups"),
1740 "plOptions" => array("resolution_hook" => array("type" => "string",
1741 "description" => _("Command to extend the list of possible screen resolutions"))),
1743 "plProvidedAcls" => array(
1745 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1746 "gotoProfileFlagC" => _("Cache profile localy") ,
1748 "gotoProfileQuota" => _("Profile quota") ,
1749 "gotoProfileServer" => _("Profile server") ,
1751 "gotoXResolution" => _("Resolution") ,
1752 "gotoKioskProfile" => _("Kiosk profile") ,
1754 "gosaDefaultPrinter" => _("Default printer") ,
1755 "gotoLogonScript" => _("Logon script") ,
1756 "gotoHotplugDevice" => _("Hotplug devices"),
1757 "gotoShare" => _("Shares"))
1758 ));
1759 }
1760 }
1762 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1763 ?>