helpdesk
parent
6e467b35e9
commit
7005888d34
|
@ -5,10 +5,14 @@ import random
|
|||
import time
|
||||
from sys import argv
|
||||
from tempfile import mkdtemp, mkstemp
|
||||
|
||||
from pyhocon import ConfigFactory
|
||||
import requests
|
||||
from flask import Flask, render_template, request, redirect
|
||||
|
||||
from stats import get_data
|
||||
|
||||
## disgusting hack for python 3.4
|
||||
## disgusting hack for python 3.4.0
|
||||
import pkgutil
|
||||
orig_get_loader = pkgutil.get_loader
|
||||
def get_loader(name):
|
||||
|
@ -17,12 +21,17 @@ def get_loader(name):
|
|||
except AttributeError:
|
||||
pass
|
||||
pkgutil.get_loader = get_loader
|
||||
###########
|
||||
##########
|
||||
|
||||
SITE_NAME = 'tilde.town'
|
||||
|
||||
app = Flask('~cgi')
|
||||
|
||||
@lru_cache(maxsize=32)
|
||||
def cfg(k):
|
||||
conf = ConfigFactory.parse_file('cfg.conf')
|
||||
return conf[k]
|
||||
|
||||
@lru_cache(maxsize=32)
|
||||
def site_context():
|
||||
return get_data()
|
||||
|
@ -73,8 +82,43 @@ def post_guestbook():
|
|||
return redirect("/guestbook")
|
||||
|
||||
@app.route('/helpdesk', methods=['GET'])
|
||||
def helpdesk():
|
||||
return "HELPDESK UNDER CONSTRUCTION"
|
||||
def get_helpdesk():
|
||||
status = request.args.get('status', 'unsubmitted')
|
||||
desc = request.args.get('desc', '')
|
||||
context = {
|
||||
'status': status,
|
||||
'desc': desc,
|
||||
}
|
||||
context.update(site_context())
|
||||
return render_template('helpdesk.html', **context)
|
||||
|
||||
def send_email(data):
|
||||
name = data.get('name', 'anonymous')
|
||||
email = data['email']
|
||||
request_type = data['type']
|
||||
desc = request.form['desc']
|
||||
response = requests.post(
|
||||
cfg('mailgun_url'),
|
||||
auth=("api", cfg('mailgun_key')),
|
||||
data={"from": "root@tilde.town",
|
||||
"to": cfg('trello'),
|
||||
"subject": "{} from {} <{}>".format(request_type, name, email),
|
||||
"text": desc})
|
||||
|
||||
return response.status_code == 200
|
||||
|
||||
@app.route('/helpdesk', methods=['POST'])
|
||||
def post_helpdesk():
|
||||
desc = request.form['desc']
|
||||
captcha = request.form['hmm']
|
||||
|
||||
if captcha == 'scrop':
|
||||
status = "success" if send_email(request.form) else "fail"
|
||||
else:
|
||||
status = "fail"
|
||||
|
||||
# should we bother restoring other fields beside desc?
|
||||
return redirect('/helpdesk?status={}&desc={}'.format(status, desc))
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(argv) == 2:
|
|
@ -2,7 +2,7 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>{{site_name}} guestbook</title>
|
||||
<link rel="stylesheet" type="text/css" href="http://tilde.town/style.css">
|
||||
<link rel="stylesheet" type="text/css" href="{{site_url}}/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{site_name}} guestbook</h1>
|
||||
|
|
|
@ -0,0 +1,68 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title> {{ site_name }} help desk </title>
|
||||
<link rel="stylesheet" href="{{ site_url }}/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ site_name }} help desk</h1>
|
||||
<p>
|
||||
hi! this form exists to make it a little easier for {{ site_name }} admins
|
||||
to help people out with system issues like logging in, installing
|
||||
packages, and general questions about how to do stuff.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
in using this system, recall that there are only a handful of admins and
|
||||
you'll get a response (by email) as they are able to help out.
|
||||
</p>
|
||||
|
||||
<p>
|
||||
thanks!
|
||||
</p>
|
||||
|
||||
{% if status == 'fail' %}
|
||||
<p style="background-color:red">
|
||||
oops, sorry! that didn't work. either something is wrong on the server or
|
||||
there was a problem with the form..try again?
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if status == 'success' %}
|
||||
<p style="background-color:green">
|
||||
hooray, your request has been sent.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<form method="post">
|
||||
<p>
|
||||
name: <input type="text" name="name" maxlength="140">
|
||||
</p>
|
||||
<p>
|
||||
email: <input type="email" name="email" maxlength="140" required="true">
|
||||
</p>
|
||||
<p>
|
||||
type of issue:
|
||||
<select name="type">
|
||||
<option value="login">help logging in</option>
|
||||
<option value="concern">concern about the site or another user</option>
|
||||
<option value="package">new package installed</option>
|
||||
<option value="question">a question</option>
|
||||
<option value="other">something else</option>
|
||||
</select>
|
||||
</p>
|
||||
<p>
|
||||
describe your issue (in 500 characters or less):<br>
|
||||
<textarea name="desc" required="true" rows="10" cols="50" maxlength="500">{{desc}}</textarea>
|
||||
</p>
|
||||
<p>
|
||||
are you a robot?<br>
|
||||
<input type="radio" name="hmm" value="scriz" checked="true">yeah<br>
|
||||
<input type="radio" name="hmm" value="scrop">nope<br>
|
||||
</p>
|
||||
<p>
|
||||
<input type="submit" value="<3">
|
||||
</p>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
Reference in New Issue