bug fixes; fixes XML output to file and STDOUT

This commit is contained in:
d4t4king 2016-11-25 21:32:02 -08:00
parent 55a41fbc9e
commit 2c790320e3

View File

@ -241,7 +241,14 @@ if ($json) {
undef(%lynis_report_data); undef(%lynis_report_data);
} elsif ($xml) { } elsif ($xml) {
require XML::Writer; require XML::Writer;
my $writer = XML::Writer->new('CONTENT'=>'self','DATA_MODE'=>1,'DATA_INDENT'=>2,); my ($xmlout,$writer);
if (($xml) and ($output)) {
require IO::File;
$xmlout = IO::File->new(">$output");
$writer = XML::Writer->new('CONTENT'=>'self','DATA_MODE'=>1,'DATA_INDENT'=>2,'OUTPUT'=>$xmlout);
} else {
$writer = XML::Writer->new('CONTENT'=>'self','DATA_MODE'=>1,'DATA_INDENT'=>2,);
}
$writer->xmlDecl('UTF-8'); $writer->xmlDecl('UTF-8');
$writer->startTag('lynisReportData'); $writer->startTag('lynisReportData');
foreach my $key ( sort keys %lynis_report_data ) { foreach my $key ( sort keys %lynis_report_data ) {
@ -323,12 +330,10 @@ if ($json) {
$writer->endTag('lynisReportData'); $writer->endTag('lynisReportData');
my $xml = $writer->end(); my $xml = $writer->end();
if ($output) { if ($output) {
# open the file and write to it $xmlout->close();
open OUT, ">$output" or die colored("There was a problem opening the output ($output) file for writing: $! ", "bold red"); } else {
print OUT $xml; print $xml;
close OUT or die colored("There was a problem closing the output file ($output) after writing: $! ", "bold red");
} }
print $xml if (($verbose) and ($verbose > 1));
# XML is parsed directly from the report data array, using the XML::Writer module. So there should be no unhandled key-value pairs. # XML is parsed directly from the report data array, using the XML::Writer module. So there should be no unhandled key-value pairs.
# So just undef the hash. # So just undef the hash.