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 }
101 /* Try to load client infos from the gosa support daemon
102 */
103 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 // Get package info
129 if(!empty($this->hostId)){
130 $list = $this->opsi->get_full_product_host_information($this->hostId);
131 }
134 /* Read informations about available netboot products.
135 If not already done, before.
136 */
137 if(!$err && !count($this->a_availableNetbootProducts)){
138 $this->a_availableNetbootProducts = $this->opsi->get_netboot_products();
139 ksort($this->a_availableNetbootProducts);
140 $err |= $this->opsi->is_error();
141 }
143 /* Read informations about available netboot products.
144 If not already done, before.
145 */
146 foreach($list as $key => $entry){
147 if(!$entry['installed']){
148 $this->a_availableLocalProducts[$key] = array('DESC'=>$entry['data']['DESCRIPTION'],'NAME'=>$key);
149 }else{
150 $this->a_selectedLocalProducts[$key] = array('DESC'=>$entry['data']['DESCRIPTION'],'NAME'=>$key);
151 if($entry['configurable']){
152 $this->a_selectedLocalProducts[$key]['CFG'] = $entry['data']['PROPERTIES'];
153 }
154 }
155 }
156 # if(!$err && !count($this->a_availableLocalProducts)) {
157 # $this->a_availableLocalProducts = $this->opsi->get_local_products();
158 # ksort($this->a_availableLocalProducts);
159 # $err |= $this->opsi->is_error();
160 # }
162 /* Get products selected by this host.
163 */
164 if(!$err && !empty($this->hostId)) {
165 $tmp = array_keys($this->opsi->get_netboot_products($this->hostId));
166 $err |= $this->opsi->is_error();
167 if(count($tmp) && !$err && !isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
168 $this->s_selectedNetbootProduct = $tmp[0];
170 /* Read configuration for "Netboot Products" */
171 if(isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct])){
172 $CFG = $this->opsi->get_product_properties($this->s_selectedNetbootProduct,$this->hostId);
173 $this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'] = $CFG;
174 }
175 }
176 $err |= $this->opsi->is_error();
177 }
179 # /* Get all selected local products
180 # */
181 # if(!$err && !empty($this->hostId) && !count($this->a_selectedLocalProducts)) {
182 # $tmp = $this->opsi->get_local_products($this->hostId);
183 # $err |= $this->opsi->is_error();
184 # $this->a_selectedLocalProducts = $tmp;
185 # }
186 #
187 # /* Load product configuration for all already selected products.
188 # */
189 # if(!$err && !empty($this->hostId)) {
190 # foreach($this->a_selectedLocalProducts as $name => $data){
191 # if(!$err && !isset($this->a_selectedLocalProducts[$name]['CFG'])){
192 # $CFG = $this->opsi->get_product_properties($name,$this->hostId);
193 # $err |= $this->opsi->is_error();
194 # $this->a_selectedLocalProducts[$name]['CFG'] = $CFG;
195 # }
196 # }
197 # }
199 /* Check if everything went fine else reset everything and display a retry button
200 */
201 if($err){
202 $this->init_failed = TRUE;
204 }else{
206 /* Remember initial settings */
207 $this->a_initial_selectedLocalProducts = $this->a_selectedLocalProducts;
208 $this->s_initial_selectedNetbootProduct = $this->s_selectedNetbootProduct;
209 $this->a_initial_availableNetbootProducts = $this->a_availableNetbootProducts;
211 /* Ensure that a valid netboot is selected product is.
212 */
213 if(empty($this->s_selectedNetbootProduct)){
214 $this->s_selectedNetbootProduct = key($this->a_availableNetbootProducts);
215 }
217 // Now fake a valid ldap entry ... this is necessary to avoid
218 // modifications in the dns/dhcp classes
220 // First fake cn
221 $this->attrs['hostId'][0] = $this->hostId;
222 $this->attrs['cn'][0] = $this->hostId;
224 // Second detect DNS settings.
225 $ldap = $this->config->get_ldap_link();
226 $ldap->cd($this->config->current['BASE']);
227 $strippedHostId = preg_replace("/\..*$/","",$this->hostId);
228 $ldap->search("(&(objectClass=dNSZone)(|(relativeDomainName=".$this->hostId.")(relativeDomainName=".$strippedHostId."))(aRecord=*))",array("aRecord"));
229 if($ldap->count()){
230 $attrs = $ldap->fetch();
231 $this->attrs['ipHostNumber']['count'] = 0;
232 $this->attrs['ipHostNumber'][0] = $attrs['aRecord'][0];
233 }
235 $this->attrs['macAddress']['count'] = 1;
236 $this->attrs['macAddress'][0] = &$this->mac;
238 // Initialize DHCP and DNS
239 $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses, FALSE, "hostId");
240 $this->netConfigDNS->set_acl_category("opsi");
241 $this->netConfigDNS->set_acl_base($this->config->current['BASE']);
242 $this->netConfigDNS->IPisMust = FALSE;
243 $this->netConfigDNS->MACisMust = FALSE;
244 }
245 }
248 /*! \brief Check given data.
249 @return Array Returns an array with all issues.
250 */
251 public function check()
252 {
254 // In case of initialization problem, we do not save anything.
255 // We can skip checks here, the date isn't usable.
256 if($this->init_failed){
257 return;
258 };
260 $messages = plugin::check();
261 $messages= array_merge($messages, $this->netConfigDNS->check());
263 if(empty($this->hostId)){
264 $messages[] = msgPool::required(_("Name"));
265 }elseif(!preg_match("/\./",$this->hostId)){
267 /* The hostId must contain a domain part
268 */
269 $messages[] = msgPool::invalid(_("Name"),$this->hostId,"",
270 _("The field 'Name' must contain a domain part!"));
271 }elseif(preg_match("/[^a-z0-9\.\-_]/",$this->hostId)){
272 $messages[] = msgPool::invalid(_("Name"),$this->hostId,"/[a-z0-9\.\-_]/");
273 }
275 /* Ensure that the mac address is valid
276 */
277 if(!tests::is_mac($this->mac) || empty($this->mac)){
278 $messages[] = msgPool::invalid(_("MAC address"),$this->mac,"","00:0C:7F:31:33:F1");
279 }
280 return($messages);
281 }
284 /*! \brief Create the html ui of this plugin
285 @return String HTML content.
286 */
287 public function execute()
288 {
289 $display ="";
291 /* The pluign initialization failed due to communication problems with the gosa daemon.
292 A retry button will be displayed here.
293 */
294 if($this->init_failed){
295 $smarty = get_smarty();
296 $smarty->assign("standalone ", $this->standalone );
297 $smarty->assign("init_failed",TRUE);
298 $smarty->assign("message",$this->opsi->get_error());
299 return($smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
300 }
303 /* If we are not a stand alone opsi client, we must be a samba client
304 which has the opsi tab enabled.
305 Check if the opsi is added or removed and display state buttons.
306 */
307 if(!$this->standalone ){
309 /* Do we need to flip is_account state? */
310 if(isset($_POST['modify_state'])){
311 if($this->is_account && $this->acl_is_removeable()){
312 $this->is_account= FALSE;
313 }elseif(!$this->is_account && $this->acl_is_createable()){
314 $this->is_account= TRUE;
315 }
316 }
317 if($this->is_account){
318 $display = $this->show_disable_header(msgPool::removeFeaturesButton(_("OPSI")),
319 msgPool::featuresEnabled(_("OPSI")));
320 }else{
321 $display = $this->show_enable_header(msgPool::addFeaturesButton(_("OPSI")),
322 msgPool::featuresDisabled(_("OPSI")));
323 return($display);
324 }
325 }
327 /* Check if we have a sub dialog opened
328 */
329 if(is_object($this->dialog)){
330 $this->dialog->save_object();
331 return($this->dialog->execute());
332 }
334 /* Create HTML output of this plugin
335 */
336 $smarty = get_smarty();
337 $smarty->assign("standalone", $this->standalone );
338 foreach($this->attributes as $attr){
339 $smarty->assign($attr,$this->$attr);
340 }
342 /* Assign ACLs */
343 $tmp = $this->plInfo();
344 foreach($tmp['plProvidedAcls'] as $name => $translated){
345 $smarty->assign($name."ACL",$this->getacl($name));
346 }
348 $smarty->assign("is_installed", $this->is_installed);
349 $smarty->assign("init_failed",FALSE);
350 $divSLP = new divSelectBox();
351 $divALP = new divSelectBox();
353 /* Create list of available local products
354 */
355 foreach($this->a_availableLocalProducts as $name => $data){
356 if(isset($this->a_selectedLocalProducts[$name])) continue;
358 $add_tab = array("string" => "<input type='image' src='images/back.png' name='add_lp_".$name."'>");
359 $name_tab = array("string" => $name);
360 $desc_tab = array("string" => "<div style='height: 14px;overflow:hidden;'>".$data['DESC']."</div>",
361 "attach" => "title='".$data['DESC']."' style='border-right:0px;'");
363 if($this->acl_is_writeable("localProduct")){
364 $divALP->AddEntry(array($add_tab,$name_tab,$desc_tab));
365 }else{
366 $divALP->AddEntry(array($name_tab,$desc_tab));
367 }
368 }
370 /* Create list of selected local products
371 */
372 ksort($this->a_selectedLocalProducts);
373 if($this->acl_is_readable("localProduct")){
374 foreach($this->a_selectedLocalProducts as $name => $data){
376 $name_tab = array("string" => $name);
377 $desc_tab = array(
378 "string" => "<div style='height: 14px;overflow:hidden;'>".$data['DESC']."</div>",
379 "attach" => "title='".$data['DESC']."'");
381 /* Only display edit button, if there is something to edit
382 */
383 $edit = "<img src='images/empty.png' alt=' '>";
384 if(count($data['CFG'])){
385 $edit = "<input type='image' src='images/lists/edit.png' name='edit_lp_".$name."'>";
386 }
387 $del = "<input type='image' src='images/lists/trash.png' name='del_lp_".$name."'>";
389 $opt_tab = array("string" => $edit.$del,
390 "attach" => "style='border-right:0px; width: 40px; text-align:right;'");
392 if($this->acl_is_writeable("localProduct")){
393 $divSLP->AddEntry(array($name_tab,$desc_tab,$opt_tab));
394 }else{
395 $divSLP->AddEntry(array($name_tab,$desc_tab));
396 }
397 }
398 }
400 /* Check if netboot product is configurable
401 */
402 $cfg_able =FALSE;
403 if(isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
404 $cfg_able = count($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG']);
405 $cfg_able &= $this->acl_is_readable("netbootProduct");
406 }
408 // Get net config template
409 $str = $this->netConfigDNS->execute();
410 if(is_object($this->netConfigDNS->dialog)){
411 return($str);
412 }
413 $smarty->assign("netconfig", $str);
415 $smarty->assign("netboot_configurable",$cfg_able);
416 $smarty->assign("hostId", $this->hostId);
417 $smarty->assign("divSLP", $divSLP->DrawList());
418 $smarty->assign("divALP", $divALP->DrawList());
419 $smarty->assign("SNP", $this->s_selectedNetbootProduct);
420 $smarty->assign("ANP", $this->a_availableNetbootProducts);
421 return($display.$smarty->fetch(get_template_path("generic.tpl",TRUE,dirname(__FILE__))));
422 }
425 /*! \brief Save modifications using the gosa support daemon.
426 */
427 public function save()
428 {
429 if($this->init_failed){
430 return;
431 }
433 /* Check if we have to create a new opsi client
434 or just have to save client modifications.
435 */
436 if(!$this->initially_was_account && $this->is_account){
437 $res = $this->opsi->add_client($this->hostId,$this->mac,$this->note,$this->description);
438 if($this->opsi->is_error()){
439 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
440 return;
441 }
442 }else{
444 /* Update client modifcations.
445 -Only if necessary
446 */
447 if($this->note != $this->initial_note ||
448 $this->description != $this->initial_description ||
449 $this->mac != $this->initial_mac){
450 $this->opsi->modify_client($this->hostId,$this->mac,$this->note,$this->description);
451 if($this->opsi->is_error()){
452 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
453 return;
454 }
455 }
456 }
459 /***********
460 Detect local netboot product changes
461 - Check which products were removed.
462 - Check which products were added.
463 ***********/
466 /* Detect which products were removed an which added.
467 */
468 $del = array_diff_assoc($this->a_initial_selectedLocalProducts,$this->a_selectedLocalProducts);
469 $add = array_diff_assoc($this->a_selectedLocalProducts,$this->a_initial_selectedLocalProducts);
471 /* Remove products from client
472 */
473 foreach($del as $name => $data){
474 $this->opsi->del_product_from_client($name,$this->hostId);
475 if($this->opsi->is_error()){
476 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
477 return;
478 }
479 }
481 /* Add products to client
482 And set the product properties.
483 */
484 foreach($add as $name => $data){
485 $this->opsi->add_product_to_client($name,$this->hostId);
486 if($this->opsi->is_error()){
487 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
488 return;
489 }
490 if(!empty($data['CFG'])){
491 $this->opsi->set_product_properties($name,$data['CFG'],$this->hostId);
492 if($this->opsi->is_error()){
493 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
494 return;
495 }
496 }
497 }
499 /* Save local product properties
500 */
501 foreach($this->a_selectedLocalProducts as $name => $data){
502 if(isset($del[$name]) || isset($add[$name])) continue;
504 /* Update product properties if there are changes
505 */
506 $diffs = $this->get_config_changes($data['CFG'],$this->a_initial_selectedLocalProducts[$name]['CFG']);
507 if(count($diffs)){
508 $this->opsi->set_product_properties($name,$diffs,$this->hostId);
509 if($this->opsi->is_error()){
510 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
511 return;
512 }
513 }
514 }
516 /*********
517 Detect Netboot product changes
518 - Check if another netboot product was selected.
519 - Check if the product properties were changes.
520 *********/
522 /* Update used netboot product.
523 */
524 if($this->s_selectedNetbootProduct != $this->s_initial_selectedNetbootProduct){
525 if(!empty($this->s_initial_selectedNetbootProduct)){
526 $this->opsi->del_product_from_client($this->s_initial_selectedNetbootProduct,$this->hostId);
527 if($this->opsi->is_error()){
528 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
529 return;
530 }
531 }
532 $this->opsi->add_product_to_client($this->s_selectedNetbootProduct,$this->hostId);
533 if($this->opsi->is_error()){
534 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
535 return;
536 }
537 }
539 /* Check if we have to update the netboot product properties
540 This is the case, if this product is newly selected.
541 Or if there was at least one configuration attribute modified.
542 */
543 $cfg_1 = $cfg_2 = array();
544 if(isset($this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
545 $cfg_1 = $this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'];
546 }
547 if(isset($this->a_initial_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'])){
548 $cfg_2 = $this->a_initial_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'];
549 }
550 $diffs = $this->get_config_changes($cfg_1,$cfg_2);
551 $to_update = array();
552 if( !$this->initially_was_account ||
553 $this->s_selectedNetbootProduct != $this->s_initial_selectedNetbootProduct){
554 $to_update = $this->a_availableNetbootProducts[$this->s_selectedNetbootProduct]['CFG'];
555 }elseif(count($diffs)){
556 $to_update = $diffs;
557 }
559 if(count($to_update)){
560 $name = $this->s_selectedNetbootProduct;
561 $this->opsi->set_product_properties($name,$to_update,$this->hostId);
562 if($this->opsi->is_error()){
563 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
564 return;
565 }
566 }
568 $this->netConfigDNS->cn = $this->hostId;
569 $this->netConfigDNS->save();
570 }
573 public function get_config_changes($c1,$c2)
574 {
575 /* Get key which are not present in both entries
576 */
577 $res = array();
578 foreach($c2 as $name => $value){
579 if(!isset($c1[$name]) || $c1[$name]['DEFAULT'] != $c2[$name]['DEFAULT']){
580 $res[$name] = $c2[$name];
581 }
582 }
583 foreach($c1 as $name => $value){
584 if(!isset($c2[$name]) || $c2[$name]['DEFAULT'] != $c1[$name]['DEFAULT']){
585 $res[$name] = $c1[$name];
586 }
587 }
588 return($res);
589 }
592 /*! \brief Removes the opsi client
593 */
594 public function remove_from_parent()
595 {
596 if($this->init_failed){
597 return;
598 }
599 $this->netConfigDNS->remove_from_parent();
601 $this->opsi->del_client($this->hostId);
602 if($this->opsi->is_error()){
603 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
604 return;
605 }
606 }
609 /*! \brief Save html posts
610 */
611 public function save_object()
612 {
613 /* Init failed; reinit is triggered here.
614 */
615 if(isset($_POST['reinit']) && $this->init_failed){
616 $this->init();
617 }
619 /* Property are currently edited, close the dialog.
620 */
621 if(isset($_POST['cancel_properties']) && is_object($this->dialog)){
622 $this->dialog = NULL;
623 }
625 /* Save product property changes
626 */
627 if(isset($_POST['save_properties']) && ($this->dialog instanceof opsiProperties)){
628 $this->dialog->save_object();
629 $pro = $this->dialog->get_product();
630 $CFG = $this->dialog->get_cfg();
631 if(isset($this->a_selectedLocalProducts[$pro])){
632 if($this->acl_is_writeable("localProduct")){
633 $this->a_selectedLocalProducts[$pro]['CFG'] = $CFG;
634 }
635 $this->dialog = NULL;
636 }elseif($this->s_selectedNetbootProduct == $pro){
637 if($this->acl_is_writeable("netbootProduct")){
638 $this->a_availableNetbootProducts[$pro]['CFG'] = $CFG;
639 }
640 $this->dialog = NULL;
641 }else{
642 trigger_error("Fatal, unknown product was configured.");
643 }
644 }
646 /* Save html post
647 */
648 if(isset($_POST['opsiGeneric_posted'])){
650 plugin::save_object();
651 $this->netConfigDNS->save_object();
652 $this->mac = $this->netConfigDNS->macAddress;
654 /* Get hostId
655 */
656 if(isset($_POST['hostId']) && $this->standalone && $this->acl_is_writeable("hostId")){
657 $this->hostId = get_post('hostId');
658 }
660 /* Send actions like 'install' or 'wake' to the si server
661 */
662 if($this->acl_is_writeable("triggerAction") &&
663 isset($_POST['opsi_action']) &&
664 isset($_POST['opsi_trigger_action']) &&
665 $this->standalone ){
666 $action = $_POST['opsi_action'];
667 if($action == "install"){
668 $this->install_client();
669 }
670 if($action == "wake"){
671 $this->wake_client();
672 }
673 }
675 /* Get selected netboot product.
676 */
677 if(isset($_POST['opsi_netboot_product']) && $this->acl_is_writeable("netbootProduct")){
678 $SNP = trim($_POST['opsi_netboot_product']);
679 if(isset($this->a_availableNetbootProducts[$SNP])){
680 if(!isset($this->a_availableNetbootProducts[$SNP]['CFG'])){
681 $CFG = $this->opsi->get_product_properties($SNP);
682 $this->a_availableNetbootProducts[$SNP]['CFG'] = $CFG;
683 if($this->opsi->is_error()){
684 $this->init_failed = TRUE;
685 return;
686 }
687 }
688 $this->s_selectedNetbootProduct = $SNP;
689 }
690 }
692 /* Add/remove/edit local products
693 */
694 foreach($_POST as $name => $value){
696 /* Check if netboot product configuration is requested
697 */
698 if(preg_match("/^configure_netboot/",$name) && $this->acl_is_readable("netbootProduct")){
699 $pro = $this->s_selectedNetbootProduct;
700 $cfg = $this->a_availableNetbootProducts[$pro]['CFG'];
701 $this->dialog = new opsiProperties($this->config,$pro,$cfg,$this->hostId);
702 break;
703 }
705 /* Add product
706 */
707 if(preg_match("/^add_lp_/",$name) && $this->acl_is_writeable("localProduct")){
708 $product = preg_replace("/^add_lp_(.*)_.$/","\\1",$name);
709 if(isset($this->a_availableLocalProducts[$product]) && !isset($this->a_selectedLocalProducts[$product])){
710 $this->a_selectedLocalProducts[$product] = $this->a_availableLocalProducts[$product];
711 $CFG = $this->opsi->get_product_properties($product);
712 if($this->opsi->is_error()){
713 $this->init_failed = TRUE;
714 return;
715 }
716 $this->a_selectedLocalProducts[$product]['CFG'] = $CFG;
717 }
718 break;
719 }
721 /* Delete product
722 */
723 if(preg_match("/^del_lp_/",$name) && $this->acl_is_writeable("localProduct")){
724 $product = preg_replace("/^del_lp_(.*)_.$/","\\1",$name);
725 if(isset($this->a_selectedLocalProducts[$product])){
726 unset($this->a_selectedLocalProducts[$product]);
727 }
728 break;
729 }
731 /* Edit a product
732 */
733 if(preg_match("/^edit_lp_/",$name) && $this->acl_is_readable("localProduct")){
734 $product = preg_replace("/^edit_lp_(.*)_.$/","\\1",$name);
735 $this->dialog = new opsiProperties($this->config,
736 $product,$this->a_selectedLocalProducts[$product]['CFG'],$this->hostId);
737 break;
738 }
739 }
740 }
741 }
744 /* Triggers client installation
745 */
746 function install_client()
747 {
748 $this->opsi->send_action("install",$this->hostId,$this->mac);
749 if($this->opsi->is_error()){
750 msg_dialog::display(_("Error"),msgPool::siError($this->opsi->get_error()),ERROR_DIALOG);
751 }
752 }
755 /* Wake up client
756 */
757 function wake_client()
758 {
759 /* Check if we are able to communicate with the GOsa supprot daemon
760 */
761 if(class_available("gosaSupportDaemon")){
762 $o = new gosaSupportDaemon();
763 if($o->connect() && class_available("DaemonEvent_wakeup")){
764 $evt = new DaemonEvent_wakeup($this->config);
765 $evt->add_targets(array($this->mac));
766 $o->append($evt);
767 }
768 }
769 }
772 /* Return plugin informations for acl handling */
773 static function plInfo()
774 {
775 return (array(
776 "plShortName" => _("Generic"),
777 "plDescription" => _("OPSI generic"),
778 "plSelfModify" => FALSE,
779 "plDepends" => array(),
780 "plPriority" => 1,
781 "plSection" => array("administration"),
782 "plCategory" => array("opsi" => array("description" => _("Opsi"),
783 "objectClass" => "dummy_class_opsi")),
785 "plProvidedAcls"=> array(
786 "hostId" => _("Name"),
787 "mac" => _("MAC address"),
788 "description" => _("Description"),
789 "note" => _("Note"),
790 "netbootProduct" => _("Netboot product"),
791 "localProduct" => _("Local product"),
792 "triggerAction" => _("Action"))
793 ));
794 }
795 }
798 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
799 ?>