1 <?php
3 class workservice 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 var $gotoScannerEnable;
11 /* Generic terminal attributes */
12 var $gotoXMonitor= "";
13 var $gotoXDriver= "";
14 var $gotoXResolution= "";
15 var $gotoXColordepth= "";
16 var $gotoXHsync= "";
17 var $gotoXVsync= "";
18 var $AutoSync = false;
19 var $gotoXKbModel= "";
20 var $gotoXKbLayout= "";
21 var $gotoXKbVariant= "";
22 var $gotoXMouseType= "";
23 var $gotoXMouseport= "";
24 var $gotoScannerClients= "";
25 var $gotoScannerBackend= "";
26 var $goFonHardware= "automatic";
27 var $view_logged = 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 $MouseTypes= array();
38 var $MousePorts= array();
39 var $hardware_list= array();
40 var $used_hardware= array();
43 /* attribute list for save action */
44 var $attributes= array("gotoXMonitor",
45 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
46 "gotoXHsync", "gotoXVsync",
47 "gotoScannerEnable", "gotoScannerClients",
48 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
49 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
50 var $objectclasses= array("GOhard");
52 var $XColordepths =array();
53 var $XKbModels =array();
54 var $XKbLayouts =array();
55 var $XKbVariants =array();
57 function workservice (&$config, $dn= NULL, $parent= NULL)
58 {
59 plugin::plugin ($config, $dn, $parent);
61 $this->XResolutions= array(
62 "640x480" => "640x480",
63 "800x600" => "800x600",
64 "1024x768" => "1024x768",
65 "1152x864" => "1152x864",
66 "1280x1024" => "1280x1024",
67 "1400x1050" => "1400x1050",
68 "1600x1200" => "1600x1200");
70 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
71 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
73 if(is_readable($file)){
74 $str = file_get_contents($file);
75 $lines = split("\n",$str);
76 foreach($lines as $line){
77 $line = trim($line);
78 if(!empty($line)){
79 $this->XResolutions[$line]=$line;
80 }
81 }
82 //natcasesort($this->gotoXResolutions);
83 }else{
84 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
85 }
86 }
88 /* Get list of available xdrivers */
89 $this->XDrivers = $this->getListOfXDrivers();
91 array_unshift($this->XDrivers, "["._("unknown")."]");
93 $this->XColordepths= array(
94 "8" => "8 " ._("bit"),
95 "15" => "15 "._("bit"),
96 "16" => "16 "._("bit"),
97 "24" => "24 "._("bit"));
99 foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
100 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
101 "logiinetnav", "logiinternet", "macintosh", "microsoft",
102 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
103 "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
104 $this->XKbModels[$type] = $type;
105 }
107 $this->MouseTypes= array("ImPS/2" => "ImPS/2", "PS/2" => "PS/2", "Microsoft" => "Microsoft",
108 "Logitech" => "Logitech");
110 $this->MousePorts= array("/dev/ttyS0" =>"/dev/ttyS0",
111 "/dev/ttyS1" => "/dev/ttyS1", "/dev/psaux" =>"/dev/psaux",
112 "/dev/input/mice" => "/dev/input/mice");
114 /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */
115 $this->XKbLayouts= array ("de"=> "de","intl" =>"intl","us" =>"us");
116 $this->XKbVariants= array ("nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
118 /* try to read additional keyboard layouts
119 */
120 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
121 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
122 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
123 $tmp = split("\n",$str);
124 foreach($tmp as $entry){
125 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
126 $entry = trim($entry);
127 $tmp2 = split ("\:",$entry);
128 $la = trim($tmp2[0]); // What would be saved to ldap
129 $da = trim($tmp2[1]); // This wis displayed in the listbox
130 $this->XKbLayouts [ $la] = $da;
131 }
132 }
133 }
134 }
136 /* Initialize methods */
137 $this->XMethods["indirect"]= _("show chooser");
138 $this->XMethods["query"]= _("direct");
139 #$this->XMethods["squery"]= _("direct via ssh");
140 #$this->XMethods["nquery"]= _("direct via nx");
141 $this->XMethods["load"]= _("load balanced");
142 #$this->XMethods["sload"]= _("load balanced via ssh");
143 #$this->XMethods["nload"]= _("load balanced via nx");
144 $this->XMethods["rdp"]= _("Windows RDP");
145 $this->XMethods["citrix"]= _("ICA client");
147 $this->orig_dn= $this->dn;
149 /* Load hardware list */
150 $ldap= $this->config->get_ldap_link();
151 $ldap->cd($this->config->current['BASE']);
152 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
153 while ($attrs= $ldap->fetch()){
154 $cn= $attrs['cn'][0];
155 if (isset($attrs['description'])){
156 $description= " - ".$attrs['description'][0];
157 } else {
158 $description= "";
159 }
160 $this->hardware_list[$cn]= "$cn$description";
161 }
163 /* Eventually colorize phones */
164 $ldap->cd($this->config->current['BASE']);
165 $ldap->search("(goFonHardware=*)",array('cn','dn','goFonHardware'));
166 while($attrs = $ldap->fetch()){
167 $cn = $attrs['goFonHardware'][0];
168 if(isset($this->hardware_list[$cn])){
169 $this->used_hardware[$cn]= $cn;
170 }
171 }
173 if(preg_match("/\+/",$this->gotoXHsync)){
174 $this->AutoSync = true;
175 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
176 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
177 }
179 $this->hardware_list["automatic"]= _("automatic");
180 ksort($this->hardware_list);
182 /* Load hardware list */
183 $ldap= $this->config->get_ldap_link();
184 $ldap->cd($this->config->current['BASE']);
185 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
186 if ($ldap->count() == 1){
187 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
188 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
189 $attrs= $ldap->fetch();
191 foreach ($map as $name){
192 if (!isset($attrs[$name][0])){
193 continue;
194 }
196 switch ($name){
197 case 'gotoXResolution':
198 $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
199 break;
200 case 'gotoXColordepth':
201 $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
202 break;
203 case 'gotoXKbModel':
204 $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
205 break;
206 case 'gotoXKbLayout':
207 $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
208 break;
209 case 'gotoXKbVariant':
210 $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
211 break;
212 case 'gotoXMouseType':
213 $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
214 break;
215 case 'gotoXMouseport':
216 $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
217 break;
218 }
220 }
222 }
224 /* Workaround to fill in inherited values if we've specified an objectclass */
225 $SelectedSystemType = session::get("SelectedSystemType");
226 if (isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
227 $this->XResolutions= array('default' => _("inherited"));
228 $this->XColordepths= array('default' => _("inherited"));
229 $this->XKbModels= array('default' => _("inherited"));
230 $this->XKbLayouts= array('default' => _("inherited"));
231 $this->XKbVariants= array('default' => _("inherited"));
232 $this->MouseTypes= array('AUTO' => _("inherited"));
233 $this->MousePorts= array('AUTO' => _("inherited"));
234 }
235 }
237 function execute()
238 {
239 /* Call parent execute */
240 plugin::execute();
242 if($this->is_account && !$this->view_logged){
243 $this->view_logged = TRUE;
244 new log("view","workstation/".get_class($this),$this->dn);
245 }
247 /* Do we need to flip is_account state? */
248 if (isset($_POST['modify_state'])){
249 $this->is_account= !$this->is_account;
250 }
252 /* Do we need to flip is_account state? */
253 if(isset($_POST['modify_state'])){
254 if($this->is_account && $this->acl_is_removeable()){
255 $this->is_account= FALSE;
256 }elseif(!$this->is_account && $this->acl_is_createable()){
257 $this->is_account= TRUE;
258 }
259 }
261 /* Show main page */
262 $smarty= get_smarty();
264 /* Assign ACLs */
265 $tmp = $this->plInfo();
266 foreach($tmp['plProvidedAcls'] as $name => $translated){
267 $smarty->assign($name."ACL",$this->getacl($name));
268 }
270 /* Arrays */
271 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
272 "XKbModels", "XKbVariants",
273 "MouseTypes", "MousePorts") as $val){
274 $smarty->assign("$val", $this->$val);
275 }
276 $smarty->assign("XKbLayouts" ,$this->XKbLayouts);
277 $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
279 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
280 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
281 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
282 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
284 /* Variables - select */
285 foreach(array(
286 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
287 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
288 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
290 $smarty->assign($val."_select", $this->$val);
291 }
293 /* Variables */
294 foreach(array("gotoXHsync", "gotoXVsync") as $val){
295 $smarty->assign($val, $this->$val);
296 }
297 $smarty->assign("staticAddress", "");
299 /* Checkboxes */
300 foreach(array("gotoScannerEnable") as $val){
301 if ($this->$val == TRUE) {
302 $smarty->assign("$val", "checked");
303 } else {
304 $smarty->assign("$val", "");
305 }
306 }
308 /* Phone stuff */
309 $smarty->assign ("goFonHardware", $this->goFonHardware);
311 $perms = "";
312 if($this->acl_is_writeable("goFonHardware")){
313 $perms = " disabled ";
314 }
316 $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
317 _("Choose the phone located at the current terminal")."\" >";
318 foreach ($this->hardware_list as $cn => $description){
319 if ($cn == $this->goFonHardware){
320 $selected= "selected";
321 } else {
322 $selected= "";
323 }
324 if (isset($this->used_hardware[$cn])){
325 $color= "style=\"color:#A0A0A0\"";
326 } else {
327 $color= "";
328 }
329 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
330 }
331 $hl.= "</select>\n";
332 $smarty->assign ("hardware_list", $hl);
333 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
335 if($this->AutoSync){
336 $smarty->assign("AutoSyncCHK"," checked ");
337 $smarty->assign("hiddenState"," disabled ");
338 }else{
339 $smarty->assign("AutoSyncCHK"," ");
340 $smarty->assign("hiddenState","");
341 }
343 /* Show main page */
344 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
345 }
347 function remove_from_parent()
348 {
349 $this->handle_post_events("remove");
350 new log("remove","workstation/".get_class($this),$this->dn);
351 }
353 /* Save data to object */
354 function save_object()
355 {
356 plugin::save_object();
358 if((isset($_POST['gotoXDriver'])) && $this->acl_is_writeable("AutoSync")) {
359 if(isset($_POST['AutoSync'])){
360 $this->AutoSync = true;
361 }else{
362 $this->AutoSync = false;
363 }
364 }
365 }
367 /* Check supplied data */
368 function check()
369 {
370 /* Call common method to give check the hook */
371 $message= plugin::check();
373 /* Default entries can use blank hsync/vsync entries */
374 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
376 /* But only if no auto sync is enabled... */
377 if (!$this->AutoSync){
379 /* Check vsync for correct usage */
380 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
382 if($this->acl_is_writeable("gotoXVsync")){
383 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
384 $message[]= _("Please specify a valid VSync range.");
385 } else{
386 list($v1,$v2)= preg_split ("/[-+]/", $val);
387 if ($v2 != ""){
388 if ($v1 > $v2){
389 $message[]= _("Please specify a valid VSync range.");
390 }
391 }
392 }
393 }
395 /* Check hsync for correct usage */
396 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
397 if($this->acl_is_writeable("gotoXHsync")){
398 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
399 $message[]= _("Please specify a valid HSync range.");
400 } else{
401 list($v1,$v2)= preg_split ("/[-+]/", $val);
402 if ($v2 != ""){
403 if ($v1 > $v2){
404 $message[]= _("Please specify a valid HSync range.");
405 }
406 }
407 }
408 }
409 }
410 }
412 return ($message);
413 }
416 /* Save to LDAP */
417 function save()
418 {
419 /* remove objectclass GOhard if this is an ogroup tab */
420 if(isset($this->parent->by_object['ogroup'])){
421 $this->objectclasses = array();
422 }
424 plugin::save();
426 /* Strip out 'default' values */
427 foreach(array(
428 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
429 "gotoXKbModel", "gotoXKbLayout",
430 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
432 if ($this->attrs[$val] == "default"){
433 $this->attrs[$val]= array();
434 }
435 }
437 if($this->AutoSync){
438 $this->attrs['gotoXHsync'] = "30+55";
439 $this->attrs['gotoXVsync'] = "50+70";
440 }
442 /* Write back to ldap */
443 $ldap= $this->config->get_ldap_link();
444 $ldap->cd($this->dn);
445 $this->cleanup();
446 $ldap->modify ($this->attrs);
447 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
448 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/service with dn '%s' failed."),$this->dn));
449 $this->handle_post_events("modify");
450 }
453 function getListOfXDrivers()
454 {
455 /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */
456 $drivers = array();
457 if (file_exists(CONFIG_DIR.'/xdrivers')){
458 $xdrivers = file (CONFIG_DIR.'/xdrivers');
459 foreach ($xdrivers as $line){
460 if (!preg_match ("/^#/", $line)){
461 $drivers[]= trim($line);
462 }
463 }
464 } else {
465 $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
466 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia",
467 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
468 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
469 }
470 return($drivers);
471 }
474 /* Return plugin informations for acl handling */
475 static function plInfo()
476 {
477 return (array(
478 "plShortName" => _("Service"),
479 "plDescription" => _("Workstation service"),
480 "plSelfModify" => FALSE,
481 "plDepends" => array(),
482 "plPriority" => 10,
483 "plSection" => array("administration"),
484 "plCategory" => array("workstation","ogroups"),
486 "plProvidedAcls"=> array(
487 "gotoXMonitor" => _("Monitor"),
488 "gotoXDriver" => _("Gfx driver"),
489 "gotoXResolution" => _("Gfx resolution"),
490 "gotoXColordepth" => _("Gfx color depth"),
491 "gotoXHsync" => _("Hsync"),
492 "gotoXVsync" => _("Vsync"),
493 "AutoSync" => _("Use DDC"),
494 "gotoScannerEnable" => _("Scanner enabled"),
495 "gotoXKbModel" => _("Keyboard model"),
496 "gotoXKbLayout" => _("Keyboard layout"),
497 "gotoXKbVariant" => _("Keyboard variant"),
498 "gotoXMouseType" => _("Mouse type"),
499 "gotoXMouseport" => _("Mouse port"),
500 "goFonHardware" => _("Telephone hardware"))
501 ));
502 }
503 }
505 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
506 ?>