Add CAPTCHA

This commit is contained in:
2021-08-20 20:23:43 +00:00
parent e51f7e98df
commit 52892f88e2
+29 -6
View File
@@ -16,10 +16,13 @@ def help():
form = ( form = (
'<form action="{0}" method="POST" accept-charset="UTF-8">' '<form action="{0}" method="POST" accept-charset="UTF-8">'
'<input name="web" type="hidden" value="true">' '<input name="web" type="hidden" value="true">'
'<textarea name="{1}" cols="60" rows="18"></textarea>' '<input name="name" style="border: none;">'
'<br><textarea name="{1}" cols="60" rows="18"></textarea>'
'<br>CAPTCHA: Who owns this site? <input name="captcha">'
'<br><button type="submit">Submit</button></form>'.format(URL, POST) '<br><button type="submit">Submit</button></form>'.format(URL, POST)
) )
return """ return """
<meta name="viewport" content="width=device-width, initial-scale=0.8">
<pre> <pre>
txt.t0.vc txt.t0.vc
NAME NAME
@@ -28,7 +31,6 @@ NAME
USAGE USAGE
&lt;command&gt; | curl -F '{0}=&lt;-' {1} &lt;command&gt; | curl -F '{0}=&lt;-' {1}
or upload from the web: or upload from the web:
{2} {2}
DESCRIPTION DESCRIPTION
@@ -68,21 +70,42 @@ def index():
@flask_app.route('/', methods=['POST']) @flask_app.route('/', methods=['POST'])
def new(): def new():
print()
try: try:
is_web = 'web' in request.form
name = request.form.get('name', None)
if name:
print('Name filled out:', name)
captcha = request.form.get('captcha', None)
if is_web and captcha.lower() not in ['tanner', 'tanner collin', 'tannercollin', 'collin']:
print('Captcha failed:', captcha)
return redirect('https://txt.t0.vc/LPPZ')
else:
print('Captcha passed:', captcha)
with shelve.open(DB) as db: with shelve.open(DB) as db:
nid = new_id() nid = new_id()
while nid in db: while nid in db:
nid = new_id() nid = new_id()
txt = request.form['txt'] txt = request.form['txt']
if not txt: raise
if len(txt) > 250000: raise if not txt:
print('Note is empty.')
raise
if len(txt) > 250000:
print('Note too large.')
raise
db[nid] = txt db[nid] = txt
print('Adding note {}:\n{}'.format(nid, txt)) print('Adding note {} via {}:\n{}'.format(nid, 'web' if is_web else 'api', txt))
url = '{}/{}'.format(URL, nid) url = '{}/{}'.format(URL, nid)
if 'web' in request.form:
if is_web:
return redirect(url) return redirect(url)
else: else:
return url + '\n' return url + '\n'