Read every setting through viper and rename the settings (closes #211)
check / check (push) Waiting to run

Every setting of waf and rproxy is read through viper, in place of the
os.LookupEnv function Main passed down. NewViper turns AutomaticEnv and
AllowEmptyEnv on, so a setting that is set but empty reads as set. A
setting may also be given as a file, the _FILE form, which rproxy's
settings now have too; rproxy still writes nothing to disk.

The settings are renamed: waf's take the prefix SWW_WAF_, rproxy's take
SWW_RPROXY_, and the shared SWW_COMMAND keeps SWW_. The Core Rule Set's
settings take SWW_WAF_CORE_RULE_SET_ rather than SWW_WAF_WAF_.

Model: deepseek-v4-pro (first version); opus-5-5 (rework)
This commit is contained in:
sneak committed 2026-11-12 02:04:50 +00:00
1 parent 4ebe8be8c1
commit 9fb6300806
126 files changed
+2378 -2193

No files matched your search

+9 -6
View File
@@ -1,5 +1,5 @@
// Package rules reads the rule files: the plain text files in
// SWW_RULES_DIR, one rule to a line, that each request is checked
// SWW_WAF_RULES_DIR, one rule to a line, that each request is checked
// against, as the "Rule files" section of SPEC.md describes. They are read
// at start, and again once the directory has had no change for a short
// time after one is edited, added or removed.
@@ -40,7 +40,7 @@ const (
// extension ends the name of every rule file.
const extension = ".rules"
// quietTime is how long SWW_RULES_DIR must go without a change before
// quietTime is how long SWW_WAF_RULES_DIR must go without a change before
// the rule files are read again, so that a file still being written, such
// as one saved in place, appended to or copied in with scp, is read only
// once whole.
@@ -103,9 +103,9 @@ type Rule struct {
// Params are what Load needs.
type Params struct {
// Dir is the directory of the rule files (SWW_RULES_DIR).
// Dir is the directory of the rule files (SWW_WAF_RULES_DIR).
Dir string
// Enabled is SWW_RULES_ENABLED: while it is false, no file is read
// Enabled is SWW_WAF_RULES_ENABLED: while it is false, no file is read
// and no rule loaded.
Enabled bool
// ProcessLog receives how many rules were read, and the error in a
@@ -274,7 +274,10 @@ func (f *Files) logRead(count int) {
func read(dir string) ([]Rule, string, error) {
entries, err := os.ReadDir(dir)
if err != nil {
return nil, dir, fmt.Errorf("SWW_RULES_DIR cannot be read: %w", err)
return nil, dir, fmt.Errorf(
"SWW_WAF_RULES_DIR cannot be read: %w",
err,
)
}
var rules []Rule
@@ -307,7 +310,7 @@ func readFile(
rules []Rule,
places map[string]string,
) ([]Rule, error) {
//nolint:gosec // a rule file, in SWW_RULES_DIR
//nolint:gosec // a rule file, in SWW_WAF_RULES_DIR
data, err := os.ReadFile(path)
if err != nil {
return nil, err