Code

Apply patch for #5572
[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 = $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>&nbsp;<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);
305         
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     }
440     
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();
457  
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       # Do not allow objects with the same name in other departments, either
477       $ldap->cd ($this->config->current['BASE']);
479       if($this->cn == "wdefault"){
480         $ldap->cat($this->dn);
481       }else{
482         $ldap->search ("(&(cn=".$this->cn.")(objectClass=gotoWorkstation))", array("cn", "gosaUnitTag"));
483       }
484       if ($ldap->count() != 0){
485         while ($attrs= $ldap->fetch()){
486           if (preg_match("/cn=dhcp,/",$attrs['dn']) || preg_match ("/,".get_ou('systemIncomingRDN')."/", $ldap->getDN())){
487             continue;
488           } else {
489             if ($attrs['dn'] != $this->orig_dn) {
490               if (isset($this->config->current['HONOURUNITTAGS']) &&
491                   preg_match('/true/i', $this->config->current['HONOURUNITTAGS']) &&
492                   $attrs['gosaUnitTag'][0] != $this->get_gosaUnitTag()) {
493                 # the new/moved object is in a different administrative unit, this is not a duplicate 
494                 continue;
495               } else {
496                 $message[]= msgPool::duplicated(_("Name"));
497                 break;
498               }
499             }
500           }
501         }
502       }
503     }
505     /* Check for valid ntpServer selection */
506     if((!$this->inheritTimeServer) && (!count($this->gotoNtpServer))){
507       $message[]= msgPool::required(_("NTP server"));
508     }
510     /* Only systems with a valid ldap handle can be activated 
511      */
512     if($this->gotoMode == "active" && $this->initial_gotoMode != "active"){
514       if(isset($this->parent->by_object['workstartup']) &&
515           !count($this->parent->by_object['workstartup']->gotoLdapServers) && 
516           !$this->parent->by_object['workstartup']->gotoLdap_inherit){
518         $message[] = _("A valid LDAP server assignement is missing!");
519       }
520     }else{
521       /* Warn the user, that this host is currently installing */
522       if($this->currently_installing && !$this->currently_installing_warned && 
523           !preg_match("/".preg_quote(get_ou("systemIncomingRDN"), '/')."/",$this->orig_dn)){
524       
525         /* Force aborting without message dialog */
526         $message[] = "";
527         $this->currently_installing_warned = TRUE;
528         msg_dialog::display(_("Software deployment"), 
529             _("This host is currently installing. If you want to save it, press 'OK'."),
530             CONFIRM_DIALOG);
531       }
532     }
534     /* Check if we are allowed to create or move this object
535      */
536     if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
537       $message[] = msgPool::permCreate();
538     }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
539       $message[] = msgPool::permMove();
540     }
541  
542     return ($message);
543   }
546   /* Save to LDAP */
547   function save()
548   {
549     /* Detect mode changes */
550     $activate= (isset($this->saved_attributes['gotoMode']) &&
551         $this->gotoMode != $this->saved_attributes['gotoMode'] &&
552         $this->gotoMode == "active" &&
553         tests::is_ip($this->netConfigDNS->ipHostNumber)) || $this->auto_activate;
554     plugin::save();
556     /* Strip out 'default' values */
557     foreach (array("gotoSyslogServer") as $val){
559       if (isset($this->attrs[$val]) && $this->attrs[$val] == "default"){
560         $this->attrs[$val]= array();
561       }
562     }
564     /* Add missing arrays */
565     foreach (array("ghScsiDev", "ghIdeDev", "ghNetNic") as $val){
566       if (isset ($this->$val) && count ($this->$val) != 0){
567         $this->attrs["$val"]= $this->$val;
568       }
569     }
571     /* Remove all empty values */
572     if ($this->orig_dn == 'new'){
573       $attrs= array();
574       foreach ($this->attrs as $key => $val){
575         if (is_array($val) && count($val) == 0){
576           continue;
577         }
578         $attrs[$key]= $val;
579       }
580       $this->attrs= $attrs;
581     }
583     /* Update ntp server settings */
584     if($this->inheritTimeServer){
585       if($this->is_new){
586         if(isset($this->attrs['gotoNtpServer'])){
587           unset($this->attrs['gotoNtpServer']);
588         }
589       }else{
590         $this->attrs['gotoNtpServer'] = array();
591       }
592     }else{
593       /* Set ntpServers */
594       $this->attrs['gotoNtpServer'] = array();
595       foreach($this->gotoNtpServer as $server){
596         $this->attrs['gotoNtpServer'][] = $server;
597       }
598     }
600     /* cn=default and macAddress=- indicates that this is a template */
601     if($this->cn == "wdefault"){
602       $this->netConfigDNS->macAddress = "-";
603     }
605     /* Write back to ldap */
606     $ldap= $this->config->get_ldap_link();
607     if ($this->orig_dn == 'new'){
608       $ldap->cd($this->config->current['BASE']);
609       $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
610       $ldap->cd($this->dn);
611       $ldap->add($this->attrs);
612       new log("create","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
613       if (!$ldap->success()){
614         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
615       }
617       $this->netConfigDNS->cn = $this->cn;
618       $this->netConfigDNS->save();
620       $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
621     } else {
622       if ($this->orig_dn != $this->dn){
624         /* Remove all accessTo/trust dependencies */
625         update_accessTo($this->orig_cn,$this->cn);
626       }
627       $ldap->cd($this->dn);
628       $this->cleanup();
629       $ldap->modify ($this->attrs); 
630       if (!$ldap->success()){
631         msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_MOD, get_class()));
632       }
633       new log("modify","workstation/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
635       $this->netConfigDNS->cn = $this->cn;
636       $this->netConfigDNS->save();
638       $this->handle_post_events("modify",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
639     }
641     if ($activate && class_available("DaemonEvent")){
643       /* Send installation activation
644        */
645       $events = DaemonEvent::get_event_types(SYSTEM_EVENT | HIDDEN_EVENT);
646       $o_queue = new gosaSupportDaemon();
647       if(isset($events['TRIGGERED']['DaemonEvent_installation_activation'])){
648         $evt = $events['TRIGGERED']['DaemonEvent_installation_activation'];
649         $tmp = new $evt['CLASS_NAME']($this->config);
650         $tmp->set_type(TRIGGERED_EVENT);
651         $tmp->add_targets(array($this->netConfigDNS->macAddress));
652         if(!$o_queue->append($tmp)){
653           msg_dialog::display(_("Service infrastructure"),msgPool::siError($o_queue->get_error()),ERROR_DIALOG);
654         }
655       }
656     }
658     /* If $this->ogroup is set add the new system to the requested ogroup */
659     if ($this->ogroup) {
660       $og = new ogroup($this->config, $this->ogroup);
661       $og->AddDelMembership($this->dn);
662       $og->save();
663     }
664   }
667   /* Display generic part for server copy & paste */
668   function getCopyDialog()
669   {
670     $vars = array("cn");
671     $smarty = get_smarty();
672     $smarty->assign("cn" ,$this->cn);
673     $smarty->assign("object","workstation");
674     $str = $smarty->fetch(get_template_path("paste_generic.tpl",TRUE));
675     $ret = array();
676     $ret['string'] = $str;
677     $ret['status'] = "";
678     return($ret);
679   }
682   function saveCopyDialog()
683   {
684     if(isset($_POST['cn'])){
685       $this->cn = $_POST['cn'];
686     }
687   }
690   function PrepareForCopyPaste($source)
691   {
692     plugin::PrepareForCopyPaste($source);
693     if(isset($source['macAddress'][0])){
694       $this->netConfigDNS->macAddress = $source['macAddress'][0];
695     }
696     if(isset($source['ipHostNumber'][0])){
697       $this->netConfigDNS->ipHostNumber = $source['ipHostNumber'][0];
698     }
700     /* Create used ntp server array */
701     $this->gotoNtpServer= array();
702     if(isset($source['gotoNtpServer'])){
703       $this->inheritTimeServer = false;
704       unset($source['gotoNtpServer']['count']);
705       foreach($source['gotoNtpServer'] as $server){
706         $this->gotoNtpServer[$server] = $server;
707       }
708     }
710     /* Set inherit checkbox state */
711     if((in_array("default",$this->gotoNtpServer)) || (count($this->gotoNtpServer)==0)){
712       $this->inheritTimeServer = true;
713       $this->gotoNtpServer=array();
714     }
716     $source_o = new workgeneric($this->config, $source['dn']);
717     foreach (array('ghIdeDev', 'ghNetNic', 'ghScsiDev') as $attr) {
718       if (isset($source_o->$attr)) {
719         $this->$attr = $source_o->$attr;
720       }
721     }
723     $ldap = $this->config->get_ldap_link();
724     $res = $ldap->cat($source['dn'], array('gotoHardwareChecksum', 'gotoSysStatus'));
725     if ($res) {
726       $attrs = $ldap->fetch();
727       foreach(array('gotoHardwareChecksum', 'gotoSysStatus') as $attr) {
728         if (isset($attrs[$attr])) {
729             $this->$attr = $attrs[$attr][0];
730         }
731       }
732     }
733   }
736   /* Return plugin informations for acl handling 
737       #FIXME FAIscript seams to ununsed within this class... */ 
738   static function plInfo()
739   {
740     return (array(  
741           "plShortName"   => _("Generic"),
742           "plDescription" => _("Workstation generic"),
743           "plSelfModify"  => FALSE,
744           "plDepends"     => array(),
745           "plPriority"    => 0,
746           "plSection"     => array("administration"),
747           "plCategory"    => array("workstation" => array("description"  => _("Workstation"),
748                                                           "objectClass"  => "gotoWorkstation")),
749           "plProvidedAcls"=> array(
750             "cn"                  => _("Workstation name"),
751             "description"         => _("Description") ,
752             "l"                   => _("Location") ,
753             "base"                => _("Base") ,
754             "gotoMode"            => _("Goto mode"), 
755             "gotoSyslogServer"    => _("Syslog server"), 
756             "gotoNtpServer"       => _("Ntp server"), 
757             "userPassword"      => _("Root password"),
758             "createFAICD"         => _("Create FAI CD"),
759             "FAIstate"            => _("Action flag"))
760           ));
761   }
763   function set_everything_to_inherited()
764   {
765     /* Find out what is set in the object group as XDriver */
766     $inherit_xdriver = 0;
767     $inherit_xy_sync = 0;
768     if ($this->dn != 'new' || $this->ogroup) {
769         $ldap = $this->config->get_ldap_link();
770         $entry = NULL;
771         /* If initialized with an object group we need to use this instead of
772          * an object group we'll become a member in */
773         if ($this->ogroup) {
774             $entry = $ldap->cat($this->ogroup, array("gotoXDriver", "gotoXHsync", "gotoXVsync"));
775         }else {
776           $ldap->search ("(&(objectClass=gosaGroupOfNames)(member=".LDAP::prepare4filter($this->dn)."))", array("gotoXDriver", "gotoXHsync", "gotoXVsync"));
777           if ($ldap->count() == 1) {
778             $entry = $ldap->fetch();
779           }
780         }
781         if ($entry) {
782             /* Get list of valid XDrivers */
783             $xdrivers = $this->parent->by_object['workservice']->getListOfXDrivers();
784             /* Only inherit if driver in object group is set to something in the list of
785              * valid XDrivers */
786             if (in_array($entry['gotoXDriver'][0], $xdrivers)) {
787               $inherit_xdriver = 1;
788             }
789             if (isset($entry['gotoXHsync']) and isset($entry['gotoXVsync'])) {
790               $inherit_xy_sync = 1;
791             }
792         } 
793     }
795     $this->gotoSyslogServer  = "default";
796     $this->inheritTimeServer = TRUE;
798     /* Set workstation service attributes to inherited */
799     if($this->member_of_ogroup && isset($this->parent->by_object['workservice'])){
800       foreach(array("gotoXKbLayout","gotoXKbModel","gotoXKbVariant", "gotoXDriver",
801         "gotoXResolution","gotoXColordepth","gotoXMouseType","gotoXMouseport") as $name){
802           if(!(($name == 'gotoXDriver') && ($inherit_xdriver == 0))) {
803               if($this->parent->by_object['workservice']->acl_is_writeable($name)){
804                 $this->parent->by_object['workservice']->$name = "default"; 
805               }
806           }
807       }
808       
809       /* Inherit VSync/HSync if defined in the object group */
810       if ($inherit_xy_sync) {
811         $this->parent->by_object['workservice']->InheritXYSync = TRUE;
812       }
813     }
815     /* Set workstation startup attributes to inherited */
816     if($this->member_of_ogroup && isset($this->parent->by_object['workstartup'])){
817       $obj = $this->parent->by_object['workstartup'];
818       if($obj->acl_is_writeable("gotoBootKernel")){
819         $this->parent->by_object['workstartup']->gotoBootKernel = "default-inherited";
820       }
821       if($obj->acl_is_writeable("gotoLdapServer")){
822         $this->parent->by_object['workstartup']->gotoLdapServer = "default-inherited";
823         $this->parent->by_object['workstartup']->gotoLdap_inherit = TRUE;
824         $this->parent->by_object['workstartup']->gotoLdapServers = array();
825       }
826       if($obj->acl_is_writeable("FAIdebianMirror")){
827         $this->parent->by_object['workstartup']->FAIdebianMirror= "inherited";
828       }
829     }
830   }
832   // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
833 ?>