Code

Updated Terminal Service.
[gosa.git] / gosa-plugins / goto / admin / systems / goto / 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 $gotoXDriver= "";
16   var $gotoXResolution= "";
17   var $gotoXColordepth= "";
18   var $gotoXHsync= "";
19   var $gotoXVsync= "";
20   var $gotoXKbModel= "";
21   var $gotoXKbLayout= "";
22   var $gotoXKbVariant= "";
23   var $gotoXMouseType= "";
24   var $gotoXMouseport= "";
25   var $gotoLpdServer= "";
26   var $gotoScannerEnable= "";
27   var $gotoScannerModel= "";
28   var $gotoScannerClients= "";
29   var $gotoScannerBackend= "";
30   var $goFonHardware= "automatic";
32   var $AutoSync = false;
33   var $view_logged = FALSE;
35   /* Needed values and lists */
36   var $ignore_account= TRUE;
37   var $base= "";
38   var $cn= "";
39   var $orig_dn= "";
40   var $XMethods= array();
41   var $XDrivers= array();
42   var $XResolutions= array();
43   var $XColordepths= array();
44   var $XKbModels= array ();
45   var $XKbLayouts= array ();
46   var $XKbVariants= array ();
47   var $MouseTypes= array();
48   var $MousePorts= array();
49   var $hardware_list= array();
50   var $used_hardware= array();
53   /* attribute list for save action */
54   var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
55       "gotoXDriver", "gotoXResolution", "gotoXColordepth",
56       "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
57       "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
58       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
59       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
60   var $objectclasses= array("GOhard");
62   var $is_ogroup        = FALSE;
63   var $is_ogroup_member = FALSE;
65   function termservice (&$config, $dn= NULL, $parent= NULL)
66   {
67     plugin::plugin ($config, $dn, $parent);
68     $this->orig_dn= $this->dn;
70     /* Check if we are a part of an ogroup.
71      * In this case, we have to hide all the inherit stuff.
72      */ 
73     if(isset($parent) && get_class($parent) == "ogroup"){
74       $this->is_ogroup = TRUE;
75     }
77     /* Check if we are member of an object group.
78      */
79     $ldap= $this->config->get_ldap_link();
80     $ldap->cd($this->config->current['BASE']);
81     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
82     if($ldap->count()){
83       $this->is_ogroup_member = TRUE;
84     }
86     /* Get list of available xdrivers */
87     $this->XDrivers = $this->getListOfXDrivers();
89     /* Create a list of available resolutions.
90      */     
91     $this->XResolutions= array(
92           "640x480"   =>  "640x480",
93           "800x600"   =>  "800x600",
94           "1024x768"  =>  "1024x768",
95           "1152x864"  =>  "1152x864",
96           "1280x1024" =>  "1280x1024",
97           "1400x1050" =>  "1400x1050",
98           "1600x1200" =>  "1600x1200");
100     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
101       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
102       if(is_readable($file)){
103         $str = file_get_contents($file);
104         $lines = split("\n",$str);
105         foreach($lines as $line){
106           $line = trim($line);
107           if(!empty($line)){
108             $this->XResolutions[$line]=$line;
109           }
110         }
111       }else{
112         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
113       }
114     }
116     /* Create a set of selectable color depths
117      */
118     $this->XColordepths= array(
119         "8"        => "8 " ._("bit"),
120         "15"       => "15 "._("bit"),
121         "16"       => "16 "._("bit"),
122         "24"       => "24 "._("bit"));
124     
125     /* Create a set of selectable keyboard models
126      */
127     $this->XKbModels = array();
128     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
129           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
130           "logiinetnav", "logiinternet", "macintosh", "microsoft",
131           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
132           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
133       $this->XKbModels[$type] = $type;
134     }
136     /* Additional values will be extracted from CONFIG_DIR.keyboardLayouts */
137     $this->XKbLayouts = array("de"=> "de","intl" =>"intl","us" =>"us");
138     $this->XKbVariants= array("nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
139     $this->MouseTypes = array("ImPS/2"=>"ImPS/2","PS/2"=>"PS/2",
140                               "Microsoft"=>"Microsoft","Logitech"=>"Logitech");
141     $this->MousePorts = array("/dev/ttyS0"=>"/dev/ttyS0",
142                               "/dev/ttyS1"=>"/dev/ttyS1","/dev/psaux"=>"/dev/psaux", 
143                               "/dev/input/mice"=>"/dev/input/mice");
144  
146     /* Try to read additional keyboard layouts
147      */
148     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
149       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
150         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
151         $tmp = split("\n",$str);
152         foreach($tmp as $entry){
153           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
154             $entry = trim($entry);
155             $tmp2 = split ("\:",$entry);
156             $la =   trim($tmp2[0]);   // What would be saved to ldap
157             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
158             $this->XKbLayouts [ $la] = $da;
159           }
160         }
161       }
162     }
164     /* Terminal server methods 
165      */
166     $this->XMethods["default"]= _("default");
167     $this->XMethods["xdmcp"]  = _("XDMCP");
168     $this->XMethods["ldm"]    = _("LDM");
169     $this->XMethods["rdp"]    = _("Windows RDP");
170     $this->XMethods["citrix"] = _("ICA client");
173     /* Load phone hardware list 
174      */
175     $ldap= $this->config->get_ldap_link();
176     $ldap->cd($this->config->current['BASE']);
177     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
178     while ($attrs= $ldap->fetch()){
179       $cn= $attrs['cn'][0];
180       if (isset($attrs['description'])){
181         $description= " - ".$attrs['description'][0];
182       } else {
183         $description= "";
184       }
185       $this->hardware_list[$cn]= "$cn$description";
186     }
188     /* Eventually colorize phones */
189     $ldap->cd($this->config->current['BASE']);
190     $ldap->search("(goFonHardware=*)",array('cn','dn','goFonHardware'));
191     while($attrs = $ldap->fetch()){
192         $cn = $attrs['goFonHardware'][0];
193         if(isset($this->hardware_list[$cn])){
194           $this->used_hardware[$cn]= $cn;
195         }
196     }
197     $this->hardware_list["automatic"]= _("automatic");
198     ksort($this->hardware_list);
200     /* Convert gotoLpdEnable 
201      */
202     $this->gotoLpdEnable= preg_match("/yes/i",$this->gotoLpdEnable);
205     /* Load hardware list */
206     $ldap= $this->config->get_ldap_link();
207     $ldap->cd($this->config->current['BASE']);
208     $map= array(
209         "gotoXResolution", 
210         "gotoXColordepth", 
211         "gotoXKbModel", 
212         "gotoXKbLayout",
213 #        "gotoXDriver",
214         "gotoXKbVariant",
215         "gotoXMouseType", 
216         "gotoXMethod",
217         "gotoXMouseport");
218     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",$map);
219     if ($ldap->count() == 1){
220       $attrs= $ldap->fetch();
221       foreach ($map as $name){
222         if (!isset($attrs[$name][0])){
223           continue;
224         }
226         switch ($name){
227 #         case 'gotoXDriver': 
228 #           $this->XDrivers = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers;
229 #           break;
230           case 'gotoXMethod': 
231             $this->XMethods = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XMethods;
232             break;
233           case 'gotoXResolution':
234             $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
235             break;
236           case 'gotoXColordepth':
237             $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
238             break;
239           case 'gotoXKbModel':
240             $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
241             break;
242           case 'gotoXKbLayout':
243             $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
244             break;
245           case 'gotoXKbVariant':
246             $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
247             break;
248           case 'gotoXMouseType':
249             $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
250             break;
251           case 'gotoXMouseport':
252             $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
253             break;
254         }
255       }
256     }
258     if(preg_match("/\+/",$this->gotoXHsync)){
259       $this->AutoSync = true;
260       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
261       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
262     }
263   }
266   function execute()
267   {
268     /* Call parent execute */
269     plugin::execute();
271     if($this->is_account && !$this->view_logged){
272       $this->view_logged = TRUE;
273       new log("view","terminal/".get_class($this),$this->dn);
274     }
276     /* Do we need to flip is_account state? */
277     if (isset($_POST['modify_state'])){
278       $this->is_account= !$this->is_account;
279     }
281     /* Do we represent a valid terminal? */
282     if (!$this->is_account && $this->parent === NULL){
283       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
284         _("This 'dn' has no terminal features.")."</b>";
285       return ($display);
286     }
288     /* Show main page */
289     $smarty= get_smarty();
291     /* Assign acls */
292     $tmp= $this->plInfo();
293     foreach($tmp['plProvidedAcls'] as $name => $translation){
294       $smarty->assign($name."ACL",$this->getacl($name));
295     }
298     /* Arrays */ 
299     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
300           "XKbModels","XKbVariants",
301           "MouseTypes", "MousePorts") as $val){
302       $smarty->assign("$val", $this->$val);
303     }
304     $smarty->assign("XKbLayouts",   $this->XKbLayouts);
305     $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
306   
307     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
308     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
310     /* Variables - select */
311     foreach(array("gotoXMethod", "gotoXdmcpServer", 
312           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
313           "gotoLpdServer", "gotoXKbModel", "gotoXKbLayout",
314           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
316       $smarty->assign($val."_select", $this->$val);
317     }
319     /* Variables */
320     foreach(array("gotoXHsync", "gotoXVsync") as $val){
321       $smarty->assign($val, $this->$val);
322     }
323     $smarty->assign("staticAddress", "");
325     /* Checkboxes */
326     foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
327       if ($this->$val == TRUE) {
328         $smarty->assign("$val", "checked");
329       } else {
330         $smarty->assign("$val", "");
331       }
332     }
334     /* Phone stuff */
335     $smarty->assign ("goFonHardware", $this->goFonHardware);
336     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
337          _("Choose the phone located at the current terminal")."\" >\n";
338     foreach ($this->hardware_list as $cn => $description){
339       if ($cn == $this->goFonHardware){
340         $selected= "selected";
341       } else {
342         $selected= "";
343       }
344       if (isset($this->used_hardware[$cn])){
345         $color= "style=\"color:#A0A0A0\"";
346       } else {
347         $color= "";
348       }
349       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
350     }
351     $hl.= "</select>\n";
352     $smarty->assign ("hardware_list", $hl);
353     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
355     $smarty->assign("AutoSyncACL",$this->getacl("AutoSync"));
357     $smarty->assign("AutoSyncCHK"," ");
358     if($this->AutoSync){
359       $smarty->assign("AutoSyncCHK"," checked ");
360       $smarty->assign("gotoXVsyncACL", preg_replace("/w/","",$this->getacl("gotoXVsync")));
361       $smarty->assign("gotoXHsyncACL", preg_replace("/w/","",$this->getacl("gotoXHsync")));
362     }
364     /* Show main page */
365     return($smarty->fetch (get_template_path('terminalService.tpl', TRUE,dirname(__FILE__))));
366   }
368   function remove_from_parent()
369   {
370     new log("remove","terminal/".get_class($this),$this->dn,array_keys($this->attrs));
371     $this->handle_post_events("remove");
372   }
375   /* Save data to object */
376   function save_object()
377   {
378     plugin::save_object();
380     /* Save checkbox state */
381     if (isset ($_POST['gotoXMethod'])){
382       foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
384         if($this->acl_is_writeable($val)){
385           if (!isset ($_POST["$val"])){
386             $this->$val= FALSE;
387           } else {
388             $this->$val= TRUE;
389           }
390         }
391       }
392     } 
394     if(isset($_POST['gotoXDriver'])){
395       if(isset($_POST['AutoSync'])){
396         $this->AutoSync = true;
397       }else{
398         $this->AutoSync = false;
399       }
400     }
402     /* Default entries can use blank hsync/vsync entries */
403     if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){
405       /* But only if no auto sync is enabled... */
406       if (!$this->AutoSync){
408         /* Check vsync for correct usage */
409         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
410         if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXVsync")){
412           $message[]= _("Please specify a valid VSync range.");
413         } elseif ($this->acl_is_writeable("gotoXVsync")){
414           list($v1,$v2)= preg_split ("/[-+]/", $val);
415           if ($v2 != ""){
416             if ($v1 > $v2){
417               $message[]= _("Please specify a valid VSync range.");
418             }
419           }
420         }
422         /* Check hsync for correct usage */
423         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
424         if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXHsync")){
426           $message[]= _("Please specify a valid HSync range.");
427         } elseif ($this->acl_is_writeable("gotoXHsync")){
428           list($v1,$v2)= preg_split ("/[-+]/", $val);
429           if ($v2 != ""){
430             if ($v1 > $v2){
431               $message[]= _("Please specify a valid HSync range.");
432             }
433           }
434         }
435       }
436     }
437   }
440   /* Check supplied data */
441   function check()
442   {
443     /* Call common method to give check the hook */
444     $message= plugin::check();
445     return ($message);
446   }
449   /* Save to LDAP */
450   function save()
451   {
452     /* Convert to string */
453     $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
455     if(isset($this->parent->by_object['ogroup'])){
456       $this->objectclasses = array("gotoWorkstationTemplate");
457     }elseif(isset($this->parent->by_object['terminalgeneric'])){
458       $this->objectclasses = array("GOhard");
459     }else{
460       print "Object Type Configuration : unknown";
461       exit();
462     }
465     plugin::save();
467     /* Strip out 'default' values */
468     foreach(array("gotoXMethod", "gotoXdmcpServer",
469           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
470           "gotoLpdServer", "gotoXKbModel", "gotoXKbLayout",
471           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
473       if ($this->attrs[$val] == "default"){
474         $this->attrs[$val]= array();
475       }
476     }
478     if($this->AutoSync){
479       $this->attrs['gotoXHsync'] = "30+55";
480       $this->attrs['gotoXVsync'] = "50+70";
481     }
483     /* Write back to ldap */
484     $ldap= $this->config->get_ldap_link();
485     $ldap->cd($this->dn);
486     $this->cleanup();
487     $ldap->modify ($this->attrs); 
488     new log("modify","terminal/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
490     show_ldap_error($ldap->get_error(), sprintf(_("Saving of object system terminal/service with dn '%s' failed."),$this->dn));
491     $this->handle_post_events("modify");
492   }
495   function getListOfXDrivers()
496   {
497     $drivers = array("unknown" => "["._("unknown")."]");
499     /* Generate a list of xdrivers from CONFIG_DIR/xdrivers */
500     if (file_exists(CONFIG_DIR.'/xdrivers')){
501       $xdrivers = file (CONFIG_DIR.'/xdrivers');
502       foreach ($xdrivers as $line){
503         if (!preg_match ("/^#/", $line)){
504           $drivers[]= trim($line);
505         }
506       }
507     } else {
508       foreach( array(
509           "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
510           "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv", "nvidia",
511           "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
512           "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware") as $driver){
513         $drivers[] = $driver;
514       }
515     }
516     return($drivers);
517   }
520   /* Return plugin informations for acl handling */
521   static function plInfo()
522   {
523     return (array(
524           "plShortName"   => _("Service"),
525           "plDescription" => _("Terminal service"),
526           "plSelfModify"  => FALSE,
527           "plDepends"     => array(),
528           "plPriority"    => 3,
529           "plSection"     => array("administration"),
530           "plCategory"    => array("terminal"),
532           "plProvidedAcls"=> array(
533             "gotoXMonitor"            => _("Monitor"),
534             "gotoXMethod"             => _("Method"),
535             "gotoXdmcpServer"         => _("Remote desktop"),
536             "gotoXDriver"             => _("Gfx driver"),
537             "gotoXResolution"         => _("Gfx resolution"),
538             "gotoXColordepth"         => _("Gfx color depth"),
539             "gotoXHsync"              => _("Hsync"),
540             "gotoXVsync"              => _("Vsync"),
541             "AutoSync"                => _("Auto-Sync"),
542             "gotoLpdEnable"           => _("Printer service enabled"),
543             "gotoLpdServer"           => _("Spool server"),
544             "gotoScannerEnable"       => _("Scanner enabled"),
545             "gotoXKbModel"            => _("Keyboard model"),
546             "gotoXKbLayout"           => _("Keyboard layout"),
547             "gotoXKbVariant"          => _("Keyboard variant"),
548             "gotoXMouseType"          => _("Mouse type"),
549             "gotoXMouseport"          => _("Mouse port"),
550             "goFonHardware"           => _("Telephone hardware"))
551           ));
552   }
555 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
556 ?>