diff --git a/lib/frpc.js b/lib/frpc.js index ba9b0c1..feb0759 100644 --- a/lib/frpc.js +++ b/lib/frpc.js @@ -153,8 +153,12 @@ function downloadFile(url, dest) { } function writeFrpcConfig(clawId, frpConfig, sshSecretKey, dashboardEnabled = true) { - const { auth_token, dashboard_local_port = 18789 } = frpConfig; + const { auth_token, dashboard_local_port = 18789, dashboard_host_header } = frpConfig; const ttyRemotePort = 10000 + Number(clawId); + const dashboardHostHeader = String(dashboard_host_header || '').trim(); + const dashboardHostHeaderLine = dashboardHostHeader + ? `hostHeaderRewrite = "${dashboardHostHeader.replace(/"/g, '\\"')}"` + : ''; const stcpBlock = sshSecretKey ? ` [[proxies]] name = "ssh-${clawId}-secret" @@ -175,6 +179,7 @@ name = "dashboard-${clawId}" type = "http" localPort = ${dashboard_local_port} subdomain = "${clawId}" +${dashboardHostHeaderLine} ` : ''; const toml = `# 由 clawd 自动生成,请勿手动修改 serverAddr = "frp.claw.cutos.ai" @@ -236,5 +241,6 @@ module.exports = { getDashboardInfo, resolveOpenclawConfigFile, startTtyd, + writeFrpcConfig, FrpcManager, }; diff --git a/package.json b/package.json index 8c3d634..621737c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "clawd", - "version": "1.5.9", + "version": "1.5.10", "description": "Claw Box daemon - connects local Linux box to claw.cutos.ai via WebSocket", "main": "lib/client.js", "bin": { diff --git a/test/frpc-config.test.js b/test/frpc-config.test.js new file mode 100644 index 0000000..164e29b --- /dev/null +++ b/test/frpc-config.test.js @@ -0,0 +1,25 @@ +'use strict'; + +const test = require('node:test'); +const assert = require('node:assert/strict'); +const fs = require('node:fs'); +const os = require('node:os'); +const path = require('node:path'); + +const configDir = fs.mkdtempSync(path.join(os.tmpdir(), 'clawd-frpc-')); +process.env.CLAWD_CONFIG_DIR = configDir; + +const { writeFrpcConfig } = require('../lib/frpc'); + +test('dashboard proxy can rewrite Host header for CutOS pi-web', () => { + writeFrpcConfig(1045, { + auth_token: 'test-token', + dashboard_local_port: 30141, + dashboard_host_header: '127.0.0.1', + }, null, true); + + const toml = fs.readFileSync(path.join(configDir, 'frpc.toml'), 'utf8'); + assert.match(toml, /localPort = 30141/); + assert.match(toml, /subdomain = "1045"/); + assert.match(toml, /hostHeaderRewrite = "127\.0\.0\.1"/); +});