Code

Moved ldap->error
[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("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();
44   var $XColordepths= array();
45   var $XKbModels= array ();
46   var $XKbLayouts= array ();
47   var $XKbVariants= array ();
48   var $MouseTypes= array();
49   var $MousePorts= array();
50   var $gotoScannerModels= array();
51   var $hardware_list= array();
52   var $used_hardware= array();
55   /* attribute list for save action */
56   var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
57       "gotoFontPath", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
58       "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
59       "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
60       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
61       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
62   var $objectclasses= array("GOhard");
65   function termservice ($config, $dn= NULL)
66   {
67     plugin::plugin ($config, $dn);
68     
69     array_unshift($this->XDrivers, "["._("unknown")."]");
70     
71     $this->XResolutions= array(
72         "default"   =>  "["._("inherited")."]"  ,
73         "640x480"   =>  "640x480",
74         "800x600"   =>  "800x600",
75         "1024x768"  =>  "1024x768",
76         "1152x864"  =>  "1152x864",
77         "1280x1024" =>  "1280x1024",
78         "1400x1050" =>  "1400x1050",
79         "1600x1200" =>  "1600x1200");
81     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
82       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
84       if(is_readable($file)){
85         $str = file_get_contents($file);
86         $lines = split("\n",$str);
87         foreach($lines as $line){
88           $line = trim($line);
89           if(!empty($line)){
90             $this->XResolutions[$line]=$line;
91           }
92         }
93         //natcasesort($this->gotoXResolutions);
94       }else{
95         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
96       }
97     }
99     $this->XColordepths= array(
100         "default"  => "["._("inherited")."]",
101         "8"        => "8 " ._("bit"),
102         "15"       => "15 "._("bit"),
103         "16"       => "16 "._("bit"),
104         "24"       => "24 "._("bit"));
106     $this->XKbModels['default']= "["._("inherited")."]";
107     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
108           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
109           "logiinetnav", "logiinternet", "macintosh", "microsoft",
110           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
111           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
112       $this->XKbModels[$type] = $type;
113     }
115     /* Additional values will be extracted from /etc/gosa/keyboardLayouts */
116     $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
117     $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
119     $this->MouseTypes= array( "AUTO"      =>  "["._("inherited")."]" ,  "ImPS/2"      => "ImPS/2", 
120                               "PS/2"      =>  "PS/2"                 ,  "Microsoft"   => "Microsoft", 
121                               "Logitech"  =>  "Logitech");
123     $this->MousePorts= array("AUTO"             =>"["._("inherited")."]"   , "/dev/ttyS0"  => "/dev/ttyS0", 
124                              "/dev/ttyS1"       => "/dev/ttyS1"            , "/dev/psaux"  => "/dev/psaux", 
125                              "/dev/input/mice"  =>"/dev/input/mice");
126  
128     /* try to read additional keyboard layouts
129      */
130     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
131       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
132         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
133         $tmp = split("\n",$str);
134         foreach($tmp as $entry){
135           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
136             $entry = trim($entry);
137             $tmp2 = split ("\:",$entry);
138             $la =   trim($tmp2[0]);   // What would be saved to ldap
139             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
140             $this->XKbLayouts [ $la] = $da;
141           }
142         }
143       }
144     }
146     /* Load scanner models */
147     $fcontents = file ($this->config->basedir."/include/scanner.inc");
148     while (list ($line_num, $line) = each ($fcontents)) {
149       preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
150       $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
151     }
152     ksort ($this->gotoScannerModels);
154     /* Initialize methods */
155     $this->XMethods["default"]= _("default");
156     $this->XMethods["indirect"]= _("show chooser");
157     $this->XMethods["query"]= _("direct");
158 #$this->XMethods["squery"]= _("direct via ssh");
159 #$this->XMethods["nquery"]= _("direct via nx");
160     $this->XMethods["load"]= _("load balanced");
161 #$this->XMethods["sload"]= _("load balanced via ssh");
162 #$this->XMethods["nload"]= _("load balanced via nx");
163     $this->XMethods["rdp"]= _("Windows RDP");
164     $this->XMethods["citrix"]= _("ICA client");
166     $this->orig_dn= $this->dn;
168     /* Load hardware list */
169     $ldap= $this->config->get_ldap_link();
170     $ldap->cd($this->config->current['BASE']);
171     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
172     while ($attrs= $ldap->fetch()){
173       $cn= $attrs['cn'][0];
174       if (isset($attrs['description'])){
175         $description= " - ".$attrs['description'][0];
176       } else {
177         $description= "";
178       }
179       $this->hardware_list[$cn]= "$cn$description";
180     }
182     /* Eventually colorize phones */
183     $ldap->cd($this->config->current['BASE']);
184     foreach ($this->hardware_list as $cn => $desc){
185       $ldap->search("(goFonHardware=$cn)", array('cn'));
186       if ($ldap->count() > 0){
187         $ldap->fetch();
188         if ($ldap->getDN() != $this->dn){
189           $this->used_hardware[$cn]= $ldap->getDN();
190         }
191       }
192     }
194     $this->hardware_list["automatic"]= _("automatic");
195     ksort($this->hardware_list);
196   }
198   function execute()
199   {
200         /* Call parent execute */
201         plugin::execute();
203     /* Do we need to flip is_account state? */
204     if (isset($_POST['modify_state'])){
205       $this->is_account= !$this->is_account;
206     }
208     /* Do we represent a valid terminal? */
209     if (!$this->is_account && $this->parent == NULL){
210       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
211         _("This 'dn' has no terminal features.")."</b>";
212       return ($display);
213     }
215     /* Show main page */
216     $smarty= get_smarty();
218     /* Arrays */ 
219     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
220           "gotoScannerModels", "XKbModels","XKbVariants",
221           "MouseTypes", "MousePorts") as $val){
222       $smarty->assign("$val", $this->$val);
223     }
224     $smarty->assign("XKbLayouts",   $this->XKbLayouts);
225     $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
226   
227     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
228     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
229     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
230     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
232     /* Variables - select */
233     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath", 
234           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
235           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
236           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
238       $smarty->assign($val."_select", $this->$val);
239       $smarty->assign($val."ACL", chkacl($this->acl, $val));
240     }
242     /* Variables */
243     foreach(array("gotoXHsync", "gotoXVsync") as $val){
244       $smarty->assign($val, $this->$val);
245       $smarty->assign($val."ACL", chkacl($this->acl, $val));
246     }
247     $smarty->assign("staticAddress", "");
249     /* Checkboxes */
250     foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
251       if ($this->$val == TRUE) {
252         $smarty->assign("$val", "checked");
253       } else {
254         $smarty->assign("$val", "");
255       }
256       $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
257     }
259     /* Phone stuff */
260     $smarty->assign ("goFonHardware", $this->goFonHardware);
261     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
262          _("Choose the phone located at the current terminal")."\" ".
263          chkacl($this->acl, "goFonHardware").">\n";
264     foreach ($this->hardware_list as $cn => $description){
265       if ($cn == $this->goFonHardware){
266         $selected= "selected";
267       } else {
268         $selected= "";
269       }
270       if (isset($this->used_hardware[$cn])){
271         $color= "style=\"color:#A0A0A0\"";
272       } else {
273         $color= "";
274       }
275       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
276     }
277     $hl.= "</select>\n";
278     $smarty->assign ("hardware_list", $hl);
279     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
281     /* Show main page */
282     return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
283   }
285   function remove_from_parent()
286   {
287     $this->handle_post_events("remove");
288   }
291   /* Save data to object */
292   function save_object()
293   {
294     plugin::save_object();
296     /* Save checkbox state */
297     if (isset ($_POST['gotoXMethod'])){
298       foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
300         if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
301           $this->$val= FALSE;
302         } else {
303           $this->$val= TRUE;
304         }
305       }
306     }
307   }
310   /* Check supplied data */
311   function check()
312   {
313     /* Call common method to give check the hook */
314     $message= plugin::check();
316     /* Default entries can use blank hsync/vsync entries */
317     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
319       /* Check vsync for correct usage */
320       $val= preg_replace ("/\s/", "", $this->gotoXVsync);
321       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
322           && chkacl ($this->acl, "gotoXVsync") == ""){
324         $message[]= _("Please specify a valid VSync range.");
325       } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
326         list($v1,$v2)= split ("-", $val);
327         if ($v2 != ""){
328           if ($v1 > $v2){
329             $message[]= _("Please specify a valid VSync range.");
330           }
331         }
332       }
334       /* Check hsync for correct usage */
335       $val= preg_replace ("/\s/", "", $this->gotoXHsync);
336       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
337           && chkacl ($this->acl, "gotoXHsync") == ""){
339         $message[]= _("Please specify a valid HSync range.");
340       } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
341         list($v1,$v2)= split ("-", $val);
342         if ($v2 != ""){
343           if ($v1 > $v2){
344             $message[]= _("Please specify a valid HSync range.");
345           }
346         }
347       }
348     }
349     return ($message);
350   }
353   /* Save to LDAP */
354   function save()
355   {
356     plugin::save();
358     /* Strip out 'default' values */
359     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
360           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
361           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
362           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
364       if ($this->attrs[$val] == "default"){
365         $this->attrs[$val]= array();
366       }
367     }
369     /* Write back to ldap */
370     $ldap= $this->config->get_ldap_link();
371     $ldap->cd($this->dn);
372     $this->cleanup();
373     $ldap->modify ($this->attrs); 
375     show_ldap_error($ldap->get_error(), _("Saving terminal service information failed"));
376     $this->handle_post_events("modify");
377   }
381 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
382 ?>