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","explorerps/2"=>"explorerps/2",);
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 phone hardware list
150 */
151 $tmp = get_sub_list("(objectClass=goFonHardware)","",array(get_ou("phoneou")),
152 $this->config->current['BASE'],array("cn","description"), GL_NO_ACL_CHECK);
153 foreach($tmp as $attrs){
154 $cn= $attrs['cn'][0];
155 $description= "";
156 if (isset($attrs['description'])){
157 $description= " - ".$attrs['description'][0];
158 }
159 $this->hardware_list[$cn]= "$cn$description";
160 }
161 $this->hardware_list["automatic"]= _("automatic");
162 ksort($this->hardware_list);
164 /* These departments may contain objects that have
165 goFonHardware set.
166 */
167 $deps_a = array(
168 get_people_ou(),
169 get_ou("ogroupou"),
170 get_ou("serverou"),
171 get_ou("terminalou"),
172 get_ou("workstationou"),
173 get_ou("printerou"),
174 get_ou("componentou"),
175 get_ou("phoneou"));
177 $tmp = get_sub_list("(goFonHardware=*)","",$deps_a,$this->config->current['BASE'],
178 array('cn','dn','goFonHardware'),GL_NO_ACL_CHECK);
179 foreach($tmp as $attrs){
180 $cn = $attrs['goFonHardware'][0];
181 if(isset($this->hardware_list[$cn])){
182 $this->used_hardware[$cn]= $cn;
183 }
184 }
186 if(preg_match("/\+/",$this->gotoXHsync)){
187 $this->AutoSync = true;
188 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
189 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
190 }
192 /* Load hardware list */
193 $ldap= $this->config->get_ldap_link();
194 $ldap->cd($this->config->current['BASE']);
195 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
196 if ($ldap->count() == 1){
197 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
198 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
199 $attrs= $ldap->fetch();
201 foreach ($map as $name){
202 if (!isset($attrs[$name][0])){
203 continue;
204 }
206 switch ($name){
207 case 'gotoXResolution':
208 $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
209 break;
210 case 'gotoXColordepth':
211 $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
212 break;
213 case 'gotoXKbModel':
214 $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
215 break;
216 case 'gotoXKbLayout':
217 $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
218 break;
219 case 'gotoXKbVariant':
220 $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
221 break;
222 case 'gotoXMouseType':
223 $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
224 break;
225 case 'gotoXMouseport':
226 $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
227 break;
228 }
230 }
232 }
234 /* Workaround to fill in inherited values if we've specified an objectclass */
235 $SelectedSystemType = session::get("SelectedSystemType");
236 if (isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
237 $this->XResolutions= array('default' => _("inherited"));
238 $this->XColordepths= array('default' => _("inherited"));
239 $this->XKbModels= array('default' => _("inherited"));
240 $this->XKbLayouts= array('default' => _("inherited"));
241 $this->XKbVariants= array('default' => _("inherited"));
242 $this->MouseTypes= array('AUTO' => _("inherited"));
243 $this->MousePorts= array('AUTO' => _("inherited"));
244 }
245 }
247 function execute()
248 {
249 /* Call parent execute */
250 plugin::execute();
252 if($this->is_account && !$this->view_logged){
253 $this->view_logged = TRUE;
254 new log("view","workstation/".get_class($this),$this->dn);
255 }
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 need to flip is_account state? */
263 if(isset($_POST['modify_state'])){
264 if($this->is_account && $this->acl_is_removeable()){
265 $this->is_account= FALSE;
266 }elseif(!$this->is_account && $this->acl_is_createable()){
267 $this->is_account= TRUE;
268 }
269 }
271 /* Show main page */
272 $smarty= get_smarty();
274 /* Assign ACLs */
275 $tmp = $this->plInfo();
276 foreach($tmp['plProvidedAcls'] as $name => $translated){
277 $smarty->assign($name."ACL",$this->getacl($name));
278 }
280 /* Arrays */
281 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
282 "XKbModels", "XKbVariants",
283 "MouseTypes", "MousePorts") as $val){
284 $smarty->assign("$val", $this->$val);
285 }
286 $smarty->assign("XKbLayouts" ,$this->XKbLayouts);
287 $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
289 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
290 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
291 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
293 /* Variables - select */
294 foreach(array(
295 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
296 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
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("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);
320 $perms = "";
321 if(!$this->acl_is_writeable("goFonHardware")){
322 $perms = " disabled ";
323 }
325 $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
326 _("Choose the phone located at the current terminal")."\" >";
327 foreach ($this->hardware_list as $cn => $description){
328 if ($cn == $this->goFonHardware){
329 $selected= "selected";
330 } else {
331 $selected= "";
332 }
333 if (isset($this->used_hardware[$cn])){
334 $color= "style=\"color:#A0A0A0\"";
335 } else {
336 $color= "";
337 }
338 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
339 }
340 $hl.= "</select>\n";
341 $smarty->assign ("hardware_list", $hl);
342 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
344 if($this->AutoSync){
345 $smarty->assign("AutoSyncCHK"," checked ");
346 $smarty->assign("hiddenState"," disabled ");
347 }else{
348 $smarty->assign("AutoSyncCHK"," ");
349 $smarty->assign("hiddenState","");
350 }
352 /* Show main page */
353 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
354 }
356 function remove_from_parent()
357 {
358 $this->handle_post_events("remove");
359 new log("remove","workstation/".get_class($this),$this->dn);
360 }
362 /* Save data to object */
363 function save_object()
364 {
365 plugin::save_object();
367 if((isset($_POST['gotoXDriver'])) && $this->acl_is_writeable("AutoSync")) {
368 if(isset($_POST['AutoSync'])){
369 $this->AutoSync = true;
370 }else{
371 $this->AutoSync = false;
372 }
373 }
374 }
376 /* Check supplied data */
377 function check()
378 {
379 /* Call common method to give check the hook */
380 $message= plugin::check();
382 /* Default entries can use blank hsync/vsync entries */
383 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
385 /* But only if no auto sync is enabled... */
386 if (!$this->AutoSync){
388 /* Check vsync for correct usage */
389 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
391 if($this->acl_is_writeable("gotoXVsync")){
392 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
393 $message[]= _("Please specify a valid VSync range.");
394 } else{
395 list($v1,$v2)= preg_split ("/[-+]/", $val);
396 if ($v2 != ""){
397 if ($v1 > $v2){
398 $message[]= _("Please specify a valid VSync range.");
399 }
400 }
401 }
402 }
404 /* Check hsync for correct usage */
405 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
406 if($this->acl_is_writeable("gotoXHsync")){
407 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
408 $message[]= _("Please specify a valid HSync range.");
409 } else{
410 list($v1,$v2)= preg_split ("/[-+]/", $val);
411 if ($v2 != ""){
412 if ($v1 > $v2){
413 $message[]= _("Please specify a valid HSync range.");
414 }
415 }
416 }
417 }
418 }
419 }
421 return ($message);
422 }
425 /* Save to LDAP */
426 function save()
427 {
428 /* remove objectclass GOhard if this is an ogroup tab */
429 if(isset($this->parent->by_object['ogroup'])){
430 $this->objectclasses = array();
431 }
433 plugin::save();
435 /* Strip out 'default' values */
436 foreach(array(
437 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
438 "gotoXKbModel", "gotoXKbLayout",
439 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
441 if ($this->attrs[$val] == "default"){
442 $this->attrs[$val]= array();
443 }
444 }
446 if($this->AutoSync){
447 $this->attrs['gotoXHsync'] = "30+55";
448 $this->attrs['gotoXVsync'] = "50+70";
449 }
451 /* Write back to ldap */
452 $ldap= $this->config->get_ldap_link();
453 $ldap->cd($this->dn);
454 $this->cleanup();
455 $ldap->modify ($this->attrs);
456 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
457 show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/service with dn '%s' failed."),$this->dn));
458 $this->handle_post_events("modify");
459 }
462 function getListOfXDrivers()
463 {
464 /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */
465 $drivers = array();
466 if (file_exists(CONFIG_DIR.'/xdrivers')){
467 $xdrivers = file (CONFIG_DIR.'/xdrivers');
468 foreach ($xdrivers as $line){
469 if (!preg_match ("/^#/", $line)){
470 $drivers[]= trim($line);
471 }
472 }
473 } else {
474 $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
475 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia",
476 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
477 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
478 }
479 return($drivers);
480 }
483 /* Return plugin informations for acl handling */
484 static function plInfo()
485 {
486 return (array(
487 "plShortName" => _("Service"),
488 "plDescription" => _("Workstation service"),
489 "plSelfModify" => FALSE,
490 "plDepends" => array(),
491 "plPriority" => 10,
492 "plSection" => array("administration"),
493 "plCategory" => array("workstation","ogroups"),
495 "plProvidedAcls"=> array(
496 "gotoXMonitor" => _("Monitor"),
497 "gotoXDriver" => _("Gfx driver"),
498 "gotoXResolution" => _("Gfx resolution"),
499 "gotoXColordepth" => _("Gfx color depth"),
500 "gotoXHsync" => _("Hsync"),
501 "gotoXVsync" => _("Vsync"),
502 "AutoSync" => _("Use DDC"),
503 "gotoScannerEnable" => _("Scanner enabled"),
504 "gotoXKbModel" => _("Keyboard model"),
505 "gotoXKbLayout" => _("Keyboard layout"),
506 "gotoXKbVariant" => _("Keyboard variant"),
507 "gotoXMouseType" => _("Mouse type"),
508 "gotoXMouseport" => _("Mouse port"),
509 "goFonHardware" => _("Telephone hardware"))
510 ));
511 }
512 }
514 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
515 ?>