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 "gotoLogonScripts","gotoLogonScript",
72 "gotoPrinter", "gosaDefaultPrinter",
73 "gotoShares","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 = split("\|",$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 = split("\|",$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(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
221 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
223 if(is_readable($file)){
224 $str = file_get_contents($file);
225 $lines = 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 /* Are we editing from MyAccount and not editing a user */
346 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
348 /* Check profile server */
349 if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
351 if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
354 if(count($this->gotoProfileServers)){
356 /* Get First Profile */
357 $new = key($this->gotoProfileServers);
359 /* Another profile server found */
360 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
361 }else{
363 /* No other profile servers found */
364 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
365 $this->gotoProfileServer = "none";
366 }
367 }
368 }
370 $this->detect_grouptype();
372 /* Fill templating stuff */
373 $smarty= get_smarty();
374 $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
375 $display= "";
377 $smarty->assign("is_group",$this->is_group);
379 /* Prepare all variables for smarty */
380 foreach($this->attributes as $s_attr){
381 /* Set value*/
382 $smarty->assign($s_attr,$this->$s_attr);
384 /* Set checkbox state*/
385 if(empty($this->$s_attr)){
386 $smarty->assign($s_attr."CHK","");
387 }else{
388 $smarty->assign($s_attr."CHK"," checked ");
389 }
391 /* Prepare ACL settings*/
392 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
393 }
395 /* Is accout enabled | are we editing from usermenu or admin menu
396 All these tab management is done here
397 */
400 /* Working from Usermenu an the Account is currently disbled
401 * this->parent : is only set if we are working in a list of tabs
402 * is_account : is only true if the needed objectClass is given
403 */
404 if((!isset($this->parent))&&(!$this->is_account)){
405 /* We are currently editing this tab from usermenu, but this account is not enabled */
406 $smarty->assign("is_account",$this->is_account);
407 /* Load template */
408 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
409 /* Avoid the "You are currently editing ...." message when you leave this tab */
410 $display .= back_to_main();
411 /* Display our message to the user */
412 return $display;
415 /* We are currently editing from group tabs, because
416 * $this->parent is set
417 * posixAccount is not set, so we are not in usertabs.
418 */
419 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
420 $smarty->assign("is_account","true");
421 $this->uid = $this->cn;
422 $this->attrs['uid'] = $this->cn;
424 /* Change state if needed */
425 if (isset($_POST['modify_state'])){
426 if(($this->acl_is_createable() && !$this->is_account) ||
427 ($this->acl_is_removeable() && $this->is_account)){
428 $this->is_account= !$this->is_account;
429 }
430 }
431 /* Group Dialog with enabled environment options */
432 if ($this->is_account){
433 $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
434 msgPool::featuresEnabled(_("Environment")));
435 } else {
437 /* Environment is disabled
438 If theres is no posixAccount enabled, you won't be able to enable
439 environment extensions
440 */
441 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
442 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
443 msgPool::featuresDisabled(_("Environment")));
444 return $display;
445 }elseif((isset($this->parent->by_object['ogroup']))){
446 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
447 msgPool::featuresDisabled(_("Environment")));
448 return $display;
449 }else{
450 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
451 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
452 return $display;
453 }
454 }
455 }else{
456 /* Editing from Usermenu
457 * Tell smarty that this accoutn is enabled
458 */
459 $smarty->assign("is_account","true");
461 /* Change state if needed */
462 if (isset($_POST['modify_state'])){
463 if(($this->acl_is_createable() && !$this->is_account) ||
464 ($this->acl_is_removeable() && $this->is_account)){
465 $this->is_account= !$this->is_account;
466 }
467 }
469 if(isset($this->parent)){
471 // 3. Account enabled . Editing from adminmenu
472 if ($this->is_account){
473 $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
474 msgPool::featuresEnabled(_("Environment")));
475 } else {
477 if($this->parent->by_object['posixAccount']->is_account==true){
478 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
479 msgPool::featuresDisabled(_("Environment")));
480 return $display;
481 }else{
482 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
483 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
484 return $display;
485 }
486 }
487 }
488 }
490 /* Reset header toggle */
491 if($this->multiple_support_active){
492 $display = "";
493 }
495 /* Account is Account : is_accounbt=true.
496 * Else we won't reach this.
497 */
499 /* Prepare all variables for smarty */
500 foreach($this->attributes as $s_attr){
501 /* Set value*/
502 $smarty->assign($s_attr,$this->$s_attr);
504 /* Set checkbox state*/
505 if(empty($this->$s_attr)){
506 $smarty->assign($s_attr."CHK","");
507 }else{
508 $smarty->assign($s_attr."CHK"," checked ");
509 }
511 /* Prepare ACL settings*/
512 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
513 }
515 foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
516 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
517 }
519 if($WriteOnly) {
520 $smarty->assign("gotoPrinterACL","r");
521 }else{
522 $smarty->assign("gotoPrinterACL","rw");
523 }
526 $smarty->assign("useProfile",$this->useProfile);
527 if(empty($this->useProfile) && !$this->multiple_support_active){
528 $smarty->assign("useProfileCHK","");
529 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
530 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
531 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
532 }else{
533 $smarty->assign("useProfileCHK"," checked ");
534 }
536 $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
537 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
539 /* HANDLE Profile Settings here
540 * Assign available Quota and resolution settings
541 * Get all available profile server
542 * Get cache checkbox
543 * Assign this all to Smarty
544 */
546 if(empty($this->gotoProfileFlagL)){
547 $smarty->assign("gotoProfileFlagLCHK"," ");
548 }else{
549 $smarty->assign("gotoProfileFlagLCHK"," checked ");
550 }
552 if(empty($this->gotoProfileFlagC)){
553 $smarty->assign("gotoProfileFlagCCHK"," ");
554 }else{
555 $smarty->assign("gotoProfileFlagCCHK"," checked ");
556 }
559 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
560 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
562 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
563 if(!is_array($this->gotoProfileServers)){
564 $this->gotoProfileServers =array();
565 }
567 /* Handle kiosk profiles*/
568 $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
569 $smarty->assign("kiosk_server" , $this->gotoKioskProfile_Server);
570 $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
571 $smarty->assign("kiosk_profile" , $this->gotoKioskProfile_Profile);
574 /* Logonscript Management
575 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
576 * Perform add Delete edit Posts
577 */
579 /* Dialog Save */
580 if(isset($_POST['LogonSave'])){
582 if(!$this->acl_is_writeable("gotoLogonScript")){
583 msg_dialog::display(_("Permission error"), msgPool::permModify(_("Logon scripts")), ERROR_DIALOG);
584 unset($this->dialog);
585 $this->dialog=FALSE;
586 $this->is_dialog=false;
587 }else{
588 $this->dialog->save_object();
589 if(count($this->dialog->check())!=0){
590 foreach($this->dialog->check() as $msg){
591 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
592 }
593 }else{
594 $tmp = $this->dialog->save();
595 unset($this->dialog);
596 $this->dialog=FALSE;
597 $this->is_dialog=false;
599 if($this->multiple_support_active){
600 $tmp['UsedByAllUsers'] = TRUE;
601 }
602 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
603 }
604 }
605 }
608 /* Dialog Quit without saving */
609 if(isset($_POST['LogonCancel'])){
610 $this->is_dialog= false;
611 unset($this->dialog);
612 $this->dialog= FALSE;
613 }
615 /* Check Edit Del New Posts for a selected LogonScript */
616 if($this->acl_is_writeable("gotoLogonScript") &&
617 (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
619 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
620 * In this case we create a new Logon Script.
621 */
622 if(isset($_POST['gotoLogonScriptNew'])){
623 $this->is_dialog = true;
624 $this->dialog = new logonManagementDialog($this->config,$this->dn);
625 }
627 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
628 * We only can delete if there is an entry selected.
629 */
630 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
631 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
632 }
634 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
635 * There must be an entry selected to perform edit request.
636 */
637 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
638 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
639 $this->is_dialog = true;
640 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
641 }
642 }
644 /* Append List to smarty*/
645 if($this->multiple_support_active){
646 $smarty->assign("gotoLogonScripts", $this->gotoLogonScripts);
647 $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
648 }else{
649 $ls = $this->printOutLogonScripts();
650 $smarty->assign("gotoLogonScripts", $ls);
651 $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
652 $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
653 }
655 /* In this section server shares will be defined
656 * A user can select one of the given shares and a mount point
657 * and attach this combination to his setup.
658 */
660 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
661 if(!is_array($this->gotoShareSelections)){
662 $this->gotoShareSelections = array();
663 }
664 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
666 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
667 * This entry will be, a combination of mountPoint and sharedefinitions
668 */
669 if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
671 /* We assign a share to this user, if we don't know where to mount the share */
672 if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
673 msg_dialog::display(_("Error"), msgPool::invalid(_("Share")), ERROR_DIALOG);
674 }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
675 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
676 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
677 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point"), "/[^\s]/"), ERROR_DIALOG);
678 }elseif(!(
679 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
680 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
681 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
682 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
683 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
684 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
685 preg_match("/^%/",$_POST['gotoShareMountPoint'])
686 )
687 ){
688 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
689 }else{
690 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
691 $s_mount = $_POST['gotoShareMountPoint'];
692 $s_user = $_POST['ShareUser'];
693 /* Preparing the new assignment */
694 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
695 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
696 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
697 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
699 if($this->multiple_support_active){
700 $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
701 }
702 }
703 }
705 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
706 * If there is no defined share selected, we will abort the deletion without any message
707 */
708 $once = true;
709 if($this->acl_is_writeable("gotoShare")){
710 foreach($_POST as $name => $value){
711 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
712 $once = false;
713 $key = preg_replace("/^gotoShareDel_/","",$name);
714 $key = preg_replace("/_+[xy]$/","",$key);
715 $key = base64_decode($key);
716 if(isset($this->gotoShares[$key])) {
717 unset($this->gotoShares[$key]);
718 }
720 /* Remove corresponding password entry, too. This is a workaround
721 to get rid of old-style entries. */
722 $key= preg_replace("/\|/", "|!", $key);
723 if(isset($this->gotoShares[$key])) {
724 unset($this->gotoShares[$key]);
725 }
726 }
727 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
728 $once = false;
729 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
730 $key = preg_replace("/_+[xy]$/","",$key);
731 $key = base64_decode($key);
732 $this->gotoShares[$key]['PwdHash'] = "";
733 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
734 unset($this->gotoShares[$key]);
735 }
736 }
737 }
738 }
739 $divlistShares = new divSelectBox("gotoShares");
740 $divlistShares->SetHeight(100);
743 $tmp = array();
744 if($this->acl_is_readable("gotoShare")){
745 $tmp = $this->printOutAssignedShares();
746 }
749 foreach($tmp as $key => $value){
750 $img = "";
752 /* Skip apssword only entries */
753 if( empty($this->gotoShares[$key]['server']) &&
754 empty($this->gotoShares[$key]['name']) &&
755 empty($this->gotoShares[$key]['mountPoint']) &&
756 empty($this->gotoShares[$key]['Username'])){
757 continue;
758 }
760 $color = "";
761 if($this->multiple_support_active){
762 if($this->gotoShares[$key]['UsedByAllUsers']){
763 $value .= " (<b>"._("Used by all users")."</b>)";
764 }else{
765 $color = "color: #999999;";
766 $value .= " (<b>"._("Used by some users")."</b>)";
767 }
768 }
770 /* Check if entry starts with an ! */
771 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
773 /* If we are currently editing groups environment, skip those ! entries */
774 if($this->is_group) continue;
776 /* Create pwd reset images */
777 if($this->gotoShares[$key]['PwdHash'] != ""){
778 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
779 title='"._("Reset password hash")."'>";
780 }
781 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
782 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
783 }else{
785 /* Create pwd reset img && delete image */
786 if($this->gotoShares[$key]['PwdHash'] != ""){
787 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
788 title='"._("Reset password hash")."'>";
789 $img.= " ";
790 }
791 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/lists/trash.png' alt='".msgPool::delButton()."'
792 title='"._("Delete share entry")."'>";
793 $field1 = array("string" => $value , "attach" => "style='".$color."'");
794 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
795 }
796 $divlistShares->AddEntry(array($field1,$field2));
797 }
798 $smarty->assign("divlistShares",$divlistShares->DrawList());
800 /* Hotplug devices will be handled here
801 * There are 3 possible methods for this feature
802 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
803 * Delete will erase an entry, the entry must be selcted in the ListBox first
804 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
805 */
807 /* We have to delete the selected hotplug from the list*/
808 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
809 if($this->acl_is_writeable("gotoHotplugDevice")){
810 foreach($_POST['gotoHotplugDevice_post'] as $name){
811 unset($this->gotoHotplugDevices[$name]);
812 }
813 }
814 }
816 /* There are already defined hotplugs from other users we could use */
817 if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
818 $tmp =array();
819 foreach($this->gotoHotplugDevices as $plugs){
820 $tmp[] = $plugs['name'];
821 }
822 $this->dialog = new hotplugDialog($this->config,$tmp);
823 $this->is_dialog = true;
824 }
826 /* Dialog Aborted */
827 if(isset($_POST['HotPlugCancel'])){
828 unset($this->dialog);
829 $this->dialog= FALSE;
830 $this->is_dialog = false;
831 }
833 /* Dialod saved */
834 if(isset($_POST['HotPlugSave'])){
836 $this->dialog->save_object();
837 if(count($this->dialog->check())!=0){
838 foreach($this->dialog->check() as $msg){
839 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
840 }
841 }else{
842 $this->dialog->save_object();
843 $a_tmp = $this->dialog->save();
845 if(is_array($a_tmp)){
846 foreach($a_tmp as $name => $hotplug){
847 if($this->multiple_support_active){
848 $hotplug['UsedByAllUsers'] = TRUE;
849 }
850 $this->gotoHotplugDevices[$name]= $hotplug;
851 }
852 }
853 unset($this->dialog);
854 $this->dialog= FALSE;
855 $this->is_dialog = false;
856 }
857 }
859 if($this->multiple_support_active){
860 $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
861 }else{
862 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
863 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
864 }
866 /* Printer Assignment will managed below
867 * A printer can be assigned in two different ways and two different types
868 * There are 2 types of users assigned to a printer : user and admin
869 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
870 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
871 */
873 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
874 if(isset($_POST['gotoPrinterAdd'])){
876 $this->is_dialog=true;
877 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
878 }
880 if(isset($_POST['PrinterCancel'])){
881 $this->is_dialog=false;
882 unset($this->dialog);
883 $this->dialog=FALSE;
884 }
886 if(isset($_POST['PrinterSave'])){
887 if(count($this->dialog->check())!=0){
888 $tmp = $this->dialog->check();
889 foreach($tmp as $msg){
890 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
891 }
892 }else{
893 $this->dialog->save_object();
894 $tmp = $this->dialog->save();
895 $tmp2= $this->dialog->getPrinter(true);
897 foreach($tmp as $pname){
898 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
899 $printerObj->set_acl_base($tmp2[$pname]['dn']);
901 $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]=$tmp2[$pname];
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 }
937 }
939 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
940 $printer = $_POST['gotoPrinterSel'];
941 foreach($printer as $pname){
943 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
944 $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
946 $type = false;
947 if($this->is_group){
948 if(isset($this->NewAddedPrinters[$pname])){
949 $type = "Group";
950 }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
951 $type = "Group";
952 }
953 }else{
954 if(isset($this->NewAddedPrinters[$pname])){
955 $type = "User";
956 }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
957 $type = "User";
958 }
959 }
960 if($type){
961 $this->add_del_printer_member_was_called = true;
962 unset($this->gotoPrinter[$pname]);
964 $this->NewDeletedPrinters[$pname] = $pname;
965 if(isset($this->NewAddedPrinters[$pname])){
966 UNSET($this->NewAddedPrinters[$pname]);
967 }
968 }
969 }
970 }
972 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
973 $printers = $_POST['gotoPrinterSel'];
974 $this->add_del_printer_member_was_called = true;
975 foreach($printers as $printer){
976 if($this->gotoPrinter[$printer]['mode']=="user"){
977 $this->gotoPrinter[$printer]['mode']="admin";
978 }else{
979 $this->gotoPrinter[$printer]['mode']="user";
980 }
981 }
982 }
984 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
985 if($this->is_group){
986 msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
987 }else{
988 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
989 $this->gosaDefaultPrinter= "";
990 } else {
991 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
992 }
993 }
994 }
996 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
997 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
999 /* General behavior */
1000 if(is_object($this->dialog)){
1001 $this->dialog->save_object();
1002 $disp =$this->dialog->execute();
1003 return($disp);
1004 }
1006 /* Assign used attributes for multiple edit */
1007 foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
1008 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
1009 $ubox ="use_".$box;
1010 if(in_array($box,$this->multi_boxes)){
1011 $smarty->assign($ubox,TRUE);
1012 }else{
1013 $smarty->assign($ubox,FALSE);
1014 }
1015 }
1017 /* Als smarty vars are set. Get smarty template and generate output */
1018 $smarty->assign("multiple_support",$this->multiple_support_active);
1019 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
1020 return($display);
1021 }
1023 function remove_from_parent()
1024 {
1025 /* only if it was an account*/
1026 if (!$this->initially_was_account){
1027 return;
1028 }
1030 /* include global link_info */
1031 $ldap= $this->config->get_ldap_link();
1033 /* Remove and write to LDAP */
1034 plugin::remove_from_parent();
1036 /* Don't save our template variables */
1037 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1039 /* Skip all these attributes */
1040 foreach($skip as $del){
1041 unset($this->attrs[$del]);
1042 }
1044 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1046 $ldap->cd($this->dn);
1047 $this->cleanup();
1048 $ldap->modify ($this->attrs);
1050 if($this->is_group){
1051 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1052 }else{
1053 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1054 }
1056 if (!$ldap->success()){
1057 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1058 }
1060 /* Optionally execute a command after we're done */
1061 $this->handle_post_events("remove",array("uid" => $this->uid));
1062 }
1065 /* Save data to object */
1066 function save_object()
1067 {
1068 /* Get all Posted vars
1069 * Setup checkboxes
1070 */
1071 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
1072 if(isset($_POST['iamposted'])){
1074 $PACL = $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1076 if(isset($_POST['kiosk_server'])){
1077 $tmp = $_POST['kiosk_server'];
1078 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1079 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1080 }
1081 }
1082 if(isset($_POST['kiosk_profile'])){
1083 $tmp = $_POST['kiosk_profile'];
1084 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1085 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1086 }
1087 }
1089 if(preg_match("/w/",$PACL)){
1090 if(isset($_POST['useProfile'])){
1091 $this->useProfile = true;
1092 }else{
1093 $this->useProfile = false;
1094 }
1095 }
1097 if($this->acl_is_writeable("gotoProfileFlagC")){
1098 if(isset($_POST['gotoProfileFlagC'])){
1099 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1100 }else{
1101 $this->gotoProfileFlagC = false;
1102 }
1103 }
1105 if($this->acl_is_writeable("gotoProfileFlagL")){
1106 if(isset($_POST['gotoProfileFlagL'])){
1107 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1108 }else{
1109 $this->gotoProfileFlagL = false;
1110 }
1111 }
1113 plugin::save_object();
1114 foreach($this->attributes as $s_attr){
1115 if((!isset($_POST[$s_attr])) ||
1116 in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1117 if(!$this->acl_is_writeable($s_attr)){
1118 continue;
1119 }else{
1120 if(isset($_POST[$s_attr])){
1121 $this->$s_attr = $_POST[$s_attr];
1122 }else{
1123 $this->$s_attr = false;
1124 }
1125 }
1126 }
1127 }
1128 }
1131 /* Check supplied data */
1132 function check()
1133 {
1134 /* Call common method to give check the hook */
1135 $message= plugin::check();
1137 $this->detect_grouptype();
1139 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1140 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1141 }
1142 if(!isset($this->attrs['objectClass'])){
1143 $this->attrs['objectClass']=array();
1144 }
1145 if(!$this->is_group){
1146 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1147 $message[]= msgPool::featuresDisabled(_("environment"),_("POSIX"));
1148 }
1149 }
1150 return ($message);
1151 }
1154 /* Save to LDAP */
1155 function save()
1156 {
1157 /* If group was renamed, all printer settings get lost
1158 */
1159 /* only save changed variables ....*/
1160 if ($this->gotoKioskProfile_Server != "none"){
1161 $method = $this->gotoKioskProfiles['MAP'][$this->gotoKioskProfile_Server][$this->gotoKioskProfile_Profile];
1162 $this->gotoKioskProfile= $method;
1163 }else{
1164 $this->gotoKioskProfile= array();
1165 }
1167 plugin::save();
1168 $ldap= $this->config->get_ldap_link();
1170 $realyUsedAttrs= array();
1172 /* Save already used objectClasses */
1173 $ocs = $this->attrs['objectClass'];
1174 unset($ocs['count']);
1175 $this->attrs = array();
1176 $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1178 /* 1. Search all printers that have our uid/cn as member
1179 * 2. Delete this uid/cn from every single entry and save it again.
1180 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1181 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
1182 */
1184 $this->detect_grouptype();
1186 if($this->add_del_printer_member_was_called){
1188 $types = array( "gotoUserPrinter" => "AddUser",
1189 "gotoGroupPrinter" => "AddGroup",
1190 "gotoUserAdminPrinter" => "AddAdminUser",
1191 "gotoGroupAdminPrinter" => "AddAdminGroup");
1193 if($this->is_group){
1194 $s_suffix = "Group";
1195 $useVar = "cn";
1196 }else{
1197 $useVar = "uid";
1198 $s_suffix = "User";
1199 }
1201 /* Remove old entries */
1202 $ldap->cd($this->config->current['BASE']);;
1203 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1204 while($attr = $ldap->fetch()){
1205 $printerObj = NULL;
1206 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1207 $printerObj->set_acl_base($attr['dn']);
1208 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1209 $printerObj->by_object['printgeneric']->save();
1210 }
1212 $ldap->cd($this->config->current['BASE']);;
1213 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1214 while($attr = $ldap->fetch()){
1215 $printerObj = NULL;
1216 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1217 $printerObj->set_acl_base($attr['dn']);
1218 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1219 $printerObj->by_object['printgeneric']->save();
1220 }
1222 foreach($this->gotoPrinter as $printer){
1223 $printerObj = NULL;
1224 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1225 $printerObj->set_acl_base($printer['dn']);
1228 if($printer['mode'] == "admin") {
1229 $attribute = "goto".$s_suffix."AdminPrinter";
1230 }else{
1231 $attribute = "goto".$s_suffix."Printer";
1232 }
1234 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1235 $printerObj->by_object['printgeneric']->save();
1236 }
1237 }
1239 /* Prepare HotPlug devices */
1240 $this->attrs['gotoHotplugDeviceDN'] = array();
1241 foreach($this->gotoHotplugDevices as $name => $device){
1242 $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1243 }
1245 /* Prepare LogonScripts */
1246 $this->attrs['gotoLogonScript'] = array();
1247 foreach($this->gotoLogonScripts as $name => $script){
1248 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1249 $script['LogonOverload'].$script['LogonLast']."|".
1250 $script['LogonPriority']."|".
1251 base64_encode($script['LogonData'])."|".
1252 $script['LogonDescription'];
1253 }
1255 /* Prepare Shares */
1256 $this->attrs['gotoShare']=array();
1257 foreach($this->gotoShares as $name => $share){
1258 $mntp= $share['mountPoint'];
1259 if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1260 $mntp= base64_encode($mntp);
1261 }
1262 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1263 }
1266 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1267 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1269 foreach($saveThis as $tosave){
1270 if(!empty($this->$tosave)){
1271 $this->attrs[$tosave]=$this->$tosave;
1272 }else{
1273 $this->attrs[$tosave]=array();
1274 }
1275 }
1277 /* Prepare Flags */
1278 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1279 if(empty($this->attrs['gotoProfileFlags'][0])){
1280 $this->attrs['gotoProfileFlags']=array();
1281 }
1283 if($this->useProfile == false){
1284 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1285 $this->attrs['gotoProfileServer']= array();
1286 }
1288 $ldap->cat ($this->dn, array('dn'));
1289 if ($ldap->fetch()){
1290 $mode= "modify";
1291 } else {
1292 $mode= "add";
1293 $ldap->cd($this->config->current['BASE']);
1294 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1295 }
1297 $ldap->cd($this->dn);
1298 $this->cleanup();
1299 $ldap->$mode($this->attrs);
1301 $cat = "users";
1302 if($this->is_group){
1303 $cat = "groups";
1304 }
1306 /* Log last action */
1307 if($this->initially_was_account){
1308 new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1309 }else{
1310 new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1311 }
1313 if (!$ldap->success()){
1314 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1315 }
1316 $this->handle_post_events($mode,array("uid"=>$this->uid));
1317 }
1319 /* Generate ListBox frindly output for the defined shares
1320 * Possibly Add or remove an attribute here,
1321 */
1322 function printOutAssignedShares()
1323 {
1324 $a_return = array();
1325 if(is_array($this->gotoShares)){
1326 foreach($this->gotoShares as $share){
1327 if(preg_match("/^!/",$share['server'])){
1328 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1329 }else{
1330 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1331 }
1332 }
1333 natcasesort($a_return);
1334 }
1335 return($a_return);
1336 }
1338 /* Generate ListBox frindly output for the definedhotplugs
1339 * Possibly Add or remove an attribute here,
1340 */
1341 function printOutHotPlugDevices()
1342 {
1343 $a_return= array();
1344 if(is_array($this->gotoHotplugDevices)){
1345 foreach($this->gotoHotplugDevices as $key=>$device){
1346 $a_return[$key] = $device['name']." - ".$device['id'];
1347 }
1348 }
1349 return($a_return);
1350 }
1352 /* Generates ListBox frienly output of used printer devices
1353 * Append ' - admin' if printer is used in admin mode
1354 */
1355 function printOutPrinterDevices()
1356 {
1357 $a_return = array();
1359 if(is_array($this->gotoPrinter)){
1360 foreach($this->gotoPrinter as $printer){
1361 if($printer['mode'] == "admin"){
1362 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1363 }else{
1364 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1365 }
1366 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1367 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1368 }
1369 }
1370 }
1371 return($a_return);
1372 }
1375 function PrepareForCopyPaste($source)
1376 {
1377 plugin::PrepareForCopyPaste($source);
1379 $class= get_class($this);
1380 $o_source = new $class($this->config,$source['dn']);
1381 foreach($this->CopyPasteVars as $attr){
1382 $this->$attr = $o_source->$attr;
1383 }
1384 }
1387 function saveCopyDialog()
1388 {
1389 if(isset($_POST['cn'])){
1390 $this->cn = $_POST['cn'];
1391 $this->uid = $_POST['cn'];
1392 }
1393 }
1396 /* Generates ListBox frienly output of used logonscripts
1397 */
1398 function printOutLogonScripts()
1399 {
1400 $a_return = array();
1401 if(is_array($this->gotoLogonScripts)){
1402 foreach($this->gotoLogonScripts as $script){
1403 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1404 }
1405 }
1406 return($a_return);
1407 }
1410 function multiple_execute()
1411 {
1412 /* Reset header toggle */
1413 $this->is_account = TRUE;
1414 return($this->execute());
1415 }
1418 /* Initialize plugin with given atribute arrays
1419 */
1420 function init_multiple_support($attrs,$all)
1421 {
1422 plugin::init_multiple_support($attrs,$all);
1424 /* Prepare Shares */
1425 if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1426 unset($this->multi_attrs_all['gotoShare']['count']);
1427 foreach($this->multi_attrs_all['gotoShare'] as $share){
1428 $tmp = $tmp2 = array();
1429 $tmp = split("\|",$share);
1430 $tmp2['server'] =$tmp[0];
1431 $tmp2['name'] =$tmp[1];
1433 /* Decode base64 if needed */
1434 if (!preg_match('%/%', $tmp[2])){
1435 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1436 } else {
1437 $tmp2['mountPoint'] =$tmp[2];
1438 }
1440 if(isset($tmp[3])){
1441 $tmp2['PwdHash'] =$tmp[3];
1442 }else{
1443 $tmp2['PwdHash'] ="";
1444 }
1445 if(isset($tmp[4])){
1446 $tmp2['Username'] =$tmp[4];
1447 }else{
1448 $tmp2['Username'] ="";
1449 }
1450 $tmp2['UsedByAllUsers'] = FALSE;
1451 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1452 }
1453 }
1455 /* Prepare Shares */
1456 if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1457 unset($this->multi_attrs['gotoShare']['count']);
1458 foreach($this->multi_attrs['gotoShare'] as $share){
1459 $tmp = $tmp2 = array();
1460 $tmp = split("\|",$share);
1461 $tmp2['server'] =$tmp[0];
1462 $tmp2['name'] =$tmp[1];
1464 /* Decode base64 if needed */
1465 if (!preg_match('%/%', $tmp[2])){
1466 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1467 } else {
1468 $tmp2['mountPoint'] =$tmp[2];
1469 }
1471 if(isset($tmp[3])){
1472 $tmp2['PwdHash'] =$tmp[3];
1473 }else{
1474 $tmp2['PwdHash'] ="";
1475 }
1476 if(isset($tmp[4])){
1477 $tmp2['Username'] =$tmp[4];
1478 }else{
1479 $tmp2['Username'] ="";
1480 }
1481 $tmp2['UsedByAllUsers'] = TRUE;
1482 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1483 }
1484 }
1487 /* prepare LogonScripts */
1488 if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1489 unset($this->multi_attrs_all['gotoLogonScript']['count']);
1490 foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1491 $tmp = $tmp2 = array();
1492 $tmp = split("\|",$device);
1493 $tmp2['LogonName'] = $tmp[0];
1494 $tmp2['LogonPriority'] = $tmp[2];
1495 if(preg_match("/O/i",$tmp[1])){
1496 $tmp2['LogonOverload'] = "O";
1497 }else{
1498 $tmp2['LogonOverload'] = "";
1499 }
1500 if(preg_match("/L/i",$tmp[1])){
1501 $tmp2['LogonLast'] = "L";
1502 }else{
1503 $tmp2['LogonLast'] = "";
1504 }
1505 $tmp2['LogonData'] = base64_decode($tmp[3]);
1506 $tmp2['LogonDescription'] = $tmp[4];
1507 $tmp2['UsedByAllUsers'] = FALSE;
1508 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1509 }
1510 }
1512 /* prepare LogonScripts */
1513 if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1514 unset($this->multi_attrs['gotoLogonScript']['count']);
1515 foreach($this->multi_attrs['gotoLogonScript'] as $device){
1516 $tmp = $tmp2 = array();
1517 $tmp = split("\|",$device);
1518 $tmp2['LogonName'] = $tmp[0];
1519 $tmp2['LogonPriority'] = $tmp[2];
1520 if(preg_match("/O/i",$tmp[1])){
1521 $tmp2['LogonOverload'] = "O";
1522 }else{
1523 $tmp2['LogonOverload'] = "";
1524 }
1525 if(preg_match("/L/i",$tmp[1])){
1526 $tmp2['LogonLast'] = "L";
1527 }else{
1528 $tmp2['LogonLast'] = "";
1529 }
1530 $tmp2['LogonData'] = base64_decode($tmp[3]);
1531 $tmp2['LogonDescription'] = $tmp[4];
1532 $tmp2['UsedByAllUsers'] = TRUE;
1533 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1534 }
1535 }
1537 /* Prepare hotplugs */
1538 if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1539 $ldap = $this->config->get_ldap_link();
1540 $ldap->cd($this->config->current['BASE']);
1541 for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1542 $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1543 if($ldap->count()){
1544 $multi_attrs_all = $ldap->fetch();
1546 if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1547 $tmp = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1548 $tmp2 = array();
1549 $tmp2['name'] = $multi_attrs_all['cn'][0];
1550 $tmp2['description'] = $tmp[0];
1551 $tmp2['id'] = $tmp[1];
1552 $tmp2['produkt'] = $tmp[2];
1553 $tmp2['vendor'] = $tmp[3];
1554 $tmp2['dn'] = $multi_attrs_all['dn'];
1555 $tmp2['UsedByAllUsers'] = FALSE;
1556 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1557 }
1558 }
1559 }
1560 }
1562 /* Prepare hotplugs */
1563 if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1564 $ldap = $this->config->get_ldap_link();
1565 $ldap->cd($this->config->current['BASE']);
1566 for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1567 $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1568 if($ldap->count()){
1569 $multi_attrs = $ldap->fetch();
1571 if(isset($multi_attrs['gotoHotplugDevice'][0])){
1572 $tmp = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1573 $tmp2 = array();
1574 $tmp2['name'] = $multi_attrs['cn'][0];
1575 $tmp2['description'] = $tmp[0];
1576 $tmp2['id'] = $tmp[1];
1577 $tmp2['produkt'] = $tmp[2];
1578 $tmp2['vendor'] = $tmp[3];
1579 $tmp2['dn'] = $multi_attrs['dn'];
1580 $tmp2['UsedByAllUsers'] = TRUE;
1581 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1582 }
1583 }
1584 }
1585 }
1586 $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1587 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1588 $chr = $this->gotoProfileFlags[$i];
1589 $name = "gotoProfileFlag".$chr;
1590 $this->$name=$chr;
1591 }
1592 $this->update_kiosk_profiles();
1593 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1595 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1596 $this->useProfile = true;
1597 }else{
1598 $this->useProfile = false;
1599 }
1601 }
1604 function set_multi_edit_values($attrs)
1605 {
1606 $shares = $this->gotoShares;
1607 $scripts= $this->gotoLogonScripts;
1608 $plugs= $this->gotoHotplugDevices;
1609 plugin::set_multi_edit_values($attrs);
1611 $this->gotoShares = $shares;
1612 $this->gotoLogonScripts = $scripts;
1613 $this->gotoHotplugDevices = $plugs;
1615 foreach($attrs['gotoShares'] as $name => $share){
1616 if($share['UsedByAllUsers'] == TRUE){
1617 $this->gotoShares[$name] = $share;
1618 }
1619 }
1620 foreach($this->gotoShares as $name => $share){
1621 if(!isset($attrs['gotoShares'][$name])){
1622 unset($this->gotoShares[$name]);
1623 }
1624 }
1625 foreach($attrs['gotoLogonScripts'] as $name => $script){
1626 if($script['UsedByAllUsers'] == TRUE){
1627 $this->gotoLogonScripts[$name] = $script;
1628 }
1629 }
1630 foreach($this->gotoLogonScripts as $name => $script){
1631 if(!isset($attrs['gotoLogonScripts'][$name])){
1632 unset($this->gotoLogonScripts[$name]);
1633 }
1634 }
1635 $tmp = array();
1636 foreach($this->gotoHotplugDevices as $entry){
1637 $tmp[$entry['dn']] = $entry;
1638 }
1640 foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1641 if($plug['UsedByAllUsers'] == TRUE){
1642 $tmp[$plug['dn']] = $plug;
1643 }
1644 }
1645 foreach($tmp as $name => $plug){
1646 $found = false;
1647 foreach($attrs['gotoHotplugDevices'] as $test){
1648 if($test['dn'] == $name){
1649 $found = true;
1650 }
1651 }
1652 if(!$found){
1653 unset($tmp[$name]);
1654 }
1655 }
1656 }
1659 /* Return selected values for multiple edit */
1660 function get_multi_edit_values()
1661 {
1662 $ret = plugin::get_multi_edit_values();
1663 $ret['gotoShares'] = $this->gotoShares;
1664 $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1665 $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1667 if(in_array("gotoPrinter",$this->multi_boxes)){
1668 $ret['gotoPrinter'] = $this->gotoPrinter;
1669 $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1670 $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1672 /* Force printer reset */
1673 $ret['add_del_printer_member_was_called'] = TRUE;
1674 }
1676 if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1677 $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1678 }
1680 if(in_array("useProfile",$this->multi_boxes)){
1681 $ret['useProfile']=$this->useProfile;
1682 if(in_array("gotoProfileServer",$this->multi_boxes)){
1683 $ret['gotoProfileServer']=$this->gotoProfileServer;
1684 }
1685 if(in_array("gotoProfileQuota",$this->multi_boxes)){
1686 $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1687 }
1688 if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1689 $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1690 }
1691 }
1692 if(in_array("gotoXResolution",$this->multi_boxes)){
1693 $ret['gotoXResolution'] = $this->gotoXResolution;
1694 }
1695 if(in_array("kiosk_server",$this->multi_boxes)){
1696 $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1697 $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1698 }
1699 return($ret);
1700 }
1703 function multiple_check()
1704 {
1705 $message = plugin::multiple_check();
1706 $this->detect_grouptype();
1708 if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
1709 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1710 }
1711 return($message);
1712 }
1715 function multiple_save_object()
1716 {
1717 if(isset($_POST['environment_multiple_posted'])){
1718 plugin::multiple_save_object();
1720 if(isset($_POST['useProfile'])){
1721 $this->useProfile = true;
1722 }else{
1723 $this->useProfile = false;
1724 }
1725 if(isset($_POST['gotoProfileFlagC'])){
1726 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1727 }else{
1728 $this->gotoProfileFlagC = false;
1729 }
1731 if(isset($_POST['gotoProfileFlagL'])){
1732 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1733 }else{
1734 $this->gotoProfileFlagL = false;
1735 }
1737 foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1738 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1739 $uattr = "use_".$attr;
1740 if(isset($_POST[$uattr])){
1741 $this->multi_boxes[] = $attr;
1742 }
1743 }
1744 if(isset($_POST['kiosk_server'])){
1745 $tmp = $_POST['kiosk_server'];
1746 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1747 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1748 }
1749 }
1750 if(isset($_POST['kiosk_profile'])){
1751 $tmp = $_POST['kiosk_profile'];
1752 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1753 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1754 }
1755 }
1757 }
1758 }
1760 /* Return plugin informations for acl handling
1761 #FIXME these ACLs should work for groups too */
1762 static function plInfo()
1763 {
1764 return (array("plShortName" => _("Environment"),
1765 "plDescription" => _("Environment settings"), // Description
1766 "plSelfModify" => TRUE,
1767 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1768 "plPriority" => 3, // Position in tabs
1769 "plSection" => array("personal" => _("My account")),
1770 "plCategory" => array("users",
1771 "groups"),
1772 "plOptions" => array("resolution_hook" => array("type" => "string",
1773 "description" => _("Command to extend the list of possible screen resolutions"))),
1775 "plProvidedAcls" => array(
1777 "gotoProfileServer" => _("Profile server") ,
1778 "gotoProfileQuota" => _("Profile quota") ,
1779 "gotoProfileFlagC" => _("Cache profile localy") ,
1780 "gotoShare" => _("Shares"),
1781 "gotoHotplugDevice" => _("Hotplug devices"),
1782 "gotoKioskProfile" => _("Kiosk profile") ,
1783 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1784 "gotoXResolution" => _("Resolution") ,
1785 "gotoLogonScript" => _("Logon script"))
1786 ));
1787 }
1788 }
1790 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1791 ?>