diff --git a/backend/browse.py b/backend/browse.py index 16f85db..a4b999b 100644 --- a/backend/browse.py +++ b/backend/browse.py @@ -181,16 +181,17 @@ def start_browser() -> None: # Config helpers # --------------------------------------------------------------------------- -def _rns_config_path() -> Path: - """Return the path to the RNS config file.""" - configdir = os.environ.get("RNS_CONFIG_DIR", str(Path.home() / ".reticulum")) - return Path(configdir) / "config" +_CONFIG_PATHS = { + "reticulum": lambda: Path(os.environ.get("RNS_SERVER_CONFIG_DIR", os.environ.get("RNS_CONFIG_DIR", str(Path.home() / ".reticulum")))) / "config", + "nomadnet": lambda: Path(os.environ.get("NOMADNET_CONFIG_DIR", str(Path.home() / ".nomadnetwork"))) / "config", +} -def _nomadnet_config_path() -> Path: - """Return the path to the NomadNet config file.""" - configdir = os.environ.get("NOMADNET_CONFIG_DIR", str(Path.home() / ".nomadnetwork")) - return Path(configdir) / "config" +def _config_path(kind: str) -> Path: + resolver = _CONFIG_PATHS.get(kind) + if not resolver: + raise ValueError(f"Unknown config kind: {kind}") + return resolver() def _restart_nomadnet() -> bool: @@ -405,46 +406,27 @@ async def _request_remote_page(hash_hex: str, path: str) -> str | None: # Reticulum config endpoints # --------------------------------------------------------------------------- -@router.get("/browse/config/reticulum") -async def get_reticulum_config(): - """Return the current Reticulum config file contents.""" - path = _rns_config_path() - if not path.exists(): - return {"content": ""} - return {"content": path.read_text(encoding="utf-8")} - - -@router.post("/browse/config/reticulum") -async def save_reticulum_config(body: dict): - """Write Reticulum config.""" - content = body.get("content", "") - path = _rns_config_path() - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(content, encoding="utf-8") - return {"ok": True} - - -@router.get("/browse/config/nomadnet") -async def get_nomadnet_config(): - """Return the current NomadNet config file contents.""" - path = _nomadnet_config_path() - if not path.exists(): - return {"content": ""} - return {"content": path.read_text(encoding="utf-8")} - - -@router.post("/browse/config/nomadnet") -async def save_nomadnet_config(body: dict): - """Write NomadNet config.""" - content = body.get("content", "") - path = _nomadnet_config_path() - path.parent.mkdir(parents=True, exist_ok=True) - path.write_text(content, encoding="utf-8") - return {"ok": True} - - -@router.post("/browse/config/restart") +@router.post("/browse/restart") async def restart_services(): """Restart NomadNet to apply config changes.""" restarted = _restart_nomadnet() return {"ok": True, "nomadnet_restarted": restarted} + + +@router.get("/browse/config/{kind}") +async def get_config(kind: str): + """Return config file contents for reticulum or nomadnet.""" + path = _config_path(kind) + if not path.exists(): + return {"content": ""} + return {"content": path.read_text(encoding="utf-8")} + + +@router.post("/browse/config/{kind}") +async def save_config(kind: str, body: dict): + """Write config file for reticulum or nomadnet.""" + content = body.get("content", "") + path = _config_path(kind) + path.parent.mkdir(parents=True, exist_ok=True) + path.write_text(content, encoding="utf-8") + return {"ok": True} diff --git a/compose.yml b/compose.yml index 8a421a0..011c723 100644 --- a/compose.yml +++ b/compose.yml @@ -10,17 +10,19 @@ services: - SOURCES_DIR=/data/sources - NOMADNET_CONTAINER=nomadnet - RNS_CONFIG_DIR=/rns + - RNS_SERVER_CONFIG_DIR=/rns-server - NOMADNET_CONFIG_DIR=/nomadnet - LOG_LEVEL=DEBUG volumes: - pages:/data/pages - sources:/data/sources - /var/run/docker.sock:/var/run/docker.sock:ro - - reticulum:/rns - - ./reticulum.conf:/rns/config - - nomadnet-config:/nomadnet + - ./reticulum-client.conf:/rns/config + - ./reticulum.conf:/rns-server/config - ./nomadnet.conf:/nomadnet/config restart: unless-stopped + depends_on: + - nomadnet nomadnet: image: ghcr.io/markqvist/nomadnet:latest @@ -30,7 +32,6 @@ services: - pages:/root/.nomadnetwork/storage/pages - nomadnet-config:/root/.nomadnetwork - ./nomadnet.conf:/root/.nomadnetwork/config - - reticulum:/root/.reticulum - ./reticulum.conf:/root/.reticulum/config restart: unless-stopped @@ -38,4 +39,3 @@ volumes: pages: sources: nomadnet-config: - reticulum: diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index a47556a..54d7e8c 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -242,7 +242,7 @@ export async function saveConfig(kind: "reticulum" | "nomadnet", content: string } export async function restartServices(): Promise<{ nomadnet_restarted: boolean }> { - const res = await fetch("/api/browse/config/restart", { method: "POST" }); + const res = await fetch("/api/browse/restart", { method: "POST" }); if (!res.ok) throw new Error(await res.text()); return res.json(); } diff --git a/reticulum-client.conf b/reticulum-client.conf new file mode 100644 index 0000000..fea72cf --- /dev/null +++ b/reticulum-client.conf @@ -0,0 +1,23 @@ +[reticulum] + enable_transport = False + share_instance = No + +[logging] + loglevel = 4 + +[interfaces] + # Connect to NomadNet's TCP server + [[NomadNet Link]] + type = TCPClientInterface + enabled = Yes + target_host = nomadnet + target_port = 4242 + + [[Quad4]] + type = TCPClientInterface + interface_enabled = true + target_host = 62.151.179.77 + target_port = 45657 + mode = full + name = Quad4 + selected_interface_mode = 1 diff --git a/reticulum.conf b/reticulum.conf index ffc325c..3a2b514 100644 --- a/reticulum.conf +++ b/reticulum.conf @@ -14,24 +14,3 @@ listen_ip = 0.0.0.0 listen_port = 4242 - [[Quad4]] - type = TCPClientInterface - interface_enabled = true - target_host = 62.151.179.77 - target_port = 45657 - mode = full - name = Quad4 - selected_interface_mode = 1 - - [[Hispagatos_org_HQ]] - type = BackboneInterface - enabled = yes - remote = reticulum.hispagatos.org - target_port = 4242 - transport_identity = 305c8452b222c9d367bc9e482956a4fa - - [[NomadNet Link]] - type = TCPClientInterface - enabled = Yes - target_host = nomadnet - target_port = 4242