summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cead0ab)
raw | patch | inline | side by side (parent: cead0ab)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 28 Sep 2009 14:36:16 +0000 (14:36 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Mon, 28 Sep 2009 14:36:16 +0000 (14:36 +0000) |
* extended function check_opsi_res at GosaSupportDaemon.pm
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14379 594d385d-05f5-0310-b6e9-bd551577e9d8
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@14379 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/modules/GosaSupportDaemon.pm | patch | blob | history | |
gosa-si/server/events/opsi_com.pm | patch | blob | history | |
gosa-si/tests/client.php | patch | blob | history |
index 1301f6605f51f48e7b584d3117d6e5a2d22ad9bb..6a28f8c730ec86655436e30746331836ea399b47 100644 (file)
if ($res->is_error) {
my $error_string;
if (ref $res->error_message eq "HASH") {
+ # for different versions
$error_string = $res->error_message->{'message'};
+ $_ = $res->error_message->{'message'};
} else {
+ # for different versions
$error_string = $res->error_message;
+ $_ = $res->error_message;
}
return 1, $error_string;
}
} else {
+ # for different versions
+ $_ = $main::opsi_client->status_line;
return 1, $main::opsi_client->status_line;
}
return 0;
index 040f4a9b9542e3076a83fb12eaf7a8db5e9c22b7..567e6119fc0bcfcb7d43225a39ee3d070cdeeeb4 100644 (file)
"opsi_getLicensePools_listOfHashes",
"opsi_getLicenseInformationForProduct",
"opsi_getPool",
+ "opsi_getAllSoftwareLicenses",
"opsi_removeLicense",
"opsi_getReservedLicenses",
"opsi_boundHostToLicense",
#
# @brief Writes the log line and returns the error message for GOsa.
#
-sub _give_feedback {
- my ($msg, $msg_hash, $session_id, $error) = @_;
- &main::daemon_log("$session_id ERROR: $error: ".$msg, 1);
- my $out_hash = &main::create_xml_hash("error", $main::server_address, @{$msg_hash->{'source'}}[0], $error);
- return &create_xml_string($out_hash);
+sub _giveErrorFeedback {
+ my ($msg_hash, $err_string, $session_id) = @_;
+ &main::daemon_log("$session_id ERROR: $err_string", 1);
+ my $out_hash = &main::create_xml_hash("error", $main::server_address, @{$msg_hash->{source}}[0], $err_string);
+ if (exists $msg_hash->{forward_to_gosa}) {
+ &add_content2xml_hash($out_hash, "forward_to_gosa", @{$msg_hash->{'forward_to_gosa'}}[0]);
+ }
+ return ( &create_xml_string($out_hash) );
}
+
## @method opsi_add_product_to_client
# Adds an Opsi product to an Opsi client.
# @param msg - STRING - xml message with tags hostId and productId
my $source = @{$msg_hash->{'source'}}[0];
my $target = @{$msg_hash->{'target'}}[0];
my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
- my ($hostId, $productId);
- my $error = 0;
# Build return message
my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
# Sanity check of needed parameter
if ((not exists $msg_hash->{'hostId'}) || (@{$msg_hash->{'hostId'}} != 1) || (@{$msg_hash->{'hostId'}}[0] eq ref 'HASH')) {
- $error++;
- &add_content2xml_hash($out_hash, "error_string", "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);
-
+ return &_giveErrorFeedback($msg_hash, "no hostId specified or hostId tag invalid", $session_id);
}
if ((not exists $msg_hash->{'productId'}) || (@{$msg_hash->{'productId'}} != 1) || (@{$msg_hash->{'productId'}}[0] eq ref 'HASH')) {
- $error++;
- &add_content2xml_hash($out_hash, "error_string", "no productId specified or productId tag invalid");
- &add_content2xml_hash($out_hash, "error", "productId");
- &main::daemon_log("$session_id ERROR: no productId specified or procutId tag invalid: $msg", 1);
+ return &_giveErrorFeedback($msg_hash, "no productId specified or productId tag invalid", $session_id);
}
- if (not $error) {
- # Get hostId
- $hostId = @{$msg_hash->{'hostId'}}[0];
- &add_content2xml_hash($out_hash, "hostId", $hostId);
+ # Get hostId
+ my $hostId = @{$msg_hash->{'hostId'}}[0];
+ &add_content2xml_hash($out_hash, "hostId", $hostId);
- # Get productID
- $productId = @{$msg_hash->{'productId'}}[0];
- &add_content2xml_hash($out_hash, "productId", $productId);
+ # Get productID
+ my $productId = @{$msg_hash->{'productId'}}[0];
+ &add_content2xml_hash($out_hash, "productId", $productId);
- # Do an action request for all these -> "setup".
- my $callobj = {
- method => 'setProductActionRequest',
- params => [ $productId, $hostId, "setup" ],
- id => 1, };
+ # Do an action request for all these -> "setup".
+ my $callobj = {
+ method => 'setProductActionRequest',
+ params => [ $productId, $hostId, "setup" ],
+ 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("$session_id ERROR: cannot add product: ".$sres_err_string, 1);
- &add_content2xml_hash($out_hash, "error", $sres_err_string);
- }
- }
+ my $res = $main::opsi_client->call($main::opsi_url, $callobj);
+ if (&check_opsi_res($res)) { return ( (caller(0))[3]." : ".$_, 1 ); };
# return message
return ( &create_xml_string($out_hash) );
if (&_check_xml_tag_is_ok ($msg_hash, 'licensePoolId')) {
$licensePoolId = @{$msg_hash->{'licensePoolId'}}[0];
} else {
- return ( &_giveErrorFeedback($msg_hash, "", $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, "", $session_id, $_);
}
# Fetch infos from Opsi server
if (&_check_xml_tag_is_ok ($msg_hash, 'productId')) {
$productId= @{$msg_hash->{'productId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Fetch licensePoolId for productId
if (&_check_xml_tag_is_ok ($msg_hash, 'softwareLicenseId')) {
$softwareLicenseId = @{$msg_hash->{'softwareLicenseId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
my $callobj = {
if (&_check_xml_tag_is_ok ($msg_hash, 'licensePoolId')) {
$licensePoolId = @{$msg_hash->{'licensePoolId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Fetch softwareLicenseIds used in license pool
if (&_check_xml_tag_is_ok ($msg_hash, 'licenseKey')) {
$licenseKey = @{$msg_hash->{'licenseKey'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
if (&_check_xml_tag_is_ok ($msg_hash, 'licensePoolId')) {
$licensePoolId = @{$msg_hash->{'licensePoolId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
if ((defined $licenseType) && (not exists $licenseTyp_hash->{$licenseType})) {
- return ( &_give_feedback($msg, $msg_hash, $session_id, "The typ of a license can be either 'OEM', 'VOLUME' or 'RETAIL'."));
+ return &_giveErrorFeedback($msg_hash, "The typ of a license can be either 'OEM', 'VOLUME' or 'RETAIL'.", $session_id);
}
# Automatically define licenseContractId if ID is not given
if (&_check_xml_tag_is_ok ($msg_hash, 'hostId')) {
$hostId = @{$msg_hash->{'hostId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
if (&_check_xml_tag_is_ok ($msg_hash, 'licensePoolId')) {
$licensePoolId = @{$msg_hash->{'licensePoolId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Assign a software license to a host
if (&_check_xml_tag_is_ok ($msg_hash, 'hostId')) {
$hostId = @{$msg_hash->{'hostId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
if (&_check_xml_tag_is_ok ($msg_hash, 'licensePoolId')) {
$licensePoolId = @{$msg_hash->{'licensePoolId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Unassign a software license from a host
if (&_check_xml_tag_is_ok ($msg_hash, 'hostId')) {
$hostId = @{$msg_hash->{'hostId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Unassign all software licenses from a host
if (&_check_xml_tag_is_ok ($msg_hash, 'productId')) {
$productId = @{$msg_hash->{'productId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Fetch infos from Opsi server
if (&_check_xml_tag_is_ok ($msg_hash, 'licensePoolId')) {
$licensePoolId = @{$msg_hash->{'licensePoolId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Create hash for the answer
if (&_check_xml_tag_is_ok ($msg_hash, 'softwareLicenseId')) {
$softwareLicenseId = @{$msg_hash->{'softwareLicenseId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
my $licensePoolId;
if (&_check_xml_tag_is_ok ($msg_hash, 'licensePoolId')) {
$licensePoolId = @{$msg_hash->{'licensePoolId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Call Opsi
if (&_check_xml_tag_is_ok ($msg_hash, 'hostId')) {
$hostId = @{$msg_hash->{'hostId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Fetch informations from Opsi server
if (&_check_xml_tag_is_ok ($msg_hash, 'hostId')) {
$hostId = @{$msg_hash->{'hostId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
my $softwareLicenseId;
if (&_check_xml_tag_is_ok ($msg_hash, 'softwareLicenseId')) {
$softwareLicenseId = @{$msg_hash->{'softwareLicenseId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Fetch informations from Opsi server
}
if (not $found) {
- return ( &_give_feedback($msg, $msg_hash, $session_id, "no softwarelicenseId found with name '".$softwareLicenseId."'") );
+ return &_giveErrorFeedback($msg_hash, "no softwarelicenseId found with name '".$softwareLicenseId."'", $session_id);
}
# Set boundToHost option for a given software license
if (&_check_xml_tag_is_ok ($msg_hash, 'softwareLicenseId')) {
$softwareLicenseId = @{$msg_hash->{'softwareLicenseId'}}[0];
} else {
- return ( &_give_feedback($msg, $msg_hash, $session_id, $_) );
+ return &_giveErrorFeedback($msg_hash, $_, $session_id);
}
# Memorize parameter witch are required for this procedure
return ( &create_xml_string($out_hash) );
}
+################################
+#
+# @brief
+# @param
+#
+sub opsi_getAllSoftwareLicenses {
+ my ($msg, $msg_hash, $session_id) = @_;
+ my $header = @{$msg_hash->{'header'}}[0];
+ my $source = @{$msg_hash->{'source'}}[0];
+
+ my ($res, $err) = &_getSoftwareLicenses_listOfHashes();
+ if ($err) {
+ return &_giveErrorFeedback($msg_hash, "cannot fetch software licenses from Opsi server : ".$res, $session_id);
+ }
+
+ # Parse result
+ my $res_hash = { 'hit'=> [] };
+ foreach my $license ( @$res) {
+ my $license_hash = { 'softwareLicenseId' => [$license->{'softwareLicenseId'}],
+ 'maxInstallations' => [$license->{'maxInstallations'}],
+ 'boundToHost' => [$license->{'boundToHost'}],
+ 'expirationDate' => [$license->{'expirationDate'}],
+ 'licenseContractId' => [$license->{'licenseContractId'}],
+ 'licenseType' => [$license->{'licenseType'}],
+ 'licensePoolIds' => [],
+ 'licenseKeys'=> {}
+ };
+ foreach my $licensePoolId (@{$license->{'licensePoolIds'}}) {
+ push( @{$license_hash->{'licensePoolIds'}}, $licensePoolId);
+ $license_hash->{licenseKeys}->{$licensePoolId} = [ $license->{'licenseKeys'}->{$licensePoolId} ];
+ }
+ push( @{$res_hash->{hit}}, $license_hash );
+ }
+
+ my $out_hash = &main::create_xml_hash("answer_$header", $main::server_address, $source);
+ $out_hash->{licenses} = [$res_hash];
+ return ( &create_xml_string($out_hash) );
+}
+
sub opsi_test {
my ($msg, $msg_hash, $session_id) = @_;
my $header = @{$msg_hash->{'header'}}[0];
return ();
}
-sub _giveErrorFeedback {
- my ($msg_hash, $err_string, $session_id) = @_;
- &main::daemon_log("$session_id ERROR: $err_string", 1);
- my $out_hash = &main::create_xml_hash("error", $main::server_address, @{$msg_hash->{source}}[0], $err_string);
- return ( &create_xml_string($out_hash) );
-}
+
sub _getLicensePool_hash {
index d98a5f93d6d322d433f20653e628fa20211a383b..f01246d9ebffef2860422c38ad033ea01e5e6c88 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
#$sock = new Socket_Client("10.89.1.42","20081",TRUE,5);
#$sock->setEncryptionKey("secret-gosa-password");
+ $mac = "00:01:6C:9D:B9:FA"; # ws-muc-02
+
if($sock->connected()){
# Funktioniert noch nicht
#$data = "<xml><header>gosa_opsi_getReservedLicenses</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><hostId>krakenarme.intranet.gonicus.de</hostId></xml>";
- $data = "<xml><header>gosa_opsi_boundHostToLicense</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><softwareLicenseId>andisLizenz</softwareLicenseId><hostId>krakenarme.intranet.gonicus.de</hostId></xml>";
+ #$data = "<xml><header>gosa_opsi_boundHostToLicense</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><softwareLicenseId>andisLizenz</softwareLicenseId><hostId>krakenarme.intranet.gonicus.de</hostId></xml>";
#$data = "<xml><header>gosa_opsi_unboundHostFromLicense</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target><softwareLicenseId>andisLizenz</softwareLicenseId></xml>";
+ $data = "<xml><header>gosa_opsi_getAllSoftwareLicenses</header><source>GOSA</source><target>00:01:6C:9D:B9:FA</target></xml>";
+
##############################
# periodical jobs
#$data = "<xml> <header>gosa_opsi_add_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <macaddress>00:11:25:4b:8c:e5</macaddress> <description>Test halt</description> <ip>1.2.3.4</ip> <notes>Im a note</notes> </xml>";
# Add product to Opsi client
- #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>winxppro</productId> </xml>";
+ #$data = "<xml><header>gosa_opsi_add_product_to_client</header><source>GOSA</source><target>$mac</target><hostId>linux-cl-2.intranet.gonicus.de</hostId><productId>winxppro</productId></xml>";
+ #$data = "<xml><header>gosa_opsi_add_product_to_client</header><source>GOSA</source><target>$mac</target><hostId>linux-cl-2.intranet.gonicus.de</hostId><productId>acroread</productId></xml>";
#$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>preloginloader</productId> </xml>";
- #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>opsi-adminutils</productId> </xml>";
- #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>xpconfig</productId> </xml>";
- #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>hwaudit</productId> </xml>";
- #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>javavm</productId> </xml>";
- #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>firefox</productId> </xml>";
- #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>flashplayer</productId> </xml>";
+
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>opsi-adminutils</productId> </xml>";
+
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>xpconfig</productId> </xml>";
+
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>hwaudit</productId> </xml>";
+
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>javavm</productId> </xml>";
+
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>firefox</productId> </xml>";
+
+ #$data = "<xml> <header>gosa_opsi_add_product_to_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <macaddress>00:11:25:4b:8c:e5</macaddress> <hostId>linux-cl-2.intranet.gonicus.de</hostId> <productId>flashplayer</productId> </xml>";
# Delete product from Opsi client
#$data = "<xml> <header>gosa_opsi_del_product_from_client</header> <source>GOSA</source> <target>00:01:6c:9d:b9:fa</target> <hostId>linux-cl-1.intranet.gonicus.de</hostId> <macaddress>00:11:25:4b:8c:e5</macaddress> <productId>wipedisk</productId> </xml>";