This commit is contained in:
Frank Denis 2018-01-31 22:49:40 +01:00
parent d575ec8beb
commit ba2293149e
3 changed files with 53 additions and 39 deletions

View File

@ -26,26 +26,26 @@ type Config struct {
CertIgnoreTimestamp bool `toml:"cert_ignore_timestamp"` CertIgnoreTimestamp bool `toml:"cert_ignore_timestamp"`
BlockIPv6 bool `toml:"block_ipv6"` BlockIPv6 bool `toml:"block_ipv6"`
Cache bool Cache bool
CacheSize int `toml:"cache_size"` CacheSize int `toml:"cache_size"`
CacheNegTTL uint32 `toml:"cache_neg_ttl"` CacheNegTTL uint32 `toml:"cache_neg_ttl"`
CacheMinTTL uint32 `toml:"cache_min_ttl"` CacheMinTTL uint32 `toml:"cache_min_ttl"`
CacheMaxTTL uint32 `toml:"cache_max_ttl"` CacheMaxTTL uint32 `toml:"cache_max_ttl"`
QueryLog QueryLogConfig `toml:"query_log"` QueryLog QueryLogConfig `toml:"query_log"`
NxLog NxLogConfig `toml:"nx_log"` NxLog NxLogConfig `toml:"nx_log"`
BlockName BlockNameConfig `toml:"blacklist"` BlockName BlockNameConfig `toml:"blacklist"`
BlockIP BlockIPConfig `toml:"ip_blacklist"` BlockIP BlockIPConfig `toml:"ip_blacklist"`
ForwardFile string `toml:"forwarding_rules"` ForwardFile string `toml:"forwarding_rules"`
ServersConfig map[string]StaticConfig `toml:"static"` ServersConfig map[string]StaticConfig `toml:"static"`
SourcesConfig map[string]SourceConfig `toml:"sources"` SourcesConfig map[string]SourceConfig `toml:"sources"`
SourceRequireDNSSEC bool `toml:"require_dnssec"` SourceRequireDNSSEC bool `toml:"require_dnssec"`
SourceRequireNoLog bool `toml:"require_nolog"` SourceRequireNoLog bool `toml:"require_nolog"`
SourceRequireNoFilter bool `toml:"require_nofilter"` SourceRequireNoFilter bool `toml:"require_nofilter"`
SourceIPv4 bool `toml:"ipv4_servers"` SourceIPv4 bool `toml:"ipv4_servers"`
SourceIPv6 bool `toml:"ipv6_servers"` SourceIPv6 bool `toml:"ipv6_servers"`
MaxClients uint32 `toml:"max_clients"` MaxClients uint32 `toml:"max_clients"`
FallbackResolver string `toml:"fallback_resolver"` FallbackResolver string `toml:"fallback_resolver"`
IgnoreSystemDNS bool `toml:"ignore_system_dns"` IgnoreSystemDNS bool `toml:"ignore_system_dns"`
TimeRanges map[string][]TimeRangeStr `toml:"time_ranges"` AllWeeklyRanges map[string]WeeklyRangesStr `toml:"time_ranges"`
} }
func newConfig() Config { func newConfig() Config {
@ -222,7 +222,9 @@ func ConfigLoad(proxy *Proxy, svcFlag *string) error {
proxy.forwardFile = config.ForwardFile proxy.forwardFile = config.ForwardFile
parseWeeklyRanges(config.TimeRanges) if err := parseAllWeeklyRanges(config.AllWeeklyRanges); err != nil {
return err
}
if err := config.loadSources(proxy); err != nil { if err := config.loadSources(proxy); err != nil {
return err return err

View File

@ -320,12 +320,11 @@ format = 'tsv'
[time_ranges] [time_ranges]
[time_ranges.'time-to-sleep'] [time_ranges.'timetosleep']
mon = [{after="22:00", before="07:00"}] mon = [{after="22:00", before="07:00"}]
# mon = [{after="22:00", before="07:00"}] tue = [{after="22:00", before="07:00"}]
# tue = [{after="22:00", before="07:00"}] wed = [{after="22:00", before="07:00"}]
# wed = [{after="22:00", before="07:00"}] thu = [{after="22:00", before="07:00"}]
# thu = [{after="22:00", before="07:00"}] fri = [{after="22:00", before="07:00"}]
# fri = [{after="22:00", before="07:00"}] sat = [{after="22:00", before="07:00"}]
# sat = [{after="22:00", before="07:00"}] sun = [{after="22:00", before="07:00"}]
# sun = [{after="26:00", before="07:00"}]

View File

@ -40,8 +40,8 @@ type PluginBlockName struct {
} }
type TimeRange struct { type TimeRange struct {
start int after int
end int before int
} }
type WeeklyRanges struct { type WeeklyRanges struct {
@ -53,6 +53,10 @@ type TimeRangeStr struct {
Before string Before string
} }
type WeeklyRangesStr struct {
Sun, Mon, Tue, Wed, Thu, Fri, Sat []TimeRangeStr
}
func daySecsFromStr(str string) (int, error) { func daySecsFromStr(str string) (int, error) {
parts := strings.Split(str, ":") parts := strings.Split(str, ":")
if len(parts) != 2 { if len(parts) != 2 {
@ -83,19 +87,16 @@ func parseTimeRanges(timeRangesStr []TimeRangeStr) ([]TimeRange, error) {
if after == before { if after == before {
after, before = -1, 86402 after, before = -1, 86402
} }
timeRanges = append(timeRanges, TimeRange{after: after, before: before})
} }
return timeRanges, nil return timeRanges, nil
} }
func parseWeeklyRanges(weeklyRangeStr map[string][]TimeRangeStr) (WeeklyRanges, error) { func parseWeeklyRanges(weeklyRangesStr WeeklyRangesStr) (WeeklyRanges, error) {
weeklyRanges := WeeklyRanges{} weeklyRanges := WeeklyRanges{}
daysStr := []string{"sun", "mon", "tue", "wed", "thu", "fri", "sat"} weeklyRangesStrX := [7][]TimeRangeStr{weeklyRangesStr.Sun, weeklyRangesStr.Mon, weeklyRangesStr.Tue, weeklyRangesStr.Wed, weeklyRangesStr.Thu, weeklyRangesStr.Fri, weeklyRangesStr.Sat}
for day, dayStr := range daysStr { for day, weeklyRangeStrX := range weeklyRangesStrX {
timeRangesStr, ok := weeklyRangeStr[dayStr] timeRanges, err := parseTimeRanges(weeklyRangeStrX)
if !ok {
continue
}
timeRanges, err := parseTimeRanges(timeRangesStr)
if err != nil { if err != nil {
return weeklyRanges, err return weeklyRanges, err
} }
@ -104,6 +105,18 @@ func parseWeeklyRanges(weeklyRangeStr map[string][]TimeRangeStr) (WeeklyRanges,
return weeklyRanges, nil return weeklyRanges, nil
} }
func parseAllWeeklyRanges(allWeeklyRangesStr map[string]WeeklyRangesStr) error {
allWeeklyRanges := make(map[string]WeeklyRanges)
for weeklyRangesName, weeklyRangesStr := range allWeeklyRangesStr {
weeklyRanges, err := parseWeeklyRanges(weeklyRangesStr)
if err != nil {
return err
}
allWeeklyRanges[weeklyRangesName] = weeklyRanges
}
return nil
}
func (plugin *PluginBlockName) Name() string { func (plugin *PluginBlockName) Name() string {
return "block_name" return "block_name"
} }