Code

fe580b76e5632f58bb4a5e14cde52882df6fa0dd
[gosa.git] / plugins / admin / systems / class_terminalService.inc
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", "vmware");
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"=>"default","de"=> "de","intl" =>"intl","us" =>"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     
75     /* try to read additional keyboard layouts
76      */
77     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
78       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
79         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
80         $tmp = split("\n",$str);
81         foreach($tmp as $entry){
82           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
83             $entry = trim($entry);
84             $tmp2 = split ("\:",$entry);
85             $la =   trim($tmp2[0]);   // What would be saved to ldap
86             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
87             $this->XKbLayouts [ $la] = $da;
88           }
89         }
90       }
91     }
93     /* Load scanner models */
94     $fcontents = file ($this->config->basedir."/include/scanner.inc");
95     while (list ($line_num, $line) = each ($fcontents)) {
96       preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
97       $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
98     }
99     ksort ($this->gotoScannerModels);
101     /* Initialize methods */
102     $this->XMethods["default"]= _("default");
103     $this->XMethods["indirect"]= _("show chooser");
104     $this->XMethods["query"]= _("direct");
105 #$this->XMethods["squery"]= _("direct via ssh");
106 #$this->XMethods["nquery"]= _("direct via nx");
107     $this->XMethods["load"]= _("load balanced");
108 #$this->XMethods["sload"]= _("load balanced via ssh");
109 #$this->XMethods["nload"]= _("load balanced via nx");
110     $this->XMethods["rdp"]= _("Windows RDP");
111     $this->XMethods["citrix"]= _("ICA client");
113     $this->orig_dn= $this->dn;
115     /* Load hardware list */
116     $ldap= $this->config->get_ldap_link();
117     $ldap->cd($this->config->current['BASE']);
118     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
119     while ($attrs= $ldap->fetch()){
120       $cn= $attrs['cn'][0];
121       if (isset($attrs['description'])){
122         $description= " - ".$attrs['description'][0];
123       } else {
124         $description= "";
125       }
126       $this->hardware_list[$cn]= "$cn$description";
127     }
129     /* Eventually colorize phones */
130     $ldap->cd($this->config->current['BASE']);
131     foreach ($this->hardware_list as $cn => $desc){
132       $ldap->search("(goFonHardware=$cn)", array('cn'));
133       if ($ldap->count() > 0){
134         $ldap->fetch();
135         if ($ldap->getDN() != $this->dn){
136           $this->used_hardware[$cn]= $ldap->getDN();
137         }
138       }
139     }
141     $this->hardware_list["automatic"]= _("automatic");
142     ksort($this->hardware_list);
143   }
145   function execute()
146   {
147         /* Call parent execute */
148         plugin::execute();
150     /* Do we need to flip is_account state? */
151     if (isset($_POST['modify_state'])){
152       $this->is_account= !$this->is_account;
153     }
155     /* Do we represent a valid terminal? */
156     if (!$this->is_account && $this->parent == NULL){
157       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
158         _("This 'dn' has no terminal features.")."</b>";
159       return ($display);
160     }
162     /* Show main page */
163     $smarty= get_smarty();
165     /* Arrays */ 
166     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
167           "gotoScannerModels", "XKbModels","XKbVariants",
168           "MouseTypes", "MousePorts") as $val){
169       $smarty->assign("$val", $this->$val);
170     }
171     $smarty->assign("XKbLayouts",   $this->XKbLayouts);
172     $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
173   
174     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
175     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
176     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
177     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
179     /* Variables - select */
180     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath", 
181           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
182           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
183           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
185       $smarty->assign($val."_select", $this->$val);
186       $smarty->assign($val."ACL", chkacl($this->acl, $val));
187     }
189     /* Variables */
190     foreach(array("gotoXHsync", "gotoXVsync") as $val){
191       $smarty->assign($val, $this->$val);
192       $smarty->assign($val."ACL", chkacl($this->acl, $val));
193     }
194     $smarty->assign("staticAddress", "");
196     /* Checkboxes */
197     foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
198       if ($this->$val == TRUE) {
199         $smarty->assign("$val", "checked");
200       } else {
201         $smarty->assign("$val", "");
202       }
203       $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
204     }
206     /* Phone stuff */
207     $smarty->assign ("goFonHardware", $this->goFonHardware);
208     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
209          _("Choose the phone located at the current terminal")."\" ".
210          chkacl($this->acl, "goFonHardware").">\n";
211     foreach ($this->hardware_list as $cn => $description){
212       if ($cn == $this->goFonHardware){
213         $selected= "selected";
214       } else {
215         $selected= "";
216       }
217       if (isset($this->used_hardware[$cn])){
218         $color= "style=\"color:#A0A0A0\"";
219       } else {
220         $color= "";
221       }
222       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
223     }
224     $hl.= "</select>\n";
225     $smarty->assign ("hardware_list", $hl);
226     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
228     /* Show main page */
229     return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
230   }
232   function remove_from_parent()
233   {
234     $this->handle_post_events("remove");
235   }
238   /* Save data to object */
239   function save_object()
240   {
241     plugin::save_object();
243     /* Save checkbox state */
244     if (isset ($_POST['gotoXMethod'])){
245       foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
247         if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
248           $this->$val= FALSE;
249         } else {
250           $this->$val= TRUE;
251         }
252       }
253     }
254   }
257   /* Check supplied data */
258   function check()
259   {
260     /* Call common method to give check the hook */
261     $message= plugin::check();
263     /* Default entries can use blank hsync/vsync entries */
264     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
266       /* Check vsync for correct usage */
267       $val= preg_replace ("/\s/", "", $this->gotoXVsync);
268       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
269           && chkacl ($this->acl, "gotoXVsync") == ""){
271         $message[]= _("Please specify a valid VSync range.");
272       } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
273         list($v1,$v2)= split ("-", $val);
274         if ($v2 != ""){
275           if ($v1 > $v2){
276             $message[]= _("Please specify a valid VSync range.");
277           }
278         }
279       }
281       /* Check hsync for correct usage */
282       $val= preg_replace ("/\s/", "", $this->gotoXHsync);
283       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
284           && chkacl ($this->acl, "gotoXHsync") == ""){
286         $message[]= _("Please specify a valid HSync range.");
287       } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
288         list($v1,$v2)= split ("-", $val);
289         if ($v2 != ""){
290           if ($v1 > $v2){
291             $message[]= _("Please specify a valid HSync range.");
292           }
293         }
294       }
295     }
296     return ($message);
297   }
300   /* Save to LDAP */
301   function save()
302   {
303     plugin::save();
305     /* Strip out 'default' values */
306     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
307           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
308           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
309           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
311       if ($this->attrs[$val] == "default"){
312         $this->attrs[$val]= array();
313       }
314     }
316     /* Write back to ldap */
317     $ldap= $this->config->get_ldap_link();
318     $ldap->cd($this->dn);
319     $this->cleanup();
320 $ldap->modify ($this->attrs); 
322     show_ldap_error($ldap->get_error());
323     $this->handle_post_events("modify");
324   }
328 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
329 ?>