1 <?php
3 class workgeneric extends plugin
4 {
5 /* Generic terminal attributes */
6 var $gotoMode= "locked";
7 var $initial_gotoMode= "locked";
8 var $gotoSyslogServer= "";
9 var $gotoSyslogServers= array();
10 var $gotoNtpServer= array();
11 var $gotoNtpServers= array();
12 var $gotoSndModule= "";
13 var $gotoFloppyEnable= "";
14 var $gotoCdromEnable= "";
15 var $description= "";
16 var $ghCpuType= "-";
17 var $ghMemSize= "-";
18 var $ghUsbSupport= "-";
19 var $ghNetNic= array();
20 var $ghIdeDev= array();
21 var $ghScsiDev= array();
22 var $ghGfxAdapter= "-";
23 var $ghSoundAdapter= "-";
24 var $gotoLastUser= "-";
25 var $FAIscript= "";
26 var $view_logged = FALSE;
27 var $auto_activate= FALSE;
29 /* Needed values and lists */
30 var $base= "";
31 var $cn= "";
32 var $l= "";
33 var $orig_dn= "";
34 var $orig_cn= "";
35 var $orig_base= "";
36 var $ogroup=FALSE;
38 /* Plugin side filled */
39 var $modes= array();
41 var $netConfigDNS;
43 var $inheritTimeServer = true;
45 /* attribute list for save action */
46 var $ignore_account= TRUE;
47 var $attributes= array("gotoMode", "gotoSyslogServer", "gotoNtpServer",
48 "gotoFloppyEnable", "gotoCdromEnable", "cn", "gotoSndModule",
49 "ghCpuType", "ghMemSize", "ghUsbSupport", "description",
50 "ghGfxAdapter", "ghSoundAdapter", "gotoLastUser", "l","FAIscript");
51 var $objectclasses= array("top", "gotoWorkstation", "GOhard");
53 var $validActions = array("reboot" => "", "localboot" => "", "halt" => "", "update" => "", "reinstall" => "",
54 "rescan" => "", "wakeup" => "", "memcheck" => "", "sysinfo" => "");
56 var $fai_activated = FALSE;
58 var $member_of_ogroup = FALSE;
60 var $currently_installing = FALSE;
61 var $currently_installing_warned = FALSE;
63 var $kerberos_key_service = NULL;
65 function workgeneric (&$config, $dn= NULL, $parent= NULL)
66 {
67 $tmp= $config->search("faiManagement", "CLASS",array('menu','tabs'));
68 if(!empty($tmp)){
69 $this->fai_activated = TRUE;
70 }
72 plugin::plugin ($config, $dn, $parent);
74 if(class_available("krbHostKeys")){
75 $this->kerberos_key_service = new krbHostKeys($this->config,$this);
76 }
78 if(!isset($this->parent->by_object['ogroup'])){
79 $ldap = $this->config->get_ldap_link();
80 $ldap->cd ($this->config->current['BASE']);
81 $ldap->search("(&(objectClass=gotoWorkstationTemplate)(member=".LDAP::prepare4filter($this->dn)."))",array("cn"));
82 $this->member_of_ogroup = $ldap->count() >= 1;
83 }
85 $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses);
87 /* Check if this host is currently in installation process*/
88 if(class_available("gosaSupportDaemon") && class_available("DaemonEvent")){
89 $o = new gosaSupportDaemon();
90 $e_types = DaemonEvent::get_event_types(USER_EVENT | SYSTEM_EVENT | HIDDEN_EVENT);
91 $evts = $o->get_entries_by_mac(array($this->netConfigDNS->macAddress));
92 foreach($evts as $evt){
93 if(isset($e_types['QUEUED'][$evt['HEADERTAG']]) && $evt['STATUS'] == "processing" &&
94 $e_types['QUEUED'][$evt['HEADERTAG']] == "DaemonEvent_reinstall"){
95 $this->currently_installing =TRUE;
96 }
97 }
98 }
100 /* Read arrays */
101 foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
102 if (!isset($this->attrs[$val])){
103 continue;
104 }
105 for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
106 array_push($this->$val, $this->attrs[$val][$i]);
107 }
108 }
110 /* Create used ntp server array */
111 $this->gotoNtpServer= array();
112 if(isset($this->attrs['gotoNtpServer'])){
113 $this->inheritTimeServer = false;
114 unset($this->attrs['gotoNtpServer']['count']);
115 foreach($this->attrs['gotoNtpServer'] as $server){
116 $this->gotoNtpServer[$server] = $server;
117 }
118 }
120 /* Set inherit checkbox state */
121 if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer) == 0)){
122 $this->inheritTimeServer = true;
123 $this->gotoNtpServer=array();
124 }
126 /* You can't inherit the NTP service, if we are not member in an object group */
127 if(!$this->member_of_ogroup){
128 $this->inheritTimeServer = FALSE;
129 }
131 /* Create available ntp options */
132 $tmp = $this->config->data['SERVERS']['NTP'];
133 $this->gotoNtpServers = array();
134 foreach($tmp as $key => $server){
135 if($server == "default") continue;
136 $this->gotoNtpServers[$server] = $server;
137 }
139 $this->modes["active"]= _("Activated");
140 $this->modes["locked"]= _("Locked");
142 /* Set base */
143 if ($this->dn == "new"){
144 $ui= get_userinfo();
145 $this->base= dn2base($ui->dn);
146 } else {
147 $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("workstationRDN"), '/')."/i", "", $this->dn);
148 }
150 /* Create an array of all Syslog servers */
151 $tmp = $this->config->data['SERVERS']['SYSLOG'];
152 foreach($tmp as $server){
153 $visible = $server;
154 if($server == "default" && $this->member_of_ogroup) {
155 $visible = "["._("inherited")."]";
156 }
157 $this->gotoSyslogServers[$server] = $visible;
158 }
160 $this->initial_gotoMode = $this->gotoMode;
162 /* Save 'dn' for later referal */
163 $this->orig_dn= $this->dn;
164 $this->orig_cn= $this->cn;
165 $this->orig_base= $this->base;
166 }
169 function set_acl_base($base)
170 {
171 plugin::set_acl_base($base);
172 $this->netConfigDNS->set_acl_base($base);
173 }
175 function set_acl_category($cat)
176 {
177 plugin::set_acl_category($cat);
178 $this->netConfigDNS->set_acl_category($cat);
179 }
181 function execute()
182 {
183 /* Call parent execute */
184 plugin::execute();
186 if ($this->ogroup) {
187 $this->member_of_ogroup = TRUE;
188 $this->parent->by_object['workservice']->ogroup = $this->ogroup;
189 $this->set_everything_to_inherited();
190 }
192 if($this->is_account && !$this->view_logged){
193 $this->view_logged = TRUE;
194 new log("view","workstation/".get_class($this),$this->dn);
195 }
197 /* Do we need to flip is_account state? */
198 if(isset($_POST['modify_state'])){
199 if($this->is_account && $this->acl_is_removeable()){
200 $this->is_account= FALSE;
201 }elseif(!$this->is_account && $this->acl_is_createable()){
202 $this->is_account= TRUE;
203 }
204 }
206 if ((isset($_POST['action'])) && ($this->acl_is_writeable("FAIstate")) && isset($this->validActions[$_POST['saction']]) ){
207 $action= $_POST['saction'];
209 /* Check if we have an DaemonEvent for this action */
210 if(class_available("DaemonEvent")){
211 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
212 if(isset($events['TRIGGERED']["DaemonEvent_".$action])){
213 $evt = $events['TRIGGERED']["DaemonEvent_".$action];
214 $tmp = new $evt['CLASS_NAME']($this->config);
215 $tmp->add_targets(array($this->netConfigDNS->macAddress));
216 $tmp->set_type(TRIGGERED_EVENT);
217 $o_queue = new gosaSupportDaemon();
218 if(!$o_queue->append($tmp)){
219 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
220 }
221 }
222 } else {
223 msg_dialog::display(_("Event error"),
224 sprintf(_("Event '%s' is not available!"),$action),ERROR_DIALOG);
225 }
228 }
230 /* Do we represent a valid terminal? */
231 if (!$this->is_account && $this->parent === NULL){
232 $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle> <b>".
233 msgPool::noValidExtension(_("workstation"))."</b>";
234 return($display);
235 }
237 /* Base select dialog */
238 $once = true;
239 foreach($_POST as $name => $value){
240 if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
241 $once = false;
242 $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
243 $this->dialog->setCurrentBase($this->base);
244 }
245 }
247 /* Dialog handling */
248 if(is_object($this->dialog)){
249 /* Must be called before save_object */
250 $this->dialog->save_object();
252 if($this->dialog->isClosed()){
253 $this->dialog = false;
254 }elseif($this->dialog->isSelected()){
256 /* A new base was selected, check if it is a valid one */
257 $tmp = $this->get_allowed_bases();
258 if(isset($tmp[$this->dialog->isSelected()])){
259 $this->base = $this->dialog->isSelected();
260 }
262 $this->dialog= false;
263 }else{
264 return($this->dialog->execute());
265 }
266 }
268 /* Add new ntp Server to our list */
269 if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers'])) && $this->acl_is_writeable("gotoNtpServer")){
270 $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers'];
271 }
273 /* Delete selected NtpServer for list of used servers */
274 if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected'])) && $this->acl_is_writeable("gotoNtpServer")){
275 foreach($_POST['gotoNtpServerSelected'] as $name){
276 unset($this->gotoNtpServer[$name]);
277 }
278 }
280 /* Fill templating stuff */
281 $smarty= get_smarty();
283 /* Set acls */
284 $tmp = $this->plInfo();
285 foreach($tmp['plProvidedAcls'] as $name => $translation){
286 $smarty->assign($name."ACL",$this->getacl($name));
287 }
289 $smarty->assign("cn", $this->cn);
290 $smarty->assign("description", $this->description);
291 $smarty->assign("l", $this->l);
292 $smarty->assign("bases", $this->get_allowed_bases());
293 $smarty->assign("staticAddress", "");
295 $tmp = array();
296 foreach($this->gotoNtpServers as $server){
297 if(!in_array($server,$this->gotoNtpServer)){
298 $tmp[$server] = $server;
299 }
300 }
301 $smarty->assign("gotoNtpServers",$tmp);
303 /* Check if workstation is online */
304 if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){
305 $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
306 "update" => _("Software update"),
307 "reinstall" => _("Reinstall"),
308 "rescan" => _("Rescan hardware"),
309 #"memcheck" => _("Memory test"),
310 "localboot" => _("Force localboot"),
311 #"sysinfo" => _("System analysis")
312 ));
313 } else {
314 $smarty->assign("actions", array("wakeup" => _("Wake up"),
315 "reinstall" => _("Reinstall"),
316 "update" => _("Software update"),
317 #"memcheck" => _("Memory test"),
318 "localboot" => _("Force localboot"),
319 #"sysinfo" => _("System analysis")
320 ));
321 }
322 /* Arrays */
323 $smarty->assign("modes", $this->modes);
324 $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
325 $smarty->assign("syslogservers", $this->gotoSyslogServers);
326 $smarty->assign("fai_activated",$this->fai_activated);
328 $ntpser = array();
329 foreach($this->gotoNtpServers as $server){
330 if(!in_array($server,$this->gotoNtpServer)){
331 $ntpser[$server] = $server;
332 }
333 }
334 $smarty->assign("gotoNtpServers", $ntpser);
336 /* Variables */
337 foreach(array("base", "gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
338 $smarty->assign($val."_select", $this->$val);
339 }
341 /* tell smarty the inherit checkbox state */
342 $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
343 $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
345 $str = $this->netConfigDNS->execute();
346 if(is_object($this->netConfigDNS->dialog)){
347 return($str);
348 }
349 $smarty->assign("netconfig", $str);
351 /* Display kerberos host key options */
352 $smarty->assign("host_key","");
353 if(is_object($this->kerberos_key_service)){
354 $smarty->assign("host_key",$this->kerberos_key_service->execute_by_prefix("host/"));
355 }
357 /* Show main page */
358 $smarty->assign("currently_installing", $this->currently_installing);
359 return($smarty->fetch (get_template_path('workstation.tpl', TRUE, dirname(__FILE__))));
360 }
362 function remove_from_parent()
363 {
364 if($this->acl_is_removeable()){
366 $this->netConfigDNS->remove_from_parent();
367 $ldap= $this->config->get_ldap_link();
368 $ldap->rmdir($this->dn);
369 new log("remove","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
370 if (!$ldap->success()){
371 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
372 }
374 /* Remove kerberos key dependencies too */
375 if(is_object($this->kerberos_key_service)){
376 $this->kerberos_key_service->remove_from_parent_by_prefix("host/");
377 }
379 /* Optionally execute a command after we're done */
380 $this->handle_post_events("remove", array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
382 /* Delete references to object groups */
383 $ldap->cd ($this->config->current['BASE']);
384 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
385 while ($ldap->fetch()){
386 $og= new ogroup($this->config, $ldap->getDN());
387 unset($og->member[$this->dn]);
388 $og->save ();
389 }
391 /* Remove all accessTo/trust dependencies */
392 update_accessTo($this->cn,"");
393 }
395 /* Clean queue form entries with this mac
396 */
397 if(class_available("gosaSupportDaemon") && tests::is_mac($this->netConfigDNS->orig_macAddress)){
398 $q = new gosaSupportDaemon();
399 $q->clean_queue_from_mac($this->netConfigDNS->orig_macAddress);
400 }
402 if(isset($_POST["inheritAll"])){
403 $this->set_everything_to_inherited();
404 }
405 }
408 /* Save data to object */
409 function save_object()
410 {
412 /* Create a base backup and reset the
413 base directly after calling plugin::save_object();
414 Base will be set seperatly a few lines below */
415 $base_tmp = $this->base;
416 plugin::save_object();
417 $this->base = $base_tmp;
419 /* Save base, since this is no LDAP attribute */
420 $tmp = $this->get_allowed_bases();
421 if(isset($_POST['base'])){
422 if(isset($tmp[$_POST['base']])){
423 $this->base= $_POST['base'];
424 }
425 }
427 $this->netConfigDNS->save_object();
429 /* Set inherit mode */
430 if((isset($_POST['workgeneric_posted'])) && ($this->acl_is_writeable("gotoNtpServer"))){
431 if(isset($_POST["inheritTimeServer"]) && $this->member_of_ogroup){
432 $this->inheritTimeServer = true;
433 }else{
434 $this->inheritTimeServer = false;
435 }
436 }
438 if(isset($_POST["inheritAll"])){
439 $this->set_everything_to_inherited();
440 }
442 /* Hanle kerberos host key plugin */
443 if(is_object($this->kerberos_key_service)){
444 $this->kerberos_key_service->save_object_by_prefix("host/");
445 }
446 }
449 /* Check supplied data */
450 function check()
451 {
452 /* Call common method to give check the hook */
453 $message= plugin::check();
455 /* Skip IP & Mac checks if this is a template */
456 if($this->cn != "wdefault"){
457 $message= array_merge($message, $this->netConfigDNS->check());
458 }
460 $this->dn= "cn=".$this->cn.",".get_ou('workstationRDN').$this->base;
462 if ($this->cn == ""){
463 $message[]= msgPool::required(_("Name"));
464 }
466 /* Check if given name is a valid host/dns name */
467 if(!tests::is_dns_name($this->cn)){
468 $message[] = msgPool::invalid(_("Name"));
469 }
471 if ($this->orig_dn != $this->dn){
472 $ldap= $this->config->get_ldap_link();
473 $ldap->cd ($this->base);
475 if($this->cn == "wdefault"){
476 $ldap->cat($this->dn);
477 }else{
478 $ldap->search ("(&(cn=".$this->cn.")(objectClass=gotoWorkstation))", array("cn"));
479 }
480 if ($ldap->count() != 0){
481 while ($attrs= $ldap->fetch()){
482 if (preg_match("/cn=dhcp,/",$attrs['dn']) || preg_match ("/,".get_ou('systemIncomingRDN')."/", $ldap->getDN())){
483 continue;
484 } else {
485 if ($attrs['dn'] != $this->orig_dn){
486 $message[]= msgPool::duplicated(_("Name"));
487 break;
488 }
489 }
490 }
491 }
492 }
494 /* Check for valid ntpServer selection */
495 if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
496 $message[]= msgPool::required(_("NTP server"));
497 }
499 /* Only systems with a valid ldap handle can be activated
500 */
501 if($this->gotoMode == "active" && $this->initial_gotoMode != "active"){
503 if(isset($this->parent->by_object['workstartup']) &&
504 !count($this->parent->by_object['workstartup']->gotoLdapServers) &&
505 !$this->parent->by_object['workstartup']->gotoLdap_inherit){
507 $message[] = _("A valid LDAP server assignement is missing!");
508 }
509 }else{
510 /* Warn the user, that this host is currently installing */
511 if($this->currently_installing && !$this->currently_installing_warned &&
512 !preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->orig_dn)){
514 /* Force aborting without message dialog */
515 $message[] = "";
516 $this->currently_installing_warned = TRUE;
517 msg_dialog::display(_("Software deployment"),
518 _("This host is currently installing. If you want to save it, press 'OK'."),
519 CONFIRM_DIALOG);
520 }
521 }
523 /* Check if we are allowed to create or move this object
524 */
525 if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
526 $message[] = msgPool::permCreate();
527 }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
528 $message[] = msgPool::permMove();
529 }
531 return ($message);
532 }
535 /* Save to LDAP */
536 function save()
537 {
538 /* Detect mode changes */
539 $activate= (isset($this->saved_attributes['gotoMode']) &&
540 $this->gotoMode != $this->saved_attributes['gotoMode'] &&
541 $this->gotoMode == "active" &&
542 tests::is_ip($this->netConfigDNS->ipHostNumber)) || $this->auto_activate;
543 plugin::save();
545 /* Strip out 'default' values */
546 foreach (array("gotoSyslogServer") as $val){
548 if (isset($this->attrs[$val]) && $this->attrs[$val] == "default"){
549 $this->attrs[$val]= array();
550 }
551 }
553 /* Add missing arrays */
554 foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
555 if (isset ($this->$val) && count ($this->$val) != 0){
556 $this->attrs["$val"]= $this->$val;
557 }
558 }
560 /* Remove all empty values */
561 if ($this->orig_dn == 'new'){
562 $attrs= array();
563 foreach ($this->attrs as $key => $val){
564 if (is_array($val) && count($val) == 0){
565 continue;
566 }
567 $attrs[$key]= $val;
568 }
569 $this->attrs= $attrs;
570 }
572 /* Update ntp server settings */
573 if($this->inheritTimeServer){
574 if($this->is_new){
575 if(isset($this->attrs['gotoNtpServer'])){
576 unset($this->attrs['gotoNtpServer']);
577 }
578 }else{
579 $this->attrs['gotoNtpServer'] = array();
580 }
581 }else{
582 /* Set ntpServers */
583 $this->attrs['gotoNtpServer'] = array();
584 foreach($this->gotoNtpServer as $server){
585 $this->attrs['gotoNtpServer'][] = $server;
586 }
587 }
589 /* cn=default and macAddress=- indicates that this is a template */
590 if($this->cn == "wdefault"){
591 $this->netConfigDNS->macAddress = "-";
592 }
594 /* Write back to ldap */
595 $ldap= $this->config->get_ldap_link();
596 if ($this->orig_dn == 'new'){
597 $ldap->cd($this->config->current['BASE']);
598 $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
599 $ldap->cd($this->dn);
600 $ldap->add($this->attrs);
601 new log("create","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
602 if (!$ldap->success()){
603 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
604 }
606 $this->netConfigDNS->cn = $this->cn;
607 $this->netConfigDNS->save();
609 $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
610 } else {
611 if ($this->orig_dn != $this->dn){
613 /* Remove all accessTo/trust dependencies */
614 update_accessTo($this->orig_cn,$this->cn);
615 }
616 $ldap->cd($this->dn);
617 $this->cleanup();
618 $ldap->modify ($this->attrs);
619 if (!$ldap->success()){
620 msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
621 }
622 new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
624 $this->netConfigDNS->cn = $this->cn;
625 $this->netConfigDNS->save();
627 $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
628 }
630 if ($activate && class_available("DaemonEvent")){
632 /* Send installation activation
633 */
634 $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
635 $o_queue = new gosaSupportDaemon();
636 if(isset($events['TRIGGERED']['DaemonEvent_installation_activation'])){
637 $evt = $events['TRIGGERED']['DaemonEvent_installation_activation'];
638 $tmp = new $evt['CLASS_NAME']($this->config);
639 $tmp->set_type(TRIGGERED_EVENT);
640 $tmp->add_targets(array($this->netConfigDNS->macAddress));
641 if(!$o_queue->append($tmp)){
642 msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
643 }
644 }
645 }
647 /* If $this->ogroup is set add the new system to the requested ogroup */
648 if ($this->ogroup) {
649 $og = new ogroup($this->config, $this->ogroup);
650 $og->AddDelMembership($this->dn);
651 $og->save();
652 }
653 }
656 /* Display generic part for server copy & paste */
657 function getCopyDialog()
658 {
659 $vars = array("cn");
660 $smarty = get_smarty();
661 $smarty->assign("cn" ,$this->cn);
662 $smarty->assign("object","workstation");
663 $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
664 $ret = array();
665 $ret['string'] = $str;
666 $ret['status'] = "";
667 return($ret);
668 }
671 function saveCopyDialog()
672 {
673 if(isset($_POST['cn'])){
674 $this->cn = $_POST['cn'];
675 }
676 }
679 function PrepareForCopyPaste($source)
680 {
681 plugin::PrepareForCopyPaste($source);
682 if(isset($source['macAddress'][0])){
683 $this->netConfigDNS->macAddress = $source['macAddress'][0];
684 }
685 if(isset($source['ipHostNumber'][0])){
686 $this->netConfigDNS->ipHostNumber = $source['ipHostNumber'][0];
687 }
689 /* Create used ntp server array */
690 $this->gotoNtpServer= array();
691 if(isset($source['gotoNtpServer'])){
692 $this->inheritTimeServer = false;
693 unset($source['gotoNtpServer']['count']);
694 foreach($source['gotoNtpServer'] as $server){
695 $this->gotoNtpServer[$server] = $server;
696 }
697 }
699 /* Set inherit checkbox state */
700 if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){
701 $this->inheritTimeServer = true;
702 $this->gotoNtpServer=array();
703 }
704 }
707 /* Return plugin informations for acl handling
708 #FIXME FAIscript seams to ununsed within this class... */
709 static function plInfo()
710 {
711 return (array(
712 "plShortName" => _("Generic"),
713 "plDescription" => _("Workstation generic"),
714 "plSelfModify" => FALSE,
715 "plDepends" => array(),
716 "plPriority" => 0,
717 "plSection" => array("administration"),
718 "plCategory" => array("workstation" => array("description" => _("Workstation"),
719 "objectClass" => "gotoWorkstation")),
720 "plProvidedAcls"=> array(
721 "cn" => _("Workstation name"),
722 "description" => _("Description") ,
723 "l" => _("Location") ,
724 "base" => _("Base") ,
725 "gotoMode" => _("Goto mode"),
726 "gotoSyslogServer" => _("Syslog server"),
727 "gotoNtpServer" => _("Ntp server"),
728 "userPassword" => _("Root password"),
729 "createFAICD" => _("Create FAI CD"),
730 "FAIstate" => _("Action flag"))
731 ));
732 }
734 function set_everything_to_inherited()
735 {
736 /* Find out what is set in the object group as XDriver */
737 $inherit_xdriver = 0;
738 if ($this->dn != 'new' || $this->ogroup) {
739 $ldap = $this->config->get_ldap_link();
740 $entry = NULL;
741 /* If initialized with an object group we need to use this instead of
742 * an object group we'll become a member in */
743 if ($this->ogroup) {
744 $entry = $ldap->cat($this->ogroup, array("gotoXDriver"));
745 }else {
746 $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("gotoXDriver"));
747 if ($ldap->count() == 1) {
748 $entry = $ldap->fetch();
749 }
750 }
751 if ($entry) {
752 /* Get list of valid XDrivers */
753 $xdrivers = $this->parent->by_object['workservice']->getListOfXDrivers();
754 /* Only inherit if driver in object group is set to something in the list of
755 * valid XDrivers */
756 if (in_array($entry['gotoXDriver'][0], $xdrivers)) {
757 $inherit_xdriver = 1;
758 }
759 }
760 }
762 $this->gotoSyslogServer = "default";
763 $this->inheritTimeServer = TRUE;
765 /* Set workstation service attributes to inherited */
766 if($this->member_of_ogroup && isset($this->parent->by_object['workservice'])){
767 foreach(array("gotoXKbLayout","gotoXKbModel","gotoXKbVariant", "gotoXDriver",
768 "gotoXResolution","gotoXColordepth","gotoXMouseType","gotoXMouseport") as $name){
769 if(!(($name == 'gotoXDriver') && ($inherit_xdriver == 0))) {
770 if($this->parent->by_object['workservice']->acl_is_writeable($name)){
771 $this->parent->by_object['workservice']->$name = "default";
772 }
773 }
774 }
775 }
777 /* Set workstation startup attributes to inherited */
778 if($this->member_of_ogroup && isset($this->parent->by_object['workstartup'])){
779 $obj = $this->parent->by_object['workstartup'];
780 if($obj->acl_is_writeable("gotoBootKernel")){
781 $this->parent->by_object['workstartup']->gotoBootKernel = "default-inherited";
782 }
783 if($obj->acl_is_writeable("gotoLdapServer")){
784 $this->parent->by_object['workstartup']->gotoLdapServer = "default-inherited";
785 $this->parent->by_object['workstartup']->gotoLdap_inherit = TRUE;
786 $this->parent->by_object['workstartup']->gotoLdapServers = array();
787 }
788 if($obj->acl_is_writeable("FAIdebianMirror")){
789 $this->parent->by_object['workstartup']->FAIdebianMirror= "inherited";
790 }
791 }
792 }
793 }
794 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
795 ?>