streamlining
This commit is contained in:
18
pin.run
18
pin.run
@@ -10,6 +10,8 @@ locale.setlocale(locale.LC_TIME, "de_DE.utf8")
|
|||||||
|
|
||||||
origin_url = "https://augustiner-kantorei.de/pinnwand"
|
origin_url = "https://augustiner-kantorei.de/pinnwand"
|
||||||
database = "db.cfg"
|
database = "db.cfg"
|
||||||
|
MAX_DATABASEFILESIZE= 100 * 1024 * 1024 # 100 MiB
|
||||||
|
MAX_ARGUMENTLENGTH = 200 # characters
|
||||||
|
|
||||||
def get_arguments():
|
def get_arguments():
|
||||||
"""Wrapper for cgi-environment.
|
"""Wrapper for cgi-environment.
|
||||||
@@ -26,13 +28,13 @@ def get_arguments():
|
|||||||
args = get_arguments()
|
args = get_arguments()
|
||||||
|
|
||||||
oversize=False
|
oversize=False
|
||||||
if os.path.getsize(database) < 100 * 1024 * 1024:
|
if os.path.getsize(database) < MAX_DATABASEFILESIZE:
|
||||||
# only add entries if file size does not exceed 100 MiB
|
# only add entries if file size does not exceed 100 MiB
|
||||||
|
|
||||||
if "ort" in args and "name" in args and "comment" in args:
|
if "ort" in args and "name" in args and "comment" in args:
|
||||||
|
|
||||||
# fail if input is too long
|
# fail if input is too long
|
||||||
if max(map(len, list(args[i] for i in args))) > 200:
|
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
|
# overlong input is a clear indication someone is fiddling with the interface
|
||||||
# this deserves no proper exit message
|
# this deserves no proper exit message
|
||||||
exit()
|
exit()
|
||||||
@@ -40,9 +42,6 @@ if os.path.getsize(database) < 100 * 1024 * 1024:
|
|||||||
# add entry
|
# add entry
|
||||||
try:
|
try:
|
||||||
zeit = datetime.timestamp(datetime(int(args["year"]), int(args["month"]), int(args["day"]), int(args["hour"]), int(args["minute"])))
|
zeit = datetime.timestamp(datetime(int(args["year"]), int(args["month"]), int(args["day"]), int(args["hour"]), int(args["minute"])))
|
||||||
except:
|
|
||||||
exit()
|
|
||||||
try:
|
|
||||||
with open(database, "a") as f:
|
with open(database, "a") as f:
|
||||||
f.write("\t".join(
|
f.write("\t".join(
|
||||||
[
|
[
|
||||||
@@ -54,7 +53,8 @@ if os.path.getsize(database) < 100 * 1024 * 1024:
|
|||||||
]
|
]
|
||||||
))
|
))
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
except Exception as e:
|
except:
|
||||||
|
# an exception here stems most likely from strange arguments and indicates fiddling. no mercy.
|
||||||
exit()
|
exit()
|
||||||
else:
|
else:
|
||||||
oversize = True
|
oversize = True
|
||||||
@@ -192,9 +192,9 @@ else:
|
|||||||
<option>55</option>
|
<option>55</option>
|
||||||
</select>
|
</select>
|
||||||
Zeitpunkt (Tag. Monat. Jahr Stunde:Minute) <br>
|
Zeitpunkt (Tag. Monat. Jahr Stunde:Minute) <br>
|
||||||
<input type="text" name="ort" placeholder="Treffpunkt" maxlength=30/> Treffpunkt<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="name" placeholder="Name" maxlength="30" /> Name<br />
|
||||||
<input type="text" name="comment" placeholder="Bemerkung" maxlength=130/> Bemerkung<br />
|
<input type="text" name="comment" placeholder="Bemerkung" maxlength="130" /> Bemerkung<br />
|
||||||
<input type="submit" name="Absenden" value="Absenden" />
|
<input type="submit" name="Absenden" value="Absenden" />
|
||||||
</form>
|
</form>
|
||||||
""")
|
""")
|
||||||
|
|||||||
Reference in New Issue
Block a user