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 /* Call parent execute */
114 plugin::execute();
116 /* Do we need to flip is_account state? */
117 if (isset($_POST['modify_state'])){
118 $this->is_account= !$this->is_account;
119 }
121 /* Do we represent a valid terminal? */
122 if (!$this->is_account && $this->parent == NULL){
123 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
124 _("This 'dn' has no terminal features.")."</b>";
125 return ($display);
126 }
128 /* Show main page */
129 $smarty= get_smarty();
131 /* Arrays */
132 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
133 "XKbModels", "XKbLayouts", "XKbVariants",
134 "MouseTypes", "MousePorts") as $val){
135 $smarty->assign("$val", $this->$val);
136 }
137 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
138 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
139 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
140 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
142 /* Variables - select */
143 foreach(array(
144 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
145 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
146 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
148 $smarty->assign($val."_select", $this->$val);
149 $smarty->assign($val."ACL", chkacl($this->acl, $val));
150 }
152 /* Variables */
153 foreach(array("gotoXHsync", "gotoXVsync") as $val){
154 $smarty->assign($val, $this->$val);
155 $smarty->assign($val."ACL", chkacl($this->acl, $val));
156 }
157 $smarty->assign("staticAddress", "");
159 /* Checkboxes */
160 foreach(array("gotoScannerEnable") as $val){
161 if ($this->$val == TRUE) {
162 $smarty->assign("$val", "checked");
163 } else {
164 $smarty->assign("$val", "");
165 }
166 }
168 /* Phone stuff */
169 $smarty->assign ("goFonHardware", $this->goFonHardware);
170 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
171 _("Choose the phone located at the current terminal")."\" ".
172 chkacl($this->acl, "goFonHardware").">\n";
173 foreach ($this->hardware_list as $cn => $description){
174 if ($cn == $this->goFonHardware){
175 $selected= "selected";
176 } else {
177 $selected= "";
178 }
179 if (isset($this->used_hardware[$cn])){
180 $color= "style=\"color:#A0A0A0\"";
181 } else {
182 $color= "";
183 }
184 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
185 }
186 $hl.= "</select>\n";
187 $smarty->assign ("hardware_list", $hl);
188 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
190 /* Show main page */
191 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
192 }
194 function remove_from_parent()
195 {
196 $this->handle_post_events("remove");
197 }
200 /* Save data to object */
201 function save_object()
202 {
203 plugin::save_object();
205 }
208 /* Check supplied data */
209 function check()
210 {
211 $message= array();
213 /* Default entries can use blank hsync/vsync entries */
214 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
216 /* Check vsync for correct usage */
217 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
218 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
219 && chkacl ($this->acl, "gotoXVsync") == ""){
221 $message[]= _("Please specify a valid VSync range.");
222 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
223 list($v1,$v2)= split ("-", $val);
224 if ($v2 != ""){
225 if ($v1 > $v2){
226 $message[]= _("Please specify a valid VSync range.");
227 }
228 }
229 }
231 /* Check hsync for correct usage */
232 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
233 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
234 && chkacl ($this->acl, "gotoXHsync") == ""){
236 $message[]= _("Please specify a valid HSync range.");
237 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
238 list($v1,$v2)= split ("-", $val);
239 if ($v2 != ""){
240 if ($v1 > $v2){
241 $message[]= _("Please specify a valid HSync range.");
242 }
243 }
244 }
245 }
246 return ($message);
247 }
250 /* Save to LDAP */
251 function save()
252 {
253 plugin::save();
255 /* Strip out 'default' values */
256 foreach(array(
257 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
258 "gotoXKbModel", "gotoXKbLayout",
259 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
261 if ($this->attrs[$val] == "default"){
262 $this->attrs[$val]= array();
263 }
264 }
266 /* Write back to ldap */
267 $ldap= $this->config->get_ldap_link();
268 $ldap->cd($this->dn);
269 $ldap->modify($this->attrs);
270 show_ldap_error($ldap->get_error());
271 $this->handle_post_events("modify");
272 }
274 }
276 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
277 ?>