def save_as_pdf(self, results, url): tmpdir = mkdtemp() try: options = {"load-error-handling": "ignore"} pdfkit.from_url(url, path.join(tmpdir, 'out.pdf'), options=options) with open(path.join(tmpdir, 'out.pdf'), 'rb') as pdf: pdf_import = AttachedFile.from_content( pdf, 'import.pdf', 'application/pdf') results.investigation.update(import_document=pdf_import) except Exception, e: print e
def save_as_pdf(self, results, url): tmpdir = mkdtemp() try: options = {"load-error-handling": "ignore"} pdfkit.from_url(url, path.join(tmpdir, 'out.pdf'), options=options) with open(path.join(tmpdir, 'out.pdf'), 'rb') as pdf: pdf_import = AttachedFile.from_content(pdf, 'import.pdf', 'application/pdf') results.investigation.update(import_document=pdf_import) except Exception, e: print e
def from_data(cls, data, hash_sha256=None): """Creates a Certificate observable based on raw certificate data and its hash_sha256 value. """ if hash_sha256 is None: hash_sha256 = hashlib.sha256(data).hexdigest() body = AttachedFile.from_content( BytesIO(data), "cert.der", "application/pkix-cert", ) return cls.get_or_create( value="CERT:{}".format(hash_sha256), body=body, )
def do_import(self, results, url): response = requests.get(url, proxies=yeti_config.proxy) content_type = magic.from_buffer(response.content, mime=True) if content_type == "text/html": import_html(results, response.content) self.save_as_pdf(results, url) else: target = AttachedFile.from_content( StringIO(response.content), url, content_type) results.investigation.update(import_document=target) try: method = ImportMethod.objects.get(acts_on=content_type) method.do_import(results, target.filepath) except: raise ValueError( "unsupported file type: '{}'".format(content_type))
def do_import(self, results, url): response = requests.get(url, proxies=yeti_config.proxy) content_type = magic.from_buffer(response.content, mime=True) if content_type == "text/html": import_html(results, response.content) self.save_as_pdf(results, url) else: target = AttachedFile.from_content(StringIO(response.content), url, content_type) results.investigation.update(import_document=target) try: method = ImportMethod.objects.get(acts_on=content_type) method.do_import(results, target.filepath) except: raise ValueError( "unsupported file type: '{}'".format(content_type))