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