mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 12:26:19 -05:00
Torrents over a fail-closed VPN (#1026)
Torrents reach the Internet only through a fail-closed VPN (WireGuard or OpenVPN, any provider), so peers never see a WROLPi's own address. - A network namespace (Pi/Debian) or the vpn container (Docker) with an nftables kill switch; NAT-PMP or fixed port forwarding. - qBittorrent inside it, sandboxed; torrents kept in config/torrents/. - Torrent download form, Torrents page, Share as torrent, nav warning, and VPN settings in both Controller UIs. - Help docs: Torrents, and The VPN for Torrents. QA'd on a Raspberry Pi with a real provider over WireGuard and OpenVPN. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
633b125dc6
commit
2c3300b8b0
80 changed files with 7516 additions and 45 deletions
|
|
@ -32,6 +32,54 @@ NON_VIEWABLE_CONTAINERS = {"redis", "memcached", "samba", "rsyncd", "tiles"}
|
|||
# Containers that should use HTTPS
|
||||
HTTPS_CONTAINERS = {"web"}
|
||||
|
||||
# What each docker-compose service is, for the Services list (systemd services have theirs in defaults.py).
|
||||
# `via_web`: the container publishes no port of its own; the web container (Caddy) serves it over HTTPS on this
|
||||
# container port (plain HTTP if `use_https` is False), so its View link uses the host port Docker publishes for that
|
||||
# port of the web container.
|
||||
DOCKER_SERVICES = {
|
||||
"api": {"description": "Python API (Sanic)"},
|
||||
"app": {"description": "React frontend", "via_web": 443},
|
||||
"archive": {"description": "Archiving (SingleFile and Readability)", "viewable": False},
|
||||
"controller": {"description": "Controller API (FastAPI)"},
|
||||
"help": {"description": "Help documentation", "via_web": 8086},
|
||||
"rsyncd": {"description": "Library for secondary WROLPis (rsync)"},
|
||||
"samba": {"description": "Samba file sharing"},
|
||||
# Tiles for ATAK and iTAK, which ask for them; no page to view.
|
||||
"tiles": {"description": "Map tiles for ATAK and iTAK", "via_web": 8088, "use_https": False, "viewable": False},
|
||||
"vpn": {"description": "VPN and torrents (qBittorrent WebUI)", "via_web": 8091},
|
||||
"web": {"description": "HTTPS proxy (Caddy) for the app, maps, Zims, help and torrents", "via_web": 443},
|
||||
"zim": {"description": "Kiwix/Zim server", "via_web": 8085},
|
||||
}
|
||||
WEB_SERVICE = "web"
|
||||
|
||||
|
||||
def _host_port(container, container_port: int = None):
|
||||
"""The host port Docker publishes for `container_port` of `container` (any published port, if None)."""
|
||||
if container is None:
|
||||
return None
|
||||
ports = container.attrs.get("NetworkSettings", {}).get("Ports", {}) or {}
|
||||
for port, host_bindings in ports.items():
|
||||
if host_bindings and (container_port is None or port == f"{container_port}/tcp"):
|
||||
return int(host_bindings[0].get("HostPort", 0))
|
||||
return None
|
||||
|
||||
|
||||
def _describe(name: str, container, web_container) -> dict:
|
||||
"""A container's description, the port its View link uses, and how."""
|
||||
service = DOCKER_SERVICES.get(name, {})
|
||||
if "via_web" in service:
|
||||
port = _host_port(web_container, service["via_web"])
|
||||
use_https = service.get("use_https", True)
|
||||
else:
|
||||
port = _host_port(container)
|
||||
use_https = name.endswith("_https") or name in HTTPS_CONTAINERS
|
||||
return {
|
||||
"description": service.get("description", ""),
|
||||
"port": port,
|
||||
"viewable": service.get("viewable", name not in NON_VIEWABLE_CONTAINERS),
|
||||
"use_https": use_https,
|
||||
}
|
||||
|
||||
|
||||
def can_manage_containers() -> bool:
|
||||
"""Check if we can manage Docker containers."""
|
||||
|
|
@ -91,23 +139,20 @@ def get_container_status(name: str) -> dict:
|
|||
else:
|
||||
status = docker_status
|
||||
|
||||
# Get port info from container
|
||||
ports = container.attrs.get("NetworkSettings", {}).get("Ports", {})
|
||||
port = None
|
||||
for container_port, host_bindings in ports.items():
|
||||
if host_bindings:
|
||||
port = int(host_bindings[0].get("HostPort", 0))
|
||||
break
|
||||
web_container = container
|
||||
if name != WEB_SERVICE and "via_web" in DOCKER_SERVICES.get(name, {}):
|
||||
try:
|
||||
web_container = client.containers.get(_get_container_name(WEB_SERVICE))
|
||||
except NotFound:
|
||||
web_container = None
|
||||
|
||||
return {
|
||||
"name": name,
|
||||
"container_name": container_name,
|
||||
"status": status,
|
||||
"docker_status": docker_status,
|
||||
"port": port,
|
||||
"available": True,
|
||||
"viewable": name not in NON_VIEWABLE_CONTAINERS,
|
||||
"use_https": name.endswith("_https") or name in HTTPS_CONTAINERS,
|
||||
**_describe(name, container, web_container),
|
||||
}
|
||||
except NotFound:
|
||||
return {
|
||||
|
|
@ -138,6 +183,7 @@ def get_all_containers_status() -> list[dict]:
|
|||
client = _get_client()
|
||||
containers = client.containers.list(all=True)
|
||||
|
||||
web_container = next((c for c in containers if c.name == _get_container_name(WEB_SERVICE)), None)
|
||||
results = []
|
||||
for container in containers:
|
||||
if container.name.startswith(CONTAINER_PREFIX):
|
||||
|
|
@ -148,22 +194,12 @@ def get_all_containers_status() -> list[dict]:
|
|||
else:
|
||||
service_name = container.name
|
||||
|
||||
# Get port info from container
|
||||
ports = container.attrs.get("NetworkSettings", {}).get("Ports", {})
|
||||
port = None
|
||||
for container_port, host_bindings in ports.items():
|
||||
if host_bindings:
|
||||
port = int(host_bindings[0].get("HostPort", 0))
|
||||
break
|
||||
|
||||
results.append({
|
||||
"name": service_name,
|
||||
"container_name": container.name,
|
||||
"status": "running" if container.status == "running" else "stopped",
|
||||
"docker_status": container.status,
|
||||
"port": port,
|
||||
"viewable": service_name not in NON_VIEWABLE_CONTAINERS,
|
||||
"use_https": service_name.endswith("_https") or service_name in HTTPS_CONTAINERS,
|
||||
**_describe(service_name, container, web_container),
|
||||
})
|
||||
|
||||
return results
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue