495e8dd370420f980d3e8dcc70670cfbf40259d5
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 $gotoXKbModel= "";
19 var $gotoXKbLayout= "";
20 var $gotoXKbVariant= "";
21 var $gotoXMouseType= "";
22 var $gotoXMouseport= "";
23 var $gotoScannerClients= "";
24 var $gotoScannerBackend= "";
25 var $goFonHardware= "automatic";
27 /* Needed values and lists */
28 var $ignore_account= TRUE;
29 var $base= "";
30 var $cn= "";
31 var $orig_dn= "";
32 var $XMethods= array();
33 var $XDrivers= array("unknown", "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
34 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv",
35 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
36 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga");
37 var $XResolutions= array("default", "640x480", "800x600", "1024x768", "1152x864", "1280x1024",
38 "1400x1050", "1600x1200");
39 var $XColordepths= array("default", "8", "15", "16", "24");
40 var $XKbModels= array ("default", "btc9000", "chicony", "compaq", "dell", "dell101", "everex",
41 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
42 "logiinetnav", "logiinternet", "macintosh", "microsoft",
43 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
44 "pc105", "rapidaccess", "rapidaccess2", "winbook");
45 var $XKbLayouts= array ("default", "de", "intl", "us");
46 var $XKbVariants= array ("default", "nodeadkeys", "basic");
47 var $MouseTypes= array("AUTO", "ImPS/2", "PS/2", "Microsoft", "Logitech");
48 var $MousePorts= array("AUTO", "/dev/ttyS0", "/dev/ttyS1", "/dev/psaux", "/dev/input/mice");
49 var $hardware_list= array();
50 var $used_hardware= array();
53 /* attribute list for save action */
54 var $attributes= array("gotoXMonitor",
55 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
56 "gotoXHsync", "gotoXVsync",
57 "gotoScannerEnable", "gotoScannerClients",
58 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
59 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
60 var $objectclasses= array("GOhard");
63 function workservice ($config, $dn= NULL)
64 {
65 plugin::plugin ($config, $dn);
67 /* Initialize methods */
68 $this->XMethods["default"]= _("default");
69 $this->XMethods["indirect"]= _("show chooser");
70 $this->XMethods["query"]= _("direct");
71 #$this->XMethods["squery"]= _("direct via ssh");
72 #$this->XMethods["nquery"]= _("direct via nx");
73 $this->XMethods["load"]= _("load balanced");
74 #$this->XMethods["sload"]= _("load balanced via ssh");
75 #$this->XMethods["nload"]= _("load balanced via nx");
76 $this->XMethods["rdp"]= _("Windows RDP");
77 $this->XMethods["citrix"]= _("ICA client");
79 $this->orig_dn= $this->dn;
81 /* Load hardware list */
82 $ldap= $this->config->get_ldap_link();
83 $ldap->cd($this->config->current['BASE']);
84 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
85 while ($attrs= $ldap->fetch()){
86 $cn= $attrs['cn'][0];
87 if (isset($attrs['description'])){
88 $description= " - ".$attrs['description'][0];
89 } else {
90 $description= "";
91 }
92 $this->hardware_list[$cn]= "$cn$description";
93 }
95 /* Eventually colorize phones */
96 $ldap->cd($this->config->current['BASE']);
97 foreach ($this->hardware_list as $cn => $desc){
98 $ldap->search("(goFonHardware=$cn)", array('cn'));
99 if ($ldap->count() > 0){
100 $ldap->fetch();
101 if ($ldap->getDN() != $this->dn){
102 $this->used_hardware[$cn]= $ldap->getDN();
103 }
104 }
105 }
107 $this->hardware_list["automatic"]= _("automatic");
108 ksort($this->hardware_list);
109 }
111 function execute()
112 {
113 /* Do we need to flip is_account state? */
114 if (isset($_POST['modify_state'])){
115 $this->is_account= !$this->is_account;
116 }
118 /* Do we represent a valid terminal? */
119 if (!$this->is_account && $this->parent == NULL){
120 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
121 _("This 'dn' has no terminal features.")."</b>";
122 return ($display);
123 }
125 /* Show main page */
126 $smarty= get_smarty();
128 /* Arrays */
129 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
130 "XKbModels", "XKbLayouts", "XKbVariants",
131 "MouseTypes", "MousePorts") as $val){
132 $smarty->assign("$val", $this->$val);
133 }
134 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
135 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
136 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
137 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
139 /* Variables - select */
140 foreach(array(
141 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
142 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
143 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
145 $smarty->assign($val."_select", $this->$val);
146 $smarty->assign($val."ACL", chkacl($this->acl, $val));
147 }
149 /* Variables */
150 foreach(array("gotoXHsync", "gotoXVsync") as $val){
151 $smarty->assign($val, $this->$val);
152 $smarty->assign($val."ACL", chkacl($this->acl, $val));
153 }
154 $smarty->assign("staticAddress", "");
156 /* Checkboxes */
157 foreach(array("gotoScannerEnable") as $val){
158 if ($this->$val == TRUE) {
159 $smarty->assign("$val", "checked");
160 } else {
161 $smarty->assign("$val", "");
162 }
163 }
165 /* Phone stuff */
166 $smarty->assign ("goFonHardware", $this->goFonHardware);
167 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
168 _("Choose the phone located at the current terminal")."\" ".
169 chkacl($this->acl, "goFonHardware").">\n";
170 foreach ($this->hardware_list as $cn => $description){
171 if ($cn == $this->goFonHardware){
172 $selected= "selected";
173 } else {
174 $selected= "";
175 }
176 if (isset($this->used_hardware[$cn])){
177 $color= "style=\"color:#A0A0A0\"";
178 } else {
179 $color= "";
180 }
181 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
182 }
183 $hl.= "</select>\n";
184 $smarty->assign ("hardware_list", $hl);
185 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
187 /* Show main page */
188 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
189 }
191 function remove_from_parent()
192 {
193 /* This is not necessary, i think
194 * Remove should be called from workGeneric ...
195 */
196 /*$ldap= $this->config->get_ldap_link();
197 $ldap->rmdir($this->dn);
198 show_ldap_error($ldap->get_error());
199 $this->handle_post_events("remove");
200 */
202 /* This only removes the attributes from this tab,
203 * and not hte whole entry
204 */
205 $ldap= $this->config->get_ldap_link();
206 plugin::remove_from_parent();
207 $ldap->cd($this->dn);
208 $ldap->modify($this->attrs);
209 show_ldap_error($ldap->get_error());}
212 /* Save data to object */
213 function save_object()
214 {
215 plugin::save_object();
217 }
220 /* Check supplied data */
221 function check()
222 {
223 $message= array();
225 /* Default entries can use blank hsync/vsync entries */
226 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
228 /* Check vsync for correct usage */
229 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
230 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
231 && chkacl ($this->acl, "gotoXVsync") == ""){
233 $message[]= _("Please specify a valid VSync range.");
234 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
235 list($v1,$v2)= split ("-", $val);
236 if ($v2 != ""){
237 if ($v1 > $v2){
238 $message[]= _("Please specify a valid VSync range.");
239 }
240 }
241 }
243 /* Check hsync for correct usage */
244 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
245 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
246 && chkacl ($this->acl, "gotoXHsync") == ""){
248 $message[]= _("Please specify a valid HSync range.");
249 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
250 list($v1,$v2)= split ("-", $val);
251 if ($v2 != ""){
252 if ($v1 > $v2){
253 $message[]= _("Please specify a valid HSync range.");
254 }
255 }
256 }
257 }
258 return ($message);
259 }
262 /* Save to LDAP */
263 function save()
264 {
265 plugin::save();
267 /* Strip out 'default' values */
268 foreach(array(
269 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
270 "gotoXKbModel", "gotoXKbLayout",
271 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
273 if ($this->attrs[$val] == "default"){
274 $this->attrs[$val]= array();
275 }
276 }
278 /* Write back to ldap */
279 $ldap= $this->config->get_ldap_link();
280 $ldap->cd($this->dn);
281 $ldap->modify($this->attrs);
282 show_ldap_error($ldap->get_error());
283 $this->handle_post_events("modify");
284 }
286 }
288 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
289 ?>