Code

d0d45262fdf991d43595a5c18a3c7874019eb0d3
[gosa.git] / plugins / admin / systems / 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("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
36       "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv",
37       "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
38       "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
40   var $XResolutions = array();
42   var $MouseTypes= array();
43   var $MousePorts= array();
44   var $hardware_list= array();
45   var $used_hardware= array();
48   /* attribute list for save action */
49   var $attributes= array("gotoXMonitor",
50       "gotoXDriver", "gotoXResolution", "gotoXColordepth",
51       "gotoXHsync", "gotoXVsync",
52       "gotoScannerEnable", "gotoScannerClients",
53       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
54       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
55   var $objectclasses= array("GOhard");
57   var $XColordepths     =array();
58   var $XKbModels        =array();
59   var $XKbLayouts       =array();
60   var $XKbVariants      =array();
62   function workservice ($config, $dn= NULL, $parent= NULL)
63   {
64     plugin::plugin ($config, $dn, $parent);
66     $this->XResolutions= array( 
67         "640x480"   =>  "640x480",
68         "800x600"   =>  "800x600",
69         "1024x768"  =>  "1024x768",
70         "1152x864"  =>  "1152x864", 
71         "1280x1024" =>  "1280x1024",
72         "1400x1050" =>  "1400x1050", 
73         "1600x1200" =>  "1600x1200");
75     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
76       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
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         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
90       }
91     }
93     array_unshift($this->XDrivers, "["._("unknown")."]");
94  
95     $this->XColordepths= array( 
96         "8"        => "8 " ._("bit"), 
97         "15"       => "15 "._("bit"),      
98         "16"       => "16 "._("bit"),   
99         "24"       => "24 "._("bit"));
101     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
102           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
103           "logiinetnav", "logiinternet", "macintosh", "microsoft",
104           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
105           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
106       $this->XKbModels[$type] = $type;
107     }
109     $this->MouseTypes= array("ImPS/2" => "ImPS/2", "PS/2" => "PS/2", "Microsoft" => "Microsoft", 
110                               "Logitech" => "Logitech");
112     $this->MousePorts= array("/dev/ttyS0"  =>"/dev/ttyS0", 
113                              "/dev/ttyS1"       => "/dev/ttyS1",          "/dev/psaux"  =>"/dev/psaux", 
114                              "/dev/input/mice"  => "/dev/input/mice");
116     /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */
117     $this->XKbLayouts= array ("de"=> "de","intl" =>"intl","us" =>"us");
118     $this->XKbVariants= array ("nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
120     /* try to read additional keyboard layouts 
121      */
122     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
123       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
124         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
125         $tmp = split("\n",$str);
126         foreach($tmp as $entry){
127           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
128             $entry = trim($entry);
129             $tmp2 = split ("\:",$entry);
130             $la =   trim($tmp2[0]);   // What would be saved to ldap
131             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
132             $this->XKbLayouts [ $la] = $da;  
133           } 
134         }
135       }
136     }
138     /* Initialize methods */
139     $this->XMethods["indirect"]= _("show chooser");
140     $this->XMethods["query"]= _("direct");
141     #$this->XMethods["squery"]= _("direct via ssh");
142     #$this->XMethods["nquery"]= _("direct via nx");
143     $this->XMethods["load"]= _("load balanced");
144     #$this->XMethods["sload"]= _("load balanced via ssh");
145     #$this->XMethods["nload"]= _("load balanced via nx");
146     $this->XMethods["rdp"]= _("Windows RDP");
147     $this->XMethods["citrix"]= _("ICA client");
149     $this->orig_dn= $this->dn;
151     /* Load hardware list */
152     $ldap= $this->config->get_ldap_link();
153     $ldap->cd($this->config->current['BASE']);
154     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
155     while ($attrs= $ldap->fetch()){
156       $cn= $attrs['cn'][0];
157       if (isset($attrs['description'])){
158         $description= " - ".$attrs['description'][0];
159       } else {
160         $description= "";
161       }
162       $this->hardware_list[$cn]= "$cn$description";
163     }
165     /* Eventually colorize phones */
166     $ldap->cd($this->config->current['BASE']);
167     foreach ($this->hardware_list as $cn => $desc){
168       $ldap->search("(goFonHardware=$cn)", array('cn'));
169       if ($ldap->count() > 0){
170         $ldap->fetch();
171         if ($ldap->getDN() != $this->dn){
172           $this->used_hardware[$cn]= $ldap->getDN();
173         }
174       }
175     }
177     if(preg_match("/\+/",$this->gotoXHsync)){
178       $this->AutoSync = true;
179       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
180       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
181     }
183     $this->hardware_list["automatic"]= _("automatic");
184     ksort($this->hardware_list);
186     /* Load hardware list */
187     $ldap= $this->config->get_ldap_link();
188     $ldap->cd($this->config->current['BASE']);
189     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$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     if (isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
230       $this->XResolutions= array('default' => _("inherited"));
231       $this->XColordepths= array('default' => _("inherited"));
232       $this->XKbModels= array('default' => _("inherited"));
233       $this->XKbLayouts= array('default' => _("inherited"));
234       $this->XKbVariants= array('default' => _("inherited"));
235       $this->MouseTypes= array('AUTO' => _("inherited"));
236       $this->MousePorts= array('AUTO' => _("inherited"));
237     }
238   }
240   function execute()
241   {
242     /* Call parent execute */
243     plugin::execute();
245     if($this->is_account && !$this->view_logged){
246       $this->view_logged = TRUE;
247       new log("view","workstation/".get_class($this),$this->dn);
248     }
250     /* Do we need to flip is_account state? */
251     if (isset($_POST['modify_state'])){
252       $this->is_account= !$this->is_account;
253     }
255     /* Do we need to flip is_account state? */
256     if(isset($_POST['modify_state'])){
257       if($this->is_account && $this->acl_is_removeable()){
258         $this->is_account= FALSE;
259       }elseif(!$this->is_account && $this->acl_is_createable()){
260         $this->is_account= TRUE;
261       }
262     }
264     /* Show main page */
265     $smarty= get_smarty();
267     /* Assign ACLs */
268     $tmp = $this->plInfo();
269     foreach($tmp['plProvidedAcls'] as $name => $translated){
270       $smarty->assign($name."ACL",$this->getacl($name));
271     }
273     /* Arrays */ 
274     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
275           "XKbModels", "XKbVariants",
276           "MouseTypes", "MousePorts") as $val){
277       $smarty->assign("$val", $this->$val);
278     }
279     $smarty->assign("XKbLayouts"    ,$this->XKbLayouts);
280     $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
282     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
283     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
284     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
285     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
287     /* Variables - select */
288     foreach(array(
289           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
290           "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
291           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
293       $smarty->assign($val."_select", $this->$val);
294     }
296     /* Variables */
297     foreach(array("gotoXHsync", "gotoXVsync") as $val){
298       $smarty->assign($val, $this->$val);
299     }
300     $smarty->assign("staticAddress", "");
302     /* Checkboxes */
303     foreach(array("gotoScannerEnable") as $val){
304       if ($this->$val == TRUE) {
305         $smarty->assign("$val", "checked");
306       } else {
307         $smarty->assign("$val", "");
308       }
309     }
311     /* Phone stuff */
312     $smarty->assign ("goFonHardware", $this->goFonHardware);
314     $perms = "";
315     if($this->acl_is_writeable("goFonHardware")){
316       $perms = " disabled ";
317     }
319     $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
320       _("Choose the phone located at the current terminal")."\" >";
321     foreach ($this->hardware_list as $cn => $description){
322       if ($cn == $this->goFonHardware){
323         $selected= "selected";
324       } else {
325         $selected= "";
326       }
327       if (isset($this->used_hardware[$cn])){
328         $color= "style=\"color:#A0A0A0\"";
329       } else {
330         $color= "";
331       }
332       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
333     }
334     $hl.= "</select>\n";
335     $smarty->assign ("hardware_list", $hl);
336     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
338     if($this->AutoSync){
339       $smarty->assign("AutoSyncCHK"," checked ");
340       $smarty->assign("hiddenState"," disabled ");
341     }else{
342       $smarty->assign("AutoSyncCHK"," ");
343       $smarty->assign("hiddenState","");
344     }
346     /* Show main page */
347     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
348   }
350   function remove_from_parent()
351   {
352     $this->handle_post_events("remove");
353     new log("remove","workstation/".get_class($this),$this->dn);
354   }
356   /* Save data to object */
357   function save_object()
358   {
359     plugin::save_object();
361     if((isset($_POST['gotoXDriver'])) && $this->acl_is_writeable("AutoSync")) {
362       if(isset($_POST['AutoSync'])){
363         $this->AutoSync = true;
364       }else{
365         $this->AutoSync = false;
366       }
367     }
368   }
370   /* Check supplied data */
371   function check()
372   {
373     /* Call common method to give check the hook */
374     $message= plugin::check();
376     /* Default entries can use blank hsync/vsync entries */
377     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
379       /* But only if no auto sync is enabled... */
380       if (!$this->AutoSync){
382         /* Check vsync for correct usage */
383         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
385         if($this->acl_is_writeable("gotoXVsync")){
386           if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
387             $message[]= _("Please specify a valid VSync range.");
388           } else{
389             list($v1,$v2)= preg_split ("/[-+]/", $val);
390             if ($v2 != ""){
391               if ($v1 > $v2){
392                 $message[]= _("Please specify a valid VSync range.");
393               }
394             }
395           }
396         }
398         /* Check hsync for correct usage */
399         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
400         if($this->acl_is_writeable("gotoXHsync")){
401           if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
402             $message[]= _("Please specify a valid HSync range.");
403           } else{
404             list($v1,$v2)= preg_split ("/[-+]/", $val);
405             if ($v2 != ""){
406               if ($v1 > $v2){
407                 $message[]= _("Please specify a valid HSync range.");
408               }
409             }
410           }
411         }
412       }
413     }
415     return ($message);
416   }
419   /* Save to LDAP */
420   function save()
421   {
422     /* remove objectclass GOhard if this is an ogroup tab */
423     if(isset($this->parent->by_object['ogroup'])){
424       $this->objectclasses = array();
425     }
427     plugin::save();
429     /* Strip out 'default' values */
430     foreach(array(
431           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
432           "gotoXKbModel", "gotoXKbLayout",
433           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
435       if ($this->attrs[$val] == "default"){
436         $this->attrs[$val]= array();
437       }
438     }
440     if($this->AutoSync){
441       $this->attrs['gotoXHsync'] = "30+55";
442       $this->attrs['gotoXVsync'] = "50+70";
443     }
445     /* Write back to ldap */
446     $ldap= $this->config->get_ldap_link();
447     $ldap->cd($this->dn);
448     $this->cleanup();
449     $ldap->modify ($this->attrs); 
450     new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
451     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/service with dn '%s' failed."),$this->dn));
452     $this->handle_post_events("modify");
453   }
455   /* Return plugin informations for acl handling */
456   function plInfo()
457   {
458     return (array(
459           "plShortName"   => _("Service"),
460           "plDescription" => _("Workstation service"),
461           "plSelfModify"  => FALSE,
462           "plDepends"     => array(),
463           "plPriority"    => 10,
464           "plSection"     => array("administration"),
465           "plCategory"    => array("workstation","ogroups"), 
467           "plProvidedAcls"=> array(
468             "gotoXMonitor"          => _("Monitor"),
469             "gotoXDriver"           => _("Gfx driver"),
470             "gotoXResolution"       => _("Gfx resolution"),
471             "gotoXColordepth"       => _("Gfx color depth"),
472             "gotoXHsync"            => _("Hsync"),
473             "gotoXVsync"            => _("Vsync"),
474             "AutoSync"              => _("Use DDC"),
475             "gotoScannerEnable"     => _("Scanner enabled"),
476             "gotoXKbModel"          => _("Keyboard model"),
477             "gotoXKbLayout"         => _("Keyboard layout"),
478             "gotoXKbVariant"        => _("Keyboard variant"),
479             "gotoXMouseType"        => _("Mouse type"),
480             "gotoXMouseport"        => _("Mouse port"),
481             "goFonHardware"         => _("Telephone hardware")) 
482             ));
483   }
486 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
487 ?>