block: import blocklist from roskomsvoboda

This commit is contained in:
Iain Learmonth 2022-05-09 14:11:05 +01:00
parent af0b808cfd
commit 5dfc3931a8
2 changed files with 38 additions and 1 deletions

View file

@ -0,0 +1,34 @@
from fnmatch import fnmatch
from typing import Tuple, List
import requests
from app.extensions import db
from app.models.mirrors import Proxy
from app.terraform import BaseAutomation
class BlockRoskomsvobodaAutomation(BaseAutomation):
short_name = "block_roskomsvoboda"
description = "Import Russian blocklist from RosKomSvoboda"
frequency = 120
def automate(self, full: bool = False) -> Tuple[bool, str]:
proxies: List[Proxy] = Proxy.query.filter(
Proxy.deprecated == None,
Proxy.destroyed == None
).all()
patterns = requests.get("https://reestr.rublacklist.net/api/v2/domains/json").json()
for pattern in patterns:
for p in proxies:
if fnmatch(p.url[len("https://"):], pattern):
print(f"Found {p.url} blocked")
if not p.origin.auto_rotation:
print("Proxy auto-rotation forbidden for origin")
continue
if p.deprecated:
print("Proxy already marked blocked")
continue
p.deprecate(reason="roskomsvoboda")
db.session.commit()
return True, ""