1 <?php
3 class termservice extends plugin
4 {
5 /* Generic terminal attributes */
6 var $gotoLpdEnable= FALSE;
7 var $gotoXMonitor= "";
8 var $gotoXMethod= "";
9 var $gotoXdmcpServer= "";
10 var $gotoFontPath= "";
11 var $gotoXDriver= "";
12 var $gotoXResolution= "";
13 var $gotoXColordepth= "";
14 var $gotoXHsync= "";
15 var $gotoXVsync= "";
16 var $gotoXKbModel= "";
17 var $gotoXKbLayout= "";
18 var $gotoXKbVariant= "";
19 var $gotoXMouseType= "";
20 var $gotoXMouseport= "";
21 var $gotoLpdServer= "";
22 var $gotoScannerEnable= "";
23 var $gotoScannerModel= "";
24 var $gotoScannerClients= "";
25 var $gotoScannerBackend= "";
26 var $goFonHardware= "automatic";
27 var $AutoSync = false;
29 /* Needed values and lists */
30 var $ignore_account= TRUE;
31 var $base= "";
32 var $cn= "";
33 var $orig_dn= "";
34 var $XMethods= array();
35 var $XDrivers= array();
36 var $XResolutions= array();
37 var $XColordepths= array();
38 var $XKbModels= array ();
39 var $XKbLayouts= array ();
40 var $XKbVariants= array ();
41 var $MouseTypes= array();
42 var $MousePorts= array();
43 var $gotoScannerModels= array();
44 var $hardware_list= array();
45 var $used_hardware= array();
48 /* attribute list for save action */
49 var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
50 "gotoFontPath", "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");
58 function termservice ($config, $dn= NULL, $parent= NULL)
59 {
60 plugin::plugin ($config, $dn, $parent);
62 /* Get list of available xdrivers */
63 $this->XDrivers = $this->getListOfXDrivers();
64 array_unshift($this->XDrivers, "["._("unknown")."]");
66 $this->XResolutions= array(
67 "default" => "["._("inherited")."]" ,
68 "640x480" => "640x480",
69 "800x600" => "800x600",
70 "1024x768" => "1024x768",
71 "1152x864" => "1152x864",
72 "1280x1024" => "1280x1024",
73 "1400x1050" => "1400x1050",
74 "1600x1200" => "1600x1200");
76 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
77 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
79 if(is_readable($file)){
80 $str = file_get_contents($file);
81 $lines = split("\n",$str);
82 foreach($lines as $line){
83 $line = trim($line);
84 if(!empty($line)){
85 $this->XResolutions[$line]=$line;
86 }
87 }
88 //natcasesort($this->gotoXResolutions);
89 }else{
90 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
91 }
92 }
94 $this->XColordepths= array(
95 "default" => "["._("inherited")."]",
96 "8" => "8 " ._("bit"),
97 "15" => "15 "._("bit"),
98 "16" => "16 "._("bit"),
99 "24" => "24 "._("bit"));
101 $this->XKbModels['default']= "["._("inherited")."]";
102 foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
103 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
104 "logiinetnav", "logiinternet", "macintosh", "microsoft",
105 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
106 "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
107 $this->XKbModels[$type] = $type;
108 }
110 /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */
111 $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
112 $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
114 $this->MouseTypes= array( "AUTO" => "["._("inherited")."]" , "ImPS/2" => "ImPS/2",
115 "PS/2" => "PS/2" , "Microsoft" => "Microsoft",
116 "Logitech" => "Logitech");
118 $this->MousePorts= array("AUTO" =>"["._("inherited")."]" , "/dev/ttyS0" => "/dev/ttyS0",
119 "/dev/ttyS1" => "/dev/ttyS1" , "/dev/psaux" => "/dev/psaux",
120 "/dev/input/mice" =>"/dev/input/mice");
123 /* try to read additional keyboard layouts
124 */
125 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
126 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
127 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
128 $tmp = split("\n",$str);
129 foreach($tmp as $entry){
130 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
131 $entry = trim($entry);
132 $tmp2 = split ("\:",$entry);
133 $la = trim($tmp2[0]); // What would be saved to ldap
134 $da = trim($tmp2[1]); // This wis displayed in the listbox
135 $this->XKbLayouts [ $la] = $da;
136 }
137 }
138 }
139 }
141 /* Load scanner models */
142 $fcontents = file ($this->config->basedir."/include/scanner.inc");
143 while (list ($line_num, $line) = each ($fcontents)) {
144 preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
145 $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
146 }
147 ksort ($this->gotoScannerModels);
149 /* Initialize methods */
150 $this->XMethods["default"]= _("default");
151 $this->XMethods["indirect"]= _("show chooser");
152 $this->XMethods["query"]= _("direct");
153 #$this->XMethods["squery"]= _("direct via ssh");
154 #$this->XMethods["nquery"]= _("direct via nx");
155 $this->XMethods["load"]= _("load balanced");
156 #$this->XMethods["sload"]= _("load balanced via ssh");
157 #$this->XMethods["nload"]= _("load balanced via nx");
158 $this->XMethods["rdp"]= _("Windows RDP");
159 $this->XMethods["citrix"]= _("ICA client");
161 $this->orig_dn= $this->dn;
163 /* Load hardware list */
164 $ldap= $this->config->get_ldap_link();
165 $ldap->cd($this->config->current['BASE']);
166 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
167 while ($attrs= $ldap->fetch()){
168 $cn= $attrs['cn'][0];
169 if (isset($attrs['description'])){
170 $description= " - ".$attrs['description'][0];
171 } else {
172 $description= "";
173 }
174 $this->hardware_list[$cn]= "$cn$description";
175 }
177 /* Eventually colorize phones */
178 $ldap->cd($this->config->current['BASE']);
179 foreach ($this->hardware_list as $cn => $desc){
180 $ldap->search("(goFonHardware=$cn)", array('cn'));
181 if ($ldap->count() > 0){
182 $ldap->fetch();
183 if ($ldap->getDN() != $this->dn){
184 $this->used_hardware[$cn]= $ldap->getDN();
185 }
186 }
187 }
189 $this->hardware_list["automatic"]= _("automatic");
190 ksort($this->hardware_list);
192 /* Convert gotoLpdEnable */
193 $this->gotoLpdEnable= preg_match("/yes/i",$this->gotoLpdEnable);
195 /* Load hardware list */
196 $ldap= $this->config->get_ldap_link();
197 $ldap->cd($this->config->current['BASE']);
198 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
199 if ($ldap->count() == 1){
200 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
201 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
202 $attrs= $ldap->fetch();
204 foreach ($map as $name){
205 if (!isset($attrs[$name][0])){
206 continue;
207 }
209 switch ($name){
210 case 'gotoXResolution':
211 $this->XResolutions['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
212 break;
213 case 'gotoXColordepth':
214 $this->XColordepths['default'] = _("inherited").' ['.$attrs[$name][0].' '._('Bit').']';
215 break;
216 case 'gotoXKbModel':
217 $this->XKbModels['default'] = _("inherited").' ['.$attrs[$name][0].']';
218 break;
219 case 'gotoXKbLayout':
220 $this->XKbLayouts['default'] = _("inherited").' ['.$attrs[$name][0].']';
221 break;
222 case 'gotoXKbVariant':
223 $this->XKbVariants['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
224 break;
225 case 'gotoXMouseType':
226 $this->MouseTypes['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
227 break;
228 case 'gotoXMouseport':
229 $this->MousePorts['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
230 break;
231 }
232 }
233 }
234 if(preg_match("/\+/",$this->gotoXHsync)){
235 $this->AutoSync = true;
236 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
237 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
238 }
239 }
241 function execute()
242 {
243 /* Call parent execute */
244 plugin::execute();
246 /* Do we need to flip is_account state? */
247 if (isset($_POST['modify_state'])){
248 $this->is_account= !$this->is_account;
249 }
251 /* Do we represent a valid terminal? */
252 if (!$this->is_account && $this->parent == NULL){
253 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
254 _("This 'dn' has no terminal features.")."</b>";
255 return ($display);
256 }
258 /* Show main page */
259 $smarty= get_smarty();
261 /* Arrays */
262 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
263 "gotoScannerModels", "XKbModels","XKbVariants",
264 "MouseTypes", "MousePorts") as $val){
265 $smarty->assign("$val", $this->$val);
266 }
267 $smarty->assign("XKbLayouts", $this->XKbLayouts);
268 $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
270 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
271 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
272 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
273 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
275 /* Variables - select */
276 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
277 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
278 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
279 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
281 $smarty->assign($val."_select", $this->$val);
282 $smarty->assign($val."ACL", chkacl($this->acl, $val));
283 }
285 /* Variables */
286 foreach(array("gotoXHsync", "gotoXVsync") as $val){
287 $smarty->assign($val, $this->$val);
288 $smarty->assign($val."ACL", chkacl($this->acl, $val));
289 }
290 $smarty->assign("staticAddress", "");
292 /* Checkboxes */
293 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
294 if ($this->$val == TRUE) {
295 $smarty->assign("$val", "checked");
296 } else {
297 $smarty->assign("$val", "");
298 }
299 $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
300 }
302 /* Phone stuff */
303 $smarty->assign ("goFonHardware", $this->goFonHardware);
304 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
305 _("Choose the phone located at the current terminal")."\" ".
306 chkacl($this->acl, "goFonHardware").">\n";
307 foreach ($this->hardware_list as $cn => $description){
308 if ($cn == $this->goFonHardware){
309 $selected= "selected";
310 } else {
311 $selected= "";
312 }
313 if (isset($this->used_hardware[$cn])){
314 $color= "style=\"color:#A0A0A0\"";
315 } else {
316 $color= "";
317 }
318 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
319 }
320 $hl.= "</select>\n";
321 $smarty->assign ("hardware_list", $hl);
322 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
324 $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
326 if($this->AutoSync){
327 $smarty->assign("AutoSyncCHK"," checked ");
328 $smarty->assign("hiddenState"," disabled ");
329 }else{
330 $smarty->assign("AutoSyncCHK"," ");
331 $smarty->assign("hiddenState","");
332 }
335 /* Show main page */
336 return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
337 }
339 function remove_from_parent()
340 {
341 $this->handle_post_events("remove");
342 }
345 /* Save data to object */
346 function save_object()
347 {
348 plugin::save_object();
350 /* Save checkbox state */
351 if (isset ($_POST['gotoXMethod'])){
352 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
354 if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
355 $this->$val= FALSE;
356 } else {
357 $this->$val= TRUE;
358 }
359 }
360 }
361 if(isset($_POST['gotoXDriver'])){
362 if(isset($_POST['AutoSync'])){
363 $this->AutoSync = true;
364 }else{
365 $this->AutoSync = false;
366 }
367 }
369 }
372 /* Check supplied data */
373 function check()
374 {
375 /* Call common method to give check the hook */
376 $message= plugin::check();
378 /* Default entries can use blank hsync/vsync entries */
379 if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){
381 /* But only if no auto sync is enabled... */
382 if (!$this->AutoSync){
384 /* Check vsync for correct usage */
385 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
386 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
387 && chkacl ($this->acl, "gotoXVsync") == ""){
389 $message[]= _("Please specify a valid VSync range.");
390 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
391 list($v1,$v2)= preg_split ("/[-+]/", $val);
392 if ($v2 != ""){
393 if ($v1 > $v2){
394 $message[]= _("Please specify a valid VSync range.");
395 }
396 }
397 }
399 /* Check hsync for correct usage */
400 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
401 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
402 && chkacl ($this->acl, "gotoXHsync") == ""){
404 $message[]= _("Please specify a valid HSync range.");
405 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
406 list($v1,$v2)= preg_split ("/[-+]/", $val);
407 if ($v2 != ""){
408 if ($v1 > $v2){
409 $message[]= _("Please specify a valid HSync range.");
410 }
411 }
412 }
413 }
414 }
416 return ($message);
417 }
420 /* Save to LDAP */
421 function save()
422 {
423 /* Convert to string */
424 $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
426 plugin::save();
428 /* Strip out 'default' values */
429 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
430 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
431 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
432 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
434 if ($this->attrs[$val] == "default"){
435 $this->attrs[$val]= array();
436 }
437 }
439 if($this->AutoSync){
440 $this->attrs['gotoXHsync'] = "30+55";
441 $this->attrs['gotoXVsync'] = "50+70";
442 }
444 /* Write back to ldap */
445 $ldap= $this->config->get_ldap_link();
446 $ldap->cd($this->dn);
447 $this->cleanup();
448 $ldap->modify ($this->attrs);
450 show_ldap_error($ldap->get_error(), _("Saving terminal service information failed"));
451 $this->handle_post_events("modify");
452 }
455 function getListOfXDrivers()
456 {
457 $drivers = array();
459 /* Generate a list of xdrivers from CONFIG_DIR/xdrivers */
460 if (file_exists(CONFIG_DIR.'/xdrivers')){
461 $xdrivers = file (CONFIG_DIR.'/xdrivers');
462 foreach ($xdrivers as $line){
463 if (!preg_match ("/^#/", $line)){
464 $drivers[]= trim($line);
465 }
466 }
467 } else {
468 $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
469 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia",
470 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
471 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
472 }
473 return($drivers);
474 }
475 }
477 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
478 ?>