update go packages version, add ip proxy and real ip headers to config.
This commit is contained in:
@@ -52,6 +52,10 @@ type Config struct {
|
||||
FailuresWindowMinutes int
|
||||
AutoBanDurationHours int
|
||||
AutoBanPermanent bool
|
||||
|
||||
// Proxy settings
|
||||
TrustedProxies []string
|
||||
RealIPHeaders []string
|
||||
}
|
||||
|
||||
var defaultConfig = map[string]map[string]string{
|
||||
@@ -96,6 +100,10 @@ var defaultConfig = map[string]map[string]string{
|
||||
"AUTO_BAN_DURATION_HOURS": "12",
|
||||
"AUTO_BAN_PERMANENT": "false",
|
||||
},
|
||||
"PROXY": {
|
||||
"TRUSTED_PROXIES": "127.0.0.1, ::1",
|
||||
"REAL_IP_HEADERS": "CF-Connecting-IP, X-Forwarded-For, X-Real-IP",
|
||||
},
|
||||
}
|
||||
|
||||
// exeDir returns the directory containing the running executable.
|
||||
@@ -220,6 +228,11 @@ func Load() (*Config, error) {
|
||||
config.AutoBanDurationHours, _ = secSection.Key("AUTO_BAN_DURATION_HOURS").Int()
|
||||
config.AutoBanPermanent, _ = secSection.Key("AUTO_BAN_PERMANENT").Bool()
|
||||
|
||||
// Load PROXY section
|
||||
proxySection := cfg.Section("PROXY")
|
||||
config.TrustedProxies = parseCommaSeparated(proxySection.Key("TRUSTED_PROXIES").String())
|
||||
config.RealIPHeaders = parseCommaSeparated(proxySection.Key("REAL_IP_HEADERS").String())
|
||||
|
||||
return config, nil
|
||||
}
|
||||
|
||||
@@ -404,6 +417,13 @@ func (c *Config) SaveSetting(section, key, value string) error {
|
||||
case "AUTO_BAN_PERMANENT":
|
||||
c.AutoBanPermanent = value == "true"
|
||||
}
|
||||
case "PROXY":
|
||||
switch key {
|
||||
case "TRUSTED_PROXIES":
|
||||
c.TrustedProxies = parseCommaSeparated(value)
|
||||
case "REAL_IP_HEADERS":
|
||||
c.RealIPHeaders = parseCommaSeparated(value)
|
||||
}
|
||||
}
|
||||
|
||||
return cfg.SaveTo(configPath)
|
||||
|
||||
Reference in New Issue
Block a user