2020-09-15 14:44:11 +08:00
|
|
|
|
package models
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
2020-09-17 10:16:00 +08:00
|
|
|
|
"encoding/json"
|
2020-09-15 14:44:11 +08:00
|
|
|
|
"errors"
|
2021-11-11 14:16:42 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeAPI/internal/utils"
|
2020-09-15 14:44:11 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
2020-10-06 21:02:15 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/firewallconfigs"
|
2020-09-23 18:43:42 +08:00
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
2020-09-15 14:44:11 +08:00
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
|
|
"github.com/iwind/TeaGo/Tea"
|
|
|
|
|
|
"github.com/iwind/TeaGo/dbs"
|
2020-10-20 20:18:06 +08:00
|
|
|
|
"github.com/iwind/TeaGo/lists"
|
2021-01-17 16:48:00 +08:00
|
|
|
|
"github.com/iwind/TeaGo/maps"
|
2020-09-15 14:44:11 +08:00
|
|
|
|
"github.com/iwind/TeaGo/types"
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
HTTPWebStateEnabled = 1 // 已启用
|
|
|
|
|
|
HTTPWebStateDisabled = 0 // 已禁用
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type HTTPWebDAO dbs.DAO
|
|
|
|
|
|
|
|
|
|
|
|
func NewHTTPWebDAO() *HTTPWebDAO {
|
|
|
|
|
|
return dbs.NewDAO(&HTTPWebDAO{
|
|
|
|
|
|
DAOObject: dbs.DAOObject{
|
|
|
|
|
|
DB: Tea.Env,
|
|
|
|
|
|
Table: "edgeHTTPWebs",
|
|
|
|
|
|
Model: new(HTTPWeb),
|
|
|
|
|
|
PkName: "id",
|
|
|
|
|
|
},
|
|
|
|
|
|
}).(*HTTPWebDAO)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-13 20:05:13 +08:00
|
|
|
|
var SharedHTTPWebDAO *HTTPWebDAO
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
|
dbs.OnReady(func() {
|
|
|
|
|
|
SharedHTTPWebDAO = NewHTTPWebDAO()
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
2020-09-15 14:44:11 +08:00
|
|
|
|
|
2020-09-26 08:06:40 +08:00
|
|
|
|
func (this *HTTPWebDAO) Init() {
|
2021-01-17 16:48:00 +08:00
|
|
|
|
_ = this.DAOObject.Init()
|
2020-09-26 08:06:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// EnableHTTPWeb 启用条目
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) EnableHTTPWeb(tx *dbs.Tx, id int64) error {
|
|
|
|
|
|
_, err := this.Query(tx).
|
2020-09-15 14:44:11 +08:00
|
|
|
|
Pk(id).
|
|
|
|
|
|
Set("state", HTTPWebStateEnabled).
|
|
|
|
|
|
Update()
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// DisableHTTPWeb 禁用条目
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) DisableHTTPWeb(tx *dbs.Tx, id int64) error {
|
|
|
|
|
|
_, err := this.Query(tx).
|
2020-09-15 14:44:11 +08:00
|
|
|
|
Pk(id).
|
|
|
|
|
|
Set("state", HTTPWebStateDisabled).
|
|
|
|
|
|
Update()
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindEnabledHTTPWeb 查找启用中的条目
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindEnabledHTTPWeb(tx *dbs.Tx, id int64) (*HTTPWeb, error) {
|
|
|
|
|
|
result, err := this.Query(tx).
|
2020-09-15 14:44:11 +08:00
|
|
|
|
Pk(id).
|
|
|
|
|
|
Attr("state", HTTPWebStateEnabled).
|
|
|
|
|
|
Find()
|
|
|
|
|
|
if result == nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
return result.(*HTTPWeb), err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// ComposeWebConfig 组合配置
|
2021-11-11 14:16:42 +08:00
|
|
|
|
func (this *HTTPWebDAO) ComposeWebConfig(tx *dbs.Tx, webId int64, cacheMap *utils.CacheMap) (*serverconfigs.HTTPWebConfig, error) {
|
2021-08-22 11:35:33 +08:00
|
|
|
|
if cacheMap == nil {
|
2021-11-11 14:16:42 +08:00
|
|
|
|
cacheMap = utils.NewCacheMap()
|
2021-08-22 11:35:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
var cacheKey = this.Table + ":config:" + types.String(webId)
|
2021-11-11 14:16:42 +08:00
|
|
|
|
var cache, _ = cacheMap.Get(cacheKey)
|
2021-08-22 11:35:33 +08:00
|
|
|
|
if cache != nil {
|
|
|
|
|
|
return cache.(*serverconfigs.HTTPWebConfig), nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-01 23:31:30 +08:00
|
|
|
|
web, err := SharedHTTPWebDAO.FindEnabledHTTPWeb(tx, webId)
|
2020-09-15 14:44:11 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if web == nil {
|
|
|
|
|
|
return nil, nil
|
|
|
|
|
|
}
|
2020-09-20 16:28:07 +08:00
|
|
|
|
|
2020-09-16 09:09:21 +08:00
|
|
|
|
config := &serverconfigs.HTTPWebConfig{}
|
|
|
|
|
|
config.Id = webId
|
2020-09-15 14:44:11 +08:00
|
|
|
|
config.IsOn = web.IsOn == 1
|
2020-09-26 11:21:43 +08:00
|
|
|
|
|
|
|
|
|
|
// root
|
|
|
|
|
|
if IsNotNull(web.Root) {
|
|
|
|
|
|
rootConfig := &serverconfigs.HTTPRootConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Root), rootConfig)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.Root = rootConfig
|
|
|
|
|
|
}
|
2020-09-16 09:09:21 +08:00
|
|
|
|
|
2021-09-29 19:32:25 +08:00
|
|
|
|
// compression
|
|
|
|
|
|
if IsNotNull(web.Compression) {
|
|
|
|
|
|
compression := &serverconfigs.HTTPCompressionConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Compression), compression)
|
2020-09-20 16:28:07 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
2021-09-29 19:32:25 +08:00
|
|
|
|
config.Compression = compression
|
2020-09-20 16:28:07 +08:00
|
|
|
|
|
2021-09-29 19:32:25 +08:00
|
|
|
|
// gzip
|
|
|
|
|
|
if compression.GzipRef != nil && compression.GzipRef.Id > 0 {
|
|
|
|
|
|
gzipConfig, err := SharedHTTPGzipDAO.ComposeGzipConfig(tx, compression.GzipRef.Id)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
compression.Gzip = gzipConfig
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// brotli
|
|
|
|
|
|
if compression.BrotliRef != nil && compression.BrotliRef.Id > 0 {
|
|
|
|
|
|
brotliConfig, err := SharedHTTPBrotliPolicyDAO.ComposeBrotliConfig(tx, compression.BrotliRef.Id)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
compression.Brotli = brotliConfig
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// deflate
|
|
|
|
|
|
if compression.DeflateRef != nil && compression.DeflateRef.Id > 0 {
|
|
|
|
|
|
deflateConfig, err := SharedHTTPDeflatePolicyDAO.ComposeDeflateConfig(tx, compression.DeflateRef.Id)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
compression.Deflate = deflateConfig
|
2020-09-16 09:09:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-16 20:29:18 +08:00
|
|
|
|
// charset
|
2020-09-23 18:43:42 +08:00
|
|
|
|
if IsNotNull(web.Charset) {
|
|
|
|
|
|
charsetConfig := &serverconfigs.HTTPCharsetConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Charset), charsetConfig)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.Charset = charsetConfig
|
|
|
|
|
|
}
|
2020-09-16 20:29:18 +08:00
|
|
|
|
|
|
|
|
|
|
// headers
|
2020-09-23 18:43:42 +08:00
|
|
|
|
if IsNotNull(web.RequestHeader) {
|
|
|
|
|
|
ref := &shared.HTTPHeaderPolicyRef{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.RequestHeader), ref)
|
2020-09-16 20:29:18 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
2020-09-23 18:43:42 +08:00
|
|
|
|
config.RequestHeaderPolicyRef = ref
|
|
|
|
|
|
|
|
|
|
|
|
if ref.HeaderPolicyId > 0 {
|
2021-01-01 23:31:30 +08:00
|
|
|
|
headerPolicy, err := SharedHTTPHeaderPolicyDAO.ComposeHeaderPolicyConfig(tx, ref.HeaderPolicyId)
|
2020-09-23 18:43:42 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if headerPolicy != nil {
|
|
|
|
|
|
config.RequestHeaderPolicy = headerPolicy
|
|
|
|
|
|
}
|
2020-09-16 20:29:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-23 18:43:42 +08:00
|
|
|
|
if IsNotNull(web.ResponseHeader) {
|
|
|
|
|
|
ref := &shared.HTTPHeaderPolicyRef{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.ResponseHeader), ref)
|
2020-09-16 20:29:18 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
2020-09-23 18:43:42 +08:00
|
|
|
|
config.ResponseHeaderPolicyRef = ref
|
|
|
|
|
|
|
|
|
|
|
|
if ref.HeaderPolicyId > 0 {
|
2021-01-01 23:31:30 +08:00
|
|
|
|
headerPolicy, err := SharedHTTPHeaderPolicyDAO.ComposeHeaderPolicyConfig(tx, ref.HeaderPolicyId)
|
2020-09-23 18:43:42 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if headerPolicy != nil {
|
|
|
|
|
|
config.ResponseHeaderPolicy = headerPolicy
|
|
|
|
|
|
}
|
2020-09-16 20:29:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-16 09:09:21 +08:00
|
|
|
|
|
2020-09-17 10:16:00 +08:00
|
|
|
|
// shutdown
|
|
|
|
|
|
if IsNotNull(web.Shutdown) {
|
|
|
|
|
|
shutdownConfig := &serverconfigs.HTTPShutdownConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Shutdown), shutdownConfig)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.Shutdown = shutdownConfig
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// pages
|
|
|
|
|
|
if IsNotNull(web.Pages) {
|
|
|
|
|
|
pages := []*serverconfigs.HTTPPageConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Pages), &pages)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
for index, page := range pages {
|
2021-08-22 11:35:33 +08:00
|
|
|
|
pageConfig, err := SharedHTTPPageDAO.ComposePageConfig(tx, page.Id, cacheMap)
|
2020-09-17 10:16:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
pages[index] = pageConfig
|
|
|
|
|
|
}
|
|
|
|
|
|
if len(pages) > 0 {
|
|
|
|
|
|
config.Pages = pages
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-20 11:56:30 +08:00
|
|
|
|
// 访问日志
|
|
|
|
|
|
if IsNotNull(web.AccessLog) {
|
2020-09-20 16:28:07 +08:00
|
|
|
|
accessLogConfig := &serverconfigs.HTTPAccessLogRef{}
|
2020-09-20 11:56:30 +08:00
|
|
|
|
err = json.Unmarshal([]byte(web.AccessLog), accessLogConfig)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
2020-09-20 16:28:07 +08:00
|
|
|
|
config.AccessLogRef = accessLogConfig
|
2020-09-20 11:56:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-20 14:48:41 +08:00
|
|
|
|
// 统计配置
|
|
|
|
|
|
if IsNotNull(web.Stat) {
|
2020-09-20 16:28:07 +08:00
|
|
|
|
statRef := &serverconfigs.HTTPStatRef{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Stat), statRef)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.StatRef = statRef
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 缓存配置
|
|
|
|
|
|
if IsNotNull(web.Cache) {
|
2020-10-04 20:38:12 +08:00
|
|
|
|
cacheConfig := &serverconfigs.HTTPCacheConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Cache), &cacheConfig)
|
2020-09-20 14:48:41 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
2020-10-04 20:38:12 +08:00
|
|
|
|
config.Cache = cacheConfig
|
2020-12-17 17:36:20 +08:00
|
|
|
|
|
|
|
|
|
|
// 暂不支持自定义缓存策略设置,因为同一个集群下的服务需要集中管理
|
2020-09-20 14:48:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-20 20:12:47 +08:00
|
|
|
|
// 防火墙配置
|
|
|
|
|
|
if IsNotNull(web.Firewall) {
|
2020-10-06 21:02:15 +08:00
|
|
|
|
firewallRef := &firewallconfigs.HTTPFirewallRef{}
|
2020-09-20 20:12:47 +08:00
|
|
|
|
err = json.Unmarshal([]byte(web.Firewall), firewallRef)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.FirewallRef = firewallRef
|
2020-10-08 15:08:08 +08:00
|
|
|
|
|
2021-01-03 20:18:07 +08:00
|
|
|
|
// 自定义防火墙设置
|
|
|
|
|
|
if firewallRef.FirewallPolicyId > 0 {
|
2021-08-22 11:35:33 +08:00
|
|
|
|
firewallPolicy, err := SharedHTTPFirewallPolicyDAO.ComposeFirewallPolicy(tx, firewallRef.FirewallPolicyId, cacheMap)
|
2021-01-03 20:18:07 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if firewallPolicy == nil {
|
|
|
|
|
|
config.FirewallRef = nil
|
|
|
|
|
|
} else {
|
|
|
|
|
|
config.FirewallPolicy = firewallPolicy
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-09-20 20:12:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-13 14:30:30 +08:00
|
|
|
|
// 路由规则
|
2020-09-21 19:51:56 +08:00
|
|
|
|
if IsNotNull(web.Locations) {
|
|
|
|
|
|
refs := []*serverconfigs.HTTPLocationRef{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Locations), &refs)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if len(refs) > 0 {
|
|
|
|
|
|
config.LocationRefs = refs
|
|
|
|
|
|
|
2021-08-22 11:35:33 +08:00
|
|
|
|
locations, err := SharedHTTPLocationDAO.ConvertLocationRefs(tx, refs, cacheMap)
|
2020-09-21 19:51:56 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.Locations = locations
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-23 18:43:42 +08:00
|
|
|
|
// 跳转
|
|
|
|
|
|
if IsNotNull(web.RedirectToHttps) {
|
|
|
|
|
|
redirectToHTTPSConfig := &serverconfigs.HTTPRedirectToHTTPSConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.RedirectToHttps), redirectToHTTPSConfig)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.RedirectToHttps = redirectToHTTPSConfig
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-26 19:54:15 +08:00
|
|
|
|
// Websocket
|
|
|
|
|
|
if IsNotNull(web.Websocket) {
|
|
|
|
|
|
ref := &serverconfigs.HTTPWebsocketRef{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Websocket), ref)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.WebsocketRef = ref
|
|
|
|
|
|
if ref.WebsocketId > 0 {
|
2021-01-01 23:31:30 +08:00
|
|
|
|
websocketConfig, err := SharedHTTPWebsocketDAO.ComposeWebsocketConfig(tx, ref.WebsocketId)
|
2020-09-26 19:54:15 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if websocketConfig != nil {
|
|
|
|
|
|
config.Websocket = websocketConfig
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-28 16:25:39 +08:00
|
|
|
|
// 重写规则
|
|
|
|
|
|
if IsNotNull(web.RewriteRules) {
|
|
|
|
|
|
refs := []*serverconfigs.HTTPRewriteRef{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.RewriteRules), &refs)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
for _, ref := range refs {
|
2021-08-22 11:35:33 +08:00
|
|
|
|
rewriteRule, err := SharedHTTPRewriteRuleDAO.ComposeRewriteRule(tx, ref.RewriteRuleId, cacheMap)
|
2020-09-28 16:25:39 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if rewriteRule != nil {
|
|
|
|
|
|
config.RewriteRefs = append(config.RewriteRefs, ref)
|
|
|
|
|
|
config.RewriteRules = append(config.RewriteRules, rewriteRule)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-10 17:34:35 +08:00
|
|
|
|
// 主机跳转
|
|
|
|
|
|
if IsNotNull(web.HostRedirects) {
|
|
|
|
|
|
redirects := []*serverconfigs.HTTPHostRedirectConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.HostRedirects), &redirects)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.HostRedirects = redirects
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// 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
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-17 21:17:53 +08:00
|
|
|
|
// 认证
|
|
|
|
|
|
if IsNotNull(web.Auth) {
|
|
|
|
|
|
authConfig := &serverconfigs.HTTPAuthConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Auth), authConfig)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
var newRefs []*serverconfigs.HTTPAuthPolicyRef
|
|
|
|
|
|
for _, ref := range authConfig.PolicyRefs {
|
2021-08-22 11:35:33 +08:00
|
|
|
|
policyConfig, err := SharedHTTPAuthPolicyDAO.ComposePolicyConfig(tx, ref.AuthPolicyId, cacheMap)
|
2021-06-17 21:17:53 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if policyConfig != nil {
|
|
|
|
|
|
ref.AuthPolicy = policyConfig
|
|
|
|
|
|
newRefs = append(newRefs, ref)
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
config.Auth = authConfig
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-01 16:24:56 +08:00
|
|
|
|
// WebP
|
|
|
|
|
|
if IsNotNull(web.Webp) {
|
|
|
|
|
|
var webpConfig = &serverconfigs.WebPImageConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.Webp), webpConfig)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.WebP = webpConfig
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-06 11:40:29 +08:00
|
|
|
|
// RemoteAddr
|
|
|
|
|
|
if IsNotNull(web.RemoteAddr) {
|
|
|
|
|
|
var remoteAddrConfig = &serverconfigs.HTTPRemoteAddrConfig{}
|
|
|
|
|
|
err = json.Unmarshal([]byte(web.RemoteAddr), remoteAddrConfig)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
config.RemoteAddr = remoteAddrConfig
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-24 12:00:38 +08:00
|
|
|
|
// mergeSlashes
|
|
|
|
|
|
config.MergeSlashes = web.MergeSlashes == 1
|
|
|
|
|
|
|
2021-11-11 14:16:42 +08:00
|
|
|
|
if cacheMap != nil {
|
|
|
|
|
|
cacheMap.Put(cacheKey, config)
|
|
|
|
|
|
}
|
2021-08-22 11:35:33 +08:00
|
|
|
|
|
2020-09-15 14:44:11 +08:00
|
|
|
|
return config, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// CreateWeb 创建Web配置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) CreateWeb(tx *dbs.Tx, adminId int64, userId int64, rootJSON []byte) (int64, error) {
|
2020-09-15 14:44:11 +08:00
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.State = HTTPWebStateEnabled
|
2020-12-18 21:18:53 +08:00
|
|
|
|
op.AdminId = adminId
|
|
|
|
|
|
op.UserId = userId
|
|
|
|
|
|
if len(rootJSON) > 0 {
|
|
|
|
|
|
op.Root = JSONBytes(rootJSON)
|
|
|
|
|
|
}
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2020-09-15 14:44:11 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
}
|
|
|
|
|
|
return types.Int64(op.Id), nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWeb 修改Web配置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWeb(tx *dbs.Tx, webId int64, rootJSON []byte) error {
|
2020-09-15 14:44:11 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
2020-09-26 19:54:15 +08:00
|
|
|
|
op.Root = JSONBytes(rootJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-16 09:09:21 +08:00
|
|
|
|
}
|
2020-09-15 14:44:11 +08:00
|
|
|
|
|
2021-09-29 19:32:25 +08:00
|
|
|
|
// UpdateWebCompression 修改压缩配置
|
|
|
|
|
|
func (this *HTTPWebDAO) UpdateWebCompression(tx *dbs.Tx, webId int64, compressionConfig []byte) error {
|
2020-09-16 09:09:21 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
2021-09-29 19:32:25 +08:00
|
|
|
|
op.Compression = JSONBytes(compressionConfig)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-16 09:09:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-01 16:24:56 +08:00
|
|
|
|
// UpdateWebWebP 修改WebP配置
|
|
|
|
|
|
func (this *HTTPWebDAO) UpdateWebWebP(tx *dbs.Tx, webId int64, webpConfig []byte) error {
|
|
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.Webp = JSONBytes(webpConfig)
|
|
|
|
|
|
err := this.Save(tx, op)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-06 11:40:29 +08:00
|
|
|
|
// UpdateWebRemoteAddr 修改RemoteAddr配置
|
|
|
|
|
|
func (this *HTTPWebDAO) UpdateWebRemoteAddr(tx *dbs.Tx, webId int64, remoteAddrConfig []byte) error {
|
|
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
var op = NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.RemoteAddr = remoteAddrConfig
|
|
|
|
|
|
err := this.Save(tx, op)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebCharset 修改字符编码
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebCharset(tx *dbs.Tx, webId int64, charsetJSON []byte) error {
|
2020-09-16 20:29:18 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
2020-09-26 19:54:15 +08:00
|
|
|
|
op.Charset = JSONBytes(charsetJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-16 20:29:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebRequestHeaderPolicy 更改请求Header策略
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebRequestHeaderPolicy(tx *dbs.Tx, webId int64, headerPolicyJSON []byte) error {
|
2020-09-16 20:29:18 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
2020-09-23 18:43:42 +08:00
|
|
|
|
op.RequestHeader = JSONBytes(headerPolicyJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-16 20:29:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebResponseHeaderPolicy 更改响应Header策略
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebResponseHeaderPolicy(tx *dbs.Tx, webId int64, headerPolicyJSON []byte) error {
|
2020-09-16 20:29:18 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
2020-09-23 18:43:42 +08:00
|
|
|
|
op.ResponseHeader = JSONBytes(headerPolicyJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-16 20:29:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebPages 更改特殊页面配置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebPages(tx *dbs.Tx, webId int64, pagesJSON []byte) error {
|
2020-09-17 10:16:00 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.Pages = JSONBytes(pagesJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-17 10:16:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebShutdown 更改Shutdown配置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebShutdown(tx *dbs.Tx, webId int64, shutdownJSON []byte) error {
|
2020-09-17 10:16:00 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.Shutdown = JSONBytes(shutdownJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-17 10:16:00 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebAccessLogConfig 更改访问日志策略
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebAccessLogConfig(tx *dbs.Tx, webId int64, accessLogJSON []byte) error {
|
2020-09-20 11:56:30 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.AccessLog = JSONBytes(accessLogJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-20 11:56:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebStat 更改统计配置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebStat(tx *dbs.Tx, webId int64, statJSON []byte) error {
|
2020-09-20 14:48:41 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.Stat = JSONBytes(statJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-20 14:48:41 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebCache 更改缓存配置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebCache(tx *dbs.Tx, webId int64, cacheJSON []byte) error {
|
2020-09-20 16:28:07 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.Cache = JSONBytes(cacheJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-20 16:28:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebFirewall 更改防火墙配置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebFirewall(tx *dbs.Tx, webId int64, firewallJSON []byte) error {
|
2020-09-20 20:12:47 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.Firewall = JSONBytes(firewallJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-20 20:12:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-07-13 14:30:30 +08:00
|
|
|
|
// UpdateWebLocations 更改路由规则配置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebLocations(tx *dbs.Tx, webId int64, locationsJSON []byte) error {
|
2020-09-21 19:51:56 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.Locations = JSONBytes(locationsJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-21 19:51:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebRedirectToHTTPS 更改跳转到HTTPS设置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebRedirectToHTTPS(tx *dbs.Tx, webId int64, redirectToHTTPSJSON []byte) error {
|
2020-09-23 18:43:42 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.RedirectToHttps = JSONBytes(redirectToHTTPSJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-15 14:44:11 +08:00
|
|
|
|
}
|
2020-09-26 19:54:15 +08:00
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebsocket 修改Websocket设置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebsocket(tx *dbs.Tx, webId int64, websocketJSON []byte) error {
|
2020-09-26 19:54:15 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.Websocket = JSONBytes(websocketJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-26 19:54:15 +08:00
|
|
|
|
}
|
2020-09-28 16:25:39 +08:00
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// 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 修改重写规则设置
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebRewriteRules(tx *dbs.Tx, webId int64, rewriteRulesJSON []byte) error {
|
2020-09-28 16:25:39 +08:00
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.RewriteRules = JSONBytes(rewriteRulesJSON)
|
2021-01-01 23:31:30 +08:00
|
|
|
|
err := this.Save(tx, op)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2020-09-28 16:25:39 +08:00
|
|
|
|
}
|
2020-10-02 17:22:32 +08:00
|
|
|
|
|
2021-06-17 21:17:53 +08:00
|
|
|
|
// UpdateWebAuth 修改认证信息
|
|
|
|
|
|
func (this *HTTPWebDAO) UpdateWebAuth(tx *dbs.Tx, webId int64, authJSON []byte) error {
|
|
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
op := NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.Auth = JSONBytes(authJSON)
|
|
|
|
|
|
err := this.Save(tx, op)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindAllWebIdsWithCachePolicyId 根据缓存策略ID查找所有的WebId
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindAllWebIdsWithCachePolicyId(tx *dbs.Tx, cachePolicyId int64) ([]int64, error) {
|
|
|
|
|
|
ones, err := this.Query(tx).
|
2020-10-02 17:22:32 +08:00
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
2021-01-17 16:48:00 +08:00
|
|
|
|
Where(`JSON_CONTAINS(cache, :jsonQuery, '$.cacheRefs')`).
|
|
|
|
|
|
Param("jsonQuery", maps.Map{"cachePolicyId": cachePolicyId}.AsJSON()).
|
2020-10-06 21:02:15 +08:00
|
|
|
|
FindAll()
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
result := []int64{}
|
|
|
|
|
|
for _, one := range ones {
|
|
|
|
|
|
webId := int64(one.(*HTTPWeb).Id)
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为Location
|
|
|
|
|
|
for {
|
2021-01-01 23:31:30 +08:00
|
|
|
|
locationId, err := SharedHTTPLocationDAO.FindEnabledLocationIdWithWebId(tx, webId)
|
2020-10-06 21:02:15 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果非Location
|
|
|
|
|
|
if locationId == 0 {
|
2020-10-20 20:18:06 +08:00
|
|
|
|
if !lists.ContainsInt64(result, webId) {
|
2020-10-06 21:02:15 +08:00
|
|
|
|
result = append(result, webId)
|
|
|
|
|
|
}
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 查找包含此Location的Web
|
|
|
|
|
|
// TODO 需要支持嵌套的Location查询
|
2021-01-01 23:31:30 +08:00
|
|
|
|
webId, err = this.FindEnabledWebIdWithLocationId(tx, locationId)
|
2020-10-06 21:02:15 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if webId == 0 {
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindAllWebIdsWithHTTPFirewallPolicyId 根据防火墙策略ID查找所有的WebId
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindAllWebIdsWithHTTPFirewallPolicyId(tx *dbs.Tx, firewallPolicyId int64) ([]int64, error) {
|
|
|
|
|
|
ones, err := this.Query(tx).
|
2020-10-06 21:02:15 +08:00
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
2021-01-17 16:48:00 +08:00
|
|
|
|
Where(`JSON_CONTAINS(firewall, :jsonQuery)`).
|
|
|
|
|
|
Param("jsonQuery", maps.Map{
|
|
|
|
|
|
// 这里不加入isOn的判断,无论是否开启我们都同步
|
|
|
|
|
|
"firewallPolicyId": firewallPolicyId,
|
|
|
|
|
|
}.AsJSON()).
|
2020-10-02 17:22:32 +08:00
|
|
|
|
FindAll()
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
result := []int64{}
|
|
|
|
|
|
for _, one := range ones {
|
|
|
|
|
|
webId := int64(one.(*HTTPWeb).Id)
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否为Location
|
|
|
|
|
|
for {
|
2021-01-01 23:31:30 +08:00
|
|
|
|
locationId, err := SharedHTTPLocationDAO.FindEnabledLocationIdWithWebId(tx, webId)
|
2020-10-02 17:22:32 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 如果非Location
|
|
|
|
|
|
if locationId == 0 {
|
2020-10-20 20:18:06 +08:00
|
|
|
|
if !lists.ContainsInt64(result, webId) {
|
2020-10-02 17:22:32 +08:00
|
|
|
|
result = append(result, webId)
|
|
|
|
|
|
}
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 查找包含此Location的Web
|
|
|
|
|
|
// TODO 需要支持嵌套的Location查询
|
2021-01-01 23:31:30 +08:00
|
|
|
|
webId, err = this.FindEnabledWebIdWithLocationId(tx, locationId)
|
2020-10-02 17:22:32 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if webId == 0 {
|
|
|
|
|
|
break
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return result, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindEnabledWebIdWithLocationId 查找包含某个Location的Web
|
2021-01-01 23:31:30 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindEnabledWebIdWithLocationId(tx *dbs.Tx, locationId int64) (webId int64, err error) {
|
|
|
|
|
|
return this.Query(tx).
|
2020-10-02 17:22:32 +08:00
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
2021-01-17 16:48:00 +08:00
|
|
|
|
Where("JSON_CONTAINS(locations, :jsonQuery)").
|
|
|
|
|
|
Param("jsonQuery", maps.Map{"locationId": locationId}.AsJSON()).
|
|
|
|
|
|
FindInt64Col(0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindEnabledWebIdWithRewriteRuleId 查找包含某个重写规则的Web
|
2021-01-17 16:48:00 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindEnabledWebIdWithRewriteRuleId(tx *dbs.Tx, rewriteRuleId int64) (webId int64, err error) {
|
|
|
|
|
|
return this.Query(tx).
|
|
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
|
|
|
|
|
Where("JSON_CONTAINS(rewriteRules, :jsonQuery)").
|
|
|
|
|
|
Param("jsonQuery", maps.Map{"rewriteRuleId": rewriteRuleId}.AsJSON()).
|
|
|
|
|
|
FindInt64Col(0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindEnabledWebIdWithPageId 查找包含某个页面的Web
|
2021-01-17 16:48:00 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindEnabledWebIdWithPageId(tx *dbs.Tx, pageId int64) (webId int64, err error) {
|
|
|
|
|
|
return this.Query(tx).
|
|
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
|
|
|
|
|
Where("JSON_CONTAINS(pages, :jsonQuery)").
|
|
|
|
|
|
Param("jsonQuery", maps.Map{"id": pageId}.AsJSON()).
|
|
|
|
|
|
FindInt64Col(0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindEnabledWebIdWithHeaderPolicyId 查找包含某个Header的Web
|
2021-01-17 16:48:00 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindEnabledWebIdWithHeaderPolicyId(tx *dbs.Tx, headerPolicyId int64) (webId int64, err error) {
|
|
|
|
|
|
return this.Query(tx).
|
|
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
|
|
|
|
|
Where("(JSON_CONTAINS(requestHeader, :jsonQuery) OR JSON_CONTAINS(responseHeader, :jsonQuery))").
|
|
|
|
|
|
Param("jsonQuery", maps.Map{"headerPolicyId": headerPolicyId}.AsJSON()).
|
|
|
|
|
|
FindInt64Col(0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindEnabledWebIdWithGzipId 查找包含某个Gzip配置的Web
|
2021-01-17 16:48:00 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindEnabledWebIdWithGzipId(tx *dbs.Tx, gzipId int64) (webId int64, err error) {
|
|
|
|
|
|
return this.Query(tx).
|
|
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
2021-09-29 19:32:25 +08:00
|
|
|
|
Where("JSON_CONTAINS(compression, :jsonQuery, '$.gzipRef')").
|
|
|
|
|
|
Param("jsonQuery", maps.Map{"id": gzipId}.AsJSON()).
|
|
|
|
|
|
FindInt64Col(0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FindEnabledWebIdWithBrotliPolicyId 查找包含某个Brotli配置的Web
|
|
|
|
|
|
func (this *HTTPWebDAO) FindEnabledWebIdWithBrotliPolicyId(tx *dbs.Tx, brotliPolicyId int64) (webId int64, err error) {
|
|
|
|
|
|
return this.Query(tx).
|
|
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
|
|
|
|
|
Where("JSON_CONTAINS(compression, :jsonQuery, '$.brotliRef')").
|
|
|
|
|
|
Param("jsonQuery", maps.Map{"id": brotliPolicyId}.AsJSON()).
|
|
|
|
|
|
FindInt64Col(0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// FindEnabledWebIdWithDeflatePolicyId 查找包含某个Deflate配置的Web
|
|
|
|
|
|
func (this *HTTPWebDAO) FindEnabledWebIdWithDeflatePolicyId(tx *dbs.Tx, deflatePolicyId int64) (webId int64, err error) {
|
|
|
|
|
|
return this.Query(tx).
|
|
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
|
|
|
|
|
Where("JSON_CONTAINS(compression, :jsonQuery, '$.deflateRef')").
|
|
|
|
|
|
Param("jsonQuery", maps.Map{"id": deflatePolicyId}.AsJSON()).
|
2020-10-02 17:22:32 +08:00
|
|
|
|
FindInt64Col(0)
|
2021-01-19 13:14:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindEnabledWebIdWithWebsocketId 查找包含某个Websocket配置的Web
|
2021-01-19 13:14:25 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindEnabledWebIdWithWebsocketId(tx *dbs.Tx, websocketId int64) (webId int64, err error) {
|
|
|
|
|
|
return this.Query(tx).
|
|
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
|
|
|
|
|
Where("JSON_CONTAINS(websocket, :jsonQuery)").
|
|
|
|
|
|
Param("jsonQuery", maps.Map{"websocketId": websocketId}.AsJSON()).
|
|
|
|
|
|
FindInt64Col(0)
|
2020-10-02 17:22:32 +08:00
|
|
|
|
}
|
2021-01-10 17:34:35 +08:00
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// 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)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-06-17 21:17:53 +08:00
|
|
|
|
// FindEnabledWebIdWithHTTPAuthPolicyId 查找包含某个认证策略的Web
|
|
|
|
|
|
func (this *HTTPWebDAO) FindEnabledWebIdWithHTTPAuthPolicyId(tx *dbs.Tx, httpAuthPolicyId int64) (webId int64, err error) {
|
|
|
|
|
|
return this.Query(tx).
|
|
|
|
|
|
State(HTTPWebStateEnabled).
|
|
|
|
|
|
ResultPk().
|
|
|
|
|
|
Where("JSON_CONTAINS(auth, :jsonQuery, '$.policyRefs')").
|
|
|
|
|
|
Param("jsonQuery", maps.Map{"authPolicyId": httpAuthPolicyId}.AsJSON()).
|
|
|
|
|
|
FindInt64Col(0)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindWebServerId 查找使用此Web的Server
|
2021-01-10 17:34:35 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindWebServerId(tx *dbs.Tx, webId int64) (serverId int64, err error) {
|
|
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return 0, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
serverId, err = SharedServerDAO.FindEnabledServerIdWithWebId(tx, webId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if serverId > 0 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// web在Location中的情况
|
|
|
|
|
|
locationId, err := SharedHTTPLocationDAO.FindEnabledLocationIdWithWebId(tx, webId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if locationId == 0 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
webId, err = this.FindEnabledWebIdWithLocationId(tx, locationId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 第二轮查找
|
|
|
|
|
|
return this.FindWebServerId(tx, webId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-10-07 16:47:21 +08:00
|
|
|
|
// FindWebServerGroupId 查找使用此Web的分组ID
|
|
|
|
|
|
func (this *HTTPWebDAO) FindWebServerGroupId(tx *dbs.Tx, webId int64) (groupId int64, err error) {
|
|
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return 0, nil
|
|
|
|
|
|
}
|
|
|
|
|
|
groupId, err = SharedServerGroupDAO.FindEnabledGroupIdWithWebId(tx, webId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if groupId > 0 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// web在Location中的情况
|
|
|
|
|
|
locationId, err := SharedHTTPLocationDAO.FindEnabledLocationIdWithWebId(tx, webId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return 0, err
|
|
|
|
|
|
}
|
|
|
|
|
|
if locationId == 0 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
webId, err = this.FindEnabledWebIdWithLocationId(tx, locationId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 第二轮查找
|
|
|
|
|
|
return this.FindWebServerGroupId(tx, webId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// CheckUserWeb 检查用户权限
|
2021-01-10 17:34:35 +08:00
|
|
|
|
func (this *HTTPWebDAO) CheckUserWeb(tx *dbs.Tx, userId int64, webId int64) error {
|
|
|
|
|
|
serverId, err := this.FindWebServerId(tx, webId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
if serverId == 0 {
|
|
|
|
|
|
return ErrNotFound
|
|
|
|
|
|
}
|
2021-01-17 16:48:00 +08:00
|
|
|
|
return SharedServerDAO.CheckUserServer(tx, userId, serverId)
|
2021-01-10 17:34:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// UpdateWebHostRedirects 设置主机跳转
|
2021-01-10 17:34:35 +08:00
|
|
|
|
func (this *HTTPWebDAO) UpdateWebHostRedirects(tx *dbs.Tx, webId int64, hostRedirects []*serverconfigs.HTTPHostRedirectConfig) error {
|
|
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid ")
|
|
|
|
|
|
}
|
|
|
|
|
|
if hostRedirects == nil {
|
|
|
|
|
|
hostRedirects = []*serverconfigs.HTTPHostRedirectConfig{}
|
|
|
|
|
|
}
|
|
|
|
|
|
hostRedirectsJSON, err := json.Marshal(hostRedirects)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
_, err = this.Query(tx).
|
|
|
|
|
|
Pk(webId).
|
|
|
|
|
|
Set("hostRedirects", hostRedirectsJSON).
|
|
|
|
|
|
Update()
|
2021-01-17 16:48:00 +08:00
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return this.NotifyUpdate(tx, webId)
|
2021-01-10 17:34:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-11-24 12:00:38 +08:00
|
|
|
|
// 通用设置
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// FindWebHostRedirects 查找主机跳转
|
2021-01-10 17:34:35 +08:00
|
|
|
|
func (this *HTTPWebDAO) FindWebHostRedirects(tx *dbs.Tx, webId int64) ([]byte, error) {
|
|
|
|
|
|
col, err := this.Query(tx).
|
|
|
|
|
|
Pk(webId).
|
|
|
|
|
|
Result("hostRedirects").
|
|
|
|
|
|
FindStringCol("")
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
}
|
|
|
|
|
|
return []byte(col), nil
|
|
|
|
|
|
}
|
2021-01-17 16:48:00 +08:00
|
|
|
|
|
2021-11-24 12:00:38 +08:00
|
|
|
|
// UpdateWebCommon 修改通用设置
|
|
|
|
|
|
func (this *HTTPWebDAO) UpdateWebCommon(tx *dbs.Tx, webId int64, mergeSlashes bool) error {
|
|
|
|
|
|
if webId <= 0 {
|
|
|
|
|
|
return errors.New("invalid webId")
|
|
|
|
|
|
}
|
|
|
|
|
|
var op = NewHTTPWebOperator()
|
|
|
|
|
|
op.Id = webId
|
|
|
|
|
|
op.MergeSlashes = mergeSlashes
|
|
|
|
|
|
return this.Save(tx, op)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-05-10 21:13:32 +08:00
|
|
|
|
// NotifyUpdate 通知更新
|
2021-01-17 16:48:00 +08:00
|
|
|
|
func (this *HTTPWebDAO) NotifyUpdate(tx *dbs.Tx, webId int64) error {
|
2021-10-07 16:47:21 +08:00
|
|
|
|
// server
|
2021-01-17 16:48:00 +08:00
|
|
|
|
serverId, err := this.FindWebServerId(tx, webId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
2021-10-07 16:47:21 +08:00
|
|
|
|
if serverId > 0 {
|
|
|
|
|
|
return SharedServerDAO.NotifyUpdate(tx, serverId)
|
2021-01-17 16:48:00 +08:00
|
|
|
|
}
|
2021-10-07 16:47:21 +08:00
|
|
|
|
|
|
|
|
|
|
// group
|
|
|
|
|
|
groupId, err := this.FindWebServerGroupId(tx, webId)
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
return err
|
|
|
|
|
|
}
|
|
|
|
|
|
if groupId > 0 {
|
|
|
|
|
|
return SharedServerGroupDAO.NotifyUpdate(tx, groupId)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
2021-01-17 16:48:00 +08:00
|
|
|
|
}
|