return res.c or 0
- async def check_spam(self, email, address):
- sfs = StopForumSpam(self.backend, email, address)
-
- # Get spam score
- score = await sfs.check()
-
- return score >= 50
-
def auth(self, username, password):
# Find account
account = self.backend.accounts.find_account(username)
await user.disable(text)
-class StopForumSpam(Object):
- def init(self, email, address):
- self.email, self.address = email, address
-
- async def send_request(self, **kwargs):
- arguments = {
- "json" : "1",
- }
- arguments.update(kwargs)
-
- # Create request
- request = tornado.httpclient.HTTPRequest(
- "https://api.stopforumspam.org/api", method="POST",
- connect_timeout=2, request_timeout=5)
- request.body = urllib.parse.urlencode(arguments)
-
- # Send the request
- response = await self.backend.http_client.fetch(request)
-
- # Decode the JSON response
- return json.loads(response.body.decode())
-
- async def check_address(self):
- response = await self.send_request(ip=self.address)
-
- try:
- confidence = response["ip"]["confidence"]
- except KeyError:
- confidence = 100
-
- logging.debug("Confidence for %s: %s" % (self.address, confidence))
-
- return confidence
-
- async def check_email(self):
- response = await self.send_request(email=self.email)
-
- try:
- confidence = response["email"]["confidence"]
- except KeyError:
- confidence = 100
-
- logging.debug("Confidence for %s: %s" % (self.email, confidence))
-
- return confidence
-
- async def check(self, threshold=95):
- """
- This function tries to detect if we have a spammer.
-
- To honour the privacy of our users, we only send the IP
- address and username and if those are on the database, we
- will send the email address as well.
- """
- confidences = [await self.check_address(), await self.check_email()]
-
- # Build a score based on the lowest confidence
- return 100 - min(confidences)
-
-
class Groups(Object):
hidden_groups = (
"cn=LDAP Read Only,ou=Group,dc=ipfire,dc=org",
"accounts:delete" : self.accounts._delete,
"announce-blog-posts" : self.blog.announce,
"check-mirrors" : self.mirrors.check_all,
- "check-spam" : self.accounts.check_spam,
"cleanup" : self.cleanup,
"get-all-emails" : self.accounts.get_all_emails,
"launch-campaigns" : self.campaigns.launch_manually,
+++ /dev/null
-{% extends "../base.html" %}
-
-{% block title %}{{ _("Oops!") }}{% end block %}
-
-{% block content %}
- <div class="row justify-content-center my-5">
- <div class="col-12 col-md-6">
- <div class="card bg-warning text-white p-md-5">
- <div class="card-body text-center">
- <span class="fas fa-exclamation fa-5x my-4"></span>
-
- <p class="lead">
- {{ _("Unfortunately we could not create your account because you have shown up on our spam radar.") }}
- {{ _("Please get in touch if you think that this is an error.") }}
- </p>
- </div>
- </div>
- </div>
- </div>
-{% end block %}