Rewrite CutOS console host header

This commit is contained in:
yankun
2026-08-02 18:20:17 +08:00
parent 40ca8cd5af
commit b53ef2a890
3 changed files with 33 additions and 2 deletions
+7 -1
View File
@@ -153,8 +153,12 @@ function downloadFile(url, dest) {
} }
function writeFrpcConfig(clawId, frpConfig, sshSecretKey, dashboardEnabled = true) { 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 ttyRemotePort = 10000 + Number(clawId);
const dashboardHostHeader = String(dashboard_host_header || '').trim();
const dashboardHostHeaderLine = dashboardHostHeader
? `hostHeaderRewrite = "${dashboardHostHeader.replace(/"/g, '\\"')}"`
: '';
const stcpBlock = sshSecretKey ? ` const stcpBlock = sshSecretKey ? `
[[proxies]] [[proxies]]
name = "ssh-${clawId}-secret" name = "ssh-${clawId}-secret"
@@ -175,6 +179,7 @@ name = "dashboard-${clawId}"
type = "http" type = "http"
localPort = ${dashboard_local_port} localPort = ${dashboard_local_port}
subdomain = "${clawId}" subdomain = "${clawId}"
${dashboardHostHeaderLine}
` : ''; ` : '';
const toml = `# 由 clawd 自动生成,请勿手动修改 const toml = `# 由 clawd 自动生成,请勿手动修改
serverAddr = "frp.claw.cutos.ai" serverAddr = "frp.claw.cutos.ai"
@@ -236,5 +241,6 @@ module.exports = {
getDashboardInfo, getDashboardInfo,
resolveOpenclawConfigFile, resolveOpenclawConfigFile,
startTtyd, startTtyd,
writeFrpcConfig,
FrpcManager, FrpcManager,
}; };
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "clawd", "name": "clawd",
"version": "1.5.9", "version": "1.5.10",
"description": "Claw Box daemon - connects local Linux box to claw.cutos.ai via WebSocket", "description": "Claw Box daemon - connects local Linux box to claw.cutos.ai via WebSocket",
"main": "lib/client.js", "main": "lib/client.js",
"bin": { "bin": {
+25
View File
@@ -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"/);
});