Code

Fixed some sprintf
[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, $parent= NULL)
66   {
67     plugin::plugin ($config, $dn, $parent);
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     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
82       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
84       if(is_readable($file)){
85         $str = file_get_contents($file);
86         $lines = split("\n",$str);
87         foreach($lines as $line){
88           $line = trim($line);
89           if(!empty($line)){
90             $this->XResolutions[$line]=$line;
91           }
92         }
93         //natcasesort($this->gotoXResolutions);
94       }else{
95         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
96       }
97     }
99     $this->XColordepths= array(
100         "default"  => "["._("inherited")."]",
101         "8"        => "8 " ._("bit"),
102         "15"       => "15 "._("bit"),
103         "16"       => "16 "._("bit"),
104         "24"       => "24 "._("bit"));
106     $this->XKbModels['default']= "["._("inherited")."]";
107     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
108           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
109           "logiinetnav", "logiinternet", "macintosh", "microsoft",
110           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
111           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
112       $this->XKbModels[$type] = $type;
113     }
115     /* Additional values will be extracted from /etc/gosa/keyboardLayouts */
116     $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
117     $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
119     $this->MouseTypes= array( "AUTO"      =>  "["._("inherited")."]" ,  "ImPS/2"      => "ImPS/2", 
120                               "PS/2"      =>  "PS/2"                 ,  "Microsoft"   => "Microsoft", 
121                               "Logitech"  =>  "Logitech");
123     $this->MousePorts= array("AUTO"             =>"["._("inherited")."]"   , "/dev/ttyS0"  => "/dev/ttyS0", 
124                              "/dev/ttyS1"       => "/dev/ttyS1"            , "/dev/psaux"  => "/dev/psaux", 
125                              "/dev/input/mice"  =>"/dev/input/mice");
126  
128     /* try to read additional keyboard layouts
129      */
130     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
131       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
132         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
133         $tmp = split("\n",$str);
134         foreach($tmp as $entry){
135           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
136             $entry = trim($entry);
137             $tmp2 = split ("\:",$entry);
138             $la =   trim($tmp2[0]);   // What would be saved to ldap
139             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
140             $this->XKbLayouts [ $la] = $da;
141           }
142         }
143       }
144     }
146     /* Load scanner models */
147     $fcontents = file ($this->config->basedir."/include/scanner.inc");
148     while (list ($line_num, $line) = each ($fcontents)) {
149       preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
150       $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
151     }
152     ksort ($this->gotoScannerModels);
154     /* Initialize methods */
155     $this->XMethods["default"]= _("default");
156     $this->XMethods["indirect"]= _("show chooser");
157     $this->XMethods["query"]= _("direct");
158 #$this->XMethods["squery"]= _("direct via ssh");
159 #$this->XMethods["nquery"]= _("direct via nx");
160     $this->XMethods["load"]= _("load balanced");
161 #$this->XMethods["sload"]= _("load balanced via ssh");
162 #$this->XMethods["nload"]= _("load balanced via nx");
163     $this->XMethods["rdp"]= _("Windows RDP");
164     $this->XMethods["citrix"]= _("ICA client");
166     $this->orig_dn= $this->dn;
168     /* Load hardware list */
169     $ldap= $this->config->get_ldap_link();
170     $ldap->cd($this->config->current['BASE']);
171     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
172     while ($attrs= $ldap->fetch()){
173       $cn= $attrs['cn'][0];
174       if (isset($attrs['description'])){
175         $description= " - ".$attrs['description'][0];
176       } else {
177         $description= "";
178       }
179       $this->hardware_list[$cn]= "$cn$description";
180     }
182     /* Eventually colorize phones */
183     $ldap->cd($this->config->current['BASE']);
184     foreach ($this->hardware_list as $cn => $desc){
185       $ldap->search("(goFonHardware=$cn)", array('cn'));
186       if ($ldap->count() > 0){
187         $ldap->fetch();
188         if ($ldap->getDN() != $this->dn){
189           $this->used_hardware[$cn]= $ldap->getDN();
190         }
191       }
192     }
194     $this->hardware_list["automatic"]= _("automatic");
195     ksort($this->hardware_list);
198       /* Load hardware list */
199     $ldap= $this->config->get_ldap_link();
200     $ldap->cd($this->config->current['BASE']);
201     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
202     if ($ldap->count() == 1){
203       $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
204                   "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
205       $attrs= $ldap->fetch();
207       foreach ($map as $name){
208         if (!isset($attrs[$name][0])){
209           continue;
210         }
212         switch ($name){
213           case 'gotoXResolution':
214             $this->XResolutions['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
215             break;
216           case 'gotoXColordepth':
217             $this->XColordepths['default'] =  _("inherited").' ['.$attrs[$name][0].' '._('Bit').']';
218             break;
219           case 'gotoXKbModel':
220             $this->XKbModels['default'] =  _("inherited").' ['.$attrs[$name][0].']';
221             break;
222           case 'gotoXKbLayout':
223             $this->XKbLayouts['default'] =  _("inherited").' ['.$attrs[$name][0].']';
224             break;
225           case 'gotoXKbVariant':
226             $this->XKbVariants['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
227             break;
228           case 'gotoXMouseType':
229             $this->MouseTypes['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
230             break;
231           case 'gotoXMouseport':
232             $this->MousePorts['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
233             break;
234         }
235       }
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     /* Assign acls */
260     $tmp= $this->plInfo();
261     foreach($tmp['plProvidedAcls'] as $name => $translation){
262       $smarty->assign($name."ACL",$this->getacl($name));
263     }
266     /* Arrays */ 
267     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
268           "gotoScannerModels", "XKbModels","XKbVariants",
269           "MouseTypes", "MousePorts") as $val){
270       $smarty->assign("$val", $this->$val);
271     }
272     $smarty->assign("XKbLayouts",   $this->XKbLayouts);
273     $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
274   
275     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
276     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
277     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
278     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
280     /* Variables - select */
281     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath", 
282           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
283           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
284           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
286       $smarty->assign($val."_select", $this->$val);
287     }
289     /* Variables */
290     foreach(array("gotoXHsync", "gotoXVsync") as $val){
291       $smarty->assign($val, $this->$val);
292     }
293     $smarty->assign("staticAddress", "");
295     /* Checkboxes */
296     foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
297       if ($this->$val == TRUE) {
298         $smarty->assign("$val", "checked");
299       } else {
300         $smarty->assign("$val", "");
301       }
302     }
304     /* Phone stuff */
305     $smarty->assign ("goFonHardware", $this->goFonHardware);
306     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
307          _("Choose the phone located at the current terminal")."\" >\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     /* Show main page */
326     return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
327   }
329   function remove_from_parent()
330   {
331     $this->handle_post_events("remove");
332   }
335   /* Save data to object */
336   function save_object()
337   {
338     plugin::save_object();
340     /* Save checkbox state */
341     if (isset ($_POST['gotoXMethod'])){
342       foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
344         if($this->acl_is_writeable($val)){
345           if (!isset ($_POST["$val"])){
346             $this->$val= FALSE;
347           } else {
348             $this->$val= TRUE;
349           }
350         }
351       }
352     }
353   }
356   /* Check supplied data */
357   function check()
358   {
359     /* Call common method to give check the hook */
360     $message= plugin::check();
362     /* Default entries can use blank hsync/vsync entries */
363     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
365       /* Check vsync for correct usage */
366       $val= preg_replace ("/\s/", "", $this->gotoXVsync);
367       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
368           && $this->acl_is_writeable("gotoXVsync")){
370         $message[]= _("Please specify a valid VSync range.");
371       } elseif ($this->acl_is_writeable("gotoXVsync")){
372         list($v1,$v2)= split ("-", $val);
373         if ($v2 != ""){
374           if ($v1 > $v2){
375             $message[]= _("Please specify a valid VSync range.");
376           }
377         }
378       }
380       /* Check hsync for correct usage */
381       $val= preg_replace ("/\s/", "", $this->gotoXHsync);
382       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
383           && $this->acl_is_writeable("gotoXHsync")){
385         $message[]= _("Please specify a valid HSync range.");
386       } elseif ($this->acl_is_writeable("gotoXHsync")){
387         list($v1,$v2)= split ("-", $val);
388         if ($v2 != ""){
389           if ($v1 > $v2){
390             $message[]= _("Please specify a valid HSync range.");
391           }
392         }
393       }
394     }
395     return ($message);
396   }
399   /* Save to LDAP */
400   function save()
401   {
402     plugin::save();
404     /* Strip out 'default' values */
405     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
406           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
407           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
408           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
410       if ($this->attrs[$val] == "default"){
411         $this->attrs[$val]= array();
412       }
413     }
415     /* Write back to ldap */
416     $ldap= $this->config->get_ldap_link();
417     $ldap->cd($this->dn);
418     $this->cleanup();
419     $ldap->modify ($this->attrs); 
421     show_ldap_error($ldap->get_error(), sprintf(_("Saving of object system terminal/service with dn '%s' failed."),$this->dn));
422     $this->handle_post_events("modify");
423   }
426 /* Return plugin informations for acl handling */
427   function plInfo()
428   {
429     return (array(
430           "plShortName"   => _("Service"),
431           "plDescription" => _("Terminal service"),
432           "plSelfModify"  => FALSE,
433           "plDepends"     => array(),
434           "plPriority"    => 3,
435           "plSection"     => array("administration"),
436           "plCategory"    => array("terminal"),
438           "plProvidedAcls"=> array(
439             "gotoXMonitor"            => _("Monitor"),
440             "gotoXMethod"             => _("Method"),
441             "gotoXdmcpServer"         => _("Remote desktop"),
442             "gotoFontPath"            => _("Font path"),
443             "gotoXDriver"             => _("Gfx driver"),
444             "gotoXResolution"         => _("Gfx resolution"),
445             "gotoXColordepth"         => _("Gfx color depth"),
446             "gotoXHsync"              => _("Hsync"),
447             "gotoXVsync"              => _("Vsync"),
448             "gotoLpdEnable"           => _("Printer service enabled"),
449             "gotoLpdServer"           => _("Spool server"),
450             "gotoScannerEnable"       => _("Scanner enabled"),
451             "gotoScannerModel"        => _("Scanner model"),
452             "gotoScannerClients"      => _(""),
453             "gotoScannerBackend"      => _(""),
454             "gotoXKbModel"            => _("Keyboard model"),
455             "gotoXKbLayout"           => _("Keyboard layout"),
456             "gotoXKbVariant"          => _("Keyboard variant"),
457             "gotoXMouseType"          => _("Mouse type"),
458             "gotoXMouseport"          => _("Mouse port"),
459             "goFonHardware"           => _("Telephone hardware"))
460           ));
461   }
464 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
465 ?>