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();
43 var $XResolutions= array();
44 var $XColordepths= array();
45 var $XKbModels= array ();
46 var $XKbLayouts= array ();
47 var $XKbVariants= array ();
48 var $MouseTypes= array();
49 var $MousePorts= array();
50 var $gotoScannerModels= array();
51 var $hardware_list= array();
52 var $used_hardware= array();
55 /* attribute list for save action */
56 var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
57 "gotoFontPath", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
58 "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
59 "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
60 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
61 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
62 var $objectclasses= array("GOhard");
65 function termservice (&$config, $dn= NULL, $parent= NULL)
66 {
67 plugin::plugin ($config, $dn, $parent);
69 /* Get list of available xdrivers */
70 $this->XDrivers = $this->getListOfXDrivers();
71 array_unshift($this->XDrivers, "["._("unknown")."]");
73 $this->XResolutions= array(
74 "default" => "["._("inherited")."]" ,
75 "640x480" => "640x480",
76 "800x600" => "800x600",
77 "1024x768" => "1024x768",
78 "1152x864" => "1152x864",
79 "1280x1024" => "1280x1024",
80 "1400x1050" => "1400x1050",
81 "1600x1200" => "1600x1200");
83 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
84 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
86 if(is_readable($file)){
87 $str = file_get_contents($file);
88 $lines = split("\n",$str);
89 foreach($lines as $line){
90 $line = trim($line);
91 if(!empty($line)){
92 $this->XResolutions[$line]=$line;
93 }
94 }
95 //natcasesort($this->gotoXResolutions);
96 }else{
97 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
98 }
99 }
101 $this->XColordepths= array(
102 "default" => "["._("inherited")."]",
103 "8" => "8 " ._("bit"),
104 "15" => "15 "._("bit"),
105 "16" => "16 "._("bit"),
106 "24" => "24 "._("bit"));
108 $this->XKbModels['default']= "["._("inherited")."]";
109 foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
110 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
111 "logiinetnav", "logiinternet", "macintosh", "microsoft",
112 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
113 "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
114 $this->XKbModels[$type] = $type;
115 }
117 /* Additional values will be extracted from CONFIG_DIR.keyboardLayouts */
118 $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
119 $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
121 $this->MouseTypes= array( "AUTO" => "["._("inherited")."]" , "ImPS/2" => "ImPS/2",
122 "PS/2" => "PS/2" , "Microsoft" => "Microsoft",
123 "Logitech" => "Logitech");
125 $this->MousePorts= array("AUTO" =>"["._("inherited")."]" , "/dev/ttyS0" => "/dev/ttyS0",
126 "/dev/ttyS1" => "/dev/ttyS1" , "/dev/psaux" => "/dev/psaux",
127 "/dev/input/mice" =>"/dev/input/mice");
130 /* try to read additional keyboard layouts
131 */
132 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
133 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
134 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
135 $tmp = split("\n",$str);
136 foreach($tmp as $entry){
137 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
138 $entry = trim($entry);
139 $tmp2 = split ("\:",$entry);
140 $la = trim($tmp2[0]); // What would be saved to ldap
141 $da = trim($tmp2[1]); // This wis displayed in the listbox
142 $this->XKbLayouts [ $la] = $da;
143 }
144 }
145 }
146 }
148 /* Load scanner models */
149 $fcontents = file (CONFIG_DIR."/scanner-list");
150 while (list ($line_num, $line) = each ($fcontents)) {
151 preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
152 $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
153 }
154 ksort ($this->gotoScannerModels);
156 /* Initialize methods */
157 $this->XMethods["default"]= _("default");
158 $this->XMethods["indirect"]= _("show chooser");
159 $this->XMethods["query"]= _("direct");
160 #$this->XMethods["squery"]= _("direct via ssh");
161 #$this->XMethods["nquery"]= _("direct via nx");
162 $this->XMethods["load"]= _("load balanced");
163 #$this->XMethods["sload"]= _("load balanced via ssh");
164 #$this->XMethods["nload"]= _("load balanced via nx");
165 $this->XMethods["rdp"]= _("Windows RDP");
166 $this->XMethods["citrix"]= _("ICA client");
168 $this->orig_dn= $this->dn;
170 /* Load hardware list */
171 $ldap= $this->config->get_ldap_link();
172 $ldap->cd($this->config->current['BASE']);
173 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
174 while ($attrs= $ldap->fetch()){
175 $cn= $attrs['cn'][0];
176 if (isset($attrs['description'])){
177 $description= " - ".$attrs['description'][0];
178 } else {
179 $description= "";
180 }
181 $this->hardware_list[$cn]= "$cn$description";
182 }
184 /* Eventually colorize phones */
185 $ldap->cd($this->config->current['BASE']);
186 $ldap->search("(goFonHardware=*)",array('cn','dn','goFonHardware'));
187 while($attrs = $ldap->fetch()){
188 $cn = $attrs['goFonHardware'][0];
189 if(isset($this->hardware_list[$cn])){
190 $this->used_hardware[$cn]= $cn;
191 }
192 }
194 $this->hardware_list["automatic"]= _("automatic");
195 ksort($this->hardware_list);
197 /* Convert gotoLpdEnable */
198 $this->gotoLpdEnable= preg_match("/yes/i",$this->gotoLpdEnable);
200 /* Load hardware list */
201 $ldap= $this->config->get_ldap_link();
202 $ldap->cd($this->config->current['BASE']);
203 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
204 if ($ldap->count() == 1){
205 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
206 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
207 $attrs= $ldap->fetch();
209 foreach ($map as $name){
210 if (!isset($attrs[$name][0])){
211 continue;
212 }
214 switch ($name){
215 case 'gotoXResolution':
216 $this->XResolutions['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
217 break;
218 case 'gotoXColordepth':
219 $this->XColordepths['default'] = _("inherited").' ['.$attrs[$name][0].' '._('Bit').']';
220 break;
221 case 'gotoXKbModel':
222 $this->XKbModels['default'] = _("inherited").' ['.$attrs[$name][0].']';
223 break;
224 case 'gotoXKbLayout':
225 $this->XKbLayouts['default'] = _("inherited").' ['.$attrs[$name][0].']';
226 break;
227 case 'gotoXKbVariant':
228 $this->XKbVariants['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
229 break;
230 case 'gotoXMouseType':
231 $this->MouseTypes['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
232 break;
233 case 'gotoXMouseport':
234 $this->MousePorts['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
235 break;
236 }
237 }
238 }
239 if(preg_match("/\+/",$this->gotoXHsync)){
240 $this->AutoSync = true;
241 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
242 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
243 }
244 }
246 function execute()
247 {
248 /* Call parent execute */
249 plugin::execute();
251 if($this->is_account && !$this->view_logged){
252 $this->view_logged = TRUE;
253 new log("view","terminal/".get_class($this),$this->dn);
254 }
256 /* Do we need to flip is_account state? */
257 if (isset($_POST['modify_state'])){
258 $this->is_account= !$this->is_account;
259 }
261 /* Do we represent a valid terminal? */
262 if (!$this->is_account && $this->parent === NULL){
263 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
264 _("This 'dn' has no terminal features.")."</b>";
265 return ($display);
266 }
268 /* Show main page */
269 $smarty= get_smarty();
271 /* Assign acls */
272 $tmp= $this->plInfo();
273 foreach($tmp['plProvidedAcls'] as $name => $translation){
274 $smarty->assign($name."ACL",$this->getacl($name));
275 }
278 /* Arrays */
279 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
280 "gotoScannerModels", "XKbModels","XKbVariants",
281 "MouseTypes", "MousePorts") as $val){
282 $smarty->assign("$val", $this->$val);
283 }
284 $smarty->assign("XKbLayouts", $this->XKbLayouts);
285 $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
287 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
288 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
289 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
290 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
292 /* Variables - select */
293 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
294 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
295 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
296 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
298 $smarty->assign($val."_select", $this->$val);
299 }
301 /* Variables */
302 foreach(array("gotoXHsync", "gotoXVsync") as $val){
303 $smarty->assign($val, $this->$val);
304 }
305 $smarty->assign("staticAddress", "");
307 /* Checkboxes */
308 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
309 if ($this->$val == TRUE) {
310 $smarty->assign("$val", "checked");
311 } else {
312 $smarty->assign("$val", "");
313 }
314 }
316 /* Phone stuff */
317 $smarty->assign ("goFonHardware", $this->goFonHardware);
318 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
319 _("Choose the phone located at the current terminal")."\" >\n";
320 foreach ($this->hardware_list as $cn => $description){
321 if ($cn == $this->goFonHardware){
322 $selected= "selected";
323 } else {
324 $selected= "";
325 }
326 if (isset($this->used_hardware[$cn])){
327 $color= "style=\"color:#A0A0A0\"";
328 } else {
329 $color= "";
330 }
331 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
332 }
333 $hl.= "</select>\n";
334 $smarty->assign ("hardware_list", $hl);
335 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
337 $smarty->assign("AutoSyncACL",$this->getacl("AutoSync"));
339 $smarty->assign("AutoSyncCHK"," ");
340 if($this->AutoSync){
341 $smarty->assign("AutoSyncCHK"," checked ");
342 $smarty->assign("gotoXVsyncACL", preg_replace("/w/","",$this->getacl("gotoXVsync")));
343 $smarty->assign("gotoXHsyncACL", preg_replace("/w/","",$this->getacl("gotoXHsync")));
344 }
346 /* Show main page */
347 return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
348 }
350 function remove_from_parent()
351 {
352 new log("remove","terminal/".get_class($this),$this->dn,array_keys($this->attrs));
353 $this->handle_post_events("remove");
354 }
357 /* Save data to object */
358 function save_object()
359 {
360 plugin::save_object();
362 /* Save checkbox state */
363 if (isset ($_POST['gotoXMethod'])){
364 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
366 if($this->acl_is_writeable($val)){
367 if (!isset ($_POST["$val"])){
368 $this->$val= FALSE;
369 } else {
370 $this->$val= TRUE;
371 }
372 }
373 }
374 }
376 if(isset($_POST['gotoXDriver'])){
377 if(isset($_POST['AutoSync'])){
378 $this->AutoSync = true;
379 }else{
380 $this->AutoSync = false;
381 }
382 }
384 /* Default entries can use blank hsync/vsync entries */
385 if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){
387 /* But only if no auto sync is enabled... */
388 if (!$this->AutoSync){
390 /* Check vsync for correct usage */
391 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
392 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXVsync")){
394 $message[]= _("Please specify a valid VSync range.");
395 } elseif ($this->acl_is_writeable("gotoXVsync")){
396 list($v1,$v2)= preg_split ("/[-+]/", $val);
397 if ($v2 != ""){
398 if ($v1 > $v2){
399 $message[]= _("Please specify a valid VSync range.");
400 }
401 }
402 }
404 /* Check hsync for correct usage */
405 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
406 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXHsync")){
408 $message[]= _("Please specify a valid HSync range.");
409 } elseif ($this->acl_is_writeable("gotoXHsync")){
410 list($v1,$v2)= preg_split ("/[-+]/", $val);
411 if ($v2 != ""){
412 if ($v1 > $v2){
413 $message[]= _("Please specify a valid HSync range.");
414 }
415 }
416 }
417 }
418 }
419 }
422 /* Check supplied data */
423 function check()
424 {
425 /* Call common method to give check the hook */
426 $message= plugin::check();
427 return ($message);
428 }
431 /* Save to LDAP */
432 function save()
433 {
434 /* Convert to string */
435 $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
437 plugin::save();
439 /* Strip out 'default' values */
440 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
441 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
442 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
443 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
445 if ($this->attrs[$val] == "default"){
446 $this->attrs[$val]= array();
447 }
448 }
450 if($this->AutoSync){
451 $this->attrs['gotoXHsync'] = "30+55";
452 $this->attrs['gotoXVsync'] = "50+70";
453 }
455 /* Write back to ldap */
456 $ldap= $this->config->get_ldap_link();
457 $ldap->cd($this->dn);
458 $this->cleanup();
459 $ldap->modify ($this->attrs);
460 new log("modify","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
462 show_ldap_error($ldap->get_error(), sprintf(_("Saving of object system terminal/service with dn '%s' failed."),$this->dn));
463 $this->handle_post_events("modify");
464 }
467 function getListOfXDrivers()
468 {
469 $drivers = array();
471 /* Generate a list of xdrivers from CONFIG_DIR/xdrivers */
472 if (file_exists(CONFIG_DIR.'/xdrivers')){
473 $xdrivers = file (CONFIG_DIR.'/xdrivers');
474 foreach ($xdrivers as $line){
475 if (!preg_match ("/^#/", $line)){
476 $drivers[]= trim($line);
477 }
478 }
479 } else {
480 $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
481 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia",
482 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
483 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
484 }
485 return($drivers);
486 }
489 /* Return plugin informations for acl handling */
490 static function plInfo()
491 {
492 return (array(
493 "plShortName" => _("Service"),
494 "plDescription" => _("Terminal service"),
495 "plSelfModify" => FALSE,
496 "plDepends" => array(),
497 "plPriority" => 3,
498 "plSection" => array("administration"),
499 "plCategory" => array("terminal"),
501 "plProvidedAcls"=> array(
502 "gotoXMonitor" => _("Monitor"),
503 "gotoXMethod" => _("Method"),
504 "gotoXdmcpServer" => _("Remote desktop"),
505 "gotoFontPath" => _("Font path"),
506 "gotoXDriver" => _("Gfx driver"),
507 "gotoXResolution" => _("Gfx resolution"),
508 "gotoXColordepth" => _("Gfx color depth"),
509 "gotoXHsync" => _("Hsync"),
510 "gotoXVsync" => _("Vsync"),
511 "AutoSync" => _("Auto-Sync"),
512 "gotoLpdEnable" => _("Printer service enabled"),
513 "gotoLpdServer" => _("Spool server"),
514 "gotoScannerEnable" => _("Scanner enabled"),
515 "gotoScannerModel" => _("Scanner model"),
516 "gotoXKbModel" => _("Keyboard model"),
517 "gotoXKbLayout" => _("Keyboard layout"),
518 "gotoXKbVariant" => _("Keyboard variant"),
519 "gotoXMouseType" => _("Mouse type"),
520 "gotoXMouseport" => _("Mouse port"),
521 "goFonHardware" => _("Telephone hardware"))
522 ));
523 }
524 }
526 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
527 ?>