deb06944b44abce34030c30d699f4b046a9043ac
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 $tmp1[$attrs['cn'][0]][] = $name;
256 }
257 $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
258 $cnt ++;
259 }
261 if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
262 $this->kiosk_enabled = TRUE;
263 }
265 $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
266 $this->gotoKioskProfiles['SERVERS'] = $tmp2;
268 $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
269 $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
271 $error = false;
272 if(!in_array($this->gotoKioskProfile_Server, $this->gotoKioskProfiles['SERVERS'])){
273 $this->gotoKioskProfile_Server = key($this->gotoKioskProfiles['SERVERS']);
274 $error = true;
275 }
277 if(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
278 $this->gotoKioskProfile_Profile = $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server][0];
279 $error = true;
280 }
281 if($error && !empty($this->gotoKioskProfile)){
282 $this->gotoKioskProfile_Server ="none";
283 $this->gotoKioskProfile_Profile="";
284 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);
285 }
286 }
289 /* Detect type of edited object (user|group)*/
290 function detect_grouptype()
291 {
292 if((!isset($this->parent))&&(!$this->is_account)){
293 $this->is_group = false;
294 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
295 $this->is_group = true;
296 }else{
297 $this->is_group = false;
298 }
299 }
302 function execute()
303 {
305 /* Call parent execute */
306 plugin::execute();
307 /* Log view */
308 if($this->is_account && !$this->view_logged){
309 $this->view_logged = TRUE;
310 if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
311 new log("view","users/".get_class($this),$this->dn);
312 }else{
313 new log("view","groups/".get_class($this),$this->dn);
314 }
315 }
317 /* Are we editing from MyAccount and not editing a user */
318 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
320 /* Check profile server */
321 if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
322 if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
323 if(count($this->gotoProfileServers)){
325 /* Get First Profile */
326 $new = key($this->gotoProfileServers);
328 /* Another profile server found */
329 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
330 }else{
332 /* No other profile servers found */
333 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
334 $this->gotoProfileServer = "none";
335 }
336 }
337 }
339 $this->detect_grouptype();
341 /* Fill templating stuff */
342 $smarty= get_smarty();
343 $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
344 $display= "";
346 $smarty->assign("is_group",$this->is_group);
348 /* Prepare all variables for smarty */
349 foreach($this->attributes as $s_attr){
350 /* Set value*/
351 $smarty->assign($s_attr,$this->$s_attr);
353 /* Set checkbox state*/
354 if(empty($this->$s_attr)){
355 $smarty->assign($s_attr."CHK","");
356 }else{
357 $smarty->assign($s_attr."CHK"," checked ");
358 }
360 /* Prepare ACL settings*/
361 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
362 }
364 /* Is accout enabled | are we editing from usermenu or admin menu
365 All these tab management is done here
366 */
369 /* Working from Usermenu an the Account is currently disbled
370 * this->parent : is only set if we are working in a list of tabs
371 * is_account : is only true if the needed objectClass is given
372 */
373 if((!isset($this->parent))&&(!$this->is_account)){
374 /* We are currently editing this tab from usermenu, but this account is not enabled */
375 $smarty->assign("is_account",$this->is_account);
376 /* Load template */
377 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
378 /* Avoid the "You are currently editing ...." message when you leave this tab */
379 $display .= back_to_main();
380 /* Display our message to the user */
381 return $display;
384 /* We are currently editing from group tabs, because
385 * $this->parent is set
386 * posixAccount is not set, so we are not in usertabs.
387 */
388 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
389 $smarty->assign("is_account","true");
390 $this->uid = $this->cn;
391 $this->attrs['uid'] = $this->cn;
393 /* Change state if needed */
394 if (isset($_POST['modify_state'])){
395 if(($this->acl_is_createable() && !$this->is_account) ||
396 ($this->acl_is_removeable() && $this->is_account)){
397 $this->is_account= !$this->is_account;
398 }
399 }
400 /* Group Dialog with enabled environment options */
401 if ($this->is_account){
402 $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
403 msgPool::featuresEnabled(_("Environment")));
404 } else {
406 /* Environment is disabled
407 If theres is no posixAccount enabled, you won't be able to enable
408 environment extensions
409 */
410 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
411 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
412 msgPool::featuresDisabled(_("Environment")));
413 return $display;
414 }else{
415 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
416 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
417 return $display;
418 }
419 }
420 }else{
421 /* Editing from Usermenu
422 * Tell smarty that this accoutn is enabled
423 */
424 $smarty->assign("is_account","true");
426 /* Change state if needed */
427 if (isset($_POST['modify_state'])){
428 if(($this->acl_is_createable() && !$this->is_account) ||
429 ($this->acl_is_removeable() && $this->is_account)){
430 $this->is_account= !$this->is_account;
431 }
432 }
434 if(isset($this->parent)){
436 // 3. Account enabled . Editing from adminmenu
437 if ($this->is_account){
438 $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
439 msgPool::featuresEnabled(_("Environment")));
440 } else {
442 if($this->parent->by_object['posixAccount']->is_account==true){
443 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
444 msgPool::featuresDisabled(_("Environment")));
445 return $display;
446 }else{
447 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
448 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
449 return $display;
450 }
451 }
452 }
453 }
455 /* Reset header toggle */
456 if($this->multiple_support_active){
457 $display = "";
458 }
460 /* Account is Account : is_accounbt=true.
461 * Else we won't reach this.
462 */
464 /* Prepare all variables for smarty */
465 foreach($this->attributes as $s_attr){
466 /* Set value*/
467 $smarty->assign($s_attr,$this->$s_attr);
469 /* Set checkbox state*/
470 if(empty($this->$s_attr)){
471 $smarty->assign($s_attr."CHK","");
472 }else{
473 $smarty->assign($s_attr."CHK"," checked ");
474 }
476 /* Prepare ACL settings*/
477 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
478 }
480 foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
481 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
482 }
484 if($WriteOnly) {
485 $smarty->assign("gotoPrinterACL","r");
486 }else{
487 $smarty->assign("gotoPrinterACL","rw");
488 }
491 $smarty->assign("useProfile",$this->useProfile);
492 if(empty($this->useProfile) && !$this->multiple_support_active){
493 $smarty->assign("useProfileCHK","");
494 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
495 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
496 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
497 }else{
498 $smarty->assign("useProfileCHK"," checked ");
499 }
501 $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
502 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
504 /* HANDLE Profile Settings here
505 * Assign available Quota and resolution settings
506 * Get all available profile server
507 * Get cache checkbox
508 * Assign this all to Smarty
509 */
511 if(empty($this->gotoProfileFlagL)){
512 $smarty->assign("gotoProfileFlagLCHK"," ");
513 }else{
514 $smarty->assign("gotoProfileFlagLCHK"," checked ");
515 }
517 if(empty($this->gotoProfileFlagC)){
518 $smarty->assign("gotoProfileFlagCCHK"," ");
519 }else{
520 $smarty->assign("gotoProfileFlagCCHK"," checked ");
521 }
524 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
525 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
527 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
528 if(!is_array($this->gotoProfileServers)){
529 $this->gotoProfileServers =array();
530 }
531 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
533 /* Handle kiosk profiles*/
534 $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
535 $smarty->assign("kiosk_server" , $this->gotoKioskProfile_Server);
536 $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
537 $smarty->assign("kiosk_profile" , $this->gotoKioskProfile_Profile);
540 /* Logonscript Management
541 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
542 * Perform add Delete edit Posts
543 */
545 /* Dialog Save */
546 if(isset($_POST['LogonSave'])){
548 if(!$this->acl_is_writeable("gotoLogonScript")){
549 msg_dialog::display(_("Permission error"), _("You have no permission to modify logon scripts!"), ERROR_DIALOG);
550 unset($this->dialog);
551 $this->dialog=FALSE;
552 $this->is_dialog=false;
553 }else{
554 $this->dialog->save_object();
555 if(count($this->dialog->check())!=0){
556 foreach($this->dialog->check() as $msg){
557 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
558 }
559 }else{
560 $tmp = $this->dialog->save();
561 unset($this->dialog);
562 $this->dialog=FALSE;
563 $this->is_dialog=false;
565 if($this->multiple_support_active){
566 $tmp['UsedByAllUsers'] = TRUE;
567 }
568 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
569 }
570 }
571 }
574 /* Dialog Quit without saving */
575 if(isset($_POST['LogonCancel'])){
576 $this->is_dialog= false;
577 unset($this->dialog);
578 $this->dialog= FALSE;
579 }
581 /* Check Edit Del New Posts for a selected LogonScript */
582 if($this->acl_is_writeable("gotoLogonScript") &&
583 (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
585 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
586 * In this case we create a new Logon Script.
587 */
588 if(isset($_POST['gotoLogonScriptNew'])){
589 $this->is_dialog = true;
590 $this->dialog = new logonManagementDialog($this->config,$this->dn);
591 }
593 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
594 * We only can delete if there is an entry selected.
595 */
596 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
597 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
598 }
600 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
601 * There must be an entry selected to perform edit request.
602 */
603 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
604 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
605 $this->is_dialog = true;
606 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
607 }
608 }
610 /* Append List to smarty*/
611 if($this->multiple_support_active){
612 $smarty->assign("gotoLogonScripts", $this->gotoLogonScripts);
613 $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
614 }else{
615 $ls = $this->printOutLogonScripts();
616 $smarty->assign("gotoLogonScripts", $ls);
617 $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
618 $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
619 }
621 /* In this section server shares will be defined
622 * A user can select one of the given shares and a mount point
623 * and attach this combination to his setup.
624 */
626 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
627 if(!is_array($this->gotoShareSelections)){
628 $this->gotoShareSelections = array();
629 }
630 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
632 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
633 * This entry will be, a combination of mountPoint and sharedefinitions
634 */
635 if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
637 /* We assign a share to this user, if we don't know where to mount the share */
638 if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
639 msg_dialog::display(_("Error"), msgPool::invalid(_("Share")), ERROR_DIALOG);
640 }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
641 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
642 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
643 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point"), "/[^\s]/"), ERROR_DIALOG);
644 }elseif(!(
645 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
646 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
647 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
648 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
649 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
650 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
651 preg_match("/^%/",$_POST['gotoShareMountPoint'])
652 )
653 ){
654 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
655 }else{
656 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
657 $s_mount = $_POST['gotoShareMountPoint'];
658 $s_user = $_POST['ShareUser'];
659 /* Preparing the new assignment */
660 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
661 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
662 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
663 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
665 if($this->multiple_support_active){
666 $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
667 }
668 }
669 }
671 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
672 * If there is no defined share selected, we will abort the deletion without any message
673 */
674 $once = true;
675 if($this->acl_is_writeable("gotoShare")){
676 foreach($_POST as $name => $value){
677 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
678 $once = false;
679 $key = preg_replace("/^gotoShareDel_/","",$name);
680 $key = preg_replace("/_+[xy]$/","",$key);
681 $key = base64_decode($key);
682 if(isset($this->gotoShares[$key])) {
683 unset($this->gotoShares[$key]);
684 }
686 /* Remove corresponding password entry, too. This is a workaround
687 to get rid of old-style entries. */
688 $key= preg_replace("/\|/", "|!", $key);
689 if(isset($this->gotoShares[$key])) {
690 unset($this->gotoShares[$key]);
691 }
692 }
693 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
694 $once = false;
695 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
696 $key = preg_replace("/_+[xy]$/","",$key);
697 $key = base64_decode($key);
698 $this->gotoShares[$key]['PwdHash'] = "";
699 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
700 unset($this->gotoShares[$key]);
701 }
702 }
703 }
704 }
705 $divlistShares = new divSelectBox("gotoShares");
706 $divlistShares->SetHeight(100);
709 $tmp = array();
710 if($this->acl_is_readable("gotoShares")){
711 $tmp = $this->printOutAssignedShares();
712 }
715 foreach($tmp as $key => $value){
716 $img = "";
718 /* Skip apssword only entries */
719 if( empty($this->gotoShares[$key]['server']) &&
720 empty($this->gotoShares[$key]['name']) &&
721 empty($this->gotoShares[$key]['mountPoint']) &&
722 empty($this->gotoShares[$key]['Username'])){
723 continue;
724 }
726 $color = "";
727 if($this->multiple_support_active){
728 if($this->gotoShares[$key]['UsedByAllUsers']){
729 $value .= " (<b>"._("Used by all users")."</b>)";
730 }else{
731 $color = "color: #999999;";
732 $value .= " (<b>"._("Used by some users")."</b>)";
733 }
734 }
736 /* Check if entry starts with an ! */
737 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
739 /* If we are currently editing groups environment, skip those ! entries */
740 if($this->is_group) continue;
742 /* Create pwd reset images */
743 if($this->gotoShares[$key]['PwdHash'] != ""){
744 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
745 title='"._("Reset password hash")."'>";
746 }
747 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
748 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
749 }else{
751 /* Create pwd reset img && delete image */
752 if($this->gotoShares[$key]['PwdHash'] != ""){
753 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
754 title='"._("Reset password hash")."'>";
755 $img.= " ";
756 }
757 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='".msgPool::delButton()."'
758 title='"._("Delete share entry")."'>";
759 $field1 = array("string" => $value , "attach" => "style='".$color."'");
760 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
761 }
762 $divlistShares->AddEntry(array($field1,$field2));
763 }
764 $smarty->assign("divlistShares",$divlistShares->DrawList());
766 /* Hotplug devices will be handled here
767 * There are 3 possible methods for this feature
768 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
769 * Delete will erase an entry, the entry must be selcted in the ListBox first
770 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
771 */
773 /* We have to delete the selected hotplug from the list*/
774 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
775 if($this->acl_is_writeable("gotoHotplugDevice")){
776 foreach($_POST['gotoHotplugDevice_post'] as $name){
777 unset($this->gotoHotplugDevices[$name]);
778 }
779 }
780 }
782 /* There are already defined hotplugs from other users we could use */
783 if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
784 $tmp =array();
785 foreach($this->gotoHotplugDevices as $plugs){
786 $tmp[] = $plugs['name'];
787 }
788 $this->dialog = new hotplugDialog($this->config,$tmp);
789 $this->is_dialog = true;
790 }
792 /* Dialog Aborted */
793 if(isset($_POST['HotPlugCancel'])){
794 unset($this->dialog);
795 $this->dialog= FALSE;
796 $this->is_dialog = false;
797 }
799 /* Dialod saved */
800 if(isset($_POST['HotPlugSave'])){
802 $this->dialog->save_object();
803 if(count($this->dialog->check())!=0){
804 foreach($this->dialog->check() as $msg){
805 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
806 }
807 }else{
808 $this->dialog->save_object();
809 $a_tmp = $this->dialog->save();
811 if(is_array($a_tmp)){
812 foreach($a_tmp as $name => $hotplug){
813 if($this->multiple_support_active){
814 $hotplug['UsedByAllUsers'] = TRUE;
815 }
816 $this->gotoHotplugDevices[$name]= $hotplug;
817 }
818 }
819 unset($this->dialog);
820 $this->dialog= FALSE;
821 $this->is_dialog = false;
822 }
823 }
825 if($this->multiple_support_active){
826 $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
827 }else{
828 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
829 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
830 }
832 /* Printer Assignment will managed below
833 * A printer can be assigned in two different ways and two different types
834 * There are 2 types of users assigned to a printer : user and admin
835 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
836 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
837 */
839 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
840 if(isset($_POST['gotoPrinterAdd'])){
842 $this->is_dialog=true;
843 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
844 }
846 if(isset($_POST['PrinterCancel'])){
847 $this->is_dialog=false;
848 unset($this->dialog);
849 $this->dialog=FALSE;
850 }
852 if(isset($_POST['PrinterSave'])){
853 if(count($this->dialog->check())!=0){
854 $tmp = $this->dialog->check();
855 foreach($tmp as $msg){
856 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
857 }
858 }else{
859 $this->dialog->save_object();
860 $tmp = $this->dialog->save();
861 $tmp2= $this->dialog->getPrinter(true);
863 foreach($tmp as $pname){
864 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
865 $printerObj->set_acl_base($tmp2[$pname]['dn']);
867 $type = false;
869 if($this->is_group){
870 if($this->dn == "new"){
871 $type = "AddGroup";
872 }elseif(isset($this->NewDeletedPrinters[$pname])){
873 $type = "AddGroup";
874 }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
875 $type = "AddGroup";
876 }
877 }else{
878 if($this->multiple_support_active){
879 $type = "AddUser";
880 }elseif(isset($this->NewDeletedPrinters[$pname])){
881 $type = "AddUser";
882 }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
883 $type = "AddUser";
884 }
885 }
887 if($type){
888 $this->gotoPrinter[$pname]=$tmp2[$pname];
889 $this->gotoPrinter[$pname]['mode']="user";
890 $this->add_del_printer_member_was_called = true;
892 $this->NewAddedPrinters[$pname] = $pname;
893 if(isset($this->NewDeletedPrinters[$pname])){
894 unset($this->NewDeletedPrinters[$pname]);
895 }
896 }
897 }
899 $this->is_dialog=false;
900 unset($this->dialog);
901 $this->dialog =FALSE;
902 }
903 }
905 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
906 $printer = $_POST['gotoPrinterSel'];
907 foreach($printer as $pname){
909 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
910 $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
912 $type = false;
913 if($this->is_group){
914 if(isset($this->NewAddedPrinters[$pname])){
915 $type = "Group";
916 }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
917 $type = "Group";
918 }
919 }else{
920 if(isset($this->NewAddedPrinters[$pname])){
921 $type = "User";
922 }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
923 $type = "User";
924 }
925 }
926 if($type){
927 $this->add_del_printer_member_was_called = true;
928 unset($this->gotoPrinter[$pname]);
930 $this->NewDeletedPrinters[$pname] = $pname;
931 if(isset($this->NewAddedPrinters[$pname])){
932 UNSET($this->NewAddedPrinters[$pname]);
933 }
934 }
935 }
936 }
938 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
939 $printers = $_POST['gotoPrinterSel'];
940 $this->add_del_printer_member_was_called = true;
941 foreach($printers as $printer){
942 if($this->gotoPrinter[$printer]['mode']=="user"){
943 $this->gotoPrinter[$printer]['mode']="admin";
944 }else{
945 $this->gotoPrinter[$printer]['mode']="user";
946 }
947 }
948 }
950 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
951 if($this->is_group){
952 msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
953 }else{
954 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
955 $this->gosaDefaultPrinter= "";
956 } else {
957 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
958 }
959 }
960 }
962 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
963 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
965 /* General behavior */
966 if(is_object($this->dialog)){
967 $this->dialog->save_object();
968 $disp =$this->dialog->execute();
969 return($disp);
970 }
972 /* Assign used attributes for multiple edit */
973 foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
974 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
975 $ubox ="use_".$box;
976 if(in_array($box,$this->multi_boxes)){
977 $smarty->assign($ubox,TRUE);
978 }else{
979 $smarty->assign($ubox,FALSE);
980 }
981 }
983 /* Als smarty vars are set. Get smarty template and generate output */
984 $smarty->assign("multiple_support",$this->multiple_support_active);
985 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
986 return($display);
987 }
989 function remove_from_parent()
990 {
991 /* only if it was an account*/
992 if (!$this->initially_was_account){
993 return;
994 }
996 /* include global link_info */
997 $ldap= $this->config->get_ldap_link();
999 /* Remove and write to LDAP */
1000 plugin::remove_from_parent();
1002 /* Don't save our template variables */
1003 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1005 /* Skip all these attributes */
1006 foreach($skip as $del){
1007 unset($this->attrs[$del]);
1008 }
1010 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1012 $ldap->cd($this->dn);
1013 $this->cleanup();
1014 $ldap->modify ($this->attrs);
1016 if($this->is_group){
1017 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1018 }else{
1019 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1020 }
1022 if (!$ldap->success()){
1023 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1024 }
1026 /* Optionally execute a command after we're done */
1027 $this->handle_post_events("remove",array("uid" => $this->uid));
1028 }
1031 /* Save data to object */
1032 function save_object()
1033 {
1034 /* Get all Posted vars
1035 * Setup checkboxes
1036 */
1037 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
1038 if(isset($_POST['iamposted'])){
1040 $PACL = $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1042 if(isset($_POST['kiosk_server'])){
1043 $tmp = $_POST['kiosk_server'];
1044 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1045 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1046 }
1047 }
1048 if(isset($_POST['kiosk_profile'])){
1049 $tmp = $_POST['kiosk_profile'];
1050 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1051 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1052 }
1053 }
1055 if(preg_match("/w/",$PACL)){
1056 if(isset($_POST['useProfile'])){
1057 $this->useProfile = true;
1058 }else{
1059 $this->useProfile = false;
1060 }
1061 }
1063 if($this->acl_is_writeable("gotoProfileFlagC")){
1064 if(isset($_POST['gotoProfileFlagC'])){
1065 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1066 }else{
1067 $this->gotoProfileFlagC = false;
1068 }
1069 }
1071 if($this->acl_is_writeable("gotoProfileFlagL")){
1072 if(isset($_POST['gotoProfileFlagL'])){
1073 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1074 }else{
1075 $this->gotoProfileFlagL = false;
1076 }
1077 }
1079 plugin::save_object();
1080 foreach($this->attributes as $s_attr){
1081 if((!isset($_POST[$s_attr])) ||
1082 in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1083 if(!$this->acl_is_writeable($s_attr)){
1084 continue;
1085 }else{
1086 if(isset($_POST[$s_attr])){
1087 $this->$s_attr = $_POST[$s_attr];
1088 }else{
1089 $this->$s_attr = false;
1090 }
1091 }
1092 }
1093 }
1094 }
1097 /* Check supplied data */
1098 function check()
1099 {
1100 /* Call common method to give check the hook */
1101 $message= plugin::check();
1103 $this->detect_grouptype();
1105 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1106 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1107 }
1108 if(!isset($this->attrs['objectClass'])){
1109 $this->attrs['objectClass']=array();
1110 }
1111 if(!$this->is_group){
1112 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1113 $message[]=(_("You need to enable POSIX features in order to enable evironment features!"));
1114 }
1115 }
1116 return ($message);
1117 }
1120 /* Save to LDAP */
1121 function save()
1122 {
1123 /* If group was renamed, all printer settings get lost
1124 */
1125 /* only save changed variables ....*/
1126 if ($this->gotoKioskProfile_Server != "none"){
1127 if(preg_match("/https/i",$_SERVER['HTTP_REFERER'])){
1128 $method="https://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1129 }else{
1130 $method="http://".$this->gotoKioskProfile_Server."/kiosk/".$this->gotoKioskProfile_Profile;
1131 }
1132 $this->gotoKioskProfile= $method;
1133 }else{
1134 $this->gotoKioskProfile= array();
1135 }
1137 plugin::save();
1138 $ldap= $this->config->get_ldap_link();
1140 $realyUsedAttrs= array();
1142 /* Save already used objectClasses */
1143 $ocs = $this->attrs['objectClass'];
1144 unset($ocs['count']);
1145 $this->attrs = array();
1146 $this->attrs['objectClass']= gosa_array_merge($ocs,$this->objectclasses);
1148 /* 1. Search all printers that have our uid/cn as member
1149 * 2. Delete this uid/cn from every single entry and save it again.
1150 * 2.1 There are different types of members: Users / Groups, this will be defined in $suffix
1151 * 2.2 And each type has two modes, Admin (e.g. 'gotoUserAdminPrinter') and Normal
1152 */
1154 $this->detect_grouptype();
1156 if($this->add_del_printer_member_was_called){
1158 $types = array( "gotoUserPrinter" => "AddUser",
1159 "gotoGroupPrinter" => "AddGroup",
1160 "gotoUserAdminPrinter" => "AddAdminUser",
1161 "gotoGroupAdminPrinter" => "AddAdminGroup");
1163 if($this->is_group){
1164 $s_suffix = "Group";
1165 $useVar = "cn";
1166 }else{
1167 $useVar = "uid";
1168 $s_suffix = "User";
1169 }
1171 /* Remove old entries */
1172 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."Printer=".$this->$useVar."))",array("*"));
1173 while($attr = $ldap->fetch()){
1174 $printerObj = NULL;
1175 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1176 $printerObj->set_acl_base($attr['dn']);
1177 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."Printer"],$this->$useVar);
1178 $printerObj->by_object['printgeneric']->save();
1179 }
1181 $ldap->search("(&(objectClass=gotoPrinter)(goto".$s_suffix."AdminPrinter=".$this->$useVar."))",array("*"));
1182 while($attr = $ldap->fetch()){
1183 $printerObj = NULL;
1184 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$attr['dn'],"printer");
1185 $printerObj->set_acl_base($attr['dn']);
1186 $printerObj->by_object['printgeneric']->DelMember($types["goto".$s_suffix."AdminPrinter"],$this->$useVar);
1187 $printerObj->by_object['printgeneric']->save();
1188 }
1190 foreach($this->gotoPrinter as $printer){
1191 $printerObj = NULL;
1192 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$printer['dn'],"printer");
1193 $printerObj->set_acl_base($printer['dn']);
1196 if($printer['mode'] == "admin") {
1197 $attribute = "goto".$s_suffix."AdminPrinter";
1198 }else{
1199 $attribute = "goto".$s_suffix."Printer";
1200 }
1202 $printerObj->by_object['printgeneric']->AddMember($types[$attribute],$this->dn);
1203 $printerObj->by_object['printgeneric']->save();
1204 }
1205 }
1207 /* Prepare HotPlug devices */
1208 $this->attrs['gotoHotplugDeviceDN'] = array();
1209 foreach($this->gotoHotplugDevices as $name => $device){
1210 $this->attrs['gotoHotplugDeviceDN'][]= $device['dn'];
1211 }
1213 /* Prepare LogonScripts */
1214 $this->attrs['gotoLogonScript'] = array();
1215 foreach($this->gotoLogonScripts as $name => $script){
1216 $this->attrs['gotoLogonScript'][] = $script['LogonName']."|".
1217 $script['LogonOverload'].$script['LogonLast']."|".
1218 $script['LogonPriority']."|".
1219 base64_encode($script['LogonData'])."|".
1220 $script['LogonDescription'];
1221 }
1223 /* Prepare Shares */
1224 $this->attrs['gotoShare']=array();
1225 foreach($this->gotoShares as $name => $share){
1226 $mntp= $share['mountPoint'];
1227 if (!preg_match('=^[a-z0-9+\._/%-]+$=i', $mntp)){
1228 $mntp= base64_encode($mntp);
1229 }
1230 $this->attrs['gotoShare'][] =$share['server']."|".$share['name']."|".$mntp."|".$share['PwdHash']."|".$share['Username'];
1231 }
1234 if($this->gotoXResolution == "auto") $this->gotoXResolution ="";
1235 $saveThis = array("gotoProfileQuota","gotoXResolution","gotoProfileServer","gotoKioskProfile","gosaDefaultPrinter");
1237 foreach($saveThis as $tosave){
1238 if(!empty($this->$tosave)){
1239 $this->attrs[$tosave]=$this->$tosave;
1240 }else{
1241 $this->attrs[$tosave]=array();
1242 }
1243 }
1245 /* Prepare Flags */
1246 $this->attrs['gotoProfileFlags'] = array($this->gotoProfileFlagC.$this->gotoProfileFlagL);
1247 if(empty($this->attrs['gotoProfileFlags'][0])){
1248 $this->attrs['gotoProfileFlags']=array();
1249 }
1251 if($this->useProfile == false){
1252 $this->attrs['gotoProfileFlags'] = preg_replace("/C/i","",$this->attrs['gotoProfileFlags']);
1253 $this->attrs['gotoProfileServer']= array();
1254 }
1256 $ldap->cat ($this->dn, array('dn'));
1257 if ($ldap->fetch()){
1258 $mode= "modify";
1259 } else {
1260 $mode= "add";
1261 $ldap->cd($this->config->current['BASE']);
1262 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
1263 }
1265 $ldap->cd($this->dn);
1266 $this->cleanup();
1267 $ldap->$mode($this->attrs);
1269 $cat = "users";
1270 if($this->is_group){
1271 $cat = "groups";
1272 }
1274 /* Log last action */
1275 if($this->initially_was_account){
1276 new log("modify",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1277 }else{
1278 new log("create",$cat."/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1279 }
1281 if (!$ldap->success()){
1282 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1283 }
1284 $this->handle_post_events($mode,array("uid"=>$this->uid));
1285 }
1287 /* Generate ListBox frindly output for the defined shares
1288 * Possibly Add or remove an attribute here,
1289 */
1290 function printOutAssignedShares()
1291 {
1292 $a_return = array();
1293 if(is_array($this->gotoShares)){
1294 foreach($this->gotoShares as $share){
1295 if(preg_match("/^!/",$share['server'])){
1296 $a_return[$share['name']."|".$share['server']]= preg_replace("/^!/","",$share['server'])."://".$share['name']." - "._("group share");
1297 }else{
1298 $a_return[$share['name']."|".$share['server']]= $share['server']."://".$share['name']." on ".$share['mountPoint']." as ".$share['Username'];
1299 }
1300 }
1301 natcasesort($a_return);
1302 }
1303 return($a_return);
1304 }
1306 /* Generate ListBox frindly output for the definedhotplugs
1307 * Possibly Add or remove an attribute here,
1308 */
1309 function printOutHotPlugDevices()
1310 {
1311 $a_return= array();
1312 if(is_array($this->gotoHotplugDevices)){
1313 foreach($this->gotoHotplugDevices as $key=>$device){
1314 $a_return[$key] = $device['name']." - ".$device['id'];
1315 }
1316 }
1317 return($a_return);
1318 }
1320 /* Generates ListBox frienly output of used printer devices
1321 * Append ' - admin' if printer is used in admin mode
1322 */
1323 function printOutPrinterDevices()
1324 {
1325 $a_return = array();
1327 if($this->acl_is_readable("gotoPrinter")){
1329 if(is_array($this->gotoPrinter)){
1330 foreach($this->gotoPrinter as $printer){
1331 if($printer['mode'] == "admin"){
1332 $a_return[$printer['cn'][0]]= $printer['cn'][0]." - "._("Administrator");
1333 }else{
1334 $a_return[$printer['cn'][0]]= $printer['cn'][0];
1335 }
1336 if ($printer['cn'][0] == $this->gosaDefaultPrinter){
1337 $a_return[$printer['cn'][0]].=" - "._("Default printer");
1338 }
1339 }
1340 }
1341 }
1342 return($a_return);
1343 }
1346 function PrepareForCopyPaste($source)
1347 {
1348 plugin::PrepareForCopyPaste($source);
1350 $class= get_class($this);
1351 $o_source = new $class($this->config,$source['dn']);
1352 foreach($this->CopyPasteVars as $attr){
1353 $this->$attr = $o_source->$attr;
1354 }
1355 }
1358 function saveCopyDialog()
1359 {
1360 if(isset($_POST['cn'])){
1361 $this->cn = $_POST['cn'];
1362 $this->uid = $_POST['cn'];
1363 }
1364 }
1367 /* Generates ListBox frienly output of used logonscripts
1368 */
1369 function printOutLogonScripts()
1370 {
1371 $a_return = array();
1372 if(is_array($this->gotoLogonScripts)){
1373 foreach($this->gotoLogonScripts as $script){
1374 $a_return[$script['LogonName']]= $script['LogonPriority']." - ".$script['LogonName'];
1375 }
1376 }
1377 return($a_return);
1378 }
1381 function multiple_execute()
1382 {
1383 /* Reset header toggle */
1384 $this->is_account = TRUE;
1385 return($this->execute());
1386 }
1389 /* Initialize plugin with given atribute arrays
1390 */
1391 function init_multiple_support($attrs,$all)
1392 {
1393 plugin::init_multiple_support($attrs,$all);
1395 /* Prepare Shares */
1396 if((isset($this->multi_attrs_all['gotoShare']))&&(is_array($this->multi_attrs_all['gotoShare']))){
1397 unset($this->multi_attrs_all['gotoShare']['count']);
1398 foreach($this->multi_attrs_all['gotoShare'] as $share){
1399 $tmp = $tmp2 = array();
1400 $tmp = split("\|",$share);
1401 $tmp2['server'] =$tmp[0];
1402 $tmp2['name'] =$tmp[1];
1404 /* Decode base64 if needed */
1405 if (!preg_match('%/%', $tmp[2])){
1406 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1407 } else {
1408 $tmp2['mountPoint'] =$tmp[2];
1409 }
1411 if(isset($tmp[3])){
1412 $tmp2['PwdHash'] =$tmp[3];
1413 }else{
1414 $tmp2['PwdHash'] ="";
1415 }
1416 if(isset($tmp[4])){
1417 $tmp2['Username'] =$tmp[4];
1418 }else{
1419 $tmp2['Username'] ="";
1420 }
1421 $tmp2['UsedByAllUsers'] = FALSE;
1422 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1423 }
1424 }
1426 /* Prepare Shares */
1427 if((isset($this->multi_attrs['gotoShare']))&&(is_array($this->multi_attrs['gotoShare']))){
1428 unset($this->multi_attrs['gotoShare']['count']);
1429 foreach($this->multi_attrs['gotoShare'] as $share){
1430 $tmp = $tmp2 = array();
1431 $tmp = split("\|",$share);
1432 $tmp2['server'] =$tmp[0];
1433 $tmp2['name'] =$tmp[1];
1435 /* Decode base64 if needed */
1436 if (!preg_match('%/%', $tmp[2])){
1437 $tmp2['mountPoint'] =base64_decode($tmp[2]);
1438 } else {
1439 $tmp2['mountPoint'] =$tmp[2];
1440 }
1442 if(isset($tmp[3])){
1443 $tmp2['PwdHash'] =$tmp[3];
1444 }else{
1445 $tmp2['PwdHash'] ="";
1446 }
1447 if(isset($tmp[4])){
1448 $tmp2['Username'] =$tmp[4];
1449 }else{
1450 $tmp2['Username'] ="";
1451 }
1452 $tmp2['UsedByAllUsers'] = TRUE;
1453 $this->gotoShares[$tmp[1]."|".$tmp[0]]=$tmp2;
1454 }
1455 }
1458 /* prepare LogonScripts */
1459 if((isset($this->multi_attrs_all['gotoLogonScript']))&&(is_array($this->multi_attrs_all['gotoLogonScript']))){
1460 unset($this->multi_attrs_all['gotoLogonScript']['count']);
1461 foreach($this->multi_attrs_all['gotoLogonScript'] as $device){
1462 $tmp = $tmp2 = array();
1463 $tmp = split("\|",$device);
1464 $tmp2['LogonName'] = $tmp[0];
1465 $tmp2['LogonPriority'] = $tmp[2];
1466 if(preg_match("/O/i",$tmp[1])){
1467 $tmp2['LogonOverload'] = "O";
1468 }else{
1469 $tmp2['LogonOverload'] = "";
1470 }
1471 if(preg_match("/L/i",$tmp[1])){
1472 $tmp2['LogonLast'] = "L";
1473 }else{
1474 $tmp2['LogonLast'] = "";
1475 }
1476 $tmp2['LogonData'] = base64_decode($tmp[3]);
1477 $tmp2['LogonDescription'] = $tmp[4];
1478 $tmp2['UsedByAllUsers'] = FALSE;
1479 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1480 }
1481 }
1483 /* prepare LogonScripts */
1484 if((isset($this->multi_attrs['gotoLogonScript']))&&(is_array($this->multi_attrs['gotoLogonScript']))){
1485 unset($this->multi_attrs['gotoLogonScript']['count']);
1486 foreach($this->multi_attrs['gotoLogonScript'] as $device){
1487 $tmp = $tmp2 = array();
1488 $tmp = split("\|",$device);
1489 $tmp2['LogonName'] = $tmp[0];
1490 $tmp2['LogonPriority'] = $tmp[2];
1491 if(preg_match("/O/i",$tmp[1])){
1492 $tmp2['LogonOverload'] = "O";
1493 }else{
1494 $tmp2['LogonOverload'] = "";
1495 }
1496 if(preg_match("/L/i",$tmp[1])){
1497 $tmp2['LogonLast'] = "L";
1498 }else{
1499 $tmp2['LogonLast'] = "";
1500 }
1501 $tmp2['LogonData'] = base64_decode($tmp[3]);
1502 $tmp2['LogonDescription'] = $tmp[4];
1503 $tmp2['UsedByAllUsers'] = TRUE;
1504 $this->gotoLogonScripts[$tmp[0]]=$tmp2;
1505 }
1506 }
1508 /* Prepare hotplugs */
1509 if(isset($this->multi_attrs_all['gotoHotplugDeviceDN']) && is_array($this->multi_attrs_all['gotoHotplugDeviceDN'])){
1510 $ldap = $this->config->get_ldap_link();
1511 $ldap->cd($this->config->current['BASE']);
1512 for($i = 0 ; $i < $this->multi_attrs_all['gotoHotplugDeviceDN']['count'] ; $i ++){
1513 $ldap->cat($this->multi_attrs_all['gotoHotplugDeviceDN'][$i]);
1514 if($ldap->count()){
1515 $multi_attrs_all = $ldap->fetch();
1517 if(isset($multi_attrs_all['gotoHotplugDevice'][0])){
1518 $tmp = preg_split("/\|/",$multi_attrs_all['gotoHotplugDevice'][0]);
1519 $tmp2 = array();
1520 $tmp2['name'] = $multi_attrs_all['cn'][0];
1521 $tmp2['description'] = $tmp[0];
1522 $tmp2['id'] = $tmp[1];
1523 $tmp2['produkt'] = $tmp[2];
1524 $tmp2['vendor'] = $tmp[3];
1525 $tmp2['dn'] = $multi_attrs_all['dn'];
1526 $tmp2['UsedByAllUsers'] = FALSE;
1527 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1528 }
1529 }
1530 }
1531 }
1533 /* Prepare hotplugs */
1534 if(isset($this->multi_attrs['gotoHotplugDeviceDN']) && is_array($this->multi_attrs['gotoHotplugDeviceDN'])){
1535 $ldap = $this->config->get_ldap_link();
1536 $ldap->cd($this->config->current['BASE']);
1537 for($i = 0 ; $i < $this->multi_attrs['gotoHotplugDeviceDN']['count'] ; $i ++){
1538 $ldap->cat($this->multi_attrs['gotoHotplugDeviceDN'][$i]);
1539 if($ldap->count()){
1540 $multi_attrs = $ldap->fetch();
1542 if(isset($multi_attrs['gotoHotplugDevice'][0])){
1543 $tmp = preg_split("/\|/",$multi_attrs['gotoHotplugDevice'][0]);
1544 $tmp2 = array();
1545 $tmp2['name'] = $multi_attrs['cn'][0];
1546 $tmp2['description'] = $tmp[0];
1547 $tmp2['id'] = $tmp[1];
1548 $tmp2['produkt'] = $tmp[2];
1549 $tmp2['vendor'] = $tmp[3];
1550 $tmp2['dn'] = $multi_attrs['dn'];
1551 $tmp2['UsedByAllUsers'] = TRUE;
1552 $this->gotoHotplugDevices[$tmp2['dn']] = $tmp2;
1553 }
1554 }
1555 }
1556 }
1557 $this->gotoHotplugDevices = array_values($this->gotoHotplugDevices);
1558 for($i = 0 ; $i < strlen($this->gotoProfileFlags) ; $i ++){
1559 $chr = $this->gotoProfileFlags[$i];
1560 $name = "gotoProfileFlag".$chr;
1561 $this->$name=$chr;
1562 }
1563 $this->update_kiosk_profiles();
1564 $this->gotoKioskProfile= preg_replace("/^.*\//i","",$this->gotoKioskProfile);
1566 if((!empty($this->gotoProfileServer))||($this->gotoProfileFlagC=="C")){
1567 $this->useProfile = true;
1568 }else{
1569 $this->useProfile = false;
1570 }
1572 }
1575 function set_multi_edit_values($attrs)
1576 {
1577 $shares = $this->gotoShares;
1578 $scripts= $this->gotoLogonScripts;
1579 $plugs= $this->gotoHotplugDevices;
1580 plugin::set_multi_edit_values($attrs);
1582 $this->gotoShares = $shares;
1583 $this->gotoLogonScripts = $scripts;
1584 $this->gotoHotplugDevices = $plugs;
1586 foreach($attrs['gotoShares'] as $name => $share){
1587 if($share['UsedByAllUsers'] == TRUE){
1588 $this->gotoShares[$name] = $share;
1589 }
1590 }
1591 foreach($this->gotoShares as $name => $share){
1592 if(!isset($attrs['gotoShares'][$name])){
1593 unset($this->gotoShares[$name]);
1594 }
1595 }
1596 foreach($attrs['gotoLogonScripts'] as $name => $script){
1597 if($script['UsedByAllUsers'] == TRUE){
1598 $this->gotoLogonScripts[$name] = $script;
1599 }
1600 }
1601 foreach($this->gotoLogonScripts as $name => $script){
1602 if(!isset($attrs['gotoLogonScripts'][$name])){
1603 unset($this->gotoLogonScripts[$name]);
1604 }
1605 }
1606 $tmp = array();
1607 foreach($this->gotoHotplugDevices as $entry){
1608 $tmp[$entry['dn']] = $entry;
1609 }
1611 foreach($attrs['gotoHotplugDevices'] as $name => $plug){
1612 if($plug['UsedByAllUsers'] == TRUE){
1613 $tmp[$plug['dn']] = $plug;
1614 }
1615 }
1616 foreach($tmp as $name => $plug){
1617 $found = false;
1618 foreach($attrs['gotoHotplugDevices'] as $test){
1619 if($test['dn'] == $name){
1620 $found = true;
1621 }
1622 }
1623 if(!$found){
1624 unset($tmp[$name]);
1625 }
1626 }
1627 }
1630 /* Return selected values for multiple edit */
1631 function get_multi_edit_values()
1632 {
1633 $ret = plugin::get_multi_edit_values();
1634 $ret['gotoShares'] = $this->gotoShares;
1635 $ret['gotoLogonScripts'] = $this->gotoLogonScripts;
1636 $ret['gotoHotplugDevices'] = $this->gotoHotplugDevices;
1638 if(in_array("gotoPrinter",$this->multi_boxes)){
1639 $ret['gotoPrinter'] = $this->gotoPrinter;
1640 $ret['gotoPrinterSel'] = $this->gotoPrinterSel;
1641 $ret['gosaDefaultPrinter'] = $this->gosaDefaultPrinter;
1643 /* Force printer reset */
1644 $ret['add_del_printer_member_was_called'] = TRUE;
1645 }
1647 if(in_array("gotoProfileFlagL",$this->multi_boxes)){
1648 $ret['gotoProfileFlagL'] = $this->gotoProfileFlagL;
1649 }
1651 if(in_array("useProfile",$this->multi_boxes)){
1652 $ret['useProfile']=$this->useProfile;
1653 if(in_array("gotoProfileServer",$this->multi_boxes)){
1654 $ret['gotoProfileServer']=$this->gotoProfileServer;
1655 }
1656 if(in_array("gotoProfileQuota",$this->multi_boxes)){
1657 $ret['gotoProfileQuota']=$this->gotoProfileQuota;
1658 }
1659 if(in_array("gotoProfileFlagC",$this->multi_boxes)){
1660 $ret['gotoProfileFlagC'] = $this->gotoProfileFlagC;
1661 }
1662 }
1663 if(in_array("gotoXResolution",$this->multi_boxes)){
1664 $ret['gotoXResolution'] = $this->gotoXResolution;
1665 }
1666 if(in_array("kiosk_server",$this->multi_boxes)){
1667 $ret['gotoKioskProfile_Server'] = $this->gotoKioskProfile_Server;
1668 $ret['gotoKioskProfile_Profile'] = $this->gotoKioskProfile_Profile;
1669 }
1670 return($ret);
1671 }
1674 function multiple_check()
1675 {
1676 $message = plugin::multiple_check();
1677 $this->detect_grouptype();
1679 if(preg_match("/[^0-9]/",$this->gotoProfileQuota) && in_array("gotoProfileQuota",$this->multi_boxes)) {
1680 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1681 }
1682 return($message);
1683 }
1686 function multiple_save_object()
1687 {
1688 if(isset($_POST['environment_multiple_posted'])){
1689 plugin::multiple_save_object();
1691 if(isset($_POST['useProfile'])){
1692 $this->useProfile = true;
1693 }else{
1694 $this->useProfile = false;
1695 }
1696 if(isset($_POST['gotoProfileFlagC'])){
1697 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1698 }else{
1699 $this->gotoProfileFlagC = false;
1700 }
1702 if(isset($_POST['gotoProfileFlagL'])){
1703 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1704 }else{
1705 $this->gotoProfileFlagL = false;
1706 }
1708 foreach(array("gotoProfileFlagL","gotoPrinter","kiosk_server","gotoXResolution",
1709 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $attr){
1710 $uattr = "use_".$attr;
1711 if(isset($_POST[$uattr])){
1712 $this->multi_boxes[] = $attr;
1713 }
1714 }
1715 if(isset($_POST['kiosk_server'])){
1716 $tmp = $_POST['kiosk_server'];
1717 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1718 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1719 }
1720 }
1721 if(isset($_POST['kiosk_profile'])){
1722 $tmp = $_POST['kiosk_profile'];
1723 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1724 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1725 }
1726 }
1728 }
1729 }
1731 /* Return plugin informations for acl handling
1732 #FIXME these ACLs should work for groups too */
1733 static function plInfo()
1734 {
1735 return (array("plShortName" => _("Environment"),
1736 "plDescription" => _("Environment settings"), // Description
1737 "plSelfModify" => TRUE,
1738 "plDepends" => array("user", "posixAccount"), // This plugin depends on
1739 "plPriority" => 3, // Position in tabs
1740 "plSection" => array("personal" => _("My account")),
1741 "plCategory" => array("users",
1742 "groups"),
1743 "plOptions" => array("resolution_hook" => array("type" => "string",
1744 "description" => _("Command to extend the list of possible screen resolutions"))),
1746 "plProvidedAcls" => array(
1748 "gotoProfileFlagL" => _("Resolution changeable during session") ,
1749 "gotoProfileFlagC" => _("Cache profile localy") ,
1751 "gotoProfileQuota" => _("Profile quota") ,
1752 "gotoProfileServer" => _("Profile server") ,
1754 "gotoXResolution" => _("Resolution") ,
1755 "gotoKioskProfile" => _("Kiosk profile") ,
1757 "gosaDefaultPrinter" => _("Default printer") ,
1758 "gotoLogonScript" => _("Logon script") ,
1759 "gotoHotplugDevice" => _("Hotplug devices"),
1760 "gotoShare" => _("Shares"))
1761 ));
1762 }
1763 }
1765 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
1766 ?>