mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-06 23:28:20 +00:00
Compare commits
8 Commits
63eb3bebef
...
2171d7fda9
| Author | SHA1 | Date | |
|---|---|---|---|
|
2171d7fda9
|
|||
|
3c4ccfb103
|
|||
|
04c7e4b518
|
|||
|
beb0ba915d
|
|||
|
ac15ab3729
|
|||
|
15230cb361
|
|||
|
b5b8dc104c
|
|||
|
55aa41acfd
|
@@ -5,6 +5,7 @@ import premailer
|
||||
import simplejson
|
||||
import urllib
|
||||
import hmac
|
||||
import hashlib
|
||||
|
||||
from envparse import env
|
||||
from bs4 import BeautifulSoup
|
||||
@@ -408,13 +409,15 @@ class RecieveForumWebhook(generic.View):
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
computed = f"sha256={hmac.new(env('FORUM_WEBHOOK_SECRET').encode(), request.body, digestmod='sha256').hexdigest()}"
|
||||
if request.POST.get('X-Discourse-Event-Signature') == computed: # and request.POST.get('X-Discourse-Event') == "topic_created":
|
||||
body = json.loads(request.body.decode('utf-8'))
|
||||
event_id = int(body['title'][1:5]) # find the ID, force convert it to an int to eliminate leading zeros
|
||||
event = models.Event.objects.filter(pk=event_id).first()
|
||||
if event:
|
||||
event.forum_url = "https://forum.nottinghamtec.co.uk/t/{}"
|
||||
event.save()
|
||||
return HttpResponse(status=200)
|
||||
computed = f"sha256={hmac.new(env('FORUM_WEBHOOK_SECRET').encode(), request.body, hashlib.sha256).hexdigest()}"
|
||||
print(computed)
|
||||
if not hmac.compare_digest(request.headers.get('X-Discourse-Event-Signature'), computed):
|
||||
return HttpResponseForbidden('Invalid signature header')
|
||||
body = simplejson.loads(request.body.decode('utf-8'))
|
||||
event_id = int(body['topic']['title'][1:6]) # find the ID, force convert it to an int to eliminate leading zeros
|
||||
event = models.Event.objects.filter(pk=event_id).first()
|
||||
if event:
|
||||
event.forum_url = f"https://forum.nottinghamtec.co.uk/t/{body['topic']['slug']}"
|
||||
event.save()
|
||||
return HttpResponse(status=202)
|
||||
return HttpResponse(status=204)
|
||||
|
||||
Reference in New Issue
Block a user