Code

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