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 /* Do we need to flip is_account state? */
129 if (isset($_POST['modify_state'])){
130 $this->is_account= !$this->is_account;
131 }
133 /* Do we represent a valid terminal? */
134 if (!$this->is_account && $this->parent == NULL){
135 $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\"> <b>".
136 _("This 'dn' has no terminal features.")."</b>";
137 return ($display);
138 }
140 /* Show main page */
141 $smarty= get_smarty();
143 /* Arrays */
144 foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
145 "gotoScannerModels", "XKbModels", "XKbLayouts", "XKbVariants",
146 "MouseTypes", "MousePorts") as $val){
147 $smarty->assign("$val", $this->$val);
148 }
149 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
150 $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
151 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
152 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
154 /* Variables - select */
155 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
156 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
157 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
158 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
160 $smarty->assign($val."_select", $this->$val);
161 $smarty->assign($val."ACL", chkacl($this->acl, $val));
162 }
164 /* Variables */
165 foreach(array("gotoXHsync", "gotoXVsync") as $val){
166 $smarty->assign($val, $this->$val);
167 $smarty->assign($val."ACL", chkacl($this->acl, $val));
168 }
170 /* Checkboxes */
171 foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
172 if ($this->$val == TRUE) {
173 $smarty->assign("$val", "checked");
174 } else {
175 $smarty->assign("$val", "");
176 }
177 $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
178 }
180 /* Phone stuff */
181 $smarty->assign ("goFonHardware", $this->goFonHardware);
182 $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
183 _("Choose the phone located at the current terminal")."\" ".
184 chkacl($this->acl, "goFonHardware").">\n";
185 foreach ($this->hardware_list as $cn => $description){
186 if ($cn == $this->goFonHardware){
187 $selected= "selected";
188 } else {
189 $selected= "";
190 }
191 if (isset($this->used_hardware[$cn])){
192 $color= "style=\"color:#A0A0A0\"";
193 } else {
194 $color= "";
195 }
196 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
197 }
198 $hl.= "</select>\n";
199 $smarty->assign ("hardware_list", $hl);
200 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
202 /* Show main page */
203 return($smarty->fetch (get_template_path('service.tpl', TRUE)));
204 }
206 function remove_from_parent()
207 {
208 $ldap= $this->config->get_ldap_link();
209 $ldap->rmdir($this->dn);
210 show_ldap_error($ldap->get_error());
211 $this->handle_post_events("remove");
212 }
215 /* Save data to object */
216 function save_object()
217 {
218 plugin::save_object();
220 /* Save checkbox state */
221 if (isset ($_POST['gotoXMethod'])){
222 foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
224 if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
225 $this->$val= FALSE;
226 } else {
227 $this->$val= TRUE;
228 }
229 }
230 }
231 }
234 /* Check supplied data */
235 function check()
236 {
237 $message= array();
239 /* Default entries can use blank hsync/vsync entries */
240 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
242 /* Check vsync for correct usage */
243 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
244 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
245 && chkacl ($this->acl, "gotoXVsync") == ""){
247 $message[]= _("Please specify a valid VSync range.");
248 } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
249 list($v1,$v2)= split ("-", $val);
250 if ($v2 != ""){
251 if ($v1 > $v2){
252 $message[]= _("Please specify a valid VSync range.");
253 }
254 }
255 }
257 /* Check hsync for correct usage */
258 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
259 if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
260 && chkacl ($this->acl, "gotoXHsync") == ""){
262 $message[]= _("Please specify a valid HSync range.");
263 } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
264 list($v1,$v2)= split ("-", $val);
265 if ($v2 != ""){
266 if ($v1 > $v2){
267 $message[]= _("Please specify a valid HSync range.");
268 }
269 }
270 }
271 }
272 return ($message);
273 }
276 /* Save to LDAP */
277 function save()
278 {
279 plugin::save();
281 /* Strip out 'default' values */
282 foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
283 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
284 "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
285 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
287 if ($this->attrs[$val] == "default"){
288 $this->attrs[$val]= array();
289 }
290 }
292 /* Write back to ldap */
293 $ldap= $this->config->get_ldap_link();
294 $ldap->cd($this->dn);
295 $ldap->modify($this->attrs);
296 show_ldap_error($ldap->get_error());
297 $this->handle_post_events("modify");
298 }
300 }
302 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
303 ?>