summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: cccf704)
raw | patch | inline | side by side (parent: cccf704)
author | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 8 Apr 2008 16:18:51 +0000 (16:18 +0000) | ||
committer | rettenbe <rettenbe@594d385d-05f5-0310-b6e9-bd551577e9d8> | |
Tue, 8 Apr 2008 16:18:51 +0000 (16:18 +0000) |
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@10284 594d385d-05f5-0310-b6e9-bd551577e9d8
gosa-si/modules/SIPackages.pm | patch | blob | history | |
gosa-si/server/events/logHandling.pm | patch | blob | history | |
gosa-si/tests/client.php | patch | blob | history |
index 960c666cd81b08f25714ef5ed914cf1fc2331269..4e8705902fa71a76c43613b132a95b8730de400d 100644 (file)
eval{ require $event; };
if( $@ ) {
- &main::daemon_log("import of event module '$event' failed", 1);
+ &main::daemon_log("S ERROR: import of event module '$event' failed", 1);
&main::daemon_log("$@", 8);
next;
}
index bad5d9fc9e166c3821eb475414f4e72da4742398..0b636108141245a99e7e75a80e1b3bafff38f910 100644 (file)
"get_events",
"show_log_by_mac",
"show_log_by_date",
-# "show_log_by_date_and_mac",
-# "get_log_by_date",
-# "get_log_by_mac",
-# "get_log_by_date_and_mac",
-# "get_recent_log_by_mac",
-# "delete_log_by_date_and_mac",
+ "show_log_by_date_and_mac",
+ "show_log_files_by_date_and_mac",
+ "get_log_file_by_date_and_mac",
+ "get_recent_log_by_mac",
+ "delete_log_by_date_and_mac",
);
@EXPORT = @events;
use GOSA::GosaSupportDaemon;
use Data::Dumper;
use File::Spec;
+use MIME::Base64;
BEGIN {}
sub show_log_by_date {
my ($msg, $msg_hash, $session_id) = @_;
my $header = @{$msg_hash->{header}}[0];
- $header =~ s/gosa_//;
my $target = @{$msg_hash->{target}}[0];
my $source = @{$msg_hash->{source}}[0];
-
my $date_l = $msg_hash->{date};
- #my $date_h;
- #map {$date_h->{$_}++} @{$date_l};
+
+ $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);
# build out_msg
my $out_hash = &create_xml_hash($header, $target, $source);
- # fetch mac directory
+ # read mac directory
opendir(DIR, $main::client_fai_log_dir);
my @avail_macs = readdir(DIR);
closedir(DIR);
-
- # goto each mac directory
- # select all dates which matches the parameter dates
- my %res_h;
- foreach my $date ( @{$date_l} ) {
-
- # go through all mac addresses
- foreach my $mac (@avail_macs) {
- if ($mac eq ".." || $mac eq ".") { next; }
-
- # read all installations dates
- my $mac_dir = File::Spec->catdir($main::client_fai_log_dir, $mac);
- opendir(DIR, $mac_dir);
- my @avail_dates = readdir(DIR);
- closedir(DIR);
-
- # go through all dates of one mac address
- foreach my $avail_date (@avail_dates) {
+ foreach my $avail_mac (@avail_macs) {
+ # check mac address
+ if ($avail_mac eq ".." || $avail_mac eq ".") { next; }
+
+ # read install dates directory
+ my $mac_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac);
+ opendir(DIR, $mac_dir);
+ my @avail_dates = readdir(DIR);
+ closedir(DIR);
+ foreach my $date ( @{$date_l} ) { # multiple date selection is allowed
+ foreach my $avail_date (@avail_dates) {
+ # check install date
if ($avail_date eq ".." || $avail_date eq ".") { next; }
- if ($avail_date =~ /$date/i) {
- #$mac =~ s/:/_/g;
- &add_content2xml_hash($out_hash, $avail_date, $mac);
- }
- }
- }
- }
+ if (not $avail_date =~ /$date/i) { next; }
+
+ # add content to out_msg
+ &add_content2xml_hash($out_hash, $avail_date, $avail_mac);
+ }
+ }
+ }
my $out_msg = &create_xml_string($out_hash);
return ($out_msg);
sub show_log_by_mac {
my ($msg, $msg_hash, $session_id) = @_;
my $header = @{$msg_hash->{header}}[0];
- $header =~ s/gosa_//;
my $target = @{$msg_hash->{target}}[0];
my $source = @{$msg_hash->{source}}[0];
my $mac_l = $msg_hash->{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;
}
- # fetch mac directory
+ # build out_msg
+ my $out_hash = &create_xml_hash($header, $target, $source);
+
+ # read mac directory
opendir(DIR, $main::client_fai_log_dir);
my @avail_macs = readdir(DIR);
closedir(DIR);
-
- # build out_msg
- my $out_hash = &create_xml_hash($header, $target, $source);
- foreach my $mac (@{$mac_l}) {
+ foreach my $mac (@{$mac_l}) { # multiple mac selection is allowed
foreach my $avail_mac ( @avail_macs ) {
+ # check mac address
if ($avail_mac eq ".." || $avail_mac eq ".") { next; }
- if ($avail_mac =~ /$mac/i) {
- my $act_log_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac);
- if (not -d $act_log_dir) { next; }
- $avail_mac =~ s/:/_/g;
-
- # fetch mac directory
- opendir(DIR, $act_log_dir);
- my @install_dates = readdir(DIR);
- closedir(DIR);
- foreach my $date (@install_dates) {
- if ($date eq ".." || $date eq ".") { next; }
- &add_content2xml_hash($out_hash, "mac_$avail_mac", $date);
- }
+ if (not $avail_mac =~ /$mac/i) { next; }
+
+ # read install dates directory
+ my $act_log_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac);
+ if (not -d $act_log_dir) { next; }
+ opendir(DIR, $act_log_dir);
+ my @avail_dates = readdir(DIR);
+ closedir(DIR);
+ $avail_mac =~ s/:/_/g; # make mac address XML::Simple valid
+ foreach my $avail_date (@avail_dates) {
+ # check install date
+ if ($avail_date eq ".." || $avail_date eq ".") { next; }
+
+ # add content to out_msg
+ &add_content2xml_hash($out_hash, "mac_$avail_mac", $avail_date);
}
}
}
sub show_log_by_date_and_mac {
my ($msg, $msg_hash, $session_id) = @_ ;
- my $date_l = $msg_hash->{date};
- my $mac_l = $msg_hash->{mac};
-
- print STDERR "###########################################################\n";
- print STDERR "date:".Dumper($date_l);
- print STDERR "mac: ".Dumper($mac_l);
- print STDERR "client_fai_log_dir: $main::client_fai_log_dir\n";
+ my $header = @{$msg_hash->{header}}[0];
+ my $target = @{$msg_hash->{target}}[0];
+ my $source = @{$msg_hash->{source}}[0];
+ my $date = @{$msg_hash->{date}}[0];
+ my $mac = @{$msg_hash->{mac}}[0];
+ $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;
}
- # fetch mac directory
+ # build out_msg
+ my $out_hash = &create_xml_hash($header, $target, $source);
+
+ # read mac directory
opendir(DIR, $main::client_fai_log_dir);
my @avail_macs = readdir(DIR);
closedir(DIR);
+ foreach my $avail_mac ( @avail_macs ) {
+ # check mac address
+ if ($avail_mac eq ".." || $avail_mac eq ".") { next; }
+ if (not $avail_mac =~ /$mac/i) { next; }
+ my $act_log_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac);
- foreach my $avail_mac (@avail_macs) {
- if (not $avail_mac =~ /^([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 ) {
- next;
+ # read install date directory
+ opendir(DIR, $act_log_dir);
+ my @install_dates = readdir(DIR);
+ closedir(DIR);
+ foreach my $avail_date (@install_dates) {
+ # check install date
+ if ($avail_date eq ".." || $avail_date eq ".") { next; }
+ if (not $avail_date =~ /$date/i) { next; }
+
+ # add content to out_msg
+ &add_content2xml_hash($out_hash, $avail_date, $avail_mac);
}
+ }
- print STDERR "mac: $avail_mac\n";
- # fetch date directory
- my $mac_log_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac);
- opendir(DIR, $mac_log_dir);
- my @avail_dates = readdir(DIR);
- closedir(DIR);
- #print STDERR "\@avail_dates:".Dumper(@avail_dates);
+ my $out_msg = &create_xml_string($out_hash);
+ return $out_msg;
+}
+
+
+sub show_log_files_by_date_and_mac {
+ 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 = @{$msg_hash->{date}}[0];
+ my $mac = @{$msg_hash->{mac}}[0];
+ $header =~ s/gosa_//;
+
+ 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;
}
- return;
+ # build out_msg
+ my $out_hash = &create_xml_hash($header, $target, $source);
+
+ # read mac / install date directory
+ opendir(DIR, $act_log_dir);
+ my @log_files = readdir(DIR);
+ closedir(DIR);
+
+ foreach my $log_file (@log_files) {
+ if ($log_file eq ".." || $log_file eq ".") { next; }
+
+ # add content to out_msg
+ &add_content2xml_hash($out_hash, $header, $log_file);
+ }
+
+ my $out_msg = &create_xml_string($out_hash);
+ return $out_msg;
}
-sub get_log_by_date {}
-sub get_log_by_mac {}
-sub get_log_by_date_and_mac {}
-sub fetch_log {}
+sub get_log_file_by_date_and_mac {
+ 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 = @{$msg_hash->{date}}[0];
+ my $mac = @{$msg_hash->{mac}}[0];
+ my $log_file = @{$msg_hash->{log_file}}[0];
+ $header =~ s/gosa_//;
+
+ # 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;
+ }
+
+ # read log file
+ my $log_content;
+ open(FILE, "<$act_log_file");
+ my @log_lines = <FILE>;
+ close(FILE);
+
+ # prepare content for xml sending
+ $log_content = join("", @log_lines);
+ $log_content = &encode_base64($log_content);
+
+ # build out_msg and send
+ 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);
+ return $out_msg;
+}
+
+# sorting function for fai log directory names
+# used by get_recent_log_by_mac
+sub transform {
+ my $a = shift;
+ $a =~ /_(\d{8}?)_(\d{6}?)$/ || return 0;
+ return int("$1$2");
+}
+sub by_log_date {
+ &transform($a) <=> &transform($b);
+}
sub get_recent_log_by_mac {
+ 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 $mac = @{$msg_hash->{mac}}[0];
+ $header =~ s/gosa_//;
+
+ # sanity check
+ 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;
+ }
+
+ opendir (DIR, $main::client_fai_log_dir);
+ my @avail_macs = readdir(DIR);
+ closedir(DIR);
+ my $act_log_dir;
+ my $act_mac;
+ foreach my $avail_mac (@avail_macs) {
+ if ($avail_mac eq ".." || $avail_mac eq ".") { next; }
+ if (not $avail_mac =~ /$mac/i) { next; }
+ $act_log_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac);
+ $act_mac = $avail_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;
+ }
+
+ # read mac directory
+ opendir(DIR, $act_log_dir);
+ my @avail_dates = readdir(DIR);
+ closedir(DIR);
+
+ # search for the latest log
+ my @sorted_dates = sort by_log_date @avail_dates;
+ my $latest_log = pop(@sorted_dates);
+
+ # build out_msg
+ my $out_hash = &create_xml_hash($header, $target, $source);
+
+ # read latest log directory
+ my $latest_log_dir = File::Spec->catdir($main::client_fai_log_dir, $act_mac, $latest_log);
+ opendir(DIR, $latest_log_dir);
+ my @log_files = readdir(DIR);
+ closedir(DIR);
+ # add all log_files to out_msg
+ foreach my $log_file (@log_files) {
+ if ($log_file eq ".." || $log_file eq ".") { next; }
+ &add_content2xml_hash($out_hash, $latest_log, $log_file);
+ }
+
+ my $out_msg = &create_xml_string($out_hash);
+ return $out_msg;
}
sub delete_log_by_date_and_mac {
+ 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 = @{$msg_hash->{date}}[0];
+ my $mac = @{$msg_hash->{mac}}[0];
+ $header =~ s/gosa_//;
+
+ # 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;
+ }
+ 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;
+ }
+ 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
+
+ # build out_msg
+ my $out_hash = &create_xml_hash($header, $target, $source);
+ # read mac directory
+ opendir(DIR, $main::client_fai_log_dir);
+ my @avail_macs = readdir(DIR);
+ closedir(DIR);
+ foreach my $avail_mac ( @avail_macs ) {
+ # check mac address
+ if ($avail_mac eq ".." || $avail_mac eq ".") { next; }
+ if (not $avail_mac =~ /$mac/i) { next; }
+ my $act_log_dir = File::Spec->catdir($main::client_fai_log_dir, $avail_mac);
+
+ # read install date directory
+ opendir(DIR, $act_log_dir);
+ my @install_dates = readdir(DIR);
+ closedir(DIR);
+ foreach my $avail_date (@install_dates) {
+ # check install date
+ if ($avail_date eq ".." || $avail_date eq ".") { next; }
+ if (not $avail_date =~ /$date/i) { next; }
+
+ # delete directory and reptorting
+ my $dir_to_delete = File::Spec->catdir($main::client_fai_log_dir, $avail_mac, $avail_date);
+ #my $error = rmdir($dir_to_delete);
+ my $error = 0;
+ if ($error == 1) {
+ &main::daemon_log("$session_id ERROR: log directory '$dir_to_delete' cannot be deleted: $!", 1);
+ } else {
+ &main::daemon_log("$session_id INFO: log directory '$dir_to_delete' deleted", 5);
+ &add_content2xml_hash($out_hash, $avail_date, $avail_mac);
+ }
+ }
+ }
+
+ my $out_msg = &create_xml_string($out_hash);
+ return $out_msg;
}
1;
index 425c828185fac83dd643fba6283439ab8f26bc79..b46aea2d67277162ae2d6b755fb6ea67ef126501 100755 (executable)
--- a/gosa-si/tests/client.php
+++ b/gosa-si/tests/client.php
################
# logHandling.pm
+# all date and mac parameter accept regular expression as input unless other instructions are given
#$data = "<xml> <header>gosa_show_log_by_mac</header> <target>GOSA</target> <source>GOSA</source> <mac>00:01:6C:9D:B9:FA</mac> <mac>00:01:6c:9d:b9:fb</mac> </xml>";
-$data = "<xml> <header>gosa_show_log_by_date</header> <target>GOSA</target> <source>GOSA</source> <date>20080313</date> <date>20080323</date> </xml>";
-
+#$data = "<xml> <header>gosa_show_log_by_date</header> <target>GOSA</target> <source>GOSA</source> <date>20080313</date> <date>20080323</date> </xml>";
+#$data = "<xml> <header>gosa_show_log_by_date_and_mac</header> <target>GOSA</target> <source>GOSA</source> <date>200803</date> <mac>00:01:6c:9d:b9:FA</mac> </xml>";
+# exact date and mac are required as input for show_log_files_by_date_and_mac
+#$data = "<xml> <header>gosa_show_log_files_by_date_and_mac</header> <target>GOSA</target> <source>GOSA</source> <date>install_20080311_090900</date> <mac>00:01:6c:9d:b9:fa</mac> </xml>";
+# exact date and mac parameter are required as input for get_log_file_by_date_and_mac
+#$data = "<xml> <header>gosa_get_log_file_by_date_and_mac</header> <target>GOSA</target> <source>GOSA</source> <date>install_20080311_090900</date> <mac>00:01:6c:9d:b9:fa</mac> <log_file>boot.log</log_file></xml>";
+#$data = "<xml> <header>gosa_delete_log_by_date_and_mac</header> <target>GOSA</target> <source>GOSA</source> <mac>00:01:6c:9d:b9:fa</mac></xml>";
+# exact mac parameter are required as input for get_recent_log_by_mac
+$data = "<xml> <header>gosa_get_recent_log_by_mac</header> <target>GOSA</target> <source>GOSA</source> <mac>00:01:6c:9d:b9:fA</mac></xml>";