fix(proxy): add "oldName" && "newName" paras to fix unable to modify proxy name
This commit is contained in:
+14
-3
@@ -23,6 +23,8 @@ type InstanceInfo struct {
|
||||
|
||||
type FrpcProxyInfo struct {
|
||||
Name string `json:"name"`
|
||||
OldName string `json:"oldName"`
|
||||
NewName string `json:"newName"`
|
||||
Type string `json:"type"`
|
||||
LocalIP string `json:"local_ip"`
|
||||
LocalPort int `json:"local_port"`
|
||||
@@ -349,11 +351,20 @@ func ModifyFrpcProxy(configContent string, info FrpcProxyInfo) (string, error) {
|
||||
return "", fmt.Errorf("failed to parse config: %w", err)
|
||||
}
|
||||
|
||||
searchName := info.OldName
|
||||
if searchName == "" {
|
||||
searchName = info.Name
|
||||
}
|
||||
|
||||
var found bool
|
||||
for i, proxy := range config.Proxies {
|
||||
if name, ok := proxy["name"].(string); ok && name == info.Name {
|
||||
if name, ok := proxy["name"].(string); ok && name == searchName {
|
||||
proxyName := info.NewName
|
||||
if proxyName == "" {
|
||||
proxyName = info.Name
|
||||
}
|
||||
config.Proxies[i] = map[string]interface{}{
|
||||
"name": info.Name,
|
||||
"name": proxyName,
|
||||
"type": info.Type,
|
||||
"localIP": info.LocalIP,
|
||||
"localPort": info.LocalPort,
|
||||
@@ -365,7 +376,7 @@ func ModifyFrpcProxy(configContent string, info FrpcProxyInfo) (string, error) {
|
||||
}
|
||||
|
||||
if !found {
|
||||
return "", fmt.Errorf("proxy %s not found", info.Name)
|
||||
return "", fmt.Errorf("proxy %s not found", searchName)
|
||||
}
|
||||
|
||||
result, err := EncodeFrpcConfig(config)
|
||||
|
||||
+6
-4
@@ -1063,7 +1063,8 @@ X-Timestamp: 1704067200000
|
||||
{
|
||||
"instanceID": "1",
|
||||
"proxyInfo": {
|
||||
"name": "ssh_proxy",
|
||||
"oldName": "ssh_proxy",
|
||||
"newName": "ssh_proxy123",
|
||||
"type": "tcp",
|
||||
"localIP": "127.0.0.1",
|
||||
"localPort": "22",
|
||||
@@ -1080,7 +1081,8 @@ X-Timestamp: 1704067200000
|
||||
| Field | Type | Required | Description |
|
||||
|-------|------|----------|-------------|
|
||||
| instanceID | string | Yes | Instance ID (the ID of the frpc instance) |
|
||||
| proxyInfo.name | string | Yes | Proxy name (used to identify which proxy to modify) |
|
||||
| proxyInfo.oldName | string | Yes | Proxy old name (used to identify which proxy to modify) |
|
||||
| proxyInfo.newName | string | Yes | Proxy new name (used to identify which proxy to modify to) |
|
||||
| proxyInfo.type | string | Yes | Proxy type (e.g., tcp, udp, http, https) |
|
||||
| proxyInfo.localIP | string | Yes | Local IP address to forward to |
|
||||
| proxyInfo.localPort | string | Yes | Local port to forward from |
|
||||
@@ -1094,7 +1096,7 @@ X-Timestamp: 1704067200000
|
||||
"data": {
|
||||
"instanceID": 1,
|
||||
"configPath": "./configs/superfrpc_user_my_frpc.toml",
|
||||
"proxyName": "ssh_proxy"
|
||||
"proxyName": "ssh_proxy123"
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -1111,7 +1113,7 @@ The proxy configuration in the config file will be updated to the following form
|
||||
|
||||
```toml
|
||||
[[proxies]]
|
||||
name = ssh_proxy
|
||||
name = ssh_proxy123
|
||||
type = tcp
|
||||
local_ip = 127.0.0.1
|
||||
local_port = 22
|
||||
|
||||
+12
-4
@@ -10,8 +10,8 @@ import (
|
||||
|
||||
"super-frpc/config"
|
||||
"super-frpc/database"
|
||||
"super-frpc/utils"
|
||||
"super-frpc/postLog"
|
||||
"super-frpc/utils"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
@@ -149,6 +149,8 @@ func ModifyProxyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
proxyInfo := config.FrpcProxyInfo{
|
||||
OldName: getStringFromMap(proxyInfoMap, "oldName"),
|
||||
NewName: getStringFromMap(proxyInfoMap, "newName"),
|
||||
Name: getStringFromMap(proxyInfoMap, "name"),
|
||||
Type: getStringFromMap(proxyInfoMap, "type"),
|
||||
LocalIP: getStringFromMap(proxyInfoMap, "localIP"),
|
||||
@@ -156,7 +158,13 @@ func ModifyProxyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
RemotePort: getNumFromMap(proxyInfoMap, "remotePort"),
|
||||
}
|
||||
|
||||
if proxyInfo.Name == "" || proxyInfo.Type == "" || proxyInfo.LocalIP == "" ||
|
||||
if proxyInfo.OldName == "" {
|
||||
postLog.Error("[ModifyProxyHandler] oldName is required")
|
||||
utils.SendErrorResponse(w, http.StatusBadRequest, "oldName is required")
|
||||
return
|
||||
}
|
||||
|
||||
if proxyInfo.NewName == "" || proxyInfo.Type == "" || proxyInfo.LocalIP == "" ||
|
||||
proxyInfo.LocalPort == 0 || proxyInfo.RemotePort == 0 {
|
||||
postLog.Error("[ModifyProxyHandler] Missing required fields in proxyInfo")
|
||||
utils.SendErrorResponse(w, http.StatusBadRequest, "Missing required fields in proxyInfo")
|
||||
@@ -201,9 +209,9 @@ func ModifyProxyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
utils.SendSuccessResponse(w, "Proxy modified successfully", map[string]interface{}{
|
||||
"instanceID": instance.ID,
|
||||
"configPath": instance.ConfigPath,
|
||||
"proxyName": proxyInfo.Name,
|
||||
"proxyName": proxyInfo.NewName,
|
||||
})
|
||||
postLog.Info(fmt.Sprintf("[ModifyProxyHandler] Proxy %s modified successfully for instance %d", proxyInfo.Name, instance.ID))
|
||||
postLog.Info(fmt.Sprintf("[ModifyProxyHandler] Proxy %s modified successfully for instance %d", proxyInfo.NewName, instance.ID))
|
||||
}
|
||||
|
||||
func DeleteProxyHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
Reference in New Issue
Block a user