Skip to content

Commit a7d66c3

Browse files
author
root
committed
feat(gateway): add LAN mode toggle in add-on config
Add gateway_lan_mode option to control gateway bind mode: - false (default): bind to loopback only (secure, local access) - true: bind to LAN (accessible from local network) Non-destructive config patching: only modifies gateway.bind, preserves auth token and all other settings.
1 parent 02f8103 commit a7d66c3

2 files changed

Lines changed: 49 additions & 0 deletions

File tree

openclaw_assistant_dev/config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ options:
4747
clean_session_locks_on_start: true
4848
clean_session_locks_on_exit: true
4949

50+
# Gateway network bind mode:
51+
# - true: bind to LAN (accessible from local network, e.g., 0.0.0.0 or LAN IP)
52+
# - false: bind to loopback only (127.0.0.1, local access only)
53+
# Default is false for security. Toggle this on if you need external access.
54+
gateway_lan_mode: false
55+
5056

5157
schema:
5258
timezone: str
@@ -60,4 +66,5 @@ schema:
6066

6167
clean_session_locks_on_start: bool?
6268
clean_session_locks_on_exit: bool?
69+
gateway_lan_mode: bool?
6370

openclaw_assistant_dev/run.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ ROUTER_KEY=$(jq -r '.router_ssh_key_path // "/data/keys/router_ssh"' "$OPTIONS_F
2727
CLEAN_LOCKS_ON_START=$(jq -r '.clean_session_locks_on_start // true' "$OPTIONS_FILE")
2828
CLEAN_LOCKS_ON_EXIT=$(jq -r '.clean_session_locks_on_exit // true' "$OPTIONS_FILE")
2929

30+
# Gateway LAN mode toggle (default false for security)
31+
GATEWAY_LAN_MODE=$(jq -r '.gateway_lan_mode // false' "$OPTIONS_FILE")
32+
3033
export TZ="$TZNAME"
3134

3235
# Reduce risk of secrets ending up in logs
@@ -182,6 +185,45 @@ print("INFO: Wrote minimal OpenClaw config (gateway.mode=local, auth.token gener
182185
PY
183186
fi
184187

188+
# ------------------------------------------------------------------------------
189+
# Apply gateway LAN mode setting safely (non-destructive config patch)
190+
# This updates gateway.bind without touching other settings (auth token, etc.)
191+
# ------------------------------------------------------------------------------
192+
LAN_MODE="${GATEWAY_LAN_MODE}"
193+
if [ -f "$OPENCLAW_CONFIG_PATH" ]; then
194+
python3 - <<PY
195+
import json
196+
from pathlib import Path
197+
import os
198+
199+
cfg_path = Path(os.environ['OPENCLAW_CONFIG_PATH'])
200+
lan_mode = os.environ.get('GATEWAY_LAN_MODE', 'false').lower() == 'true'
201+
202+
# Read existing config (preserve formatting as much as possible)
203+
text = cfg_path.read_text(encoding='utf-8')
204+
cfg = json.loads(text)
205+
206+
# Determine desired bind value
207+
desired_bind = "lan" if lan_mode else "loopback"
208+
209+
current_bind = cfg.get("gateway", {}).get("bind", "")
210+
211+
if current_bind != desired_bind:
212+
# Ensure gateway section exists
213+
if "gateway" not in cfg:
214+
cfg["gateway"] = {}
215+
cfg["gateway"]["bind"] = desired_bind
216+
217+
# Write back with nice formatting
218+
cfg_path.write_text(json.dumps(cfg, indent=2) + "\n", encoding='utf-8')
219+
print(f"INFO: Updated gateway.bind to '{desired_bind}' (gateway_lan_mode={lan_mode})")
220+
else:
221+
print(f"INFO: gateway.bind already '{desired_bind}', no change needed")
222+
PY
223+
else
224+
echo "WARN: OpenClaw config not found at $OPENCLAW_CONFIG_PATH, cannot apply gateway_lan_mode"
225+
fi
226+
185227
echo "Starting OpenClaw Assistant gateway (openclaw)..."
186228
openclaw gateway run &
187229
GW_PID=$!

0 commit comments

Comments
 (0)