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_install_client",
22 );
23 @EXPORT = @events;
25 use strict;
26 use warnings;
27 use GOSA::GosaSupportDaemon;
28 use Data::Dumper;
31 BEGIN {}
33 END {}
35 ## @method get_events()
36 # A brief function returning a list of functions which are exported by importing the module.
37 # @return List of all provided functions
38 sub get_events {
39 return \@events;
40 }
43 ## @method opsi_install_client
44 # A new windows installing job is created at job_queue_db.
45 # @param msg - STRING - xml message with tags macaddress and hostId
46 # @param msg_hash - HASHREF - message information parsed into a hash
47 # @param session_id - INTEGER - POE session id of the processing of this message
48 sub opsi_install_client {
49 my ($msg, $msg_hash, $session_id) = @_ ;
50 my $error = 0;
51 my $out_msg;
52 my $out_hash;
54 # Prepare incoming message
55 $msg =~ s/<header>gosa_/<header>/;
56 $msg_hash->{'header'}[0] =~ s/gosa_//;
59 # Assign variables
60 my $header = @{$msg_hash->{'header'}}[0];
61 my $source = @{$msg_hash->{'source'}}[0];
62 my $target = @{$msg_hash->{'target'}}[0];
65 # If no timestamp is specified in incoming message, use 19700101000000
66 my $timestamp = "19700101000000";
67 if( exists $msg_hash->{'timestamp'} ) {
68 $timestamp = @{$msg_hash->{'timestamp'}}[0];
69 }
72 # If no macaddress is specified, raise error
73 my $macaddress;
74 if ((exists $msg_hash->{'macaddress'}) &&
75 ($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)) {
76 $macaddress = $1;
77 } else {
78 $error ++;
79 $out_msg = "<xml>".
80 "<header>answer</header>".
81 "<source>$main::server_address</source>".
82 "<target>GOSA</target>".
83 "<answer1>1</answer1>".
84 "<error_string>no mac address specified in macaddres-tag</error_string>".
85 "</xml>";
86 }
89 # Set hostID to plain_name
90 my $plain_name;
91 if (not $error) {
92 if (exists $msg_hash->{'hostId'}) {
93 $plain_name = $msg_hash->{'hostId'}[0];
94 } else {
95 $error++;
96 $out_msg = "<xml>".
97 "<header>answer</header>".
98 "<source>$main::server_address</source>".
99 "<target>GOSA</target>".
100 "<answer1>1</answer1>".
101 "<error_string>no hostId specified in hostId-tag</error_string>".
102 "</xml>";
103 }
104 }
107 # Add installation job to job queue
108 if (not $error) {
109 my $insert_dic = {table=>$main::job_queue_tn,
110 primkey=>['macaddress', 'headertag'],
111 timestamp=>&get_time(),
112 status=>'processing',
113 result=>'none',
114 progress=>'none',
115 headertag=>$header,
116 targettag=>$target,
117 xmlmessage=>$msg,
118 macaddress=>$macaddress,
119 plainname=>$plain_name,
120 siserver=>"localhost",
121 modified=>"1",
122 };
123 my $res = $main::job_db->add_dbentry($insert_dic);
124 if (not $res == 0) {
125 &main::daemon_log("$session_id ERROR: Cannot add opsi-job to job_queue: $msg", 1);
126 } else {
127 &main::daemon_log("$session_id INFO: '$header'-job successfully added to job queue", 5);
128 }
129 $out_msg = $msg; # forward GOsa message to client
130 }
132 return ($out_msg);
133 }
136 ## @method opsi_get_netboot_products
137 # ???
138 # @param msg - STRING - xml message with tag hostId
139 # @param msg_hash - HASHREF - message information parsed into a hash
140 # @param session_id - INTEGER - POE session id of the processing of this message
141 sub opsi_get_netboot_products {
142 my ($msg, $msg_hash, $session_id) = @_;
143 my $header = @{$msg_hash->{'header'}}[0];
144 my $source = @{$msg_hash->{'source'}}[0];
145 my $target = @{$msg_hash->{'target'}}[0];
146 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
147 my $hostId;
149 # build return message with twisted target and source
150 my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
151 #&add_content2xml_hash($out_hash, "session_id", $session_id); ### possibly not needed, to be checked
152 if (defined $forward_to_gosa) {
153 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
154 }
156 # Get hostID if defined
157 if (defined @{$msg_hash->{'hostId'}}[0]){
158 $hostId = @{$msg_hash->{'hostId'}}[0];
159 &add_content2xml_hash($out_hash, "hostId", $hostId);
160 }
162 &add_content2xml_hash($out_hash, "xxx", "");
163 my $xml_msg= &create_xml_string($out_hash);
165 # For hosts, only return the products that are or get installed
166 my $callobj;
167 $callobj = {
168 method => 'getNetBootProductIds_list',
169 params => [ ],
170 id => 1,
171 };
173 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
174 my %r = ();
175 for (@{$res->result}) { $r{$_} = 1 }
177 if (check_res($res)){
179 if (defined $hostId){
180 $callobj = {
181 method => 'getProductStates_hash',
182 params => [ $hostId ],
183 id => 1,
184 };
186 my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
187 if (check_res($hres)){
188 my $htmp= $hres->result->{$hostId};
190 # check state != not_installed or action == setup -> load and add
191 foreach my $product (@{$htmp}){
193 if (!defined ($r{$product->{'productId'}})){
194 next;
195 }
197 # Now we've a couple of hashes...
198 if ($product->{'installationStatus'} ne "not_installed" or
199 $product->{'actionRequest'} eq "setup"){
200 my $state= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
202 $callobj = {
203 method => 'getProduct_hash',
204 params => [ $product->{'productId'} ],
205 id => 1,
206 };
208 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
209 if (check_res($sres)){
210 my $tres= $sres->result;
212 my $name= xml_quote($tres->{'name'});
213 my $r= $product->{'productId'};
214 my $description= xml_quote($tres->{'description'});
215 $name=~ s/\//\\\//;
216 $description=~ s/\//\\\//;
217 $xml_msg=~ s/<xxx><\/xxx>/<item><ProductId>$r<\/ProductId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
218 }
220 }
221 }
223 }
225 } else {
226 foreach my $r (@{$res->result}) {
227 $callobj = {
228 method => 'getProduct_hash',
229 params => [ $r ],
230 id => 1,
231 };
233 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
234 if (check_res($sres)){
235 my $tres= $sres->result;
237 my $name= xml_quote($tres->{'name'});
238 my $description= xml_quote($tres->{'description'});
239 $name=~ s/\//\\\//;
240 $description=~ s/\//\\\//;
241 $xml_msg=~ s/<xxx><\/xxx>/<item><ProductId>$r<\/ProductId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
242 }
244 }
246 }
247 }
249 $xml_msg=~ s/<xxx><\/xxx>//;
251 return ($xml_msg);
252 }
255 ## @method opsi_get_product_properties
256 # ???
257 # @param msg - STRING - xml message with tags ProductId and hostId
258 # @param msg_hash - HASHREF - message information parsed into a hash
259 # @param session_id - INTEGER - POE session id of the processing of this message
260 sub opsi_get_product_properties {
261 my ($msg, $msg_hash, $session_id) = @_;
262 my $header = @{$msg_hash->{'header'}}[0];
263 my $source = @{$msg_hash->{'source'}}[0];
264 my $target = @{$msg_hash->{'target'}}[0];
265 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
266 my $productId = @{$msg_hash->{'ProductId'}}[0];
267 my $hostId;
269 # build return message with twisted target and source
270 my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
271 &add_content2xml_hash($out_hash, "session_id", $session_id);
273 # Get hostID if defined
274 if (defined @{$msg_hash->{'hostId'}}[0]){
275 $hostId = @{$msg_hash->{'hostId'}}[0];
276 &add_content2xml_hash($out_hash, "hostId", $hostId);
277 }
279 if (defined $forward_to_gosa) {
280 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
281 }
282 &add_content2xml_hash($out_hash, "ProducId", "$productId");
284 # Load actions
285 my $callobj = {
286 method => 'getPossibleProductActions_list',
287 params => [ $productId ],
288 id => 1,
289 };
290 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
291 if (check_res($res)){
292 foreach my $action (@{$res->result}){
293 &add_content2xml_hash($out_hash, "action", $action);
294 }
295 }
297 # Add place holder
298 &add_content2xml_hash($out_hash, "xxx", "");
300 # Move to XML string
301 my $xml_msg= &create_xml_string($out_hash);
303 # JSON Query
304 $callobj = {
305 method => 'getProductProperties_hash',
306 params => [ $productId ],
307 id => 1,
308 };
310 $res = $main::opsi_client->call($main::opsi_url, $callobj);
312 if (check_res($res)){
313 my $r= $res->result;
314 foreach my $key (keys %{$r}) {
315 my $item= "<item>";
316 my $value= $r->{$key};
317 if (UNIVERSAL::isa( $value, "ARRAY" )){
318 foreach my $subval (@{$value}){
319 $item.= "<$key>".xml_quote($subval)."</$key>";
320 }
321 } else {
322 $item.= "<$key>".xml_quote($value)."</$key>";
323 }
324 $item.= "</item>";
325 $xml_msg=~ s/<xxx><\/xxx>/$item<xxx><\/xxx>/;
326 }
327 }
330 $xml_msg=~ s/<xxx><\/xxx>//;
332 return ($xml_msg);
333 }
336 ## @method opsi_set_product_properties
337 # ???
338 # @param msg - STRING - xml message with tags ProductId, hostId, action and state
339 # @param msg_hash - HASHREF - message information parsed into a hash
340 # @param session_id - INTEGER - POE session id of the processing of this message
341 sub opsi_set_product_properties {
342 my ($msg, $msg_hash, $session_id) = @_;
343 my $header = @{$msg_hash->{'header'}}[0];
344 my $source = @{$msg_hash->{'source'}}[0];
345 my $target = @{$msg_hash->{'target'}}[0];
346 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
347 my $productId = @{$msg_hash->{'ProductId'}}[0];
348 my $hostId;
350 # build return message with twisted target and source
351 my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
352 &add_content2xml_hash($out_hash, "session_id", $session_id);
353 &add_content2xml_hash($out_hash, "ProductId", $productId);
355 # Get hostID if defined
356 if (defined @{$msg_hash->{'hostId'}}[0]){
357 $hostId = @{$msg_hash->{'hostId'}}[0];
358 &add_content2xml_hash($out_hash, "hostId", $hostId);
359 }
361 # Set product states if requested
362 if (defined @{$msg_hash->{'action'}}[0]){
363 &_set_action($productId, @{$msg_hash->{'action'}}[0], $hostId);
364 }
365 if (defined @{$msg_hash->{'state'}}[0]){
366 &_set_state($productId, @{$msg_hash->{'state'}}[0], $hostId);
367 }
369 if (defined $forward_to_gosa) {
370 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
371 }
373 # Find properties
374 foreach my $item (@{$msg_hash->{'item'}}){
375 # JSON Query
376 my $callobj;
378 if (defined $hostId){
379 $callobj = {
380 method => 'setProductProperty',
381 params => [ $productId, $item->{'name'}[0], $item->{'value'}[0], $hostId ],
382 id => 1,
383 };
384 } else {
385 $callobj = {
386 method => 'setProductProperty',
387 params => [ $productId, $item->{'name'}[0], $item->{'value'}[0] ],
388 id => 1,
389 };
390 }
392 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
394 if (!check_res($res)){
395 &main::daemon_log("ERROR: no communication failed while setting '".$item->{'name'}[0]."': ".$res->error_message, 1);
396 &add_content2xml_hash($out_hash, "error", $res->error_message);
397 }
399 }
401 # return message
402 return ( &create_xml_string($out_hash) );
403 }
406 ## @method opsi_get_client_hardware
407 # ???
408 # @param msg - STRING - xml message with tag hostId
409 # @param msg_hash - HASHREF - message information parsed into a hash
410 # @param session_id - INTEGER - POE session id of the processing of this message
411 sub opsi_get_client_hardware {
412 my ($msg, $msg_hash, $session_id) = @_;
413 my $header = @{$msg_hash->{'header'}}[0];
414 my $source = @{$msg_hash->{'source'}}[0];
415 my $target = @{$msg_hash->{'target'}}[0];
416 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
417 my $hostId = @{$msg_hash->{'hostId'}}[0];
419 # build return message with twisted target and source
420 my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
421 &add_content2xml_hash($out_hash, "session_id", $session_id);
423 if (defined $forward_to_gosa) {
424 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
425 }
426 &add_content2xml_hash($out_hash, "hostId", "$hostId");
427 &add_content2xml_hash($out_hash, "xxx", "");
428 my $xml_msg= &create_xml_string($out_hash);
430 # JSON Query
431 my $callobj = {
432 method => 'getHardwareInformation_hash',
433 params => [ $hostId ],
434 id => 1,
435 };
437 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
438 if (check_res($res)){
439 my $result= $res->result;
440 foreach my $r (keys %{$result}){
441 my $item= "<item><id>".xml_quote($r)."</id>";
442 my $value= $result->{$r};
443 foreach my $sres (@{$value}){
445 foreach my $dres (keys %{$sres}){
446 if (defined $sres->{$dres}){
447 $item.= "<$dres>".xml_quote($sres->{$dres})."</$dres>";
448 }
449 }
451 }
452 $item.= "</item>";
453 $xml_msg=~ s%<xxx></xxx>%$item<xxx></xxx>%;
455 }
456 }
458 $xml_msg=~ s/<xxx><\/xxx>//;
460 return ( $xml_msg );
461 }
464 ## @method opsi_list_clients
465 # ???
466 # @param msg - STRING - xml message
467 # @param msg_hash - HASHREF - message information parsed into a hash
468 # @param session_id - INTEGER - POE session id of the processing of this message
469 sub opsi_list_clients {
470 my ($msg, $msg_hash, $session_id) = @_;
471 my $header = @{$msg_hash->{'header'}}[0];
472 my $source = @{$msg_hash->{'source'}}[0];
473 my $target = @{$msg_hash->{'target'}}[0];
474 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
476 # build return message with twisted target and source
477 my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
478 &add_content2xml_hash($out_hash, "session_id", $session_id);
480 if (defined $forward_to_gosa) {
481 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
482 }
484 &add_content2xml_hash($out_hash, "xxx", "");
485 my $xml_msg= &create_xml_string($out_hash);
487 # JSON Query
488 my $callobj = {
489 method => 'getClients_listOfHashes',
490 params => [ ],
491 id => 1,
492 };
494 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
495 if (check_res($res)){
497 foreach my $host (@{$res->result}){
498 my $item= "<item><name>".$host->{'hostId'}."</name>";
499 if (defined($host->{'description'})){
500 $item.= "<description>".xml_quote($host->{'description'})."</description>";
501 }
502 $item.= "</item>";
503 $xml_msg=~ s%<xxx></xxx>%$item<xxx></xxx>%;
504 }
506 }
508 $xml_msg=~ s/<xxx><\/xxx>//;
509 return ( $xml_msg );
510 }
513 ## @method opsi_get_client_software
514 # ???
515 # @param msg - STRING - xml message with tag hostId
516 # @param msg_hash - HASHREF - message information parsed into a hash
517 # @param session_id - INTEGER - POE session id of the processing of this message
518 sub opsi_get_client_software {
519 my ($msg, $msg_hash, $session_id) = @_;
520 my $header = @{$msg_hash->{'header'}}[0];
521 my $source = @{$msg_hash->{'source'}}[0];
522 my $target = @{$msg_hash->{'target'}}[0];
523 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
524 my $hostId = @{$msg_hash->{'hostId'}}[0];
526 # build return message with twisted target and source
527 my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
528 &add_content2xml_hash($out_hash, "session_id", $session_id);
530 if (defined $forward_to_gosa) {
531 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
532 }
533 &add_content2xml_hash($out_hash, "hostId", "$hostId");
534 &add_content2xml_hash($out_hash, "xxx", "");
535 my $xml_msg= &create_xml_string($out_hash);
537 # JSON Query
538 my $callobj = {
539 method => 'getSoftwareInformation_hash',
540 params => [ $hostId ],
541 id => 1,
542 };
544 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
545 if (check_res($res)){
546 my $result= $res->result;
547 }
549 $xml_msg=~ s/<xxx><\/xxx>//;
551 return ( $xml_msg );
552 }
555 ## @method opsi_get_local_products
556 # ???
557 # @param msg - STRING - xml message with tag hostId
558 # @param msg_hash - HASHREF - message information parsed into a hash
559 # @param session_id - INTEGER - POE session id of the processing of this message
560 sub opsi_get_local_products {
561 my ($msg, $msg_hash, $session_id) = @_;
562 my $header = @{$msg_hash->{'header'}}[0];
563 my $source = @{$msg_hash->{'source'}}[0];
564 my $target = @{$msg_hash->{'target'}}[0];
565 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
566 my $hostId;
568 # build return message with twisted target and source
569 my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
570 &add_content2xml_hash($out_hash, "session_id", $session_id);
572 # Get hostID if defined
573 if (defined @{$msg_hash->{'hostId'}}[0]){
574 $hostId = @{$msg_hash->{'hostId'}}[0];
575 &add_content2xml_hash($out_hash, "hostId", $hostId);
576 }
578 if (defined $forward_to_gosa) {
579 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
580 }
581 &add_content2xml_hash($out_hash, "xxx", "");
582 my $xml_msg= &create_xml_string($out_hash);
584 # For hosts, only return the products that are or get installed
585 my $callobj;
586 $callobj = {
587 method => 'getLocalBootProductIds_list',
588 params => [ ],
589 id => 1,
590 };
592 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
593 my %r = ();
594 for (@{$res->result}) { $r{$_} = 1 }
596 if (check_res($res)){
598 if (defined $hostId){
599 $callobj = {
600 method => 'getProductStates_hash',
601 params => [ $hostId ],
602 id => 1,
603 };
605 my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
606 if (check_res($hres)){
607 my $htmp= $hres->result->{$hostId};
609 # check state != not_installed or action == setup -> load and add
610 foreach my $product (@{$htmp}){
612 if (!defined ($r{$product->{'productId'}})){
613 next;
614 }
616 # Now we've a couple of hashes...
617 if ($product->{'installationStatus'} ne "not_installed" or
618 $product->{'actionRequest'} eq "setup"){
619 my $state= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
621 $callobj = {
622 method => 'getProduct_hash',
623 params => [ $product->{'productId'} ],
624 id => 1,
625 };
627 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
628 if (check_res($sres)){
629 my $tres= $sres->result;
631 my $name= xml_quote($tres->{'name'});
632 my $r= $product->{'productId'};
633 my $description= xml_quote($tres->{'description'});
634 $name=~ s/\//\\\//;
635 $description=~ s/\//\\\//;
636 $xml_msg=~ s/<xxx><\/xxx>/<item><ProductId>$r<\/ProductId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
637 }
639 }
640 }
642 }
644 } else {
645 foreach my $r (@{$res->result}) {
646 $callobj = {
647 method => 'getProduct_hash',
648 params => [ $r ],
649 id => 1,
650 };
652 my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
653 if (check_res($sres)){
654 my $tres= $sres->result;
656 my $name= xml_quote($tres->{'name'});
657 my $description= xml_quote($tres->{'description'});
658 $name=~ s/\//\\\//;
659 $description=~ s/\//\\\//;
660 $xml_msg=~ s/<xxx><\/xxx>/<item><ProductId>$r<\/ProductId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
661 }
663 }
665 }
666 }
668 $xml_msg=~ s/<xxx><\/xxx>//;
670 return ( $xml_msg );
671 }
674 ### @method _opsi_get_client_status
675 ##
676 ## @param msg - STRING - xml message with tags
677 ## @param msg_hash - HASHREF - message information parsed into a hash
678 ## @param session_id - INTEGER - POE session id of the processing of this message
679 #sub _opsi_get_client_status {
680 # my $hostId = shift;
681 # my $result= {};
682 #
683 # # For hosts, only return the products that are or get installed
684 # my $callobj;
685 # $callobj = {
686 # method => 'getProductStates_hash',
687 # params => [ $hostId ],
688 # id => 1,
689 # };
690 #
691 # my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
692 # if (check_res($hres)){
693 # my $htmp= $hres->result->{$hostId};
694 #
695 # # check state != not_installed or action == setup -> load and add
696 # my $products= 0;
697 # my $installed= 0;
698 # my $error= 0;
699 # foreach my $product (@{$htmp}){
700 #
701 # if ($product->{'installationStatus'} ne "not_installed" or
702 # $product->{'actionRequest'} eq "setup"){
703 #
704 # # Increase number of products for this host
705 # $products++;
706 #
707 # if ($product->{'installationStatus'} eq "failed"){
708 # $result->{$product->{'productId'}}= "error";
709 # $error++;
710 # }
711 # if ($product->{'installationStatus'} eq "installed"){
712 # $result->{$product->{'productId'}}= "installed";
713 # $installed++;
714 # }
715 # if ($product->{'installationStatus'} eq "installing"){
716 # $result->{$product->{'productId'}}= "installing";
717 # }
718 # }
719 # }
720 #
721 # # Estimate "rough" progress
722 # $result->{'progress'}= int($installed * 100 / $products);
723 # }
724 #
725 # return $result;
726 #}
729 ## @method opsi_del_client
730 # ???
731 # @param msg - STRING - xml message with tag hostId
732 # @param msg_hash - HASHREF - message information parsed into a hash
733 # @param session_id - INTEGER - POE session id of the processing of this message
734 sub opsi_del_client {
735 my ($msg, $msg_hash, $session_id) = @_;
736 my $header = @{$msg_hash->{'header'}}[0];
737 my $source = @{$msg_hash->{'source'}}[0];
738 my $target = @{$msg_hash->{'target'}}[0];
739 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
740 my $hostId = @{$msg_hash->{'hostId'}}[0];
742 # build return message with twisted target and source
743 my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
744 &add_content2xml_hash($out_hash, "session_id", $session_id);
746 if (defined $forward_to_gosa) {
747 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
748 }
749 &add_content2xml_hash($out_hash, "hostId", "$hostId");
751 # JSON Query
752 my $callobj = {
753 method => 'deleteClient',
754 params => [ $hostId ],
755 id => 1,
756 };
758 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
760 my $xml_msg= &create_xml_string($out_hash);
761 return ( $xml_msg );
762 }
765 ## @method opsi_install_client
766 # ???
767 # @param msg - STRING - xml message with tag hostId
768 # @param msg_hash - HASHREF - message information parsed into a hash
769 # @param session_id - INTEGER - POE session id of the processing of this message
770 sub opsi_install_client {
771 my ($msg, $msg_hash, $session_id) = @_;
772 my $header = @{$msg_hash->{'header'}}[0];
773 my $source = @{$msg_hash->{'source'}}[0];
774 my $target = @{$msg_hash->{'target'}}[0];
775 my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
776 my $hostId = @{$msg_hash->{'hostId'}}[0];
778 # build return message with twisted target and source
779 my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
780 &add_content2xml_hash($out_hash, "session_id", $session_id);
782 if (defined $forward_to_gosa) {
783 &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
784 }
785 &add_content2xml_hash($out_hash, "hostId", "$hostId");
787 # Load all products for this host with status != "not_installed" or actionRequest != "none"
788 if (defined $hostId){
789 my $callobj = {
790 method => 'getProductStates_hash',
791 params => [ $hostId ],
792 id => 1,
793 };
795 my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
796 if (check_res($hres)){
797 my $htmp= $hres->result->{$hostId};
799 # check state != not_installed or action == setup -> load and add
800 foreach my $product (@{$htmp}){
802 # Now we've a couple of hashes...
803 if ($product->{'installationStatus'} ne "not_installed" or
804 $product->{'actionRequest'} ne "none"){
806 # Do an action request for all these -> "setup".
807 $callobj = {
808 method => 'setProductActionRequest',
809 params => [ $product->{'productId'}, $hostId, "setup" ],
810 id => 1,
811 };
812 my $res = $main::opsi_client->call($main::opsi_url, $callobj);
813 if (!check_res($res)){
814 &main::daemon_log("ERROR: cannot set product action request for $hostId!", 1);
815 } else {
816 &main::daemon_log("INFO: requesting 'setup' for '".$product->{'productId'}."' on $hostId", 1);
817 }
819 }
820 }
821 }
822 }
826 # # JSON Query
827 # my $callobj = {
828 # method => 'deleteClient',
829 # params => [ $hostId ],
830 # id => 1,
831 # };
832 #
833 # my $res = $main::opsi_client->call($main::opsi_url, $callobj);
835 my $xml_msg= &create_xml_string($out_hash);
836 return ($xml_msg);
837 }
840 ## @method _set_action
841 # ???
842 # @param product - STRING - ???
843 # @param action - STRING - ???
844 # @param hostId - STRING - ???
845 sub _set_action {
846 my $product= shift;
847 my $action = shift;
848 my $hostId = shift;
849 my $callobj;
851 $callobj = {
852 method => 'setProductActionRequest',
853 params => [ $product, $hostId, $action],
854 id => 1,
855 };
857 $main::opsi_client->call($main::opsi_url, $callobj);
858 }
860 ## @method _set_state
861 # ???
862 # @param product - STRING - ???
863 # @param action - STRING - ???
864 # @param hostId - STRING - ???
865 sub _set_state {
866 my $product = shift;
867 my $hostId = shift;
868 my $action = shift;
869 my $callobj;
871 $callobj = {
872 method => 'setProductState',
873 params => [ $product, $hostId, $action ],
874 id => 1,
875 };
877 $main::opsi_client->call($main::opsi_url, $callobj);
878 }
880 1;