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