2779986921f66762e73301db26a4224c31ede072
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= ($this->gotoLpdEnable == "yes");
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 /* Arrays */
262 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
263 "gotoScannerModels", "XKbModels","XKbVariants",
264 "MouseTypes", "MousePorts") as $val){
265 $smarty->assign("$val", $this->$val);
266 }
267 $smarty->assign("XKbLayouts", $this->XKbLayouts);
268 $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
270 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
271 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
272 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
273 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
275 /* Variables - select */
276 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
277 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
278 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
279 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
281 $smarty->assign($val."_select", $this->$val);
282 $smarty->assign($val."ACL", chkacl($this->acl, $val));
283 }
285 /* Variables */
286 foreach(array("gotoXHsync", "gotoXVsync") as $val){
287 $smarty->assign($val, $this->$val);
288 $smarty->assign($val."ACL", chkacl($this->acl, $val));
289 }
290 $smarty->assign("staticAddress", "");
292 /* Checkboxes */
293 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
294 if ($this->$val == TRUE) {
295 $smarty->assign("$val", "checked");
296 } else {
297 $smarty->assign("$val", "");
298 }
299 $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
300 }
302 /* Phone stuff */
303 $smarty->assign ("goFonHardware", $this->goFonHardware);
304 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
305 _("Choose the phone located at the current terminal")."\" ".
306 chkacl($this->acl, "goFonHardware").">\n";
307 foreach ($this->hardware_list as $cn => $description){
308 if ($cn == $this->goFonHardware){
309 $selected= "selected";
310 } else {
311 $selected= "";
312 }
313 if (isset($this->used_hardware[$cn])){
314 $color= "style=\"color:#A0A0A0\"";
315 } else {
316 $color= "";
317 }
318 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
319 }
320 $hl.= "</select>\n";
321 $smarty->assign ("hardware_list", $hl);
322 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
324 /* Show main page */
325 return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
326 }
328 function remove_from_parent()
329 {
330 $this->handle_post_events("remove");
331 }
334 /* Save data to object */
335 function save_object()
336 {
337 plugin::save_object();
339 /* Save checkbox state */
340 if (isset ($_POST['gotoXMethod'])){
341 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
343 if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
344 $this->$val= FALSE;
345 } else {
346 $this->$val= TRUE;
347 }
348 }
349 }
350 }
353 /* Check supplied data */
354 function check()
355 {
356 /* Call common method to give check the hook */
357 $message= plugin::check();
359 /* Default entries can use blank hsync/vsync entries */
360 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
362 /* Check vsync for correct usage */
363 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
364 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
365 && chkacl ($this->acl, "gotoXVsync") == ""){
367 $message[]= _("Please specify a valid VSync range.");
368 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
369 list($v1,$v2)= split ("-", $val);
370 if ($v2 != ""){
371 if ($v1 > $v2){
372 $message[]= _("Please specify a valid VSync range.");
373 }
374 }
375 }
377 /* Check hsync for correct usage */
378 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
379 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
380 && chkacl ($this->acl, "gotoXHsync") == ""){
382 $message[]= _("Please specify a valid HSync range.");
383 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
384 list($v1,$v2)= split ("-", $val);
385 if ($v2 != ""){
386 if ($v1 > $v2){
387 $message[]= _("Please specify a valid HSync range.");
388 }
389 }
390 }
391 }
392 return ($message);
393 }
396 /* Save to LDAP */
397 function save()
398 {
399 plugin::save();
401 /* Strip out 'default' values */
402 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
403 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
404 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
405 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
407 if ($this->attrs[$val] == "default"){
408 $this->attrs[$val]= array();
409 }
410 }
412 /* Convert to string */
413 $this->gotoLpdEnable= $this->gotoLpdEnable?"yes":"no";
415 /* Write back to ldap */
416 $ldap= $this->config->get_ldap_link();
417 $ldap->cd($this->dn);
418 $this->cleanup();
419 $ldap->modify ($this->attrs);
421 show_ldap_error($ldap->get_error(), _("Saving terminal service information failed"));
422 $this->handle_post_events("modify");
423 }
425 }
427 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
428 ?>