Code

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