1 <?php
3 class termservice 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 /* Generic terminal attributes */
11 var $gotoLpdEnable= FALSE;
12 var $gotoXMonitor= "";
13 var $gotoXMethod= "";
14 var $gotoXdmcpServer= "";
15 var $gotoFontPath= "";
16 var $gotoXDriver= "";
17 var $gotoXResolution= "";
18 var $gotoXColordepth= "";
19 var $gotoXHsync= "";
20 var $gotoXVsync= "";
21 var $gotoXKbModel= "";
22 var $gotoXKbLayout= "";
23 var $gotoXKbVariant= "";
24 var $gotoXMouseType= "";
25 var $gotoXMouseport= "";
26 var $gotoLpdServer= "";
27 var $gotoScannerEnable= "";
28 var $gotoScannerModel= "";
29 var $gotoScannerClients= "";
30 var $gotoScannerBackend= "";
31 var $goFonHardware= "automatic";
33 /* Needed values and lists */
34 var $ignore_account= TRUE;
35 var $base= "";
36 var $cn= "";
37 var $orig_dn= "";
38 var $XMethods= array();
39 var $XDrivers= array("unknown", "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
40 "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc", "nv",
41 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
42 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga");
43 var $XResolutions= array("default", "640x480", "800x600", "1024x768", "1152x864", "1280x1024",
44 "1400x1050", "1600x1200");
45 var $XColordepths= array("default", "8", "15", "16", "24");
46 var $XKbModels= array ("default", "btc9000", "chicony", "compaq", "dell", "dell101", "everex",
47 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
48 "logiinetnav", "logiinternet", "macintosh", "microsoft",
49 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
50 "pc105", "rapidaccess", "rapidaccess2", "winbook");
51 var $XKbLayouts= array ("default", "de", "intl", "us");
52 var $XKbVariants= array ("default", "nodeadkeys", "basic");
53 var $MouseTypes= array("AUTO", "ImPS/2", "PS/2", "Microsoft", "Logitech");
54 var $MousePorts= array("AUTO", "/dev/ttyS0", "/dev/ttyS1", "/dev/psaux", "/dev/input/mice");
55 var $gotoScannerModels= array();
56 var $hardware_list= array();
57 var $used_hardware= array();
60 /* attribute list for save action */
61 var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
62 "gotoFontPath", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
63 "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
64 "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
65 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
66 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
67 var $objectclasses= array("GOhard");
70 function termservice ($config, $dn= NULL)
71 {
72 plugin::plugin ($config, $dn);
74 /* Load scanner models */
75 $fcontents = file ($this->config->basedir."/include/scanner.inc");
76 while (list ($line_num, $line) = each ($fcontents)) {
77 preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
78 $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
79 }
80 ksort ($this->gotoScannerModels);
82 /* Initialize methods */
83 $this->XMethods["default"]= _("default");
84 $this->XMethods["indirect"]= _("show chooser");
85 $this->XMethods["query"]= _("direct");
86 #$this->XMethods["squery"]= _("direct via ssh");
87 #$this->XMethods["nquery"]= _("direct via nx");
88 $this->XMethods["load"]= _("load balanced");
89 #$this->XMethods["sload"]= _("load balanced via ssh");
90 #$this->XMethods["nload"]= _("load balanced via nx");
91 $this->XMethods["rdp"]= _("Windows RDP");
92 $this->XMethods["citrix"]= _("ICA client");
94 $this->orig_dn= $this->dn;
96 /* Load hardware list */
97 $ldap= $this->config->get_ldap_link();
98 $ldap->cd($this->config->current['BASE']);
99 $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
100 while ($attrs= $ldap->fetch()){
101 $cn= $attrs['cn'][0];
102 if (isset($attrs['description'])){
103 $description= " - ".$attrs['description'][0];
104 } else {
105 $description= "";
106 }
107 $this->hardware_list[$cn]= "$cn$description";
108 }
110 /* Eventually colorize phones */
111 $ldap->cd($this->config->current['BASE']);
112 foreach ($this->hardware_list as $cn => $desc){
113 $ldap->search("(goFonHardware=$cn)", array('cn'));
114 if ($ldap->count() > 0){
115 $ldap->fetch();
116 if ($ldap->getDN() != $this->dn){
117 $this->used_hardware[$cn]= $ldap->getDN();
118 }
119 }
120 }
122 $this->hardware_list["automatic"]= _("automatic");
123 ksort($this->hardware_list);
124 }
126 function execute()
127 {
128 /* Call parent execute */
129 plugin::execute();
131 /* Do we need to flip is_account state? */
132 if (isset($_POST['modify_state'])){
133 $this->is_account= !$this->is_account;
134 }
136 /* Do we represent a valid terminal? */
137 if (!$this->is_account && $this->parent == NULL){
138 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
139 _("This 'dn' has no terminal features.")."</b>";
140 return ($display);
141 }
143 /* Show main page */
144 $smarty= get_smarty();
146 /* Arrays */
147 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
148 "gotoScannerModels", "XKbModels", "XKbLayouts", "XKbVariants",
149 "MouseTypes", "MousePorts") as $val){
150 $smarty->assign("$val", $this->$val);
151 }
152 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
153 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
154 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
155 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
157 /* Variables - select */
158 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
159 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
160 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
161 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
163 $smarty->assign($val."_select", $this->$val);
164 $smarty->assign($val."ACL", chkacl($this->acl, $val));
165 }
167 /* Variables */
168 foreach(array("gotoXHsync", "gotoXVsync") as $val){
169 $smarty->assign($val, $this->$val);
170 $smarty->assign($val."ACL", chkacl($this->acl, $val));
171 }
172 $smarty->assign("staticAddress", "");
174 /* Checkboxes */
175 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
176 if ($this->$val == TRUE) {
177 $smarty->assign("$val", "checked");
178 } else {
179 $smarty->assign("$val", "");
180 }
181 $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
182 }
184 /* Phone stuff */
185 $smarty->assign ("goFonHardware", $this->goFonHardware);
186 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
187 _("Choose the phone located at the current terminal")."\" ".
188 chkacl($this->acl, "goFonHardware").">\n";
189 foreach ($this->hardware_list as $cn => $description){
190 if ($cn == $this->goFonHardware){
191 $selected= "selected";
192 } else {
193 $selected= "";
194 }
195 if (isset($this->used_hardware[$cn])){
196 $color= "style=\"color:#A0A0A0\"";
197 } else {
198 $color= "";
199 }
200 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
201 }
202 $hl.= "</select>\n";
203 $smarty->assign ("hardware_list", $hl);
204 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
206 /* Show main page */
207 return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
208 }
210 function remove_from_parent()
211 {
212 $ldap= $this->config->get_ldap_link();
213 $ldap->rmdir($this->dn);
214 show_ldap_error($ldap->get_error());
215 $this->handle_post_events("remove");
216 }
219 /* Save data to object */
220 function save_object()
221 {
222 plugin::save_object();
224 /* Save checkbox state */
225 if (isset ($_POST['gotoXMethod'])){
226 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
228 if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
229 $this->$val= FALSE;
230 } else {
231 $this->$val= TRUE;
232 }
233 }
234 }
235 }
238 /* Check supplied data */
239 function check()
240 {
241 $message= array();
243 /* Default entries can use blank hsync/vsync entries */
244 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
246 /* Check vsync for correct usage */
247 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
248 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
249 && chkacl ($this->acl, "gotoXVsync") == ""){
251 $message[]= _("Please specify a valid VSync range.");
252 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
253 list($v1,$v2)= split ("-", $val);
254 if ($v2 != ""){
255 if ($v1 > $v2){
256 $message[]= _("Please specify a valid VSync range.");
257 }
258 }
259 }
261 /* Check hsync for correct usage */
262 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
263 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
264 && chkacl ($this->acl, "gotoXHsync") == ""){
266 $message[]= _("Please specify a valid HSync range.");
267 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
268 list($v1,$v2)= split ("-", $val);
269 if ($v2 != ""){
270 if ($v1 > $v2){
271 $message[]= _("Please specify a valid HSync range.");
272 }
273 }
274 }
275 }
276 return ($message);
277 }
280 /* Save to LDAP */
281 function save()
282 {
283 plugin::save();
285 /* Strip out 'default' values */
286 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
287 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
288 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
289 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
291 if ($this->attrs[$val] == "default"){
292 $this->attrs[$val]= array();
293 }
294 }
296 /* Write back to ldap */
297 $ldap= $this->config->get_ldap_link();
298 $ldap->cd($this->dn);
299 $ldap->modify($this->attrs);
300 show_ldap_error($ldap->get_error());
301 $this->handle_post_events("modify");
302 }
304 }
306 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
307 ?>