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