Somrat Sorkar commited on
Commit
aeb1d95
Β·
1 Parent(s): 567a914

Auto-inject gateway token into Control UI to bypass pairing

Browse files
Files changed (1) hide show
  1. start.sh +32 -18
start.sh CHANGED
@@ -193,7 +193,7 @@ printf " β”‚ %-40s β”‚\n" "Backup: ❌ not configured"
193
  fi
194
  if [ -n "$SPACE_HOST" ]; then
195
  printf " β”‚ %-40s β”‚\n" "Keep-alive: βœ… every ${KEEP_ALIVE_INTERVAL:-300}s"
196
- printf " β”‚ %-40s β”‚\n" "Control UI: https://${SPACE_HOST}"
197
  else
198
  printf " β”‚ %-40s β”‚\n" "Keep-alive: ⏸️ local mode"
199
  fi
@@ -242,24 +242,38 @@ echo ""
242
  # Set model via environment for the gateway
243
  export LLM_MODEL="$LLM_MODEL"
244
 
245
- # For headless Docker: pre-approve the Control UI device to bypass pairing
246
- # Store approved device entry in ~/.openclaw/devices/paired.json
247
- mkdir -p /home/node/.openclaw/devices
248
- cat > /home/node/.openclaw/devices/paired.json <<'DEVICEEOF'
249
- {
250
- "devices": [
251
- {
252
- "id": "control-ui-docker",
253
- "kind": "device",
254
- "role": "control-ui",
255
- "name": "HuggingClaw Control UI",
256
- "approved": true,
257
- "approvedAt": "2026-03-31T06:07:00.000Z",
258
- "scopes": ["*"]
 
 
 
 
 
 
259
  }
260
- ]
261
- }
262
- DEVICEEOF
 
 
 
 
 
 
 
 
263
 
264
  openclaw gateway run --port 7860 --bind lan --verbose 2>&1 | tee -a /home/node/.openclaw/gateway.log &
265
  GATEWAY_PID=$!
 
193
  fi
194
  if [ -n "$SPACE_HOST" ]; then
195
  printf " β”‚ %-40s β”‚\n" "Keep-alive: βœ… every ${KEEP_ALIVE_INTERVAL:-300}s"
196
+ printf " β”‚ %-40s β”‚\n" "Control UI: https://${SPACE_HOST}/__openclaw__/canvas/auto-login.html"
197
  else
198
  printf " β”‚ %-40s β”‚\n" "Keep-alive: ⏸️ local mode"
199
  fi
 
242
  # Set model via environment for the gateway
243
  export LLM_MODEL="$LLM_MODEL"
244
 
245
+ # For headless Docker: auto-approve the Control UI by injecting token into localStorage
246
+ # Create a wrapper page that auto-configures the token and loads the dashboard
247
+ mkdir -p /home/node/.openclaw/canvas
248
+ cat > /home/node/.openclaw/canvas/auto-login.html <<'HTMLEOF'
249
+ <!DOCTYPE html>
250
+ <html>
251
+ <head>
252
+ <meta charset="utf-8">
253
+ <title>HuggingClaw β€” Connecting...</title>
254
+ <script>
255
+ // Auto-inject gateway token into Control UI on startup
256
+ const token = 'GATEWAY_TOKEN_PLACEHOLDER';
257
+ if (token && token !== 'GATEWAY_TOKEN_PLACEHOLDER') {
258
+ localStorage.setItem('openclaw:gateway:token', token);
259
+ localStorage.setItem('openclaw:gateway:url', window.location.origin);
260
+ console.log('βœ… Gateway token auto-configured. Redirecting to dashboard...');
261
+ // Redirect to the actual Control UI after a tiny delay
262
+ setTimeout(() => window.location.href = '/', 100);
263
+ } else {
264
+ document.body.innerHTML = '<h1>⚠️ Gateway token not configured</h1>';
265
  }
266
+ </script>
267
+ </head>
268
+ <body>
269
+ <h1>Connecting to OpenClaw...</h1>
270
+ <p>If this page doesn't redirect, your gateway token may not be set.</p>
271
+ </body>
272
+ </html>
273
+ HTMLEOF
274
+
275
+ # Replace the placeholder with the actual token
276
+ sed -i "s|GATEWAY_TOKEN_PLACEHOLDER|$GATEWAY_TOKEN|g" /home/node/.openclaw/canvas/auto-login.html
277
 
278
  openclaw gateway run --port 7860 --bind lan --verbose 2>&1 | tee -a /home/node/.openclaw/gateway.log &
279
  GATEWAY_PID=$!