From 1f47bd74631c7f1ec152a814ae5618c86c5d7f0a Mon Sep 17 00:00:00 2001 From: rettenbe Date: Thu, 7 Aug 2008 13:52:12 +0000 Subject: [PATCH] update: opsi_com complete with sanity checks and doxygen lines git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@12178 594d385d-05f5-0310-b6e9-bd551577e9d8 --- gosa-si/server/events/opsi_com.pm | 1166 ++++++++++++++++------------- gosa-si/tests/client.php | 20 +- 2 files changed, 675 insertions(+), 511 deletions(-) diff --git a/gosa-si/server/events/opsi_com.pm b/gosa-si/server/events/opsi_com.pm index 10778ca23..0e6204263 100644 --- a/gosa-si/server/events/opsi_com.pm +++ b/gosa-si/server/events/opsi_com.pm @@ -297,453 +297,561 @@ sub opsi_add_client { return ( &create_xml_string($out_hash) ); } -## @method -# ??? -# @param msg - STRING - xml message with tag hostId +## @method opsi_modify_client +# Modifies the parameters description, mac or notes for an Opsi client if the corresponding message tags are given. +# @param msg - STRING - xml message with tag hostId and optional description, mac or notes # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message +# @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_modify_client { - my ($msg, $msg_hash, $session_id) = @_; - my $header = @{$msg_hash->{'header'}}[0]; - my $source = @{$msg_hash->{'source'}}[0]; - my $target = @{$msg_hash->{'target'}}[0]; - my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; - my $hostId; - - # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); - if (defined $forward_to_gosa) { - &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); - } - - # Get hostID - $hostId = @{$msg_hash->{'hostId'}}[0]; - &add_content2xml_hash($out_hash, "hostId", $hostId); - my $name= $hostId; - $name=~ s/^([^.]+).*$/$1/; - my $domain= $hostId; - $domain=~ s/^[^.]+(.*)$/$1/; - my ($description, $notes, $ip, $mac); - - my $callobj; + my ($msg, $msg_hash, $session_id) = @_; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + my $target = @{$msg_hash->{'target'}}[0]; + my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; + my $hostId; + my $error = 0; + my ($sres, $sres_err, $sres_err_string); - if (defined @{$msg_hash->{'description'}}[0]){ - $description = @{$msg_hash->{'description'}}[0]; - $callobj = { - method => 'setHostDescription', - params => [ $hostId, $description ], - id => 1, - }; - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - my ($sres_err, $sres_err_string) = &check_opsi_res($sres); - if ($sres_err){ - &main::daemon_log("ERROR: cannot set description: ".$sres_err_string, 1); - &add_content2xml_hash($out_hash, "error", $sres_err_string); - return ( &create_xml_string($out_hash) ); + # Build return message with twisted target and source + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); + if (defined $forward_to_gosa) { + &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } - } - if (defined @{$msg_hash->{'notes'}}[0]){ - $notes = @{$msg_hash->{'notes'}}[0]; - $callobj = { - method => 'setHostNotes', - params => [ $hostId, $notes ], - id => 1, - }; - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - my ($sres_err, $sres_err_string) = &check_opsi_res($sres); - if ($sres_err){ - &main::daemon_log("ERROR: cannot set notes: ".$sres_err_string, 1); - &add_content2xml_hash($out_hash, "error", $sres_err_string); - return ( &create_xml_string($out_hash) ); + + # Sanity check of needed parameter + if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1)) { + $error++; + &add_content2xml_hash($out_hash, "hostId_error", "no hostId specified or hostId tag invalid"); + &add_content2xml_hash($out_hash, "error", "hostId"); + &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1); } - } - if (defined @{$msg_hash->{'mac'}}[0]){ - $mac = @{$msg_hash->{'mac'}}[0]; - $callobj = { - method => 'setMacAddress', - params => [ $hostId, $mac ], - id => 1, - }; - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - my ($sres_err, $sres_err_string) = &check_opsi_res($sres); - if ($sres_err){ - &main::daemon_log("ERROR: cannot set mac address: ".$sres_err_string, 1); - &add_content2xml_hash($out_hash, "error", $sres_err_string); - return ( &create_xml_string($out_hash) ); + + if (not $error) { + # Get hostID + $hostId = @{$msg_hash->{'hostId'}}[0]; + &add_content2xml_hash($out_hash, "hostId", $hostId); + my $name= $hostId; + $name=~ s/^([^.]+).*$/$1/; + my $domain= $hostId; + $domain=~ s/^[^.]+(.*)$/$1/; + + # Modify description, notes or mac if defined + my ($description, $notes, $mac); + my $callobj; + if ((exists $msg_hash->{'description'}) && (@{$msg_hash->{'description'}} == 1) ){ + $description = @{$msg_hash->{'description'}}[0]; + $callobj = { + method => 'setHostDescription', + params => [ $hostId, $description ], + id => 1, + }; + my $sres = $main::opsi_client->call($main::opsi_url, $callobj); + my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + if ($sres_err){ + &main::daemon_log("ERROR: cannot set description: ".$sres_err_string, 1); + &add_content2xml_hash($out_hash, "error", $sres_err_string); + } + } + if ((exists $msg_hash->{'notes'}) && (@{$msg_hash->{'notes'}} == 1)) { + $notes = @{$msg_hash->{'notes'}}[0]; + $callobj = { + method => 'setHostNotes', + params => [ $hostId, $notes ], + id => 1, + }; + my $sres = $main::opsi_client->call($main::opsi_url, $callobj); + my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + if ($sres_err){ + &main::daemon_log("ERROR: cannot set notes: ".$sres_err_string, 1); + &add_content2xml_hash($out_hash, "error", $sres_err_string); + } + } + if ((exists $msg_hash->{'mac'}) && (@{$msg_hash->{'mac'}} == 1)){ + $mac = @{$msg_hash->{'mac'}}[0]; + $callobj = { + method => 'setMacAddress', + params => [ $hostId, $mac ], + id => 1, + }; + my $sres = $main::opsi_client->call($main::opsi_url, $callobj); + my ($sres_err, $sres_err_string) = &check_opsi_res($sres); + if ($sres_err){ + &main::daemon_log("ERROR: cannot set mac address: ".$sres_err_string, 1); + &add_content2xml_hash($out_hash, "error", $sres_err_string); + } + } } - } - - # return message - return ( &create_xml_string($out_hash) ); + + # Return message + return ( &create_xml_string($out_hash) ); } ## @method opsi_get_netboot_products -# ??? +# Get netboot products for specific host. # @param msg - STRING - xml message with tag hostId # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message +# @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_get_netboot_products { - my ($msg, $msg_hash, $session_id) = @_; - my $header = @{$msg_hash->{'header'}}[0]; - my $source = @{$msg_hash->{'source'}}[0]; - my $target = @{$msg_hash->{'target'}}[0]; - my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; - my $hostId; - - # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); - if (defined $forward_to_gosa) { - &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); - } - - # Get hostID if defined - if (defined @{$msg_hash->{'hostId'}}[0]){ - $hostId = @{$msg_hash->{'hostId'}}[0]; - &add_content2xml_hash($out_hash, "hostId", $hostId); - } - - &add_content2xml_hash($out_hash, "xxx", ""); - my $xml_msg= &create_xml_string($out_hash); - - # For hosts, only return the products that are or get installed - my $callobj; - $callobj = { - method => 'getNetBootProductIds_list', - params => [ ], - id => 1, - }; + my ($msg, $msg_hash, $session_id) = @_; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + my $target = @{$msg_hash->{'target'}}[0]; + my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; + my $hostId; + my $error = 0; + my $xml_msg; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - my %r = (); - for (@{$res->result}) { $r{$_} = 1 } + # Build return message with twisted target and source + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); + if (defined $forward_to_gosa) { + &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); + } - if (&check_opsi_res($res)){ + # Sanity check of needed parameter + if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1)) { + $error++; + &add_content2xml_hash($out_hash, "hostId_error", "no hostId specified or hostId tag invalid"); + &add_content2xml_hash($out_hash, "error", "hostId"); + &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1); + } - if (defined $hostId){ - $callobj = { - method => 'getProductStates_hash', - params => [ $hostId ], - id => 1, - }; + if (not $error) { - my $hres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($hres)){ - my $htmp= $hres->result->{$hostId}; + # Get hostID if defined + $hostId = @{$msg_hash->{'hostId'}}[0]; + &add_content2xml_hash($out_hash, "hostId", $hostId); - # check state != not_installed or action == setup -> load and add - foreach my $product (@{$htmp}){ + &add_content2xml_hash($out_hash, "xxx", ""); + $xml_msg= &create_xml_string($out_hash); - if (!defined ($r{$product->{'productId'}})){ - next; - } + # For hosts, only return the products that are or get installed + my $callobj; + $callobj = { + method => 'getNetBootProductIds_list', + params => [ ], + id => 1, + }; - # Now we've a couple of hashes... - if ($product->{'installationStatus'} ne "not_installed" or - $product->{'actionRequest'} eq "setup"){ - my $state= "".$product->{'installationStatus'}."".$product->{'actionRequest'}.""; + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + my %r = (); + for (@{$res->result}) { $r{$_} = 1 } - $callobj = { - method => 'getProduct_hash', - params => [ $product->{'productId'} ], - id => 1, - }; + if (not &check_opsi_res($res)){ - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($sres)){ - my $tres= $sres->result; - - my $name= xml_quote($tres->{'name'}); - my $r= $product->{'productId'}; - my $description= xml_quote($tres->{'description'}); - $name=~ s/\//\\\//; - $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item>$state<\/xxx>/; - } + if (defined $hostId){ + $callobj = { + method => 'getProductStates_hash', + params => [ $hostId ], + id => 1, + }; - } - } + my $hres = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($hres)){ + my $htmp= $hres->result->{$hostId}; - } + # check state != not_installed or action == setup -> load and add + foreach my $product (@{$htmp}){ - } else { - foreach my $r (@{$res->result}) { - $callobj = { - method => 'getProduct_hash', - params => [ $r ], - id => 1, - }; + if (!defined ($r{$product->{'productId'}})){ + next; + } - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($sres)){ - my $tres= $sres->result; - - my $name= xml_quote($tres->{'name'}); - my $description= xml_quote($tres->{'description'}); - $name=~ s/\//\\\//; - $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item><\/xxx>/; - } + # Now we've a couple of hashes... + if ($product->{'installationStatus'} ne "not_installed" or + $product->{'actionRequest'} eq "setup"){ + my $state= "".$product->{'installationStatus'}."".$product->{'actionRequest'}.""; + + $callobj = { + method => 'getProduct_hash', + params => [ $product->{'productId'} ], + id => 1, + }; + + my $sres = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($sres)){ + my $tres= $sres->result; + + my $name= xml_quote($tres->{'name'}); + my $r= $product->{'productId'}; + my $description= xml_quote($tres->{'description'}); + $name=~ s/\//\\\//; + $description=~ s/\//\\\//; + $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item>$state<\/xxx>/; + } + } + } - } + } - } - } + } else { + foreach my $r (@{$res->result}) { + $callobj = { + method => 'getProduct_hash', + params => [ $r ], + id => 1, + }; + + my $sres = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($sres)){ + my $tres= $sres->result; + + my $name= xml_quote($tres->{'name'}); + my $description= xml_quote($tres->{'description'}); + $name=~ s/\//\\\//; + $description=~ s/\//\\\//; + $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item><\/xxx>/; + } + } - $xml_msg=~ s/<\/xxx>//; + } + } + $xml_msg=~ s/<\/xxx>//; + } - return ($xml_msg); + # Return message + return ( $xml_msg ); } ## @method opsi_get_product_properties -# ??? -# @param msg - STRING - xml message with tags ProductId and hostId +# Get product properties for a product and a specific host or gobally for a product. +# @param msg - STRING - xml message with tags productId and optional hostId # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message +# @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_get_product_properties { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; - my $productId = @{$msg_hash->{'productId'}}[0]; - my $hostId; + my ($hostId, $productId); + my $error = 0; + my $xml_msg; # build return message with twisted target and source my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); - - # Get hostID if defined - if (defined @{$msg_hash->{'hostId'}}[0]){ - $hostId = @{$msg_hash->{'hostId'}}[0]; - &add_content2xml_hash($out_hash, "hostId", $hostId); - } - if (defined $forward_to_gosa) { - &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); + &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } - &add_content2xml_hash($out_hash, "ProducId", "$productId"); - # Load actions - my $callobj = { - method => 'getPossibleProductActions_list', - params => [ $productId ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($res)){ - foreach my $action (@{$res->result}){ - &add_content2xml_hash($out_hash, "action", $action); - } + # Sanity check of needed parameter + if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1)) { + $error++; + &add_content2xml_hash($out_hash, "productId_error", "no productId specified or productId tag invalid"); + &add_content2xml_hash($out_hash, "error", "productId"); + &main::daemon_log("$session_id ERROR: no productId specified or productId tag invalid: $msg", 1); } - # Add place holder - &add_content2xml_hash($out_hash, "xxx", ""); + if (not $error) { - # Move to XML string - my $xml_msg= &create_xml_string($out_hash); + # Get productid + $productId = @{$msg_hash->{'productId'}}[0]; + &add_content2xml_hash($out_hash, "producId", "$productId"); - # JSON Query - $callobj = { - method => 'getProductProperties_hash', - params => [ $productId ], - id => 1, - }; - $res = $main::opsi_client->call($main::opsi_url, $callobj); + $hostId = @{$msg_hash->{'hostId'}}[0]; + &add_content2xml_hash($out_hash, "hostId", $hostId); - if (&check_opsi_res($res)){ - my $r= $res->result; - foreach my $key (keys %{$r}) { - my $item= ""; - my $value= $r->{$key}; - if (UNIVERSAL::isa( $value, "ARRAY" )){ - foreach my $subval (@{$value}){ - $item.= "<$key>".xml_quote($subval).""; + # Load actions + my $callobj = { + method => 'getPossibleProductActions_list', + params => [ $productId ], + id => 1, + }; + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($res)){ + foreach my $action (@{$res->result}){ + &add_content2xml_hash($out_hash, "action", $action); } - } else { - $item.= "<$key>".xml_quote($value).""; - } - $item.= ""; - $xml_msg=~ s/<\/xxx>/$item<\/xxx>/; } + + # Add place holder + &add_content2xml_hash($out_hash, "xxx", ""); + } + # Move to XML string + $xml_msg= &create_xml_string($out_hash); - $xml_msg=~ s/<\/xxx>//; + if (not $error) { - return ($xml_msg); + # JSON Query + my $callobj = { + method => 'getProductProperties_hash', + params => [ $productId ], + id => 1, + }; + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($res)){ + my $r= $res->result; + foreach my $key (keys %{$r}) { + my $item= ""; + my $value= $r->{$key}; + if (UNIVERSAL::isa( $value, "ARRAY" )){ + foreach my $subval (@{$value}){ + $item.= "<$key>".xml_quote($subval).""; + } + } else { + $item.= "<$key>".xml_quote($value).""; + } + $item.= ""; + $xml_msg=~ s/<\/xxx>/$item<\/xxx>/; + } + } + + $xml_msg=~ s/<\/xxx>//; + } + + # Return message + return ( $xml_msg ); } ## @method opsi_set_product_properties -# ??? -# @param msg - STRING - xml message with tags ProductId, hostId, action and state +# 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. +# @param msg - STRING - xml message with tags productId, action, state and optional hostId, action and state # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message +# @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_set_product_properties { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; - my $productId = @{$msg_hash->{'productId'}}[0]; - my $hostId; + my ($productId, $hostId); + my $error = 0; - # build return message with twisted target and source + # Build return message with twisted target and source my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); - &add_content2xml_hash($out_hash, "productId", $productId); - - # Get hostID if defined - if (defined @{$msg_hash->{'hostId'}}[0]){ - $hostId = @{$msg_hash->{'hostId'}}[0]; - &add_content2xml_hash($out_hash, "hostId", $hostId); + if (defined $forward_to_gosa) { + &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } - # Set product states if requested - if (defined @{$msg_hash->{'action'}}[0]){ - &_set_action($productId, @{$msg_hash->{'action'}}[0], $hostId); + # Sanity check of needed parameter + if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1)) { + $error++; + &add_content2xml_hash($out_hash, "productId_error", "no productId specified or productId tag invalid"); + &add_content2xml_hash($out_hash, "error", "productId"); + &main::daemon_log("$session_id ERROR: no productId specified or productId tag invalid: $msg", 1); } - if (defined @{$msg_hash->{'state'}}[0]){ - &_set_state($productId, @{$msg_hash->{'state'}}[0], $hostId); + if ((not exists $msg_hash->{'item'}) || (@{$msg_hash->{'item'}}[0] != 1)) { + $error++; + &add_content2xml_hash($out_hash, "item_error", "message needs one xml-tag 'item' and within the xml-tags 'name' and 'value'"); + &add_content2xml_hash($out_hash, "error", "item"); + &main::daemon_log("$session_id ERROR: message needs one xml-tag 'item' and within the xml-tags 'name' and 'value': $msg", 1); + } else { + if ((not exists $msg_hash->{'item'}->{'name'}) || (@{$msg_hash->{'item'}->{'name'}}[0] != 1)) { + $error++; + &add_content2xml_hash($out_hash, "name_error", "message needs within the xml-tag 'item' one xml-tags 'name'"); + &add_content2xml_hash($out_hash, "error", "name"); + &main::daemon_log("$session_id ERROR: message needs within the xml-tag 'item' one xml-tags 'name': $msg", 1); + } + if ((not exists $msg_hash->{'item'}->{'value'}) || (@{$msg_hash->{'item'}->{'value'}}[0] != 1)) { + $error++; + &add_content2xml_hash($out_hash, "value_error", "message needs within the xml-tag 'item' one xml-tags 'value'"); + &add_content2xml_hash($out_hash, "error", "value"); + &main::daemon_log("$session_id ERROR: message needs within the xml-tag 'item' one xml-tags 'value': $msg", 1); + } } - - if (defined $forward_to_gosa) { - &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); + if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1)) { + $error++; + &add_content2xml_hash($out_hash, "hostId_error", "hostId contains no or more than one values"); + &add_content2xml_hash($out_hash, "error", "hostId"); + &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1); } - # Find properties - foreach my $item (@{$msg_hash->{'item'}}){ - # JSON Query - my $callobj; + if (not $error) { + + # Get productId + $productId = @{$msg_hash->{'productId'}}[0]; + &add_content2xml_hash($out_hash, "productId", $productId); - if (defined $hostId){ - $callobj = { - method => 'setProductProperty', - params => [ $productId, $item->{'name'}[0], $item->{'value'}[0], $hostId ], - id => 1, - }; - } else { - $callobj = { - method => 'setProductProperty', - params => [ $productId, $item->{'name'}[0], $item->{'value'}[0] ], - id => 1, - }; - } + # Get hostID if defined + if (exists $msg_hash->{'hostId'}){ + $hostId = @{$msg_hash->{'hostId'}}[0]; + &add_content2xml_hash($out_hash, "hostId", $hostId); + } + + # Set product states if requested + if (defined @{$msg_hash->{'action'}}[0]){ + &_set_action($productId, @{$msg_hash->{'action'}}[0], $hostId); + } + if (defined @{$msg_hash->{'state'}}[0]){ + &_set_state($productId, @{$msg_hash->{'state'}}[0], $hostId); + } + + # Find properties + foreach my $item (@{$msg_hash->{'item'}}){ + # JSON Query + my $callobj; + + if (defined $hostId){ + $callobj = { + method => 'setProductProperty', + params => [ $productId, $item->{'name'}[0], $item->{'value'}[0], $hostId ], + id => 1, + }; + } else { + $callobj = { + method => 'setProductProperty', + params => [ $productId, $item->{'name'}[0], $item->{'value'}[0] ], + id => 1, + }; + } - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - my ($res_err, $res_err_string) = &check_opsi_res($res); + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + my ($res_err, $res_err_string) = &check_opsi_res($res); # TODO : This error message sounds strange - if ($res_err){ - &man::daemon_log("$session_id ERROR: no communication failed while setting '".$item->{'name'}[0]."': ".$res_err_string, 1); - &add_content2xml_hash($out_hash, "error", $res_err_string); - } + if ($res_err){ + &man::daemon_log("$session_id ERROR: no communication failed while setting '".$item->{'name'}[0]."': ".$res_err_string, 1); + &add_content2xml_hash($out_hash, "error", $res_err_string); + } + } } - # return message + # Return message return ( &create_xml_string($out_hash) ); } ## @method opsi_get_client_hardware -# ??? +# Reports client hardware inventory. # @param msg - STRING - xml message with tag hostId # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message +# @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_get_client_hardware { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; - my $hostId = @{$msg_hash->{'hostId'}}[0]; + my $hostId; + my $error = 0; + my $xml_msg; # build return message with twisted target and source my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); - if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } - &add_content2xml_hash($out_hash, "hostId", "$hostId"); - &add_content2xml_hash($out_hash, "xxx", ""); - my $xml_msg= &create_xml_string($out_hash); + + # Sanity check of needed parameter + if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1)) { + $error++; + &add_content2xml_hash($out_hash, "hostId_error", "hostId contains no or more than one values"); + &add_content2xml_hash($out_hash, "error", "hostId"); + &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1); + } + + if (not $error) { + + # Get hostID + $hostId = @{$msg_hash->{'hostId'}}[0]; + &add_content2xml_hash($out_hash, "hostId", "$hostId"); + &add_content2xml_hash($out_hash, "xxx", ""); + } + + # Move to XML string + $xml_msg= &create_xml_string($out_hash); + + if (not $error) { # JSON Query - my $callobj = { - method => 'getHardwareInformation_hash', - params => [ $hostId ], - id => 1, - }; + my $callobj = { + method => 'getHardwareInformation_hash', + params => [ $hostId ], + id => 1, + }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($res)){ - my $result= $res->result; - foreach my $r (keys %{$result}){ - my $item= "".xml_quote($r).""; - my $value= $result->{$r}; - foreach my $sres (@{$value}){ - - foreach my $dres (keys %{$sres}){ - if (defined $sres->{$dres}){ - $item.= "<$dres>".xml_quote($sres->{$dres}).""; - } - } + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($res)){ + my $result= $res->result; + foreach my $r (keys %{$result}){ + my $item= "".xml_quote($r).""; + my $value= $result->{$r}; + foreach my $sres (@{$value}){ + + foreach my $dres (keys %{$sres}){ + if (defined $sres->{$dres}){ + $item.= "<$dres>".xml_quote($sres->{$dres}).""; + } + } + } + $item.= ""; + $xml_msg=~ s%%$item%; + + } } - $item.= ""; - $xml_msg=~ s%%$item%; - } - } + $xml_msg=~ s/<\/xxx>//; - $xml_msg=~ s/<\/xxx>//; + } + # Return message return ( $xml_msg ); } ## @method opsi_list_clients -# ??? +# Reports all Opsi clients. # @param msg - STRING - xml message # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message +# @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_list_clients { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; + my $error = 0; # build return message with twisted target and source my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); - if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } - &add_content2xml_hash($out_hash, "xxx", ""); - my $xml_msg= &create_xml_string($out_hash); - # JSON Query - my $callobj = { - method => 'getClients_listOfHashes', - params => [ ], - id => 1, - }; + # Move to XML string + my $xml_msg= &create_xml_string($out_hash); - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($res)){ + if (not $error) { - foreach my $host (@{$res->result}){ - my $item= "".$host->{'hostId'}.""; - if (defined($host->{'description'})){ - $item.= "".xml_quote($host->{'description'}).""; + # JSON Query + my $callobj = { + method => 'getClients_listOfHashes', + params => [ ], + id => 1, + }; + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($res)){ + foreach my $host (@{$res->result}){ + my $item= "".$host->{'hostId'}.""; + if (defined($host->{'description'})){ + $item.= "".xml_quote($host->{'description'}).""; + } + if (defined($host->{'ip'})){ + $item.= "".xml_quote($host->{'ip'}).""; + } + if (defined($host->{'mac'})){ + $item.= "".xml_quote($host->{'mac'}).""; + } + if (defined($host->{'notes'})){ + $item.= "".xml_quote($host->{'notes'}).""; + } + $item.= ""; + $xml_msg=~ s%%$item%; + } } - $item.= ""; - $xml_msg=~ s%%$item%; - } - } $xml_msg=~ s/<\/xxx>//; @@ -752,301 +860,357 @@ sub opsi_list_clients { ## @method opsi_get_client_software -# ??? +# Reports client software inventory. # @param msg - STRING - xml message with tag hostId # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message +# @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_get_client_software { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; - my $hostId = @{$msg_hash->{'hostId'}}[0]; + my $error = 0; + my $hostId; + my $xml_msg; # build return message with twisted target and source my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); - if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } - &add_content2xml_hash($out_hash, "hostId", "$hostId"); - &add_content2xml_hash($out_hash, "xxx", ""); - my $xml_msg= &create_xml_string($out_hash); - # JSON Query - my $callobj = { - method => 'getSoftwareInformation_hash', - params => [ $hostId ], - id => 1, - }; + # Sanity check of needed parameter + if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1)) { + $error++; + &add_content2xml_hash($out_hash, "hostId_error", "hostId contains no or more than one values"); + &add_content2xml_hash($out_hash, "error", "hostId"); + &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1); + } - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($res)){ - my $result= $res->result; + if (not $error) { + + # Get hostID + $hostId = @{$msg_hash->{'hostId'}}[0]; + &add_content2xml_hash($out_hash, "hostId", "$hostId"); + &add_content2xml_hash($out_hash, "xxx", ""); } - $xml_msg=~ s/<\/xxx>//; + $xml_msg= &create_xml_string($out_hash); + + if (not $error) { + + # JSON Query + my $callobj = { + method => 'getSoftwareInformation_hash', + params => [ $hostId ], + id => 1, + }; + + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($res)){ + my $result= $res->result; +# TODO : fertig??? + } + $xml_msg=~ s/<\/xxx>//; + + } + + # Return message return ( $xml_msg ); } ## @method opsi_get_local_products -# ??? -# @param msg - STRING - xml message with tag hostId +# Reports product for given hostId or globally. +# @param msg - STRING - xml message with optional tag hostId # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message +# @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_get_local_products { - my ($msg, $msg_hash, $session_id) = @_; - my $header = @{$msg_hash->{'header'}}[0]; - my $source = @{$msg_hash->{'source'}}[0]; - my $target = @{$msg_hash->{'target'}}[0]; - my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; - my $hostId; - - # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); - - # Get hostID if defined - if (defined @{$msg_hash->{'hostId'}}[0]){ - $hostId = @{$msg_hash->{'hostId'}}[0]; - &add_content2xml_hash($out_hash, "hostId", $hostId); - } - - if (defined $forward_to_gosa) { - &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); - } - &add_content2xml_hash($out_hash, "xxx", ""); - my $xml_msg= &create_xml_string($out_hash); - - # For hosts, only return the products that are or get installed - my $callobj; - $callobj = { - method => 'getLocalBootProductIds_list', - params => [ ], - id => 1, - }; - - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - my %r = (); - for (@{$res->result}) { $r{$_} = 1 } + my ($msg, $msg_hash, $session_id) = @_; + my $header = @{$msg_hash->{'header'}}[0]; + my $source = @{$msg_hash->{'source'}}[0]; + my $target = @{$msg_hash->{'target'}}[0]; + my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; + my $hostId; + my $error = 0; + my $xml_msg; - if (&check_opsi_res($res)){ + # Build return message with twisted target and source + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); + if (defined $forward_to_gosa) { + &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); + } + &add_content2xml_hash($out_hash, "xxx", ""); - if (defined $hostId){ - $callobj = { - method => 'getProductStates_hash', - params => [ $hostId ], - id => 1, - }; + # Get hostID if defined + if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} == 1)) { + $hostId = @{$msg_hash->{'hostId'}}[0]; + &add_content2xml_hash($out_hash, "hostId", $hostId); + } - my $hres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($hres)){ - my $htmp= $hres->result->{$hostId}; + # Move to XML string + my $xml_msg= &create_xml_string($out_hash); - # check state != not_installed or action == setup -> load and add - foreach my $product (@{$htmp}){ + # For hosts, only return the products that are or get installed + my $callobj; + $callobj = { + method => 'getLocalBootProductIds_list', + params => [ ], + id => 1, + }; - if (!defined ($r{$product->{'productId'}})){ - next; - } + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + my %r = (); + for (@{$res->result}) { $r{$_} = 1 } - # Now we've a couple of hashes... - if ($product->{'installationStatus'} ne "not_installed" or - $product->{'actionRequest'} eq "setup"){ - my $state= "".$product->{'installationStatus'}."".$product->{'actionRequest'}.""; + if (not &check_opsi_res($res)){ + if (defined $hostId){ $callobj = { - method => 'getProduct_hash', - params => [ $product->{'productId'} ], - id => 1, + method => 'getProductStates_hash', + params => [ $hostId ], + id => 1, }; - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($sres)){ - my $tres= $sres->result; - - my $name= xml_quote($tres->{'name'}); - my $r= $product->{'productId'}; - my $description= xml_quote($tres->{'description'}); - $name=~ s/\//\\\//; - $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item>$state<\/xxx>/; - } + my $hres = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($hres)){ + my $htmp= $hres->result->{$hostId}; - } - } + # Check state != not_installed or action == setup -> load and add + foreach my $product (@{$htmp}){ - } + if (!defined ($r{$product->{'productId'}})){ + next; + } - } else { - foreach my $r (@{$res->result}) { - $callobj = { - method => 'getProduct_hash', - params => [ $r ], - id => 1, - }; + # Now we've a couple of hashes... + if ($product->{'installationStatus'} ne "not_installed" or + $product->{'actionRequest'} eq "setup"){ + my $state= "".$product->{'installationStatus'}."".$product->{'actionRequest'}.""; - my $sres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($sres)){ - my $tres= $sres->result; - - my $name= xml_quote($tres->{'name'}); - my $description= xml_quote($tres->{'description'}); - $name=~ s/\//\\\//; - $description=~ s/\//\\\//; - $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item><\/xxx>/; - } + $callobj = { + method => 'getProduct_hash', + params => [ $product->{'productId'} ], + id => 1, + }; - } + my $sres = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($sres)){ + my $tres= $sres->result; + my $name= xml_quote($tres->{'name'}); + my $r= $product->{'productId'}; + my $description= xml_quote($tres->{'description'}); + $name=~ s/\//\\\//; + $description=~ s/\//\\\//; + $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item>$state<\/xxx>/; + } + + } + } + + } + + } else { + foreach my $r (@{$res->result}) { + $callobj = { + method => 'getProduct_hash', + params => [ $r ], + id => 1, + }; + + my $sres = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($sres)){ + my $tres= $sres->result; + + my $name= xml_quote($tres->{'name'}); + my $description= xml_quote($tres->{'description'}); + $name=~ s/\//\\\//; + $description=~ s/\//\\\//; + $xml_msg=~ s/<\/xxx>/$r<\/productId><\/name>$description<\/description><\/item><\/xxx>/; + } + + } + + } } - } - $xml_msg=~ s/<\/xxx>//; + $xml_msg=~ s/<\/xxx>//; - return ( $xml_msg ); + # Retrun Message + return ( $xml_msg ); } ## @method opsi_del_client -# ??? +# Deletes a client from Opsi. # @param msg - STRING - xml message with tag hostId # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message +# @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_del_client { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; - my $hostId = @{$msg_hash->{'hostId'}}[0]; + my $hostId; + my $error = 0; - # build return message with twisted target and source + # Build return message with twisted target and source my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); - if (defined $forward_to_gosa) { &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); } - &add_content2xml_hash($out_hash, "hostId", "$hostId"); - # JSON Query - my $callobj = { - method => 'deleteClient', - params => [ $hostId ], - id => 1, - }; + # Sanity check of needed parameter + if ((exists $msg_hash->{'hostId'}) && (@{$msg_hash->{'hostId'}} != 1)) { + $error++; + &add_content2xml_hash($out_hash, "hostId_error", "hostId contains no or more than one values"); + &add_content2xml_hash($out_hash, "error", "hostId"); + &main::daemon_log("$session_id ERROR: hostId contains no or more than one values: $msg", 1); + } - my $res = $main::opsi_client->call($main::opsi_url, $callobj); + if (not $error) { + # Get hostID + $hostId = @{$msg_hash->{'hostId'}}[0]; + &add_content2xml_hash($out_hash, "hostId", "$hostId"); + + # JSON Query + my $callobj = { + method => 'deleteClient', + params => [ $hostId ], + id => 1, + }; + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + } + + # Move to XML string my $xml_msg= &create_xml_string($out_hash); + + # Return message return ( $xml_msg ); } ## @method opsi_install_client -# ??? +# Set a client in Opsi to install and trigger a wake on lan message (WOL). # @param msg - STRING - xml message with tags hostId, macaddress # @param msg_hash - HASHREF - message information parsed into a hash # @param session_id - INTEGER - POE session id of the processing of this message +# @return out_msg - STRING - feedback to GOsa in success and error case sub opsi_install_client { my ($msg, $msg_hash, $session_id) = @_; my $header = @{$msg_hash->{'header'}}[0]; my $source = @{$msg_hash->{'source'}}[0]; my $target = @{$msg_hash->{'target'}}[0]; my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0]; - my $hostId = @{$msg_hash->{'hostId'}}[0]; + + + my ($hostId, $macaddress); + my $error = 0; my @out_msg_l; - # If no macaddress is specified, raise error - my $macaddress; - if ((exists $msg_hash->{'macaddress'}) && - ($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)) { - $macaddress = $1; - } else { - $error ++; - my $out_msg = "". - "
answer
". - "$main::server_address". - "GOSA". - "1". - "no mac address specified in macaddres-tag". - "
"; - push(@out_msg_l, $out_msg); - } + # Build return message with twisted target and source + my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); + if (defined $forward_to_gosa) { + &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); + } + + # Sanity check of needed parameter + if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1)) { + $error++; + &add_content2xml_hash($out_hash, "hostId_error", "no hostId specified or hostId tag invalid"); + &add_content2xml_hash($out_hash, "error", "hostId"); + &main::daemon_log("$session_id ERROR: no hostId specified or hostId tag invalid: $msg", 1); + } + if ((not exists $msg_hash->{'macaddress'}) || (@{$msg_hash->{'macaddress'}} != 1)) { + $error++; + &add_content2xml_hash($out_hash, "macaddress_error", "no macaddress specified or macaddress tag invalid"); + &add_content2xml_hash($out_hash, "error", "macaddress"); + &main::daemon_log("$session_id ERROR: no macaddress specified or macaddress tag invalid: $msg", 1); + } else { + if ((exists $msg_hash->{'macaddress'}) && + ($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)) { + $macaddress = $1; + } else { + $error ++; + &add_content2xml_hash($out_hash, "macaddress_error", "given mac address is not correct"); + &add_content2xml_hash($out_hash, "error", "macaddress"); + &main::daemon_log("$session_id ERROR: given mac address is not correct: $msg", 1); + } + } - # Set parameters in opsi if (not $error) { - # build return message with twisted target and source - my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source); - if (defined $forward_to_gosa) { - &add_content2xml_hash($out_hash, "forward_to_gosa", $forward_to_gosa); - } + # Get hostId + $hostId = @{$msg_hash->{'hostId'}}[0]; &add_content2xml_hash($out_hash, "hostId", "$hostId"); # Load all products for this host with status != "not_installed" or actionRequest != "none" - if (defined $hostId){ - my $callobj = { - method => 'getProductStates_hash', - params => [ $hostId ], - id => 1, - }; - - my $hres = $main::opsi_client->call($main::opsi_url, $callobj); - if (&check_opsi_res($hres)){ - my $htmp= $hres->result->{$hostId}; - - # check state != not_installed or action == setup -> load and add - foreach my $product (@{$htmp}){ - # Now we've a couple of hashes... - if ($product->{'installationStatus'} ne "not_installed" or - $product->{'actionRequest'} ne "none"){ - - # Do an action request for all these -> "setup". - $callobj = { - method => 'setProductActionRequest', - params => [ $product->{'productId'}, $hostId, "setup" ], - id => 1, - }; - my $res = $main::opsi_client->call($main::opsi_url, $callobj); - if (!&check_opsi_res($res)){ - &main::daemon_log("ERROR: cannot set product action request for $hostId!", 1); - } else { - &main::daemon_log("INFO: requesting 'setup' for '".$product->{'productId'}."' on $hostId", 1); - } + my $callobj = { + method => 'getProductStates_hash', + params => [ $hostId ], + id => 1, + }; + my $hres = $main::opsi_client->call($main::opsi_url, $callobj); + if (not &check_opsi_res($hres)){ + my $htmp= $hres->result->{$hostId}; + + # check state != not_installed or action == setup -> load and add + foreach my $product (@{$htmp}){ + # Now we've a couple of hashes... + if ($product->{'installationStatus'} ne "not_installed" or + $product->{'actionRequest'} ne "none"){ + + # Do an action request for all these -> "setup". + $callobj = { + method => 'setProductActionRequest', + params => [ $product->{'productId'}, $hostId, "setup" ], + id => 1, + }; + my $res = $main::opsi_client->call($main::opsi_url, $callobj); + my ($res_err, $res_err_string) = &check_opsi_res($res); + if ($res_err){ + &main::daemon_log("$session_id ERROR: cannot set product action request for '$hostId': ".$product->{'productId'}, 1); + } else { + &main::daemon_log("$session_id INFO: requesting 'setup' for '".$product->{'productId'}."' on $hostId", 1); } } } } - push(@out_msg_l, &create_xml_string($out_hash)); - } + # Build wakeup message for client - if (not $error) { - my $wakeup_hash = &create_xml_hash("trigger_wake", "GOSA", "KNOWN_SERVER"); - &add_content2xml_hash($wakeup_hash, 'macAddress', $macaddress); - my $wakeup_msg = &create_xml_string($wakeup_hash); - push(@out_msg_l, $wakeup_msg); - - # invoke trigger wake for this gosa-si-server - &main::server_server_com::trigger_wake($wakeup_msg, $wakeup_hash, $session_id); + if (not $error) { + my $wakeup_hash = &create_xml_hash("trigger_wake", "GOSA", "KNOWN_SERVER"); + &add_content2xml_hash($wakeup_hash, 'macAddress', $macaddress); + my $wakeup_msg = &create_xml_string($wakeup_hash); + push(@out_msg_l, $wakeup_msg); + + # invoke trigger wake for this gosa-si-server + &main::server_server_com::trigger_wake($wakeup_msg, $wakeup_hash, $session_id); + } } - - + + # Return messages return @out_msg_l; } ## @method _set_action -# ??? -# @param product - STRING - ??? -# @param action - STRING - ??? -# @param hostId - STRING - ??? +# Set action for an Opsi client +# @param product - STRING - Opsi product +# @param action - STRING - action +# @param hostId - STRING - Opsi hostId sub _set_action { my $product= shift; my $action = shift; @@ -1063,19 +1227,19 @@ sub _set_action { } ## @method _set_state -# ??? -# @param product - STRING - ??? -# @param action - STRING - ??? -# @param hostId - STRING - ??? +# Set state for an Opsi client +# @param product - STRING - Opsi product +# @param action - STRING - state +# @param hostId - STRING - Opsi hostId sub _set_state { my $product = shift; + my $state = shift; my $hostId = shift; - my $action = shift; my $callobj; $callobj = { method => 'setProductState', - params => [ $product, $hostId, $action ], + params => [ $product, $hostId, $state ], id => 1, }; diff --git a/gosa-si/tests/client.php b/gosa-si/tests/client.php index 3481915df..a228df5ff 100755 --- a/gosa-si/tests/client.php +++ b/gosa-si/tests/client.php @@ -130,16 +130,16 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_opsi_get_local_products
GOSA GOSA limux-cl-2.intranet.gonicus.de
"; # Get product properties - global - #$data = "
gosa_opsi_get_product_properties
GOSA GOSA winxppro
"; + #$data = "
gosa_opsi_get_product_properties
GOSA GOSA firefox
"; # Get product properties - per host - #$data = "
gosa_opsi_get_product_properties
GOSA GOSA firefox limux-cl-2.intranet.gonicus.de
"; + #$data = "
gosa_opsi_get_product_properties
GOSA GOSA firefox limux-cl-2.intranet.gonicus.de
"; # Set product properties - global - #$data = "
gosa_opsi_set_product_properties
GOSA 00:01:6c:9d:aa:16 winxppro askbeforeinstfalse
"; + #$data = "
gosa_opsi_set_product_properties
GOSA 00:01:6c:9d:b9:fa firefox askbeforeinstfalse
"; # Set product properties - per host - #$data = "
gosa_opsi_set_product_properties
GOSA 00:01:6c:9d:aa:16 limux-cl-2.intranet.gonicus.de winxppro askbeforeinstfalse
"; + #$data = "
gosa_opsi_set_product_properties
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de firefox askbeforeinst false
"; # Get hardware inventory #$data = "
gosa_opsi_get_client_hardware
GOSA GOSA limux-cl-2.intranet.gonicus.de
"; @@ -151,21 +151,21 @@ for($count = 1; $count <= $zahl; $count++) #$data = "
gosa_opsi_list_clients
GOSA GOSA
"; # Delete Opsi client - #$data = "
gosa_opsi_del_client
GOSA 00:01:6c:9d:aa:16 sdfgsg.intranet.gonicus.de
"; + #$data = "
gosa_opsi_del_client
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de
"; # Install Opsi client + # Please do always use 'job_...' and never 'gosa_...' otherways the job will never appear in job queue #$data = "
job_opsi_install_client
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de 00:11:25:4b:8c:e5
"; # Add Opsi client - $data = "
gosa_opsi_add_client
GOSA 00:01:6c:9d:b9:fa limux-cl-1.intranet.gonicus.de 00:11:25:4b:8c:e6 Test halt 1.2.3.4 Im a note
"; - #$data = "
gosa_opsi_add_client
GOSA 00:01:6c:9d:b9:fa
"; + #$data = "
gosa_opsi_add_client
GOSA 00:01:6c:9d:b9:fa limux-cl-2.intranet.gonicus.de 00:11:25:4b:8c:e5 Test halt 1.2.3.4 Im a note
"; # Add product to Opsi client - #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e6
"; + #$data = "
gosa_opsi_add_product_to_client
GOSA 00:01:6c:9d:b9:fa 00:11:25:4b:8c:e5 limux-cl-2.intranet.gonicus.de winxppro
"; # Delete product from Opsi client - #$data = "
gosa_opsi_del_product_from_client
GOSA 00:01:6c:9d:b9:fa limux-cl-1.intranet.gonicus.de 00:11:25:4b:8c:e6 softprod
"; - #$data = "
gosa_opsi_del_product_from_client
GOSA 00:01:6c:9d:b9:fa
"; + #$data = "
gosa_opsi_del_product_from_client
GOSA 00:01:6c:9d:b9:fa limux-cl-1.intranet.gonicus.de 00:11:25:4b:8c:e5 softprod
"; + ######################### # Mailqueue communication -- 2.30.2