Skip to content

Commit

Permalink
feat: enable ip reporting via email with exemptions list
Browse files Browse the repository at this point in the history
  • Loading branch information
NicholasBottone committed Nov 4, 2024
1 parent 7a644bc commit ce590b0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
35 changes: 20 additions & 15 deletions highscores/lib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.http import HttpRequest
from django.core.mail import send_mail

from .models import Score, CleanCodeSubmission
from .models import Score, CleanCodeSubmission, ExemptedIP
from .forms import ScoreForm
from SRCweb.settings import NEW_AES_KEY, DEBUG, ADMIN_EMAILS, EMAIL_HOST_USER

Expand Down Expand Up @@ -661,23 +661,28 @@ def search_for_reused_code(score_obj: Score) -> Union[str, None]:

return 'That clean code has already been submitted by another player.'

# # same ip but different player
# ip_search = CleanCodeSubmission.objects.filter(
# ip=score_obj.ip).exclude(player=score_obj.player)
# same ip but different player
ip_search = CleanCodeSubmission.objects.filter(
ip=score_obj.ip).exclude(player=score_obj.player)

# if ip_search.exists():
# # Uh oh, there are multiple users submitting from the same IP.
# # Report this via email.
if ip_search.exists():
# search if an exemption exists
exempted_ip_search = ExemptedIP.objects.filter(ip=score_obj.ip)
if exempted_ip_search.exists():
return None

# message = f"{score_obj.player} ({score_obj.ip}) submitted a score (successfully): [{score_obj.score}] - {score_obj.leaderboard}\n\n This IP has also been used by {ip_search[0].player} ({ip_search[0].ip})\n\n {score_obj.source}\n\nhttps://secondrobotics.org/admin/highscores/score/"
# try:
# if (not DEBUG):
# send_mail(f"Duplicate IP usage from {score_obj.player}",
# message, EMAIL_HOST_USER, ADMIN_EMAILS, fail_silently=False)
# except Exception as ex:
# print(ex)
# Uh oh, there are multiple users submitting from the same IP.
# Report this via email.

message = f"{score_obj.player} ({score_obj.ip}) submitted a score (successfully): [{score_obj.score}] - {score_obj.leaderboard}\n\n This IP has also been used by {ip_search[0].player} ({ip_search[0].ip})\n\n {score_obj.source}\n\nhttps://secondrobotics.org/admin/highscores/score/"
try:
if (not DEBUG):
send_mail(f"Duplicate IP usage from {score_obj.player}",
message, EMAIL_HOST_USER, ADMIN_EMAILS, fail_silently=False)
except Exception as ex:
print(ex)

# # Still allow the score to be submitted.
# Still allow the score to be submitted.

return None # No error

Expand Down
7 changes: 7 additions & 0 deletions highscores/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,10 @@ class CleanCodeSubmission(models.Model):
def __str__(self):
return self.clean_code


class ExemptedIP(models.Model):
ip = models.CharField(max_length=20)
reason = models.CharField(max_length=200, null=True, blank=True)

def __str__(self):
return self.ip

0 comments on commit ce590b0

Please sign in to comment.