Code

27caf1a013c288a7e02c2fe58108c2ab3e064ab3
[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     $this->XColordepths= array(
82         "default"  => "["._("inherited")."]",
83         "8"        => "8 " ._("bit"),
84         "15"       => "15 "._("bit"),
85         "16"       => "16 "._("bit"),
86         "24"       => "24 "._("bit"));
88     $this->XKbModels['default']= "["._("inherited")."]";
89     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
90           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
91           "logiinetnav", "logiinternet", "macintosh", "microsoft",
92           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
93           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
94       $this->XKbModels[$type] = $type;
95     }
97     /* Additional values will be extracted from /etc/gosa/keyboardLayouts */
98     $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
99     $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
101     $this->MouseTypes= array( "AUTO"      =>  "["._("inherited")."]" ,  "ImPS/2"      => "ImPS/2", 
102                               "PS/2"      =>  "PS/2"                 ,  "Microsoft"   => "Microsoft", 
103                               "Logitech"  =>  "Logitech");
105     $this->MousePorts= array("AUTO"             =>"["._("inherited")."]"   , "/dev/ttyS0"  => "/dev/ttyS0", 
106                              "/dev/ttyS1"       => "/dev/ttyS1"            , "/dev/psaux"  => "/dev/psaux", 
107                              "/dev/input/mice"  =>"/dev/input/mice");
108  
110     /* try to read additional keyboard layouts
111      */
112     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
113       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
114         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
115         $tmp = split("\n",$str);
116         foreach($tmp as $entry){
117           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
118             $entry = trim($entry);
119             $tmp2 = split ("\:",$entry);
120             $la =   trim($tmp2[0]);   // What would be saved to ldap
121             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
122             $this->XKbLayouts [ $la] = $da;
123           }
124         }
125       }
126     }
128     /* Load scanner models */
129     $fcontents = file ($this->config->basedir."/include/scanner.inc");
130     while (list ($line_num, $line) = each ($fcontents)) {
131       preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
132       $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
133     }
134     ksort ($this->gotoScannerModels);
136     /* Initialize methods */
137     $this->XMethods["default"]= _("default");
138     $this->XMethods["indirect"]= _("show chooser");
139     $this->XMethods["query"]= _("direct");
140 #$this->XMethods["squery"]= _("direct via ssh");
141 #$this->XMethods["nquery"]= _("direct via nx");
142     $this->XMethods["load"]= _("load balanced");
143 #$this->XMethods["sload"]= _("load balanced via ssh");
144 #$this->XMethods["nload"]= _("load balanced via nx");
145     $this->XMethods["rdp"]= _("Windows RDP");
146     $this->XMethods["citrix"]= _("ICA client");
148     $this->orig_dn= $this->dn;
150     /* Load hardware list */
151     $ldap= $this->config->get_ldap_link();
152     $ldap->cd($this->config->current['BASE']);
153     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
154     while ($attrs= $ldap->fetch()){
155       $cn= $attrs['cn'][0];
156       if (isset($attrs['description'])){
157         $description= " - ".$attrs['description'][0];
158       } else {
159         $description= "";
160       }
161       $this->hardware_list[$cn]= "$cn$description";
162     }
164     /* Eventually colorize phones */
165     $ldap->cd($this->config->current['BASE']);
166     foreach ($this->hardware_list as $cn => $desc){
167       $ldap->search("(goFonHardware=$cn)", array('cn'));
168       if ($ldap->count() > 0){
169         $ldap->fetch();
170         if ($ldap->getDN() != $this->dn){
171           $this->used_hardware[$cn]= $ldap->getDN();
172         }
173       }
174     }
176     $this->hardware_list["automatic"]= _("automatic");
177     ksort($this->hardware_list);
178   }
180   function execute()
181   {
182         /* Call parent execute */
183         plugin::execute();
185     /* Do we need to flip is_account state? */
186     if (isset($_POST['modify_state'])){
187       $this->is_account= !$this->is_account;
188     }
190     /* Do we represent a valid terminal? */
191     if (!$this->is_account && $this->parent == NULL){
192       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
193         _("This 'dn' has no terminal features.")."</b>";
194       return ($display);
195     }
197     /* Show main page */
198     $smarty= get_smarty();
200     /* Arrays */ 
201     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
202           "gotoScannerModels", "XKbModels","XKbVariants",
203           "MouseTypes", "MousePorts") as $val){
204       $smarty->assign("$val", $this->$val);
205     }
206     $smarty->assign("XKbLayouts",   $this->XKbLayouts);
207     $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
208   
209     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
210     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
211     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
212     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
214     /* Variables - select */
215     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath", 
216           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
217           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
218           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
220       $smarty->assign($val."_select", $this->$val);
221       $smarty->assign($val."ACL", chkacl($this->acl, $val));
222     }
224     /* Variables */
225     foreach(array("gotoXHsync", "gotoXVsync") as $val){
226       $smarty->assign($val, $this->$val);
227       $smarty->assign($val."ACL", chkacl($this->acl, $val));
228     }
229     $smarty->assign("staticAddress", "");
231     /* Checkboxes */
232     foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
233       if ($this->$val == TRUE) {
234         $smarty->assign("$val", "checked");
235       } else {
236         $smarty->assign("$val", "");
237       }
238       $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
239     }
241     /* Phone stuff */
242     $smarty->assign ("goFonHardware", $this->goFonHardware);
243     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
244          _("Choose the phone located at the current terminal")."\" ".
245          chkacl($this->acl, "goFonHardware").">\n";
246     foreach ($this->hardware_list as $cn => $description){
247       if ($cn == $this->goFonHardware){
248         $selected= "selected";
249       } else {
250         $selected= "";
251       }
252       if (isset($this->used_hardware[$cn])){
253         $color= "style=\"color:#A0A0A0\"";
254       } else {
255         $color= "";
256       }
257       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
258     }
259     $hl.= "</select>\n";
260     $smarty->assign ("hardware_list", $hl);
261     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
263     /* Show main page */
264     return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
265   }
267   function remove_from_parent()
268   {
269     $this->handle_post_events("remove");
270   }
273   /* Save data to object */
274   function save_object()
275   {
276     plugin::save_object();
278     /* Save checkbox state */
279     if (isset ($_POST['gotoXMethod'])){
280       foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
282         if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
283           $this->$val= FALSE;
284         } else {
285           $this->$val= TRUE;
286         }
287       }
288     }
289   }
292   /* Check supplied data */
293   function check()
294   {
295     /* Call common method to give check the hook */
296     $message= plugin::check();
298     /* Default entries can use blank hsync/vsync entries */
299     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
301       /* Check vsync for correct usage */
302       $val= preg_replace ("/\s/", "", $this->gotoXVsync);
303       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
304           && chkacl ($this->acl, "gotoXVsync") == ""){
306         $message[]= _("Please specify a valid VSync range.");
307       } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
308         list($v1,$v2)= split ("-", $val);
309         if ($v2 != ""){
310           if ($v1 > $v2){
311             $message[]= _("Please specify a valid VSync range.");
312           }
313         }
314       }
316       /* Check hsync for correct usage */
317       $val= preg_replace ("/\s/", "", $this->gotoXHsync);
318       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
319           && chkacl ($this->acl, "gotoXHsync") == ""){
321         $message[]= _("Please specify a valid HSync range.");
322       } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
323         list($v1,$v2)= split ("-", $val);
324         if ($v2 != ""){
325           if ($v1 > $v2){
326             $message[]= _("Please specify a valid HSync range.");
327           }
328         }
329       }
330     }
331     return ($message);
332   }
335   /* Save to LDAP */
336   function save()
337   {
338     plugin::save();
340     /* Strip out 'default' values */
341     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
342           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
343           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
344           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
346       if ($this->attrs[$val] == "default"){
347         $this->attrs[$val]= array();
348       }
349     }
351     /* Write back to ldap */
352     $ldap= $this->config->get_ldap_link();
353     $ldap->cd($this->dn);
354     $this->cleanup();
355     $ldap->modify ($this->attrs); 
357     show_ldap_error($ldap->get_error(), _("Saving terminal service information failed"));
358     $this->handle_post_events("modify");
359   }
363 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
364 ?>