// Package web implements the KeyHunter embedded web dashboard and REST API. package web import ( "html/template" "net/http" "github.com/go-chi/chi/v5" "github.com/salvacybersec/keyhunter/pkg/dorks" "github.com/salvacybersec/keyhunter/pkg/engine" "github.com/salvacybersec/keyhunter/pkg/providers" "github.com/salvacybersec/keyhunter/pkg/recon" "github.com/salvacybersec/keyhunter/pkg/storage" ) // ServerConfig holds all dependencies injected into the web Server. type ServerConfig struct { DB *storage.DB EncKey []byte Providers *providers.Registry Dorks *dorks.Registry ScanEngine *engine.Engine ReconEngine *recon.Engine } // Server is the central HTTP server holding all handler dependencies. type Server struct { cfg ServerConfig sse *SSEHub tmpl *template.Template } // NewServer creates a Server with the given configuration. func NewServer(cfg ServerConfig) *Server { tmpl, _ := template.ParseFS(templateFiles, "templates/*.html") return &Server{ cfg: cfg, sse: NewSSEHub(), tmpl: tmpl, } } // Mount registers all web dashboard routes on the given chi router. func (s *Server) Mount(r chi.Router) { // Static assets. r.Handle("/static/*", http.StripPrefix("/static/", http.FileServer(http.FS(staticFiles)))) // HTML pages. r.Get("/", s.handleOverview) // REST API (routes defined in api.go). s.mountAPI(r) // SSE progress endpoints. r.Get("/events/scan", s.handleSSEScanProgress) r.Get("/events/recon", s.handleSSEReconProgress) }