mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-07 18:50:26 +08:00
多处增加是否独立配置选项
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
"github.com/iwind/TeaGo/Tea"
|
"github.com/iwind/TeaGo/Tea"
|
||||||
"github.com/iwind/TeaGo/dbs"
|
"github.com/iwind/TeaGo/dbs"
|
||||||
@@ -92,26 +93,51 @@ func (this *HTTPWebDAO) ComposeWebConfig(webId int64) (*serverconfigs.HTTPWebCon
|
|||||||
}
|
}
|
||||||
|
|
||||||
// charset
|
// charset
|
||||||
config.Charset = web.Charset
|
if IsNotNull(web.Charset) {
|
||||||
|
charsetConfig := &serverconfigs.HTTPCharsetConfig{}
|
||||||
|
err = json.Unmarshal([]byte(web.Charset), charsetConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.Charset = charsetConfig
|
||||||
|
}
|
||||||
|
|
||||||
// headers
|
// headers
|
||||||
if web.RequestHeaderPolicyId > 0 {
|
if IsNotNull(web.RequestHeader) {
|
||||||
headerPolicy, err := SharedHTTPHeaderPolicyDAO.ComposeHeaderPolicyConfig(int64(web.RequestHeaderPolicyId))
|
ref := &shared.HTTPHeaderPolicyRef{}
|
||||||
|
err = json.Unmarshal([]byte(web.RequestHeader), ref)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.RequestHeaderPolicyRef = ref
|
||||||
|
|
||||||
|
if ref.HeaderPolicyId > 0 {
|
||||||
|
headerPolicy, err := SharedHTTPHeaderPolicyDAO.ComposeHeaderPolicyConfig(ref.HeaderPolicyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if headerPolicy != nil {
|
if headerPolicy != nil {
|
||||||
config.RequestHeaders = headerPolicy
|
config.RequestHeaderPolicy = headerPolicy
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if web.ResponseHeaderPolicyId > 0 {
|
if IsNotNull(web.ResponseHeader) {
|
||||||
headerPolicy, err := SharedHTTPHeaderPolicyDAO.ComposeHeaderPolicyConfig(int64(web.ResponseHeaderPolicyId))
|
ref := &shared.HTTPHeaderPolicyRef{}
|
||||||
|
err = json.Unmarshal([]byte(web.ResponseHeader), ref)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.ResponseHeaderPolicyRef = ref
|
||||||
|
|
||||||
|
if ref.HeaderPolicyId > 0 {
|
||||||
|
headerPolicy, err := SharedHTTPHeaderPolicyDAO.ComposeHeaderPolicyConfig(ref.HeaderPolicyId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if headerPolicy != nil {
|
if headerPolicy != nil {
|
||||||
config.ResponseHeaders = headerPolicy
|
config.ResponseHeaderPolicy = headerPolicy
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,6 +228,16 @@ func (this *HTTPWebDAO) ComposeWebConfig(webId int64) (*serverconfigs.HTTPWebCon
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 跳转
|
||||||
|
if IsNotNull(web.RedirectToHttps) {
|
||||||
|
redirectToHTTPSConfig := &serverconfigs.HTTPRedirectToHTTPSConfig{}
|
||||||
|
err = json.Unmarshal([]byte(web.RedirectToHttps), redirectToHTTPSConfig)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
config.RedirectToHttps = redirectToHTTPSConfig
|
||||||
|
}
|
||||||
|
|
||||||
// TODO 更多配置
|
// TODO 更多配置
|
||||||
|
|
||||||
return config, nil
|
return config, nil
|
||||||
@@ -252,13 +288,13 @@ func (this *HTTPWebDAO) UpdateWebGzip(webId int64, gzipJSON []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 修改字符编码
|
// 修改字符编码
|
||||||
func (this *HTTPWebDAO) UpdateWebCharset(webId int64, charset string) error {
|
func (this *HTTPWebDAO) UpdateWebCharset(webId int64, charsetJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
}
|
}
|
||||||
op := NewHTTPWebOperator()
|
op := NewHTTPWebOperator()
|
||||||
op.Id = webId
|
op.Id = webId
|
||||||
op.Charset = charset
|
op.Charset = charsetJSON
|
||||||
_, err := this.Save(op)
|
_, err := this.Save(op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -268,13 +304,13 @@ func (this *HTTPWebDAO) UpdateWebCharset(webId int64, charset string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更改请求Header策略
|
// 更改请求Header策略
|
||||||
func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(webId int64, headerPolicyId int64) error {
|
func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(webId int64, headerPolicyJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
}
|
}
|
||||||
op := NewHTTPWebOperator()
|
op := NewHTTPWebOperator()
|
||||||
op.Id = webId
|
op.Id = webId
|
||||||
op.RequestHeaderPolicyId = headerPolicyId
|
op.RequestHeader = JSONBytes(headerPolicyJSON)
|
||||||
_, err := this.Save(op)
|
_, err := this.Save(op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -284,13 +320,13 @@ func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(webId int64, headerPolicyId
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更改响应Header策略
|
// 更改响应Header策略
|
||||||
func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(webId int64, headerPolicyId int64) error {
|
func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(webId int64, headerPolicyJSON []byte) error {
|
||||||
if webId <= 0 {
|
if webId <= 0 {
|
||||||
return errors.New("invalid webId")
|
return errors.New("invalid webId")
|
||||||
}
|
}
|
||||||
op := NewHTTPWebOperator()
|
op := NewHTTPWebOperator()
|
||||||
op.Id = webId
|
op.Id = webId
|
||||||
op.ResponseHeaderPolicyId = headerPolicyId
|
op.ResponseHeader = JSONBytes(headerPolicyJSON)
|
||||||
_, err := this.Save(op)
|
_, err := this.Save(op)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -411,6 +447,22 @@ func (this *HTTPWebDAO) UpdateWebLocations(webId int64, locationsJSON []byte) er
|
|||||||
return this.NotifyUpdating(webId)
|
return this.NotifyUpdating(webId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更改跳转到HTTPS设置
|
||||||
|
func (this *HTTPWebDAO) UpdateWebRedirectToHTTPS(webId int64, redirectToHTTPSJSON []byte) error {
|
||||||
|
if webId <= 0 {
|
||||||
|
return errors.New("invalid webId")
|
||||||
|
}
|
||||||
|
op := NewHTTPWebOperator()
|
||||||
|
op.Id = webId
|
||||||
|
op.RedirectToHttps = JSONBytes(redirectToHTTPSJSON)
|
||||||
|
_, err := this.Save(op)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.NotifyUpdating(webId)
|
||||||
|
}
|
||||||
|
|
||||||
// 通知更新
|
// 通知更新
|
||||||
func (this *HTTPWebDAO) NotifyUpdating(webId int64) error {
|
func (this *HTTPWebDAO) NotifyUpdating(webId int64) error {
|
||||||
err := SharedServerDAO.UpdateServerIsUpdatingWithWebId(webId)
|
err := SharedServerDAO.UpdateServerIsUpdatingWithWebId(webId)
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ type HTTPWeb struct {
|
|||||||
RedirectToHttps string `field:"redirectToHttps"` // 跳转到HTTPS设置
|
RedirectToHttps string `field:"redirectToHttps"` // 跳转到HTTPS设置
|
||||||
Indexes string `field:"indexes"` // 首页文件列表
|
Indexes string `field:"indexes"` // 首页文件列表
|
||||||
MaxRequestBodySize string `field:"maxRequestBodySize"` // 最大允许的请求内容尺寸
|
MaxRequestBodySize string `field:"maxRequestBodySize"` // 最大允许的请求内容尺寸
|
||||||
RequestHeaderPolicyId uint32 `field:"requestHeaderPolicyId"` // Request Header策略ID
|
RequestHeader string `field:"requestHeader"` // Request Header策略ID
|
||||||
ResponseHeaderPolicyId uint32 `field:"responseHeaderPolicyId"` // Response Header策略
|
ResponseHeader string `field:"responseHeader"` // Response Header策略
|
||||||
AccessLog string `field:"accessLog"` // 访问日志配置
|
AccessLog string `field:"accessLog"` // 访问日志配置
|
||||||
Stat string `field:"stat"` // 统计配置
|
Stat string `field:"stat"` // 统计配置
|
||||||
Gzip string `field:"gzip"` // Gzip配置
|
Gzip string `field:"gzip"` // Gzip配置
|
||||||
@@ -41,8 +41,8 @@ type HTTPWebOperator struct {
|
|||||||
RedirectToHttps interface{} // 跳转到HTTPS设置
|
RedirectToHttps interface{} // 跳转到HTTPS设置
|
||||||
Indexes interface{} // 首页文件列表
|
Indexes interface{} // 首页文件列表
|
||||||
MaxRequestBodySize interface{} // 最大允许的请求内容尺寸
|
MaxRequestBodySize interface{} // 最大允许的请求内容尺寸
|
||||||
RequestHeaderPolicyId interface{} // Request Header策略ID
|
RequestHeader interface{} // Request Header策略ID
|
||||||
ResponseHeaderPolicyId interface{} // Response Header策略
|
ResponseHeader interface{} // Response Header策略
|
||||||
AccessLog interface{} // 访问日志配置
|
AccessLog interface{} // 访问日志配置
|
||||||
Stat interface{} // 统计配置
|
Stat interface{} // 统计配置
|
||||||
Gzip interface{} // Gzip配置
|
Gzip interface{} // Gzip配置
|
||||||
|
|||||||
@@ -48,9 +48,6 @@ func (this *HTTPWebService) FindEnabledHTTPWeb(ctx context.Context, req *pb.Find
|
|||||||
result.Id = int64(web.Id)
|
result.Id = int64(web.Id)
|
||||||
result.IsOn = web.IsOn == 1
|
result.IsOn = web.IsOn == 1
|
||||||
result.Root = web.Root
|
result.Root = web.Root
|
||||||
result.Charset = web.Charset
|
|
||||||
result.RequestHeaderPolicyId = int64(web.RequestHeaderPolicyId)
|
|
||||||
result.ResponseHeaderPolicyId = int64(web.ResponseHeaderPolicyId)
|
|
||||||
return &pb.FindEnabledHTTPWebResponse{Web: result}, nil
|
return &pb.FindEnabledHTTPWebResponse{Web: result}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,7 +111,7 @@ func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.Up
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = models.SharedHTTPWebDAO.UpdateWebCharset(req.WebId, req.Charset)
|
err = models.SharedHTTPWebDAO.UpdateWebCharset(req.WebId, req.CharsetJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -122,14 +119,14 @@ func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.Up
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更改请求Header策略
|
// 更改请求Header策略
|
||||||
func (this *HTTPWebService) UpdateHTTPWebRequestHeaderPolicy(ctx context.Context, req *pb.UpdateHTTPWebRequestHeaderPolicyRequest) (*pb.RPCUpdateSuccess, error) {
|
func (this *HTTPWebService) UpdateHTTPWebRequestHeader(ctx context.Context, req *pb.UpdateHTTPWebRequestHeaderRequest) (*pb.RPCUpdateSuccess, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = models.SharedHTTPWebDAO.UpdateWebRequestHeaderPolicy(req.WebId, req.HeaderPolicyId)
|
err = models.SharedHTTPWebDAO.UpdateWebRequestHeaderPolicy(req.WebId, req.HeaderJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -138,14 +135,14 @@ func (this *HTTPWebService) UpdateHTTPWebRequestHeaderPolicy(ctx context.Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 更改响应Header策略
|
// 更改响应Header策略
|
||||||
func (this *HTTPWebService) UpdateHTTPWebResponseHeaderPolicy(ctx context.Context, req *pb.UpdateHTTPWebResponseHeaderPolicyRequest) (*pb.RPCUpdateSuccess, error) {
|
func (this *HTTPWebService) UpdateHTTPWebResponseHeader(ctx context.Context, req *pb.UpdateHTTPWebResponseHeaderRequest) (*pb.RPCUpdateSuccess, error) {
|
||||||
// 校验请求
|
// 校验请求
|
||||||
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = models.SharedHTTPWebDAO.UpdateWebResponseHeaderPolicy(req.WebId, req.HeaderPolicyId)
|
err = models.SharedHTTPWebDAO.UpdateWebResponseHeaderPolicy(req.WebId, req.HeaderJSON)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -260,3 +257,18 @@ func (this *HTTPWebService) UpdateHTTPWebLocations(ctx context.Context, req *pb.
|
|||||||
|
|
||||||
return rpcutils.RPCUpdateSuccess()
|
return rpcutils.RPCUpdateSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 跳转到HTTPS
|
||||||
|
func (this *HTTPWebService) UpdateHTTPWebRedirectToHTTPS(ctx context.Context, req *pb.UpdateHTTPWebRedirectToHTTPSRequest) (*pb.RPCUpdateSuccess, error) {
|
||||||
|
// 校验请求
|
||||||
|
_, _, err := rpcutils.ValidateRequest(ctx, rpcutils.UserTypeAdmin)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = models.SharedHTTPWebDAO.UpdateWebRedirectToHTTPS(req.WebId, req.RedirectToHTTPSJSON)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return rpcutils.RPCUpdateSuccess()
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user