1 <?php
3 class termservice extends plugin
4 {
5 /* Generic terminal attributes */
6 var $gotoLpdEnable= FALSE;
7 var $gotoXMonitor= "";
8 var $gotoXMethod= "default";
9 var $gotoXdmcpServer= "";
10 var $gotoXDriver= "";
11 var $gotoXResolution= "";
12 var $gotoXColordepth= "";
13 var $gotoXHsync= "";
14 var $gotoXVsync= "";
15 var $gotoXKbModel= "";
16 var $gotoXKbLayout= "";
17 var $gotoXKbVariant= "";
18 var $gotoXMouseType= "";
19 var $gotoXMouseport= "";
20 var $gotoLpdServer= "";
21 var $gotoScannerEnable= "";
22 var $gotoScannerModel= "";
23 var $gotoScannerClients= "";
24 var $gotoScannerBackend= "";
25 var $goFonHardware= "automatic";
27 var $AutoSync = false;
28 var $view_logged = FALSE;
30 /* Needed values and lists */
31 var $ignore_account= TRUE;
32 var $base= "";
33 var $cn= "";
34 var $orig_dn= "";
35 var $XMethods= array();
36 var $XDrivers= array();
37 var $XResolutions= array();
38 var $XColordepths= array();
39 var $XKbModels= array ();
40 var $XKbLayouts= array ();
41 var $XKbVariants= array ();
42 var $MouseTypes= array();
43 var $MousePorts= array();
44 var $hardware_list= array();
45 var $used_hardware= array();
48 /* attribute list for save action */
49 var $attributes= array("gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
50 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
51 "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
52 "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
53 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
54 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
55 var $objectclasses= array("GOhard");
57 var $is_ogroup = FALSE;
58 var $is_ogroup_member = FALSE;
60 var $selected_xdmcp_servers = array();
61 var $inherited_xdmcp_servers = array();
63 function termservice (&$config, $dn= NULL, $parent= NULL)
64 {
65 plugin::plugin ($config, $dn, $parent);
66 $this->orig_dn= $this->dn;
68 /* Check if we are a part of an ogroup.
69 * In this case, we have to hide all the inherit stuff.
70 */
71 if(isset($parent) && get_class($parent) == "ogroup"){
72 $this->is_ogroup = TRUE;
73 }
75 /* Check if we are member of an object group.
76 */
77 $ldap= $this->config->get_ldap_link();
78 $ldap->cd($this->config->current['BASE']);
79 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
80 if($ldap->count()){
81 $this->is_ogroup_member = TRUE;
82 }
84 /* Get list of available xdrivers */
85 $this->XDrivers = $this->getListOfXDrivers();
87 /* Create a list of available resolutions.
88 */
89 $this->XResolutions= array(
90 "640x480" => "640x480",
91 "800x600" => "800x600",
92 "1024x768" => "1024x768",
93 "1152x864" => "1152x864",
94 "1280x1024" => "1280x1024",
95 "1400x1050" => "1400x1050",
96 "1600x1200" => "1600x1200");
98 if($this->config->get_cfg_value("resolutions") != ""){
99 $file = $this->config->get_cfg_value("resolutions");
100 if(is_readable($file)){
101 $str = file_get_contents($file);
102 $lines = split("\n",$str);
103 foreach($lines as $line){
104 $line = trim($line);
105 if(!empty($line)){
106 $this->XResolutions[$line]=$line;
107 }
108 }
109 }else{
110 msg_dialog::display(_("Configuration error"), msgPool::cannotReadFile($file), WARNING_DIALOG);
111 }
112 }
114 /* Create a set of selectable color depths
115 */
116 $this->XColordepths= array(
117 "8" => "8 " ._("bit"),
118 "15" => "15 "._("bit"),
119 "16" => "16 "._("bit"),
120 "24" => "24 "._("bit"));
123 /* Create a set of selectable keyboard models
124 */
125 $this->XKbModels = array();
126 foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
127 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
128 "logiinetnav", "logiinternet", "macintosh", "microsoft",
129 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
130 "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
131 $this->XKbModels[$type] = $type;
132 }
134 /* Additional values will be extracted from CONFIG_DIR.keyboardLayouts */
135 $this->XKbLayouts = array("de"=> "de","intl" =>"intl","us" =>"us");
136 $this->XKbVariants= array("nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
137 $this->MouseTypes = array("ImPS/2"=>"ImPS/2","PS/2"=>"PS/2", "explorerps/2"=>"explorerps/2",
138 "Microsoft"=>"Microsoft","Logitech"=>"Logitech");
139 $this->MousePorts = array("/dev/ttyS0"=>"/dev/ttyS0",
140 "/dev/ttyS1"=>"/dev/ttyS1","/dev/psaux"=>"/dev/psaux",
141 "/dev/input/mice"=>"/dev/input/mice");
144 /* Try to read additional keyboard layouts
145 */
146 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
147 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
148 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
149 $tmp = split("\n",$str);
150 foreach($tmp as $entry){
151 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
152 $entry = trim($entry);
153 $tmp2 = split ("\:",$entry);
154 $la = trim($tmp2[0]); // What would be saved to ldap
155 $da = trim($tmp2[1]); // This wis displayed in the listbox
156 $this->XKbLayouts [ $la] = $da;
157 }
158 }
159 }
160 }
162 /* Terminal server methods
163 */
164 if($this->is_ogroup_member){
165 $this->XMethods["default"]= _("inherited");
166 }
167 $this->XMethods["xdmcp"] = _("XDMCP");
168 $this->XMethods["ldm"] = _("LDM");
169 $this->XMethods["rdp"] = _("Windows RDP");
170 $this->XMethods["citrix"] = _("ICA client");
172 /* Get selected gotoXdmcpServer
173 */
174 $this->selected_xdmcp_servers = array();
175 if(isset($this->attrs['gotoXdmcpServer'])){
176 for($i = 0 ; $i < $this->attrs['gotoXdmcpServer']['count'] ; $i++){
177 $this->selected_xdmcp_servers[] = $this->attrs['gotoXdmcpServer'][$i];
178 }
179 }
181 /* Load phone hardware list
182 */
183 $tmp = get_sub_list("(objectClass=goFonHardware)","",array(get_ou("phoneRDN")),
184 $this->config->current['BASE'],array("cn","description"), GL_NO_ACL_CHECK);
185 foreach($tmp as $attrs){
186 $cn= $attrs['cn'][0];
187 $description= "";
188 if (isset($attrs['description'])){
189 $description= " - ".$attrs['description'][0];
190 }
191 $this->hardware_list[$cn]= "$cn$description";
192 }
193 $this->hardware_list["automatic"]= _("automatic");
194 ksort($this->hardware_list);
196 /* These departments may contain objects that have
197 goFonHardware set.
198 */
199 $deps_a = array(
200 get_people_ou(),
201 get_ou("ogroupou"),
202 get_ou("serverRDN"),
203 get_ou("terminalRDN"),
204 get_ou("workstationRDN"),
205 get_ou("printerRDN"),
206 get_ou("componentRDN"),
207 get_ou("phoneRDN"));
209 $tmp = get_sub_list("(goFonHardware=*)","",$deps_a,$this->config->current['BASE'],
210 array('cn','dn','goFonHardware'),GL_NO_ACL_CHECK);
211 foreach($tmp as $attrs){
212 $cn = $attrs['goFonHardware'][0];
213 if(isset($this->hardware_list[$cn])){
214 $this->used_hardware[$cn]= $cn;
215 }
216 }
218 /* Convert gotoLpdEnable
219 */
220 $this->gotoLpdEnable= preg_match("/yes/i",$this->gotoLpdEnable);
222 /* Load hardware list */
223 $ldap= $this->config->get_ldap_link();
224 $ldap->cd($this->config->current['BASE']);
225 $map= array(
226 "gotoXResolution",
227 "gotoXColordepth",
228 "gotoXKbModel",
229 "gotoXKbLayout",
230 # "gotoXDriver",
231 "gotoXdmcpServer",
232 "gotoXKbVariant",
233 "gotoXMouseType",
234 "gotoXMethod",
235 "gotoXMouseport");
236 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",$map);
237 if ($ldap->count() == 1){
238 $attrs= $ldap->fetch();
239 foreach ($map as $name){
240 if (!isset($attrs[$name][0])){
241 continue;
242 }
244 switch ($name){
245 # case 'gotoXDriver':
246 # $this->XDrivers = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers;
247 # break;
248 case 'gotoXMethod':
249 $this->XMethods = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XMethods;
250 if(isset($attrs['gotoXdmcpServer'])){
251 for($i = 0 ; $i < $attrs['gotoXdmcpServer']['count'] ; $i++){
252 $this->inherited_xdmcp_servers[] = $attrs['gotoXdmcpServer'][$i];
253 }
254 }
255 break;
256 case 'gotoXResolution':
257 $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
258 break;
259 case 'gotoXColordepth':
260 $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
261 break;
262 case 'gotoXKbModel':
263 $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
264 break;
265 case 'gotoXKbLayout':
266 $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
267 break;
268 case 'gotoXKbVariant':
269 $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
270 break;
271 case 'gotoXMouseType':
272 $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
273 break;
274 case 'gotoXMouseport':
275 $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
276 break;
277 }
278 }
279 }
281 if(preg_match("/\+/",$this->gotoXHsync)){
282 $this->AutoSync = true;
283 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
284 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
285 }
286 }
289 function execute()
290 {
291 /* Call parent execute */
292 plugin::execute();
294 if($this->is_account && !$this->view_logged){
295 $this->view_logged = TRUE;
296 new log("view","terminal/".get_class($this),$this->dn);
297 }
299 /* Do we need to flip is_account state? */
300 if (isset($_POST['modify_state'])){
301 $this->is_account= !$this->is_account;
302 }
304 /* Do we represent a valid terminal? */
305 if (!$this->is_account && $this->parent === NULL){
306 $display= "<img alt=\"\" src=\"images/small-error.png\" align=\"middle\"> <b>".
307 _("This 'dn' has no terminal features.")."</b>";
308 return ($display);
309 }
311 /* Show main page */
312 $smarty= get_smarty();
314 /* Assign acls */
315 $tmp= $this->plInfo();
316 foreach($tmp['plProvidedAcls'] as $name => $translation){
317 $smarty->assign($name."ACL",$this->getacl($name));
318 }
320 if(isset($_POST['gotoXdmcpServer_add']) && isset($_POST['XdmcpAddServer'])){
321 if(!in_array($_POST['gotoXdmcpServer_add'],$this->selected_xdmcp_servers)){
322 $this->selected_xdmcp_servers[] = $_POST['gotoXdmcpServer_add'];
323 }
324 }
326 if(isset($_POST['selected_xdmcp_servers']) && isset($_POST['XdmcpDelServer'])){
327 $tmp = array();
328 foreach($this->selected_xdmcp_servers as $name){
329 if(!in_array($name,$_POST['selected_xdmcp_servers'])){
330 $tmp[] = $name;
331 }
332 }
333 $this->selected_xdmcp_servers = $tmp;
334 }
336 /* Arrays */
337 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
338 "XKbModels","XKbVariants","MouseTypes", "MousePorts") as $val){
339 $smarty->assign("$val", $this->$val);
340 }
341 $smarty->assign("XKbLayouts", $this->XKbLayouts);
342 $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
343 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
346 /* Create a list of useable servers for the currently selected
347 * connection type.
348 */
349 $xdmcp_types = $this->config->data['SERVERS']['TERMINAL_SESSION_TYPES'];
350 $available_servers = array();
351 foreach($xdmcp_types as $servername =>$supported_types){
352 if(in_array(strtoupper($this->gotoXMethod),$supported_types)){
353 $available_servers[] = $servername;
354 }
355 }
357 /* Append additional information to invalid server selections.
358 */
359 $tmp = array();
360 foreach($this->selected_xdmcp_servers as $server){
361 if(in_array($server,$available_servers)){
362 $tmp[$server] = $server;
363 }else{
364 $tmp[$server] = $server." - "._("Unsupported");
365 }
366 }
368 /* Remove already selected servers from available list.
369 */
370 foreach($available_servers as $key => $server){
371 if(isset($tmp[$server])){
372 unset($available_servers[$key]);
373 }
374 }
376 $smarty->assign("selected_xdmcp_servers", $tmp);
377 $smarty->assign("inherited_xdmcp_servers", $this->inherited_xdmcp_servers);
378 $smarty->assign("available_xdmcp_servers", $available_servers);
380 /* Variables - select */
381 foreach(array("gotoXMethod","gotoXDriver", "gotoXResolution", "gotoXColordepth",
382 "gotoLpdServer", "gotoXKbModel", "gotoXKbLayout",
383 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
385 $smarty->assign($val."_select", $this->$val);
386 }
388 /* Variables */
389 foreach(array("gotoXHsync", "gotoXVsync") as $val){
390 $smarty->assign($val, $this->$val);
391 }
392 $smarty->assign("staticAddress", "");
394 /* Checkboxes */
395 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
396 if ($this->$val == TRUE) {
397 $smarty->assign("$val", "checked");
398 } else {
399 $smarty->assign("$val", "");
400 }
401 }
403 /* Phone stuff */
404 $smarty->assign ("goFonHardware", $this->goFonHardware);
405 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
406 _("Choose the phone located at the current terminal")."\" >\n";
407 foreach ($this->hardware_list as $cn => $description){
408 if ($cn == $this->goFonHardware){
409 $selected= "selected";
410 } else {
411 $selected= "";
412 }
413 if (isset($this->used_hardware[$cn])){
414 $color= "style=\"color:#A0A0A0\"";
415 } else {
416 $color= "";
417 }
418 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
419 }
420 $hl.= "</select>\n";
421 $smarty->assign ("hardware_list", $hl);
422 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
424 $smarty->assign("AutoSyncACL",$this->getacl("AutoSync"));
426 $smarty->assign("AutoSyncCHK"," ");
427 if($this->AutoSync){
428 $smarty->assign("AutoSyncCHK"," checked ");
429 $smarty->assign("gotoXVsyncACL", preg_replace("/w/","",$this->getacl("gotoXVsync")));
430 $smarty->assign("gotoXHsyncACL", preg_replace("/w/","",$this->getacl("gotoXHsync")));
431 }
433 /* Show main page */
434 return($smarty->fetch (get_template_path('terminalService.tpl', TRUE,dirname(__FILE__))));
435 }
437 function remove_from_parent()
438 {
439 new log("remove","terminal/".get_class($this),$this->dn,array_keys($this->attrs));
440 $this->handle_post_events("remove");
441 }
444 /* Save data to object */
445 function save_object()
446 {
447 plugin::save_object();
449 /* Save checkbox state */
450 if (isset ($_POST['gotoXMethod'])){
451 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
453 if($this->acl_is_writeable($val)){
454 if (!isset ($_POST["$val"])){
455 $this->$val= FALSE;
456 } else {
457 $this->$val= TRUE;
458 }
459 }
460 }
461 }
463 if(isset($_POST['gotoXDriver'])){
464 if(isset($_POST['AutoSync'])){
465 $this->AutoSync = true;
466 }else{
467 $this->AutoSync = false;
468 }
469 }
471 /* Default entries can use blank hsync/vsync entries */
472 if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){
474 /* But only if no auto sync is enabled... */
475 if (!$this->AutoSync){
477 /* Check vsync for correct usage */
478 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
479 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXVsync")){
480 $message[]= msgPool::invalid(_("VSync range"));
481 } elseif ($this->acl_is_writeable("gotoXVsync")){
482 list($v1,$v2)= preg_split ("/[-+]/", $val);
483 if ($v2 != ""){
484 if ($v1 > $v2){
485 $message[]= msgPool::invalid(_("VSync range"));
486 }
487 }
488 }
490 /* Check hsync for correct usage */
491 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
492 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXHsync")){
493 $message[]= msgPool::invalid(_("HSync range"));
494 } elseif ($this->acl_is_writeable("gotoXHsync")){
495 list($v1,$v2)= preg_split ("/[-+]/", $val);
496 if ($v2 != ""){
497 if ($v1 > $v2){
498 $message[]= msgPool::invalid(_("HSync range"));
499 }
500 }
501 }
502 }
503 }
504 }
507 /* Check supplied data */
508 function check()
509 {
510 /* Call common method to give check the hook */
511 $message= plugin::check();
513 if($this->gotoXMethod != "default"){
514 $xdmcp_types = $this->config->data['SERVERS']['TERMINAL_SESSION_TYPES'];
515 $available_servers = array();
516 foreach($xdmcp_types as $servername =>$supported_types){
517 if(in_array(strtoupper($this->gotoXMethod),$supported_types)){
518 $available_servers[] = $servername;
519 }
520 }
521 foreach($this->selected_xdmcp_servers as $server){
522 if(!in_array($server,$available_servers)){
523 $message[] = _("Remote desktop settings contains servers that do not support the selected connection method.");
524 break;
525 }
526 }
527 }
529 return ($message);
530 }
533 /* Save to LDAP */
534 function save()
535 {
536 /* Convert to string */
537 $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
539 if($this->is_ogroup){
540 $this->objectclasses = array("gotoWorkstationTemplate");
541 }else{
542 $this->objectclasses = array("GOhard");
543 }
545 plugin::save();
547 /* Strip out 'default' values */
548 foreach(array("gotoXMethod","gotoXDriver", "gotoXResolution", "gotoXColordepth",
549 "gotoLpdServer", "gotoXKbModel", "gotoXKbLayout",
550 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
552 if ($this->attrs[$val] == "default"){
553 $this->attrs[$val]= array();
554 }
555 }
557 if($this->gotoXMethod == "default"){
558 $this->attrs['gotoXdmcpServer'] = array();
559 $this->attrs['gotoXMethod'] = array();
560 }else{
561 $this->attrs['gotoXdmcpServer'] = array_values($this->selected_xdmcp_servers);
562 }
565 if($this->AutoSync){
566 $this->attrs['gotoXHsync'] = "30+55";
567 $this->attrs['gotoXVsync'] = "50+70";
568 }
570 /* Write back to ldap */
571 $ldap= $this->config->get_ldap_link();
572 $ldap->cd($this->dn);
573 $this->cleanup();
574 $ldap->modify ($this->attrs);
575 new log("modify","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
577 if (!$ldap->success()){
578 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
579 }
580 $this->handle_post_events("modify");
581 }
584 function getListOfXDrivers()
585 {
586 $drivers = array("default" => "["._("unknown")."]");
588 /* Generate a list of xdrivers from CONFIG_DIR/xdrivers */
589 if (file_exists(CONFIG_DIR.'/xdrivers')){
590 $xdrivers = file (CONFIG_DIR.'/xdrivers');
591 foreach ($xdrivers as $line){
592 if (!preg_match ("/^#/", $line)){
593 $drivers[]= trim($line);
594 }
595 }
596 } else {
597 foreach( array(
598 "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
599 "i128", "i740", "i810", "intel", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia",
600 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
601 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware") as $driver){
602 $drivers[] = $driver;
603 }
604 }
605 return($drivers);
606 }
609 /* Return plugin informations for acl handling */
610 static function plInfo()
611 {
612 return (array(
613 "plShortName" => _("Service"),
614 "plDescription" => _("Terminal service"),
615 "plSelfModify" => FALSE,
616 "plDepends" => array(),
617 "plPriority" => 3,
618 "plSection" => array("administration"),
619 "plCategory" => array("terminal"),
621 "plProvidedAcls"=> array(
622 "gotoXMonitor" => _("Monitor"),
623 "gotoXMethod" => _("Method"),
624 "gotoXdmcpServer" => _("Remote desktop"),
625 "gotoXDriver" => _("Gfx driver"),
626 "gotoXResolution" => _("Gfx resolution"),
627 "gotoXColordepth" => _("Gfx color depth"),
628 "gotoXHsync" => _("HSync"),
629 "gotoXVsync" => _("VSync"),
630 "AutoSync" => _("Auto-Sync"),
631 "gotoLpdEnable" => _("Printer service enabled"),
632 "gotoLpdServer" => _("Spool server"),
633 "gotoScannerEnable" => _("Scanner enabled"),
634 "gotoXKbModel" => _("Keyboard model"),
635 "gotoXKbLayout" => _("Keyboard layout"),
636 "gotoXKbVariant" => _("Keyboard variant"),
637 "gotoXMouseType" => _("Mouse type"),
638 "gotoXMouseport" => _("Mouse port"),
639 "goFonHardware" => _("Telephone hardware"))
640 ));
641 }
642 }
644 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
645 ?>