203 lines
5.6 KiB
Python
Executable File
203 lines
5.6 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
print("Content-type: text/html\n")
|
|
print("")
|
|
import os
|
|
import cgi
|
|
from datetime import datetime
|
|
import locale
|
|
locale.setlocale(locale.LC_TIME, "de_DE.utf8")
|
|
|
|
origin_url = "https://augustiner-kantorei.de/pinnwand"
|
|
database = "db.cfg"
|
|
MAX_DATABASEFILESIZE= 100 * 1024 * 1024 # 100 MiB
|
|
MAX_ARGUMENTLENGTH = 200 # characters
|
|
|
|
def get_arguments():
|
|
"""Wrapper for cgi-environment.
|
|
Takes no options, return dict of arguments
|
|
"""
|
|
rawargs = cgi.FieldStorage()
|
|
args = {}
|
|
|
|
for i in rawargs:
|
|
args[i] = rawargs.getvalue(i)
|
|
|
|
return args
|
|
|
|
args = get_arguments()
|
|
|
|
oversize=False
|
|
if os.path.getsize(database) < MAX_DATABASEFILESIZE:
|
|
# only add entries if file size does not exceed 100 MiB
|
|
|
|
if "ort" in args and "name" in args and "comment" in args:
|
|
|
|
# fail if input is too long
|
|
if max(map(len, list(args[i] for i in args))) > MAX_ARGUMENTLENGTH:
|
|
# overlong input is a clear indication someone is fiddling with the interface
|
|
# this deserves no proper exit message
|
|
exit()
|
|
|
|
# add entry
|
|
try:
|
|
zeit = datetime.timestamp(datetime(int(args["year"]), int(args["month"]), int(args["day"]), int(args["hour"]), int(args["minute"])))
|
|
with open(database, "a") as f:
|
|
f.write("\t".join(
|
|
[
|
|
str(zeit),
|
|
args["ort"].replace("\t", ""),
|
|
args["name"].replace("\t", ""),
|
|
args["comment"].replace("\t", "").replace("\n", " ").replace("\r", " "),
|
|
datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
]
|
|
))
|
|
f.write("\n")
|
|
except:
|
|
# an exception here stems most likely from strange arguments and indicates fiddling. no mercy.
|
|
exit()
|
|
else:
|
|
oversize = True
|
|
|
|
# display current entries
|
|
now = datetime.timestamp(datetime.now())
|
|
with open(database, "r") as f:
|
|
content = f.readlines()
|
|
|
|
table = ""
|
|
for line in content:
|
|
tstamp, ort, name, comment, timestamp = line.split("\t")
|
|
if float(tstamp) < now - 60*60:
|
|
continue
|
|
zeit = datetime.fromtimestamp(float(tstamp))
|
|
hzeit = datetime.strftime(zeit, "%a, %d.%m.%Y %H:%M")
|
|
table += f"<tr><td>{hzeit}</td><td>{ort}</td><td>{name}</td><td>{comment}</td></tr>"
|
|
|
|
print(f"""
|
|
<html>
|
|
<head>
|
|
<link rel="stylesheet" type="text/css" href="style.css">
|
|
</head>
|
|
<body>
|
|
<h2>Überschrift</h2>
|
|
<div class="box">
|
|
<h2>Terminangebote</h2>
|
|
Termine werden eine Stunde nach Erreichen des Termins automatisch nicht mehr angezeigt.<br>
|
|
<table border="1" style="color:#cecece">
|
|
<tr><th>Zeitpunkt</th><th>Treffpunkt</th><th>Name</th><th>Bemerkung</th></tr>
|
|
{table}
|
|
</table>
|
|
|
|
<br><br>
|
|
|
|
<h2>Neuer Eintrag</h2>
|
|
""")
|
|
if oversize:
|
|
print("neuer Eintrag derzeit nicht möglich, Datei voll.")
|
|
else:
|
|
print("""
|
|
<form action="https://augustiner-kantorei.de/pinnwand/" method="post" enctype="multipart/form-data">
|
|
<select name="day" size=1>
|
|
<option>1</option>
|
|
<option>2</option>
|
|
<option>3</option>
|
|
<option>4</option>
|
|
<option>5</option>
|
|
<option>6</option>
|
|
<option>7</option>
|
|
<option>8</option>
|
|
<option>9</option>
|
|
<option>10</option>
|
|
<option>11</option>
|
|
<option>12</option>
|
|
<option>13</option>
|
|
<option>14</option>
|
|
<option>15</option>
|
|
<option>16</option>
|
|
<option>17</option>
|
|
<option>18</option>
|
|
<option>19</option>
|
|
<option>20</option>
|
|
<option>21</option>
|
|
<option>22</option>
|
|
<option>23</option>
|
|
<option>24</option>
|
|
<option>25</option>
|
|
<option>26</option>
|
|
<option>27</option>
|
|
<option>28</option>
|
|
<option>29</option>
|
|
<option>30</option>
|
|
<option>31</option>
|
|
</select>
|
|
.
|
|
<select name="month" size=1>
|
|
<option>1</option>
|
|
<option>2</option>
|
|
<option>3</option>
|
|
<option>4</option>
|
|
<option>5</option>
|
|
<option>6</option>
|
|
<option>7</option>
|
|
<option>8</option>
|
|
<option>9</option>
|
|
<option>10</option>
|
|
<option>11</option>
|
|
<option>12</option>
|
|
</select>
|
|
.
|
|
<select name="year" size=1>
|
|
<option>2021</option>
|
|
</select>
|
|
|
|
<select name="hour" size=1>
|
|
<option>0</option>
|
|
<option>1</option>
|
|
<option>2</option>
|
|
<option>3</option>
|
|
<option>4</option>
|
|
<option>5</option>
|
|
<option>6</option>
|
|
<option>7</option>
|
|
<option>8</option>
|
|
<option>9</option>
|
|
<option>10</option>
|
|
<option>11</option>
|
|
<option>12</option>
|
|
<option>13</option>
|
|
<option>14</option>
|
|
<option>15</option>
|
|
<option>16</option>
|
|
<option>17</option>
|
|
<option>18</option>
|
|
<option>19</option>
|
|
<option>20</option>
|
|
<option>21</option>
|
|
<option>22</option>
|
|
<option>23</option>
|
|
</select>
|
|
:
|
|
<select name="minute" size=1>
|
|
<option>00</option>
|
|
<option>05</option>
|
|
<option>10</option>
|
|
<option>15</option>
|
|
<option>20</option>
|
|
<option>25</option>
|
|
<option>30</option>
|
|
<option>35</option>
|
|
<option>40</option>
|
|
<option>45</option>
|
|
<option>50</option>
|
|
<option>55</option>
|
|
</select>
|
|
Zeitpunkt (Tag. Monat. Jahr Stunde:Minute) <br>
|
|
<input type="text" name="ort" placeholder="Treffpunkt" maxlength="30" /> Treffpunkt<br />
|
|
<input type="text" name="name" placeholder="Name" maxlength="30" /> Name<br />
|
|
<input type="text" name="comment" placeholder="Bemerkung" maxlength="130" /> Bemerkung<br />
|
|
<input type="submit" name="Absenden" value="Absenden" />
|
|
</form>
|
|
""")
|
|
print("</div><div class=foot>Augustiner-Pinnwand - ein Service von <a href=https://dukun.de>dukun.de</a><br><a href=mailto:pinnwandrueckmeldung@augustiner-kantorei.de>Rückmeldung</a></div></body> </html>")
|
|
|