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

View File

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

View File

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