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