阶段性提交

This commit is contained in:
GoEdgeLab
2020-09-16 09:09:10 +08:00
parent 4807a6672f
commit 12c90bc553
44 changed files with 959 additions and 279 deletions

View File

@@ -28,6 +28,7 @@ type RPCClient struct {
originNodeClients []pb.OriginServerServiceClient
httpWebClients []pb.HTTPWebServiceClient
reverseProxyClients []pb.ReverseProxyServiceClient
httpGzipClients []pb.HTTPGzipServiceClient
}
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
@@ -45,6 +46,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
originNodeClients := []pb.OriginServerServiceClient{}
httpWebClients := []pb.HTTPWebServiceClient{}
reverseProxyClients := []pb.ReverseProxyServiceClient{}
httpGzipClients := []pb.HTTPGzipServiceClient{}
conns := []*grpc.ClientConn{}
for _, endpoint := range apiConfig.RPC.Endpoints {
@@ -70,6 +72,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
originNodeClients = append(originNodeClients, pb.NewOriginServerServiceClient(conn))
httpWebClients = append(httpWebClients, pb.NewHTTPWebServiceClient(conn))
reverseProxyClients = append(reverseProxyClients, pb.NewReverseProxyServiceClient(conn))
httpGzipClients = append(httpGzipClients, pb.NewHTTPGzipServiceClient(conn))
}
return &RPCClient{
@@ -84,6 +87,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
originNodeClients: originNodeClients,
httpWebClients: httpWebClients,
reverseProxyClients: reverseProxyClients,
httpGzipClients: httpGzipClients,
}, nil
}
@@ -157,6 +161,13 @@ func (this *RPCClient) ReverseProxyRPC() pb.ReverseProxyServiceClient {
return nil
}
func (this *RPCClient) HTTPGzipRPC() pb.HTTPGzipServiceClient {
if len(this.httpGzipClients) > 0 {
return this.httpGzipClients[rands.Int(0, len(this.httpGzipClients)-1)]
}
return nil
}
func (this *RPCClient) Context(adminId int64) context.Context {
ctx := context.Background()
m := maps.Map{

View File

@@ -19,8 +19,19 @@ func (this *AddPortPopupAction) Init() {
func (this *AddPortPopupAction) RunGet(params struct {
ServerType string
Protocol string
}) {
this.Data["protocols"] = serverconfigs.AllServerProtocolsForType(params.ServerType)
protocols := serverconfigs.AllServerProtocolsForType(params.ServerType)
if len(params.Protocol) > 0 {
result := []maps.Map{}
for _, p := range protocols {
if p.GetString("code") == params.Protocol {
result = append(result, p)
}
}
protocols = result
}
this.Data["protocols"] = protocols
this.Show()
}

View File

@@ -1,7 +1,13 @@
package gzip
import (
"encoding/json"
"errors"
"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"
)
type IndexAction struct {
@@ -16,7 +22,119 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
// TODO
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
}
webId := server.WebId
if webId <= 0 {
resp, err := this.RPC().ServerRPC().InitServerWeb(this.AdminContext(), &pb.InitServerWebRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
webId = resp.WebId
}
webResp, err := this.RPC().HTTPWebRPC().FindEnabledHTTPWeb(this.AdminContext(), &pb.FindEnabledHTTPWebRequest{WebId: webId})
if err != nil {
this.ErrorPage(err)
return
}
web := webResp.Web
if web == nil {
this.ErrorPage(errors.New("web should not be nil"))
return
}
this.Data["webId"] = web.Id
gzipId := web.GzipId
gzipConfig := &serverconfigs.HTTPGzipConfig{
Id: 0,
IsOn: true,
}
if gzipId > 0 {
resp, err := this.RPC().HTTPGzipRPC().FindEnabledHTTPGzipConfig(this.AdminContext(), &pb.FindEnabledGzipConfigRequest{GzipId: gzipId})
if err != nil {
this.ErrorPage(err)
return
}
err = json.Unmarshal(resp.Config, gzipConfig)
if err != nil {
this.ErrorPage(err)
return
}
}
this.Data["gzipConfig"] = gzipConfig
this.Show()
}
func (this *IndexAction) RunPost(params struct {
WebId int64
GzipId int64
Level int
MinLength string
MaxLength string
Must *actions.Must
}) {
if params.Level < 0 || params.Level > 9 {
this.Fail("请选择正确的压缩级别")
}
minLength := &pb.SizeCapacity{Count: -1}
if len(params.MinLength) > 0 {
err := json.Unmarshal([]byte(params.MinLength), minLength)
if err != nil {
this.ErrorPage(err)
return
}
}
maxLength := &pb.SizeCapacity{Count: -1}
if len(params.MaxLength) > 0 {
err := json.Unmarshal([]byte(params.MaxLength), maxLength)
if err != nil {
this.ErrorPage(err)
return
}
}
if params.GzipId > 0 {
_, err := this.RPC().HTTPGzipRPC().UpdateHTTPGzip(this.AdminContext(), &pb.UpdateHTTPGzipRequest{
GzipId: params.GzipId,
Level: int32(params.Level),
MinLength: minLength,
MaxLength: maxLength,
})
if err != nil {
this.ErrorPage(err)
return
}
} else {
resp, err := this.RPC().HTTPGzipRPC().CreateHTTPGzip(this.AdminContext(), &pb.CreateHTTPGzipRequest{
Level: 0,
MinLength: nil,
MaxLength: nil,
})
if err != nil {
this.ErrorPage(err)
return
}
gzipId := resp.GzipId
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebGzip(this.AdminContext(), &pb.UpdateHTTPWebGzipRequest{
WebId: params.WebId,
GzipId: gzipId,
})
if err != nil {
this.ErrorPage(err)
}
}
this.Success()
}

View File

@@ -12,7 +12,7 @@ func init() {
Helper(helpers.NewUserMustAuth()).
Helper(serverutils.NewServerHelper()).
Prefix("/servers/server/settings/gzip").
Get("", new(IndexAction)).
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -1,7 +1,13 @@
package http
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"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
@@ -16,7 +22,72 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
// TODO
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
}
httpConfig := &serverconfigs.HTTPProtocolConfig{}
if len(server.HttpJSON) > 0 {
err := json.Unmarshal(server.HttpJSON, httpConfig)
if err != nil {
this.ErrorPage(err)
return
}
} else {
httpConfig.IsOn = true
}
this.Data["serverType"] = server.Type
this.Data["httpConfig"] = maps.Map{
"isOn": httpConfig.IsOn,
"addresses": httpConfig.Listen,
}
this.Show()
}
func (this *IndexAction) RunPost(params struct {
ServerId int64
Addresses string
Must *actions.Must
}) {
addresses := []*serverconfigs.NetworkAddressConfig{}
err := json.Unmarshal([]byte(params.Addresses), &addresses)
if err != nil {
this.Fail("端口地址解析失败:" + err.Error())
}
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
}
httpConfig := &serverconfigs.HTTPProtocolConfig{}
if len(server.HttpJSON) > 0 {
err = json.Unmarshal(server.HttpJSON, httpConfig)
if err != nil {
this.ErrorPage(err)
return
}
} else {
httpConfig.IsOn = true
}
httpConfig.Listen = addresses
configData, err := json.Marshal(httpConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerHTTP(this.AdminContext(), &pb.UpdateServerHTTPRequest{
ServerId: params.ServerId,
Config: configData,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -12,7 +12,7 @@ func init() {
Helper(helpers.NewUserMustAuth()).
Helper(serverutils.NewServerHelper()).
Prefix("/servers/server/settings/http").
Get("", new(IndexAction)).
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -1,7 +1,13 @@
package https
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"
"github.com/iwind/TeaGo/maps"
)
type IndexAction struct {
@@ -16,5 +22,72 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
}
httpsConfig := &serverconfigs.HTTPSProtocolConfig{}
if len(server.HttpsJSON) > 0 {
err := json.Unmarshal(server.HttpsJSON, httpsConfig)
if err != nil {
this.ErrorPage(err)
return
}
} else {
httpsConfig.IsOn = true
}
this.Data["serverType"] = server.Type
this.Data["httpsConfig"] = maps.Map{
"isOn": httpsConfig.IsOn,
"addresses": httpsConfig.Listen,
}
this.Show()
}
func (this *IndexAction) RunPost(params struct {
ServerId int64
Addresses string
Must *actions.Must
}) {
addresses := []*serverconfigs.NetworkAddressConfig{}
err := json.Unmarshal([]byte(params.Addresses), &addresses)
if err != nil {
this.Fail("端口地址解析失败:" + err.Error())
}
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
}
httpsConfig := &serverconfigs.HTTPSProtocolConfig{}
if len(server.HttpsJSON) > 0 {
err = json.Unmarshal(server.HttpsJSON, httpsConfig)
if err != nil {
this.ErrorPage(err)
return
}
} else {
httpsConfig.IsOn = true
}
httpsConfig.Listen = addresses
configData, err := json.Marshal(httpsConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerHTTPS(this.AdminContext(), &pb.UpdateServerHTTPSRequest{
ServerId: params.ServerId,
Config: configData,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -12,7 +12,7 @@ func init() {
Helper(helpers.NewUserMustAuth()).
Helper(serverutils.NewServerHelper()).
Prefix("/servers/server/settings/https").
Get("", new(IndexAction)).
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -29,61 +29,60 @@ func (this *IndexAction) RunGet(params struct {
this.Data["serverType"] = server.Type
this.Data["reverseProxyId"] = server.ReverseProxyId
if server.ReverseProxyId <= 0 {
// TODO 应该在界面上提示用户开启
this.ErrorPage(errors.New("reverse proxy should not be nil"))
return
}
reverseProxyResp, err := this.RPC().ReverseProxyRPC().FindEnabledReverseProxy(this.AdminContext(), &pb.FindEnabledReverseProxyRequest{ReverseProxyId: server.ReverseProxyId})
if err != nil {
this.ErrorPage(err)
return
}
reverseProxy := reverseProxyResp.ReverseProxy
if reverseProxy == nil {
// TODO 应该在界面上提示用户开启
this.ErrorPage(errors.New("reverse proxy should not be nil"))
return
}
primaryOrigins := []*serverconfigs.OriginServerConfig{}
backupOrigins := []*serverconfigs.OriginServerConfig{}
if len(reverseProxy.PrimaryOriginsJSON) > 0 {
err = json.Unmarshal(reverseProxy.PrimaryOriginsJSON, &primaryOrigins)
isOn := false
if server.ReverseProxyId > 0 {
reverseProxyResp, err := this.RPC().ReverseProxyRPC().FindEnabledReverseProxy(this.AdminContext(), &pb.FindEnabledReverseProxyRequest{ReverseProxyId: server.ReverseProxyId})
if err != nil {
this.ErrorPage(err)
return
}
}
if len(reverseProxy.BackupOriginsJSON) > 0 {
err = json.Unmarshal(reverseProxy.BackupOriginsJSON, &backupOrigins)
if err != nil {
this.ErrorPage(err)
reverseProxy := reverseProxyResp.ReverseProxy
if reverseProxy == nil {
// TODO 应该在界面上提示用户开启
this.ErrorPage(errors.New("reverse proxy should not be nil"))
return
}
}
isOn = true
primaryOriginMaps := []maps.Map{}
backupOriginMaps := []maps.Map{}
for _, originConfig := range primaryOrigins {
m := maps.Map{
"id": originConfig.Id,
"weight": originConfig.Weight,
"addr": originConfig.Addr.Protocol.String() + "://" + originConfig.Addr.Host + ":" + originConfig.Addr.PortRange,
primaryOrigins := []*serverconfigs.OriginServerConfig{}
backupOrigins := []*serverconfigs.OriginServerConfig{}
if len(reverseProxy.PrimaryOriginsJSON) > 0 {
err = json.Unmarshal(reverseProxy.PrimaryOriginsJSON, &primaryOrigins)
if err != nil {
this.ErrorPage(err)
return
}
}
primaryOriginMaps = append(primaryOriginMaps, m)
}
for _, originConfig := range backupOrigins {
m := maps.Map{
"id": originConfig.Id,
"weight": originConfig.Weight,
"addr": originConfig.Addr.Protocol.String() + "://" + originConfig.Addr.Host + ":" + originConfig.Addr.PortRange,
if len(reverseProxy.BackupOriginsJSON) > 0 {
err = json.Unmarshal(reverseProxy.BackupOriginsJSON, &backupOrigins)
if err != nil {
this.ErrorPage(err)
return
}
}
backupOriginMaps = append(backupOriginMaps, m)
primaryOriginMaps := []maps.Map{}
backupOriginMaps := []maps.Map{}
for _, originConfig := range primaryOrigins {
m := maps.Map{
"id": originConfig.Id,
"weight": originConfig.Weight,
"addr": originConfig.Addr.Protocol.String() + "://" + originConfig.Addr.Host + ":" + originConfig.Addr.PortRange,
}
primaryOriginMaps = append(primaryOriginMaps, m)
}
for _, originConfig := range backupOrigins {
m := maps.Map{
"id": originConfig.Id,
"weight": originConfig.Weight,
"addr": originConfig.Addr.Protocol.String() + "://" + originConfig.Addr.Host + ":" + originConfig.Addr.PortRange,
}
backupOriginMaps = append(backupOriginMaps, m)
}
this.Data["primaryOrigins"] = primaryOriginMaps
this.Data["backupOrigins"] = backupOriginMaps
}
this.Data["primaryOrigins"] = primaryOriginMaps
this.Data["backupOrigins"] = backupOriginMaps
this.Data["isOn"] = isOn
this.Show()
}

View File

@@ -17,6 +17,7 @@ func init() {
Get("", new(IndexAction)).
GetPost("/scheduling", new(SchedulingAction)).
GetPost("/updateSchedulingPopup", new(UpdateSchedulingPopupAction)).
Post("/updateOn", new(UpdateOnAction)).
EndAll()
})
}

View File

@@ -0,0 +1,55 @@
package reverseProxy
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type UpdateOnAction struct {
actionutils.ParentAction
}
func (this *UpdateOnAction) RunPost(params struct {
ServerId int64
ReverseProxyId int64
IsOn bool
}) {
// 如果没有配置过,则配置
if params.ReverseProxyId <= 0 {
if !params.IsOn {
this.Success()
}
resp, err := this.RPC().ReverseProxyRPC().CreateReverseProxy(this.AdminContext(), &pb.CreateReverseProxyRequest{
SchedulingJSON: nil,
PrimaryOriginsJSON: nil,
BackupOriginsJSON: nil,
})
if err != nil {
this.ErrorPage(err)
return
}
reverseProxyId := resp.ReverseProxyId
_, err = this.RPC().ServerRPC().UpdateServerReverseProxy(this.AdminContext(), &pb.UpdateServerReverseProxyRequest{
ServerId: params.ServerId,
ReverseProxyId: reverseProxyId,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}
// 如果已经配置过
_, err := this.RPC().ReverseProxyRPC().UpdateReverseProxyIsOn(this.AdminContext(), &pb.UpdateReverseProxyIsOnRequest{
ReverseProxyId: params.ReverseProxyId,
IsOn: params.IsOn,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,63 @@
package serverNames
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"
)
// 域名管理
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.FirstMenu("index")
}
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
}
serverNamesConfig := []*serverconfigs.ServerNameConfig{}
if len(server.ServerNamesJON) > 0 {
err := json.Unmarshal(server.ServerNamesJON, &serverNamesConfig)
if err != nil {
this.ErrorPage(err)
return
}
}
this.Data["serverNames"] = serverNamesConfig
this.Show()
}
func (this *IndexAction) RunPost(params struct {
ServerId int64
ServerNames string
Must *actions.Must
}) {
serverNames := []*serverconfigs.ServerNameConfig{}
err := json.Unmarshal([]byte(params.ServerNames), &serverNames)
if err != nil {
this.Fail("域名解析失败:" + err.Error())
}
_, err = this.RPC().ServerRPC().UpdateServerNames(this.AdminContext(), &pb.UpdateServerNamesRequest{
ServerId: params.ServerId,
Config: []byte(params.ServerNames),
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,20 @@
package serverNames
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(serverutils.NewServerHelper()).
Data("mainTab", "setting").
Data("secondMenuItem", "serverName").
Prefix("/servers/server/settings/serverNames").
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -2,7 +2,6 @@ package tcp
import (
"encoding/json"
"errors"
"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"
@@ -23,21 +22,22 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
server, config, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
}
if config.TCP == nil {
this.ErrorPage(errors.New("there is no tcp setting"))
return
}
if config.TCP.Listen == nil {
config.TCP.Listen = []*serverconfigs.NetworkAddressConfig{}
tcpConfig := &serverconfigs.TCPProtocolConfig{}
if len(server.TcpJSON) > 0 {
err := json.Unmarshal(server.TcpJSON, tcpConfig)
if err != nil {
this.ErrorPage(err)
}
} else {
tcpConfig.IsOn = true
}
this.Data["serverType"] = server.Type
this.Data["addresses"] = config.TCP.Listen
this.Data["tcpConfig"] = tcpConfig
this.Show()
}
@@ -49,8 +49,6 @@ func (this *IndexAction) RunPost(params struct {
Must *actions.Must
}) {
serverId := params.ServerId
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
@@ -62,188 +60,30 @@ func (this *IndexAction) RunPost(params struct {
this.Fail("端口地址解析失败:" + err.Error())
}
switch server.Type {
case serverconfigs.ServerTypeHTTPProxy, serverconfigs.ServerTypeHTTPWeb:
var httpConfig = &serverconfigs.HTTPProtocolConfig{}
if len(server.HttpJSON) > 0 {
err = json.Unmarshal(server.HttpJSON, httpConfig)
if err != nil {
this.ErrorPage(err)
return
}
httpConfig.Listen = []*serverconfigs.NetworkAddressConfig{}
} else {
httpConfig.IsOn = true
tcpConfig := &serverconfigs.TCPProtocolConfig{}
if len(server.TcpJSON) > 0 {
err := json.Unmarshal(server.TcpJSON, tcpConfig)
if err != nil {
this.ErrorPage(err)
}
} else {
tcpConfig.IsOn = true
}
tcpConfig.Listen = addresses
var httpsConfig = &serverconfigs.HTTPSProtocolConfig{}
if len(server.HttpsJSON) > 0 {
err = json.Unmarshal(server.HttpsJSON, httpsConfig)
if err != nil {
this.ErrorPage(err)
return
}
httpsConfig.Listen = []*serverconfigs.NetworkAddressConfig{}
} else {
httpsConfig.IsOn = true
}
configData, err := json.Marshal(tcpConfig)
if err != nil {
this.ErrorPage(err)
return
}
for _, addr := range addresses {
switch addr.Protocol.Primary() {
case serverconfigs.ProtocolHTTP:
httpConfig.AddListen(addr)
case serverconfigs.ProtocolHTTPS:
httpsConfig.AddListen(addr)
}
}
httpData, err := json.Marshal(httpConfig)
if err != nil {
this.ErrorPage(err)
return
}
httpsData, err := json.Marshal(httpsConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerHTTP(this.AdminContext(), &pb.UpdateServerHTTPRequest{
ServerId: serverId,
Config: httpData,
})
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerHTTPS(this.AdminContext(), &pb.UpdateServerHTTPSRequest{
ServerId: serverId,
Config: httpsData,
})
if err != nil {
this.ErrorPage(err)
return
}
case serverconfigs.ServerTypeTCPProxy:
tcpProxy := &serverconfigs.TCPProtocolConfig{}
if len(server.TcpJSON) > 0 {
err = json.Unmarshal(server.TcpJSON, tcpProxy)
if err != nil {
this.ErrorPage(err)
return
}
tcpProxy.Listen = []*serverconfigs.NetworkAddressConfig{}
} else {
tcpProxy.IsOn = true
}
tlsProxy := &serverconfigs.TLSProtocolConfig{}
if len(server.TlsJSON) > 0 {
err = json.Unmarshal(server.TlsJSON, tlsProxy)
if err != nil {
this.ErrorPage(err)
return
}
tlsProxy.Listen = []*serverconfigs.NetworkAddressConfig{}
} else {
tlsProxy.IsOn = true
}
for _, addr := range addresses {
switch addr.Protocol.Primary() {
case serverconfigs.ProtocolTCP:
tcpProxy.AddListen(addr)
case serverconfigs.ProtocolTLS:
tlsProxy.AddListen(addr)
}
}
tcpData, err := json.Marshal(tcpProxy)
if err != nil {
this.ErrorPage(err)
return
}
tlsData, err := json.Marshal(tlsProxy)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerTCP(this.AdminContext(), &pb.UpdateServerTCPRequest{
ServerId: serverId,
Config: tcpData,
})
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerTLS(this.AdminContext(), &pb.UpdateServerTLSRequest{
ServerId: serverId,
Config: tlsData,
})
if err != nil {
this.ErrorPage(err)
return
}
case serverconfigs.ServerTypeUnixProxy:
unixConfig := &serverconfigs.UnixProtocolConfig{}
if len(server.UnixJSON) > 0 {
err = json.Unmarshal(server.UnixJSON, unixConfig)
if err != nil {
this.ErrorPage(err)
return
}
unixConfig.Listen = []*serverconfigs.NetworkAddressConfig{}
}
for _, addr := range addresses {
switch addr.Protocol.Primary() {
case serverconfigs.ProtocolUnix:
unixConfig.AddListen(addr)
}
}
unixData, err := json.Marshal(unixConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerUnix(this.AdminContext(), &pb.UpdateServerUnixRequest{
ServerId: serverId,
Config: unixData,
})
if err != nil {
this.ErrorPage(err)
return
}
case serverconfigs.ServerTypeUDPProxy:
udpConfig := &serverconfigs.UDPProtocolConfig{}
if len(server.UdpJSON) > 0 {
err = json.Unmarshal(server.UdpJSON, udpConfig)
if err != nil {
this.ErrorPage(err)
return
}
udpConfig.Listen = []*serverconfigs.NetworkAddressConfig{}
}
for _, addr := range addresses {
switch addr.Protocol.Primary() {
case serverconfigs.ProtocolUDP:
udpConfig.AddListen(addr)
}
}
udpData, err := json.Marshal(udpConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerUDP(this.AdminContext(), &pb.UpdateServerUDPRequest{
ServerId: serverId,
Config: udpData,
})
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerTCP(this.AdminContext(), &pb.UpdateServerTCPRequest{
ServerId: params.ServerId,
Config: configData,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()

View File

@@ -0,0 +1,90 @@
package tls
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"
)
// TLS设置
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "setting", "index")
this.SecondMenu("tls")
}
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
}
tlsConfig := &serverconfigs.TLSProtocolConfig{}
if len(server.TlsJSON) > 0 {
err := json.Unmarshal(server.TlsJSON, tlsConfig)
if err != nil {
this.ErrorPage(err)
}
} else {
tlsConfig.IsOn = true
}
this.Data["serverType"] = server.Type
this.Data["tlsConfig"] = tlsConfig
this.Show()
}
func (this *IndexAction) RunPost(params struct {
ServerId int64
ServerType string
Addresses string
Must *actions.Must
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
}
addresses := []*serverconfigs.NetworkAddressConfig{}
err := json.Unmarshal([]byte(params.Addresses), &addresses)
if err != nil {
this.Fail("端口地址解析失败:" + err.Error())
}
tlsConfig := &serverconfigs.TLSProtocolConfig{}
if len(server.TlsJSON) > 0 {
err := json.Unmarshal(server.TlsJSON, tlsConfig)
if err != nil {
this.ErrorPage(err)
}
} else {
tlsConfig.IsOn = true
}
tlsConfig.Listen = addresses
configData, err := json.Marshal(tlsConfig)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().ServerRPC().UpdateServerTLS(this.AdminContext(), &pb.UpdateServerTLSRequest{
ServerId: params.ServerId,
Config: configData,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,18 @@
package tls
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/serverutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(serverutils.NewServerHelper()).
Prefix("/servers/server/settings/tls").
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -2,6 +2,10 @@ package web
import (
"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"
)
type IndexAction struct {
@@ -16,7 +20,70 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
// TODO
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
if !isOk {
return
}
webId := server.WebId
webConfig := &serverconfigs.HTTPWebConfig{
Id: webId,
IsOn: true,
}
if webId > 0 {
resp, err := this.RPC().HTTPWebRPC().FindEnabledHTTPWeb(this.AdminContext(), &pb.FindEnabledHTTPWebRequest{WebId: webId})
if err != nil {
this.ErrorPage(err)
return
}
if resp.Web != nil {
web := resp.Web
webConfig.Id = webId
webConfig.IsOn = web.IsOn
webConfig.Root = web.Root
}
}
this.Data["webConfig"] = webConfig
this.Show()
}
func (this *IndexAction) RunPost(params struct {
ServerId int64
WebId int64
Root string
Must *actions.Must
}) {
if params.WebId <= 0 {
resp, err := this.RPC().HTTPWebRPC().CreateHTTPWeb(this.AdminContext(), &pb.CreateHTTPWebRequest{
Root: params.Root,
})
if err != nil {
this.ErrorPage(err)
return
}
webId := resp.WebId
_, err = this.RPC().ServerRPC().UpdateServerWeb(this.AdminContext(), &pb.UpdateServerWebRequest{
ServerId: params.ServerId,
WebId: webId,
})
if err != nil {
this.ErrorPage(err)
return
}
} else {
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWeb(this.AdminContext(), &pb.UpdateHTTPWebRequest{
WebId: params.WebId,
Root: params.Root,
})
if err != nil {
this.ErrorPage(err)
return
}
}
this.Success()
}

View File

@@ -12,7 +12,7 @@ func init() {
Helper(helpers.NewUserMustAuth()).
Helper(serverutils.NewServerHelper()).
Prefix("/servers/server/settings/web").
Get("", new(IndexAction)).
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -141,6 +141,12 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
// HTTP
if serverConfig.IsHTTP() {
menuItems = append(menuItems, maps.Map{
"name": "域名",
"url": "/servers/server/settings/serverNames?serverId=" + serverIdString,
"isActive": secondMenuItem == "serverName",
})
menuItems = append(menuItems, maps.Map{
"name": "HTTP",
"url": "/servers/server/settings/http?serverId=" + serverIdString,
@@ -235,6 +241,11 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
"url": "/servers/server/settings/tcp?serverId=" + serverIdString,
"isActive": secondMenuItem == "tcp",
})
menuItems = append(menuItems, maps.Map{
"name": "TLS",
"url": "/servers/server/settings/tls?serverId=" + serverIdString,
"isActive": secondMenuItem == "tls",
})
menuItems = append(menuItems, maps.Map{
"name": "反向代理",
"url": "/servers/server/settings/reverseProxy?serverId=" + serverIdString,

View File

@@ -38,8 +38,10 @@ import (
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/origins"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/pages"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/reverseProxy"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/serverNames"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/stat"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/tcp"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/tls"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/udp"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/unix"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/waf"