1 <?php
3 class termservice 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 /* Generic terminal attributes */
11 var $gotoLpdEnable= FALSE;
12 var $gotoXMonitor= "";
13 var $gotoXMethod= "";
14 var $gotoXdmcpServer= "";
15 var $gotoFontPath= "";
16 var $gotoXDriver= "";
17 var $gotoXResolution= "";
18 var $gotoXColordepth= "";
19 var $gotoXHsync= "";
20 var $gotoXVsync= "";
21 var $gotoXKbModel= "";
22 var $gotoXKbLayout= "";
23 var $gotoXKbVariant= "";
24 var $gotoXMouseType= "";
25 var $gotoXMouseport= "";
26 var $gotoLpdServer= "";
27 var $gotoScannerEnable= "";
28 var $gotoScannerModel= "";
29 var $gotoScannerClients= "";
30 var $gotoScannerBackend= "";
31 var $goFonHardware= "automatic";
33 /* Needed values and lists */
34 var $ignore_account= TRUE;
35 var $base= "";
36 var $cn= "";
37 var $orig_dn= "";
38 var $XMethods= array();
39 var $XDrivers= array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
40 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv",
41 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
42 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
43 var $XResolutions= array();
44 var $XColordepths= array();
45 var $XKbModels= array ();
46 var $XKbLayouts= array ();
47 var $XKbVariants= array ();
48 var $MouseTypes= array();
49 var $MousePorts= array();
50 var $gotoScannerModels= array();
51 var $hardware_list= array();
52 var $used_hardware= array();
55 /* attribute list for save action */
56 var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
57 "gotoFontPath", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
58 "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
59 "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
60 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
61 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
62 var $objectclasses= array("GOhard");
65 function termservice ($config, $dn= NULL, $parent= NULL)
66 {
67 plugin::plugin ($config, $dn, $parent);
69 array_unshift($this->XDrivers, "["._("unknown")."]");
71 $this->XResolutions= array(
72 "default" => "["._("inherited")."]" ,
73 "640x480" => "640x480",
74 "800x600" => "800x600",
75 "1024x768" => "1024x768",
76 "1152x864" => "1152x864",
77 "1280x1024" => "1280x1024",
78 "1400x1050" => "1400x1050",
79 "1600x1200" => "1600x1200");
81 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
82 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
84 if(is_readable($file)){
85 $str = file_get_contents($file);
86 $lines = split("\n",$str);
87 foreach($lines as $line){
88 $line = trim($line);
89 if(!empty($line)){
90 $this->XResolutions[$line]=$line;
91 }
92 }
93 //natcasesort($this->gotoXResolutions);
94 }else{
95 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
96 }
97 }
99 $this->XColordepths= array(
100 "default" => "["._("inherited")."]",
101 "8" => "8 " ._("bit"),
102 "15" => "15 "._("bit"),
103 "16" => "16 "._("bit"),
104 "24" => "24 "._("bit"));
106 $this->XKbModels['default']= "["._("inherited")."]";
107 foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
108 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
109 "logiinetnav", "logiinternet", "macintosh", "microsoft",
110 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
111 "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
112 $this->XKbModels[$type] = $type;
113 }
115 /* Additional values will be extracted from /etc/gosa/keyboardLayouts */
116 $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
117 $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
119 $this->MouseTypes= array( "AUTO" => "["._("inherited")."]" , "ImPS/2" => "ImPS/2",
120 "PS/2" => "PS/2" , "Microsoft" => "Microsoft",
121 "Logitech" => "Logitech");
123 $this->MousePorts= array("AUTO" =>"["._("inherited")."]" , "/dev/ttyS0" => "/dev/ttyS0",
124 "/dev/ttyS1" => "/dev/ttyS1" , "/dev/psaux" => "/dev/psaux",
125 "/dev/input/mice" =>"/dev/input/mice");
128 /* try to read additional keyboard layouts
129 */
130 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
131 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
132 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
133 $tmp = split("\n",$str);
134 foreach($tmp as $entry){
135 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
136 $entry = trim($entry);
137 $tmp2 = split ("\:",$entry);
138 $la = trim($tmp2[0]); // What would be saved to ldap
139 $da = trim($tmp2[1]); // This wis displayed in the listbox
140 $this->XKbLayouts [ $la] = $da;
141 }
142 }
143 }
144 }
146 /* Load scanner models */
147 $fcontents = file ($this->config->basedir."/include/scanner.inc");
148 while (list ($line_num, $line) = each ($fcontents)) {
149 preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
150 $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
151 }
152 ksort ($this->gotoScannerModels);
154 /* Initialize methods */
155 $this->XMethods["default"]= _("default");
156 $this->XMethods["indirect"]= _("show chooser");
157 $this->XMethods["query"]= _("direct");
158 #$this->XMethods["squery"]= _("direct via ssh");
159 #$this->XMethods["nquery"]= _("direct via nx");
160 $this->XMethods["load"]= _("load balanced");
161 #$this->XMethods["sload"]= _("load balanced via ssh");
162 #$this->XMethods["nload"]= _("load balanced via nx");
163 $this->XMethods["rdp"]= _("Windows RDP");
164 $this->XMethods["citrix"]= _("ICA client");
166 $this->orig_dn= $this->dn;
168 /* Load hardware list */
169 $ldap= $this->config->get_ldap_link();
170 $ldap->cd($this->config->current['BASE']);
171 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
172 while ($attrs= $ldap->fetch()){
173 $cn= $attrs['cn'][0];
174 if (isset($attrs['description'])){
175 $description= " - ".$attrs['description'][0];
176 } else {
177 $description= "";
178 }
179 $this->hardware_list[$cn]= "$cn$description";
180 }
182 /* Eventually colorize phones */
183 $ldap->cd($this->config->current['BASE']);
184 foreach ($this->hardware_list as $cn => $desc){
185 $ldap->search("(goFonHardware=$cn)", array('cn'));
186 if ($ldap->count() > 0){
187 $ldap->fetch();
188 if ($ldap->getDN() != $this->dn){
189 $this->used_hardware[$cn]= $ldap->getDN();
190 }
191 }
192 }
194 $this->hardware_list["automatic"]= _("automatic");
195 ksort($this->hardware_list);
198 /* Load hardware list */
199 $ldap= $this->config->get_ldap_link();
200 $ldap->cd($this->config->current['BASE']);
201 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
202 if ($ldap->count() == 1){
203 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
204 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
205 $attrs= $ldap->fetch();
207 foreach ($map as $name){
208 if (!isset($attrs[$name][0])){
209 continue;
210 }
212 switch ($name){
213 case 'gotoXResolution':
214 $this->XResolutions['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
215 break;
216 case 'gotoXColordepth':
217 $this->XColordepths['default'] = _("inherited").' ['.$attrs[$name][0].' '._('Bit').']';
218 break;
219 case 'gotoXKbModel':
220 $this->XKbModels['default'] = _("inherited").' ['.$attrs[$name][0].']';
221 break;
222 case 'gotoXKbLayout':
223 $this->XKbLayouts['default'] = _("inherited").' ['.$attrs[$name][0].']';
224 break;
225 case 'gotoXKbVariant':
226 $this->XKbVariants['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
227 break;
228 case 'gotoXMouseType':
229 $this->MouseTypes['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
230 break;
231 case 'gotoXMouseport':
232 $this->MousePorts['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
233 break;
234 }
235 }
236 }
237 }
239 function execute()
240 {
241 /* Call parent execute */
242 plugin::execute();
244 /* Do we need to flip is_account state? */
245 if (isset($_POST['modify_state'])){
246 $this->is_account= !$this->is_account;
247 }
249 /* Do we represent a valid terminal? */
250 if (!$this->is_account && $this->parent == NULL){
251 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
252 _("This 'dn' has no terminal features.")."</b>";
253 return ($display);
254 }
256 /* Show main page */
257 $smarty= get_smarty();
259 /* Arrays */
260 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
261 "gotoScannerModels", "XKbModels","XKbVariants",
262 "MouseTypes", "MousePorts") as $val){
263 $smarty->assign("$val", $this->$val);
264 }
265 $smarty->assign("XKbLayouts", $this->XKbLayouts);
266 $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
268 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
269 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
270 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
271 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
273 /* Variables - select */
274 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
275 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
276 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
277 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
279 $smarty->assign($val."_select", $this->$val);
280 $smarty->assign($val."ACL", chkacl($this->acl, $val));
281 }
283 /* Variables */
284 foreach(array("gotoXHsync", "gotoXVsync") as $val){
285 $smarty->assign($val, $this->$val);
286 $smarty->assign($val."ACL", chkacl($this->acl, $val));
287 }
288 $smarty->assign("staticAddress", "");
290 /* Checkboxes */
291 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
292 if ($this->$val == TRUE) {
293 $smarty->assign("$val", "checked");
294 } else {
295 $smarty->assign("$val", "");
296 }
297 $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
298 }
300 /* Phone stuff */
301 $smarty->assign ("goFonHardware", $this->goFonHardware);
302 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
303 _("Choose the phone located at the current terminal")."\" ".
304 chkacl($this->acl, "goFonHardware").">\n";
305 foreach ($this->hardware_list as $cn => $description){
306 if ($cn == $this->goFonHardware){
307 $selected= "selected";
308 } else {
309 $selected= "";
310 }
311 if (isset($this->used_hardware[$cn])){
312 $color= "style=\"color:#A0A0A0\"";
313 } else {
314 $color= "";
315 }
316 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
317 }
318 $hl.= "</select>\n";
319 $smarty->assign ("hardware_list", $hl);
320 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
322 /* Show main page */
323 return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
324 }
326 function remove_from_parent()
327 {
328 $this->handle_post_events("remove");
329 }
332 /* Save data to object */
333 function save_object()
334 {
335 plugin::save_object();
337 /* Save checkbox state */
338 if (isset ($_POST['gotoXMethod'])){
339 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
341 if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
342 $this->$val= FALSE;
343 } else {
344 $this->$val= TRUE;
345 }
346 }
347 }
348 }
351 /* Check supplied data */
352 function check()
353 {
354 /* Call common method to give check the hook */
355 $message= plugin::check();
357 /* Default entries can use blank hsync/vsync entries */
358 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
360 /* Check vsync for correct usage */
361 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
362 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
363 && chkacl ($this->acl, "gotoXVsync") == ""){
365 $message[]= _("Please specify a valid VSync range.");
366 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
367 list($v1,$v2)= split ("-", $val);
368 if ($v2 != ""){
369 if ($v1 > $v2){
370 $message[]= _("Please specify a valid VSync range.");
371 }
372 }
373 }
375 /* Check hsync for correct usage */
376 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
377 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
378 && chkacl ($this->acl, "gotoXHsync") == ""){
380 $message[]= _("Please specify a valid HSync range.");
381 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
382 list($v1,$v2)= split ("-", $val);
383 if ($v2 != ""){
384 if ($v1 > $v2){
385 $message[]= _("Please specify a valid HSync range.");
386 }
387 }
388 }
389 }
390 return ($message);
391 }
394 /* Save to LDAP */
395 function save()
396 {
397 plugin::save();
399 /* Strip out 'default' values */
400 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
401 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
402 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
403 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
405 if ($this->attrs[$val] == "default"){
406 $this->attrs[$val]= array();
407 }
408 }
410 /* Write back to ldap */
411 $ldap= $this->config->get_ldap_link();
412 $ldap->cd($this->dn);
413 $this->cleanup();
414 $ldap->modify ($this->attrs);
416 show_ldap_error($ldap->get_error(), sprintf(_("Saving of object system terminal/service with dn '%s' failed."),$this->dn));
417 $this->handle_post_events("modify");
418 }
421 /* Return plugin informations for acl handling */
422 function plInfo()
423 {
424 return (array(
425 "plShortName" => _("Service"),
426 "plDescription" => _("Terminal service"),
427 "plSelfModify" => FALSE,
428 "plDepends" => array(),
429 "plPriority" => 0,
430 "plSection" => array("administration"),
431 "plCategory" => array("terminal"),
433 "plProvidedAcls"=> array(
434 "gotoXMonitor" => _("Monitor"),
435 "gotoXMethod" => _("Method"),
436 "gotoXdmcpServer" => _("Remote desktop"),
437 "gotoFontPath" => _("Font path"),
438 "gotoXDriver" => _("Gfx driver"),
439 "gotoXResolution" => _("Gfx resolution"),
440 "gotoXColordepth" => _("Gfx color depth"),
441 "gotoXHsync" => _("Hsync"),
442 "gotoXVsync" => _("Vsync"),
443 "gotoLpdEnable" => _("Printer service enabled"),
444 "gotoLpdServer" => _("Spool server"),
445 "gotoScannerEnable" => _("Scanner enabled"),
446 "gotoScannerModel" => _("Scanner model"),
447 "gotoScannerClients" => _(""),
448 "gotoScannerBackend" => _(""),
449 "gotoXKbModel" => _("Keyboard model"),
450 "gotoXKbLayout" => _("Keyboard layout"),
451 "gotoXKbVariant" => _("Keyboard variant"),
452 "gotoXMouseType" => _("Mouse type"),
453 "gotoXMouseport" => _("Mouse port"),
454 "goFonHardware" => _("Telephone hardware"))
455 ));
456 }
457 }
459 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
460 ?>