47a3da9d939fda67aac55933038af92f214ce26e
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();
36 var $ogroup = FALSE;
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 foreach($this->getListOfXDrivers() as $xdriver) {
84 $this->XDrivers[$xdriver] = $xdriver;
85 }
87 if (isset($this->attrs['gosaGroupObjects'])) {
88 array_unshift($this->XDrivers, "["._("manual/auto")."]");
89 }
90 else {
91 array_unshift($this->XDrivers, "["._("unknown")."]");
92 }
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("auto" => "auto",
109 "explorerps/2" => "explorerps/2",
110 "ImPS/2" => "ImPS/2",
111 "PS/2" => "PS/2",
112 "Microsoft" => "Microsoft",
113 "Logitech" => "Logitech",);
115 $this->MousePorts= array("/dev/input/mice" => "/dev/input/mice",
116 "/dev/mouse" => "/dev/mouse",
117 "/dev/psaux" => "/dev/psaux",
118 "/dev/ttyS0" => "/dev/ttyS0",
119 "/dev/ttyS1" => "/dev/ttyS1",);
121 /* Additional values will be extracted from CONFIG_DIR./keyboardLayouts */
122 $this->XKbLayouts = array("de"=> "de","en" =>"en", "es" => "es", "us" =>"us", "fr" => "fr");
123 $this->XKbVariants= array ("nodeadkeys"=>"nodeadkeys", "basic"=>"basic");
125 /* try to read additional keyboard layouts
126 */
127 if(file_exists(CONFIG_DIR."/keyboardLayouts")){
128 if(is_readable(CONFIG_DIR."/keyboardLayouts")){
129 $str = file_get_contents(CONFIG_DIR."/keyboardLayouts");
130 $tmp = split("\n",$str);
131 foreach($tmp as $entry){
132 if((!empty($entry)) && (!preg_match("/^#/",$entry))){
133 $entry = trim($entry);
134 $tmp2 = split ("\:",$entry);
135 $la = trim($tmp2[0]); // What would be saved to ldap
136 $da = trim($tmp2[1]); // This wis displayed in the listbox
137 $this->XKbLayouts [ $la] = $da;
138 }
139 }
140 }
141 }
143 $this->orig_dn= $this->dn;
145 /* Load phone hardware list
146 */
147 $tmp = get_sub_list("(objectClass=goFonHardware)","",array(get_ou("phoneRDN")),
148 $this->config->current['BASE'],array("cn","description"), GL_NO_ACL_CHECK);
149 foreach($tmp as $attrs){
150 $cn= $attrs['cn'][0];
151 $description= "";
152 if (isset($attrs['description'])){
153 $description= " - ".$attrs['description'][0];
154 }
155 $this->hardware_list[$cn]= "$cn$description";
156 }
157 $this->hardware_list["automatic"]= _("automatic");
158 ksort($this->hardware_list);
160 /* These departments may contain objects that have
161 goFonHardware set.
162 */
163 $deps_a = array(
164 get_people_ou(),
165 get_ou("ogroupRDN"),
166 get_ou("serverRDN"),
167 get_ou("terminalRDN"),
168 get_ou("workstationRDN"),
169 get_ou("printerRDN"),
170 get_ou("componentRDN"),
171 get_ou("phoneRDN"));
173 $tmp = get_sub_list("(goFonHardware=*)","",$deps_a,$this->config->current['BASE'],
174 array('cn','dn','goFonHardware'),GL_NO_ACL_CHECK);
175 foreach($tmp as $attrs){
176 $cn = $attrs['goFonHardware'][0];
177 if(isset($this->hardware_list[$cn])){
178 $this->used_hardware[$cn]= $cn;
179 }
180 }
182 if(preg_match("/\+/",$this->gotoXHsync)){
183 $this->AutoSync = true;
184 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
185 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
186 }
188 /* Workaround to fill in inherited values if we've specified an objectclass */
189 $SelectedSystemType = session::get("SelectedSystemType");
190 if (isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
191 $this->XDrivers=array('default' => _("inherited"));
192 $this->XResolutions= array('default' => _("inherited"));
193 $this->XColordepths= array('default' => _("inherited"));
194 $this->XKbModels= array('default' => _("inherited"));
195 $this->XKbLayouts= array('default' => _("inherited"));
196 $this->XKbVariants= array('default' => _("inherited"));
197 $this->MouseTypes= array('default' => _("inherited"));
198 $this->MousePorts= array('default' => _("inherited"));
199 }
200 }
202 function execute()
203 {
204 /* Call parent execute */
205 plugin::execute();
207 /* Load hardware list */
208 $this->loadHardwareList();
210 if($this->is_account && !$this->view_logged){
211 $this->view_logged = TRUE;
212 new log("view","workstation/".get_class($this),$this->dn);
213 }
215 /* Do we need to flip is_account state? */
216 if (isset($_POST['modify_state'])){
217 $this->is_account= !$this->is_account;
218 }
220 /* Do we need to flip is_account state? */
221 if(isset($_POST['modify_state'])){
222 if($this->is_account && $this->acl_is_removeable()){
223 $this->is_account= FALSE;
224 }elseif(!$this->is_account && $this->acl_is_createable()){
225 $this->is_account= TRUE;
226 }
227 }
229 /* Show main page */
230 $smarty= get_smarty();
232 /* Assign ACLs */
233 $tmp = $this->plInfo();
234 foreach($tmp['plProvidedAcls'] as $name => $translated){
235 $smarty->assign($name."ACL",$this->getacl($name));
236 }
238 /* Arrays */
239 foreach(array("XDrivers", "XResolutions", "XColordepths",
240 "XKbModels", "XKbVariants",
241 "MouseTypes", "MousePorts") as $val){
242 $smarty->assign("$val", $this->$val);
243 }
244 $smarty->assign("XKbLayouts" ,$this->XKbLayouts);
245 $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
247 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
248 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
249 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
251 /* Variables - select */
252 foreach(array(
253 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
254 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
255 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
257 $smarty->assign($val."_select", $this->$val);
258 }
260 /* Variables */
261 foreach(array("gotoXHsync", "gotoXVsync") as $val){
262 $smarty->assign($val, $this->$val);
263 }
264 $smarty->assign("staticAddress", "");
266 /* Checkboxes */
267 foreach(array("gotoScannerEnable") as $val){
268 if ($this->$val == TRUE) {
269 $smarty->assign("$val", "checked");
270 } else {
271 $smarty->assign("$val", "");
272 }
273 }
275 /* Phone stuff */
276 $smarty->assign ("goFonHardware", $this->goFonHardware);
278 $perms = "";
279 if(!$this->acl_is_writeable("goFonHardware")){
280 $perms = " disabled ";
281 }
283 $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
284 _("Choose the phone located at the current terminal")."\" >";
285 foreach ($this->hardware_list as $cn => $description){
286 if ($cn == $this->goFonHardware){
287 $selected= "selected";
288 } else {
289 $selected= "";
290 }
291 if (isset($this->used_hardware[$cn])){
292 $color= "style=\"color:#A0A0A0\"";
293 } else {
294 $color= "";
295 }
296 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
297 }
298 $hl.= "</select>\n";
299 $smarty->assign ("hardware_list", $hl);
300 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
302 if($this->AutoSync){
303 $smarty->assign("AutoSyncCHK"," checked ");
304 $smarty->assign("hiddenState"," disabled ");
305 }else{
306 $smarty->assign("AutoSyncCHK"," ");
307 $smarty->assign("hiddenState","");
308 }
310 /* Show main page */
311 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
312 }
314 function remove_from_parent()
315 {
316 /* Cancel if there's nothing to do here */
317 if ((!$this->acl_is_removeable())){
318 return;
319 }
321 /* Remove and write to LDAP */
322 plugin::remove_from_parent();
323 $ldap = $this->config->get_ldap_link();
324 $ldap->cd($this->dn);
325 $this->cleanup();
326 $ldap->modify($this->attrs);
327 $this->handle_post_events("remove");
328 new log("remove","workstation/".get_class($this),$this->dn);
329 }
331 /* Save data to object */
332 function save_object()
333 {
334 plugin::save_object();
336 if((isset($_POST['workservicePosted'])) && $this->acl_is_writeable("AutoSync")) {
337 if(isset($_POST['AutoSync'])){
338 $this->AutoSync = true;
339 }else{
340 $this->AutoSync = false;
341 }
342 }
343 }
345 /* Check supplied data */
346 function check()
347 {
348 /* Call common method to give check the hook */
349 $message= plugin::check();
351 /* Default entries can use blank hsync/vsync entries */
352 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
354 /* But only if no auto sync is enabled... */
355 if (!$this->AutoSync){
357 /* Check vsync for correct usage */
358 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
360 if($this->acl_is_writeable("gotoXVsync")){
361 if(empty($val)){
362 $message[]= msgPool::required(_("VSync"));
363 }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
364 $message[]= msgPool::invalid(_("VSync"));
365 } else{
366 list($v1,$v2)= preg_split ("/[-+]/", $val);
367 if ($v2 != ""){
368 if ($v1 > $v2){
369 $message[]= msgPool::invalid(_("VSync"));
370 }
371 }
372 }
373 }
375 /* Check hsync for correct usage */
376 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
377 if($this->acl_is_writeable("gotoXHsync")){
378 if(empty($val)){
379 $message[]= msgPool::required(_("HSync"));
380 }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
381 $message[]= msgPool::invalid(_("HSync"));
382 } else{
383 list($v1,$v2)= preg_split ("/[-+]/", $val);
384 if ($v2 != ""){
385 if ($v1 > $v2){
386 $message[]= msgPool::invalid(_("HSync"));
387 }
388 }
389 }
390 }
391 }
392 }
394 return ($message);
395 }
398 /* Save to LDAP */
399 function save()
400 {
401 /* remove objectclass GOhard if this is an ogroup tab */
402 if(isset($this->parent->by_object['ogroup'])){
403 $this->objectclasses = array();
404 }
406 plugin::save();
408 /* Strip out 'default' values */
409 foreach(array(
410 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
411 "gotoXKbModel", "gotoXKbLayout", "gotoXDriver",
412 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
414 if ($this->attrs[$val] == "default"){
415 $this->attrs[$val]= array();
416 }
417 }
419 if($this->AutoSync){
420 $this->attrs['gotoXHsync'] = "30+55";
421 $this->attrs['gotoXVsync'] = "50+70";
422 }
424 /* Write back to ldap */
425 $ldap= $this->config->get_ldap_link();
426 $ldap->cd($this->dn);
427 $this->cleanup();
430 $ldap->modify ($this->attrs);
431 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
432 if (!$ldap->success()){
433 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
434 }
435 $this->handle_post_events("modify");
437 /* Send goto reload event to gosaSupportDaemon */
438 if(count($this->attrs)){
439 $this->send_goto_reload();
440 }
442 }
444 function loadHardwareList()
445 {
446 $ldap= $this->config->get_ldap_link();
448 if ($this->ogroup) {
449 $ldap->cat($this->ogroup);
450 } else {
451 $ldap->cd($this->config->current['BASE']);
452 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
453 }
454 if ($ldap->count() == 1){
455 $attrs= $ldap->fetch();
456 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
457 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport", "gotoXDriver");
458 foreach ($map as $name){
459 if (!isset($attrs[$name][0])){
460 continue;
461 }
463 switch ($name){
464 case 'gotoXDriver':
465 $ogroup_driver = $attrs['gotoXDriver'][0];
466 if (in_array($ogroup_driver, $this->XDrivers) && (empty($this->attrs['gotoXDriver']))) {
467 $this->XDrivers = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers;
468 }
469 break;
470 case 'gotoXResolution':
471 $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
472 break;
473 case 'gotoXColordepth':
474 $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
475 break;
476 case 'gotoXKbModel':
477 $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
478 break;
479 case 'gotoXKbLayout':
480 $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
481 break;
482 case 'gotoXKbVariant':
483 $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
484 break;
485 case 'gotoXMouseType':
486 $this->MouseTypes= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
487 break;
488 case 'gotoXMouseport':
489 $this->MousePorts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
490 break;
491 }
493 }
495 }
498 }
500 function getListOfXDrivers()
501 {
502 /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */
503 $drivers = array();
504 if (file_exists(CONFIG_DIR.'/xdrivers')){
505 $xdrivers = file (CONFIG_DIR.'/xdrivers');
506 foreach ($xdrivers as $line){
507 if (!preg_match ("/^#/", $line)){
508 $drivers[]= trim($line);
509 }
510 }
511 } else {
512 $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
513 "i128", "i740", "i810", "intel", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia",
514 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
515 "sis", "tdfx", "tga", "trident", "tseng", "vboxvideo", "vesa", "vga", "vmware");
516 }
517 return($drivers);
518 }
521 /* Return plugin informations for acl handling */
522 static function plInfo()
523 {
524 return (array(
525 "plShortName" => _("Service"),
526 "plDescription" => _("Workstation service"),
527 "plSelfModify" => FALSE,
528 "plDepends" => array(),
529 "plPriority" => 10,
530 "plSection" => array("administration"),
531 "plCategory" => array("workstation","ogroups"),
533 "plProvidedAcls"=> array(
534 "gotoXMonitor" => _("Monitor"),
535 "gotoXDriver" => _("Gfx driver"),
536 "gotoXResolution" => _("Gfx resolution"),
537 "gotoXColordepth" => _("Gfx color depth"),
538 "gotoXHsync" => _("HSync"),
539 "gotoXVsync" => _("VSync"),
540 "AutoSync" => _("Use DDC"),
541 "gotoScannerEnable" => _("Scanner enabled"),
542 "gotoXKbModel" => _("Keyboard model"),
543 "gotoXKbLayout" => _("Keyboard layout"),
544 "gotoXKbVariant" => _("Keyboard variant"),
545 "gotoXMouseType" => _("Mouse type"),
546 "gotoXMouseport" => _("Mouse port"),
547 "goFonHardware" => _("Telephone hardware"))
548 ));
549 }
552 /*! \brief Send goto_reload event to support daemon
553 */
554 function send_goto_reload()
555 {
556 if(count($this->attrs) && class_available("DaemonEvent")){
557 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
558 $o_queue = new gosaSupportDaemon();
559 if(isset($events['TRIGGERED']['DaemonEvent_goto_reload'])){
560 $evt = $events['TRIGGERED']['DaemonEvent_goto_reload'];
561 $macs = array();
563 /* Get list of macAddresses
564 */
565 if(isset($this->parent->by_object['ogroup'])){
567 /* If we are an object group, add all member macs
568 */
569 $p = $this->parent->by_object['ogroup'];
570 foreach($p->memberList as $dn => $obj){
571 if(preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$dn)) continue;
572 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
573 $macs[] = $p->objcache[$dn]['macAddress'];
574 }
575 }
576 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
578 /* We are a workstation. Add current mac.
579 */
580 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
581 if(!empty($mac) && !preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->orig_dn)){
582 $macs[] = $mac;
583 }
584 }
586 /* Trigger event for all member objects
587 */
588 if(count($macs)){
589 $tmp = new $evt['CLASS_NAME']($this->config);
590 $tmp->set_type(TRIGGERED_EVENT);
591 $target = $o_queue->get_host().":".$o_queue->get_port();
592 $tmp->add_targets(array($target));
593 $tmp->set_macs($macs);
594 if(!$o_queue->append($tmp,TRUE)){
595 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
596 }
597 }
598 }
599 }
600 }
603 function PrepareForCopyPaste($source)
604 {
605 plugin::PrepareForCopyPaste($source);
607 if(preg_match("/\+/",$this->gotoXHsync)){
608 $this->AutoSync = true;
609 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
610 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
611 }
612 }
613 }
615 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
616 ?>