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