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