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 msg_dialog::display(_("Warning"), sprintf(_("Device '%s' is not available anymore. It will be removed!"), $this->attrs['gotoHotplugDeviceDN'][$i]), WARNING_DIALOG);
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 msg_dialog::display(_("Configuration error"), sprintf(_("Cannot open file '%s'!"), $file), WARNING_DIALOG);
238 }
239 }
241 $this->gotoProfileServers= $config->getShareServerList() ;
242 $this->gotoShareSelections= $config->getShareList(true);
243 $this->gotoAvailableShares= $config->getShareList(false);
245 $this->update_kiosk_profiles();
246 }
249 function update_kiosk_profiles()
250 {
251 $tmp1 = array("none" => array(_("disabled")));
252 $tmp2 = array("none" => _("disabled"));
253 $ldap = $this->config->get_ldap_link();
254 $ldap->cd($this->config->current['BASE']);
255 $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
256 $cnt = 0;
257 while($attrs = $ldap->fetch()){
258 for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
259 $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
260 $tmp1[$attrs['cn'][0]][] = $name;
261 }
262 $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
263 $cnt ++;
264 }
266 if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
267 $this->kiosk_enabled = TRUE;
268 }
270 $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
271 $this->gotoKioskProfiles['SERVERS'] = $tmp2;
273 $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
274 $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
276 $error = false;
277 if(!in_array($this->gotoKioskProfile_Server, $this->gotoKioskProfiles['SERVERS'])){
278 $this->gotoKioskProfile_Server = key($this->gotoKioskProfiles['SERVERS']);
279 $error = true;
280 }
282 if(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
283 $this->gotoKioskProfile_Profile = $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server][0];
284 $error = true;
285 }
286 if($error && !empty($this->gotoKioskProfile)){
287 $this->gotoKioskProfile_Server ="none";
288 $this->gotoKioskProfile_Profile="";
289 msg_dialog::display(_("Warning"), sprintf(_("Kiosk profile '%s' located on server '%s' is not available anymore. Kiosk profile will be disabled!"), $this->gotoKioskProfile_Profile, $this->gotoKioskProfile_Server), WARNING_DIALOG);
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) && !session::is_set('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 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
335 }else{
337 /* No other profile servers found */
338 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
339 $this->gotoProfileServer = "none";
340 }
341 }
342 }
344 $this->detect_grouptype();
346 /* Fill templating stuff */
347 $smarty= get_smarty();
348 $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
349 $display= "";
351 $smarty->assign("is_group",$this->is_group);
353 /* Prepare all variables for smarty */
354 foreach($this->attributes as $s_attr){
355 /* Set value*/
356 $smarty->assign($s_attr,$this->$s_attr);
358 /* Set checkbox state*/
359 if(empty($this->$s_attr)){
360 $smarty->assign($s_attr."CHK","");
361 }else{
362 $smarty->assign($s_attr."CHK"," checked ");
363 }
365 /* Prepare ACL settings*/
366 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
367 }
369 /* Is accout enabled | are we editing from usermenu or admin menu
370 All these tab management is done here
371 */
374 /* Working from Usermenu an the Account is currently disbled
375 * this->parent : is only set if we are working in a list of tabs
376 * is_account : is only true if the needed objectClass is given
377 */
378 if((!isset($this->parent))&&(!$this->is_account)){
379 /* We are currently editing this tab from usermenu, but this account is not enabled */
380 $smarty->assign("is_account",$this->is_account);
381 /* Load template */
382 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
383 /* Avoid the "You are currently editing ...." message when you leave this tab */
384 $display .= back_to_main();
385 /* Display our message to the user */
386 return $display;
389 /* We are currently editing from group tabs, because
390 * $this->parent is set
391 * posixAccount is not set, so we are not in usertabs.
392 */
393 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
394 $smarty->assign("is_account","true");
395 $this->uid = $this->cn;
396 $this->attrs['uid'] = $this->cn;
398 /* Change state if needed */
399 if (isset($_POST['modify_state'])){
400 if(($this->acl_is_createable() && !$this->is_account) ||
401 ($this->acl_is_removeable() && $this->is_account)){
402 $this->is_account= !$this->is_account;
403 }
404 }
405 /* Group Dialog with enabled environment options */
406 if ($this->is_account){
407 $display= $this->show_enable_header(_("Remove environment extension"),
408 _("Environment extension enabled. You can disable it by clicking below."));
409 } else {
411 /* Environment is disabled
412 If theres is no posixAccount enabled, you won't be able to enable
413 environment extensions
414 */
415 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
416 // 4. There is a PosixAccount
417 $display= $this->show_enable_header(_("Add environment extension"),
418 _("Environment extension disabled. You can enable it by clicking below."));
419 return $display;
420 }else{
421 // 4. There is no PosixAccount
422 $display= $this->show_enable_header(_("Add environment extension"),
423 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."));
424 return $display;
425 }
426 }
427 }else{
428 /* Editing from Usermenu
429 * Tell smarty that this accoutn is enabled
430 */
431 $smarty->assign("is_account","true");
433 /* Change state if needed */
434 if (isset($_POST['modify_state'])){
435 if(($this->acl_is_createable() && !$this->is_account) ||
436 ($this->acl_is_removeable() && $this->is_account)){
437 $this->is_account= !$this->is_account;
438 }
439 }
441 if(isset($this->parent)){
443 // 3. Account enabled . Editing from adminmenu
444 if ($this->is_account){
445 $display= $this->show_disable_header(_("Remove environment extension"),
446 _("Environment extension enabled. You can disable it by clicking below."));
447 } else {
449 if($this->parent->by_object['posixAccount']->is_account==true){
450 // 4. There is a PosixAccount
451 $display= $this->show_disable_header(_("Add environment extension"),
452 _("Environment extension disabled. You can enable it by clicking below."));
453 return $display;
454 }else{
455 // 4. There is a PosixAccount
456 $display= $this->show_disable_header(_("Add environment extension"),
457 _("Environment extension disabled. You have to setup a posix account before you can enable this feature."),TRUE,TRUE);
458 return $display;
459 }
460 }
461 }
462 }
464 /* Reset header toggle */
465 if($this->multiple_support_active){
466 $display = "";
467 }
469 /* Account is Account : is_accounbt=true.
470 * Else we won't reach this.
471 */
473 /* Prepare all variables for smarty */
474 foreach($this->attributes as $s_attr){
475 /* Set value*/
476 $smarty->assign($s_attr,$this->$s_attr);
478 /* Set checkbox state*/
479 if(empty($this->$s_attr)){
480 $smarty->assign($s_attr."CHK","");
481 }else{
482 $smarty->assign($s_attr."CHK"," checked ");
483 }
485 /* Prepare ACL settings*/
486 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
487 }
489 foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
490 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
491 }
493 if($WriteOnly) {
494 $smarty->assign("gotoPrinterACL","r");
495 }else{
496 $smarty->assign("gotoPrinterACL","rw");
497 }
500 $smarty->assign("useProfile",$this->useProfile);
501 if(empty($this->useProfile) && !$this->multiple_support_active){
502 $smarty->assign("useProfileCHK","");
503 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
504 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
505 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
506 }else{
507 $smarty->assign("useProfileCHK"," checked ");
508 }
510 $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
511 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
513 /* HANDLE Profile Settings here
514 * Assign available Quota and resolution settings
515 * Get all available profile server
516 * Get cache checkbox
517 * Assign this all to Smarty
518 */
520 if(empty($this->gotoProfileFlagL)){
521 $smarty->assign("gotoProfileFlagLCHK"," ");
522 }else{
523 $smarty->assign("gotoProfileFlagLCHK"," checked ");
524 }
526 if(empty($this->gotoProfileFlagC)){
527 $smarty->assign("gotoProfileFlagCCHK"," ");
528 }else{
529 $smarty->assign("gotoProfileFlagCCHK"," checked ");
530 }
533 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
534 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
536 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
537 if(!is_array($this->gotoProfileServers)){
538 $this->gotoProfileServers =array();
539 }
540 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
542 /* Handle kiosk profiles*/
543 $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
544 $smarty->assign("kiosk_server" , $this->gotoKioskProfile_Server);
545 $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
546 $smarty->assign("kiosk_profile" , $this->gotoKioskProfile_Profile);
549 /* Logonscript Management
550 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
551 * Perform add Delete edit Posts
552 */
554 /* Dialog Save */
555 if(isset($_POST['LogonSave'])){
557 if(!$this->acl_is_writeable("gotoLogonScript")){
558 msg_dialog::display(_("Permission error"), _("You have no permission to modify logon scripts!"), ERROR_DIALOG);
559 unset($this->dialog);
560 $this->dialog=FALSE;
561 $this->is_dialog=false;
562 }else{
563 $this->dialog->save_object();
564 if(count($this->dialog->check())!=0){
565 foreach($this->dialog->check() as $msg){
566 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
567 }
568 }else{
569 $tmp = $this->dialog->save();
570 unset($this->dialog);
571 $this->dialog=FALSE;
572 $this->is_dialog=false;
574 if($this->multiple_support_active){
575 $tmp['UsedByAllUsers'] = TRUE;
576 }
577 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
578 }
579 }
580 }
583 /* Dialog Quit without saving */
584 if(isset($_POST['LogonCancel'])){
585 $this->is_dialog= false;
586 unset($this->dialog);
587 $this->dialog= FALSE;
588 }
590 /* Check Edit Del New Posts for a selected LogonScript */
591 if($this->acl_is_writeable("gotoLogonScript") &&
592 (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
594 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
595 * In this case we create a new Logon Script.
596 */
597 if(isset($_POST['gotoLogonScriptNew'])){
598 $this->is_dialog = true;
599 $this->dialog = new logonManagementDialog($this->config,$this->dn);
600 }
602 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
603 * We only can delete if there is an entry selected.
604 */
605 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
606 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
607 }
609 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
610 * There must be an entry selected to perform edit request.
611 */
612 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
613 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
614 $this->is_dialog = true;
615 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
616 }
617 }
619 /* Append List to smarty*/
620 if($this->multiple_support_active){
621 $smarty->assign("gotoLogonScripts", $this->gotoLogonScripts);
622 $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
623 }else{
624 $ls = $this->printOutLogonScripts();
625 $smarty->assign("gotoLogonScripts", $ls);
626 $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
627 $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
628 }
630 /* In this section server shares will be defined
631 * A user can select one of the given shares and a mount point
632 * and attach this combination to his setup.
633 */
635 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
636 if(!is_array($this->gotoShareSelections)){
637 $this->gotoShareSelections = array();
638 }
639 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
641 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
642 * This entry will be, a combination of mountPoint and sharedefinitions
643 */
644 if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
646 /* We assign a share to this user, if we don't know where to mount the share */
647 if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
648 msg_dialog::display(_("Error"), _("Please select a valid share!"), ERROR_DIALOG);
649 }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
650 msg_dialog::display(_("Error"), _("Please specify a valid mount point!"), ERROR_DIALOG);
651 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
652 msg_dialog::display(_("Error"), _("You cannot use spaces in the mount path!"), ERROR_DIALOG);
653 }elseif(!(
654 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
655 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
656 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
657 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
658 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
659 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
660 preg_match("/^%/",$_POST['gotoShareMountPoint'])
661 )
662 ){
663 msg_dialog::display(_("Error"), _("Please specify a valid mount point!"), ERROR_DIALOG);
664 }else{
665 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
666 $s_mount = $_POST['gotoShareMountPoint'];
667 $s_user = $_POST['ShareUser'];
668 /* Preparing the new assignment */
669 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
670 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
671 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
672 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
674 if($this->multiple_support_active){
675 $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
676 }
677 }
678 }
680 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
681 * If there is no defined share selected, we will abort the deletion without any message
682 */
683 $once = true;
684 if($this->acl_is_writeable("gotoShare")){
685 foreach($_POST as $name => $value){
686 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
687 $once = false;
688 $key = preg_replace("/^gotoShareDel_/","",$name);
689 $key = preg_replace("/_+[xy]$/","",$key);
690 $key = base64_decode($key);
691 if(isset($this->gotoShares[$key])) {
692 unset($this->gotoShares[$key]);
693 }
695 /* Remove corresponding password entry, too. This is a workaround
696 to get rid of old-style entries. */
697 $key= preg_replace("/\|/", "|!", $key);
698 if(isset($this->gotoShares[$key])) {
699 unset($this->gotoShares[$key]);
700 }
701 }
702 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
703 $once = false;
704 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
705 $key = preg_replace("/_+[xy]$/","",$key);
706 $key = base64_decode($key);
707 $this->gotoShares[$key]['PwdHash'] = "";
708 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
709 unset($this->gotoShares[$key]);
710 }
711 }
712 }
713 }
714 $divlistShares = new divSelectBox("gotoShares");
715 $divlistShares->SetHeight(100);
718 $tmp = array();
719 if($this->acl_is_readable("gotoShares")){
720 $tmp = $this->printOutAssignedShares();
721 }
724 foreach($tmp as $key => $value){
725 $img = "";
727 /* Skip apssword only entries */
728 if( empty($this->gotoShares[$key]['server']) &&
729 empty($this->gotoShares[$key]['name']) &&
730 empty($this->gotoShares[$key]['mountPoint']) &&
731 empty($this->gotoShares[$key]['Username'])){
732 continue;
733 }
735 $color = "";
736 if($this->multiple_support_active){
737 if($this->gotoShares[$key]['UsedByAllUsers']){
738 $value .= " (<b>"._("Used by all users")."</b>)";
739 }else{
740 $color = "color: #999999;";
741 $value .= " (<b>"._("Used by some users")."</b>)";
742 }
743 }
745 /* Check if entry starts with an ! */
746 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
748 /* If we are currently editing groups environment, skip those ! entries */
749 if($this->is_group) continue;
751 /* Create pwd reset images */
752 if($this->gotoShares[$key]['PwdHash'] != ""){
753 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
754 title='"._("Reset password hash")."'>";
755 }
756 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
757 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
758 }else{
760 /* Create pwd reset img && delete image */
761 if($this->gotoShares[$key]['PwdHash'] != ""){
762 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
763 title='"._("Reset password hash")."'>";
764 $img.= " ";
765 }
766 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='"._("Delete")."'
767 title='"._("Delete share entry")."'>";
768 $field1 = array("string" => $value , "attach" => "style='".$color."'");
769 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
770 }
771 $divlistShares->AddEntry(array($field1,$field2));
772 }
773 $smarty->assign("divlistShares",$divlistShares->DrawList());
775 /* Hotplug devices will be handled here
776 * There are 3 possible methods for this feature
777 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
778 * Delete will erase an entry, the entry must be selcted in the ListBox first
779 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
780 */
782 /* We have to delete the selected hotplug from the list*/
783 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
784 if($this->acl_is_writeable("gotoHotplugDevice")){
785 foreach($_POST['gotoHotplugDevice_post'] as $name){
786 unset($this->gotoHotplugDevices[$name]);
787 }
788 }
789 }
791 /* There are already defined hotplugs from other users we could use */
792 if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
793 $tmp =array();
794 foreach($this->gotoHotplugDevices as $plugs){
795 $tmp[] = $plugs['name'];
796 }
797 $this->dialog = new hotplugDialog($this->config,$tmp);
798 $this->is_dialog = true;
799 }
801 /* Dialog Aborted */
802 if(isset($_POST['HotPlugCancel'])){
803 unset($this->dialog);
804 $this->dialog= FALSE;
805 $this->is_dialog = false;
806 }
808 /* Dialod saved */
809 if(isset($_POST['HotPlugSave'])){
811 $this->dialog->save_object();
812 if(count($this->dialog->check())!=0){
813 foreach($this->dialog->check() as $msg){
814 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
815 }
816 }else{
817 $this->dialog->save_object();
818 $a_tmp = $this->dialog->save();
820 if(is_array($a_tmp)){
821 foreach($a_tmp as $name => $hotplug){
822 if($this->multiple_support_active){
823 $hotplug['UsedByAllUsers'] = TRUE;
824 }
825 $this->gotoHotplugDevices[$name]= $hotplug;
826 }
827 }
828 unset($this->dialog);
829 $this->dialog= FALSE;
830 $this->is_dialog = false;
831 }
832 }
834 if($this->multiple_support_active){
835 $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
836 }else{
837 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
838 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
839 }
841 /* Printer Assignment will managed below
842 * A printer can be assigned in two different ways and two different types
843 * There are 2 types of users assigned to a printer : user and admin
844 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
845 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
846 */
848 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
849 if(isset($_POST['gotoPrinterAdd'])){
851 $this->is_dialog=true;
852 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
853 }
855 if(isset($_POST['PrinterCancel'])){
856 $this->is_dialog=false;
857 unset($this->dialog);
858 $this->dialog=FALSE;
859 }
861 if(isset($_POST['PrinterSave'])){
862 if(count($this->dialog->check())!=0){
863 $tmp = $this->dialog->check();
864 foreach($tmp as $msg){
865 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
866 }
867 }else{
868 $this->dialog->save_object();
869 $tmp = $this->dialog->save();
870 $tmp2= $this->dialog->getPrinter(true);
872 foreach($tmp as $pname){
873 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
874 $printerObj->set_acl_base($tmp2[$pname]['dn']);
876 $type = false;
878 if($this->is_group){
879 if($this->dn == "new"){
880 $type = "AddGroup";
881 }elseif(isset($this->NewDeletedPrinters[$pname])){
882 $type = "AddGroup";
883 }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
884 $type = "AddGroup";
885 }
886 }else{
887 if($this->multiple_support_active){
888 $type = "AddUser";
889 }elseif(isset($this->NewDeletedPrinters[$pname])){
890 $type = "AddUser";
891 }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
892 $type = "AddUser";
893 }
894 }
896 if($type){
897 $this->gotoPrinter[$pname]=$tmp2[$pname];
898 $this->gotoPrinter[$pname]['mode']="user";
899 $this->add_del_printer_member_was_called = true;
901 $this->NewAddedPrinters[$pname] = $pname;
902 if(isset($this->NewDeletedPrinters[$pname])){
903 unset($this->NewDeletedPrinters[$pname]);
904 }
905 }
906 }
908 $this->is_dialog=false;
909 unset($this->dialog);
910 $this->dialog =FALSE;
911 }
912 }
914 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
915 $printer = $_POST['gotoPrinterSel'];
916 foreach($printer as $pname){
918 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
919 $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
921 $type = false;
922 if($this->is_group){
923 if(isset($this->NewAddedPrinters[$pname])){
924 $type = "Group";
925 }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
926 $type = "Group";
927 }
928 }else{
929 if(isset($this->NewAddedPrinters[$pname])){
930 $type = "User";
931 }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
932 $type = "User";
933 }
934 }
935 if($type){
936 $this->add_del_printer_member_was_called = true;
937 unset($this->gotoPrinter[$pname]);
939 $this->NewDeletedPrinters[$pname] = $pname;
940 if(isset($this->NewAddedPrinters[$pname])){
941 UNSET($this->NewAddedPrinters[$pname]);
942 }
943 }
944 }
945 }
947 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
948 $printers = $_POST['gotoPrinterSel'];
949 $this->add_del_printer_member_was_called = true;
950 foreach($printers as $printer){
951 if($this->gotoPrinter[$printer]['mode']=="user"){
952 $this->gotoPrinter[$printer]['mode']="admin";
953 }else{
954 $this->gotoPrinter[$printer]['mode']="user";
955 }
956 }
957 }
959 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
960 if($this->is_group){
961 msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
962 }else{
963 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
964 $this->gosaDefaultPrinter= "";
965 } else {
966 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
967 }
968 }
969 }
971 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
972 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
974 /* General behavior */
975 if(is_object($this->dialog)){
976 $this->dialog->save_object();
977 $disp =$this->dialog->execute();
978 return($disp);
979 }
981 /* Assign used attributes for multiple edit */
982 foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
983 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
984 $ubox ="use_".$box;
985 if(in_array($box,$this->multi_boxes)){
986 $smarty->assign($ubox,TRUE);
987 }else{
988 $smarty->assign($ubox,FALSE);
989 }
990 }
992 /* Als smarty vars are set. Get smarty template and generate output */
993 $smarty->assign("multiple_support",$this->multiple_support_active);
994 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
995 return($display);
996 }
998 function remove_from_parent()
999 {
1000 /* only if it was an account*/
1001 if (!$this->initially_was_account){
1002 return;
1003 }
1005 /* include global link_info */
1006 $ldap= $this->config->get_ldap_link();
1008 /* Remove and write to LDAP */
1009 plugin::remove_from_parent();
1011 /* Don't save our template variables */
1012 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1014 /* Skip all these attributes */
1015 foreach($skip as $del){
1016 unset($this->attrs[$del]);
1017 }
1019 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1021 $ldap->cd($this->dn);
1022 $this->cleanup();
1023 $ldap->modify ($this->attrs);
1025 if($this->is_group){
1026 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1027 }else{
1028 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1029 }
1031 show_ldap_error($ldap->get_error(), sprintf(_("Removing of user/environment account with dn '%s' failed."),$this->dn));
1033 /* Optionally execute a command after we're done */
1034 $this->handle_post_events("remove",array("uid" => $this->uid));
1035 }
1038 /* Save data to object */
1039 function save_object()
1040 {
1041 /* Get all Posted vars
1042 * Setup checkboxes
1043 */
1044 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
1045 if(isset($_POST['iamposted'])){
1047 $PACL = $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1049 if(isset($_POST['kiosk_server'])){
1050 $tmp = $_POST['kiosk_server'];
1051 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1052 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1053 }
1054 }
1055 if(isset($_POST['kiosk_profile'])){
1056 $tmp = $_POST['kiosk_profile'];
1057 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1058 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1059 }
1060 }
1062 if(preg_match("/w/",$PACL)){
1063 if(isset($_POST['useProfile'])){
1064 $this->useProfile = true;
1065 }else{
1066 $this->useProfile = false;
1067 }
1068 }
1070 if($this->acl_is_writeable("gotoProfileFlagC")){
1071 if(isset($_POST['gotoProfileFlagC'])){
1072 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1073 }else{
1074 $this->gotoProfileFlagC = false;
1075 }
1076 }
1078 if($this->acl_is_writeable("gotoProfileFlagL")){
1079 if(isset($_POST['gotoProfileFlagL'])){
1080 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1081 }else{
1082 $this->gotoProfileFlagL = false;
1083 }
1084 }
1086 plugin::save_object();
1087 foreach($this->attributes as $s_attr){
1088 if((!isset($_POST[$s_attr])) ||
1089 in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1090 if(!$this->acl_is_writeable($s_attr)){
1091 continue;
1092 }else{
1093 if(isset($_POST[$s_attr])){
1094 $this->$s_attr = $_POST[$s_attr];
1095 }else{
1096 $this->$s_attr = false;
1097 }
1098 }
1099 }
1100 }
1101 }
1104 /* Check supplied data */
1105 function check()
1106 {
1107 /* Call common method to give check the hook */
1108 $message= plugin::check();
1110 $this->detect_grouptype();
1112 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1113 $message[]=_("Please set a valid profile quota size.");
1114 }
1115 if(!isset($this->attrs['objectClass'])){
1116 $this->attrs['objectClass']=array();
1117 }
1118 if(!$this->is_group){
1119 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1120 $message[]=(_("You need to setup a valid posix extension in order to enable evironment features."));
1121 }
1122 }
1123 return ($message);
1124 }
1127 /* Save to LDAP */
1128 function save()
1129 {
1130 /* If group was renamed, all printer settings get lost
1131 */
1132 /* only save changed variables ....*/
1133 if ($this->gotoKioskProfile_Server != "none"){
1134 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
1135 $method="https://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1136 }else{
1137 $method="http://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1138 }
1139 $this->gotoKioskProfile= $method;
1140 }else{
1141 $this->gotoKioskProfile= array();
1142 }
1144 plugin::save();
1145 $ldap= $this->config->get_ldap_link();
1147 $realyUsedAttrs= array();
1149 /* Save already used objectClasses */
1150 $ocs = $this->attrs['objectClass'];
1151 unset($ocs['count']);
1152 $this->attrs = array();
1153 $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1155 /* 1. Search all printers that have our uid/cn as member
1156 * 2. Delete this uid/cn from every single entry and save it again.
1157 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1158 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
1159 */
1161 $this->detect_grouptype();
1163 if($this->add_del_printer_member_was_called){
1165 $types = array( "gotoUserPrinter" => "AddUser",
1166 "gotoGroupPrinter" => "AddGroup",
1167 "gotoUserAdminPrinter" => "AddAdminUser",
1168 "gotoGroupAdminPrinter" => "AddAdminGroup");
1170 if($this->is_group){
1171 $s_suffix = "Group";
1172 $useVar = "cn";
1173 }else{
1174 $useVar = "uid";
1175 $s_suffix = "User";
1176 }
1178 /* Remove old entries */
1179 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1180 while($attr = $ldap->fetch()){
1181 $printerObj = NULL;
1182 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1183 $printerObj->set_acl_base($attr['dn']);
1184 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1185 $printerObj->by_object['printgeneric']->save();
1186 }
1188 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1189 while($attr = $ldap->fetch()){
1190 $printerObj = NULL;
1191 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1192 $printerObj->set_acl_base($attr['dn']);
1193 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1194 $printerObj->by_object['printgeneric']->save();
1195 }
1197 foreach($this->gotoPrinter as $printer){
1198 $printerObj = NULL;
1199 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1200 $printerObj->set_acl_base($printer['dn']);
1203 if($printer['mode'] == "admin") {
1204 $attribute = "goto".$s_suffix."AdminPrinter";
1205 }else{
1206 $attribute = "goto".$s_suffix."Printer";
1207 }
1209 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1210 $printerObj->by_object['printgeneric']->save();
1211 }
1212 }
1214 /* Prepare HotPlug devices */
1215 $this->attrs['gotoHotplugDeviceDN'] = array();
1216 foreach($this->gotoHotplugDevices as $name => $device){
1217 $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1218 }
1220 /* Prepare LogonScripts */
1221 $this->attrs['gotoLogonScript'] = array();
1222 foreach($this->gotoLogonScripts as $name => $script){
1223 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1224 $script['LogonOverload'].$script['LogonLast']."|".
1225 $script['LogonPriority']."|".
1226 base64_encode($script['LogonData'])."|".
1227 $script['LogonDescription'];
1228 }
1230 /* Prepare Shares */
1231 $this->attrs['gotoShare']=array();
1232 foreach($this->gotoShares as $name => $share){
1233 $mntp= $share['mountPoint'];
1234 if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1235 $mntp= base64_encode($mntp);
1236 }
1237 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1238 }
1241 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1242 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1244 foreach($saveThis as $tosave){
1245 if(!empty($this->$tosave)){
1246 $this->attrs[$tosave]=$this->$tosave;
1247 }else{
1248 $this->attrs[$tosave]=array();
1249 }
1250 }
1252 /* Prepare Flags */
1253 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1254 if(empty($this->attrs['gotoProfileFlags'][0])){
1255 $this->attrs['gotoProfileFlags']=array();
1256 }
1258 if($this->useProfile == false){
1259 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1260 $this->attrs['gotoProfileServer']= array();
1261 }
1263 $ldap->cat ($this->dn, array('dn'));
1264 if ($ldap->fetch()){
1265 $mode= "modify";
1266 } else {
1267 $mode= "add";
1268 $ldap->cd($this->config->current['BASE']);
1269 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1270 }
1272 $ldap->cd($this->dn);
1273 $this->cleanup();
1274 $ldap->$mode($this->attrs);
1276 $cat = "users";
1277 if($this->is_group){
1278 $cat = "groups";
1279 }
1281 /* Log last action */
1282 if($this->initially_was_account){
1283 new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1284 }else{
1285 new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1286 }
1288 show_ldap_error($ldap->get_error(), sprintf(_("Saving of user/environment account with dn '%s' failed."),$this->dn));
1289 $this->handle_post_events($mode,array("uid"=>$this->uid));
1290 }
1292 /* Generate ListBox frindly output for the defined shares
1293 * Possibly Add or remove an attribute here,
1294 */
1295 function printOutAssignedShares()
1296 {
1297 $a_return = array();
1298 if(is_array($this->gotoShares)){
1299 foreach($this->gotoShares as $share){
1300 if(preg_match("/^!/",$share['server'])){
1301 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1302 }else{
1303 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1304 }
1305 }
1306 natcasesort($a_return);
1307 }
1308 return($a_return);
1309 }
1311 /* Generate ListBox frindly output for the definedhotplugs
1312 * Possibly Add or remove an attribute here,
1313 */
1314 function printOutHotPlugDevices()
1315 {
1316 $a_return= array();
1317 if(is_array($this->gotoHotplugDevices)){
1318 foreach($this->gotoHotplugDevices as $key=>$device){
1319 $a_return[$key] = $device['name']." - ".$device['id'];
1320 }
1321 }
1322 return($a_return);
1323 }
1325 /* Generates ListBox frienly output of used printer devices
1326 * Append ' - admin' if printer is used in admin mode
1327 */
1328 function printOutPrinterDevices()
1329 {
1330 $a_return = array();
1332 if($this->acl_is_readable("gotoPrinter")){
1334 if(is_array($this->gotoPrinter)){
1335 foreach($this->gotoPrinter as $printer){
1336 if($printer['mode'] == "admin"){
1337 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1338 }else{
1339 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1340 }
1341 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1342 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1343 }
1344 }
1345 }
1346 }
1347 return($a_return);
1348 }
1351 function PrepareForCopyPaste($source)
1352 {
1353 plugin::PrepareForCopyPaste($source);
1355 $class= get_class($this);
1356 $o_source = new $class($this->config,$source['dn']);
1357 foreach($this->CopyPasteVars as $attr){
1358 $this->$attr = $o_source->$attr;
1359 }
1360 }
1363 function saveCopyDialog()
1364 {
1365 if(isset($_POST['cn'])){
1366 $this->cn = $_POST['cn'];
1367 $this->uid = $_POST['cn'];
1368 }
1369 }
1372 /* Generates ListBox frienly output of used logonscripts
1373 */
1374 function printOutLogonScripts()
1375 {
1376 $a_return = array();
1377 if(is_array($this->gotoLogonScripts)){
1378 foreach($this->gotoLogonScripts as $script){
1379 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1380 }
1381 }
1382 return($a_return);
1383 }
1386 function multiple_execute()
1387 {
1388 /* Reset header toggle */
1389 $this->is_account = TRUE;
1390 return($this->execute());
1391 }
1394 /* Initialize plugin with given atribute arrays
1395 */
1396 function init_multiple_support($attrs,$all)
1397 {
1398 plugin::init_multiple_support($attrs,$all);
1400 /* Prepare Shares */
1401 if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1402 unset($this->multi_attrs_all['gotoShare']['count']);
1403 foreach($this->multi_attrs_all['gotoShare'] as $share){
1404 $tmp = $tmp2 = array();
1405 $tmp = split("\|",$share);
1406 $tmp2['server'] =$tmp[0];
1407 $tmp2['name'] =$tmp[1];
1409 /* Decode base64 if needed */
1410 if (!preg_match('%/%', $tmp[2])){
1411 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1412 } else {
1413 $tmp2['mountPoint'] =$tmp[2];
1414 }
1416 if(isset($tmp[3])){
1417 $tmp2['PwdHash'] =$tmp[3];
1418 }else{
1419 $tmp2['PwdHash'] ="";
1420 }
1421 if(isset($tmp[4])){
1422 $tmp2['Username'] =$tmp[4];
1423 }else{
1424 $tmp2['Username'] ="";
1425 }
1426 $tmp2['UsedByAllUsers'] = FALSE;
1427 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1428 }
1429 }
1431 /* Prepare Shares */
1432 if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1433 unset($this->multi_attrs['gotoShare']['count']);
1434 foreach($this->multi_attrs['gotoShare'] as $share){
1435 $tmp = $tmp2 = array();
1436 $tmp = split("\|",$share);
1437 $tmp2['server'] =$tmp[0];
1438 $tmp2['name'] =$tmp[1];
1440 /* Decode base64 if needed */
1441 if (!preg_match('%/%', $tmp[2])){
1442 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1443 } else {
1444 $tmp2['mountPoint'] =$tmp[2];
1445 }
1447 if(isset($tmp[3])){
1448 $tmp2['PwdHash'] =$tmp[3];
1449 }else{
1450 $tmp2['PwdHash'] ="";
1451 }
1452 if(isset($tmp[4])){
1453 $tmp2['Username'] =$tmp[4];
1454 }else{
1455 $tmp2['Username'] ="";
1456 }
1457 $tmp2['UsedByAllUsers'] = TRUE;
1458 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1459 }
1460 }
1463 /* prepare LogonScripts */
1464 if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1465 unset($this->multi_attrs_all['gotoLogonScript']['count']);
1466 foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1467 $tmp = $tmp2 = array();
1468 $tmp = split("\|",$device);
1469 $tmp2['LogonName'] = $tmp[0];
1470 $tmp2['LogonPriority'] = $tmp[2];
1471 if(preg_match("/O/i",$tmp[1])){
1472 $tmp2['LogonOverload'] = "O";
1473 }else{
1474 $tmp2['LogonOverload'] = "";
1475 }
1476 if(preg_match("/L/i",$tmp[1])){
1477 $tmp2['LogonLast'] = "L";
1478 }else{
1479 $tmp2['LogonLast'] = "";
1480 }
1481 $tmp2['LogonData'] = base64_decode($tmp[3]);
1482 $tmp2['LogonDescription'] = $tmp[4];
1483 $tmp2['UsedByAllUsers'] = FALSE;
1484 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1485 }
1486 }
1488 /* prepare LogonScripts */
1489 if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1490 unset($this->multi_attrs['gotoLogonScript']['count']);
1491 foreach($this->multi_attrs['gotoLogonScript'] as $device){
1492 $tmp = $tmp2 = array();
1493 $tmp = split("\|",$device);
1494 $tmp2['LogonName'] = $tmp[0];
1495 $tmp2['LogonPriority'] = $tmp[2];
1496 if(preg_match("/O/i",$tmp[1])){
1497 $tmp2['LogonOverload'] = "O";
1498 }else{
1499 $tmp2['LogonOverload'] = "";
1500 }
1501 if(preg_match("/L/i",$tmp[1])){
1502 $tmp2['LogonLast'] = "L";
1503 }else{
1504 $tmp2['LogonLast'] = "";
1505 }
1506 $tmp2['LogonData'] = base64_decode($tmp[3]);
1507 $tmp2['LogonDescription'] = $tmp[4];
1508 $tmp2['UsedByAllUsers'] = TRUE;
1509 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1510 }
1511 }
1513 /* Prepare hotplugs */
1514 if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1515 $ldap = $this->config->get_ldap_link();
1516 $ldap->cd($this->config->current['BASE']);
1517 for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1518 $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1519 if($ldap->count()){
1520 $multi_attrs_all = $ldap->fetch();
1522 if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1523 $tmp = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1524 $tmp2 = array();
1525 $tmp2['name'] = $multi_attrs_all['cn'][0];
1526 $tmp2['description'] = $tmp[0];
1527 $tmp2['id'] = $tmp[1];
1528 $tmp2['produkt'] = $tmp[2];
1529 $tmp2['vendor'] = $tmp[3];
1530 $tmp2['dn'] = $multi_attrs_all['dn'];
1531 $tmp2['UsedByAllUsers'] = FALSE;
1532 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1533 }
1534 }
1535 }
1536 }
1538 /* Prepare hotplugs */
1539 if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1540 $ldap = $this->config->get_ldap_link();
1541 $ldap->cd($this->config->current['BASE']);
1542 for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1543 $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1544 if($ldap->count()){
1545 $multi_attrs = $ldap->fetch();
1547 if(isset($multi_attrs['gotoHotplugDevice'][0])){
1548 $tmp = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1549 $tmp2 = array();
1550 $tmp2['name'] = $multi_attrs['cn'][0];
1551 $tmp2['description'] = $tmp[0];
1552 $tmp2['id'] = $tmp[1];
1553 $tmp2['produkt'] = $tmp[2];
1554 $tmp2['vendor'] = $tmp[3];
1555 $tmp2['dn'] = $multi_attrs['dn'];
1556 $tmp2['UsedByAllUsers'] = TRUE;
1557 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1558 }
1559 }
1560 }
1561 }
1562 $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1563 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1564 $chr = $this->gotoProfileFlags[$i];
1565 $name = "gotoProfileFlag".$chr;
1566 $this->$name=$chr;
1567 }
1568 $this->update_kiosk_profiles();
1569 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1571 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1572 $this->useProfile = true;
1573 }else{
1574 $this->useProfile = false;
1575 }
1577 }
1580 function set_multi_edit_values($attrs)
1581 {
1582 $shares = $this->gotoShares;
1583 $scripts= $this->gotoLogonScripts;
1584 $plugs= $this->gotoHotplugDevices;
1585 plugin::set_multi_edit_values($attrs);
1587 $this->gotoShares = $shares;
1588 $this->gotoLogonScripts = $scripts;
1589 $this->gotoHotplugDevices = $plugs;
1591 foreach($attrs['gotoShares'] as $name => $share){
1592 if($share['UsedByAllUsers'] == TRUE){
1593 $this->gotoShares[$name] = $share;
1594 }
1595 }
1596 foreach($this->gotoShares as $name => $share){
1597 if(!isset($attrs['gotoShares'][$name])){
1598 unset($this->gotoShares[$name]);
1599 }
1600 }
1601 foreach($attrs['gotoLogonScripts'] as $name => $script){
1602 if($script['UsedByAllUsers'] == TRUE){
1603 $this->gotoLogonScripts[$name] = $script;
1604 }
1605 }
1606 foreach($this->gotoLogonScripts as $name => $script){
1607 if(!isset($attrs['gotoLogonScripts'][$name])){
1608 unset($this->gotoLogonScripts[$name]);
1609 }
1610 }
1611 $tmp = array();
1612 foreach($this->gotoHotplugDevices as $entry){
1613 $tmp[$entry['dn']] = $entry;
1614 }
1616 foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1617 if($plug['UsedByAllUsers'] == TRUE){
1618 $tmp[$plug['dn']] = $plug;
1619 }
1620 }
1621 foreach($tmp as $name => $plug){
1622 $found = false;
1623 foreach($attrs['gotoHotplugDevices'] as $test){
1624 if($test['dn'] == $name){
1625 $found = true;
1626 }
1627 }
1628 if(!$found){
1629 unset($tmp[$name]);
1630 }
1631 }
1632 }
1635 /* Return selected values for multiple edit */
1636 function get_multi_edit_values()
1637 {
1638 $ret = plugin::get_multi_edit_values();
1639 $ret['gotoShares'] = $this->gotoShares;
1640 $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1641 $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1643 if(in_array("gotoPrinter",$this->multi_boxes)){
1644 $ret['gotoPrinter'] = $this->gotoPrinter;
1645 $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1646 $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1648 /* Force printer reset */
1649 $ret['add_del_printer_member_was_called'] = TRUE;
1650 }
1652 if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1653 $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1654 }
1656 if(in_array("useProfile",$this->multi_boxes)){
1657 $ret['useProfile']=$this->useProfile;
1658 if(in_array("gotoProfileServer",$this->multi_boxes)){
1659 $ret['gotoProfileServer']=$this->gotoProfileServer;
1660 }
1661 if(in_array("gotoProfileQuota",$this->multi_boxes)){
1662 $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1663 }
1664 if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1665 $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1666 }
1667 }
1668 if(in_array("gotoXResolution",$this->multi_boxes)){
1669 $ret['gotoXResolution'] = $this->gotoXResolution;
1670 }
1671 if(in_array("kiosk_server",$this->multi_boxes)){
1672 $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1673 $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1674 }
1675 return($ret);
1676 }
1679 function multiple_check()
1680 {
1681 $message = plugin::multiple_check();
1682 $this->detect_grouptype();
1684 if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
1685 $message[]=_("Please set a valid profile quota size.");
1686 }
1687 return($message);
1688 }
1691 function multiple_save_object()
1692 {
1693 if(isset($_POST['environment_multiple_posted'])){
1694 plugin::multiple_save_object();
1696 if(isset($_POST['useProfile'])){
1697 $this->useProfile = true;
1698 }else{
1699 $this->useProfile = false;
1700 }
1701 if(isset($_POST['gotoProfileFlagC'])){
1702 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1703 }else{
1704 $this->gotoProfileFlagC = false;
1705 }
1707 if(isset($_POST['gotoProfileFlagL'])){
1708 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1709 }else{
1710 $this->gotoProfileFlagL = false;
1711 }
1713 foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1714 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1715 $uattr = "use_".$attr;
1716 if(isset($_POST[$uattr])){
1717 $this->multi_boxes[] = $attr;
1718 }
1719 }
1720 if(isset($_POST['kiosk_server'])){
1721 $tmp = $_POST['kiosk_server'];
1722 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1723 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1724 }
1725 }
1726 if(isset($_POST['kiosk_profile'])){
1727 $tmp = $_POST['kiosk_profile'];
1728 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1729 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1730 }
1731 }
1733 }
1734 }
1736 /* Return plugin informations for acl handling
1737 #FIXME these ACLs should work for groups too */
1738 static function plInfo()
1739 {
1740 return (array("plShortName" => _("Environment"),
1741 "plDescription" => _("Environment settings"), // Description
1742 "plSelfModify" => TRUE,
1743 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1744 "plPriority" => 3, // Position in tabs
1745 "plSection" => array("personal" => _("My account")),
1746 "plCategory" => array("users",
1747 "groups"),
1748 "plOptions" => array("resolution_hook" => array("type" => "string",
1749 "description" => _("Command to extend the list of possible screen resolutions"))),
1751 "plProvidedAcls" => array(
1753 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1754 "gotoProfileFlagC" => _("Cache profile localy") ,
1756 "gotoProfileQuota" => _("Profile quota") ,
1757 "gotoProfileServer" => _("Profile server") ,
1759 "gotoXResolution" => _("Resolution") ,
1760 "gotoKioskProfile" => _("Kiosk profile") ,
1762 "gosaDefaultPrinter" => _("Default printer") ,
1763 "gotoLogonScript" => _("Logon script") ,
1764 "gotoHotplugDevice" => _("Hotplug devices"),
1765 "gotoShare" => _("Shares"))
1766 ));
1767 }
1768 }
1770 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1771 ?>