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