实现路径规则部分功能

This commit is contained in:
GoEdgeLab
2020-09-21 19:51:50 +08:00
parent f796a1d4d7
commit c126d06f70
50 changed files with 630 additions and 114 deletions

View File

@@ -35,6 +35,7 @@ type RPCClient struct {
httpAccessLogPolicyClients []pb.HTTPAccessLogPolicyServiceClient
httpCachePolicyClients []pb.HTTPCachePolicyServiceClient
httpFirewallPolicyClients []pb.HTTPFirewallPolicyServiceClient
httpLocationClients []pb.HTTPLocationServiceClient
}
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
@@ -59,6 +60,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
httpAccessLogPolicyClients := []pb.HTTPAccessLogPolicyServiceClient{}
httpCachePolicyClients := []pb.HTTPCachePolicyServiceClient{}
httpFirewallPolicyClients := []pb.HTTPFirewallPolicyServiceClient{}
httpLocationClients := []pb.HTTPLocationServiceClient{}
conns := []*grpc.ClientConn{}
for _, endpoint := range apiConfig.RPC.Endpoints {
@@ -91,6 +93,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
httpAccessLogPolicyClients = append(httpAccessLogPolicyClients, pb.NewHTTPAccessLogPolicyServiceClient(conn))
httpCachePolicyClients = append(httpCachePolicyClients, pb.NewHTTPCachePolicyServiceClient(conn))
httpFirewallPolicyClients = append(httpFirewallPolicyClients, pb.NewHTTPFirewallPolicyServiceClient(conn))
httpLocationClients = append(httpLocationClients, pb.NewHTTPLocationServiceClient(conn))
}
return &RPCClient{
@@ -112,6 +115,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
httpAccessLogPolicyClients: httpAccessLogPolicyClients,
httpCachePolicyClients: httpCachePolicyClients,
httpFirewallPolicyClients: httpFirewallPolicyClients,
httpLocationClients: httpLocationClients,
}, nil
}
@@ -234,6 +238,13 @@ func (this *RPCClient) HTTPFirewallPolicyRPC() pb.HTTPFirewallPolicyServiceClien
return nil
}
func (this *RPCClient) HTTPLocationRPC() pb.HTTPLocationServiceClient {
if len(this.httpLocationClients) > 0 {
return this.httpLocationClients[rands.Int(0, len(this.httpLocationClients)-1)]
}
return nil
}
func (this *RPCClient) Context(adminId int64) context.Context {
ctx := context.Background()
m := maps.Map{

View File

@@ -20,6 +20,11 @@ type ParentAction struct {
rpcClient *rpc.RPCClient
}
// 可以调用自身的一个简便方法
func (this *ParentAction) Parent() *ParentAction {
return this
}
func (this *ParentAction) ErrorPage(err error) {
if err == nil {
return
@@ -64,6 +69,10 @@ func (this *ParentAction) SecondMenu(menuItem string) {
this.Data["secondMenuItem"] = menuItem
}
func (this *ParentAction) TinyMenu(menuItem string) {
this.Data["tinyMenuItem"] = menuItem
}
func (this *ParentAction) AdminId() int64 {
return this.Context.GetInt64("adminId")
}

View File

@@ -1,8 +1,8 @@
package accessLog
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
@@ -22,13 +22,7 @@ func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
// 获取配置
webResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
webConfig := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(webResp.Config, webConfig)
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
@@ -67,7 +61,7 @@ func (this *IndexAction) RunPost(params struct {
}) {
// TODO 检查参数
_, err := this.RPC().HTTPWebRPC().UpdateHTTPAccessLog(this.AdminContext(), &pb.UpdateHTTPAccessLogRequest{
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebAccessLog(this.AdminContext(), &pb.UpdateHTTPWebAccessLogRequest{
WebId: params.WebId,
AccessLogJSON: params.AccessLogJSON,
})

View File

@@ -1,10 +1,9 @@
package cache
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
@@ -21,13 +20,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
webConfigResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
webConfig := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(webConfigResp.Config, webConfig)
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
@@ -63,7 +56,7 @@ func (this *IndexAction) RunPost(params struct {
}) {
// TODO 校验配置
_, err := this.RPC().HTTPWebRPC().UpdateHTTPCache(this.AdminContext(), &pb.UpdateHTTPCacheRequest{
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{
WebId: params.WebId,
CacheJSON: params.CacheJSON,
})

View File

@@ -1,10 +1,9 @@
package charset
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/configutils"
"github.com/iwind/TeaGo/actions"
)
@@ -21,13 +20,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
webConfigResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
webConfig := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(webConfigResp.Config, webConfig)
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -3,6 +3,7 @@ package gzip
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
@@ -21,18 +22,12 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
webConfigResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId})
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
}
webConfig := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(webConfigResp.Config, webConfig)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["webId"] = webConfig.Id
gzipId := int64(0)
@@ -49,7 +44,7 @@ func (this *IndexAction) RunGet(params struct {
this.ErrorPage(err)
return
}
err = json.Unmarshal(resp.Config, gzipConfig)
err = json.Unmarshal(resp.GzipJSON, gzipConfig)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -36,7 +36,7 @@ func (this *CreateDeletePopupAction) RunPost(params struct {
return
}
policyConfig := &shared.HTTPHeaderPolicy{}
err = json.Unmarshal(policyConfigResp.Config, policyConfig)
err = json.Unmarshal(policyConfigResp.HeaderPolicyJSON, policyConfig)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -42,7 +42,7 @@ func (this *CreateSetPopupAction) RunPost(params struct {
return
}
policyConfig := &shared.HTTPHeaderPolicy{}
err = json.Unmarshal(configResp.Config, policyConfig)
err = json.Unmarshal(configResp.HeaderPolicyJSON, policyConfig)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -25,7 +25,7 @@ func (this *DeleteAction) RunPost(params struct {
return
}
policyConfig := &shared.HTTPHeaderPolicy{}
err = json.Unmarshal(policyConfigResp.Config, policyConfig)
err = json.Unmarshal(policyConfigResp.HeaderPolicyJSON, policyConfig)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -20,7 +20,7 @@ func (this *DeleteDeletingHeaderAction) RunPost(params struct {
this.ErrorPage(err)
return
}
policyConfigJSON := policyConfigResp.Config
policyConfigJSON := policyConfigResp.HeaderPolicyJSON
policyConfig := &shared.HTTPHeaderPolicy{}
err = json.Unmarshal(policyConfigJSON, policyConfig)
if err != nil {

View File

@@ -1,11 +1,10 @@
package headers
import (
"encoding/json"
"errors"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
)
type IndexAction struct {
@@ -20,13 +19,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
webConfigResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
webConfig := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(webConfigResp.Config, webConfig)
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
@@ -73,12 +66,7 @@ func (this *IndexAction) RunGet(params struct {
// 重新获取配置
if isChanged {
webConfigResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
err = json.Unmarshal(webConfigResp.Config, webConfig)
webConfig, err = webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -29,7 +29,7 @@ func (this *UpdateSetPopupAction) RunGet(params struct {
return
}
headerConfig := &shared.HTTPHeaderConfig{}
err = json.Unmarshal(headerResp.Config, headerConfig)
err = json.Unmarshal(headerResp.HeaderJSON, headerConfig)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -22,7 +22,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}
@@ -58,7 +58,7 @@ func (this *IndexAction) RunPost(params struct {
this.Fail("端口地址解析失败:" + err.Error())
}
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}

View File

@@ -22,7 +22,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}
@@ -58,7 +58,7 @@ func (this *IndexAction) RunPost(params struct {
this.Fail("端口地址解析失败:" + err.Error())
}
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}

View File

@@ -0,0 +1,116 @@
package locations
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"regexp"
"strings"
)
type CreateAction struct {
actionutils.ParentAction
}
func (this *CreateAction) Init() {
this.Nav("", "setting", "create")
this.SecondMenu("locations")
}
func (this *CreateAction) RunGet(params struct {
ServerId int64
}) {
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["webId"] = webConfig.Id
this.Data["patternTypes"] = serverconfigs.AllLocationPatternTypes()
this.Show()
}
func (this *CreateAction) RunPost(params struct {
WebId int64
Name string
Pattern string
PatternType int
Description string
IsBreak bool
IsCaseInsensitive bool
IsReverse bool
Must *actions.Must
}) {
params.Must.
Field("pattern", params.Pattern).
Require("请输入路径匹配规则")
// 校验正则
if params.PatternType == serverconfigs.HTTPLocationPatternTypeRegexp {
_, err := regexp.Compile(params.Pattern)
if err != nil {
this.Fail("正则表达式校验失败:" + err.Error())
}
}
// 自动加上前缀斜杠
if params.PatternType == serverconfigs.HTTPLocationPatternTypePrefix ||
params.PatternType == serverconfigs.HTTPLocationPatternTypeExact {
params.Pattern = "/" + strings.TrimLeft(params.Pattern, "/")
}
location := &serverconfigs.HTTPLocationConfig{}
location.SetPattern(params.Pattern, params.PatternType, params.IsCaseInsensitive, params.IsReverse)
resultPattern := location.Pattern
locationResp, err := this.RPC().HTTPLocationRPC().CreateHTTPLocation(this.AdminContext(), &pb.CreateHTTPLocationRequest{
ParentId: 0, // TODO 需要实现
Name: params.Name,
Description: params.Description,
Pattern: resultPattern,
IsBreak: params.IsBreak,
})
if err != nil {
this.ErrorPage(err)
return
}
locationId := locationResp.LocationId
// Web中Location
webConfig, err := webutils.FindWebConfigWithId(this.Parent(), params.WebId)
if err != nil {
this.ErrorPage(err)
return
}
// TODO 支持Location嵌套
webConfig.LocationRefs = append(webConfig.LocationRefs, &serverconfigs.HTTPLocationRef{
IsOn: true,
LocationId: locationId,
Children: nil,
})
refJSON, err := json.Marshal(webConfig.LocationRefs)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebLocations(this.AdminContext(), &pb.UpdateHTTPWebLocationsRequest{
WebId: params.WebId,
LocationsJSON: refJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,40 @@
package locations
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
WebId int64
LocationId int64
}) {
webConfig, err := webutils.FindWebConfigWithId(this.Parent(), params.WebId)
if err != nil {
this.ErrorPage(err)
return
}
webConfig.RemoveLocationRef(params.LocationId)
refJSON, err := json.Marshal(webConfig.LocationRefs)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebLocations(this.AdminContext(), &pb.UpdateHTTPWebLocationsRequest{
WebId: params.WebId,
LocationsJSON: refJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -2,6 +2,7 @@ package locations
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
)
type IndexAction struct {
@@ -16,7 +17,18 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
// TODO
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["webId"] = webConfig.Id
if webConfig.Locations != nil {
this.Data["locations"] = webConfig.Locations
} else {
this.Data["locations"] = []interface{}{}
}
this.Show()
}

View File

@@ -13,6 +13,8 @@ func init() {
Helper(serverutils.NewServerHelper()).
Prefix("/servers/server/settings/locations").
Get("", new(IndexAction)).
GetPost("/create", new(CreateAction)).
Post("/delete", new(DeleteAction)).
EndAll()
})
}

View File

@@ -0,0 +1,38 @@
package location
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
)
// 路径规则详情
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.TinyMenu("basic")
}
func (this *IndexAction) RunGet(params struct {
LocationId int64
}) {
locationConfigResp, err := this.RPC().HTTPLocationRPC().FindEnabledHTTPLocationConfig(this.AdminContext(), &pb.FindEnabledHTTPLocationConfigRequest{LocationId: params.LocationId})
if err != nil {
this.ErrorPage(err)
return
}
locationConfig := &serverconfigs.HTTPLocationConfig{}
err = json.Unmarshal(locationConfigResp.LocationJSON, locationConfig)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["locationId"] = locationConfig.Id
this.Data["locationConfig"] = locationConfig
this.Show()
}

View File

@@ -0,0 +1,20 @@
package location
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/locationutils"
"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(locationutils.NewLocationHelper()).
Helper(serverutils.NewServerHelper()).
Prefix("/servers/server/settings/locations/location").
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -0,0 +1,113 @@
package locationutils
import (
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"net/http"
)
type LocationHelper struct {
}
func NewLocationHelper() *LocationHelper {
return &LocationHelper{}
}
func (this *LocationHelper) BeforeAction(action *actions.ActionObject) {
if action.Request.Method != http.MethodGet {
return
}
serverIdString := action.ParamString("serverId")
locationIdString := action.ParamString("locationId")
action.Data["leftMenuItemIsDisabled"] = true
action.Data["mainMenu"] = "server"
action.Data["mainTab"] = "setting"
action.Data["secondMenuItem"] = "locations"
action.Data["tinyLeftMenuItems"] = this.createMenus(serverIdString, locationIdString, action.Data.GetString("tinyMenuItem"))
}
func (this *LocationHelper) createMenus(serverIdString string, locationIdString string, secondMenuItem string) []maps.Map {
menuItems := []maps.Map{
{
"name": "基本信息",
"url": "/servers/server/settings/locations/location?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "basic",
},
}
menuItems = append(menuItems, maps.Map{
"name": "Web设置",
"url": "/servers/server/settings/locations/web?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "web",
})
menuItems = append(menuItems, maps.Map{
"name": "反向代理",
"url": "/servers/server/settings/locations/reverseProxy?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "reverseProxy",
})
menuItems = append(menuItems, maps.Map{
"name": "访问控制",
"url": "/servers/server/settings/locations/access?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "access",
})
menuItems = append(menuItems, maps.Map{
"name": "WAF",
"url": "/servers/server/settings/locations/waf?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "waf",
})
menuItems = append(menuItems, maps.Map{
"name": "缓存",
"url": "/servers/server/settings/locations/cache?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "cache",
})
menuItems = append(menuItems, maps.Map{
"name": "-",
"url": "",
"isActive": false,
})
menuItems = append(menuItems, maps.Map{
"name": "字符编码",
"url": "/servers/server/settings/locations/charset?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "charset",
})
menuItems = append(menuItems, maps.Map{
"name": "访问日志",
"url": "/servers/server/settings/locations/accessLog?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "accessLog",
})
menuItems = append(menuItems, maps.Map{
"name": "统计",
"url": "/servers/server/settings/locations/stat?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "stat",
})
menuItems = append(menuItems, maps.Map{
"name": "Gzip压缩",
"url": "/servers/server/settings/locations/gzip?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "gzip",
})
menuItems = append(menuItems, maps.Map{
"name": "特殊页面",
"url": "/servers/server/settings/locations/pages?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "pages",
})
menuItems = append(menuItems, maps.Map{
"name": "HTTP Header",
"url": "/servers/server/settings/locations/headers?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "header",
})
return menuItems
}

View File

@@ -75,7 +75,7 @@ func (this *AddPopupAction) RunPost(params struct {
this.ErrorPage(err)
return
}
originConfigData := originConfigResp.Config
originConfigData := originConfigResp.OriginJSON
var originConfig = &serverconfigs.OriginServerConfig{}
err = json.Unmarshal(originConfigData, originConfig)
if err != nil {

View File

@@ -46,7 +46,7 @@ func (this *UpdatePopupAction) RunGet(params struct {
this.ErrorPage(err)
return
}
configData := originResp.Config
configData := originResp.OriginJSON
config := &serverconfigs.OriginServerConfig{}
err = json.Unmarshal(configData, config)
if err != nil {
@@ -105,7 +105,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
this.ErrorPage(err)
return
}
originConfigData := originConfigResp.Config
originConfigData := originConfigResp.OriginJSON
var originConfig = &serverconfigs.OriginServerConfig{}
err = json.Unmarshal(originConfigData, originConfig)
if err != nil {

View File

@@ -53,7 +53,7 @@ func (this *CreatePopupAction) RunPost(params struct {
}
pageConfig := &serverconfigs.HTTPPageConfig{}
err = json.Unmarshal(configResp.Config, pageConfig)
err = json.Unmarshal(configResp.PageJSON, pageConfig)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -1,10 +1,9 @@
package pages
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
)
@@ -20,13 +19,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
webResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
webConfig := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(webResp.Config, webConfig)
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -27,7 +27,7 @@ func (this *UpdatePopupAction) RunGet(params struct {
}
pageConfig := &serverconfigs.HTTPPageConfig{}
err = json.Unmarshal(configResp.Config, pageConfig)
err = json.Unmarshal(configResp.PageJSON, pageConfig)
if err != nil {
this.ErrorPage(err)
return
@@ -71,7 +71,7 @@ func (this *UpdatePopupAction) RunPost(params struct {
}
pageConfig := &serverconfigs.HTTPPageConfig{}
err = json.Unmarshal(configResp.Config, pageConfig)
err = json.Unmarshal(configResp.PageJSON, pageConfig)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -34,14 +34,14 @@ func (this *IndexAction) RunGet(params struct {
return
}
reverseProxyRef := &serverconfigs.ReverseProxyRef{}
err = json.Unmarshal(reverseProxyResp.ReverseProxyRef, reverseProxyRef)
err = json.Unmarshal(reverseProxyResp.ReverseProxyRefJSON, reverseProxyRef)
if err != nil {
this.ErrorPage(err)
return
}
reverseProxy := &serverconfigs.ReverseProxyConfig{}
err = json.Unmarshal(reverseProxyResp.ReverseProxy, reverseProxy)
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -26,7 +26,7 @@ func (this *SchedulingAction) RunGet(params struct {
return
}
reverseProxy := &serverconfigs.ReverseProxyConfig{}
err = json.Unmarshal(reverseProxyResp.ReverseProxy, reverseProxy)
err = json.Unmarshal(reverseProxyResp.ReverseProxyJSON, reverseProxy)
if err != nil {
this.ErrorPage(err)
return

View File

@@ -30,7 +30,7 @@ func (this *UpdateSchedulingPopupAction) RunGet(params struct {
this.Data["serverId"] = params.ServerId
this.Data["reverseProxyId"] = params.ReverseProxyId
_, serverConfig, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
_, serverConfig, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}
@@ -42,7 +42,7 @@ func (this *UpdateSchedulingPopupAction) RunGet(params struct {
this.ErrorPage(err)
return
}
configData := reverseProxyResp.Config
configData := reverseProxyResp.ReverseProxyJSON
reverseProxyConfig := &serverconfigs.ReverseProxyConfig{}
err = json.Unmarshal(configData, reverseProxyConfig)
@@ -98,7 +98,7 @@ func (this *UpdateSchedulingPopupAction) RunPost(params struct {
this.ErrorPage(err)
return
}
configData := reverseProxyResp.Config
configData := reverseProxyResp.ReverseProxyJSON
reverseProxy := &serverconfigs.ReverseProxyConfig{}
err = json.Unmarshal(configData, reverseProxy)
if err != nil {

View File

@@ -21,7 +21,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}

View File

@@ -1,10 +1,9 @@
package stat
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
)
@@ -20,13 +19,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
webResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
webConfig := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(webResp.Config, webConfig)
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
@@ -46,7 +39,7 @@ func (this *IndexAction) RunPost(params struct {
}) {
// TODO 校验配置
_, err := this.RPC().HTTPWebRPC().UpdateHTTPStat(this.AdminContext(), &pb.UpdateHTTPStatRequest{
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebStat(this.AdminContext(), &pb.UpdateHTTPWebStatRequest{
WebId: params.WebId,
StatJSON: params.StatJSON,
})

View File

@@ -22,7 +22,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}
@@ -49,7 +49,7 @@ func (this *IndexAction) RunPost(params struct {
Must *actions.Must
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}

View File

@@ -22,7 +22,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}
@@ -49,7 +49,7 @@ func (this *IndexAction) RunPost(params struct {
Must *actions.Must
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}

View File

@@ -1,10 +1,9 @@
package waf
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
@@ -21,17 +20,12 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
webConfigResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId})
if err != nil {
this.ErrorPage(err)
return
}
webConfig := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(webConfigResp.Config, webConfig)
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["webId"] = webConfig.Id
this.Data["firewallConfig"] = webConfig.FirewallRef
@@ -62,7 +56,7 @@ func (this *IndexAction) RunPost(params struct {
}) {
// TODO 检查配置
_, err := this.RPC().HTTPWebRPC().UpdateHTTPFirewall(this.AdminContext(), &pb.UpdateHTTPFirewallRequest{
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebFirewall(this.AdminContext(), &pb.UpdateHTTPWebFirewallRequest{
WebId: params.WebId,
FirewallJSON: params.FirewallJSON,
})

View File

@@ -20,7 +20,7 @@ func (this *IndexAction) Init() {
func (this *IndexAction) RunGet(params struct {
ServerId int64
}) {
server, _, isOk := serverutils.FindServer(&this.ParentAction, params.ServerId)
server, _, isOk := serverutils.FindServer(this.Parent(), params.ServerId)
if !isOk {
return
}

View File

@@ -0,0 +1,50 @@
package webutils
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
)
// 根据ServerId查找Web配置
func FindWebConfigWithServerId(parentAction *actionutils.ParentAction, serverId int64) (*serverconfigs.HTTPWebConfig, error) {
resp, err := parentAction.RPC().ServerRPC().FindAndInitServerWebConfig(parentAction.AdminContext(), &pb.FindAndInitServerWebConfigRequest{ServerId: serverId})
if err != nil {
return nil, err
}
config := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(resp.WebJSON, config)
if err != nil {
return nil, err
}
return config, nil
}
// 根据LocationId查找Web配置
func FindWebConfigWithLocationId(parentAction *actionutils.ParentAction, locationId int64) (*serverconfigs.HTTPWebConfig, error) {
resp, err := parentAction.RPC().HTTPLocationRPC().FindAndInitHTTPLocationWebConfig(parentAction.AdminContext(), &pb.FindAndInitHTTPLocationWebConfigRequest{LocationId: locationId})
if err != nil {
return nil, err
}
config := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(resp.WebJSON, config)
if err != nil {
return nil, err
}
return config, nil
}
// 根据WebId查找Web配置
func FindWebConfigWithId(parentAction *actionutils.ParentAction, webId int64) (*serverconfigs.HTTPWebConfig, error) {
resp, err := parentAction.RPC().HTTPWebRPC().FindEnabledHTTPWebConfig(parentAction.AdminContext(), &pb.FindEnabledHTTPWebConfigRequest{WebId: webId})
if err != nil {
return nil, err
}
config := &serverconfigs.HTTPWebConfig{}
err = json.Unmarshal(resp.WebJSON, config)
if err != nil {
return nil, err
}
return config, nil
}

View File

@@ -35,6 +35,9 @@ func (this *ServerHelper) BeforeAction(action *actions.ActionObject) {
func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
// 初始化
if !action.Data.Has("leftMenuItemIsDisabled") {
action.Data["leftMenuItemIsDisabled"] = false
}
action.Data["leftMenuItems"] = []maps.Map{}
mainTab, _ := action.Data["mainTab"]
secondMenuItem, _ := action.Data["secondMenuItem"]

View File

@@ -35,6 +35,7 @@ import (
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/http"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/https"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations"
_ "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/locations/location"
_ "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"

View File

@@ -36,6 +36,12 @@
.left-box::-webkit-scrollbar {
width: 4px;
}
.left-box.disabled {
opacity: 0.3;
}
.left-box.tiny {
top: 10em;
}
.right-box {
position: fixed;
top: 7.5em;

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
<div class="margin"></div>
<div class="left-box">
<div class="left-box" :class="{disabled:leftMenuItemIsDisabled}">
<div class="ui menu text blue vertical small">
<a class="item" v-for="item in leftMenuItems" :href="item.url" :class="{active:item.isActive, separator:item.name == '-'}">
<span v-if="item.name != '-'"><i class="icon play tiny" :style="{'visibility':item.isActive ? 'visible' : 'hidden'}"></i>{{item.name}}</span>

View File

@@ -43,10 +43,19 @@
}
}
.left-box::-webkit-scrollbar {
width: 4px;
}
.left-box.disabled {
opacity: 0.3;
}
.left-box.tiny {
top: 10em;
}
.right-box {
position: fixed;
top: 7.5em;
@@ -60,4 +69,4 @@
.right-box::-webkit-scrollbar {
width: 4px;
}
}

View File

@@ -0,0 +1,9 @@
<div class="margin"></div>
<div class="left-box tiny">
<div class="ui menu text blue vertical tiny">
<a class="item" v-for="item in tinyLeftMenuItems" :href="item.url" :class="{active:item.isActive, separator:item.name == '-'}">
<span v-if="item.name != '-'"><i class="icon play tiny" :style="{'visibility':item.isActive ? 'visible' : 'hidden'}"></i>{{item.name}}</span>
</a>
</div>
</div>

View File

@@ -0,0 +1,4 @@
<first-menu>
<menu-item :href="'/servers/server/settings/locations?serverId=' + serverId" code="index">列表</menu-item>
<menu-item :href="'/servers/server/settings/locations/create?serverId=' + serverId" code="create">创建</menu-item>
</first-menu>

View File

@@ -0,0 +1,77 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
{$template "menu"}
<div class="margin"></div>
<form class="ui form" data-tea-action="$" data-tea-success="success">
<input type="hidden" name="webId" :value="webId"/>
<table class="ui table selectable definition">
<tr>
<td>路径匹配规则 *</td>
<td>
<input type="text" name="pattern" maxlength="500"/>
<p class="comment">路径通常以斜杠(/)开头,比如/hello。如果匹配类型是正则表达式匹配则可以是一个正则表达式</p>
</td>
</tr>
<tr>
<td>匹配类型</td>
<td>
<select class="ui dropdown auto-width" name="patternType" v-model="type" @change="changePatternType(type)">
<option v-for="patternType in patternTypes" :value="patternType.type">{{patternType.name}}</option>
</select>
<p class="comment" v-if="selectedType != null" v-html="selectedType.description"></p>
</td>
</tr>
<tr>
<td>是否终止往下匹配</td>
<td>
<div class="ui checkbox">
<input type="checkbox" name="isBreak" value="1"/>
<label></label>
</div>
<p class="comment">如果选中了此选项,一旦匹配成功,不会继续匹配其他的路径规则。</p>
</td>
</tr>
<tr>
<td class="title">名称</td>
<td>
<input type="text" name="name" ref="focus" maxlength="100"/>
<p class="comment">可以用来说明此规则用途。。</p>
</td>
</tr>
<tr>
<td colspan="2"><more-options-indicator></more-options-indicator></td>
</tr>
<tbody v-show="moreOptionsVisible">
<tr>
<td>不区分大小写</td>
<td>
<div class="ui checkbox">
<input type="checkbox" name="isCaseInsensitive" value="1"/>
<label></label>
</div>
<p class="comment">选中表示匹配规则中的路径中的英文字母不区分大小写。</p>
</td>
</tr>
<tr>
<td>反向匹配</td>
<td>
<div class="ui checkbox">
<input type="checkbox" name="isReverse" value="1"/>
<label></label>
</div>
<p class="comment">选中表示匹配所有<strong>不符合规则</strong>的路径。</p>
</td>
</tr>
<tr>
<td>描述</td>
<td>
<textarea rows="3" name="description" maxlength="200"></textarea>
</td>
</tr>
</tbody>
</table>
<submit-btn></submit-btn>
</form>
</div>

View File

@@ -0,0 +1,13 @@
Tea.context(function () {
this.success = NotifySuccess("添加成功", "/servers/server/settings/locations?serverId=" + this.serverId)
this.type = 1
this.selectedType = null
this.changePatternType = function (type) {
this.selectedType = this.patternTypes.$find(function (k, v) {
return v.type == type;
})
}
})

View File

@@ -3,5 +3,23 @@
{$template "/left_menu"}
<div class="right-box">
<p class="ui message">此功能暂未开放,敬请期待。</p>
{$template "menu"}
<p class="comment" v-if="locations.length == 0">暂时还没有路径规则。</p>
<table class="ui table selectable" v-if="locations.length > 0">
<thead>
<tr>
<th>匹配规则</th>
<th class="two op">操作</th>
</tr>
</thead>
<tr v-for="location in locations">
<td>{{location.pattern}}</td>
<td>
<a :href="'/servers/server/settings/locations/location?serverId=' + serverId + '&locationId=' + location.id">详情</a> &nbsp;
<a href="" @click.prevent="deleteLocation(location.id)">删除</a>
</td>
</tr>
</table>
</div>

View File

@@ -0,0 +1,12 @@
Tea.context(function () {
this.deleteLocation = function (locationId) {
teaweb.confirm("确定要删除此路径规则吗?", function () {
this.$post(".delete")
.params({
webId: this.webId,
locationId: locationId
})
.refresh()
})
}
})

View File

@@ -0,0 +1,10 @@
{$layout}
{$template "/left_menu"}
<div class="right-box">
<first-menu>
<menu-item :href="'/servers/server/settings/locations?serverId=' + serverId">所有路径规则 &raquo;</menu-item>
<menu-item :href="'/servers/server/settings/locations/location?serverId=' + serverId + '&locationId=' + locationId" :active="true">{{locationConfig.pattern}}</menu-item>
</first-menu>
{$template "/servers/server/settings/locations/left_menu"}
</div>

View File

@@ -10,7 +10,7 @@
<input type="hidden" name="reverseProxyRefJSON" :value="JSON.stringify(reverseProxyRef)"/>
<table class="ui table selectable definition">
<tr>
<td class="title">是否启用</td>
<td class="title">是否启用反向代理</td>
<td>
<div class="ui checkbox">
<input type="checkbox" v-model="reverseProxyRef.isOn"/>