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 &main::daemon_log("\n================================== 0", 1);
409 # Build return message with twisted target and source
410 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
411 if (defined $forward_to_gosa) {
412 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
413 }
415 # Get hostId if defined
416 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} == 1)) {
417 $hostId = @{$msg_hash->{'hostId'}}[0];
418 &add_content2xml_hash($out_hash, "hostId", $hostId);
419 }
421 &add_content2xml_hash($out_hash, "xxx", "");
422 $xml_msg = &create_xml_string($out_hash);
423 &main::daemon_log("\n================================== 1", 1);
424 # For hosts, only return the products that are or get installed
425 my $callobj;
426 $callobj = {
427 method => 'getNetBootProductIds_list',
428 params => [ ],
429 id => 1,
430 };
432 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
433 my %r = ();
434 for (@{$res->result}) { $r{$_} = 1 }
436 &main::daemon_log("\n================================== 2", 1);
437 if (not &check_opsi_res($res)){
439 if (defined $hostId){
441 &main::daemon_log("\n================================== 3.1", 1);
442 $callobj = {
443 method => 'getProductStates_hash',
444 params => [ $hostId ],
445 id => 1,
446 };
448 my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
449 if (not &check_opsi_res($hres)){
450 my $htmp= $hres->result->{$hostId};
452 # check state != not_installed or action == setup -> load and add
453 foreach my $product (@{$htmp}){
455 if (!defined ($r{$product->{'productId'}})){
456 next;
457 }
459 # Now we've a couple of hashes...
460 if ($product->{'installationStatus'} ne "not_installed" or
461 $product->{'actionRequest'} eq "setup"){
462 my $state= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
464 $callobj = {
465 method => 'getProduct_hash',
466 params => [ $product->{'productId'} ],
467 id => 1,
468 };
470 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
471 if (not &check_opsi_res($sres)){
472 my $tres= $sres->result;
474 my $name= xml_quote($tres->{'name'});
475 my $r= $product->{'productId'};
476 my $description= xml_quote($tres->{'description'});
477 $name=~ s/\//\\\//;
478 $description=~ s/\//\\\//;
479 $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
480 }
481 }
482 }
484 }
486 } else {
487 &main::daemon_log("\n================================== 3.2", 1);
488 foreach my $r (@{$res->result}) {
489 $callobj = {
490 method => 'getProduct_hash',
491 params => [ $r ],
492 id => 1,
493 };
495 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
496 if (not &check_opsi_res($sres)){
497 my $tres= $sres->result;
499 my $name= xml_quote($tres->{'name'});
500 my $description= xml_quote($tres->{'description'});
501 $name=~ s/\//\\\//;
502 $description=~ s/\//\\\//;
503 $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
504 }
505 }
507 }
508 }
509 $xml_msg=~ s/<xxx><\/xxx>//;
511 &main::daemon_log("\n================================== 4", 1);
512 # Return message
513 return ( $xml_msg );
514 }
517 ## @method opsi_get_product_properties
518 # Get product properties for a product and a specific host or gobally for a product.
519 # @param msg - STRING - xml message with tags productId and optional hostId
520 # @param msg_hash - HASHREF - message information parsed into a hash
521 # @param session_id - INTEGER - POE session id of the processing of this message
522 # @return out_msg - STRING - feedback to GOsa in success and error case
523 sub opsi_get_product_properties {
524 my ($msg, $msg_hash, $session_id) = @_;
525 my $header = @{$msg_hash->{'header'}}[0];
526 my $source = @{$msg_hash->{'source'}}[0];
527 my $target = @{$msg_hash->{'target'}}[0];
528 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
529 my ($hostId, $productId);
530 my $xml_msg;
532 # Build return message with twisted target and source
533 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
534 if (defined $forward_to_gosa) {
535 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
536 }
538 # Sanity check of needed parameter
539 if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1) || (@{$msg_hash->{'productId'}}[0] eq ref 'HASH')) {
540 &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
541 &add_content2xml_hash($out_hash, "error", "productId");
542 &main::daemon_log("$session_id ERROR: no productId specified or productId tag invalid: $msg", 1);
544 # Return message
545 return ( &create_xml_string($out_hash) );
546 }
548 # Get productid
549 $productId = @{$msg_hash->{'productId'}}[0];
550 &add_content2xml_hash($out_hash, "producId", "$productId");
552 # Get hostId if defined
553 if (defined @{$msg_hash->{'hostId'}}[0]){
554 $hostId = @{$msg_hash->{'hostId'}}[0];
555 &add_content2xml_hash($out_hash, "hostId", $hostId);
556 }
558 # Load actions
559 my $callobj = {
560 method => 'getPossibleProductActions_list',
561 params => [ $productId ],
562 id => 1,
563 };
564 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
565 if (not &check_opsi_res($res)){
566 foreach my $action (@{$res->result}){
567 &add_content2xml_hash($out_hash, "action", $action);
568 }
569 }
571 # Add place holder
572 &add_content2xml_hash($out_hash, "xxx", "");
574 # Move to XML string
575 $xml_msg= &create_xml_string($out_hash);
577 # JSON Query
578 if (defined $hostId){
579 $callobj = {
580 method => 'getProductProperties_hash',
581 params => [ $productId, $hostId ],
582 id => 1,
583 };
584 } else {
585 $callobj = {
586 method => 'getProductProperties_hash',
587 params => [ $productId ],
588 id => 1,
589 };
590 }
591 $res = $main::opsi_client->call($main::opsi_url, $callobj);
593 # JSON Query 2
594 $callobj = {
595 method => 'getProductPropertyDefinitions_listOfHashes',
596 params => [ $productId ],
597 id => 1,
598 };
600 # Assemble options
601 my $res2 = $main::opsi_client->call($main::opsi_url, $callobj);
602 my $values = {};
603 my $descriptions = {};
604 if (not &check_opsi_res($res2)){
605 my $r= $res2->result;
607 foreach my $entr (@$r){
608 # Unroll values
609 my $cnv;
610 if (UNIVERSAL::isa( $entr->{'values'}, "ARRAY" )){
611 foreach my $v (@{$entr->{'values'}}){
612 $cnv.= "<value>$v</value>";
613 }
614 } else {
615 $cnv= $entr->{'values'};
616 }
617 $values->{$entr->{'name'}}= $cnv;
618 $descriptions->{$entr->{'name'}}= "<description>".$entr->{'description'}."</description>";
619 }
620 }
622 if (not &check_opsi_res($res)){
623 my $r= $res->result;
624 foreach my $key (keys %{$r}) {
625 my $item= "\n<item>";
626 my $value= $r->{$key};
627 my $dsc= "";
628 my $vals= "";
629 if (defined $descriptions->{$key}){
630 $dsc= $descriptions->{$key};
631 }
632 if (defined $values->{$key}){
633 $vals= $values->{$key};
634 }
635 $item.= "<$key>$dsc<default>".xml_quote($value)."</default>$vals</$key>";
636 $item.= "</item>";
637 $xml_msg=~ s/<xxx><\/xxx>/$item<xxx><\/xxx>/;
638 }
639 }
641 $xml_msg=~ s/<xxx><\/xxx>//;
643 # Return message
644 return ( $xml_msg );
645 }
648 ## @method opsi_set_product_properties
649 # 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.
650 # @param msg - STRING - xml message with tags productId, action, state and optional hostId, action and state
651 # @param msg_hash - HASHREF - message information parsed into a hash
652 # @param session_id - INTEGER - POE session id of the processing of this message
653 # @return out_msg - STRING - feedback to GOsa in success and error case
654 sub opsi_set_product_properties {
655 my ($msg, $msg_hash, $session_id) = @_;
656 my $header = @{$msg_hash->{'header'}}[0];
657 my $source = @{$msg_hash->{'source'}}[0];
658 my $target = @{$msg_hash->{'target'}}[0];
659 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
660 my ($productId, $hostId);
662 # Build return message with twisted target and source
663 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
664 if (defined $forward_to_gosa) {
665 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
666 }
668 # Sanity check of needed parameter
669 if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1) || (@{$msg_hash->{'productId'}}[0] eq ref 'HASH')) {
670 &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
671 &add_content2xml_hash($out_hash, "error", "productId");
672 &main::daemon_log("$session_id ERROR: no productId specified or productId tag invalid: $msg", 1);
673 return ( &create_xml_string($out_hash) );
674 }
675 if (not exists $msg_hash->{'item'}) {
676 &add_content2xml_hash($out_hash, "error_string", "message needs one xml-tag 'item' and within the xml-tags 'name' and 'value'");
677 &add_content2xml_hash($out_hash, "error", "item");
678 &main::daemon_log("$session_id ERROR: message needs one xml-tag 'item' and within the xml-tags 'name' and 'value': $msg", 1);
679 return ( &create_xml_string($out_hash) );
680 } else {
681 if ((not exists @{$msg_hash->{'item'}}[0]->{'name'}) || (@{@{$msg_hash->{'item'}}[0]->{'name'}} != 1 )) {
682 &add_content2xml_hash($out_hash, "error_string", "message needs within the xml-tag 'item' one xml-tags 'name'");
683 &add_content2xml_hash($out_hash, "error", "name");
684 &main::daemon_log("$session_id ERROR: message needs within the xml-tag 'item' one xml-tags 'name': $msg", 1);
685 return ( &create_xml_string($out_hash) );
686 }
687 if ((not exists @{$msg_hash->{'item'}}[0]->{'value'}) || (@{@{$msg_hash->{'item'}}[0]->{'value'}} != 1 )) {
688 &add_content2xml_hash($out_hash, "error_string", "message needs within the xml-tag 'item' one xml-tags 'value'");
689 &add_content2xml_hash($out_hash, "error", "value");
690 &main::daemon_log("$session_id ERROR: message needs within the xml-tag 'item' one xml-tags 'value': $msg", 1);
691 return ( &create_xml_string($out_hash) );
692 }
693 }
694 # if no hostId is given, set_product_properties will act on globally
695 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} > 1)) {
696 &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
697 &add_content2xml_hash($out_hash, "error", "hostId");
698 &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1);
699 return ( &create_xml_string($out_hash) );
700 }
703 # Get productId
704 $productId = @{$msg_hash->{'productId'}}[0];
705 &add_content2xml_hash($out_hash, "productId", $productId);
707 # Get hostId if defined
708 if (exists $msg_hash->{'hostId'}){
709 $hostId = @{$msg_hash->{'hostId'}}[0];
710 &add_content2xml_hash($out_hash, "hostId", $hostId);
711 }
713 # Set product states if requested
714 if (defined @{$msg_hash->{'action'}}[0]){
715 &_set_action($productId, @{$msg_hash->{'action'}}[0], $hostId);
716 }
717 if (defined @{$msg_hash->{'state'}}[0]){
718 &_set_state($productId, @{$msg_hash->{'state'}}[0], $hostId);
719 }
721 # Find properties
722 foreach my $item (@{$msg_hash->{'item'}}){
723 # JSON Query
724 my $callobj;
726 if (defined $hostId){
727 $callobj = {
728 method => 'setProductProperty',
729 params => [ $productId, $item->{'name'}[0], $item->{'value'}[0], $hostId ],
730 id => 1,
731 };
732 } else {
733 $callobj = {
734 method => 'setProductProperty',
735 params => [ $productId, $item->{'name'}[0], $item->{'value'}[0] ],
736 id => 1,
737 };
738 }
740 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
741 my ($res_err, $res_err_string) = &check_opsi_res($res);
743 if ($res_err){
744 &main::daemon_log("$session_id ERROR: communication failed while setting '".$item->{'name'}[0]."': ".$res_err_string, 1);
745 &add_content2xml_hash($out_hash, "error", $res_err_string);
746 }
747 }
750 # Return message
751 return ( &create_xml_string($out_hash) );
752 }
755 ## @method opsi_get_client_hardware
756 # Reports client hardware inventory.
757 # @param msg - STRING - xml message with tag hostId
758 # @param msg_hash - HASHREF - message information parsed into a hash
759 # @param session_id - INTEGER - POE session id of the processing of this message
760 # @return out_msg - STRING - feedback to GOsa in success and error case
761 sub opsi_get_client_hardware {
762 my ($msg, $msg_hash, $session_id) = @_;
763 my $header = @{$msg_hash->{'header'}}[0];
764 my $source = @{$msg_hash->{'source'}}[0];
765 my $target = @{$msg_hash->{'target'}}[0];
766 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
767 my $hostId;
768 my $error = 0;
769 my $xml_msg;
771 # Build return message with twisted target and source
772 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
773 if (defined $forward_to_gosa) {
774 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
775 }
777 # Sanity check of needed parameter
778 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
779 $error++;
780 &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
781 &add_content2xml_hash($out_hash, "error", "hostId");
782 &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1);
783 }
785 if (not $error) {
787 # Get hostId
788 $hostId = @{$msg_hash->{'hostId'}}[0];
789 &add_content2xml_hash($out_hash, "hostId", "$hostId");
790 &add_content2xml_hash($out_hash, "xxx", "");
791 }
793 # Move to XML string
794 $xml_msg= &create_xml_string($out_hash);
796 if (not $error) {
798 # JSON Query
799 my $callobj = {
800 method => 'getHardwareInformation_hash',
801 params => [ $hostId ],
802 id => 1,
803 };
805 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
806 if (not &check_opsi_res($res)){
807 my $result= $res->result;
808 if (ref $result eq "HASH") {
809 foreach my $r (keys %{$result}){
810 my $item= "\n<item><id>".xml_quote($r)."</id>";
811 my $value= $result->{$r};
812 foreach my $sres (@{$value}){
814 foreach my $dres (keys %{$sres}){
815 if (defined $sres->{$dres}){
816 $item.= "<$dres>".xml_quote($sres->{$dres})."</$dres>";
817 }
818 }
820 }
821 $item.= "</item>";
822 $xml_msg=~ s%<xxx></xxx>%$item<xxx></xxx>%;
824 }
825 }
826 }
828 $xml_msg=~ s/<xxx><\/xxx>//;
830 }
832 # Return message
833 return ( $xml_msg );
834 }
837 ## @method opsi_list_clients
838 # Reports all Opsi clients.
839 # @param msg - STRING - xml message
840 # @param msg_hash - HASHREF - message information parsed into a hash
841 # @param session_id - INTEGER - POE session id of the processing of this message
842 # @return out_msg - STRING - feedback to GOsa in success and error case
843 sub opsi_list_clients {
844 my ($msg, $msg_hash, $session_id) = @_;
845 my $header = @{$msg_hash->{'header'}}[0];
846 my $source = @{$msg_hash->{'source'}}[0];
847 my $target = @{$msg_hash->{'target'}}[0];
848 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
850 # Build return message with twisted target and source
851 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
852 if (defined $forward_to_gosa) {
853 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
854 }
855 &add_content2xml_hash($out_hash, "xxx", "");
857 # Move to XML string
858 my $xml_msg= &create_xml_string($out_hash);
860 # JSON Query
861 my $callobj = {
862 method => 'getClients_listOfHashes',
863 params => [ ],
864 id => 1,
865 };
866 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
867 if (not &check_opsi_res($res)){
868 foreach my $host (@{$res->result}){
869 my $item= "\n<item><name>".$host->{'hostId'}."</name>";
870 if (defined($host->{'description'})){
871 $item.= "<description>".xml_quote($host->{'description'})."</description>";
872 }
873 if (defined($host->{'notes'})){
874 $item.= "<notes>".xml_quote($host->{'notes'})."</notes>";
875 }
876 if (defined($host->{'lastSeen'})){
877 $item.= "<lastSeen>".xml_quote($host->{'lastSeen'})."</lastSeen>";
878 }
880 $callobj = {
881 method => 'getIpAddress',
882 params => [ $host->{'hostId'} ],
883 id => 1,
884 };
885 my $sres= $main::opsi_client->call($main::opsi_url, $callobj);
886 if ( not &check_opsi_res($sres)){
887 $item.= "<ip>".xml_quote($sres->result)."</ip>";
888 }
890 $callobj = {
891 method => 'getMacAddress',
892 params => [ $host->{'hostId'} ],
893 id => 1,
894 };
895 $sres= $main::opsi_client->call($main::opsi_url, $callobj);
896 if ( not &check_opsi_res($sres)){
897 $item.= "<mac>".xml_quote($sres->result)."</mac>";
898 }
899 $item.= "</item>";
900 $xml_msg=~ s%<xxx></xxx>%$item<xxx></xxx>%;
901 }
902 }
904 $xml_msg=~ s/<xxx><\/xxx>//;
905 return ( $xml_msg );
906 }
910 ## @method opsi_get_client_software
911 # Reports client software inventory.
912 # @param msg - STRING - xml message with tag hostId
913 # @param msg_hash - HASHREF - message information parsed into a hash
914 # @param session_id - INTEGER - POE session id of the processing of this message
915 # @return out_msg - STRING - feedback to GOsa in success and error case
916 sub opsi_get_client_software {
917 my ($msg, $msg_hash, $session_id) = @_;
918 my $header = @{$msg_hash->{'header'}}[0];
919 my $source = @{$msg_hash->{'source'}}[0];
920 my $target = @{$msg_hash->{'target'}}[0];
921 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
922 my $error = 0;
923 my $hostId;
924 my $xml_msg;
926 # Build return message with twisted target and source
927 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
928 if (defined $forward_to_gosa) {
929 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
930 }
932 # Sanity check of needed parameter
933 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
934 $error++;
935 &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
936 &add_content2xml_hash($out_hash, "error", "hostId");
937 &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1);
938 }
940 if (not $error) {
942 # Get hostId
943 $hostId = @{$msg_hash->{'hostId'}}[0];
944 &add_content2xml_hash($out_hash, "hostId", "$hostId");
945 &add_content2xml_hash($out_hash, "xxx", "");
946 }
948 $xml_msg= &create_xml_string($out_hash);
950 if (not $error) {
952 # JSON Query
953 my $callobj = {
954 method => 'getSoftwareInformation_hash',
955 params => [ $hostId ],
956 id => 1,
957 };
959 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
960 if (not &check_opsi_res($res)){
961 my $result= $res->result;
962 # TODO : Ist das hier schon fertig???
963 }
965 $xml_msg=~ s/<xxx><\/xxx>//;
967 }
969 # Return message
970 return ( $xml_msg );
971 }
974 ## @method opsi_get_local_products
975 # Reports product for given hostId or globally.
976 # @param msg - STRING - xml message with optional tag hostId
977 # @param msg_hash - HASHREF - message information parsed into a hash
978 # @param session_id - INTEGER - POE session id of the processing of this message
979 # @return out_msg - STRING - feedback to GOsa in success and error case
980 sub opsi_get_local_products {
981 my ($msg, $msg_hash, $session_id) = @_;
982 my $header = @{$msg_hash->{'header'}}[0];
983 my $source = @{$msg_hash->{'source'}}[0];
984 my $target = @{$msg_hash->{'target'}}[0];
985 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
986 my $hostId;
988 # Build return message with twisted target and source
989 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
990 if (defined $forward_to_gosa) {
991 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
992 }
993 &add_content2xml_hash($out_hash, "xxx", "");
995 # Get hostId if defined
996 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} == 1)) {
997 $hostId = @{$msg_hash->{'hostId'}}[0];
998 &add_content2xml_hash($out_hash, "hostId", $hostId);
999 }
1001 # Move to XML string
1002 my $xml_msg= &create_xml_string($out_hash);
1004 # For hosts, only return the products that are or get installed
1005 my $callobj;
1006 $callobj = {
1007 method => 'getLocalBootProductIds_list',
1008 params => [ ],
1009 id => 1,
1010 };
1012 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
1013 my %r = ();
1014 for (@{$res->result}) { $r{$_} = 1 }
1016 if (not &check_opsi_res($res)){
1018 if (defined $hostId){
1019 $callobj = {
1020 method => 'getProductStates_hash',
1021 params => [ $hostId ],
1022 id => 1,
1023 };
1025 my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
1026 if (not &check_opsi_res($hres)){
1027 my $htmp= $hres->result->{$hostId};
1029 # Check state != not_installed or action == setup -> load and add
1030 foreach my $product (@{$htmp}){
1032 if (!defined ($r{$product->{'productId'}})){
1033 next;
1034 }
1036 # Now we've a couple of hashes...
1037 if ($product->{'installationStatus'} ne "not_installed" or
1038 $product->{'actionRequest'} eq "setup"){
1039 my $state= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
1041 $callobj = {
1042 method => 'getProduct_hash',
1043 params => [ $product->{'productId'} ],
1044 id => 1,
1045 };
1047 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
1048 if (not &check_opsi_res($sres)){
1049 my $tres= $sres->result;
1051 my $name= xml_quote($tres->{'name'});
1052 my $r= $product->{'productId'};
1053 my $description= xml_quote($tres->{'description'});
1054 $name=~ s/\//\\\//;
1055 $description=~ s/\//\\\//;
1056 $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
1057 }
1059 }
1060 }
1062 }
1064 } else {
1065 foreach my $r (@{$res->result}) {
1066 $callobj = {
1067 method => 'getProduct_hash',
1068 params => [ $r ],
1069 id => 1,
1070 };
1072 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
1073 if (not &check_opsi_res($sres)){
1074 my $tres= $sres->result;
1076 my $name= xml_quote($tres->{'name'});
1077 my $description= xml_quote($tres->{'description'});
1078 $name=~ s/\//\\\//;
1079 $description=~ s/\//\\\//;
1080 $xml_msg=~ s/<xxx><\/xxx>/\n<item><productId>$r<\/productId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
1081 }
1083 }
1085 }
1086 }
1088 $xml_msg=~ s/<xxx><\/xxx>//;
1090 # Retrun Message
1091 return ( $xml_msg );
1092 }
1095 ## @method opsi_del_client
1096 # Deletes a client from Opsi.
1097 # @param msg - STRING - xml message with tag hostId
1098 # @param msg_hash - HASHREF - message information parsed into a hash
1099 # @param session_id - INTEGER - POE session id of the processing of this message
1100 # @return out_msg - STRING - feedback to GOsa in success and error case
1101 sub opsi_del_client {
1102 my ($msg, $msg_hash, $session_id) = @_;
1103 my $header = @{$msg_hash->{'header'}}[0];
1104 my $source = @{$msg_hash->{'source'}}[0];
1105 my $target = @{$msg_hash->{'target'}}[0];
1106 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
1107 my $hostId;
1108 my $error = 0;
1110 # Build return message with twisted target and source
1111 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
1112 if (defined $forward_to_gosa) {
1113 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
1114 }
1116 # Sanity check of needed parameter
1117 if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
1118 $error++;
1119 &add_content2xml_hash($out_hash, "error_string", "hostId contains no or more than one values");
1120 &add_content2xml_hash($out_hash, "error", "hostId");
1121 &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1);
1122 }
1124 if (not $error) {
1126 # Get hostId
1127 $hostId = @{$msg_hash->{'hostId'}}[0];
1128 &add_content2xml_hash($out_hash, "hostId", "$hostId");
1130 # JSON Query
1131 my $callobj = {
1132 method => 'deleteClient',
1133 params => [ $hostId ],
1134 id => 1,
1135 };
1136 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
1137 }
1139 # Move to XML string
1140 my $xml_msg= &create_xml_string($out_hash);
1142 # Return message
1143 return ( $xml_msg );
1144 }
1147 ## @method opsi_install_client
1148 # Set a client in Opsi to install and trigger a wake on lan message (WOL).
1149 # @param msg - STRING - xml message with tags hostId, macaddress
1150 # @param msg_hash - HASHREF - message information parsed into a hash
1151 # @param session_id - INTEGER - POE session id of the processing of this message
1152 # @return out_msg - STRING - feedback to GOsa in success and error case
1153 sub opsi_install_client {
1154 my ($msg, $msg_hash, $session_id) = @_;
1155 my $header = @{$msg_hash->{'header'}}[0];
1156 my $source = @{$msg_hash->{'source'}}[0];
1157 my $target = @{$msg_hash->{'target'}}[0];
1158 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
1161 my ($hostId, $macaddress);
1163 my $error = 0;
1164 my @out_msg_l;
1166 # Build return message with twisted target and source
1167 my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
1168 if (defined $forward_to_gosa) {
1169 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
1170 }
1172 # Sanity check of needed parameter
1173 if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
1174 $error++;
1175 &add_content2xml_hash($out_hash, "error_string", "no hostId specified or hostId tag invalid");
1176 &add_content2xml_hash($out_hash, "error", "hostId");
1177 &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1);
1178 }
1179 if ((not exists $msg_hash->{'macaddress'}) || (@{$msg_hash->{'macaddress'}} != 1) || (@{$msg_hash->{'macaddress'}}[0] eq ref 'HASH') ) {
1180 $error++;
1181 &add_content2xml_hash($out_hash, "error_string", "no macaddress specified or macaddress tag invalid");
1182 &add_content2xml_hash($out_hash, "error", "macaddress");
1183 &main::daemon_log("$session_id ERROR: no macaddress specified or macaddress tag invalid: $msg", 1);
1184 } else {
1185 if ((exists $msg_hash->{'macaddress'}) &&
1186 ($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)) {
1187 $macaddress = $1;
1188 } else {
1189 $error ++;
1190 &add_content2xml_hash($out_hash, "error_string", "given mac address is not correct");
1191 &add_content2xml_hash($out_hash, "error", "macaddress");
1192 &main::daemon_log("$session_id ERROR: given mac address is not correct: $msg", 1);
1193 }
1194 }
1196 if (not $error) {
1198 # Get hostId
1199 $hostId = @{$msg_hash->{'hostId'}}[0];
1200 &add_content2xml_hash($out_hash, "hostId", "$hostId");
1202 # Load all products for this host with status != "not_installed" or actionRequest != "none"
1203 my $callobj = {
1204 method => 'getProductStates_hash',
1205 params => [ $hostId ],
1206 id => 1,
1207 };
1209 my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
1210 if (not &check_opsi_res($hres)){
1211 my $htmp= $hres->result->{$hostId};
1213 # check state != not_installed or action == setup -> load and add
1214 foreach my $product (@{$htmp}){
1215 # Now we've a couple of hashes...
1216 if ($product->{'installationStatus'} ne "not_installed" or
1217 $product->{'actionRequest'} ne "none"){
1219 # Do an action request for all these -> "setup".
1220 $callobj = {
1221 method => 'setProductActionRequest',
1222 params => [ $product->{'productId'}, $hostId, "setup" ],
1223 id => 1,
1224 };
1225 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
1226 my ($res_err, $res_err_string) = &check_opsi_res($res);
1227 if ($res_err){
1228 &main::daemon_log("$session_id ERROR: cannot set product action request for '$hostId': ".$product->{'productId'}, 1);
1229 } else {
1230 &main::daemon_log("$session_id INFO: requesting 'setup' for '".$product->{'productId'}."' on $hostId", 1);
1231 }
1232 }
1233 }
1234 }
1235 push(@out_msg_l, &create_xml_string($out_hash));
1238 # Build wakeup message for client
1239 if (not $error) {
1240 my $wakeup_hash = &create_xml_hash("trigger_wake", "GOSA", "KNOWN_SERVER");
1241 &add_content2xml_hash($wakeup_hash, 'macAddress', $macaddress);
1242 my $wakeup_msg = &create_xml_string($wakeup_hash);
1243 push(@out_msg_l, $wakeup_msg);
1245 # invoke trigger wake for this gosa-si-server
1246 &main::server_server_com::trigger_wake($wakeup_msg, $wakeup_hash, $session_id);
1247 }
1248 }
1250 # Return messages
1251 return @out_msg_l;
1252 }
1255 ## @method _set_action
1256 # Set action for an Opsi client
1257 # @param product - STRING - Opsi product
1258 # @param action - STRING - action
1259 # @param hostId - STRING - Opsi hostId
1260 sub _set_action {
1261 my $product= shift;
1262 my $action = shift;
1263 my $hostId = shift;
1264 my $callobj;
1266 $callobj = {
1267 method => 'setProductActionRequest',
1268 params => [ $product, $hostId, $action],
1269 id => 1,
1270 };
1272 $main::opsi_client->call($main::opsi_url, $callobj);
1273 }
1275 ## @method _set_state
1276 # Set state for an Opsi client
1277 # @param product - STRING - Opsi product
1278 # @param action - STRING - state
1279 # @param hostId - STRING - Opsi hostId
1280 sub _set_state {
1281 my $product = shift;
1282 my $state = shift;
1283 my $hostId = shift;
1284 my $callobj;
1286 $callobj = {
1287 method => 'setProductState',
1288 params => [ $product, $hostId, $state ],
1289 id => 1,
1290 };
1292 $main::opsi_client->call($main::opsi_url, $callobj);
1293 }
1295 1;