d59eb4120577bbc25378481486c8d3320665d8a6
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 $tmp3 = array();
249 $ldap = $this->config->get_ldap_link();
250 $ldap->cd($this->config->current['BASE']);
251 $ldap->search("(&(objectClass=goEnvironmentServer)(gotoKioskProfile=*)(cn=*))",array("cn","gotoKioskProfile"));
252 $cnt = 0;
253 while($attrs = $ldap->fetch()){
254 for($i = 0 ; $i < $attrs['gotoKioskProfile']['count'] ; $i ++){
255 $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
256 $name = preg_replace("/^.*\//","",$attrs['gotoKioskProfile'][$i]);
257 $tmp1[$attrs['cn'][0]][] = $name;
258 $tmp3[$attrs['cn'][0]][$name] = $attrs['gotoKioskProfile'][$i];
259 }
260 $tmp2[$attrs['cn'][0]]= $attrs['cn'][0];
261 $cnt ++;
262 }
264 if($cnt && $this->config->search("environment","kioskpath",array('menu','tabs'))){
265 $this->kiosk_enabled = TRUE;
266 }
268 $this->gotoKioskProfiles['BY_SERVER'] = $tmp1;
269 $this->gotoKioskProfiles['SERVERS'] = $tmp2;
270 $this->gotoKioskProfiles['MAP'] = $tmp3;
272 $this->gotoKioskProfile_Server = preg_replace("/^.*:\/\/([^\/]*).*$/","\\1",$this->gotoKioskProfile);
273 $this->gotoKioskProfile_Profile= preg_replace("/^.*\//","",$this->gotoKioskProfile);
275 $error = false;
276 if(!in_array($this->gotoKioskProfile_Server, $this->gotoKioskProfiles['SERVERS'])){
277 $this->gotoKioskProfile_Server = key($this->gotoKioskProfiles['SERVERS']);
278 $error = true;
279 }
281 if(!in_array($this->gotoKioskProfile_Profile, $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
282 $this->gotoKioskProfile_Profile = $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server][0];
283 $error = true;
284 }
285 if($error && !empty($this->gotoKioskProfile)){
286 $this->gotoKioskProfile_Server ="none";
287 $this->gotoKioskProfile_Profile="";
288 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);
289 }
290 }
293 /* Detect type of edited object (user|group)*/
294 function detect_grouptype()
295 {
296 if((!isset($this->parent))&&(!$this->is_account)){
297 $this->is_group = false;
298 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
299 $this->is_group = true;
300 }else{
301 $this->is_group = false;
302 }
303 }
306 function execute()
307 {
309 /* Call parent execute */
310 plugin::execute();
311 /* Log view */
312 if($this->is_account && !$this->view_logged){
313 $this->view_logged = TRUE;
314 if(isset($this->parent->by_object['user']) || (isset($this->attrs['objectClass']) &&in_array("gosaAccount",$this->attrs['objectClass']))){
315 new log("view","users/".get_class($this),$this->dn);
316 }else{
317 new log("view","groups/".get_class($this),$this->dn);
318 }
319 }
321 /* Are we editing from MyAccount and not editing a user */
322 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
324 /* Check profile server */
325 if($this->acl_is_writeable("gotoProfileServer",$WriteOnly)){
326 if(!empty($this->gotoProfileServer) && !isset($this->gotoProfileServers[$this->gotoProfileServer])){
327 if(count($this->gotoProfileServers)){
329 /* Get First Profile */
330 $new = key($this->gotoProfileServers);
332 /* Another profile server found */
333 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Switched to server '%s'."), $this->gotoProfileServer, $new), WARNING_DIALOG);
334 }else{
336 /* No other profile servers found */
337 msg_dialog::display(_("Warning"), sprintf(_("Profile server '%s' is not available anymore. Kiosk profile will be disabled."), $this->gotoProfileServer), WARNING_DIALOG);
338 $this->gotoProfileServer = "none";
339 }
340 }
341 }
343 $this->detect_grouptype();
345 /* Fill templating stuff */
346 $smarty= get_smarty();
347 $smarty->assign("kiosk_enabled",$this->kiosk_enabled);
348 $display= "";
350 $smarty->assign("is_group",$this->is_group);
352 /* Prepare all variables for smarty */
353 foreach($this->attributes as $s_attr){
354 /* Set value*/
355 $smarty->assign($s_attr,$this->$s_attr);
357 /* Set checkbox state*/
358 if(empty($this->$s_attr)){
359 $smarty->assign($s_attr."CHK","");
360 }else{
361 $smarty->assign($s_attr."CHK"," checked ");
362 }
364 /* Prepare ACL settings*/
365 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
366 }
368 /* Is accout enabled | are we editing from usermenu or admin menu
369 All these tab management is done here
370 */
373 /* Working from Usermenu an the Account is currently disbled
374 * this->parent : is only set if we are working in a list of tabs
375 * is_account : is only true if the needed objectClass is given
376 */
377 if((!isset($this->parent))&&(!$this->is_account)){
378 /* We are currently editing this tab from usermenu, but this account is not enabled */
379 $smarty->assign("is_account",$this->is_account);
380 /* Load template */
381 $display .= $smarty->fetch(get_template_path('environment.tpl', TRUE));
382 /* Avoid the "You are currently editing ...." message when you leave this tab */
383 $display .= back_to_main();
384 /* Display our message to the user */
385 return $display;
388 /* We are currently editing from group tabs, because
389 * $this->parent is set
390 * posixAccount is not set, so we are not in usertabs.
391 */
392 }elseif((isset($this->parent))&&(!isset($this->parent->by_object['posixAccount']))){
393 $smarty->assign("is_account","true");
394 $this->uid = $this->cn;
395 $this->attrs['uid'] = $this->cn;
397 /* Change state if needed */
398 if (isset($_POST['modify_state'])){
399 if(($this->acl_is_createable() && !$this->is_account) ||
400 ($this->acl_is_removeable() && $this->is_account)){
401 $this->is_account= !$this->is_account;
402 }
403 }
404 /* Group Dialog with enabled environment options */
405 if ($this->is_account){
406 $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
407 msgPool::featuresEnabled(_("Environment")));
408 } else {
410 /* Environment is disabled
411 If theres is no posixAccount enabled, you won't be able to enable
412 environment extensions
413 */
414 if((isset($this->parent->by_object['group']))||(isset($this->attrs['objectClass']))&&((in_array("posixAccount",$this->attrs['objectClass'])))){
415 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
416 msgPool::featuresDisabled(_("Environment")));
417 return $display;
418 }else{
419 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
420 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
421 return $display;
422 }
423 }
424 }else{
425 /* Editing from Usermenu
426 * Tell smarty that this accoutn is enabled
427 */
428 $smarty->assign("is_account","true");
430 /* Change state if needed */
431 if (isset($_POST['modify_state'])){
432 if(($this->acl_is_createable() && !$this->is_account) ||
433 ($this->acl_is_removeable() && $this->is_account)){
434 $this->is_account= !$this->is_account;
435 }
436 }
438 if(isset($this->parent)){
440 // 3. Account enabled . Editing from adminmenu
441 if ($this->is_account){
442 $display= $this->show_enable_header(msgPool::removeFeaturesButton(_("Environment")),
443 msgPool::featuresEnabled(_("Environment")));
444 } else {
446 if($this->parent->by_object['posixAccount']->is_account==true){
447 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
448 msgPool::featuresDisabled(_("Environment")));
449 return $display;
450 }else{
451 $display= $this->show_enable_header(msgPool::addFeaturesButton(_("Environment")),
452 msgPool::featuresDisabled(_("Environment"), _("POSIX")), TRUE);
453 return $display;
454 }
455 }
456 }
457 }
459 /* Reset header toggle */
460 if($this->multiple_support_active){
461 $display = "";
462 }
464 /* Account is Account : is_accounbt=true.
465 * Else we won't reach this.
466 */
468 /* Prepare all variables for smarty */
469 foreach($this->attributes as $s_attr){
470 /* Set value*/
471 $smarty->assign($s_attr,$this->$s_attr);
473 /* Set checkbox state*/
474 if(empty($this->$s_attr)){
475 $smarty->assign($s_attr."CHK","");
476 }else{
477 $smarty->assign($s_attr."CHK"," checked ");
478 }
480 /* Prepare ACL settings*/
481 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
482 }
484 foreach(array("gotoHotplugDevice","gotoProfileFlagC","gotoProfileFlagL") as $s_attr){
485 $smarty->assign($s_attr."ACL",$this->getacl($s_attr,$WriteOnly));
486 }
488 if($WriteOnly) {
489 $smarty->assign("gotoPrinterACL","r");
490 }else{
491 $smarty->assign("gotoPrinterACL","rw");
492 }
495 $smarty->assign("useProfile",$this->useProfile);
496 if(empty($this->useProfile) && !$this->multiple_support_active){
497 $smarty->assign("useProfileCHK","");
498 $smarty->assign("gotoProfileServerACL" , preg_replace("/w/","",$this->getacl("gotoProfileServer",$WriteOnly)));
499 $smarty->assign("gotoProfileQuotaACL" , preg_replace("/w/","",$this->getacl("gotoProfileQuota",$WriteOnly)));
500 $smarty->assign("gotoProfileFlagCACL" , preg_replace("/w/","",$this->getacl("gotoProfileFlagC",$WriteOnly)));
501 }else{
502 $smarty->assign("useProfileCHK"," checked ");
503 }
505 $smarty->assign("gotoProfileServerWriteable", $this->acl_is_writeable("gotoProfileServer",$WriteOnly));
506 $smarty->assign("gotoProfileACL", $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly));
508 /* HANDLE Profile Settings here
509 * Assign available Quota and resolution settings
510 * Get all available profile server
511 * Get cache checkbox
512 * Assign this all to Smarty
513 */
515 if(empty($this->gotoProfileFlagL)){
516 $smarty->assign("gotoProfileFlagLCHK"," ");
517 }else{
518 $smarty->assign("gotoProfileFlagLCHK"," checked ");
519 }
521 if(empty($this->gotoProfileFlagC)){
522 $smarty->assign("gotoProfileFlagCCHK"," ");
523 }else{
524 $smarty->assign("gotoProfileFlagCCHK"," checked ");
525 }
528 $smarty->assign("gotoXResolutions" , $this->gotoXResolutions);
529 $smarty->assign("gotoXResolutionKeys" , array_flip($this->gotoXResolutions));
531 $smarty->assign("gotoProfileServers",$this->gotoProfileServers);
532 if(!is_array($this->gotoProfileServers)){
533 $this->gotoProfileServers =array();
534 }
535 $smarty->assign("gotoProfileServerKeys",array_flip($this->gotoProfileServers));
537 /* Handle kiosk profiles*/
538 $smarty->assign("kiosk_servers" , $this->gotoKioskProfiles['SERVERS']);
539 $smarty->assign("kiosk_server" , $this->gotoKioskProfile_Server);
540 $smarty->assign("kiosk_profiles" , $this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server]);
541 $smarty->assign("kiosk_profile" , $this->gotoKioskProfile_Profile);
544 /* Logonscript Management
545 * Get available LogonScripts (possibly grey out (or mark) these script that are defined for the group)
546 * Perform add Delete edit Posts
547 */
549 /* Dialog Save */
550 if(isset($_POST['LogonSave'])){
552 if(!$this->acl_is_writeable("gotoLogonScript")){
553 msg_dialog::display(_("Permission error"), msgPool::permModify(_("Logon scripts")), ERROR_DIALOG);
554 unset($this->dialog);
555 $this->dialog=FALSE;
556 $this->is_dialog=false;
557 }else{
558 $this->dialog->save_object();
559 if(count($this->dialog->check())!=0){
560 foreach($this->dialog->check() as $msg){
561 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
562 }
563 }else{
564 $tmp = $this->dialog->save();
565 unset($this->dialog);
566 $this->dialog=FALSE;
567 $this->is_dialog=false;
569 if($this->multiple_support_active){
570 $tmp['UsedByAllUsers'] = TRUE;
571 }
572 $this->gotoLogonScripts[$tmp['LogonName']]=$tmp;
573 }
574 }
575 }
578 /* Dialog Quit without saving */
579 if(isset($_POST['LogonCancel'])){
580 $this->is_dialog= false;
581 unset($this->dialog);
582 $this->dialog= FALSE;
583 }
585 /* Check Edit Del New Posts for a selected LogonScript */
586 if($this->acl_is_writeable("gotoLogonScript") &&
587 (isset($_POST['gotoLogonScriptNew'])) || isset($_POST['gotoLogonScriptEdit']) ||isset($_POST['gotoLogonScriptDel'])){
589 /* New Logon Script: Open an edit dialog, we don't need a $_POST['gotoLogonScript'] here.
590 * In this case we create a new Logon Script.
591 */
592 if(isset($_POST['gotoLogonScriptNew'])){
593 $this->is_dialog = true;
594 $this->dialog = new logonManagementDialog($this->config,$this->dn);
595 }
597 /* If we receive a Delete request and there is a Script selected in the selectbox, delete this one.
598 * We only can delete if there is an entry selected.
599 */
600 if((isset($_POST['gotoLogonScriptDel']))&&(isset($_POST['gotoLogonScript']))){
601 unset($this->gotoLogonScripts[$_POST['gotoLogonScript']]);
602 }
604 /* In this case we want to edit an existing entry, we open a new Dialog to allow editing.
605 * There must be an entry selected to perform edit request.
606 */
607 if((isset($_POST['gotoLogonScriptEdit']))&&(isset($_POST['gotoLogonScript']))){
608 $is_entry = $this->gotoLogonScripts[$_POST['gotoLogonScript']];
609 $this->is_dialog = true;
610 $this->dialog = new logonManagementDialog($this->config,$this->dn,$is_entry);
611 }
612 }
614 /* Append List to smarty*/
615 if($this->multiple_support_active){
616 $smarty->assign("gotoLogonScripts", $this->gotoLogonScripts);
617 $smarty->assign("gotoLogonScriptKeysCnt",count($this->gotoLogonScripts));
618 }else{
619 $ls = $this->printOutLogonScripts();
620 $smarty->assign("gotoLogonScripts", $ls);
621 $smarty->assign("gotoLogonScriptKeys",array_flip($ls));
622 $smarty->assign("gotoLogonScriptKeysCnt",count($ls));
623 }
625 /* In this section server shares will be defined
626 * A user can select one of the given shares and a mount point
627 * and attach this combination to his setup.
628 */
630 $smarty->assign("gotoShareSelections", $this->gotoShareSelections);
631 if(!is_array($this->gotoShareSelections)){
632 $this->gotoShareSelections = array();
633 }
634 $smarty->assign("gotoShareSelectionKeys", array_flip($this->gotoShareSelections));
636 /* if $_POST['gotoShareAdd'] is set, we will try to add a new entry
637 * This entry will be, a combination of mountPoint and sharedefinitions
638 */
639 if(isset($_POST['gotoShareAdd']) && $this->acl_is_writeable("gotoShare")){
641 /* We assign a share to this user, if we don't know where to mount the share */
642 if(!isset($_POST['gotoShareSelection']) || get_post('gotoShareSelection') == ""){
643 msg_dialog::display(_("Error"), msgPool::invalid(_("Share")), ERROR_DIALOG);
644 }elseif((!isset($_POST['gotoShareMountPoint']))||(empty($_POST['gotoShareMountPoint']))||(preg_match("/[\|]/i",$_POST['gotoShareMountPoint']))){
645 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
646 }elseif(preg_match('/ /', $_POST['gotoShareMountPoint'])){
647 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point"), "/[^\s]/"), ERROR_DIALOG);
648 }elseif(!(
649 preg_match("/^\//",$_POST['gotoShareMountPoint']) ||
650 preg_match("/^~/",$_POST['gotoShareMountPoint']) ||
651 preg_match("/^\$HOME/",$_POST['gotoShareMountPoint']) ||
652 preg_match("/^.HOME/",$_POST['gotoShareMountPoint']) ||
653 preg_match("/^\$USER/",$_POST['gotoShareMountPoint']) ||
654 preg_match("/^.USER/",$_POST['gotoShareMountPoint']) ||
655 preg_match("/^%/",$_POST['gotoShareMountPoint'])
656 )
657 ){
658 msg_dialog::display(_("Error"), msgPool::invalid(_("Mount point")), ERROR_DIALOG);
659 }else{
660 $a_share = $this->gotoAvailableShares[$_POST['gotoShareSelection']];
661 $s_mount = $_POST['gotoShareMountPoint'];
662 $s_user = $_POST['ShareUser'];
663 /* Preparing the new assignment */
664 $this->gotoShares[$a_share['name']."|".$a_share['server']]=$a_share;
665 $this->gotoShares[$a_share['name']."|".$a_share['server']]['Username']=$s_user;
666 $this->gotoShares[$a_share['name']."|".$a_share['server']]['PwdHash']="";
667 $this->gotoShares[$a_share['name']."|".$a_share['server']]['mountPoint']=$s_mount;
669 if($this->multiple_support_active){
670 $this->gotoShares[$a_share['name']."|".$a_share['server']]['UsedByAllUsers']= TRUE;
671 }
672 }
673 }
675 /* if the Post gotoShareDel is set, someone asked GOsa to delete the selected entry (if there is one selected)
676 * If there is no defined share selected, we will abort the deletion without any message
677 */
678 $once = true;
679 if($this->acl_is_writeable("gotoShare")){
680 foreach($_POST as $name => $value){
681 if((preg_match("/^gotoShareDel_/",$name)) && ($once)){
682 $once = false;
683 $key = preg_replace("/^gotoShareDel_/","",$name);
684 $key = preg_replace("/_+[xy]$/","",$key);
685 $key = base64_decode($key);
686 if(isset($this->gotoShares[$key])) {
687 unset($this->gotoShares[$key]);
688 }
690 /* Remove corresponding password entry, too. This is a workaround
691 to get rid of old-style entries. */
692 $key= preg_replace("/\|/", "|!", $key);
693 if(isset($this->gotoShares[$key])) {
694 unset($this->gotoShares[$key]);
695 }
696 }
697 if((preg_match("/^gotoShareResetPwd_/",$name)) && ($once)){
698 $once = false;
699 $key = preg_replace("/^gotoShareResetPwd_/","",$name);
700 $key = preg_replace("/_+[xy]$/","",$key);
701 $key = base64_decode($key);
702 $this->gotoShares[$key]['PwdHash'] = "";
703 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
704 unset($this->gotoShares[$key]);
705 }
706 }
707 }
708 }
709 $divlistShares = new divSelectBox("gotoShares");
710 $divlistShares->SetHeight(100);
713 $tmp = array();
714 if($this->acl_is_readable("gotoShares")){
715 $tmp = $this->printOutAssignedShares();
716 }
719 foreach($tmp as $key => $value){
720 $img = "";
722 /* Skip apssword only entries */
723 if( empty($this->gotoShares[$key]['server']) &&
724 empty($this->gotoShares[$key]['name']) &&
725 empty($this->gotoShares[$key]['mountPoint']) &&
726 empty($this->gotoShares[$key]['Username'])){
727 continue;
728 }
730 $color = "";
731 if($this->multiple_support_active){
732 if($this->gotoShares[$key]['UsedByAllUsers']){
733 $value .= " (<b>"._("Used by all users")."</b>)";
734 }else{
735 $color = "color: #999999;";
736 $value .= " (<b>"._("Used by some users")."</b>)";
737 }
738 }
740 /* Check if entry starts with an ! */
741 if(preg_match("/^!/",$this->gotoShares[$key]['server'])){
743 /* If we are currently editing groups environment, skip those ! entries */
744 if($this->is_group) continue;
746 /* Create pwd reset images */
747 if($this->gotoShares[$key]['PwdHash'] != ""){
748 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
749 title='"._("Reset password hash")."'>";
750 }
751 $field1 = array("string" => "<font style=\"color:#C0C0C0\">".$value."</font>" , "attach" => "style='".$color."'");
752 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
753 }else{
755 /* Create pwd reset img && delete image */
756 if($this->gotoShares[$key]['PwdHash'] != ""){
757 $img.= "<input type='image' name='gotoShareResetPwd_".base64_encode($key)." 'src='images/list_reset_password.png' alt='"._("Reset password hash")."'
758 title='"._("Reset password hash")."'>";
759 $img.= " ";
760 }
761 $img.= "<input type='image' name='gotoShareDel_".base64_encode($key)." 'src='images/edittrash.png' alt='".msgPool::delButton()."'
762 title='"._("Delete share entry")."'>";
763 $field1 = array("string" => $value , "attach" => "style='".$color."'");
764 $field2 = array("string" => $img , "attach" => "style='border-right:0px;'");
765 }
766 $divlistShares->AddEntry(array($field1,$field2));
767 }
768 $smarty->assign("divlistShares",$divlistShares->DrawList());
770 /* Hotplug devices will be handled here
771 * There are 3 possible methods for this feature
772 * Create a new Hotplug, A Dialog will open where you can specify some hotplug information
773 * Delete will erase an entry, the entry must be selcted in the ListBox first
774 * Editing an entry will open a dialog where the informations about the selcted entry can be changed
775 */
777 /* We have to delete the selected hotplug from the list*/
778 if((isset($_POST['gotoHotplugDeviceDel']))&&(isset($_POST['gotoHotplugDevice_post'])) && $this->acl_is_writeable("gotoHotplugDevice")){
779 if($this->acl_is_writeable("gotoHotplugDevice")){
780 foreach($_POST['gotoHotplugDevice_post'] as $name){
781 unset($this->gotoHotplugDevices[$name]);
782 }
783 }
784 }
786 /* There are already defined hotplugs from other users we could use */
787 if(isset($_POST['gotoHotplugDeviceUse']) && $this->acl_is_writeable("gotoHotplugDevice")){
788 $tmp =array();
789 foreach($this->gotoHotplugDevices as $plugs){
790 $tmp[] = $plugs['name'];
791 }
792 $this->dialog = new hotplugDialog($this->config,$tmp);
793 $this->is_dialog = true;
794 }
796 /* Dialog Aborted */
797 if(isset($_POST['HotPlugCancel'])){
798 unset($this->dialog);
799 $this->dialog= FALSE;
800 $this->is_dialog = false;
801 }
803 /* Dialod saved */
804 if(isset($_POST['HotPlugSave'])){
806 $this->dialog->save_object();
807 if(count($this->dialog->check())!=0){
808 foreach($this->dialog->check() as $msg){
809 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
810 }
811 }else{
812 $this->dialog->save_object();
813 $a_tmp = $this->dialog->save();
815 if(is_array($a_tmp)){
816 foreach($a_tmp as $name => $hotplug){
817 if($this->multiple_support_active){
818 $hotplug['UsedByAllUsers'] = TRUE;
819 }
820 $this->gotoHotplugDevices[$name]= $hotplug;
821 }
822 }
823 unset($this->dialog);
824 $this->dialog= FALSE;
825 $this->is_dialog = false;
826 }
827 }
829 if($this->multiple_support_active){
830 $smarty->assign("gotoHotplugDevices",$this->gotoHotplugDevices);
831 }else{
832 $smarty->assign("gotoHotplugDevices",$this->printOutHotPlugDevices());
833 $smarty->assign("gotoHotplugDeviceKeys",array_flip($this->printOutHotPlugDevices()));
834 }
836 /* Printer Assignment will managed below
837 * A printer can be assigned in two different ways and two different types
838 * There are 2 types of users assigned to a printer : user and admin
839 * They only differ in the member attribute they will be assigned to. user: gotoUserPrinter admin: gotoadminPrinter
840 * The different types of assigning a user are : 1 assigning a user to a printer 2. assigning a group to a printer
841 */
843 /* First handle Add Post. Open a dialog that allows us to select a printer or two */
844 if(isset($_POST['gotoPrinterAdd'])){
846 $this->is_dialog=true;
847 $this->dialog = new selectPrinterDialog($this->config,$this->dn,$this->gotoPrinter);
848 }
850 if(isset($_POST['PrinterCancel'])){
851 $this->is_dialog=false;
852 unset($this->dialog);
853 $this->dialog=FALSE;
854 }
856 if(isset($_POST['PrinterSave'])){
857 if(count($this->dialog->check())!=0){
858 $tmp = $this->dialog->check();
859 foreach($tmp as $msg){
860 msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
861 }
862 }else{
863 $this->dialog->save_object();
864 $tmp = $this->dialog->save();
865 $tmp2= $this->dialog->getPrinter(true);
867 foreach($tmp as $pname){
868 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$tmp2[$pname]['dn'],"printer");
869 $printerObj->set_acl_base($tmp2[$pname]['dn']);
871 $type = false;
873 if($this->is_group){
874 if($this->dn == "new"){
875 $type = "AddGroup";
876 }elseif(isset($this->NewDeletedPrinters[$pname])){
877 $type = "AddGroup";
878 }elseif($printerObj->by_object['printgeneric']->AddMember("AddGroup",$this->dn)){
879 $type = "AddGroup";
880 }
881 }else{
882 if($this->multiple_support_active){
883 $type = "AddUser";
884 }elseif(isset($this->NewDeletedPrinters[$pname])){
885 $type = "AddUser";
886 }elseif($printerObj->by_object['printgeneric']->AddMember("AddUser",$this->dn)){
887 $type = "AddUser";
888 }
889 }
891 if($type){
892 $this->gotoPrinter[$pname]=$tmp2[$pname];
893 $this->gotoPrinter[$pname]['mode']="user";
894 $this->add_del_printer_member_was_called = true;
896 $this->NewAddedPrinters[$pname] = $pname;
897 if(isset($this->NewDeletedPrinters[$pname])){
898 unset($this->NewDeletedPrinters[$pname]);
899 }
900 }
901 }
903 $this->is_dialog=false;
904 unset($this->dialog);
905 $this->dialog =FALSE;
906 }
907 }
909 if((isset($_POST['gotoPrinterDel']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
910 $printer = $_POST['gotoPrinterSel'];
911 foreach($printer as $pname){
913 $printerObj = new printtabs($this->config,$this->config->data['TABS']['PRINTTABS'],$this->gotoPrinter[$pname]['dn'],"printer");
914 $printerObj->set_acl_base($this->gotoPrinter[$pname]['dn']);
916 $type = false;
917 if($this->is_group){
918 if(isset($this->NewAddedPrinters[$pname])){
919 $type = "Group";
920 }elseif($printerObj->by_object['printgeneric']->DelMember("AddGroup",$this->cn)){
921 $type = "Group";
922 }
923 }else{
924 if(isset($this->NewAddedPrinters[$pname])){
925 $type = "User";
926 }elseif($printerObj->by_object['printgeneric']->DelMember("AddUser",$this->uid)){
927 $type = "User";
928 }
929 }
930 if($type){
931 $this->add_del_printer_member_was_called = true;
932 unset($this->gotoPrinter[$pname]);
934 $this->NewDeletedPrinters[$pname] = $pname;
935 if(isset($this->NewAddedPrinters[$pname])){
936 UNSET($this->NewAddedPrinters[$pname]);
937 }
938 }
939 }
940 }
942 if((isset($_POST['gotoPrinterEdit']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
943 $printers = $_POST['gotoPrinterSel'];
944 $this->add_del_printer_member_was_called = true;
945 foreach($printers as $printer){
946 if($this->gotoPrinter[$printer]['mode']=="user"){
947 $this->gotoPrinter[$printer]['mode']="admin";
948 }else{
949 $this->gotoPrinter[$printer]['mode']="user";
950 }
951 }
952 }
954 if((isset($_POST['gotoPrinterDefault']))&&(isset($_POST['gotoPrinterSel']))&&(!empty($_POST['gotoPrinterSel']))){
955 if($this->is_group){
956 msg_dialog::display(_("Error"), _("Cannot set default printer flag for groups!"), ERROR_DIALOG);
957 }else{
958 if ($this->gosaDefaultPrinter == $_POST['gotoPrinterSel'][0]){
959 $this->gosaDefaultPrinter= "";
960 } else {
961 $this->gosaDefaultPrinter= $_POST['gotoPrinterSel'][0];
962 }
963 }
964 }
966 $smarty->assign("gotoPrinter",$this->printOutPrinterDevices());
967 $smarty->assign("gotoPrinterKeys",array_flip($this->printOutPrinterDevices()));
969 /* General behavior */
970 if(is_object($this->dialog)){
971 $this->dialog->save_object();
972 $disp =$this->dialog->execute();
973 return($disp);
974 }
976 /* Assign used attributes for multiple edit */
977 foreach(array("gotoPrinter","kiosk_server","gotoProfileFlagL","gotoXResolution",
978 "useProfile","gotoProfileServer","gotoProfileQuota","gotoProfileFlagC") as $box){
979 $ubox ="use_".$box;
980 if(in_array($box,$this->multi_boxes)){
981 $smarty->assign($ubox,TRUE);
982 }else{
983 $smarty->assign($ubox,FALSE);
984 }
985 }
987 /* Als smarty vars are set. Get smarty template and generate output */
988 $smarty->assign("multiple_support",$this->multiple_support_active);
989 $display.= $smarty->fetch(get_template_path('environment.tpl', TRUE,dirname(__FILE__)));
990 return($display);
991 }
993 function remove_from_parent()
994 {
995 /* only if it was an account*/
996 if (!$this->initially_was_account){
997 return;
998 }
1000 /* include global link_info */
1001 $ldap= $this->config->get_ldap_link();
1003 /* Remove and write to LDAP */
1004 plugin::remove_from_parent();
1006 /* Don't save our template variables */
1007 $skip = array("uid","gotoLogonScripts","gotoPrinter","gotoShares","gotoHotplugDevices" );
1009 /* Skip all these attributes */
1010 foreach($skip as $del){
1011 unset($this->attrs[$del]);
1012 }
1014 @DEBUG (DEBUG_LDAP, __LINE__, __FUNCTION__, __FILE__,$this->attributes, "Save");
1016 $ldap->cd($this->dn);
1017 $this->cleanup();
1018 $ldap->modify ($this->attrs);
1020 if($this->is_group){
1021 new log("remove","groups/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1022 }else{
1023 new log("remove","users/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
1024 }
1026 if (!$ldap->success()){
1027 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
1028 }
1030 /* Optionally execute a command after we're done */
1031 $this->handle_post_events("remove",array("uid" => $this->uid));
1032 }
1035 /* Save data to object */
1036 function save_object()
1037 {
1038 /* Get all Posted vars
1039 * Setup checkboxes
1040 */
1041 $WriteOnly = (!isset($this->parent)|| !$this->parent) && !session::is_set('edit');
1042 if(isset($_POST['iamposted'])){
1044 $PACL = $this->getacl("gotoProfileServer",$WriteOnly).$this->getacl("gotoProfileQuota",$WriteOnly);
1046 if(isset($_POST['kiosk_server'])){
1047 $tmp = $_POST['kiosk_server'];
1048 if(isset($this->gotoKioskProfiles['SERVERS'][$tmp])){
1049 $this->gotoKioskProfile_Server = $_POST['kiosk_server'];
1050 }
1051 }
1052 if(isset($_POST['kiosk_profile'])){
1053 $tmp = $_POST['kiosk_profile'];
1054 if(in_array($tmp,$this->gotoKioskProfiles['BY_SERVER'][$this->gotoKioskProfile_Server])){
1055 $this->gotoKioskProfile_Profile = $_POST['kiosk_profile'];
1056 }
1057 }
1059 if(preg_match("/w/",$PACL)){
1060 if(isset($_POST['useProfile'])){
1061 $this->useProfile = true;
1062 }else{
1063 $this->useProfile = false;
1064 }
1065 }
1067 if($this->acl_is_writeable("gotoProfileFlagC")){
1068 if(isset($_POST['gotoProfileFlagC'])){
1069 $this->gotoProfileFlagC = $_POST['gotoProfileFlagC'];
1070 }else{
1071 $this->gotoProfileFlagC = false;
1072 }
1073 }
1075 if($this->acl_is_writeable("gotoProfileFlagL")){
1076 if(isset($_POST['gotoProfileFlagL'])){
1077 $this->gotoProfileFlagL = $_POST['gotoProfileFlagL'];
1078 }else{
1079 $this->gotoProfileFlagL = false;
1080 }
1081 }
1083 plugin::save_object();
1084 foreach($this->attributes as $s_attr){
1085 if((!isset($_POST[$s_attr])) ||
1086 in_array($s_attr,array("gosaDefaultPrinter","gotoShares","gotoHotplugDevices","gotoPrinter","gotoLogonScripts","uid"))) continue;
1087 if(!$this->acl_is_writeable($s_attr)){
1088 continue;
1089 }else{
1090 if(isset($_POST[$s_attr])){
1091 $this->$s_attr = $_POST[$s_attr];
1092 }else{
1093 $this->$s_attr = false;
1094 }
1095 }
1096 }
1097 }
1098 }
1101 /* Check supplied data */
1102 function check()
1103 {
1104 /* Call common method to give check the hook */
1105 $message= plugin::check();
1107 $this->detect_grouptype();
1109 if(preg_match("/[^0-9]/",$this->gotoProfileQuota)) {
1110 $message[] = msgPool::invalid(_("Profile quota"),$this->gotoProfileQuota,"/[0-9]/") ;
1111 }
1112 if(!isset($this->attrs['objectClass'])){
1113 $this->attrs['objectClass']=array();
1114 }
1115 if(!$this->is_group){
1116 if((!((in_array("posixAccount",$this->attrs['objectClass']))||($this->parent->by_object['posixAccount']->is_account==true)))&&(!$this->is_group)){
1117 $message[]= msgPool::featuresDisabled(_("environemnt"),_("POSIX"));
1118 }
1119 }
1120 return ($message);
1121 }
1124 /* Save to LDAP */
1125 function save()
1126 {
1127 /* If group was renamed, all printer settings get lost
1128 */
1129 /* only save changed variables ....*/
1130 if ($this->gotoKioskProfile_Server != "none"){
1131 $method = $this->gotoKioskProfiles['MAP'][$this->gotoKioskProfile_Server][$this->gotoKioskProfile_Profile];
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 ?>