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 = "Desktop";
10 var $plDescription = "Manage desktop settings";
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("environment","resolutions") != ""){
223 $file = $this->config->get_cfg_value("environment","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 $tmp = $this->config->get_cfg_value("environment","kioskPath");
305 if($cnt && !empty($tmp)){
306 $this->kiosk_enabled = TRUE;
307 }
309 $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
310 $this->gotoKioskProfiles['SERVERS'] = $tmp2;
311 $this->gotoKioskProfiles['MAP'] = $tmp3;
313 $error = false;
314 if(!isset($this->gotoKioskProfiles['SERVERS'][$this->gotoKioskProfile_Server])){
315 $error = true;
316 }elseif(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
317 $error = true;
318 }
319 if($error && !empty($this->gotoKioskProfile)){
320 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);
321 $this->gotoKioskProfile_Server ="none";
322 $this->gotoKioskProfile_Profile="";
323 }elseif(empty($this->gotoKioskProfile)){
324 $this->gotoKioskProfile_Server ="none";
325 $this->gotoKioskProfile_Profile="";
326 }
327 }
330 /* Detect type of edited object (user|group)*/
331 function detect_grouptype()
332 {
333 if((!isset($this->parent))&&(!$this->is_account)){
334 $this->is_group = false;
335 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
336 $this->is_group = true;
337 }else{
338 $this->is_group = false;
339 }
340 }
343 function execute()
344 {
346 /* Call parent execute */
347 plugin::execute();
348 /* Log view */
349 if($this->is_account && !$this->view_logged){
350 $this->view_logged = TRUE;
351 if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
352 new log("view","users/".get_class($this),$this->dn);
353 }else{
354 new log("view","groups/".get_class($this),$this->dn);
355 }
356 }
358 /* Check profile server */
359 if($this->acl_is_writeable("gotoProfileServer")){
361 if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
364 if(count($this->gotoProfileServers)){
366 /* Get First Profile */
367 $new = key($this->gotoProfileServers);
369 /* Another profile server found */
370 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
371 }else{
373 /* No other profile servers found */
374 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
375 $this->gotoProfileServer = "none";
376 }
377 }
378 }
380 $this->detect_grouptype();
382 /* Fill templating stuff */
383 $smarty= get_smarty();
384 $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
385 $display= "";
387 $smarty->assign("is_group",$this->is_group);
389 /* Prepare all variables for smarty */
390 foreach($this->attributes as $s_attr){
391 /* Set value*/
392 $smarty->assign($s_attr,set_post($this->$s_attr));
394 /* Set checkbox state*/
395 if(empty($this->$s_attr)){
396 $smarty->assign($s_attr."CHK","");
397 }else{
398 $smarty->assign($s_attr."CHK"," checked ");
399 }
400 }
402 $tmp = $this->plInfo();
403 foreach($tmp['plProvidedAcls'] as $val => $desc){
404 $smarty->assign("$val"."ACL", $this->getacl($val));
405 }
407 /* Is accout enabled | are we editing from usermenu or admin menu
408 All these tab management is done here
409 */
412 /* Working from Usermenu an the Account is currently disbled
413 * this->parent : is only set if we are working in a list of tabs
414 * is_account : is only true if the needed objectClass is given
415 */
416 if((!isset($this->parent))&&(!$this->is_account)){
417 /* We are currently editing this tab from usermenu, but this account is not enabled */
418 $smarty->assign("is_account",$this->is_account);
419 /* Load template */
420 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
421 /* Avoid the "You are currently editing ...." message when you leave this tab */
422 $display .= back_to_main();
423 /* Display our message to the user */
424 return $display;
427 /* We are currently editing from group tabs, because
428 * $this->parent is set
429 * posixAccount is not set, so we are not in usertabs.
430 */
431 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
432 $smarty->assign("is_account","true");
433 $this->uid = $this->cn;
434 $this->attrs['uid'] = $this->cn;
436 /* Change state if needed */
437 if (isset($_POST['modify_state'])){
438 if(($this->acl_is_createable() && !$this->is_account) ||
439 ($this->acl_is_removeable() && $this->is_account)){
440 $this->is_account= !$this->is_account;
441 }
442 }
443 /* Group Dialog with enabled environment options */
444 if ($this->is_account){
445 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Desktop")),
446 msgPool::featuresEnabled(_("Desktop")));
447 } else {
449 /* Environment is disabled
450 If theres is no posixAccount enabled, you won't be able to enable
451 environment extensions
452 */
453 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
454 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Desktop")),
455 msgPool::featuresDisabled(_("Desktop")));
456 return $display;
457 }elseif((isset($this->parent->by_object['ogroup']))){
458 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Desktop")),
459 msgPool::featuresDisabled(_("Desktop")));
460 return $display;
461 }else{
462 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Desktop")),
463 msgPool::featuresDisabled(_("Desktop"), _("POSIX")), TRUE);
464 return $display;
465 }
466 }
467 }else{
468 /* Editing from Usermenu
469 * Tell smarty that this accoutn is enabled
470 */
471 $smarty->assign("is_account","true");
473 /* Change state if needed */
474 if (isset($_POST['modify_state'])){
475 if(($this->acl_is_createable() && !$this->is_account) ||
476 ($this->acl_is_removeable() && $this->is_account)){
477 $this->is_account= !$this->is_account;
478 }
479 }
481 if(isset($this->parent)){
483 // 3. Account enabled . Editing from adminmenu
484 if ($this->is_account){
485 $display= $this->show_disable_header(msgPool::removeFeaturesButton(_("Desktop")),
486 msgPool::featuresEnabled(_("Desktop")));
487 } else {
489 if($this->parent->by_object['posixAccount']->is_account==true){
490 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Desktop")),
491 msgPool::featuresDisabled(_("Desktop")));
492 return $display;
493 }else{
494 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Desktop")),
495 msgPool::featuresDisabled(_("Desktop"), _("POSIX")), TRUE);
496 return $display;
497 }
498 }
499 }
500 }
502 /* Reset header toggle */
503 if($this->multiple_support_active){
504 $display = "";
505 }
507 /* Account is Account : is_accounbt=true.
508 * Else we won't reach this.
509 */
511 /* Prepare all variables for smarty */
512 foreach($this->attributes as $s_attr){
513 /* Set value*/
514 $smarty->assign($s_attr,set_post($this->$s_attr));
516 /* Set checkbox state*/
517 if(empty($this->$s_attr)){
518 $smarty->assign($s_attr."CHK","");
519 }else{
520 $smarty->assign($s_attr."CHK"," checked ");
521 }
522 }
524 $tmp = $this->plInfo();
525 foreach($tmp['plProvidedAcls'] as $val => $desc){
526 $smarty->assign("$val"."ACL", $this->getacl($val));
527 }
529 foreach(array("gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
530 $smarty->assign($s_attr."ACL",$this->getacl($s_attr));
531 }
533 if($this->read_only) {
534 $smarty->assign("gotoPrinterACL","r");
535 }else{
536 $smarty->assign("gotoPrinterACL","rw");
537 }
540 $smarty->assign("useProfile",$this->useProfile);
541 if(empty($this->useProfile) && !$this->multiple_support_active){
542 $smarty->assign("useProfileCHK","");
543 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer")));
544 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota")));
545 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC")));
546 }else{
547 $smarty->assign("useProfileCHK"," checked ");
548 }
550 $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer"));
551 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer").$this->getacl("gotoProfileQuota"));
553 /* HANDLE Profile Settings here
554 * Assign available Quota and resolution settings
555 * Get all available profile server
556 * Get cache checkbox
557 * Assign this all to Smarty
558 */
560 if(empty($this->gotoProfileFlagL)){
561 $smarty->assign("gotoProfileFlagLCHK"," ");
562 }else{
563 $smarty->assign("gotoProfileFlagLCHK"," checked ");
564 }
566 if(empty($this->gotoProfileFlagC)){
567 $smarty->assign("gotoProfileFlagCCHK"," ");
568 }else{
569 $smarty->assign("gotoProfileFlagCCHK"," checked ");
570 }
573 $smarty->assign("gotoXResolutions" , set_post($this->gotoXResolutions));
574 $smarty->assign("gotoXResolutionKeys" , set_post(array_flip($this->gotoXResolutions)));
576 $smarty->assign("gotoProfileServers", set_post($this->gotoProfileServers));
577 if(!is_array($this->gotoProfileServers)){
578 $this->gotoProfileServers =array();
579 }
581 /* Handle kiosk profiles*/
582 $smarty->assign("kiosk_servers" , set_post($this->gotoKioskProfiles['SERVERS']));
583 $smarty->assign("kiosk_server" , set_post($this->gotoKioskProfile_Server));
584 $smarty->assign("kiosk_profiles", set_post($this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]));
585 $smarty->assign("kiosk_profile" , set_post($this->gotoKioskProfile_Profile));
588 /* Logonscript Management
589 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
590 * Perform add Delete edit Posts
591 */
593 /* Dialog Save */
594 if(isset($_POST['LogonSave'])){
596 if(!$this->acl_is_writeable("gotoLogonScript")){
597 msg_dialog::display(_("Permission error"), msgPool::permModify(_("Log on scripts")), ERROR_DIALOG);
598 unset($this->dialog);
599 $this->dialog=FALSE;
600 $this->is_dialog=false;
601 }else{
602 $this->dialog->save_object();
603 if(count($this->dialog->check())!=0){
604 foreach($this->dialog->check() as $msg){
605 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
606 }
607 }else{
608 $tmp = $this->dialog->save();
609 unset($this->dialog);
610 $this->dialog=FALSE;
611 $this->is_dialog=false;
613 if($this->multiple_support_active){
614 $tmp['UsedByAllUsers'] = TRUE;
615 }
616 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
617 }
618 }
619 }
622 /* Dialog Quit without saving */
623 if(isset($_POST['LogonCancel'])){
624 $this->is_dialog= false;
625 unset($this->dialog);
626 $this->dialog= FALSE;
627 }
629 /* Check Edit Del New Posts for a selected LogonScript */
630 if($this->acl_is_writeable("gotoLogonScript") &&
631 (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
633 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
634 * In this case we create a new Logon Script.
635 */
636 if(isset($_POST['gotoLogonScriptNew'])){
637 $this->is_dialog = true;
638 $this->dialog = new logonManagementDialog($this->config,$this->dn);
639 }
641 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
642 * We only can delete if there is an entry selected.
643 */
644 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
645 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
646 }
648 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
649 * There must be an entry selected to perform edit request.
650 */
651 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
652 $is_entry = $this->gotoLogonScripts[get_post('gotoLogonScript')];
653 $this->is_dialog = true;
654 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
655 }
656 }
658 /* Append List to smarty*/
659 if($this->multiple_support_active){
660 $smarty->assign("gotoLogonScripts", set_post($this->gotoLogonScripts));
661 $smarty->assign("gotoLogonScriptKeysCnt", count($this->gotoLogonScripts));
662 }else{
663 $ls = $this->printOutLogonScripts();
664 $smarty->assign("gotoLogonScripts", set_post($ls));
665 $smarty->assign("gotoLogonScriptKeys",set_post(array_flip($ls)));
666 $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
667 }
669 /* In this section server shares will be defined
670 * A user can select one of the given shares and a mount point
671 * and attach this combination to his setup.
672 */
674 $smarty->assign("gotoShareSelections", set_post($this->gotoShareSelections));
675 if(!is_array($this->gotoShareSelections)){
676 $this->gotoShareSelections = array();
677 }
678 $smarty->assign("gotoShareSelectionKeys", set_post(array_flip($this->gotoShareSelections)));
680 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
681 * This entry will be, a combination of mountPoint and sharedefinitions
682 */
683 if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
685 /* We assign a share to this user, if we don't know where to mount the share */
686 if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
687 msg_dialog::display(_("Error"), msgPool::invalid(_("Share")), ERROR_DIALOG);
688 }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
689 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
690 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
691 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point"), "/[^\s]/"), ERROR_DIALOG);
692 }elseif(!(
693 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
694 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
695 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
696 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
697 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
698 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
699 preg_match("/^%/",$_POST['gotoShareMountPoint'])
700 )
701 ){
702 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
703 }else{
704 $a_share = $this->gotoAvailableShares[get_post('gotoShareSelection')];
705 $s_mount = get_post('gotoShareMountPoint');
706 $s_user = get_post('ShareUser');
707 /* Preparing the new assignment */
708 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
709 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
710 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
711 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
713 if($this->multiple_support_active){
714 $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
715 }
716 }
717 }
719 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
720 * If there is no defined share selected, we will abort the deletion without any message
721 */
722 $once = true;
723 if($this->acl_is_writeable("gotoShare")){
724 foreach($_POST as $name => $value){
725 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
726 $once = false;
727 $key = preg_replace("/^gotoShareDel_/","",$name);
728 $key = postDecode($key);
729 if(isset($this->gotoShares[$key])) {
730 unset($this->gotoShares[$key]);
731 }
733 /* Remove corresponding password entry, too. This is a workaround
734 to get rid of old-style entries. */
735 $key= preg_replace("/\|/", "|!", $key);
736 if(isset($this->gotoShares[$key])) {
737 unset($this->gotoShares[$key]);
738 }
739 }
740 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
741 $once = false;
742 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
743 $key = postDecode($key);
744 $this->gotoShares[$key]['PwdHash'] = "";
745 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
746 unset($this->gotoShares[$key]);
747 }
748 }
749 }
750 }
752 // Build up share list
753 $data = $lData = array();
754 foreach($this->gotoShares as $key => $entry){
755 $img = "";
757 // Skip password only entries
758 if( empty($entry['server']) && empty($entry['name']) &&
759 empty($entry['mountPoint']) && empty($entry['Username'])){
760 continue;
761 }
763 // While editing mutlipe users at once we've to seperate
764 // entries used by all users and those used by only some.
765 $color = "";
766 if($this->multiple_support_active){
767 if($entry['UsedByAllUsers']){
768 $value .= " (<b>"._("Used by all users")."</b>)";
769 }else{
770 $color = "color: #999999;";
771 $value .= " (<b>"._("Used by some users")."</b>)";
772 }
773 }
775 // Create password reset image button
776 if($entry['PwdHash'] != ""){
777 $img.=
778 image('plugins/goto/images/list_reset_password.png',
779 'gotoShareResetPwd_'.postEncode($key),
780 _("Reset password hash"));
781 }
783 // Build up list entries - Handle entries starting with '!' here.
784 $data[$key]=$key;
785 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
787 // If we are currently editing groups environment, skip those ! entries */
788 if($this->is_group) continue;
790 $lData[$key] = array('data' => array(
791 $entry['server']."://",
792 $entry['name'],
793 "",
794 "",
795 image("plugins/groups/images/select_group.png","",_("Group share")),
796 $img));
797 }else{
799 $img.= image('images/lists/trash.png',"gotoShareDel_".postEncode($key),msgPool::delButton());
800 $lData[$key] = array('data' => array(
801 $entry['server']."://",
802 $entry['name'],
803 $entry['mountPoint'],
804 $entry['Username'],
805 image("plugins/users/images/select_user.png","",_("User share")),
806 $img));
807 }
808 }
809 $this->shareList->setListData($data,$lData);
810 $this->shareList->update();
811 $this->shareList->setAcl($this->getacl("gotoShare"));
812 $smarty->assign("shareList",$this->shareList->render());
814 /* Hotplug devices will be handled here
815 * There are 3 possible methods for this feature
816 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
817 * Delete will erase an entry, the entry must be selcted in the ListBox first
818 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
819 */
821 /* We have to delete the selected hotplug from the list*/
822 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDeviceDN")){
823 if($this->acl_is_writeable("gotoHotplugDeviceDN")){
824 foreach($_POST['gotoHotplugDevice_post'] as $name){
825 unset($this->gotoHotplugDevices[$name]);
826 }
827 }
828 }
830 /* There are already defined hotplugs from other users we could use */
831 if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDeviceDN")){
832 $tmp =array();
833 foreach($this->gotoHotplugDevices as $plugs){
834 $tmp[] = $plugs['name'];
835 }
836 $this->dialog = new hotplugSelect($this->config, get_userinfo());
837 $this->is_dialog = true;
838 }
840 /* Dialog Aborted */
841 if(isset($_POST['hotplugSelect_cancel'])){
842 $this->dialog= FALSE;
843 $this->is_dialog = false;
844 }
846 /* Dialod saved */
847 if(isset($_POST['hotplugSelect_save'])){
849 $res = $this->dialog->save();
850 foreach($res as $hotplug){
851 $name = $hotplug['cn'][0];
852 $entry['dn'] = $hotplug['dn'];
854 /* Set class values */
855 $tmp = preg_split("/\|/",$hotplug['gotoHotplugDevice'][0]);
856 $entry['name'] = $hotplug['cn'][0];
857 $entry['description'] = $tmp[0];
858 $entry['id'] = $tmp[1];
859 $entry['produkt'] = $tmp[2];
860 $entry['vendor'] = $tmp[3];
861 if($this->multiple_support_active){
862 $entry['UsedByAllUsers'] = TRUE;
863 }
864 $this->gotoHotplugDevices[$name]= $entry;
865 }
866 $this->dialog= FALSE;
867 $this->is_dialog = false;
868 }
870 if($this->dialog instanceOf hotplugSelect){
872 // Build up blocklist
873 session::set('filterBlacklist', array('cn' => array_keys($this->gotoHotplugDevices)));
874 return($this->dialog->execute());
875 }
877 if($this->multiple_support_active){
878 $smarty->assign("gotoHotplugDevices", set_post($this->gotoHotplugDevices));
879 }else{
880 $smarty->assign("gotoHotplugDevices", set_post($this->printOutHotPlugDevices()));
881 $smarty->assign("gotoHotplugDeviceKeys",set_post(array_flip($this->printOutHotPlugDevices())));
882 }
884 /* Printer Assignment will managed below
885 * A printer can be assigned in two different ways and two different types
886 * There are 2 types of users assigned to a printer : user and admin
887 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
888 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
889 */
891 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
892 if(isset($_POST['gotoPrinterAdd'])){
893 $this->dialog = new printerSelect($this->config,get_userinfo());
894 $this->is_dialog=true;
895 }
897 if(isset($_POST['printerSelect_cancel']) && $this->dialog instanceOf printerSelect){
898 $this->is_dialog=false;
899 $this->dialog=FALSE;
900 }
902 if(isset($_POST['printerSelect_save']) && $this->dialog instanceOf printerSelect){
904 $res = $this->dialog->save();
905 foreach($res as $printer){
907 $pname = $printer['cn'][0];
908 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'], $printer['dn'],"printer");
909 $printerObj->set_acl_base($printer['dn']);
911 $type = false;
914 if($this->is_group){
915 if($this->dn == "new"){
916 $type = "AddGroup";
917 }elseif(isset($this->NewDeletedPrinters[$pname])){
918 $type = "AddGroup";
919 }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
920 $type = "AddGroup";
921 }
922 }else{
923 if($this->multiple_support_active){
924 $type = "AddUser";
925 }elseif(isset($this->NewDeletedPrinters[$pname])){
926 $type = "AddUser";
927 }elseif($this->dn == "new"){
928 $type = "AddUser";
929 }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
930 $type = "AddUser";
931 }
932 }
934 if($type){
935 $this->gotoPrinter[$pname]=$printer;
936 $this->gotoPrinter[$pname]['mode']="user";
937 $this->add_del_printer_member_was_called = true;
939 $this->NewAddedPrinters[$pname] = $pname;
940 if(isset($this->NewDeletedPrinters[$pname])){
941 unset($this->NewDeletedPrinters[$pname]);
942 }
943 }
944 }
946 $this->is_dialog=false;
947 unset($this->dialog);
948 $this->dialog =FALSE;
949 }
951 // Display printer selection dialog
952 if($this->dialog instanceOf printerSelect){
954 // Build up blocklist
955 session::set('filterBlacklist',array('cn' => array_keys($this->gotoPrinter)));
956 return($this->dialog->execute());
957 }
960 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
961 $printer = get_post('gotoPrinterSel');
962 foreach($printer as $pname){
964 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
965 $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
967 $type = false;
968 if($this->is_group){
969 if(isset($this->NewAddedPrinters[$pname])){
970 $type = "Group";
971 }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
972 $type = "Group";
973 }
974 }else{
975 if(isset($this->NewAddedPrinters[$pname])){
976 $type = "User";
977 }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
978 $type = "User";
979 }
980 }
981 if($type){
982 $this->add_del_printer_member_was_called = true;
983 unset($this->gotoPrinter[$pname]);
985 $this->NewDeletedPrinters[$pname] = $pname;
986 if(isset($this->NewAddedPrinters[$pname])){
987 UNSET($this->NewAddedPrinters[$pname]);
988 }
989 }
990 }
991 }
993 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
994 $printers = get_post('gotoPrinterSel');
995 $this->add_del_printer_member_was_called = true;
996 foreach($printers as $printer){
997 if($this->gotoPrinter[$printer]['mode']=="user"){
998 $this->gotoPrinter[$printer]['mode']="admin";
999 }else{
1000 $this->gotoPrinter[$printer]['mode']="user";
1001 }
1002 }
1003 }
1005 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
1006 if($this->is_group){
1007 msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
1008 }else{
1009 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
1010 $this->gosaDefaultPrinter= "";
1011 } else {
1012 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
1013 }
1014 }
1015 }
1017 $smarty->assign("gotoPrinter", set_post($this->printOutPrinterDevices()));
1019 /* General behavior */
1020 if(is_object($this->dialog)){
1021 $this->dialog->save_object();
1022 $disp =$this->dialog->execute();
1023 return($disp);
1024 }
1026 /* Assign used attributes for multiple edit */
1027 foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
1028 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
1029 $ubox ="use_".$box;
1030 if(in_array($box,$this->multi_boxes)){
1031 $smarty->assign($ubox,TRUE);
1032 }else{
1033 $smarty->assign($ubox,FALSE);
1034 }
1035 }
1037 /* Als smarty vars are set. Get smarty template and generate output */
1038 $smarty->assign("multiple_support",$this->multiple_support_active);
1039 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
1040 return($display);
1041 }
1043 function remove_from_parent()
1044 {
1045 /* only if it was an account*/
1046 if (!$this->initially_was_account){
1047 return;
1048 }
1050 /* include global link_info */
1051 $ldap= $this->config->get_ldap_link();
1053 /* Remove and write to LDAP */
1054 plugin::remove_from_parent();
1056 /* Don't save our template variables */
1057 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1059 /* Skip all these attributes */
1060 foreach($skip as $del){
1061 unset($this->attrs[$del]);
1062 }
1064 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1066 $ldap->cd($this->dn);
1067 $this->cleanup();
1068 $ldap->modify ($this->attrs);
1070 if($this->is_group){
1071 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1072 }else{
1073 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1074 }
1076 if (!$ldap->success()){
1077 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1078 }
1080 /* Optionally execute a command after we're done */
1081 $this->handle_post_events("remove",array("uid" => $this->uid));
1082 }
1085 /* Save data to object */
1086 function save_object()
1087 {
1088 /* Get all Posted vars
1089 * Setup checkboxes
1090 */
1091 if(isset($_POST['iamposted'])){
1093 $PACL = $this->getacl("gotoProfileServer").$this->getacl("gotoProfileQuota");
1095 if(isset($_POST['kiosk_server'])){
1096 $tmp = get_post('kiosk_server');
1097 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1098 $this->gotoKioskProfile_Server = get_post('kiosk_server');
1099 }
1100 }
1101 if(isset($_POST['kiosk_profile'])){
1102 $tmp = get_post('kiosk_profile');
1103 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1104 $this->gotoKioskProfile_Profile = get_post('kiosk_profile');
1105 }
1106 }
1108 if(preg_match("/w/",$PACL)){
1109 if(isset($_POST['useProfile'])){
1110 $this->useProfile = true;
1111 }else{
1112 $this->useProfile = false;
1113 }
1114 }
1116 if($this->acl_is_writeable("gotoProfileFlagC")){
1117 if(isset($_POST['gotoProfileFlagC'])){
1118 $this->gotoProfileFlagC = get_post('gotoProfileFlagC');
1119 }else{
1120 $this->gotoProfileFlagC = false;
1121 }
1122 }
1124 if($this->acl_is_writeable("gotoProfileFlagL")){
1125 if(isset($_POST['gotoProfileFlagL'])){
1126 $this->gotoProfileFlagL = get_post('gotoProfileFlagL');
1127 }else{
1128 $this->gotoProfileFlagL = false;
1129 }
1130 }
1132 plugin::save_object();
1133 foreach($this->attributes as $s_attr){
1134 if((!isset($_POST[$s_attr])) ||
1135 in_array($s_attr,array("gosaDefaultPrinter","gotoShare","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1136 if(!$this->acl_is_writeable($s_attr)){
1137 continue;
1138 }else{
1139 if(isset($_POST[$s_attr])){
1140 $this->$s_attr = get_post($s_attr);
1141 }else{
1142 $this->$s_attr = false;
1143 }
1144 }
1145 }
1146 }
1147 }
1150 /* Check supplied data */
1151 function check()
1152 {
1153 /* Call common method to give check the hook */
1154 $message= plugin::check();
1156 $this->detect_grouptype();
1158 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1159 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1160 }
1161 if(!isset($this->attrs['objectClass'])){
1162 $this->attrs['objectClass']=array();
1163 }
1164 if(!$this->is_group){
1165 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1166 $message[]= msgPool::featuresDisabled(_("environment"),_("POSIX"));
1167 }
1168 }
1169 return ($message);
1170 }
1173 /* Save to LDAP */
1174 function save()
1175 {
1176 /* If group was renamed, all printer settings get lost
1177 */
1178 /* only save changed variables ....*/
1179 if ($this->gotoKioskProfile_Server != "none"){
1180 $method = $this->gotoKioskProfiles['MAP'][$this->gotoKioskProfile_Server][$this->gotoKioskProfile_Profile];
1181 $this->gotoKioskProfile= $method;
1182 }else{
1183 $this->gotoKioskProfile= array();
1184 }
1186 plugin::save();
1187 $ldap= $this->config->get_ldap_link();
1189 $realyUsedAttrs= array();
1191 /* Save already used objectClasses */
1192 $ocs = $this->attrs['objectClass'];
1193 unset($ocs['count']);
1194 $this->attrs = array();
1195 $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1197 /* 1. Search all printers that have our uid/cn as member
1198 * 2. Delete this uid/cn from every single entry and save it again.
1199 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1200 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
1201 */
1203 $this->detect_grouptype();
1205 if($this->add_del_printer_member_was_called){
1207 $types = array( "gotoUserPrinter" => "AddUser",
1208 "gotoGroupPrinter" => "AddGroup",
1209 "gotoUserAdminPrinter" => "AddAdminUser",
1210 "gotoGroupAdminPrinter" => "AddAdminGroup");
1212 if($this->is_group){
1213 $s_suffix = "Group";
1214 $useVar = "cn";
1215 }else{
1216 $useVar = "uid";
1217 $s_suffix = "User";
1218 }
1220 /* Remove old entries */
1221 $ldap->cd($this->config->current['BASE']);;
1222 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1223 while($attr = $ldap->fetch()){
1224 $printerObj = NULL;
1225 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1226 $printerObj->set_acl_base($attr['dn']);
1227 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1228 $printerObj->by_object['printgeneric']->save();
1229 }
1231 $ldap->cd($this->config->current['BASE']);;
1232 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1233 while($attr = $ldap->fetch()){
1234 $printerObj = NULL;
1235 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1236 $printerObj->set_acl_base($attr['dn']);
1237 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1238 $printerObj->by_object['printgeneric']->save();
1239 }
1241 foreach($this->gotoPrinter as $printer){
1242 $printerObj = NULL;
1243 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1244 $printerObj->set_acl_base($printer['dn']);
1247 if($printer['mode'] == "admin") {
1248 $attribute = "goto".$s_suffix."AdminPrinter";
1249 }else{
1250 $attribute = "goto".$s_suffix."Printer";
1251 }
1253 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1254 $printerObj->by_object['printgeneric']->save();
1255 }
1256 }
1258 /* Prepare HotPlug devices */
1259 $this->attrs['gotoHotplugDeviceDN'] = array();
1260 foreach($this->gotoHotplugDevices as $name => $device){
1261 $this->attrs['gotoHotplugDeviceDN'][]= LDAP::fix($device['dn']);
1262 }
1264 /* Prepare LogonScripts */
1265 $this->attrs['gotoLogonScript'] = array();
1266 foreach($this->gotoLogonScripts as $name => $script){
1267 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1268 $script['LogonOverload'].$script['LogonLast']."|".
1269 $script['LogonPriority']."|".
1270 base64_encode($script['LogonData'])."|".
1271 $script['LogonDescription'];
1272 }
1274 /* Prepare Shares */
1275 $this->attrs['gotoShare']=array();
1276 foreach($this->gotoShares as $name => $share){
1277 $mntp= $share['mountPoint'];
1278 if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1279 $mntp= base64_encode($mntp);
1280 }
1281 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1282 }
1285 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1286 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1288 foreach($saveThis as $tosave){
1289 if(!empty($this->$tosave)){
1290 $this->attrs[$tosave]=$this->$tosave;
1291 }else{
1292 $this->attrs[$tosave]=array();
1293 }
1294 }
1296 /* Prepare Flags */
1297 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1298 if(empty($this->attrs['gotoProfileFlags'][0])){
1299 $this->attrs['gotoProfileFlags']=array();
1300 }
1302 if($this->useProfile == false){
1303 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1304 $this->attrs['gotoProfileServer']= array();
1305 }
1307 $ldap->cat ($this->dn, array('dn'));
1308 if ($ldap->fetch()){
1309 $mode= "modify";
1310 } else {
1311 $mode= "add";
1312 $ldap->cd($this->config->current['BASE']);
1313 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1314 }
1316 $ldap->cd($this->dn);
1317 $this->cleanup();
1318 $ldap->$mode($this->attrs);
1320 $cat = "users";
1321 if($this->is_group){
1322 $cat = "groups";
1323 }
1325 /* Log last action */
1326 if($this->initially_was_account){
1327 new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1328 }else{
1329 new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1330 }
1332 if (!$ldap->success()){
1333 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1334 }
1335 $this->handle_post_events($mode,array("uid"=>$this->uid));
1336 }
1339 /* Generate ListBox frindly output for the definedhotplugs
1340 * Possibly Add or remove an attribute here,
1341 */
1342 function printOutHotPlugDevices()
1343 {
1344 $a_return= array();
1345 if(is_array($this->gotoHotplugDevices)){
1346 foreach($this->gotoHotplugDevices as $key=>$device){
1347 $a_return[$key] = $device['name']." - ".$device['id'];
1348 }
1349 }
1350 return($a_return);
1351 }
1353 /* Generates ListBox frienly output of used printer devices
1354 * Append ' - admin' if printer is used in admin mode
1355 */
1356 function printOutPrinterDevices()
1357 {
1358 $a_return = array();
1360 if(is_array($this->gotoPrinter)){
1361 foreach($this->gotoPrinter as $printer){
1362 if($printer['mode'] == 'admin'){
1363 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1364 }else{
1365 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1366 }
1367 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1368 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1369 }
1370 }
1371 }
1372 asort($a_return);
1373 return($a_return);
1374 }
1377 function PrepareForCopyPaste($source)
1378 {
1379 plugin::PrepareForCopyPaste($source);
1381 $class= get_class($this);
1382 $o_source = new $class($this->config,$source['dn']);
1383 foreach($this->CopyPasteVars as $attr){
1384 $this->$attr = $o_source->$attr;
1385 }
1386 }
1389 function saveCopyDialog()
1390 {
1391 if(isset($_POST['cn'])){
1392 $this->cn = get_post('cn');
1393 $this->uid = get_post('cn');
1394 }
1395 }
1398 /* Generates ListBox frienly output of used logonscripts
1399 */
1400 function printOutLogonScripts()
1401 {
1402 $a_return = array();
1403 if(is_array($this->gotoLogonScripts)){
1404 foreach($this->gotoLogonScripts as $script){
1405 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1406 }
1407 }
1408 return($a_return);
1409 }
1412 function multiple_execute()
1413 {
1414 /* Reset header toggle */
1415 $this->is_account = TRUE;
1416 return($this->execute());
1417 }
1420 /* Initialize plugin with given atribute arrays
1421 */
1422 function init_multiple_support($attrs,$all)
1423 {
1424 plugin::init_multiple_support($attrs,$all);
1426 /* Prepare Shares */
1427 if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1428 unset($this->multi_attrs_all['gotoShare']['count']);
1429 foreach($this->multi_attrs_all['gotoShare'] as $share){
1430 $tmp = $tmp2 = array();
1431 $tmp = explode("|",$share);
1432 $tmp2['server'] =$tmp[0];
1433 $tmp2['name'] =$tmp[1];
1435 /* Decode base64 if needed */
1436 if (!preg_match('%/%', $tmp[2])){
1437 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1438 } else {
1439 $tmp2['mountPoint'] =$tmp[2];
1440 }
1442 if(isset($tmp[3])){
1443 $tmp2['PwdHash'] =$tmp[3];
1444 }else{
1445 $tmp2['PwdHash'] ="";
1446 }
1447 if(isset($tmp[4])){
1448 $tmp2['Username'] =$tmp[4];
1449 }else{
1450 $tmp2['Username'] ="";
1451 }
1452 $tmp2['UsedByAllUsers'] = FALSE;
1453 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1454 }
1455 }
1457 /* Prepare Shares */
1458 if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1459 unset($this->multi_attrs['gotoShare']['count']);
1460 foreach($this->multi_attrs['gotoShare'] as $share){
1461 $tmp = $tmp2 = array();
1462 $tmp = explode("|",$share);
1463 $tmp2['server'] =$tmp[0];
1464 $tmp2['name'] =$tmp[1];
1466 /* Decode base64 if needed */
1467 if (!preg_match('%/%', $tmp[2])){
1468 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1469 } else {
1470 $tmp2['mountPoint'] =$tmp[2];
1471 }
1473 if(isset($tmp[3])){
1474 $tmp2['PwdHash'] =$tmp[3];
1475 }else{
1476 $tmp2['PwdHash'] ="";
1477 }
1478 if(isset($tmp[4])){
1479 $tmp2['Username'] =$tmp[4];
1480 }else{
1481 $tmp2['Username'] ="";
1482 }
1483 $tmp2['UsedByAllUsers'] = TRUE;
1484 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1485 }
1486 }
1489 /* prepare LogonScripts */
1490 if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1491 unset($this->multi_attrs_all['gotoLogonScript']['count']);
1492 foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1493 $tmp = $tmp2 = array();
1494 $tmp = explode("|",$device);
1495 $tmp2['LogonName'] = $tmp[0];
1496 $tmp2['LogonPriority'] = $tmp[2];
1497 if(preg_match("/O/i",$tmp[1])){
1498 $tmp2['LogonOverload'] = "O";
1499 }else{
1500 $tmp2['LogonOverload'] = "";
1501 }
1502 if(preg_match("/L/i",$tmp[1])){
1503 $tmp2['LogonLast'] = "L";
1504 }else{
1505 $tmp2['LogonLast'] = "";
1506 }
1507 $tmp2['LogonData'] = base64_decode($tmp[3]);
1508 $tmp2['LogonDescription'] = $tmp[4];
1509 $tmp2['UsedByAllUsers'] = FALSE;
1510 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1511 }
1512 }
1514 /* prepare LogonScripts */
1515 if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1516 unset($this->multi_attrs['gotoLogonScript']['count']);
1517 foreach($this->multi_attrs['gotoLogonScript'] as $device){
1518 $tmp = $tmp2 = array();
1519 $tmp = explode("|",$device);
1520 $tmp2['LogonName'] = $tmp[0];
1521 $tmp2['LogonPriority'] = $tmp[2];
1522 if(preg_match("/O/i",$tmp[1])){
1523 $tmp2['LogonOverload'] = "O";
1524 }else{
1525 $tmp2['LogonOverload'] = "";
1526 }
1527 if(preg_match("/L/i",$tmp[1])){
1528 $tmp2['LogonLast'] = "L";
1529 }else{
1530 $tmp2['LogonLast'] = "";
1531 }
1532 $tmp2['LogonData'] = base64_decode($tmp[3]);
1533 $tmp2['LogonDescription'] = $tmp[4];
1534 $tmp2['UsedByAllUsers'] = TRUE;
1535 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1536 }
1537 }
1539 /* Prepare hotplugs */
1540 if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1541 $ldap = $this->config->get_ldap_link();
1542 $ldap->cd($this->config->current['BASE']);
1543 for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1544 $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1545 if($ldap->count()){
1546 $multi_attrs_all = $ldap->fetch();
1548 if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1549 $tmp = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1550 $tmp2 = array();
1551 $tmp2['name'] = $multi_attrs_all['cn'][0];
1552 $tmp2['description'] = $tmp[0];
1553 $tmp2['id'] = $tmp[1];
1554 $tmp2['produkt'] = $tmp[2];
1555 $tmp2['vendor'] = $tmp[3];
1556 $tmp2['dn'] = $multi_attrs_all['dn'];
1557 $tmp2['UsedByAllUsers'] = FALSE;
1558 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1559 }
1560 }
1561 }
1562 }
1564 /* Prepare hotplugs */
1565 if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1566 $ldap = $this->config->get_ldap_link();
1567 $ldap->cd($this->config->current['BASE']);
1568 for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1569 $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1570 if($ldap->count()){
1571 $multi_attrs = $ldap->fetch();
1573 if(isset($multi_attrs['gotoHotplugDevice'][0])){
1574 $tmp = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1575 $tmp2 = array();
1576 $tmp2['name'] = $multi_attrs['cn'][0];
1577 $tmp2['description'] = $tmp[0];
1578 $tmp2['id'] = $tmp[1];
1579 $tmp2['produkt'] = $tmp[2];
1580 $tmp2['vendor'] = $tmp[3];
1581 $tmp2['dn'] = $multi_attrs['dn'];
1582 $tmp2['UsedByAllUsers'] = TRUE;
1583 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1584 }
1585 }
1586 }
1587 }
1588 $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1589 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1590 $chr = $this->gotoProfileFlags[$i];
1591 $name = "gotoProfileFlag".$chr;
1592 $this->$name=$chr;
1593 }
1594 $this->update_kiosk_profiles();
1595 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1597 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1598 $this->useProfile = true;
1599 }else{
1600 $this->useProfile = false;
1601 }
1603 }
1606 function set_multi_edit_values($attrs)
1607 {
1608 $shares = $this->gotoShares;
1609 $scripts= $this->gotoLogonScripts;
1610 $plugs= $this->gotoHotplugDevices;
1611 plugin::set_multi_edit_values($attrs);
1613 $this->gotoShares = $shares;
1614 $this->gotoLogonScripts = $scripts;
1615 $this->gotoHotplugDevices = $plugs;
1617 foreach($attrs['gotoShares'] as $name => $share){
1618 if($share['UsedByAllUsers'] == TRUE){
1619 $this->gotoShares[$name] = $share;
1620 }
1621 }
1622 foreach($this->gotoShares as $name => $share){
1623 if(!isset($attrs['gotoShares'][$name])){
1624 unset($this->gotoShares[$name]);
1625 }
1626 }
1627 foreach($attrs['gotoLogonScripts'] as $name => $script){
1628 if($script['UsedByAllUsers'] == TRUE){
1629 $this->gotoLogonScripts[$name] = $script;
1630 }
1631 }
1632 foreach($this->gotoLogonScripts as $name => $script){
1633 if(!isset($attrs['gotoLogonScripts'][$name])){
1634 unset($this->gotoLogonScripts[$name]);
1635 }
1636 }
1637 $tmp = array();
1638 foreach($this->gotoHotplugDevices as $entry){
1639 $tmp[$entry['dn']] = $entry;
1640 }
1642 foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1643 if($plug['UsedByAllUsers'] == TRUE){
1644 $tmp[$plug['dn']] = $plug;
1645 }
1646 }
1647 foreach($tmp as $name => $plug){
1648 $found = false;
1649 foreach($attrs['gotoHotplugDevices'] as $test){
1650 if($test['dn'] == $name){
1651 $found = true;
1652 }
1653 }
1654 if(!$found){
1655 unset($tmp[$name]);
1656 }
1657 }
1658 }
1661 /* Return selected values for multiple edit */
1662 function get_multi_edit_values()
1663 {
1664 $ret = plugin::get_multi_edit_values();
1665 $ret['gotoShares'] = $this->gotoShares;
1666 $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1667 $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1669 if(in_array("gotoPrinter",$this->multi_boxes)){
1670 $ret['gotoPrinter'] = $this->gotoPrinter;
1671 $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1672 $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1674 /* Force printer reset */
1675 $ret['add_del_printer_member_was_called'] = TRUE;
1676 }
1678 if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1679 $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1680 }
1682 if(in_array("useProfile",$this->multi_boxes)){
1683 $ret['useProfile']=$this->useProfile;
1684 if(in_array("gotoProfileServer",$this->multi_boxes)){
1685 $ret['gotoProfileServer']=$this->gotoProfileServer;
1686 }
1687 if(in_array("gotoProfileQuota",$this->multi_boxes)){
1688 $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1689 }
1690 if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1691 $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1692 }
1693 }
1694 if(in_array("gotoXResolution",$this->multi_boxes)){
1695 $ret['gotoXResolution'] = $this->gotoXResolution;
1696 }
1697 if(in_array("kiosk_server",$this->multi_boxes)){
1698 $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1699 $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1700 }
1701 return($ret);
1702 }
1705 function multiple_check()
1706 {
1707 $message = plugin::multiple_check();
1708 $this->detect_grouptype();
1710 if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
1711 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1712 }
1713 return($message);
1714 }
1717 function multiple_save_object()
1718 {
1719 if(isset($_POST['environment_multiple_posted'])){
1720 plugin::multiple_save_object();
1722 if(isset($_POST['useProfile'])){
1723 $this->useProfile = true;
1724 }else{
1725 $this->useProfile = false;
1726 }
1727 if(isset($_POST['gotoProfileFlagC'])){
1728 $this->gotoProfileFlagC = get_post('gotoProfileFlagC');
1729 }else{
1730 $this->gotoProfileFlagC = false;
1731 }
1733 if(isset($_POST['gotoProfileFlagL'])){
1734 $this->gotoProfileFlagL = get_post('gotoProfileFlagL');
1735 }else{
1736 $this->gotoProfileFlagL = false;
1737 }
1739 foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1740 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1741 $uattr = "use_".$attr;
1742 if(isset($_POST[$uattr])){
1743 $this->multi_boxes[] = $attr;
1744 }
1745 }
1746 if(isset($_POST['kiosk_server'])){
1747 $tmp = get_post('kiosk_server');
1748 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1749 $this->gotoKioskProfile_Server = get_post('kiosk_server');
1750 }
1751 }
1752 if(isset($_POST['kiosk_profile'])){
1753 $tmp = get_post('kiosk_profile');
1754 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1755 $this->gotoKioskProfile_Profile = get_post('kiosk_profile');
1756 }
1757 }
1759 }
1760 }
1762 /* Return plugin informations for acl handling
1763 #FIXME these ACLs should work for groups too */
1764 static function plInfo()
1765 {
1766 return (array("plShortName" => _("Desktop"),
1767 "plDescription" => _("Desktop settings"), // Description
1768 "plSelfModify" => TRUE,
1769 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1770 "plPriority" => 3, // Position in tabs
1771 "plSection" => array("personal" => _("My account")),
1772 "plCategory" => array("users",
1773 "groups","ogroups"),
1774 "plOptions" => array("resolution_hook" => array("type" => "string",
1775 "description" => _("Command to extend the list of possible screen resolutions"))),
1776 "plRequirements"=> array(
1777 'ldapSchema' => array('gotoEnvironment' => '>=2.7'),
1778 'onFailureDisablePlugin' => array(get_class())
1779 ),
1780 "plProperties" => array(
1782 array(
1783 "name" => "resolutions",
1784 "type" => "file",
1785 "default" => "",
1786 "description" => _("File containing additional resolutions for workstations and thin clients."),
1787 "check" => "gosaProperty::isReadableFile",
1788 "migrate" => "",
1789 "group" => "environment",
1790 "mandatory" => FALSE
1791 ),
1792 array(
1793 "name" => "kioskPath",
1794 "type" => "path",
1795 "default" => "/var/spool/kiosk",
1796 "description" => _("Directory to store KDE kiosk profiles."),
1797 "check" => "gosaProperty::isWriteablePath",
1798 "migrate" => "",
1799 "group" => "environment",
1800 "mandatory" => FALSE
1801 )
1802 ),
1805 "plProvidedAcls" => array(
1807 "gotoPrinter" => _("Printer") ,
1808 "gotoProfileServer" => _("Profile server") ,
1809 "gosaDefaultPrinter" => _("Default printer"),
1810 "gotoProfileQuota" => _("Profile quota") ,
1811 "gotoProfileFlagC" => _("Cache profile locally") ,
1812 "gotoShare" => _("Shares"),
1813 "gotoHotplugDeviceDN" => _("Hot-plug devices"),
1814 "gotoKioskProfile" => _("Kiosk profile") ,
1815 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1816 "gotoXResolution" => _("Resolution") ,
1817 "gotoLogonScript" => _("Log on script"))
1818 ));
1819 }
1820 }
1822 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1823 ?>