mirror of https://github.com/MISP/misp-modules
Test 1 - PDF call
parent
be01d54779
commit
2d29ce11bb
|
@ -7,61 +7,26 @@ import shlex
|
||||||
import subprocess
|
import subprocess
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from pymisp import MISPEvent
|
from pymisp import MISPEvent, reportlab_generator
|
||||||
|
|
||||||
|
|
||||||
misperrors = {'error': 'Error'}
|
misperrors = {'error': 'Error'}
|
||||||
|
|
||||||
moduleinfo = {'version': '42',
|
moduleinfo = {'version': '2',
|
||||||
'author': 'Raphaël Vinot',
|
'author': 'Vincent Falconieri (prev. Raphaël Vinot)',
|
||||||
'description': 'Simple export to PDF',
|
'description': 'Simple export to PDF',
|
||||||
'module-type': ['export'],
|
'module-type': ['export'],
|
||||||
'require_standard_format': True}
|
'require_standard_format': True}
|
||||||
|
|
||||||
moduleconfig = []
|
moduleconfig = []
|
||||||
|
|
||||||
mispattributes = {}
|
mispattributes = {}
|
||||||
|
|
||||||
outputFileExtension = "pdf"
|
outputFileExtension = "pdf"
|
||||||
responseType = "application/pdf"
|
responseType = "application/pdf"
|
||||||
|
|
||||||
types_to_attach = ['ip-dst', 'url', 'domain']
|
types_to_attach = ['ip-dst', 'url', 'domain']
|
||||||
objects_to_attach = ['domain-ip']
|
objects_to_attach = ['domain-ip']
|
||||||
|
|
||||||
headers = """
|
|
||||||
:toc: right
|
|
||||||
:toclevels: 1
|
|
||||||
:toc-title: Daily Report
|
|
||||||
:icons: font
|
|
||||||
:sectanchors:
|
|
||||||
:sectlinks:
|
|
||||||
= Daily report by {org_name}
|
|
||||||
{date}
|
|
||||||
|
|
||||||
:icons: font
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
event_level_tags = """
|
|
||||||
IMPORTANT: This event is classified TLP:{value}.
|
|
||||||
|
|
||||||
{expanded}
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
attributes = """
|
|
||||||
=== Indicator(s) of compromise
|
|
||||||
|
|
||||||
{list_attributes}
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
title = """
|
|
||||||
== ({internal_id}) {title}
|
|
||||||
|
|
||||||
{summary}
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
class ReportGenerator():
|
class ReportGenerator():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -79,6 +44,9 @@ class ReportGenerator():
|
||||||
self.misp_event = MISPEvent()
|
self.misp_event = MISPEvent()
|
||||||
self.misp_event.load(event)
|
self.misp_event.load(event)
|
||||||
|
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
def attributes(self):
|
def attributes(self):
|
||||||
if not self.misp_event.attributes:
|
if not self.misp_event.attributes:
|
||||||
return ''
|
return ''
|
||||||
|
@ -132,7 +100,7 @@ class ReportGenerator():
|
||||||
self.report += self.title()
|
self.report += self.title()
|
||||||
self.report += self.event_level_tags()
|
self.report += self.event_level_tags()
|
||||||
self.report += self.attributes()
|
self.report += self.attributes()
|
||||||
|
'''
|
||||||
|
|
||||||
def handler(q=False):
|
def handler(q=False):
|
||||||
if q is False:
|
if q is False:
|
||||||
|
@ -144,19 +112,27 @@ def handler(q=False):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
for evt in request['data']:
|
for evt in request['data']:
|
||||||
|
|
||||||
|
'''
|
||||||
|
print(" DATA ")
|
||||||
print(request['data'])
|
print(request['data'])
|
||||||
|
|
||||||
|
reportlab_generator.
|
||||||
|
|
||||||
report = ReportGenerator()
|
report = ReportGenerator()
|
||||||
report.report_headers()
|
report.report_headers()
|
||||||
report.from_event(evt)
|
report.from_event(evt)
|
||||||
report.asciidoc()
|
report.asciidoc()
|
||||||
|
|
||||||
command_line = 'asciidoctor-pdf -'
|
print(" REPORT : ")
|
||||||
args = shlex.split(command_line)
|
print(report)
|
||||||
with subprocess.Popen(args, stdout=subprocess.PIPE, stdin=subprocess.PIPE) as process:
|
'''
|
||||||
cmd_out, cmd_err = process.communicate(
|
misp_event = MISPEvent()
|
||||||
input=report.report.encode('utf-8'))
|
misp_event.load(request['data'])
|
||||||
return {'response': [], 'data': str(base64.b64encode(cmd_out), 'utf-8')}
|
|
||||||
|
pdf = reportlab_generator.get_base64_from_buffer(reportlab_generator.convert_event_in_pdf_buffer(misp_event))
|
||||||
|
|
||||||
|
return {'response': [], 'data': str(pdf, 'utf-8')}
|
||||||
|
|
||||||
|
|
||||||
def introspection():
|
def introspection():
|
||||||
|
|
Loading…
Reference in New Issue