mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-13 22:32:15 +00:00
Blacklist checking fixes
This commit is contained in:
15
hr/tasks.py
15
hr/tasks.py
@@ -4,17 +4,24 @@ from datetime import datetime, timedelta
|
|||||||
from celery.decorators import task
|
from celery.decorators import task
|
||||||
from hr.utils import blacklist_values
|
from hr.utils import blacklist_values
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.core.mail import send_mail
|
||||||
|
|
||||||
@task(ignore_result=True)
|
@task(ignore_result=True)
|
||||||
def blacklist_check():
|
def blacklist_check():
|
||||||
log = blacklist_check.get_logger()
|
log = blacklist_check.get_logger()
|
||||||
|
|
||||||
users = User.objects.filter(active=True)
|
users = User.objects.filter(is_active=True)
|
||||||
|
|
||||||
for u in users:
|
for u in users:
|
||||||
if users.groups.count() > 0:
|
if u.groups.count() > 0:
|
||||||
# Has groups
|
# Has groups
|
||||||
val = blacklist_values(user)
|
val = blacklist_values(u)
|
||||||
if len(val) > 0:
|
if len(val) > 0:
|
||||||
# Report possible issue
|
# Report possible issue
|
||||||
log.warn("Suspect User: %s, %s entries found" % (u.username, len(val)))
|
log.warning("Suspect User: %s, %s entries found: %s" % (u.username, len(val), val))
|
||||||
|
|
||||||
|
blstr = ""
|
||||||
|
for i in val:
|
||||||
|
blstr = "%s%s - %s - %s\n" % (blstr, i.get_type_display(), i.value, i.reason)
|
||||||
|
msg = "Suspect User found: %s\nGroups: %s\nBlacklist Items:\n\n%s" % (u.username, u.groups.all(), blstr)
|
||||||
|
send_mail('Automated blacklist checker alert - %s' % u.username, msg, 'blacklist@pleaseignore.com', ['abuse@pleaseignore.com'])
|
||||||
|
|||||||
18
hr/utils.py
18
hr/utils.py
@@ -1,5 +1,23 @@
|
|||||||
|
from datetime import datetime
|
||||||
from hr.app_defines import *
|
from hr.app_defines import *
|
||||||
from hr.models import Blacklist
|
from hr.models import Blacklist
|
||||||
|
from django.db import models
|
||||||
|
from eve_api.models import EVEPlayerCharacter
|
||||||
|
|
||||||
|
def installed(value):
|
||||||
|
from django.conf import settings
|
||||||
|
apps = settings.INSTALLED_APPS
|
||||||
|
if "." in value:
|
||||||
|
for app in apps:
|
||||||
|
if app == value:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
for app in apps:
|
||||||
|
fields = app.split(".")
|
||||||
|
if fields[-1] == value:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
def blacklist_values(user):
|
def blacklist_values(user):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user