Skip to content

Commit

Permalink
Modified the captcha to read secret key from file.
Browse files Browse the repository at this point in the history
Also changed the keys for the recaptcha due to their accidental
committal earlier.
  • Loading branch information
malnoxon committed Aug 20, 2015
1 parent 64bf8dd commit bdf3188
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion rsstory/archive_fails.pt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</td>
</tr>
</table>
<div class="g-recaptcha" data-sitekey="6LcHZQsTAAAAAG1MSHuQpKKvtx4D_o8FYt2VfSFq"></div>
<div class="g-recaptcha" data-sitekey="6LcnlgsTAAAAAGmVA_COh_S6FDDtnEUJY9aL8Ulf"></div>
<button type="button" id="submit">
Report
</button>
Expand Down
2 changes: 1 addition & 1 deletion rsstory/index.pt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</td>
</tr>
</table>
<div class="g-recaptcha" data-sitekey="6LcHZQsTAAAAAG1MSHuQpKKvtx4D_o8FYt2VfSFq"></div>
<div class="g-recaptcha" data-sitekey="6LcnlgsTAAAAAGmVA_COh_S6FDDtnEUJY9aL8Ulf"></div>
<button type="button" id="submit">
Submit
</button>
Expand Down
24 changes: 19 additions & 5 deletions rsstory/rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ def write_preview_feed(rss_items, url, title, feed_id):
return fname

def archive_to_rss(url, time_between_posts, title, recaptcha_answer, ip):
#TODO: do NOT push until the secret key is hidden in a config file!
log.info("Beginning archive_to_rss()")
captcha_response = submit(remote_ip=ip, secret_key="6LcHZQsTAAAAALNHKDDOht1UXok-vnY4KJE13RGJ", response=recaptcha_answer)
key = ""
try:
with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'secret', 'recaptcha_key_secret.key'), 'r') as f:
key = f.readline()
except:
log.error("The file containing the secret key was not located")
return (False, False)

captcha_response = submit(remote_ip=ip, secret_key=key, response=recaptcha_answer)
log.debug("recaptcha_answer is: {}".format(recaptcha_answer))
if captcha_response.is_valid:
log.info("Captcha response verified as valid")
Expand Down Expand Up @@ -95,12 +102,19 @@ def archive_to_rss(url, time_between_posts, title, recaptcha_answer, ip):
return (rss_feed_filename, preview_feed_filename)
else:
log.error("Invalid captcha entered")
raise Exception('Invalid captcha')
return
return (False, False)

def report_archive_fail(url, comments, ip, recaptcha_answer):
log.info("Beginning report_archive_fail")
captcha_response = submit(remote_ip=ip, secret_key="6LcHZQsTAAAAALNHKDDOht1UXok-vnY4KJE13RGJ", response=recaptcha_answer)
key = ""
try:
with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'secret', 'recaptcha_key_secret.key'), 'r') as f:
key = f.readline()
except:
log.error("The file containing the secret key was not located")
return False

captcha_response = submit(remote_ip=ip, secret_key=key, response=recaptcha_answer)
log.debug("recaptcha_answer is: {}".format(recaptcha_answer))
if captcha_response.is_valid:
log.info("Captcha response verified as valid")
Expand Down
2 changes: 2 additions & 0 deletions rsstory/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def feed(request):
if request.json_body['url'] == '':
return {"rss": "Error"}
xml_feed, preview_page = rss.archive_to_rss(request.json_body['url'], request.json_body['time'], request.json_body['title'], request.json_body['captcha'], request.remote_addr)
if xml_feed == False and preview_page == False:
return {"rss": "Error"}
return {"rss": "/static/feeds/" + xml_feed + ".xml", "preview": "/static/previews/" + preview_page}

@view_config(route_name='archive_fails', renderer='archive_fails.pt')
Expand Down

0 comments on commit bdf3188

Please sign in to comment.