chg: Remove extra code, return unziped resources

pull/197/head
Raphaël Vinot 2021-04-08 01:05:11 +02:00
parent e79387ee0d
commit 4d23d7ac36
2 changed files with 11 additions and 20 deletions

View File

@ -82,12 +82,11 @@ class Lookyloo():
self.logger.warning('Unable to setup the MISP module')
self.context = Context(self.sanejs)
self._captures_index: Dict[str, CaptureCache] = {}
if not self.redis.exists('cache_loaded'):
self._init_existing_dumps()
self._captures_index: Dict[str, CaptureCache] = {}
def cache_user_agents(self, user_agent: str, remote_ip: str) -> None:
'''Cache the useragents of the visitors'''
today = date.today().isoformat()
@ -1092,14 +1091,6 @@ class Lookyloo():
if not hostnode:
raise MissingUUID(f'Unable to find UUID {node_uuid} in {node_uuid}')
cnames_path = ct.root_hartree.har.path.parent / 'cnames.json'
if cnames_path.exists():
with cnames_path.open() as f:
host_cnames = json.load(f)
cnames = self._build_cname_chain(host_cnames, hostnode.name)
if cnames:
hostnode.add_feature('cname', cnames)
known_content = self.context.find_known_content(hostnode)
urls: List[Dict[str, Any]] = []

View File

@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
import base64
from zipfile import ZipFile, ZIP_DEFLATED
from io import BytesIO, StringIO
import os
from pathlib import Path
@ -810,16 +809,17 @@ def get_ressource(tree_uuid: str, node_uuid: str):
else:
h_request = None
ressource = lookyloo.get_ressource(tree_uuid, node_uuid, h_request)
to_return = BytesIO()
with ZipFile(to_return, 'w', ZIP_DEFLATED) as zfile:
if ressource:
filename, r, mimetype = ressource
zfile.writestr(filename, r.getvalue())
else:
zfile.writestr('file.txt', b'Unknown Hash')
if ressource:
filename, to_return, mimetype = ressource
if not mimetype.startswith('image'):
# Force a .txt extension
filename += '.txt'
else:
to_return = BytesIO(b'Unknown Hash')
filename = 'file.txt'
mimetype = 'text/text'
to_return.seek(0)
return send_file(to_return, mimetype='application/zip',
as_attachment=True, attachment_filename='file.zip')
return send_file(to_return, mimetype=mimetype, as_attachment=True, attachment_filename=filename)
@app.route('/tree/<string:tree_uuid>/url/<string:node_uuid>/ressource_preview', methods=['GET'])