This commit is contained in:
Frank Denis 2021-03-30 11:02:47 +02:00
parent c748f93752
commit 3efbacc0d4
4 changed files with 28 additions and 28 deletions

View File

@ -558,9 +558,9 @@ func ConfigLoad(proxy *Proxy, flags *ConfigFlags) error {
if config.AllowedName.Format != "tsv" && config.AllowedName.Format != "ltsv" {
return errors.New("Unsupported allowed_names log format")
}
proxy.whitelistNameFile = config.AllowedName.File
proxy.whitelistNameFormat = config.AllowedName.Format
proxy.whitelistNameLogFile = config.AllowedName.LogFile
proxy.allowNameFile = config.AllowedName.File
proxy.allowNameFormat = config.AllowedName.Format
proxy.allowNameLogFile = config.AllowedName.LogFile
if len(config.BlockIP.File) > 0 && len(config.BlockIPLegacy.File) > 0 {
return errors.New("Don't specify both [blocked_ips] and [ip_blacklist] sections - Update your config file")

View File

@ -13,24 +13,24 @@ import (
"github.com/miekg/dns"
)
type PluginWhitelistName struct {
type PluginAllowName struct {
allWeeklyRanges *map[string]WeeklyRanges
patternMatcher *PatternMatcher
logger io.Writer
format string
}
func (plugin *PluginWhitelistName) Name() string {
return "whitelist_name"
func (plugin *PluginAllowName) Name() string {
return "allow_name"
}
func (plugin *PluginWhitelistName) Description() string {
return "Whitelists DNS queries matching name patterns"
func (plugin *PluginAllowName) Description() string {
return "Allow names matching patterns"
}
func (plugin *PluginWhitelistName) Init(proxy *Proxy) error {
dlog.Noticef("Loading the set of whitelisting rules from [%s]", proxy.whitelistNameFile)
bin, err := ReadTextFile(proxy.whitelistNameFile)
func (plugin *PluginAllowName) Init(proxy *Proxy) error {
dlog.Noticef("Loading the set of allowed names from [%s]", proxy.allowNameFile)
bin, err := ReadTextFile(proxy.allowNameFile)
if err != nil {
return err
}
@ -47,7 +47,7 @@ func (plugin *PluginWhitelistName) Init(proxy *Proxy) error {
line = strings.TrimFunc(parts[0], unicode.IsSpace)
timeRangeName = strings.TrimFunc(parts[1], unicode.IsSpace)
} else if len(parts) > 2 {
dlog.Errorf("Syntax error in whitelist rules at line %d -- Unexpected @ character", 1+lineNo)
dlog.Errorf("Syntax error in allowed names at line %d -- Unexpected @ character", 1+lineNo)
continue
}
var weeklyRanges *WeeklyRanges
@ -64,36 +64,36 @@ func (plugin *PluginWhitelistName) Init(proxy *Proxy) error {
continue
}
}
if len(proxy.whitelistNameLogFile) == 0 {
if len(proxy.allowNameLogFile) == 0 {
return nil
}
plugin.logger = Logger(proxy.logMaxSize, proxy.logMaxAge, proxy.logMaxBackups, proxy.whitelistNameLogFile)
plugin.format = proxy.whitelistNameFormat
plugin.logger = Logger(proxy.logMaxSize, proxy.logMaxAge, proxy.logMaxBackups, proxy.allowNameLogFile)
plugin.format = proxy.allowNameFormat
return nil
}
func (plugin *PluginWhitelistName) Drop() error {
func (plugin *PluginAllowName) Drop() error {
return nil
}
func (plugin *PluginWhitelistName) Reload() error {
func (plugin *PluginAllowName) Reload() error {
return nil
}
func (plugin *PluginWhitelistName) Eval(pluginsState *PluginsState, msg *dns.Msg) error {
func (plugin *PluginAllowName) Eval(pluginsState *PluginsState, msg *dns.Msg) error {
qName := pluginsState.qName
whitelist, reason, xweeklyRanges := plugin.patternMatcher.Eval(qName)
allowList, reason, xweeklyRanges := plugin.patternMatcher.Eval(qName)
var weeklyRanges *WeeklyRanges
if xweeklyRanges != nil {
weeklyRanges = xweeklyRanges.(*WeeklyRanges)
}
if whitelist {
if allowList {
if weeklyRanges != nil && !weeklyRanges.Match() {
whitelist = false
allowList = false
}
}
if whitelist {
if allowList {
pluginsState.sessionData["whitelisted"] = true
if plugin.logger != nil {
var clientIPStr string

View File

@ -101,8 +101,8 @@ func (proxy *Proxy) InitPluginsGlobals() error {
if len(proxy.queryMeta) != 0 {
*queryPlugins = append(*queryPlugins, Plugin(new(PluginQueryMeta)))
}
if len(proxy.whitelistNameFile) != 0 {
*queryPlugins = append(*queryPlugins, Plugin(new(PluginWhitelistName)))
if len(proxy.allowNameFile) != 0 {
*queryPlugins = append(*queryPlugins, Plugin(new(PluginAllowName)))
}
*queryPlugins = append(*queryPlugins, Plugin(new(PluginFirefox)))

View File

@ -56,16 +56,16 @@ type Proxy struct {
allowedIPLogFile string
queryLogFormat string
blockIPFile string
whitelistNameFormat string
whitelistNameLogFile string
allowNameFile string
allowNameFormat string
allowNameLogFile string
blockNameLogFile string
whitelistNameFile string
blockNameFormat string
blockNameFile string
queryLogFile string
blockedQueryResponse string
userName string
nxLogFile string
blockNameFormat string
proxySecretKey [32]byte
proxyPublicKey [32]byte
certRefreshDelayAfterFailure time.Duration