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