Files
EdgeAdmin/internal/web/actions/default/servers/server/settings/tcp/index.go

93 lines
2.0 KiB
Go
Raw Normal View History

2020-08-21 21:09:42 +08:00
package tcp
import (
2020-09-13 20:37:07 +08:00
"encoding/json"
2020-08-21 21:09:42 +08:00
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
2020-09-13 20:37:07 +08:00
"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"
2020-08-21 21:09:42 +08:00
)
2020-09-13 20:37:07 +08:00
// TCP设置
2020-08-21 21:09:42 +08:00
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "setting", "index")
this.SecondMenu("tcp")
}
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
2020-09-21 19:51:50 +08:00
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
2020-09-13 20:37:07 +08:00
if !isOk {
return
}
2020-09-16 09:09:10 +08:00
tcpConfig := &serverconfigs.TCPProtocolConfig{}
if len(server.TcpJSON) > 0 {
err := json.Unmarshal(server.TcpJSON, tcpConfig)
if err != nil {
this.ErrorPage(err)
}
} else {
tcpConfig.IsOn = true
2020-09-13 20:37:07 +08:00
}
this.Data["serverType"] = server.Type
2020-09-16 09:09:10 +08:00
this.Data["tcpConfig"] = tcpConfig
2020-08-21 21:09:42 +08:00
this.Show()
}
2020-09-13 20:37:07 +08:00
func (this *IndexAction) RunPost(params struct {
ServerId int64
ServerType string
Addresses string
Must *actions.Must
}) {
2020-11-20 15:32:42 +08:00
defer this.CreateLogInfo("修改代理服务 %d TCP设置", params.ServerId)
2020-09-21 19:51:50 +08:00
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
2020-09-13 20:37:07 +08:00
if !isOk {
return
}
2020-09-15 14:44:52 +08:00
addresses := []*serverconfigs.NetworkAddressConfig{}
err := json.Unmarshal([]byte(params.Addresses), &addresses)
2020-09-13 20:37:07 +08:00
if err != nil {
this.Fail("端口地址解析失败:" + err.Error())
}
2020-09-16 09:09:10 +08:00
tcpConfig := &serverconfigs.TCPProtocolConfig{}
if len(server.TcpJSON) > 0 {
err := json.Unmarshal(server.TcpJSON, tcpConfig)
2020-09-15 14:44:52 +08:00
if err != nil {
this.ErrorPage(err)
}
2020-09-16 09:09:10 +08:00
} else {
tcpConfig.IsOn = true
}
tcpConfig.Listen = addresses
2020-09-15 14:44:52 +08:00
2020-09-16 09:09:10 +08:00
configData, err := json.Marshal(tcpConfig)
if err != nil {
this.ErrorPage(err)
return
}
2020-09-15 14:44:52 +08:00
2020-09-16 09:09:10 +08:00
_, err = this.RPC().ServerRPC().UpdateServerTCP(this.AdminContext(), &pb.UpdateServerTCPRequest{
ServerId: params.ServerId,
2020-12-23 09:52:31 +08:00
TcpJSON: configData,
2020-09-16 09:09:10 +08:00
})
if err != nil {
this.ErrorPage(err)
return
2020-09-13 20:37:07 +08:00
}
this.Success()
}