Merge branch 'master' of https://github.com/d4t4king/lynis_report
This commit is contained in:
commit
2bc7caf753
|
@ -10,17 +10,21 @@ use Getopt::Long qw( :config no_ignore_case bundling );
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
use Module::Load::Conditional qw( can_load check_install requires );
|
use Module::Load::Conditional qw( can_load check_install requires );
|
||||||
|
|
||||||
my ($help,$verbose,$excel,$output,$pdf);
|
my ($help,$verbose,$excel,$output,$pdf,$debug,$json,$quiet,$xml);
|
||||||
GetOptions(
|
GetOptions(
|
||||||
'h|help' => \$help,
|
'h|help' => \$help,
|
||||||
'v|verbose+' => \$verbose,
|
'v|verbose+' => \$verbose,
|
||||||
'E|excel' => \$excel,
|
'E|excel' => \$excel,
|
||||||
'o|output=s' => \$output,
|
'o|output=s' => \$output,
|
||||||
'p|pdf' => \$pdf,
|
'p|pdf' => \$pdf,
|
||||||
|
'D|debug' => \$debug,
|
||||||
|
'j|json' => \$json,
|
||||||
|
'x|xml' => \$xml,
|
||||||
|
'q|quiet' => \$quiet,
|
||||||
);
|
);
|
||||||
|
|
||||||
&usage if ($help);
|
&usage if ($help);
|
||||||
&usage if (!$output);
|
&usage if ((!$output) and (!$json));
|
||||||
|
|
||||||
my %to_bool = ( 0 => 'false', 1 => 'true' );
|
my %to_bool = ( 0 => 'false', 1 => 'true' );
|
||||||
my %vm_mode = ( 0 => 'false', 1 => 'guest', 2 => 'host' );
|
my %vm_mode = ( 0 => 'false', 1 => 'guest', 2 => 'host' );
|
||||||
|
@ -32,6 +36,8 @@ my %systemd_uf_status_color = (
|
||||||
'masked' => 'goldenrod'
|
'masked' => 'goldenrod'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($json) { $quiet = 1; }
|
||||||
|
|
||||||
my ($basename, $path, $suffix, $htmldoc);
|
my ($basename, $path, $suffix, $htmldoc);
|
||||||
|
|
||||||
if ($excel) {
|
if ($excel) {
|
||||||
|
@ -59,18 +65,22 @@ if (( -e $lynis_report) and ( ! -z $lynis_report )) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($audit_run) and ($audit_run >= 1)) {
|
if (($audit_run) and ($audit_run >= 1)) {
|
||||||
print colored("Looks like the audit has been run.", "bold green");
|
print colored("Looks like the audit has been run.", "bold green") unless ($quiet);
|
||||||
print "\n";
|
print "\n" unless ($quiet);
|
||||||
} else {
|
} else {
|
||||||
print colored("Couldn't find one or more of the lynis output files. Try running the audit again. \n", "bold red");
|
warn colored("Couldn't find one or more of the lynis output files. Try running the audit again. \n", "bold red");
|
||||||
}
|
}
|
||||||
|
|
||||||
print colored("Outputting report to $output, in ", "bold green");
|
unless ($quiet) {
|
||||||
if ($excel) { print colored("Excel ", "bold green"); }
|
print colored("Outputting report to $output, in ", "bold green");
|
||||||
elsif ($pdf) { print colored("PDF ", "bold green)"); }
|
if ($excel) { print colored("Excel ", "bold green"); }
|
||||||
else { print colored("HTML ", "bold green"); }
|
elsif ($pdf) { print colored("PDF ", "bold green)"); }
|
||||||
print colored("format.", "bold green");
|
elsif ($xml) { print colored("XML ", "bold green"); }
|
||||||
print "\n";
|
elsif ($json) { print colored("JSON ", "bold green"); }
|
||||||
|
else { print colored("HTML ", "bold green"); }
|
||||||
|
print colored("format.", "bold green");
|
||||||
|
print "\n";
|
||||||
|
}
|
||||||
|
|
||||||
# the report is easy to process, and actually doesn't contain the "audit findings"....just the data.
|
# the report is easy to process, and actually doesn't contain the "audit findings"....just the data.
|
||||||
# but it is not our job to draw conclusions here, just present the findings of the tool.
|
# but it is not our job to draw conclusions here, just present the findings of the tool.
|
||||||
|
@ -100,6 +110,8 @@ while (my $line = <RPT>) {
|
||||||
}
|
}
|
||||||
close RPT or die colored("There was a problem closing the lynis report: $! \n", "bold red");
|
close RPT or die colored("There was a problem closing the lynis report: $! \n", "bold red");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@{$lynis_report_data{'automation_tool_running[]'}} = &dedup_array($lynis_report_data{'automation_tool_running[]'}) if (ref($lynis_report_data{'automation_tool_running[]'}) eq 'ARRAY');
|
@{$lynis_report_data{'automation_tool_running[]'}} = &dedup_array($lynis_report_data{'automation_tool_running[]'}) if (ref($lynis_report_data{'automation_tool_running[]'}) eq 'ARRAY');
|
||||||
@{$lynis_report_data{'boot_service[]'}} = &dedup_array($lynis_report_data{'boot_service[]'}) if (ref($lynis_report_data{'boot_service[]'}) eq "ARRAY");
|
@{$lynis_report_data{'boot_service[]'}} = &dedup_array($lynis_report_data{'boot_service[]'}) if (ref($lynis_report_data{'boot_service[]'}) eq "ARRAY");
|
||||||
@{$lynis_report_data{'cronjob[]'}} = &dedup_array($lynis_report_data{'cronjob[]'}) if (ref($lynis_report_data{'cronjob[]'}) eq 'ARRAY');
|
@{$lynis_report_data{'cronjob[]'}} = &dedup_array($lynis_report_data{'cronjob[]'}) if (ref($lynis_report_data{'cronjob[]'}) eq 'ARRAY');
|
||||||
|
@ -135,6 +147,51 @@ delete($lynis_report_data{'tests_skipped'});
|
||||||
@tests_executed = @{$lynis_report_data{'tests_executed'}};
|
@tests_executed = @{$lynis_report_data{'tests_executed'}};
|
||||||
delete($lynis_report_data{'tests_executed'});
|
delete($lynis_report_data{'tests_executed'});
|
||||||
|
|
||||||
|
if ($debug) {
|
||||||
|
print Dumper(\%lynis_report_data);
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($json) {
|
||||||
|
require JSON;
|
||||||
|
if ($output) {
|
||||||
|
# open the file and write to it
|
||||||
|
}
|
||||||
|
# it's moe likely JSON consumers would want to pipe the output to another process
|
||||||
|
# so print to STDOUT
|
||||||
|
my $json_obj = JSON->new->allow_nonref;
|
||||||
|
my $json_text = $json_obj->encode( \%lynis_report_data );
|
||||||
|
print $json_text;
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($xml) {
|
||||||
|
require XML::Writer;
|
||||||
|
my $writer = XML::Writer->new('CONTENT'=>'self','DATA_MODE'=>1,'DATA_INDENT'=>2,);
|
||||||
|
$writer->xmlDecl('UTF-8');
|
||||||
|
$writer->startTag('lynisReportData');
|
||||||
|
foreach my $key ( sort keys %lynis_report_data ) {
|
||||||
|
if (ref($lynis_report_data{$key}) eq 'ARRAY') {
|
||||||
|
my $tmpkey = $key;
|
||||||
|
$tmpkey =~ s/\[\]//g;
|
||||||
|
$writer->startTag("${tmpkey}s");
|
||||||
|
foreach my $ele ( sort @{$lynis_report_data{$key}} ) {
|
||||||
|
$writer->dataElement($tmpkey, $ele);
|
||||||
|
}
|
||||||
|
$writer->endTag("${tmpkey}s");
|
||||||
|
} else {
|
||||||
|
$writer->dataElement($key, $lynis_report_data{$key});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$writer->endTag('lynisReportData');
|
||||||
|
my $xml = $writer->end();
|
||||||
|
if ($output) {
|
||||||
|
# open the file and write to it
|
||||||
|
}
|
||||||
|
print $xml;
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
if ($excel) {
|
if ($excel) {
|
||||||
require Excel::Writer::XLSX;
|
require Excel::Writer::XLSX;
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
|
@ -2010,6 +2067,11 @@ if ($verbose) {
|
||||||
# subs
|
# subs
|
||||||
###############################################################################
|
###############################################################################
|
||||||
sub usage {
|
sub usage {
|
||||||
|
|
||||||
|
if (!$output) {
|
||||||
|
print colored("You must specify an output file.\n", "bold yellow");
|
||||||
|
}
|
||||||
|
|
||||||
print <<END;
|
print <<END;
|
||||||
|
|
||||||
$0 -h|--help -v|--verbose -E|--excel -o|--output
|
$0 -h|--help -v|--verbose -E|--excel -o|--output
|
||||||
|
|
Loading…
Reference in New Issue
Block a user