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;
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 }
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];
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 }
183 /* Check if everything went fine else reset everything and display a retry button
184 */
185 if($err){
186 $this->init_failed = TRUE;
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 {
238 // In case of initialization problem, we do not save anything.
239 // We can skip checks here, the date isn't usable.
240 if($this->init_failed){
241 return;
242 };
244 $messages = plugin::check();
245 $messages= array_merge($messages, $this->netConfigDNS->check());
247 if(empty($this->hostId)){
248 $messages[] = msgPool::required(_("Name"));
249 }elseif(!preg_match("/\./",$this->hostId)){
251 /* The hostId must contain a domain part
252 */
253 $messages[] = msgPool::invalid(_("Name"),$this->hostId,"",
254 _("The field 'Name' must contain a domain part!"));
255 }elseif(preg_match("/[^a-z0-9\.\-_]/",$this->hostId)){
256 $messages[] = msgPool::invalid(_("Name"),$this->hostId,"/[a-z0-9\.\-_]/");
257 }
259 /* Ensure that the mac address is valid
260 */
261 if(!tests::is_mac($this->mac) || empty($this->mac)){
262 $messages[] = msgPool::invalid(_("MAC address"),$this->mac,"","00:0C:7F:31:33:F1");
263 }
264 return($messages);
265 }
268 /*! \brief Create the html ui of this plugin
269 @return String HTML content.
270 */
271 public function execute()
272 {
273 $display ="";
275 /* The pluign initialization failed due to communication problems with the gosa daemon.
276 A retry button will be displayed here.
277 */
278 if($this->init_failed){
279 $smarty = get_smarty();
280 $smarty->assign("standalone ", $this->standalone );
281 $smarty->assign("init_failed",TRUE);
282 $smarty->assign("message",$this->opsi->get_error());
283 return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
284 }
287 /* If we are not a stand alone opsi client, we must be a samba client
288 which has the opsi tab enabled.
289 Check if the opsi is added or removed and display state buttons.
290 */
291 if(!$this->standalone ){
293 /* Do we need to flip is_account state? */
294 if(isset($_POST['modify_state'])){
295 if($this->is_account && $this->acl_is_removeable()){
296 $this->is_account= FALSE;
297 }elseif(!$this->is_account && $this->acl_is_createable()){
298 $this->is_account= TRUE;
299 }
300 }
301 if($this->is_account){
302 $display = $this->show_disable_header(msgPool::removeFeaturesButton(_("OPSI")),
303 msgPool::featuresEnabled(_("OPSI")));
304 }else{
305 $display = $this->show_enable_header(msgPool::addFeaturesButton(_("OPSI")),
306 msgPool::featuresDisabled(_("OPSI")));
307 return($display);
308 }
309 }
311 /* Check if we have a sub dialog opened
312 */
313 if(is_object($this->dialog)){
314 $this->dialog->save_object();
315 return($this->dialog->execute());
316 }
318 /* Create HTML output of this plugin
319 */
320 $smarty = get_smarty();
321 $smarty->assign("standalone", $this->standalone );
322 foreach($this->attributes as $attr){
323 $smarty->assign($attr,$this->$attr);
324 }
326 /* Assign ACLs */
327 $tmp = $this->plInfo();
328 foreach($tmp['plProvidedAcls'] as $name => $translated){
329 $smarty->assign($name."ACL",$this->getacl($name));
330 }
332 $smarty->assign("is_installed", $this->is_installed);
333 $smarty->assign("init_failed",FALSE);
334 $divSLP = new divSelectBox();
335 $divALP = new divSelectBox();
337 /* Create list of available local products
338 */
339 foreach($this->a_availableLocalProducts as $name => $data){
340 if(isset($this->a_selectedLocalProducts[$name])) continue;
342 $add_tab = array("string" => "<input type='image' src='images/back.png' name='add_lp_".$name."'>");
343 $name_tab = array("string" => $name);
344 $desc_tab = array("string" => "<div style='height: 14px;overflow:hidden;'>".$data['DESC']."</div>",
345 "attach" => "title='".$data['DESC']."' style='border-right:0px;'");
347 if($this->acl_is_writeable("localProduct")){
348 $divALP->AddEntry(array($add_tab,$name_tab,$desc_tab));
349 }else{
350 $divALP->AddEntry(array($name_tab,$desc_tab));
351 }
352 }
354 /* Create list of selected local products
355 */
356 ksort($this->a_selectedLocalProducts);
357 if($this->acl_is_readable("localProduct")){
358 foreach($this->a_selectedLocalProducts as $name => $data){
360 $name_tab = array("string" => $name);
361 $desc_tab = array(
362 "string" => "<div style='height: 14px;overflow:hidden;'>".$data['DESC']."</div>",
363 "attach" => "title='".$data['DESC']."'");
365 /* Only display edit button, if there is something to edit
366 */
367 $edit = "<img src='images/empty.png' alt=' '>";
368 if(count($data['CFG'])){
369 $edit = "<input type='image' src='images/lists/edit.png' name='edit_lp_".$name."'>";
370 }
371 $del = "<input type='image' src='images/lists/trash.png' name='del_lp_".$name."'>";
373 $opt_tab = array("string" => $edit.$del,
374 "attach" => "style='border-right:0px; width: 40px; text-align:right;'");
376 if($this->acl_is_writeable("localProduct")){
377 $divSLP->AddEntry(array($name_tab,$desc_tab,$opt_tab));
378 }else{
379 $divSLP->AddEntry(array($name_tab,$desc_tab));
380 }
381 }
382 }
384 /* Check if netboot product is configurable
385 */
386 $cfg_able =FALSE;
387 if(isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
388 $cfg_able = count($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG']);
389 $cfg_able &= $this->acl_is_readable("netbootProduct");
390 }
392 // Get net config template
393 $str = $this->netConfigDNS->execute();
394 if(is_object($this->netConfigDNS->dialog)){
395 return($str);
396 }
397 $smarty->assign("netconfig", $str);
399 $smarty->assign("netboot_configurable",$cfg_able);
400 $smarty->assign("hostId", $this->hostId);
401 $smarty->assign("divSLP", $divSLP->DrawList());
402 $smarty->assign("divALP", $divALP->DrawList());
403 $smarty->assign("SNP", $this->s_selectedNetbootProduct);
404 $smarty->assign("ANP", $this->a_availableNetbootProducts);
405 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
406 }
409 /*! \brief Save modifications using the gosa support daemon.
410 */
411 public function save()
412 {
413 if($this->init_failed){
414 return;
415 }
417 /* Check if we have to create a new opsi client
418 or just have to save client modifications.
419 */
420 if(!$this->initially_was_account && $this->is_account){
421 $res = $this->opsi->add_client($this->hostId,$this->mac,$this->note,$this->description);
422 if($this->opsi->is_error()){
423 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
424 return;
425 }
426 }else{
428 /* Update client modifcations.
429 -Only if necessary
430 */
431 if($this->note != $this->initial_note ||
432 $this->description != $this->initial_description ||
433 $this->mac != $this->initial_mac){
434 $this->opsi->modify_client($this->hostId,$this->mac,$this->note,$this->description);
435 if($this->opsi->is_error()){
436 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
437 return;
438 }
439 }
440 }
443 /***********
444 Detect local netboot product changes
445 - Check which products were removed.
446 - Check which products were added.
447 ***********/
450 /* Detect which products were removed an which added.
451 */
452 $del = array_diff_assoc($this->a_initial_selectedLocalProducts,$this->a_selectedLocalProducts);
453 $add = array_diff_assoc($this->a_selectedLocalProducts,$this->a_initial_selectedLocalProducts);
455 /* Remove products from client
456 */
457 foreach($del as $name => $data){
458 $this->opsi->del_product_from_client($name,$this->hostId);
459 if($this->opsi->is_error()){
460 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
461 return;
462 }
463 }
465 /* Add products to client
466 And set the product properties.
467 */
468 foreach($add as $name => $data){
469 $this->opsi->add_product_to_client($name,$this->hostId);
470 if($this->opsi->is_error()){
471 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
472 return;
473 }
474 if(!empty($data['CFG'])){
475 $this->opsi->set_product_properties($name,$data['CFG'],$this->hostId);
476 if($this->opsi->is_error()){
477 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
478 return;
479 }
480 }
481 }
483 /* Save local product properties
484 */
485 foreach($this->a_selectedLocalProducts as $name => $data){
486 if(isset($del[$name]) || isset($add[$name])) continue;
488 /* Update product properties if there are changes
489 */
490 $diffs = $this->get_config_changes($data['CFG'],$this->a_initial_selectedLocalProducts[$name]['CFG']);
491 if(count($diffs)){
492 $this->opsi->set_product_properties($name,$diffs,$this->hostId);
493 if($this->opsi->is_error()){
494 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
495 return;
496 }
497 }
498 }
500 /*********
501 Detect Netboot product changes
502 - Check if another netboot product was selected.
503 - Check if the product properties were changes.
504 *********/
506 /* Update used netboot product.
507 */
508 if($this->s_selectedNetbootProduct != $this->s_initial_selectedNetbootProduct){
509 if(!empty($this->s_initial_selectedNetbootProduct)){
510 $this->opsi->del_product_from_client($this->s_initial_selectedNetbootProduct,$this->hostId);
511 if($this->opsi->is_error()){
512 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
513 return;
514 }
515 }
516 $this->opsi->add_product_to_client($this->s_selectedNetbootProduct,$this->hostId);
517 if($this->opsi->is_error()){
518 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
519 return;
520 }
521 }
523 /* Check if we have to update the netboot product properties
524 This is the case, if this product is newly selected.
525 Or if there was at least one configuration attribute modified.
526 */
527 $cfg_1 = $cfg_2 = array();
528 if(isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
529 $cfg_1 = $this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'];
530 }
531 if(isset($this->a_initial_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
532 $cfg_2 = $this->a_initial_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'];
533 }
534 $diffs = $this->get_config_changes($cfg_1,$cfg_2);
535 $to_update = array();
536 if( !$this->initially_was_account ||
537 $this->s_selectedNetbootProduct != $this->s_initial_selectedNetbootProduct){
538 $to_update = $this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'];
539 }elseif(count($diffs)){
540 $to_update = $diffs;
541 }
543 if(count($to_update)){
544 $name = $this->s_selectedNetbootProduct;
545 $this->opsi->set_product_properties($name,$to_update,$this->hostId);
546 if($this->opsi->is_error()){
547 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
548 return;
549 }
550 }
552 $this->netConfigDNS->cn = $this->hostId;
553 $this->netConfigDNS->save();
554 }
557 public function get_config_changes($c1,$c2)
558 {
559 /* Get key which are not present in both entries
560 */
561 $res = array();
562 foreach($c2 as $name => $value){
563 if(!isset($c1[$name]) || $c1[$name]['DEFAULT'] != $c2[$name]['DEFAULT']){
564 $res[$name] = $c2[$name];
565 }
566 }
567 foreach($c1 as $name => $value){
568 if(!isset($c2[$name]) || $c2[$name]['DEFAULT'] != $c1[$name]['DEFAULT']){
569 $res[$name] = $c1[$name];
570 }
571 }
572 return($res);
573 }
576 /*! \brief Removes the opsi client
577 */
578 public function remove_from_parent()
579 {
580 if($this->init_failed){
581 return;
582 }
583 $this->netConfigDNS->remove_from_parent();
585 $this->opsi->del_client($this->hostId);
586 if($this->opsi->is_error()){
587 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
588 return;
589 }
590 }
593 /*! \brief Save html posts
594 */
595 public function save_object()
596 {
597 /* Init failed; reinit is triggered here.
598 */
599 if(isset($_POST['reinit']) && $this->init_failed){
600 $this->init();
601 }
603 /* Property are currently edited, close the dialog.
604 */
605 if(isset($_POST['cancel_properties']) && is_object($this->dialog)){
606 $this->dialog = NULL;
607 }
609 /* Save product property changes
610 */
611 if(isset($_POST['save_properties']) && ($this->dialog instanceof opsiProperties)){
612 $this->dialog->save_object();
613 $pro = $this->dialog->get_product();
614 $CFG = $this->dialog->get_cfg();
615 if(isset($this->a_selectedLocalProducts[$pro])){
616 if($this->acl_is_writeable("localProduct")){
617 $this->a_selectedLocalProducts[$pro]['CFG'] = $CFG;
618 }
619 $this->dialog = NULL;
620 }elseif($this->s_selectedNetbootProduct == $pro){
621 if($this->acl_is_writeable("netbootProduct")){
622 $this->a_availableNetbootProducts[$pro]['CFG'] = $CFG;
623 }
624 $this->dialog = NULL;
625 }else{
626 trigger_error("Fatal, unknown product was configured.");
627 }
628 }
630 /* Save html post
631 */
632 if(isset($_POST['opsiGeneric_posted'])){
634 plugin::save_object();
635 $this->netConfigDNS->save_object();
636 $this->mac = $this->netConfigDNS->macAddress;
638 /* Get hostId
639 */
640 if(isset($_POST['hostId']) && $this->standalone && $this->acl_is_writeable("hostId")){
641 $this->hostId = get_post('hostId');
642 }
644 /* Send actions like 'install' or 'wake' to the si server
645 */
646 if($this->acl_is_writeable("triggerAction") &&
647 isset($_POST['opsi_action']) &&
648 isset($_POST['opsi_trigger_action']) &&
649 $this->standalone ){
650 $action = $_POST['opsi_action'];
651 if($action == "install"){
652 $this->install_client();
653 }
654 if($action == "wake"){
655 $this->wake_client();
656 }
657 }
659 /* Get selected netboot product.
660 */
661 if(isset($_POST['opsi_netboot_product']) && $this->acl_is_writeable("netbootProduct")){
662 $SNP = trim($_POST['opsi_netboot_product']);
663 if(isset($this->a_availableNetbootProducts[$SNP])){
664 if(!isset($this->a_availableNetbootProducts[$SNP]['CFG'])){
665 $CFG = $this->opsi->get_product_properties($SNP);
666 $this->a_availableNetbootProducts[$SNP]['CFG'] = $CFG;
667 if($this->opsi->is_error()){
668 $this->init_failed = TRUE;
669 return;
670 }
671 }
672 $this->s_selectedNetbootProduct = $SNP;
673 }
674 }
676 /* Add/remove/edit local products
677 */
678 foreach($_POST as $name => $value){
680 /* Check if netboot product configuration is requested
681 */
682 if(preg_match("/^configure_netboot/",$name) && $this->acl_is_readable("netbootProduct")){
683 $pro = $this->s_selectedNetbootProduct;
684 $cfg = $this->a_availableNetbootProducts[$pro]['CFG'];
685 $this->dialog = new opsiProperties($this->config,$pro,$cfg,$this->hostId);
686 break;
687 }
689 /* Add product
690 */
691 if(preg_match("/^add_lp_/",$name) && $this->acl_is_writeable("localProduct")){
692 $product = preg_replace("/^add_lp_(.*)_.$/","\\1",$name);
693 if(isset($this->a_availableLocalProducts[$product]) && !isset($this->a_selectedLocalProducts[$product])){
694 $this->a_selectedLocalProducts[$product] = $this->a_availableLocalProducts[$product];
695 $CFG = $this->opsi->get_product_properties($product);
696 if($this->opsi->is_error()){
697 $this->init_failed = TRUE;
698 return;
699 }
700 $this->a_selectedLocalProducts[$product]['CFG'] = $CFG;
701 }
702 break;
703 }
705 /* Delete product
706 */
707 if(preg_match("/^del_lp_/",$name) && $this->acl_is_writeable("localProduct")){
708 $product = preg_replace("/^del_lp_(.*)_.$/","\\1",$name);
709 if(isset($this->a_selectedLocalProducts[$product])){
710 unset($this->a_selectedLocalProducts[$product]);
711 }
712 break;
713 }
715 /* Edit a product
716 */
717 if(preg_match("/^edit_lp_/",$name) && $this->acl_is_readable("localProduct")){
718 $product = preg_replace("/^edit_lp_(.*)_.$/","\\1",$name);
719 $this->dialog = new opsiProperties($this->config,
720 $product,$this->a_selectedLocalProducts[$product]['CFG'],$this->hostId);
721 break;
722 }
723 }
724 }
725 }
728 /* Triggers client installation
729 */
730 function install_client()
731 {
732 $this->opsi->send_action("install",$this->hostId,$this->mac);
733 if($this->opsi->is_error()){
734 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
735 }
736 }
739 /* Wake up client
740 */
741 function wake_client()
742 {
743 /* Check if we are able to communicate with the GOsa supprot daemon
744 */
745 if(class_available("gosaSupportDaemon")){
746 $o = new gosaSupportDaemon();
747 if($o->connect() && class_available("DaemonEvent_wakeup")){
748 $evt = new DaemonEvent_wakeup($this->config);
749 $evt->add_targets(array($this->mac));
750 $o->append($evt);
751 }
752 }
753 }
756 /* Return plugin informations for acl handling */
757 static function plInfo()
758 {
759 return (array(
760 "plShortName" => _("Generic"),
761 "plDescription" => _("OPSI generic"),
762 "plSelfModify" => FALSE,
763 "plDepends" => array(),
764 "plPriority" => 1,
765 "plSection" => array("administration"),
766 "plCategory" => array("opsi" => array("description" => _("Opsi"),
767 "objectClass" => "dummy_class_opsi")),
769 "plProvidedAcls"=> array(
770 "hostId" => _("Name"),
771 "mac" => _("MAC address"),
772 "description" => _("Description"),
773 "note" => _("Note"),
774 "netbootProduct" => _("Netboot product"),
775 "localProduct" => _("Local product"),
776 "triggerAction" => _("Action"))
777 ));
778 }
779 }
782 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
783 ?>