1 <?php
3 class workservice extends plugin
4 {
5 var $gotoScannerEnable;
7 /* Generic terminal attributes */
8 var $gotoXMonitor= "";
9 var $gotoXDriver= "";
10 var $gotoXResolution= "";
11 var $gotoXColordepth= "";
12 var $gotoXHsync= "";
13 var $gotoXVsync= "";
14 var $AutoSync = false;
15 var $gotoXKbModel= "";
16 var $gotoXKbLayout= "";
17 var $gotoXKbVariant= "";
18 var $gotoXMouseType= "";
19 var $gotoXMouseport= "";
20 var $gotoScannerClients= "";
21 var $gotoScannerBackend= "";
22 var $goFonHardware= "automatic";
23 var $view_logged = FALSE;
25 /* Needed values and lists */
26 var $ignore_account= TRUE;
27 var $base= "";
28 var $cn= "";
29 var $orig_dn= "";
30 var $XDrivers= array();
31 var $XResolutions = array();
32 var $MouseTypes= array();
33 var $MousePorts= array();
34 var $hardware_list= array();
35 var $used_hardware= array();
38 /* attribute list for save action */
39 var $attributes= array("gotoXMonitor", "gotoXDriver", "gotoXResolution", "gotoXColordepth",
40 "gotoXHsync", "gotoXVsync",
41 "gotoScannerEnable", "gotoScannerClients",
42 "gotoScannerBackend", "gotoXKbModel", "gotoXKbLayout", "gotoXKbVariant",
43 "gotoXMouseType", "gotoXMouseport", "goFonHardware");
44 var $objectclasses= array("GOhard");
46 var $XColordepths =array();
47 var $XKbModels =array();
48 var $XKbLayouts =array();
49 var $XKbVariants =array();
51 function workservice (&$config, $dn= NULL, $parent= NULL)
52 {
53 plugin::plugin ($config, $dn, $parent);
55 $this->XResolutions= array(
56 "640x480" => "640x480",
57 "800x600" => "800x600",
58 "1024x768" => "1024x768",
59 "1152x864" => "1152x864",
60 "1280x1024" => "1280x1024",
61 "1400x1050" => "1400x1050",
62 "1600x1200" => "1600x1200");
64 if($this->config->get_cfg_value("resolutions") != ""){
65 $file = $this->config->get_cfg_value("resolutions");
67 if(is_readable($file)){
68 $str = file_get_contents($file);
69 $lines = split("\n",$str);
70 foreach($lines as $line){
71 $line = trim($line);
72 if(!empty($line)){
73 $this->XResolutions[$line]=$line;
74 }
75 }
76 //natcasesort($this->gotoXResolutions);
77 }else{
78 msg_dialog::display(_("Configuration error"), msgPool::cannotReadFile($file), WARNING_DIALOG);
79 }
80 }
82 /* Get list of available xdrivers */
83 $this->XDrivers = $this->getListOfXDrivers();
85 array_unshift($this->XDrivers, "["._("unknown")."]");
87 $this->XColordepths= array(
88 "8" => "8 " ._("bit"),
89 "15" => "15 "._("bit"),
90 "16" => "16 "._("bit"),
91 "24" => "24 "._("bit"));
93 foreach(array ("btc9000", "chicony", "compaq", "dell", "dell101", "everex",
94 "flexpro", "geniuscomfy", "hp", "itouch", "jp106", "logicordless",
95 "logiinetnav", "logiinternet", "macintosh", "microsoft",
96 "microsoftpro", "omnikey101", "pc101", "pc102", "pc104",
97 "pc105", "rapidaccess", "rapidaccess2", "winbook") as $type){
98 $this->XKbModels[$type] = $type;
99 }
101 $this->MouseTypes= array("ImPS/2" => "ImPS/2", "PS/2" => "PS/2", "Microsoft" => "Microsoft",
102 "Logitech" => "Logitech","explorerps/2"=>"explorerps/2",);
104 $this->MousePorts= array("/dev/ttyS0" =>"/dev/ttyS0",
105 "/dev/ttyS1" => "/dev/ttyS1", "/dev/psaux" =>"/dev/psaux",
106 "/dev/input/mice" => "/dev/input/mice");
108 /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */
109 $this->XKbLayouts = array("de"=> "de","en" =>"en", "es" => "es", "us" =>"us", "fr" => "fr");
110 $this->XKbVariants= array ("nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
112 /* try to read additional keyboard layouts
113 */
114 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
115 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
116 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
117 $tmp = split("\n",$str);
118 foreach($tmp as $entry){
119 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
120 $entry = trim($entry);
121 $tmp2 = split ("\:",$entry);
122 $la = trim($tmp2[0]); // What would be saved to ldap
123 $da = trim($tmp2[1]); // This wis displayed in the listbox
124 $this->XKbLayouts [ $la] = $da;
125 }
126 }
127 }
128 }
130 $this->orig_dn= $this->dn;
132 /* Load phone hardware list
133 */
134 $tmp = get_sub_list("(objectClass=goFonHardware)","",array(get_ou("phoneRDN")),
135 $this->config->current['BASE'],array("cn","description"), GL_NO_ACL_CHECK);
136 foreach($tmp as $attrs){
137 $cn= $attrs['cn'][0];
138 $description= "";
139 if (isset($attrs['description'])){
140 $description= " - ".$attrs['description'][0];
141 }
142 $this->hardware_list[$cn]= "$cn$description";
143 }
144 $this->hardware_list["automatic"]= _("automatic");
145 ksort($this->hardware_list);
147 /* These departments may contain objects that have
148 goFonHardware set.
149 */
150 $deps_a = array(
151 get_people_ou(),
152 get_ou("ogroupRDN"),
153 get_ou("serverRDN"),
154 get_ou("terminalRDN"),
155 get_ou("workstationRDN"),
156 get_ou("printerRDN"),
157 get_ou("componentRDN"),
158 get_ou("phoneRDN"));
160 $tmp = get_sub_list("(goFonHardware=*)","",$deps_a,$this->config->current['BASE'],
161 array('cn','dn','goFonHardware'),GL_NO_ACL_CHECK);
162 foreach($tmp as $attrs){
163 $cn = $attrs['goFonHardware'][0];
164 if(isset($this->hardware_list[$cn])){
165 $this->used_hardware[$cn]= $cn;
166 }
167 }
169 if(preg_match("/\+/",$this->gotoXHsync)){
170 $this->AutoSync = true;
171 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
172 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
173 }
175 /* Load hardware list */
176 $ldap= $this->config->get_ldap_link();
177 $ldap->cd($this->config->current['BASE']);
178 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
179 if ($ldap->count() == 1){
180 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
181 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport");
182 $attrs= $ldap->fetch();
184 foreach ($map as $name){
185 if (!isset($attrs[$name][0])){
186 continue;
187 }
189 switch ($name){
190 case 'gotoXResolution':
191 $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
192 break;
193 case 'gotoXColordepth':
194 $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
195 break;
196 case 'gotoXKbModel':
197 $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
198 break;
199 case 'gotoXKbLayout':
200 $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
201 break;
202 case 'gotoXKbVariant':
203 $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
204 break;
205 case 'gotoXMouseType':
206 $this->MouseTypes= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
207 break;
208 case 'gotoXMouseport':
209 $this->MousePorts= array('AUTO' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
210 break;
211 }
213 }
215 }
217 /* Workaround to fill in inherited values if we've specified an objectclass */
218 $SelectedSystemType = session::get("SelectedSystemType");
219 if (isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
220 $this->XResolutions= array('default' => _("inherited"));
221 $this->XColordepths= array('default' => _("inherited"));
222 $this->XKbModels= array('default' => _("inherited"));
223 $this->XKbLayouts= array('default' => _("inherited"));
224 $this->XKbVariants= array('default' => _("inherited"));
225 $this->MouseTypes= array('AUTO' => _("inherited"));
226 $this->MousePorts= array('AUTO' => _("inherited"));
227 }
228 }
230 function execute()
231 {
232 /* Call parent execute */
233 plugin::execute();
235 if($this->is_account && !$this->view_logged){
236 $this->view_logged = TRUE;
237 new log("view","workstation/".get_class($this),$this->dn);
238 }
240 /* Do we need to flip is_account state? */
241 if (isset($_POST['modify_state'])){
242 $this->is_account= !$this->is_account;
243 }
245 /* Do we need to flip is_account state? */
246 if(isset($_POST['modify_state'])){
247 if($this->is_account && $this->acl_is_removeable()){
248 $this->is_account= FALSE;
249 }elseif(!$this->is_account && $this->acl_is_createable()){
250 $this->is_account= TRUE;
251 }
252 }
254 /* Show main page */
255 $smarty= get_smarty();
257 /* Assign ACLs */
258 $tmp = $this->plInfo();
259 foreach($tmp['plProvidedAcls'] as $name => $translated){
260 $smarty->assign($name."ACL",$this->getacl($name));
261 }
263 /* Arrays */
264 foreach(array("XDrivers", "XResolutions", "XColordepths",
265 "XKbModels", "XKbVariants",
266 "MouseTypes", "MousePorts") as $val){
267 $smarty->assign("$val", $this->$val);
268 }
269 $smarty->assign("XKbLayouts" ,$this->XKbLayouts);
270 $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
272 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
273 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
274 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
276 /* Variables - select */
277 foreach(array(
278 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
279 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
280 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
282 $smarty->assign($val."_select", $this->$val);
283 }
285 /* Variables */
286 foreach(array("gotoXHsync", "gotoXVsync") as $val){
287 $smarty->assign($val, $this->$val);
288 }
289 $smarty->assign("staticAddress", "");
291 /* Checkboxes */
292 foreach(array("gotoScannerEnable") as $val){
293 if ($this->$val == TRUE) {
294 $smarty->assign("$val", "checked");
295 } else {
296 $smarty->assign("$val", "");
297 }
298 }
300 /* Phone stuff */
301 $smarty->assign ("goFonHardware", $this->goFonHardware);
303 $perms = "";
304 if(!$this->acl_is_writeable("goFonHardware")){
305 $perms = " disabled ";
306 }
308 $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
309 _("Choose the phone located at the current terminal")."\" >";
310 foreach ($this->hardware_list as $cn => $description){
311 if ($cn == $this->goFonHardware){
312 $selected= "selected";
313 } else {
314 $selected= "";
315 }
316 if (isset($this->used_hardware[$cn])){
317 $color= "style=\"color:#A0A0A0\"";
318 } else {
319 $color= "";
320 }
321 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
322 }
323 $hl.= "</select>\n";
324 $smarty->assign ("hardware_list", $hl);
325 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
327 if($this->AutoSync){
328 $smarty->assign("AutoSyncCHK"," checked ");
329 $smarty->assign("hiddenState"," disabled ");
330 }else{
331 $smarty->assign("AutoSyncCHK"," ");
332 $smarty->assign("hiddenState","");
333 }
335 /* Show main page */
336 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
337 }
339 function remove_from_parent()
340 {
341 $this->handle_post_events("remove");
342 new log("remove","workstation/".get_class($this),$this->dn);
343 }
345 /* Save data to object */
346 function save_object()
347 {
348 plugin::save_object();
350 if((isset($_POST['workservicePosted'])) && $this->acl_is_writeable("AutoSync")) {
351 if(isset($_POST['AutoSync'])){
352 $this->AutoSync = true;
353 }else{
354 $this->AutoSync = false;
355 }
356 }
357 }
359 /* Check supplied data */
360 function check()
361 {
362 /* Call common method to give check the hook */
363 $message= plugin::check();
365 /* Default entries can use blank hsync/vsync entries */
366 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
368 /* But only if no auto sync is enabled... */
369 if (!$this->AutoSync){
371 /* Check vsync for correct usage */
372 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
374 if($this->acl_is_writeable("gotoXVsync")){
375 if(empty($val)){
376 $message[]= msgPool::required(_("VSync"));
377 }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
378 $message[]= msgPool::invalid(_("VSync"));
379 } else{
380 list($v1,$v2)= preg_split ("/[-+]/", $val);
381 if ($v2 != ""){
382 if ($v1 > $v2){
383 $message[]= msgPool::invalid(_("VSync"));
384 }
385 }
386 }
387 }
389 /* Check hsync for correct usage */
390 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
391 if($this->acl_is_writeable("gotoXHsync")){
392 if(empty($val)){
393 $message[]= msgPool::required(_("HSync"));
394 }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
395 $message[]= msgPool::invalid(_("HSync"));
396 } else{
397 list($v1,$v2)= preg_split ("/[-+]/", $val);
398 if ($v2 != ""){
399 if ($v1 > $v2){
400 $message[]= msgPool::invalid(_("HSync"));
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();
444 $ldap->modify ($this->attrs);
445 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
446 if (!$ldap->success()){
447 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
448 }
449 $this->handle_post_events("modify");
451 /* Send goto reload event to gosaSupportDaemon */
452 if(count($this->attrs)){
453 $this->send_goto_reload();
454 }
456 }
459 function getListOfXDrivers()
460 {
461 /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */
462 $drivers = array();
463 if (file_exists(CONFIG_DIR.'/xdrivers')){
464 $xdrivers = file (CONFIG_DIR.'/xdrivers');
465 foreach ($xdrivers as $line){
466 if (!preg_match ("/^#/", $line)){
467 $drivers[]= trim($line);
468 }
469 }
470 } else {
471 $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
472 "i128", "i740", "i810", "intel", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia",
473 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
474 "sis", "tdfx", "tga", "trident", "tseng", "vesa", "vga", "vmware");
475 }
476 return($drivers);
477 }
480 /* Return plugin informations for acl handling */
481 static function plInfo()
482 {
483 return (array(
484 "plShortName" => _("Service"),
485 "plDescription" => _("Workstation service"),
486 "plSelfModify" => FALSE,
487 "plDepends" => array(),
488 "plPriority" => 10,
489 "plSection" => array("administration"),
490 "plCategory" => array("workstation","ogroups"),
492 "plProvidedAcls"=> array(
493 "gotoXMonitor" => _("Monitor"),
494 "gotoXDriver" => _("Gfx driver"),
495 "gotoXResolution" => _("Gfx resolution"),
496 "gotoXColordepth" => _("Gfx color depth"),
497 "gotoXHsync" => _("HSync"),
498 "gotoXVsync" => _("VSync"),
499 "AutoSync" => _("Use DDC"),
500 "gotoScannerEnable" => _("Scanner enabled"),
501 "gotoXKbModel" => _("Keyboard model"),
502 "gotoXKbLayout" => _("Keyboard layout"),
503 "gotoXKbVariant" => _("Keyboard variant"),
504 "gotoXMouseType" => _("Mouse type"),
505 "gotoXMouseport" => _("Mouse port"),
506 "goFonHardware" => _("Telephone hardware"))
507 ));
508 }
511 /*! \brief Send goto_reload event to support daemon
512 */
513 function send_goto_reload()
514 {
515 if(count($this->attrs) && class_available("DaemonEvent")){
516 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
517 $o_queue = new gosaSupportDaemon();
518 if(isset($events['TRIGGERED']['DaemonEvent_goto_reload'])){
519 $evt = $events['TRIGGERED']['DaemonEvent_goto_reload'];
520 $macs = array();
522 /* Get list of macAddresses
523 */
524 if(isset($this->parent->by_object['ogroup'])){
526 /* If we are an object group, add all member macs
527 */
528 $p = $this->parent->by_object['ogroup'];
529 foreach($p->memberList as $dn => $obj){
530 if(preg_match("/".preg_quote(get_ou("systemIncomingRDN"))."/",$dn)) continue;
531 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
532 $macs[] = $p->objcache[$dn]['macAddress'];
533 }
534 }
535 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
537 /* We are a workstation. Add current mac.
538 */
539 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
540 if(!empty($mac) && !preg_match("/".preg_quote(get_ou("systemIncomingRDN"))."/",$this->orig_dn)){
541 $macs[] = $mac;
542 }
543 }
545 /* Trigger event for all member objects
546 */
547 if(count($macs)){
548 $tmp = new $evt['CLASS_NAME']($this->config);
549 $tmp->set_type(TRIGGERED_EVENT);
550 $target = $o_queue->get_host().":".$o_queue->get_port();
551 $tmp->add_targets(array($target));
552 $tmp->set_macs($macs);
553 if(!$o_queue->append($tmp,TRUE)){
554 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
555 }
556 }
557 }
558 }
559 }
562 function PrepareForCopyPaste($source)
563 {
564 plugin::PrepareForCopyPaste($source);
566 if(preg_match("/\+/",$this->gotoXHsync)){
567 $this->AutoSync = true;
568 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
569 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
570 }
571 }
572 }
574 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
575 ?>