mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-12-16 05:36:36 +08:00
阶段性提交
This commit is contained in:
@@ -3,10 +3,10 @@ package serverutils
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configs/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
@@ -41,6 +41,7 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
|
||||
|
||||
serverId := action.ParamInt64("serverId")
|
||||
serverIdString := strconv.FormatInt(serverId, 10)
|
||||
action.Data["serverId"] = serverId
|
||||
|
||||
// 读取server信息
|
||||
rpcClient, err := rpc.SharedRPC()
|
||||
@@ -60,7 +61,7 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
|
||||
return
|
||||
}
|
||||
|
||||
// 源站管理
|
||||
// 服务管理
|
||||
serverConfig := &serverconfigs.ServerConfig{}
|
||||
err = json.Unmarshal(server.Config, serverConfig)
|
||||
if err != nil {
|
||||
@@ -234,6 +235,11 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri
|
||||
"url": "/servers/server/settings/tcp?serverId=" + serverIdString,
|
||||
"isActive": secondMenuItem == "tcp",
|
||||
})
|
||||
menuItems = append(menuItems, maps.Map{
|
||||
"name": "反向代理",
|
||||
"url": "/servers/server/settings/reverseProxy?serverId=" + serverIdString,
|
||||
"isActive": secondMenuItem == "reverseProxy",
|
||||
})
|
||||
} else if serverConfig.IsUnix() {
|
||||
menuItems = append(menuItems, maps.Map{
|
||||
"name": "Unix",
|
||||
|
||||
@@ -1,97 +1,30 @@
|
||||
package serverutils
|
||||
|
||||
import (
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type ServerType = string
|
||||
|
||||
const (
|
||||
ServerTypeHTTPProxy ServerType = "httpProxy"
|
||||
ServerTypeHTTPWeb ServerType = "httpWeb"
|
||||
ServerTypeTCPProxy ServerType = "tcpProxy"
|
||||
ServerTypeUnixProxy ServerType = "unixProxy"
|
||||
ServerTypeUDPProxy ServerType = "udp"
|
||||
)
|
||||
|
||||
// 获取所有的服务类型
|
||||
func AllServerTypes() []maps.Map {
|
||||
return []maps.Map{
|
||||
{
|
||||
"name": "HTTP反向代理",
|
||||
"code": ServerTypeHTTPProxy,
|
||||
},
|
||||
{
|
||||
"name": "HTTP Web服务",
|
||||
"code": ServerTypeHTTPWeb,
|
||||
},
|
||||
{
|
||||
"name": "TCP反向代理",
|
||||
"code": ServerTypeTCPProxy,
|
||||
},
|
||||
/**{
|
||||
"name": "UNIX协议反向代理",
|
||||
"code": ServerTypeUnixProxy,
|
||||
},
|
||||
{
|
||||
"name": "UDP反向代理",
|
||||
"code": ServerTypeUDPProxy,
|
||||
},**/
|
||||
// 查找Server
|
||||
func FindServer(p *actionutils.ParentAction, serverId int64) (*pb.Server, *serverconfigs.ServerConfig, bool) {
|
||||
serverResp, err := p.RPC().ServerRPC().FindEnabledServer(p.AdminContext(), &pb.FindEnabledServerRequest{ServerId: serverId})
|
||||
if err != nil {
|
||||
p.ErrorPage(err)
|
||||
return nil, nil, false
|
||||
}
|
||||
}
|
||||
|
||||
// 查找服务类型
|
||||
func FindServerType(code string) maps.Map {
|
||||
for _, m := range AllServerTypes() {
|
||||
if m.GetString("code") == code {
|
||||
return m
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 获取所有协议
|
||||
func AllServerProtocolsForType(serverType ServerType) []maps.Map {
|
||||
protocols := []maps.Map{
|
||||
{
|
||||
"name": "HTTP",
|
||||
"code": "http",
|
||||
"serverTypes": []ServerType{ServerTypeHTTPProxy, ServerTypeHTTPWeb},
|
||||
},
|
||||
{
|
||||
"name": "HTTPS",
|
||||
"code": "https",
|
||||
"serverTypes": []ServerType{ServerTypeHTTPProxy, ServerTypeHTTPWeb},
|
||||
},
|
||||
{
|
||||
"name": "TCP",
|
||||
"code": "tcp",
|
||||
"serverTypes": []ServerType{ServerTypeTCPProxy},
|
||||
},
|
||||
{
|
||||
"name": "TLS",
|
||||
"code": "tls",
|
||||
"serverTypes": []ServerType{ServerTypeTCPProxy},
|
||||
},
|
||||
{
|
||||
"name": "Unix",
|
||||
"code": "unix",
|
||||
"serverTypes": []ServerType{ServerTypeUnixProxy},
|
||||
},
|
||||
{
|
||||
"name": "UDP",
|
||||
"code": "udp",
|
||||
"serverTypes": []ServerType{ServerTypeUDPProxy},
|
||||
},
|
||||
}
|
||||
|
||||
result := []maps.Map{}
|
||||
for _, p := range protocols {
|
||||
serverTypes := p.GetSlice("serverTypes")
|
||||
if lists.Contains(serverTypes, serverType) {
|
||||
result = append(result, p)
|
||||
}
|
||||
}
|
||||
return result
|
||||
server := serverResp.Server
|
||||
if server == nil {
|
||||
p.ErrorPage(errors.New("not found server with id '" + strconv.FormatInt(serverId, 10) + "'"))
|
||||
return nil, nil, false
|
||||
}
|
||||
config, err := serverconfigs.NewServerConfigFromJSON(server.Config)
|
||||
if err != nil {
|
||||
p.ErrorPage(err)
|
||||
return nil, nil, false
|
||||
}
|
||||
|
||||
return server, config, true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user