X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-si%2Fmodules%2FGosaSupportDaemon.pm;h=7d769c08ad6ff4e302a900203e214f955cb2b16c;hb=fcfa0de5a118f5e42a0a48bfbb3d355d3e180c51;hp=6a28f8c730ec86655436e30746331836ea399b47;hpb=7cb203854bd5cf5faf614465d1d9290eb23e92ad;p=gosa.git
diff --git a/gosa-si/modules/GosaSupportDaemon.pm b/gosa-si/modules/GosaSupportDaemon.pm
index 6a28f8c73..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)."$tag>";
+ } elsif ( ref $content eq "ARRAY") {
+ $s .= &_transformArrayToString($tag, $content);
+ } else {
+ $content = defined $content ? $content : "";
+ $s .= "<$tag>".&xml_quote($content)."$tag>";
+ }
+ }
+ return $s;
+}
+
+sub _transformArrayToString {
+ my ($tag, $contentArray) = @_;
+ my $s = "";
+ foreach my $content (@$contentArray) {
+ if (ref $content eq "HASH") {
+ $s .= "<$tag>".&_transformHashToString($content)."$tag>";
+ } else {
+ $content = defined $content ? $content : "";
+ $s .= "<$tag>".&xml_quote($content)."$tag>";
+ }
+ }
+ 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
+#
+#
+#
+# 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") {