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