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("AUTO", "ImPS/2", "PS/2", "Microsoft", "Logitech");
49 var $MousePorts= array("AUTO", "/dev/ttyS0", "/dev/ttyS1", "/dev/psaux", "/dev/input/mice");
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)
66 {
67 plugin::plugin ($config, $dn);
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 $this->XColordepths= array(
82 "default" => _("inherited"),
83 "8" => "8 " ._("bit"),
84 "15" => "15 "._("bit"),
85 "16" => "16 "._("bit"),
86 "24" => "24 "._("bit"));
88 $this->XKbModels['default']= _("inherited");
89 foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
90 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
91 "logiinetnav", "logiinternet", "macintosh", "microsoft",
92 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
93 "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
94 $this->XKbModels[$type] = $type;
95 }
97 /* Additional values will be extracted from /etc/gosa/keyboardLayouts */
98 $this->XKbLayouts= array ("default"=>_("inherited"),"de"=> "de","intl" =>"intl","us" =>"us");
99 $this->XKbVariants= array ("default"=>_("inherited"), "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
101 /* try to read additional keyboard layouts
102 */
103 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
104 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
105 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
106 $tmp = split("\n",$str);
107 foreach($tmp as $entry){
108 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
109 $entry = trim($entry);
110 $tmp2 = split ("\:",$entry);
111 $la = trim($tmp2[0]); // What would be saved to ldap
112 $da = trim($tmp2[1]); // This wis displayed in the listbox
113 $this->XKbLayouts [ $la] = $da;
114 }
115 }
116 }
117 }
119 /* Load scanner models */
120 $fcontents = file ($this->config->basedir."/include/scanner.inc");
121 while (list ($line_num, $line) = each ($fcontents)) {
122 preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
123 $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
124 }
125 ksort ($this->gotoScannerModels);
127 /* Initialize methods */
128 $this->XMethods["default"]= _("default");
129 $this->XMethods["indirect"]= _("show chooser");
130 $this->XMethods["query"]= _("direct");
131 #$this->XMethods["squery"]= _("direct via ssh");
132 #$this->XMethods["nquery"]= _("direct via nx");
133 $this->XMethods["load"]= _("load balanced");
134 #$this->XMethods["sload"]= _("load balanced via ssh");
135 #$this->XMethods["nload"]= _("load balanced via nx");
136 $this->XMethods["rdp"]= _("Windows RDP");
137 $this->XMethods["citrix"]= _("ICA client");
139 $this->orig_dn= $this->dn;
141 /* Load hardware list */
142 $ldap= $this->config->get_ldap_link();
143 $ldap->cd($this->config->current['BASE']);
144 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
145 while ($attrs= $ldap->fetch()){
146 $cn= $attrs['cn'][0];
147 if (isset($attrs['description'])){
148 $description= " - ".$attrs['description'][0];
149 } else {
150 $description= "";
151 }
152 $this->hardware_list[$cn]= "$cn$description";
153 }
155 /* Eventually colorize phones */
156 $ldap->cd($this->config->current['BASE']);
157 foreach ($this->hardware_list as $cn => $desc){
158 $ldap->search("(goFonHardware=$cn)", array('cn'));
159 if ($ldap->count() > 0){
160 $ldap->fetch();
161 if ($ldap->getDN() != $this->dn){
162 $this->used_hardware[$cn]= $ldap->getDN();
163 }
164 }
165 }
167 $this->hardware_list["automatic"]= _("automatic");
168 ksort($this->hardware_list);
169 }
171 function execute()
172 {
173 /* Call parent execute */
174 plugin::execute();
176 /* Do we need to flip is_account state? */
177 if (isset($_POST['modify_state'])){
178 $this->is_account= !$this->is_account;
179 }
181 /* Do we represent a valid terminal? */
182 if (!$this->is_account && $this->parent == NULL){
183 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
184 _("This 'dn' has no terminal features.")."</b>";
185 return ($display);
186 }
188 /* Show main page */
189 $smarty= get_smarty();
191 /* Arrays */
192 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
193 "gotoScannerModels", "XKbModels","XKbVariants",
194 "MouseTypes", "MousePorts") as $val){
195 $smarty->assign("$val", $this->$val);
196 }
197 $smarty->assign("XKbLayouts", $this->XKbLayouts);
198 $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
200 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
201 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
202 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
203 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
205 /* Variables - select */
206 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
207 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
208 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
209 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
211 $smarty->assign($val."_select", $this->$val);
212 $smarty->assign($val."ACL", chkacl($this->acl, $val));
213 }
215 /* Variables */
216 foreach(array("gotoXHsync", "gotoXVsync") as $val){
217 $smarty->assign($val, $this->$val);
218 $smarty->assign($val."ACL", chkacl($this->acl, $val));
219 }
220 $smarty->assign("staticAddress", "");
222 /* Checkboxes */
223 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
224 if ($this->$val == TRUE) {
225 $smarty->assign("$val", "checked");
226 } else {
227 $smarty->assign("$val", "");
228 }
229 $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
230 }
232 /* Phone stuff */
233 $smarty->assign ("goFonHardware", $this->goFonHardware);
234 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
235 _("Choose the phone located at the current terminal")."\" ".
236 chkacl($this->acl, "goFonHardware").">\n";
237 foreach ($this->hardware_list as $cn => $description){
238 if ($cn == $this->goFonHardware){
239 $selected= "selected";
240 } else {
241 $selected= "";
242 }
243 if (isset($this->used_hardware[$cn])){
244 $color= "style=\"color:#A0A0A0\"";
245 } else {
246 $color= "";
247 }
248 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
249 }
250 $hl.= "</select>\n";
251 $smarty->assign ("hardware_list", $hl);
252 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
254 /* Show main page */
255 return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
256 }
258 function remove_from_parent()
259 {
260 $this->handle_post_events("remove");
261 }
264 /* Save data to object */
265 function save_object()
266 {
267 plugin::save_object();
269 /* Save checkbox state */
270 if (isset ($_POST['gotoXMethod'])){
271 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
273 if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
274 $this->$val= FALSE;
275 } else {
276 $this->$val= TRUE;
277 }
278 }
279 }
280 }
283 /* Check supplied data */
284 function check()
285 {
286 /* Call common method to give check the hook */
287 $message= plugin::check();
289 /* Default entries can use blank hsync/vsync entries */
290 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
292 /* Check vsync for correct usage */
293 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
294 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
295 && chkacl ($this->acl, "gotoXVsync") == ""){
297 $message[]= _("Please specify a valid VSync range.");
298 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
299 list($v1,$v2)= split ("-", $val);
300 if ($v2 != ""){
301 if ($v1 > $v2){
302 $message[]= _("Please specify a valid VSync range.");
303 }
304 }
305 }
307 /* Check hsync for correct usage */
308 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
309 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
310 && chkacl ($this->acl, "gotoXHsync") == ""){
312 $message[]= _("Please specify a valid HSync range.");
313 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
314 list($v1,$v2)= split ("-", $val);
315 if ($v2 != ""){
316 if ($v1 > $v2){
317 $message[]= _("Please specify a valid HSync range.");
318 }
319 }
320 }
321 }
322 return ($message);
323 }
326 /* Save to LDAP */
327 function save()
328 {
329 plugin::save();
331 /* Strip out 'default' values */
332 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
333 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
334 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
335 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
337 if ($this->attrs[$val] == "default"){
338 $this->attrs[$val]= array();
339 }
340 }
342 /* Write back to ldap */
343 $ldap= $this->config->get_ldap_link();
344 $ldap->cd($this->dn);
345 $this->cleanup();
346 $ldap->modify ($this->attrs);
348 show_ldap_error($ldap->get_error(), _("Saving terminal service information failed"));
349 $this->handle_post_events("modify");
350 }
352 }
354 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
355 ?>