Excel work....

This commit is contained in:
dataking 2016-07-26 13:56:33 -07:00
commit d435db2d41

View File

@ -7,6 +7,8 @@ no if $] ge '5.018', warnings => "experimental::smartmatch";
use Term::ANSIColor;
use Getopt::Long qw( :config no_ignore_case bundling );
use Data::Dumper;
#use Spreadsheet::WriteExcel;
use Excel::Writer::XLSX;
my ($help,$verbose,$excel,$output);
GetOptions(
@ -21,7 +23,11 @@ if ($help) { &usage; }
my %to_bool = ( 0 => 'false', 1 => 'true' );
my %to_long_severity = ( 'C' => 'Critical', 'S' => 'Severe', 'H' => 'High', 'M' => 'Medium', 'L' => 'Low', 'I' => 'Informational' );
if ($excel) {
$output = 'report.xlsx' unless ((defined($output)) and ($output ne ""));
} else {
$output = "report.html" unless ((defined($output)) and ($output ne ""));
}
my $lynis_log = '/var/log/lynis.log';
my $lynis_report = '/var/log/lynis-report.dat';
@ -112,6 +118,46 @@ delete($lynis_report_data{'tests_executed'});
#print Dumper(\%warnings);
if ($excel) {
# do the Excel thing....
my $wb = Excel::Writer::XLSX->new($output);
my $title_format = $wb->add_format();
$title_format->set_size('32');
my $subtitle_format = $wb->add_format();
$subtitle_format->set_size('24');
my $subsub_format = $wb->add_format();
$subsub_format->set_size('16');
my $summary_ws = $wb->add_worksheet('Summary');
$summary_ws->write('B2', "lynis Asset Report", $title_format);
$summary_ws->write('B3', "created by ");
$summary_ws->write_url('C3', "http://github.com/d4t4king/lynis_report.git", '', 'lynis_report');
$summary_ws->write('A4', "Host Findings:", $subtitle_format);
$summary_ws->write('A5', "hardening index:");
$summary_ws->write('B5', $lynis_report_data{'hardening_index'});
$summary_ws->write('A7', "warnings \(".scalar(@{$lynis_report_data{'warning[]'}})."\):", $subsub_format);
my @table_data;
my $header_row = [ 'Warning ID', 'Description', 'Severity', 'F4' ];
if (exists($lynis_report_data{'warning[]'})) {
if (ref($lynis_report_data{'warning[]'}) eq 'ARRAY') {
if ($lynis_report_data{'warning[]'}[0] =~ /\|/) {
foreach my $warn ( sort @{$lynis_report_data{'warning[]'}} ) {
my ($warn_id,$warn_desc,$warn_sev,$warn_f4) = split(/\|/, $warn);
push @table_data, [$warn_id,$warn_desc,$warn_sev,$warn_f4];
}
}
}
}
my %params = (
'data' => \@table_data,
'header_row' => $header_row,
);
my $last_row_number = 8 + scalar(@table_data);
$summary_ws->add_table("A8:D$last_row_number", \%params);
} else {
open OUT, ">$output" or die colored("There was a problem opening the output file ($output): $! \n", "bold red");
print OUT <<END;
@ -632,6 +678,8 @@ my @indexes = qw( lynis_version lynis_tests_done lynis_update_available license_
foreach my $idx ( sort @indexes ) {
delete($lynis_report_data{$idx});
}
}
#print Dumper(\%lynis_report_data);
###############################################################################