Code

Removed old CLI stuff - cleanup
[gosa.git] / plugins / admin / systems / class_workstationService.inc
1 <?php
3 class workservice extends plugin
4 {
5   var $gotoScannerEnable;
6   /* Generic terminal attributes */
7   var $gotoXMonitor= "";
8   var $gotoXDriver= "";
9   var $gotoXResolution= "";
10   var $gotoXColordepth= "";
11   var $gotoXHsync= "";
12   var $gotoXVsync= "";
13   var $AutoSync = false;
14   var $gotoXKbModel= "";
15   var $gotoXKbLayout= "";
16   var $gotoXKbVariant= "";
17   var $gotoXMouseType= "";
18   var $gotoXMouseport= "";
19   var $gotoScannerClients= "";
20   var $gotoScannerBackend= "";
21   var $goFonHardware= "automatic";
23   /* Needed values and lists */
24   var $ignore_account= TRUE;
25   var $base= "";
26   var $cn= "";
27   var $orig_dn= "";
28   var $XMethods= array();
29   var $XDrivers= array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
30       "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv",
31       "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
32       "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
34   var $XResolutions = array();
36   var $MouseTypes= array();
37   var $MousePorts= array();
38   var $hardware_list= array();
39   var $used_hardware= array();
42   /* attribute list for save action */
43   var $attributes= array("gotoXMonitor",
44       "gotoXDriver", "gotoXResolution", "gotoXColordepth",
45       "gotoXHsync", "gotoXVsync",
46       "gotoScannerEnable", "gotoScannerClients",
47       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
48       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
49   var $objectclasses= array("GOhard");
51   var $XColordepths     =array();
52   var $XKbModels        =array();
53   var $XKbLayouts       =array();
54   var $XKbVariants      =array();
56   function workservice ($config, $dn= NULL, $parent= NULL)
57   {
58     plugin::plugin ($config, $dn, $parent);
60     $this->XResolutions= array( 
61         "640x480"   =>  "640x480",
62         "800x600"   =>  "800x600",
63         "1024x768"  =>  "1024x768",
64         "1152x864"  =>  "1152x864", 
65         "1280x1024" =>  "1280x1024",
66         "1400x1050" =>  "1400x1050", 
67         "1600x1200" =>  "1600x1200");
69     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
70       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
72       if(is_readable($file)){
73         $str = file_get_contents($file);
74         $lines = split("\n",$str);
75         foreach($lines as $line){
76           $line = trim($line);
77           if(!empty($line)){
78             $this->XResolutions[$line]=$line;
79           }
80         }
81         //natcasesort($this->gotoXResolutions);
82       }else{
83         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
84       }
85     }
87     array_unshift($this->XDrivers, "["._("unknown")."]");
88  
89     $this->XColordepths= array( 
90         "8"        => "8 " ._("bit"), 
91         "15"       => "15 "._("bit"),      
92         "16"       => "16 "._("bit"),   
93         "24"       => "24 "._("bit"));
95     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
96           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
97           "logiinetnav", "logiinternet", "macintosh", "microsoft",
98           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
99           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
100       $this->XKbModels[$type] = $type;
101     }
103     $this->MouseTypes= array("ImPS/2" => "ImPS/2", "PS/2" => "PS/2", "Microsoft" => "Microsoft", 
104                               "Logitech" => "Logitech");
106     $this->MousePorts= array("/dev/ttyS0"  =>"/dev/ttyS0", 
107                              "/dev/ttyS1"       => "/dev/ttyS1",          "/dev/psaux"  =>"/dev/psaux", 
108                              "/dev/input/mice"  => "/dev/input/mice");
110     /* Additional values will be extracted from CONFIG_DIR/gosa/keyboardLayouts */
111     $this->XKbLayouts= array ("de"=> "de","intl" =>"intl","us" =>"us");
112     $this->XKbVariants= array ("nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
114     /* try to read additional keyboard layouts 
115      */
116     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
117       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
118         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
119         $tmp = split("\n",$str);
120         foreach($tmp as $entry){
121           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
122             $entry = trim($entry);
123             $tmp2 = split ("\:",$entry);
124             $la =   trim($tmp2[0]);   // What would be saved to ldap
125             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
126             $this->XKbLayouts [ $la] = $da;  
127           } 
128         }
129       }
130     }
132     /* Initialize methods */
133     $this->XMethods["indirect"]= _("show chooser");
134     $this->XMethods["query"]= _("direct");
135     #$this->XMethods["squery"]= _("direct via ssh");
136     #$this->XMethods["nquery"]= _("direct via nx");
137     $this->XMethods["load"]= _("load balanced");
138     #$this->XMethods["sload"]= _("load balanced via ssh");
139     #$this->XMethods["nload"]= _("load balanced via nx");
140     $this->XMethods["rdp"]= _("Windows RDP");
141     $this->XMethods["citrix"]= _("ICA client");
143     $this->orig_dn= $this->dn;
145     /* Load hardware list */
146     $ldap= $this->config->get_ldap_link();
147     $ldap->cd($this->config->current['BASE']);
148     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
149     while ($attrs= $ldap->fetch()){
150       $cn= $attrs['cn'][0];
151       if (isset($attrs['description'])){
152         $description= " - ".$attrs['description'][0];
153       } else {
154         $description= "";
155       }
156       $this->hardware_list[$cn]= "$cn$description";
157     }
159     /* Eventually colorize phones */
160     $ldap->cd($this->config->current['BASE']);
161     foreach ($this->hardware_list as $cn => $desc){
162       $ldap->search("(goFonHardware=$cn)", array('cn'));
163       if ($ldap->count() > 0){
164         $ldap->fetch();
165         if ($ldap->getDN() != $this->dn){
166           $this->used_hardware[$cn]= $ldap->getDN();
167         }
168       }
169     }
171     if(preg_match("/\+/",$this->gotoXHsync)){
172       $this->AutoSync = true;
173       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
174       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
175     }
177     $this->hardware_list["automatic"]= _("automatic");
178     ksort($this->hardware_list);
180     /* Load hardware list */
181     $ldap= $this->config->get_ldap_link();
182     $ldap->cd($this->config->current['BASE']);
183     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
184     if ($ldap->count() == 1){
185       $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
186                   "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
187       $attrs= $ldap->fetch();
189       foreach ($map as $name){
190         if (!isset($attrs[$name][0])){
191           continue;
192         }
193         
194         switch ($name){
195           case 'gotoXResolution':
196             $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
197             break;
198           case 'gotoXColordepth':
199             $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
200             break;
201           case 'gotoXKbModel':
202             $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
203             break;
204           case 'gotoXKbLayout':
205             $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
206             break;
207           case 'gotoXKbVariant':
208             $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
209             break;
210           case 'gotoXMouseType':
211             $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
212             break;
213           case 'gotoXMouseport':
214             $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
215             break;
216         }
218       }
220     }
222     /* Workaround to fill in inherited values if we've specified an objectclass */
223     if (isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
224       $this->XResolutions= array('default' => _("inherited"));
225       $this->XColordepths= array('default' => _("inherited"));
226       $this->XKbModels= array('default' => _("inherited"));
227       $this->XKbLayouts= array('default' => _("inherited"));
228       $this->XKbVariants= array('default' => _("inherited"));
229       $this->MouseTypes= array('AUTO' => _("inherited"));
230       $this->MousePorts= array('AUTO' => _("inherited"));
231     }
232   }
234   function execute()
235   {
236     /* Call parent execute */
237     plugin::execute();
239     /* Do we need to flip is_account state? */
240     if (isset($_POST['modify_state'])){
241       $this->is_account= !$this->is_account;
242     }
244     /* Do we represent a valid terminal? */
245     if (!$this->is_account && $this->parent == NULL){
246       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
247         _("This 'dn' has no terminal features.")."</b>";
248       return ($display);
249     }
251     /* Show main page */
252     $smarty= get_smarty();
254     /* Arrays */ 
255     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
256           "XKbModels", "XKbVariants",
257           "MouseTypes", "MousePorts") as $val){
258       $smarty->assign("$val", $this->$val);
259     }
260     $smarty->assign("XKbLayouts"    ,$this->XKbLayouts);
261     $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
263     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
264     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
265     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
266     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
268     /* Variables - select */
269     foreach(array(
270           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
271           "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
272           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
274       $smarty->assign($val."_select", $this->$val);
275       $smarty->assign($val."ACL", chkacl($this->acl, $val));
276     }
278     /* Variables */
279     foreach(array("gotoXHsync", "gotoXVsync") as $val){
280       $smarty->assign($val, $this->$val);
281       $smarty->assign($val."ACL", chkacl($this->acl, $val));
282     }
283     $smarty->assign("staticAddress", "");
285     /* Checkboxes */
286     foreach(array("gotoScannerEnable") as $val){
287       if ($this->$val == TRUE) {
288         $smarty->assign("$val", "checked");
289       } else {
290         $smarty->assign("$val", "");
291       }
292     }
294     /* Phone stuff */
295     $smarty->assign ("goFonHardware", $this->goFonHardware);
296     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
297       _("Choose the phone located at the current terminal")."\" ".
298       chkacl($this->acl, "goFonHardware").">\n";
299     foreach ($this->hardware_list as $cn => $description){
300       if ($cn == $this->goFonHardware){
301         $selected= "selected";
302       } else {
303         $selected= "";
304       }
305       if (isset($this->used_hardware[$cn])){
306         $color= "style=\"color:#A0A0A0\"";
307       } else {
308         $color= "";
309       }
310       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
311     }
312     $hl.= "</select>\n";
313     $smarty->assign ("hardware_list", $hl);
314     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
315     $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
317     if($this->AutoSync){
318       $smarty->assign("AutoSyncCHK"," checked ");
319       $smarty->assign("hiddenState"," disabled ");
320     }else{
321       $smarty->assign("AutoSyncCHK"," ");
322       $smarty->assign("hiddenState","");
323     }
325     /* Show main page */
326     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
327   }
329   function remove_from_parent()
330   {
331     $this->handle_post_events("remove");
332   }
334   /* Save data to object */
335   function save_object()
336   {
337     plugin::save_object();
339     if(isset($_POST['gotoXDriver']) && chkacl($this->acl,"AutoSync") == ""){
340       if(isset($_POST['AutoSync'])){
341         $this->AutoSync = true;
342       }else{
343         $this->AutoSync = false;
344       }
345     }
346   }
348   /* Check supplied data */
349   function check()
350   {
351     /* Call common method to give check the hook */
352     $message= plugin::check();
354     /* Default entries can use blank hsync/vsync entries */
355     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
357       /* But only if no auto sync is enabled... */
358       if (!$this->AutoSync){
360         /* Check vsync for correct usage */
361         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
362         if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
363             && chkacl ($this->acl, "gotoXVsync") == ""){
365           $message[]= _("Please specify a valid VSync range.");
366         } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
367           list($v1,$v2)= preg_split ("/[-+]/", $val);
368           if ($v2 != ""){
369             if ($v1 > $v2){
370               $message[]= _("Please specify a valid VSync range.");
371             }
372           }
373         }
375         /* Check hsync for correct usage */
376         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
377         if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
378             && chkacl ($this->acl, "gotoXHsync") == ""){
380           $message[]= _("Please specify a valid HSync range.");
381         } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
382           list($v1,$v2)= preg_split ("/[-+]/", $val);
383           if ($v2 != ""){
384             if ($v1 > $v2){
385               $message[]= _("Please specify a valid HSync range.");
386             }
387           }
388         }
389       }
390     }
392     return ($message);
393   }
396   /* Save to LDAP */
397   function save()
398   {
399     /* remove objectclass GOhard if this is an ogroup tab */
400     if(isset($this->parent->by_object['ogroup'])){
401       $this->objectclasses = array();
402     }
404     plugin::save();
406     /* Strip out 'default' values */
407     foreach(array(
408           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
409           "gotoXKbModel", "gotoXKbLayout",
410           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
412       if ($this->attrs[$val] == "default"){
413         $this->attrs[$val]= array();
414       }
415     }
417     if($this->AutoSync){
418       $this->attrs['gotoXHsync'] = "30+55";
419       $this->attrs['gotoXVsync'] = "50+70";
420     }
422     /* Write back to ldap */
423     $ldap= $this->config->get_ldap_link();
424     $ldap->cd($this->dn);
425     $this->cleanup();
426     $ldap->modify ($this->attrs); 
428     show_ldap_error($ldap->get_error(), _("Saving workstation services failed"));
429     $this->handle_post_events("modify");
430   }
434 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
435 ?>