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 foreach ($this->hardware_list as $cn => $desc){
166 $ldap->search("(goFonHardware=$cn)", array('cn'));
167 if ($ldap->count() > 0){
168 $ldap->fetch();
169 if ($ldap->getDN() != $this->dn){
170 $this->used_hardware[$cn]= $ldap->getDN();
171 }
172 }
173 }
175 if(preg_match("/\+/",$this->gotoXHsync)){
176 $this->AutoSync = true;
177 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
178 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
179 }
181 $this->hardware_list["automatic"]= _("automatic");
182 ksort($this->hardware_list);
184 /* Load hardware list */
185 $ldap= $this->config->get_ldap_link();
186 $ldap->cd($this->config->current['BASE']);
187 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
188 if ($ldap->count() == 1){
189 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
190 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
191 $attrs= $ldap->fetch();
193 foreach ($map as $name){
194 if (!isset($attrs[$name][0])){
195 continue;
196 }
198 switch ($name){
199 case 'gotoXResolution':
200 $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
201 break;
202 case 'gotoXColordepth':
203 $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
204 break;
205 case 'gotoXKbModel':
206 $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
207 break;
208 case 'gotoXKbLayout':
209 $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
210 break;
211 case 'gotoXKbVariant':
212 $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
213 break;
214 case 'gotoXMouseType':
215 $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
216 break;
217 case 'gotoXMouseport':
218 $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
219 break;
220 }
222 }
224 }
226 /* Workaround to fill in inherited values if we've specified an objectclass */
227 if (isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
228 $this->XResolutions= array('default' => _("inherited"));
229 $this->XColordepths= array('default' => _("inherited"));
230 $this->XKbModels= array('default' => _("inherited"));
231 $this->XKbLayouts= array('default' => _("inherited"));
232 $this->XKbVariants= array('default' => _("inherited"));
233 $this->MouseTypes= array('AUTO' => _("inherited"));
234 $this->MousePorts= array('AUTO' => _("inherited"));
235 }
236 }
238 function execute()
239 {
240 /* Call parent execute */
241 plugin::execute();
243 if($this->is_account && !$this->view_logged){
244 $this->view_logged = TRUE;
245 new log("view","workstation/".get_class($this),$this->dn);
246 }
248 /* Do we need to flip is_account state? */
249 if (isset($_POST['modify_state'])){
250 $this->is_account= !$this->is_account;
251 }
253 /* Do we need to flip is_account state? */
254 if(isset($_POST['modify_state'])){
255 if($this->is_account && $this->acl_is_removeable()){
256 $this->is_account= FALSE;
257 }elseif(!$this->is_account && $this->acl_is_createable()){
258 $this->is_account= TRUE;
259 }
260 }
262 /* Show main page */
263 $smarty= get_smarty();
265 /* Assign ACLs */
266 $tmp = $this->plInfo();
267 foreach($tmp['plProvidedAcls'] as $name => $translated){
268 $smarty->assign($name."ACL",$this->getacl($name));
269 }
271 /* Arrays */
272 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
273 "XKbModels", "XKbVariants",
274 "MouseTypes", "MousePorts") as $val){
275 $smarty->assign("$val", $this->$val);
276 }
277 $smarty->assign("XKbLayouts" ,$this->XKbLayouts);
278 $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
280 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
281 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
282 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
283 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
285 /* Variables - select */
286 foreach(array(
287 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
288 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
289 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
291 $smarty->assign($val."_select", $this->$val);
292 }
294 /* Variables */
295 foreach(array("gotoXHsync", "gotoXVsync") as $val){
296 $smarty->assign($val, $this->$val);
297 }
298 $smarty->assign("staticAddress", "");
300 /* Checkboxes */
301 foreach(array("gotoScannerEnable") as $val){
302 if ($this->$val == TRUE) {
303 $smarty->assign("$val", "checked");
304 } else {
305 $smarty->assign("$val", "");
306 }
307 }
309 /* Phone stuff */
310 $smarty->assign ("goFonHardware", $this->goFonHardware);
312 $perms = "";
313 if($this->acl_is_writeable("goFonHardware")){
314 $perms = " disabled ";
315 }
317 $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
318 _("Choose the phone located at the current terminal")."\" >";
319 foreach ($this->hardware_list as $cn => $description){
320 if ($cn == $this->goFonHardware){
321 $selected= "selected";
322 } else {
323 $selected= "";
324 }
325 if (isset($this->used_hardware[$cn])){
326 $color= "style=\"color:#A0A0A0\"";
327 } else {
328 $color= "";
329 }
330 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
331 }
332 $hl.= "</select>\n";
333 $smarty->assign ("hardware_list", $hl);
334 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
336 if($this->AutoSync){
337 $smarty->assign("AutoSyncCHK"," checked ");
338 $smarty->assign("hiddenState"," disabled ");
339 }else{
340 $smarty->assign("AutoSyncCHK"," ");
341 $smarty->assign("hiddenState","");
342 }
344 /* Show main page */
345 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
346 }
348 function remove_from_parent()
349 {
350 $this->handle_post_events("remove");
351 new log("remove","workstation/".get_class($this),$this->dn);
352 }
354 /* Save data to object */
355 function save_object()
356 {
357 plugin::save_object();
359 if((isset($_POST['gotoXDriver'])) && $this->acl_is_writeable("AutoSync")) {
360 if(isset($_POST['AutoSync'])){
361 $this->AutoSync = true;
362 }else{
363 $this->AutoSync = false;
364 }
365 }
366 }
368 /* Check supplied data */
369 function check()
370 {
371 /* Call common method to give check the hook */
372 $message= plugin::check();
374 /* Default entries can use blank hsync/vsync entries */
375 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
377 /* But only if no auto sync is enabled... */
378 if (!$this->AutoSync){
380 /* Check vsync for correct usage */
381 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
383 if($this->acl_is_writeable("gotoXVsync")){
384 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
385 $message[]= _("Please specify a valid VSync range.");
386 } else{
387 list($v1,$v2)= preg_split ("/[-+]/", $val);
388 if ($v2 != ""){
389 if ($v1 > $v2){
390 $message[]= _("Please specify a valid VSync range.");
391 }
392 }
393 }
394 }
396 /* Check hsync for correct usage */
397 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
398 if($this->acl_is_writeable("gotoXHsync")){
399 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
400 $message[]= _("Please specify a valid HSync range.");
401 } else{
402 list($v1,$v2)= preg_split ("/[-+]/", $val);
403 if ($v2 != ""){
404 if ($v1 > $v2){
405 $message[]= _("Please specify a valid HSync range.");
406 }
407 }
408 }
409 }
410 }
411 }
413 return ($message);
414 }
417 /* Save to LDAP */
418 function save()
419 {
420 /* remove objectclass GOhard if this is an ogroup tab */
421 if(isset($this->parent->by_object['ogroup'])){
422 $this->objectclasses = array();
423 }
425 plugin::save();
427 /* Strip out 'default' values */
428 foreach(array(
429 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
430 "gotoXKbModel", "gotoXKbLayout",
431 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
433 if ($this->attrs[$val] == "default"){
434 $this->attrs[$val]= array();
435 }
436 }
438 if($this->AutoSync){
439 $this->attrs['gotoXHsync'] = "30+55";
440 $this->attrs['gotoXVsync'] = "50+70";
441 }
443 /* Write back to ldap */
444 $ldap= $this->config->get_ldap_link();
445 $ldap->cd($this->dn);
446 $this->cleanup();
447 $ldap->modify ($this->attrs);
448 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
449 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/service with dn '%s' failed."),$this->dn));
450 $this->handle_post_events("modify");
451 }
454 function getListOfXDrivers()
455 {
456 /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */
457 $drivers = array();
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 function plInfo()
477 {
478 return (array(
479 "plShortName" => _("Service"),
480 "plDescription" => _("Workstation service"),
481 "plSelfModify" => FALSE,
482 "plDepends" => array(),
483 "plPriority" => 10,
484 "plSection" => array("administration"),
485 "plCategory" => array("workstation","ogroups"),
487 "plProvidedAcls"=> array(
488 "gotoXMonitor" => _("Monitor"),
489 "gotoXDriver" => _("Gfx driver"),
490 "gotoXResolution" => _("Gfx resolution"),
491 "gotoXColordepth" => _("Gfx color depth"),
492 "gotoXHsync" => _("Hsync"),
493 "gotoXVsync" => _("Vsync"),
494 "AutoSync" => _("Use DDC"),
495 "gotoScannerEnable" => _("Scanner enabled"),
496 "gotoXKbModel" => _("Keyboard model"),
497 "gotoXKbLayout" => _("Keyboard layout"),
498 "gotoXKbVariant" => _("Keyboard variant"),
499 "gotoXMouseType" => _("Mouse type"),
500 "gotoXMouseport" => _("Mouse port"),
501 "goFonHardware" => _("Telephone hardware"))
502 ));
503 }
504 }
506 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
507 ?>