|
@@ -1,4 +1,6 @@
|
|
|
import hashlib
|
|
|
+import random
|
|
|
+from pathlib import Path
|
|
|
import json
|
|
|
import logging
|
|
|
import os
|
|
@@ -22,6 +24,15 @@ UPLOAD_DIR = os.getenv("UPLOAD_DIR", "./uploads/")
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
app.logger.setLevel(logging.DEBUG)
|
|
|
|
|
|
+def testo_random(basepath):
|
|
|
+ '''Per sembrare meno spammosi, alleghiamo una bella poesia.
|
|
|
+ Che idea di merda'''
|
|
|
+ if not basepath:
|
|
|
+ return ''
|
|
|
+ texts = list(Path(basepath).rglob('*.txt'))
|
|
|
+ if not texts:
|
|
|
+ return ''
|
|
|
+ return random.sample(texts, k=1)[0].open(encoding='utf8').read().strip()
|
|
|
|
|
|
def sendmail(sender, to, subject, body):
|
|
|
# msg = MIMEText(body)
|
|
@@ -33,6 +44,7 @@ def sendmail(sender, to, subject, body):
|
|
|
p = Popen(args, stdin=PIPE)
|
|
|
# p.communicate(msg.as_bytes())
|
|
|
p.communicate(body.encode("utf8"))
|
|
|
+ logging.info("mando mail a %s", str(to))
|
|
|
|
|
|
|
|
|
def read_config():
|
|
@@ -54,9 +66,11 @@ def home():
|
|
|
|
|
|
@app.route("/<site>")
|
|
|
def site(site):
|
|
|
+ logging.debug("Visito %s", site)
|
|
|
try:
|
|
|
sitedata = read_config()["sites"][site]
|
|
|
except KeyError:
|
|
|
+ logging.debug("Sito %s non definito", site)
|
|
|
sitedata = {}
|
|
|
return render_template("index.htm", siteid=site, sitedata=sitedata)
|
|
|
|
|
@@ -83,20 +97,23 @@ def upload(site):
|
|
|
if to:
|
|
|
sender = os.getenv("MAIL_FROM", "")
|
|
|
if not sender:
|
|
|
- app.logger.info("Not sending email (unconfigured FROM)")
|
|
|
+ logging.info("Not sending email (unconfigured FROM)")
|
|
|
else:
|
|
|
- app.logger.debug("Sending email for `%s` to `%s`", site, ";".join(to))
|
|
|
- url = url_for("dl", fname=fname, _external=True, _scheme="https")
|
|
|
+ logging.debug("Sending email for `%s` to `%s`", site, ";".join(to))
|
|
|
+ url = url_for("play", fname=fname, _external=True, _scheme="https")
|
|
|
sendmail(
|
|
|
sender,
|
|
|
to,
|
|
|
subject="Nuovo messaggio (%s)" % site,
|
|
|
body="Alle {now:%H:%M} hai ricevuto un messaggio nella segreteria di {site}\n"
|
|
|
"Puoi ascoltarlo cliccando su\n{url}\n"
|
|
|
- "Per scaricare l'audio, troverai un link dentro la pagina"
|
|
|
- "---\n"
|
|
|
- "Il servizio è gentilmente offerto da degenerazione.xyz".format(
|
|
|
- now=datetime.now(), site=site, url=url
|
|
|
+ "Per scaricare l'audio, troverai un link dentro la pagina\n\n"
|
|
|
+ "Il servizio è gentilmente offerto da degenerazione.xyz\n\n"
|
|
|
+ "Al fine di aumentare la vostra cultura, "
|
|
|
+ "e di far contento spamssassain, "
|
|
|
+ "ecco una bella poesia:\n\n{text}".format(
|
|
|
+ now=datetime.now(), site=site, url=url,
|
|
|
+ text=testo_random(os.getenv('TEXT_DIR', None)),
|
|
|
),
|
|
|
)
|
|
|
else:
|