From f1545b2afd0b014f4fef5cf07a99f07029d5dc00 Mon Sep 17 00:00:00 2001 From: Andrey Lutsenko Date: Thu, 9 Apr 2026 22:07:15 +1000 Subject: [PATCH] Add minimal topology web UI and serve static files. Provide browser-based topology viewer at root path and update technical spec checkboxes for completed UI milestone. Made-with: Cursor --- README.md | 7 +++ TECH_SPEC.md | 4 +- internal/api/handler.go | 7 ++- web/index.html | 125 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 3 deletions(-) create mode 100644 web/index.html diff --git a/README.md b/README.md index c004fab..ce291f9 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,7 @@ - `GET /api/scans/{id}/lldp` - LLDP соседи (если устройство отдает LLDP-MIB по SNMP). - `GET /api/scans/{id}/links` - базовые связи из LLDP с попыткой сопоставления по `remote_sys_name`. - `GET /api/scans/{id}/topology` - граф `nodes/edges` для визуализации. +- `GET /` - простая UI-страница для просмотра топологии. - Валидация CIDR и exclude IP. - Два backend-хранилища: in-memory и PostgreSQL. - После создания scan запускается фоновый discovery с обновлением статуса и прогресса. @@ -49,6 +50,12 @@ cp .env.example .env HTTP_ADDR=:8080 go run ./cmd/server ``` +UI открывается по адресу: + +```bash +http://localhost:8080/ +``` + По умолчанию используется `STORE_BACKEND=memory`. SNMP-проверка по умолчанию включена (`SNMP_ENABLED=true`, community `public`). diff --git a/TECH_SPEC.md b/TECH_SPEC.md index bad3ce6..e40b391 100644 --- a/TECH_SPEC.md +++ b/TECH_SPEC.md @@ -85,7 +85,7 @@ 2. [x] PostgreSQL и миграции 3. [x] Ping + port scan 4. [x] SNMP system + LLDP -5. [ ] Граф топологии в UI +5. [x] Граф топологии в UI (минимальная web-страница `/`) 6. [x] История и diff ## Критерии приемки v1 @@ -94,5 +94,5 @@ - [x] живые узлы фиксируются в результатах; - [x] SNMP-доступные устройства читаются; - [x] LLDP-связи строятся минимум на тестовой сети; -- [ ] топология отображается в интерфейсе; +- [x] топология отображается в интерфейсе; - [ ] приложение запускается на Linux и Windows (нужна ваша проверка на 2 ОС). diff --git a/internal/api/handler.go b/internal/api/handler.go index 9b6d101..106e9dc 100644 --- a/internal/api/handler.go +++ b/internal/api/handler.go @@ -54,6 +54,9 @@ func NewHandler(store scans.Store, run *scans.Runner) *Handler { func (h *Handler) Routes() http.Handler { mux := http.NewServeMux() + webFS := http.FileServer(http.Dir("web")) + mux.Handle("GET /", webFS) + mux.Handle("GET /web/", http.StripPrefix("/web/", webFS)) mux.HandleFunc("GET /health", h.health) mux.HandleFunc("POST /api/scans", h.createScan) mux.HandleFunc("GET /api/scans", h.listScans) @@ -411,7 +414,9 @@ func (h *Handler) getScanTopology(w http.ResponseWriter, r *http.Request) { func withJSON(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "application/json; charset=utf-8") + if strings.HasPrefix(r.URL.Path, "/api/") || r.URL.Path == "/health" { + w.Header().Set("Content-Type", "application/json; charset=utf-8") + } next.ServeHTTP(w, r) }) } diff --git a/web/index.html b/web/index.html new file mode 100644 index 0000000..0ba1f83 --- /dev/null +++ b/web/index.html @@ -0,0 +1,125 @@ + + + + + + NetTopo UI + + + +

NetTopo: просмотр топологии

+
Введите `scan_id`, нажмите "Загрузить", и страница покажет граф nodes/edges.
+
+ + + +
+
Ожидание данных...
+ + + + +