Code

* gosa-si-server-nobus
[gosa.git] / gosa-si / server / events / logHandling.pm
index 0b636108141245a99e7e75a80e1b3bafff38f910..714b9768e948bdf38681b6d9ecc730a42d9c1d24 100644 (file)
@@ -26,24 +26,39 @@ END {}
 
 ### Start ######################################################################
 
-#&main::read_configfile($main::cfg_file, %cfg_defaults);
 
+#===  FUNCTION  ================================================================
+#         NAME:  get_events
+#   PARAMETERS:  none
+#      RETURNS:  reference of exported events
+#  DESCRIPTION:  tells the caller which functions are available
+#===============================================================================
 sub get_events {
     return \@events
 }
 
+
+#===  FUNCTION  ================================================================
+#         NAME: show_log_by_date
+#  DESCRIPTION: reporting installed hosts matching to regex of date
+#   PARAMETERS: [$msg]        original incoming message
+#               [$msg_hash]   incoming message transformed to hash concerning XML::Simple
+#               [$session_id] POE session id 
+#      RETURNS: gosa-si valid answer string
+#===============================================================================
 sub show_log_by_date {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{header}}[0];
     my $target = @{$msg_hash->{target}}[0];
     my $source = @{$msg_hash->{source}}[0];
     my $date_l =  $msg_hash->{date};
-
+    my $out_msg;
     $header =~ s/gosa_//;
 
     if (not -d $main::client_fai_log_dir) {
-        &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1); 
-        return;
+        my $error_string = "client fai log directory '$main::client_fai_log_dir' do not exist";
+        &main::daemon_log("$session_id ERROR: $error_string", 1); 
+        return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
     }
 
     # build out_msg
@@ -74,10 +89,24 @@ sub show_log_by_date {
         }
     }
 
-    my $out_msg = &create_xml_string($out_hash);
+    $out_msg = &create_xml_string($out_hash);
+    my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+    if (defined $forward_to_gosa) {
+        $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
+    }
+
     return ($out_msg);
 }
 
+
+#===  FUNCTION  ================================================================
+#         NAME: show_log_by_mac
+#  DESCRIPTION: reporting installation dates matching to regex of mac address
+#   PARAMETERS: [$msg]        original incoming message
+#               [$msg_hash]   incoming message transformed to hash concerning XML::Simple
+#               [$session_id] POE session id 
+#      RETURNS: gosa-si valid answer string 
+#===============================================================================
 sub show_log_by_mac {
     my ($msg, $msg_hash, $session_id) = @_;
     my $header = @{$msg_hash->{header}}[0];
@@ -88,8 +117,9 @@ sub show_log_by_mac {
     $header =~ s/gosa_//;
 
     if (not -d $main::client_fai_log_dir) {
-        &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1); 
-        return;
+        my $error_string = "client fai log directory '$main::client_fai_log_dir' do not exist";
+        &main::daemon_log("$session_id ERROR: $error_string", 1); 
+        return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
     }
 
     # build out_msg
@@ -123,10 +153,23 @@ sub show_log_by_mac {
     }
 
     my $out_msg = &create_xml_string($out_hash);
+    my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+    if (defined $forward_to_gosa) {
+        $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
+    }
+
     return ($out_msg);
 }
 
 
+#===  FUNCTION  ================================================================
+#         NAME: show_log_by_date_and_mac
+#  DESCRIPTION: reporting host and installation dates matching to regex of date and regex of mac address
+#   PARAMETERS: [$msg]        original incoming message
+#               [$msg_hash]   incoming message transformed to hash concerning XML::Simple
+#               [$session_id] POE session id 
+#      RETURNS: gosa-si valid answer string 
+#===============================================================================
 sub show_log_by_date_and_mac {
     my ($msg, $msg_hash, $session_id) = @_ ;
     my $header = @{$msg_hash->{header}}[0];
@@ -137,8 +180,9 @@ sub show_log_by_date_and_mac {
     $header =~ s/gosa_//;
 
     if (not -d $main::client_fai_log_dir) {
-        &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1); 
-        return;
+        my $error_string = "client fai log directory '$main::client_fai_log_dir' do not exist"; 
+        &main::daemon_log("$session_id ERROR: $error_string", 1); 
+        return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
     }
 
     # build out_msg
@@ -169,10 +213,23 @@ sub show_log_by_date_and_mac {
     }
 
     my $out_msg = &create_xml_string($out_hash);
+    my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+    if (defined $forward_to_gosa) {
+        $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
+    }
+
     return $out_msg;
 }
 
 
