SusInstances

pull/7/head
db0 2023-06-21 00:14:53 +02:00
parent f82126e348
commit b45cd82196
2 changed files with 41 additions and 1 deletions

View File

@ -2,6 +2,9 @@ from flask_restx import fields
class Models:
def __init__(self,api):
self.response_model_error = api.model('RequestError', {
'message': fields.String(description="The error message for this status code."),
})
self.response_model_suspicious_instances = api.model('SuspiciousInstances', {
'domain': fields.String(description="The instance domain"),
'uptime_alltime': fields.Float(description="The instance uptime pct. 100% and thousand of users is unlikely"),
@ -11,3 +14,11 @@ class Models:
'signup': fields.Boolean(default=False,description="True when subscriptions are open, else False"),
'user_post_ratio': fields.Float(description="Users to Post Ratio"),
})
self.input_model_SusInstances_post = api.model('SuspiciousInstancesListInput', {
'user_to_post_ratio': fields.Integer(default=20,description="The threshold over which to consider instances suspicious."),
'whitelist': fields.List(fields.String(description="List of domains to avoid returning in the supicion list.")),
'blacklist': fields.List(fields.String(description="List of domains to append to the supicion list.")),
})
self.response_model_model_SusInstances_post = api.model('SuspiciousInstancesDomainList', {
'domains': fields.List(fields.String(description="The domains in shit suspicious list.")),
})

View File

@ -30,3 +30,32 @@ class SusInstances(Resource):
'''
self.args = self.get_parser.parse_args()
return retrieve_suspicious_instances(self.args.user_to_post_ratio),200
post_parser = reqparse.RequestParser()
post_parser.add_argument("Client-Agent", default="unknown:0:unknown", type=str, required=False, help="The client name and version.", location="headers")
post_parser.add_argument("user_to_post_ratio", required=False, default=20, type=int, help="The amount of local users / amount of local posts to consider suspicious", location="json")
post_parser.add_argument("whitelist", type=list, required=False, help="Workers to whitelist even if we think they're suspicious", location="json")
post_parser.add_argument("blacklist", type=list, required=False, help="Extra workers to blacklist.", location="json")
@api.expect(post_parser, models.input_model_SusInstances_post, validate=True)
@logger.catch(reraise=True)
# @cache.cached(timeout=10, query_string=True)
@api.marshal_with(models.response_model_model_SusInstances_post, code=200, description='Suspicious Instances List')
@api.response(400, 'Validation Error', models.response_model_error)
def post(self):
'''A List with just the domains of all suspicious instances
This can then be easily converted into a defederation list
'''
self.args = self.post_parser.parse_args()
logger.debug(self.args)
sus_instances = retrieve_suspicious_instances(self.args.user_to_post_ratio)
final_list = []
if self.args.blacklist:
final_list = self.args.blacklist
whitelist = []
if self.args.whitelist:
whitelist = self.args.whitelist
for instance in sus_instances:
if instance["domain"] not in whitelist:
final_list.append(instance["domain"])
return {"domains": final_list},200