2023-05-15 21:15:29 -04:00
|
|
|
package limiter
|
|
|
|
|
|
|
|
import (
|
2023-05-21 22:36:10 -04:00
|
|
|
"regexp"
|
2023-07-20 09:14:18 -04:00
|
|
|
|
2023-07-29 07:27:15 -04:00
|
|
|
"github.com/InazumaV/V2bX/api/panel"
|
2023-05-15 21:15:29 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (l *Limiter) CheckDomainRule(destination string) (reject bool) {
|
|
|
|
// have rule
|
2023-07-20 09:14:18 -04:00
|
|
|
for i := range l.DomainRules {
|
|
|
|
if l.DomainRules[i].MatchString(destination) {
|
2023-05-15 21:15:29 -04:00
|
|
|
reject = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *Limiter) CheckProtocolRule(protocol string) (reject bool) {
|
|
|
|
for i := range l.ProtocolRules {
|
|
|
|
if l.ProtocolRules[i] == protocol {
|
|
|
|
reject = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-07-20 09:14:18 -04:00
|
|
|
func (l *Limiter) UpdateRule(rule *panel.Rules) error {
|
|
|
|
l.DomainRules = make([]*regexp.Regexp, len(rule.Regexp))
|
|
|
|
for i := range rule.Regexp {
|
|
|
|
l.DomainRules[i] = regexp.MustCompile(rule.Regexp[i])
|
2023-05-15 21:15:29 -04:00
|
|
|
}
|
2023-07-20 09:14:18 -04:00
|
|
|
l.ProtocolRules = rule.Protocol
|
2023-05-15 21:15:29 -04:00
|
|
|
return nil
|
|
|
|
}
|