Code

Updated Terminal and Workstation classes.
[gosa.git] / gosa-plugins / goto / admin / systems / goto / class_workstationService.inc
1 <?php
3 class workservice 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   var $gotoScannerEnable;
11   /* Generic terminal attributes */
12   var $gotoXMonitor= "";
13   var $gotoXDriver= "";
14   var $gotoXResolution= "";
15   var $gotoXColordepth= "";
16   var $gotoXHsync= "";
17   var $gotoXVsync= "";
18   var $AutoSync = false;
19   var $gotoXKbModel= "";
20   var $gotoXKbLayout= "";
21   var $gotoXKbVariant= "";
22   var $gotoXMouseType= "";
23   var $gotoXMouseport= "";
24   var $gotoScannerClients= "";
25   var $gotoScannerBackend= "";
26   var $goFonHardware= "automatic";
27   var $view_logged = 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 $MouseTypes= array();
38   var $MousePorts= array();
39   var $hardware_list= array();
40   var $used_hardware= array();
43   /* attribute list for save action */
44   var $attributes= array("gotoXMonitor",
45       "gotoXDriver", "gotoXResolution", "gotoXColordepth",
46       "gotoXHsync", "gotoXVsync",
47       "gotoScannerEnable", "gotoScannerClients",
48       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
49       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
50   var $objectclasses= array("GOhard");
52   var $XColordepths     =array();
53   var $XKbModels        =array();
54   var $XKbLayouts       =array();
55   var $XKbVariants      =array();
57   function workservice (&$config, $dn= NULL, $parent= NULL)
58   {
59     plugin::plugin ($config, $dn, $parent);
61     $this->XResolutions= array( 
62         "640x480"   =>  "640x480",
63         "800x600"   =>  "800x600",
64         "1024x768"  =>  "1024x768",
65         "1152x864"  =>  "1152x864", 
66         "1280x1024" =>  "1280x1024",
67         "1400x1050" =>  "1400x1050", 
68         "1600x1200" =>  "1600x1200");
70     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
71       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
73       if(is_readable($file)){
74         $str = file_get_contents($file);
75         $lines = split("\n",$str);
76         foreach($lines as $line){
77           $line = trim($line);
78           if(!empty($line)){
79             $this->XResolutions[$line]=$line;
80           }
81         }
82         //natcasesort($this->gotoXResolutions);
83       }else{
84         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
85       }
86     }
88     /* Get list of available xdrivers */
89     $this->XDrivers = $this->getListOfXDrivers();
91     array_unshift($this->XDrivers, "["._("unknown")."]");
92  
93     $this->XColordepths= array( 
94         "8"        => "8 " ._("bit"), 
95         "15"       => "15 "._("bit"),      
96         "16"       => "16 "._("bit"),   
97         "24"       => "24 "._("bit"));
99     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
100           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
101           "logiinetnav", "logiinternet", "macintosh", "microsoft",
102           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
103           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
104       $this->XKbModels[$type] = $type;
105     }
107     $this->MouseTypes= array("ImPS/2" => "ImPS/2", "PS/2" => "PS/2", "Microsoft" => "Microsoft", 
108                               "Logitech" => "Logitech","explorerps/2"=>"explorerps/2",);
110     $this->MousePorts= array("/dev/ttyS0"  =>"/dev/ttyS0", 
111                              "/dev/ttyS1"       => "/dev/ttyS1",          "/dev/psaux"  =>"/dev/psaux", 
112                              "/dev/input/mice"  => "/dev/input/mice");
114     /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */
115     $this->XKbLayouts= array ("de"=> "de","intl" =>"intl","us" =>"us");
116     $this->XKbVariants= array ("nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
118     /* try to read additional keyboard layouts 
119      */
120     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
121       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
122         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
123         $tmp = split("\n",$str);
124         foreach($tmp as $entry){
125           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
126             $entry = trim($entry);
127             $tmp2 = split ("\:",$entry);
128             $la =   trim($tmp2[0]);   // What would be saved to ldap
129             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
130             $this->XKbLayouts [ $la] = $da;  
131           } 
132         }
133       }
134     }
136     /* Initialize methods */
137     $this->XMethods["indirect"]= _("show chooser");
138     $this->XMethods["query"]= _("direct");
139     #$this->XMethods["squery"]= _("direct via ssh");
140     #$this->XMethods["nquery"]= _("direct via nx");
141     $this->XMethods["load"]= _("load balanced");
142     #$this->XMethods["sload"]= _("load balanced via ssh");
143     #$this->XMethods["nload"]= _("load balanced via nx");
144     $this->XMethods["rdp"]= _("Windows RDP");
145     $this->XMethods["citrix"]= _("ICA client");
147     $this->orig_dn= $this->dn;
158     /* Load phone hardware list
159      */
160     $ldap= $this->config->get_ldap_link();
161     $deps = array();
162     $ou = preg_replace("/,.*$/","",get_ou("phoneou"));
163     if(!empty($ou)){
164       $ldap->cd($this->config->current['BASE']);
165       $ldap->search("(&(objectClass=organizationalUnit)(".$ou."))",array("dn"));
166       while($attrs = $ldap->fetch()){
167         $deps[] = $attrs['dn'];
168       }
169     }else{
171       /* Phone ou seems to be empty, fall back to overall base .
172        */
173       $deps[] = $this->config->current['BASE'];
174     }
175     foreach($deps as $dep){
176       $ldap->cd($dep);
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       }
187     }
191     /* Eventually colorize phones */
192     $deps = array();
193     $ou = preg_replace("/,.*$/","",get_ou("systemsou"));
194     $deps_a = array(get_ou("ogroupou"),
195                     get_ou("serverou"),
196                     get_ou("terminalou"),
197                     get_ou("workstationou"),
198                     get_ou("printerou"),
199                     get_ou("componentou"),
200                     get_ou("phoneou"));
201     if(!empty($ou)){
202       $ldap->cd($this->config->current['BASE']);
203       $ldap->search("(&(objectClass=organizationalUnit)(".$ou."))",array("dn"));
204       while($attrs = $ldap->fetch()){
205         foreach($deps_a as $allowed){
206             $to_add = preg_replace("/".get_ou('systemsou')."$/","",$allowed);
207             $deps[] = $to_add.$attrs['dn'];
208         }
209       }
210     }else{
212       /* Phone ou seems to be empty, fall back to overall base .
213        */
214       $deps[] = $this->config->current['BASE'];
215     }
217     foreach($deps as $dep){
218       $ldap->cd($dep);
219       $ldap->search("(goFonHardware=*)",array('cn','dn','goFonHardware'));
220       while($attrs = $ldap->fetch()){
221         $cn = $attrs['goFonHardware'][0];
222         if(isset($this->hardware_list[$cn])){
223           $this->used_hardware[$cn]= $cn;
224         }
225       }
226     }
227     $this->hardware_list["automatic"]= _("automatic");
228     ksort($this->hardware_list);
230     if(preg_match("/\+/",$this->gotoXHsync)){
231       $this->AutoSync = true;
232       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
233       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
234     }
236     /* Load hardware list */
237     $ldap= $this->config->get_ldap_link();
238     $ldap->cd($this->config->current['BASE']);
239     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
240     if ($ldap->count() == 1){
241       $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
242                   "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
243       $attrs= $ldap->fetch();
245       foreach ($map as $name){
246         if (!isset($attrs[$name][0])){
247           continue;
248         }
249         
250         switch ($name){
251           case 'gotoXResolution':
252             $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
253             break;
254           case 'gotoXColordepth':
255             $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
256             break;
257           case 'gotoXKbModel':
258             $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
259             break;
260           case 'gotoXKbLayout':
261             $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
262             break;
263           case 'gotoXKbVariant':
264             $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
265             break;
266           case 'gotoXMouseType':
267             $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
268             break;
269           case 'gotoXMouseport':
270             $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
271             break;
272         }
274       }
276     }
278     /* Workaround to fill in inherited values if we've specified an objectclass */
279     $SelectedSystemType = session::get("SelectedSystemType");
280     if (isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
281       $this->XResolutions= array('default' => _("inherited"));
282       $this->XColordepths= array('default' => _("inherited"));
283       $this->XKbModels= array('default' => _("inherited"));
284       $this->XKbLayouts= array('default' => _("inherited"));
285       $this->XKbVariants= array('default' => _("inherited"));
286       $this->MouseTypes= array('AUTO' => _("inherited"));
287       $this->MousePorts= array('AUTO' => _("inherited"));
288     }
289   }
291   function execute()
292   {
293     /* Call parent execute */
294     plugin::execute();
296     if($this->is_account && !$this->view_logged){
297       $this->view_logged = TRUE;
298       new log("view","workstation/".get_class($this),$this->dn);
299     }
301     /* Do we need to flip is_account state? */
302     if (isset($_POST['modify_state'])){
303       $this->is_account= !$this->is_account;
304     }
306     /* Do we need to flip is_account state? */
307     if(isset($_POST['modify_state'])){
308       if($this->is_account && $this->acl_is_removeable()){
309         $this->is_account= FALSE;
310       }elseif(!$this->is_account && $this->acl_is_createable()){
311         $this->is_account= TRUE;
312       }
313     }
315     /* Show main page */
316     $smarty= get_smarty();
318     /* Assign ACLs */
319     $tmp = $this->plInfo();
320     foreach($tmp['plProvidedAcls'] as $name => $translated){
321       $smarty->assign($name."ACL",$this->getacl($name));
322     }
324     /* Arrays */ 
325     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
326           "XKbModels", "XKbVariants",
327           "MouseTypes", "MousePorts") as $val){
328       $smarty->assign("$val", $this->$val);
329     }
330     $smarty->assign("XKbLayouts"    ,$this->XKbLayouts);
331     $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
333     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
334     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
335     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
337     /* Variables - select */
338     foreach(array(
339           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
340           "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
341           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
343       $smarty->assign($val."_select", $this->$val);
344     }
346     /* Variables */
347     foreach(array("gotoXHsync", "gotoXVsync") as $val){
348       $smarty->assign($val, $this->$val);
349     }
350     $smarty->assign("staticAddress", "");
352     /* Checkboxes */
353     foreach(array("gotoScannerEnable") as $val){
354       if ($this->$val == TRUE) {
355         $smarty->assign("$val", "checked");
356       } else {
357         $smarty->assign("$val", "");
358       }
359     }
361     /* Phone stuff */
362     $smarty->assign ("goFonHardware", $this->goFonHardware);
364     $perms = "";
365     if(!$this->acl_is_writeable("goFonHardware")){
366       $perms = " disabled ";
367     }
369     $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
370       _("Choose the phone located at the current terminal")."\" >";
371     foreach ($this->hardware_list as $cn => $description){
372       if ($cn == $this->goFonHardware){
373         $selected= "selected";
374       } else {
375         $selected= "";
376       }
377       if (isset($this->used_hardware[$cn])){
378         $color= "style=\"color:#A0A0A0\"";
379       } else {
380         $color= "";
381       }
382       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
383     }
384     $hl.= "</select>\n";
385     $smarty->assign ("hardware_list", $hl);
386     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
388     if($this->AutoSync){
389       $smarty->assign("AutoSyncCHK"," checked ");
390       $smarty->assign("hiddenState"," disabled ");
391     }else{
392       $smarty->assign("AutoSyncCHK"," ");
393       $smarty->assign("hiddenState","");
394     }
396     /* Show main page */
397     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
398   }
400   function remove_from_parent()
401   {
402     $this->handle_post_events("remove");
403     new log("remove","workstation/".get_class($this),$this->dn);
404   }
406   /* Save data to object */
407   function save_object()
408   {
409     plugin::save_object();
411     if((isset($_POST['gotoXDriver'])) && $this->acl_is_writeable("AutoSync")) {
412       if(isset($_POST['AutoSync'])){
413         $this->AutoSync = true;
414       }else{
415         $this->AutoSync = false;
416       }
417     }
418   }
420   /* Check supplied data */
421   function check()
422   {
423     /* Call common method to give check the hook */
424     $message= plugin::check();
426     /* Default entries can use blank hsync/vsync entries */
427     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
429       /* But only if no auto sync is enabled... */
430       if (!$this->AutoSync){
432         /* Check vsync for correct usage */
433         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
435         if($this->acl_is_writeable("gotoXVsync")){
436           if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
437             $message[]= _("Please specify a valid VSync range.");
438           } else{
439             list($v1,$v2)= preg_split ("/[-+]/", $val);
440             if ($v2 != ""){
441               if ($v1 > $v2){
442                 $message[]= _("Please specify a valid VSync range.");
443               }
444             }
445           }
446         }
448         /* Check hsync for correct usage */
449         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
450         if($this->acl_is_writeable("gotoXHsync")){
451           if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
452             $message[]= _("Please specify a valid HSync range.");
453           } else{
454             list($v1,$v2)= preg_split ("/[-+]/", $val);
455             if ($v2 != ""){
456               if ($v1 > $v2){
457                 $message[]= _("Please specify a valid HSync range.");
458               }
459             }
460           }
461         }
462       }
463     }
465     return ($message);
466   }
469   /* Save to LDAP */
470   function save()
471   {
472     /* remove objectclass GOhard if this is an ogroup tab */
473     if(isset($this->parent->by_object['ogroup'])){
474       $this->objectclasses = array();
475     }
477     plugin::save();
479     /* Strip out 'default' values */
480     foreach(array(
481           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
482           "gotoXKbModel", "gotoXKbLayout",
483           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
485       if ($this->attrs[$val] == "default"){
486         $this->attrs[$val]= array();
487       }
488     }
490     if($this->AutoSync){
491       $this->attrs['gotoXHsync'] = "30+55";
492       $this->attrs['gotoXVsync'] = "50+70";
493     }
495     /* Write back to ldap */
496     $ldap= $this->config->get_ldap_link();
497     $ldap->cd($this->dn);
498     $this->cleanup();
499     $ldap->modify ($this->attrs); 
500     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
501     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/service with dn '%s' failed."),$this->dn));
502     $this->handle_post_events("modify");
503   }
506   function getListOfXDrivers()
507   {
508     /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */
509     $drivers = array();
510     if (file_exists(CONFIG_DIR.'/xdrivers')){
511       $xdrivers = file (CONFIG_DIR.'/xdrivers');
512       foreach ($xdrivers as $line){
513         if (!preg_match ("/^#/", $line)){
514           $drivers[]= trim($line);
515         }
516       }
517     } else {
518       $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
519           "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv", "nvidia",
520           "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
521           "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
522     }
523     return($drivers);
524   }
527   /* Return plugin informations for acl handling */
528   static function plInfo()
529   {
530     return (array(
531           "plShortName"   => _("Service"),
532           "plDescription" => _("Workstation service"),
533           "plSelfModify"  => FALSE,
534           "plDepends"     => array(),
535           "plPriority"    => 10,
536           "plSection"     => array("administration"),
537           "plCategory"    => array("workstation","ogroups"), 
539           "plProvidedAcls"=> array(
540             "gotoXMonitor"          => _("Monitor"),
541             "gotoXDriver"           => _("Gfx driver"),
542             "gotoXResolution"       => _("Gfx resolution"),
543             "gotoXColordepth"       => _("Gfx color depth"),
544             "gotoXHsync"            => _("Hsync"),
545             "gotoXVsync"            => _("Vsync"),
546             "AutoSync"              => _("Use DDC"),
547             "gotoScannerEnable"     => _("Scanner enabled"),
548             "gotoXKbModel"          => _("Keyboard model"),
549             "gotoXKbLayout"         => _("Keyboard layout"),
550             "gotoXKbVariant"        => _("Keyboard variant"),
551             "gotoXMouseType"        => _("Mouse type"),
552             "gotoXMouseport"        => _("Mouse port"),
553             "goFonHardware"         => _("Telephone hardware")) 
554             ));
555   }
558 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
559 ?>