51982ff1f7d2e3384742c9ee2bc808869bceda72
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 foreach ($this->hardware_list as $cn => $desc){
160 $ldap->search("(goFonHardware=$cn)", array('cn'));
161 if ($ldap->count() > 0){
162 $ldap->fetch();
163 if ($ldap->getDN() != $this->dn){
164 $this->used_hardware[$cn]= $ldap->getDN();
165 }
166 }
167 }
169 if(preg_match("/\+/",$this->gotoXHsync)){
170 $this->AutoSync = true;
171 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
172 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
173 }
175 $this->hardware_list["automatic"]= _("automatic");
176 ksort($this->hardware_list);
178 /* Load hardware list */
179 $ldap= $this->config->get_ldap_link();
180 $ldap->cd($this->config->current['BASE']);
181 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
182 if ($ldap->count() == 1){
183 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
184 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
185 $attrs= $ldap->fetch();
187 foreach ($map as $name){
188 if (!isset($attrs[$name][0])){
189 continue;
190 }
192 switch ($name){
193 case 'gotoXResolution':
194 $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
195 break;
196 case 'gotoXColordepth':
197 $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
198 break;
199 case 'gotoXKbModel':
200 $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
201 break;
202 case 'gotoXKbLayout':
203 $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
204 break;
205 case 'gotoXKbVariant':
206 $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
207 break;
208 case 'gotoXMouseType':
209 $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
210 break;
211 case 'gotoXMouseport':
212 $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
213 break;
214 }
216 }
218 }
220 /* Workaround to fill in inherited values if we've specified an objectclass */
221 if (isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
222 $this->XResolutions= array('default' => _("inherited"));
223 $this->XColordepths= array('default' => _("inherited"));
224 $this->XKbModels= array('default' => _("inherited"));
225 $this->XKbLayouts= array('default' => _("inherited"));
226 $this->XKbVariants= array('default' => _("inherited"));
227 $this->MouseTypes= array('AUTO' => _("inherited"));
228 $this->MousePorts= array('AUTO' => _("inherited"));
229 }
230 }
232 function execute()
233 {
234 /* Call parent execute */
235 plugin::execute();
237 /* Do we need to flip is_account state? */
238 if (isset($_POST['modify_state'])){
239 $this->is_account= !$this->is_account;
240 }
242 /* Do we represent a valid terminal? */
243 if (!$this->is_account && $this->parent == NULL){
244 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
245 _("This 'dn' has no terminal features.")."</b>";
246 return ($display);
247 }
249 /* Show main page */
250 $smarty= get_smarty();
252 /* Arrays */
253 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
254 "XKbModels", "XKbVariants",
255 "MouseTypes", "MousePorts") as $val){
256 $smarty->assign("$val", $this->$val);
257 }
258 $smarty->assign("XKbLayouts" ,$this->XKbLayouts);
259 $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
261 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
262 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
263 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
264 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
266 /* Variables - select */
267 foreach(array(
268 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
269 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
270 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
272 $smarty->assign($val."_select", $this->$val);
273 $smarty->assign($val."ACL", chkacl($this->acl, $val));
274 }
276 /* Variables */
277 foreach(array("gotoXHsync", "gotoXVsync") as $val){
278 $smarty->assign($val, $this->$val);
279 $smarty->assign($val."ACL", chkacl($this->acl, $val));
280 }
281 $smarty->assign("staticAddress", "");
283 /* Checkboxes */
284 foreach(array("gotoScannerEnable") as $val){
285 if ($this->$val == TRUE) {
286 $smarty->assign("$val", "checked");
287 } else {
288 $smarty->assign("$val", "");
289 }
290 }
292 /* Phone stuff */
293 $smarty->assign ("goFonHardware", $this->goFonHardware);
294 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
295 _("Choose the phone located at the current terminal")."\" ".
296 chkacl($this->acl, "goFonHardware").">\n";
297 foreach ($this->hardware_list as $cn => $description){
298 if ($cn == $this->goFonHardware){
299 $selected= "selected";
300 } else {
301 $selected= "";
302 }
303 if (isset($this->used_hardware[$cn])){
304 $color= "style=\"color:#A0A0A0\"";
305 } else {
306 $color= "";
307 }
308 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
309 }
310 $hl.= "</select>\n";
311 $smarty->assign ("hardware_list", $hl);
312 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
313 $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
315 if($this->AutoSync){
316 $smarty->assign("AutoSyncCHK"," checked ");
317 $smarty->assign("hiddenState"," disabled ");
318 }else{
319 $smarty->assign("AutoSyncCHK"," ");
320 $smarty->assign("hiddenState","");
321 }
323 /* Show main page */
324 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
325 }
327 function remove_from_parent()
328 {
329 $this->handle_post_events("remove");
330 }
332 /* Save data to object */
333 function save_object()
334 {
335 plugin::save_object();
337 if(isset($_POST['gotoXDriver']) && chkacl($this->acl,"AutoSync") == ""){
338 if(isset($_POST['AutoSync'])){
339 $this->AutoSync = true;
340 }else{
341 $this->AutoSync = false;
342 }
343 }
344 }
346 /* Check supplied data */
347 function check()
348 {
349 /* Call common method to give check the hook */
350 $message= plugin::check();
352 /* Default entries can use blank hsync/vsync entries */
353 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
355 /* But only if no auto sync is enabled... */
356 if (!$this->AutoSync){
358 /* Check vsync for correct usage */
359 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
360 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
361 && chkacl ($this->acl, "gotoXVsync") == ""){
363 $message[]= _("Please specify a valid VSync range.");
364 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
365 list($v1,$v2)= preg_split ("/[-+]/", $val);
366 if ($v2 != ""){
367 if ($v1 > $v2){
368 $message[]= _("Please specify a valid VSync range.");
369 }
370 }
371 }
373 /* Check hsync for correct usage */
374 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
375 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
376 && chkacl ($this->acl, "gotoXHsync") == ""){
378 $message[]= _("Please specify a valid HSync range.");
379 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
380 list($v1,$v2)= preg_split ("/[-+]/", $val);
381 if ($v2 != ""){
382 if ($v1 > $v2){
383 $message[]= _("Please specify a valid HSync range.");
384 }
385 }
386 }
387 }
388 }
390 return ($message);
391 }
394 /* Save to LDAP */
395 function save()
396 {
397 /* remove objectclass GOhard if this is an ogroup tab */
398 if(isset($this->parent->by_object['ogroup'])){
399 $this->objectclasses = array();
400 }
402 plugin::save();
404 /* Strip out 'default' values */
405 foreach(array(
406 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
407 "gotoXKbModel", "gotoXKbLayout",
408 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
410 if ($this->attrs[$val] == "default"){
411 $this->attrs[$val]= array();
412 }
413 }
415 if($this->AutoSync){
416 $this->attrs['gotoXHsync'] = "30+55";
417 $this->attrs['gotoXVsync'] = "50+70";
418 }
420 /* Write back to ldap */
421 $ldap= $this->config->get_ldap_link();
422 $ldap->cd($this->dn);
423 $this->cleanup();
424 $ldap->modify ($this->attrs);
426 show_ldap_error($ldap->get_error(), _("Saving workstation services failed"));
427 $this->handle_post_events("modify");
428 }
431 function getListOfXDrivers()
432 {
433 $drivers = array();
435 /* Generate a list of xdrivers from CONFIG_DIR/xdrivers */
436 if (file_exists(CONFIG_DIR.'/xdrivers')){
437 $xdrivers = file (CONFIG_DIR.'/xdrivers');
438 foreach ($xdrivers as $line){
439 if (!preg_match ("/^#/", $line)){
440 $drivers[]= trim($line);
441 }
442 }
443 } else {
444 $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
445 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia",
446 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
447 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
448 }
449 return($drivers);
450 }
451 }
453 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
454 ?>