commit 20e5b88daeaab8efa7a55ace2dbf9ef572d4b566 Author: Thomas Lindner Date: Tue Nov 9 00:23:07 2021 +0100 collect ALL the data diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a9240e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.*.swp +db.sqlite +/venv/ diff --git a/datentrog b/datentrog new file mode 100644 index 0000000..1920e1b --- /dev/null +++ b/datentrog @@ -0,0 +1,11 @@ +#!/bin/ksh + +daemon="/var/lib/datentrog/venv/bin/python3 /var/lib/datentrog/datentrog.py" +daemon_user="datentrog" + +. /etc/rc.d/rc.subr + +rc_bg=YES +rc_reload=NO + +rc_cmd $1 diff --git a/datentrog.py b/datentrog.py new file mode 100755 index 0000000..62b4f1a --- /dev/null +++ b/datentrog.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +import bottle +import sqlite3 + + +application = bottle.default_app() +connection = sqlite3.connect("db.sqlite") +cursor = connection.cursor() +cursor.execute(""" + CREATE TABLE IF NOT EXISTS visitors ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + event TEXT, + time DATETIME, + name TEXT, + address TEXT, + contact TEXT + ); + """) + + +@application.get("/") +@bottle.view("datentrog.tpl") +def datentrog_get(): + return dict(event=bottle.request.query.get("event", "Heizhaus")) + + +@application.post("/") +@bottle.view("datentrog.tpl") +def datentrog_post(): + data = {"feedback": True, "success": True} + for field in ("event", "name", "address", "contact"): + data[field] = bottle.request.forms.get(field, "") + data["success"] = data["success"] and data[field] + if data["success"]: + cursor.execute(""" + INSERT INTO visitors (event, time, name, address, contact) + VALUES (:event, datetime('now'), :name, :address, :contact); + """, data) + connection.commit() + return data + + +@application.get("/cleanup") +def cleanup(): + cursor.execute(""" + DELETE FROM visitors WHERE time < datetime('now', '-1 month'); + """) + connection.commit() + + +if __name__ == "__main__": + bottle.run(host="0.0.0.0", port=8080) +else: + application.catchall = False diff --git a/datentrog.tpl b/datentrog.tpl new file mode 100644 index 0000000..3451b4d --- /dev/null +++ b/datentrog.tpl @@ -0,0 +1,50 @@ + + + + Corona-Kontaktformular - {{ get("event", "Heizhaus") }} + + + + +
+

Corona-Kontaktformular

+ % if get("success", False): +

Erfolgreich registriert.

+
+ + +
+ % else: +

Die Daten werden nach 1 Monat gelöscht und ausschließlich zur Corona-Kontaktverfolgung verwendet.

+
+
+ + +
+
+ + + % if get("feedback", False): + + % end +
+
+ + + % if get("feedback", False): + + % end +
+
+ + + % if get("feedback", False): + + % end +
+ +
+ % end +
+ + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..310dc0b --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +bottle