eb40ec0ac5c44ccb720c754a7bd8969211333db4
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);
197 /* Convert gotoLpdEnable */
198 $this->gotoLpdEnable= preg_match("/yes/i",$this->gotoLpdEnable);
200 /* Load hardware list */
201 $ldap= $this->config->get_ldap_link();
202 $ldap->cd($this->config->current['BASE']);
203 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
204 if ($ldap->count() == 1){
205 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
206 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
207 $attrs= $ldap->fetch();
209 foreach ($map as $name){
210 if (!isset($attrs[$name][0])){
211 continue;
212 }
214 switch ($name){
215 case 'gotoXResolution':
216 $this->XResolutions['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
217 break;
218 case 'gotoXColordepth':
219 $this->XColordepths['default'] = _("inherited").' ['.$attrs[$name][0].' '._('Bit').']';
220 break;
221 case 'gotoXKbModel':
222 $this->XKbModels['default'] = _("inherited").' ['.$attrs[$name][0].']';
223 break;
224 case 'gotoXKbLayout':
225 $this->XKbLayouts['default'] = _("inherited").' ['.$attrs[$name][0].']';
226 break;
227 case 'gotoXKbVariant':
228 $this->XKbVariants['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
229 break;
230 case 'gotoXMouseType':
231 $this->MouseTypes['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
232 break;
233 case 'gotoXMouseport':
234 $this->MousePorts['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
235 break;
236 }
237 }
238 }
239 }
241 function execute()
242 {
243 /* Call parent execute */
244 plugin::execute();
246 /* Do we need to flip is_account state? */
247 if (isset($_POST['modify_state'])){
248 $this->is_account= !$this->is_account;
249 }
251 /* Do we represent a valid terminal? */
252 if (!$this->is_account && $this->parent == NULL){
253 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
254 _("This 'dn' has no terminal features.")."</b>";
255 return ($display);
256 }
258 /* Show main page */
259 $smarty= get_smarty();
261 /* Assign acls */
262 $tmp= $this->plInfo();
263 foreach($tmp['plProvidedAcls'] as $name => $translation){
264 $smarty->assign($name."ACL",$this->getacl($name));
265 }
268 /* Arrays */
269 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
270 "gotoScannerModels", "XKbModels","XKbVariants",
271 "MouseTypes", "MousePorts") as $val){
272 $smarty->assign("$val", $this->$val);
273 }
274 $smarty->assign("XKbLayouts", $this->XKbLayouts);
275 $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
277 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
278 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
279 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
280 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
282 /* Variables - select */
283 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
284 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
285 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
286 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
288 $smarty->assign($val."_select", $this->$val);
289 }
291 /* Variables */
292 foreach(array("gotoXHsync", "gotoXVsync") as $val){
293 $smarty->assign($val, $this->$val);
294 }
295 $smarty->assign("staticAddress", "");
297 /* Checkboxes */
298 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
299 if ($this->$val == TRUE) {
300 $smarty->assign("$val", "checked");
301 } else {
302 $smarty->assign("$val", "");
303 }
304 }
306 /* Phone stuff */
307 $smarty->assign ("goFonHardware", $this->goFonHardware);
308 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
309 _("Choose the phone located at the current terminal")."\" >\n";
310 foreach ($this->hardware_list as $cn => $description){
311 if ($cn == $this->goFonHardware){
312 $selected= "selected";
313 } else {
314 $selected= "";
315 }
316 if (isset($this->used_hardware[$cn])){
317 $color= "style=\"color:#A0A0A0\"";
318 } else {
319 $color= "";
320 }
321 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
322 }
323 $hl.= "</select>\n";
324 $smarty->assign ("hardware_list", $hl);
325 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
327 /* Show main page */
328 return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
329 }
331 function remove_from_parent()
332 {
333 $this->handle_post_events("remove");
334 }
337 /* Save data to object */
338 function save_object()
339 {
340 plugin::save_object();
342 /* Save checkbox state */
343 if (isset ($_POST['gotoXMethod'])){
344 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
346 if($this->acl_is_writeable($val)){
347 if (!isset ($_POST["$val"])){
348 $this->$val= FALSE;
349 } else {
350 $this->$val= TRUE;
351 }
352 }
353 }
354 }
355 }
358 /* Check supplied data */
359 function check()
360 {
361 /* Call common method to give check the hook */
362 $message= plugin::check();
364 /* Default entries can use blank hsync/vsync entries */
365 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
367 /* Check vsync for correct usage */
368 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
369 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
370 && $this->acl_is_writeable("gotoXVsync")){
372 $message[]= _("Please specify a valid VSync range.");
373 } elseif ($this->acl_is_writeable("gotoXVsync")){
374 list($v1,$v2)= split ("-", $val);
375 if ($v2 != ""){
376 if ($v1 > $v2){
377 $message[]= _("Please specify a valid VSync range.");
378 }
379 }
380 }
382 /* Check hsync for correct usage */
383 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
384 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
385 && $this->acl_is_writeable("gotoXHsync")){
387 $message[]= _("Please specify a valid HSync range.");
388 } elseif ($this->acl_is_writeable("gotoXHsync")){
389 list($v1,$v2)= split ("-", $val);
390 if ($v2 != ""){
391 if ($v1 > $v2){
392 $message[]= _("Please specify a valid HSync range.");
393 }
394 }
395 }
396 }
397 return ($message);
398 }
401 /* Save to LDAP */
402 function save()
403 {
404 /* Convert to string */
405 $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
407 plugin::save();
409 /* Strip out 'default' values */
410 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
411 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
412 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
413 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
415 if ($this->attrs[$val] == "default"){
416 $this->attrs[$val]= array();
417 }
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(), sprintf(_("Saving of object system terminal/service with dn '%s' failed."),$this->dn));
427 $this->handle_post_events("modify");
428 }
431 /* Return plugin informations for acl handling */
432 function plInfo()
433 {
434 return (array(
435 "plShortName" => _("Service"),
436 "plDescription" => _("Terminal service"),
437 "plSelfModify" => FALSE,
438 "plDepends" => array(),
439 "plPriority" => 3,
440 "plSection" => array("administration"),
441 "plCategory" => array("terminal"),
443 "plProvidedAcls"=> array(
444 "gotoXMonitor" => _("Monitor"),
445 "gotoXMethod" => _("Method"),
446 "gotoXdmcpServer" => _("Remote desktop"),
447 "gotoFontPath" => _("Font path"),
448 "gotoXDriver" => _("Gfx driver"),
449 "gotoXResolution" => _("Gfx resolution"),
450 "gotoXColordepth" => _("Gfx color depth"),
451 "gotoXHsync" => _("Hsync"),
452 "gotoXVsync" => _("Vsync"),
453 "gotoLpdEnable" => _("Printer service enabled"),
454 "gotoLpdServer" => _("Spool server"),
455 "gotoScannerEnable" => _("Scanner enabled"),
456 "gotoScannerModel" => _("Scanner model"),
457 "gotoScannerClients" => _(""),
458 "gotoScannerBackend" => _(""),
459 "gotoXKbModel" => _("Keyboard model"),
460 "gotoXKbLayout" => _("Keyboard layout"),
461 "gotoXKbVariant" => _("Keyboard variant"),
462 "gotoXMouseType" => _("Mouse type"),
463 "gotoXMouseport" => _("Mouse port"),
464 "goFonHardware" => _("Telephone hardware"))
465 ));
466 }
467 }
469 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
470 ?>