XML WIP
This commit is contained in:
parent
13b987a9c6
commit
7e001c4919
|
@ -154,18 +154,20 @@ if ($debug) {
|
||||||
|
|
||||||
if ($json) {
|
if ($json) {
|
||||||
require 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_obj = JSON->new->allow_nonref;
|
||||||
my $json_text = $json_obj->encode( \%lynis_report_data );
|
my $json_text = $json_obj->encode( \%lynis_report_data );
|
||||||
|
if ($output) {
|
||||||
|
# open the file and write to it
|
||||||
|
open OUT, ">$output" or die colored("There was a problem with the output file: $!", "bold red");
|
||||||
|
print OUT $json_text."\n";
|
||||||
|
close OUT
|
||||||
|
} else {
|
||||||
|
# it's more likely JSON consumers would want to pipe the output to another process
|
||||||
|
# so print to STDOUT
|
||||||
print $json_text;
|
print $json_text;
|
||||||
|
}
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
} elsif ($xml) {
|
||||||
|
|
||||||
if ($xml) {
|
|
||||||
require XML::Writer;
|
require XML::Writer;
|
||||||
my $writer = XML::Writer->new('CONTENT'=>'self','DATA_MODE'=>1,'DATA_INDENT'=>2,);
|
my $writer = XML::Writer->new('CONTENT'=>'self','DATA_MODE'=>1,'DATA_INDENT'=>2,);
|
||||||
$writer->xmlDecl('UTF-8');
|
$writer->xmlDecl('UTF-8');
|
||||||
|
@ -174,11 +176,33 @@ if ($xml) {
|
||||||
if (ref($lynis_report_data{$key}) eq 'ARRAY') {
|
if (ref($lynis_report_data{$key}) eq 'ARRAY') {
|
||||||
my $tmpkey = $key;
|
my $tmpkey = $key;
|
||||||
$tmpkey =~ s/\[\]//g;
|
$tmpkey =~ s/\[\]//g;
|
||||||
|
given ($key) {
|
||||||
|
when (/suggestion\[\]/) {
|
||||||
|
$writer->startTag('suggestions');
|
||||||
|
foreach my $ele ( sort @{$lynis_report_data{$key}} ) {
|
||||||
|
my @parts = split(/\|/, $ele);
|
||||||
|
$writer->emptyTag('suggestion', 'id' => $parts[0], 'description' => $parts[1], 'severity' => $parts[2], 'f4' => $parts[3]);
|
||||||
|
}
|
||||||
|
$writer->endTag();
|
||||||
|
}
|
||||||
|
when (/real_user\[\]/) {
|
||||||
|
$writer->startTag('real_users');
|
||||||
|
foreach my $ele ( sort @{$lynis_report_data{$key}} ) {
|
||||||
|
my ($name,$uid) = split(/\,/, $ele);
|
||||||
|
$writer->startTag('real_user', 'uid' => $uid);
|
||||||
|
$writer->characters($name);
|
||||||
|
$writer->endTag();
|
||||||
|
}
|
||||||
|
$writer->endTag();
|
||||||
|
}
|
||||||
|
default {
|
||||||
$writer->startTag("${tmpkey}s");
|
$writer->startTag("${tmpkey}s");
|
||||||
foreach my $ele ( sort @{$lynis_report_data{$key}} ) {
|
foreach my $ele ( sort @{$lynis_report_data{$key}} ) {
|
||||||
$writer->dataElement($tmpkey, $ele);
|
$writer->dataElement($tmpkey, $ele);
|
||||||
}
|
}
|
||||||
$writer->endTag("${tmpkey}s");
|
$writer->endTag();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$writer->dataElement($key, $lynis_report_data{$key});
|
$writer->dataElement($key, $lynis_report_data{$key});
|
||||||
}
|
}
|
||||||
|
@ -190,9 +214,7 @@ if ($xml) {
|
||||||
}
|
}
|
||||||
print $xml;
|
print $xml;
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
} elsif ($excel) {
|
||||||
|
|
||||||
if ($excel) {
|
|
||||||
require Excel::Writer::XLSX;
|
require Excel::Writer::XLSX;
|
||||||
my $i = 0;
|
my $i = 0;
|
||||||
# do the Excel thing....
|
# do the Excel thing....
|
||||||
|
@ -867,7 +889,7 @@ if ($excel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
open OUT, ">$htmldoc" or die colored("There was a problem opening the output file ($htmldoc): $! \n", "bold red");
|
open OUT, ">$htmldoc" or die colored("There was a problem opening the output file ($htmldoc): $!", "bold red");
|
||||||
print OUT <<END;
|
print OUT <<END;
|
||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
|
Loading…
Reference in New Issue
Block a user