home · contact · privacy
Use "python3 -m venv" instead of "pyvenv".
[url-catcher] / url_catcher.py
old mode 100644 (file)
new mode 100755 (executable)
index ac4b7a7..5f5b030
@@ -1,3 +1,5 @@
+#!/usr/bin/python3
+
 import bottle
 import validators
 import html
@@ -47,7 +49,7 @@ os.makedirs(lists_dir, exist_ok=True)
 def atomic_write(path, content, mode):
     """Atomic write/append to file."""
     _, tmpPath = tempfile.mkstemp()
-    if 'a' == mode:
+    if 'a' == mode and os.path.exists(path):
         shutil.copy2(path, tmpPath)
     f = open(tmpPath, mode)
     f.write(content)
@@ -114,7 +116,7 @@ def post_link():
                 str(start_date) + '\n' + str(attempts), 'w')
 
     # Derive page / page file name.
-    page = bottle.request.forms.get('page')
+    page = bottle.request.forms.page
     if '\0' in page or '/' in page or '.' in page or len(page.encode()) > 255:
         return bottle.HTTPResponse(messages['badPageName'], 400)
 
@@ -122,12 +124,12 @@ def post_link():
     captcha_file = open(captchas_dir + '/' + page, 'r')
     captcha_correct = captcha_file.readline().rstrip()
     captcha_file.close()
-    captcha_input = bottle.request.forms.get('captcha')
+    captcha_input = bottle.request.forms.captcha
     if captcha_correct != captcha_input:
         return bottle.HTTPResponse(messages['wrongCaptcha'], 400)
 
     # Record URL.
-    url = bottle.request.forms.get('url')
+    url = bottle.request.forms.url
     if not validators.url(url):
         return bottle.HTTPResponse(messages['invalidURL'], 400)
     send_mail(page, url)