2020-11-24 19:45:03 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from flask import Flask, render_template, send_from_directory, jsonify, redirect
|
|
|
|
from app.decorators import auth
|
|
|
|
from app.blueprints.ioc import ioc_bp
|
|
|
|
from app.blueprints.whitelist import whitelist_bp
|
|
|
|
from app.blueprints.config import config_bp
|
2021-06-08 18:22:52 +02:00
|
|
|
from app.blueprints.misp import misp_bp
|
2020-11-24 19:45:03 +01:00
|
|
|
import datetime
|
|
|
|
import secrets
|
|
|
|
import jwt
|
|
|
|
from app.utils import read_config
|
|
|
|
from sys import path
|
|
|
|
|
|
|
|
app = Flask(__name__, template_folder="../../app/backend/dist")
|
|
|
|
app.config["SECRET_KEY"] = secrets.token_bytes(32)
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/", methods=["GET"])
|
|
|
|
@auth.login_required
|
|
|
|
def main():
|
|
|
|
"""
|
|
|
|
Return the index.html generated by Vue
|
|
|
|
"""
|
|
|
|
return render_template("index.html")
|
|
|
|
|
|
|
|
|
|
|
|
@app.route("/api/get-token", methods=["GET"])
|
|
|
|
@auth.login_required
|
|
|
|
def get_token():
|
|
|
|
"""
|
|
|
|
Return the JWT token for API requests.
|
|
|
|
"""
|
|
|
|
token = jwt.encode({"exp": datetime.datetime.now() +
|
|
|
|
datetime.timedelta(hours=24)}, app.config["SECRET_KEY"])
|
Update main.py
ERROR in app: Exception on /api/get-token [GET]
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1952, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1821, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/usr/local/lib/python3.7/dist-packages/flask/_compat.py", line 39, in reraise
raise value
File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1950, in full_dispatch_request
rv = self.dispatch_request()
File "/usr/local/lib/python3.7/dist-packages/flask/app.py", line 1936, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/usr/local/lib/python3.7/dist-packages/flask_httpauth.py", line 164, in decorated
return f(*args, **kwargs)
File "/usr/share/sauron/server/backend/main.py", line 37, in get_token
return jsonify({"token": token.decode("utf8")})
AttributeError: 'str' object has no attribute 'decode'
2021-03-23 21:02:41 +01:00
|
|
|
return jsonify({"token": token})
|
2020-11-24 19:45:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
@app.route("/<p>/<path:path>", methods=["GET"])
|
|
|
|
@auth.login_required
|
|
|
|
def get_file(p, path):
|
|
|
|
"""
|
|
|
|
Return the backend assets (css, js files, fonts etc.)
|
|
|
|
"""
|
|
|
|
rp = "../../app/backend/dist/{}".format(p)
|
|
|
|
return send_from_directory(rp, path) if p in ["css", "fonts", "js", "img"] else redirect("/")
|
|
|
|
|
|
|
|
|
|
|
|
@app.errorhandler(404)
|
|
|
|
def page_not_found(e):
|
|
|
|
return redirect("/")
|
|
|
|
|
|
|
|
|
|
|
|
# API Blueprints.
|
|
|
|
app.register_blueprint(ioc_bp, url_prefix='/api/ioc')
|
|
|
|
app.register_blueprint(whitelist_bp, url_prefix='/api/whitelist')
|
|
|
|
app.register_blueprint(config_bp, url_prefix='/api/config')
|
2021-06-08 18:22:52 +02:00
|
|
|
app.register_blueprint(misp_bp, url_prefix='/api/misp')
|
2020-11-24 19:45:03 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
ssl_cert = "{}/{}".format(path[0], 'cert.pem')
|
|
|
|
ssl_key = "{}/{}".format(path[0], 'key.pem')
|
|
|
|
|
|
|
|
if read_config(("backend", "remote_access")):
|
2023-05-30 14:20:09 +02:00
|
|
|
app.run(host="0.0.0.0", port=443, ssl_context=(ssl_cert, ssl_key))
|
2020-11-24 19:45:03 +01:00
|
|
|
else:
|
2023-05-30 14:20:09 +02:00
|
|
|
app.run(port=443)
|