From b8a24f57513ea065c1815822563aecee37a1d5c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E9=BB=84=E6=9E=97?= Date: Mon, 11 Sep 2023 18:24:54 +0800 Subject: [PATCH] support skip tls for frps dashboard --- cmd/frps-panel/cmd.go | 1 + config/frps-panel.ini | 2 ++ pkg/server/controller/controller.go | 24 ++++++++++++++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cmd/frps-panel/cmd.go b/cmd/frps-panel/cmd.go index 550044b..9ecae63 100644 --- a/cmd/frps-panel/cmd.go +++ b/cmd/frps-panel/cmd.go @@ -119,6 +119,7 @@ func ParseConfigFile(file string) (controller.HandleController, server.TLS, erro common.PluginPort = commonSection.Key("plugin_port").MustInt(7200) common.User = commonSection.Key("admin_user").Value() common.Pwd = commonSection.Key("admin_pwd").Value() + common.DashboardTLS = commonSection.Key("dashboard_tls").MustBool(false) common.DashboardAddr = commonSection.Key("dashboard_addr").MustString("127.0.0.1") common.DashboardPort = commonSection.Key("dashboard_port").MustInt(7500) common.DashboardUser = commonSection.Key("dashboard_user").Value() diff --git a/config/frps-panel.ini b/config/frps-panel.ini index 483f422..41307fc 100644 --- a/config/frps-panel.ini +++ b/config/frps-panel.ini @@ -16,6 +16,8 @@ dashboard_addr = 127.0.0.1 dashboard_port = 7500 dashboard_user = admin dashboard_pwd = admin +; if your frps dashboard enable tls, change this to true +dashboard_tls = false ; user tokens [users] diff --git a/pkg/server/controller/controller.go b/pkg/server/controller/controller.go index aa12e85..265c8a0 100644 --- a/pkg/server/controller/controller.go +++ b/pkg/server/controller/controller.go @@ -1,6 +1,7 @@ package controller import ( + "crypto/tls" "encoding/base64" "encoding/json" "errors" @@ -46,6 +47,7 @@ type CommonInfo struct { PluginPort int User string Pwd string + DashboardTLS bool DashboardAddr string DashboardPort int DashboardUser string @@ -697,10 +699,27 @@ func (c *HandleController) MakeEnableTokensFunc() func(context *gin.Context) { func (c *HandleController) MakeProxyFunc() func(context *gin.Context) { return func(context *gin.Context) { + var client *http.Client + var protocol string + + if c.CommonInfo.DashboardTLS { + client = &http.Client{ + Transport: &http.Transport{ + TLSClientConfig: &tls.Config{ + InsecureSkipVerify: true, + }, + }, + } + protocol = "https://" + } else { + client = http.DefaultClient + protocol = "http://" + } + res := ProxyResponse{} host := c.CommonInfo.DashboardAddr port := c.CommonInfo.DashboardPort - requestUrl := "http://" + host + ":" + strconv.Itoa(port) + context.Param("serverApi") + requestUrl := protocol + host + ":" + strconv.Itoa(port) + context.Param("serverApi") request, _ := http.NewRequest("GET", requestUrl, nil) username := c.CommonInfo.DashboardUser if len(strings.TrimSpace(username)) != 0 { @@ -710,7 +729,8 @@ func (c *HandleController) MakeProxyFunc() func(context *gin.Context) { request.Header.Add("Authorization", authorization) log.Printf("Proxy to %s with Authorization %s", requestUrl, authorization) } - response, err := http.DefaultClient.Do(request) + + response, err := client.Do(request) if err != nil { res.Code = FrpServerError