Code

Add vboxvideo to video driver list
[gosa.git] / trunk / gosa-plugins / goto / admin / systems / goto / class_workstationService.inc
1 <?php
3 class workservice extends plugin
4 {
5   var $gotoScannerEnable;
7   /* Generic terminal attributes */
8   var $gotoXMonitor= "";
9   var $gotoXDriver= "";
10   var $gotoXResolution= "";
11   var $gotoXColordepth= "";
12   var $gotoXHsync= "";
13   var $gotoXVsync= "";
14   var $AutoSync = false;
15   var $gotoXKbModel= "";
16   var $gotoXKbLayout= "";
17   var $gotoXKbVariant= "";
18   var $gotoXMouseType= "";
19   var $gotoXMouseport= "";
20   var $gotoScannerClients= "";
21   var $gotoScannerBackend= "";
22   var $goFonHardware= "automatic";
23   var $view_logged = FALSE;
25   /* Needed values and lists */
26   var $ignore_account= TRUE;
27   var $base= "";
28   var $cn= "";
29   var $orig_dn= "";
30   var $XDrivers= array();
31   var $XResolutions = array();
32   var $MouseTypes= array();
33   var $MousePorts= array();
34   var $hardware_list= array();
35   var $used_hardware= array();
38   /* attribute list for save action */
39   var $attributes= array("gotoXMonitor", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
40       "gotoXHsync", "gotoXVsync",
41       "gotoScannerEnable", "gotoScannerClients",
42       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
43       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
44   var $objectclasses= array("GOhard");
46   var $XColordepths     =array();
47   var $XKbModels        =array();
48   var $XKbLayouts       =array();
49   var $XKbVariants      =array();
51   function workservice (&$config, $dn= NULL, $parent= NULL)
52   {
53     plugin::plugin ($config, $dn, $parent);
55     $this->XResolutions= array( 
56         "640x480"   =>  "640x480",
57         "800x600"   =>  "800x600",
58         "1024x768"  =>  "1024x768",
59         "1152x864"  =>  "1152x864", 
60         "1280x1024" =>  "1280x1024",
61         "1400x1050" =>  "1400x1050", 
62         "1600x1200" =>  "1600x1200");
64     if($this->config->get_cfg_value("resolutions") != ""){
65       $file = $this->config->get_cfg_value("resolutions");
67       if(is_readable($file)){
68         $str = file_get_contents($file);
69         $lines = split("\n",$str);
70         foreach($lines as $line){
71           $line = trim($line);
72           if(!empty($line)){
73             $this->XResolutions[$line]=$line;
74           }
75         }
76         //natcasesort($this->gotoXResolutions);
77       }else{
78         msg_dialog::display(_("Configuration error"), msgPool::cannotReadFile($file), WARNING_DIALOG);
79       }
80     }
82     /* Get list of available xdrivers */
83     $this->XDrivers = $this->getListOfXDrivers();
85     array_unshift($this->XDrivers, "["._("unknown")."]");
86  
87     $this->XColordepths= array( 
88         "8"        => "8 " ._("bit"), 
89         "15"       => "15 "._("bit"),      
90         "16"       => "16 "._("bit"),   
91         "24"       => "24 "._("bit"));
93     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
94           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
95           "logiinetnav", "logiinternet", "macintosh", "microsoft",
96           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
97           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
98       $this->XKbModels[$type] = $type;
99     }
101     $this->MouseTypes= array("auto" => "auto",
102                              "explorerps/2" => "explorerps/2",
103                              "ImPS/2" => "ImPS/2",
104                              "PS/2" => "PS/2",
105                              "Microsoft" => "Microsoft",
106                              "Logitech" => "Logitech",);
108     $this->MousePorts= array("/dev/input/mice" => "/dev/input/mice",
109                              "/dev/mouse" => "/dev/mouse",
110                              "/dev/psaux" => "/dev/psaux",
111                              "/dev/ttyS0" => "/dev/ttyS0",
112                              "/dev/ttyS1" => "/dev/ttyS1",);
114     /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */
115     $this->XKbLayouts = array("de"=> "de","en" =>"en", "es" => "es", "us" =>"us", "fr" => "fr");
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     $this->orig_dn= $this->dn;
138     /* Load phone hardware list
139      */
140     $tmp = get_sub_list("(objectClass=goFonHardware)","",array(get_ou("phoneRDN")),
141                   $this->config->current['BASE'],array("cn","description"), GL_NO_ACL_CHECK);
142     foreach($tmp as $attrs){
143       $cn= $attrs['cn'][0];
144       $description= "";
145       if (isset($attrs['description'])){
146         $description= " - ".$attrs['description'][0];
147       }
148       $this->hardware_list[$cn]= "$cn$description";
149     }
150     $this->hardware_list["automatic"]= _("automatic");
151     ksort($this->hardware_list);
153     /* These departments may contain objects that have
154         goFonHardware set.
155      */
156     $deps_a = array(
157         get_people_ou(),
158         get_ou("ogroupRDN"),
159         get_ou("serverRDN"),
160         get_ou("terminalRDN"),
161         get_ou("workstationRDN"),
162         get_ou("printerRDN"),
163         get_ou("componentRDN"),
164         get_ou("phoneRDN"));
166     $tmp = get_sub_list("(goFonHardware=*)","",$deps_a,$this->config->current['BASE'],
167         array('cn','dn','goFonHardware'),GL_NO_ACL_CHECK);
168     foreach($tmp as $attrs){
169       $cn = $attrs['goFonHardware'][0];
170       if(isset($this->hardware_list[$cn])){
171         $this->used_hardware[$cn]= $cn;
172       }
173     }
175     if(preg_match("/\+/",$this->gotoXHsync)){
176       $this->AutoSync = true;
177       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
178       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
179     }
181     /* Load hardware list */
182     $ldap= $this->config->get_ldap_link();
183     $ldap->cd($this->config->current['BASE']);
184     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
185     if ($ldap->count() == 1){
186       $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
187                   "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
188       $attrs= $ldap->fetch();
190       foreach ($map as $name){
191         if (!isset($attrs[$name][0])){
192           continue;
193         }
194         
195         switch ($name){
196           case 'gotoXResolution':
197             $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
198             break;
199           case 'gotoXColordepth':
200             $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
201             break;
202           case 'gotoXKbModel':
203             $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
204             break;
205           case 'gotoXKbLayout':
206             $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
207             break;
208           case 'gotoXKbVariant':
209             $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
210             break;
211           case 'gotoXMouseType':
212             $this->MouseTypes= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
213             break;
214           case 'gotoXMouseport':
215             $this->MousePorts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
216             break;
217         }
219       }
221     }
223     /* Workaround to fill in inherited values if we've specified an objectclass */
224     $SelectedSystemType = session::get("SelectedSystemType");
225     if (isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
226       $this->XResolutions= array('default' => _("inherited"));
227       $this->XColordepths= array('default' => _("inherited"));
228       $this->XKbModels= array('default' => _("inherited"));
229       $this->XKbLayouts= array('default' => _("inherited"));
230       $this->XKbVariants= array('default' => _("inherited"));
231       $this->MouseTypes= array('default' => _("inherited"));
232       $this->MousePorts= array('default' => _("inherited"));
233     }
234   }
236   function execute()
237   {
238     /* Call parent execute */
239     plugin::execute();
241     if($this->is_account && !$this->view_logged){
242       $this->view_logged = TRUE;
243       new log("view","workstation/".get_class($this),$this->dn);
244     }
246     /* Do we need to flip is_account state? */
247     if (isset($_POST['modify_state'])){
248       $this->is_account= !$this->is_account;
249     }
251     /* Do we need to flip is_account state? */
252     if(isset($_POST['modify_state'])){
253       if($this->is_account && $this->acl_is_removeable()){
254         $this->is_account= FALSE;
255       }elseif(!$this->is_account && $this->acl_is_createable()){
256         $this->is_account= TRUE;
257       }
258     }
260     /* Show main page */
261     $smarty= get_smarty();
263     /* Assign ACLs */
264     $tmp = $this->plInfo();
265     foreach($tmp['plProvidedAcls'] as $name => $translated){
266       $smarty->assign($name."ACL",$this->getacl($name));
267     }
269     /* Arrays */ 
270     foreach(array("XDrivers", "XResolutions", "XColordepths",
271           "XKbModels", "XKbVariants",
272           "MouseTypes", "MousePorts") as $val){
273       $smarty->assign("$val", $this->$val);
274     }
275     $smarty->assign("XKbLayouts"    ,$this->XKbLayouts);
276     $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
278     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
279     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
280     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
282     /* Variables - select */
283     foreach(array(
284           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
285           "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
286           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
288       $smarty->assign($val."_select", $this->$val);
289     }
291     /* Variables */
292     foreach(array("gotoXHsync", "gotoXVsync") as $val){
293       $smarty->assign($val, $this->$val);
294     }
295     $smarty->assign("staticAddress", "");
297     /* Checkboxes */
298     foreach(array("gotoScannerEnable") as $val){
299       if ($this->$val == TRUE) {
300         $smarty->assign("$val", "checked");
301       } else {
302         $smarty->assign("$val", "");
303       }
304     }
306     /* Phone stuff */
307     $smarty->assign ("goFonHardware", $this->goFonHardware);
309     $perms = "";
310     if(!$this->acl_is_writeable("goFonHardware")){
311       $perms = " disabled ";
312     }
314     $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
315       _("Choose the phone located at the current terminal")."\" >";
316     foreach ($this->hardware_list as $cn => $description){
317       if ($cn == $this->goFonHardware){
318         $selected= "selected";
319       } else {
320         $selected= "";
321       }
322       if (isset($this->used_hardware[$cn])){
323         $color= "style=\"color:#A0A0A0\"";
324       } else {
325         $color= "";
326       }
327       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
328     }
329     $hl.= "</select>\n";
330     $smarty->assign ("hardware_list", $hl);
331     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
333     if($this->AutoSync){
334       $smarty->assign("AutoSyncCHK"," checked ");
335       $smarty->assign("hiddenState"," disabled ");
336     }else{
337       $smarty->assign("AutoSyncCHK"," ");
338       $smarty->assign("hiddenState","");
339     }
341     /* Show main page */
342     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
343   }
345   function remove_from_parent()
346   {
347     $this->handle_post_events("remove");
348     new log("remove","workstation/".get_class($this),$this->dn);
349   }
351   /* Save data to object */
352   function save_object()
353   {
354     plugin::save_object();
356     if((isset($_POST['workservicePosted'])) && $this->acl_is_writeable("AutoSync")) {
357       if(isset($_POST['AutoSync'])){
358         $this->AutoSync = true;
359       }else{
360         $this->AutoSync = false;
361       }
362     }
363   }
365   /* Check supplied data */
366   function check()
367   {
368     /* Call common method to give check the hook */
369     $message= plugin::check();
371     /* Default entries can use blank hsync/vsync entries */
372     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
374       /* But only if no auto sync is enabled... */
375       if (!$this->AutoSync){
377         /* Check vsync for correct usage */
378         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
380         if($this->acl_is_writeable("gotoXVsync")){
381           if(empty($val)){
382             $message[]= msgPool::required(_("VSync"));
383           }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
384             $message[]= msgPool::invalid(_("VSync"));
385           } else{
386             list($v1,$v2)= preg_split ("/[-+]/", $val);
387             if ($v2 != ""){
388               if ($v1 > $v2){
389                 $message[]= msgPool::invalid(_("VSync"));
390               }
391             }
392           }
393         }
395         /* Check hsync for correct usage */
396         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
397         if($this->acl_is_writeable("gotoXHsync")){
398           if(empty($val)){
399             $message[]= msgPool::required(_("HSync"));
400           }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
401             $message[]= msgPool::invalid(_("HSync"));
402           } else{
403             list($v1,$v2)= preg_split ("/[-+]/", $val);
404             if ($v2 != ""){
405               if ($v1 > $v2){
406                 $message[]= msgPool::invalid(_("HSync"));
407               }
408             }
409           }
410         }
411       }
412     }
414     return ($message);
415   }
418   /* Save to LDAP */
419   function save()
420   {
421     /* remove objectclass GOhard if this is an ogroup tab */
422     if(isset($this->parent->by_object['ogroup'])){
423       $this->objectclasses = array();
424     }
426     plugin::save();
428     /* Strip out 'default' values */
429     foreach(array(
430           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
431           "gotoXKbModel", "gotoXKbLayout",
432           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
434       if ($this->attrs[$val] == "default"){
435         $this->attrs[$val]= array();
436       }
437     }
439     if($this->AutoSync){
440       $this->attrs['gotoXHsync'] = "30+55";
441       $this->attrs['gotoXVsync'] = "50+70";
442     }
444     /* Write back to ldap */
445     $ldap= $this->config->get_ldap_link();
446     $ldap->cd($this->dn);
447     $this->cleanup();
450     $ldap->modify ($this->attrs); 
451     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
452     if (!$ldap->success()){
453       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
454     }
455     $this->handle_post_events("modify");
457     /* Send goto reload event to gosaSupportDaemon */
458     if(count($this->attrs)){
459       $this->send_goto_reload(); 
460     }
462   }
465   function getListOfXDrivers()
466   {
467     /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */
468     $drivers = array();
469     if (file_exists(CONFIG_DIR.'/xdrivers')){
470       $xdrivers = file (CONFIG_DIR.'/xdrivers');
471       foreach ($xdrivers as $line){
472         if (!preg_match ("/^#/", $line)){
473           $drivers[]= trim($line);
474         }
475       }
476     } else {
477       $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
478           "i128", "i740", "i810", "intel", "imstt", "mga", "neomagic", "newport", "nsc",  "nv", "nvidia",
479           "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
480           "sis", "tdfx", "tga", "trident", "tseng", "vboxvideo", "vesa", "vga", "vmware");
481     }
482     return($drivers);
483   }
486   /* Return plugin informations for acl handling */
487   static function plInfo()
488   {
489     return (array(
490           "plShortName"   => _("Service"),
491           "plDescription" => _("Workstation service"),
492           "plSelfModify"  => FALSE,
493           "plDepends"     => array(),
494           "plPriority"    => 10,
495           "plSection"     => array("administration"),
496           "plCategory"    => array("workstation","ogroups"), 
498           "plProvidedAcls"=> array(
499             "gotoXMonitor"          => _("Monitor"),
500             "gotoXDriver"           => _("Gfx driver"),
501             "gotoXResolution"       => _("Gfx resolution"),
502             "gotoXColordepth"       => _("Gfx color depth"),
503             "gotoXHsync"            => _("HSync"),
504             "gotoXVsync"            => _("VSync"),
505             "AutoSync"              => _("Use DDC"),
506             "gotoScannerEnable"     => _("Scanner enabled"),
507             "gotoXKbModel"          => _("Keyboard model"),
508             "gotoXKbLayout"         => _("Keyboard layout"),
509             "gotoXKbVariant"        => _("Keyboard variant"),
510             "gotoXMouseType"        => _("Mouse type"),
511             "gotoXMouseport"        => _("Mouse port"),
512             "goFonHardware"         => _("Telephone hardware")) 
513             ));
514   }
517   /*! \brief  Send goto_reload event to support daemon
518    */
519   function send_goto_reload()
520   {
521     if(count($this->attrs) && class_available("DaemonEvent")){
522       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
523       $o_queue = new gosaSupportDaemon();
524       if(isset($events['TRIGGERED']['DaemonEvent_goto_reload'])){
525         $evt = $events['TRIGGERED']['DaemonEvent_goto_reload'];
526         $macs = array();
528         /* Get list of macAddresses 
529          */
530         if(isset($this->parent->by_object['ogroup'])){
532           /* If we are an object group, add all member macs 
533            */
534           $p = $this->parent->by_object['ogroup'];
535           foreach($p->memberList as $dn => $obj){
536             if(preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$dn)) continue;
537             if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
538               $macs[] = $p->objcache[$dn]['macAddress'];
539             }
540           }
541         }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
543           /* We are a workstation. Add current mac.
544            */
545           $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
546           if(!empty($mac) && !preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->orig_dn)){
547             $macs[] = $mac;
548           }          
549         }
551         /* Trigger event for all member objects 
552          */
553         if(count($macs)){
554           $tmp = new $evt['CLASS_NAME']($this->config);
555           $tmp->set_type(TRIGGERED_EVENT);
556           $target = $o_queue->get_host().":".$o_queue->get_port();
557           $tmp->add_targets(array($target));
558           $tmp->set_macs($macs);
559           if(!$o_queue->append($tmp,TRUE)){
560             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
561           }
562         }
563       }
564     }
565   }
568   function PrepareForCopyPaste($source)
569   {
570     plugin::PrepareForCopyPaste($source);
572     if(preg_match("/\+/",$this->gotoXHsync)){
573       $this->AutoSync = true;
574       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
575       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
576     }
577   }
580 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
581 ?>