tao-shen commited on
Commit
cb0513d
Β·
1 Parent(s): 331869d

fix: use fixed auth token + python-based token injection + restore entrypoint inject

Browse files
openclaw.json CHANGED
@@ -3,7 +3,7 @@
3
  "mode": "local",
4
  "bind": "lan",
5
  "port": 7860,
6
- "auth": { "mode": "none" },
7
  "trustedProxies": [
8
  "0.0.0.0/0"
9
  ],
 
3
  "mode": "local",
4
  "bind": "lan",
5
  "port": 7860,
6
+ "auth": { "token": "hf-space-public-token" },
7
  "trustedProxies": [
8
  "0.0.0.0/0"
9
  ],
scripts/entrypoint.sh CHANGED
@@ -48,6 +48,13 @@ touch /home/node/logs/app.log
48
  ENTRYPOINT_END=$(date +%s)
49
  echo "[TIMER] Entrypoint (before sync_hf.py): $((ENTRYPOINT_END - BOOT_START))s"
50
 
 
 
 
 
 
 
 
51
  # ── Start OpenClaw via sync_hf.py (don't wait for DNS β€” it runs in bg) ─────
52
  echo "[entrypoint] Starting OpenClaw via sync_hf.py..."
53
  echo "[entrypoint] DNS resolution running in background (PID $DNS_PID), app will use it when ready"
 
48
  ENTRYPOINT_END=$(date +%s)
49
  echo "[TIMER] Entrypoint (before sync_hf.py): $((ENTRYPOINT_END - BOOT_START))s"
50
 
51
+ # ── Inject auth token into Control UI HTML ─────────────────────────────────
52
+ INJECT_START=$(date +%s)
53
+ if [ -x /home/node/scripts/inject-token.sh ]; then
54
+ bash /home/node/scripts/inject-token.sh
55
+ fi
56
+ echo "[TIMER] Token inject: $(($(date +%s) - INJECT_START))s"
57
+
58
  # ── Start OpenClaw via sync_hf.py (don't wait for DNS β€” it runs in bg) ─────
59
  echo "[entrypoint] Starting OpenClaw via sync_hf.py..."
60
  echo "[entrypoint] DNS resolution running in background (PID $DNS_PID), app will use it when ready"
scripts/inject-token.sh CHANGED
@@ -1,15 +1,30 @@
1
  #!/bin/sh
2
  # Inject auto-token config into Control UI so the browser auto-connects
3
- TOKEN_SCRIPT='<script>!function(){var K="openclaw.control.settings.v1";try{var s=JSON.parse(localStorage.getItem(K)||"{}")||{};if(!s.token){s.token="openclaw-space-default";localStorage.setItem(K,JSON.stringify(s))}}catch(e){}}()</script>'
 
4
 
5
- OPENCLAW_APP_DIR="${OPENCLAW_APP_DIR:-/usr/local/lib/node_modules/openclaw}"
6
 
7
- for f in "$OPENCLAW_APP_DIR/dist/control-ui/index.html" "$OPENCLAW_APP_DIR/control-ui/index.html" /app/openclaw/dist/control-ui/index.html; do
8
- if [ -f "$f" ]; then
9
- sed -i "s|</head>|${TOKEN_SCRIPT}</head>|" "$f"
10
- echo "[build] Token auto-config injected into $f"
11
- exit 0
12
- fi
13
- done
14
 
15
- echo "[build] WARNING: control-ui/index.html not found, skipping token injection"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #!/bin/sh
2
  # Inject auto-token config into Control UI so the browser auto-connects
3
+ # The token must match gateway.auth.token in openclaw.json
4
+ TOKEN="hf-space-public-token"
5
 
6
+ INDEX_HTML="/app/openclaw/dist/control-ui/index.html"
7
 
8
+ if [ ! -f "$INDEX_HTML" ]; then
9
+ echo "[inject-token] WARNING: $INDEX_HTML not found, skipping"
10
+ exit 0
11
+ fi
 
 
 
12
 
13
+ # Create the injection script
14
+ INJECT_SCRIPT="<script>!function(){var K='openclaw.control.settings.v1';try{var s=JSON.parse(localStorage.getItem(K)||'{}');if(!s.token||s.token===''){s.token='${TOKEN}';localStorage.setItem(K,JSON.stringify(s))}}catch(e){}}()</script>"
15
+
16
+ # Use python3 for reliable string replacement (avoids sed delimiter issues)
17
+ python3 -c "
18
+ import sys
19
+ f = '${INDEX_HTML}'
20
+ with open(f, 'r') as fh:
21
+ html = fh.read()
22
+ inject = '''${INJECT_SCRIPT}'''
23
+ if '</head>' in html and inject not in html:
24
+ html = html.replace('</head>', inject + '</head>')
25
+ with open(f, 'w') as fh:
26
+ fh.write(html)
27
+ print('[inject-token] Token injected into ' + f)
28
+ else:
29
+ print('[inject-token] Skipped (already injected or no </head> found)')
30
+ "
scripts/sync_hf.py CHANGED
@@ -327,7 +327,7 @@ class OpenClawFullSync:
327
  "mode": "local",
328
  "bind": "lan",
329
  "port": 7860,
330
- "auth": {"mode": "none"},
331
  "trustedProxies": ["0.0.0.0/0"],
332
  "controlUi": {
333
  "allowInsecureAuth": True,
 
327
  "mode": "local",
328
  "bind": "lan",
329
  "port": 7860,
330
+ "auth": {"token": "hf-space-public-token"},
331
  "trustedProxies": ["0.0.0.0/0"],
332
  "controlUi": {
333
  "allowInsecureAuth": True,