1 <?php
3 class environment extends plugin
4 {
5 /* attribute list for save action */
6 var $ignore_account = FALSE;
7 var $plHeadline = "Environment";
8 var $plDescription = "This does something";
9 var $dialog = false; // Indicates that we are currently editing in an seperate dialog
11 var $in_dialog = false;
12 var $uid = "";
14 var $is_group = false;
15 var $view_logged = FALSE;
17 /* Attribute definition
18 */
20 /* profile management */
21 var $useProfile = false; // Specifies if we want to use a Server
22 var $gotoProfileServer = ""; // Specifies the selected profile server
23 var $gotoProfileServers = array();// Specifies all available and selectable servers
24 var $gotoProfileFlags = ""; // Flags enabled ? only used to set ACL and save
25 var $gotoProfileFlagC = ""; // Flag is set to C if we have the profile caching fucntion enabled
27 var $gotoXResolution = "auto"; // The selected resolution eg: 1024x768
28 var $gotoXResolutions = array();// Contains all available resolutions for this account
29 var $gotoProfileFlagL = ""; // Flag is set to L to enable runtime resolution change
30 var $gotoProfileQuota = ""; // User Quota Settings
32 /* Logon script section*/
33 var $gotoLogonScripts = array();// Contains all available Logon Scripts
34 var $gotoLogonScript = ""; // The selected Logon Script
36 /* Printer */
37 var $gotoPrinter = array();// All available Printer, with their configurations
38 var $gotoPrinterSel = ""; // The selected Printer
39 var $gosaDefaultPrinter = ""; // Default printer
41 /* Share */
42 var $gotoShares = array();// Current Share Options
43 var $gotoShare = ""; // currently selected Share Option
44 var $gotoShareSelections= array();// Available Shares for this account in Listbox format
45 var $gotoAvailableShares= array();// Available Shares for this account
47 /* Kiosk profile */
48 var $kiosk_enabled = FALSE;
49 var $gotoKioskProfile = ""; // The selected Kiosk Profile
50 var $gotoKioskProfile_Server = ""; // The selected Kiosk Profile
51 var $gotoKioskProfile_Profile = ""; // The selected Kiosk Profile
52 var $gotoKioskProfiles = array();// All available Kiosk profiles
54 /* Hotplug Devices */
55 var $gotoHotplugDevice = array(); // Selected hotplug
56 var $gotoHotplugDevices = array();// Already configured hotplug devices
57 var $gotoHotplugDeviceDN= array();
59 var $NewAddedPrinters = array();
60 var $NewDeletedPrinters = array();
62 /* general settings */
63 // Sets the attributes which will kept on page reload, which will be saved, ...
65 var $CopyPasteVars = array("gotoHotplugDevices","gotoAvailableShares","gotoShareSelections","gotoPrinterSel","gotoProfileFlagL","gotoXResolutions","gotoProfileFlagC","gotoProfileServers","useProfile","is_group","in_dialog","OrigCn","gotoKioskProfile_Server","gotoKioskProfile_Profile");
67 var $attributes = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
68 "gotoXResolution","gotoProfileQuota",
69 "gotoLogonScripts","gotoLogonScript",
70 "gotoPrinter", "gosaDefaultPrinter",
71 "gotoShares","gotoShare",
72 "gotoKioskProfile");
73 var $objectclasses = array("gotoEnvironment"); // Specifies the objectClass which contains the attributes edited here
74 var $cn;
75 var $OrigCn;
76 var $add_del_printer_member_was_called = false;
78 var $multiple_support =TRUE;
80 var $use_gotoPrinter;
82 function environment (&$config, $dn= NULL)
83 {
84 plugin::plugin ($config, $dn);
86 /* Setting uid to default */
87 if(isset($this->attrs['uid'][0])){
88 $this->uid = $this->attrs['uid'][0];
89 }
91 /* Check : Are we currently editing a group or user dialog */
92 if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
93 $suffix="Group";
94 $this->uid = $this->attrs['cn'][0];
95 $this->attrs['uid'] = $this->attrs['cn'][0];
96 $this->OrigCn = $this->attrs['cn'][0];
97 }else{
98 $suffix="User";
99 }
101 /* Get all Printer assignments */
102 $ldap = $this->config->get_ldap_link();
103 $ldap->cd($this->config->current['BASE']);
104 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
105 while($printer = $ldap->fetch()){
106 $this->gotoPrinter[$printer['cn'][0]]=$printer;
107 $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
108 }
109 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
110 while($printer = $ldap->fetch()){
111 $this->gotoPrinter[$printer['cn'][0]]=$printer;
112 $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
113 }
116 /* Prepare hotplugs */
117 if(isset($this->attrs['gotoHotplugDeviceDN']) && is_array($this->attrs['gotoHotplugDeviceDN'])){
118 $ldap = $this->config->get_ldap_link();
119 $ldap->cd($this->config->current['BASE']);
120 for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
121 $ldap->cat($this->attrs['gotoHotplugDeviceDN'][$i]);
122 if($ldap->count()){
123 $attrs = $ldap->fetch();
125 if(isset($attrs['gotoHotplugDevice'][0])){
126 $tmp = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
127 $tmp2 = array();
128 $tmp2['name'] = $attrs['cn'][0];
129 $tmp2['description'] = $tmp[0];
130 $tmp2['id'] = $tmp[1];
131 $tmp2['produkt'] = $tmp[2];
132 $tmp2['vendor'] = $tmp[3];
133 $tmp2['dn'] = $attrs['dn'];
134 $this->gotoHotplugDevices[] = $tmp2;
135 }
136 }else{
137 msg_dialog::display(_("Warning"), sprintf(_("Device '%s' is not available anymore. It will be removed!"), $this->attrs['gotoHotplugDeviceDN'][$i]), WARNING_DIALOG);
138 }
139 }
140 }
143 /* prepare LogonScripts */
144 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
145 unset($this->attrs['gotoLogonScript']['count']);
146 foreach($this->attrs['gotoLogonScript'] as $device){
147 $tmp = $tmp2 = array();
148 $tmp = split("\|",$device);
149 $tmp2['LogonName'] = $tmp[0];
150 $tmp2['LogonPriority'] = $tmp[2];
151 if(preg_match("/O/i",$tmp[1])){
152 $tmp2['LogonOverload'] = "O";
153 }else{
154 $tmp2['LogonOverload'] = "";
155 }
156 if(preg_match("/L/i",$tmp[1])){
157 $tmp2['LogonLast'] = "L";
158 }else{
159 $tmp2['LogonLast'] = "";
160 }
161 $tmp2['LogonData'] = base64_decode($tmp[3]);
162 $tmp2['LogonDescription'] = $tmp[4];
163 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
164 }
165 }
167 /* Prepare Shares */
168 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
169 unset($this->attrs['gotoShare']['count']);
170 foreach($this->attrs['gotoShare'] as $share){
171 $tmp = $tmp2 = array();
172 $tmp = split("\|",$share);
173 $tmp2['server'] =$tmp[0];
174 $tmp2['name'] =$tmp[1];
176 /* Decode base64 if needed */
177 if (!preg_match('%/%', $tmp[2])){
178 $tmp2['mountPoint'] =base64_decode($tmp[2]);
179 } else {
180 $tmp2['mountPoint'] =$tmp[2];
181 }
183 if(isset($tmp[3])){
184 $tmp2['PwdHash'] =$tmp[3];
185 }else{
186 $tmp2['PwdHash'] ="";
187 }
188 if(isset($tmp[4])){
189 $tmp2['Username'] =$tmp[4];
190 }else{
191 $tmp2['Username'] ="";
192 }
193 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
194 }
195 }
197 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
198 $chr = $this->gotoProfileFlags[$i];
199 $name = "gotoProfileFlag".$chr;
200 $this->$name=$chr;
201 }
203 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
204 $this->useProfile = true;
205 }else{
206 $this->useProfile = false;
207 }
209 /* Set resolutions */
210 $this->gotoXResolutions = array("auto"=>_("auto"),
211 "640x480" => "640x480",
212 "800x600" => "800x600",
213 "1024x768" => "1024x768",
214 "1152x864" => "1152x864",
215 "1280x768" => "1280x768",
216 "1280x1024" => "1280x1024");
218 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
219 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
221 if(is_readable($file)){
222 $str = file_get_contents($file);
223 $lines = split("\n",$str);
224 foreach($lines as $line){
225 $line = trim($line);
226 if(!empty($line)){
227 $this->gotoXResolutions[$line]=$line;
228 }
229 }
230 //natcasesort($this->gotoXResolutions);
231 }else{
232 msg_dialog::display(_("Configuration error"), sprintf(_("Cannot open file '%s'!"), $file), WARNING_DIALOG);
233 }
234 }
236 $this->gotoProfileServers= $config->getShareServerList() ;
237 $this->gotoShareSelections= $config->getShareList(true);
238 $this->gotoAvailableShares= $config->getShareList(false);
240 /* Ensure that a currently selected server will stay selected, even if the list of profile servers
241 is empty due to insufficient permissions.
242 */
243 if(count($this->gotoProfileServers) && !empty($this->gotoProfileServer)){
245 /* The currently selected profile server is outdated/no longer available */
246 if(!isset($this->gotoProfileServers[$this->gotoProfileServer])){
248 }else{
249 $c = $this->gotoProfileServers[$this->gotoProfileServer];
250 if(!preg_match("/r/",$c['ACL'])){
252 /* We are not allowed to read to currently selected server.
253 But to ensure that the selection will be kept after saving the account, we
254 override the current ACL tag.
255 */
256 $this->gotoProfileServers[$this->gotoProfileServer]['ACL'] .= "r";
257 }
258 }
259 }
260 $this->update_kiosk_profiles();
261 }
264 function update_kiosk_profiles()
265 {
266 $tmp1 = array("none" => array(_("disabled")));
267 $tmp2 = array("none" => _("disabled"));
268 $tmp3 = array();
269 $ldap = $this->config->get_ldap_link();
270 $ldap->cd($this->config->current['BASE']);
271 $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
272 $cnt = 0;
273 while($attrs = $ldap->fetch()){
274 for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
275 $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
276 $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
277 $tmp1[$attrs['cn'][0]][] = $name;
278 $tmp3[$attrs['cn'][0]][$name] = $attrs['gotoKioskProfile'][$i];
279 }
280 $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
281 $cnt ++;
282 }
284 if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
285 $this->kiosk_enabled = TRUE;
286 }
288 $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
289 $this->gotoKioskProfiles['SERVERS'] = $tmp2;
290 $this->gotoKioskProfiles['MAP'] = $tmp3;
292 $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
293 $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
295 $error = false;
296 if(!isset($this->gotoKioskProfiles['SERVERS'][$this->gotoKioskProfile_Server])){
297 $error = true;
298 }elseif(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
299 $error = true;
300 }
301 if($error && !empty($this->gotoKioskProfile)){
302 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);
303 $this->gotoKioskProfile_Server ="none";
304 $this->gotoKioskProfile_Profile="";
305 }elseif(empty($this->gotoKioskProfile)){
306 $this->gotoKioskProfile_Server ="none";
307 $this->gotoKioskProfile_Profile="";
308 }
309 }
312 /* Detect type of edited object (user|group)*/
313 function detect_grouptype()
314 {
315 if((!isset($this->parent))&&(!$this->is_account)){
316 $this->is_group = false;
317 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
318 $this->is_group = true;
319 }else{
320 $this->is_group = false;
321 }
322 }
325 function execute()
326 {
328 /* Call parent execute */
329 plugin::execute();
330 /* Log view */
331 if($this->is_account && !$this->view_logged){
332 $this->view_logged = TRUE;
333 if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
334 new log("view","users/".get_class($this),$this->dn);
335 }else{
336 new log("view","groups/".get_class($this),$this->dn);
337 }
338 }
340 /* Are we editing from MyAccount and not editing a user */
341 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
343 /* Check profile server */
344 if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
346 if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
349 if(count($this->gotoProfileServers)){
351 /* Get First Profile */
352 $new = key($this->gotoProfileServers);
354 /* Another profile server found */
355 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
356 }else{
358 /* No other profile servers found */
359 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
360 $this->gotoProfileServer = "none";
361 }
362 }
363 }
365 $this->detect_grouptype();
367 /* Fill templating stuff */
368 $smarty= get_smarty();
369 $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
370 $display= "";
372 $smarty->assign("is_group",$this->is_group);
374 /* Prepare all variables for smarty */
375 foreach($this->attributes as $s_attr){
376 /* Set value*/
377 $smarty->assign($s_attr,$this->$s_attr);
379 /* Set checkbox state*/
380 if(empty($this->$s_attr)){
381 $smarty->assign($s_attr."CHK","");
382 }else{
383 $smarty->assign($s_attr."CHK"," checked ");
384 }
386 /* Prepare ACL settings*/
387 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
388 }
390 /* Is accout enabled | are we editing from usermenu or admin menu
391 All these tab management is done here
392 */
395 /* Working from Usermenu an the Account is currently disbled
396 * this->parent : is only set if we are working in a list of tabs
397 * is_account : is only true if the needed objectClass is given
398 */
399 if((!isset($this->parent))&&(!$this->is_account)){
400 /* We are currently editing this tab from usermenu, but this account is not enabled */
401 $smarty->assign("is_account",$this->is_account);
402 /* Load template */
403 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
404 /* Avoid the "You are currently editing ...." message when you leave this tab */
405 $display .= back_to_main();
406 /* Display our message to the user */
407 return $display;
410 /* We are currently editing from group tabs, because
411 * $this->parent is set
412 * posixAccount is not set, so we are not in usertabs.
413 */
414 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
415 $smarty->assign("is_account","true");
416 $this->uid = $this->cn;
417 $this->attrs['uid'] = $this->cn;
419 /* Change state if needed */
420 if (isset($_POST['modify_state'])){
421 if(($this->acl_is_createable() && !$this->is_account) ||
422 ($this->acl_is_removeable() && $this->is_account)){
423 $this->is_account= !$this->is_account;
424 }
425 }
426 /* Group Dialog with enabled environment options */
427 if ($this->is_account){
428 $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
429 msgPool::featuresEnabled(_("Environment")));
430 } else {
432 /* Environment is disabled
433 If theres is no posixAccount enabled, you won't be able to enable
434 environment extensions
435 */
436 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
437 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
438 msgPool::featuresDisabled(_("Environment")));
439 return $display;
440 }elseif((isset($this->parent->by_object['ogroup']))){
441 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
442 msgPool::featuresDisabled(_("Environment")));
443 return $display;
444 }else{
445 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
446 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
447 return $display;
448 }
449 }
450 }else{
451 /* Editing from Usermenu
452 * Tell smarty that this accoutn is enabled
453 */
454 $smarty->assign("is_account","true");
456 /* Change state if needed */
457 if (isset($_POST['modify_state'])){
458 if(($this->acl_is_createable() && !$this->is_account) ||
459 ($this->acl_is_removeable() && $this->is_account)){
460 $this->is_account= !$this->is_account;
461 }
462 }
464 if(isset($this->parent)){
466 // 3. Account enabled . Editing from adminmenu
467 if ($this->is_account){
468 $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
469 msgPool::featuresEnabled(_("Environment")));
470 } else {
472 if($this->parent->by_object['posixAccount']->is_account==true){
473 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
474 msgPool::featuresDisabled(_("Environment")));
475 return $display;
476 }else{
477 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
478 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
479 return $display;
480 }
481 }
482 }
483 }
485 /* Reset header toggle */
486 if($this->multiple_support_active){
487 $display = "";
488 }
490 /* Account is Account : is_accounbt=true.
491 * Else we won't reach this.
492 */
494 /* Prepare all variables for smarty */
495 foreach($this->attributes as $s_attr){
496 /* Set value*/
497 $smarty->assign($s_attr,$this->$s_attr);
499 /* Set checkbox state*/
500 if(empty($this->$s_attr)){
501 $smarty->assign($s_attr."CHK","");
502 }else{
503 $smarty->assign($s_attr."CHK"," checked ");
504 }
506 /* Prepare ACL settings*/
507 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
508 }
510 foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
511 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
512 }
514 if($WriteOnly) {
515 $smarty->assign("gotoPrinterACL","r");
516 }else{
517 $smarty->assign("gotoPrinterACL","rw");
518 }
521 $smarty->assign("useProfile",$this->useProfile);
522 if(empty($this->useProfile) && !$this->multiple_support_active){
523 $smarty->assign("useProfileCHK","");
524 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
525 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
526 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
527 }else{
528 $smarty->assign("useProfileCHK"," checked ");
529 }
531 $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
532 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
534 /* HANDLE Profile Settings here
535 * Assign available Quota and resolution settings
536 * Get all available profile server
537 * Get cache checkbox
538 * Assign this all to Smarty
539 */
541 if(empty($this->gotoProfileFlagL)){
542 $smarty->assign("gotoProfileFlagLCHK"," ");
543 }else{
544 $smarty->assign("gotoProfileFlagLCHK"," checked ");
545 }
547 if(empty($this->gotoProfileFlagC)){
548 $smarty->assign("gotoProfileFlagCCHK"," ");
549 }else{
550 $smarty->assign("gotoProfileFlagCCHK"," checked ");
551 }
554 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
555 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
557 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
558 if(!is_array($this->gotoProfileServers)){
559 $this->gotoProfileServers =array();
560 }
562 /* Handle kiosk profiles*/
563 $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
564 $smarty->assign("kiosk_server" , $this->gotoKioskProfile_Server);
565 $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
566 $smarty->assign("kiosk_profile" , $this->gotoKioskProfile_Profile);
569 /* Logonscript Management
570 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
571 * Perform add Delete edit Posts
572 */
574 /* Dialog Save */
575 if(isset($_POST['LogonSave'])){
577 if(!$this->acl_is_writeable("gotoLogonScript")){
578 msg_dialog::display(_("Permission error"), msgPool::permModify(_("Logon scripts")), ERROR_DIALOG);
579 unset($this->dialog);
580 $this->dialog=FALSE;
581 $this->is_dialog=false;
582 }else{
583 $this->dialog->save_object();
584 if(count($this->dialog->check())!=0){
585 foreach($this->dialog->check() as $msg){
586 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
587 }
588 }else{
589 $tmp = $this->dialog->save();
590 unset($this->dialog);
591 $this->dialog=FALSE;
592 $this->is_dialog=false;
594 if($this->multiple_support_active){
595 $tmp['UsedByAllUsers'] = TRUE;
596 }
597 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
598 }
599 }
600 }
603 /* Dialog Quit without saving */
604 if(isset($_POST['LogonCancel'])){
605 $this->is_dialog= false;
606 unset($this->dialog);
607 $this->dialog= FALSE;
608 }
610 /* Check Edit Del New Posts for a selected LogonScript */
611 if($this->acl_is_writeable("gotoLogonScript") &&
612 (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
614 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
615 * In this case we create a new Logon Script.
616 */
617 if(isset($_POST['gotoLogonScriptNew'])){
618 $this->is_dialog = true;
619 $this->dialog = new logonManagementDialog($this->config,$this->dn);
620 }
622 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
623 * We only can delete if there is an entry selected.
624 */
625 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
626 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
627 }
629 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
630 * There must be an entry selected to perform edit request.
631 */
632 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
633 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
634 $this->is_dialog = true;
635 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
636 }
637 }
639 /* Append List to smarty*/
640 if($this->multiple_support_active){
641 $smarty->assign("gotoLogonScripts", $this->gotoLogonScripts);
642 $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
643 }else{
644 $ls = $this->printOutLogonScripts();
645 $smarty->assign("gotoLogonScripts", $ls);
646 $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
647 $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
648 }
650 /* In this section server shares will be defined
651 * A user can select one of the given shares and a mount point
652 * and attach this combination to his setup.
653 */
655 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
656 if(!is_array($this->gotoShareSelections)){
657 $this->gotoShareSelections = array();
658 }
659 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
661 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
662 * This entry will be, a combination of mountPoint and sharedefinitions
663 */
664 if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
666 /* We assign a share to this user, if we don't know where to mount the share */
667 if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
668 msg_dialog::display(_("Error"), msgPool::invalid(_("Share")), ERROR_DIALOG);
669 }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
670 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
671 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
672 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point"), "/[^\s]/"), ERROR_DIALOG);
673 }elseif(!(
674 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
675 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
676 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
677 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
678 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
679 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
680 preg_match("/^%/",$_POST['gotoShareMountPoint'])
681 )
682 ){
683 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
684 }else{
685 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
686 $s_mount = $_POST['gotoShareMountPoint'];
687 $s_user = $_POST['ShareUser'];
688 /* Preparing the new assignment */
689 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
690 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
691 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
692 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
694 if($this->multiple_support_active){
695 $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
696 }
697 }
698 }
700 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
701 * If there is no defined share selected, we will abort the deletion without any message
702 */
703 $once = true;
704 if($this->acl_is_writeable("gotoShare")){
705 foreach($_POST as $name => $value){
706 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
707 $once = false;
708 $key = preg_replace("/^gotoShareDel_/","",$name);
709 $key = preg_replace("/_+[xy]$/","",$key);
710 $key = base64_decode($key);
711 if(isset($this->gotoShares[$key])) {
712 unset($this->gotoShares[$key]);
713 }
715 /* Remove corresponding password entry, too. This is a workaround
716 to get rid of old-style entries. */
717 $key= preg_replace("/\|/", "|!", $key);
718 if(isset($this->gotoShares[$key])) {
719 unset($this->gotoShares[$key]);
720 }
721 }
722 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
723 $once = false;
724 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
725 $key = preg_replace("/_+[xy]$/","",$key);
726 $key = base64_decode($key);
727 $this->gotoShares[$key]['PwdHash'] = "";
728 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
729 unset($this->gotoShares[$key]);
730 }
731 }
732 }
733 }
734 $divlistShares = new divSelectBox("gotoShares");
735 $divlistShares->SetHeight(100);
738 $tmp = array();
739 if($this->acl_is_readable("gotoShares")){
740 $tmp = $this->printOutAssignedShares();
741 }
744 foreach($tmp as $key => $value){
745 $img = "";
747 /* Skip apssword only entries */
748 if( empty($this->gotoShares[$key]['server']) &&
749 empty($this->gotoShares[$key]['name']) &&
750 empty($this->gotoShares[$key]['mountPoint']) &&
751 empty($this->gotoShares[$key]['Username'])){
752 continue;
753 }
755 $color = "";
756 if($this->multiple_support_active){
757 if($this->gotoShares[$key]['UsedByAllUsers']){
758 $value .= " (<b>"._("Used by all users")."</b>)";
759 }else{
760 $color = "color: #999999;";
761 $value .= " (<b>"._("Used by some users")."</b>)";
762 }
763 }
765 /* Check if entry starts with an ! */
766 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
768 /* If we are currently editing groups environment, skip those ! entries */
769 if($this->is_group) continue;
771 /* Create pwd reset images */
772 if($this->gotoShares[$key]['PwdHash'] != ""){
773 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
774 title='"._("Reset password hash")."'>";
775 }
776 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
777 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
778 }else{
780 /* Create pwd reset img && delete image */
781 if($this->gotoShares[$key]['PwdHash'] != ""){
782 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
783 title='"._("Reset password hash")."'>";
784 $img.= " ";
785 }
786 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/lists/trash.png' alt='".msgPool::delButton()."'
787 title='"._("Delete share entry")."'>";
788 $field1 = array("string" => $value , "attach" => "style='".$color."'");
789 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
790 }
791 $divlistShares->AddEntry(array($field1,$field2));
792 }
793 $smarty->assign("divlistShares",$divlistShares->DrawList());
795 /* Hotplug devices will be handled here
796 * There are 3 possible methods for this feature
797 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
798 * Delete will erase an entry, the entry must be selcted in the ListBox first
799 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
800 */
802 /* We have to delete the selected hotplug from the list*/
803 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
804 if($this->acl_is_writeable("gotoHotplugDevice")){
805 foreach($_POST['gotoHotplugDevice_post'] as $name){
806 unset($this->gotoHotplugDevices[$name]);
807 }
808 }
809 }
811 /* There are already defined hotplugs from other users we could use */
812 if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
813 $tmp =array();
814 foreach($this->gotoHotplugDevices as $plugs){
815 $tmp[] = $plugs['name'];
816 }
817 $this->dialog = new hotplugDialog($this->config,$tmp);
818 $this->is_dialog = true;
819 }
821 /* Dialog Aborted */
822 if(isset($_POST['HotPlugCancel'])){
823 unset($this->dialog);
824 $this->dialog= FALSE;
825 $this->is_dialog = false;
826 }
828 /* Dialod saved */
829 if(isset($_POST['HotPlugSave'])){
831 $this->dialog->save_object();
832 if(count($this->dialog->check())!=0){
833 foreach($this->dialog->check() as $msg){
834 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
835 }
836 }else{
837 $this->dialog->save_object();
838 $a_tmp = $this->dialog->save();
840 if(is_array($a_tmp)){
841 foreach($a_tmp as $name => $hotplug){
842 if($this->multiple_support_active){
843 $hotplug['UsedByAllUsers'] = TRUE;
844 }
845 $this->gotoHotplugDevices[$name]= $hotplug;
846 }
847 }
848 unset($this->dialog);
849 $this->dialog= FALSE;
850 $this->is_dialog = false;
851 }
852 }
854 if($this->multiple_support_active){
855 $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
856 }else{
857 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
858 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
859 }
861 /* Printer Assignment will managed below
862 * A printer can be assigned in two different ways and two different types
863 * There are 2 types of users assigned to a printer : user and admin
864 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
865 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
866 */
868 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
869 if(isset($_POST['gotoPrinterAdd'])){
871 $this->is_dialog=true;
872 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
873 }
875 if(isset($_POST['PrinterCancel'])){
876 $this->is_dialog=false;
877 unset($this->dialog);
878 $this->dialog=FALSE;
879 }
881 if(isset($_POST['PrinterSave'])){
882 if(count($this->dialog->check())!=0){
883 $tmp = $this->dialog->check();
884 foreach($tmp as $msg){
885 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
886 }
887 }else{
888 $this->dialog->save_object();
889 $tmp = $this->dialog->save();
890 $tmp2= $this->dialog->getPrinter(true);
892 foreach($tmp as $pname){
893 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
894 $printerObj->set_acl_base($tmp2[$pname]['dn']);
896 $type = false;
898 if($this->is_group){
899 if($this->dn == "new"){
900 $type = "AddGroup";
901 }elseif(isset($this->NewDeletedPrinters[$pname])){
902 $type = "AddGroup";
903 }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
904 $type = "AddGroup";
905 }
906 }else{
907 if($this->multiple_support_active){
908 $type = "AddUser";
909 }elseif(isset($this->NewDeletedPrinters[$pname])){
910 $type = "AddUser";
911 }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
912 $type = "AddUser";
913 }
914 }
916 if($type){
917 $this->gotoPrinter[$pname]=$tmp2[$pname];
918 $this->gotoPrinter[$pname]['mode']="user";
919 $this->add_del_printer_member_was_called = true;
921 $this->NewAddedPrinters[$pname] = $pname;
922 if(isset($this->NewDeletedPrinters[$pname])){
923 unset($this->NewDeletedPrinters[$pname]);
924 }
925 }
926 }
928 $this->is_dialog=false;
929 unset($this->dialog);
930 $this->dialog =FALSE;
931 }
932 }
934 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
935 $printer = $_POST['gotoPrinterSel'];
936 foreach($printer as $pname){
938 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
939 $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
941 $type = false;
942 if($this->is_group){
943 if(isset($this->NewAddedPrinters[$pname])){
944 $type = "Group";
945 }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
946 $type = "Group";
947 }
948 }else{
949 if(isset($this->NewAddedPrinters[$pname])){
950 $type = "User";
951 }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
952 $type = "User";
953 }
954 }
955 if($type){
956 $this->add_del_printer_member_was_called = true;
957 unset($this->gotoPrinter[$pname]);
959 $this->NewDeletedPrinters[$pname] = $pname;
960 if(isset($this->NewAddedPrinters[$pname])){
961 UNSET($this->NewAddedPrinters[$pname]);
962 }
963 }
964 }
965 }
967 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
968 $printers = $_POST['gotoPrinterSel'];
969 $this->add_del_printer_member_was_called = true;
970 foreach($printers as $printer){
971 if($this->gotoPrinter[$printer]['mode']=="user"){
972 $this->gotoPrinter[$printer]['mode']="admin";
973 }else{
974 $this->gotoPrinter[$printer]['mode']="user";
975 }
976 }
977 }
979 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
980 if($this->is_group){
981 msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
982 }else{
983 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
984 $this->gosaDefaultPrinter= "";
985 } else {
986 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
987 }
988 }
989 }
991 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
992 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
994 /* General behavior */
995 if(is_object($this->dialog)){
996 $this->dialog->save_object();
997 $disp =$this->dialog->execute();
998 return($disp);
999 }
1001 /* Assign used attributes for multiple edit */
1002 foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
1003 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
1004 $ubox ="use_".$box;
1005 if(in_array($box,$this->multi_boxes)){
1006 $smarty->assign($ubox,TRUE);
1007 }else{
1008 $smarty->assign($ubox,FALSE);
1009 }
1010 }
1012 /* Als smarty vars are set. Get smarty template and generate output */
1013 $smarty->assign("multiple_support",$this->multiple_support_active);
1014 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
1015 return($display);
1016 }
1018 function remove_from_parent()
1019 {
1020 /* only if it was an account*/
1021 if (!$this->initially_was_account){
1022 return;
1023 }
1025 /* include global link_info */
1026 $ldap= $this->config->get_ldap_link();
1028 /* Remove and write to LDAP */
1029 plugin::remove_from_parent();
1031 /* Don't save our template variables */
1032 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1034 /* Skip all these attributes */
1035 foreach($skip as $del){
1036 unset($this->attrs[$del]);
1037 }
1039 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1041 $ldap->cd($this->dn);
1042 $this->cleanup();
1043 $ldap->modify ($this->attrs);
1045 if($this->is_group){
1046 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1047 }else{
1048 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1049 }
1051 if (!$ldap->success()){
1052 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1053 }
1055 /* Optionally execute a command after we're done */
1056 $this->handle_post_events("remove",array("uid" => $this->uid));
1057 }
1060 /* Save data to object */
1061 function save_object()
1062 {
1063 /* Get all Posted vars
1064 * Setup checkboxes
1065 */
1066 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
1067 if(isset($_POST['iamposted'])){
1069 $PACL = $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1071 if(isset($_POST['kiosk_server'])){
1072 $tmp = $_POST['kiosk_server'];
1073 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1074 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1075 }
1076 }
1077 if(isset($_POST['kiosk_profile'])){
1078 $tmp = $_POST['kiosk_profile'];
1079 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1080 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1081 }
1082 }
1084 if(preg_match("/w/",$PACL)){
1085 if(isset($_POST['useProfile'])){
1086 $this->useProfile = true;
1087 }else{
1088 $this->useProfile = false;
1089 }
1090 }
1092 if($this->acl_is_writeable("gotoProfileFlagC")){
1093 if(isset($_POST['gotoProfileFlagC'])){
1094 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1095 }else{
1096 $this->gotoProfileFlagC = false;
1097 }
1098 }
1100 if($this->acl_is_writeable("gotoProfileFlagL")){
1101 if(isset($_POST['gotoProfileFlagL'])){
1102 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1103 }else{
1104 $this->gotoProfileFlagL = false;
1105 }
1106 }
1108 plugin::save_object();
1109 foreach($this->attributes as $s_attr){
1110 if((!isset($_POST[$s_attr])) ||
1111 in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1112 if(!$this->acl_is_writeable($s_attr)){
1113 continue;
1114 }else{
1115 if(isset($_POST[$s_attr])){
1116 $this->$s_attr = $_POST[$s_attr];
1117 }else{
1118 $this->$s_attr = false;
1119 }
1120 }
1121 }
1122 }
1123 }
1126 /* Check supplied data */
1127 function check()
1128 {
1129 /* Call common method to give check the hook */
1130 $message= plugin::check();
1132 $this->detect_grouptype();
1134 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1135 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1136 }
1137 if(!isset($this->attrs['objectClass'])){
1138 $this->attrs['objectClass']=array();
1139 }
1140 if(!$this->is_group){
1141 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1142 $message[]= msgPool::featuresDisabled(_("environment"),_("POSIX"));
1143 }
1144 }
1145 return ($message);
1146 }
1149 /* Save to LDAP */
1150 function save()
1151 {
1152 /* If group was renamed, all printer settings get lost
1153 */
1154 /* only save changed variables ....*/
1155 if ($this->gotoKioskProfile_Server != "none"){
1156 $method = $this->gotoKioskProfiles['MAP'][$this->gotoKioskProfile_Server][$this->gotoKioskProfile_Profile];
1157 $this->gotoKioskProfile= $method;
1158 }else{
1159 $this->gotoKioskProfile= array();
1160 }
1162 plugin::save();
1163 $ldap= $this->config->get_ldap_link();
1165 $realyUsedAttrs= array();
1167 /* Save already used objectClasses */
1168 $ocs = $this->attrs['objectClass'];
1169 unset($ocs['count']);
1170 $this->attrs = array();
1171 $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1173 /* 1. Search all printers that have our uid/cn as member
1174 * 2. Delete this uid/cn from every single entry and save it again.
1175 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1176 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
1177 */
1179 $this->detect_grouptype();
1181 if($this->add_del_printer_member_was_called){
1183 $types = array( "gotoUserPrinter" => "AddUser",
1184 "gotoGroupPrinter" => "AddGroup",
1185 "gotoUserAdminPrinter" => "AddAdminUser",
1186 "gotoGroupAdminPrinter" => "AddAdminGroup");
1188 if($this->is_group){
1189 $s_suffix = "Group";
1190 $useVar = "cn";
1191 }else{
1192 $useVar = "uid";
1193 $s_suffix = "User";
1194 }
1196 /* Remove old entries */
1197 $ldap->cd($this->config->current['BASE']);;
1198 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1199 while($attr = $ldap->fetch()){
1200 $printerObj = NULL;
1201 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1202 $printerObj->set_acl_base($attr['dn']);
1203 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1204 $printerObj->by_object['printgeneric']->save();
1205 }
1207 $ldap->cd($this->config->current['BASE']);;
1208 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1209 while($attr = $ldap->fetch()){
1210 $printerObj = NULL;
1211 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1212 $printerObj->set_acl_base($attr['dn']);
1213 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1214 $printerObj->by_object['printgeneric']->save();
1215 }
1217 foreach($this->gotoPrinter as $printer){
1218 $printerObj = NULL;
1219 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1220 $printerObj->set_acl_base($printer['dn']);
1223 if($printer['mode'] == "admin") {
1224 $attribute = "goto".$s_suffix."AdminPrinter";
1225 }else{
1226 $attribute = "goto".$s_suffix."Printer";
1227 }
1229 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1230 $printerObj->by_object['printgeneric']->save();
1231 }
1232 }
1234 /* Prepare HotPlug devices */
1235 $this->attrs['gotoHotplugDeviceDN'] = array();
1236 foreach($this->gotoHotplugDevices as $name => $device){
1237 $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1238 }
1240 /* Prepare LogonScripts */
1241 $this->attrs['gotoLogonScript'] = array();
1242 foreach($this->gotoLogonScripts as $name => $script){
1243 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1244 $script['LogonOverload'].$script['LogonLast']."|".
1245 $script['LogonPriority']."|".
1246 base64_encode($script['LogonData'])."|".
1247 $script['LogonDescription'];
1248 }
1250 /* Prepare Shares */
1251 $this->attrs['gotoShare']=array();
1252 foreach($this->gotoShares as $name => $share){
1253 $mntp= $share['mountPoint'];
1254 if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1255 $mntp= base64_encode($mntp);
1256 }
1257 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1258 }
1261 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1262 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1264 foreach($saveThis as $tosave){
1265 if(!empty($this->$tosave)){
1266 $this->attrs[$tosave]=$this->$tosave;
1267 }else{
1268 $this->attrs[$tosave]=array();
1269 }
1270 }
1272 /* Prepare Flags */
1273 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1274 if(empty($this->attrs['gotoProfileFlags'][0])){
1275 $this->attrs['gotoProfileFlags']=array();
1276 }
1278 if($this->useProfile == false){
1279 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1280 $this->attrs['gotoProfileServer']= array();
1281 }
1283 $ldap->cat ($this->dn, array('dn'));
1284 if ($ldap->fetch()){
1285 $mode= "modify";
1286 } else {
1287 $mode= "add";
1288 $ldap->cd($this->config->current['BASE']);
1289 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1290 }
1292 $ldap->cd($this->dn);
1293 $this->cleanup();
1294 $ldap->$mode($this->attrs);
1296 $cat = "users";
1297 if($this->is_group){
1298 $cat = "groups";
1299 }
1301 /* Log last action */
1302 if($this->initially_was_account){
1303 new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1304 }else{
1305 new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1306 }
1308 if (!$ldap->success()){
1309 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1310 }
1311 $this->handle_post_events($mode,array("uid"=>$this->uid));
1312 }
1314 /* Generate ListBox frindly output for the defined shares
1315 * Possibly Add or remove an attribute here,
1316 */
1317 function printOutAssignedShares()
1318 {
1319 $a_return = array();
1320 if(is_array($this->gotoShares)){
1321 foreach($this->gotoShares as $share){
1322 if(preg_match("/^!/",$share['server'])){
1323 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1324 }else{
1325 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1326 }
1327 }
1328 natcasesort($a_return);
1329 }
1330 return($a_return);
1331 }
1333 /* Generate ListBox frindly output for the definedhotplugs
1334 * Possibly Add or remove an attribute here,
1335 */
1336 function printOutHotPlugDevices()
1337 {
1338 $a_return= array();
1339 if(is_array($this->gotoHotplugDevices)){
1340 foreach($this->gotoHotplugDevices as $key=>$device){
1341 $a_return[$key] = $device['name']." - ".$device['id'];
1342 }
1343 }
1344 return($a_return);
1345 }
1347 /* Generates ListBox frienly output of used printer devices
1348 * Append ' - admin' if printer is used in admin mode
1349 */
1350 function printOutPrinterDevices()
1351 {
1352 $a_return = array();
1354 if($this->acl_is_readable("gotoPrinter")){
1356 if(is_array($this->gotoPrinter)){
1357 foreach($this->gotoPrinter as $printer){
1358 if($printer['mode'] == "admin"){
1359 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1360 }else{
1361 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1362 }
1363 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1364 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1365 }
1366 }
1367 }
1368 }
1369 return($a_return);
1370 }
1373 function PrepareForCopyPaste($source)
1374 {
1375 plugin::PrepareForCopyPaste($source);
1377 $class= get_class($this);
1378 $o_source = new $class($this->config,$source['dn']);
1379 foreach($this->CopyPasteVars as $attr){
1380 $this->$attr = $o_source->$attr;
1381 }
1382 }
1385 function saveCopyDialog()
1386 {
1387 if(isset($_POST['cn'])){
1388 $this->cn = $_POST['cn'];
1389 $this->uid = $_POST['cn'];
1390 }
1391 }
1394 /* Generates ListBox frienly output of used logonscripts
1395 */
1396 function printOutLogonScripts()
1397 {
1398 $a_return = array();
1399 if(is_array($this->gotoLogonScripts)){
1400 foreach($this->gotoLogonScripts as $script){
1401 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1402 }
1403 }
1404 return($a_return);
1405 }
1408 function multiple_execute()
1409 {
1410 /* Reset header toggle */
1411 $this->is_account = TRUE;
1412 return($this->execute());
1413 }
1416 /* Initialize plugin with given atribute arrays
1417 */
1418 function init_multiple_support($attrs,$all)
1419 {
1420 plugin::init_multiple_support($attrs,$all);
1422 /* Prepare Shares */
1423 if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1424 unset($this->multi_attrs_all['gotoShare']['count']);
1425 foreach($this->multi_attrs_all['gotoShare'] as $share){
1426 $tmp = $tmp2 = array();
1427 $tmp = split("\|",$share);
1428 $tmp2['server'] =$tmp[0];
1429 $tmp2['name'] =$tmp[1];
1431 /* Decode base64 if needed */
1432 if (!preg_match('%/%', $tmp[2])){
1433 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1434 } else {
1435 $tmp2['mountPoint'] =$tmp[2];
1436 }
1438 if(isset($tmp[3])){
1439 $tmp2['PwdHash'] =$tmp[3];
1440 }else{
1441 $tmp2['PwdHash'] ="";
1442 }
1443 if(isset($tmp[4])){
1444 $tmp2['Username'] =$tmp[4];
1445 }else{
1446 $tmp2['Username'] ="";
1447 }
1448 $tmp2['UsedByAllUsers'] = FALSE;
1449 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1450 }
1451 }
1453 /* Prepare Shares */
1454 if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1455 unset($this->multi_attrs['gotoShare']['count']);
1456 foreach($this->multi_attrs['gotoShare'] as $share){
1457 $tmp = $tmp2 = array();
1458 $tmp = split("\|",$share);
1459 $tmp2['server'] =$tmp[0];
1460 $tmp2['name'] =$tmp[1];
1462 /* Decode base64 if needed */
1463 if (!preg_match('%/%', $tmp[2])){
1464 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1465 } else {
1466 $tmp2['mountPoint'] =$tmp[2];
1467 }
1469 if(isset($tmp[3])){
1470 $tmp2['PwdHash'] =$tmp[3];
1471 }else{
1472 $tmp2['PwdHash'] ="";
1473 }
1474 if(isset($tmp[4])){
1475 $tmp2['Username'] =$tmp[4];
1476 }else{
1477 $tmp2['Username'] ="";
1478 }
1479 $tmp2['UsedByAllUsers'] = TRUE;
1480 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1481 }
1482 }
1485 /* prepare LogonScripts */
1486 if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1487 unset($this->multi_attrs_all['gotoLogonScript']['count']);
1488 foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1489 $tmp = $tmp2 = array();
1490 $tmp = split("\|",$device);
1491 $tmp2['LogonName'] = $tmp[0];
1492 $tmp2['LogonPriority'] = $tmp[2];
1493 if(preg_match("/O/i",$tmp[1])){
1494 $tmp2['LogonOverload'] = "O";
1495 }else{
1496 $tmp2['LogonOverload'] = "";
1497 }
1498 if(preg_match("/L/i",$tmp[1])){
1499 $tmp2['LogonLast'] = "L";
1500 }else{
1501 $tmp2['LogonLast'] = "";
1502 }
1503 $tmp2['LogonData'] = base64_decode($tmp[3]);
1504 $tmp2['LogonDescription'] = $tmp[4];
1505 $tmp2['UsedByAllUsers'] = FALSE;
1506 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1507 }
1508 }
1510 /* prepare LogonScripts */
1511 if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1512 unset($this->multi_attrs['gotoLogonScript']['count']);
1513 foreach($this->multi_attrs['gotoLogonScript'] as $device){
1514 $tmp = $tmp2 = array();
1515 $tmp = split("\|",$device);
1516 $tmp2['LogonName'] = $tmp[0];
1517 $tmp2['LogonPriority'] = $tmp[2];
1518 if(preg_match("/O/i",$tmp[1])){
1519 $tmp2['LogonOverload'] = "O";
1520 }else{
1521 $tmp2['LogonOverload'] = "";
1522 }
1523 if(preg_match("/L/i",$tmp[1])){
1524 $tmp2['LogonLast'] = "L";
1525 }else{
1526 $tmp2['LogonLast'] = "";
1527 }
1528 $tmp2['LogonData'] = base64_decode($tmp[3]);
1529 $tmp2['LogonDescription'] = $tmp[4];
1530 $tmp2['UsedByAllUsers'] = TRUE;
1531 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1532 }
1533 }
1535 /* Prepare hotplugs */
1536 if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1537 $ldap = $this->config->get_ldap_link();
1538 $ldap->cd($this->config->current['BASE']);
1539 for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1540 $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1541 if($ldap->count()){
1542 $multi_attrs_all = $ldap->fetch();
1544 if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1545 $tmp = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1546 $tmp2 = array();
1547 $tmp2['name'] = $multi_attrs_all['cn'][0];
1548 $tmp2['description'] = $tmp[0];
1549 $tmp2['id'] = $tmp[1];
1550 $tmp2['produkt'] = $tmp[2];
1551 $tmp2['vendor'] = $tmp[3];
1552 $tmp2['dn'] = $multi_attrs_all['dn'];
1553 $tmp2['UsedByAllUsers'] = FALSE;
1554 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1555 }
1556 }
1557 }
1558 }
1560 /* Prepare hotplugs */
1561 if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1562 $ldap = $this->config->get_ldap_link();
1563 $ldap->cd($this->config->current['BASE']);
1564 for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1565 $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1566 if($ldap->count()){
1567 $multi_attrs = $ldap->fetch();
1569 if(isset($multi_attrs['gotoHotplugDevice'][0])){
1570 $tmp = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1571 $tmp2 = array();
1572 $tmp2['name'] = $multi_attrs['cn'][0];
1573 $tmp2['description'] = $tmp[0];
1574 $tmp2['id'] = $tmp[1];
1575 $tmp2['produkt'] = $tmp[2];
1576 $tmp2['vendor'] = $tmp[3];
1577 $tmp2['dn'] = $multi_attrs['dn'];
1578 $tmp2['UsedByAllUsers'] = TRUE;
1579 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1580 }
1581 }
1582 }
1583 }
1584 $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1585 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1586 $chr = $this->gotoProfileFlags[$i];
1587 $name = "gotoProfileFlag".$chr;
1588 $this->$name=$chr;
1589 }
1590 $this->update_kiosk_profiles();
1591 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1593 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1594 $this->useProfile = true;
1595 }else{
1596 $this->useProfile = false;
1597 }
1599 }
1602 function set_multi_edit_values($attrs)
1603 {
1604 $shares = $this->gotoShares;
1605 $scripts= $this->gotoLogonScripts;
1606 $plugs= $this->gotoHotplugDevices;
1607 plugin::set_multi_edit_values($attrs);
1609 $this->gotoShares = $shares;
1610 $this->gotoLogonScripts = $scripts;
1611 $this->gotoHotplugDevices = $plugs;
1613 foreach($attrs['gotoShares'] as $name => $share){
1614 if($share['UsedByAllUsers'] == TRUE){
1615 $this->gotoShares[$name] = $share;
1616 }
1617 }
1618 foreach($this->gotoShares as $name => $share){
1619 if(!isset($attrs['gotoShares'][$name])){
1620 unset($this->gotoShares[$name]);
1621 }
1622 }
1623 foreach($attrs['gotoLogonScripts'] as $name => $script){
1624 if($script['UsedByAllUsers'] == TRUE){
1625 $this->gotoLogonScripts[$name] = $script;
1626 }
1627 }
1628 foreach($this->gotoLogonScripts as $name => $script){
1629 if(!isset($attrs['gotoLogonScripts'][$name])){
1630 unset($this->gotoLogonScripts[$name]);
1631 }
1632 }
1633 $tmp = array();
1634 foreach($this->gotoHotplugDevices as $entry){
1635 $tmp[$entry['dn']] = $entry;
1636 }
1638 foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1639 if($plug['UsedByAllUsers'] == TRUE){
1640 $tmp[$plug['dn']] = $plug;
1641 }
1642 }
1643 foreach($tmp as $name => $plug){
1644 $found = false;
1645 foreach($attrs['gotoHotplugDevices'] as $test){
1646 if($test['dn'] == $name){
1647 $found = true;
1648 }
1649 }
1650 if(!$found){
1651 unset($tmp[$name]);
1652 }
1653 }
1654 }
1657 /* Return selected values for multiple edit */
1658 function get_multi_edit_values()
1659 {
1660 $ret = plugin::get_multi_edit_values();
1661 $ret['gotoShares'] = $this->gotoShares;
1662 $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1663 $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1665 if(in_array("gotoPrinter",$this->multi_boxes)){
1666 $ret['gotoPrinter'] = $this->gotoPrinter;
1667 $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1668 $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1670 /* Force printer reset */
1671 $ret['add_del_printer_member_was_called'] = TRUE;
1672 }
1674 if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1675 $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1676 }
1678 if(in_array("useProfile",$this->multi_boxes)){
1679 $ret['useProfile']=$this->useProfile;
1680 if(in_array("gotoProfileServer",$this->multi_boxes)){
1681 $ret['gotoProfileServer']=$this->gotoProfileServer;
1682 }
1683 if(in_array("gotoProfileQuota",$this->multi_boxes)){
1684 $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1685 }
1686 if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1687 $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1688 }
1689 }
1690 if(in_array("gotoXResolution",$this->multi_boxes)){
1691 $ret['gotoXResolution'] = $this->gotoXResolution;
1692 }
1693 if(in_array("kiosk_server",$this->multi_boxes)){
1694 $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1695 $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1696 }
1697 return($ret);
1698 }
1701 function multiple_check()
1702 {
1703 $message = plugin::multiple_check();
1704 $this->detect_grouptype();
1706 if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
1707 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1708 }
1709 return($message);
1710 }
1713 function multiple_save_object()
1714 {
1715 if(isset($_POST['environment_multiple_posted'])){
1716 plugin::multiple_save_object();
1718 if(isset($_POST['useProfile'])){
1719 $this->useProfile = true;
1720 }else{
1721 $this->useProfile = false;
1722 }
1723 if(isset($_POST['gotoProfileFlagC'])){
1724 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1725 }else{
1726 $this->gotoProfileFlagC = false;
1727 }
1729 if(isset($_POST['gotoProfileFlagL'])){
1730 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1731 }else{
1732 $this->gotoProfileFlagL = false;
1733 }
1735 foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1736 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1737 $uattr = "use_".$attr;
1738 if(isset($_POST[$uattr])){
1739 $this->multi_boxes[] = $attr;
1740 }
1741 }
1742 if(isset($_POST['kiosk_server'])){
1743 $tmp = $_POST['kiosk_server'];
1744 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1745 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1746 }
1747 }
1748 if(isset($_POST['kiosk_profile'])){
1749 $tmp = $_POST['kiosk_profile'];
1750 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1751 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1752 }
1753 }
1755 }
1756 }
1758 /* Return plugin informations for acl handling
1759 #FIXME these ACLs should work for groups too */
1760 static function plInfo()
1761 {
1762 return (array("plShortName" => _("Environment"),
1763 "plDescription" => _("Environment settings"), // Description
1764 "plSelfModify" => TRUE,
1765 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1766 "plPriority" => 3, // Position in tabs
1767 "plSection" => array("personal" => _("My account")),
1768 "plCategory" => array("users",
1769 "groups"),
1770 "plOptions" => array("resolution_hook" => array("type" => "string",
1771 "description" => _("Command to extend the list of possible screen resolutions"))),
1773 "plProvidedAcls" => array(
1775 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1776 "gotoProfileFlagC" => _("Cache profile localy") ,
1778 "gotoProfileQuota" => _("Profile quota") ,
1779 "gotoProfileServer" => _("Profile server") ,
1781 "gotoXResolution" => _("Resolution") ,
1782 "gotoKioskProfile" => _("Kiosk profile") ,
1784 "gosaDefaultPrinter" => _("Default printer") ,
1785 "gotoLogonScript" => _("Logon script") ,
1786 "gotoHotplugDevice" => _("Hotplug devices"),
1787 "gotoShare" => _("Shares"))
1788 ));
1789 }
1790 }
1792 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1793 ?>