-
Notifications
You must be signed in to change notification settings - Fork 0
/
pdf.py
114 lines (90 loc) · 3.74 KB
/
pdf.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from reportlab.lib.pagesizes import letter
from reportlab.lib.styles import getSampleStyleSheet
import json
from reportlab.lib.units import inch, mm
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle, PageTemplate, Frame
def loadFromJsonFile(file):
with open(file, 'r') as file:
return json.load(file)
def create_action_card(filename, scenario, scenario_description, tasks, phase):
doc = SimpleDocTemplate(filename, pagesize=letter)
story = []
styles = getSampleStyleSheet()
# Add scenario title
title = styles['Title']
scenario_title = Paragraph(scenario, title)
story.append(scenario_title)
# Add scenario description
description = styles['BodyText']
scenario_description = Paragraph(scenario_description, description)
story.append(scenario_description)
# Add "OPENING"
opening = Paragraph(phase, styles['Heading2'])
story.append(opening)
story.append(Spacer(1, 12))
# Tasks
data = []
col1 = Paragraph("<b>Task</b>", styles['Heading4'])
col2 = Paragraph("<b>Role</b>", styles['Heading4'])
col3 = Paragraph("<b>Description</b>", styles['Heading4'])
col4 = Paragraph("<b>Priority</b>", styles['Heading4'])
col5 = Paragraph("<b>Done</b>", styles['Heading4'])
data.append([col1, col2, col3, col4, col5])
for task in tasks:
checkbox = " " # empty box for checkbox
task_title = Paragraph("{}".format(task['title']), styles['BodyText'])
task_role = Paragraph("{}".format(task['responsible']), styles['BodyText'])
task_description = Paragraph(task['description'], styles['BodyText'])
task_priority = Paragraph(task['priority'], styles['BodyText'])
data.append([task_title, task_role, task_description, task_priority, checkbox])
# Create table for tasks
table = Table(data, colWidths=[200, 100, 200, 50, 40])
table.setStyle(TableStyle([
('GRID', (0, 0), (-1, -1), 1, 'black'),
('VALIGN', (0, 0), (-1, -1), 'TOP'),
]))
story.append(table)
# Create PDF
doc.build(story)
# TODO: Let user select scenario and then create PDF (use ScenarioLogic.py)
scen_desc = "Crisis Chess Board Incident Scenario for Ransomware Incident."
filename = "ransomware.json"
phase1_tasks = loadFromJsonFile("./01_opening/" + filename)
phase2_tasks = loadFromJsonFile("./02_mid_game/" + filename)
phase3_tasks = loadFromJsonFile("./03_end_game/" + "post-incident-tasks.json")
# Opening PDF
phase = "OPENING"
tasks = []
for task in phase1_tasks:
tasks.append({
"title": task["Description"],
"description": task["Content"],
"responsible": task["Responsible"],
"priority": str(task["Priority"])
})
create_action_card("Opening-ActionCard.pdf", "Ransomware Scenario", scen_desc, tasks, phase)
print("[!] Opening-ActionCard.pdf created")
# Middlegame
phase = "MIDDLEGAME"
tasks = []
for task in phase2_tasks:
tasks.append({
"title": task["Description"],
"description": task["Content"],
"responsible": task["Responsible"],
"priority": str(task["Priority"])
})
create_action_card("Middlegame-ActionCard.pdf", "Ransomware Scenario", scen_desc, tasks, phase)
print("[!] Middlegame-ActionCard.pdf created")
# Endgame
phase = "ENDGAME"
tasks = []
for task in phase3_tasks:
tasks.append({
"title": task["Description"],
"description": task["Content"],
"responsible": task["Responsible"],
"priority": str(task["Priority"])
})
create_action_card("Endgame-ActionCard.pdf", "Ransomware Scenario", scen_desc, tasks, phase)
print("[!] Endgame-ActionCard.pdf created")