geoip and config editor online

This commit is contained in:
2026-05-17 15:38:10 +00:00
parent f4a88035ee
commit 1293bafffa
25 changed files with 1645 additions and 31 deletions
+31 -6
View File
@@ -6,23 +6,26 @@ import (
"crowdsec-dashy/internal/config"
"crowdsec-dashy/internal/crowdsec"
"crowdsec-dashy/internal/geoip"
"crowdsec-dashy/internal/handlers"
"crowdsec-dashy/internal/middleware"
)
// New constructs the full HTTP handler: renderer, deps, routes, and middleware chain.
func New(cfg *config.Config, lapi *crowdsec.LAPIClient, webFS fs.FS) (http.Handler, error) {
func New(cfg *config.Config, lapi *crowdsec.LAPIClient, webFS fs.FS, geoUpdater *geoip.Updater) (http.Handler, error) {
renderer, err := handlers.NewRenderer(webFS)
if err != nil {
return nil, err
}
deps := handlers.Deps{
Renderer: renderer,
LAPI: lapi,
CLI: crowdsec.NewCLIClient(cfg.CscliPath),
CLIAvailable: cfg.CscliAvailable(),
PollInterval: cfg.PollIntervalSec,
Renderer: renderer,
LAPI: lapi,
CLI: crowdsec.NewCLIClient(cfg.CscliPath),
CLIAvailable: cfg.CscliAvailable(),
PollInterval: cfg.PollIntervalSec,
CrowdsecBinPath: cfg.CrowdsecBinPath,
CrowdsecConfigDir: cfg.CrowdsecConfigDir,
}
mux := http.NewServeMux()
@@ -78,6 +81,28 @@ func New(cfg *config.Config, lapi *crowdsec.LAPIClient, webFS fs.FS) (http.Handl
met := handlers.NewMetricsHandler(deps)
mux.HandleFunc("GET /metrics-ui", met.ServeHTTP)
// Countries
ctr := handlers.NewCountriesHandler(deps)
mux.HandleFunc("GET /countries", ctr.List)
mux.HandleFunc("POST /countries/add", ctr.Add)
mux.HandleFunc("POST /countries/delete", ctr.Delete)
// Allowlist
alw := handlers.NewAllowlistHandler(deps)
mux.HandleFunc("GET /allowlist", alw.List)
mux.HandleFunc("POST /allowlist/add", alw.AddEntry)
mux.HandleFunc("POST /allowlist/remove", alw.RemoveEntry)
// Config Editor
ced := handlers.NewConfigEditorHandler(deps)
mux.HandleFunc("GET /config-editor", ced.List)
mux.HandleFunc("POST /config-editor/save", ced.Save)
// GeoIP
geo := handlers.NewGeoIPHandler(deps, geoUpdater)
mux.HandleFunc("GET /geoip", geo.ServeHTTP)
mux.HandleFunc("POST /geoip/refresh", geo.Refresh)
// Internal JSON API
api := handlers.NewAPIHandler(deps)
mux.HandleFunc("GET /api/v1/stats", api.Stats)