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