-
Notifications
You must be signed in to change notification settings - Fork 0
/
vulpy.py
executable file
·55 lines (42 loc) · 1.34 KB
/
vulpy.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
#!/usr/bin/env python3
from pathlib import Path
from flask import Flask, g, redirect, request, render_template
import libsession
from mod_api import mod_api
from mod_csp import mod_csp
from mod_hello import mod_hello
from mod_mfa import mod_mfa
from mod_posts import mod_posts
from mod_user import mod_user
app = Flask('vulpy')
app.config['SECRET_KEY'] = 'aaaaaaa'
app.register_blueprint(mod_hello, url_prefix='/hello')
app.register_blueprint(mod_user, url_prefix='/user')
app.register_blueprint(mod_posts, url_prefix='/posts')
app.register_blueprint(mod_mfa, url_prefix='/mfa')
app.register_blueprint(mod_csp, url_prefix='/csp')
app.register_blueprint(mod_api, url_prefix='/api')
csp_file = Path('csp.txt')
csp = ''
if csp_file.is_file():
with csp_file.open() as f:
for line in f.readlines():
if line.startswith('#'):
continue
line = line.replace('\n', '')
if line:
csp += line
if csp:
print('CSP:', csp)
@app.route('/')
def do_home():
return render_template('welcome.html')
@app.before_request
def before_request():
g.session = libsession.load(request)
@app.after_request
def add_csp_headers(response):
if csp:
response.headers['Content-Security-Policy'] = csp
return response
app.run(debug=True, host='0.0.0.0', port=5000, extra_files='csp.txt')