mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-03 23:20:26 +08:00
多处增加是否独立配置选项
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
@@ -92,26 +93,51 @@ func (this *HTTPWebDAO) ComposeWebConfig(webId int64) (*serverconfigs.HTTPWebCon
|
||||
}
|
||||
|
||||
// charset
|
||||
config.Charset = web.Charset
|
||||
|
||||
// headers
|
||||
if web.RequestHeaderPolicyId > 0 {
|
||||
headerPolicy, err := SharedHTTPHeaderPolicyDAO.ComposeHeaderPolicyConfig(int64(web.RequestHeaderPolicyId))
|
||||
if IsNotNull(web.Charset) {
|
||||
charsetConfig := &serverconfigs.HTTPCharsetConfig{}
|
||||
err = json.Unmarshal([]byte(web.Charset), charsetConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if headerPolicy != nil {
|
||||
config.RequestHeaders = headerPolicy
|
||||
config.Charset = charsetConfig
|
||||
}
|
||||
|
||||
// headers
|
||||
if IsNotNull(web.RequestHeader) {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
if headerPolicy != nil {
|
||||
config.RequestHeaderPolicy = headerPolicy
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if web.ResponseHeaderPolicyId > 0 {
|
||||
headerPolicy, err := SharedHTTPHeaderPolicyDAO.ComposeHeaderPolicyConfig(int64(web.ResponseHeaderPolicyId))
|
||||
if IsNotNull(web.ResponseHeader) {
|
||||
ref := &shared.HTTPHeaderPolicyRef{}
|
||||
err = json.Unmarshal([]byte(web.ResponseHeader), ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if headerPolicy != nil {
|
||||
config.ResponseHeaders = headerPolicy
|
||||
config.ResponseHeaderPolicyRef = ref
|
||||
|
||||
if ref.HeaderPolicyId > 0 {
|
||||
headerPolicy, err := SharedHTTPHeaderPolicyDAO.ComposeHeaderPolicyConfig(ref.HeaderPolicyId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if headerPolicy != nil {
|
||||
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 更多配置
|
||||
|
||||
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 {
|
||||
return errors.New("invalid webId")
|
||||
}
|
||||
op := NewHTTPWebOperator()
|
||||
op.Id = webId
|
||||
op.Charset = charset
|
||||
op.Charset = charsetJSON
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -268,13 +304,13 @@ func (this *HTTPWebDAO) UpdateWebCharset(webId int64, charset string) error {
|
||||
}
|
||||
|
||||
// 更改请求Header策略
|
||||
func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(webId int64, headerPolicyId int64) error {
|
||||
func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(webId int64, headerPolicyJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
}
|
||||
op := NewHTTPWebOperator()
|
||||
op.Id = webId
|
||||
op.RequestHeaderPolicyId = headerPolicyId
|
||||
op.RequestHeader = JSONBytes(headerPolicyJSON)
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -284,13 +320,13 @@ func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(webId int64, headerPolicyId
|
||||
}
|
||||
|
||||
// 更改响应Header策略
|
||||
func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(webId int64, headerPolicyId int64) error {
|
||||
func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(webId int64, headerPolicyJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
}
|
||||
op := NewHTTPWebOperator()
|
||||
op.Id = webId
|
||||
op.ResponseHeaderPolicyId = headerPolicyId
|
||||
op.ResponseHeader = JSONBytes(headerPolicyJSON)
|
||||
_, err := this.Save(op)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -411,6 +447,22 @@ func (this *HTTPWebDAO) UpdateWebLocations(webId int64, locationsJSON []byte) er
|
||||
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 {
|
||||
err := SharedServerDAO.UpdateServerIsUpdatingWithWebId(webId)
|
||||
|
||||
@@ -2,53 +2,53 @@ package models
|
||||
|
||||
// HTTP Web
|
||||
type HTTPWeb struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
IsOn uint8 `field:"isOn"` // 是否启用
|
||||
TemplateId uint32 `field:"templateId"` // 模版ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
Root string `field:"root"` // 资源根目录
|
||||
Charset string `field:"charset"` // 字符集
|
||||
Shutdown string `field:"shutdown"` // 临时关闭页面配置
|
||||
Pages string `field:"pages"` // 特殊页面
|
||||
RedirectToHttps string `field:"redirectToHttps"` // 跳转到HTTPS设置
|
||||
Indexes string `field:"indexes"` // 首页文件列表
|
||||
MaxRequestBodySize string `field:"maxRequestBodySize"` // 最大允许的请求内容尺寸
|
||||
RequestHeaderPolicyId uint32 `field:"requestHeaderPolicyId"` // Request Header策略ID
|
||||
ResponseHeaderPolicyId uint32 `field:"responseHeaderPolicyId"` // Response Header策略
|
||||
AccessLog string `field:"accessLog"` // 访问日志配置
|
||||
Stat string `field:"stat"` // 统计配置
|
||||
Gzip string `field:"gzip"` // Gzip配置
|
||||
Cache string `field:"cache"` // 缓存配置
|
||||
Firewall string `field:"firewall"` // 防火墙设置
|
||||
Locations string `field:"locations"` // 路径规则配置
|
||||
Id uint32 `field:"id"` // ID
|
||||
IsOn uint8 `field:"isOn"` // 是否启用
|
||||
TemplateId uint32 `field:"templateId"` // 模版ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
State uint8 `field:"state"` // 状态
|
||||
CreatedAt uint64 `field:"createdAt"` // 创建时间
|
||||
Root string `field:"root"` // 资源根目录
|
||||
Charset string `field:"charset"` // 字符集
|
||||
Shutdown string `field:"shutdown"` // 临时关闭页面配置
|
||||
Pages string `field:"pages"` // 特殊页面
|
||||
RedirectToHttps string `field:"redirectToHttps"` // 跳转到HTTPS设置
|
||||
Indexes string `field:"indexes"` // 首页文件列表
|
||||
MaxRequestBodySize string `field:"maxRequestBodySize"` // 最大允许的请求内容尺寸
|
||||
RequestHeader string `field:"requestHeader"` // Request Header策略ID
|
||||
ResponseHeader string `field:"responseHeader"` // Response Header策略
|
||||
AccessLog string `field:"accessLog"` // 访问日志配置
|
||||
Stat string `field:"stat"` // 统计配置
|
||||
Gzip string `field:"gzip"` // Gzip配置
|
||||
Cache string `field:"cache"` // 缓存配置
|
||||
Firewall string `field:"firewall"` // 防火墙设置
|
||||
Locations string `field:"locations"` // 路径规则配置
|
||||
}
|
||||
|
||||
type HTTPWebOperator struct {
|
||||
Id interface{} // ID
|
||||
IsOn interface{} // 是否启用
|
||||
TemplateId interface{} // 模版ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
Root interface{} // 资源根目录
|
||||
Charset interface{} // 字符集
|
||||
Shutdown interface{} // 临时关闭页面配置
|
||||
Pages interface{} // 特殊页面
|
||||
RedirectToHttps interface{} // 跳转到HTTPS设置
|
||||
Indexes interface{} // 首页文件列表
|
||||
MaxRequestBodySize interface{} // 最大允许的请求内容尺寸
|
||||
RequestHeaderPolicyId interface{} // Request Header策略ID
|
||||
ResponseHeaderPolicyId interface{} // Response Header策略
|
||||
AccessLog interface{} // 访问日志配置
|
||||
Stat interface{} // 统计配置
|
||||
Gzip interface{} // Gzip配置
|
||||
Cache interface{} // 缓存配置
|
||||
Firewall interface{} // 防火墙设置
|
||||
Locations interface{} // 路径规则配置
|
||||
Id interface{} // ID
|
||||
IsOn interface{} // 是否启用
|
||||
TemplateId interface{} // 模版ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
State interface{} // 状态
|
||||
CreatedAt interface{} // 创建时间
|
||||
Root interface{} // 资源根目录
|
||||
Charset interface{} // 字符集
|
||||
Shutdown interface{} // 临时关闭页面配置
|
||||
Pages interface{} // 特殊页面
|
||||
RedirectToHttps interface{} // 跳转到HTTPS设置
|
||||
Indexes interface{} // 首页文件列表
|
||||
MaxRequestBodySize interface{} // 最大允许的请求内容尺寸
|
||||
RequestHeader interface{} // Request Header策略ID
|
||||
ResponseHeader interface{} // Response Header策略
|
||||
AccessLog interface{} // 访问日志配置
|
||||
Stat interface{} // 统计配置
|
||||
Gzip interface{} // Gzip配置
|
||||
Cache interface{} // 缓存配置
|
||||
Firewall interface{} // 防火墙设置
|
||||
Locations interface{} // 路径规则配置
|
||||
}
|
||||
|
||||
func NewHTTPWebOperator() *HTTPWebOperator {
|
||||
|
||||
@@ -48,9 +48,6 @@ func (this *HTTPWebService) FindEnabledHTTPWeb(ctx context.Context, req *pb.Find
|
||||
result.Id = int64(web.Id)
|
||||
result.IsOn = web.IsOn == 1
|
||||
result.Root = web.Root
|
||||
result.Charset = web.Charset
|
||||
result.RequestHeaderPolicyId = int64(web.RequestHeaderPolicyId)
|
||||
result.ResponseHeaderPolicyId = int64(web.ResponseHeaderPolicyId)
|
||||
return &pb.FindEnabledHTTPWebResponse{Web: result}, nil
|
||||
}
|
||||
|
||||
@@ -114,7 +111,7 @@ func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.Up
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWebCharset(req.WebId, req.Charset)
|
||||
err = models.SharedHTTPWebDAO.UpdateWebCharset(req.WebId, req.CharsetJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -122,14 +119,14 @@ func (this *HTTPWebService) UpdateHTTPWebCharset(ctx context.Context, req *pb.Up
|
||||
}
|
||||
|
||||
// 更改请求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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWebRequestHeaderPolicy(req.WebId, req.HeaderPolicyId)
|
||||
err = models.SharedHTTPWebDAO.UpdateWebRequestHeaderPolicy(req.WebId, req.HeaderJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -138,14 +135,14 @@ func (this *HTTPWebService) UpdateHTTPWebRequestHeaderPolicy(ctx context.Context
|
||||
}
|
||||
|
||||
// 更改响应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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = models.SharedHTTPWebDAO.UpdateWebResponseHeaderPolicy(req.WebId, req.HeaderPolicyId)
|
||||
err = models.SharedHTTPWebDAO.UpdateWebResponseHeaderPolicy(req.WebId, req.HeaderJSON)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -260,3 +257,18 @@ func (this *HTTPWebService) UpdateHTTPWebLocations(ctx context.Context, req *pb.
|
||||
|
||||
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