1
|
1 |
|
import argparse |
2
|
1 |
|
import uuid |
3
|
1 |
|
from .client import Client |
4
|
1 |
|
from .xml_parser import XmlParser |
5
|
1 |
|
from ._builder_html_report import BuilderHtmlReport |
6
|
|
|
|
7
|
|
|
|
8
|
1 |
|
class ArfToHtmlReport(Client): |
9
|
1 |
|
def __init__(self, args): |
10
|
|
|
self.parser = None |
11
|
|
|
self.MESSAGES = self._get_message() |
12
|
|
|
self.arg = self.parse_arguments(args) |
13
|
|
|
self.source_filename = self.arg.source_filename |
14
|
|
|
self.out = self.arg.output |
15
|
|
|
self.display_html = True if self.out is None else self.arg.display |
16
|
|
|
self.verbose = self.arg.verbose |
17
|
|
|
self.xml_parser = XmlParser(self.source_filename) |
18
|
|
|
self.rule_name = '.' |
19
|
|
|
self.isatty = False |
20
|
|
|
self.show_failed_rules = False |
21
|
|
|
self.all_in_one = True |
22
|
|
|
self.START_OF_FILE_NAME = 'report-' |
23
|
|
|
|
24
|
1 |
|
def _get_message(self): |
25
|
|
|
MESSAGES = { |
26
|
|
|
'description': 'Client for genretate of SCAP report from ARF file.', |
27
|
|
|
'--output': 'The directory where to save output directory with files.', |
28
|
|
|
'source_filename': 'ARF scan file', |
29
|
|
|
} |
30
|
|
|
return MESSAGES |
31
|
|
|
|
32
|
1 |
|
def prepare_data(self, rules): |
33
|
|
|
builder = BuilderHtmlReport( |
34
|
|
|
self.display_html, |
35
|
|
|
self.xml_parser, |
36
|
|
|
self.source_filename) |
37
|
|
|
out_src = builder.save_report_and_open( |
38
|
|
|
self.get_save_src(str(uuid.uuid4()))) |
39
|
|
|
self.open_html(out_src) |
40
|
|
|
return out_src |
41
|
|
|
|
42
|
1 |
|
def prepare_parser(self): |
43
|
|
|
self.parser = argparse.ArgumentParser( |
44
|
|
|
description=self.MESSAGES.get('description')) |
45
|
|
|
self.parser.add_argument( |
46
|
|
|
'-v', |
47
|
|
|
'--verbose', |
48
|
|
|
action="store_true", |
49
|
|
|
default=False, |
50
|
|
|
help="Displays details about the results of the running command.") |
51
|
|
|
self.parser.add_argument( |
52
|
|
|
'-d', |
53
|
|
|
'--display', |
54
|
|
|
action="store_true", |
55
|
|
|
default=False, |
56
|
|
|
help="Enables opening a web browser with a graph, when is used --output.") |
57
|
|
|
self.parser.add_argument( |
58
|
|
|
'-o', |
59
|
|
|
'--output', |
60
|
|
|
action="store", |
61
|
|
|
default=None, |
62
|
|
|
help=self.MESSAGES.get('--output')) |
63
|
|
|
self.parser.add_argument( |
64
|
|
|
"source_filename", |
65
|
|
|
help=self.MESSAGES.get('source_filename')) |
66
|
|
|
|