Code

315df0e52748dc72c9dd14bb18778ef87b562aa0
[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";
28   /* Needed values and lists */
29   var $ignore_account= TRUE;
30   var $base= "";
31   var $cn= "";
32   var $orig_dn= "";
33   var $XMethods= array();
34   var $XDrivers= array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
35       "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv",
36       "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
37       "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
39   var $XResolutions = array();
41   var $MouseTypes= array();
42   var $MousePorts= array();
43   var $hardware_list= array();
44   var $used_hardware= array();
47   /* attribute list for save action */
48   var $attributes= array("gotoXMonitor",
49       "gotoXDriver", "gotoXResolution", "gotoXColordepth",
50       "gotoXHsync", "gotoXVsync",
51       "gotoScannerEnable", "gotoScannerClients",
52       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
53       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
54   var $objectclasses= array("GOhard");
56   var $XColordepths     =array();
57   var $XKbModels        =array();
58   var $XKbLayouts       =array();
59   var $XKbVariants      =array();
61   function workservice ($config, $dn= NULL)
62   {
63     plugin::plugin ($config, $dn);
65     $this->XResolutions= array( 
66         "default"   =>  "["._("inherited")."]",
67         "640x480"   =>  "640x480",
68         "800x600"   =>  "800x600",
69         "1024x768"  =>  "1024x768",
70         "1152x864"  =>  "1152x864", 
71         "1280x1024" =>  "1280x1024",
72         "1400x1050" =>  "1400x1050", 
73         "1600x1200" =>  "1600x1200");
75     array_unshift($this->XDrivers, "["._("unknown")."]");
76   
77     $this->XColordepths= array( 
78         "default"  => "["._("inherited")."]", 
79         "8"        => "8 " ._("bit"), 
80         "15"       => "15 "._("bit"),      
81         "16"       => "16 "._("bit"),   
82         "24"       => "24 "._("bit"));
84     $this->XKbModels['default']= "["._("inherited")."]"; 
85     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
86           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
87           "logiinetnav", "logiinternet", "macintosh", "microsoft",
88           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
89           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
90       $this->XKbModels[$type] = $type;
91     }
93     $this->MouseTypes= array("AUTO"     => "["._("inherited")."]", "ImPS/2"      =>"ImPS/2", 
94                              "PS/2"     => "PS/2",                "Microsoft"   =>"Microsoft", 
95                               "Logitech"=>"Microsoft");
97     $this->MousePorts= array("AUTO"             => "["._("inherited")."]", "/dev/ttyS0"  =>"/dev/ttyS0", 
98                              "/dev/ttyS1"       => "/dev/ttyS1",          "/dev/psaux"  =>"/dev/psaux", 
99                              "/dev/input/mice"  => "/dev/input/mice");
101     /* Additional values will be extracted from /etc/gosa/keyboardLayouts */
102     $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
103     $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
105     /* try to read additional keyboard layouts 
106      */
107     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
108       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
109         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
110         $tmp = split("\n",$str);
111         foreach($tmp as $entry){
112           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
113             $entry = trim($entry);
114             $tmp2 = split ("\:",$entry);
115             $la =   trim($tmp2[0]);   // What would be saved to ldap
116             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
117             $this->XKbLayouts [ $la] = $da;  
118           } 
119         }
120       }
121     }
123     /* Initialize methods */
124     $this->XMethods["default"]= _("default");
125     $this->XMethods["indirect"]= _("show chooser");
126     $this->XMethods["query"]= _("direct");
127 #$this->XMethods["squery"]= _("direct via ssh");
128 #$this->XMethods["nquery"]= _("direct via nx");
129     $this->XMethods["load"]= _("load balanced");
130 #$this->XMethods["sload"]= _("load balanced via ssh");
131 #$this->XMethods["nload"]= _("load balanced via nx");
132     $this->XMethods["rdp"]= _("Windows RDP");
133     $this->XMethods["citrix"]= _("ICA client");
135     $this->orig_dn= $this->dn;
137     /* Load hardware list */
138     $ldap= $this->config->get_ldap_link();
139     $ldap->cd($this->config->current['BASE']);
140     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
141     while ($attrs= $ldap->fetch()){
142       $cn= $attrs['cn'][0];
143       if (isset($attrs['description'])){
144         $description= " - ".$attrs['description'][0];
145       } else {
146         $description= "";
147       }
148       $this->hardware_list[$cn]= "$cn$description";
149     }
151     /* Eventually colorize phones */
152     $ldap->cd($this->config->current['BASE']);
153     foreach ($this->hardware_list as $cn => $desc){
154       $ldap->search("(goFonHardware=$cn)", array('cn'));
155       if ($ldap->count() > 0){
156         $ldap->fetch();
157         if ($ldap->getDN() != $this->dn){
158           $this->used_hardware[$cn]= $ldap->getDN();
159         }
160       }
161     }
163     if(preg_match("/\+/",$this->gotoXHsync)){
164       $this->AutoSync = true;
165       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
166       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
167     }
169     $this->hardware_list["automatic"]= _("automatic");
170     ksort($this->hardware_list);
171   }
173   function execute()
174   {
175     /* Call parent execute */
176     plugin::execute();
178     /* Do we need to flip is_account state? */
179     if (isset($_POST['modify_state'])){
180       $this->is_account= !$this->is_account;
181     }
183     /* Do we represent a valid terminal? */
184     if (!$this->is_account && $this->parent == NULL){
185       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
186         _("This 'dn' has no terminal features.")."</b>";
187       return ($display);
188     }
190     /* Show main page */
191     $smarty= get_smarty();
193     /* Arrays */ 
194     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
195           "XKbModels", "XKbVariants",
196           "MouseTypes", "MousePorts") as $val){
197       $smarty->assign("$val", $this->$val);
198     }
199     $smarty->assign("XKbLayouts"    ,$this->XKbLayouts);
200     $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
202     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
203     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
204     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
205     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
207     /* Variables - select */
208     foreach(array(
209           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
210           "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
211           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
213       $smarty->assign($val."_select", $this->$val);
214       $smarty->assign($val."ACL", chkacl($this->acl, $val));
215     }
217     /* Variables */
218     foreach(array("gotoXHsync", "gotoXVsync") as $val){
219       $smarty->assign($val, $this->$val);
220       $smarty->assign($val."ACL", chkacl($this->acl, $val));
221     }
222     $smarty->assign("staticAddress", "");
224     /* Checkboxes */
225     foreach(array("gotoScannerEnable") as $val){
226       if ($this->$val == TRUE) {
227         $smarty->assign("$val", "checked");
228       } else {
229         $smarty->assign("$val", "");
230       }
231     }
233     /* Phone stuff */
234     $smarty->assign ("goFonHardware", $this->goFonHardware);
235     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
236       _("Choose the phone located at the current terminal")."\" ".
237       chkacl($this->acl, "goFonHardware").">\n";
238     foreach ($this->hardware_list as $cn => $description){
239       if ($cn == $this->goFonHardware){
240         $selected= "selected";
241       } else {
242         $selected= "";
243       }
244       if (isset($this->used_hardware[$cn])){
245         $color= "style=\"color:#A0A0A0\"";
246       } else {
247         $color= "";
248       }
249       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
250     }
251     $hl.= "</select>\n";
252     $smarty->assign ("hardware_list", $hl);
253     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
254     $smarty->assign("AutoSyncACL",chkacl($this->acl,"AutoSync"));
256     if($this->AutoSync){
257       $smarty->assign("AutoSyncCHK"," checked ");
258     }else{
259       $smarty->assign("AutoSyncCHK"," ");
260     }
262     /* Show main page */
263     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
264   }
266   function remove_from_parent()
267   {
268     $this->handle_post_events("remove");
269   }
271   /* Save data to object */
272   function save_object()
273   {
274     plugin::save_object();
276     if(isset($_POST['gotoXHsync'])){
277       if(isset($_POST['AutoSync'])){
278         $this->AutoSync = true;
279       }else{
280         $this->AutoSync = false;
281       }
282     }
283   }
285   /* Check supplied data */
286   function check()
287   {
288     /* Call common method to give check the hook */
289     $message= plugin::check();
291     /* Default entries can use blank hsync/vsync entries */
292     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
294       /* Check vsync for correct usage */
295       $val= preg_replace ("/\s/", "", $this->gotoXVsync);
296       if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
297           && chkacl ($this->acl, "gotoXVsync") == ""){
299         $message[]= _("Please specify a valid VSync range.");
300       } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
301         list($v1,$v2)= preg_split ("/[-+]/", $val);
302         if ($v2 != ""){
303           if ($v1 > $v2){
304             $message[]= _("Please specify a valid VSync range.");
305           }
306         }
307       }
309       /* Check hsync for correct usage */
310       $val= preg_replace ("/\s/", "", $this->gotoXHsync);
311       if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)
312           && chkacl ($this->acl, "gotoXHsync") == ""){
314         $message[]= _("Please specify a valid HSync range.");
315       } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
316         list($v1,$v2)= preg_split ("/[-+]/", $val);
317         if ($v2 != ""){
318           if ($v1 > $v2){
319             $message[]= _("Please specify a valid HSync range.");
320           }
321         }
322       }
323     }
324     return ($message);
325   }
328   /* Save to LDAP */
329   function save()
330   {
331     /* remove objectclass GOhard if this is an ogroup tab */
332     if(isset($this->parent->by_object['ogroup'])){
333       $this->objectclasses = array();
334     }
336     plugin::save();
338     /* Strip out 'default' values */
339     foreach(array(
340           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
341           "gotoXKbModel", "gotoXKbLayout",
342           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
344       if ($this->attrs[$val] == "default"){
345         $this->attrs[$val]= array();
346       }
347     }
349     if($this->AutoSync){
350       $this->attrs['gotoXHsync'] = preg_replace("/-/","+",$this->attrs['gotoXHsync']) ;
351       $this->attrs['gotoXVsync'] = preg_replace("/-/","+",$this->attrs['gotoXVsync']) ;
352     }
354     /* Write back to ldap */
355     $ldap= $this->config->get_ldap_link();
356     $ldap->cd($this->dn);
357     $this->cleanup();
358     $ldap->modify ($this->attrs); 
360     show_ldap_error($ldap->get_error(), _("Saving workstation services failed"));
361     $this->handle_post_events("modify");
362   }
366 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
367 ?>