adding rudimentary JSON support
This commit is contained in:
parent
6005466f60
commit
225330465e
|
@ -10,17 +10,20 @@ 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);
|
||||||
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,
|
||||||
|
'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 +35,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 +64,20 @@ 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");
|
else { print colored("HTML ", "bold green"); }
|
||||||
print "\n";
|
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 +107,24 @@ 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");
|
||||||
|
|
||||||
|
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 = JSON->new->allow_nonref;
|
||||||
|
my $json_text = $json->encode( \%lynis_report_data );
|
||||||
|
print $json_text;
|
||||||
|
exit 0;
|
||||||
|
}
|
||||||
|
|
||||||
@{$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');
|
||||||
|
@ -2010,6 +2035,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