blob: 515aa3e864304df1dea05fa743eedebd42dc12b2 (
plain) (
tree)
|
|
#!/usr/bin/python3
from flask import Flask, render_template, request
import os
import sqlite3
import sys
app = Flask(__name__)
@app.route("/", methods=["GET"])
def frontend():
return render_template("frontend.html")
@app.route("/sql", methods=["POST"])
def sql():
with sqlite3.connect(os.getenv("SUBMISSION_DB", "flags.db")) as db:
db.setconfig(sqlite3.SQLITE_DBCONFIG_DEFENSIVE, True)
rows = []
for row in db.execute(request.data.decode()):
columns = []
for column in row:
if type(column) == bytes:
columns.append(column.decode("utf-8", errors="surrogateescape"))
else:
columns.append(column)
rows.append(columns)
return rows
if __name__ == "__main__":
port = 21503
host = "::"
if len(sys.argv) > 1:
port = int(sys.argv[1])
if len(sys.argv) > 2:
host = sys.argv[2]
app.run(port=port, debug=True, host=host)
|