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");
69 var $attributes = array("uid","gotoProfileServer","gotoProfileFlags","gotoHotplugDeviceDN",
70 "gotoXResolution","gotoProfileQuota",
71 "gotoLogonScript",
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;
84 function environment (&$config, $dn= NULL)
85 {
86 plugin::plugin ($config, $dn);
88 /* Setting uid to default */
89 if(isset($this->attrs['uid'][0])){
90 $this->uid = $this->attrs['uid'][0];
91 }
93 /* Check : Are we currently editing a group or user dialog */
94 if((isset($this->attrs['cn'][0]))&&(!isset($this->attrs['uid'][0]))){
95 $suffix="Group";
96 $this->uid = $this->attrs['cn'][0];
97 $this->attrs['uid'] = $this->attrs['cn'][0];
98 $this->OrigCn = $this->attrs['cn'][0];
99 }else{
100 $suffix="User";
101 }
103 /* Get all Printer assignments */
104 $ldap = $this->config->get_ldap_link();
105 $ldap->cd($this->config->current['BASE']);
106 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."Printer=".$this->uid."))",array("*"));
107 while($printer = $ldap->fetch()){
108 $this->gotoPrinter[$printer['cn'][0]]=$printer;
109 $this->gotoPrinter[$printer['cn'][0]]['mode']="user";
110 }
111 $ldap->search("(&(objectClass=gotoPrinter)(goto".$suffix."AdminPrinter=".$this->uid."))",array("*"));
112 while($printer = $ldap->fetch()){
113 $this->gotoPrinter[$printer['cn'][0]]=$printer;
114 $this->gotoPrinter[$printer['cn'][0]]['mode']="admin";
115 }
118 /* Prepare hotplugs */
119 if(isset($this->attrs['gotoHotplugDeviceDN']) && is_array($this->attrs['gotoHotplugDeviceDN'])){
120 $ldap = $this->config->get_ldap_link();
121 $ldap->cd($this->config->current['BASE']);
122 for($i = 0 ; $i < $this->attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
123 $ldap->cat($this->attrs['gotoHotplugDeviceDN'][$i]);
124 if($ldap->count()){
125 $attrs = $ldap->fetch();
127 if(isset($attrs['gotoHotplugDevice'][0])){
128 $tmp = preg_split("/\|/",$attrs['gotoHotplugDevice'][0]);
129 $tmp2 = array();
130 $tmp2['name'] = $attrs['cn'][0];
131 $tmp2['description'] = $tmp[0];
132 $tmp2['id'] = $tmp[1];
133 $tmp2['produkt'] = $tmp[2];
134 $tmp2['vendor'] = $tmp[3];
135 $tmp2['dn'] = $attrs['dn'];
136 $this->gotoHotplugDevices[] = $tmp2;
137 }
138 }else{
139 msg_dialog::display(_("Warning"), sprintf(_("Device '%s' is not available anymore. It will be removed!"), $this->attrs['gotoHotplugDeviceDN'][$i]), WARNING_DIALOG);
140 }
141 }
142 }
145 /* prepare LogonScripts */
146 if((isset($this->attrs['gotoLogonScript']))&&(is_array($this->attrs['gotoLogonScript']))){
147 unset($this->attrs['gotoLogonScript']['count']);
148 foreach($this->attrs['gotoLogonScript'] as $device){
149 $tmp = $tmp2 = array();
150 $tmp = explode("|",$device);
151 $tmp2['LogonName'] = $tmp[0];
152 $tmp2['LogonPriority'] = $tmp[2];
153 if(preg_match("/O/i",$tmp[1])){
154 $tmp2['LogonOverload'] = "O";
155 }else{
156 $tmp2['LogonOverload'] = "";
157 }
158 if(preg_match("/L/i",$tmp[1])){
159 $tmp2['LogonLast'] = "L";
160 }else{
161 $tmp2['LogonLast'] = "";
162 }
163 $tmp2['LogonData'] = base64_decode($tmp[3]);
164 $tmp2['LogonDescription'] = $tmp[4];
165 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
166 }
167 }
169 /* Prepare Shares */
170 if((isset($this->attrs['gotoShare']))&&(is_array($this->attrs['gotoShare']))){
171 unset($this->attrs['gotoShare']['count']);
172 foreach($this->attrs['gotoShare'] as $share){
173 $tmp = $tmp2 = array();
174 $tmp = explode("|",$share);
175 $tmp2['server'] =$tmp[0];
176 $tmp2['name'] =$tmp[1];
178 /* Decode base64 if needed */
179 if (!preg_match('%/%', $tmp[2])){
180 $tmp2['mountPoint'] =base64_decode($tmp[2]);
181 } else {
182 $tmp2['mountPoint'] =$tmp[2];
183 }
185 if(isset($tmp[3])){
186 $tmp2['PwdHash'] =$tmp[3];
187 }else{
188 $tmp2['PwdHash'] ="";
189 }
190 if(isset($tmp[4])){
191 $tmp2['Username'] =$tmp[4];
192 }else{
193 $tmp2['Username'] ="";
194 }
195 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
196 }
197 }
199 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
200 $chr = $this->gotoProfileFlags[$i];
201 $name = "gotoProfileFlag".$chr;
202 $this->$name=$chr;
203 }
205 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
206 $this->useProfile = true;
207 }else{
208 $this->useProfile = false;
209 }
211 /* Set resolutions */
212 $this->gotoXResolutions = array("auto"=>_("auto"),
213 "640x480" => "640x480",
214 "800x600" => "800x600",
215 "1024x768" => "1024x768",
216 "1152x864" => "1152x864",
217 "1280x768" => "1280x768",
218 "1280x1024" => "1280x1024");
220 if($this->config->get_cfg_value("resolutions") != ""){
221 $file = $this->config->get_cfg_value("resolutions");
223 if(is_readable($file)){
224 $str = file_get_contents($file);
225 $lines = preg_split("/\n/",$str);
226 foreach($lines as $line){
227 $line = trim($line);
228 if(!empty($line)){
229 $this->gotoXResolutions[$line]=$line;
230 }
231 }
232 //natcasesort($this->gotoXResolutions);
233 }else{
234 msg_dialog::display(_("Configuration error"), sprintf(_("Cannot open file '%s'!"), $file), WARNING_DIALOG);
235 }
236 }
238 $this->gotoProfileServers= $config->getShareServerList() ;
239 $this->gotoShareSelections= $config->getShareList(true);
240 $this->gotoAvailableShares= $config->getShareList(false);
242 /* Ensure that a currently selected server will stay selected, even if the list of profile servers
243 is empty due to insufficient permissions.
244 */
245 if(count($this->gotoProfileServers) && !empty($this->gotoProfileServer)){
247 /* The currently selected profile server is outdated/no longer available */
248 if(!isset($this->gotoProfileServers[$this->gotoProfileServer])){
250 }else{
251 $c = $this->gotoProfileServers[$this->gotoProfileServer];
252 if(!preg_match("/r/",$c['ACL'])){
254 /* We are not allowed to read to currently selected server.
255 But to ensure that the selection will be kept after saving the account, we
256 override the current ACL tag.
257 */
258 $this->gotoProfileServers[$this->gotoProfileServer]['ACL'] .= "r";
259 }
260 }
261 }
262 $this->update_kiosk_profiles();
263 }
266 function update_kiosk_profiles()
267 {
268 $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
269 $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
271 $tmp1 = array("none" => array(_("disabled")));
272 $tmp2 = array("none" => _("disabled"));
273 $tmp3 = array();
274 $ldap = $this->config->get_ldap_link();
275 $ldap->cd($this->config->current['BASE']);
276 $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
277 $cnt = 0;
278 $ui = get_userinfo();
279 while($attrs = $ldap->fetch()){
280 $acl = $ui->get_permissions($attrs['dn'],"server/goKioskService","");
281 for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
282 if(preg_match("/r/",$acl) || $this->gotoKioskProfile_Server == $attrs['cn'][0]){
283 $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
284 $tmp1[$attrs['cn'][0]][] = $name;
285 $tmp3[$attrs['cn'][0]][$name] = $attrs['gotoKioskProfile'][$i];
286 $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
287 $cnt ++;
288 }
289 }
290 }
292 if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
293 $this->kiosk_enabled = TRUE;
294 }
296 $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
297 $this->gotoKioskProfiles['SERVERS'] = $tmp2;
298 $this->gotoKioskProfiles['MAP'] = $tmp3;
300 $error = false;
301 if(!isset($this->gotoKioskProfiles['SERVERS'][$this->gotoKioskProfile_Server])){
302 $error = true;
303 }elseif(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
304 $error = true;
305 }
306 if($error && !empty($this->gotoKioskProfile)){
307 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);
308 $this->gotoKioskProfile_Server ="none";
309 $this->gotoKioskProfile_Profile="";
310 }elseif(empty($this->gotoKioskProfile)){
311 $this->gotoKioskProfile_Server ="none";
312 $this->gotoKioskProfile_Profile="";
313 }
314 }
317 /* Detect type of edited object (user|group)*/
318 function detect_grouptype()
319 {
320 if((!isset($this->parent))&&(!$this->is_account)){
321 $this->is_group = false;
322 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
323 $this->is_group = true;
324 }else{
325 $this->is_group = false;
326 }
327 }
330 function execute()
331 {
333 /* Call parent execute */
334 plugin::execute();
335 /* Log view */
336 if($this->is_account && !$this->view_logged){
337 $this->view_logged = TRUE;
338 if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
339 new log("view","users/".get_class($this),$this->dn);
340 }else{
341 new log("view","groups/".get_class($this),$this->dn);
342 }
343 }
345 /* Check profile server */
346 if($this->acl_is_writeable("gotoProfileServer")){
348 if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
351 if(count($this->gotoProfileServers)){
353 /* Get First Profile */
354 $new = key($this->gotoProfileServers);
356 /* Another profile server found */
357 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
358 }else{
360 /* No other profile servers found */
361 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
362 $this->gotoProfileServer = "none";
363 }
364 }
365 }
367 $this->detect_grouptype();
369 /* Fill templating stuff */
370 $smarty= get_smarty();
371 $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
372 $display= "";
374 $smarty->assign("is_group",$this->is_group);
376 /* Prepare all variables for smarty */
377 foreach($this->attributes as $s_attr){
378 /* Set value*/
379 $smarty->assign($s_attr,$this->$s_attr);
381 /* Set checkbox state*/
382 if(empty($this->$s_attr)){
383 $smarty->assign($s_attr."CHK","");
384 }else{
385 $smarty->assign($s_attr."CHK"," checked ");
386 }
387 }
389 $tmp = $this->plInfo();
390 foreach($tmp['plProvidedAcls'] as $val => $desc){
391 $smarty->assign("$val"."ACL", $this->getacl($val));
392 }
394 /* Is accout enabled | are we editing from usermenu or admin menu
395 All these tab management is done here
396 */
399 /* Working from Usermenu an the Account is currently disbled
400 * this->parent : is only set if we are working in a list of tabs
401 * is_account : is only true if the needed objectClass is given
402 */
403 if((!isset($this->parent))&&(!$this->is_account)){
404 /* We are currently editing this tab from usermenu, but this account is not enabled */
405 $smarty->assign("is_account",$this->is_account);
406 /* Load template */
407 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
408 /* Avoid the "You are currently editing ...." message when you leave this tab */
409 $display .= back_to_main();
410 /* Display our message to the user */
411 return $display;
414 /* We are currently editing from group tabs, because
415 * $this->parent is set
416 * posixAccount is not set, so we are not in usertabs.
417 */
418 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
419 $smarty->assign("is_account","true");
420 $this->uid = $this->cn;
421 $this->attrs['uid'] = $this->cn;
423 /* Change state if needed */
424 if (isset($_POST['modify_state'])){
425 if(($this->acl_is_createable() && !$this->is_account) ||
426 ($this->acl_is_removeable() && $this->is_account)){
427 $this->is_account= !$this->is_account;
428 }
429 }
430 /* Group Dialog with enabled environment options */
431 if ($this->is_account){
432 $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
433 msgPool::featuresEnabled(_("Environment")));
434 } else {
436 /* Environment is disabled
437 If theres is no posixAccount enabled, you won't be able to enable
438 environment extensions
439 */
440 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
441 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
442 msgPool::featuresDisabled(_("Environment")));
443 return $display;
444 }elseif((isset($this->parent->by_object['ogroup']))){
445 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
446 msgPool::featuresDisabled(_("Environment")));
447 return $display;
448 }else{
449 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
450 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
451 return $display;
452 }
453 }
454 }else{
455 /* Editing from Usermenu
456 * Tell smarty that this accoutn is enabled
457 */
458 $smarty->assign("is_account","true");
460 /* Change state if needed */
461 if (isset($_POST['modify_state'])){
462 if(($this->acl_is_createable() && !$this->is_account) ||
463 ($this->acl_is_removeable() && $this->is_account)){
464 $this->is_account= !$this->is_account;
465 }
466 }
468 if(isset($this->parent)){
470 // 3. Account enabled . Editing from adminmenu
471 if ($this->is_account){
472 $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
473 msgPool::featuresEnabled(_("Environment")));
474 } else {
476 if($this->parent->by_object['posixAccount']->is_account==true){
477 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
478 msgPool::featuresDisabled(_("Environment")));
479 return $display;
480 }else{
481 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
482 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
483 return $display;
484 }
485 }
486 }
487 }
489 /* Reset header toggle */
490 if($this->multiple_support_active){
491 $display = "";
492 }
494 /* Account is Account : is_accounbt=true.
495 * Else we won't reach this.
496 */
498 /* Prepare all variables for smarty */
499 foreach($this->attributes as $s_attr){
500 /* Set value*/
501 $smarty->assign($s_attr,$this->$s_attr);
503 /* Set checkbox state*/
504 if(empty($this->$s_attr)){
505 $smarty->assign($s_attr."CHK","");
506 }else{
507 $smarty->assign($s_attr."CHK"," checked ");
508 }
509 }
511 $tmp = $this->plInfo();
512 foreach($tmp['plProvidedAcls'] as $val => $desc){
513 $smarty->assign("$val"."ACL", $this->getacl($val));
514 }
516 foreach(array("gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
517 $smarty->assign($s_attr."ACL",$this->getacl($s_attr));
518 }
520 if($this->read_only) {
521 $smarty->assign("gotoPrinterACL","r");
522 }else{
523 $smarty->assign("gotoPrinterACL","rw");
524 }
527 $smarty->assign("useProfile",$this->useProfile);
528 if(empty($this->useProfile) && !$this->multiple_support_active){
529 $smarty->assign("useProfileCHK","");
530 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer")));
531 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota")));
532 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC")));
533 }else{
534 $smarty->assign("useProfileCHK"," checked ");
535 }
537 $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer"));
538 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer").$this->getacl("gotoProfileQuota"));
540 /* HANDLE Profile Settings here
541 * Assign available Quota and resolution settings
542 * Get all available profile server
543 * Get cache checkbox
544 * Assign this all to Smarty
545 */
547 if(empty($this->gotoProfileFlagL)){
548 $smarty->assign("gotoProfileFlagLCHK"," ");
549 }else{
550 $smarty->assign("gotoProfileFlagLCHK"," checked ");
551 }
553 if(empty($this->gotoProfileFlagC)){
554 $smarty->assign("gotoProfileFlagCCHK"," ");
555 }else{
556 $smarty->assign("gotoProfileFlagCCHK"," checked ");
557 }
560 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
561 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
563 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
564 if(!is_array($this->gotoProfileServers)){
565 $this->gotoProfileServers =array();
566 }
568 /* Handle kiosk profiles*/
569 $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
570 $smarty->assign("kiosk_server" , $this->gotoKioskProfile_Server);
571 $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
572 $smarty->assign("kiosk_profile" , $this->gotoKioskProfile_Profile);
575 /* Logonscript Management
576 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
577 * Perform add Delete edit Posts
578 */
580 /* Dialog Save */
581 if(isset($_POST['LogonSave'])){
583 if(!$this->acl_is_writeable("gotoLogonScript")){
584 msg_dialog::display(_("Permission error"), msgPool::permModify(_("Logon scripts")), ERROR_DIALOG);
585 unset($this->dialog);
586 $this->dialog=FALSE;
587 $this->is_dialog=false;
588 }else{
589 $this->dialog->save_object();
590 if(count($this->dialog->check())!=0){
591 foreach($this->dialog->check() as $msg){
592 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
593 }
594 }else{
595 $tmp = $this->dialog->save();
596 unset($this->dialog);
597 $this->dialog=FALSE;
598 $this->is_dialog=false;
600 if($this->multiple_support_active){
601 $tmp['UsedByAllUsers'] = TRUE;
602 }
603 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
604 }
605 }
606 }
609 /* Dialog Quit without saving */
610 if(isset($_POST['LogonCancel'])){
611 $this->is_dialog= false;
612 unset($this->dialog);
613 $this->dialog= FALSE;
614 }
616 /* Check Edit Del New Posts for a selected LogonScript */
617 if($this->acl_is_writeable("gotoLogonScript") &&
618 (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
620 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
621 * In this case we create a new Logon Script.
622 */
623 if(isset($_POST['gotoLogonScriptNew'])){
624 $this->is_dialog = true;
625 $this->dialog = new logonManagementDialog($this->config,$this->dn);
626 }
628 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
629 * We only can delete if there is an entry selected.
630 */
631 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
632 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
633 }
635 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
636 * There must be an entry selected to perform edit request.
637 */
638 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
639 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
640 $this->is_dialog = true;
641 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
642 }
643 }
645 /* Append List to smarty*/
646 if($this->multiple_support_active){
647 $smarty->assign("gotoLogonScripts", $this->gotoLogonScripts);
648 $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
649 }else{
650 $ls = $this->printOutLogonScripts();
651 $smarty->assign("gotoLogonScripts", $ls);
652 $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
653 $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
654 }
656 /* In this section server shares will be defined
657 * A user can select one of the given shares and a mount point
658 * and attach this combination to his setup.
659 */
661 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
662 if(!is_array($this->gotoShareSelections)){
663 $this->gotoShareSelections = array();
664 }
665 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
667 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
668 * This entry will be, a combination of mountPoint and sharedefinitions
669 */
670 if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
672 /* We assign a share to this user, if we don't know where to mount the share */
673 if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
674 msg_dialog::display(_("Error"), msgPool::invalid(_("Share")), ERROR_DIALOG);
675 }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
676 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
677 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
678 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point"), "/[^\s]/"), ERROR_DIALOG);
679 }elseif(!(
680 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
681 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
682 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
683 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
684 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
685 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
686 preg_match("/^%/",$_POST['gotoShareMountPoint'])
687 )
688 ){
689 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
690 }else{
691 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
692 $s_mount = $_POST['gotoShareMountPoint'];
693 $s_user = $_POST['ShareUser'];
694 /* Preparing the new assignment */
695 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
696 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
697 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
698 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
700 if($this->multiple_support_active){
701 $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
702 }
703 }
704 }
706 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
707 * If there is no defined share selected, we will abort the deletion without any message
708 */
709 $once = true;
710 if($this->acl_is_writeable("gotoShare")){
711 foreach($_POST as $name => $value){
712 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
713 $once = false;
714 $key = preg_replace("/^gotoShareDel_/","",$name);
715 $key = preg_replace("/_+[xy]$/","",$key);
716 $key = base64_decode($key);
717 if(isset($this->gotoShares[$key])) {
718 unset($this->gotoShares[$key]);
719 }
721 /* Remove corresponding password entry, too. This is a workaround
722 to get rid of old-style entries. */
723 $key= preg_replace("/\|/", "|!", $key);
724 if(isset($this->gotoShares[$key])) {
725 unset($this->gotoShares[$key]);
726 }
727 }
728 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
729 $once = false;
730 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
731 $key = preg_replace("/_+[xy]$/","",$key);
732 $key = base64_decode($key);
733 $this->gotoShares[$key]['PwdHash'] = "";
734 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
735 unset($this->gotoShares[$key]);
736 }
737 }
738 }
739 }
740 $divlistShares = new divSelectBox("gotoShares");
741 $divlistShares->SetHeight(100);
744 $tmp = array();
745 if($this->acl_is_readable("gotoShare")){
746 $tmp = $this->printOutAssignedShares();
747 }
750 foreach($tmp as $key => $value){
751 $img = "";
753 /* Skip apssword only entries */
754 if( empty($this->gotoShares[$key]['server']) &&
755 empty($this->gotoShares[$key]['name']) &&
756 empty($this->gotoShares[$key]['mountPoint']) &&
757 empty($this->gotoShares[$key]['Username'])){
758 continue;
759 }
761 $color = "";
762 if($this->multiple_support_active){
763 if($this->gotoShares[$key]['UsedByAllUsers']){
764 $value .= " (<b>"._("Used by all users")."</b>)";
765 }else{
766 $color = "color: #999999;";
767 $value .= " (<b>"._("Used by some users")."</b>)";
768 }
769 }
771 /* Check if entry starts with an ! */
772 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
774 /* If we are currently editing groups environment, skip those ! entries */
775 if($this->is_group) continue;
777 /* Create pwd reset images */
778 if($this->gotoShares[$key]['PwdHash'] != ""){
779 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)."
780 'src='plugins/goto/images/list_reset_password.png' alt='"._("Reset password hash")."'
781 title='"._("Reset password hash")."'>";
782 }
783 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
784 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
785 }else{
787 /* Create pwd reset img && delete image */
788 if($this->gotoShares[$key]['PwdHash'] != ""){
789 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)."
790 'src='plugins/goto/images/list_reset_password.png' alt='"._("Reset password hash")."'
791 title='"._("Reset password hash")."'>";
792 $img.= " ";
793 }
794 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/lists/trash.png' alt='".msgPool::delButton()."'
795 title='"._("Delete share entry")."'>";
796 $field1 = array("string" => $value , "attach" => "style='".$color."'");
797 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
798 }
799 $divlistShares->AddEntry(array($field1,$field2));
800 }
801 $smarty->assign("divlistShares",$divlistShares->DrawList());
803 /* Hotplug devices will be handled here
804 * There are 3 possible methods for this feature
805 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
806 * Delete will erase an entry, the entry must be selcted in the ListBox first
807 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
808 */
810 /* We have to delete the selected hotplug from the list*/
811 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
812 if($this->acl_is_writeable("gotoHotplugDevice")){
813 foreach($_POST['gotoHotplugDevice_post'] as $name){
814 unset($this->gotoHotplugDevices[$name]);
815 }
816 }
817 }
819 /* There are already defined hotplugs from other users we could use */
820 if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
821 $tmp =array();
822 foreach($this->gotoHotplugDevices as $plugs){
823 $tmp[] = $plugs['name'];
824 }
825 $this->dialog = new hotplugSelect($this->config, get_userinfo());
826 $this->is_dialog = true;
827 }
829 /* Dialog Aborted */
830 if(isset($_POST['hotplugSelect_cancel'])){
831 $this->dialog= FALSE;
832 $this->is_dialog = false;
833 }
835 /* Dialod saved */
836 if(isset($_POST['hotplugSelect_save'])){
838 $res = $this->dialog->save();
839 foreach($res as $hotplug){
840 $name = $hotplug['cn'][0];
841 $entry['dn'] = $hotplug['dn'];
843 /* Set class values */
844 $tmp = preg_split("/\|/",$hotplug['gotoHotplugDevice'][0]);
845 $entry['name'] = $hotplug['cn'][0];
846 $entry['description'] = $tmp[0];
847 $entry['id'] = $tmp[1];
848 $entry['produkt'] = $tmp[2];
849 $entry['vendor'] = $tmp[3];
850 if($this->multiple_support_active){
851 $entry['UsedByAllUsers'] = TRUE;
852 }
853 $this->gotoHotplugDevices[$name]= $entry;
854 }
855 $this->dialog= FALSE;
856 $this->is_dialog = false;
857 }
859 if($this->dialog instanceOf hotplugSelect){
861 // Build up blocklist
862 session::set('filterBlacklist', array('cn' => array_keys($this->gotoHotplugDevices)));
863 return($this->dialog->execute());
864 }
866 if($this->multiple_support_active){
867 $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
868 }else{
869 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
870 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
871 }
873 /* Printer Assignment will managed below
874 * A printer can be assigned in two different ways and two different types
875 * There are 2 types of users assigned to a printer : user and admin
876 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
877 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
878 */
880 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
881 if(isset($_POST['gotoPrinterAdd'])){
882 $this->dialog = new printerSelect($this->config,get_userinfo());
883 $this->is_dialog=true;
884 }
886 if(isset($_POST['printerSelect_cancel']) && $this->dialog instanceOf printerSelect){
887 $this->is_dialog=false;
888 $this->dialog=FALSE;
889 }
891 if(isset($_POST['printerSelect_save']) && $this->dialog instanceOf printerSelect){
893 $res = $this->dialog->save();
894 foreach($res as $printer){
896 $pname = $printer['cn'][0];
897 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'], $printer['dn'],"printer");
898 $printerObj->set_acl_base($printer['dn']);
900 $type = false;
903 if($this->is_group){
904 if($this->dn == "new"){
905 $type = "AddGroup";
906 }elseif(isset($this->NewDeletedPrinters[$pname])){
907 $type = "AddGroup";
908 }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
909 $type = "AddGroup";
910 }
911 }else{
912 if($this->multiple_support_active){
913 $type = "AddUser";
914 }elseif(isset($this->NewDeletedPrinters[$pname])){
915 $type = "AddUser";
916 }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
917 $type = "AddUser";
918 }
919 }
921 if($type){
922 $this->gotoPrinter[$pname]=$printer;
923 $this->gotoPrinter[$pname]['mode']="user";
924 $this->add_del_printer_member_was_called = true;
926 $this->NewAddedPrinters[$pname] = $pname;
927 if(isset($this->NewDeletedPrinters[$pname])){
928 unset($this->NewDeletedPrinters[$pname]);
929 }
930 }
931 }
933 $this->is_dialog=false;
934 unset($this->dialog);
935 $this->dialog =FALSE;
936 }
938 // Display printer selection dialog
939 if($this->dialog instanceOf printerSelect){
941 // Build up blocklist
942 session::set('filterBlacklist',array('cn' => array_keys($this->gotoPrinter)));
943 return($this->dialog->execute());
944 }
947 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
948 $printer = $_POST['gotoPrinterSel'];
949 foreach($printer as $pname){
951 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
952 $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
954 $type = false;
955 if($this->is_group){
956 if(isset($this->NewAddedPrinters[$pname])){
957 $type = "Group";
958 }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
959 $type = "Group";
960 }
961 }else{
962 if(isset($this->NewAddedPrinters[$pname])){
963 $type = "User";
964 }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
965 $type = "User";
966 }
967 }
968 if($type){
969 $this->add_del_printer_member_was_called = true;
970 unset($this->gotoPrinter[$pname]);
972 $this->NewDeletedPrinters[$pname] = $pname;
973 if(isset($this->NewAddedPrinters[$pname])){
974 UNSET($this->NewAddedPrinters[$pname]);
975 }
976 }
977 }
978 }
980 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
981 $printers = $_POST['gotoPrinterSel'];
982 $this->add_del_printer_member_was_called = true;
983 foreach($printers as $printer){
984 if($this->gotoPrinter[$printer]['mode']=="user"){
985 $this->gotoPrinter[$printer]['mode']="admin";
986 }else{
987 $this->gotoPrinter[$printer]['mode']="user";
988 }
989 }
990 }
992 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
993 if($this->is_group){
994 msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
995 }else{
996 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
997 $this->gosaDefaultPrinter= "";
998 } else {
999 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
1000 }
1001 }
1002 }
1004 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
1006 /* General behavior */
1007 if(is_object($this->dialog)){
1008 $this->dialog->save_object();
1009 $disp =$this->dialog->execute();
1010 return($disp);
1011 }
1013 /* Assign used attributes for multiple edit */
1014 foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
1015 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
1016 $ubox ="use_".$box;
1017 if(in_array($box,$this->multi_boxes)){
1018 $smarty->assign($ubox,TRUE);
1019 }else{
1020 $smarty->assign($ubox,FALSE);
1021 }
1022 }
1024 /* Als smarty vars are set. Get smarty template and generate output */
1025 $smarty->assign("multiple_support",$this->multiple_support_active);
1026 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
1027 return($display);
1028 }
1030 function remove_from_parent()
1031 {
1032 /* only if it was an account*/
1033 if (!$this->initially_was_account){
1034 return;
1035 }
1037 /* include global link_info */
1038 $ldap= $this->config->get_ldap_link();
1040 /* Remove and write to LDAP */
1041 plugin::remove_from_parent();
1043 /* Don't save our template variables */
1044 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1046 /* Skip all these attributes */
1047 foreach($skip as $del){
1048 unset($this->attrs[$del]);
1049 }
1051 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1053 $ldap->cd($this->dn);
1054 $this->cleanup();
1055 $ldap->modify ($this->attrs);
1057 if($this->is_group){
1058 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1059 }else{
1060 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1061 }
1063 if (!$ldap->success()){
1064 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1065 }
1067 /* Optionally execute a command after we're done */
1068 $this->handle_post_events("remove",array("uid" => $this->uid));
1069 }
1072 /* Save data to object */
1073 function save_object()
1074 {
1075 /* Get all Posted vars
1076 * Setup checkboxes
1077 */
1078 if(isset($_POST['iamposted'])){
1080 $PACL = $this->getacl("gotoProfileServer").$this->getacl("gotoProfileQuota");
1082 if(isset($_POST['kiosk_server'])){
1083 $tmp = $_POST['kiosk_server'];
1084 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1085 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1086 }
1087 }
1088 if(isset($_POST['kiosk_profile'])){
1089 $tmp = $_POST['kiosk_profile'];
1090 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1091 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1092 }
1093 }
1095 if(preg_match("/w/",$PACL)){
1096 if(isset($_POST['useProfile'])){
1097 $this->useProfile = true;
1098 }else{
1099 $this->useProfile = false;
1100 }
1101 }
1103 if($this->acl_is_writeable("gotoProfileFlagC")){
1104 if(isset($_POST['gotoProfileFlagC'])){
1105 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1106 }else{
1107 $this->gotoProfileFlagC = false;
1108 }
1109 }
1111 if($this->acl_is_writeable("gotoProfileFlagL")){
1112 if(isset($_POST['gotoProfileFlagL'])){
1113 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1114 }else{
1115 $this->gotoProfileFlagL = false;
1116 }
1117 }
1119 plugin::save_object();
1120 foreach($this->attributes as $s_attr){
1121 if((!isset($_POST[$s_attr])) ||
1122 in_array($s_attr,array("gosaDefaultPrinter","gotoShare","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1123 if(!$this->acl_is_writeable($s_attr)){
1124 continue;
1125 }else{
1126 if(isset($_POST[$s_attr])){
1127 $this->$s_attr = $_POST[$s_attr];
1128 }else{
1129 $this->$s_attr = false;
1130 }
1131 }
1132 }
1133 }
1134 }
1137 /* Check supplied data */
1138 function check()
1139 {
1140 /* Call common method to give check the hook */
1141 $message= plugin::check();
1143 $this->detect_grouptype();
1145 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1146 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1147 }
1148 if(!isset($this->attrs['objectClass'])){
1149 $this->attrs['objectClass']=array();
1150 }
1151 if(!$this->is_group){
1152 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1153 $message[]= msgPool::featuresDisabled(_("environment"),_("POSIX"));
1154 }
1155 }
1156 return ($message);
1157 }
1160 /* Save to LDAP */
1161 function save()
1162 {
1163 /* If group was renamed, all printer settings get lost
1164 */
1165 /* only save changed variables ....*/
1166 if ($this->gotoKioskProfile_Server != "none"){
1167 $method = $this->gotoKioskProfiles['MAP'][$this->gotoKioskProfile_Server][$this->gotoKioskProfile_Profile];
1168 $this->gotoKioskProfile= $method;
1169 }else{
1170 $this->gotoKioskProfile= array();
1171 }
1173 plugin::save();
1174 $ldap= $this->config->get_ldap_link();
1176 $realyUsedAttrs= array();
1178 /* Save already used objectClasses */
1179 $ocs = $this->attrs['objectClass'];
1180 unset($ocs['count']);
1181 $this->attrs = array();
1182 $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1184 /* 1. Search all printers that have our uid/cn as member
1185 * 2. Delete this uid/cn from every single entry and save it again.
1186 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1187 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
1188 */
1190 $this->detect_grouptype();
1192 if($this->add_del_printer_member_was_called){
1194 $types = array( "gotoUserPrinter" => "AddUser",
1195 "gotoGroupPrinter" => "AddGroup",
1196 "gotoUserAdminPrinter" => "AddAdminUser",
1197 "gotoGroupAdminPrinter" => "AddAdminGroup");
1199 if($this->is_group){
1200 $s_suffix = "Group";
1201 $useVar = "cn";
1202 }else{
1203 $useVar = "uid";
1204 $s_suffix = "User";
1205 }
1207 /* Remove old entries */
1208 $ldap->cd($this->config->current['BASE']);;
1209 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1210 while($attr = $ldap->fetch()){
1211 $printerObj = NULL;
1212 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1213 $printerObj->set_acl_base($attr['dn']);
1214 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1215 $printerObj->by_object['printgeneric']->save();
1216 }
1218 $ldap->cd($this->config->current['BASE']);;
1219 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$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."AdminPrinter"],$this->$useVar);
1225 $printerObj->by_object['printgeneric']->save();
1226 }
1228 foreach($this->gotoPrinter as $printer){
1229 $printerObj = NULL;
1230 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1231 $printerObj->set_acl_base($printer['dn']);
1234 if($printer['mode'] == "admin") {
1235 $attribute = "goto".$s_suffix."AdminPrinter";
1236 }else{
1237 $attribute = "goto".$s_suffix."Printer";
1238 }
1240 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1241 $printerObj->by_object['printgeneric']->save();
1242 }
1243 }
1245 /* Prepare HotPlug devices */
1246 $this->attrs['gotoHotplugDeviceDN'] = array();
1247 foreach($this->gotoHotplugDevices as $name => $device){
1248 $this->attrs['gotoHotplugDeviceDN'][]= LDAP::fix($device['dn']);
1249 }
1251 /* Prepare LogonScripts */
1252 $this->attrs['gotoLogonScript'] = array();
1253 foreach($this->gotoLogonScripts as $name => $script){
1254 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1255 $script['LogonOverload'].$script['LogonLast']."|".
1256 $script['LogonPriority']."|".
1257 base64_encode($script['LogonData'])."|".
1258 $script['LogonDescription'];
1259 }
1261 /* Prepare Shares */
1262 $this->attrs['gotoShare']=array();
1263 foreach($this->gotoShares as $name => $share){
1264 $mntp= $share['mountPoint'];
1265 if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1266 $mntp= base64_encode($mntp);
1267 }
1268 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1269 }
1272 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1273 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1275 foreach($saveThis as $tosave){
1276 if(!empty($this->$tosave)){
1277 $this->attrs[$tosave]=$this->$tosave;
1278 }else{
1279 $this->attrs[$tosave]=array();
1280 }
1281 }
1283 /* Prepare Flags */
1284 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1285 if(empty($this->attrs['gotoProfileFlags'][0])){
1286 $this->attrs['gotoProfileFlags']=array();
1287 }
1289 if($this->useProfile == false){
1290 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1291 $this->attrs['gotoProfileServer']= array();
1292 }
1294 $ldap->cat ($this->dn, array('dn'));
1295 if ($ldap->fetch()){
1296 $mode= "modify";
1297 } else {
1298 $mode= "add";
1299 $ldap->cd($this->config->current['BASE']);
1300 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1301 }
1303 $ldap->cd($this->dn);
1304 $this->cleanup();
1305 $ldap->$mode($this->attrs);
1307 $cat = "users";
1308 if($this->is_group){
1309 $cat = "groups";
1310 }
1312 /* Log last action */
1313 if($this->initially_was_account){
1314 new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1315 }else{
1316 new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1317 }
1319 if (!$ldap->success()){
1320 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1321 }
1322 $this->handle_post_events($mode,array("uid"=>$this->uid));
1323 }
1325 /* Generate ListBox frindly output for the defined shares
1326 * Possibly Add or remove an attribute here,
1327 */
1328 function printOutAssignedShares()
1329 {
1330 $a_return = array();
1331 if(is_array($this->gotoShares)){
1332 foreach($this->gotoShares as $share){
1333 if(preg_match("/^!/",$share['server'])){
1334 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1335 }else{
1336 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1337 }
1338 }
1339 natcasesort($a_return);
1340 }
1341 return($a_return);
1342 }
1344 /* Generate ListBox frindly output for the definedhotplugs
1345 * Possibly Add or remove an attribute here,
1346 */
1347 function printOutHotPlugDevices()
1348 {
1349 $a_return= array();
1350 if(is_array($this->gotoHotplugDevices)){
1351 foreach($this->gotoHotplugDevices as $key=>$device){
1352 $a_return[$key] = $device['name']." - ".$device['id'];
1353 }
1354 }
1355 return($a_return);
1356 }
1358 /* Generates ListBox frienly output of used printer devices
1359 * Append ' - admin' if printer is used in admin mode
1360 */
1361 function printOutPrinterDevices()
1362 {
1363 $a_return = array();
1365 if(is_array($this->gotoPrinter)){
1366 foreach($this->gotoPrinter as $printer){
1367 if($printer['mode'] == 'admin'){
1368 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1369 }else{
1370 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1371 }
1372 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1373 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1374 }
1375 }
1376 }
1377 asort($a_return);
1378 return($a_return);
1379 }
1382 function PrepareForCopyPaste($source)
1383 {
1384 plugin::PrepareForCopyPaste($source);
1386 $class= get_class($this);
1387 $o_source = new $class($this->config,$source['dn']);
1388 foreach($this->CopyPasteVars as $attr){
1389 $this->$attr = $o_source->$attr;
1390 }
1391 }
1394 function saveCopyDialog()
1395 {
1396 if(isset($_POST['cn'])){
1397 $this->cn = $_POST['cn'];
1398 $this->uid = $_POST['cn'];
1399 }
1400 }
1403 /* Generates ListBox frienly output of used logonscripts
1404 */
1405 function printOutLogonScripts()
1406 {
1407 $a_return = array();
1408 if(is_array($this->gotoLogonScripts)){
1409 foreach($this->gotoLogonScripts as $script){
1410 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1411 }
1412 }
1413 return($a_return);
1414 }
1417 function multiple_execute()
1418 {
1419 /* Reset header toggle */
1420 $this->is_account = TRUE;
1421 return($this->execute());
1422 }
1425 /* Initialize plugin with given atribute arrays
1426 */
1427 function init_multiple_support($attrs,$all)
1428 {
1429 plugin::init_multiple_support($attrs,$all);
1431 /* Prepare Shares */
1432 if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1433 unset($this->multi_attrs_all['gotoShare']['count']);
1434 foreach($this->multi_attrs_all['gotoShare'] as $share){
1435 $tmp = $tmp2 = array();
1436 $tmp = explode("|",$share);
1437 $tmp2['server'] =$tmp[0];
1438 $tmp2['name'] =$tmp[1];
1440 /* Decode base64 if needed */
1441 if (!preg_match('%/%', $tmp[2])){
1442 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1443 } else {
1444 $tmp2['mountPoint'] =$tmp[2];
1445 }
1447 if(isset($tmp[3])){
1448 $tmp2['PwdHash'] =$tmp[3];
1449 }else{
1450 $tmp2['PwdHash'] ="";
1451 }
1452 if(isset($tmp[4])){
1453 $tmp2['Username'] =$tmp[4];
1454 }else{
1455 $tmp2['Username'] ="";
1456 }
1457 $tmp2['UsedByAllUsers'] = FALSE;
1458 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1459 }
1460 }
1462 /* Prepare Shares */
1463 if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1464 unset($this->multi_attrs['gotoShare']['count']);
1465 foreach($this->multi_attrs['gotoShare'] as $share){
1466 $tmp = $tmp2 = array();
1467 $tmp = explode("|",$share);
1468 $tmp2['server'] =$tmp[0];
1469 $tmp2['name'] =$tmp[1];
1471 /* Decode base64 if needed */
1472 if (!preg_match('%/%', $tmp[2])){
1473 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1474 } else {
1475 $tmp2['mountPoint'] =$tmp[2];
1476 }
1478 if(isset($tmp[3])){
1479 $tmp2['PwdHash'] =$tmp[3];
1480 }else{
1481 $tmp2['PwdHash'] ="";
1482 }
1483 if(isset($tmp[4])){
1484 $tmp2['Username'] =$tmp[4];
1485 }else{
1486 $tmp2['Username'] ="";
1487 }
1488 $tmp2['UsedByAllUsers'] = TRUE;
1489 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1490 }
1491 }
1494 /* prepare LogonScripts */
1495 if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1496 unset($this->multi_attrs_all['gotoLogonScript']['count']);
1497 foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1498 $tmp = $tmp2 = array();
1499 $tmp = explode("|",$device);
1500 $tmp2['LogonName'] = $tmp[0];
1501 $tmp2['LogonPriority'] = $tmp[2];
1502 if(preg_match("/O/i",$tmp[1])){
1503 $tmp2['LogonOverload'] = "O";
1504 }else{
1505 $tmp2['LogonOverload'] = "";
1506 }
1507 if(preg_match("/L/i",$tmp[1])){
1508 $tmp2['LogonLast'] = "L";
1509 }else{
1510 $tmp2['LogonLast'] = "";
1511 }
1512 $tmp2['LogonData'] = base64_decode($tmp[3]);
1513 $tmp2['LogonDescription'] = $tmp[4];
1514 $tmp2['UsedByAllUsers'] = FALSE;
1515 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1516 }
1517 }
1519 /* prepare LogonScripts */
1520 if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1521 unset($this->multi_attrs['gotoLogonScript']['count']);
1522 foreach($this->multi_attrs['gotoLogonScript'] as $device){
1523 $tmp = $tmp2 = array();
1524 $tmp = explode("|",$device);
1525 $tmp2['LogonName'] = $tmp[0];
1526 $tmp2['LogonPriority'] = $tmp[2];
1527 if(preg_match("/O/i",$tmp[1])){
1528 $tmp2['LogonOverload'] = "O";
1529 }else{
1530 $tmp2['LogonOverload'] = "";
1531 }
1532 if(preg_match("/L/i",$tmp[1])){
1533 $tmp2['LogonLast'] = "L";
1534 }else{
1535 $tmp2['LogonLast'] = "";
1536 }
1537 $tmp2['LogonData'] = base64_decode($tmp[3]);
1538 $tmp2['LogonDescription'] = $tmp[4];
1539 $tmp2['UsedByAllUsers'] = TRUE;
1540 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1541 }
1542 }
1544 /* Prepare hotplugs */
1545 if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1546 $ldap = $this->config->get_ldap_link();
1547 $ldap->cd($this->config->current['BASE']);
1548 for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1549 $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1550 if($ldap->count()){
1551 $multi_attrs_all = $ldap->fetch();
1553 if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1554 $tmp = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1555 $tmp2 = array();
1556 $tmp2['name'] = $multi_attrs_all['cn'][0];
1557 $tmp2['description'] = $tmp[0];
1558 $tmp2['id'] = $tmp[1];
1559 $tmp2['produkt'] = $tmp[2];
1560 $tmp2['vendor'] = $tmp[3];
1561 $tmp2['dn'] = $multi_attrs_all['dn'];
1562 $tmp2['UsedByAllUsers'] = FALSE;
1563 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1564 }
1565 }
1566 }
1567 }
1569 /* Prepare hotplugs */
1570 if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1571 $ldap = $this->config->get_ldap_link();
1572 $ldap->cd($this->config->current['BASE']);
1573 for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1574 $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1575 if($ldap->count()){
1576 $multi_attrs = $ldap->fetch();
1578 if(isset($multi_attrs['gotoHotplugDevice'][0])){
1579 $tmp = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1580 $tmp2 = array();
1581 $tmp2['name'] = $multi_attrs['cn'][0];
1582 $tmp2['description'] = $tmp[0];
1583 $tmp2['id'] = $tmp[1];
1584 $tmp2['produkt'] = $tmp[2];
1585 $tmp2['vendor'] = $tmp[3];
1586 $tmp2['dn'] = $multi_attrs['dn'];
1587 $tmp2['UsedByAllUsers'] = TRUE;
1588 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1589 }
1590 }
1591 }
1592 }
1593 $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1594 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1595 $chr = $this->gotoProfileFlags[$i];
1596 $name = "gotoProfileFlag".$chr;
1597 $this->$name=$chr;
1598 }
1599 $this->update_kiosk_profiles();
1600 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1602 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1603 $this->useProfile = true;
1604 }else{
1605 $this->useProfile = false;
1606 }
1608 }
1611 function set_multi_edit_values($attrs)
1612 {
1613 $shares = $this->gotoShares;
1614 $scripts= $this->gotoLogonScripts;
1615 $plugs= $this->gotoHotplugDevices;
1616 plugin::set_multi_edit_values($attrs);
1618 $this->gotoShares = $shares;
1619 $this->gotoLogonScripts = $scripts;
1620 $this->gotoHotplugDevices = $plugs;
1622 foreach($attrs['gotoShares'] as $name => $share){
1623 if($share['UsedByAllUsers'] == TRUE){
1624 $this->gotoShares[$name] = $share;
1625 }
1626 }
1627 foreach($this->gotoShares as $name => $share){
1628 if(!isset($attrs['gotoShares'][$name])){
1629 unset($this->gotoShares[$name]);
1630 }
1631 }
1632 foreach($attrs['gotoLogonScripts'] as $name => $script){
1633 if($script['UsedByAllUsers'] == TRUE){
1634 $this->gotoLogonScripts[$name] = $script;
1635 }
1636 }
1637 foreach($this->gotoLogonScripts as $name => $script){
1638 if(!isset($attrs['gotoLogonScripts'][$name])){
1639 unset($this->gotoLogonScripts[$name]);
1640 }
1641 }
1642 $tmp = array();
1643 foreach($this->gotoHotplugDevices as $entry){
1644 $tmp[$entry['dn']] = $entry;
1645 }
1647 foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1648 if($plug['UsedByAllUsers'] == TRUE){
1649 $tmp[$plug['dn']] = $plug;
1650 }
1651 }
1652 foreach($tmp as $name => $plug){
1653 $found = false;
1654 foreach($attrs['gotoHotplugDevices'] as $test){
1655 if($test['dn'] == $name){
1656 $found = true;
1657 }
1658 }
1659 if(!$found){
1660 unset($tmp[$name]);
1661 }
1662 }
1663 }
1666 /* Return selected values for multiple edit */
1667 function get_multi_edit_values()
1668 {
1669 $ret = plugin::get_multi_edit_values();
1670 $ret['gotoShares'] = $this->gotoShares;
1671 $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1672 $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1674 if(in_array("gotoPrinter",$this->multi_boxes)){
1675 $ret['gotoPrinter'] = $this->gotoPrinter;
1676 $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1677 $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1679 /* Force printer reset */
1680 $ret['add_del_printer_member_was_called'] = TRUE;
1681 }
1683 if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1684 $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1685 }
1687 if(in_array("useProfile",$this->multi_boxes)){
1688 $ret['useProfile']=$this->useProfile;
1689 if(in_array("gotoProfileServer",$this->multi_boxes)){
1690 $ret['gotoProfileServer']=$this->gotoProfileServer;
1691 }
1692 if(in_array("gotoProfileQuota",$this->multi_boxes)){
1693 $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1694 }
1695 if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1696 $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1697 }
1698 }
1699 if(in_array("gotoXResolution",$this->multi_boxes)){
1700 $ret['gotoXResolution'] = $this->gotoXResolution;
1701 }
1702 if(in_array("kiosk_server",$this->multi_boxes)){
1703 $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1704 $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1705 }
1706 return($ret);
1707 }
1710 function multiple_check()
1711 {
1712 $message = plugin::multiple_check();
1713 $this->detect_grouptype();
1715 if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
1716 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1717 }
1718 return($message);
1719 }
1722 function multiple_save_object()
1723 {
1724 if(isset($_POST['environment_multiple_posted'])){
1725 plugin::multiple_save_object();
1727 if(isset($_POST['useProfile'])){
1728 $this->useProfile = true;
1729 }else{
1730 $this->useProfile = false;
1731 }
1732 if(isset($_POST['gotoProfileFlagC'])){
1733 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1734 }else{
1735 $this->gotoProfileFlagC = false;
1736 }
1738 if(isset($_POST['gotoProfileFlagL'])){
1739 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1740 }else{
1741 $this->gotoProfileFlagL = false;
1742 }
1744 foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1745 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1746 $uattr = "use_".$attr;
1747 if(isset($_POST[$uattr])){
1748 $this->multi_boxes[] = $attr;
1749 }
1750 }
1751 if(isset($_POST['kiosk_server'])){
1752 $tmp = $_POST['kiosk_server'];
1753 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1754 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1755 }
1756 }
1757 if(isset($_POST['kiosk_profile'])){
1758 $tmp = $_POST['kiosk_profile'];
1759 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1760 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1761 }
1762 }
1764 }
1765 }
1767 /* Return plugin informations for acl handling
1768 #FIXME these ACLs should work for groups too */
1769 static function plInfo()
1770 {
1771 return (array("plShortName" => _("Environment"),
1772 "plDescription" => _("Environment settings"), // Description
1773 "plSelfModify" => TRUE,
1774 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1775 "plPriority" => 3, // Position in tabs
1776 "plSection" => array("personal" => _("My account")),
1777 "plCategory" => array("users",
1778 "groups"),
1779 "plOptions" => array("resolution_hook" => array("type" => "string",
1780 "description" => _("Command to extend the list of possible screen resolutions"))),
1782 "plProvidedAcls" => array(
1784 "gotoPrinter" => _("Printer") ,
1785 "gotoProfileServer" => _("Profile server") ,
1786 "gosaDefaultPrinter" => _("Default printer"),
1787 "gotoProfileQuota" => _("Profile quota") ,
1788 "gotoProfileFlagC" => _("Cache profile localy") ,
1789 "gotoShare" => _("Shares"),
1790 "gotoHotplugDeviceDN" => _("Hotplug devices"),
1791 "gotoKioskProfile" => _("Kiosk profile") ,
1792 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1793 "gotoXResolution" => _("Resolution") ,
1794 "gotoLogonScript" => _("Logon script"))
1795 ));
1796 }
1797 }
1799 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1800 ?>