2be95df7957e78c00dc78fec861bde405badcf05
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;
35 /* Needed values and lists */
36 var $ignore_account= TRUE;
37 var $base= "";
38 var $cn= "";
39 var $orig_dn= "";
40 var $XMethods= array();
41 var $XDrivers= array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
42 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv",
43 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
44 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
45 var $XResolutions= array();
46 var $XColordepths= array();
47 var $XKbModels= array ();
48 var $XKbLayouts= array ();
49 var $XKbVariants= array ();
50 var $MouseTypes= array();
51 var $MousePorts= array();
52 var $gotoScannerModels= array();
53 var $hardware_list= array();
54 var $used_hardware= array();
57 /* attribute list for save action */
58 var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
59 "gotoFontPath", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
60 "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
61 "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
62 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
63 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
64 var $objectclasses= array("GOhard");
67 function termservice ($config, $dn= NULL, $parent= NULL)
68 {
69 plugin::plugin ($config, $dn, $parent);
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 ($this->config->basedir."/include/scanner.inc");
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 foreach ($this->hardware_list as $cn => $desc){
187 $ldap->search("(goFonHardware=$cn)", array('cn'));
188 if ($ldap->count() > 0){
189 $ldap->fetch();
190 if ($ldap->getDN() != $this->dn){
191 $this->used_hardware[$cn]= $ldap->getDN();
192 }
193 }
194 }
196 $this->hardware_list["automatic"]= _("automatic");
197 ksort($this->hardware_list);
199 /* Convert gotoLpdEnable */
200 $this->gotoLpdEnable= preg_match("/yes/i",$this->gotoLpdEnable);
202 /* Load hardware list */
203 $ldap= $this->config->get_ldap_link();
204 $ldap->cd($this->config->current['BASE']);
205 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
206 if ($ldap->count() == 1){
207 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
208 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
209 $attrs= $ldap->fetch();
211 foreach ($map as $name){
212 if (!isset($attrs[$name][0])){
213 continue;
214 }
216 switch ($name){
217 case 'gotoXResolution':
218 $this->XResolutions['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
219 break;
220 case 'gotoXColordepth':
221 $this->XColordepths['default'] = _("inherited").' ['.$attrs[$name][0].' '._('Bit').']';
222 break;
223 case 'gotoXKbModel':
224 $this->XKbModels['default'] = _("inherited").' ['.$attrs[$name][0].']';
225 break;
226 case 'gotoXKbLayout':
227 $this->XKbLayouts['default'] = _("inherited").' ['.$attrs[$name][0].']';
228 break;
229 case 'gotoXKbVariant':
230 $this->XKbVariants['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
231 break;
232 case 'gotoXMouseType':
233 $this->MouseTypes['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
234 break;
235 case 'gotoXMouseport':
236 $this->MousePorts['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
237 break;
238 }
239 }
240 }
241 if(preg_match("/\+/",$this->gotoXHsync)){
242 $this->AutoSync = true;
243 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
244 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
245 }
247 if($this->is_account){
248 @log::log("view","terminal/".get_class($this),$this->dn);
249 }
250 }
252 function execute()
253 {
254 /* Call parent execute */
255 plugin::execute();
257 /* Do we need to flip is_account state? */
258 if (isset($_POST['modify_state'])){
259 $this->is_account= !$this->is_account;
260 }
262 /* Do we represent a valid terminal? */
263 if (!$this->is_account && $this->parent == NULL){
264 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
265 _("This 'dn' has no terminal features.")."</b>";
266 return ($display);
267 }
269 /* Show main page */
270 $smarty= get_smarty();
272 /* Assign acls */
273 $tmp= $this->plInfo();
274 foreach($tmp['plProvidedAcls'] as $name => $translation){
275 $smarty->assign($name."ACL",$this->getacl($name));
276 }
279 /* Arrays */
280 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
281 "gotoScannerModels", "XKbModels","XKbVariants",
282 "MouseTypes", "MousePorts") as $val){
283 $smarty->assign("$val", $this->$val);
284 }
285 $smarty->assign("XKbLayouts", $this->XKbLayouts);
286 $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
288 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
289 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
290 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
291 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
293 /* Variables - select */
294 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
295 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
296 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
297 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
299 $smarty->assign($val."_select", $this->$val);
300 }
302 /* Variables */
303 foreach(array("gotoXHsync", "gotoXVsync") as $val){
304 $smarty->assign($val, $this->$val);
305 }
306 $smarty->assign("staticAddress", "");
308 /* Checkboxes */
309 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
310 if ($this->$val == TRUE) {
311 $smarty->assign("$val", "checked");
312 } else {
313 $smarty->assign("$val", "");
314 }
315 }
317 /* Phone stuff */
318 $smarty->assign ("goFonHardware", $this->goFonHardware);
319 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
320 _("Choose the phone located at the current terminal")."\" >\n";
321 foreach ($this->hardware_list as $cn => $description){
322 if ($cn == $this->goFonHardware){
323 $selected= "selected";
324 } else {
325 $selected= "";
326 }
327 if (isset($this->used_hardware[$cn])){
328 $color= "style=\"color:#A0A0A0\"";
329 } else {
330 $color= "";
331 }
332 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
333 }
334 $hl.= "</select>\n";
335 $smarty->assign ("hardware_list", $hl);
336 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
338 $smarty->assign("AutoSyncACL",$this->getacl("AutoSync"));
340 $smarty->assign("AutoSyncCHK"," ");
341 if($this->AutoSync){
342 $smarty->assign("AutoSyncCHK"," checked ");
343 $smarty->assign("gotoXVsyncACL", preg_replace("/w/","",$this->getacl("gotoXVsync")));
344 $smarty->assign("gotoXHsyncACL", preg_replace("/w/","",$this->getacl("gotoXHsync")));
345 }
347 /* Show main page */
348 return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
349 }
351 function remove_from_parent()
352 {
353 @log::log("remove","terminal/".get_class($this),$this->dn,array_keys($this->attrs));
354 $this->handle_post_events("remove");
355 }
358 /* Save data to object */
359 function save_object()
360 {
361 plugin::save_object();
363 /* Save checkbox state */
364 if (isset ($_POST['gotoXMethod'])){
365 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
367 if($this->acl_is_writeable($val)){
368 if (!isset ($_POST["$val"])){
369 $this->$val= FALSE;
370 } else {
371 $this->$val= TRUE;
372 }
373 }
374 }
375 }
377 if(isset($_POST['gotoXDriver'])){
378 if(isset($_POST['AutoSync'])){
379 $this->AutoSync = true;
380 }else{
381 $this->AutoSync = false;
382 }
383 }
385 /* Default entries can use blank hsync/vsync entries */
386 if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){
388 /* But only if no auto sync is enabled... */
389 if (!$this->AutoSync){
391 /* Check vsync for correct usage */
392 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
393 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXVsync")){
395 $message[]= _("Please specify a valid VSync range.");
396 } elseif ($this->acl_is_writeable("gotoXVsync")){
397 list($v1,$v2)= preg_split ("/[-+]/", $val);
398 if ($v2 != ""){
399 if ($v1 > $v2){
400 $message[]= _("Please specify a valid VSync range.");
401 }
402 }
403 }
405 /* Check hsync for correct usage */
406 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
407 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXHsync")){
409 $message[]= _("Please specify a valid HSync range.");
410 } elseif ($this->acl_is_writeable("gotoXHsync")){
411 list($v1,$v2)= preg_split ("/[-+]/", $val);
412 if ($v2 != ""){
413 if ($v1 > $v2){
414 $message[]= _("Please specify a valid HSync range.");
415 }
416 }
417 }
418 }
419 }
420 }
423 /* Check supplied data */
424 function check()
425 {
426 /* Call common method to give check the hook */
427 $message= plugin::check();
428 return ($message);
429 }
432 /* Save to LDAP */
433 function save()
434 {
435 /* Convert to string */
436 $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
438 plugin::save();
440 /* Strip out 'default' values */
441 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
442 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
443 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
444 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
446 if ($this->attrs[$val] == "default"){
447 $this->attrs[$val]= array();
448 }
449 }
451 if($this->AutoSync){
452 $this->attrs['gotoXHsync'] = "30+55";
453 $this->attrs['gotoXVsync'] = "50+70";
454 }
456 /* Write back to ldap */
457 $ldap= $this->config->get_ldap_link();
458 $ldap->cd($this->dn);
459 $this->cleanup();
460 $ldap->modify ($this->attrs);
461 @log::log("modify","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
463 show_ldap_error($ldap->get_error(), sprintf(_("Saving of object system terminal/service with dn '%s' failed."),$this->dn));
464 $this->handle_post_events("modify");
465 }
468 /* Return plugin informations for acl handling */
469 function plInfo()
470 {
471 return (array(
472 "plShortName" => _("Service"),
473 "plDescription" => _("Terminal service"),
474 "plSelfModify" => FALSE,
475 "plDepends" => array(),
476 "plPriority" => 3,
477 "plSection" => array("administration"),
478 "plCategory" => array("terminal"),
480 "plProvidedAcls"=> array(
481 "gotoXMonitor" => _("Monitor"),
482 "gotoXMethod" => _("Method"),
483 "gotoXdmcpServer" => _("Remote desktop"),
484 "gotoFontPath" => _("Font path"),
485 "gotoXDriver" => _("Gfx driver"),
486 "gotoXResolution" => _("Gfx resolution"),
487 "gotoXColordepth" => _("Gfx color depth"),
488 "gotoXHsync" => _("Hsync"),
489 "gotoXVsync" => _("Vsync"),
490 "AutoSync" => _("Auto-Sync"),
491 "gotoLpdEnable" => _("Printer service enabled"),
492 "gotoLpdServer" => _("Spool server"),
493 "gotoScannerEnable" => _("Scanner enabled"),
494 "gotoScannerModel" => _("Scanner model"),
495 "gotoScannerClients" => _("Haeh ? "),
496 "gotoScannerBackend" => _("..."),
497 "gotoXKbModel" => _("Keyboard model"),
498 "gotoXKbLayout" => _("Keyboard layout"),
499 "gotoXKbVariant" => _("Keyboard variant"),
500 "gotoXMouseType" => _("Mouse type"),
501 "gotoXMouseport" => _("Mouse port"),
502 "goFonHardware" => _("Telephone hardware"))
503 ));
504 }
505 }
507 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
508 ?>