mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-01 09:20:24 +08:00
支持UDP代理
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
package udp
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
)
|
||||
|
||||
// IndexAction UDP设置
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
@@ -16,7 +22,71 @@ func (this *IndexAction) Init() {
|
||||
func (this *IndexAction) RunGet(params struct {
|
||||
ServerId int64
|
||||
}) {
|
||||
// TODO
|
||||
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
|
||||
if !isOk {
|
||||
return
|
||||
}
|
||||
udpConfig := &serverconfigs.UDPProtocolConfig{}
|
||||
if len(server.UdpJSON) > 0 {
|
||||
err := json.Unmarshal(server.UdpJSON, udpConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
}
|
||||
} else {
|
||||
udpConfig.IsOn = true
|
||||
}
|
||||
|
||||
this.Data["serverType"] = server.Type
|
||||
this.Data["udpConfig"] = udpConfig
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
ServerId int64
|
||||
ServerType string
|
||||
Addresses string
|
||||
|
||||
Must *actions.Must
|
||||
}) {
|
||||
defer this.CreateLogInfo("修改代理服务 %d UDP设置", params.ServerId)
|
||||
|
||||
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
|
||||
if !isOk {
|
||||
return
|
||||
}
|
||||
|
||||
addresses := []*serverconfigs.NetworkAddressConfig{}
|
||||
err := json.Unmarshal([]byte(params.Addresses), &addresses)
|
||||
if err != nil {
|
||||
this.Fail("端口地址解析失败:" + err.Error())
|
||||
}
|
||||
|
||||
udpConfig := &serverconfigs.UDPProtocolConfig{}
|
||||
if len(server.UdpJSON) > 0 {
|
||||
err := json.Unmarshal(server.UdpJSON, udpConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
}
|
||||
} else {
|
||||
udpConfig.IsOn = true
|
||||
}
|
||||
udpConfig.Listen = addresses
|
||||
|
||||
configData, err := json.Marshal(udpConfig)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = this.RPC().ServerRPC().UpdateServerUDP(this.AdminContext(), &pb.UpdateServerUDPRequest{
|
||||
ServerId: params.ServerId,
|
||||
UdpJSON: configData,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user