geoip and config editor online

This commit is contained in:
2026-05-17 15:38:10 +00:00
parent d4ce217dc9
commit 0a38298fa6
26 changed files with 1645 additions and 31 deletions
+27
View File
@@ -31,10 +31,16 @@ type Config struct {
CrowdSecAPILogin string
CrowdSecAPIPassword string // sent as-is to LAPI — never hashed
CscliPath string
CrowdsecBinPath string // crowdsec daemon binary (for -t config test)
CrowdsecConfigDir string // /etc/crowdsec or equivalent
UIUsername string
UIPassword string // bcrypt hash after first run
UISessionSecret string
PollIntervalSec int
IPInfoToken string // ipinfo.io API token for GeoIP DB download
IPInfoDBFile string // e.g. "asn.mmdb" or "country.mmdb"
IPInfoDBPath string // absolute path where the MMDB is saved
IPInfoRefreshDays int // auto-refresh interval in days
}
// FirstRunError is returned when the config file was just created and needs editing.
@@ -96,7 +102,13 @@ func Load() (*Config, error) {
CrowdSecAPILogin: vals["crowdsec_api_login"],
CrowdSecAPIPassword: vals["crowdsec_api_password"],
CscliPath: strVal(vals, "cscli_path", "/usr/local/bin/cscli"),
CrowdsecBinPath: strVal(vals, "crowdsec_path", "/usr/sbin/crowdsec"),
CrowdsecConfigDir: strVal(vals, "crowdsec_config_dir", "/etc/crowdsec"),
UIUsername: strVal(vals, "ui_username", "admin"),
IPInfoToken: vals["ipinfo_token"],
IPInfoDBFile: strVal(vals, "ipinfo_db_file", "asn.mmdb"),
IPInfoDBPath: strVal(vals, "ipinfo_db_path", "/var/lib/crowdsec/data/GeoLite2-ASN.mmdb"),
IPInfoRefreshDays: intVal(vals, "ipinfo_refresh_days", 7),
UIPassword: strVal(vals, "ui_password", "changeme"),
UISessionSecret: vals["ui_session_secret"],
PollIntervalSec: intVal(vals, "poll_interval_sec", 15),
@@ -197,6 +209,13 @@ crowdsec_api_password =
# Leave empty or point to a missing path to disable CLI features gracefully.
cscli_path = /usr/local/bin/cscli
# CrowdSec daemon binary — used to test configs before applying (crowdsec -t)
# Leave empty to disable config validation (saves will apply without testing).
crowdsec_path = /usr/sbin/crowdsec
# CrowdSec config directory — files editable via the Config Editor page
crowdsec_config_dir = /etc/crowdsec
# Web UI — HTTP Basic Auth
# ui_password is auto-hashed with bcrypt on first startup.
# To pre-hash a password: crowdsec-dashy -pwhash "your-password"
@@ -208,6 +227,14 @@ ui_session_secret = %s
# Dashboard live-poll interval (seconds)
poll_interval_sec = 15
# IPInfo.io GeoIP database auto-refresh
# Get a free token at https://ipinfo.io/signup
# Available free DB files: asn.mmdb, country.mmdb, country_asn.mmdb
ipinfo_token =
ipinfo_db_file = asn.mmdb
ipinfo_db_path = /var/lib/crowdsec/data/GeoLite2-ASN.mmdb
ipinfo_refresh_days = 7
`, secret)
return os.WriteFile(path, []byte(content), 0600)