diff --git a/lib/frpc.js b/lib/frpc.js index 344e4c6..6d2018d 100644 --- a/lib/frpc.js +++ b/lib/frpc.js @@ -20,23 +20,24 @@ const TTYD_PORT = 7681; /** * 从 openclaw 配置文件中提取 dashboard token 和端口。 - * openclaw 将 gateway token 持久化存储在 ~/.openclaw/openclaw.json 中, + * openclaw 将配置持久化存储在 ~/.openclaw/config/config.yaml 中, * 直接读取比执行命令更可靠(不依赖 PATH、不需要进程启动等待)。 * systemd 服务的 ProtectHome=read-only 允许读取 /home 下的文件。 */ function getDashboardInfo() { const configCandidates = [ - path.join(os.homedir(), '.openclaw', 'openclaw.json'), - '/home/sts/.openclaw/openclaw.json', - '/root/.openclaw/openclaw.json', + path.join(os.homedir(), '.openclaw', 'config', 'config.yaml'), + '/home/sts/.openclaw/config/config.yaml', + '/root/.openclaw/config/config.yaml', ]; for (const cfgPath of configCandidates) { try { - const raw = fs.readFileSync(cfgPath, 'utf8'); - const config = JSON.parse(raw); - const token = config?.gateway?.auth?.token; - const port = config?.gateway?.port || 18789; + const raw = fs.readFileSync(cfgPath, 'utf8'); + const tokenMatch = raw.match(/^\s*token:\s*["']?([A-Za-z0-9_\-\.]+)["']?\s*$/m); + const portMatch = raw.match(/^\s*port:\s*(\d+)\s*$/m); + const token = tokenMatch?.[1]; + const port = portMatch ? Number(portMatch[1]) : 18789; if (token) { log.info('dashboard', `从配置文件读取: port=${port}, token=${token.substring(0, 8)}...`); return Promise.resolve({ dashboard_port: port, dashboard_token: token });