Subsequently commited on
Commit
c3e8ce8
·
verified ·
1 Parent(s): 34e0162

Update entrypoint.sh

Browse files
Files changed (1) hide show
  1. entrypoint.sh +45 -34
entrypoint.sh CHANGED
@@ -189,7 +189,8 @@ clear_stale_locks
189
  run_doctor
190
  if doctor_locked; then
191
  warn "doctor blocked by state ownership lock - diagnostics follow"
192
- log "now (UTC): $(date -u +%Y-%m-%dT%H:%M:%S)" log "processes in this container:"
 
193
  for p in /proc/[0-9]*; do
194
  c=$(tr '\0' ' ' < "$p/cmdline" 2>/dev/null)
195
  [ -n "$c" ] && echo "[proc] ${p#/proc/}: $(echo "$c" | cut -c1-160)"
@@ -210,46 +211,56 @@ log "Doctor step done."
210
  chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
211
 
212
  # ----------------------------------------------------------------
213
- # Auto-approve pending device pairings (background)
 
 
 
 
214
  # ----------------------------------------------------------------
 
215
  (
216
- DEVICES_DIR="$OPENCLAW_HOME/.openclaw/devices"
217
- mkdir -p "$DEVICES_DIR"
218
- log "Device auto-pairing watcher started"
219
  while true; do
220
- sleep 8
221
- PENDING="$DEVICES_DIR/pending.json"
222
- PAIRED="$DEVICES_DIR/paired.json"
223
- if [ -f "$PENDING" ]; then
224
- node - << 'JSEOF'
 
 
225
  const fs = require('fs');
226
- const dir = process.env.OPENCLAW_HOME + '/.openclaw/devices';
227
- const pend = dir + '/pending.json';
228
- const pair = dir + '/paired.json';
229
- try {
230
- const raw = fs.readFileSync(pend, 'utf-8').trim();
231
- if (!raw || raw === '[]' || raw === '{}') process.exit(0);
232
- let pending = JSON.parse(raw);
233
- if (!Array.isArray(pending)) pending = Object.values(pending);
234
- if (pending.length === 0) process.exit(0);
235
- let paired = [];
236
- try { paired = JSON.parse(fs.readFileSync(pair, 'utf-8')); } catch(e) {}
237
- if (!Array.isArray(paired)) paired = [];
238
- const ids = new Set(paired.map(function(d){ return d.id||d.deviceId||d.name; }));
239
- const todo = pending.filter(function(d){ return !ids.has(d.id||d.deviceId||d.name); });
240
- if (todo.length === 0) process.exit(0);
241
- const now = new Date().toISOString();
242
- paired = paired.concat(todo.map(function(d){
243
- return Object.assign({}, d, { approved: true, approvedAt: now });
244
- }));
245
- fs.writeFileSync(pair, JSON.stringify(paired, null, 2));
246
- fs.writeFileSync(pend, '[]');
247
- console.log('[auto-pair] Approved ' + todo.length + ' device(s)');
248
- } catch(e) { /* ignore */ }
249
  JSEOF
250
- fi
 
 
 
 
 
 
 
251
  done
252
  ) &
 
253
 
254
  # ----------------------------------------------------------------
255
  # Gateway loop
 
189
  run_doctor
190
  if doctor_locked; then
191
  warn "doctor blocked by state ownership lock - diagnostics follow"
192
+ log "now (UTC): $(date -u +%Y-%m-%dT%H:%M:%S)"
193
+ log "processes in this container:"
194
  for p in /proc/[0-9]*; do
195
  c=$(tr '\0' ' ' < "$p/cmdline" 2>/dev/null)
196
  [ -n "$c" ] && echo "[proc] ${p#/proc/}: $(echo "$c" | cut -c1-160)"
 
211
  chmod -R go-w "$OPENCLAW_HOME/.openclaw/npm" "$OPENCLAW_HOME/.openclaw/extensions" 2>/dev/null || true
212
 
213
  # ----------------------------------------------------------------
214
+ # Password-only access.
215
+ # A pairing request only exists AFTER the gateway password/token was accepted,
216
+ # so approving pending requests = "correct password gets in".
217
+ # Security therefore depends entirely on OPENCLAW_GATEWAY_TOKEN being long.
218
+ # Set AUTO_APPROVE_PAIRING=0 (Space variable) to switch this off.
219
  # ----------------------------------------------------------------
220
+ if [ "${AUTO_APPROVE_PAIRING:-1}" = "1" ]; then
221
  (
222
+ log "Pairing auto-approver started (only requests that already passed gateway auth)"
223
+ SAMPLED=0
 
224
  while true; do
225
+ sleep 5
226
+ openclaw devices list --json </dev/null >/tmp/devices.json 2>/tmp/devices.err || continue
227
+ if [ $SAMPLED -eq 0 ] && [ -s /tmp/devices.json ]; then
228
+ log "devices list sample: $(head -c 300 /tmp/devices.json | tr '\n' ' ')"
229
+ SAMPLED=1
230
+ fi
231
+ IDS=$(node - <<'JSEOF'
232
  const fs = require('fs');
233
+ let data;
234
+ try { data = JSON.parse(fs.readFileSync('/tmp/devices.json', 'utf8')); } catch (e) { process.exit(0); }
235
+ const out = [];
236
+ (function walk(v, key) {
237
+ if (Array.isArray(v)) {
238
+ const pending = /pending/i.test(key || '');
239
+ for (const x of v) {
240
+ if (pending && x && typeof x === 'object') {
241
+ const id = x.requestId || x.id;
242
+ if (typeof id === 'string') out.push(id);
243
+ } else {
244
+ walk(x, key);
245
+ }
246
+ }
247
+ } else if (v && typeof v === 'object') {
248
+ for (const k of Object.keys(v)) walk(v[k], k);
249
+ }
250
+ })(data, '');
251
+ console.log(out.join('\n'));
 
 
 
 
252
  JSEOF
253
+ )
254
+ for ID in $IDS; do
255
+ if openclaw devices approve "$ID" </dev/null >/tmp/approve.out 2>&1; then
256
+ log "Approved pairing request $ID"
257
+ else
258
+ warn "approve failed for $ID: $(head -c 200 /tmp/approve.out | tr '\n' ' ')"
259
+ fi
260
+ done
261
  done
262
  ) &
263
+ fi
264
 
265
  # ----------------------------------------------------------------
266
  # Gateway loop