forked from kenzuya/unshackle
feat(service): warn when a proxy exit is outside GEOFENCE
This commit is contained in:
@@ -235,16 +235,20 @@ class Service(TitleSource):
|
||||
# plaintext-http forward-proxy requests with HTTP 407.
|
||||
# Verify the proxy IP every time, because a proxy can change its exit node. A dead
|
||||
# proxy fails here, not after every service request has used up its retries.
|
||||
exit_region = verify_proxy_exit(self.session).get("country")
|
||||
self.current_region = exit_region
|
||||
# Only GEOBLOCK applies here: an explicit --proxy outside GEOFENCE stays the user's call.
|
||||
if exit_region and any(x.lower() == exit_region.lower() for x in self.GEOBLOCK):
|
||||
self.current_region = verify_proxy_exit(self.session).get("country")
|
||||
region = (self.current_region or "").upper()
|
||||
blocked = [x.upper() for x in self.GEOBLOCK or ()]
|
||||
if region and region in blocked:
|
||||
raise coded(
|
||||
click.ClickException(
|
||||
f"Service is not available in {whose} proxy's region ({exit_region.upper()})"
|
||||
),
|
||||
click.ClickException(f"Service is not available in {whose} proxy's region ({region})"),
|
||||
APIErrorCode.GEOFENCE,
|
||||
)
|
||||
# Warn only: the proxy is the user's call. Not is_region_allowed: self.GEOFENCE can be set per instance.
|
||||
fence = [x.upper() for x in self.GEOFENCE or () if x.upper() not in blocked]
|
||||
if region and fence and region not in fence:
|
||||
self.log.warning(
|
||||
f"Proxy exit region {region} is outside the regions of the service ({', '.join(fence)})"
|
||||
)
|
||||
else:
|
||||
# No proxy, use cached IP info for title caching (non-critical)
|
||||
try:
|
||||
|
||||
@@ -69,8 +69,8 @@ class EXAMPLE(Service):
|
||||
|
||||
# ALIASES: extra CLI tags that resolve to this service (e.g. `dl EX ...`).
|
||||
ALIASES = ("EX", "DOMAIN")
|
||||
# GEOFENCE: regions required; the framework warns/blocks if proxy region mismatches.
|
||||
GEOFENCE = ("US", "UK")
|
||||
# GEOFENCE: regions required; the framework warns if the proxy exit region is not one of them.
|
||||
GEOFENCE = ("US", "GB")
|
||||
# GEOBLOCK: the negative form; regions where the service refuses to work, all others allowed.
|
||||
# GEOBLOCK = ("GB",)
|
||||
# TITLE_RE: named groups (?P<...>) parsed in get_titles(). Accepts URL or bare id.
|
||||
|
||||
@@ -70,8 +70,8 @@ class MUSIC_EXAMPLE(Service):
|
||||
|
||||
# ALIASES: extra CLI tags that resolve to this service (e.g. `dl MUSICEX ...`).
|
||||
ALIASES = ("MUSICEX", "MUSICDOMAIN")
|
||||
# GEOFENCE: regions required; the framework warns/blocks if proxy region mismatches.
|
||||
GEOFENCE = ("US", "UK")
|
||||
# GEOFENCE: regions required; the framework warns if the proxy exit region is not one of them.
|
||||
GEOFENCE = ("US", "GB")
|
||||
# GEOBLOCK: the negative form; regions where the service refuses to work, all others allowed.
|
||||
# GEOBLOCK = ("GB",)
|
||||
# TITLE_RE: named groups (?P<...>) parsed in get_titles(). Accepts URL or bare id.
|
||||
|
||||
Reference in New Issue
Block a user