mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-12-27 07:26:36 +08:00
服务支持fastcgi
This commit is contained in:
201
internal/db/models/http_fastcgi_dao.go
Normal file
201
internal/db/models/http_fastcgi_dao.go
Normal file
@@ -0,0 +1,201 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/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"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
)
|
||||
|
||||
const (
|
||||
HTTPFastcgiStateEnabled = 1 // 已启用
|
||||
HTTPFastcgiStateDisabled = 0 // 已禁用
|
||||
)
|
||||
|
||||
type HTTPFastcgiDAO dbs.DAO
|
||||
|
||||
func NewHTTPFastcgiDAO() *HTTPFastcgiDAO {
|
||||
return dbs.NewDAO(&HTTPFastcgiDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeHTTPFastcgis",
|
||||
Model: new(HTTPFastcgi),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*HTTPFastcgiDAO)
|
||||
}
|
||||
|
||||
var SharedHTTPFastcgiDAO *HTTPFastcgiDAO
|
||||
|
||||
func init() {
|
||||
dbs.OnReady(func() {
|
||||
SharedHTTPFastcgiDAO = NewHTTPFastcgiDAO()
|
||||
})
|
||||
}
|
||||
|
||||
// EnableHTTPFastcgi 启用条目
|
||||
func (this *HTTPFastcgiDAO) EnableHTTPFastcgi(tx *dbs.Tx, id int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Set("state", HTTPFastcgiStateEnabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// DisableHTTPFastcgi 禁用条目
|
||||
func (this *HTTPFastcgiDAO) DisableHTTPFastcgi(tx *dbs.Tx, id int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Set("state", HTTPFastcgiStateDisabled).
|
||||
Update()
|
||||
return err
|
||||
}
|
||||
|
||||
// FindEnabledHTTPFastcgi 查找启用中的条目
|
||||
func (this *HTTPFastcgiDAO) FindEnabledHTTPFastcgi(tx *dbs.Tx, id int64) (*HTTPFastcgi, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
Attr("state", HTTPFastcgiStateEnabled).
|
||||
Find()
|
||||
if result == nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.(*HTTPFastcgi), err
|
||||
}
|
||||
|
||||
// ComposeFastcgiConfig 组合配置
|
||||
func (this *HTTPFastcgiDAO) ComposeFastcgiConfig(tx *dbs.Tx, fastcgiId int64) (*serverconfigs.HTTPFastcgiConfig, error) {
|
||||
if fastcgiId <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
fastcgi, err := this.FindEnabledHTTPFastcgi(tx, fastcgiId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if fastcgi == nil {
|
||||
return nil, nil
|
||||
}
|
||||
config := &serverconfigs.HTTPFastcgiConfig{}
|
||||
config.Id = int64(fastcgi.Id)
|
||||
config.IsOn = fastcgi.IsOn == 1
|
||||
config.Address = fastcgi.Address
|
||||
|
||||
if IsNotNull(fastcgi.Params) {
|
||||
params := []*serverconfigs.HTTPFastcgiParam{}
|
||||
err = json.Unmarshal([]byte(fastcgi.Params), ¶ms)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.Params = params
|
||||
}
|
||||
|
||||
if IsNotNull(fastcgi.ReadTimeout) {
|
||||
duration := &shared.TimeDuration{}
|
||||
err = json.Unmarshal([]byte(fastcgi.ReadTimeout), duration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.ReadTimeout = duration
|
||||
}
|
||||
|
||||
if IsNotNull(fastcgi.ConnTimeout) {
|
||||
duration := &shared.TimeDuration{}
|
||||
err = json.Unmarshal([]byte(fastcgi.ConnTimeout), duration)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.ConnTimeout = duration
|
||||
}
|
||||
|
||||
if fastcgi.PoolSize > 0 {
|
||||
config.PoolSize = types.Int(fastcgi.PoolSize)
|
||||
}
|
||||
config.PathInfoPattern = fastcgi.PathInfoPattern
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// CreateFastcgi 创建Fastcgi
|
||||
func (this *HTTPFastcgiDAO) CreateFastcgi(tx *dbs.Tx, adminId int64, userId int64, isOn bool, address string, paramsJSON []byte, readTimeoutJSON []byte, connTimeoutJSON []byte, poolSize int32, pathInfoPattern string) (int64, error) {
|
||||
op := NewHTTPFastcgiOperator()
|
||||
op.AdminId = adminId
|
||||
op.UserId = userId
|
||||
op.IsOn = isOn
|
||||
op.Address = address
|
||||
if len(paramsJSON) > 0 {
|
||||
op.Params = paramsJSON
|
||||
}
|
||||
if len(readTimeoutJSON) > 0 {
|
||||
op.ReadTimeout = readTimeoutJSON
|
||||
}
|
||||
if len(connTimeoutJSON) > 0 {
|
||||
op.ConnTimeout = connTimeoutJSON
|
||||
}
|
||||
op.PoolSize = poolSize
|
||||
op.PathInfoPattern = pathInfoPattern
|
||||
|
||||
op.State = HTTPFastcgiStateEnabled
|
||||
return this.SaveInt64(tx, op)
|
||||
}
|
||||
|
||||
// UpdateFastcgi 修改Fastcgi
|
||||
func (this *HTTPFastcgiDAO) UpdateFastcgi(tx *dbs.Tx, fastcgiId int64, isOn bool, address string, paramsJSON []byte, readTimeoutJSON []byte, connTimeoutJSON []byte, poolSize int32, pathInfoPattern string) error {
|
||||
if fastcgiId <= 0 {
|
||||
return errors.New("invalid 'fastcgiId'")
|
||||
}
|
||||
op := NewHTTPFastcgiOperator()
|
||||
op.Id = fastcgiId
|
||||
op.IsOn = isOn
|
||||
op.Address = address
|
||||
if len(paramsJSON) > 0 {
|
||||
op.Params = paramsJSON
|
||||
}
|
||||
if len(readTimeoutJSON) > 0 {
|
||||
op.ReadTimeout = readTimeoutJSON
|
||||
}
|
||||
if len(connTimeoutJSON) > 0 {
|
||||
op.ConnTimeout = connTimeoutJSON
|
||||
}
|
||||
op.PoolSize = poolSize
|
||||
op.PathInfoPattern = pathInfoPattern
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return this.NotifyUpdate(tx, fastcgiId)
|
||||
}
|
||||
|
||||
// CheckUserFastcgi 检查用户Fastcgi权限
|
||||
func (this *HTTPFastcgiDAO) CheckUserFastcgi(tx *dbs.Tx, userId int64, fastcgiId int64) error {
|
||||
if userId <= 0 || fastcgiId <= 0 {
|
||||
return errors.New("permission error")
|
||||
}
|
||||
exists, err := this.Query(tx).
|
||||
Pk(fastcgiId).
|
||||
Attr("userId", userId).
|
||||
State(HTTPFastcgiStateEnabled).
|
||||
Exist()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exists {
|
||||
return errors.New("permission error")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// NotifyUpdate 通知更新
|
||||
func (this *HTTPFastcgiDAO) NotifyUpdate(tx *dbs.Tx, fastcgiId int64) error {
|
||||
webId, err := SharedHTTPWebDAO.FindEnabledWebIdWithFastcgiId(tx, fastcgiId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if webId > 0 {
|
||||
return SharedHTTPWebDAO.NotifyUpdate(tx, webId)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
6
internal/db/models/http_fastcgi_dao_test.go
Normal file
6
internal/db/models/http_fastcgi_dao_test.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/iwind/TeaGo/bootstrap"
|
||||
)
|
||||
34
internal/db/models/http_fastcgi_model.go
Normal file
34
internal/db/models/http_fastcgi_model.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package models
|
||||
|
||||
// HTTPFastcgi Fastcgi设置
|
||||
type HTTPFastcgi struct {
|
||||
Id uint64 `field:"id"` // ID
|
||||
AdminId uint32 `field:"adminId"` // 管理员ID
|
||||
UserId uint32 `field:"userId"` // 用户ID
|
||||
IsOn uint8 `field:"isOn"` // 是否启用
|
||||
Address string `field:"address"` // 地址
|
||||
Params string `field:"params"` // 参数
|
||||
ReadTimeout string `field:"readTimeout"` // 读取超时
|
||||
ConnTimeout string `field:"connTimeout"` // 连接超时
|
||||
PoolSize uint32 `field:"poolSize"` // 连接池尺寸
|
||||
PathInfoPattern string `field:"pathInfoPattern"` // PATH_INFO匹配
|
||||
State uint8 `field:"state"` // 状态
|
||||
}
|
||||
|
||||
type HTTPFastcgiOperator struct {
|
||||
Id interface{} // ID
|
||||
AdminId interface{} // 管理员ID
|
||||
UserId interface{} // 用户ID
|
||||
IsOn interface{} // 是否启用
|
||||
Address interface{} // 地址
|
||||
Params interface{} // 参数
|
||||
ReadTimeout interface{} // 读取超时
|
||||
ConnTimeout interface{} // 连接超时
|
||||
PoolSize interface{} // 连接池尺寸
|
||||
PathInfoPattern interface{} // PATH_INFO匹配
|
||||
State interface{} // 状态
|
||||
}
|
||||
|
||||
func NewHTTPFastcgiOperator() *HTTPFastcgiOperator {
|
||||
return &HTTPFastcgiOperator{}
|
||||
}
|
||||
1
internal/db/models/http_fastcgi_model_ext.go
Normal file
1
internal/db/models/http_fastcgi_model_ext.go
Normal file
@@ -0,0 +1 @@
|
||||
package models
|
||||
@@ -44,7 +44,7 @@ func (this *HTTPWebDAO) Init() {
|
||||
_ = this.DAOObject.Init()
|
||||
}
|
||||
|
||||
// 启用条目
|
||||
// EnableHTTPWeb 启用条目
|
||||
func (this *HTTPWebDAO) EnableHTTPWeb(tx *dbs.Tx, id int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -53,7 +53,7 @@ func (this *HTTPWebDAO) EnableHTTPWeb(tx *dbs.Tx, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 禁用条目
|
||||
// DisableHTTPWeb 禁用条目
|
||||
func (this *HTTPWebDAO) DisableHTTPWeb(tx *dbs.Tx, id int64) error {
|
||||
_, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -62,7 +62,7 @@ func (this *HTTPWebDAO) DisableHTTPWeb(tx *dbs.Tx, id int64) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 查找启用中的条目
|
||||
// FindEnabledHTTPWeb 查找启用中的条目
|
||||
func (this *HTTPWebDAO) FindEnabledHTTPWeb(tx *dbs.Tx, id int64) (*HTTPWeb, error) {
|
||||
result, err := this.Query(tx).
|
||||
Pk(id).
|
||||
@@ -74,7 +74,7 @@ func (this *HTTPWebDAO) FindEnabledHTTPWeb(tx *dbs.Tx, id int64) (*HTTPWeb, erro
|
||||
return result.(*HTTPWeb), err
|
||||
}
|
||||
|
||||
// 组合配置
|
||||
// ComposeWebConfig 组合配置
|
||||
func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64) (*serverconfigs.HTTPWebConfig, error) {
|
||||
web, err := SharedHTTPWebDAO.FindEnabledHTTPWeb(tx, webId)
|
||||
if err != nil {
|
||||
@@ -323,10 +323,34 @@ func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64) (*serverconfig
|
||||
config.HostRedirects = redirects
|
||||
}
|
||||
|
||||
// Fastcgi
|
||||
if IsNotNull(web.Fastcgi) {
|
||||
ref := &serverconfigs.HTTPFastcgiRef{}
|
||||
err = json.Unmarshal([]byte(web.Fastcgi), ref)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.FastcgiRef = ref
|
||||
|
||||
if len(ref.FastcgiIds) > 0 {
|
||||
list := []*serverconfigs.HTTPFastcgiConfig{}
|
||||
for _, fastcgiId := range ref.FastcgiIds {
|
||||
fastcgiConfig, err := SharedHTTPFastcgiDAO.ComposeFastcgiConfig(tx, fastcgiId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if fastcgiConfig != nil {
|
||||
list = append(list, fastcgiConfig)
|
||||
}
|
||||
}
|
||||
config.FastcgiList = list
|
||||
}
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// 创建Web配置
|
||||
// CreateWeb 创建Web配置
|
||||
func (this *HTTPWebDAO) CreateWeb(tx *dbs.Tx, adminId int64, userId int64, rootJSON []byte) (int64, error) {
|
||||
op := NewHTTPWebOperator()
|
||||
op.State = HTTPWebStateEnabled
|
||||
@@ -342,7 +366,7 @@ func (this *HTTPWebDAO) CreateWeb(tx *dbs.Tx, adminId int64, userId int64, rootJ
|
||||
return types.Int64(op.Id), nil
|
||||
}
|
||||
|
||||
// 修改Web配置
|
||||
// UpdateWeb 修改Web配置
|
||||
func (this *HTTPWebDAO) UpdateWeb(tx *dbs.Tx, webId int64, rootJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -358,7 +382,7 @@ func (this *HTTPWebDAO) UpdateWeb(tx *dbs.Tx, webId int64, rootJSON []byte) erro
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 修改Gzip配置
|
||||
// UpdateWebGzip 修改Gzip配置
|
||||
func (this *HTTPWebDAO) UpdateWebGzip(tx *dbs.Tx, webId int64, gzipJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -374,7 +398,7 @@ func (this *HTTPWebDAO) UpdateWebGzip(tx *dbs.Tx, webId int64, gzipJSON []byte)
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 修改字符编码
|
||||
// UpdateWebCharset 修改字符编码
|
||||
func (this *HTTPWebDAO) UpdateWebCharset(tx *dbs.Tx, webId int64, charsetJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -390,7 +414,7 @@ func (this *HTTPWebDAO) UpdateWebCharset(tx *dbs.Tx, webId int64, charsetJSON []
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 更改请求Header策略
|
||||
// UpdateWebRequestHeaderPolicy 更改请求Header策略
|
||||
func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(tx *dbs.Tx, webId int64, headerPolicyJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -406,7 +430,7 @@ func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(tx *dbs.Tx, webId int64, he
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 更改响应Header策略
|
||||
// UpdateWebResponseHeaderPolicy 更改响应Header策略
|
||||
func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(tx *dbs.Tx, webId int64, headerPolicyJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -422,7 +446,7 @@ func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(tx *dbs.Tx, webId int64, h
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 更改特殊页面配置
|
||||
// UpdateWebPages 更改特殊页面配置
|
||||
func (this *HTTPWebDAO) UpdateWebPages(tx *dbs.Tx, webId int64, pagesJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -438,7 +462,7 @@ func (this *HTTPWebDAO) UpdateWebPages(tx *dbs.Tx, webId int64, pagesJSON []byte
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 更改Shutdown配置
|
||||
// UpdateWebShutdown 更改Shutdown配置
|
||||
func (this *HTTPWebDAO) UpdateWebShutdown(tx *dbs.Tx, webId int64, shutdownJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -454,7 +478,7 @@ func (this *HTTPWebDAO) UpdateWebShutdown(tx *dbs.Tx, webId int64, shutdownJSON
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 更改访问日志策略
|
||||
// UpdateWebAccessLogConfig 更改访问日志策略
|
||||
func (this *HTTPWebDAO) UpdateWebAccessLogConfig(tx *dbs.Tx, webId int64, accessLogJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -470,7 +494,7 @@ func (this *HTTPWebDAO) UpdateWebAccessLogConfig(tx *dbs.Tx, webId int64, access
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 更改统计配置
|
||||
// UpdateWebStat 更改统计配置
|
||||
func (this *HTTPWebDAO) UpdateWebStat(tx *dbs.Tx, webId int64, statJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -486,7 +510,7 @@ func (this *HTTPWebDAO) UpdateWebStat(tx *dbs.Tx, webId int64, statJSON []byte)
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 更改缓存配置
|
||||
// UpdateWebCache 更改缓存配置
|
||||
func (this *HTTPWebDAO) UpdateWebCache(tx *dbs.Tx, webId int64, cacheJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -502,7 +526,7 @@ func (this *HTTPWebDAO) UpdateWebCache(tx *dbs.Tx, webId int64, cacheJSON []byte
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 更改防火墙配置
|
||||
// UpdateWebFirewall 更改防火墙配置
|
||||
func (this *HTTPWebDAO) UpdateWebFirewall(tx *dbs.Tx, webId int64, firewallJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -518,7 +542,7 @@ func (this *HTTPWebDAO) UpdateWebFirewall(tx *dbs.Tx, webId int64, firewallJSON
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 更改路径规则配置
|
||||
// UpdateWebLocations 更改路径规则配置
|
||||
func (this *HTTPWebDAO) UpdateWebLocations(tx *dbs.Tx, webId int64, locationsJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -534,7 +558,7 @@ func (this *HTTPWebDAO) UpdateWebLocations(tx *dbs.Tx, webId int64, locationsJSO
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 更改跳转到HTTPS设置
|
||||
// UpdateWebRedirectToHTTPS 更改跳转到HTTPS设置
|
||||
func (this *HTTPWebDAO) UpdateWebRedirectToHTTPS(tx *dbs.Tx, webId int64, redirectToHTTPSJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -550,7 +574,7 @@ func (this *HTTPWebDAO) UpdateWebRedirectToHTTPS(tx *dbs.Tx, webId int64, redire
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 修改Websocket设置
|
||||
// UpdateWebsocket 修改Websocket设置
|
||||
func (this *HTTPWebDAO) UpdateWebsocket(tx *dbs.Tx, webId int64, websocketJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -566,7 +590,23 @@ func (this *HTTPWebDAO) UpdateWebsocket(tx *dbs.Tx, webId int64, websocketJSON [
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 修改重写规则设置
|
||||
// UpdateWebFastcgi 修改Fastcgi设置
|
||||
func (this *HTTPWebDAO) UpdateWebFastcgi(tx *dbs.Tx, webId int64, fastcgiJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
}
|
||||
op := NewHTTPWebOperator()
|
||||
op.Id = webId
|
||||
op.Fastcgi = JSONBytes(fastcgiJSON)
|
||||
err := this.Save(tx, op)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// UpdateWebRewriteRules 修改重写规则设置
|
||||
func (this *HTTPWebDAO) UpdateWebRewriteRules(tx *dbs.Tx, webId int64, rewriteRulesJSON []byte) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid webId")
|
||||
@@ -582,7 +622,7 @@ func (this *HTTPWebDAO) UpdateWebRewriteRules(tx *dbs.Tx, webId int64, rewriteRu
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 根据缓存策略ID查找所有的WebId
|
||||
// FindAllWebIdsWithCachePolicyId 根据缓存策略ID查找所有的WebId
|
||||
func (this *HTTPWebDAO) FindAllWebIdsWithCachePolicyId(tx *dbs.Tx, cachePolicyId int64) ([]int64, error) {
|
||||
ones, err := this.Query(tx).
|
||||
State(HTTPWebStateEnabled).
|
||||
@@ -626,7 +666,7 @@ func (this *HTTPWebDAO) FindAllWebIdsWithCachePolicyId(tx *dbs.Tx, cachePolicyId
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// 根据防火墙策略ID查找所有的WebId
|
||||
// FindAllWebIdsWithHTTPFirewallPolicyId 根据防火墙策略ID查找所有的WebId
|
||||
func (this *HTTPWebDAO) FindAllWebIdsWithHTTPFirewallPolicyId(tx *dbs.Tx, firewallPolicyId int64) ([]int64, error) {
|
||||
ones, err := this.Query(tx).
|
||||
State(HTTPWebStateEnabled).
|
||||
@@ -673,7 +713,7 @@ func (this *HTTPWebDAO) FindAllWebIdsWithHTTPFirewallPolicyId(tx *dbs.Tx, firewa
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// 查找包含某个Location的Web
|
||||
// FindEnabledWebIdWithLocationId 查找包含某个Location的Web
|
||||
func (this *HTTPWebDAO) FindEnabledWebIdWithLocationId(tx *dbs.Tx, locationId int64) (webId int64, err error) {
|
||||
return this.Query(tx).
|
||||
State(HTTPWebStateEnabled).
|
||||
@@ -683,7 +723,7 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithLocationId(tx *dbs.Tx, locationId in
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// 查找包含某个重写规则的Web
|
||||
// FindEnabledWebIdWithRewriteRuleId 查找包含某个重写规则的Web
|
||||
func (this *HTTPWebDAO) FindEnabledWebIdWithRewriteRuleId(tx *dbs.Tx, rewriteRuleId int64) (webId int64, err error) {
|
||||
return this.Query(tx).
|
||||
State(HTTPWebStateEnabled).
|
||||
@@ -693,7 +733,7 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithRewriteRuleId(tx *dbs.Tx, rewriteRul
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// 查找包含某个页面的Web
|
||||
// FindEnabledWebIdWithPageId 查找包含某个页面的Web
|
||||
func (this *HTTPWebDAO) FindEnabledWebIdWithPageId(tx *dbs.Tx, pageId int64) (webId int64, err error) {
|
||||
return this.Query(tx).
|
||||
State(HTTPWebStateEnabled).
|
||||
@@ -703,7 +743,7 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithPageId(tx *dbs.Tx, pageId int64) (we
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// 查找包含某个Header的Web
|
||||
// FindEnabledWebIdWithHeaderPolicyId 查找包含某个Header的Web
|
||||
func (this *HTTPWebDAO) FindEnabledWebIdWithHeaderPolicyId(tx *dbs.Tx, headerPolicyId int64) (webId int64, err error) {
|
||||
return this.Query(tx).
|
||||
State(HTTPWebStateEnabled).
|
||||
@@ -713,7 +753,7 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithHeaderPolicyId(tx *dbs.Tx, headerPol
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// 查找包含某个Gzip配置的Web
|
||||
// FindEnabledWebIdWithGzipId 查找包含某个Gzip配置的Web
|
||||
func (this *HTTPWebDAO) FindEnabledWebIdWithGzipId(tx *dbs.Tx, gzipId int64) (webId int64, err error) {
|
||||
return this.Query(tx).
|
||||
State(HTTPWebStateEnabled).
|
||||
@@ -723,7 +763,7 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithGzipId(tx *dbs.Tx, gzipId int64) (we
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// 查找包含某个Websocket配置的Web
|
||||
// FindEnabledWebIdWithWebsocketId 查找包含某个Websocket配置的Web
|
||||
func (this *HTTPWebDAO) FindEnabledWebIdWithWebsocketId(tx *dbs.Tx, websocketId int64) (webId int64, err error) {
|
||||
return this.Query(tx).
|
||||
State(HTTPWebStateEnabled).
|
||||
@@ -733,7 +773,17 @@ func (this *HTTPWebDAO) FindEnabledWebIdWithWebsocketId(tx *dbs.Tx, websocketId
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// 查找使用此Web的Server
|
||||
// FindEnabledWebIdWithFastcgiId 查找包含某个Fastcgi配置的Web
|
||||
func (this *HTTPWebDAO) FindEnabledWebIdWithFastcgiId(tx *dbs.Tx, fastcgiId int64) (webId int64, err error) {
|
||||
return this.Query(tx).
|
||||
State(HTTPWebStateEnabled).
|
||||
ResultPk().
|
||||
Where("JSON_CONTAINS(fastcgi, :jsonQuery)").
|
||||
Param("jsonQuery", maps.Map{"fastcgiIds": fastcgiId}.AsJSON()).
|
||||
FindInt64Col(0)
|
||||
}
|
||||
|
||||
// FindWebServerId 查找使用此Web的Server
|
||||
func (this *HTTPWebDAO) FindWebServerId(tx *dbs.Tx, webId int64) (serverId int64, err error) {
|
||||
if webId <= 0 {
|
||||
return 0, nil
|
||||
@@ -766,7 +816,7 @@ func (this *HTTPWebDAO) FindWebServerId(tx *dbs.Tx, webId int64) (serverId int64
|
||||
return this.FindWebServerId(tx, webId)
|
||||
}
|
||||
|
||||
// 检查用户权限
|
||||
// CheckUserWeb 检查用户权限
|
||||
func (this *HTTPWebDAO) CheckUserWeb(tx *dbs.Tx, userId int64, webId int64) error {
|
||||
serverId, err := this.FindWebServerId(tx, webId)
|
||||
if err != nil {
|
||||
@@ -778,7 +828,7 @@ func (this *HTTPWebDAO) CheckUserWeb(tx *dbs.Tx, userId int64, webId int64) erro
|
||||
return SharedServerDAO.CheckUserServer(tx, userId, serverId)
|
||||
}
|
||||
|
||||
// 设置主机跳转
|
||||
// UpdateWebHostRedirects 设置主机跳转
|
||||
func (this *HTTPWebDAO) UpdateWebHostRedirects(tx *dbs.Tx, webId int64, hostRedirects []*serverconfigs.HTTPHostRedirectConfig) error {
|
||||
if webId <= 0 {
|
||||
return errors.New("invalid ")
|
||||
@@ -801,7 +851,7 @@ func (this *HTTPWebDAO) UpdateWebHostRedirects(tx *dbs.Tx, webId int64, hostRedi
|
||||
return this.NotifyUpdate(tx, webId)
|
||||
}
|
||||
|
||||
// 查找主机跳转
|
||||
// FindWebHostRedirects 查找主机跳转
|
||||
func (this *HTTPWebDAO) FindWebHostRedirects(tx *dbs.Tx, webId int64) ([]byte, error) {
|
||||
col, err := this.Query(tx).
|
||||
Pk(webId).
|
||||
@@ -813,7 +863,7 @@ func (this *HTTPWebDAO) FindWebHostRedirects(tx *dbs.Tx, webId int64) ([]byte, e
|
||||
return []byte(col), nil
|
||||
}
|
||||
|
||||
// 通知更新
|
||||
// NotifyUpdate 通知更新
|
||||
func (this *HTTPWebDAO) NotifyUpdate(tx *dbs.Tx, webId int64) error {
|
||||
serverId, err := this.FindWebServerId(tx, webId)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package models
|
||||
|
||||
// HTTP Web
|
||||
// HTTPWeb HTTP Web
|
||||
type HTTPWeb struct {
|
||||
Id uint32 `field:"id"` // ID
|
||||
IsOn uint8 `field:"isOn"` // 是否启用
|
||||
@@ -27,6 +27,7 @@ type HTTPWeb struct {
|
||||
Websocket string `field:"websocket"` // Websocket设置
|
||||
RewriteRules string `field:"rewriteRules"` // 重写规则配置
|
||||
HostRedirects string `field:"hostRedirects"` // 域名跳转
|
||||
Fastcgi string `field:"fastcgi"` // Fastcgi配置
|
||||
}
|
||||
|
||||
type HTTPWebOperator struct {
|
||||
@@ -55,6 +56,7 @@ type HTTPWebOperator struct {
|
||||
Websocket interface{} // Websocket设置
|
||||
RewriteRules interface{} // 重写规则配置
|
||||
HostRedirects interface{} // 域名跳转
|
||||
Fastcgi interface{} // Fastcgi配置
|
||||
}
|
||||
|
||||
func NewHTTPWebOperator() *HTTPWebOperator {
|
||||
|
||||
Reference in New Issue
Block a user