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