Code

Added nvidia driver to the list of xorg drivers
[gosa.git] / plugins / admin / systems / class_terminalService.inc
1 <?php
3 class termservice extends plugin
4 {
5   /* Generic terminal attributes */
6   var $gotoLpdEnable= FALSE;
7   var $gotoXMonitor= "";
8   var $gotoXMethod= "";
9   var $gotoXdmcpServer= "";
10   var $gotoFontPath= "";
11   var $gotoXDriver= "";
12   var $gotoXResolution= "";
13   var $gotoXColordepth= "";
14   var $gotoXHsync= "";
15   var $gotoXVsync= "";
16   var $gotoXKbModel= "";
17   var $gotoXKbLayout= "";
18   var $gotoXKbVariant= "";
19   var $gotoXMouseType= "";
20   var $gotoXMouseport= "";
21   var $gotoLpdServer= "";
22   var $gotoScannerEnable= "";
23   var $gotoScannerModel= "";
24   var $gotoScannerClients= "";
25   var $gotoScannerBackend= "";
26   var $goFonHardware= "automatic";
27   var $AutoSync = false;
29   /* Needed values and lists */
30   var $ignore_account= TRUE;
31   var $base= "";
32   var $cn= "";
33   var $orig_dn= "";
34   var $XMethods= array();
35   var $XDrivers= array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
36       "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv", "nvidia",
37       "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
38       "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
39   var $XResolutions= array();
40   var $XColordepths= array();
41   var $XKbModels= array ();
42   var $XKbLayouts= array ();
43   var $XKbVariants= array ();
44   var $MouseTypes= array();
45   var $MousePorts= array();
46   var $gotoScannerModels= array();
47   var $hardware_list= array();
48   var $used_hardware= array();
51   /* attribute list for save action */
52   var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
53       "gotoFontPath", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
54       "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
55       "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
56       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
57       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
58   var $objectclasses= array("GOhard");
61   function termservice ($config, $dn= NULL, $parent= NULL)
62   {
63     plugin::plugin ($config, $dn, $parent);
64     
65     array_unshift($this->XDrivers, "["._("unknown")."]");
66     
67     $this->XResolutions= array(
68         "default"   =>  "["._("inherited")."]"  ,
69         "640x480"   =>  "640x480",
70         "800x600"   =>  "800x600",
71         "1024x768"  =>  "1024x768",
72         "1152x864"  =>  "1152x864",
73         "1280x1024" =>  "1280x1024",
74         "1400x1050" =>  "1400x1050",
75         "1600x1200" =>  "1600x1200");
77     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
78       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
80       if(is_readable($file)){
81         $str = file_get_contents($file);
82         $lines = split("\n",$str);
83         foreach($lines as $line){
84           $line = trim($line);
85           if(!empty($line)){
86             $this->XResolutions[$line]=$line;
87           }
88         }
89         //natcasesort($this->gotoXResolutions);
90       }else{
91         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
92       }
93     }
95     $this->XColordepths= array(
96         "default"  => "["._("inherited")."]",
97         "8"        => "8 " ._("bit"),
98         "15"       => "15 "._("bit"),
99         "16"       => "16 "._("bit"),
100         "24"       => "24 "._("bit"));
102     $this->XKbModels['default']= "["._("inherited")."]";
103     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
104           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
105           "logiinetnav", "logiinternet", "macintosh", "microsoft",
106           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
107           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
108       $this->XKbModels[$type] = $type;
109     }
111     /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */
112     $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
113     $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
115     $this->MouseTypes= array( "AUTO"      =>  "["._("inherited")."]" ,  "ImPS/2"      => "ImPS/2", 
116                               "PS/2"      =>  "PS/2"                 ,  "Microsoft"   => "Microsoft", 
117                               "Logitech"  =>  "Logitech");
119     $this->MousePorts= array("AUTO"             =>"["._("inherited")."]"   , "/dev/ttyS0"  => "/dev/ttyS0", 
120                              "/dev/ttyS1"       => "/dev/ttyS1"            , "/dev/psaux"  => "/dev/psaux", 
121                              "/dev/input/mice"  =>"/dev/input/mice");
122  
124     /* try to read additional keyboard layouts
125      */
126     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
127       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
128         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
129         $tmp = split("\n",$str);
130         foreach($tmp as $entry){
131           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
132             $entry = trim($entry);
133             $tmp2 = split ("\:",$entry);
134             $la =   trim($tmp2[0]);   // What would be saved to ldap
135             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
136             $this->XKbLayouts [ $la] = $da;
137           }
138         }
139       }
140     }
142     /* Load scanner models */
143     $fcontents = file ($this->config->basedir."/include/scanner.inc");
144     while (list ($line_num, $line) = each ($fcontents)) {
145       preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
146       $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
147     }
148     ksort ($this->gotoScannerModels);
150     /* Initialize methods */
151     $this->XMethods["default"]= _("default");
152     $this->XMethods["indirect"]= _("show chooser");
153     $this->XMethods["query"]= _("direct");
154 #$this->XMethods["squery"]= _("direct via ssh");
155 #$this->XMethods["nquery"]= _("direct via nx");
156     $this->XMethods["load"]= _("load balanced");
157 #$this->XMethods["sload"]= _("load balanced via ssh");
158 #$this->XMethods["nload"]= _("load balanced via nx");
159     $this->XMethods["rdp"]= _("Windows RDP");
160     $this->XMethods["citrix"]= _("ICA client");
162     $this->orig_dn= $this->dn;
164     /* Load hardware list */
165     $ldap= $this->config->get_ldap_link();
166     $ldap->cd($this->config->current['BASE']);
167     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
168     while ($attrs= $ldap->fetch()){
169       $cn= $attrs['cn'][0];
170       if (isset($attrs['description'])){
171         $description= " - ".$attrs['description'][0];
172       } else {
173         $description= "";
174       }
175       $this->hardware_list[$cn]= "$cn$description";
176     }
178     /* Eventually colorize phones */
179     $ldap->cd($this->config->current['BASE']);
180     foreach ($this->hardware_list as $cn => $desc){
181       $ldap->search("(goFonHardware=$cn)", array('cn'));
182       if ($ldap->count() > 0){
183         $ldap->fetch();
184         if ($ldap->getDN() != $this->dn){
185           $this->used_hardware[$cn]= $ldap->getDN();
186         }
187       }
188     }
190     $this->hardware_list["automatic"]= _("automatic");
191     ksort($this->hardware_list);
193     /* Convert gotoLpdEnable */
194     $this->gotoLpdEnable= preg_match("/yes/i",$this->gotoLpdEnable);
196       /* Load hardware list */
197     $ldap= $this->config->get_ldap_link();
198     $ldap->cd($this->config->current['BASE']);
199     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
200     if ($ldap->count() == 1){
201       $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
202                   "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
203       $attrs= $ldap->fetch();
205       foreach ($map as $name){
206         if (!isset($attrs[$name][0])){
207           continue;
208         }
210         switch ($name){
211           case 'gotoXResolution':
212             $this->XResolutions['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
213             break;
214           case 'gotoXColordepth':
215             $this->XColordepths['default'] =  _("inherited").' ['.$attrs[$name][0].' '._('Bit').']';
216             break;
217           case 'gotoXKbModel':
218             $this->XKbModels['default'] =  _("inherited").' ['.$attrs[$name][0].']';
219             break;
220           case 'gotoXKbLayout':
221             $this->XKbLayouts['default'] =  _("inherited").' ['.$attrs[$name][0].']';
222             break;
223           case 'gotoXKbVariant':
224             $this->XKbVariants['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
225             break;
226           case 'gotoXMouseType':
227             $this->MouseTypes['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
228             break;
229           case 'gotoXMouseport':
230             $this->MousePorts['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
231             break;
232         }
233       }
234     }
235     if(preg_match("/\+/",$this->gotoXHsync)){
236       $this->AutoSync = true;
237       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
238       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
239     }
240   }
242   function execute()
243   {
244         /* Call parent execute */
245         plugin::execute();
247     /* Do we need to flip is_account state? */
248     if (isset($_POST['modify_state'])){
249       $this->is_account= !$this->is_account;
250     }
252     /* Do we represent a valid terminal? */
253     if (!$this->is_account && $this->parent == NULL){
254       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
255         _("This 'dn' has no terminal features.")."</b>";
256       return ($display);
257     }
259     /* Show main page */
260     $smarty= get_smarty();
262     /* Arrays */ 
263     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
264           "gotoScannerModels", "XKbModels","XKbVariants",
265           "MouseTypes", "MousePorts") as $val){
266       $smarty->assign("$val", $this->$val);
267     }
268     $smarty->assign("XKbLayouts",   $this->XKbLayouts);
269     $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
270   
271     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
272     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
273     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
274     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
276     /* Variables - select */
277     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath", 
278           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
279           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
280           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
282       $smarty->assign($val."_select", $this->$val);
283       $smarty->assign($val."ACL", chkacl($this->acl, $val));
284     }
286     /* Variables */
287     foreach(array("gotoXHsync", "gotoXVsync") as $val){
288       $smarty->assign($val, $this->$val);
289       $smarty->assign($val."ACL", chkacl($this->acl, $val));
290     }
291     $smarty->assign("staticAddress", "");
293     /* Checkboxes */
294     foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
295       if ($this->$val == TRUE) {
296         $smarty->assign("$val", "checked");
297       } else {
298         $smarty->assign("$val", "");
299       }
300       $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
301     }
303     /* Phone stuff */
304     $smarty->assign ("goFonHardware", $this->goFonHardware);
305     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
306          _("Choose the phone located at the current terminal")."\" ".
307          chkacl($this->acl, "goFonHardware").">\n";
308     foreach ($this->hardware_list as $cn => $description){
309       if ($cn == $this->goFonHardware){
310         $selected= "selected";
311       } else {
312         $selected= "";
313       }
314       if (isset($this->used_hardware[$cn])){
315         $color= "style=\"color:#A0A0A0\"";
316       } else {
317         $color= "";
318       }
319       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
320     }
321     $hl.= "</select>\n";
322     $smarty->assign ("hardware_list", $hl);
323     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
325     $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
326   
327     if($this->AutoSync){
328       $smarty->assign("AutoSyncCHK"," checked ");
329       $smarty->assign("hiddenState"," disabled ");
330     }else{
331       $smarty->assign("AutoSyncCHK"," ");
332       $smarty->assign("hiddenState","");
333     }
335   
336     /* Show main page */
337     return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
338   }
340   function remove_from_parent()
341   {
342     $this->handle_post_events("remove");
343   }
346   /* Save data to object */
347   function save_object()
348   {
349     plugin::save_object();
351     /* Save checkbox state */
352     if (isset ($_POST['gotoXMethod'])){
353       foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
355         if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
356           $this->$val= FALSE;
357         } else {
358           $this->$val= TRUE;
359         }
360       }
361     } 
362     if(isset($_POST['gotoXDriver'])){
363       if(isset($_POST['AutoSync'])){
364         $this->AutoSync = true;
365       }else{
366         $this->AutoSync = false;
367       }
368     }
370   }
373   /* Check supplied data */
374   function check()
375   {
376     /* Call common method to give check the hook */
377     $message= plugin::check();
379     /* Default entries can use blank hsync/vsync entries */
380     if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){
382       /* But only if no auto sync is enabled... */
383       if (!$this->AutoSync){
385         /* Check vsync for correct usage */
386         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
387         if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
388             && chkacl ($this->acl, "gotoXVsync") == ""){
390           $message[]= _("Please specify a valid VSync range.");
391         } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
392           list($v1,$v2)= preg_split ("/[-+]/", $val);
393           if ($v2 != ""){
394             if ($v1 > $v2){
395               $message[]= _("Please specify a valid VSync range.");
396             }
397           }
398         }
400         /* Check hsync for correct usage */
401         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
402         if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
403             && chkacl ($this->acl, "gotoXHsync") == ""){
405           $message[]= _("Please specify a valid HSync range.");
406         } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
407           list($v1,$v2)= preg_split ("/[-+]/", $val);
408           if ($v2 != ""){
409             if ($v1 > $v2){
410               $message[]= _("Please specify a valid HSync range.");
411             }
412           }
413         }
414       }
415     }
417     return ($message);
418   }
421   /* Save to LDAP */
422   function save()
423   {
424     /* Convert to string */
425     $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
427     plugin::save();
429     /* Strip out 'default' values */
430     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
431           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
432           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
433           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
435       if ($this->attrs[$val] == "default"){
436         $this->attrs[$val]= array();
437       }
438     }
440     if($this->AutoSync){
441       $this->attrs['gotoXHsync'] = "30+55";
442       $this->attrs['gotoXVsync'] = "50+70";
443     }
445     /* Write back to ldap */
446     $ldap= $this->config->get_ldap_link();
447     $ldap->cd($this->dn);
448     $this->cleanup();
449     $ldap->modify ($this->attrs); 
451     show_ldap_error($ldap->get_error(), _("Saving terminal service information failed"));
452     $this->handle_post_events("modify");
453   }
457 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
458 ?>