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