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";
23 /* Needed values and lists */
24 var $ignore_account= TRUE;
25 var $base= "";
26 var $cn= "";
27 var $orig_dn= "";
28 var $XMethods= array();
29 var $XDrivers= array();
30 var $XResolutions = array();
31 var $MouseTypes= array();
32 var $MousePorts= array();
33 var $hardware_list= array();
34 var $used_hardware= array();
37 /* attribute list for save action */
38 var $attributes= array("gotoXMonitor",
39 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
40 "gotoXHsync", "gotoXVsync",
41 "gotoScannerEnable", "gotoScannerClients",
42 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
43 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
44 var $objectclasses= array("GOhard");
46 var $XColordepths =array();
47 var $XKbModels =array();
48 var $XKbLayouts =array();
49 var $XKbVariants =array();
51 function workservice ($config, $dn= NULL, $parent= NULL)
52 {
53 plugin::plugin ($config, $dn, $parent);
55 $this->XResolutions= array(
56 "640x480" => "640x480",
57 "800x600" => "800x600",
58 "1024x768" => "1024x768",
59 "1152x864" => "1152x864",
60 "1280x1024" => "1280x1024",
61 "1400x1050" => "1400x1050",
62 "1600x1200" => "1600x1200");
64 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
65 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
67 if(is_readable($file)){
68 $str = file_get_contents($file);
69 $lines = split("\n",$str);
70 foreach($lines as $line){
71 $line = trim($line);
72 if(!empty($line)){
73 $this->XResolutions[$line]=$line;
74 }
75 }
76 //natcasesort($this->gotoXResolutions);
77 }else{
78 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
79 }
80 }
82 /* Get list of available xdrivers */
83 $this->XDrivers = $this->getListOfXDrivers();
85 array_unshift($this->XDrivers, "["._("unknown")."]");
87 $this->XColordepths= array(
88 "8" => "8 " ._("bit"),
89 "15" => "15 "._("bit"),
90 "16" => "16 "._("bit"),
91 "24" => "24 "._("bit"));
93 foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
94 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
95 "logiinetnav", "logiinternet", "macintosh", "microsoft",
96 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
97 "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
98 $this->XKbModels[$type] = $type;
99 }
101 $this->MouseTypes= array("ImPS/2" => "ImPS/2", "PS/2" => "PS/2", "Microsoft" => "Microsoft",
102 "Logitech" => "Logitech");
104 $this->MousePorts= array("/dev/ttyS0" =>"/dev/ttyS0",
105 "/dev/ttyS1" => "/dev/ttyS1", "/dev/psaux" =>"/dev/psaux",
106 "/dev/input/mice" => "/dev/input/mice");
108 /* Additional values will be extracted from CONFIG_DIR/gosa/keyboardLayouts */
109 $this->XKbLayouts= array ("de"=> "de","intl" =>"intl","us" =>"us");
110 $this->XKbVariants= array ("basic"=>"basic", "nodeadkeys"=>"nodeadkeys");
112 /* try to read additional keyboard layouts
113 */
114 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
115 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
116 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
117 $tmp = split("\n",$str);
118 foreach($tmp as $entry){
119 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
120 $entry = trim($entry);
121 $tmp2 = split ("\:",$entry);
122 $la = trim($tmp2[0]); // What would be saved to ldap
123 $da = trim($tmp2[1]); // This wis displayed in the listbox
124 $this->XKbLayouts [ $la] = $da;
125 }
126 }
127 }
128 }
130 /* Initialize methods */
131 $this->XMethods["indirect"]= _("show chooser");
132 $this->XMethods["query"]= _("direct");
133 #$this->XMethods["squery"]= _("direct via ssh");
134 #$this->XMethods["nquery"]= _("direct via nx");
135 $this->XMethods["load"]= _("load balanced");
136 #$this->XMethods["sload"]= _("load balanced via ssh");
137 #$this->XMethods["nload"]= _("load balanced via nx");
138 $this->XMethods["rdp"]= _("Windows RDP");
139 $this->XMethods["citrix"]= _("ICA client");
141 $this->orig_dn= $this->dn;
143 /* Load hardware list */
144 $ldap= $this->config->get_ldap_link();
145 $ldap->cd($this->config->current['BASE']);
146 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
147 while ($attrs= $ldap->fetch()){
148 $cn= $attrs['cn'][0];
149 if (isset($attrs['description'])){
150 $description= " - ".$attrs['description'][0];
151 } else {
152 $description= "";
153 }
154 $this->hardware_list[$cn]= "$cn$description";
155 }
157 /* Eventually colorize phones */
158 $ldap->cd($this->config->current['BASE']);
159 $ldap->search("(goFonHardware=*)",array('cn','dn','goFonHardware'));
160 while($attrs = $ldap->fetch()){
161 $cn = $attrs['goFonHardware'][0];
162 if(isset($this->hardware_list[$cn])){
163 $this->used_hardware[$cn]= $cn;
164 }
165 }
167 if(preg_match("/\+/",$this->gotoXHsync)){
168 $this->AutoSync = true;
169 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
170 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
171 }
173 $this->hardware_list["automatic"]= _("automatic");
174 ksort($this->hardware_list);
176 /* Load hardware list */
177 $ldap= $this->config->get_ldap_link();
178 $ldap->cd($this->config->current['BASE']);
179 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
180 if ($ldap->count() == 1){
181 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
182 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
183 $attrs= $ldap->fetch();
185 foreach ($map as $name){
186 if (!isset($attrs[$name][0])){
187 continue;
188 }
190 switch ($name){
191 case 'gotoXResolution':
192 $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
193 break;
194 case 'gotoXColordepth':
195 $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
196 break;
197 case 'gotoXKbModel':
198 $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
199 break;
200 case 'gotoXKbLayout':
201 $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
202 break;
203 case 'gotoXKbVariant':
204 $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
205 break;
206 case 'gotoXMouseType':
207 $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
208 break;
209 case 'gotoXMouseport':
210 $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
211 break;
212 }
214 }
216 }
218 /* Workaround to fill in inherited values if we've specified an objectclass */
219 if (isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
220 $this->XResolutions= array('default' => _("inherited"));
221 $this->XColordepths= array('default' => _("inherited"));
222 $this->XKbModels= array('default' => _("inherited"));
223 $this->XKbLayouts= array('default' => _("inherited"));
224 $this->XKbVariants= array('default' => _("inherited"));
225 $this->MouseTypes= array('AUTO' => _("inherited"));
226 $this->MousePorts= array('AUTO' => _("inherited"));
227 }
228 }
230 function execute()
231 {
232 /* Call parent execute */
233 plugin::execute();
235 /* Do we need to flip is_account state? */
236 if (isset($_POST['modify_state'])){
237 $this->is_account= !$this->is_account;
238 }
240 /* Do we represent a valid terminal? */
241 if (!$this->is_account && $this->parent == NULL){
242 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
243 _("This 'dn' has no terminal features.")."</b>";
244 return ($display);
245 }
247 /* Show main page */
248 $smarty= get_smarty();
250 /* Arrays */
251 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
252 "XKbModels", "XKbVariants",
253 "MouseTypes", "MousePorts") as $val){
254 $smarty->assign("$val", $this->$val);
255 }
256 $smarty->assign("XKbLayouts" ,$this->XKbLayouts);
257 $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
259 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
260 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
261 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
262 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
264 /* Variables - select */
265 foreach(array(
266 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
267 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
268 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
270 $smarty->assign($val."_select", $this->$val);
271 $smarty->assign($val."ACL", chkacl($this->acl, $val));
272 }
274 /* Variables */
275 foreach(array("gotoXHsync", "gotoXVsync") as $val){
276 $smarty->assign($val, $this->$val);
277 $smarty->assign($val."ACL", chkacl($this->acl, $val));
278 }
279 $smarty->assign("staticAddress", "");
281 /* Checkboxes */
282 foreach(array("gotoScannerEnable") as $val){
283 if ($this->$val == TRUE) {
284 $smarty->assign("$val", "checked");
285 } else {
286 $smarty->assign("$val", "");
287 }
288 }
290 /* Phone stuff */
291 $smarty->assign ("goFonHardware", $this->goFonHardware);
292 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
293 _("Choose the phone located at the current terminal")."\" ".
294 chkacl($this->acl, "goFonHardware").">\n";
295 foreach ($this->hardware_list as $cn => $description){
296 if ($cn == $this->goFonHardware){
297 $selected= "selected";
298 } else {
299 $selected= "";
300 }
301 if (isset($this->used_hardware[$cn])){
302 $color= "style=\"color:#A0A0A0\"";
303 } else {
304 $color= "";
305 }
306 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
307 }
308 $hl.= "</select>\n";
309 $smarty->assign ("hardware_list", $hl);
310 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
311 $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
313 if($this->AutoSync){
314 $smarty->assign("AutoSyncCHK"," checked ");
315 $smarty->assign("hiddenState"," disabled ");
316 }else{
317 $smarty->assign("AutoSyncCHK"," ");
318 $smarty->assign("hiddenState","");
319 }
321 /* Show main page */
322 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
323 }
325 function remove_from_parent()
326 {
327 $this->handle_post_events("remove");
328 }
330 /* Save data to object */
331 function save_object()
332 {
333 plugin::save_object();
335 if(isset($_POST['gotoXDriver']) && chkacl($this->acl,"AutoSync") == ""){
336 if(isset($_POST['AutoSync'])){
337 $this->AutoSync = true;
338 }else{
339 $this->AutoSync = false;
340 }
341 }
342 }
344 /* Check supplied data */
345 function check()
346 {
347 /* Call common method to give check the hook */
348 $message= plugin::check();
350 /* Default entries can use blank hsync/vsync entries */
351 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
353 /* But only if no auto sync is enabled... */
354 if (!$this->AutoSync){
356 /* Check vsync for correct usage */
357 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
358 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
359 && chkacl ($this->acl, "gotoXVsync") == ""){
361 $message[]= _("Please specify a valid VSync range.");
362 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
363 list($v1,$v2)= preg_split ("/[-+]/", $val);
364 if ($v2 != ""){
365 if ($v1 > $v2){
366 $message[]= _("Please specify a valid VSync range.");
367 }
368 }
369 }
371 /* Check hsync for correct usage */
372 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
373 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
374 && chkacl ($this->acl, "gotoXHsync") == ""){
376 $message[]= _("Please specify a valid HSync range.");
377 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
378 list($v1,$v2)= preg_split ("/[-+]/", $val);
379 if ($v2 != ""){
380 if ($v1 > $v2){
381 $message[]= _("Please specify a valid HSync range.");
382 }
383 }
384 }
385 }
386 }
388 return ($message);
389 }
392 /* Save to LDAP */
393 function save()
394 {
395 /* remove objectclass GOhard if this is an ogroup tab */
396 if(isset($this->parent->by_object['ogroup'])){
397 $this->objectclasses = array();
398 }
400 plugin::save();
402 /* Strip out 'default' values */
403 foreach(array(
404 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
405 "gotoXKbModel", "gotoXKbLayout",
406 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
408 if ($this->attrs[$val] == "default"){
409 $this->attrs[$val]= array();
410 }
411 }
413 if($this->AutoSync){
414 $this->attrs['gotoXHsync'] = "30+55";
415 $this->attrs['gotoXVsync'] = "50+70";
416 }
418 /* Write back to ldap */
419 $ldap= $this->config->get_ldap_link();
420 $ldap->cd($this->dn);
421 $this->cleanup();
422 $ldap->modify ($this->attrs);
424 show_ldap_error($ldap->get_error(), _("Saving workstation services failed"));
425 $this->handle_post_events("modify");
426 }
429 function getListOfXDrivers()
430 {
431 $drivers = array();
433 /* Generate a list of xdrivers from CONFIG_DIR/xdrivers */
434 if (file_exists(CONFIG_DIR.'/xdrivers')){
435 $xdrivers = file (CONFIG_DIR.'/xdrivers');
436 foreach ($xdrivers as $line){
437 if (!preg_match ("/^#/", $line)){
438 $drivers[]= trim($line);
439 }
440 }
441 } else {
442 $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
443 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia",
444 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
445 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
446 }
447 return($drivers);
448 }
449 }
451 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
452 ?>