Code

Apply fix for #6888
[gosa.git] / trunk / gosa-plugins / goto / admin / systems / goto / class_workstationGeneric.inc
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" => "");
58   
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 = array();
95       if (tests::is_mac($this->netConfigDNS->macAddress)) {
96         $evts = $o->get_entries_by_mac(array($this->netConfigDNS->macAddress));
97       }
98       foreach($evts as $evt){
99         if(isset($e_types['QUEUED'][$evt['HEADERTAG']]) && $evt['STATUS'] == "processing" &&
100             $e_types['QUEUED'][$evt['HEADERTAG']] == "DaemonEvent_reinstall"){
101           $this->currently_installing =TRUE;
102         }
103       }
104     }
106     /* Read arrays */
107     foreach (array("ghNetNic", "ghIdeDev", "ghScsiDev") as $val){
108       if (!isset($this->attrs[$val])){
109         continue;
110       }
111       for ($i= 0; $i<$this->attrs[$val]['count']; $i++){
112         array_push($this->$val, $this->attrs[$val][$i]);
113       }
114     }
116     /* Create used ntp server array */
117     $this->gotoNtpServer= array();
118     if(isset($this->attrs['gotoNtpServer'])){
119       $this->inheritTimeServer = false;
120       unset($this->attrs['gotoNtpServer']['count']);
121       foreach($this->attrs['gotoNtpServer'] as $server){
122         $this->gotoNtpServer[$server] = $server;
123       }
124     }
126     /* Set inherit checkbox state */
127     if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer) == 0)){
128       $this->inheritTimeServer = true;
129       $this->gotoNtpServer=array();
130     }
132     /* You can't inherit the NTP service, if we are not member in an object group */
133     if(!$this->member_of_ogroup){
134       $this->inheritTimeServer = FALSE;
135     }
137     /* Create available ntp options */
138     $tmp = $this->config->data['SERVERS']['NTP'];
139     $this->gotoNtpServers = array();
140     foreach($tmp as $key => $server){
141       if($server == "default") continue;
142       $this->gotoNtpServers[$server] = $server;
143     }
145     $this->modes["active"]= _("Activated");
146     $this->modes["locked"]= _("Locked");
148     /* Set base */
149     if ($this->dn == "new"){
150       $ui= get_userinfo();
151       $this->base= dn2base($ui->dn);
152     } else {
153       $this->base= preg_replace ("/^[^,]+,".preg_quote(get_ou("workstationRDN"), '/')."/i", "", $this->dn);
154     }
156     /* Create an array of all Syslog servers */
157     $tmp = $this->config->data['SERVERS']['SYSLOG'];
158     foreach($tmp as $server){
159       $visible = $server;
160       if($server == "default" && $this->member_of_ogroup) {
161         $visible = "["._("inherited")."]";
162       }
163       $this->gotoSyslogServers[$server] = $visible;
164     }
166     $this->initial_gotoMode = $this->gotoMode;
168     /* Save 'dn' for later referal */
169     $this->orig_dn= $this->dn;
170     $this->orig_cn= $this->cn;
171     $this->orig_base= $this->base;
172   }
175   function set_acl_base($base)
176   {
177     plugin::set_acl_base($base);
178     $this->netConfigDNS->set_acl_base($base);
179   }
181   function set_acl_category($cat)
182   {
183     plugin::set_acl_category($cat);
184     $this->netConfigDNS->set_acl_category($cat);
185   }
187   function execute()
188   {
189     /* Call parent execute */
190     plugin::execute();
192     if ($this->ogroup) {
193       $this->member_of_ogroup = TRUE;
194       $this->parent->by_object['workservice']->ogroup = $this->ogroup;
195       $this->set_everything_to_inherited();
196     }
198     if($this->is_account && !$this->view_logged){
199       $this->view_logged = TRUE;
200       new log("view","workstation/".get_class($this),$this->dn);
201     }
203     /* Do we need to flip is_account state? */
204     if(isset($_POST['modify_state'])){
205       if($this->is_account && $this->acl_is_removeable()){
206         $this->is_account= FALSE;
207       }elseif(!$this->is_account && $this->acl_is_createable()){
208         $this->is_account= TRUE;
209       }
210     }
212     if ((isset($_POST['action'])) && ($this->acl_is_writeable("FAIstate")) && isset($this->validActions[$_POST['saction']]) ){
213       $action= $_POST['saction'];
215       /* Check if we have an DaemonEvent for this action */ 
216       if(class_available("DaemonEvent")){
217         $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
218         if(isset($events['TRIGGERED']["DaemonEvent_".$action])){
219           $evt = $events['TRIGGERED']["DaemonEvent_".$action];
220           $tmp = new $evt['CLASS_NAME']($this->config);
221           $tmp->add_targets(array($this->netConfigDNS->macAddress));
222           $tmp->set_type(TRIGGERED_EVENT);
223           $o_queue = new gosaSupportDaemon();
224           if(!$o_queue->append($tmp)){
225             msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
226           }
227         }
228       } else {
229         msg_dialog::display(_("Event error"),
230                     sprintf(_("Event '%s' is not available!"),$action),ERROR_DIALOG);
231       }
234     }
236     /* Do we represent a valid terminal? */
237     if (!$this->is_account && $this->parent === NULL){
238       $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
239         msgPool::noValidExtension(_("workstation"))."</b>";
240       return($display);
241     }
243     /* Base select dialog */
244     $once = true;
245     foreach($_POST as $name => $value){
246       if(preg_match("/^chooseBase/",$name) && $once && $this->acl_is_writeable("base")){
247         $once = false;
248         $this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
249         $this->dialog->setCurrentBase($this->base);
250       }
251     }
253     /* Dialog handling */
254     if(is_object($this->dialog)){
255       /* Must be called before save_object */
256       $this->dialog->save_object();
258       if($this->dialog->isClosed()){
259         $this->dialog = false;
260       }elseif($this->dialog->isSelected()){
262         /* A new base was selected, check if it is a valid one */
263         $tmp = $this->get_allowed_bases();
264         if(isset($tmp[$this->dialog->isSelected()])){
265           $this->base = $this->dialog->isSelected();
266         }
268         $this->dialog= false;
269       }else{
270         return($this->dialog->execute());
271       }
272     }
274     /* Add new ntp Server to our list */ 
275     if((isset($_POST['addNtpServer'])) && (isset($_POST['gotoNtpServers'])) && $this->acl_is_writeable("gotoNtpServer")){
276       $this->gotoNtpServer[$_POST['gotoNtpServers']] = $_POST['gotoNtpServers'];
277     }
279     /* Delete selected NtpServer for list of used servers  */
280     if((isset($_POST['delNtpServer'])) && (isset($_POST['gotoNtpServerSelected'])) && $this->acl_is_writeable("gotoNtpServer")){
281       foreach($_POST['gotoNtpServerSelected'] as $name){
282         unset($this->gotoNtpServer[$name]);
283       }
284     }
286     /* Fill templating stuff */
287     $smarty= get_smarty();
289     /* Set acls */
290     $tmp = $this->plInfo();
291     foreach($tmp['plProvidedAcls'] as $name => $translation){
292       $smarty->assign($name."ACL",$this->getacl($name));
293     }
295     $smarty->assign("cn", $this->cn);
296     $smarty->assign("description", $this->description);
297     $smarty->assign("l", $this->l);
298     $smarty->assign("bases", $this->get_allowed_bases());
299     $smarty->assign("staticAddress", "");
301     $tmp = array();
302     foreach($this->gotoNtpServers as $server){
303       if(!in_array($server,$this->gotoNtpServer)){
304         $tmp[$server] = $server;
305       }
306     }
307     $smarty->assign("gotoNtpServers",$tmp);
308         
309     /* Check if workstation is online */
310     if (gosaSupportDaemon::ping($this->netConfigDNS->macAddress)){
311       $smarty->assign("actions", array("halt" => _("Switch off"), "reboot" => _("Reboot"),
312                                        "update" => _("Software update"),
313                                        "reinstall" => _("Reinstall"),
314                                        "rescan" => _("Rescan hardware"),
315                                        #"memcheck" => _("Memory test"),
316                                        "localboot" => _("Force localboot"),
317                                        #"sysinfo"  => _("System analysis")
318                                         ));
319     } else {
320       $smarty->assign("actions", array("wakeup" => _("Wake up"),
321                                        "reinstall" => _("Reinstall"),
322                                        "update" => _("Software update"),
323                                        #"memcheck" => _("Memory test"),
324                                        "localboot" => _("Force localboot"),
325                                        #"sysinfo"  => _("System analysis")
326                                         ));
327     }
328     /* Arrays */
329     $smarty->assign("modes", $this->modes);
330     $smarty->assign("nfsservers", $this->config->data['SERVERS']['NFS']);
331     $smarty->assign("syslogservers", $this->gotoSyslogServers);
332     $smarty->assign("fai_activated",$this->fai_activated);
334     $ntpser = array();
335     foreach($this->gotoNtpServers as $server){
336       if(!in_array($server,$this->gotoNtpServer)){
337         $ntpser[$server] = $server;
338       }
339     }
340     $smarty->assign("gotoNtpServers", $ntpser);
342     /* Variables */
343     foreach(array("base", "gotoMode", "gotoSyslogServer", "gotoNtpServer") as $val){
344       $smarty->assign($val."_select", $this->$val);
345     }
347     /* tell smarty the inherit checkbox state */
348     $smarty->assign("inheritTimeServer",$this->inheritTimeServer);
349     $smarty->assign("member_of_ogroup",$this->member_of_ogroup);
351     $str = $this->netConfigDNS->execute();
352     if(is_object($this->netConfigDNS->dialog)){
353       return($str);
354     }
355     $smarty->assign("netconfig", $str);
357     /* Display kerberos host key options */
358     $smarty->assign("host_key","");
359     if(is_object($this->kerberos_key_service)){
360       $smarty->assign("host_key",$this->kerberos_key_service->execute_by_prefix("host/"));
361     }
363     /* Show main page */
364     $smarty->assign("currently_installing", $this->currently_installing);
365     return($smarty->fetch (get_template_path('workstation.tpl', TRUE, dirname(__FILE__))));
366   }
368   function remove_from_parent()
369   {
370     if($this->acl_is_removeable()){
372       $this->netConfigDNS->remove_from_parent();
373       $ldap= $this->config->get_ldap_link();
374       $ldap->rmdir($this->dn);
375       new log("remove","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
376       if (!$ldap->success()){
377         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
378       }
380       /* Remove kerberos key dependencies too */
381       if(is_object($this->kerberos_key_service)){
382         $this->kerberos_key_service->remove_from_parent_by_prefix("host/");
383       }
385       /* Optionally execute a command after we're done */
386       $this->handle_post_events("remove", array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
388       /* Delete references to object groups */
389       $ldap->cd ($this->config->current['BASE']);
390       $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("cn"));
391       while ($ldap->fetch()){
392         $og= new ogroup($this->config, $ldap->getDN());
393         unset($og->member[$this->dn]);
394         $og->save ();
395       }
397       /* Remove all accessTo/trust dependencies */
398       update_accessTo($this->cn,"");
399     }
401     /* Clean queue form entries with this mac 
402      */
403     if(class_available("gosaSupportDaemon") && tests::is_mac($this->netConfigDNS->orig_macAddress)){
404       $q = new gosaSupportDaemon();
405       $q->clean_queue_from_mac($this->netConfigDNS->orig_macAddress);
406     }
408     if(isset($_POST["inheritAll"])){
409       $this->set_everything_to_inherited();
410     }
411   }
414   /* Save data to object */
415   function save_object()
416   {
418     /* Create a base backup and reset the
419        base directly after calling plugin::save_object();
420        Base will be set seperatly a few lines below */
421     $base_tmp = $this->base;
422     plugin::save_object();
423     $this->base = $base_tmp;
425     /* Save base, since this is no LDAP attribute */
426     $tmp = $this->get_allowed_bases();
427     if(isset($_POST['base'])){
428       if(isset($tmp[$_POST['base']])){
429         $this->base= $_POST['base'];
430       }
431     }
433     $this->netConfigDNS->save_object();
435     /* Set inherit mode */
436     if((isset($_POST['workgeneric_posted'])) && ($this->acl_is_writeable("gotoNtpServer"))){
437       if(isset($_POST["inheritTimeServer"]) && $this->member_of_ogroup){
438         $this->inheritTimeServer = true;
439       }else{
440         $this->inheritTimeServer = false;
441       }
442     }
443     
444     if(isset($_POST["inheritAll"])){
445       $this->set_everything_to_inherited();
446     }
448     /* Hanle kerberos host key plugin */
449     if(is_object($this->kerberos_key_service)){
450       $this->kerberos_key_service->save_object_by_prefix("host/");
451     }
452   }
455   /* Check supplied data */
456   function check()
457   {
458     /* Call common method to give check the hook */
459     $message= plugin::check();
460  
461     /* Skip IP & Mac checks if this is a template */
462     if($this->cn != "wdefault"){
463       $message= array_merge($message, $this->netConfigDNS->check());
464     }
466     $this->dn= "cn=".$this->cn.",".get_ou('workstationRDN').$this->base;
468     if ($this->cn == ""){
469       $message[]= msgPool::required(_("Name"));
470     }
472     /* Check if given name is a valid host/dns name */
473     if(!tests::is_dns_name($this->cn)){
474       $message[] = msgPool::invalid(_("Name"));
475     }
477     if ($this->orig_dn != $this->dn){
478       $ldap= $this->config->get_ldap_link();
479       # Do not allow objects with the same name in other departments, either
480       $ldap->cd ($this->config->current['BASE']);
482       if($this->cn == "wdefault"){
483         $ldap->cat($this->dn);
484       }else{
485         $ldap->search ("(&(cn=".$this->cn.")(objectClass=gotoWorkstation))", array("cn", "gosaUnitTag"));
486       }
487       if ($ldap->count() != 0){
488         while ($attrs= $ldap->fetch()){
489           if (preg_match("/cn=dhcp,/",$attrs['dn']) || preg_match ("/,".get_ou('systemIncomingRDN')."/", $ldap->getDN())){
490             continue;
491           } else {
492             if ($attrs['dn'] != $this->orig_dn) {
493               if (isset($this->config->current['HONOURUNITTAGS']) &&
494                   preg_match('/true/i', $this->config->current['HONOURUNITTAGS']) &&
495                   $attrs['gosaUnitTag'][0] != $this->get_gosaUnitTag()) {
496                 # the new/moved object is in a different administrative unit, this is not a duplicate 
497                 continue;
498               } else {
499                 $message[]= msgPool::duplicated(_("Name"));
500                 break;
501               }
502             }
503           }
504         }
505       }
506     }
508     /* Check for valid ntpServer selection */
509     if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
510       $message[]= msgPool::required(_("NTP server"));
511     }
513     /* Only systems with a valid ldap handle can be activated 
514      */
515     if($this->gotoMode == "active" && $this->initial_gotoMode != "active"){
517       if(isset($this->parent->by_object['workstartup']) &&
518           !count($this->parent->by_object['workstartup']->gotoLdapServers) && 
519           !$this->parent->by_object['workstartup']->gotoLdap_inherit){
521         $message[] = _("A valid LDAP server assignement is missing!");
522       }
523     }else{
524       /* Warn the user, that this host is currently installing */
525       if($this->currently_installing && !$this->currently_installing_warned && 
526           !preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->orig_dn)){
527       
528         /* Force aborting without message dialog */
529         $message[] = "";
530         $this->currently_installing_warned = TRUE;
531         msg_dialog::display(_("Software deployment"), 
532             _("This host is currently installing. If you want to save it, press 'OK'."),
533             CONFIRM_DIALOG);
534       }
535     }
537     /* Check if we are allowed to create or move this object
538      */
539     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
540       $message[] = msgPool::permCreate();
541     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
542       $message[] = msgPool::permMove();
543     }
544  
545     return ($message);
546   }
549   /* Save to LDAP */
550   function save()
551   {
552     /* Detect mode changes */
553     $activate= (isset($this->saved_attributes['gotoMode']) &&
554         $this->gotoMode != $this->saved_attributes['gotoMode'] &&
555         $this->gotoMode == "active" &&
556         tests::is_ip($this->netConfigDNS->ipHostNumber)) || $this->auto_activate;
557     plugin::save();
559     /* Strip out 'default' values */
560     foreach (array("gotoSyslogServer") as $val){
562       if (isset($this->attrs[$val]) && $this->attrs[$val] == "default"){
563         $this->attrs[$val]= array();
564       }
565     }
567     /* Add missing arrays */
568     foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
569       if (isset ($this->$val) && count ($this->$val) != 0){
570         $this->attrs["$val"]= $this->$val;
571       }
572     }
574     /* Remove all empty values */
575     if ($this->orig_dn == 'new'){
576       $attrs= array();
577       foreach ($this->attrs as $key => $val){
578         if (is_array($val) && count($val) == 0){
579           continue;
580         }
581         $attrs[$key]= $val;
582       }
583       $this->attrs= $attrs;
584     }
586     /* Update ntp server settings */
587     if($this->inheritTimeServer){
588       if($this->is_new){
589         if(isset($this->attrs['gotoNtpServer'])){
590           unset($this->attrs['gotoNtpServer']);
591         }
592       }else{
593         $this->attrs['gotoNtpServer'] = array();
594       }
595     }else{
596       /* Set ntpServers */
597       $this->attrs['gotoNtpServer'] = array();
598       foreach($this->gotoNtpServer as $server){
599         $this->attrs['gotoNtpServer'][] = $server;
600       }
601     }
603     /* cn=default and macAddress=- indicates that this is a template */
604     if($this->cn == "wdefault"){
605       $this->netConfigDNS->macAddress = "-";
606     }
608     /* Write back to ldap */
609     $ldap= $this->config->get_ldap_link();
610     if ($this->orig_dn == 'new'){
611       $ldap->cd($this->config->current['BASE']);
612       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
613       $ldap->cd($this->dn);
614       $ldap->add($this->attrs);
615       new log("create","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
616       if (!$ldap->success()){
617         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
618       }
620       $this->netConfigDNS->cn = $this->cn;
621       $this->netConfigDNS->save();
623       $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
624     } else {
625       if ($this->orig_dn != $this->dn){
627         /* Remove all accessTo/trust dependencies */
628         update_accessTo($this->orig_cn,$this->cn);
629       }
630       $ldap->cd($this->dn);
631       $this->cleanup();
632       $ldap->modify ($this->attrs); 
633       if (!$ldap->success()){
634         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
635       }
636       new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
638       $this->netConfigDNS->cn = $this->cn;
639       $this->netConfigDNS->save();
641       $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
642     }
644     if ($activate && class_available("DaemonEvent")){
646       /* Send installation activation
647        */
648       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
649       $o_queue = new gosaSupportDaemon();
650       if(isset($events['TRIGGERED']['DaemonEvent_installation_activation'])){
651         $evt = $events['TRIGGERED']['DaemonEvent_installation_activation'];
652         $tmp = new $evt['CLASS_NAME']($this->config);
653         $tmp->set_type(TRIGGERED_EVENT);
654         $tmp->add_targets(array($this->netConfigDNS->macAddress));
655         if(!$o_queue->append($tmp)){
656           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
657         }
658       }
659     }
661     /* If $this->ogroup is set add the new system to the requested ogroup */
662     if ($this->ogroup) {
663       $og = new ogroup($this->config, $this->ogroup);
664       $og->AddDelMembership($this->dn);
665       $og->save();
666     }
667   }
670   /* Display generic part for server copy & paste */
671   function getCopyDialog()
672   {
673     $vars = array("cn");
674     $smarty = get_smarty();
675     $smarty->assign("cn" ,$this->cn);
676     $smarty->assign("object","workstation");
677     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
678     $ret = array();
679     $ret['string'] = $str;
680     $ret['status'] = "";
681     return($ret);
682   }
685   function saveCopyDialog()
686   {
687     if(isset($_POST['cn'])){
688       $this->cn = $_POST['cn'];
689     }
690   }
693   function PrepareForCopyPaste($source)
694   {
695     plugin::PrepareForCopyPaste($source);
696     if(isset($source['macAddress'][0])){
697       $this->netConfigDNS->macAddress = $source['macAddress'][0];
698     }
699     if(isset($source['ipHostNumber'][0])){
700       $this->netConfigDNS->ipHostNumber = $source['ipHostNumber'][0];
701     }
703     /* Create used ntp server array */
704     $this->gotoNtpServer= array();
705     if(isset($source['gotoNtpServer'])){
706       $this->inheritTimeServer = false;
707       unset($source['gotoNtpServer']['count']);
708       foreach($source['gotoNtpServer'] as $server){
709         $this->gotoNtpServer[$server] = $server;
710       }
711     }
713     /* Set inherit checkbox state */
714     if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){
715       $this->inheritTimeServer = true;
716       $this->gotoNtpServer=array();
717     }
719     $source_o = new workgeneric($this->config, $source['dn']);
720     foreach (array('ghIdeDev', 'ghNetNic', 'ghScsiDev') as $attr) {
721       if (isset($source_o->$attr)) {
722         $this->$attr = $source_o->$attr;
723       }
724     }
726     $ldap = $this->config->get_ldap_link();
727     $res = $ldap->cat($source['dn'], array('gotoHardwareChecksum', 'gotoSysStatus'));
728     if ($res) {
729       $attrs = $ldap->fetch();
730       foreach(array('gotoHardwareChecksum', 'gotoSysStatus') as $attr) {
731         if (isset($attrs[$attr])) {
732             $this->$attr = $attrs[$attr][0];
733         }
734       }
735     }
736   }
739   /* Return plugin informations for acl handling 
740       #FIXME FAIscript seams to ununsed within this class... */ 
741   static function plInfo()
742   {
743     return (array(  
744           "plShortName"   => _("Generic"),
745           "plDescription" => _("Workstation generic"),
746           "plSelfModify"  => FALSE,
747           "plDepends"     => array(),
748           "plPriority"    => 0,
749           "plSection"     => array("administration"),
750           "plCategory"    => array("workstation" => array("description"  => _("Workstation"),
751                                                           "objectClass"  => "gotoWorkstation")),
752           "plProvidedAcls"=> array(
753             "cn"                  => _("Workstation name"),
754             "description"         => _("Description") ,
755             "l"                   => _("Location") ,
756             "base"                => _("Base") ,
757             "gotoMode"            => _("Goto mode"), 
758             "gotoSyslogServer"    => _("Syslog server"), 
759             "gotoNtpServer"       => _("Ntp server"), 
760             "userPassword"      => _("Root password"),
761             "createFAICD"         => _("Create FAI CD"),
762             "FAIstate"            => _("Action flag"))
763           ));
764   }
766   function set_everything_to_inherited()
767   {
768     /* Find out what is set in the object group as XDriver */
769     $inherit_xdriver = 0;
770     $inherit_xy_sync = 0;
771     if ($this->dn != 'new' || $this->ogroup) {
772         $ldap = $this->config->get_ldap_link();
773         $entry = NULL;
774         /* If initialized with an object group we need to use this instead of
775          * an object group we'll become a member in */
776         if ($this->ogroup) {
777             $entry = $ldap->cat($this->ogroup, array("gotoXDriver", "gotoXHsync", "gotoXVsync"));
778         }else {
779           $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("gotoXDriver", "gotoXHsync", "gotoXVsync"));
780           if ($ldap->count() == 1) {
781             $entry = $ldap->fetch();
782           }
783         }
784         if ($entry) {
785             /* Get list of valid XDrivers */
786             $xdrivers = $this->parent->by_object['workservice']->getListOfXDrivers();
787             /* Only inherit if driver in object group is set to something in the list of
788              * valid XDrivers */
789             if (in_array($entry['gotoXDriver'][0], $xdrivers)) {
790               $inherit_xdriver = 1;
791             }
792             if (isset($entry['gotoXHsync']) and isset($entry['gotoXVsync'])) {
793               $inherit_xy_sync = 1;
794             }
795         } 
796     }
798     $this->gotoSyslogServer  = "default";
799     $this->inheritTimeServer = TRUE;
801     /* Set workstation service attributes to inherited */
802     if($this->member_of_ogroup && isset($this->parent->by_object['workservice'])){
803       foreach(array("gotoXKbLayout","gotoXKbModel","gotoXKbVariant", "gotoXDriver",
804         "gotoXResolution","gotoXColordepth","gotoXMouseType","gotoXMouseport") as $name){
805           if(!(($name == 'gotoXDriver') && ($inherit_xdriver == 0))) {
806               if($this->parent->by_object['workservice']->acl_is_writeable($name)){
807                 $this->parent->by_object['workservice']->$name = "default"; 
808               }
809           }
810       }
811       
812       /* Inherit VSync/HSync if defined in the object group */
813       if ($inherit_xy_sync) {
814         $this->parent->by_object['workservice']->InheritXYSync = TRUE;
815       }
816     }
818     /* Set workstation startup attributes to inherited */
819     if($this->member_of_ogroup && isset($this->parent->by_object['workstartup'])){
820       $obj = $this->parent->by_object['workstartup'];
821       if($obj->acl_is_writeable("gotoBootKernel")){
822         $this->parent->by_object['workstartup']->gotoBootKernel = "default-inherited";
823       }
824       if($obj->acl_is_writeable("gotoLdapServer")){
825         $this->parent->by_object['workstartup']->gotoLdapServer = "default-inherited";
826         $this->parent->by_object['workstartup']->gotoLdap_inherit = TRUE;
827         $this->parent->by_object['workstartup']->gotoLdapServers = array();
828       }
829       if($obj->acl_is_writeable("FAIdebianMirror")){
830         $this->parent->by_object['workstartup']->FAIdebianMirror= "inherited";
831       }
832     }
833   }
835   // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
836 ?>