Code

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