fde0993dee56fd7ce4e142a2a532266bcc7344bd
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 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 /* Load hardware list */
189 $ldap= $this->config->get_ldap_link();
190 $ldap->cd($this->config->current['BASE']);
191 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))");
192 if ($ldap->count() == 1){
193 $map= array("gotoXResolution", "gotoXColordepth", "gotoXKbModel", "gotoXKbLayout",
194 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport", "gotoXDriver");
195 $attrs= $ldap->fetch();
197 foreach ($map as $name){
198 if (!isset($attrs[$name][0])){
199 continue;
200 }
202 switch ($name){
203 case 'gotoXDriver':
204 $ogroup_driver = $attrs['gotoXDriver'][0];
205 if (in_array($ogroup_driver, $this->XDrivers) && (empty($this->attrs['gotoXDriver']))) {
206 $this->XDrivers = array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XDrivers;
207 }
208 break;
209 case 'gotoXResolution':
210 $this->XResolutions= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XResolutions;
211 break;
212 case 'gotoXColordepth':
213 $this->XColordepths= array('default' => _("inherited").' ['.$attrs[$name][0].' '._('Bit').']') + $this->XColordepths;
214 break;
215 case 'gotoXKbModel':
216 $this->XKbModels= array('default' => _("inherited").' ['.$attrs[$name][0].']') + $this->XKbModels;
217 break;
218 case 'gotoXKbLayout':
219 $this->XKbLayouts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbLayouts;
220 break;
221 case 'gotoXKbVariant':
222 $this->XKbVariants= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->XKbVariants;
223 break;
224 case 'gotoXMouseType':
225 $this->MouseTypes= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MouseTypes;
226 break;
227 case 'gotoXMouseport':
228 $this->MousePorts= array('default' => _("inherited").' ['.$attrs[$name][0].']' ) + $this->MousePorts;
229 break;
230 }
232 }
234 }
236 /* Workaround to fill in inherited values if we've specified an objectclass */
237 $SelectedSystemType = session::get("SelectedSystemType");
238 if (isset($SelectedSystemType['ogroup']) && $SelectedSystemType['ogroup'] != 'none'){
239 $this->XDrivers=array('default' => _("inherited"));
240 $this->XResolutions= array('default' => _("inherited"));
241 $this->XColordepths= array('default' => _("inherited"));
242 $this->XKbModels= array('default' => _("inherited"));
243 $this->XKbLayouts= array('default' => _("inherited"));
244 $this->XKbVariants= array('default' => _("inherited"));
245 $this->MouseTypes= array('default' => _("inherited"));
246 $this->MousePorts= array('default' => _("inherited"));
247 }
248 }
250 function execute()
251 {
252 /* Call parent execute */
253 plugin::execute();
255 if($this->is_account && !$this->view_logged){
256 $this->view_logged = TRUE;
257 new log("view","workstation/".get_class($this),$this->dn);
258 }
260 /* Do we need to flip is_account state? */
261 if (isset($_POST['modify_state'])){
262 $this->is_account= !$this->is_account;
263 }
265 /* Do we need to flip is_account state? */
266 if(isset($_POST['modify_state'])){
267 if($this->is_account && $this->acl_is_removeable()){
268 $this->is_account= FALSE;
269 }elseif(!$this->is_account && $this->acl_is_createable()){
270 $this->is_account= TRUE;
271 }
272 }
274 /* Show main page */
275 $smarty= get_smarty();
277 /* Assign ACLs */
278 $tmp = $this->plInfo();
279 foreach($tmp['plProvidedAcls'] as $name => $translated){
280 $smarty->assign($name."ACL",$this->getacl($name));
281 }
283 /* Arrays */
284 foreach(array("XDrivers", "XResolutions", "XColordepths",
285 "XKbModels", "XKbVariants",
286 "MouseTypes", "MousePorts") as $val){
287 $smarty->assign("$val", $this->$val);
288 }
289 $smarty->assign("XKbLayouts" ,$this->XKbLayouts);
290 $smarty->assign("XKbLayoutKeys" ,array_flip($this->XKbLayouts));
292 $smarty->assign("xdmcpservers", $this->config->data['SERVERS']['TERMINAL']);
293 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
294 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
296 /* Variables - select */
297 foreach(array(
298 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
299 "gotoXKbModel", "gotoXKbLayout","gotoScannerEnable",
300 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
302 $smarty->assign($val."_select", $this->$val);
303 }
305 /* Variables */
306 foreach(array("gotoXHsync", "gotoXVsync") as $val){
307 $smarty->assign($val, $this->$val);
308 }
309 $smarty->assign("staticAddress", "");
311 /* Checkboxes */
312 foreach(array("gotoScannerEnable") as $val){
313 if ($this->$val == TRUE) {
314 $smarty->assign("$val", "checked");
315 } else {
316 $smarty->assign("$val", "");
317 }
318 }
320 /* Phone stuff */
321 $smarty->assign ("goFonHardware", $this->goFonHardware);
323 $perms = "";
324 if(!$this->acl_is_writeable("goFonHardware")){
325 $perms = " disabled ";
326 }
328 $hl= "<select size=\"1\" name=\"goFonHardware\" ".$perms." title=\"".
329 _("Choose the phone located at the current terminal")."\" >";
330 foreach ($this->hardware_list as $cn => $description){
331 if ($cn == $this->goFonHardware){
332 $selected= "selected";
333 } else {
334 $selected= "";
335 }
336 if (isset($this->used_hardware[$cn])){
337 $color= "style=\"color:#A0A0A0\"";
338 } else {
339 $color= "";
340 }
341 $hl.= " <option $color label=\"$cn\" value=\"$cn\" $selected>$description</option>\n";
342 }
343 $hl.= "</select>\n";
344 $smarty->assign ("hardware_list", $hl);
345 $smarty->assign ("gotoXMonitor", $this->gotoXMonitor);
347 if($this->AutoSync){
348 $smarty->assign("AutoSyncCHK"," checked ");
349 $smarty->assign("hiddenState"," disabled ");
350 }else{
351 $smarty->assign("AutoSyncCHK"," ");
352 $smarty->assign("hiddenState","");
353 }
355 /* Show main page */
356 return($smarty->fetch (get_template_path('workstationService.tpl',TRUE,dirname(__FILE__))));
357 }
359 function remove_from_parent()
360 {
361 /* Cancel if there's nothing to do here */
362 if ((!$this->acl_is_removeable())){
363 return;
364 }
366 /* Remove and write to LDAP */
367 plugin::remove_from_parent();
368 $ldap = $this->config->get_ldap_link();
369 $ldap->cd($this->dn);
370 $this->cleanup();
371 $ldap->modify($this->attrs);
372 $this->handle_post_events("remove");
373 new log("remove","workstation/".get_class($this),$this->dn);
374 }
376 /* Save data to object */
377 function save_object()
378 {
379 plugin::save_object();
381 if((isset($_POST['workservicePosted'])) && $this->acl_is_writeable("AutoSync")) {
382 if(isset($_POST['AutoSync'])){
383 $this->AutoSync = true;
384 }else{
385 $this->AutoSync = false;
386 }
387 }
388 }
390 /* Check supplied data */
391 function check()
392 {
393 /* Call common method to give check the hook */
394 $message= plugin::check();
396 /* Default entries can use blank hsync/vsync entries */
397 if ($this->dn != "" && $this->cn != "default" && $this->cn != "wdefault"){
399 /* But only if no auto sync is enabled... */
400 if (!$this->AutoSync){
402 /* Check vsync for correct usage */
403 $val= preg_replace ("/\s/", "", $this->gotoXVsync);
405 if($this->acl_is_writeable("gotoXVsync")){
406 if(empty($val)){
407 $message[]= msgPool::required(_("VSync"));
408 }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
409 $message[]= msgPool::invalid(_("VSync"));
410 } else{
411 list($v1,$v2)= preg_split ("/[-+]/", $val);
412 if ($v2 != ""){
413 if ($v1 > $v2){
414 $message[]= msgPool::invalid(_("VSync"));
415 }
416 }
417 }
418 }
420 /* Check hsync for correct usage */
421 $val= preg_replace ("/\s/", "", $this->gotoXHsync);
422 if($this->acl_is_writeable("gotoXHsync")){
423 if(empty($val)){
424 $message[]= msgPool::required(_("HSync"));
425 }elseif (!preg_match ("/^\d+(\.\d+)?([-]\d+(\.\d+)?)?$/", $val)){
426 $message[]= msgPool::invalid(_("HSync"));
427 } else{
428 list($v1,$v2)= preg_split ("/[-+]/", $val);
429 if ($v2 != ""){
430 if ($v1 > $v2){
431 $message[]= msgPool::invalid(_("HSync"));
432 }
433 }
434 }
435 }
436 }
437 }
439 return ($message);
440 }
443 /* Save to LDAP */
444 function save()
445 {
446 /* remove objectclass GOhard if this is an ogroup tab */
447 if(isset($this->parent->by_object['ogroup'])){
448 $this->objectclasses = array();
449 }
451 plugin::save();
453 /* Strip out 'default' values */
454 foreach(array(
455 "gotoXDriver", "gotoXResolution", "gotoXColordepth",
456 "gotoXKbModel", "gotoXKbLayout", "gotoXDriver",
457 "gotoXKbVariant", "gotoXMouseType", "gotoXMouseport") as $val){
459 if ($this->attrs[$val] == "default"){
460 $this->attrs[$val]= array();
461 }
462 }
464 if($this->AutoSync){
465 $this->attrs['gotoXHsync'] = "30+55";
466 $this->attrs['gotoXVsync'] = "50+70";
467 }
469 /* Write back to ldap */
470 $ldap= $this->config->get_ldap_link();
471 $ldap->cd($this->dn);
472 $this->cleanup();
475 $ldap->modify ($this->attrs);
476 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
477 if (!$ldap->success()){
478 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
479 }
480 $this->handle_post_events("modify");
482 /* Send goto reload event to gosaSupportDaemon */
483 if(count($this->attrs)){
484 $this->send_goto_reload();
485 }
487 }
490 function getListOfXDrivers()
491 {
492 /* Generate a list of xdrivers from CONFIG_DIR./xdrivers */
493 $drivers = array();
494 if (file_exists(CONFIG_DIR.'/xdrivers')){
495 $xdrivers = file (CONFIG_DIR.'/xdrivers');
496 foreach ($xdrivers as $line){
497 if (!preg_match ("/^#/", $line)){
498 $drivers[]= trim($line);
499 }
500 }
501 } else {
502 $drivers = array("ati", "atimisc", "chips", "cirrus", "cyrix", "fbdev", "fglrx",
503 "i128", "i740", "i810", "intel", "imstt", "mga", "neomagic", "newport", "nsc", "nv", "nvidia",
504 "r128", "radeon", "rendition", "s3", "s3virge", "savage", "siliconmotion",
505 "sis", "tdfx", "tga", "trident", "tseng", "vboxvideo", "vesa", "vga", "vmware");
506 }
507 return($drivers);
508 }
511 /* Return plugin informations for acl handling */
512 static function plInfo()
513 {
514 return (array(
515 "plShortName" => _("Service"),
516 "plDescription" => _("Workstation service"),
517 "plSelfModify" => FALSE,
518 "plDepends" => array(),
519 "plPriority" => 10,
520 "plSection" => array("administration"),
521 "plCategory" => array("workstation","ogroups"),
523 "plProvidedAcls"=> array(
524 "gotoXMonitor" => _("Monitor"),
525 "gotoXDriver" => _("Gfx driver"),
526 "gotoXResolution" => _("Gfx resolution"),
527 "gotoXColordepth" => _("Gfx color depth"),
528 "gotoXHsync" => _("HSync"),
529 "gotoXVsync" => _("VSync"),
530 "AutoSync" => _("Use DDC"),
531 "gotoScannerEnable" => _("Scanner enabled"),
532 "gotoXKbModel" => _("Keyboard model"),
533 "gotoXKbLayout" => _("Keyboard layout"),
534 "gotoXKbVariant" => _("Keyboard variant"),
535 "gotoXMouseType" => _("Mouse type"),
536 "gotoXMouseport" => _("Mouse port"),
537 "goFonHardware" => _("Telephone hardware"))
538 ));
539 }
542 /*! \brief Send goto_reload event to support daemon
543 */
544 function send_goto_reload()
545 {
546 if(count($this->attrs) && class_available("DaemonEvent")){
547 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
548 $o_queue = new gosaSupportDaemon();
549 if(isset($events['TRIGGERED']['DaemonEvent_goto_reload'])){
550 $evt = $events['TRIGGERED']['DaemonEvent_goto_reload'];
551 $macs = array();
553 /* Get list of macAddresses
554 */
555 if(isset($this->parent->by_object['ogroup'])){
557 /* If we are an object group, add all member macs
558 */
559 $p = $this->parent->by_object['ogroup'];
560 foreach($p->memberList as $dn => $obj){
561 if(preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$dn)) continue;
562 if(isset($p->objcache[$dn]['macAddress']) && !empty($p->objcache[$dn]['macAddress'])){
563 $macs[] = $p->objcache[$dn]['macAddress'];
564 }
565 }
566 }elseif(isset($this->parent->by_object['workgeneric']->netConfigDNS->macAddress)){
568 /* We are a workstation. Add current mac.
569 */
570 $mac = $this->parent->by_object['workgeneric']->netConfigDNS->macAddress;
571 if(!empty($mac) && !preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->orig_dn)){
572 $macs[] = $mac;
573 }
574 }
576 /* Trigger event for all member objects
577 */
578 if(count($macs)){
579 $tmp = new $evt['CLASS_NAME']($this->config);
580 $tmp->set_type(TRIGGERED_EVENT);
581 $target = $o_queue->get_host().":".$o_queue->get_port();
582 $tmp->add_targets(array($target));
583 $tmp->set_macs($macs);
584 if(!$o_queue->append($tmp,TRUE)){
585 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
586 }
587 }
588 }
589 }
590 }
593 function PrepareForCopyPaste($source)
594 {
595 plugin::PrepareForCopyPaste($source);
597 if(preg_match("/\+/",$this->gotoXHsync)){
598 $this->AutoSync = true;
599 $this->gotoXHsync = preg_replace("/\+/","-",$this->gotoXHsync);
600 $this->gotoXVsync = preg_replace("/\+/","-",$this->gotoXVsync);
601 }
602 }
603 }
605 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
606 ?>