Code

Added acls for printer glpi
[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, $parent= NULL)
62   {
63     plugin::plugin ($config, $dn, $parent);
65     $this->XResolutions= array( 
66         "640x480"   =>  "640x480",
67         "800x600"   =>  "800x600",
68         "1024x768"  =>  "1024x768",
69         "1152x864"  =>  "1152x864", 
70         "1280x1024" =>  "1280x1024",
71         "1400x1050" =>  "1400x1050", 
72         "1600x1200" =>  "1600x1200");
74     if(isset($this->config->data['MAIN']['RESOLUTION_HOOK'])){
75       $file = $this->config->data['MAIN']['RESOLUTION_HOOK'];
77       if(is_readable($file)){
78         $str = file_get_contents($file);
79         $lines = split("\n",$str);
80         foreach($lines as $line){
81           $line = trim($line);
82           if(!empty($line)){
83             $this->XResolutions[$line]=$line;
84           }
85         }
86         //natcasesort($this->gotoXResolutions);
87       }else{
88         print_red(sprintf(_("You have specified an external resolution hook which can't be read, please check the permission of the file '%s'."),$file));
89       }
90     }
92     array_unshift($this->XDrivers, "["._("unknown")."]");
93  
94     $this->XColordepths= array( 
95         "8"        => "8 " ._("bit"), 
96         "15"       => "15 "._("bit"),      
97         "16"       => "16 "._("bit"),   
98         "24"       => "24 "._("bit"));
100     foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
101           "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
102           "logiinetnav", "logiinternet", "macintosh", "microsoft",
103           "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
104           "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
105       $this->XKbModels[$type] = $type;
106     }
108     $this->MouseTypes= array("ImPS/2" => "ImPS/2", "PS/2" => "PS/2", "Microsoft" => "Microsoft", 
109                               "Logitech" => "Logitech");
111     $this->MousePorts= array("/dev/ttyS0"  =>"/dev/ttyS0", 
112                              "/dev/ttyS1"       => "/dev/ttyS1",          "/dev/psaux"  =>"/dev/psaux", 
113                              "/dev/input/mice"  => "/dev/input/mice");
115     /* Additional values will be extracted from /etc/gosa/keyboardLayouts */
116     $this->XKbLayouts= array ("de"=> "de","intl" =>"intl","us" =>"us");
117     $this->XKbVariants= array ("nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
119     /* try to read additional keyboard layouts 
120      */
121     if(file_exists(CONFIG_DIR."/keyboardLayouts")){
122       if(is_readable(CONFIG_DIR."/keyboardLayouts")){
123         $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
124         $tmp = split("\n",$str);
125         foreach($tmp as $entry){
126           if((!empty($entry)) && (!preg_match("/^#/",$entry))){
127             $entry = trim($entry);
128             $tmp2 = split ("\:",$entry);
129             $la =   trim($tmp2[0]);   // What would be saved to ldap
130             $da =   trim($tmp2[1]);   // This wis displayed in the listbox
131             $this->XKbLayouts [ $la] = $da;  
132           } 
133         }
134       }
135     }
137     /* Initialize methods */
138     $this->XMethods["indirect"]= _("show chooser");
139     $this->XMethods["query"]= _("direct");
140     #$this->XMethods["squery"]= _("direct via ssh");
141     #$this->XMethods["nquery"]= _("direct via nx");
142     $this->XMethods["load"]= _("load balanced");
143     #$this->XMethods["sload"]= _("load balanced via ssh");
144     #$this->XMethods["nload"]= _("load balanced via nx");
145     $this->XMethods["rdp"]= _("Windows RDP");
146     $this->XMethods["citrix"]= _("ICA client");
148     $this->orig_dn= $this->dn;
150     /* Load hardware list */
151     $ldap= $this->config->get_ldap_link();
152     $ldap->cd($this->config->current['BASE']);
153     $ldap->search("(objectClass=goFonHardware)", array('cn', 'description'));
154     while ($attrs= $ldap->fetch()){
155       $cn= $attrs['cn'][0];
156       if (isset($attrs['description'])){
157         $description= " - ".$attrs['description'][0];
158       } else {
159         $description= "";
160       }
161       $this->hardware_list[$cn]= "$cn$description";
162     }
164     /* Eventually colorize phones */
165     $ldap->cd($this->config->current['BASE']);
166     foreach ($this->hardware_list as $cn => $desc){
167       $ldap->search("(goFonHardware=$cn)", array('cn'));
168       if ($ldap->count() > 0){
169         $ldap->fetch();
170         if ($ldap->getDN() != $this->dn){
171           $this->used_hardware[$cn]= $ldap->getDN();
172         }
173       }
174     }
176     if(preg_match("/\+/",$this->gotoXHsync)){
177       $this->AutoSync = true;
178       $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
179       $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
180     }
182     $this->hardware_list["automatic"]= _("automatic");
183     ksort($this->hardware_list);
185     /* Load hardware list */
186     $ldap= $this->config->get_ldap_link();
187     $ldap->cd($this->config->current['BASE']);
188     $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".$this->dn."))");
189     if ($ldap->count() == 1){
190       $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
191                   "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
192       $attrs= $ldap->fetch();
194       foreach ($map as $name){
195         if (!isset($attrs[$name][0])){
196           continue;
197         }
198         
199         switch ($name){
200           case 'gotoXResolution':
201             $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
202             break;
203           case 'gotoXColordepth':
204             $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
205             break;
206           case 'gotoXKbModel':
207             $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
208             break;
209           case 'gotoXKbLayout':
210             $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
211             break;
212           case 'gotoXKbVariant':
213             $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
214             break;
215           case 'gotoXMouseType':
216             $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
217             break;
218           case 'gotoXMouseport':
219             $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
220             break;
221         }
223       }
225     }
227     /* Workaround to fill in inherited values if we've specified an objectclass */
228     if (isset($_SESSION['SelectedSystemType']['ogroup']) && $_SESSION['SelectedSystemType']['ogroup'] != 'none'){
229       $this->XResolutions= array('default' => _("inherited"));
230       $this->XColordepths= array('default' => _("inherited"));
231       $this->XKbModels= array('default' => _("inherited"));
232       $this->XKbLayouts= array('default' => _("inherited"));
233       $this->XKbVariants= array('default' => _("inherited"));
234       $this->MouseTypes= array('AUTO' => _("inherited"));
235       $this->MousePorts= array('AUTO' => _("inherited"));
236     }
237   }
239   function execute()
240   {
241     /* Call parent execute */
242     plugin::execute();
244     /* Do we need to flip is_account state? */
245     if (isset($_POST['modify_state'])){
246       $this->is_account= !$this->is_account;
247     }
249     /* Do we need to flip is_account state? */
250     if(isset($_POST['modify_state'])){
251       if($this->is_account && $this->acl_is_removeable()){
252         $this->is_account= FALSE;
253       }elseif(!$this->is_account && $this->acl_is_createable()){
254         $this->is_account= TRUE;
255       }
256     }
258     /* Show main page */
259     $smarty= get_smarty();
261     /* Assign ACLs */
262     $tmp = $this->plInfo();
263     foreach($tmp['plProvidedAcls'] as $name => $translated){
264       $smarty->assign($name."ACL",$this->getacl($name));
265     }
267     /* Arrays */ 
268     foreach(array("XMethods", "XDrivers", "XResolutions", "XColordepths",
269           "XKbModels", "XKbVariants",
270           "MouseTypes", "MousePorts") as $val){
271       $smarty->assign("$val", $this->$val);
272     }
273     $smarty->assign("XKbLayouts"    ,$this->XKbLayouts);
274     $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
276     $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
277     $smarty->assign("fontservers", $this->config->data['SERVERS']['FONT']);
278     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
279     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
281     /* Variables - select */
282     foreach(array(
283           "gotoXDriver", "gotoXResolution", "gotoXColordepth", 
284           "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
285           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
287       $smarty->assign($val."_select", $this->$val);
288     }
290     /* Variables */
291     foreach(array("gotoXHsync", "gotoXVsync") as $val){
292       $smarty->assign($val, $this->$val);
293     }
294     $smarty->assign("staticAddress", "");
296     /* Checkboxes */
297     foreach(array("gotoScannerEnable") as $val){
298       if ($this->$val == TRUE) {
299         $smarty->assign("$val", "checked");
300       } else {
301         $smarty->assign("$val", "");
302       }
303     }
305     /* Phone stuff */
306     $smarty->assign ("goFonHardware", $this->goFonHardware);
308     $perms = "";
309     if($this->acl_is_writeable("goFonHardware")){
310       $perms = " disabled ";
311     }
313     $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
314       _("Choose the phone located at the current terminal")."\" >";
315     foreach ($this->hardware_list as $cn => $description){
316       if ($cn == $this->goFonHardware){
317         $selected= "selected";
318       } else {
319         $selected= "";
320       }
321       if (isset($this->used_hardware[$cn])){
322         $color= "style=\"color:#A0A0A0\"";
323       } else {
324         $color= "";
325       }
326       $hl.= "  <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
327     }
328     $hl.= "</select>\n";
329     $smarty->assign ("hardware_list", $hl);
330     $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
332     if($this->AutoSync){
333       $smarty->assign("AutoSyncCHK"," checked ");
334       $smarty->assign("hiddenState"," disabled ");
335     }else{
336       $smarty->assign("AutoSyncCHK"," ");
337       $smarty->assign("hiddenState","");
338     }
340     /* Show main page */
341     return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
342   }
344   function remove_from_parent()
345   {
346     $this->handle_post_events("remove");
347   }
349   /* Save data to object */
350   function save_object()
351   {
352     plugin::save_object();
354     if((isset($_POST['gotoXDriver'])) && $this->acl_is_writeable("AutoSync")) {
355       if(isset($_POST['AutoSync'])){
356         $this->AutoSync = true;
357       }else{
358         $this->AutoSync = false;
359       }
360     }
361   }
363   /* Check supplied data */
364   function check()
365   {
366     /* Call common method to give check the hook */
367     $message= plugin::check();
369     /* Default entries can use blank hsync/vsync entries */
370     if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
372       /* But only if no auto sync is enabled... */
373       if (!$this->AutoSync){
375         /* Check vsync for correct usage */
376         $val= preg_replace ("/\s/", "", $this->gotoXVsync);
378         if($this->acl_is_writeable("gotoXVsync")){
379           if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
380             $message[]= _("Please specify a valid VSync range.");
381           } else{
382             list($v1,$v2)= preg_split ("/[-+]/", $val);
383             if ($v2 != ""){
384               if ($v1 > $v2){
385                 $message[]= _("Please specify a valid VSync range.");
386               }
387             }
388           }
389         }
391         /* Check hsync for correct usage */
392         $val= preg_replace ("/\s/", "", $this->gotoXHsync);
393         if($this->acl_is_writeable("gotoXHsync")){
394           if (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
395             $message[]= _("Please specify a valid HSync range.");
396           } else{
397             list($v1,$v2)= preg_split ("/[-+]/", $val);
398             if ($v2 != ""){
399               if ($v1 > $v2){
400                 $message[]= _("Please specify a valid HSync range.");
401               }
402             }
403           }
404         }
405       }
406     }
408     return ($message);
409   }
412   /* Save to LDAP */
413   function save()
414   {
415     /* remove objectclass GOhard if this is an ogroup tab */
416     if(isset($this->parent->by_object['ogroup'])){
417       $this->objectclasses = array();
418     }
420     plugin::save();
422     /* Strip out 'default' values */
423     foreach(array(
424           "gotoXDriver", "gotoXResolution", "gotoXColordepth",
425           "gotoXKbModel", "gotoXKbLayout",
426           "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
428       if ($this->attrs[$val] == "default"){
429         $this->attrs[$val]= array();
430       }
431     }
433     if($this->AutoSync){
434       $this->attrs['gotoXHsync'] = "30+55";
435       $this->attrs['gotoXVsync'] = "50+70";
436     }
438     /* Write back to ldap */
439     $ldap= $this->config->get_ldap_link();
440     $ldap->cd($this->dn);
441     $this->cleanup();
442     $ldap->modify ($this->attrs); 
443     show_ldap_error($ldap->get_error(), sprintf(_("Saving of system workstation/service with dn '%s' failed."),$this->dn));
444     $this->handle_post_events("modify");
445   }
447   /* Return plugin informations for acl handling */
448   function plInfo()
449   {
450     return (array(
451           "plShortName"   => _("Service"),
452           "plDescription" => _("Workstation service"),
453           "plSelfModify"  => FALSE,
454           "plDepends"     => array(),
455           "plPriority"    => 0,
456           "plSection"     => array("administration"),
457           "plCategory"    => array("workstation","ogroups"), 
459           "plProvidedAcls"=> array(
460             "gotoXMonitor"          => _("Monitor"),
461             "gotoXDriver"           => _("Gfx driver"),
462             "gotoXResolution"       => _("Gfx resolution"),
463             "gotoXColordepth"       => _("Gfx color depth"),
464             "gotoXHsync"            => _("Hsync"),
465             "gotoXVsync"            => _("Vsync"),
466             "AutoSync"              => _("Use DDC"),
467             "gotoScannerEnable"     => _("Scanner enabled"),
468             "gotoXKbModel"          => _("Keyboard model"),
469             "gotoXKbLayout"         => _("Keyboard layout"),
470             "gotoXKbVariant"        => _("Keyboard variant"),
471             "gotoXMouseType"        => _("Mouse type"),
472             "gotoXMouseport"        => _("Mouse port"),
473             "goFonHardware"         => _("Telephone hardware")) 
474             ));
475   }
478 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
479 ?>