X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-si%2Fmodules%2FGosaSupportDaemon.pm;h=7d769c08ad6ff4e302a900203e214f955cb2b16c;hb=bc18340d72a93568de1eb69137ff8565bcf4262f;hp=1301f6605f51f48e7b584d3117d6e5a2d22ad9bb;hpb=88dabea136b599a537f8bcfa4b90ab479b23d6b9;p=gosa.git diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm index 1301f6605..7d769c08a 100644 --- a/gosa-si/modules/GosaSupportDaemon.pm +++ b/gosa-si/modules/GosaSupportDaemon.pm @@ -5,6 +5,8 @@ use Exporter; my @functions = ( "create_passwd", "create_xml_hash", + "createXmlHash", + "myXmlHashToString", "get_content_from_xml_hash", "add_content2xml_hash", "create_xml_string", @@ -44,12 +46,12 @@ use IO::Socket::INET; use Crypt::Rijndael; use Digest::MD5 qw(md5 md5_hex md5_base64); use MIME::Base64; +use XML::Quote qw(:all); use XML::Simple; use Data::Dumper; use Net::DNS; use DateTime; - my $op_hash = { 'eq' => '=', 'ne' => '!=', @@ -67,7 +69,7 @@ END {} ### Start ###################################################################### -my $xml = new XML::Simple(); +our $xml = new XML::Simple(); sub daemon_log { my ($msg, $level) = @_ ; @@ -113,6 +115,91 @@ sub create_xml_hash { return $hash } +sub createXmlHash { + my ($header, $source, $target) = @_; + return { header=>$header, source=>$source, target=>$target}; +} + +sub _transformHashToString { + my ($hash) = @_; + my $s = ""; + + while (my ($tag, $content) = each(%$hash)) { + + if (ref $content eq "HASH") { + $s .= "<$tag>".&_transformHashToString($content).""; + } elsif ( ref $content eq "ARRAY") { + $s .= &_transformArrayToString($tag, $content); + } else { + $content = defined $content ? $content : ""; + $s .= "<$tag>".&xml_quote($content).""; + } + } + return $s; +} + +sub _transformArrayToString { + my ($tag, $contentArray) = @_; + my $s = ""; + foreach my $content (@$contentArray) { + if (ref $content eq "HASH") { + $s .= "<$tag>".&_transformHashToString($content).""; + } else { + $content = defined $content ? $content : ""; + $s .= "<$tag>".&xml_quote($content).""; + } + } + return $s; +} + + +#=== FUNCTION ================================================================ +# NAME: myXmlHashToString +# PARAMETERS: xml_hash - hash - hash from function createXmlHash +# RETURNS: xml_string - string - xml string representation of the hash +# DESCRIPTION: Transforms the given hash to a xml wellformed string. I.e.: +# { +# 'header' => 'a' +# 'source' => 'c', +# 'target' => 'b', +# 'hit' => [ '1', +# '2', +# { +# 'hit31' => 'ABC', +# 'hit32' => 'XYZ' +# } +# ], +# 'res0' => { +# 'res1' => { +# 'res2' => 'result' +# } +# }, +# }; +# +# will be transformed to +# +#
a
+# c +# b +# 1 +# 2 +# +# ABC +# XYZ +# +# +# +# result +# +# +#
+# +#=============================================================================== +sub myXmlHashToString { + my ($hash) = @_; + return "".&_transformHashToString($hash).""; +} + #=== FUNCTION ================================================================ # NAME: create_xml_string @@ -600,6 +687,15 @@ sub get_ip { sub get_interface_for_ip { my $result; my $ip= shift; + + if($ip =~ /^[a-z]/i) { + my $ip_address = inet_ntoa(scalar gethostbyname($ip)); + if(defined($ip_address) && $ip_address =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) { + # Write ip address to $source variable + $ip = $ip_address; + } + } + if ($ip && length($ip) > 0) { my @ifs= &get_interfaces(); if($ip eq "0.0.0.0") { @@ -848,13 +944,19 @@ sub check_opsi_res { 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;