1 ## @file
2 # @details A GOsa-SI-server event module containing all functions for message handling.
3 # @brief Implementation of an event module for GOsa-SI-server.
6 package opsi_com;
7 use Exporter;
8 @ISA = qw(Exporter);
9 my @events = (
10 "get_events",
11 "opsi_install_client",
12 "opsi_get_netboot_products",
13 "opsi_get_local_products",
14 "opsi_get_client_hardware",
15 "opsi_get_client_software",
16 "opsi_get_product_properties",
17 "opsi_set_product_properties",
18 "opsi_list_clients",
19 "opsi_del_client",
20 "opsi_add_client",
21 "opsi_modify_client",
22 "opsi_add_product_to_client",
23 "opsi_del_product_from_client",
24 );
25 @EXPORT = @events;
27 use strict;
28 use warnings;
29 use GOSA::GosaSupportDaemon;
30 use Data::Dumper;
31 use XML::Quote qw(:all);
34 BEGIN {}
36 END {}
38 ## @method get_events()
39 # A brief function returning a list of functions which are exported by importing the module.
40 # @return List of all provided functions
41 sub get_events {
42 return \@events;
43 }
45 ## @method opsi_add_product_to_client
46 # Adds an Opsi product to an Opsi client.
47 # @param msg - STRING - xml message with tags hostId and productId
48 # @param msg_hash - HASHREF - message information parsed into a hash
49 # @param session_id - INTEGER - POE session id of the processing of this message
50 # @return out_msg - STRING - feedback to GOsa in success and error case
51 sub opsi_add_product_to_client {
52 my ($msg, $msg_hash, $session_id) = @_;
53 my $header = @{$msg_hash->{'header'}}[0];
54 my $source = @{$msg_hash->{'source'}}[0];
55 my $target = @{$msg_hash->{'target'}}[0];
56 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
57 my ($hostId, $productId);
58 my $error = 0;
60 # Build return message
61 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
62 if (defined $forward_to_gosa) {
63 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
64 }
66 # Sanity check of needed parameter
67 if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
68 $error++;
69 &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
70 &add_content2xml_hash($out_hash, "error", "hostId");
71 &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1);
73 }
74 if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1) || (@{$msg_hash->{'productId'}}[0] eq ref 'HASH')) {
75 $error++;
76 &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
77 &add_content2xml_hash($out_hash, "error", "productId");
78 &main::daemon_log("$session_id ERROR: no productId specified or procutId tag invalid: $msg", 1);
79 }
81 if (not $error) {
82 # Get hostId
83 $hostId = @{$msg_hash->{'hostId'}}[0];
84 &add_content2xml_hash($out_hash, "hostId", $hostId);
86 # Get productID
87 $productId = @{$msg_hash->{'productId'}}[0];
88 &add_content2xml_hash($out_hash, "productId", $productId);
90 # Do an action request for all these -> "setup".
91 my $callobj = {
92 method => 'setProductActionRequest',
93 params => [ $productId, $hostId, "setup" ],
94 id => 1, };
96 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
97 my ($sres_err, $sres_err_string) = &check_opsi_res($sres);
98 if ($sres_err){
99 &main::daemon_log("$session_id ERROR: cannot add product: ".$sres_err_string, 1);
100 &add_content2xml_hash($out_hash, "error", $sres_err_string);
101 }
102 }
104 # return message
105 return ( &create_xml_string($out_hash) );
106 }
108 ## @method opsi_del_product_from_client
109 # Deletes an Opsi-product from an Opsi-client.
110 # @param msg - STRING - xml message with tags hostId and productId
111 # @param msg_hash - HASHREF - message information parsed into a hash
112 # @param session_id - INTEGER - POE session id of the processing of this message
113 # @return out_msg - STRING - feedback to GOsa in success and error case
114 sub opsi_del_product_from_client {
115 my ($msg, $msg_hash, $session_id) = @_;
116 my $header = @{$msg_hash->{'header'}}[0];
117 my $source = @{$msg_hash->{'source'}}[0];
118 my $target = @{$msg_hash->{'target'}}[0];
119 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
120 my ($hostId, $productId);
121 my $error = 0;
122 my ($sres, $sres_err, $sres_err_string);
124 # Build return message
125 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
126 if (defined $forward_to_gosa) {
127 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
128 }
130 # Sanity check of needed parameter
131 if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
132 $error++;
133 &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
134 &add_content2xml_hash($out_hash, "error", "hostId");
135 &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1);
137 }
138 if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1) || (@{$msg_hash->{'productId'}}[0] eq ref 'HASH')) {
139 $error++;
140 &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
141 &add_content2xml_hash($out_hash, "error", "productId");
142 &main::daemon_log("$session_id ERROR: no productId specified or procutId tag invalid: $msg", 1);
143 }
145 # All parameter available
146 if (not $error) {
147 # Get hostId
148 $hostId = @{$msg_hash->{'hostId'}}[0];
149 &add_content2xml_hash($out_hash, "hostId", $hostId);
151 # Get productID
152 $productId = @{$msg_hash->{'productId'}}[0];
153 &add_content2xml_hash($out_hash, "productId", $productId);
156 #TODO : check the results for more than one entry which is currently installed
157 #$callobj = {
158 # method => 'getProductDependencies_listOfHashes',
159 # params => [ $productId ],
160 # id => 1, };
161 #
162 #my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
163 #my ($sres_err, $sres_err_string) = &check_opsi_res($sres);
164 #if ($sres_err){
165 # &main::daemon_log("ERROR: cannot perform dependency check: ".$sres_err_string, 1);
166 # &add_content2xml_hash($out_hash, "error", $sres_err_string);
167 # return ( &create_xml_string($out_hash) );
168 #}
171 # Check to get product action list
172 my $callobj = {
173 method => 'getPossibleProductActions_list',
174 params => [ $productId ],
175 id => 1, };
176 $sres = $main::opsi_client->call($main::opsi_url, $callobj);
177 ($sres_err, $sres_err_string) = &check_opsi_res($sres);
178 if ($sres_err){
179 &main::daemon_log("$session_id ERROR: cannot get product action list: ".$sres_err_string, 1);
180 &add_content2xml_hash($out_hash, "error", $sres_err_string);
181 $error++;
182 }
183 }
185 # Check action uninstall of product
186 if (not $error) {
187 my $uninst_possible= 0;
188 foreach my $r (@{$sres->result}) {
189 if ($r eq 'uninstall') {
190 $uninst_possible= 1;
191 }
192 }
193 if (!$uninst_possible){
194 &main::daemon_log("$session_id ERROR: cannot uninstall product '$productId', product do not has the action 'uninstall'", 1);
195 &add_content2xml_hash($out_hash, "error", "cannot uninstall product '$productId', product do not has the action 'uninstall'");
196 $error++;
197 }
198 }
200 # Set product state to "none"
201 # Do an action request for all these -> "setup".
202 if (not $error) {
203 my $callobj = {
204 method => 'setProductActionRequest',
205 params => [ $productId, $hostId, "none" ],
206 id => 1,
207 };
208 $sres = $main::opsi_client->call($main::opsi_url, $callobj);
209 ($sres_err, $sres_err_string) = &check_opsi_res($sres);
210 if ($sres_err){
211 &main::daemon_log("$session_id ERROR: cannot delete product: ".$sres_err_string, 1);
212 &add_content2xml_hash($out_hash, "error", $sres_err_string);
213 }
214 }
216 # Return message
217 return ( &create_xml_string($out_hash) );
218 }
220 ## @method opsi_add_client
221 # Adds an Opsi client to Opsi.
222 # @param msg - STRING - xml message with tags hostId and macaddress
223 # @param msg_hash - HASHREF - message information parsed into a hash
224 # @param session_id - INTEGER - POE session id of the processing of this message
225 # @return out_msg - STRING - feedback to GOsa in success and error case
226 sub opsi_add_client {
227 my ($msg, $msg_hash, $session_id) = @_;
228 my $header = @{$msg_hash->{'header'}}[0];
229 my $source = @{$msg_hash->{'source'}}[0];
230 my $target = @{$msg_hash->{'target'}}[0];
231 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
232 my ($hostId, $mac);
233 my $error = 0;
234 my ($sres, $sres_err, $sres_err_string);
236 # Build return message with twisted target and source
237 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
238 if (defined $forward_to_gosa) {
239 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
240 }
242 # Sanity check of needed parameter
243 if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
244 $error++;
245 &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
246 &add_content2xml_hash($out_hash, "error", "hostId");
247 &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1);
248 }
249 if ((not exists $msg_hash->{'macaddress'}) || (@{$msg_hash->{'macaddress'}} != 1) || (@{$msg_hash->{'macaddress'}}[0] eq ref 'HASH')) {
250 $error++;
251 &add_content2xml_hash($out_hash, "error_string", "no macaddress specified or macaddress tag invalid");
252 &add_content2xml_hash($out_hash, "error", "macaddress");
253 &main::daemon_log("$session_id ERROR: no macaddress specified or macaddress tag invalid: $msg", 1);
254 }
256 if (not $error) {
257 # Get hostId
258 $hostId = @{$msg_hash->{'hostId'}}[0];
259 &add_content2xml_hash($out_hash, "hostId", $hostId);
261 # Get macaddress
262 $mac = @{$msg_hash->{'macaddress'}}[0];
263 &add_content2xml_hash($out_hash, "macaddress", $mac);
265 my $name= $hostId;
266 $name=~ s/^([^.]+).*$/$1/;
267 my $domain= $hostId;
268 $domain=~ s/^[^.]+\.(.*)$/$1/;
269 my ($description, $notes, $ip);
271 if (defined @{$msg_hash->{'description'}}[0]){
272 $description = @{$msg_hash->{'description'}}[0];
273 }
274 if (defined @{$msg_hash->{'notes'}}[0]){
275 $notes = @{$msg_hash->{'notes'}}[0];
276 }
277 if (defined @{$msg_hash->{'ip'}}[0]){
278 $ip = @{$msg_hash->{'ip'}}[0];
279 }
281 my $callobj;
282 $callobj = {
283 method => 'createClient',
284 params => [ $name, $domain, $description, $notes, $ip, $mac ],
285 id => 1,
286 };
288 $sres = $main::opsi_client->call($main::opsi_url, $callobj);
289 ($sres_err, $sres_err_string) = &check_opsi_res($sres);
290 if ($sres_err){
291 &main::daemon_log("$session_id ERROR: cannot create client: ".$sres_err_string, 1);
292 &add_content2xml_hash($out_hash, "error", $sres_err_string);
293 } else {
294 &main::daemon_log("$session_id INFO: add opsi client '$hostId' with mac '$mac'", 5);
295 }
296 }
298 # Return message
299 return ( &create_xml_string($out_hash) );
300 }
302 ## @method opsi_modify_client
303 # Modifies the parameters description, mac or notes for an Opsi client if the corresponding message tags are given.
304 # @param msg - STRING - xml message with tag hostId and optional description, mac or notes
305 # @param msg_hash - HASHREF - message information parsed into a hash
306 # @param session_id - INTEGER - POE session id of the processing of this message
307 # @return out_msg - STRING - feedback to GOsa in success and error case
308 sub opsi_modify_client {
309 my ($msg, $msg_hash, $session_id) = @_;
310 my $header = @{$msg_hash->{'header'}}[0];
311 my $source = @{$msg_hash->{'source'}}[0];
312 my $target = @{$msg_hash->{'target'}}[0];
313 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
314 my $hostId;
315 my $error = 0;
316 my ($sres, $sres_err, $sres_err_string);
318 # Build return message with twisted target and source
319 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
320 if (defined $forward_to_gosa) {
321 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
322 }
324 # Sanity check of needed parameter
325 if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
326 $error++;
327 &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
328 &add_content2xml_hash($out_hash, "error", "hostId");
329 &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1);
330 }
332 if (not $error) {
333 # Get hostId
334 $hostId = @{$msg_hash->{'hostId'}}[0];
335 &add_content2xml_hash($out_hash, "hostId", $hostId);
336 my $name= $hostId;
337 $name=~ s/^([^.]+).*$/$1/;
338 my $domain= $hostId;
339 $domain=~ s/^[^.]+(.*)$/$1/;
341 # Modify description, notes or mac if defined
342 my ($description, $notes, $mac);
343 my $callobj;
344 if ((exists $msg_hash->{'description'}) && (@{$msg_hash->{'description'}} == 1) ){
345 $description = @{$msg_hash->{'description'}}[0];
346 $callobj = {
347 method => 'setHostDescription',
348 params => [ $hostId, $description ],
349 id => 1,
350 };
351 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
352 my ($sres_err, $sres_err_string) = &check_opsi_res($sres);
353 if ($sres_err){
354 &main::daemon_log("ERROR: cannot set description: ".$sres_err_string, 1);
355 &add_content2xml_hash($out_hash, "error", $sres_err_string);
356 }
357 }
358 if ((exists $msg_hash->{'notes'}) && (@{$msg_hash->{'notes'}} == 1)) {
359 $notes = @{$msg_hash->{'notes'}}[0];
360 $callobj = {
361 method => 'setHostNotes',
362 params => [ $hostId, $notes ],
363 id => 1,
364 };
365 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
366 my ($sres_err, $sres_err_string) = &check_opsi_res($sres);
367 if ($sres_err){
368 &main::daemon_log("ERROR: cannot set notes: ".$sres_err_string, 1);
369 &add_content2xml_hash($out_hash, "error", $sres_err_string);
370 }
371 }
372 if ((exists $msg_hash->{'mac'}) && (@{$msg_hash->{'mac'}} == 1)){
373 $mac = @{$msg_hash->{'mac'}}[0];
374 $callobj = {
375 method => 'setMacAddress',
376 params => [ $hostId, $mac ],
377 id => 1,
378 };
379 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
380 my ($sres_err, $sres_err_string) = &check_opsi_res($sres);
381 if ($sres_err){
382 &main::daemon_log("ERROR: cannot set mac address: ".$sres_err_string, 1);
383 &add_content2xml_hash($out_hash, "error", $sres_err_string);
384 }
385 }
386 }
388 # Return message
389 return ( &create_xml_string($out_hash) );
390 }
393 ## @method opsi_get_netboot_products
394 # Get netboot products for specific host.
395 # @param msg - STRING - xml message with tag hostId
396 # @param msg_hash - HASHREF - message information parsed into a hash
397 # @param session_id - INTEGER - POE session id of the processing of this message
398 # @return out_msg - STRING - feedback to GOsa in success and error case
399 sub opsi_get_netboot_products {
400 my ($msg, $msg_hash, $session_id) = @_;
401 my $header = @{$msg_hash->{'header'}}[0];
402 my $source = @{$msg_hash->{'source'}}[0];
403 my $target = @{$msg_hash->{'target'}}[0];
404 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
405 my $hostId;
406 my $xml_msg;
408 # Build return message with twisted target and source
409 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
410 if (defined $forward_to_gosa) {
411 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
412 }
414 # Get hostId if defined
415 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} == 1)) {
416 $hostId = @{$msg_hash->{'hostId'}}[0];
417 &add_content2xml_hash($out_hash, "hostId", $hostId);
418 }
420 &add_content2xml_hash($out_hash, "xxx", "");
421 $xml_msg= &create_xml_string($out_hash);
423 # For hosts, only return the products that are or get installed
424 my $callobj;
425 $callobj = {
426 method => 'getNetBootProductIds_list',
427 params => [ ],
428 id => 1,
429 };
431 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
432 my %r = ();
433 for (@{$res->result}) { $r{$_} = 1 }
435 if (not &check_opsi_res($res)){
437 if (defined $hostId){
438 $callobj = {
439 method => 'getProductStates_hash',
440 params => [ $hostId ],
441 id => 1,
442 };
444 my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
445 if (not &check_opsi_res($hres)){
446 my $htmp= $hres->result->{$hostId};
448 # check state != not_installed or action == setup -> load and add
449 foreach my $product (@{$htmp}){
451 if (!defined ($r{$product->{'productId'}})){
452 next;
453 }
455 # Now we've a couple of hashes...
456 if ($product->{'installationStatus'} ne "not_installed" or
457 $product->{'actionRequest'} eq "setup"){
458 my $state= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
460 $callobj = {
461 method => 'getProduct_hash',
462 params => [ $product->{'productId'} ],
463 id => 1,
464 };
466 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
467 if (not &check_opsi_res($sres)){
468 my $tres= $sres->result;
470 my $name= xml_quote($tres->{'name'});
471 my $r= $product->{'productId'};
472 my $description= xml_quote($tres->{'description'});
473 $name=~ s/\//\\\//;
474 $description=~ s/\//\\\//;
475 $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
476 }
477 }
478 }
480 }
482 } else {
483 foreach my $r (@{$res->result}) {
484 $callobj = {
485 method => 'getProduct_hash',
486 params => [ $r ],
487 id => 1,
488 };
490 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
491 if (not &check_opsi_res($sres)){
492 my $tres= $sres->result;
494 my $name= xml_quote($tres->{'name'});
495 my $description= xml_quote($tres->{'description'});
496 $name=~ s/\//\\\//;
497 $description=~ s/\//\\\//;
498 $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
499 }
500 }
502 }
503 }
504 $xml_msg=~ s/<xxx><\/xxx>//;
506 # Return message
507 return ( $xml_msg );
508 }
511 ## @method opsi_get_product_properties
512 # Get product properties for a product and a specific host or gobally for a product.
513 # @param msg - STRING - xml message with tags productId and optional hostId
514 # @param msg_hash - HASHREF - message information parsed into a hash
515 # @param session_id - INTEGER - POE session id of the processing of this message
516 # @return out_msg - STRING - feedback to GOsa in success and error case
517 sub opsi_get_product_properties {
518 my ($msg, $msg_hash, $session_id) = @_;
519 my $header = @{$msg_hash->{'header'}}[0];
520 my $source = @{$msg_hash->{'source'}}[0];
521 my $target = @{$msg_hash->{'target'}}[0];
522 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
523 my ($hostId, $productId);
524 my $xml_msg;
526 # Build return message with twisted target and source
527 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
528 if (defined $forward_to_gosa) {
529 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
530 }
532 # Sanity check of needed parameter
533 if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1) || (@{$msg_hash->{'productId'}}[0] eq ref 'HASH')) {
534 &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
535 &add_content2xml_hash($out_hash, "error", "productId");
536 &main::daemon_log("$session_id ERROR: no productId specified or productId tag invalid: $msg", 1);
538 # Return message
539 return ( &create_xml_string($out_hash) );
540 }
542 # Get productid
543 $productId = @{$msg_hash->{'productId'}}[0];
544 &add_content2xml_hash($out_hash, "producId", "$productId");
546 # Get hostId if defined
547 if (defined @{$msg_hash->{'hostId'}}[0]){
548 $hostId = @{$msg_hash->{'hostId'}}[0];
549 &add_content2xml_hash($out_hash, "hostId", $hostId);
550 }
552 # Load actions
553 my $callobj = {
554 method => 'getPossibleProductActions_list',
555 params => [ $productId ],
556 id => 1,
557 };
558 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
559 if (not &check_opsi_res($res)){
560 foreach my $action (@{$res->result}){
561 &add_content2xml_hash($out_hash, "action", $action);
562 }
563 }
565 # Add place holder
566 &add_content2xml_hash($out_hash, "xxx", "");
568 # Move to XML string
569 $xml_msg= &create_xml_string($out_hash);
571 # JSON Query
572 if (defined $hostId){
573 $callobj = {
574 method => 'getProductProperties_hash',
575 params => [ $productId, $hostId ],
576 id => 1,
577 };
578 } else {
579 $callobj = {
580 method => 'getProductProperties_hash',
581 params => [ $productId ],
582 id => 1,
583 };
584 }
585 $res = $main::opsi_client->call($main::opsi_url, $callobj);
587 # JSON Query 2
588 $callobj = {
589 method => 'getProductPropertyDefinitions_listOfHashes',
590 params => [ $productId ],
591 id => 1,
592 };
594 # Assemble options
595 my $res2 = $main::opsi_client->call($main::opsi_url, $callobj);
596 my $values = {};
597 my $descriptions = {};
598 if (not &check_opsi_res($res2)){
599 my $r= $res2->result;
601 foreach my $entr (@$r){
602 # Unroll values
603 my $cnv;
604 if (UNIVERSAL::isa( $entr->{'values'}, "ARRAY" )){
605 foreach my $v (@{$entr->{'values'}}){
606 $cnv.= "<value>$v</value>";
607 }
608 } else {
609 $cnv= $entr->{'values'};
610 }
611 $values->{$entr->{'name'}}= $cnv;
612 $descriptions->{$entr->{'name'}}= "<description>".$entr->{'description'}."</description>";
613 }
614 }
616 if (not &check_opsi_res($res)){
617 my $r= $res->result;
618 foreach my $key (keys %{$r}) {
619 my $item= "\n<item>";
620 my $value= $r->{$key};
621 my $dsc= "";
622 my $vals= "";
623 if (defined $descriptions->{$key}){
624 $dsc= $descriptions->{$key};
625 }
626 if (defined $values->{$key}){
627 $vals= $values->{$key};
628 }
629 $item.= "<$key>$dsc<default>".xml_quote($value)."</default>$vals</$key>";
630 $item.= "</item>";
631 $xml_msg=~ s/<xxx><\/xxx>/$item<xxx><\/xxx>/;
632 }
633 }
635 $xml_msg=~ s/<xxx><\/xxx>//;
637 # Return message
638 return ( $xml_msg );
639 }
642 ## @method opsi_set_product_properties
643 # Set product properities for a specific host or globaly. Message needs one xml tag 'item' and within one xml tag 'name' and 'value'. The xml tags action and state are optional.
644 # @param msg - STRING - xml message with tags productId, action, state and optional hostId, action and state
645 # @param msg_hash - HASHREF - message information parsed into a hash
646 # @param session_id - INTEGER - POE session id of the processing of this message
647 # @return out_msg - STRING - feedback to GOsa in success and error case
648 sub opsi_set_product_properties {
649 my ($msg, $msg_hash, $session_id) = @_;
650 my $header = @{$msg_hash->{'header'}}[0];
651 my $source = @{$msg_hash->{'source'}}[0];
652 my $target = @{$msg_hash->{'target'}}[0];
653 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
654 my ($productId, $hostId);
656 # Build return message with twisted target and source
657 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
658 if (defined $forward_to_gosa) {
659 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
660 }
662 # Sanity check of needed parameter
663 if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1) || (@{$msg_hash->{'productId'}}[0] eq ref 'HASH')) {
664 &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
665 &add_content2xml_hash($out_hash, "error", "productId");
666 &main::daemon_log("$session_id ERROR: no productId specified or productId tag invalid: $msg", 1);
667 return ( &create_xml_string($out_hash) );
668 }
669 if (not exists $msg_hash->{'item'}) {
670 &add_content2xml_hash($out_hash, "error_string", "message needs one xml-tag 'item' and within the xml-tags 'name' and 'value'");
671 &add_content2xml_hash($out_hash, "error", "item");
672 &main::daemon_log("$session_id ERROR: message needs one xml-tag 'item' and within the xml-tags 'name' and 'value': $msg", 1);
673 return ( &create_xml_string($out_hash) );
674 } else {
675 if ((not exists @{$msg_hash->{'item'}}[0]->{'name'}) || (@{@{$msg_hash->{'item'}}[0]->{'name'}} != 1 )) {
676 &add_content2xml_hash($out_hash, "error_string", "message needs within the xml-tag 'item' one xml-tags 'name'");
677 &add_content2xml_hash($out_hash, "error", "name");
678 &main::daemon_log("$session_id ERROR: message needs within the xml-tag 'item' one xml-tags 'name': $msg", 1);
679 return ( &create_xml_string($out_hash) );
680 }
681 if ((not exists @{$msg_hash->{'item'}}[0]->{'value'}) || (@{@{$msg_hash->{'item'}}[0]->{'value'}} != 1 )) {
682 &add_content2xml_hash($out_hash, "error_string", "message needs within the xml-tag 'item' one xml-tags 'value'");
683 &add_content2xml_hash($out_hash, "error", "value");
684 &main::daemon_log("$session_id ERROR: message needs within the xml-tag 'item' one xml-tags 'value': $msg", 1);
685 return ( &create_xml_string($out_hash) );
686 }
687 }
688 # if no hostId is given, set_product_properties will act on globally
689 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} > 1)) {
690 &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
691 &add_content2xml_hash($out_hash, "error", "hostId");
692 &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1);
693 return ( &create_xml_string($out_hash) );
694 }
697 # Get productId
698 $productId = @{$msg_hash->{'productId'}}[0];
699 &add_content2xml_hash($out_hash, "productId", $productId);
701 # Get hostId if defined
702 if (exists $msg_hash->{'hostId'}){
703 $hostId = @{$msg_hash->{'hostId'}}[0];
704 &add_content2xml_hash($out_hash, "hostId", $hostId);
705 }
707 # Set product states if requested
708 if (defined @{$msg_hash->{'action'}}[0]){
709 &_set_action($productId, @{$msg_hash->{'action'}}[0], $hostId);
710 }
711 if (defined @{$msg_hash->{'state'}}[0]){
712 &_set_state($productId, @{$msg_hash->{'state'}}[0], $hostId);
713 }
715 # Find properties
716 foreach my $item (@{$msg_hash->{'item'}}){
717 # JSON Query
718 my $callobj;
720 if (defined $hostId){
721 $callobj = {
722 method => 'setProductProperty',
723 params => [ $productId, $item->{'name'}[0], $item->{'value'}[0], $hostId ],
724 id => 1,
725 };
726 } else {
727 $callobj = {
728 method => 'setProductProperty',
729 params => [ $productId, $item->{'name'}[0], $item->{'value'}[0] ],
730 id => 1,
731 };
732 }
734 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
735 my ($res_err, $res_err_string) = &check_opsi_res($res);
737 if ($res_err){
738 &main::daemon_log("$session_id ERROR: communication failed while setting '".$item->{'name'}[0]."': ".$res_err_string, 1);
739 &add_content2xml_hash($out_hash, "error", $res_err_string);
740 }
741 }
744 # Return message
745 return ( &create_xml_string($out_hash) );
746 }
749 ## @method opsi_get_client_hardware
750 # Reports client hardware inventory.
751 # @param msg - STRING - xml message with tag hostId
752 # @param msg_hash - HASHREF - message information parsed into a hash
753 # @param session_id - INTEGER - POE session id of the processing of this message
754 # @return out_msg - STRING - feedback to GOsa in success and error case
755 sub opsi_get_client_hardware {
756 my ($msg, $msg_hash, $session_id) = @_;
757 my $header = @{$msg_hash->{'header'}}[0];
758 my $source = @{$msg_hash->{'source'}}[0];
759 my $target = @{$msg_hash->{'target'}}[0];
760 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
761 my $hostId;
762 my $error = 0;
763 my $xml_msg;
765 # Build return message with twisted target and source
766 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
767 if (defined $forward_to_gosa) {
768 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
769 }
771 # Sanity check of needed parameter
772 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
773 $error++;
774 &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
775 &add_content2xml_hash($out_hash, "error", "hostId");
776 &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1);
777 }
779 if (not $error) {
781 # Get hostId
782 $hostId = @{$msg_hash->{'hostId'}}[0];
783 &add_content2xml_hash($out_hash, "hostId", "$hostId");
784 &add_content2xml_hash($out_hash, "xxx", "");
785 }
787 # Move to XML string
788 $xml_msg= &create_xml_string($out_hash);
790 if (not $error) {
792 # JSON Query
793 my $callobj = {
794 method => 'getHardwareInformation_hash',
795 params => [ $hostId ],
796 id => 1,
797 };
799 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
800 if (not &check_opsi_res($res)){
801 my $result= $res->result;
802 if (ref $result eq "HASH") {
803 foreach my $r (keys %{$result}){
804 my $item= "\n<item><id>".xml_quote($r)."</id>";
805 my $value= $result->{$r};
806 foreach my $sres (@{$value}){
808 foreach my $dres (keys %{$sres}){
809 if (defined $sres->{$dres}){
810 $item.= "<$dres>".xml_quote($sres->{$dres})."</$dres>";
811 }
812 }
814 }
815 $item.= "</item>";
816 $xml_msg=~ s%<xxx></xxx>%$item<xxx></xxx>%;
818 }
819 }
820 }
822 $xml_msg=~ s/<xxx><\/xxx>//;
824 }
826 # Return message
827 return ( $xml_msg );
828 }
831 ## @method opsi_list_clients
832 # Reports all Opsi clients.
833 # @param msg - STRING - xml message
834 # @param msg_hash - HASHREF - message information parsed into a hash
835 # @param session_id - INTEGER - POE session id of the processing of this message
836 # @return out_msg - STRING - feedback to GOsa in success and error case
837 sub opsi_list_clients {
838 my ($msg, $msg_hash, $session_id) = @_;
839 my $header = @{$msg_hash->{'header'}}[0];
840 my $source = @{$msg_hash->{'source'}}[0];
841 my $target = @{$msg_hash->{'target'}}[0];
842 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
844 # Build return message with twisted target and source
845 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
846 if (defined $forward_to_gosa) {
847 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
848 }
849 &add_content2xml_hash($out_hash, "xxx", "");
851 # Move to XML string
852 my $xml_msg= &create_xml_string($out_hash);
854 # JSON Query
855 my $callobj = {
856 method => 'getClients_listOfHashes',
857 params => [ ],
858 id => 1,
859 };
860 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
861 if (not &check_opsi_res($res)){
862 foreach my $host (@{$res->result}){
863 my $item= "\n<item><name>".$host->{'hostId'}."</name>";
864 if (defined($host->{'description'})){
865 $item.= "<description>".xml_quote($host->{'description'})."</description>";
866 }
867 if (defined($host->{'notes'})){
868 $item.= "<notes>".xml_quote($host->{'notes'})."</notes>";
869 }
870 if (defined($host->{'lastSeen'})){
871 $item.= "<lastSeen>".xml_quote($host->{'lastSeen'})."</lastSeen>";
872 }
874 $callobj = {
875 method => 'getIpAddress',
876 params => [ $host->{'hostId'} ],
877 id => 1,
878 };
879 my $sres= $main::opsi_client->call($main::opsi_url, $callobj);
880 if ( not &check_opsi_res($sres)){
881 $item.= "<ip>".xml_quote($sres->result)."</ip>";
882 }
884 $callobj = {
885 method => 'getMacAddress',
886 params => [ $host->{'hostId'} ],
887 id => 1,
888 };
889 $sres= $main::opsi_client->call($main::opsi_url, $callobj);
890 if ( not &check_opsi_res($sres)){
891 $item.= "<mac>".xml_quote($sres->result)."</mac>";
892 }
893 $item.= "</item>";
894 $xml_msg=~ s%<xxx></xxx>%$item<xxx></xxx>%;
895 }
896 }
898 $xml_msg=~ s/<xxx><\/xxx>//;
899 return ( $xml_msg );
900 }
904 ## @method opsi_get_client_software
905 # Reports client software inventory.
906 # @param msg - STRING - xml message with tag hostId
907 # @param msg_hash - HASHREF - message information parsed into a hash
908 # @param session_id - INTEGER - POE session id of the processing of this message
909 # @return out_msg - STRING - feedback to GOsa in success and error case
910 sub opsi_get_client_software {
911 my ($msg, $msg_hash, $session_id) = @_;
912 my $header = @{$msg_hash->{'header'}}[0];
913 my $source = @{$msg_hash->{'source'}}[0];
914 my $target = @{$msg_hash->{'target'}}[0];
915 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
916 my $error = 0;
917 my $hostId;
918 my $xml_msg;
920 # Build return message with twisted target and source
921 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
922 if (defined $forward_to_gosa) {
923 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
924 }
926 # Sanity check of needed parameter
927 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
928 $error++;
929 &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
930 &add_content2xml_hash($out_hash, "error", "hostId");
931 &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1);
932 }
934 if (not $error) {
936 # Get hostId
937 $hostId = @{$msg_hash->{'hostId'}}[0];
938 &add_content2xml_hash($out_hash, "hostId", "$hostId");
939 &add_content2xml_hash($out_hash, "xxx", "");
940 }
942 $xml_msg= &create_xml_string($out_hash);
944 if (not $error) {
946 # JSON Query
947 my $callobj = {
948 method => 'getSoftwareInformation_hash',
949 params => [ $hostId ],
950 id => 1,
951 };
953 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
954 if (not &check_opsi_res($res)){
955 my $result= $res->result;
956 # TODO : Ist das hier schon fertig???
957 }
959 $xml_msg=~ s/<xxx><\/xxx>//;
961 }
963 # Return message
964 return ( $xml_msg );
965 }
968 ## @method opsi_get_local_products
969 # Reports product for given hostId or globally.
970 # @param msg - STRING - xml message with optional tag hostId
971 # @param msg_hash - HASHREF - message information parsed into a hash
972 # @param session_id - INTEGER - POE session id of the processing of this message
973 # @return out_msg - STRING - feedback to GOsa in success and error case
974 sub opsi_get_local_products {
975 my ($msg, $msg_hash, $session_id) = @_;
976 my $header = @{$msg_hash->{'header'}}[0];
977 my $source = @{$msg_hash->{'source'}}[0];
978 my $target = @{$msg_hash->{'target'}}[0];
979 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
980 my $hostId;
982 # Build return message with twisted target and source
983 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
984 if (defined $forward_to_gosa) {
985 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
986 }
987 &add_content2xml_hash($out_hash, "xxx", "");
989 # Get hostId if defined
990 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} == 1)) {
991 $hostId = @{$msg_hash->{'hostId'}}[0];
992 &add_content2xml_hash($out_hash, "hostId", $hostId);
993 }
995 # Move to XML string
996 my $xml_msg= &create_xml_string($out_hash);
998 # For hosts, only return the products that are or get installed
999 my $callobj;
1000 $callobj = {
1001 method => 'getLocalBootProductIds_list',
1002 params => [ ],
1003 id => 1,
1004 };
1006 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
1007 my %r = ();
1008 for (@{$res->result}) { $r{$_} = 1 }
1010 if (not &check_opsi_res($res)){
1012 if (defined $hostId){
1013 $callobj = {
1014 method => 'getProductStates_hash',
1015 params => [ $hostId ],
1016 id => 1,
1017 };
1019 my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
1020 if (not &check_opsi_res($hres)){
1021 my $htmp= $hres->result->{$hostId};
1023 # Check state != not_installed or action == setup -> load and add
1024 foreach my $product (@{$htmp}){
1026 if (!defined ($r{$product->{'productId'}})){
1027 next;
1028 }
1030 # Now we've a couple of hashes...
1031 if ($product->{'installationStatus'} ne "not_installed" or
1032 $product->{'actionRequest'} eq "setup"){
1033 my $state= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
1035 $callobj = {
1036 method => 'getProduct_hash',
1037 params => [ $product->{'productId'} ],
1038 id => 1,
1039 };
1041 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
1042 if (not &check_opsi_res($sres)){
1043 my $tres= $sres->result;
1045 my $name= xml_quote($tres->{'name'});
1046 my $r= $product->{'productId'};
1047 my $description= xml_quote($tres->{'description'});
1048 $name=~ s/\//\\\//;
1049 $description=~ s/\//\\\//;
1050 $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
1051 }
1053 }
1054 }
1056 }
1058 } else {
1059 foreach my $r (@{$res->result}) {
1060 $callobj = {
1061 method => 'getProduct_hash',
1062 params => [ $r ],
1063 id => 1,
1064 };
1066 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
1067 if (not &check_opsi_res($sres)){
1068 my $tres= $sres->result;
1070 my $name= xml_quote($tres->{'name'});
1071 my $description= xml_quote($tres->{'description'});
1072 $name=~ s/\//\\\//;
1073 $description=~ s/\//\\\//;
1074 $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
1075 }
1077 }
1079 }
1080 }
1082 $xml_msg=~ s/<xxx><\/xxx>//;
1084 # Retrun Message
1085 return ( $xml_msg );
1086 }
1089 ## @method opsi_del_client
1090 # Deletes a client from Opsi.
1091 # @param msg - STRING - xml message with tag hostId
1092 # @param msg_hash - HASHREF - message information parsed into a hash
1093 # @param session_id - INTEGER - POE session id of the processing of this message
1094 # @return out_msg - STRING - feedback to GOsa in success and error case
1095 sub opsi_del_client {
1096 my ($msg, $msg_hash, $session_id) = @_;
1097 my $header = @{$msg_hash->{'header'}}[0];
1098 my $source = @{$msg_hash->{'source'}}[0];
1099 my $target = @{$msg_hash->{'target'}}[0];
1100 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
1101 my $hostId;
1102 my $error = 0;
1104 # Build return message with twisted target and source
1105 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
1106 if (defined $forward_to_gosa) {
1107 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
1108 }
1110 # Sanity check of needed parameter
1111 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
1112 $error++;
1113 &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
1114 &add_content2xml_hash($out_hash, "error", "hostId");
1115 &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1);
1116 }
1118 if (not $error) {
1120 # Get hostId
1121 $hostId = @{$msg_hash->{'hostId'}}[0];
1122 &add_content2xml_hash($out_hash, "hostId", "$hostId");
1124 # JSON Query
1125 my $callobj = {
1126 method => 'deleteClient',
1127 params => [ $hostId ],
1128 id => 1,
1129 };
1130 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
1131 }
1133 # Move to XML string
1134 my $xml_msg= &create_xml_string($out_hash);
1136 # Return message
1137 return ( $xml_msg );
1138 }
1141 ## @method opsi_install_client
1142 # Set a client in Opsi to install and trigger a wake on lan message (WOL).
1143 # @param msg - STRING - xml message with tags hostId, macaddress
1144 # @param msg_hash - HASHREF - message information parsed into a hash
1145 # @param session_id - INTEGER - POE session id of the processing of this message
1146 # @return out_msg - STRING - feedback to GOsa in success and error case
1147 sub opsi_install_client {
1148 my ($msg, $msg_hash, $session_id) = @_;
1149 my $header = @{$msg_hash->{'header'}}[0];
1150 my $source = @{$msg_hash->{'source'}}[0];
1151 my $target = @{$msg_hash->{'target'}}[0];
1152 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
1155 my ($hostId, $macaddress);
1157 my $error = 0;
1158 my @out_msg_l;
1160 # Build return message with twisted target and source
1161 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
1162 if (defined $forward_to_gosa) {
1163 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
1164 }
1166 # Sanity check of needed parameter
1167 if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
1168 $error++;
1169 &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
1170 &add_content2xml_hash($out_hash, "error", "hostId");
1171 &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1);
1172 }
1173 if ((not exists $msg_hash->{'macaddress'}) || (@{$msg_hash->{'macaddress'}} != 1) || (@{$msg_hash->{'macaddress'}}[0] eq ref 'HASH') ) {
1174 $error++;
1175 &add_content2xml_hash($out_hash, "error_string", "no macaddress specified or macaddress tag invalid");
1176 &add_content2xml_hash($out_hash, "error", "macaddress");
1177 &main::daemon_log("$session_id ERROR: no macaddress specified or macaddress tag invalid: $msg", 1);
1178 } else {
1179 if ((exists $msg_hash->{'macaddress'}) &&
1180 ($msg_hash->{'macaddress'}[0] =~ /^([0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2}:[0-9a-f]{2})$/i)) {
1181 $macaddress = $1;
1182 } else {
1183 $error ++;
1184 &add_content2xml_hash($out_hash, "error_string", "given mac address is not correct");
1185 &add_content2xml_hash($out_hash, "error", "macaddress");
1186 &main::daemon_log("$session_id ERROR: given mac address is not correct: $msg", 1);
1187 }
1188 }
1190 if (not $error) {
1192 # Get hostId
1193 $hostId = @{$msg_hash->{'hostId'}}[0];
1194 &add_content2xml_hash($out_hash, "hostId", "$hostId");
1196 # Load all products for this host with status != "not_installed" or actionRequest != "none"
1197 my $callobj = {
1198 method => 'getProductStates_hash',
1199 params => [ $hostId ],
1200 id => 1,
1201 };
1203 my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
1204 if (not &check_opsi_res($hres)){
1205 my $htmp= $hres->result->{$hostId};
1207 # check state != not_installed or action == setup -> load and add
1208 foreach my $product (@{$htmp}){
1209 # Now we've a couple of hashes...
1210 if ($product->{'installationStatus'} ne "not_installed" or
1211 $product->{'actionRequest'} ne "none"){
1213 # Do an action request for all these -> "setup".
1214 $callobj = {
1215 method => 'setProductActionRequest',
1216 params => [ $product->{'productId'}, $hostId, "setup" ],
1217 id => 1,
1218 };
1219 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
1220 my ($res_err, $res_err_string) = &check_opsi_res($res);
1221 if ($res_err){
1222 &main::daemon_log("$session_id ERROR: cannot set product action request for '$hostId': ".$product->{'productId'}, 1);
1223 } else {
1224 &main::daemon_log("$session_id INFO: requesting 'setup' for '".$product->{'productId'}."' on $hostId", 1);
1225 }
1226 }
1227 }
1228 }
1229 push(@out_msg_l, &create_xml_string($out_hash));
1232 # Build wakeup message for client
1233 if (not $error) {
1234 my $wakeup_hash = &create_xml_hash("trigger_wake", "GOSA", "KNOWN_SERVER");
1235 &add_content2xml_hash($wakeup_hash, 'macAddress', $macaddress);
1236 my $wakeup_msg = &create_xml_string($wakeup_hash);
1237 push(@out_msg_l, $wakeup_msg);
1239 # invoke trigger wake for this gosa-si-server
1240 &main::server_server_com::trigger_wake($wakeup_msg, $wakeup_hash, $session_id);
1241 }
1242 }
1244 # Return messages
1245 return @out_msg_l;
1246 }
1249 ## @method _set_action
1250 # Set action for an Opsi client
1251 # @param product - STRING - Opsi product
1252 # @param action - STRING - action
1253 # @param hostId - STRING - Opsi hostId
1254 sub _set_action {
1255 my $product= shift;
1256 my $action = shift;
1257 my $hostId = shift;
1258 my $callobj;
1260 $callobj = {
1261 method => 'setProductActionRequest',
1262 params => [ $product, $hostId, $action],
1263 id => 1,
1264 };
1266 $main::opsi_client->call($main::opsi_url, $callobj);
1267 }
1269 ## @method _set_state
1270 # Set state for an Opsi client
1271 # @param product - STRING - Opsi product
1272 # @param action - STRING - state
1273 # @param hostId - STRING - Opsi hostId
1274 sub _set_state {
1275 my $product = shift;
1276 my $state = shift;
1277 my $hostId = shift;
1278 my $callobj;
1280 $callobj = {
1281 method => 'setProductState',
1282 params => [ $product, $hostId, $state ],
1283 id => 1,
1284 };
1286 $main::opsi_client->call($main::opsi_url, $callobj);
1287 }
1289 1;