mirror of
https://github.com/TeaOSLab/EdgeCommon.git
synced 2026-04-24 23:05:17 +08:00
5秒盾支持例外URL和限制URL
This commit is contained in:
@@ -2,12 +2,55 @@
|
||||
|
||||
package serverconfigs
|
||||
|
||||
import "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared"
|
||||
|
||||
// UAMConfig UAM配置
|
||||
type UAMConfig struct {
|
||||
IsPrior bool `yaml:"isPrior" json:"isPrior"`
|
||||
IsOn bool `yaml:"isOn" json:"isOn"`
|
||||
|
||||
OnlyURLPatterns []*shared.URLPattern `yaml:"onlyURLPatterns" json:"onlyURLPatterns"` // 仅限的URL
|
||||
ExceptURLPatterns []*shared.URLPattern `yaml:"exceptURLPatterns" json:"exceptURLPatterns"` // 排除的URL
|
||||
}
|
||||
|
||||
func (this *UAMConfig) Init() error {
|
||||
// only urls
|
||||
for _, pattern := range this.OnlyURLPatterns {
|
||||
err := pattern.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// except urls
|
||||
for _, pattern := range this.ExceptURLPatterns {
|
||||
err := pattern.Init()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *UAMConfig) MatchURL(url string) bool {
|
||||
// except
|
||||
if len(this.ExceptURLPatterns) > 0 {
|
||||
for _, pattern := range this.ExceptURLPatterns {
|
||||
if pattern.Match(url) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if len(this.OnlyURLPatterns) > 0 {
|
||||
for _, pattern := range this.OnlyURLPatterns {
|
||||
if pattern.Match(url) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user