mirror of https://github.com/MISP/PyTaxonomies
Add website to visualize the taxonomies.
parent
d532997e3e
commit
4acccff0f5
|
@ -0,0 +1,3 @@
|
||||||
|
flask
|
||||||
|
flask_bootstrap
|
||||||
|
flask_nav
|
|
@ -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/<name>', 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()
|
|
@ -0,0 +1,24 @@
|
||||||
|
{% extends "bootstrap/base.html" %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
{{ super() }}
|
||||||
|
<script src='{{ url_for('static', filename='jquery.dataTables.min.js') }}'></script>
|
||||||
|
<script src='{{ url_for('static', filename='dataTables.bootstrap.min.js') }}'></script>
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
var table = $('#pytaxonomies_table').DataTable({
|
||||||
|
"pageLength": 25,
|
||||||
|
"lengthMenu": [[25, 25, 100, -1], [25, 50, 100, "All"]]
|
||||||
|
});
|
||||||
|
} );
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block head %}
|
||||||
|
{{ super() }}
|
||||||
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='dataTables.bootstrap.min.css') }}">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block navbar %}
|
||||||
|
{{nav.mynavbar.render()}}
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,60 @@
|
||||||
|
{% extends "main.html" %}
|
||||||
|
{% block title %}Search{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1>Search {% if query %} - {{query}} {%endif%}</h1>
|
||||||
|
|
||||||
|
<form class="form-inline" role="form" action="search" method=post>
|
||||||
|
<div class="form-group">
|
||||||
|
<input type="text" class="form-control" name="query" id=query placeholder="Search a thing ">
|
||||||
|
</div>
|
||||||
|
<button type="submit" class="btn btn-default">Search</button>
|
||||||
|
</form>
|
||||||
|
</br>
|
||||||
|
<div>
|
||||||
|
{% if query and not entries %}
|
||||||
|
Nothing found
|
||||||
|
{%endif%}
|
||||||
|
{% if entries %}
|
||||||
|
<table class="table table-striped table-bordered" id="pytaxonomies_table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Machinetag</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Machinetag</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
{% for mt, val in entries.items() %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{{ url_for('taxonomies', name=val[0].name) }}">{{ val[0].name }}</a></td>
|
||||||
|
<td>
|
||||||
|
{% 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%}
|
||||||
|
</td>
|
||||||
|
<td>{{ mt }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{%endif%}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
|
@ -0,0 +1,39 @@
|
||||||
|
{% extends "main.html" %}
|
||||||
|
{% block title %}Taxonomies{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1>Taxonomies - version {{ all_taxonomies.version }}</h1>
|
||||||
|
<table class="table table-striped table-bordered" id="pytaxonomies_table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Short name</th>
|
||||||
|
<th>Long name</th>
|
||||||
|
<th>Version</th>
|
||||||
|
<th>Entries</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th>Short name</th>
|
||||||
|
<th>Long name</th>
|
||||||
|
<th>Version</th>
|
||||||
|
<th>Entries</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
{% for a, t in all_taxonomies.items() %}
|
||||||
|
<tr>
|
||||||
|
<td><a href="{{ url_for('taxonomies', name=t.name) }}">{{ t.name }}</a></td>
|
||||||
|
<td>{% if t.expanded %} {{ t.expanded }} {%endif%}</td>
|
||||||
|
<td>{{ t.version }}</td>
|
||||||
|
<td>{{ t.amount_entries() }}</td>
|
||||||
|
<td>{{ t.description }}</td>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
{% extends "main.html" %}
|
||||||
|
{% block title %}Taxonomy - {{ taxonomy.name }} {% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1>{% if taxonomy.expanded %}{{ taxonomy.expanded }} {%else%} {{taxonomy.name}} {%endif%} (Version {{ taxonomy.version }})</h1>
|
||||||
|
<h3>{{ taxonomy.description }}</h3>
|
||||||
|
<table class="table table-striped table-bordered" id="pytaxonomies_table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Predicate</th>
|
||||||
|
{% if taxonomy.has_entries() %}
|
||||||
|
<th>Values</th>
|
||||||
|
{% else %}
|
||||||
|
<th>Machinetag</th>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Predicate</th>
|
||||||
|
{% if taxonomy.has_entries() %}
|
||||||
|
<th>Values</th>
|
||||||
|
{% else %}
|
||||||
|
<th>Machinetag</th>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
|
<tbody>
|
||||||
|
{% for p in taxonomy.predicates.values() %}
|
||||||
|
<tr>
|
||||||
|
<td>{% if p.description %}{{ p.description.decode() }}{% endif %}</td>
|
||||||
|
<td>{{ p.predicate }}</td>
|
||||||
|
{% if p.entries %}
|
||||||
|
<td>
|
||||||
|
<table class="table table-striped table-bordered">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Value</th>
|
||||||
|
<th>Expanded</th>
|
||||||
|
<th>Description</th>
|
||||||
|
<th>Machinetag</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for e in p.entries.values() %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ e.value }}</td>
|
||||||
|
<td>{% if e.expanded %}{{ e.expanded.decode() }}{% endif %}</td>
|
||||||
|
<td>{% if e.description %}{{ e.description.decode() }}{% endif %}</td>
|
||||||
|
<td>{{ taxonomy.make_machinetag(p, e) }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</td>
|
||||||
|
{% else %}
|
||||||
|
<td>{{ taxonomy.make_machinetag(p) }}</td>
|
||||||
|
{% endif %}
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -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
|
Loading…
Reference in New Issue