forked from server/reporter
add templates and static files
This commit is contained in:
parent
9ec7d6fe8c
commit
21a046f537
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
__pycache__/
|
||||||
7
Readme.rst
Normal file
7
Readme.rst
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Run
|
||||||
|
* `pip3 install -r src/requirements.txt`
|
||||||
|
* `cd src`
|
||||||
|
* `FLASK_APP=spammer.py flask run`
|
||||||
|
|
||||||
|
Docker
|
||||||
|
* `docker-compose up`
|
||||||
@ -4,3 +4,5 @@ services:
|
|||||||
rzspam:
|
rzspam:
|
||||||
build: .
|
build: .
|
||||||
image: docker.wiai.de/fswiai/rzspam:0.1
|
image: docker.wiai.de/fswiai/rzspam:0.1
|
||||||
|
ports:
|
||||||
|
- 5000:5000
|
||||||
@ -2,11 +2,9 @@ import json
|
|||||||
from collections import namedtuple
|
from collections import namedtuple
|
||||||
from string import Formatter
|
from string import Formatter
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask, render_template, request
|
||||||
from flask import request
|
|
||||||
from flask_mail import Mail, Message
|
from flask_mail import Mail, Message
|
||||||
|
|
||||||
import templates
|
|
||||||
|
|
||||||
Placeholder = namedtuple("Placeholder", ["name", "type", "desc", "default"])
|
Placeholder = namedtuple("Placeholder", ["name", "type", "desc", "default"])
|
||||||
|
|
||||||
@ -22,20 +20,22 @@ def load_config(conf="config.json"):
|
|||||||
default=p_h.get("default"))
|
default=p_h.get("default"))
|
||||||
placeholders.append(p)
|
placeholders.append(p)
|
||||||
config.pop("placeholders")
|
config.pop("placeholders")
|
||||||
flat = {}
|
flat = []
|
||||||
for org in config:
|
for org in config:
|
||||||
target = config[org]
|
target = config[org]
|
||||||
templates = []
|
templates = []
|
||||||
for issue_name in target["templates"]:
|
for issue_name in target["templates"]:
|
||||||
text = target["templates"][issue_name]
|
text = target["templates"][issue_name]
|
||||||
fields = [name for _, name, _, _ in Formatter().parse(text)]
|
fields = [name for _, name, _, _ in Formatter().parse(text)]
|
||||||
flat[f"{org}: {issue_name}"] = {
|
name = f"{org}: {issue_name}"
|
||||||
|
value = json.dumps({
|
||||||
"org": org,
|
"org": org,
|
||||||
"name": issue_name,
|
"name": issue_name,
|
||||||
"mail": config[org]["mail"],
|
"mail": config[org]["mail"],
|
||||||
"text": text,
|
"text": text,
|
||||||
"placeholders": [i._asdict() for i in placeholders if i.name in fields]
|
"placeholders": [i._asdict() for i in placeholders if i.name in fields]
|
||||||
}
|
})
|
||||||
|
flat.append({"name": name, "value": value})
|
||||||
return flat
|
return flat
|
||||||
|
|
||||||
MAIL_SERVER = "smtp.uni-bamberg.de"
|
MAIL_SERVER = "smtp.uni-bamberg.de"
|
||||||
@ -56,7 +56,7 @@ issues = load_config()
|
|||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
return templates.format_index(issues)
|
return render_template("index.html", issues=issues)
|
||||||
|
|
||||||
@app.route("/send", methods=["POST"])
|
@app.route("/send", methods=["POST"])
|
||||||
def send():
|
def send():
|
||||||
@ -73,7 +73,8 @@ def send():
|
|||||||
recipients = [request.form["target"]]
|
recipients = [request.form["target"]]
|
||||||
msg = Message("Störungsmeldung", body=text, sender=sender, recipients=recipients)
|
msg = Message("Störungsmeldung", body=text, sender=sender, recipients=recipients)
|
||||||
print(msg)
|
print(msg)
|
||||||
return str(mail.send(msg))
|
if not mail.send(msg) is None:
|
||||||
|
return "Success!"
|
||||||
print([(field,field in request.form) for field in fields])
|
print([(field,field in request.form) for field in fields])
|
||||||
return "2"
|
return "2"
|
||||||
print([(field,field in request.form) for field in ("text", "sender", "target")])
|
print([(field,field in request.form) for field in ("text", "sender", "target")])
|
||||||
|
|||||||
@ -1,9 +1,3 @@
|
|||||||
import json
|
|
||||||
BASE = """<!doctype html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<title>spammer</title>
|
|
||||||
<script>
|
|
||||||
function selection() {
|
function selection() {
|
||||||
var x = document.getElementById("issue").value;
|
var x = document.getElementById("issue").value;
|
||||||
var data = JSON.parse(x)
|
var data = JSON.parse(x)
|
||||||
@ -40,37 +34,3 @@ function selection() {
|
|||||||
placeholders.appendChild(z);
|
placeholders.appendChild(z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
"""
|
|
||||||
|
|
||||||
INDEX = """<h1>Welcome</h1>
|
|
||||||
<p>choose an issue, fill the placeholders, enter your uni-mail, then hit send</p>
|
|
||||||
|
|
||||||
<form action="send" method="post">
|
|
||||||
<p>
|
|
||||||
<select name="issue" required onchange="selection()" id="issue">
|
|
||||||
<option selected disabled="true">---</option>
|
|
||||||
{issues}
|
|
||||||
</select>
|
|
||||||
</p>
|
|
||||||
<p><textarea id="text" readonly required name="text"></textarea></p>
|
|
||||||
<p>
|
|
||||||
<label for="sender">absender:</label>
|
|
||||||
<input type="email" required="true" name="sender" id="sender" placeholder="sender email" readonly>
|
|
||||||
</p>
|
|
||||||
<div id="placeholders" ></div>
|
|
||||||
<input type="submit">
|
|
||||||
</form>
|
|
||||||
"""
|
|
||||||
|
|
||||||
def format_page(body):
|
|
||||||
return BASE + str(body) + "</body>\n</html>"
|
|
||||||
|
|
||||||
def format_index(issues):
|
|
||||||
html = ""
|
|
||||||
for issue in issues:
|
|
||||||
html+=f"<option value='{json.dumps(issues[issue])}'>{issue}</option>\n"
|
|
||||||
index = INDEX.format(issues=html)
|
|
||||||
return format_page(index)
|
|
||||||
3
src/static/style.css
Normal file
3
src/static/style.css
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
body {
|
||||||
|
background-color: aqua;
|
||||||
|
}
|
||||||
11
src/templates/base.html
Normal file
11
src/templates/base.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>spammer</title>
|
||||||
|
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
|
||||||
|
<script type="application/javascript" src="{{url_for('static', filename='script.js') }}"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% block body %} {% endblock %}
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
24
src/templates/index.html
Normal file
24
src/templates/index.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block body %}
|
||||||
|
<h1>Welcome</h1>
|
||||||
|
<p>choose an issue, fill the placeholders, enter your uni-mail, then hit send</p>
|
||||||
|
|
||||||
|
<form action="send" method="post">
|
||||||
|
<p>
|
||||||
|
<select name="issue" required onchange="selection()" id="issue">
|
||||||
|
<option selected disabled="true">---</option>
|
||||||
|
|
||||||
|
{% for issue in issues %}
|
||||||
|
<option value="{{issue.value}}">{{ issue.name }}</option>
|
||||||
|
{% endfor %}
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
<p><textarea id="text" readonly required name="text"></textarea></p>
|
||||||
|
<p>
|
||||||
|
<label for="sender">absender:</label>
|
||||||
|
<input type="email" required="true" name="sender" id="sender" placeholder="sender email" readonly>
|
||||||
|
</p>
|
||||||
|
<div id="placeholders" ></div>
|
||||||
|
<input type="submit">
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
||||||
Loading…
x
Reference in New Issue
Block a user