Code

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