mirror of
https://github.com/yhl452493373/frpc-panel.git
synced 2026-04-04 06:17:00 +08:00
complete full functions;
add some translations;
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
package controller
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"github.com/fatedier/frp/pkg/config"
|
||||
"github.com/vaughan0/go-ini"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -10,17 +16,95 @@ func trimString(str string) string {
|
||||
return strings.TrimSpace(str)
|
||||
}
|
||||
|
||||
func cleanString(originalString string) string {
|
||||
return trimString(originalString)
|
||||
func serializeSectionsToString() []byte {
|
||||
var build strings.Builder
|
||||
build.WriteString("[common]\n")
|
||||
for key, value := range clientCommon {
|
||||
build.WriteString(fmt.Sprintf("%s = %s\n", key, value))
|
||||
}
|
||||
build.WriteString("\n")
|
||||
|
||||
for name, section := range clientProxies {
|
||||
build.WriteString(fmt.Sprintf("[%s]\n", name))
|
||||
for key, value := range section {
|
||||
build.WriteString(fmt.Sprintf("%s = %s\n", key, value))
|
||||
}
|
||||
build.WriteString("\n")
|
||||
}
|
||||
|
||||
return []byte(build.String())
|
||||
}
|
||||
|
||||
func stringContains(element string, data []string) bool {
|
||||
for _, v := range data {
|
||||
if element == v {
|
||||
return true
|
||||
func (c *HandleController) buildRequestUrl(serverApi string) string {
|
||||
var protocol string
|
||||
|
||||
if c.CommonInfo.DashboardTls {
|
||||
protocol = "https://"
|
||||
} else {
|
||||
protocol = "http://"
|
||||
}
|
||||
|
||||
host := c.CommonInfo.DashboardAddr
|
||||
port := c.CommonInfo.DashboardPort
|
||||
requestUrl := protocol + host + ":" + strconv.Itoa(port) + serverApi
|
||||
|
||||
return requestUrl
|
||||
}
|
||||
|
||||
func (c *HandleController) buildClient() *http.Client {
|
||||
var client *http.Client
|
||||
|
||||
if c.CommonInfo.DashboardTls {
|
||||
client = &http.Client{
|
||||
Transport: &http.Transport{
|
||||
TLSClientConfig: &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
} else {
|
||||
client = http.DefaultClient
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func (c *HandleController) getClientResponse(request *http.Request, client *http.Client) (*http.Response, error) {
|
||||
username := c.CommonInfo.DashboardUser
|
||||
password := c.CommonInfo.DashboardPwd
|
||||
if trimString(username) != "" && trimString(password) != "" {
|
||||
request.SetBasicAuth(username, password)
|
||||
}
|
||||
|
||||
response, err := client.Do(request)
|
||||
return response, err
|
||||
}
|
||||
|
||||
func (c *HandleController) parseResponse(res *ProxyResponse, response *http.Response) string {
|
||||
res.Code = response.StatusCode
|
||||
body, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
res.Success = false
|
||||
res.Message = err.Error()
|
||||
} else {
|
||||
url := response.Request.URL
|
||||
if res.Code == http.StatusOK {
|
||||
res.Success = true
|
||||
res.Data = string(body)
|
||||
res.Message = fmt.Sprintf("Proxy to %s success", url)
|
||||
} else {
|
||||
res.Success = false
|
||||
if res.Code == http.StatusNotFound {
|
||||
res.Message = fmt.Sprintf("Proxy to %s error: url not found", url)
|
||||
} else {
|
||||
res.Message = fmt.Sprintf("Proxy to %s error: %s", url, string(body))
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
||||
log.Printf(res.Message)
|
||||
|
||||
return string(body)
|
||||
}
|
||||
|
||||
func (c *HandleController) parseConfigure(content, proxyType string) (interface{}, error) {
|
||||
@@ -44,7 +128,7 @@ func (c *HandleController) parseConfigure(content, proxyType string) (interface{
|
||||
currentProxies[name] = section
|
||||
}
|
||||
clientProxies[name] = section
|
||||
delete(clientProxies[name], "name")
|
||||
delete(clientProxies[name], nameKey)
|
||||
}
|
||||
|
||||
if proxyType == "none" {
|
||||
|
||||
Reference in New Issue
Block a user