summaryrefslogtreecommitdiffstats
path: root/iv/orodja/napad/nadzor.py
blob: 515aa3e864304df1dea05fa743eedebd42dc12b2 (plain) (blame)
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
#!/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)