Code

Added DHCP options to opsi hosts.
[gosa.git] / gosa-plugins / opsi / admin / opsi / class_opsigeneric.inc
1 <?php
4 /*! \brief  The opsi client base class.
5             This class can be implemented in tow different ways:
6               * as standalone opsi client
7               * as part of the samba tabs 
8             both types will be detected automatically.
10             This class allows to edit the properties of an opsi client
11              and its products.
12  */
13 class opsiGeneric extends plugin
14 {
15   /* Contains a list of all available netboot products 
16    */
17   private $a_availableNetbootProducts = array();
18   private $a_initial_availableNetbootProducts = array();
19   private $s_selectedNetbootProduct = "";  
20   private $s_initial_selectedNetbootProduct = "";  
22   /* Contains a list of all available local products
23    */
24   private $a_availableLocalProducts = array();
25   private $a_selectedLocalProducts = array();
26   private $a_initial_selectedLocalProducts = array();
28   /* Internal veriables 
29    */ 
30   private $opsi;            // The opsi handle
31   public  $parent = NULL;   // The parent object (in case of samba)
33   public  $hostId       = ""; // The host Id of the currently edit opsi host  
34   public  $mac          = ""; // The hosts mac address
35   public  $note         = ""; // A note
36   public  $description  = ""; // The client description
38   public  $initial_mac          = ""; 
39   public  $initial_note         = ""; 
40   public  $initial_description  = ""; 
42   private $init_failed = FALSE; // Is true if the opsi communication failed
43   private $standalone  = TRUE;  // Is true if this is a standlone plugin. (Not samba)
44   private $is_installed= FALSE; // Is true is the hast is already installed.
46   public $attributes = array("mac","note","description");
48   public $netConfigDNS = NULL;
50   /*! \brief  Initialize this class 
51       @param  Object    The GOsa base config.
52       @param  String    The Id of the host that we want to edit.
53       @param  Object    The parent object. (in case of samba)
54    */
55   public function __construct(&$config,$hostId,&$parent = NULL)
56   {
57     /* Create opsi handle
58      */
59     $this->opsi = new opsi($config); 
60     $this->config = $config;
61     
62     /* Check if we are are part of a windows workstation 
63      */
64     $this->parent = $parent;
65     if($parent instanceof wingeneric){
66       $this->standalone  = FALSE;
67     }
69     /* Get hostId 
70      */
71     if($hostId != "new"){
72       if(preg_match("/^opsi:/",$hostId)){
73         $this->hostId = preg_replace("/^opsi:=([^,]*),.*$/","\\1",$hostId);
74       }elseif($this->parent instanceof wingeneric){
75         $this->hostId = $this->parent->cn;
76         $this->hostId = preg_replace('/\$$/',"",$this->hostId);
77       }
78     }
80     /* Try to plugin */
81     $this->init();
82   }
83   
85   /*! \brief  Try to load opsi client informations from the 
86                gosa support daemon.
87    */
88   private function init()
89   {
90     $err = FALSE;
91     $this->init_failed = FALSE;
92     $this->initially_was_account = FALSE; 
94     /* We are a standalone plugin.
95      */
96     if($this->standalone ) {
97       $this->is_account = TRUE;
98     }
100     /* Try to load client infos from the gosa support daemon
101      */
102     if(!empty($this->hostId)){
104       $list = $this->opsi->list_clients($this->hostId);
105       $err |= $this->opsi->is_error();
107       /* Walk through all returned opsi clients and try to detect 
108           one that matches our hostId.
109          #FIXME Implement an opsi method which returns infos for only one opsi client, not all. 
110        */
111       foreach($list as $entry){
112         if(preg_match("/^".preg_quote($this->hostId, '/')."$/i",$entry['NAME'][0]['VALUE'])){
113           $this->initially_was_account = TRUE; 
114           $this->is_account = TRUE;
115           foreach(array(
116                 "is_installed" => "LASTSEEN",
117                 "description"  => "DESCRIPTION",
118                 "mac"          => "MAC", 
119                 "note"         => "NOTES") as $des => $src){
120             $des2 = "initial_".$des;
121             $this->$des2 = $this->$des = $entry[$src][0]['VALUE'];
122           } 
123           break;
124         }
125       }
126     }
128     /* Read informations about available netboot products. 
129         If not already done, before.
130      */
131     if(!$err && !count($this->a_availableNetbootProducts)){
132       $this->a_availableNetbootProducts = $this->opsi->get_netboot_products();
133       ksort($this->a_availableNetbootProducts);
134       $err |= $this->opsi->is_error();
135     }
137     /* Read informations about available netboot products. 
138         If not already done, before.
139      */
140     if(!$err && !count($this->a_availableLocalProducts)) {
141       $this->a_availableLocalProducts   = $this->opsi->get_local_products();
142       ksort($this->a_availableLocalProducts);
143       $err |= $this->opsi->is_error();
144     }
146     /* Get products selected by this host.
147      */
148     if(!$err && !empty($this->hostId)) {
149       $tmp = array_keys($this->opsi->get_netboot_products($this->hostId));
150       $err |= $this->opsi->is_error();
151       if(count($tmp) && !$err && !isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
152         $this->s_selectedNetbootProduct = $tmp[0];
153       
154         /* Read configuration for "Netboot Products" */
155         if(isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct])){
156           $CFG = $this->opsi->get_product_properties($this->s_selectedNetbootProduct,$this->hostId);
157           $this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'] = $CFG;
158         }
159       }
160       $err |= $this->opsi->is_error();
161     }
163     /* Get all selected local products 
164      */
165     if(!$err && !empty($this->hostId) && !count($this->a_selectedLocalProducts)) {
166       $tmp = $this->opsi->get_local_products($this->hostId); 
167       $err |= $this->opsi->is_error();
168       $this->a_selectedLocalProducts = $tmp;
169     }
171     /* Load product configuration for all already selected products.
172      */
173     if(!$err && !empty($this->hostId)) {
174       foreach($this->a_selectedLocalProducts as $name => $data){
175         if(!$err && !isset($this->a_selectedLocalProducts[$name]['CFG'])){
176           $CFG = $this->opsi->get_product_properties($name,$this->hostId);
177           $err |= $this->opsi->is_error();
178           $this->a_selectedLocalProducts[$name]['CFG'] = $CFG;
179         }
180       }
181     }
182   
183     /* Check if everything went fine else reset everything and display a retry button 
184      */
185     if($err){
186       $this->init_failed = TRUE;
187       
188     }else{
190       /* Remember initial settings */
191       $this->a_initial_selectedLocalProducts = $this->a_selectedLocalProducts;
192       $this->s_initial_selectedNetbootProduct = $this->s_selectedNetbootProduct;
193       $this->a_initial_availableNetbootProducts = $this->a_availableNetbootProducts;
195       /* Ensure that a valid netboot is selected product is.
196        */
197       if(empty($this->s_selectedNetbootProduct)){
198         $this->s_selectedNetbootProduct = key($this->a_availableNetbootProducts);
199       }
201       // Now fake a valid ldap entry ... this is necessary to avoid 
202       //  modifications in the dns/dhcp classes
204       // First fake cn 
205       $this->attrs['hostId'][0] = $this->hostId;
206       $this->attrs['cn'][0] = $this->hostId;
208       // Second detect DNS settings. 
209       $ldap = $this->config->get_ldap_link();
210       $ldap->cd($this->config->current['BASE']);
211       $strippedHostId = preg_replace("/\..*$/","",$this->hostId);
212       $ldap->search("(&(objectClass=dNSZone)(|(relativeDomainName=".$this->hostId.")(relativeDomainName=".$strippedHostId."))(aRecord=*))",array("aRecord"));
213       if($ldap->count()){
214         $attrs = $ldap->fetch();
215         $this->attrs['ipHostNumber']['count'] = 0;
216         $this->attrs['ipHostNumber'][0] = $attrs['aRecord'][0];
217       }
219       $this->attrs['macAddress']['count'] = 1;
220       $this->attrs['macAddress'][0] = &$this->mac;
222       // Initialize DHCP and DNS 
223       $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses, FALSE, "hostId");
224       $this->netConfigDNS->set_acl_category("opsi");
225       $this->netConfigDNS->set_acl_base($this->config->current['BASE']);
226       $this->netConfigDNS->IPisMust = FALSE;
227       $this->netConfigDNS->MACisMust = FALSE;
228     }
229   }
232   /*! \brief  Check given data.
233       @return Array   Returns an array with all issues.
234    */
235   public function check()
236   {
237     $messages = plugin::check();
238     $messages= array_merge($messages, $this->netConfigDNS->check());
240     if(empty($this->hostId)){
241       $messages[] = msgPool::required(_("Name"));
242     }elseif(!preg_match("/\./",$this->hostId)){
244       /* The hostId must contain a domain part 
245        */
246       $messages[] = msgPool::invalid(_("Name"),$this->hostId,"",
247           _("The field 'Name' must contain a domain part!"));
248     }elseif(preg_match("/[^a-z0-9\.\-_]/",$this->hostId)){
249       $messages[] = msgPool::invalid(_("Name"),$this->hostId,"/[a-z0-9\.\-_]/");
250     }
252     /* Ensure that the mac address is valid
253      */
254     if(!tests::is_mac($this->mac) || empty($this->mac)){
255       $messages[] = msgPool::invalid(_("MAC address"),$this->mac,"","00:0C:7F:31:33:F1");
256     }
257     return($messages);
258   }
261   /*! \brief  Create the html ui of this plugin
262       @return String  HTML content.
263    */
264   public function execute()
265   {
266     $display ="";
268     /* The pluign initialization failed due to communication problems with the gosa daemon. 
269        A retry button will be displayed here.
270      */
271     if($this->init_failed){
272       $smarty = get_smarty();
273       $smarty->assign("standalone ", $this->standalone );
274       $smarty->assign("init_failed",TRUE);
275       $smarty->assign("message",$this->opsi->get_error());
276       return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
277     }  
280     /* If we are not a stand alone opsi client, we must be a samba client 
281        which has the opsi tab enabled.
282        Check if the opsi is added or removed and display state buttons.
283      */
284     if(!$this->standalone ){
286       /* Do we need to flip is_account state? */
287       if(isset($_POST['modify_state'])){
288         if($this->is_account && $this->acl_is_removeable()){
289           $this->is_account= FALSE;
290         }elseif(!$this->is_account && $this->acl_is_createable()){
291           $this->is_account= TRUE;
292         }
293       }
294       if($this->is_account){
295         $display = $this->show_disable_header(msgPool::removeFeaturesButton(_("OPSI")), 
296             msgPool::featuresEnabled(_("OPSI")));
297       }else{
298         $display = $this->show_enable_header(msgPool::addFeaturesButton(_("OPSI")), 
299             msgPool::featuresDisabled(_("OPSI")));
300         return($display);
301       } 
302     } 
304     /* Check if we have a sub dialog opened
305      */
306     if(is_object($this->dialog)){
307       $this->dialog->save_object();
308       return($this->dialog->execute());
309     }
311     /* Create HTML output of this plugin
312      */
313     $smarty = get_smarty();
314     $smarty->assign("standalone", $this->standalone );
315     foreach($this->attributes as $attr){
316       $smarty->assign($attr,$this->$attr);
317     }
319     /* Assign ACLs */    
320     $tmp = $this->plInfo();
321     foreach($tmp['plProvidedAcls'] as $name => $translated){
322       $smarty->assign($name."ACL",$this->getacl($name));
323     }
325     $smarty->assign("is_installed", $this->is_installed);
326     $smarty->assign("init_failed",FALSE);
327     $divSLP = new divSelectBox();
328     $divALP = new divSelectBox();
330     /* Create list of available local products 
331      */
332     foreach($this->a_availableLocalProducts as $name => $data){
333       if(isset($this->a_selectedLocalProducts[$name])) continue;
335       $add_tab  = array("string"   => "<input type='image' src='images/back.png' name='add_lp_".$name."'>");
336       $name_tab = array("string"   => $name);
337       $desc_tab = array("string"   => "<div style='height: 14px;overflow:hidden;'>".$data['DESC']."</div>",
338           "attach"   => "title='".$data['DESC']."' style='border-right:0px;'");
340       if($this->acl_is_writeable("localProduct")){
341         $divALP->AddEntry(array($add_tab,$name_tab,$desc_tab));
342       }else{
343         $divALP->AddEntry(array($name_tab,$desc_tab));
344       }
345     }
347     /* Create list of selected local products 
348      */
349     ksort($this->a_selectedLocalProducts);
350     if($this->acl_is_readable("localProduct")){
351       foreach($this->a_selectedLocalProducts as $name => $data){
353         $name_tab = array("string"   => $name);
354         $desc_tab = array(
355             "string" => "<div style='height: 14px;overflow:hidden;'>".$data['DESC']."</div>",
356             "attach" => "title='".$data['DESC']."'");
358         /* Only display edit button, if there is something to edit 
359          */
360         $edit = "<img src='images/empty.png' alt=' '>";
361         if(count($data['CFG'])){
362           $edit = "<input type='image' src='images/lists/edit.png' name='edit_lp_".$name."'>";
363         }
364         $del  = "<input type='image' src='images/lists/trash.png' name='del_lp_".$name."'>";  
366         $opt_tab  = array("string" => $edit.$del,
367             "attach" => "style='border-right:0px; width: 40px; text-align:right;'");
369         if($this->acl_is_writeable("localProduct")){
370           $divSLP->AddEntry(array($name_tab,$desc_tab,$opt_tab));
371         }else{
372           $divSLP->AddEntry(array($name_tab,$desc_tab));
373         }
374       }
375     }
377     /* Check if netboot product is configurable 
378      */
379     $cfg_able =FALSE;
380     if(isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
381       $cfg_able = count($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG']);
382       $cfg_able &= $this->acl_is_readable("netbootProduct");
383     }
385     // Get net config template
386     $str = $this->netConfigDNS->execute();
387     if(is_object($this->netConfigDNS->dialog)){
388       return($str);
389     }
390     $smarty->assign("netconfig", $str);
392     $smarty->assign("netboot_configurable",$cfg_able);
393     $smarty->assign("hostId", $this->hostId);
394     $smarty->assign("divSLP", $divSLP->DrawList());
395     $smarty->assign("divALP", $divALP->DrawList());
396     $smarty->assign("SNP", $this->s_selectedNetbootProduct);
397     $smarty->assign("ANP", $this->a_availableNetbootProducts);
398     return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
399   }
402   /*! \brief  Save modifications using the gosa support daemon.
403    */
404   public function save()
405   {
406     
407     /* Check if we have to create a new opsi client
408         or just have to save client modifications.
409      */
410     if(!$this->initially_was_account && $this->is_account){
411       $res = $this->opsi->add_client($this->hostId,$this->mac,$this->note,$this->description);
412       if($this->opsi->is_error()){
413         msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
414         return;
415       }
416     }else{
418       /* Update client modifcations.
419           -Only if necessary  
420        */
421       if($this->note != $this->initial_note || 
422           $this->description != $this->initial_description ||
423           $this->mac != $this->initial_mac){
424         $this->opsi->modify_client($this->hostId,$this->mac,$this->note,$this->description);
425         if($this->opsi->is_error()){
426           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
427           return;
428         }
429       }
430     }
433     /***********
434       Detect local netboot product changes
435        - Check which products were removed.
436        - Check which products were added. 
437      ***********/
440     /* Detect which products were removed an which added.
441      */
442     $del = array_diff_assoc($this->a_initial_selectedLocalProducts,$this->a_selectedLocalProducts);
443     $add = array_diff_assoc($this->a_selectedLocalProducts,$this->a_initial_selectedLocalProducts);
445     /* Remove products from client
446      */
447     foreach($del as $name => $data){
448       $this->opsi->del_product_from_client($name,$this->hostId);
449       if($this->opsi->is_error()){
450         msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
451         return;
452       }
453     }
454     
455     /* Add products to client
456        And set the product properties.
457      */
458     foreach($add as $name => $data){
459       $this->opsi->add_product_to_client($name,$this->hostId);
460       if($this->opsi->is_error()){
461         msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
462         return;
463       }
464       if(!empty($data['CFG'])){
465         $this->opsi->set_product_properties($name,$data['CFG'],$this->hostId);
466         if($this->opsi->is_error()){
467           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
468           return;
469         }
470       }
471     }
473     /* Save local product properties 
474      */
475     foreach($this->a_selectedLocalProducts as $name => $data){
476       if(isset($del[$name]) || isset($add[$name])) continue;
478       /* Update product properties if there are changes 
479        */
480       $diffs = $this->get_config_changes($data['CFG'],$this->a_initial_selectedLocalProducts[$name]['CFG']);
481       if(count($diffs)){
482         $this->opsi->set_product_properties($name,$diffs,$this->hostId);
483         if($this->opsi->is_error()){
484           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
485           return;
486         }
487       }
488     }
490     /*********
491       Detect Netboot product changes
492        - Check if another netboot product was selected. 
493        - Check if the product properties were changes.
494      *********/
496     /* Update used netboot product. 
497      */
498     if($this->s_selectedNetbootProduct != $this->s_initial_selectedNetbootProduct){
499       if(!empty($this->s_initial_selectedNetbootProduct)){
500         $this->opsi->del_product_from_client($this->s_initial_selectedNetbootProduct,$this->hostId);
501         if($this->opsi->is_error()){
502           msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
503           return;
504         }
505       }
506       $this->opsi->add_product_to_client($this->s_selectedNetbootProduct,$this->hostId);
507       if($this->opsi->is_error()){
508         msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);    
509         return;
510       }
511     }
513     /* Check if we have to update the netboot product properties 
514         This is the case, if this product is newly selected.
515         Or if there was at least one configuration attribute modified.
516      */
517     $cfg_1 = $cfg_2 = array();
518     if(isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
519       $cfg_1 = $this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'];
520     }
521     if(isset($this->a_initial_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
522       $cfg_2 = $this->a_initial_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'];
523     }
524     $diffs = $this->get_config_changes($cfg_1,$cfg_2);
525     $to_update = array();
526     if( !$this->initially_was_account || 
527         $this->s_selectedNetbootProduct != $this->s_initial_selectedNetbootProduct){
528       $to_update = $this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'];
529     }elseif(count($diffs)){
530       $to_update = $diffs;
531     }
533     if(count($to_update)){
534       $name = $this->s_selectedNetbootProduct;
535       $this->opsi->set_product_properties($name,$to_update,$this->hostId);
536       if($this->opsi->is_error()){
537         msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
538         return;
539       }
540     }
542     $this->netConfigDNS->cn = $this->hostId;
543     $this->netConfigDNS->save();
544   }
546   
547   public function get_config_changes($c1,$c2)
548   {
549     /* Get key which are not present in both entries 
550      */
551     $res = array();
552     foreach($c2 as $name => $value){
553       if(!isset($c1[$name]) || $c1[$name]['DEFAULT'] != $c2[$name]['DEFAULT']){
554         $res[$name] = $c2[$name];
555       }
556     }
557     foreach($c1 as $name => $value){
558       if(!isset($c2[$name]) || $c2[$name]['DEFAULT'] != $c1[$name]['DEFAULT']){
559         $res[$name] = $c1[$name];
560       }
561     }
562     return($res);
563   }
566   /*! \brief  Removes the opsi client 
567    */  
568   public function remove_from_parent()
569   {
570     $this->netConfigDNS->remove_from_parent();
572     $this->opsi->del_client($this->hostId);
573     if($this->opsi->is_error()){
574       msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
575       return;
576     }
577   }
580   /*! \brief  Save html posts 
581    */
582   public function save_object()
583   {
584     /* Init failed; reinit is triggered here.
585      */
586     if(isset($_POST['reinit']) && $this->init_failed){
587       $this->init();
588     }
590     /* Property are currently edited, close the dialog. 
591      */
592     if(isset($_POST['cancel_properties']) && is_object($this->dialog)){
593       $this->dialog = NULL;
594     }
595   
596     /* Save product property changes 
597      */
598     if(isset($_POST['save_properties']) && ($this->dialog instanceof opsiProperties)){
599       $this->dialog->save_object();
600       $pro = $this->dialog->get_product();
601       $CFG = $this->dialog->get_cfg();
602       if(isset($this->a_selectedLocalProducts[$pro])){
603         if($this->acl_is_writeable("localProduct")){
604           $this->a_selectedLocalProducts[$pro]['CFG'] = $CFG;
605         }
606         $this->dialog = NULL;
607       }elseif($this->s_selectedNetbootProduct == $pro){
608         if($this->acl_is_writeable("netbootProduct")){
609           $this->a_availableNetbootProducts[$pro]['CFG'] = $CFG;
610         }
611         $this->dialog = NULL;
612       }else{
613         trigger_error("Fatal, unknown product was configured.");
614       }
615     }
617     /* Save html post
618      */
619     if(isset($_POST['opsiGeneric_posted'])){
621       plugin::save_object();
622       $this->netConfigDNS->save_object();
623       $this->mac = $this->netConfigDNS->macAddress;
624   
625       /* Get hostId 
626        */
627       if(isset($_POST['hostId']) && $this->standalone && $this->acl_is_writeable("hostId")){
628         $this->hostId = get_post('hostId');
629       }
631       /* Send actions like 'install' or 'wake' to the si server 
632        */
633       if($this->acl_is_writeable("triggerAction") && 
634           isset($_POST['opsi_action']) && 
635           isset($_POST['opsi_trigger_action']) && 
636           $this->standalone ){
637         $action = $_POST['opsi_action'];
638         if($action == "install"){
639           $this->install_client(); 
640         }
641         if($action == "wake"){
642           $this->wake_client(); 
643         }
644       }
646       /* Get selected netboot product.
647        */
648       if(isset($_POST['opsi_netboot_product']) && $this->acl_is_writeable("netbootProduct")){
649         $SNP = trim($_POST['opsi_netboot_product']);
650         if(isset($this->a_availableNetbootProducts[$SNP])){
651           if(!isset($this->a_availableNetbootProducts[$SNP]['CFG'])){
652             $CFG = $this->opsi->get_product_properties($SNP);
653             $this->a_availableNetbootProducts[$SNP]['CFG'] = $CFG;
654             if($this->opsi->is_error()){
655               $this->init_failed = TRUE;
656               return;
657             }
658           }
659           $this->s_selectedNetbootProduct = $SNP;
660         }
661       }
663       /* Add/remove/edit local products 
664        */
665       foreach($_POST as $name => $value){
667         /* Check if netboot product configuration is requested 
668          */
669         if(preg_match("/^configure_netboot/",$name) && $this->acl_is_readable("netbootProduct")){
670           $pro = $this->s_selectedNetbootProduct;
671           $cfg = $this->a_availableNetbootProducts[$pro]['CFG'];
672           $this->dialog = new opsiProperties($this->config,$pro,$cfg,$this->hostId);
673           break;
674         }
675       
676         /* Add product 
677          */
678         if(preg_match("/^add_lp_/",$name) && $this->acl_is_writeable("localProduct")){
679           $product = preg_replace("/^add_lp_(.*)_.$/","\\1",$name);
680           if(isset($this->a_availableLocalProducts[$product]) && !isset($this->a_selectedLocalProducts[$product])){
681             $this->a_selectedLocalProducts[$product] = $this->a_availableLocalProducts[$product];
682             $CFG = $this->opsi->get_product_properties($product);
683             if($this->opsi->is_error()){
684               $this->init_failed = TRUE;
685               return;
686             }
687             $this->a_selectedLocalProducts[$product]['CFG'] = $CFG;
688           }
689           break;
690         }
691   
692         /* Delete product 
693          */
694         if(preg_match("/^del_lp_/",$name) && $this->acl_is_writeable("localProduct")){
695           $product = preg_replace("/^del_lp_(.*)_.$/","\\1",$name);
696           if(isset($this->a_selectedLocalProducts[$product])){
697             unset($this->a_selectedLocalProducts[$product]);
698           }
699           break;
700         }
701       
702         /* Edit a product  
703          */
704         if(preg_match("/^edit_lp_/",$name) && $this->acl_is_readable("localProduct")){
705           $product = preg_replace("/^edit_lp_(.*)_.$/","\\1",$name);
706           $this->dialog = new opsiProperties($this->config,
707               $product,$this->a_selectedLocalProducts[$product]['CFG'],$this->hostId);
708           break;
709         }
710       }   
711     }
712   }
715   /* Triggers client installation 
716    */
717   function install_client()
718   {
719     $this->opsi->send_action("install",$this->hostId,$this->mac);
720     if($this->opsi->is_error()){
721       msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
722     }
723   }
726   /* Wake up client
727    */
728   function wake_client()
729   {
730     /* Check if we are able to communicate with the GOsa supprot daemon
731      */
732     if(class_available("gosaSupportDaemon")){
733       $o = new gosaSupportDaemon();
734       if($o->connect() && class_available("DaemonEvent_wakeup")){
735         $evt = new DaemonEvent_wakeup($this->config);      
736         $evt->add_targets(array($this->mac));
737         $o->append($evt);
738       }
739     }
740   }
743   /* Return plugin informations for acl handling */
744   static function plInfo()
745   {
746     return (array(
747           "plShortName"   => _("Generic"),
748           "plDescription" => _("OPSI generic"),
749           "plSelfModify"  => FALSE,
750           "plDepends"     => array(),
751           "plPriority"    => 1,
752           "plSection"     => array("administration"),
753           "plCategory"    => array("opsi" => array("description"  => _("Opsi"),
754               "objectClass"  => "dummy_class_opsi")),
756           "plProvidedAcls"=> array(
757             "hostId"          => _("Name"),
758             "mac"             => _("MAC address"),
759             "description"     => _("Description"),
760             "note"            => _("Note"),
761             "netbootProduct"  => _("Netboot product"),
762             "localProduct"    => _("Local product"),
763             "triggerAction"   => _("Action"))
764           ));
765   }
769 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
770 ?>