feat: geo risk scores
This commit is contained in:
parent
315dae7f06
commit
0e0d499428
17 changed files with 558 additions and 54 deletions
|
@ -1,4 +1,5 @@
|
|||
import logging
|
||||
from collections import defaultdict
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -35,17 +36,26 @@ class BlockExternalAutomation(BlockMirrorAutomation):
|
|||
|
||||
def fetch(self) -> None:
|
||||
user_agent = {'User-agent': 'BypassCensorship/1.0'}
|
||||
if isinstance(app.config.get('EXTERNAL_CHECK_URL', []), list):
|
||||
check_urls = app.config.get('EXTERNAL_CHECK_URL', [])
|
||||
elif isinstance(app.config.get('EXTERNAL_CHECK_URL'), str):
|
||||
check_urls = [app.config['EXTERNAL_CHECK_URL']]
|
||||
check_urls_config = app.config.get('EXTERNAL_CHECK_URL', [])
|
||||
|
||||
if isinstance(check_urls_config, dict):
|
||||
# Config is already a dictionary, use as is.
|
||||
check_urls = check_urls_config
|
||||
elif isinstance(check_urls_config, list):
|
||||
# Convert list of strings to a dictionary with "external_N" keys.
|
||||
check_urls = {f"external_{i}": url for i, url in enumerate(check_urls_config)}
|
||||
elif isinstance(check_urls_config, str):
|
||||
# Single string, convert to a dictionary with key "external".
|
||||
check_urls = {"external": check_urls_config}
|
||||
else:
|
||||
check_urls = []
|
||||
for check_url in check_urls:
|
||||
# Fallback if the config item is neither dict, list, nor string.
|
||||
check_urls = {}
|
||||
for source, check_url in check_urls.items():
|
||||
if self._data is None:
|
||||
self._data = []
|
||||
self._data.extend(requests.get(check_url, headers=user_agent, timeout=30).json())
|
||||
self._data = defaultdict(list)
|
||||
self._data[source].extend(requests.get(check_url, headers=user_agent, timeout=30).json())
|
||||
|
||||
def parse(self) -> None:
|
||||
self.patterns.extend(["https://" + trim_http_https(pattern) for pattern in self._data])
|
||||
for source, patterns in self._data.items():
|
||||
self.patterns[source].extend(["https://" + trim_http_https(pattern) for pattern in patterns])
|
||||
logging.debug("Found URLs: %s", self.patterns)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue