Code

043846474e144ca717e229f07ac672c10717894e
[gosa.git] / plugins / admin / systems / class_terminalService.inc
1 <?php
3 class termservice 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   /* Generic terminal attributes */
11   var $gotoLpdEnable= FALSE;
12   var $gotoXMonitor= "";
13   var $gotoXMethod= "";
14   var $gotoXdmcpServer= "";
15   var $gotoFontPath= "";
16   var $gotoXDriver= "";
17   var $gotoXResolution= "";
18   var $gotoXColordepth= "";
19   var $gotoXHsync= "";
20   var $gotoXVsync= "";
21   var $gotoXKbModel= "";
22   var $gotoXKbLayout= "";
23   var $gotoXKbVariant= "";
24   var $gotoXMouseType= "";
25   var $gotoXMouseport= "";
26   var $gotoLpdServer= "";
27   var $gotoScannerEnable= "";
28   var $gotoScannerModel= "";
29   var $gotoScannerClients= "";
30   var $gotoScannerBackend= "";
31   var $goFonHardware= "automatic";
33   /* Needed values and lists */
34   var $base= "";
35   var $cn= "";
36   var $orig_dn= "";
37   var $XMethods= array();
38   var $XDrivers= array("unknown", "ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
39       "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv",
40       "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
41       "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga");
42   var $XResolutions= array("default", "640x480", "800x600", "1024x768", "1152x864", "1280x1024",
43       "1400x1050", "1600x1200");
44   var $XColordepths= array("default", "8", "15", "16", "24");
45   var $XKbModels= array ("default", "btc9000", "chicony", "compaq", "dell", "dell101", "everex",
46       "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
47       "logiinetnav", "logiinternet", "macintosh", "microsoft",
48       "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
49       "pc105", "rapidaccess", "rapidaccess2", "winbook");
50   var $XKbLayouts= array ("default", "de", "intl", "us");
51   var $XKbVariants= array ("default", "nodeadkeys", "basic");
52   var $MouseTypes= array("AUTO", "ImPS/2", "PS/2", "Microsoft", "Logitech");
53   var $MousePorts= array("AUTO", "/dev/ttyS0", "/dev/ttyS1", "/dev/psaux", "/dev/input/mice");
54   var $gotoScannerModels= array();
55   var $hardware_list= array();
56   var $used_hardware= array();
59   /* attribute list for save action */
60   var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
61       "gotoFontPath", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
62       "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
63       "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
64       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
65       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
66   var $objectclasses= array("GOhard");
69   function termservice ($config, $dn= NULL)
70   {
71     plugin::plugin ($config, $dn);
73     /* Load scanner models */
74     $fcontents = file ($this->config->basedir."/include/scanner.inc");
75     while (list ($line_num, $line) = each ($fcontents)) {
76       preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
77       $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
78     }
79     ksort ($this->gotoScannerModels);
81     /* Initialize methods */
82     $this->XMethods["default"]= _("default");
83     $this->XMethods["indirect"]= _("show chooser");
84     $this->XMethods["query"]= _("direct");
85 #$this->XMethods["squery"]= _("direct via ssh");
86 #$this->XMethods["nquery"]= _("direct via nx");
87     $this->XMethods["load"]= _("load balanced");
88 #$this->XMethods["sload"]= _("load balanced via ssh");
89 #$this->XMethods["nload"]= _("load balanced via nx");
90     $this->XMethods["rdp"]= _("Windows RDP");
91     $this->XMethods["citrix"]= _("ICA client");
93     $this->orig_dn= $this->dn;
95     /* Load hardware list */
96     $ldap= $this->config->get_ldap_link();
97     $ldap->cd($this->config->current['BASE']);
98     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
99     while ($attrs= $ldap->fetch()){
100       $cn= $attrs['cn'][0];
101       if (isset($attrs['description'])){
102         $description= " - ".$attrs['description'][0];
103       } else {
104         $description= "";
105       }
106       $this->hardware_list[$cn]= "$cn$description";
107     }
109     /* Eventually colorize phones */
110     $ldap->cd($this->config->current['BASE']);
111     foreach ($this->hardware_list as $cn => $desc){
112       $ldap->search("(goFonHardware=$cn)", array('cn'));
113       if ($ldap->count() > 0){
114         $ldap->fetch();
115         if ($ldap->getDN() != $this->dn){
116           $this->used_hardware[$cn]= $ldap->getDN();
117         }
118       }
119     }
121     $this->hardware_list["automatic"]= _("automatic");
122     ksort($this->hardware_list);
123   }
125   function execute()
126   {
127     /* Do we need to flip is_account state? */
128     if (isset($_POST['modify_state'])){
129       $this->is_account= !$this->is_account;
130     }
132     /* Do we represent a valid terminal? */
133     if (!$this->is_account && $this->parent == NULL){
134       $display= "<img src=\"images/stop.png\" align=center>&nbsp;<b>".
135         _("This 'dn' has no terminal features.")."</b>";
136       return ($display);
137     }
139     /* Show main page */
140     $smarty= get_smarty();
142     /* Arrays */ 
143     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
144           "gotoScannerModels", "XKbModels", "XKbLayouts", "XKbVariants",
145           "MouseTypes", "MousePorts") as $val){
146       $smarty->assign("$val", $this->$val);
147     }
148     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
149     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
150     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
151     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
153     /* Variables - select */
154     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath", 
155           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
156           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
157           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
159       $smarty->assign($val."_select", $this->$val);
160       $smarty->assign($val."ACL", chkacl($this->acl, $val));
161     }
163     /* Variables */
164     foreach(array("gotoXHsync", "gotoXVsync") as $val){
165       $smarty->assign($val, $this->$val);
166       $smarty->assign($val."ACL", chkacl($this->acl, $val));
167     }
169     /* Checkboxes */
170     foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
171       if ($this->$val == TRUE) {
172         $smarty->assign("$val", "checked");
173       } else {
174         $smarty->assign("$val", "");
175       }
176       $smarty->assign($val."ACL", chkacl($this->acl, "gotoLpdEnable"));
177     }
179     /* Phone stuff */
180     $smarty->assign ("goFonHardware", $this->goFonHardware);
181     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
182          _("Choose the phone located at the current terminal")."\" ".
183          chkacl($this->acl, "goFonHardware").">\n";
184     foreach ($this->hardware_list as $cn => $description){
185       if ($cn == $this->goFonHardware){
186         $selected= "selected";
187       } else {
188         $selected= "";
189       }
190       if (isset($this->used_hardware[$cn])){
191         $color= "style=\"color:#A0A0A0\"";
192       } else {
193         $color= "";
194       }
195       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
196     }
197     $hl.= "</select>\n";
198     $smarty->assign ("hardware_list", $hl);
199     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
201     /* Show main page */
202     return($smarty->fetch (get_template_path('service.tpl', TRUE)));
203   }
205   function remove_from_parent()
206   {
207     $ldap= $this->config->get_ldap_link();
208     $ldap->rmdir($this->dn);
209     show_ldap_error($ldap->get_error());
210     $this->handle_post_events("remove");
211   }
214   /* Save data to object */
215   function save_object()
216   {
217     plugin::save_object();
219     /* Save checkbox state */
220     if (isset ($_POST['gotoXMethod'])){
221       foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
223         if (!isset ($_POST["$val"]) && chkacl ($this->acl, "$val") == ""){
224           $this->$val= FALSE;
225         } else {
226           $this->$val= TRUE;
227         }
228       }
229     }
230   }
233   /* Check supplied data */
234   function check()
235   {
236     $message= array();
238     /* Default entries can use blank hsync/vsync entries */
239     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
241       /* Check vsync for correct usage */
242       $val= preg_replace ("/\s/", "", $this->gotoXVsync);
243       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
244           && chkacl ($this->acl, "gotoXVsync") == ""){
246         $message[]= _("Please specify a valid VSync range.");
247       } elseif (chkacl ($this->acl, "gotoXVsync") == ""){
248         list($v1,$v2)= split ("-", $val);
249         if ($v2 != ""){
250           if ($v1 > $v2){
251             $message[]= _("Please specify a valid VSync range.");
252           }
253         }
254       }
256       /* Check hsync for correct usage */
257       $val= preg_replace ("/\s/", "", $this->gotoXHsync);
258       if (!preg_match ("/^\d+(\.\d+)?(\-\d+(\.\d+)?)?$/", $val)
259           && chkacl ($this->acl, "gotoXHsync") == ""){
261         $message[]= _("Please specify a valid HSync range.");
262       } elseif (chkacl ($this->acl, "gotoXHsync") == ""){
263         list($v1,$v2)= split ("-", $val);
264         if ($v2 != ""){
265           if ($v1 > $v2){
266             $message[]= _("Please specify a valid HSync range.");
267           }
268         }
269       }
270     }
271     return ($message);
272   }
275   /* Save to LDAP */
276   function save()
277   {
278     plugin::save();
280     /* Strip out 'default' values */
281     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
282           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
283           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
284           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
286       if ($this->attrs[$val] == "default"){
287         $this->attrs[$val]= array();
288       }
289     }
291     /* Write back to ldap */
292     $ldap= $this->config->get_ldap_link();
293     $ldap->cd($this->dn);
294     $ldap->modify($this->attrs);
295     show_ldap_error($ldap->get_error());
296     $this->handle_post_events("modify");
297   }
301 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
302 ?>