From 4acccff0f5ec287a7c96422b1330195aa5d3e89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 5 Oct 2016 18:11:28 +0200 Subject: [PATCH] Add website to visualize the taxonomies. --- website/REQUIREMENTS.txt | 3 ++ website/__init__.py | 60 +++++++++++++++++++++++++++ website/templates/main.html | 24 +++++++++++ website/templates/search.html | 60 +++++++++++++++++++++++++++ website/templates/taxonomies.html | 39 ++++++++++++++++++ website/templates/taxonomy.html | 68 +++++++++++++++++++++++++++++++ website/update_thirdparty.sh | 11 +++++ 7 files changed, 265 insertions(+) create mode 100644 website/REQUIREMENTS.txt create mode 100644 website/__init__.py create mode 100644 website/templates/main.html create mode 100644 website/templates/search.html create mode 100644 website/templates/taxonomies.html create mode 100644 website/templates/taxonomy.html create mode 100755 website/update_thirdparty.sh diff --git a/website/REQUIREMENTS.txt b/website/REQUIREMENTS.txt new file mode 100644 index 0000000..90ef6ca --- /dev/null +++ b/website/REQUIREMENTS.txt @@ -0,0 +1,3 @@ +flask +flask_bootstrap +flask_nav diff --git a/website/__init__.py b/website/__init__.py new file mode 100644 index 0000000..2b74260 --- /dev/null +++ b/website/__init__.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from flask import Flask, request, render_template +from flask_bootstrap import Bootstrap +from flask_nav import Nav +from flask_nav.elements import Navbar, View +from pytaxonomies import Taxonomies + + +nav = Nav() + +@nav.navigation() +def mynavbar(): + return Navbar( + 'MISP taxonomies viewer and editor', + View('Taxonomies', 'taxonomies'), + View('Search', 'search'), + ) + +app = Flask(__name__) +Bootstrap(app) +app.config['BOOTSTRAP_SERVE_LOCAL'] = True +app.debug = True +nav.init_app(app) + +#t = Taxonomies(manifest_path="../../misp-taxonomies/MANIFEST.json") +t = Taxonomies() + +@app.route('/', methods=['GET']) +def index(): + return taxonomies() + +@app.route('/taxonomies/', defaults={'name': None}) +@app.route('/taxonomies/', methods=['GET']) +def taxonomies(name=None): + if name and t.get(name): + return render_template('taxonomy.html', taxonomy=t.get(name)) + else: + return render_template('taxonomies.html', all_taxonomies=t) + +@app.route('/search', methods=['GET', 'POST']) +def search(): + if request.form.get('query'): + q = request.form.get('query') + entries = t.search(q) + if entries: + to_display = {e: t.revert_machinetag(e) for e in entries} + return render_template('search.html', query=q, entries=to_display) + else: + return render_template('search.html', query=q, entries=None) + return render_template('search.html', query=None, entries=None) + + + +def main(): + app.run() + +if __name__ == '__main__': + main() diff --git a/website/templates/main.html b/website/templates/main.html new file mode 100644 index 0000000..f722c1a --- /dev/null +++ b/website/templates/main.html @@ -0,0 +1,24 @@ +{% extends "bootstrap/base.html" %} + +{% block scripts %} + {{ super() }} + + + +{% endblock %} + +{% block head %} + {{ super() }} + +{% endblock %} + +{% block navbar %} + {{nav.mynavbar.render()}} +{% endblock %} diff --git a/website/templates/search.html b/website/templates/search.html new file mode 100644 index 0000000..f895329 --- /dev/null +++ b/website/templates/search.html @@ -0,0 +1,60 @@ +{% extends "main.html" %} +{% block title %}Search{% endblock %} + +{% block content %} +
+

Search {% if query %} - {{query}} {%endif%}

+ +
+
+ +
+ +
+
+
+ {% if query and not entries %} + Nothing found + {%endif%} + {% if entries %} + + + + + + + + + + + + + + + + + {% for mt, val in entries.items() %} + + + + + + {% endfor %} + +
NameDescriptionMachinetag
NameDescriptionMachinetag
{{ val[0].name }} + {% if val|length == 3 %} + {% if val[2].description %} + {{ val[2].description.decode() }} + {% elif val[2].expanded %} + {{ val[2].expanded.decode() }} + {%endif%} + {% elif val[1].description %} + {{ val[1].description.decode() }} + {% else %} + {{ val[1].predicate }} + {%endif%} + {{ mt }}
+ {%endif%} +
+
+{% endblock %} diff --git a/website/templates/taxonomies.html b/website/templates/taxonomies.html new file mode 100644 index 0000000..b8a41c8 --- /dev/null +++ b/website/templates/taxonomies.html @@ -0,0 +1,39 @@ +{% extends "main.html" %} +{% block title %}Taxonomies{% endblock %} + +{% block content %} +
+

Taxonomies - version {{ all_taxonomies.version }}

+ + + + + + + + + + + + + + + + + + + + + {% for a, t in all_taxonomies.items() %} + + + + + + + {% endfor %} + +
Short nameLong nameVersionEntriesDescription
Short nameLong nameVersionEntriesDescription
{{ t.name }}{% if t.expanded %} {{ t.expanded }} {%endif%}{{ t.version }}{{ t.amount_entries() }}{{ t.description }}
+
+{% endblock %} + diff --git a/website/templates/taxonomy.html b/website/templates/taxonomy.html new file mode 100644 index 0000000..8ee6855 --- /dev/null +++ b/website/templates/taxonomy.html @@ -0,0 +1,68 @@ +{% extends "main.html" %} +{% block title %}Taxonomy - {{ taxonomy.name }} {% endblock %} + +{% block content %} +
+

{% if taxonomy.expanded %}{{ taxonomy.expanded }} {%else%} {{taxonomy.name}} {%endif%} (Version {{ taxonomy.version }})

+

{{ taxonomy.description }}

+ + + + + + {% if taxonomy.has_entries() %} + + {% else %} + + {% endif %} + + + + + + + {% if taxonomy.has_entries() %} + + {% else %} + + {% endif %} + + + + {% for p in taxonomy.predicates.values() %} + + + + {% if p.entries %} + + {% else %} + + {% endif %} + + {% endfor %} + +
DescriptionPredicateValuesMachinetag
DescriptionPredicateValuesMachinetag
{% if p.description %}{{ p.description.decode() }}{% endif %}{{ p.predicate }} + + + + + + + + + + + {% for e in p.entries.values() %} + + + + + + + {% endfor %} + +
ValueExpandedDescriptionMachinetag
{{ e.value }}{% if e.expanded %}{{ e.expanded.decode() }}{% endif %}{% if e.description %}{{ e.description.decode() }}{% endif %}{{ taxonomy.make_machinetag(p, e) }}
+
{{ taxonomy.make_machinetag(p) }}
+
+{% endblock %} + diff --git a/website/update_thirdparty.sh b/website/update_thirdparty.sh new file mode 100755 index 0000000..0e59149 --- /dev/null +++ b/website/update_thirdparty.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e +set -x + +DATATABLES='1.10.12' + + +wget https://cdn.datatables.net/${DATATABLES}/js/jquery.dataTables.min.js -O static/jquery.dataTables.min.js +wget https://cdn.datatables.net/${DATATABLES}/js/dataTables.bootstrap.min.js -O static/dataTables.bootstrap.min.js +wget https://cdn.datatables.net/${DATATABLES}/css/dataTables.bootstrap.min.css -O static/dataTables.bootstrap.min.css