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