+#===  FUNCTION  ================================================================
+#         NAME: show_log_files_by_date_and_mac
+#  DESCRIPTION: reporting installation log files matching exatly to date and mac address
+#   PARAMETERS: [$msg]        original incoming message
+#               [$msg_hash]   incoming message transformed to hash concerning XML::Simple
+#               [$session_id] POE session id 
+#      RETURNS: gosa-si valid answer string 
+#===============================================================================
 sub show_log_files_by_date_and_mac {
     my ($msg, $msg_hash, $session_id) = @_ ;
     my $header = @{$msg_hash->{header}}[0];
@@ -184,8 +241,9 @@ sub show_log_files_by_date_and_mac {
 
     my $act_log_dir = File::Spec->catdir($main::client_fai_log_dir, $mac, $date);
     if (not -d $act_log_dir) {
-        &main::daemon_log("$session_id ERROR: client fai log directory '$act_log_dir' do not exist", 1); 
-        return;
+        my $error_string = "client fai log directory '$act_log_dir' do not exist";
+        &main::daemon_log("$session_id ERROR: $error_string", 1); 
+        return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
     }
 
     # build out_msg
@@ -204,10 +262,23 @@ sub show_log_files_by_date_and_mac {
     }
 
     my $out_msg = &create_xml_string($out_hash);
+    my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+    if (defined $forward_to_gosa) {
+        $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
+    }
+
     return $out_msg;
 }
 
 
+#===  FUNCTION  ================================================================
+#         NAME: get_log_file_by_date_and_mac
+#  DESCRIPTION: returning the given log file, base64 coded, matching exactly to date and mac address
+#   PARAMETERS: [$msg]        original incoming message
+#               [$msg_hash]   incoming message transformed to hash concerning XML::Simple
+#               [$session_id] POE session id 
+#      RETURNS: gosa-si valid answer string 
+#===============================================================================
 sub get_log_file_by_date_and_mac {
     my ($msg, $msg_hash, $session_id) = @_ ;
     my $header = @{$msg_hash->{header}}[0];
@@ -221,8 +292,9 @@ sub get_log_file_by_date_and_mac {
     # sanity check
     my $act_log_file = File::Spec->catfile($main::client_fai_log_dir, $mac, $date, $log_file);
     if (not -f $act_log_file) {
-        &main::daemon_log("$session_id ERROR: client fai log file '$act_log_file' do not exist or could not be read", 1); 
-        return;
+        my $error_string = "client fai log file '$act_log_file' do not exist or could not be read"; 
+        &main::daemon_log("$session_id ERROR: $error_string", 1); 
+        return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
     }
     
     # read log file
@@ -239,6 +311,11 @@ sub get_log_file_by_date_and_mac {
     my $out_hash = &create_xml_hash($header, $target, $source);
     &add_content2xml_hash($out_hash, $log_file, $log_content);
     my $out_msg = &create_xml_string($out_hash);
+    my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+    if (defined $forward_to_gosa) {
+        $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
+    }
+
     return $out_msg;
 }
 
@@ -253,6 +330,14 @@ sub transform {
 sub by_log_date {
     &transform($a) <=> &transform($b);
 }
+#===  FUNCTION  ================================================================
+#         NAME: get_recent_log_by_mac
+#  DESCRIPTION: reporting the latest installation date matching to regex of mac address
+#   PARAMETERS: [$msg]        original incoming message
+#               [$msg_hash]   incoming message transformed to hash concerning XML::Simple
+#               [$session_id] POE session id 
+#      RETURNS: gosa-si valid answer string 
+#===============================================================================
 sub get_recent_log_by_mac {
     my ($msg, $msg_hash, $session_id) = @_ ;
     my $header = @{$msg_hash->{header}}[0];
@@ -265,9 +350,7 @@ sub get_recent_log_by_mac {
     if (not -d $main::client_fai_log_dir) {
         my $error_string = "client fai log directory '$main::client_fai_log_dir' do not exist";
         &main::daemon_log("$session_id ERROR: $error_string", 1); 
-        my $out_hash = &create_xml_hash($header, $target, $source, $error_string);
-        my $out_msg = &create_xml_string($out_hash);
-        return $out_msg;
+        return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
     }
     
     opendir (DIR, $main::client_fai_log_dir);
@@ -284,9 +367,7 @@ sub get_recent_log_by_mac {
     if (not defined $act_log_dir) {
         my $error_string = "do not find mac '$mac' in directory '$main::client_fai_log_dir'";
         &main::daemon_log("$session_id ERROR: $error_string", 1); 
-        my $out_hash = &create_xml_hash($header, $target, $source, $error_string);
-        my $out_msg = &create_xml_string($out_hash);
-        return $out_msg;
+        return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
     }
 
     # read mac directory
@@ -314,10 +395,24 @@ sub get_recent_log_by_mac {
     }
 
     my $out_msg = &create_xml_string($out_hash);
+    my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+    if (defined $forward_to_gosa) {
+        $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
+    }
+
     return $out_msg;
 }
 
 
+#===  FUNCTION  ================================================================
+#         NAME: delete_log_by_date_and_mac
+#  DESCRIPTION: delete installation date directory matching to regex of date and regex of mac address
+#               missing date or mac is substitutet with regex '.'; if both is missing, deleting is rejected
+#   PARAMETERS: [$msg]        original incoming message
+#               [$msg_hash]   incoming message transformed to hash concerning XML::Simple
+#               [$session_id] POE session id 
+#      RETURNS: gosa-si valid answer string
+#===============================================================================
 sub delete_log_by_date_and_mac {
     my ($msg, $msg_hash, $session_id) = @_ ;
     my $header = @{$msg_hash->{header}}[0];
@@ -329,15 +424,14 @@ sub delete_log_by_date_and_mac {
 
     # sanity check
     if (not -d $main::client_fai_log_dir) {
-        &main::daemon_log("$session_id ERROR: client fai log directory '$main::client_fai_log_dir' do not exist", 1); 
-        return;
+        my $error_string = "client fai log directory '$main::client_fai_log_dir' do not exist";
+        &main::daemon_log("$session_id ERROR: $session_id", 1); 
+        return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
     }
     if ((not defined $date) && (not defined $mac)) {
-        my $err_string = "deleting all log files from gosa-si-server by an empty delete message is not permitted";
-        &main::daemon_log("$session_id INFO: $err_string", 5);
-        my $out_hash = &create_xml_hash($header, $target, $source, $err_string);
-        my $out_msg = &create_xml_string($out_hash);
-        return $out_msg;
+        my $error_string = "deleting all log files from gosa-si-server by an empty delete message is not permitted";
+        &main::daemon_log("$session_id INFO: $error_string", 5);
+        return &create_xml_string(&create_xml_hash($header, $target, $source, $error_string));
     }
     if (not defined $date) { $date = "."; }   # set date to a regular expression matching to everything
     if (not defined $mac) { $mac = "."; }     # set mac to a regular expression matching to everything
@@ -378,6 +472,11 @@ sub delete_log_by_date_and_mac {
     }
 
     my $out_msg = &create_xml_string($out_hash);
+    my $forward_to_gosa = @{$msg_hash->{'forward_to_gosa'}}[0];
+    if (defined $forward_to_gosa) {
+        $out_msg =~s/<\/xml>/<forward_to_gosa>$forward_to_gosa<\/forward_to_gosa><\/xml>/;
+    }
+
     return $out_msg;
 }