41 lines
1.1 KiB
Python
41 lines
1.1 KiB
Python
#!/usr/bin/env python
|
|
|
|
from quart import Quart, url_for, redirect, session, make_response, render_template, request, send_file, abort, flash
|
|
|
|
app = Quart(__name__)
|
|
app.config.from_envvar('APP_CONFIG')
|
|
if app.config['SECRET_KEY'] is None:
|
|
if (p := Path('/run/secrets/eightserve')).is_file():
|
|
app.config['SECRET_KEY'] = p.read_bytes()
|
|
else:
|
|
app.config['SECRET_KEY'] = os.urandom(32)
|
|
try:
|
|
p.write_bytes(app.config['SECRET_KEY'])
|
|
except:
|
|
pass
|
|
|
|
app.config.update(
|
|
SESSION_COOKIE_SECURE=True,
|
|
SESSION_COOKIE_HTTPONLY=True,
|
|
SESSION_COOKIE_SAMESITE='Lax',
|
|
)
|
|
|
|
|
|
@app.before_request
|
|
async def ensure_session_id():
|
|
if 'session_id' not in session:
|
|
session['session_id'] = str(uuid4())
|
|
|
|
|
|
@app.route('/', methods=['GET', 'POST'])
|
|
async def index():
|
|
return await render_template('index.html')
|
|
|
|
|
|
@app.route('/post', methods=['GET', 'POST'])
|
|
async def post():
|
|
if session.get('consent', False):
|
|
return await fun(*args, **kwargs)
|
|
|
|
else:
|
|
return redirect(url_for('/'))
|