Code

update: opsi server integration
[gosa.git] / gosa-si / server / events / opsi_com.pm
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;
29 use XML::Quote qw(:all);
32 BEGIN {}
34 END {}
36 ## @method get_events()
37 # A brief function returning a list of functions which are exported by importing the module.
38 # @return List of all provided functions
39 sub get_events {
40     return \@events;
41 }
43     
44 ## @method opsi_install_client
45 # A new windows installing job is created at job_queue_db.
46 # @param msg - STRING - xml message with tags macaddress and hostId
47 # @param msg_hash - HASHREF - message information parsed into a hash
48 # @param session_id - INTEGER - POE session id of the processing of this message
49 #sub opsi_install_client {
50 #    my ($msg, $msg_hash, $session_id) = @_ ;
51 #    my $error = 0;
52 #    my $out_msg;
53 #    my $out_hash;
54 #
55 #    # Prepare incoming message
56 #    $msg =~ s/<header>gosa_/<header>/;
57 #    $msg_hash->{'header'}[0] =~ s/gosa_//;
58 #
59 #
60 #    # Assign variables
61 #    my $header = @{$msg_hash->{'header'}}[0];
62 #    my $source = @{$msg_hash->{'source'}}[0];
63 #    my $target = @{$msg_hash->{'target'}}[0];
64 #
65 #
66 #    # If no timestamp is specified in incoming message, use 19700101000000
67 #    my $timestamp = "19700101000000";
68 #    if( exists $msg_hash->{'timestamp'} ) {
69 #        $timestamp = @{$msg_hash->{'timestamp'}}[0];
70 #    }
71 #     
72 #
73 #    # If no macaddress is specified, raise error 
74 #    my $macaddress;
75 #    if ((exists $msg_hash->{'macaddress'}) &&
76 #            ($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)) { 
77 #        $macaddress = $1;
78 #    } else {
79 #        $error ++;
80 #        $out_msg = "<xml>".
81 #            "<header>answer</header>".
82 #            "<source>$main::server_address</source>".
83 #            "<target>GOSA</target>".
84 #            "<answer1>1</answer1>".
85 #            "<error_string>no mac address specified in macaddres-tag</error_string>".
86 #            "</xml>";
87 #    }
88 #    
89 #
90 #    # Set hostID to plain_name
91 #    my $plain_name;
92 #    if (not $error) {
93 #        if (exists $msg_hash->{'hostId'}) {
94 #            $plain_name = $msg_hash->{'hostId'}[0];
95 #        } else {
96 #            $error++;
97 #            $out_msg = "<xml>".
98 #            "<header>answer</header>".
99 #            "<source>$main::server_address</source>".
100 #            "<target>GOSA</target>".
101 #            "<answer1>1</answer1>".
102 #            "<error_string>no hostId specified in hostId-tag</error_string>".
103 #            "</xml>";
104 #        }
105 #    }
108 #    # Add installation job to job queue
109 #    if (not $error) {
110 #        my $insert_dic = {table=>$main::job_queue_tn, 
111 #            primkey=>['macaddress', 'headertag'],
112 #            timestamp=>&get_time(),
113 #            status=>'processing', 
114 #            result=>'none',
115 #            progress=>'none',
116 #            headertag=>$header, 
117 #            targettag=>$target,
118 #            xmlmessage=>$msg,
119 #            macaddress=>$macaddress,
120 #            plainname=>$plain_name,
121 #            siserver=>"localhost",
122 #            modified=>"1",
123 #        };
124 #        my $res = $main::job_db->add_dbentry($insert_dic);
125 #        if (not $res == 0) {
126 #            &main::daemon_log("$session_id ERROR: Cannot add opsi-job to job_queue: $msg", 1);
127 #        } else {
128 #            &main::daemon_log("$session_id INFO: '$header'-job successfully added to job queue", 5);
129 #        }
130 #        $out_msg = $msg;   # forward GOsa message to client 
131 #    }
132 #    
133 #    return ($out_msg);
134 #}
137 ## @method opsi_get_netboot_products
138 # ???
139 # @param msg - STRING - xml message with tag hostId
140 # @param msg_hash - HASHREF - message information parsed into a hash
141 # @param session_id - INTEGER - POE session id of the processing of this message
142 sub opsi_get_netboot_products {
143   my ($msg, $msg_hash, $session_id) = @_;
144   my $header = @{$msg_hash->{'header'}}[0];
145   my $source = @{$msg_hash->{'source'}}[0];
146   my $target = @{$msg_hash->{'target'}}[0];
147   my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
148   my $hostId;
150   # build return message with twisted target and source
151   my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
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 (&main::check_opsi_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 (&main::check_opsi_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 (&main::check_opsi_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 (&main::check_opsi_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);
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);
272     # Get hostID if defined
273     if (defined @{$msg_hash->{'hostId'}}[0]){
274       $hostId = @{$msg_hash->{'hostId'}}[0];
275       &add_content2xml_hash($out_hash, "hostId", $hostId);
276     }
278     if (defined $forward_to_gosa) {
279       &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
280     }
281     &add_content2xml_hash($out_hash, "ProducId", "$productId");
283     # Load actions
284     my $callobj = {
285       method  => 'getPossibleProductActions_list',
286       params  => [ $productId ],
287       id  => 1,
288     };
289     my $res = $main::opsi_client->call($main::opsi_url, $callobj);
290     if (&main::check_opsi_res($res)){
291       foreach my $action (@{$res->result}){
292         &add_content2xml_hash($out_hash, "action", $action);
293       }
294     }
296     # Add place holder
297     &add_content2xml_hash($out_hash, "xxx", "");
299     # Move to XML string
300     my $xml_msg= &create_xml_string($out_hash);
302     # JSON Query
303     $callobj = {
304       method  => 'getProductProperties_hash',
305       params  => [ $productId ],
306       id  => 1,
307     };
309     $res = $main::opsi_client->call($main::opsi_url, $callobj);
311     if (&main::check_opsi_res($res)){
312         my $r= $res->result;
313         foreach my $key (keys %{$r}) {
314           my $item= "<item>";
315           my $value= $r->{$key};
316           if (UNIVERSAL::isa( $value, "ARRAY" )){
317             foreach my $subval (@{$value}){
318               $item.= "<$key>".xml_quote($subval)."</$key>";
319             }
320           } else {
321             $item.= "<$key>".xml_quote($value)."</$key>";
322           }
323           $item.= "</item>";
324           $xml_msg=~ s/<xxx><\/xxx>/$item<xxx><\/xxx>/;
325         }
326     }
329   $xml_msg=~ s/<xxx><\/xxx>//;
331   return ($xml_msg);
335 ## @method opsi_set_product_properties
336 # ???
337 # @param msg - STRING - xml message with tags ProductId, hostId, action and state
338 # @param msg_hash - HASHREF - message information parsed into a hash
339 # @param session_id - INTEGER - POE session id of the processing of this message
340 sub opsi_set_product_properties {
341     my ($msg, $msg_hash, $session_id) = @_;
342     my $header = @{$msg_hash->{'header'}}[0];
343     my $source = @{$msg_hash->{'source'}}[0];
344     my $target = @{$msg_hash->{'target'}}[0];
345     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
346     my $productId = @{$msg_hash->{'ProductId'}}[0];
347     my $hostId;
349     # build return message with twisted target and source
350     my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
351     &add_content2xml_hash($out_hash, "ProductId", $productId);
353     # Get hostID if defined
354     if (defined @{$msg_hash->{'hostId'}}[0]){
355       $hostId = @{$msg_hash->{'hostId'}}[0];
356       &add_content2xml_hash($out_hash, "hostId", $hostId);
357     }
359     # Set product states if requested
360     if (defined @{$msg_hash->{'action'}}[0]){
361       &_set_action($productId, @{$msg_hash->{'action'}}[0], $hostId);
362     }
363     if (defined @{$msg_hash->{'state'}}[0]){
364       &_set_state($productId, @{$msg_hash->{'state'}}[0], $hostId);
365     }
367     if (defined $forward_to_gosa) {
368         &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
369     }
371     # Find properties
372     foreach my $item (@{$msg_hash->{'item'}}){
373       # JSON Query
374       my $callobj;
376       if (defined $hostId){
377         $callobj = {
378           method  => 'setProductProperty',
379           params  => [ $productId, $item->{'name'}[0], $item->{'value'}[0], $hostId ],
380           id  => 1,
381         };
382       } else {
383         $callobj = {
384           method  => 'setProductProperty',
385           params  => [ $productId, $item->{'name'}[0], $item->{'value'}[0] ],
386           id  => 1,
387         };
388       }
390       my $res = $main::opsi_client->call($main::opsi_url, $callobj);
392       if (!&main::check_opsi_res($res)){
393         &main::daemon_log("ERROR: no communication failed while setting '".$item->{'name'}[0]."': ".$res->error_message, 1);
394         &add_content2xml_hash($out_hash, "error", $res->error_message);
395       }
397     }
399     # return message
400     return ( &create_xml_string($out_hash) );
404 ## @method opsi_get_client_hardware
405 # ???
406 # @param msg - STRING - xml message with tag hostId
407 # @param msg_hash - HASHREF - message information parsed into a hash
408 # @param session_id - INTEGER - POE session id of the processing of this message
409 sub opsi_get_client_hardware {
410     my ($msg, $msg_hash, $session_id) = @_;
411     my $header = @{$msg_hash->{'header'}}[0];
412     my $source = @{$msg_hash->{'source'}}[0];
413     my $target = @{$msg_hash->{'target'}}[0];
414     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
415     my $hostId = @{$msg_hash->{'hostId'}}[0];
417     # build return message with twisted target and source
418     my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
420     if (defined $forward_to_gosa) {
421       &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
422     }
423     &add_content2xml_hash($out_hash, "hostId", "$hostId");
424     &add_content2xml_hash($out_hash, "xxx", "");
425     my $xml_msg= &create_xml_string($out_hash);
427     # JSON Query
428     my $callobj = {
429       method  => 'getHardwareInformation_hash',
430       params  => [ $hostId ],
431       id  => 1,
432     };
434     my $res = $main::opsi_client->call($main::opsi_url, $callobj);
435     if (&main::check_opsi_res($res)){
436       my $result= $res->result;
437       foreach my $r (keys %{$result}){
438         my $item= "<item><id>".xml_quote($r)."</id>";
439         my $value= $result->{$r};
440         foreach my $sres (@{$value}){
442           foreach my $dres (keys %{$sres}){
443             if (defined $sres->{$dres}){
444               $item.= "<$dres>".xml_quote($sres->{$dres})."</$dres>";
445             }
446           }
448         }
449           $item.= "</item>";
450           $xml_msg=~ s%<xxx></xxx>%$item<xxx></xxx>%;
452       }
453     }
455     $xml_msg=~ s/<xxx><\/xxx>//;
457     return ( $xml_msg );
461 ## @method opsi_list_clients
462 # ???
463 # @param msg - STRING - xml message 
464 # @param msg_hash - HASHREF - message information parsed into a hash
465 # @param session_id - INTEGER - POE session id of the processing of this message
466 sub opsi_list_clients {
467     my ($msg, $msg_hash, $session_id) = @_;
468     my $header = @{$msg_hash->{'header'}}[0];
469     my $source = @{$msg_hash->{'source'}}[0];
470     my $target = @{$msg_hash->{'target'}}[0];
471     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
473     # build return message with twisted target and source
474     my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
476     if (defined $forward_to_gosa) {
477       &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
478     }
480     &add_content2xml_hash($out_hash, "xxx", "");
481     my $xml_msg= &create_xml_string($out_hash);
483     # JSON Query
484     my $callobj = {
485       method  => 'getClients_listOfHashes',
486       params  => [ ],
487       id  => 1,
488     };
490     my $res = $main::opsi_client->call($main::opsi_url, $callobj);
491     if (&main::check_opsi_res($res)){
493       foreach my $host (@{$res->result}){
494         my $item= "<item><name>".$host->{'hostId'}."</name>";
495         if (defined($host->{'description'})){
496           $item.= "<description>".xml_quote($host->{'description'})."</description>";
497         }
498         $item.= "</item>";
499         $xml_msg=~ s%<xxx></xxx>%$item<xxx></xxx>%;
500       }
502     }
504     $xml_msg=~ s/<xxx><\/xxx>//;
505     return ( $xml_msg );
509 ## @method opsi_get_client_software
510 # ???
511 # @param msg - STRING - xml message with tag hostId
512 # @param msg_hash - HASHREF - message information parsed into a hash
513 # @param session_id - INTEGER - POE session id of the processing of this message
514 sub opsi_get_client_software {
515     my ($msg, $msg_hash, $session_id) = @_;
516     my $header = @{$msg_hash->{'header'}}[0];
517     my $source = @{$msg_hash->{'source'}}[0];
518     my $target = @{$msg_hash->{'target'}}[0];
519     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
520     my $hostId = @{$msg_hash->{'hostId'}}[0];
522     # build return message with twisted target and source
523     my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
525     if (defined $forward_to_gosa) {
526       &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
527     }
528     &add_content2xml_hash($out_hash, "hostId", "$hostId");
529     &add_content2xml_hash($out_hash, "xxx", "");
530     my $xml_msg= &create_xml_string($out_hash);
532     # JSON Query
533     my $callobj = {
534       method  => 'getSoftwareInformation_hash',
535       params  => [ $hostId ],
536       id  => 1,
537     };
539     my $res = $main::opsi_client->call($main::opsi_url, $callobj);
540     if (&main::check_opsi_res($res)){
541       my $result= $res->result;
542     }
544     $xml_msg=~ s/<xxx><\/xxx>//;
546     return ( $xml_msg );
550 ## @method opsi_get_local_products
551 # ???
552 # @param msg - STRING - xml message with tag hostId
553 # @param msg_hash - HASHREF - message information parsed into a hash
554 # @param session_id - INTEGER - POE session id of the processing of this message
555 sub opsi_get_local_products {
556   my ($msg, $msg_hash, $session_id) = @_;
557   my $header = @{$msg_hash->{'header'}}[0];
558   my $source = @{$msg_hash->{'source'}}[0];
559   my $target = @{$msg_hash->{'target'}}[0];
560   my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
561   my $hostId;
563   # build return message with twisted target and source
564   my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
566   # Get hostID if defined
567   if (defined @{$msg_hash->{'hostId'}}[0]){
568     $hostId = @{$msg_hash->{'hostId'}}[0];
569     &add_content2xml_hash($out_hash, "hostId", $hostId);
570   }
572   if (defined $forward_to_gosa) {
573     &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
574   }
575   &add_content2xml_hash($out_hash, "xxx", "");
576   my $xml_msg= &create_xml_string($out_hash);
578   # For hosts, only return the products that are or get installed
579   my $callobj;
580   $callobj = {
581     method  => 'getLocalBootProductIds_list',
582     params  => [ ],
583     id  => 1,
584   };
586   my $res = $main::opsi_client->call($main::opsi_url, $callobj);
587   my %r = ();
588   for (@{$res->result}) { $r{$_} = 1 }
590   if (&main::check_opsi_res($res)){
592     if (defined $hostId){
593       $callobj = {
594         method  => 'getProductStates_hash',
595         params  => [ $hostId ],
596         id  => 1,
597       };
599       my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
600       if (&main::check_opsi_res($hres)){
601         my $htmp= $hres->result->{$hostId};
603         # check state != not_installed or action == setup -> load and add
604         foreach my $product (@{$htmp}){
606           if (!defined ($r{$product->{'productId'}})){
607             next;
608           }
610           # Now we've a couple of hashes...
611           if ($product->{'installationStatus'} ne "not_installed" or
612               $product->{'actionRequest'} eq "setup"){
613             my $state= "<state>".$product->{'installationStatus'}."</state><action>".$product->{'actionRequest'}."</action>";
615             $callobj = {
616               method  => 'getProduct_hash',
617               params  => [ $product->{'productId'} ],
618               id  => 1,
619             };
621             my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
622             if (&main::check_opsi_res($sres)){
623               my $tres= $sres->result;
625               my $name= xml_quote($tres->{'name'});
626               my $r= $product->{'productId'};
627               my $description= xml_quote($tres->{'description'});
628               $name=~ s/\//\\\//;
629               $description=~ s/\//\\\//;
630               $xml_msg=~ s/<xxx><\/xxx>/<item><ProductId>$r<\/ProductId><name><\/name><description>$description<\/description><\/item>$state<xxx><\/xxx>/;
631             }
633           }
634         }
636       }
638     } else {
639       foreach my $r (@{$res->result}) {
640         $callobj = {
641           method  => 'getProduct_hash',
642           params  => [ $r ],
643           id  => 1,
644         };
646         my $sres = $main::opsi_client->call($main::opsi_url, $callobj);
647         if (&main::check_opsi_res($sres)){
648           my $tres= $sres->result;
650           my $name= xml_quote($tres->{'name'});
651           my $description= xml_quote($tres->{'description'});
652           $name=~ s/\//\\\//;
653           $description=~ s/\//\\\//;
654           $xml_msg=~ s/<xxx><\/xxx>/<item><ProductId>$r<\/ProductId><name><\/name><description>$description<\/description><\/item><xxx><\/xxx>/;
655         }
657       }
659     }
660   }
662   $xml_msg=~ s/<xxx><\/xxx>//;
664   return ( $xml_msg );
668 ### @method _opsi_get_client_status
669 ## 
670 ## @param msg - STRING - xml message with tags 
671 ## @param msg_hash - HASHREF - message information parsed into a hash
672 ## @param session_id - INTEGER - POE session id of the processing of this message
673 #sub _opsi_get_client_status {
674 #  my $hostId = shift;
675 #  my $result= {};
677 #  # For hosts, only return the products that are or get installed
678 #  my $callobj;
679 #  $callobj = {
680 #    method  => 'getProductStates_hash',
681 #    params  => [ $hostId ],
682 #    id  => 1,
683 #  };
685 #  my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
686 #  if (&main::check_opsi_res($hres)){
687 #    my $htmp= $hres->result->{$hostId};
689 #    # check state != not_installed or action == setup -> load and add
690 #    my $products= 0;
691 #    my $installed= 0;
692 #    my $error= 0;
693 #    foreach my $product (@{$htmp}){
695 #      if ($product->{'installationStatus'} ne "not_installed" or
696 #          $product->{'actionRequest'} eq "setup"){
698 #        # Increase number of products for this host
699 #        $products++;
701 #        if ($product->{'installationStatus'} eq "failed"){
702 #          $result->{$product->{'productId'}}= "error";
703 #          $error++;
704 #        }
705 #        if ($product->{'installationStatus'} eq "installed"){
706 #          $result->{$product->{'productId'}}= "installed";
707 #          $installed++;
708 #        }
709 #        if ($product->{'installationStatus'} eq "installing"){
710 #          $result->{$product->{'productId'}}= "installing";
711 #        }
712 #      }
713 #    }
715 #    # Estimate "rough" progress
716 #    $result->{'progress'}= int($installed * 100 / $products);
717 #  }
719 #  return $result;
720 #}
723 ## @method opsi_del_client
724 # ???
725 # @param msg - STRING - xml message with tag hostId
726 # @param msg_hash - HASHREF - message information parsed into a hash
727 # @param session_id - INTEGER - POE session id of the processing of this message
728 sub opsi_del_client {
729     my ($msg, $msg_hash, $session_id) = @_;
730     my $header = @{$msg_hash->{'header'}}[0];
731     my $source = @{$msg_hash->{'source'}}[0];
732     my $target = @{$msg_hash->{'target'}}[0];
733     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
734     my $hostId = @{$msg_hash->{'hostId'}}[0];
736     # build return message with twisted target and source
737     my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
739     if (defined $forward_to_gosa) {
740       &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
741     }
742     &add_content2xml_hash($out_hash, "hostId", "$hostId");
744     # JSON Query
745     my $callobj = {
746       method  => 'deleteClient',
747       params  => [ $hostId ],
748       id  => 1,
749     };
751     my $res = $main::opsi_client->call($main::opsi_url, $callobj);
753     my $xml_msg= &create_xml_string($out_hash);
754     return ( $xml_msg );
758 ## @method opsi_install_client
759 # ???
760 # @param msg - STRING - xml message with tag hostId
761 # @param msg_hash - HASHREF - message information parsed into a hash
762 # @param session_id - INTEGER - POE session id of the processing of this message
763 sub opsi_install_client {
764     my ($msg, $msg_hash, $session_id) = @_;
765     my $header = @{$msg_hash->{'header'}}[0];
766     my $source = @{$msg_hash->{'source'}}[0];
767     my $target = @{$msg_hash->{'target'}}[0];
768     my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
769     my $hostId = @{$msg_hash->{'hostId'}}[0];
771     # build return message with twisted target and source
772     my $out_hash = &main::create_xml_hash("answer_$header", $target, $source);
774     if (defined $forward_to_gosa) {
775       &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa);
776     }
777     &add_content2xml_hash($out_hash, "hostId", "$hostId");
779     # Load all products for this host with status != "not_installed" or actionRequest != "none"
780     if (defined $hostId){
781       my $callobj = {
782         method  => 'getProductStates_hash',
783         params  => [ $hostId ],
784         id  => 1,
785       };
787       my $hres = $main::opsi_client->call($main::opsi_url, $callobj);
788       if (&main::check_opsi_res($hres)){
789         my $htmp= $hres->result->{$hostId};
791         # check state != not_installed or action == setup -> load and add
792         foreach my $product (@{$htmp}){
794           # Now we've a couple of hashes...
795           if ($product->{'installationStatus'} ne "not_installed" or
796               $product->{'actionRequest'} ne "none"){
798             # Do an action request for all these -> "setup".
799             $callobj = {
800               method  => 'setProductActionRequest',
801               params  => [ $product->{'productId'}, $hostId, "setup" ],
802               id  => 1,
803             };
804             my $res = $main::opsi_client->call($main::opsi_url, $callobj);
805             if (!&main::check_opsi_res($res)){
806               &main::daemon_log("ERROR: cannot set product action request for $hostId!", 1);
807             } else {
808               &main::daemon_log("INFO: requesting 'setup' for '".$product->{'productId'}."' on $hostId", 1);
809             }
811           }
812         }
813       }
814     }
818 #    # JSON Query
819 #    my $callobj = {
820 #      method  => 'deleteClient',
821 #      params  => [ $hostId ],
822 #      id  => 1,
823 #    };
825 #    my $res = $main::opsi_client->call($main::opsi_url, $callobj);
827     my $xml_msg= &create_xml_string($out_hash);
828     return ($xml_msg);
832 ## @method _set_action
833 # ???
834 # @param product - STRING - ???
835 # @param action - STRING - ???
836 # @param hostId - STRING - ???
837 sub _set_action {
838   my $product= shift;
839   my $action = shift;
840   my $hostId = shift;
841   my $callobj;
843   $callobj = {
844     method  => 'setProductActionRequest',
845     params  => [ $product, $hostId, $action],
846     id  => 1,
847   };
849   $main::opsi_client->call($main::opsi_url, $callobj);
852 ## @method _set_state
853 # ???
854 # @param product - STRING - ???
855 # @param action - STRING - ???
856 # @param hostId - STRING - ???
857 sub _set_state {
858   my $product = shift;
859   my $hostId = shift;
860   my $action = shift;
861   my $callobj;
863   $callobj = {
864     method  => 'setProductState',
865     params  => [ $product, $hostId, $action ],
866     id  => 1,
867   };
869   $main::opsi_client->call($main::opsi_url, $callobj);
872 1;