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