41ae7b4e6640740e34daa04f3ed5cf01c49b7181
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");
38 var $XResolutions= array("default", "640x480", "800x600", "1024x768", "1152x864", "1280x1024",
39 "1400x1050", "1600x1200");
40 var $XColordepths= array("default", "8", "15", "16", "24");
41 var $XKbModels= array ("default", "btc9000", "chicony", "compaq", "dell", "dell101", "everex",
42 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
43 "logiinetnav", "logiinternet", "macintosh", "microsoft",
44 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
45 "pc105", "rapidaccess", "rapidaccess2", "winbook");
47 /* Additional values will be extracted from /etc/gosa/keyboardLayouts */
48 var $XKbLayouts= array ("default"=>"default","de"=> "de","intl" =>"intl","us" =>"us");
49 var $XKbVariants= array ("default", "nodeadkeys", "basic");
50 var $MouseTypes= array("AUTO", "ImPS/2", "PS/2", "Microsoft", "Logitech");
51 var $MousePorts= array("AUTO", "/dev/ttyS0", "/dev/ttyS1", "/dev/psaux", "/dev/input/mice");
52 var $hardware_list= array();
53 var $used_hardware= array();
56 /* attribute list for save action */
57 var $attributes= array("gotoXMonitor",
58 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
59 "gotoXHsync", "gotoXVsync",
60 "gotoScannerEnable", "gotoScannerClients",
61 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
62 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
63 var $objectclasses= array("GOhard");
65 function workservice ($config, $dn= NULL)
66 {
67 plugin::plugin ($config, $dn);
69 /* try to read additional keyboard layouts
70 */
71 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
72 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
73 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
74 $tmp = split("\n",$str);
75 foreach($tmp as $entry){
76 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
77 $entry = trim($entry);
78 $tmp2 = split ("\:",$entry);
79 $la = trim($tmp2[0]); // What would be saved to ldap
80 $da = trim($tmp2[1]); // This wis displayed in the listbox
81 $this->XKbLayouts [ $la] = $da;
82 }
83 }
84 }
85 }
87 /* Initialize methods */
88 $this->XMethods["default"]= _("default");
89 $this->XMethods["indirect"]= _("show chooser");
90 $this->XMethods["query"]= _("direct");
91 #$this->XMethods["squery"]= _("direct via ssh");
92 #$this->XMethods["nquery"]= _("direct via nx");
93 $this->XMethods["load"]= _("load balanced");
94 #$this->XMethods["sload"]= _("load balanced via ssh");
95 #$this->XMethods["nload"]= _("load balanced via nx");
96 $this->XMethods["rdp"]= _("Windows RDP");
97 $this->XMethods["citrix"]= _("ICA client");
99 $this->orig_dn= $this->dn;
101 /* Load hardware list */
102 $ldap= $this->config->get_ldap_link();
103 $ldap->cd($this->config->current['BASE']);
104 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
105 while ($attrs= $ldap->fetch()){
106 $cn= $attrs['cn'][0];
107 if (isset($attrs['description'])){
108 $description= " - ".$attrs['description'][0];
109 } else {
110 $description= "";
111 }
112 $this->hardware_list[$cn]= "$cn$description";
113 }
115 /* Eventually colorize phones */
116 $ldap->cd($this->config->current['BASE']);
117 foreach ($this->hardware_list as $cn => $desc){
118 $ldap->search("(goFonHardware=$cn)", array('cn'));
119 if ($ldap->count() > 0){
120 $ldap->fetch();
121 if ($ldap->getDN() != $this->dn){
122 $this->used_hardware[$cn]= $ldap->getDN();
123 }
124 }
125 }
127 if(preg_match("/\+/",$this->gotoXHsync)){
128 $this->AutoSync = true;
129 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
130 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
131 }
133 $this->hardware_list["automatic"]= _("automatic");
134 ksort($this->hardware_list);
135 }
137 function execute()
138 {
139 /* Call parent execute */
140 plugin::execute();
142 /* Do we need to flip is_account state? */
143 if (isset($_POST['modify_state'])){
144 $this->is_account= !$this->is_account;
145 }
147 /* Do we represent a valid terminal? */
148 if (!$this->is_account && $this->parent == NULL){
149 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
150 _("This 'dn' has no terminal features.")."</b>";
151 return ($display);
152 }
154 /* Show main page */
155 $smarty= get_smarty();
157 /* Arrays */
158 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
159 "XKbModels", "XKbVariants",
160 "MouseTypes", "MousePorts") as $val){
161 $smarty->assign("$val", $this->$val);
162 }
163 $smarty->assign("XKbLayouts" ,$this->XKbLayouts);
164 $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
166 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
167 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
168 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
169 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
171 /* Variables - select */
172 foreach(array(
173 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
174 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
175 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
177 $smarty->assign($val."_select", $this->$val);
178 $smarty->assign($val."ACL", chkacl($this->acl, $val));
179 }
181 /* Variables */
182 foreach(array("gotoXHsync", "gotoXVsync") as $val){
183 $smarty->assign($val, $this->$val);
184 $smarty->assign($val."ACL", chkacl($this->acl, $val));
185 }
186 $smarty->assign("staticAddress", "");
188 /* Checkboxes */
189 foreach(array("gotoScannerEnable") as $val){
190 if ($this->$val == TRUE) {
191 $smarty->assign("$val", "checked");
192 } else {
193 $smarty->assign("$val", "");
194 }
195 }
197 /* Phone stuff */
198 $smarty->assign ("goFonHardware", $this->goFonHardware);
199 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
200 _("Choose the phone located at the current terminal")."\" ".
201 chkacl($this->acl, "goFonHardware").">\n";
202 foreach ($this->hardware_list as $cn => $description){
203 if ($cn == $this->goFonHardware){
204 $selected= "selected";
205 } else {
206 $selected= "";
207 }
208 if (isset($this->used_hardware[$cn])){
209 $color= "style=\"color:#A0A0A0\"";
210 } else {
211 $color= "";
212 }
213 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
214 }
215 $hl.= "</select>\n";
216 $smarty->assign ("hardware_list", $hl);
217 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
218 $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
220 if($this->AutoSync){
221 $smarty->assign("AutoSyncCHK"," checked ");
222 }else{
223 $smarty->assign("AutoSyncCHK"," ");
224 }
226 /* Show main page */
227 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
228 }
230 function remove_from_parent()
231 {
232 $this->handle_post_events("remove");
233 }
235 /* Save data to object */
236 function save_object()
237 {
238 plugin::save_object();
240 if(isset($_POST['gotoXHsync'])){
241 if(isset($_POST['AutoSync'])){
242 $this->AutoSync = true;
243 }else{
244 $this->AutoSync = false;
245 }
246 }
247 }
249 /* Check supplied data */
250 function check()
251 {
252 /* Call common method to give check the hook */
253 $message= plugin::check();
255 /* Default entries can use blank hsync/vsync entries */
256 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
258 /* Check vsync for correct usage */
259 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
260 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
261 && chkacl ($this->acl, "gotoXVsync") == ""){
263 $message[]= _("Please specify a valid VSync range.");
264 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
265 list($v1,$v2)= preg_split ("/[-+]/", $val);
266 if ($v2 != ""){
267 if ($v1 > $v2){
268 $message[]= _("Please specify a valid VSync range.");
269 }
270 }
271 }
273 /* Check hsync for correct usage */
274 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
275 if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
276 && chkacl ($this->acl, "gotoXHsync") == ""){
278 $message[]= _("Please specify a valid HSync range.");
279 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
280 list($v1,$v2)= preg_split ("/[-+]/", $val);
281 if ($v2 != ""){
282 if ($v1 > $v2){
283 $message[]= _("Please specify a valid HSync range.");
284 }
285 }
286 }
287 }
288 return ($message);
289 }
292 /* Save to LDAP */
293 function save()
294 {
295 /* remove objectclass GOhard if this is an ogroup tab */
296 if(isset($this->parent->by_object['ogroup'])){
297 $this->objectclasses = array();
298 }
300 plugin::save();
302 /* Strip out 'default' values */
303 foreach(array(
304 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
305 "gotoXKbModel", "gotoXKbLayout",
306 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
308 if ($this->attrs[$val] == "default"){
309 $this->attrs[$val]= array();
310 }
311 }
313 if($this->AutoSync){
314 $this->attrs['gotoXHsync'] = preg_replace("/-/","+",$this->attrs['gotoXHsync']) ;
315 $this->attrs['gotoXVsync'] = preg_replace("/-/","+",$this->attrs['gotoXVsync']) ;
316 }
318 /* Write back to ldap */
319 $ldap= $this->config->get_ldap_link();
320 $ldap->cd($this->dn);
321 $this->cleanup();
322 $ldap->modify ($this->attrs);
324 show_ldap_error($ldap->get_error());
325 $this->handle_post_events("modify");
326 }
328 }
330 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
331 ?>