Code

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