-
Notifications
You must be signed in to change notification settings - Fork 11
/
app.py
executable file
·80 lines (63 loc) · 2.28 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/python3
import json
import os
import sys
import utils
from classes import *
from flask import Flask, abort, jsonify, render_template, request
configfile = "options.json"
devicefile = "kernels.json"
forceDBUpdate = False
app = Flask(__name__)
dir = os.path.dirname(__file__)
if not os.path.isfile(os.path.join(dir, configfile)):
print("Could not find " + configfile + " aborting!")
sys.exit()
with open(os.path.join(dir, configfile)) as config_file:
config = json.load(config_file)
with open(os.path.join(dir, devicefile)) as device_file:
devices = json.load(device_file)
connect(config['dbname'], host=config['dbhost'])
@app.route("/")
def index():
return render_template('index.html', kernels=Kernel.objects().order_by('vendor', 'device'))
@app.route("/<string:k>")
def kernel(k):
try:
kernel = Kernel.objects.get(repo_name=k)
except:
abort(404)
patches = Patches.objects(kernel=Kernel.objects.get(repo_name=k).id)
patched = len(Patches.objects(kernel=Kernel.objects.get(repo_name=k).id, status=Status.objects.get(text='patched').id))
if k in devices:
devs = devices[k]
else:
devs = ['No officially supported devices!']
return render_template('kernel.html',
kernel = kernel,
patched = patched,
cves = CVE.objects().order_by('cve_name'),
status_ids = Status.objects(),
patches = patches,
devices = devs)
@app.route("/update", methods=['POST'])
def update():
r = request.get_json()
k = r['kernel_id'];
c = r['cve_id'];
s = r['status_id'];
Patches.objects(kernel=k, cve=c).update(status=Status.objects.get(short_id=s).id)
patched = len(Patches.objects(kernel=k, status=Status.objects.get(text='patched').id))
return jsonify({'error': 'success', 'patched': patched})
@app.route("/getlinks", methods=['POST'])
def getlinks():
r = request.get_json()
c = r['cve_id'];
return Links.objects(cve_id=c).to_json()
if __name__ == "__main__":
if "port" in config:
port=config['port']
else:
port=5000
# TODO: add something to check github every day for new kernel repos and call getKernelTableFromGithub()
app.run(host="0.0.0.0", debug=True, port=port)