Update gateway settings and translations for allow_insecure_auth option
This commit is contained in:
@@ -57,13 +57,14 @@ def set_gateway_setting(key, value):
|
||||
return write_config(cfg)
|
||||
|
||||
|
||||
def apply_bind_mode_settings(bind_mode: str, port: int):
|
||||
def apply_gateway_settings(bind_mode: str, port: int, allow_insecure_auth: bool):
|
||||
"""
|
||||
Apply bind mode settings to OpenClaw config.
|
||||
Apply gateway settings to OpenClaw config.
|
||||
|
||||
Args:
|
||||
bind_mode: "loopback" or "lan"
|
||||
port: Port number to listen on (must be 1-65535)
|
||||
allow_insecure_auth: Allow insecure HTTP authentication
|
||||
"""
|
||||
# Validate bind mode
|
||||
if bind_mode not in ["loopback", "lan"]:
|
||||
@@ -84,8 +85,15 @@ def apply_bind_mode_settings(bind_mode: str, port: int):
|
||||
|
||||
gateway = cfg["gateway"]
|
||||
|
||||
# controlUi should be nested inside gateway
|
||||
if "controlUi" not in gateway:
|
||||
gateway["controlUi"] = {}
|
||||
|
||||
control_ui = gateway["controlUi"]
|
||||
|
||||
current_bind = gateway.get("bind", "")
|
||||
current_port = gateway.get("port", 18789)
|
||||
current_insecure = control_ui.get("allowInsecureAuth", False)
|
||||
|
||||
changes = []
|
||||
|
||||
@@ -93,11 +101,14 @@ def apply_bind_mode_settings(bind_mode: str, port: int):
|
||||
gateway["bind"] = bind_mode
|
||||
changes.append(f"bind: {current_bind} -> {bind_mode}")
|
||||
|
||||
# Always update port when it differs from the desired value
|
||||
if current_port != port:
|
||||
gateway["port"] = port
|
||||
changes.append(f"port: {current_port} -> {port}")
|
||||
|
||||
if current_insecure != allow_insecure_auth:
|
||||
control_ui["allowInsecureAuth"] = allow_insecure_auth
|
||||
changes.append(f"allowInsecureAuth: {current_insecure} -> {allow_insecure_auth}")
|
||||
|
||||
if changes:
|
||||
if write_config(cfg):
|
||||
print(f"INFO: Updated gateway settings: {', '.join(changes)}")
|
||||
@@ -106,7 +117,7 @@ def apply_bind_mode_settings(bind_mode: str, port: int):
|
||||
print("ERROR: Failed to write config")
|
||||
return False
|
||||
else:
|
||||
print(f"INFO: Gateway settings already correct (bind={bind_mode}, port={port})")
|
||||
print(f"INFO: Gateway settings already correct (bind={bind_mode}, port={port}, allowInsecureAuth={allow_insecure_auth})")
|
||||
return True
|
||||
|
||||
|
||||
@@ -118,13 +129,14 @@ def main():
|
||||
|
||||
cmd = sys.argv[1]
|
||||
|
||||
if cmd == "apply-bind-mode":
|
||||
if len(sys.argv) != 4:
|
||||
print("Usage: oc_config_helper.py apply-bind-mode <loopback|lan> <port>")
|
||||
if cmd == "apply-gateway-settings":
|
||||
if len(sys.argv) != 5:
|
||||
print("Usage: oc_config_helper.py apply-gateway-settings <loopback|lan> <port> <true|false>")
|
||||
sys.exit(1)
|
||||
bind_mode = sys.argv[2]
|
||||
port = int(sys.argv[3])
|
||||
success = apply_bind_mode_settings(bind_mode, port)
|
||||
allow_insecure_auth = sys.argv[4].lower() == "true"
|
||||
success = apply_gateway_settings(bind_mode, port, allow_insecure_auth)
|
||||
sys.exit(0 if success else 1)
|
||||
|
||||
elif cmd == "get":
|
||||
|
||||
Reference in New Issue
Block a user