Code

updated templates
[gosa.git] / 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 = preg_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 = preg_split("/\n/",$str);
124         foreach($tmp as $entry){
125           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
126             $entry = trim($entry);
127             $tmp2 = explode(":",$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", "gotoXDriver");
188       $attrs= $ldap->fetch();
190       foreach ($map as $name){
191         if (!isset($attrs[$name][0])){
192           continue;
193         }
194         
195         switch ($name){
196           case 'gotoXDriver':
197             $this->XDrivers= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers;
198             break;
199           case 'gotoXResolution':
200             $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
201             break;
202           case 'gotoXColordepth':
203             $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
204             break;
205           case 'gotoXKbModel':
206             $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
207             break;
208           case 'gotoXKbLayout':
209             $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
210             break;
211           case 'gotoXKbVariant':
212             $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
213             break;
214           case 'gotoXMouseType':
215             $this->MouseTypes= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
216             break;
217           case 'gotoXMouseport':
218             $this->MousePorts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
219             break;
220         }
222       }
224     }
226     /* Workaround to fill in inherited values if we've specified an objectclass */
227     $SelectedSystemType = session::get("SelectedSystemType");
228     if (isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
229       $this->XResolutions= array('default' => _("inherited"));
230       $this->XColordepths= array('default' => _("inherited"));
231       $this->XKbModels= array('default' => _("inherited"));
232       $this->XKbLayouts= array('default' => _("inherited"));
233       $this->XKbVariants= array('default' => _("inherited"));
234       $this->MouseTypes= array('default' => _("inherited"));
235       $this->MousePorts= array('default' => _("inherited"));
236     }
237   }
239   function execute()
240   {
241     /* Call parent execute */
242     plugin::execute();
244     if($this->is_account && !$this->view_logged){
245       $this->view_logged = TRUE;
246       new log("view","workstation/".get_class($this),$this->dn);
247     }
249     /* Do we need to flip is_account state? */
250     if (isset($_POST['modify_state'])){
251       $this->is_account= !$this->is_account;
252     }
254     /* Do we need to flip is_account state? */
255     if(isset($_POST['modify_state'])){
256       if($this->is_account && $this->acl_is_removeable()){
257         $this->is_account= FALSE;
258       }elseif(!$this->is_account && $this->acl_is_createable()){
259         $this->is_account= TRUE;
260       }
261     }
263     /* Show main page */
264     $smarty= get_smarty();
266     /* Assign ACLs */
267     $tmp = $this->plInfo();
268     foreach($tmp['plProvidedAcls'] as $name => $translated){
269       $smarty->assign($name."ACL",$this->getacl($name));
270     }
272     /* Arrays */ 
273     foreach(array("XDrivers", "XResolutions", "XColordepths",
274           "XKbModels", "XKbVariants",
275           "MouseTypes", "MousePorts") as $val){
276       $smarty->assign("$val", $this->$val);
277     }
278     $smarty->assign("XKbLayouts"    ,$this->XKbLayouts);
279     $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
281     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
282     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
283     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
285     /* Variables - select */
286     foreach(array(
287           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
288           "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
289           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
291       $smarty->assign($val."_select", $this->$val);
292     }
294     /* Variables */
295     foreach(array("gotoXHsync", "gotoXVsync") as $val){
296       $smarty->assign($val, $this->$val);
297     }
298     $smarty->assign("staticAddress", "");
300     /* Checkboxes */
301     foreach(array("gotoScannerEnable") as $val){
302       if ($this->$val == TRUE) {
303         $smarty->assign("$val", "checked");
304       } else {
305         $smarty->assign("$val", "");
306       }
307     }
309     /* Phone stuff */
310     $smarty->assign ("goFonHardware", $this->goFonHardware);
312     $perms = "";
313     if(!$this->acl_is_writeable("goFonHardware")){
314       $perms = " disabled ";
315     }
317     $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
318       _("Choose the phone located at the current terminal")."\" >";
319     foreach ($this->hardware_list as $cn => $description){
320       if ($cn == $this->goFonHardware){
321         $selected= "selected";
322       } else {
323         $selected= "";
324       }
325       if (isset($this->used_hardware[$cn])){
326         $color= "style=\"color:#A0A0A0\"";
327       } else {
328         $color= "";
329       }
330       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
331     }
332     $hl.= "</select>\n";
333     $smarty->assign ("hardware_list", $hl);
334     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
336     if($this->AutoSync){
337       $smarty->assign("AutoSyncCHK"," checked ");
338       $smarty->assign("hiddenState"," disabled ");
339     }else{
340       $smarty->assign("AutoSyncCHK"," ");
341       $smarty->assign("hiddenState","");
342     }
344     /* Show main page */
345     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
346   }
348   function remove_from_parent()
349   {
350     $this->handle_post_events("remove");
351     new log("remove","workstation/".get_class($this),$this->dn);
352   }
354   /* Save data to object */
355   function save_object()
356   {
357     plugin::save_object();
359     if((isset($_POST['workservicePosted'])) && $this->acl_is_writeable("AutoSync")) {
360       if(isset($_POST['AutoSync'])){
361         $this->AutoSync = true;
362       }else{
363         $this->AutoSync = false;
364       }
365     }
366   }
368   /* Check supplied data */
369   function check()
370   {
371     /* Call common method to give check the hook */
372     $message= plugin::check();
374     /* Default entries can use blank hsync/vsync entries */
375     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
377       /* But only if no auto sync is enabled... */
378       if (!$this->AutoSync){
380         /* Check vsync for correct usage */
381         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
383         if($this->acl_is_writeable("gotoXVsync")){
384           if(empty($val)){
385             $message[]= msgPool::required(_("VSync"));
386           }elseif (!preg_match ("/^\d+(\.\d+)?([+-]\d+(\.\d+)?)?$/", $val)){
387             $message[]= msgPool::invalid(_("VSync"));
388           } else{
389             if (!preg_match('/^\d+$/', $val)){
390               list($v1,$v2)= preg_split ("/[-+]/", $val);
391               if ($v2 != ""){
392                 if ($v1 > $v2){
393                   $message[]= msgPool::invalid(_("VSync"));
394                 }
395               }
396             }
397           }
398         }
400         /* Check hsync for correct usage */
401         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
402         if($this->acl_is_writeable("gotoXHsync")){
403           if(empty($val)){
404             $message[]= msgPool::required(_("HSync"));
405           }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
406             $message[]= msgPool::invalid(_("HSync"));
407           } else{
408             if (!preg_match('/^\d+$/', $val)){
409               list($v1,$v2)= preg_split ("/[-+]/", $val);
410               if ($v2 != ""){
411                 if ($v1 > $v2){
412                   $message[]= msgPool::invalid(_("HSync"));
413                 }
414               }
415             }
416           }
417         }
418       }
419     }
421     return ($message);
422   }
425   /* Save to LDAP */
426   function save()
427   {
428     /* remove objectclass GOhard if this is an ogroup tab */
429     if(isset($this->parent->by_object['ogroup'])){
430       $this->objectclasses = array();
431     }
433     plugin::save();
435     /* Strip out 'default' values */
436     foreach(array(
437           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
438           "gotoXKbModel", "gotoXKbLayout",
439           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
441       if ($this->attrs[$val] == "default"){
442         $this->attrs[$val]= array();
443       }
444     }
446     if($this->AutoSync){
447       $this->attrs['gotoXHsync'] = "30+55";
448       $this->attrs['gotoXVsync'] = "50+70";
449     }
451     /* Write back to ldap */
452     $ldap= $this->config->get_ldap_link();
453     $ldap->cd($this->dn);
454     $this->cleanup();
457     $ldap->modify ($this->attrs); 
458     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
459     if (!$ldap->success()){
460       msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
461     }
462     $this->handle_post_events("modify");
464     /* Send goto reload event to gosaSupportDaemon */
465     if(count($this->attrs)){
466       $this->send_goto_reload(); 
467     }
469   }
472   function getListOfXDrivers()
473   {
474     /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */
475     $drivers = array();
476     if (file_exists(CONFIG_DIR.'/xdrivers')){
477       $xdrivers = file (CONFIG_DIR.'/xdrivers');
478       foreach ($xdrivers as $line){
479         if (!preg_match ("/^#/", $line)){
480           $drivers[]= trim($line);
481         }
482       }
483     } else {
484       $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
485           "i128", "i740", "i810", "intel", "imstt", "mga", "neomagic", "newport", "nsc",  "nv", "nvidia",
486           "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
487           "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
488     } 
489     $tmp = array();
490     foreach($drivers as $name){
491       $tmp[$name] = $name;
492     }
494     return($tmp);
495   }
498   /* Return plugin informations for acl handling */
499   static function plInfo()
500   {
501     return (array(
502           "plShortName"   => _("Service"),
503           "plDescription" => _("Workstation service"),
504           "plSelfModify"  => FALSE,
505           "plDepends"     => array(),
506           "plPriority"    => 10,
507           "plSection"     => array("administration"),
508           "plCategory"    => array("workstation","ogroups"), 
510           "plProvidedAcls"=> array(
511             "gotoXMonitor"          => _("Monitor"),
512             "gotoXDriver"           => _("Gfx driver"),
513             "gotoXResolution"       => _("Gfx resolution"),
514             "gotoXColordepth"       => _("Gfx color depth"),
515             "gotoXHsync"            => _("HSync"),
516             "gotoXVsync"            => _("VSync"),
517             "AutoSync"              => _("Use DDC"),
518             "gotoScannerEnable"     => _("Scanner enabled"),
519             "gotoXKbModel"          => _("Keyboard model"),
520             "gotoXKbLayout"         => _("Keyboard layout"),
521             "gotoXKbVariant"        => _("Keyboard variant"),
522             "gotoXMouseType"        => _("Mouse type"),
523             "gotoXMouseport"        => _("Mouse port"),
524             "goFonHardware"         => _("Telephone hardware")) 
525             ));
526   }
529   /*! \brief  Send goto_reload event to support daemon
530    */
531   function send_goto_reload()
532   {
533     if(count($this->attrs) && class_available("DaemonEvent")){
534       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
535       $o_queue = new gosaSupportDaemon();
536       if(isset($events['TRIGGERED']['DaemonEvent_goto_reload'])){
537         $evt = $events['TRIGGERED']['DaemonEvent_goto_reload'];
538         $macs = array();
540         /* Get list of macAddresses 
541          */
542         if(isset($this->parent->by_object['ogroup'])){
544           /* If we are an object group, add all member macs 
545            */
546           $p = $this->parent->by_object['ogroup'];
547           foreach($p->memberList as $dn => $obj){
548             if(preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$dn)) continue;
549             if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
550               $macs[] = $p->objcache[$dn]['macAddress'];
551             }
552           }
553         }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
555           /* We are a workstation. Add current mac.
556            */
557           $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
558           if(!empty($mac) && !preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->orig_dn)){
559             $macs[] = $mac;
560           }          
561         }
563         /* Trigger event for all member objects 
564          */
565         if(count($macs)){
566           $tmp = new $evt['CLASS_NAME']($this->config);
567           $tmp->set_type(TRIGGERED_EVENT);
568           $target = $o_queue->get_host().":".$o_queue->get_port();
569           $tmp->add_targets(array($target));
570           $tmp->set_macs($macs);
571           if(!$o_queue->append($tmp,TRUE)){
572             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
573           }
574         }
575       }
576     }
577   }
580   function PrepareForCopyPaste($source)
581   {
582     plugin::PrepareForCopyPaste($source);
584     if(preg_match("/\+/",$this->gotoXHsync)){
585       $this->AutoSync = true;
586       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
587       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
588     }
589   }
592 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
593 ?>