Enable approved private Athena TTS route in Hermes WebUI startup

This commit is contained in:
Mikei386 committed 2026-10-17 21:28:20 +02:00
1 parent 16915a04f0
commit d3251c624e
3 files changed
+98 -14

No files matched your search

@@ -1,5 +1,5 @@
#!/bin/bash
# Operator integration: keep the upstream initializer and programs unchanged.
# Operator integration: upstream initializer plus the approved, pinned LAN TTS patch.
set -Eeuo pipefail
web_pid=''
gateway_pid=''
@@ -52,6 +52,32 @@ stop_children() {
trap 'stop_children; exit 0' TERM INT
trap stop_children EXIT
# Operator-approved exception for this exact private TTS endpoint only.
# Unknown upstream versions keep their original policy; never patch them blindly.
export HERMES_WEBUI_TRUSTED_TTS_BASE_URL=http://192.168.1.212:8120/v1
/usr/local/bin/python3 - <<'TTS_PATCH'
import hashlib
from pathlib import Path
# Stock initialization copies /apptoo into /app on every start.
p = Path('/apptoo/api/routes.py')
source = p.read_text()
original_sha = '9f32e7ca096a491a36c1e774752af18c2d02ca402af4dad1886a5048deae10dc'
patched_sha = '5e51d1e2791804b825bdd3c8f000faaea3989d34cdbcd6c406800573eb8e5710'
insertion = ' # Explicit operator trust for one literal RFC1918 OpenAI TTS base URL.\n # Chat input/config cannot broaden this process environment allowlist.\n trusted = os.getenv("HERMES_WEBUI_TRUSTED_TTS_BASE_URL", "").strip().rstrip("/")\n if trusted and raw.rstrip("/") == trusted and parsed.scheme == "http":\n import ipaddress\n try:\n address = ipaddress.ip_address(hostname)\n allowed_networks = ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16")\n trusted_lan = any(address in ipaddress.ip_network(n) for n in allowed_networks)\n if trusted_lan and parsed.port and parsed.path.rstrip("/") == "/v1":\n return urlunsplit((parsed.scheme, parsed.netloc, "/v1", "", ""))\n except ValueError:\n pass\n raise ValueError("invalid trusted OpenAI TTS base_url")\n'
anchor = ' if parsed.scheme == "https":\n # Public https hosts are allowed (a user\'s own OpenAI-compatible server),'
sha = hashlib.sha256(source.encode()).hexdigest()
if sha == patched_sha:
print('LAN TTS adaptation already present', flush=True)
elif sha == original_sha and source.count(anchor) == 1:
updated = source.replace(anchor, insertion + anchor, 1)
assert hashlib.sha256(updated.encode()).hexdigest() == patched_sha
compile(updated, str(p), 'exec')
p.write_text(updated)
print('Approved LAN TTS adaptation applied', flush=True)
else:
print('WARNING: unknown WebUI source; LAN TTS adaptation NOT applied; revalidation required', flush=True)
TTS_PATCH
# setsid gives each service its own process group, including init/su children.
setsid /hermeswebui_init.bash &
web_pid=$!