340091fdedc5de08054af2fec3aceaf9a404d6a4
1 <?php
3 class workservice 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 var $gotoScannerEnable;
11 /* Generic terminal attributes */
12 var $gotoXMonitor= "";
13 var $gotoXDriver= "";
14 var $gotoXResolution= "";
15 var $gotoXColordepth= "";
16 var $gotoXHsync= "";
17 var $gotoXVsync= "";
18 var $AutoSync = false;
19 var $gotoXKbModel= "";
20 var $gotoXKbLayout= "";
21 var $gotoXKbVariant= "";
22 var $gotoXMouseType= "";
23 var $gotoXMouseport= "";
24 var $gotoScannerClients= "";
25 var $gotoScannerBackend= "";
26 var $goFonHardware= "automatic";
28 /* Needed values and lists */
29 var $ignore_account= TRUE;
30 var $base= "";
31 var $cn= "";
32 var $orig_dn= "";
33 var $XMethods= array();
34 var $XDrivers= array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
35 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv",
36 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
37 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
39 var $XResolutions = array();
41 var $MouseTypes= array();
42 var $MousePorts= array();
43 var $hardware_list= array();
44 var $used_hardware= array();
47 /* attribute list for save action */
48 var $attributes= array("gotoXMonitor",
49 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
50 "gotoXHsync", "gotoXVsync",
51 "gotoScannerEnable", "gotoScannerClients",
52 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
53 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
54 var $objectclasses= array("GOhard");
56 var $XColordepths =array();
57 var $XKbModels =array();
58 var $XKbLayouts =array();
59 var $XKbVariants =array();
61 function workservice ($config, $dn= NULL)
62 {
63 plugin::plugin ($config, $dn);
65 $this->XResolutions= array(
66 "default" => "["._("inherited")."]",
67 "640x480" => "640x480",
68 "800x600" => "800x600",
69 "1024x768" => "1024x768",
70 "1152x864" => "1152x864",
71 "1280x1024" => "1280x1024",
72 "1400x1050" => "1400x1050",
73 "1600x1200" => "1600x1200");
75 if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
76 $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
78 if(is_readable($file)){
79 $str = file_get_contents($file);
80 $lines = split("\n",$str);
81 foreach($lines as $line){
82 $line = trim($line);
83 if(!empty($line)){
84 $this->XResolutions[$line]=$line;
85 }
86 }
87 //natcasesort($this->gotoXResolutions);
88 }else{
89 print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
90 }
91 }
94 array_unshift($this->XDrivers, "["._("unknown")."]");
96 $this->XColordepths= array(
97 "default" => "["._("inherited")."]",
98 "8" => "8 " ._("bit"),
99 "15" => "15 "._("bit"),
100 "16" => "16 "._("bit"),
101 "24" => "24 "._("bit"));
103 $this->XKbModels['default']= "["._("inherited")."]";
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("AUTO" => "["._("inherited")."]", "ImPS/2" =>"ImPS/2",
113 "PS/2" => "PS/2", "Microsoft" =>"Microsoft",
114 "Logitech"=>"Microsoft");
116 $this->MousePorts= array("AUTO" => "["._("inherited")."]", "/dev/ttyS0" =>"/dev/ttyS0",
117 "/dev/ttyS1" => "/dev/ttyS1", "/dev/psaux" =>"/dev/psaux",
118 "/dev/input/mice" => "/dev/input/mice");
120 /* Additional values will be extracted from /etc/gosa/keyboardLayouts */
121 $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
122 $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
124 /* try to read additional keyboard layouts
125 */
126 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
127 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
128 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
129 $tmp = split("\n",$str);
130 foreach($tmp as $entry){
131 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
132 $entry = trim($entry);
133 $tmp2 = split ("\:",$entry);
134 $la = trim($tmp2[0]); // What would be saved to ldap
135 $da = trim($tmp2[1]); // This wis displayed in the listbox
136 $this->XKbLayouts [ $la] = $da;
137 }
138 }
139 }
140 }
142 /* Initialize methods */
143 $this->XMethods["default"]= _("default");
144 $this->XMethods["indirect"]= _("show chooser");
145 $this->XMethods["query"]= _("direct");
146 #$this->XMethods["squery"]= _("direct via ssh");
147 #$this->XMethods["nquery"]= _("direct via nx");
148 $this->XMethods["load"]= _("load balanced");
149 #$this->XMethods["sload"]= _("load balanced via ssh");
150 #$this->XMethods["nload"]= _("load balanced via nx");
151 $this->XMethods["rdp"]= _("Windows RDP");
152 $this->XMethods["citrix"]= _("ICA client");
154 $this->orig_dn= $this->dn;
156 /* Load hardware list */
157 $ldap= $this->config->get_ldap_link();
158 $ldap->cd($this->config->current['BASE']);
159 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
160 while ($attrs= $ldap->fetch()){
161 $cn= $attrs['cn'][0];
162 if (isset($attrs['description'])){
163 $description= " - ".$attrs['description'][0];
164 } else {
165 $description= "";
166 }
167 $this->hardware_list[$cn]= "$cn$description";
168 }
170 /* Eventually colorize phones */
171 $ldap->cd($this->config->current['BASE']);
172 foreach ($this->hardware_list as $cn => $desc){
173 $ldap->search("(goFonHardware=$cn)", array('cn'));
174 if ($ldap->count() > 0){
175 $ldap->fetch();
176 if ($ldap->getDN() != $this->dn){
177 $this->used_hardware[$cn]= $ldap->getDN();
178 }
179 }
180 }
182 if(preg_match("/\+/",$this->gotoXHsync)){
183 $this->AutoSync = true;
184 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
185 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
186 }
188 $this->hardware_list["automatic"]= _("automatic");
189 ksort($this->hardware_list);
190 }
192 function execute()
193 {
194 /* Call parent execute */
195 plugin::execute();
197 /* Do we need to flip is_account state? */
198 if (isset($_POST['modify_state'])){
199 $this->is_account= !$this->is_account;
200 }
202 /* Do we represent a valid terminal? */
203 if (!$this->is_account && $this->parent == NULL){
204 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
205 _("This 'dn' has no terminal features.")."</b>";
206 return ($display);
207 }
209 /* Show main page */
210 $smarty= get_smarty();
212 /* Arrays */
213 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
214 "XKbModels", "XKbVariants",
215 "MouseTypes", "MousePorts") as $val){
216 $smarty->assign("$val", $this->$val);
217 }
218 $smarty->assign("XKbLayouts" ,$this->XKbLayouts);
219 $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
221 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
222 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
223 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
224 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
226 /* Variables - select */
227 foreach(array(
228 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
229 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
230 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
232 $smarty->assign($val."_select", $this->$val);
233 $smarty->assign($val."ACL", chkacl($this->acl, $val));
234 }
236 /* Variables */
237 foreach(array("gotoXHsync", "gotoXVsync") as $val){
238 $smarty->assign($val, $this->$val);
239 $smarty->assign($val."ACL", chkacl($this->acl, $val));
240 }
241 $smarty->assign("staticAddress", "");
243 /* Checkboxes */
244 foreach(array("gotoScannerEnable") as $val){
245 if ($this->$val == TRUE) {
246 $smarty->assign("$val", "checked");
247 } else {
248 $smarty->assign("$val", "");
249 }
250 }
252 /* Phone stuff */
253 $smarty->assign ("goFonHardware", $this->goFonHardware);
254 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
255 _("Choose the phone located at the current terminal")."\" ".
256 chkacl($this->acl, "goFonHardware").">\n";
257 foreach ($this->hardware_list as $cn => $description){
258 if ($cn == $this->goFonHardware){
259 $selected= "selected";
260 } else {
261 $selected= "";
262 }
263 if (isset($this->used_hardware[$cn])){
264 $color= "style=\"color:#A0A0A0\"";
265 } else {
266 $color= "";
267 }
268 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
269 }
270 $hl.= "</select>\n";
271 $smarty->assign ("hardware_list", $hl);
272 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
273 $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
275 if($this->AutoSync){
276 $smarty->assign("AutoSyncCHK"," checked ");
277 }else{
278 $smarty->assign("AutoSyncCHK"," ");
279 }
281 /* Show main page */
282 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
283 }
285 function remove_from_parent()
286 {
287 $this->handle_post_events("remove");
288 }
290 /* Save data to object */
291 function save_object()
292 {
293 plugin::save_object();
295 if(isset($_POST['gotoXHsync'])){
296 if(isset($_POST['AutoSync'])){
297 $this->AutoSync = true;
298 }else{
299 $this->AutoSync = false;
300 }
301 }
302 }
304 /* Check supplied data */
305 function check()
306 {
307 /* Call common method to give check the hook */
308 $message= plugin::check();
310 /* Default entries can use blank hsync/vsync entries */
311 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
313 /* Check vsync for correct usage */
314 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
315 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
316 && chkacl ($this->acl, "gotoXVsync") == ""){
318 $message[]= _("Please specify a valid VSync range.");
319 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
320 list($v1,$v2)= preg_split ("/[-+]/", $val);
321 if ($v2 != ""){
322 if ($v1 > $v2){
323 $message[]= _("Please specify a valid VSync range.");
324 }
325 }
326 }
328 /* Check hsync for correct usage */
329 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
330 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
331 && chkacl ($this->acl, "gotoXHsync") == ""){
333 $message[]= _("Please specify a valid HSync range.");
334 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
335 list($v1,$v2)= preg_split ("/[-+]/", $val);
336 if ($v2 != ""){
337 if ($v1 > $v2){
338 $message[]= _("Please specify a valid HSync range.");
339 }
340 }
341 }
342 }
343 return ($message);
344 }
347 /* Save to LDAP */
348 function save()
349 {
350 /* remove objectclass GOhard if this is an ogroup tab */
351 if(isset($this->parent->by_object['ogroup'])){
352 $this->objectclasses = array();
353 }
355 plugin::save();
357 /* Strip out 'default' values */
358 foreach(array(
359 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
360 "gotoXKbModel", "gotoXKbLayout",
361 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
363 if ($this->attrs[$val] == "default"){
364 $this->attrs[$val]= array();
365 }
366 }
368 if($this->AutoSync){
369 $this->attrs['gotoXHsync'] = preg_replace("/-/","+",$this->attrs['gotoXHsync']) ;
370 $this->attrs['gotoXVsync'] = preg_replace("/-/","+",$this->attrs['gotoXVsync']) ;
371 }
373 /* Write back to ldap */
374 $ldap= $this->config->get_ldap_link();
375 $ldap->cd($this->dn);
376 $this->cleanup();
377 $ldap->modify ($this->attrs);
379 show_ldap_error($ldap->get_error(), _("Saving workstation services failed"));
380 $this->handle_post_events("modify");
381 }
383 }
385 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
386 ?>