|
1
|
1 |
|
import webbrowser |
|
2
|
1 |
|
import json |
|
3
|
1 |
|
import os |
|
4
|
1 |
|
import argparse |
|
5
|
1 |
|
import shutil |
|
6
|
1 |
|
from datetime import datetime |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
1 |
|
from .client import Client |
|
10
|
1 |
|
from .oval_node import restore_dict_to_tree |
|
11
|
1 |
|
from .converter import Converter |
|
12
|
|
|
|
|
13
|
|
|
|
|
14
|
1 |
|
class JsonToHtml(Client): |
|
15
|
1 |
|
def __init__(self, args): |
|
16
|
1 |
|
self.parser = None |
|
17
|
1 |
|
self.arg = self.parse_arguments(args) |
|
18
|
1 |
|
self.off_webbrowser = self.arg.off_web_browser |
|
19
|
1 |
|
self.source_filename = self.arg.source_filename |
|
20
|
1 |
|
self.out = self.arg.output |
|
21
|
1 |
|
self.oval_tree = None |
|
22
|
|
|
|
|
23
|
1 |
|
def load_json_to_oval_tree(self): |
|
24
|
1 |
|
with open(self.source_filename, 'r') as f: |
|
25
|
1 |
|
try: |
|
26
|
1 |
|
return restore_dict_to_tree(json.load(f)) |
|
27
|
|
|
except Exception as error: |
|
28
|
|
|
raise ValueError("err- Used file is not json or valid.") |
|
29
|
|
|
|
|
30
|
1 |
|
def create_dict_of_oval_node(self, oval_node): |
|
31
|
1 |
|
converter = Converter(oval_node) |
|
32
|
1 |
|
return converter.to_JsTree_dict() |
|
33
|
|
|
|
|
34
|
1 |
|
def prepare_data(self): |
|
35
|
1 |
|
try: |
|
36
|
1 |
|
out = [] |
|
37
|
1 |
|
self.oval_tree = self.load_json_to_oval_tree() |
|
38
|
1 |
|
rule_name = self.oval_tree.node_id |
|
39
|
1 |
|
oval_tree_dict = self.create_dict_of_oval_node(self.oval_tree) |
|
40
|
1 |
|
src = self.get_save_src(rule_name) |
|
41
|
1 |
|
self.copy_interpreter(src) |
|
42
|
1 |
|
self.save_dict(oval_tree_dict, src) |
|
43
|
1 |
|
self.open_web_browser(src) |
|
44
|
1 |
|
print('Rule "{}" done!'.format(rule_name)) |
|
45
|
1 |
|
out.append(src) |
|
46
|
1 |
|
return out |
|
47
|
|
|
except Exception as error: |
|
48
|
|
|
raise ValueError( |
|
49
|
|
|
'Rule: "{}" Error: "{}"'.format( |
|
50
|
|
|
self.source_filename, error)) |
|
51
|
|
|
|
|
52
|
1 |
|
def prepare_parser(self): |
|
53
|
1 |
|
self.parser = argparse.ArgumentParser( |
|
54
|
|
|
description="Client for visualization of SCAP rule evaluation results") |
|
55
|
1 |
|
self.parser.add_argument( |
|
56
|
|
|
'--off-web-browser', |
|
57
|
|
|
action="store_true", |
|
58
|
|
|
default=False, |
|
59
|
|
|
help="It does not start the web browser.") |
|
60
|
1 |
|
self.parser.add_argument( |
|
61
|
|
|
'--output', |
|
62
|
|
|
action="store", |
|
63
|
|
|
default=None, |
|
64
|
|
|
help="Save the output files where it is defined.") |
|
65
|
|
|
self.parser.add_argument("source_filename", help="ARF scan file") |
|
66
|
|
|
|