多处增加是否独立配置选项

This commit is contained in:
刘祥超
2020-09-23 18:43:38 +08:00
parent 6d6fb22d78
commit 94cdd7abb8
50 changed files with 615 additions and 267 deletions

View File

@@ -27,7 +27,7 @@ func (this *IndexAction) RunGet(params struct {
}
this.Data["webId"] = webConfig.Id
this.Data["charset"] = webConfig.Charset
this.Data["charsetConfig"] = webConfig.Charset
this.Data["usualCharsets"] = configutils.UsualCharsets
this.Data["allCharsets"] = configutils.AllCharsets
@@ -36,14 +36,14 @@ func (this *IndexAction) RunGet(params struct {
}
func (this *IndexAction) RunPost(params struct {
WebId int64
Charset string
WebId int64
CharsetJSON []byte
Must *actions.Must
}) {
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCharset(this.AdminContext(), &pb.UpdateHTTPWebCharsetRequest{
WebId: params.WebId,
Charset: params.Charset,
WebId: params.WebId,
CharsetJSON: params.CharsetJSON,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -27,7 +27,7 @@ func (this *IndexAction) RunGet(params struct {
this.ErrorPage(err)
return
}
this.Data["webId"] = webConfig.Id
gzipId := int64(0)
@@ -53,6 +53,15 @@ func (this *IndexAction) RunGet(params struct {
this.Data["gzipConfig"] = gzipConfig
if webConfig.GzipRef == nil {
webConfig.GzipRef = &serverconfigs.HTTPGzipRef{
IsPrior: false,
IsOn: false,
GzipId: 0,
}
}
this.Data["gzipRef"] = webConfig.GzipRef
this.Show()
}

View File

@@ -1,10 +1,11 @@
package headers
import (
"errors"
"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/shared"
)
type IndexAction struct {
@@ -24,42 +25,52 @@ func (this *IndexAction) RunGet(params struct {
this.ErrorPage(err)
return
}
webId := webConfig.Id
// 初始化Header
webResp, err := this.RPC().HTTPWebRPC().FindEnabledHTTPWeb(this.AdminContext(), &pb.FindEnabledHTTPWebRequest{WebId: webConfig.Id})
if err != nil {
this.ErrorPage(err)
return
}
web := webResp.Web
if web == nil {
this.ErrorPage(errors.New("web should not be nil"))
return
}
isChanged := false
if web.RequestHeaderPolicyId <= 0 {
if webConfig.RequestHeaderPolicy == nil {
createHeaderPolicyResp, err := this.RPC().HTTPHeaderPolicyRPC().CreateHTTPHeaderPolicy(this.AdminContext(), &pb.CreateHTTPHeaderPolicyRequest{})
if err != nil {
this.ErrorPage(err)
return
}
headerPolicyId := createHeaderPolicyResp.HeaderPolicyId
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeaderPolicy(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderPolicyRequest{
WebId: web.Id,
ref := &shared.HTTPHeaderPolicyRef{
IsPrior: false,
IsOn: true,
HeaderPolicyId: headerPolicyId,
}
refJSON, err := json.Marshal(ref)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
WebId: webId,
HeaderJSON: refJSON,
})
isChanged = true
}
if web.ResponseHeaderPolicyId <= 0 {
if webConfig.ResponseHeaderPolicy == nil {
createHeaderPolicyResp, err := this.RPC().HTTPHeaderPolicyRPC().CreateHTTPHeaderPolicy(this.AdminContext(), &pb.CreateHTTPHeaderPolicyRequest{})
if err != nil {
this.ErrorPage(err)
return
}
headerPolicyId := createHeaderPolicyResp.HeaderPolicyId
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeaderPolicy(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderPolicyRequest{
WebId: web.Id,
ref := &shared.HTTPHeaderPolicyRef{
IsPrior: false,
IsOn: true,
HeaderPolicyId: headerPolicyId,
}
refJSON, err := json.Marshal(ref)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
WebId: webId,
HeaderJSON: refJSON,
})
isChanged = true
}
@@ -73,8 +84,10 @@ func (this *IndexAction) RunGet(params struct {
}
}
this.Data["requestHeaderPolicy"] = webConfig.RequestHeaders
this.Data["responseHeaderPolicy"] = webConfig.ResponseHeaders
this.Data["requestHeaderRef"] = webConfig.RequestHeaderPolicyRef
this.Data["requestHeaderPolicy"] = webConfig.RequestHeaderPolicy
this.Data["responseHeaderRef"] = webConfig.ResponseHeaderPolicyRef
this.Data["responseHeaderPolicy"] = webConfig.ResponseHeaderPolicy
this.Show()
}

View File

@@ -3,6 +3,7 @@ package http
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/EdgeAdmin/internal/web/actions/default/servers/serverutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
@@ -43,6 +44,15 @@ func (this *IndexAction) RunGet(params struct {
"addresses": httpConfig.Listen,
}
// 跳转相关设置
webConfig, err := webutils.FindWebConfigWithServerId(this.Parent(), params.ServerId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["webId"] = webConfig.Id
this.Data["redirectToHTTPSConfig"] = webConfig.RedirectToHttps
this.Show()
}
@@ -50,6 +60,9 @@ func (this *IndexAction) RunPost(params struct {
ServerId int64
Addresses string
WebId int64
RedirectToHTTPSJSON []byte
Must *actions.Must
}) {
addresses := []*serverconfigs.NetworkAddressConfig{}
@@ -89,5 +102,16 @@ func (this *IndexAction) RunPost(params struct {
return
}
// 设置跳转到HTTPS
// TODO 校验设置
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRedirectToHTTPS(this.AdminContext(), &pb.UpdateHTTPWebRedirectToHTTPSRequest{
WebId: params.WebId,
RedirectToHTTPSJSON: params.RedirectToHTTPSJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -25,7 +25,7 @@ func (this *IndexAction) RunGet(params struct {
}
this.Data["webId"] = webConfig.Id
this.Data["charset"] = webConfig.Charset
this.Data["charsetConfig"] = webConfig.Charset
this.Data["usualCharsets"] = configutils.UsualCharsets
this.Data["allCharsets"] = configutils.AllCharsets
@@ -34,14 +34,14 @@ func (this *IndexAction) RunGet(params struct {
}
func (this *IndexAction) RunPost(params struct {
WebId int64
Charset string
WebId int64
CharsetJSON []byte
Must *actions.Must
}) {
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCharset(this.AdminContext(), &pb.UpdateHTTPWebCharsetRequest{
WebId: params.WebId,
Charset: params.Charset,
WebId: params.WebId,
CharsetJSON: params.CharsetJSON,
})
if err != nil {
this.ErrorPage(err)

View File

@@ -53,15 +53,25 @@ func (this *IndexAction) RunGet(params struct {
this.Data["gzipConfig"] = gzipConfig
if webConfig.GzipRef == nil {
webConfig.GzipRef = &serverconfigs.HTTPGzipRef{
IsPrior: false,
IsOn: false,
GzipId: 0,
}
}
this.Data["gzipRef"] = webConfig.GzipRef
this.Show()
}
func (this *IndexAction) RunPost(params struct {
WebId int64
GzipId int64
Level int
MinLength string
MaxLength string
WebId int64
GzipRefJSON []byte
GzipId int64
Level int
MinLength string
MaxLength string
Must *actions.Must
}) {
@@ -87,6 +97,14 @@ func (this *IndexAction) RunPost(params struct {
}
}
gzipRef := &serverconfigs.HTTPGzipRef{}
err := json.Unmarshal(params.GzipRefJSON, gzipRef)
if err != nil {
this.ErrorPage(err)
return
}
gzipRef.GzipId = params.GzipId
if params.GzipId > 0 {
_, err := this.RPC().HTTPGzipRPC().UpdateHTTPGzip(this.AdminContext(), &pb.UpdateHTTPGzipRequest{
GzipId: params.GzipId,
@@ -109,24 +127,21 @@ func (this *IndexAction) RunPost(params struct {
return
}
gzipId := resp.GzipId
gzipRef.GzipId = gzipId
}
gzipRef := &serverconfigs.HTTPGzipRef{
IsOn: true,
GzipId: gzipId,
}
gzipRefJSON, err := json.Marshal(gzipRef)
if err != nil {
this.ErrorPage(err)
return
}
gzipRefJSON, err := json.Marshal(gzipRef)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebGzip(this.AdminContext(), &pb.UpdateHTTPWebGzipRequest{
WebId: params.WebId,
GzipJSON: gzipRefJSON,
})
if err != nil {
this.ErrorPage(err)
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebGzip(this.AdminContext(), &pb.UpdateHTTPWebGzipRequest{
WebId: params.WebId,
GzipJSON: gzipRefJSON,
})
if err != nil {
this.ErrorPage(err)
}
this.Success()

View File

@@ -1,10 +1,12 @@
package headers
import (
"errors"
"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/shared"
"github.com/iwind/TeaGo/actions"
)
type IndexAction struct {
@@ -23,41 +25,54 @@ func (this *IndexAction) RunGet(params struct {
return
}
// 初始化Header
webResp, err := this.RPC().HTTPWebRPC().FindEnabledHTTPWeb(this.AdminContext(), &pb.FindEnabledHTTPWebRequest{WebId: webConfig.Id})
if err != nil {
this.ErrorPage(err)
return
}
web := webResp.Web
if web == nil {
this.ErrorPage(errors.New("web should not be nil"))
return
}
webId := webConfig.Id
this.Data["webId"] = webId
isChanged := false
if web.RequestHeaderPolicyId <= 0 {
if webConfig.RequestHeaderPolicy == nil {
createHeaderPolicyResp, err := this.RPC().HTTPHeaderPolicyRPC().CreateHTTPHeaderPolicy(this.AdminContext(), &pb.CreateHTTPHeaderPolicyRequest{})
if err != nil {
this.ErrorPage(err)
return
}
headerPolicyId := createHeaderPolicyResp.HeaderPolicyId
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeaderPolicy(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderPolicyRequest{
WebId: web.Id,
ref := &shared.HTTPHeaderPolicyRef{
IsPrior: false,
IsOn: true,
HeaderPolicyId: headerPolicyId,
}
refJSON, err := json.Marshal(ref)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
WebId: webId,
HeaderJSON: refJSON,
})
isChanged = true
}
if web.ResponseHeaderPolicyId <= 0 {
if webConfig.ResponseHeaderPolicy == nil {
createHeaderPolicyResp, err := this.RPC().HTTPHeaderPolicyRPC().CreateHTTPHeaderPolicy(this.AdminContext(), &pb.CreateHTTPHeaderPolicyRequest{})
if err != nil {
this.ErrorPage(err)
return
}
headerPolicyId := createHeaderPolicyResp.HeaderPolicyId
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeaderPolicy(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderPolicyRequest{
WebId: web.Id,
ref := &shared.HTTPHeaderPolicyRef{
IsPrior: false,
IsOn: true,
HeaderPolicyId: headerPolicyId,
}
refJSON, err := json.Marshal(ref)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
WebId: webId,
HeaderJSON: refJSON,
})
isChanged = true
}
@@ -71,8 +86,44 @@ func (this *IndexAction) RunGet(params struct {
}
}
this.Data["requestHeaderPolicy"] = webConfig.RequestHeaders
this.Data["responseHeaderPolicy"] = webConfig.ResponseHeaders
this.Data["requestHeaderRef"] = webConfig.RequestHeaderPolicyRef
this.Data["requestHeaderPolicy"] = webConfig.RequestHeaderPolicy
this.Data["responseHeaderRef"] = webConfig.ResponseHeaderPolicyRef
this.Data["responseHeaderPolicy"] = webConfig.ResponseHeaderPolicy
this.Show()
}
func (this *IndexAction) RunPost(params struct {
WebId int64
Type string
RequestHeaderJSON []byte
ResponseHeaderJSON []byte
Must *actions.Must
}) {
// TODO 检查配置
switch params.Type {
case "request":
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebRequestHeader(this.AdminContext(), &pb.UpdateHTTPWebRequestHeaderRequest{
WebId: params.WebId,
HeaderJSON: params.RequestHeaderJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
case "response":
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebResponseHeader(this.AdminContext(), &pb.UpdateHTTPWebResponseHeaderRequest{
WebId: params.WebId,
HeaderJSON: params.ResponseHeaderJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
}
this.Success()
}

View File

@@ -15,7 +15,7 @@ func init() {
Helper(serverutils.NewServerHelper()).
Data("tinyMenuItem", "header").
Prefix("/servers/server/settings/locations/headers").
Get("", new(IndexAction)).
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -0,0 +1,50 @@
package http
import (
"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/iwind/TeaGo/actions"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
}
func (this *IndexAction) RunGet(params struct {
LocationId int64
}) {
// 跳转相关设置
webConfig, err := webutils.FindWebConfigWithLocationId(this.Parent(), params.LocationId)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["webId"] = webConfig.Id
this.Data["redirectToHTTPSConfig"] = webConfig.RedirectToHttps
this.Show()
}
func (this *IndexAction) RunPost(params struct {
WebId int64
RedirectToHTTPSJSON []byte
Must *actions.Must
}) {
// 设置跳转到HTTPS
// TODO 校验设置
_, err := this.RPC().HTTPWebRPC().UpdateHTTPWebRedirectToHTTPS(this.AdminContext(), &pb.UpdateHTTPWebRedirectToHTTPSRequest{
WebId: params.WebId,
RedirectToHTTPSJSON: params.RedirectToHTTPSJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,21 @@
package http
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()).
Data("tinyMenuItem", "http").
Prefix("/servers/server/settings/locations/http").
GetPost("", new(IndexAction)).
EndAll()
})
}

View File

@@ -55,6 +55,12 @@ func (this *LocationHelper) createMenus(serverIdString string, locationIdString
},
}
menuItems = append(menuItems, maps.Map{
"name": "HTTP",
"url": "/servers/server/settings/locations/http?serverId=" + serverIdString + "&locationId=" + locationIdString,
"isActive": secondMenuItem == "http",
})
menuItems = append(menuItems, maps.Map{
"name": "Web设置",
"url": "/servers/server/settings/locations/web?serverId=" + serverIdString + "&locationId=" + locationIdString,