Code

5a24d156a0a42366af1fc8367e8aab8e0ba5e6c1
[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   var $AutoSync = false;
35   /* Needed values and lists */
36   var $ignore_account= TRUE;
37   var $base= "";
38   var $cn= "";
39   var $orig_dn= "";
40   var $XMethods= array();
41   var $XDrivers= array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev",
42       "i128", "i740", "i810", "imstt", "mga", "neomagic", "newport", "nsc",  "nv",
43       "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
44       "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
45   var $XResolutions= array();
46   var $XColordepths= array();
47   var $XKbModels= array ();
48   var $XKbLayouts= array ();
49   var $XKbVariants= array ();
50   var $MouseTypes= array();
51   var $MousePorts= array();
52   var $gotoScannerModels= array();
53   var $hardware_list= array();
54   var $used_hardware= array();
57   /* attribute list for save action */
58   var $attributes= array("cn", "gotoLpdEnable", "gotoXMonitor", "gotoXMethod", "gotoXdmcpServer",
59       "gotoFontPath", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
60       "gotoXHsync", "gotoXVsync", "gotoLpdEnable", "gotoLpdServer",
61       "gotoScannerEnable", "gotoScannerModel", "gotoScannerClients",
62       "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
63       "gotoXMouseType", "gotoXMouseport", "goFonHardware");
64   var $objectclasses= array("GOhard");
67   function termservice ($config, $dn= NULL, $parent= NULL)
68   {
69     plugin::plugin ($config, $dn, $parent);
70     
71     array_unshift($this->XDrivers, "["._("unknown")."]");
72     
73     $this->XResolutions= array(
74         "default"   =>  "["._("inherited")."]"  ,
75         "640x480"   =>  "640x480",
76         "800x600"   =>  "800x600",
77         "1024x768"  =>  "1024x768",
78         "1152x864"  =>  "1152x864",
79         "1280x1024" =>  "1280x1024",
80         "1400x1050" =>  "1400x1050",
81         "1600x1200" =>  "1600x1200");
83     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
84       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
86       if(is_readable($file)){
87         $str = file_get_contents($file);
88         $lines = split("\n",$str);
89         foreach($lines as $line){
90           $line = trim($line);
91           if(!empty($line)){
92             $this->XResolutions[$line]=$line;
93           }
94         }
95         //natcasesort($this->gotoXResolutions);
96       }else{
97         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
98       }
99     }
101     $this->XColordepths= array(
102         "default"  => "["._("inherited")."]",
103         "8"        => "8 " ._("bit"),
104         "15"       => "15 "._("bit"),
105         "16"       => "16 "._("bit"),
106         "24"       => "24 "._("bit"));
108     $this->XKbModels['default']= "["._("inherited")."]";
109     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
110           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
111           "logiinetnav", "logiinternet", "macintosh", "microsoft",
112           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
113           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
114       $this->XKbModels[$type] = $type;
115     }
117     /* Additional values will be extracted from CONFIG_DIR.keyboardLayouts */
118     $this->XKbLayouts= array ("default"=>"["._("inherited")."]","de"=> "de","intl" =>"intl","us" =>"us");
119     $this->XKbVariants= array ("default"=>"["._("inherited")."]", "nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
121     $this->MouseTypes= array( "AUTO"      =>  "["._("inherited")."]" ,  "ImPS/2"      => "ImPS/2", 
122                               "PS/2"      =>  "PS/2"                 ,  "Microsoft"   => "Microsoft", 
123                               "Logitech"  =>  "Logitech");
125     $this->MousePorts= array("AUTO"             =>"["._("inherited")."]"   , "/dev/ttyS0"  => "/dev/ttyS0", 
126                              "/dev/ttyS1"       => "/dev/ttyS1"            , "/dev/psaux"  => "/dev/psaux", 
127                              "/dev/input/mice"  =>"/dev/input/mice");
128  
130     /* try to read additional keyboard layouts
131      */
132     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
133       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
134         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
135         $tmp = split("\n",$str);
136         foreach($tmp as $entry){
137           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
138             $entry = trim($entry);
139             $tmp2 = split ("\:",$entry);
140             $la =   trim($tmp2[0]);   // What would be saved to ldap
141             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
142             $this->XKbLayouts [ $la] = $da;
143           }
144         }
145       }
146     }
148     /* Load scanner models */
149     $fcontents = file ($this->config->basedir."/include/scanner.inc");
150     while (list ($line_num, $line) = each ($fcontents)) {
151       preg_match('/^(\w+) "([^"]+)" "([^"]+)" "([^"]+)"/', "$line", $matches);
152       $this->gotoScannerModels[$matches[2]." - ".$matches[3]]= $matches[1]."|".$matches[4];
153     }
154     ksort ($this->gotoScannerModels);
156     /* Initialize methods */
157     $this->XMethods["default"]= _("default");
158     $this->XMethods["indirect"]= _("show chooser");
159     $this->XMethods["query"]= _("direct");
160 #$this->XMethods["squery"]= _("direct via ssh");
161 #$this->XMethods["nquery"]= _("direct via nx");
162     $this->XMethods["load"]= _("load balanced");
163 #$this->XMethods["sload"]= _("load balanced via ssh");
164 #$this->XMethods["nload"]= _("load balanced via nx");
165     $this->XMethods["rdp"]= _("Windows RDP");
166     $this->XMethods["citrix"]= _("ICA client");
168     $this->orig_dn= $this->dn;
170     /* Load hardware list */
171     $ldap= $this->config->get_ldap_link();
172     $ldap->cd($this->config->current['BASE']);
173     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
174     while ($attrs= $ldap->fetch()){
175       $cn= $attrs['cn'][0];
176       if (isset($attrs['description'])){
177         $description= " - ".$attrs['description'][0];
178       } else {
179         $description= "";
180       }
181       $this->hardware_list[$cn]= "$cn$description";
182     }
184     /* Eventually colorize phones */
185     $ldap->cd($this->config->current['BASE']);
186     foreach ($this->hardware_list as $cn => $desc){
187       $ldap->search("(goFonHardware=$cn)", array('cn'));
188       if ($ldap->count() > 0){
189         $ldap->fetch();
190         if ($ldap->getDN() != $this->dn){
191           $this->used_hardware[$cn]= $ldap->getDN();
192         }
193       }
194     }
196     $this->hardware_list["automatic"]= _("automatic");
197     ksort($this->hardware_list);
199     /* Convert gotoLpdEnable */
200     $this->gotoLpdEnable= preg_match("/yes/i",$this->gotoLpdEnable);
202     /* Load hardware list */
203     $ldap= $this->config->get_ldap_link();
204     $ldap->cd($this->config->current['BASE']);
205     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
206     if ($ldap->count() == 1){
207       $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
208                   "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
209       $attrs= $ldap->fetch();
211       foreach ($map as $name){
212         if (!isset($attrs[$name][0])){
213           continue;
214         }
216         switch ($name){
217           case 'gotoXResolution':
218             $this->XResolutions['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
219             break;
220           case 'gotoXColordepth':
221             $this->XColordepths['default'] =  _("inherited").' ['.$attrs[$name][0].' '._('Bit').']';
222             break;
223           case 'gotoXKbModel':
224             $this->XKbModels['default'] =  _("inherited").' ['.$attrs[$name][0].']';
225             break;
226           case 'gotoXKbLayout':
227             $this->XKbLayouts['default'] =  _("inherited").' ['.$attrs[$name][0].']';
228             break;
229           case 'gotoXKbVariant':
230             $this->XKbVariants['default'] = _("inherited").' ['.$attrs[$name][0].']' ;
231             break;
232           case 'gotoXMouseType':
233             $this->MouseTypes['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
234             break;
235           case 'gotoXMouseport':
236             $this->MousePorts['AUTO'] = _("inherited").' ['.$attrs[$name][0].']' ;
237             break;
238         }
239       }
240     }
241     if(preg_match("/\+/",$this->gotoXHsync)){
242       $this->AutoSync = true;
243       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
244       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
245     }
246   }
248   function execute()
249   {
250         /* Call parent execute */
251         plugin::execute();
253     /* Do we need to flip is_account state? */
254     if (isset($_POST['modify_state'])){
255       $this->is_account= !$this->is_account;
256     }
258     /* Do we represent a valid terminal? */
259     if (!$this->is_account && $this->parent == NULL){
260       $display= "<img alt=\"\" src=\"images/stop.png\" align=\"middle\">&nbsp;<b>".
261         _("This 'dn' has no terminal features.")."</b>";
262       return ($display);
263     }
265     /* Show main page */
266     $smarty= get_smarty();
268     /* Assign acls */
269     $tmp= $this->plInfo();
270     foreach($tmp['plProvidedAcls'] as $name => $translation){
271       $smarty->assign($name."ACL",$this->getacl($name));
272     }
275     /* Arrays */ 
276     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
277           "gotoScannerModels", "XKbModels","XKbVariants",
278           "MouseTypes", "MousePorts") as $val){
279       $smarty->assign("$val", $this->$val);
280     }
281     $smarty->assign("XKbLayouts",   $this->XKbLayouts);
282     $smarty->assign("XKbLayoutKeys",array_flip($this->XKbLayouts));
283   
284     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
285     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
286     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
287     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
289     /* Variables - select */
290     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath", 
291           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
292           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
293           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
295       $smarty->assign($val."_select", $this->$val);
296     }
298     /* Variables */
299     foreach(array("gotoXHsync", "gotoXVsync") as $val){
300       $smarty->assign($val, $this->$val);
301     }
302     $smarty->assign("staticAddress", "");
304     /* Checkboxes */
305     foreach(array("gotoLpdEnable", "gotoScannerEnable") as $val){
306       if ($this->$val == TRUE) {
307         $smarty->assign("$val", "checked");
308       } else {
309         $smarty->assign("$val", "");
310       }
311     }
313     /* Phone stuff */
314     $smarty->assign ("goFonHardware", $this->goFonHardware);
315     $hl= "<select size=\"1\" name=\"goFonHardware\" title=\"".
316          _("Choose the phone located at the current terminal")."\" >\n";
317     foreach ($this->hardware_list as $cn => $description){
318       if ($cn == $this->goFonHardware){
319         $selected= "selected";
320       } else {
321         $selected= "";
322       }
323       if (isset($this->used_hardware[$cn])){
324         $color= "style=\"color:#A0A0A0\"";
325       } else {
326         $color= "";
327       }
328       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
329     }
330     $hl.= "</select>\n";
331     $smarty->assign ("hardware_list", $hl);
332     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
334     $smarty->assign("AutoSyncACL",$this->getacl("AutoSync"));
336     $smarty->assign("AutoSyncCHK"," ");
337     if($this->AutoSync){
338       $smarty->assign("AutoSyncCHK"," checked ");
339       $smarty->assign("gotoXVsyncACL", preg_replace("/w/","",$this->getacl("gotoXVsync")));
340       $smarty->assign("gotoXHsyncACL", preg_replace("/w/","",$this->getacl("gotoXHsync")));
341     }
343     /* Show main page */
344     return($smarty->fetch (get_template_path('terminalService.tpl', TRUE)));
345   }
347   function remove_from_parent()
348   {
349     $this->handle_post_events("remove");
350   }
353   /* Save data to object */
354   function save_object()
355   {
356     plugin::save_object();
358     /* Save checkbox state */
359     if (isset ($_POST['gotoXMethod'])){
360       foreach (array("gotoLpdEnable", "gotoScannerEnable") as $val){
362         if($this->acl_is_writeable($val)){
363           if (!isset ($_POST["$val"])){
364             $this->$val= FALSE;
365           } else {
366             $this->$val= TRUE;
367           }
368         }
369       }
370     } 
372     if(isset($_POST['gotoXDriver'])){
373       if(isset($_POST['AutoSync'])){
374         $this->AutoSync = true;
375       }else{
376         $this->AutoSync = false;
377       }
378     }
380     /* Default entries can use blank hsync/vsync entries */
381     if ($this->dn != "" && $this->cn != "default" && $this->cn != "default"){
383       /* But only if no auto sync is enabled... */
384       if (!$this->AutoSync){
386         /* Check vsync for correct usage */
387         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
388         if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXVsync")){
390           $message[]= _("Please specify a valid VSync range.");
391         } elseif ($this->acl_is_writeable("gotoXVsync")){
392           list($v1,$v2)= preg_split ("/[-+]/", $val);
393           if ($v2 != ""){
394             if ($v1 > $v2){
395               $message[]= _("Please specify a valid VSync range.");
396             }
397           }
398         }
400         /* Check hsync for correct usage */
401         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
402         if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val) && $this->acl_is_writeable("gotoXHsync")){
404           $message[]= _("Please specify a valid HSync range.");
405         } elseif ($this->acl_is_writeable("gotoXHsync")){
406           list($v1,$v2)= preg_split ("/[-+]/", $val);
407           if ($v2 != ""){
408             if ($v1 > $v2){
409               $message[]= _("Please specify a valid HSync range.");
410             }
411           }
412         }
413       }
414     }
415   }
418   /* Check supplied data */
419   function check()
420   {
421     /* Call common method to give check the hook */
422     $message= plugin::check();
423     return ($message);
424   }
427   /* Save to LDAP */
428   function save()
429   {
430     /* Convert to string */
431     $this->gotoLpdEnable= $this->gotoLpdEnable?"Yes":"No";
433     plugin::save();
435     /* Strip out 'default' values */
436     foreach(array("gotoXMethod", "gotoXdmcpServer", "gotoFontPath",
437           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
438           "gotoLpdServer", "gotoScannerModel", "gotoXKbModel", "gotoXKbLayout",
439           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
441       if ($this->attrs[$val] == "default"){
442         $this->attrs[$val]= array();
443       }
444     }
446     if($this->AutoSync){
447       $this->attrs['gotoXHsync'] = "30+55";
448       $this->attrs['gotoXVsync'] = "50+70";
449     }
451     /* Write back to ldap */
452     $ldap= $this->config->get_ldap_link();
453     $ldap->cd($this->dn);
454     $this->cleanup();
455     $ldap->modify ($this->attrs); 
457     show_ldap_error($ldap->get_error(), sprintf(_("Saving of object system terminal/service with dn '%s' failed."),$this->dn));
458     $this->handle_post_events("modify");
459   }
462 /* Return plugin informations for acl handling */
463   function plInfo()
464   {
465     return (array(
466           "plShortName"   => _("Service"),
467           "plDescription" => _("Terminal service"),
468           "plSelfModify"  => FALSE,
469           "plDepends"     => array(),
470           "plPriority"    => 3,
471           "plSection"     => array("administration"),
472           "plCategory"    => array("terminal"),
474           "plProvidedAcls"=> array(
475             "gotoXMonitor"            => _("Monitor"),
476             "gotoXMethod"             => _("Method"),
477             "gotoXdmcpServer"         => _("Remote desktop"),
478             "gotoFontPath"            => _("Font path"),
479             "gotoXDriver"             => _("Gfx driver"),
480             "gotoXResolution"         => _("Gfx resolution"),
481             "gotoXColordepth"         => _("Gfx color depth"),
482             "gotoXHsync"              => _("Hsync"),
483             "gotoXVsync"              => _("Vsync"),
484             "AutoSync"                => _("Auto-Sync"),
485             "gotoLpdEnable"           => _("Printer service enabled"),
486             "gotoLpdServer"           => _("Spool server"),
487             "gotoScannerEnable"       => _("Scanner enabled"),
488             "gotoScannerModel"        => _("Scanner model"),
489             "gotoScannerClients"      => _("Heäh ? "),
490             "gotoScannerBackend"      => _("..."),
491             "gotoXKbModel"            => _("Keyboard model"),
492             "gotoXKbLayout"           => _("Keyboard layout"),
493             "gotoXKbVariant"          => _("Keyboard variant"),
494             "gotoXMouseType"          => _("Mouse type"),
495             "gotoXMouseport"          => _("Mouse port"),
496             "goFonHardware"           => _("Telephone hardware"))
497           ));
498   }
501 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
502 ?>