修复 frps/frpc TOML 配置注入:新增 protocol.TOMLQuote 并在两处配置渲染全部使用

Result: {"status":"keep","total_issues":8,"eslint_errors":0,"eslint_problems":0,"eslint_warnings":0,"golint_canonicalheader":0,"golint_errname":0,"golint_errorlint":1,"golint_exhaustive":0,"golint_forcetypeassert":0,"golint_gosec":0,"golint_intrange":0,"golint_modernize":3,"golint_nilnil":3,"golint_perfsprint":0,"golint_prealloc":0,"golint_recvcheck":1,"golint_test_testifylint":0,"golint_test_thelper":0,"golint_test_total":0,"golint_test_usetesting":0,"golint_total":8,"golint_usestdlibvars":0,"golint_vetx_total":0,"golint_wastedassign":0,"measure_s":77,"tsc_errors":0,"vitest_failed":0,"vitest_total":126}
This commit is contained in:
ryan
2026-08-26 10:01:33 +08:00
parent ed1efd3d54
commit 4f8e7e66e3
5 changed files with 69 additions and 9 deletions
+10 -6
View File
@@ -285,23 +285,27 @@ func buildFrpcToml(relay service.FlaredRelayInfo, proxies []service.FlaredProxyE
host, port := parseAddr(relay.Address)
fmt.Fprintf(&buf, "serverAddr = \"%s\"\nserverPort = %s\n", host, port)
fmt.Fprintf(&buf, "serverAddr = %s\nserverPort = %s\n", service.TOMLQuote(host), service.TOMLQuote(port))
if relay.AuthToken != "" {
fmt.Fprintf(&buf, "auth.method = \"token\"\nauth.token = \"%s\"\n", relay.AuthToken)
fmt.Fprintf(&buf, "auth.method = \"token\"\nauth.token = %s\n", service.TOMLQuote(relay.AuthToken))
}
if relay.ProxyURL != "" {
fmt.Fprintf(&buf, "transport.proxyURL = \"%s\"\n", relay.ProxyURL)
fmt.Fprintf(&buf, "transport.proxyURL = %s\n", service.TOMLQuote(relay.ProxyURL))
}
buf.WriteString("\n")
for _, proxy := range proxies {
fmt.Fprintf(&buf, "[[proxies]]\nname = \"%s\"\ntype = \"%s\"\nlocalIP = \"%s\"\nlocalPort = %d\n",
proxy.Name, proxy.Type, proxy.LocalAddr, proxy.LocalPort)
fmt.Fprintf(&buf, "[[proxies]]\nname = %s\ntype = %s\nlocalIP = %s\nlocalPort = %d\n",
service.TOMLQuote(proxy.Name), service.TOMLQuote(proxy.Type), service.TOMLQuote(proxy.LocalAddr), proxy.LocalPort)
if len(proxy.CustomDomains) > 0 {
fmt.Fprintf(&buf, "customDomains = [\"%s\"]\n", strings.Join(proxy.CustomDomains, "\", \""))
quoted := make([]string, len(proxy.CustomDomains))
for i := range proxy.CustomDomains {
quoted[i] = service.TOMLQuote(proxy.CustomDomains[i])
}
fmt.Fprintf(&buf, "customDomains = [%s]\n", strings.Join(quoted, ", "))
}
buf.WriteString("\n")
}
+2 -3
View File
@@ -182,7 +182,7 @@ func (m *Manager) renderConfig(cfg *service.RelayConfig) error {
if cfg.AuthToken != "" {
buf.WriteString("[auth]\n")
buf.WriteString("method = \"token\"\n")
fmt.Fprintf(&buf, "token = \"%s\"\n", cfg.AuthToken)
buf.WriteString("token = " + service.TOMLQuote(cfg.AuthToken) + "\n")
}
// WebServer configuration
@@ -203,8 +203,7 @@ func (m *Manager) renderConfig(cfg *service.RelayConfig) error {
if password == "" {
password = "admin"
}
fmt.Fprintf(&buf, "password = \"%s\"\n", password)
fmt.Fprintf(&buf, "password = %s\n", service.TOMLQuote(password))
return os.WriteFile(m.configPath, buf.Bytes(), frpsConfigFilePerm)
}