1 <?php
3 class termservice extends plugin
4 {
5 /* CLI vars */
6 var $cli_summary= "Manage terminal service aspects";
7 var $cli_description= "Some longer text\nfor help";
8 var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
10 /* Generic terminal attributes */
11 var $gotoLpdEnable= FALSE;
12 var $gotoXMonitor= "";
13 var $gotoXMethod= "";
14 var $gotoXdmcpServer= "";
15 var $gotoFontPath= "";
16 var $gotoXDriver= "";
17 var $gotoXResolution= "";
18 var $gotoXColordepth= "";
19 var $gotoXHsync= "";
20 var $gotoXVsync= "";
21 var $gotoXKbModel= "";
22 var $gotoXKbLayout= "";
23 var $gotoXKbVariant= "";
24 var $gotoXMouseType= "";
25 var $gotoXMouseport= "";
26 var $gotoLpdServer= "";
27 var $gotoScannerEnable= "";
28 var $gotoScannerModel= "";
29 var $gotoScannerClients= "";
30 var $gotoScannerBackend= "";
31 var $goFonHardware= "automatic";
33 var $AutoSync = false;
34 var $view_logged = FALSE;
36 /* Needed values and lists */
37 var $ignore_account= TRUE;
38 var $base= "";
39 var $cn= "";
40 var $orig_dn= "";
41 var $XMethods= array();
42 var $XDrivers= array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
43 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv",
44 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
45 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
46 var $XResolutions= array();
47 var $XColordepths= array();
48 var $XKbModels= array ();
49 var $XKbLayouts= array ();
50 var $XKbVariants= array ();
51 var $MouseTypes= array();
52 var $MousePorts= array();
53 var $gotoScannerModels= array();
54 var $hardware_list= array();
55 var $used_hardware= array();
58 /* attribute list for save action */
59 var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
60 "gotoFontPath", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
61 "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
62 "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
63 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
64 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
65 var $objectclasses= array("GOhard");
68 function termservice ($config, $dn= NULL, $parent= NULL)
69 {
70 plugin::plugin ($config, $dn, $parent);
72 array_unshift($this->XDrivers, "["._("unknown")."]");
74 $this->XResolutions= array(
75 "default" => "["._("inherited")."]" ,
76 "640x480" => "640x480",
77 "800x600" => "800x600",
78 "1024x768" => "1024x768",
79 "1152x864" => "1152x864",
80 "1280x1024" => "1280x1024",
81 "1400x1050" => "1400x1050",
82 "1600x1200" => "1600x1200");
84 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
85 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
87 if(is_readable($file)){
88 $str = file_get_contents($file);
89 $lines = split("\n",$str);
90 foreach($lines as $line){
91 $line = trim($line);
92 if(!empty($line)){
93 $this->XResolutions[$line]=$line;
94 }
95 }
96 //natcasesort($this->gotoXResolutions);
97 }else{
98 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
99 }
100 }
102 $this->XColordepths= array(
103 "default" => "["._("inherited")."]",
104 "8" => "8 " ._("bit"),
105 "15" => "15 "._("bit"),
106 "16" => "16 "._("bit"),
107 "24" => "24 "._("bit"));
109 $this->XKbModels['default']= "["._("inherited")."]";
110 foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
111 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
112 "logiinetnav", "logiinternet", "macintosh", "microsoft",
113 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
114 "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
115 $this->XKbModels[$type] = $type;
116 }
118 /* Additional values will be extracted from CONFIG_DIR.keyboardLayouts */
119 $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
120 $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
122 $this->MouseTypes= array( "AUTO" => "["._("inherited")."]" , "ImPS/2" => "ImPS/2",
123 "PS/2" => "PS/2" , "Microsoft" => "Microsoft",
124 "Logitech" => "Logitech");
126 $this->MousePorts= array("AUTO" =>"["._("inherited")."]" , "/dev/ttyS0" => "/dev/ttyS0",
127 "/dev/ttyS1" => "/dev/ttyS1" , "/dev/psaux" => "/dev/psaux",
128 "/dev/input/mice" =>"/dev/input/mice");
131 /* try to read additional keyboard layouts
132 */
133 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
134 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
135 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
136 $tmp = split("\n",$str);
137 foreach($tmp as $entry){
138 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
139 $entry = trim($entry);
140 $tmp2 = split ("\:",$entry);
141 $la = trim($tmp2[0]); // What would be saved to ldap
142 $da = trim($tmp2[1]); // This wis displayed in the listbox
143 $this->XKbLayouts [ $la] = $da;
144 }
145 }
146 }
147 }
149 /* Load scanner models */
150 $fcontents = file ($this->config->basedir."/include/scanner.inc");
151 while (list ($line_num, $line) = each ($fcontents)) {
152 preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
153 $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
154 }
155 ksort ($this->gotoScannerModels);
157 /* Initialize methods */
158 $this->XMethods["default"]= _("default");
159 $this->XMethods["indirect"]= _("show chooser");
160 $this->XMethods["query"]= _("direct");
161 #$this->XMethods["squery"]= _("direct via ssh");
162 #$this->XMethods["nquery"]= _("direct via nx");
163 $this->XMethods["load"]= _("load balanced");
164 #$this->XMethods["sload"]= _("load balanced via ssh");
165 #$this->XMethods["nload"]= _("load balanced via nx");
166 $this->XMethods["rdp"]= _("Windows RDP");
167 $this->XMethods["citrix"]= _("ICA client");
169 $this->orig_dn= $this->dn;
171 /* Load hardware list */
172 $ldap= $this->config->get_ldap_link();
173 $ldap->cd($this->config->current['BASE']);
174 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
175 while ($attrs= $ldap->fetch()){
176 $cn= $attrs['cn'][0];
177 if (isset($attrs['description'])){
178 $description= " - ".$attrs['description'][0];
179 } else {
180 $description= "";
181 }
182 $this->hardware_list[$cn]= "$cn$description";
183 }
185 /* Eventually colorize phones */
186 $ldap->cd($this->config->current['BASE']);
187 foreach ($this->hardware_list as $cn => $desc){
188 $ldap->search("(goFonHardware=$cn)", array('cn'));
189 if ($ldap->count() > 0){
190 $ldap->fetch();
191 if ($ldap->getDN() != $this->dn){
192 $this->used_hardware[$cn]= $ldap->getDN();
193 }
194 }
195 }
197 $this->hardware_list["automatic"]= _("automatic");
198 ksort($this->hardware_list);
200 /* Convert gotoLpdEnable */
201 $this->gotoLpdEnable= preg_match("/yes/i",$this->gotoLpdEnable);
203 /* Load hardware list */
204 $ldap= $this->config->get_ldap_link();
205 $ldap->cd($this->config->current['BASE']);
206 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
207 if ($ldap->count() == 1){
208 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
209 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
210 $attrs= $ldap->fetch();
212 foreach ($map as $name){
213 if (!isset($attrs[$name][0])){
214 continue;
215 }
217 switch ($name){
218 case 'gotoXResolution':
219 $this->XResolutions['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
220 break;
221 case 'gotoXColordepth':
222 $this->XColordepths['default'] = _("inherited").' ['.$attrs[$name][0].' '._('Bit').']';
223 break;
224 case 'gotoXKbModel':
225 $this->XKbModels['default'] = _("inherited").' ['.$attrs[$name][0].']';
226 break;
227 case 'gotoXKbLayout':
228 $this->XKbLayouts['default'] = _("inherited").' ['.$attrs[$name][0].']';
229 break;
230 case 'gotoXKbVariant':
231 $this->XKbVariants['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
232 break;
233 case 'gotoXMouseType':
234 $this->MouseTypes['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
235 break;
236 case 'gotoXMouseport':
237 $this->MousePorts['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
238 break;
239 }
240 }
241 }
242 if(preg_match("/\+/",$this->gotoXHsync)){
243 $this->AutoSync = true;
244 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
245 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
246 }
247 }
249 function execute()
250 {
251 /* Call parent execute */
252 plugin::execute();
254 if($this->is_account && !$this->view_logged){
255 $this->view_logged = TRUE;
256 new log("view","terminal/".get_class($this),$this->dn);
257 }
259 /* Do we need to flip is_account state? */
260 if (isset($_POST['modify_state'])){
261 $this->is_account= !$this->is_account;
262 }
264 /* Do we represent a valid terminal? */
265 if (!$this->is_account && $this->parent == NULL){
266 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
267 _("This 'dn' has no terminal features.")."</b>";
268 return ($display);
269 }
271 /* Show main page */
272 $smarty= get_smarty();
274 /* Assign acls */
275 $tmp= $this->plInfo();
276 foreach($tmp['plProvidedAcls'] as $name => $translation){
277 $smarty->assign($name."ACL",$this->getacl($name));
278 }
281 /* Arrays */
282 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
283 "gotoScannerModels", "XKbModels","XKbVariants",
284 "MouseTypes", "MousePorts") as $val){
285 $smarty->assign("$val", $this->$val);
286 }
287 $smarty->assign("XKbLayouts", $this->XKbLayouts);
288 $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
290 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
291 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
292 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
293 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
295 /* Variables - select */
296 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
297 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
298 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
299 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
301 $smarty->assign($val."_select", $this->$val);
302 }
304 /* Variables */
305 foreach(array("gotoXHsync", "gotoXVsync") as $val){
306 $smarty->assign($val, $this->$val);
307 }
308 $smarty->assign("staticAddress", "");
310 /* Checkboxes */
311 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
312 if ($this->$val == TRUE) {
313 $smarty->assign("$val", "checked");
314 } else {
315 $smarty->assign("$val", "");
316 }
317 }
319 /* Phone stuff */
320 $smarty->assign ("goFonHardware", $this->goFonHardware);
321 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
322 _("Choose the phone located at the current terminal")."\" >\n";
323 foreach ($this->hardware_list as $cn => $description){
324 if ($cn == $this->goFonHardware){
325 $selected= "selected";
326 } else {
327 $selected= "";
328 }
329 if (isset($this->used_hardware[$cn])){
330 $color= "style=\"color:#A0A0A0\"";
331 } else {
332 $color= "";
333 }
334 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
335 }
336 $hl.= "</select>\n";
337 $smarty->assign ("hardware_list", $hl);
338 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
340 $smarty->assign("AutoSyncACL",$this->getacl("AutoSync"));
342 $smarty->assign("AutoSyncCHK"," ");
343 if($this->AutoSync){
344 $smarty->assign("AutoSyncCHK"," checked ");
345 $smarty->assign("gotoXVsyncACL", preg_replace("/w/","",$this->getacl("gotoXVsync")));
346 $smarty->assign("gotoXHsyncACL", preg_replace("/w/","",$this->getacl("gotoXHsync")));
347 }
349 /* Show main page */
350 return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
351 }
353 function remove_from_parent()
354 {
355 new log("remove","terminal/".get_class($this),$this->dn,array_keys($this->attrs));
356 $this->handle_post_events("remove");
357 }
360 /* Save data to object */
361 function save_object()
362 {
363 plugin::save_object();
365 /* Save checkbox state */
366 if (isset ($_POST['gotoXMethod'])){
367 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
369 if($this->acl_is_writeable($val)){
370 if (!isset ($_POST["$val"])){
371 $this->$val= FALSE;
372 } else {
373 $this->$val= TRUE;
374 }
375 }
376 }
377 }
379 if(isset($_POST['gotoXDriver'])){
380 if(isset($_POST['AutoSync'])){
381 $this->AutoSync = true;
382 }else{
383 $this->AutoSync = false;
384 }
385 }
387 /* Default entries can use blank hsync/vsync entries */
388 if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){
390 /* But only if no auto sync is enabled... */
391 if (!$this->AutoSync){
393 /* Check vsync for correct usage */
394 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
395 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXVsync")){
397 $message[]= _("Please specify a valid VSync range.");
398 } elseif ($this->acl_is_writeable("gotoXVsync")){
399 list($v1,$v2)= preg_split ("/[-+]/", $val);
400 if ($v2 != ""){
401 if ($v1 > $v2){
402 $message[]= _("Please specify a valid VSync range.");
403 }
404 }
405 }
407 /* Check hsync for correct usage */
408 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
409 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXHsync")){
411 $message[]= _("Please specify a valid HSync range.");
412 } elseif ($this->acl_is_writeable("gotoXHsync")){
413 list($v1,$v2)= preg_split ("/[-+]/", $val);
414 if ($v2 != ""){
415 if ($v1 > $v2){
416 $message[]= _("Please specify a valid HSync range.");
417 }
418 }
419 }
420 }
421 }
422 }
425 /* Check supplied data */
426 function check()
427 {
428 /* Call common method to give check the hook */
429 $message= plugin::check();
430 return ($message);
431 }
434 /* Save to LDAP */
435 function save()
436 {
437 /* Convert to string */
438 $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
440 plugin::save();
442 /* Strip out 'default' values */
443 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
444 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
445 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
446 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
448 if ($this->attrs[$val] == "default"){
449 $this->attrs[$val]= array();
450 }
451 }
453 if($this->AutoSync){
454 $this->attrs['gotoXHsync'] = "30+55";
455 $this->attrs['gotoXVsync'] = "50+70";
456 }
458 /* Write back to ldap */
459 $ldap= $this->config->get_ldap_link();
460 $ldap->cd($this->dn);
461 $this->cleanup();
462 $ldap->modify ($this->attrs);
463 new log("modify","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
465 show_ldap_error($ldap->get_error(), sprintf(_("Saving of object system terminal/service with dn '%s' failed."),$this->dn));
466 $this->handle_post_events("modify");
467 }
470 /* Return plugin informations for acl handling */
471 function plInfo()
472 {
473 return (array(
474 "plShortName" => _("Service"),
475 "plDescription" => _("Terminal service"),
476 "plSelfModify" => FALSE,
477 "plDepends" => array(),
478 "plPriority" => 3,
479 "plSection" => array("administration"),
480 "plCategory" => array("terminal"),
482 "plProvidedAcls"=> array(
483 "gotoXMonitor" => _("Monitor"),
484 "gotoXMethod" => _("Method"),
485 "gotoXdmcpServer" => _("Remote desktop"),
486 "gotoFontPath" => _("Font path"),
487 "gotoXDriver" => _("Gfx driver"),
488 "gotoXResolution" => _("Gfx resolution"),
489 "gotoXColordepth" => _("Gfx color depth"),
490 "gotoXHsync" => _("Hsync"),
491 "gotoXVsync" => _("Vsync"),
492 "AutoSync" => _("Auto-Sync"),
493 "gotoLpdEnable" => _("Printer service enabled"),
494 "gotoLpdServer" => _("Spool server"),
495 "gotoScannerEnable" => _("Scanner enabled"),
496 "gotoScannerModel" => _("Scanner model"),
497 "gotoScannerClients" => _("Haeh ? "),
498 "gotoScannerBackend" => _("..."),
499 "gotoXKbModel" => _("Keyboard model"),
500 "gotoXKbLayout" => _("Keyboard layout"),
501 "gotoXKbVariant" => _("Keyboard variant"),
502 "gotoXMouseType" => _("Mouse type"),
503 "gotoXMouseport" => _("Mouse port"),
504 "goFonHardware" => _("Telephone hardware"))
505 ));
506 }
507 }
509 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
510 ?>