Print an error if a block/allow rule contains more than a pattern

... and it is not a time range.
This commit is contained in:
Frank Denis 2021-05-12 17:43:13 +02:00
parent 31f4d7aa03
commit 6e8628f796
2 changed files with 15 additions and 7 deletions

View File

@ -43,10 +43,14 @@ func (plugin *PluginAllowName) Init(proxy *Proxy) error {
parts := strings.Split(line, "@")
timeRangeName := ""
if len(parts) == 2 {
line = strings.TrimSpace(parts[0])
timeRangeName = strings.TrimSpace(parts[1])
if timeRangeParts := strings.Split(parts[1], "@"); len(timeRangeParts) == 2 {
timeRangeName = strings.TrimSpace(timeRangeParts[1])
} else {
dlog.Errorf("Syntax error in allowed names at line %d", 1+lineNo)
continue
}
} else if len(parts) > 2 {
dlog.Errorf("Syntax error in allowed names at line %d -- Unexpected @ character", 1+lineNo)
dlog.Errorf("Syntax error in allowed names at line %d", 1+lineNo)
continue
}
var weeklyRanges *WeeklyRanges

View File

@ -97,13 +97,17 @@ func (plugin *PluginBlockName) Init(proxy *Proxy) error {
if len(line) == 0 {
continue
}
parts := strings.Split(line, "@")
parts := strings.Fields(line)
timeRangeName := ""
if len(parts) == 2 {
line = strings.TrimSpace(parts[0])
timeRangeName = strings.TrimSpace(parts[1])
if timeRangeParts := strings.Split(parts[1], "@"); len(timeRangeParts) == 2 {
timeRangeName = strings.TrimSpace(timeRangeParts[1])
} else {
dlog.Errorf("Syntax error in block rules at line %d", 1+lineNo)
continue
}
} else if len(parts) > 2 {
dlog.Errorf("Syntax error in block rules at line %d -- Unexpected @ character", 1+lineNo)
dlog.Errorf("Syntax error in block rules at line %d", 1+lineNo)
continue
}
var weeklyRanges *WeeklyRanges