feat: 1.1.0 interface, geography drill-down and live attack map
Release / Plan (reuse the published image?) (push) Successful in 4s
CI / Docker image (build and smoke test) (push) Skipped
CI / Format and vet (push) Successful in 19s
CI / Tests (Linux, race detector) (push) Successful in 35s
CI / Dependency audit (push) Successful in 16s
Release / ci (push) Successful in 35s
Release / Build image (arm64) (push) Successful in 51s
Release / Build image (amd64) (push) Successful in 1m11s
Release / Publish tags (push) Successful in 13s
Release / Gitea release (push) Skipped

A new console interface (side rail, seven pages, opening sentence and
active slice on every page, IP drawer, light and dark design tokens);
a Geography page that drills from the world to a country's regions and
cities; a Live page drawing attacks as arcs on a flat map or a globe.

Backend: GET /api/v1/geo, GET /api/v1/live/recent, host/src/dst on live
events, --location, a strict static file pattern, and live federation
through GET /api/v1/peer/stream (peer token only, bounded and sanitized
relay on the hub).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas RayanandClaude Opus 5.5 committed 2026-11-14 17:47:28 -03:00
1 parent ff143ec4a2
commit f4b295f582
37 files changed
+5312 -1000

No files matched your search

+278
View File
@@ -0,0 +1,278 @@
package server
import (
"net/http"
"regexp"
"sort"
"strings"
"sync"
"time"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
)
const (
geoCountries = 250
geoRegions = 64
geoCities = 200
geoIPs = 50
geoTTL = 5 * time.Second
geoCacheMax = 256
)
var ccRe = regexp.MustCompile(`^[A-Z]{2}$`)
type geoCache struct {
mu sync.Mutex
at map[string]time.Time
v map[string]any
}
type regionOut struct {
Name string `json:"name"`
Events uint64 `json:"events"`
IPs int `json:"ips"`
Cats map[string]int `json:"cats"`
}
type cityOut struct {
Name string `json:"name"`
Region string `json:"region"`
Lat *float64 `json:"lat,omitempty"`
Lon *float64 `json:"lon,omitempty"`
Events uint64 `json:"events"`
IPs int `json:"ips"`
}
type geoIPOut struct {
IP string `json:"ip"`
Score float64 `json:"score"`
Level string `json:"level"`
City string `json:"city"`
Reg string `json:"region"`
ASN uint32 `json:"asn"`
ASOrg string `json:"as_org"`
Last int64 `json:"last"`
}
type countryOut struct {
CC string `json:"cc"`
Events uint64 `json:"events"`
IPs int `json:"ips"`
Hostile int `json:"hostile"`
Suspicious int `json:"suspicious"`
Cats map[string]int `json:"cats"`
}
type agg struct {
events uint64
ips int
hostile, suspic int
cats map[string]int
}
func (a *agg) add(x store.IPSummary, ev uint64, cats map[string]int) {
if a.cats == nil {
a.cats = map[string]int{}
}
a.events += ev
a.ips++
switch x.Level {
case core.LevelHostile:
a.hostile++
case core.LevelSuspicious:
a.suspic++
}
for k, v := range cats {
a.cats[k] += v
}
}
// attackerEvents sums the malicious category counts of an IP row.
func attackerEvents(x store.IPSummary) (uint64, map[string]int) {
var n uint64
cats := map[string]int{}
for _, c := range core.Categories {
if !c.IsMalicious() {
continue
}
if v := x.Counts[string(c)]; v > 0 {
n += uint64(v)
cats[string(c)] = int(v)
}
}
return n, cats
}
// geoAPI serves GET /api/v1/geo (see the package documentation of the routes).
func (s *Server) geoAPI(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
rg := store.ParseRange(q.Get("range")).Name
host := q.Get("host")
if host == "" {
host = "all"
}
if host != "all" && host != s.opt.Store.Name() && (s.opt.Hub == nil || !s.opt.Hub.Has(host)) {
writeJSON(w, http.StatusNotFound, map[string]string{"error": "unknown host"})
return
}
cc, region := q.Get("cc"), q.Get("region")
if cc != "" && !ccRe.MatchString(cc) {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid cc"})
return
}
if region != "" && (cc == "" || len(region) > 80) {
writeJSON(w, http.StatusBadRequest, map[string]string{"error": "invalid region"})
return
}
key := strings.Join([]string{rg, host, cc, region}, "\x00")
s.geo.mu.Lock()
defer s.geo.mu.Unlock()
if v, ok := s.geo.v[key]; ok && time.Since(s.geo.at[key]) < geoTTL {
writeJSON(w, 200, v)
return
}
if s.geo.v == nil || len(s.geo.v) >= geoCacheMax {
s.geo.v, s.geo.at = map[string]any{}, map[string]time.Time{}
}
var out any
if cc == "" {
out = s.geoWorld(rg, host)
} else {
out = s.geoCountry(rg, host, cc, region)
}
s.geo.v[key], s.geo.at[key] = out, time.Now()
writeJSON(w, 200, out)
}
// geoOf resolves the geography of a row: the local databases first, the data
// the row already carries (a peer's) as the fallback for country and city.
func (s *Server) geoOf(x store.IPSummary) core.GeoInfo {
g := s.opt.Store.GeoOf(x.IP)
if g.CC == "" && ccRe.MatchString(x.CC) {
g.CC, g.Country, g.City = x.CC, x.Country, x.City
}
return g
}
func (s *Server) geoWorld(rg, host string) map[string]any {
by := map[string]*agg{}
for _, x := range s.allIPs(rg, host) {
ev, cats := attackerEvents(x)
if ev == 0 {
continue
}
g := s.geoOf(x)
if g.CC == "" {
continue
}
a := by[g.CC]
if a == nil {
a = &agg{}
by[g.CC] = a
}
a.add(x, ev, cats)
}
list := make([]countryOut, 0, len(by))
for cc, a := range by {
list = append(list, countryOut{cc, a.events, a.ips, a.hostile, a.suspic, a.cats})
}
sort.Slice(list, func(i, j int) bool {
if list[i].Events != list[j].Events {
return list[i].Events > list[j].Events
}
return list[i].CC < list[j].CC
})
if len(list) > geoCountries {
list = list[:geoCountries]
}
return map[string]any{"range": rg, "host": host, "countries": list}
}
func (s *Server) geoCountry(rg, host, cc, region string) map[string]any {
total := &agg{}
regs := map[string]*agg{}
type ck struct{ name, region string }
cities := map[ck]*cityOut{}
var rows []geoIPOut
for _, x := range s.allIPs(rg, host) {
ev, cats := attackerEvents(x)
if ev == 0 {
continue
}
g := s.geoOf(x)
if g.CC != cc {
continue
}
ra := regs[g.Region]
if ra == nil {
ra = &agg{}
regs[g.Region] = ra
}
ra.add(x, ev, cats)
if region != "" && g.Region != region {
continue
}
total.add(x, ev, cats)
c := cities[ck{g.City, g.Region}]
if c == nil {
c = &cityOut{Name: g.City, Region: g.Region}
if (g.Lat != 0 || g.Lon != 0) && g.Lat >= -90 && g.Lat <= 90 && g.Lon >= -180 && g.Lon <= 180 {
lat, lon := g.Lat, g.Lon
c.Lat, c.Lon = &lat, &lon
}
cities[ck{g.City, g.Region}] = c
}
c.Events += ev
c.IPs++
s.opt.Store.Enrich(&x)
rows = append(rows, geoIPOut{IP: x.IP, Score: x.Score, Level: string(x.Level), City: g.City, Reg: g.Region,
ASN: g.ASN, ASOrg: g.ASOrg, Last: x.Last})
}
if total.cats == nil {
total.cats = map[string]int{}
}
rl := make([]regionOut, 0, len(regs))
for name, a := range regs {
rl = append(rl, regionOut{name, a.events, a.ips, a.cats})
}
sort.Slice(rl, func(i, j int) bool {
if rl[i].Events != rl[j].Events {
return rl[i].Events > rl[j].Events
}
return rl[i].Name < rl[j].Name
})
if len(rl) > geoRegions {
rl = rl[:geoRegions]
}
cl := make([]cityOut, 0, len(cities))
for _, c := range cities {
cl = append(cl, *c)
}
sort.Slice(cl, func(i, j int) bool {
if cl[i].Events != cl[j].Events {
return cl[i].Events > cl[j].Events
}
return cl[i].Name < cl[j].Name
})
if len(cl) > geoCities {
cl = cl[:geoCities]
}
sort.Slice(rows, func(i, j int) bool {
if rows[i].Score != rows[j].Score {
return rows[i].Score > rows[j].Score
}
return rows[i].IP < rows[j].IP
})
if len(rows) > geoIPs {
rows = rows[:geoIPs]
}
out := map[string]any{"range": rg, "host": host, "cc": cc, "events": total.events, "ips": total.ips,
"hostile": total.hostile, "suspicious": total.suspic, "cats": total.cats,
"regions": rl, "cities": cl, "top_ips": rows}
if region != "" {
out["region"] = region
}
return out
}
+242
View File
@@ -0,0 +1,242 @@
package server
import (
"bufio"
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/core"
"git.lucasrguerra.dev.br/ciberfauna/urutau/internal/store"
)
type fakeGeo struct{}
func (fakeGeo) Geo(ip string) core.GeoInfo {
switch {
case strings.HasPrefix(ip, "200.1.1."):
return core.GeoInfo{CC: "BR", Country: "Brazil", Region: "Pernambuco", City: "Recife", Lat: -8.05, Lon: -34.9, ASN: 64500, ASOrg: "Net A"}
case strings.HasPrefix(ip, "200.2.2."):
return core.GeoInfo{CC: "BR", Country: "Brazil", Region: "Sao Paulo", City: "Campinas"} // no coordinates
case strings.HasPrefix(ip, "200.3.3."):
return core.GeoInfo{CC: "BR", Country: "Brazil", City: "Nowhere"} // empty region
case strings.HasPrefix(ip, "9.9.9."):
return core.GeoInfo{CC: "US", Region: "Texas", City: "Austin", Lat: 30.2, Lon: -97.7}
}
return core.GeoInfo{}
}
func (fakeGeo) UA(string) core.UAInfo { return core.UAInfo{} }
func geoSetup(t *testing.T) (http.Handler, map[string]string) {
st := store.New(store.Config{Name: "oracle", Version: "t", Location: &store.Location{Lat: 1, Lon: 2, Label: "Home"}})
st.SetEnricher(fakeGeo{})
now := time.Now()
ing := func(ip string, c core.Category, n int, strong bool) {
for i := 0; i < n; i++ {
st.Ingest(core.Event{Time: now, IP: ip, Cat: c, Strong: strong, Source: "traefik", Method: "GET", Path: "/x"})
}
}
ing("200.1.1.1", core.Exploit, 8, true) // 64 points: hostile
ing("200.1.1.2", core.Scanner, 2, false)
ing("200.1.1.3", core.NotFound, 5, false) // not malicious: ignored
ing("200.2.2.2", core.Scanner, 5, false)
ing("200.3.3.3", core.BruteForce, 1, false)
ing("9.9.9.9", core.SSHFail, 3, false)
ing("8.8.8.8", core.Exploit, 1, false) // unknown geo: skipped
h := New(Options{Token: utok, PeerTokens: []string{ptok}, Version: "t", Store: st})
return h, map[string]string{"Authorization": "Bearer " + utok}
}
func getJSON(t *testing.T, h http.Handler, path string, hd map[string]string) map[string]any {
w := do(h, "GET", path, cloneHdr(hd), nil)
if w.Code != 200 {
t.Fatalf("%s: %d %s", path, w.Code, w.Body)
}
var m map[string]any
if err := json.Unmarshal(w.Body.Bytes(), &m); err != nil {
t.Fatal(err)
}
return m
}
func cloneHdr(h map[string]string) map[string]string {
o := map[string]string{}
for k, v := range h {
o[k] = v
}
return o
}
func TestGeoAggregation(t *testing.T) {
h, u := geoSetup(t)
m := getJSON(t, h, "/api/v1/geo?range=24h&host=all", u)
cs := m["countries"].([]any)
if m["range"] != "24h" || len(cs) != 2 {
t.Fatalf("%v", m)
}
br := cs[0].(map[string]any)
if br["cc"] != "BR" || br["events"].(float64) != 8+2+5+1 || br["ips"].(float64) != 4 || br["hostile"].(float64) != 1 {
t.Fatalf("BR %v", br)
}
if c := br["cats"].(map[string]any); c["exploit"].(float64) != 8 || c["scanner"].(float64) != 7 || c["notfound"] != nil {
t.Fatalf("cats %v", c)
}
if cs[1].(map[string]any)["cc"] != "US" {
t.Fatalf("order %v", cs)
}
d := getJSON(t, h, "/api/v1/geo?cc=BR", u)
if d["cc"] != "BR" || len(d["regions"].([]any)) != 3 || len(d["cities"].([]any)) != 3 || len(d["top_ips"].([]any)) != 4 {
t.Fatalf("detail %v", d)
}
top := d["top_ips"].([]any)[0].(map[string]any)
if top["ip"] != "200.1.1.1" || top["level"] != "hostile" || top["city"] != "Recife" || top["asn"].(float64) != 64500 {
t.Fatalf("top ip %v", top)
}
for _, c := range d["cities"].([]any) {
c := c.(map[string]any)
_, hasLat := c["lat"]
if (c["name"] == "Recife") != hasLat {
t.Fatalf("coordinates only for cities that have them: %v", c)
}
}
empty := false
for _, r := range d["regions"].([]any) {
empty = empty || r.(map[string]any)["name"] == ""
}
if !empty {
t.Fatal("empty region must be kept as an empty name")
}
r := getJSON(t, h, "/api/v1/geo?cc=BR&region=Pernambuco", u)
if r["events"].(float64) != 10 || len(r["cities"].([]any)) != 1 || len(r["top_ips"].([]any)) != 2 || r["ips"].(float64) != 2 || r["region"] != "Pernambuco" {
t.Fatalf("region %v", r)
}
if w := do(h, "GET", "/api/v1/geo?cc=br", cloneHdr(u), nil); w.Code != 400 {
t.Fatalf("lowercase cc: %d", w.Code)
}
if w := do(h, "GET", "/api/v1/geo?host=nope", cloneHdr(u), nil); w.Code != 404 {
t.Fatalf("unknown host: %d", w.Code)
}
if w := do(h, "GET", "/api/v1/geo", map[string]string{"Authorization": "Bearer " + ptok}, nil); w.Code != 403 {
t.Fatalf("peer token: %d", w.Code)
}
if w := do(h, "GET", "/api/v1/geo", nil, nil); w.Code != 401 {
t.Fatalf("anonymous: %d", w.Code)
}
}
func TestLocationOnSummaryAndRecent(t *testing.T) {
h, u := geoSetup(t)
m := getJSON(t, h, "/api/v1/summary", u)
loc := m["hosts"].([]any)[0].(map[string]any)["location"].(map[string]any)
if loc["lat"].(float64) != 1 || loc["label"] != "Home" {
t.Fatalf("%v", loc)
}
rc := getJSON(t, h, "/api/v1/live/recent?limit=3", u)["events"].([]any)
if len(rc) != 3 {
t.Fatalf("limit: %d", len(rc))
}
all := getJSON(t, h, "/api/v1/live/recent?limit=9999", u)["events"].([]any)
if len(all) != 8+2+5+1+3+1 {
t.Fatalf("only malicious events: %d", len(all))
}
var seenSrc bool
for _, e := range all {
e := e.(map[string]any)
if e["host"] != "oracle" || e["dst"].(map[string]any)["label"] != "Home" || e["cat"] == "notfound" {
t.Fatalf("event %v", e)
}
if s, ok := e["src"].(map[string]any); ok && e["ip"] == "200.1.1.1" {
seenSrc = s["cc"] == "BR" && s["city"] == "Recife"
}
if e["ip"] == "8.8.8.8" && e["src"] != nil {
t.Fatal("src omitted when unknown")
}
}
if !seenSrc {
t.Fatal("src missing")
}
}
func TestStaticAssetsWhitelist(t *testing.T) {
h, _ := setup(t)
if w := do(h, "GET", "/style.css", nil, nil); w.Code != 200 || !strings.HasPrefix(w.Header().Get("Content-Type"), "text/css") || w.Header().Get("Content-Security-Policy") == "" {
t.Fatalf("css %d %v", w.Code, w.Header())
}
if w := do(h, "GET", "/logo.png", nil, nil); w.Code != 200 || w.Header().Get("Content-Type") != "image/png" {
t.Fatalf("png %d", w.Code)
}
for _, p := range []string{"/index.html", "/login.html", "/missing.js", "/Style.css", "/web", "/..%2fserver.go", "/%2e%2e/go.mod", "/a.go", "/.js", "/app.js/", "/x/app.js"} {
if w := do(h, "GET", p, nil, nil); w.Code == 200 {
t.Errorf("%s must not be served (200)", p)
}
}
}
func TestPeerStreamIsPeerOnly(t *testing.T) {
old := sseHeartbeat
sseHeartbeat = 50 * time.Millisecond
defer func() { sseHeartbeat = old }()
h, _ := geoSetup(t)
if w := do(h, "GET", "/api/v1/peer/stream", map[string]string{"Authorization": "Bearer " + utok}, nil); w.Code != 401 {
t.Fatalf("user token: %d", w.Code)
}
if w := do(h, "GET", "/api/v1/peer/stream", nil, nil); w.Code != 401 {
t.Fatalf("anonymous: %d", w.Code)
}
for _, p := range []string{"/api/v1/events/stream"} {
if w := do(h, "GET", p, map[string]string{"Authorization": "Bearer " + ptok}, nil); w.Code != 403 {
t.Fatalf("peer token on %s: %d", p, w.Code)
}
}
h2 := New(Options{Token: utok, PeerAllow: mustPrefixes("203.0.113.0/24"), PeerTokens: []string{ptok}, Version: "t", Store: store.New(store.Config{Name: "x"})})
if w := do(h2, "GET", "/api/v1/peer/stream", map[string]string{"Authorization": "Bearer " + ptok}, nil); w.Code != 403 {
t.Fatalf("--peer-allow: %d", w.Code)
}
h3 := New(Options{Token: utok, Version: "t", Store: store.New(store.Config{Name: "x"})})
if w := do(h3, "GET", "/api/v1/peer/stream", map[string]string{"Authorization": "Bearer " + ptok}, nil); w.Code != 404 {
t.Fatalf("federation off: %d", w.Code)
}
st := store.New(store.Config{Name: "edge", Version: "t", Location: &store.Location{Lat: 3, Lon: 4, Label: "Edge"}})
st.SetEnricher(fakeGeo{})
ts := httptest.NewServer(New(Options{Token: utok, PeerTokens: []string{ptok}, Version: "t", Store: st}))
defer ts.Close()
req, _ := http.NewRequest("GET", ts.URL+"/api/v1/peer/stream", nil)
req.Header.Set("Authorization", "Bearer "+ptok)
resp, err := http.DefaultClient.Do(req)
if err != nil || resp.StatusCode != 200 {
t.Fatal(err, resp)
}
defer resp.Body.Close()
go func() {
time.Sleep(200 * time.Millisecond)
st.Ingest(core.Event{Time: time.Now(), IP: "200.1.1.9", Cat: core.OK, Source: "traefik"}) // not malicious, not sent
st.Ingest(core.Event{Time: time.Now(), IP: "200.1.1.9", Cat: core.Scanner, Source: "traefik", Method: "GET", Path: "/wp"})
}()
sc := bufio.NewScanner(resp.Body)
deadline := time.After(5 * time.Second)
got := make(chan string, 1)
go func() {
for sc.Scan() {
if strings.HasPrefix(sc.Text(), "data: ") {
got <- sc.Text()[6:]
return
}
}
got <- ""
}()
select {
case d := <-got:
var e map[string]any
if json.Unmarshal([]byte(d), &e) != nil || e["ip"] != "200.1.1.9" || e["cat"] != "scanner" || e["dst"].(map[string]any)["label"] != "Edge" || e["src"].(map[string]any)["cc"] != "BR" {
t.Fatalf("peer event %s", d)
}
case <-deadline:
t.Fatal("no event")
}
}
+135 -10
View File
@@ -11,6 +11,7 @@ import (
"net/http"
"net/netip"
"net/url"
"regexp"
"sort"
"strconv"
"strings"
@@ -29,6 +30,9 @@ var webFS embed.FS
// maxSSE bounds the simultaneous live streams.
const maxSSE = 20
// maxPeerSSE bounds the simultaneous hub subscriptions to /api/v1/peer/stream.
const maxPeerSSE = 10
// sseHeartbeat is how often a live stream pings and revalidates its session.
var sseHeartbeat = 20 * time.Second
@@ -73,6 +77,8 @@ type Server struct {
lim *limiter
mux *http.ServeMux
assets fs.FS
geo geoCache
psse atomic.Int32
}
// New builds the handler.
@@ -88,11 +94,11 @@ func New(opt Options) http.Handler {
m.HandleFunc("POST /login", s.login)
m.HandleFunc("POST /logout", s.logout)
m.HandleFunc("GET /{$}", s.index)
for _, f := range []string{"/style.css", "/app.js", "/i18n.js", "/login.js", "/logo.png", "/favicon.png", "/world.js"} {
name := strings.TrimPrefix(f, "/")
m.HandleFunc("GET "+f, func(w http.ResponseWriter, r *http.Request) { s.static(w, r, name) })
}
m.HandleFunc("GET /{file}", s.asset)
m.HandleFunc("GET /api/v1/peer/export", s.peerExport)
m.HandleFunc("GET /api/v1/peer/stream", s.peerStream)
m.HandleFunc("GET /api/v1/geo", s.api(s.geoAPI))
m.HandleFunc("GET /api/v1/live/recent", s.api(s.liveRecent))
m.HandleFunc("GET /api/v1/summary", s.api(s.summary))
m.HandleFunc("GET /api/v1/traffic", s.api(s.traffic))
m.HandleFunc("GET /api/v1/ips", s.api(s.ips))
@@ -220,17 +226,18 @@ type exportCache struct {
v map[string][]byte
}
// peerExport is the only route the peer token opens: GET /api/v1/peer/export.
func (s *Server) peerExport(w http.ResponseWriter, r *http.Request) {
// peerGate admits only the federation token (and --peer-allow sources); it
// answers the request itself and returns false when it refuses.
func (s *Server) peerGate(w http.ResponseWriter, r *http.Request) bool {
if len(s.opt.PeerTokens) == 0 && !s.opt.NoAuth {
writeJSON(w, http.StatusNotFound, map[string]string{"error": "federation is not enabled"})
return
return false
}
if len(s.opt.PeerAllow) > 0 {
a, err := netip.ParseAddr(clientIP(r, s.opt.TrustedProxy))
if err != nil || !prefixesContain(s.opt.PeerAllow, a) {
writeJSON(w, http.StatusForbidden, map[string]string{"error": "source not allowed"})
return
return false
}
}
if !s.opt.NoAuth && s.authKind(r) != "peer" {
@@ -239,6 +246,14 @@ func (s *Server) peerExport(w http.ResponseWriter, r *http.Request) {
}
w.Header().Set("WWW-Authenticate", `Bearer realm="urutau-peer"`)
writeJSON(w, http.StatusUnauthorized, map[string]string{"error": "unauthorized"})
return false
}
return true
}
// peerExport: GET /api/v1/peer/export, opened by the peer token.
func (s *Server) peerExport(w http.ResponseWriter, r *http.Request) {
if !s.peerGate(w, r) {
return
}
rg := store.ParseRange(r.URL.Query().Get("range")).Name
@@ -267,6 +282,22 @@ func prefixesContain(ps []netip.Prefix, a netip.Addr) bool {
return false
}
var assetRe = regexp.MustCompile(`^[a-z0-9-]+\.(js|css|png|svg|json)$`)
// asset serves a top-level file of the embedded web directory by name.
func (s *Server) asset(w http.ResponseWriter, r *http.Request) {
name := r.PathValue("file")
if !assetRe.MatchString(name) {
http.NotFound(w, r)
return
}
if st, err := fs.Stat(s.assets, name); err != nil || !st.Mode().IsRegular() {
http.NotFound(w, r)
return
}
s.static(w, r, name)
}
func (s *Server) static(w http.ResponseWriter, r *http.Request, name string) {
b, err := fs.ReadFile(s.assets, name)
if err != nil {
@@ -281,6 +312,10 @@ func (s *Server) static(w http.ResponseWriter, r *http.Request, name string) {
ct = "text/javascript; charset=utf-8"
case strings.HasSuffix(name, ".png"):
ct = "image/png"
case strings.HasSuffix(name, ".svg"):
ct = "image/svg+xml"
case strings.HasSuffix(name, ".json"):
ct = "application/json; charset=utf-8"
case strings.HasSuffix(name, ".html"):
ct = "text/html; charset=utf-8"
}
@@ -539,10 +574,27 @@ func (s *Server) stream(w http.ResponseWriter, r *http.Request) {
h.Set("X-Accel-Buffering", "no")
ch, stop := s.opt.Store.Subscribe()
defer stop()
var hubCh <-chan store.LiveEvent // nil blocks forever: no hub, no peer events
if s.opt.Hub != nil {
c, stopHub := s.opt.Hub.Subscribe()
defer stopHub()
hubCh = c
}
fmt.Fprint(w, "retry: 3000\n: connected\n\n")
fl.Flush()
tick := time.NewTicker(sseHeartbeat)
defer tick.Stop()
send := func(e store.LiveEvent) bool {
if k := s.authKind(r); k != "session" && k != "bearer" {
return false
}
b, _ := json.Marshal(e)
if _, err := fmt.Fprintf(w, "event: ev\ndata: %s\n\n", b); err != nil {
return false
}
fl.Flush()
return true
}
for {
select {
case <-r.Context().Done():
@@ -556,10 +608,63 @@ func (s *Server) stream(w http.ResponseWriter, r *http.Request) {
}
fl.Flush()
case e := <-ch:
if k := s.authKind(r); k != "session" && k != "bearer" {
if !send(s.opt.Store.Live(e)) {
return
}
b, _ := json.Marshal(e)
case e := <-hubCh:
if !send(e) {
return
}
}
}
}
// peerStream: GET /api/v1/peer/stream, SSE of this instance's own malicious
// events for a hub. Opened only by the peer token, like the export.
func (s *Server) peerStream(w http.ResponseWriter, r *http.Request) {
if !s.peerGate(w, r) {
return
}
fl, ok := w.(http.Flusher)
if !ok {
http.Error(w, "streaming unsupported", 500)
return
}
if s.psse.Add(1) > maxPeerSSE {
s.psse.Add(-1)
w.Header().Set("Retry-After", "10")
http.Error(w, "too many peer streams", http.StatusServiceUnavailable)
return
}
defer s.psse.Add(-1)
_ = http.NewResponseController(w).SetWriteDeadline(time.Time{})
h := w.Header()
h.Set("Content-Type", "text/event-stream")
h.Set("Cache-Control", "no-store")
h.Set("X-Accel-Buffering", "no")
ch, stop := s.opt.Store.Subscribe()
defer stop()
fmt.Fprint(w, "retry: 3000\n: connected\n\n")
fl.Flush()
tick := time.NewTicker(sseHeartbeat)
defer tick.Stop()
for {
select {
case <-r.Context().Done():
return
case <-tick.C:
if !s.opt.NoAuth && s.authKind(r) != "peer" {
return
}
if _, err := fmt.Fprint(w, ": ping\n\n"); err != nil {
return
}
fl.Flush()
case e := <-ch:
if !core.Category(e.Cat).IsMalicious() {
continue
}
b, _ := json.Marshal(s.opt.Store.Live(e))
if _, err := fmt.Fprintf(w, "event: ev\ndata: %s\n\n", b); err != nil {
return
}
@@ -568,6 +673,26 @@ func (s *Server) stream(w http.ResponseWriter, r *http.Request) {
}
}
// liveRecent: GET /api/v1/live/recent?limit=200 (max 500), newest first, local and peers.
func (s *Server) liveRecent(w http.ResponseWriter, r *http.Request) {
n, _ := strconv.Atoi(r.URL.Query().Get("limit"))
if n < 1 {
n = 200
}
if n > 500 {
n = 500
}
list := s.opt.Store.LiveRecent(n)
if s.opt.Hub != nil {
list = append(list, s.opt.Hub.Recent(n)...)
}
sort.SliceStable(list, func(i, j int) bool { return list[i].T > list[j].T })
if len(list) > n {
list = list[:n]
}
writeJSON(w, 200, map[string]any{"events": list})
}
func (s *Server) blocklist(asJSON bool) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
q := r.URL.Query()
+1 -1
View File
@@ -253,7 +253,7 @@ func TestPeerTokenOnlyOpensExport(t *testing.T) {
peer := map[string]string{"Authorization": "Bearer peer-token-0123456789-abcdefghijklmnopq"}
user := map[string]string{"Authorization": "Bearer user-token-0123456789-abcdefghijklmnop"}
for _, p := range []string{"/api/v1/summary", "/api/v1/traffic", "/api/v1/ip/45.94.31.4", "/api/v1/ips", "/api/v1/events/stream",
"/api/v1/blocklist.txt", "/api/v1/blocklist.json"} {
"/api/v1/blocklist.txt", "/api/v1/blocklist.json", "/api/v1/geo", "/api/v1/live/recent"} {
if w := do(h, "GET", p, peer, nil); w.Code != http.StatusForbidden {
t.Errorf("peer token on %s: %d (want 403)", p, w.Code)
}
+1177 -603
View File
File diff suppressed because it is too large. Load diff
+101
View File
@@ -0,0 +1,101 @@
/* Urutau - página Geografia. Só tokens do shell; sem cores fixas além do fallback. */
.geo { display: grid; gap: 14px; min-width: 0; }
.geo.is-busy .geo-main, .geo.is-busy .geo-detail { opacity: .72; transition: opacity .2s; }
.geo-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: space-between; }
.geo-crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; min-width: 0; font-size: 14px; }
.geo-crumb { background: none; border: 0; padding: 4px 6px; margin: 0 -2px; border-radius: 8px; color: var(--accent); cursor: pointer; font: inherit; }
.geo-crumb:hover { background: var(--surface-raised); text-decoration: underline; }
.geo-crumb.cur { color: var(--ink); font-weight: 600; padding: 4px 2px; overflow-wrap: anywhere; }
.geo-sep { color: var(--ink-muted); }
.geo-back, .geo-retry, .geo-chip {
background: var(--surface-raised); border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; min-height: 36px; cursor: pointer; color: var(--ink);
}
.geo-back:hover, .geo-retry:hover, .geo-chip:hover { border-color: var(--accent); }
.geo-back[hidden] { display: none; }
/* o texto de abertura usa o .lead do shell */
.geo-leadbox { min-height: 70px; }
.geo-lead { max-width: none !important; }
.geo-lead:focus { outline: none; }
.geo-err { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); }
.geo-err[hidden] { display: none; }
.geo-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 14px; align-items: stretch; }
.geo-panel { background: var(--surface-panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.geo-panel h2 { font: 700 1rem/1.3 var(--font-display); color: var(--heading); margin: 0 0 10px; }
.geo-panel h2:focus { outline: none; }
.geo-mappanel { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.geo-map { position: relative; width: 100%; aspect-ratio: 2000 / 789; min-height: 240px; overflow: hidden; border-radius: 10px; background: color-mix(in srgb, var(--surface-sunken) 60%, transparent); }
.geo-svg { width: 100%; height: 100%; display: block; }
.geo-cn { fill: var(--ink-muted); fill-opacity: .14; stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; transition: opacity .3s; }
.geo-cn.hit { fill: var(--accent); cursor: pointer; stroke: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.geo-cn.hit:hover { stroke: var(--ink); stroke-width: 1.6; }
.geo-svg.zoomed .geo-cn:not(.sel) { opacity: .35; }
.geo-svg.zoomed .geo-cn.sel { fill: var(--accent); fill-opacity: .22 !important; stroke: var(--accent); stroke-width: 1.5; cursor: default; }
.geo-city { fill: var(--viz-7); fill-opacity: .5; stroke: var(--danger); stroke-width: 1.2; vector-effect: non-scaling-stroke; animation: geo-in .35s ease-out; }
.geo-city-click { cursor: pointer; }
.geo-city:hover, .geo-city.hl { fill-opacity: .85; stroke: var(--ink); stroke-width: 2; }
@keyframes geo-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .geo-city { animation: none; } .geo-cn { transition: none; } }
.geo-tip { position: absolute; pointer-events: none; z-index: 5; background: var(--surface-overlay); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12px; min-width: 140px; max-width: 260px; box-shadow: var(--shadow); }
.geo-tip[hidden], .geo-loading[hidden], .geo-legend[hidden], .geo-detail[hidden] { display: none; }
.geo-tip-h { font-weight: 600; margin-bottom: 4px; overflow-wrap: anywhere; }
.geo-tip-r { display: flex; justify-content: space-between; gap: 12px; color: var(--ink-muted); }
.geo-tip-r b { color: var(--ink); font-weight: 600; text-align: right; overflow-wrap: anywhere; }
.geo-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-muted); }
.geo-legend { display: grid; grid-template-columns: auto minmax(60px, 160px) auto 1fr; gap: 8px; align-items: center; font-size: 12px; color: var(--ink-muted); padding: 0 4px; }
.geo-legend-bar { height: 8px; border-radius: 4px; background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 20%, transparent), var(--accent)); border: 1px solid var(--line); }
.geo-legend-t { margin-left: 6px; }
.geo-side { display: flex; flex-direction: column; min-height: 0; }
.geo-list { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; flex: 1 1 0; min-height: 120px; padding-right: 2px; }
.geo-row { display: block; width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: 10px; padding: 6px 8px; color: var(--ink); font: inherit; }
button.geo-row { cursor: pointer; }
button.geo-row:hover { background: var(--surface-raised); border-color: var(--line); }
.geo-row.on { background: color-mix(in srgb, var(--accent) 14%, transparent); border-color: var(--accent); }
.geo-row-top { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.geo-rank { color: var(--ink-muted); font-size: 11px; min-width: 1.8em; font-variant-numeric: tabular-nums; }
.geo-name { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.geo-sub { flex: 1 1 0; min-width: 0; color: var(--ink-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.geo-name + .geo-num { margin-left: auto; }
.geo-num { font-variant-numeric: tabular-nums; font-weight: 600; flex: none; margin-left: auto; }
.geo-bar { display: block; height: 4px; border-radius: 2px; background: var(--surface-raised); margin-top: 5px; overflow: hidden; }
.geo-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.geo-chip { align-self: flex-start; margin-bottom: 6px; }
.geo-empty { color: var(--ink-muted); padding: 16px 4px; text-align: center; }
.geo-note { color: var(--ink-muted); font-size: 12px; margin-top: 8px; }
.geo-detail { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; align-items: start; }
.geo-stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; margin-bottom: 12px; }
.geo-stack span { min-width: 3px; }
.geo-chips { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.geo-chipcat { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.geo-chipcat b { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 600; }
.geo-chipcat i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.geo-c-notfound { background: var(--cat-notfound); } .geo-c-scanner { background: var(--cat-scanner); }
.geo-c-bruteforce { background: var(--cat-bruteforce); } .geo-c-exploit { background: var(--cat-exploit); }
.geo-c-ssh-fail { background: var(--cat-ssh-fail); } .geo-c-ssh-probe { background: var(--cat-ssh-probe); }
.geo-c-ban { background: var(--cat-ban); } .geo-c-other { background: var(--ink-faint); }
.geo-ip { display: block; width: 100%; text-align: left; background: none; border: 1px solid transparent; border-radius: 10px; padding: 7px 8px; color: var(--ink); font: inherit; cursor: pointer; }
.geo-ip:hover { background: var(--surface-raised); border-color: var(--line); }
.geo-ip-l1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.geo-ip-l1 code { font-size: 13px; font-weight: 600; }
.geo-ip-l2, .geo-ip-l3 { display: block; color: var(--ink-muted); font-size: 12px; overflow-wrap: anywhere; }
.geo-lv { font-size: 11px; padding: 1px 7px; border-radius: 999px; border: 1px solid currentColor; }
.geo-lv-hostile { color: var(--danger); } .geo-lv-suspicious { color: var(--warn); }
.geo-lv-clean, .geo-lv-low { color: var(--ok); } .geo-lv-unknown { color: var(--ink-faint); }
.geo-score { color: var(--ink-muted); font-size: 12px; margin-left: auto; }
@media (max-width: 900px) {
.geo-main { grid-template-columns: minmax(0, 1fr); }
.geo-list { max-height: 360px; flex: none; }
.geo-detail { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
.geo-map { aspect-ratio: 4 / 3; min-height: 0; }
/* o texto de abertura usa o .lead do shell */
.geo-leadbox { min-height: 70px; }
.geo-lead { max-width: none !important; }
.geo-legend { grid-template-columns: auto minmax(40px, 1fr) auto; }
.geo-legend-t { grid-column: 1 / -1; margin-left: 0; }
}
+680
View File
@@ -0,0 +1,680 @@
/* Urutau - página Geografia: mapa coroplético, zoom em país, estados e cidades.
Todos os dados externos (cidade, região, AS) entram só via textContent. */
(function () {
'use strict';
var U = window.Urutau;
if (!U || typeof U.registerPage !== 'function') return;
// ---------------------------------------------------------------- i18n
U.registerI18n({
en: {
'geo.title': 'Geography',
'geo.world': 'World',
'geo.nav': 'Location path',
'geo.back': 'Back',
'geo.back.hint': 'Back (Esc)',
'geo.map.label': 'Map of attack origins. Use the list to choose a country.',
'geo.map.country.label': 'Map of {country} with the cities that attack the most',
'geo.lead.world': '{events} from {ips} across {countries}, in the last {range}; {top} leads with {pct}.',
'geo.lead.country': '{country} originated {events} from {ips} in the last {range}; {region} leads with {pct}.',
'geo.lead.country.flat': '{country} originated {events} from {ips} in the last {range}.',
'geo.lead.region': '{region} ({country}) originated {events} from {ips} in the last {range}; {city} leads with {pct}.',
'geo.lead.region.flat': '{region} ({country}) originated {events} from {ips} in the last {range}.',
'geo.lead.empty': 'No geolocated attacks in the last {range}.',
'geo.lead.empty.country': 'No attacks from {country} in the last {range}.',
'geo.u.events.one': '{n} event', 'geo.u.events.other': '{n} events',
'geo.u.ips.one': '{n} IP', 'geo.u.ips.other': '{n} IPs',
'geo.u.countries.one': '{n} country', 'geo.u.countries.other': '{n} countries',
'geo.range.1h': 'hour', 'geo.range.24h': '24 hours', 'geo.range.7d': '7 days',
'geo.legend': 'Events per country (log scale)',
'geo.tip.events': 'Events', 'geo.tip.ips': 'IPs', 'geo.tip.hostile': 'Hostile',
'geo.tip.region': 'Region',
'geo.countries': 'Countries',
'geo.regions': 'States / regions',
'geo.cities': 'Cities',
'geo.cats': 'Attack categories',
'geo.ips': 'Top IPs',
'geo.unknown': 'Unknown',
'geo.all_regions': 'All regions',
'geo.pick': 'Open {name}: {events}',
'geo.pick.region': 'Filter by {name}: {events}',
'geo.city.pick': 'Filter by region {name}',
'geo.nocoords.one': '{n} city has no coordinates and is not on the map.', 'geo.nocoords.other': '{n} cities have no coordinates and are not on the map.',
'geo.empty': 'Nothing to show for this range.',
'geo.empty.list': 'No data.',
'geo.loading': 'Loading…',
'geo.error': 'Could not load geography data.',
'geo.retry': 'Try again',
'geo.level.hostile': 'hostile', 'geo.level.suspicious': 'suspicious', 'geo.level.clean': 'clean', 'geo.level.low': 'low', 'geo.level.unknown': 'unknown',
'geo.score': 'score {n}',
'geo.open_ip': 'Open details of {ip}',
'geo.hostile_suspicious': '{h} hostile, {s} suspicious',
'geo.cat.notfound': 'not found', 'geo.cat.scanner': 'scanner', 'geo.cat.bruteforce': 'brute force',
'geo.cat.exploit': 'exploit', 'geo.cat.ssh-fail': 'SSH failures', 'geo.cat.ssh-probe': 'SSH probe', 'geo.cat.ban': 'ban'
},
'pt-BR': {
'geo.title': 'Geografia',
'geo.world': 'Mundo',
'geo.nav': 'Caminho da localização',
'geo.back': 'Voltar',
'geo.back.hint': 'Voltar (Esc)',
'geo.map.label': 'Mapa das origens dos ataques. Use a lista para escolher um país.',
'geo.map.country.label': 'Mapa de {country} com as cidades que mais atacam',
'geo.lead.world': '{events} de {ips} em {countries}, nas últimas {range}; {top} lidera com {pct}.',
'geo.lead.country': '{country} originou {events} de {ips} nas últimas {range}; {region} lidera com {pct}.',
'geo.lead.country.flat': '{country} originou {events} de {ips} nas últimas {range}.',
'geo.lead.region': '{region} ({country}) originou {events} de {ips} nas últimas {range}; {city} lidera com {pct}.',
'geo.lead.region.flat': '{region} ({country}) originou {events} de {ips} nas últimas {range}.',
'geo.lead.empty': 'Nenhum ataque geolocalizado nas últimas {range}.',
'geo.lead.empty.country': 'Nenhum ataque de {country} nas últimas {range}.',
'geo.u.events.one': '{n} evento', 'geo.u.events.other': '{n} eventos',
'geo.u.ips.one': '{n} IP', 'geo.u.ips.other': '{n} IPs',
'geo.u.countries.one': '{n} país', 'geo.u.countries.other': '{n} países',
'geo.range.1h': 'hora', 'geo.range.24h': '24 horas', 'geo.range.7d': '7 dias',
'geo.legend': 'Eventos por país (escala log)',
'geo.tip.events': 'Eventos', 'geo.tip.ips': 'IPs', 'geo.tip.hostile': 'Hostis',
'geo.tip.region': 'Região',
'geo.countries': 'Países',
'geo.regions': 'Estados / regiões',
'geo.cities': 'Cidades',
'geo.cats': 'Categorias de ataque',
'geo.ips': 'IPs que mais atacam',
'geo.unknown': 'Desconhecido',
'geo.all_regions': 'Todas as regiões',
'geo.pick': 'Abrir {name}: {events}',
'geo.pick.region': 'Filtrar por {name}: {events}',
'geo.city.pick': 'Filtrar pela região {name}',
'geo.nocoords.one': '{n} cidade sem coordenadas não aparece no mapa.', 'geo.nocoords.other': '{n} cidades sem coordenadas não aparecem no mapa.',
'geo.empty': 'Nada para mostrar neste período.',
'geo.empty.list': 'Sem dados.',
'geo.loading': 'Carregando…',
'geo.error': 'Não foi possível carregar os dados de geografia.',
'geo.retry': 'Tentar de novo',
'geo.level.hostile': 'hostil', 'geo.level.suspicious': 'suspeito', 'geo.level.clean': 'limpo', 'geo.level.low': 'baixo', 'geo.level.unknown': 'desconhecido',
'geo.score': 'pontuação {n}',
'geo.open_ip': 'Abrir detalhes de {ip}',
'geo.hostile_suspicious': '{h} hostis, {s} suspeitos',
'geo.cat.notfound': 'não encontrado', 'geo.cat.scanner': 'scanner', 'geo.cat.bruteforce': 'força bruta',
'geo.cat.exploit': 'exploit', 'geo.cat.ssh-fail': 'falhas SSH', 'geo.cat.ssh-probe': 'sondagem SSH', 'geo.cat.ban': 'banimento'
}
});
// ---------------------------------------------------------------- helpers
var NS = 'http://www.w3.org/2000/svg';
var CAT_CLASS = { notfound: 1, scanner: 1, bruteforce: 1, exploit: 1, 'ssh-fail': 1, 'ssh-probe': 1, ban: 1 };
var LEVELS = { hostile: 1, suspicious: 1, clean: 1, low: 1, unknown: 1 };
var RANGES = { '1h': 1, '24h': 1, '7d': 1 };
var LAT_TOP = 84, LAT_SPAN = 142;
function t(k, v) { return U.t(k, v); }
function h(tag, cls, text) {
var e = document.createElement(tag);
if (cls) e.className = cls;
if (text != null) e.textContent = text;
return e;
}
function sv(tag, attrs) {
var e = document.createElementNS(NS, tag);
if (attrs) for (var k in attrs) e.setAttribute(k, attrs[k]);
return e;
}
function clear(n) { while (n.firstChild) n.removeChild(n.firstChild); }
function nf(n) {
try { if (U.fmt && U.fmt.num) return U.fmt.num(n); } catch (e) { /* fallback */ }
return new Intl.NumberFormat(lang).format(n);
}
function pct(x) { return Math.round(x * 100) + '%'; }
function unit(kind, n) { return t('geo.u.' + kind + (n === 1 ? '.one' : '.other'), { n: nf(n) }); }
function flagOf(cc) { try { return (U.fmt && U.fmt.flag && U.fmt.flag(cc)) || ''; } catch (e) { return ''; } }
var dn = null, dnLang = '';
function countryName(cc) {
try {
if (!dn || dnLang !== lang) { dn = new Intl.DisplayNames([lang], { type: 'region' }); dnLang = lang; }
return dn.of(cc) || cc;
} catch (e) { return cc; }
}
function regionName(r) { return r ? r : t('geo.unknown'); }
function catLabel(c) { var k = 'geo.cat.' + c, v = t(k); return v && v !== k ? v : c; }
function catCls(c) { return CAT_CLASS[c] ? 'geo-c-' + c : 'geo-c-other'; }
function rangeLabel(r) { return t('geo.range.' + (RANGES[r] ? r : '24h')); }
function sum(o) { var s = 0; for (var k in o) s += o[k]; return s; }
// ---------------------------------------------------------------- geometry
var world = null, bboxCache = {};
function projX(lon) { return (lon + 180) / 360 * world.w; }
function projY(lat) { return (LAT_TOP - lat) / LAT_SPAN * world.h; }
// Bbox of a country's path: main land masses only (drops far-away small islands).
function bboxOf(cc) {
if (bboxCache[cc]) return bboxCache[cc];
var d = world.paths[cc];
if (!d) return null;
var re = /([MmLlzZ])|(-?\d+(?:\.\d+)?)/g, m, cmd = '', nums = [], subs = [], cur = null, cx = 0, cy = 0, sx = 0, sy = 0;
function flush() {
for (var i = 0; i + 1 < nums.length; i += 2) {
if (cmd === 'M' && i === 0) { cx = nums[i]; cy = nums[i + 1]; sx = cx; sy = cy; cur = [cx, cy, cx, cy]; subs.push(cur); }
else { if (cmd === 'l' || cmd === 'm') { cx += nums[i]; cy += nums[i + 1]; } else { cx = nums[i]; cy = nums[i + 1]; }
if (cur) { if (cx < cur[0]) cur[0] = cx; if (cy < cur[1]) cur[1] = cy; if (cx > cur[2]) cur[2] = cx; if (cy > cur[3]) cur[3] = cy; } }
}
nums = [];
}
while ((m = re.exec(d))) {
if (m[1]) { flush(); cmd = m[1]; if (cmd === 'z' || cmd === 'Z') { cx = sx; cy = sy; } }
else nums.push(parseFloat(m[2]));
}
flush();
var maxA = 0;
subs.forEach(function (b) { var a = (b[2] - b[0]) * (b[3] - b[1]); if (a > maxA) maxA = a; });
var out = null;
subs.forEach(function (b) {
var a = (b[2] - b[0]) * (b[3] - b[1]);
if (a < maxA * 0.12 && subs.length > 1) return;
if (!out) out = b.slice();
else { out[0] = Math.min(out[0], b[0]); out[1] = Math.min(out[1], b[1]); out[2] = Math.max(out[2], b[2]); out[3] = Math.max(out[3], b[3]); }
});
bboxCache[cc] = out;
return out;
}
// ---------------------------------------------------------------- state
var lang = 'en', ctx = null, root = null, ui = null, alive = false;
var S = { cc: '', region: '' };
var data = { world: null, country: null, full: null, error: false, loading: false };
var seq = 0, cache = {}, view = null, anim = 0, cityEls = [], ro = null;
function parseHash() {
var m = /^#\/geo(?:\/([A-Za-z]{2})(?:\/(.*))?)?$/.exec(location.hash || '');
var cc = '', region = '';
if (m && m[1]) {
cc = m[1].toUpperCase();
if (m[2]) { try { region = decodeURIComponent(m[2]); } catch (e) { region = ''; } }
}
return { cc: cc, region: region };
}
function writeHash() {
var hsh = '#/geo' + (S.cc ? '/' + S.cc + (S.region ? '/' + encodeURIComponent(S.region) : '') : '');
if (location.hash !== hsh) { try { history.pushState(null, '', hsh); } catch (e) { location.hash = hsh; } }
}
function go(cc, region, focus) {
if (world && cc && !world.paths[cc]) cc = '';
S.cc = cc || '';
S.region = cc ? (region || '') : '';
writeHash();
load(true);
if (focus && ui) setTimeout(function () { try { ui.lead.focus({ preventScroll: true }); } catch (e) { /* ignore */ } }, 0);
}
function goBack() {
if (S.region) go(S.cc, '', true);
else if (S.cc) go('', '', true);
}
function onHash() {
if (!alive) return;
var p = parseHash();
if (p.cc === S.cc && p.region === S.region) return;
S.cc = p.cc; S.region = p.region;
load(true);
}
function onKey(e) {
if (!alive || e.key !== 'Escape' || e.defaultPrevented) return;
var tg = e.target && e.target.tagName;
if (tg === 'INPUT' || tg === 'SELECT' || tg === 'TEXTAREA') return;
if (S.cc) { e.preventDefault(); goBack(); }
}
// ---------------------------------------------------------------- data
function key(extra) { return [ctx.range, ctx.host || '', extra || ''].join('|'); }
function fetchJSON(params) {
var p = { range: ctx.range };
if (ctx.host) p.host = ctx.host;
for (var k in params) p[k] = params[k];
return Promise.resolve(U.api('/api/v1/geo', p));
}
function cached(k, params) {
if (cache[k]) return Promise.resolve(cache[k]);
return fetchJSON(params).then(function (d) { cache[k] = d; return d; });
}
function load(refit) {
var my = ++seq;
data.loading = true; data.error = false;
paintState();
var cc = S.cc, region = S.region;
var jobs = [cached(key('w'), {})];
if (cc) {
jobs.push(cached(key('c:' + cc), { cc: cc }));
jobs.push(region ? cached(key('r:' + cc + ':' + region), { cc: cc, region: region }) : null);
}
Promise.all(jobs).then(function (r) {
if (my !== seq || !alive) return;
data.world = r[0];
data.full = cc ? r[1] : null;
data.country = cc ? (region ? r[2] : r[1]) : null;
data.loading = false;
render(refit);
}).catch(function () {
if (my !== seq || !alive) return;
data.loading = false; data.error = true;
render(false);
});
}
// ---------------------------------------------------------------- build
function build(el) {
clear(el);
root = h('div', 'geo');
var top = h('div', 'geo-top');
var nav = h('nav', 'geo-crumbs'); nav.setAttribute('aria-label', t('geo.nav'));
var back = h('button', 'geo-back', '‹ ' + t('geo.back')); back.type = 'button';
back.title = t('geo.back.hint'); back.addEventListener('click', goBack);
top.appendChild(nav); top.appendChild(back);
var lead = h('h2', 'geo-lead'); lead.tabIndex = -1; lead.setAttribute('aria-live', 'polite');
var leadBox = h('div', 'lead geo-leadbox'); leadBox.appendChild(lead);
var err = h('div', 'geo-err'); err.setAttribute('role', 'alert'); err.hidden = true;
var errMsg = h('span', '', t('geo.error')), retry = h('button', 'geo-retry', t('geo.retry')); retry.type = 'button';
retry.addEventListener('click', function () { cache = {}; load(false); });
err.appendChild(errMsg); err.appendChild(retry);
var main = h('div', 'geo-main');
var mapPanel = h('section', 'geo-panel geo-mappanel');
var box = h('div', 'geo-map');
var svg = sv('svg', { 'class': 'geo-svg', role: 'img', preserveAspectRatio: 'xMidYMid meet' });
var gC = sv('g', { 'class': 'geo-countries' }), gCity = sv('g', { 'class': 'geo-cities' });
svg.appendChild(gC); svg.appendChild(gCity);
var paths = {};
Object.keys(world.paths).forEach(function (cc) {
var p = sv('path', { d: world.paths[cc], 'class': 'geo-cn', 'data-cc': cc });
paths[cc] = p; gC.appendChild(p);
});
var tip = h('div', 'geo-tip'); tip.hidden = true; tip.setAttribute('role', 'presentation');
var ld = h('div', 'geo-loading', t('geo.loading')); ld.hidden = true;
box.appendChild(svg); box.appendChild(tip); box.appendChild(ld);
var legend = h('div', 'geo-legend');
var lg = h('div', 'geo-legend-bar'); lg.setAttribute('aria-hidden', 'true');
var lmin = h('span', '', '1'), lmax = h('span', '', ''), ltx = h('span', 'geo-legend-t', t('geo.legend'));
legend.appendChild(lmin); legend.appendChild(lg); legend.appendChild(lmax); legend.appendChild(ltx);
mapPanel.appendChild(box); mapPanel.appendChild(legend);
var side = h('section', 'geo-panel geo-side');
var sideH = h('h2', '', ''); sideH.tabIndex = -1;
var sideList = h('div', 'geo-list');
side.appendChild(sideH); side.appendChild(sideList);
main.appendChild(mapPanel); main.appendChild(side);
var detail = h('div', 'geo-detail');
function panel(title) {
var p = h('section', 'geo-panel'), hd = h('h2', '', title), body = h('div', 'geo-body');
p.appendChild(hd); p.appendChild(body); detail.appendChild(p);
return { p: p, h: hd, body: body };
}
var pCities = panel(''), pCats = panel(''), pIps = panel('');
root.appendChild(top); root.appendChild(leadBox); root.appendChild(err); root.appendChild(main); root.appendChild(detail);
el.appendChild(root);
ui = { nav: nav, back: back, lead: lead, err: err, errMsg: errMsg, retry: retry, svg: svg, gCity: gCity, paths: paths, box: box,
tip: tip, loading: ld, legendMax: lmax, legend: legend, legendBar: lg, side: side, sideH: sideH, sideList: sideList, detail: detail,
pCities: pCities, pCats: pCats, pIps: pIps };
gC.addEventListener('click', function (e) {
var cc = e.target && e.target.getAttribute && e.target.getAttribute('data-cc');
if (cc && hit(cc)) go(cc, '', true);
});
gC.addEventListener('mousemove', function (e) {
var cc = e.target && e.target.getAttribute && e.target.getAttribute('data-cc');
var r = cc && hit(cc);
if (!r) { ui.tip.hidden = true; return; }
showTip(e, [[flagOf(cc) + ' ' + countryName(cc), ''], [t('geo.tip.events'), nf(r.events)], [t('geo.tip.ips'), nf(r.ips)], [t('geo.tip.hostile'), nf(r.hostile || 0)]]);
});
gC.addEventListener('mouseleave', function () { ui.tip.hidden = true; });
gCity.addEventListener('mouseleave', function () { ui.tip.hidden = true; });
if (window.ResizeObserver) {
ro = new ResizeObserver(function () { if (alive && data.world && !data.error && !anim) { fitNow(); drawCities(); } });
ro.observe(box);
}
}
function hit(cc) {
var cs = data.world && data.world.countries;
if (!cs) return null;
for (var i = 0; i < cs.length; i++) if (cs[i].cc === cc) return cs[i];
return null;
}
function showTip(e, rows) {
var tip = ui.tip;
clear(tip);
rows.forEach(function (r, i) {
var d = h('div', i === 0 ? 'geo-tip-h' : 'geo-tip-r');
d.appendChild(h('span', '', r[0]));
if (r[1] !== '') d.appendChild(h('b', '', r[1]));
tip.appendChild(d);
});
tip.hidden = false;
var b = ui.box.getBoundingClientRect();
var x = e.clientX - b.left + 14, y = e.clientY - b.top + 14;
var w = tip.offsetWidth, hh = tip.offsetHeight;
if (x + w > b.width - 4) x = Math.max(4, e.clientX - b.left - w - 14);
if (y + hh > b.height - 4) y = Math.max(4, e.clientY - b.top - hh - 14);
tip.style.left = x + 'px'; tip.style.top = y + 'px';
}
// ---------------------------------------------------------------- map view
function boxSize() {
var r = ui.box.getBoundingClientRect();
return { w: r.width || 800, h: r.height || 360 };
}
function targetView() {
var sz = boxSize(), asp = sz.w / sz.h, bb, margin = 1.22;
if (!S.cc) { bb = [0, 0, world.w, world.h]; margin = 1; }
else {
bb = bboxOf(S.cc) || [0, 0, world.w, world.h];
var cs = data.country && data.country.cities;
if (S.region && cs) {
var pts = cs.filter(function (c) { return isNum(c.lat) && isNum(c.lon); });
if (pts.length) {
var x0 = 1e9, y0 = 1e9, x1 = -1e9, y1 = -1e9;
pts.forEach(function (c) { var x = projX(c.lon), y = projY(c.lat); x0 = Math.min(x0, x); x1 = Math.max(x1, x); y0 = Math.min(y0, y); y1 = Math.max(y1, y); });
bb = [x0, y0, x1, y1]; margin = 1.5;
}
}
}
var bw = Math.max(bb[2] - bb[0], 36), bh = Math.max(bb[3] - bb[1], 36 / asp);
var vw = Math.max(bw * margin, bh * margin * asp);
var vh = vw / asp;
var cx = (bb[0] + bb[2]) / 2, cy = (bb[1] + bb[3]) / 2;
return [cx - vw / 2, cy - vh / 2, vw, vh];
}
function setView(v) { if (!(v[2] > 0 && v[3] > 0)) return; view = v; ui.svg.setAttribute('viewBox', v.map(function (n) { return n.toFixed(2); }).join(' ')); }
function fitNow() { setView(targetView()); }
function reduced() { try { return window.matchMedia('(prefers-reduced-motion: reduce)').matches; } catch (e) { return false; } }
function animateTo(to, done) {
cancelAnimationFrame(anim); anim = 0;
if (!view || reduced()) { setView(to); done(); return; }
var from = view.slice(), t0 = performance.now(), dur = 420;
(function step(now) {
var k = Math.min(1, (now - t0) / dur), e = 1 - Math.pow(1 - k, 3);
setView(from.map(function (f, i) { return f + (to[i] - f) * e; }));
if (k < 1) anim = requestAnimationFrame(step); else { anim = 0; done(); }
})(t0);
}
// O contrato repete a chave "ips" (contagem e lista); aceita os dois formatos.
function ipList(d) { return Array.isArray(d.top_ips) ? d.top_ips : (Array.isArray(d.ips) ? d.ips : []); }
function ipCount(d) {
if (isNum(d.ips)) return d.ips;
var k = ['ip_count', 'ips_total', 'unique_ips', 'ips_count'];
for (var i = 0; i < k.length; i++) if (isNum(d[k[i]])) return d[k[i]];
if (S.region && data.full) { var rs = data.full.regions || []; for (var j = 0; j < rs.length; j++) if (rs[j].name === S.region) return rs[j].ips; }
var w = hit(S.cc); if (w && !S.region) return w.ips;
return (d.cities || []).reduce(function (a, c) { return a + (c.ips || 0); }, 0);
}
function isNum(n) { return typeof n === 'number' && isFinite(n); }
function drawCities() {
clear(ui.gCity); cityEls = [];
var d = data.country;
if (!S.cc || !d || !d.cities || !view) return;
var sz = boxSize(), upp = view[2] / sz.w, max = 1;
d.cities.forEach(function (c) { if (c.events > max) max = c.events; });
var rmax = sz.w < 560 ? 16 : 26;
d.cities.forEach(function (c, i) {
if (!isNum(c.lat) || !isNum(c.lon)) return;
var x = projX(c.lon), y = projY(c.lat);
if (x < view[0] - 20 || x > view[0] + view[2] + 20 || y < view[1] - 20 || y > view[1] + view[3] + 20) return;
var r = Math.max(3, rmax * Math.sqrt(c.events / max)) * upp;
var el = sv('circle', { cx: x.toFixed(2), cy: y.toFixed(2), r: r.toFixed(2), 'class': 'geo-city' });
el.addEventListener('mousemove', function (e) {
var rows = [[c.name || t('geo.unknown'), '']];
if (c.region) rows.push([t('geo.tip.region'), c.region]);
rows.push([t('geo.tip.events'), nf(c.events)], [t('geo.tip.ips'), nf(c.ips)]);
showTip(e, rows);
});
el.addEventListener('mouseleave', function () { ui.tip.hidden = true; });
if (c.region && !S.region) {
el.addEventListener('click', function () { go(S.cc, c.region, true); });
el.classList.add('geo-city-click');
}
cityEls[i] = el; ui.gCity.appendChild(el);
});
}
// ---------------------------------------------------------------- render
function paintState() {
if (!ui) return;
ui.loading.hidden = !data.loading || !!data.world;
root.classList.toggle('is-busy', data.loading);
}
function crumbs() {
var nav = ui.nav; clear(nav);
function sep() { var s = h('span', 'geo-sep', '›'); s.setAttribute('aria-hidden', 'true'); nav.appendChild(s); }
var parts = [{ txt: t('geo.world'), act: S.cc ? function () { go('', '', true); } : null }];
if (S.cc) parts.push({ txt: flagOf(S.cc) + ' ' + countryName(S.cc), act: S.region ? function () { go(S.cc, '', true); } : null });
if (S.region) parts.push({ txt: regionName(S.region), act: null });
parts.forEach(function (p, i) {
if (i) sep();
var n;
if (p.act) { n = h('button', 'geo-crumb', p.txt); n.type = 'button'; n.addEventListener('click', p.act); }
else { n = h('span', 'geo-crumb cur', p.txt); n.setAttribute('aria-current', 'page'); }
nav.appendChild(n);
});
ui.back.hidden = !S.cc;
}
function lead() {
var rl = rangeLabel(ctx.range), L = ui.lead;
if (data.error || !data.world) { L.textContent = ''; return; }
var cs = data.world.countries || [];
if (!S.cc) {
var tot = 0, ips = 0;
cs.forEach(function (c) { tot += c.events; ips += c.ips; });
if (!cs.length) { L.textContent = t('geo.lead.empty', { range: rl }); return; }
var top = cs.slice().sort(function (a, b) { return b.events - a.events; })[0];
L.textContent = t('geo.lead.world', { events: unit('events', tot), ips: unit('ips', ips), countries: unit('countries', cs.length),
range: rl, top: countryName(top.cc), pct: pct(top.events / tot) });
return;
}
var d = data.country, cn = countryName(S.cc);
if (!d || !d.events) { L.textContent = t('geo.lead.empty.country', { country: cn, range: rl }); return; }
var base = { country: cn, events: unit('events', d.events), ips: unit('ips', ipCount(d)), range: rl };
if (S.region) {
var c0 = (d.cities || [])[0];
base.region = regionName(S.region);
if (c0 && c0.name) { base.city = c0.name; base.pct = pct(c0.events / d.events); L.textContent = t('geo.lead.region', base); }
else L.textContent = t('geo.lead.region.flat', base);
return;
}
var r0 = ((d.regions || []).filter(function (r) { return r.name; })[0]);
if (r0 && d.regions.length > 1) { base.region = r0.name; base.pct = pct(r0.events / d.events); L.textContent = t('geo.lead.country', base); }
else L.textContent = t('geo.lead.country.flat', base);
}
function colorize() {
var cs = (data.world && data.world.countries) || [], max = 1, by = {};
cs.forEach(function (c) { by[c.cc] = c; if (c.events > max) max = c.events; });
var lm = Math.log(1 + max);
ui.legendMax.textContent = nf(max);
var zoomed = !!S.cc;
ui.svg.setAttribute('class', 'geo-svg' + (zoomed ? ' zoomed' : ''));
Object.keys(ui.paths).forEach(function (cc) {
var p = ui.paths[cc], c = by[cc], cls = 'geo-cn';
if (c) {
cls += ' hit';
p.style.fillOpacity = (0.2 + 0.8 * Math.log(1 + c.events) / lm).toFixed(3);
} else p.style.fillOpacity = '';
if (cc === S.cc) cls += ' sel';
p.setAttribute('class', cls);
});
ui.legend.hidden = zoomed;
if (S.cc) ui.svg.setAttribute('aria-label', t('geo.map.country.label', { country: countryName(S.cc) }));
else ui.svg.setAttribute('aria-label', t('geo.map.label'));
}
function emptyNote(txt) { return h('div', 'geo-empty', txt); }
function row(opts) {
// opts: name, sub, n, frac, onClick, label, pressed, rank, cls
var r = h(opts.onClick ? 'button' : 'div', 'geo-row' + (opts.cls ? ' ' + opts.cls : ''));
if (opts.onClick) {
r.type = 'button'; r.addEventListener('click', opts.onClick);
if (opts.label) r.setAttribute('aria-label', opts.label);
if (opts.pressed != null) r.setAttribute('aria-pressed', opts.pressed ? 'true' : 'false');
}
var top = h('span', 'geo-row-top');
if (opts.rank) top.appendChild(h('span', 'geo-rank', String(opts.rank)));
var nm = h('span', 'geo-name', opts.name); top.appendChild(nm);
if (opts.sub) top.appendChild(h('span', 'geo-sub', opts.sub));
top.appendChild(h('span', 'geo-num', nf(opts.n)));
r.appendChild(top);
var bar = h('span', 'geo-bar'), i = h('i'); i.style.width = Math.max(2, opts.frac * 100) + '%';
bar.appendChild(i); r.appendChild(bar);
return r;
}
function renderSide() {
var L = ui.sideList; clear(L);
if (!S.cc) {
ui.sideH.textContent = t('geo.countries');
var cs = ((data.world && data.world.countries) || []).slice().sort(function (a, b) { return b.events - a.events; });
if (!cs.length) { L.appendChild(emptyNote(t('geo.empty'))); return; }
var max = cs[0].events || 1;
cs.forEach(function (c, i) {
var nm = countryName(c.cc);
L.appendChild(row({ rank: i + 1, name: flagOf(c.cc) + ' ' + nm, n: c.events, frac: c.events / max,
label: t('geo.pick', { name: nm, events: unit('events', c.events) }), onClick: function () { go(c.cc, '', true); } }));
});
return;
}
ui.sideH.textContent = t('geo.regions');
var d = data.full;
var rs = (d && d.regions) || [];
if (!rs.length) { L.appendChild(emptyNote(t('geo.empty.list'))); return; }
if (S.region) {
var all = h('button', 'geo-chip', t('geo.all_regions')); all.type = 'button';
all.addEventListener('click', function () { go(S.cc, '', true); });
L.appendChild(all);
}
var mx = rs[0].events || 1;
rs.forEach(function (r, i) {
var can = !!r.name;
L.appendChild(row({ rank: i + 1, name: regionName(r.name), sub: unit('ips', r.ips), n: r.events, frac: r.events / mx,
cls: S.region === r.name && can ? 'on' : '',
pressed: can ? S.region === r.name : null,
label: can ? t('geo.pick.region', { name: r.name, events: unit('events', r.events) }) : '',
onClick: can ? function () { go(S.cc, S.region === r.name ? '' : r.name, true); } : null }));
});
}
function renderDetail() {
var show = !!S.cc && !!data.country;
ui.detail.hidden = !show;
if (!show) return;
var d = data.country;
// cities
ui.pCities.h.textContent = t('geo.cities');
var B = ui.pCities.body; clear(B);
var cs = d.cities || [];
if (!cs.length) B.appendChild(emptyNote(t('geo.empty.list')));
else {
var mx = cs[0].events || 1, nocoord = 0;
cs.slice(0, 15).forEach(function (c, i) {
var can = !!c.region && !S.region;
var r = row({ rank: i + 1, name: c.name || t('geo.unknown'), sub: c.region || '', n: c.events, frac: c.events / mx,
label: can ? t('geo.city.pick', { name: c.region }) : '', onClick: can ? function () { go(S.cc, c.region, true); } : null });
r.addEventListener('mouseenter', function () { if (cityEls[i]) cityEls[i].classList.add('hl'); });
r.addEventListener('mouseleave', function () { if (cityEls[i]) cityEls[i].classList.remove('hl'); });
B.appendChild(r);
});
cs.forEach(function (c) { if (!isNum(c.lat) || !isNum(c.lon)) nocoord++; });
if (nocoord) B.appendChild(h('div', 'geo-note', t(nocoord === 1 ? 'geo.nocoords.one' : 'geo.nocoords.other', { n: nf(nocoord) })));
}
// categories
ui.pCats.h.textContent = t('geo.cats');
B = ui.pCats.body; clear(B);
var cats = d.cats || {}, keys = Object.keys(cats).sort(function (a, b) { return cats[b] - cats[a]; }), tot = sum(cats);
if (!keys.length || !tot) B.appendChild(emptyNote(t('geo.empty.list')));
else {
var st = h('div', 'geo-stack'); st.setAttribute('aria-hidden', 'true');
keys.forEach(function (k) { var s = h('span', catCls(k)); s.style.flexGrow = String(cats[k]); st.appendChild(s); });
B.appendChild(st);
var ul = h('ul', 'geo-chips');
keys.forEach(function (k) {
var li = h('li', 'geo-chipcat'), dot = h('i', catCls(k)); dot.setAttribute('aria-hidden', 'true');
li.appendChild(dot); li.appendChild(h('span', '', catLabel(k))); li.appendChild(h('b', '', nf(cats[k]) + ' · ' + pct(cats[k] / tot)));
ul.appendChild(li);
});
B.appendChild(ul);
if (d.hostile || d.suspicious) B.appendChild(h('div', 'geo-note', t('geo.hostile_suspicious', { h: nf(d.hostile || 0), s: nf(d.suspicious || 0) })));
}
// ips
ui.pIps.h.textContent = t('geo.ips');
B = ui.pIps.body; clear(B);
var ips = ipList(d);
if (!ips.length) B.appendChild(emptyNote(t('geo.empty.list')));
else ips.slice(0, 12).forEach(function (x) {
var b = h('button', 'geo-ip'); b.type = 'button';
b.setAttribute('aria-label', t('geo.open_ip', { ip: x.ip }));
b.addEventListener('click', function () { U.openIP(x.ip); });
var l1 = h('span', 'geo-ip-l1');
l1.appendChild(h('code', '', x.ip));
var lv = LEVELS[x.level] ? x.level : 'unknown';
l1.appendChild(h('span', 'geo-lv geo-lv-' + lv, t('geo.level.' + lv)));
if (isNum(x.score)) l1.appendChild(h('span', 'geo-score', t('geo.score', { n: nf(x.score) })));
b.appendChild(l1);
var where = [x.city, x.region].filter(Boolean).join(', '), who = [x.asn, x.as_org].filter(Boolean).join(' ');
var l2 = h('span', 'geo-ip-l2', [where, who].filter(Boolean).join(' · '));
b.appendChild(l2);
if (x.last) { var ago = ''; try { ago = U.fmt.ago(x.last); } catch (e) { ago = ''; } if (ago) b.appendChild(h('span', 'geo-ip-l3', String(ago))); }
B.appendChild(b);
});
}
function render(refit) {
if (!ui) return;
paintState();
ui.err.hidden = !data.error;
ui.loading.hidden = true;
crumbs();
if (data.error || !data.world) { lead(); ui.detail.hidden = true; clear(ui.sideList); clear(ui.gCity); ui.legend.hidden = true;
ui.svg.setAttribute('class', 'geo-svg'); setView(targetView());
Object.keys(ui.paths).forEach(function (cc) { ui.paths[cc].style.fillOpacity = ''; ui.paths[cc].setAttribute('class', 'geo-cn'); });
return; }
colorize(); lead(); renderSide(); renderDetail();
clear(ui.gCity); cityEls = [];
var to = targetView();
if (refit === false) { setView(to); drawCities(); }
else animateTo(to, drawCities);
}
// ---------------------------------------------------------------- page
U.registerPage({
id: 'geo',
icon: '<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M3 12h18M12 3c3 3.2 3 14.8 0 18M12 3c-3 3.2-3 14.8 0 18"/></svg>',
titleKey: 'geo.title',
mount: function (el, c) {
ctx = c; lang = c.lang || 'en';
world = U.world || window.URUTAU_WORLD;
alive = true; cache = {}; view = null;
if (!world || !world.paths) { clear(el); el.appendChild(h('div', 'geo-empty', t('geo.error'))); return; }
var p = parseHash(); S.cc = world.paths[p.cc] ? p.cc : ''; S.region = S.cc ? p.region : '';
build(el);
window.addEventListener('hashchange', onHash);
window.addEventListener('popstate', onHash);
document.addEventListener('keydown', onKey);
load(false);
},
update: function (c) {
var langChanged = (c.lang || 'en') !== lang;
ctx = c; lang = c.lang || 'en';
if (!alive || !ui) return;
cache = {};
if (langChanged) { var el = root.parentNode; build(el); }
load(false);
},
unmount: function () {
alive = false; seq++;
cancelAnimationFrame(anim); anim = 0;
window.removeEventListener('hashchange', onHash);
window.removeEventListener('popstate', onHash);
document.removeEventListener('keydown', onKey);
if (ro) { ro.disconnect(); ro = null; }
ui = null; root = null;
}
});
})();
+200 -23
View File
@@ -1,20 +1,48 @@
/* Urutau UI dictionaries. Every key must exist in both languages:
scripts/check-ui-i18n.mjs enforces it. "{n}" is replaced by the caller. */
scripts/check-ui-i18n.mjs enforces it. Placeholders are {n}, {name}...;
scripts registered later add their own keys with Urutau.registerI18n.
This file is loaded in <head>: the first lines below choose the theme and
the language before the first paint, so there is no flash of the wrong theme. */
(function () {
try {
var th = localStorage.getItem('urutau.theme');
if (th === 'light' || th === 'dark') document.documentElement.setAttribute('data-theme', th);
var lg = localStorage.getItem('urutau.lang') || ((navigator.language || 'en').toLowerCase().indexOf('pt') === 0 ? 'pt-BR' : 'en');
document.documentElement.lang = lg === 'pt-BR' ? 'pt-BR' : 'en';
} catch (e) { /* storage blocked: the system preference applies */ }
})();
window.URUTAU_I18N = {
en: {
'tagline': 'Lightweight, always-on threat intelligence for self-hosted servers · local-first · authorized use.',
'live.connecting': 'connecting',
'live.on': 'live',
'live.off': 'reconnecting',
'conn.connecting': 'connecting',
'conn.on': 'live',
'conn.off': 'reconnecting',
'host.label': 'Host',
'host.all': 'All hosts',
'range.label': 'Time range',
'range.1h': '1 h',
'range.24h': '24 h',
'range.7d': '7 d',
'range.long.1h': 'the last hour',
'range.long.24h': 'the last 24 hours',
'range.long.7d': 'the last 7 days',
'lang.toggle': 'Switch language',
'theme.toggle': 'Switch light/dark theme',
'logout': 'Sign out',
'nav.label': 'Main navigation',
'nav.skip': 'Skip to content',
'nav.more': 'More',
'nav.overview': 'Overview',
'nav.threats': 'Threats',
'nav.traffic': 'Traffic',
'nav.ips': 'IPs',
'nav.sources': 'Sources and hosts',
'slice.showing': 'Showing',
'slice.allHosts': 'all hosts',
'slice.host': 'host {name}',
'slice.allDomains': 'all domains',
'slice.domain': 'domain {name}',
'slice.ips': '{n} IPs',
'kpi.requests': 'Requests',
'kpi.malicious': 'Malicious events',
'kpi.hostile': 'Hostile IPs',
@@ -22,14 +50,51 @@ window.URUTAU_I18N = {
'kpi.bans': 'Active bans',
'kpi.ips': 'Distinct IPs',
'kpi.monitoring': '{n} monitoring requests filtered out.',
'kpi.sub.hosts': '{n} of {m} hosts online',
'kpi.sub.malicious': 'HTTP and SSH events',
'kpi.sub.share': '{p} of {n} distinct IPs',
'kpi.sub.bans': 'reported by fail2ban',
'kpi.sub.range': 'in {range}',
'ov.lead.hostile': '{n} hostile IPs in the selected slice',
'ov.lead.hostile.one': '1 hostile IP in the selected slice',
'ov.lead.calm': 'No hostile IPs in the selected slice',
'ov.lead.empty': 'No events recorded in the selected slice',
'ov.lead.body': '{m} malicious events against {r} requests, from {ips} distinct IPs; {b} active bans.',
'ov.lead.bodyEmpty': 'Widen the time range or choose another host. Sources report their state under Sources and hosts.',
'ov.countries': 'Top countries',
'ov.countries.hint': 'Origin of the events in the slice, by number of events.',
'ov.topips': 'Top IPs by score',
'ov.topips.hint': 'Highest threat score in the slice. Select an IP for its history.',
'ov.all': 'View all',
'ov.feed': 'Latest events',
'ov.feed.hint': 'Most recent events, newest first, updated live.',
'th.lead.top': 'Most activity is classified as "{cat}"',
'th.lead.none': 'No attack activity in the selected slice',
'th.lead.noneBody': 'No scanner, exploit, brute force or SSH events were classified in this slice.',
'th.lead.body': '{n} of {m} classified events ({p}).',
'th.lead.domain': 'Most targeted domain: {name}.',
'th.lead.origin': 'Main origin: {name}.',
'tr.lead.some': '{n} visitors viewed {p} pages',
'tr.lead.none': 'No traffic recorded in the selected slice',
'tr.lead.noneBody': 'Analytics count only successful responses to non-bot clients on the configured domains.',
'tr.lead.body': '{r} requests, {b} from search and AI bots; latency p50 {a} ms and p95 {c} ms.',
'ips.lead': '{n} distinct IPs, {h} hostile and {s} suspicious',
'ips.lead.body': '{b} IPs are banned. Select a row for the full history of an IP.',
'src.lead.all': 'All {n} sources are following',
'src.lead.some': '{a} of {n} sources following; {x} need attention',
'src.lead.none': 'No log sources reported',
'src.lead.body': '{h} of {m} hosts online; {l} lines read, {f} malformed.',
'feed.forged': 'forged monitor user agent',
'timeline.title': 'Activity by category',
'timeline.hint': 'Events per time bucket, stacked by category. Select a legend item to hide it.',
'timeline.empty': 'No activity in this range.',
'ips.title': 'Top IPs',
'ips.hint': 'Every IP seen in the slice. Sort by a column heading; select a row for details.',
'ips.search': 'Filter by IP or reverse DNS',
'ips.level': 'Threat level',
'ips.bannedOnly': 'Banned only',
'ips.empty': 'No IPs match.',
'ips.perPage': 'Rows per page',
'ips.empty': 'No IPs match. Clear the filters or widen the time range.',
'level.all': 'All levels',
'level.hostile': 'Hostile',
'level.suspicious': 'Suspicious',
@@ -39,8 +104,11 @@ window.URUTAU_I18N = {
'col.level': 'Level',
'col.cats': 'Categories',
'col.last': 'Last seen',
'col.first': 'First seen',
'col.events': 'Events',
'col.banned': 'Banned',
'col.host': 'Host',
'col.hosts': 'Hosts',
'col.source': 'Source',
'col.state': 'State',
'col.lines': 'Lines',
@@ -49,29 +117,47 @@ window.URUTAU_I18N = {
'pager.prev': 'Previous',
'pager.next': 'Next',
'pager.count': '{n} IPs',
'pager.page': 'Page {n} of {m}',
'feed.title': 'Live feed',
'feed.empty': 'Waiting for events.',
'top.paths': 'Most attacked paths',
'top.domains': 'Most targeted domains',
'top.uas': 'Top user agents',
'top.users': 'SSH users tried',
'top.empty': 'No data.',
'top.empty': 'No data in the selected slice. Try a longer time range.',
'blocklist.title': 'Blocklist',
'blocklist.help': 'Export the IPs at or above a score as a plain list, one per line, for a firewall or fail2ban.',
'blocklist.help': 'Export the IPs at or above a score as a plain list, one per line, for a firewall or fail2ban. Only IPs with strong evidence and a public address are listed.',
'blocklist.minScore': 'Minimum score',
'blocklist.family': 'Address family',
'blocklist.family.all': 'IPv4 and IPv6',
'blocklist.family.4': 'IPv4 only',
'blocklist.family.6': 'IPv6 /64 only',
'blocklist.copy': 'Copy list',
'blocklist.download': 'Download',
'blocklist.download': 'Download .txt',
'blocklist.downloadJson': 'Download .json',
'blocklist.copied': '{n} IPs copied.',
'blocklist.failed': 'Could not copy the list.',
'hosts.title': 'Hosts',
'blocklist.count': '{n} IPs would be listed (last 7 days).',
'hosts.title': 'Hosts and peers',
'hosts.hint': 'This instance and the peers it federates with.',
'host.online': 'online',
'host.offline': 'offline',
'host.self': 'this instance',
'host.requests': 'Requests',
'host.malicious': 'Malicious',
'host.hostile': 'Hostile IPs',
'host.bans': 'Bans',
'host.latency': 'Latency',
'sources.title': 'Sources',
'host.seen': 'Last contact',
'sources.title': 'Log sources',
'sources.hint': 'Files this instance follows. Waiting or error states mean no new events are being read.',
'sources.empty': 'No log source configured on the reporting hosts.',
'src.geo.title': 'Geolocation',
'src.geo.hint': 'Country, city and network of each IP come from a local database; nothing is queried online.',
'src.geo.known': '{n} of {m} listed IPs have a known origin',
'src.geo.countries': '{n} countries in the slice',
'src.geo.attrib': 'Data attribution',
'src.geo.none': 'No attribution reported by the geo database.',
'state.following': 'following',
'state.waiting': 'waiting for file',
'state.backfill': 'reading history',
@@ -94,6 +180,7 @@ window.URUTAU_I18N = {
'ago.d': '{n}d ago',
'never': 'never',
'yes': 'yes',
'detail.title': 'IP details',
'detail.close': 'Close',
'detail.copyIp': 'Copy IP',
'detail.score': 'Score',
@@ -108,13 +195,14 @@ window.URUTAU_I18N = {
'detail.jails': 'Active bans',
'detail.counts': 'Events',
'detail.notfound': 'This IP is no longer in memory.',
'detail.loading': 'Loading.',
'error.load': 'Could not load data. Retrying.',
'error.rate': 'Too many requests. Retrying shortly.',
'footer': 'Urutau · watches motionless all night.',
'tab.threats': 'Threats',
'tab.traffic': 'Traffic',
'traffic.domain': 'Domain',
'traffic.allDomains': 'All domains',
'traffic.timeline': 'Requests and page views',
'traffic.timeline.hint': 'Requests answered per time bucket; the darker bar is the share counted as page views.',
'traffic.requests': 'Requests',
'traffic.pages': 'Page views',
'traffic.visitors': 'Visitors',
@@ -129,8 +217,14 @@ window.URUTAU_I18N = {
'traffic.devices': 'Devices',
'traffic.status': 'Status codes',
'traffic.privacy': 'Visitors are counted with a daily rotating hash kept in memory only. No visitor IP is stored.',
'traffic.sub.visitors': 'distinct, hash per day',
'traffic.sub.requests': 'incl. assets and bots',
'traffic.sub.pages': 'of {n} requests',
'traffic.sub.bots': 'of {n} requests',
'map.attacks': 'Origin of attacks',
'map.attacks.hint': 'Countries shaded by number of events; the list shows the largest.',
'map.visitors': 'Visitors by country',
'map.visitors.hint': 'Countries shaded by number of requests; the list shows the largest.',
'col.origin': 'Origin',
'detail.country': 'Country',
'detail.city': 'City',
@@ -149,18 +243,35 @@ window.URUTAU_I18N = {
},
'pt-BR': {
'tagline': 'Inteligência de ameaças leve e sempre ativa para servidores próprios · local-first · uso autorizado.',
'live.connecting': 'conectando',
'live.on': 'ao vivo',
'live.off': 'reconectando',
'conn.connecting': 'conectando',
'conn.on': 'ao vivo',
'conn.off': 'reconectando',
'host.label': 'Host',
'host.all': 'Todos os hosts',
'range.label': 'Período',
'range.1h': '1 h',
'range.24h': '24 h',
'range.7d': '7 d',
'range.long.1h': 'a última hora',
'range.long.24h': 'as últimas 24 horas',
'range.long.7d': 'os últimos 7 dias',
'lang.toggle': 'Trocar idioma',
'theme.toggle': 'Alternar tema claro/escuro',
'logout': 'Sair',
'nav.label': 'Navegação principal',
'nav.skip': 'Ir para o conteúdo',
'nav.more': 'Mais',
'nav.overview': 'Visão geral',
'nav.threats': 'Ameaças',
'nav.traffic': 'Tráfego',
'nav.ips': 'IPs',
'nav.sources': 'Fontes e hosts',
'slice.showing': 'Exibindo',
'slice.allHosts': 'todos os hosts',
'slice.host': 'host {name}',
'slice.allDomains': 'todos os domínios',
'slice.domain': 'domínio {name}',
'slice.ips': '{n} IPs',
'kpi.requests': 'Requisições',
'kpi.malicious': 'Eventos maliciosos',
'kpi.hostile': 'IPs hostis',
@@ -168,14 +279,51 @@ window.URUTAU_I18N = {
'kpi.bans': 'Bans ativos',
'kpi.ips': 'IPs distintos',
'kpi.monitoring': '{n} requisições de monitoramento filtradas.',
'kpi.sub.hosts': '{n} de {m} hosts online',
'kpi.sub.malicious': 'eventos HTTP e SSH',
'kpi.sub.share': '{p} dos {n} IPs distintos',
'kpi.sub.bans': 'informados pelo fail2ban',
'kpi.sub.range': 'em {range}',
'ov.lead.hostile': '{n} IPs hostis no recorte selecionado',
'ov.lead.hostile.one': '1 IP hostil no recorte selecionado',
'ov.lead.calm': 'Nenhum IP hostil no recorte selecionado',
'ov.lead.empty': 'Nenhum evento registrado no recorte selecionado',
'ov.lead.body': '{m} eventos maliciosos frente a {r} requisições, de {ips} IPs distintos; {b} bans ativos.',
'ov.lead.bodyEmpty': 'Recomenda-se ampliar o período ou escolher outro host. O estado das fontes está em Fontes e hosts.',
'ov.countries': 'Principais países',
'ov.countries.hint': 'Origem dos eventos do recorte, por número de eventos.',
'ov.topips': 'IPs de maior pontuação',
'ov.topips.hint': 'Maiores pontuações de ameaça do recorte. Selecione um IP para ver o histórico.',
'ov.all': 'Ver todos',
'ov.feed': 'Últimos eventos',
'ov.feed.hint': 'Eventos mais recentes primeiro, atualizados ao vivo.',
'th.lead.top': 'A maior parte da atividade é classificada como "{cat}"',
'th.lead.none': 'Nenhuma atividade de ataque no recorte selecionado',
'th.lead.noneBody': 'Nenhum evento de scanner, exploit, força bruta ou SSH foi classificado neste recorte.',
'th.lead.body': '{n} de {m} eventos classificados ({p}).',
'th.lead.domain': 'Domínio mais visado: {name}.',
'th.lead.origin': 'Origem principal: {name}.',
'tr.lead.some': '{n} visitantes em {p} páginas vistas',
'tr.lead.none': 'Nenhum tráfego registrado no recorte selecionado',
'tr.lead.noneBody': 'A análise de tráfego conta apenas respostas bem-sucedidas a clientes que não são bots, nos domínios configurados.',
'tr.lead.body': '{r} requisições, {b} de bots de busca e de IA; latência p50 de {a} ms e p95 de {c} ms.',
'ips.lead': '{n} IPs distintos, {h} hostis e {s} suspeitos',
'ips.lead.body': '{b} IPs estão banidos. Selecione uma linha para ver o histórico completo do IP.',
'src.lead.all': 'As {n} fontes estão sendo acompanhadas',
'src.lead.some': '{a} de {n} fontes acompanhadas; {x} exigem atenção',
'src.lead.none': 'Nenhuma fonte de log informada',
'src.lead.body': '{h} de {m} hosts online; {l} linhas lidas, {f} malformadas.',
'feed.forged': 'user-agent de monitor forjado',
'timeline.title': 'Atividade por categoria',
'timeline.hint': 'Eventos por intervalo de tempo, empilhados por categoria. Selecione um item da legenda para ocultá-lo.',
'timeline.empty': 'Nenhuma atividade neste período.',
'ips.title': 'Principais IPs',
'ips.hint': 'Todos os IPs vistos no recorte. Ordene pelo título da coluna; selecione uma linha para os detalhes.',
'ips.search': 'Filtrar por IP ou DNS reverso',
'ips.level': 'Nível de ameaça',
'ips.bannedOnly': 'Só banidos',
'ips.empty': 'Nenhum IP corresponde.',
'ips.perPage': 'Linhas por página',
'ips.empty': 'Nenhum IP corresponde. Remova os filtros ou amplie o período.',
'level.all': 'Todos os níveis',
'level.hostile': 'Hostil',
'level.suspicious': 'Suspeito',
@@ -185,8 +333,11 @@ window.URUTAU_I18N = {
'col.level': 'Nível',
'col.cats': 'Categorias',
'col.last': 'Visto por último',
'col.first': 'Visto pela primeira vez',
'col.events': 'Eventos',
'col.banned': 'Banido',
'col.host': 'Host',
'col.hosts': 'Hosts',
'col.source': 'Fonte',
'col.state': 'Estado',
'col.lines': 'Linhas',
@@ -195,29 +346,47 @@ window.URUTAU_I18N = {
'pager.prev': 'Anterior',
'pager.next': 'Próxima',
'pager.count': '{n} IPs',
'pager.page': 'Página {n} de {m}',
'feed.title': 'Feed ao vivo',
'feed.empty': 'Aguardando eventos.',
'top.paths': 'Caminhos mais atacados',
'top.domains': 'Domínios mais visados',
'top.uas': 'Principais user-agents',
'top.users': 'Usuários SSH tentados',
'top.empty': 'Sem dados.',
'top.empty': 'Sem dados no recorte selecionado. Recomenda-se ampliar o período.',
'blocklist.title': 'Lista de bloqueio',
'blocklist.help': 'Exporte os IPs a partir de uma pontuação como lista simples, um por linha, para firewall ou fail2ban.',
'blocklist.help': 'Exporta os IPs a partir de uma pontuação como lista simples, um por linha, para firewall ou fail2ban. Somente IPs com evidência forte e endereço público são listados.',
'blocklist.minScore': 'Pontuação mínima',
'blocklist.family': 'Família de endereços',
'blocklist.family.all': 'IPv4 e IPv6',
'blocklist.family.4': 'Somente IPv4',
'blocklist.family.6': 'Somente IPv6 /64',
'blocklist.copy': 'Copiar lista',
'blocklist.download': 'Baixar',
'blocklist.download': 'Baixar .txt',
'blocklist.downloadJson': 'Baixar .json',
'blocklist.copied': '{n} IPs copiados.',
'blocklist.failed': 'Não foi possível copiar a lista.',
'hosts.title': 'Hosts',
'blocklist.count': '{n} IPs seriam listados (últimos 7 dias).',
'hosts.title': 'Hosts e pares',
'hosts.hint': 'Esta instância e os pares com os quais ela se federa.',
'host.online': 'online',
'host.offline': 'offline',
'host.self': 'esta instância',
'host.requests': 'Requisições',
'host.malicious': 'Maliciosos',
'host.hostile': 'IPs hostis',
'host.bans': 'Bans',
'host.latency': 'Latência',
'sources.title': 'Fontes',
'host.seen': 'Último contato',
'sources.title': 'Fontes de log',
'sources.hint': 'Arquivos que esta instância acompanha. Os estados aguardando e erro indicam que nenhum evento novo está sendo lido.',
'sources.empty': 'Nenhuma fonte de log configurada nos hosts informantes.',
'src.geo.title': 'Geolocalização',
'src.geo.hint': 'País, cidade e rede de cada IP vêm de uma base local; nenhuma consulta é feita online.',
'src.geo.known': '{n} de {m} IPs listados têm origem conhecida',
'src.geo.countries': '{n} países no recorte',
'src.geo.attrib': 'Atribuição dos dados',
'src.geo.none': 'Nenhuma atribuição informada pela base de geolocalização.',
'state.following': 'acompanhando',
'state.waiting': 'aguardando arquivo',
'state.backfill': 'lendo histórico',
@@ -240,6 +409,7 @@ window.URUTAU_I18N = {
'ago.d': 'há {n}d',
'never': 'nunca',
'yes': 'sim',
'detail.title': 'Detalhes do IP',
'detail.close': 'Fechar',
'detail.copyIp': 'Copiar IP',
'detail.score': 'Pontos',
@@ -254,13 +424,14 @@ window.URUTAU_I18N = {
'detail.jails': 'Bans ativos',
'detail.counts': 'Eventos',
'detail.notfound': 'Este IP não está mais na memória.',
'detail.loading': 'Carregando.',
'error.load': 'Não foi possível carregar os dados. Tentando de novo.',
'error.rate': 'Requisições demais. Nova tentativa em instantes.',
'footer': 'Urutau · vigia imóvel a noite toda.',
'tab.threats': 'Ameaças',
'tab.traffic': 'Tráfego',
'traffic.domain': 'Domínio',
'traffic.allDomains': 'Todos os domínios',
'traffic.timeline': 'Requisições e páginas vistas',
'traffic.timeline.hint': 'Requisições atendidas por intervalo; a barra mais escura é a parcela contada como página vista.',
'traffic.requests': 'Requisições',
'traffic.pages': 'Páginas vistas',
'traffic.visitors': 'Visitantes',
@@ -275,8 +446,14 @@ window.URUTAU_I18N = {
'traffic.devices': 'Dispositivos',
'traffic.status': 'Códigos de status',
'traffic.privacy': 'Visitantes são contados com um hash que muda todo dia e fica só na memória. Nenhum IP de visitante é guardado.',
'traffic.sub.visitors': 'distintos, hash diário',
'traffic.sub.requests': 'inclui recursos e bots',
'traffic.sub.pages': 'de {n} requisições',
'traffic.sub.bots': 'de {n} requisições',
'map.attacks': 'Origem dos ataques',
'map.attacks.hint': 'Países sombreados pelo número de eventos; a lista mostra os maiores.',
'map.visitors': 'Visitantes por país',
'map.visitors.hint': 'Países sombreados pelo número de requisições; a lista mostra os maiores.',
'col.origin': 'Origem',
'detail.country': 'País',
'detail.city': 'Cidade',
+45 -138
View File
@@ -7,159 +7,66 @@
<title>Urutau</title>
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="stylesheet" href="/style.css">
<link rel="stylesheet" href="/geo.css">
<link rel="stylesheet" href="/live.css">
<script src="/i18n.js"></script>
</head>
<body>
<div class="wrap">
<header class="top">
<div class="brand">
<img src="/logo.png" alt="Urutau" width="44" height="44">
<div><h1>Urutau</h1><small data-i18n="tagline"></small></div>
</div>
<div class="controls">
<span class="live"><span class="dot" id="live-dot"></span><span id="live-text" data-i18n="live.connecting"></span></span>
<select id="host" data-i18n-aria="host.label"></select>
<div class="seg" id="range" role="group" data-i18n-aria="range.label">
<button type="button" data-range="1h" data-i18n="range.1h"></button>
<button type="button" data-range="24h" data-i18n="range.24h"></button>
<button type="button" data-range="7d" data-i18n="range.7d"></button>
<a class="skip" href="#view" data-i18n="nav.skip"></a>
<div class="app" id="app">
<aside class="rail" id="rail">
<a class="rail-brand" href="#/overview">
<img src="/logo.png" alt="" width="36" height="36">
<span class="brand-name">Urutau</span>
</a>
<nav class="nav" id="nav" data-i18n-aria="nav.label"></nav>
<div class="rail-foot"><span id="ver"></span></div>
</aside>
<div class="main">
<header class="topbar">
<a class="top-brand" href="#/overview"><img src="/logo.png" alt="Urutau" width="30" height="30"></a>
<h1 id="page-title"></h1>
<div class="top-actions">
<span class="conn" id="conn"><span class="dot" id="live-dot"></span><span id="live-text" data-i18n="conn.connecting"></span></span>
<button type="button" class="btn" id="lang" data-i18n-aria="lang.toggle">EN</button>
<button type="button" class="btn icon" id="theme" data-i18n-aria="theme.toggle" data-i18n-title="theme.toggle">
<svg viewBox="0 0 24 24" aria-hidden="true"><circle cx="12" cy="12" r="8"/><path d="M12 4v16"/><path d="M12 4a8 8 0 0 1 0 16z" fill="currentColor"/></svg>
</button>
<form method="post" action="/logout"><button class="btn" type="submit" data-i18n="logout"></button></form>
</div>
<button type="button" class="btn" id="lang" data-i18n-aria="lang.toggle">EN</button>
<button type="button" class="btn" id="theme" data-i18n-aria="theme.toggle" data-i18n-title="theme.toggle">&#9680;</button>
<form method="post" action="/logout"><button class="btn" type="submit" data-i18n="logout"></button></form>
</div>
</header>
</header>
<nav class="tabs" role="tablist">
<button type="button" role="tab" id="tab-btn-threats" data-tab="threats" aria-selected="true" data-i18n="tab.threats"></button>
<button type="button" role="tab" id="tab-btn-traffic" data-tab="traffic" aria-selected="false" data-i18n="tab.traffic"></button>
<select id="domain" hidden data-i18n-aria="traffic.domain"></select>
</nav>
<div class="err-banner" id="err" hidden></div>
<div id="tab-threats">
<section class="grid kpis" id="kpis"></section>
<p class="empty mono" id="monitoring"></p>
<section class="panel">
<h2 data-i18n="timeline.title"></h2>
<div class="chart-wrap" id="chart"></div>
<div class="legend" id="legend"></div>
</section>
<section class="panel mt">
<h2 data-i18n="map.attacks"></h2>
<div class="mapbox"><div class="map" id="map-threats"></div><div class="maplist" id="maplist-threats"></div></div>
</section>
<section class="grid cols-main mt">
<div class="panel">
<h2 data-i18n="ips.title"></h2>
<div class="toolbar">
<input type="text" id="q" data-i18n-ph="ips.search" data-i18n-aria="ips.search" autocomplete="off">
<select id="level" data-i18n-aria="ips.level">
<option value="" data-i18n="level.all"></option>
<option value="hostile" data-i18n="level.hostile"></option>
<option value="suspicious" data-i18n="level.suspicious"></option>
<option value="low" data-i18n="level.low"></option>
</select>
<label class="live"><input type="checkbox" id="bannedOnly"> <span data-i18n="ips.bannedOnly"></span></label>
</div>
<table class="stack" id="ips">
<thead><tr>
<th><button type="button" data-sort="ip" data-i18n="col.ip"></button></th>
<th><button type="button" data-sort="score" data-i18n="col.score"></button></th>
<th data-i18n="col.level"></th>
<th data-i18n="col.cats"></th>
<th data-i18n="col.origin"></th>
<th><button type="button" data-sort="last" data-i18n="col.last"></button></th>
<th data-i18n="col.banned"></th>
</tr></thead>
<tbody></tbody>
</table>
<div class="pager">
<span id="count"></span>
<span><button type="button" class="btn" id="prev" data-i18n="pager.prev"></button> <button type="button" class="btn" id="next" data-i18n="pager.next"></button></span>
<div class="slice" id="slice">
<div class="slice-ctl">
<div class="seg" id="range" role="group" data-i18n-aria="range.label">
<button type="button" data-range="1h" data-i18n="range.1h"></button>
<button type="button" data-range="24h" data-i18n="range.24h"></button>
<button type="button" data-range="7d" data-i18n="range.7d"></button>
</div>
<select id="host" data-i18n-aria="host.label"></select>
<select id="domain" hidden data-i18n-aria="traffic.domain"></select>
</div>
<p class="slice-txt" id="slice-text" aria-live="polite"></p>
</div>
<div class="panel">
<h2 data-i18n="feed.title"></h2>
<ul class="feed" id="feed"></ul>
</div>
</section>
<section class="grid cols-3 mt">
<div class="panel"><h2 data-i18n="top.paths"></h2><div id="top-paths"></div></div>
<div class="panel"><h2 data-i18n="top.domains"></h2><div id="top-domains"></div></div>
<div class="panel"><h2 data-i18n="top.uas"></h2><div id="top-uas"></div></div>
</section>
<div class="err-banner" id="err" role="alert" hidden></div>
<section class="grid cols-2 mt">
<div class="panel"><h2 data-i18n="top.users"></h2><div id="top-users"></div></div>
<div class="panel">
<h2 data-i18n="blocklist.title"></h2>
<p class="empty" data-i18n="blocklist.help"></p>
<div class="toolbar">
<label class="live"><span data-i18n="blocklist.minScore"></span> <input type="number" id="minScore" value="50" min="0" step="1"></label>
<button type="button" class="btn primary" id="copyBl" data-i18n="blocklist.copy"></button>
<a class="btn" id="dlBl" href="/api/v1/blocklist.txt?download=1" data-i18n="blocklist.download"></a>
</div>
<div class="empty" id="blMsg" role="status"></div>
</div>
</section>
<main id="view" tabindex="-1"></main>
</div>
<footer class="shell-foot"><span data-i18n="footer"></span><div id="attrib"></div></footer>
</div>
<div id="tab-traffic" hidden>
<section class="grid kpis" id="tkpis"></section>
<section class="panel">
<h2 data-i18n="traffic.timeline"></h2>
<div class="chart-wrap" id="tchart"></div>
<div class="legend"><span class="live"><span class="sw t-req"></span><span data-i18n="traffic.requests"></span></span> <span class="live"><span class="sw t-pages"></span><span data-i18n="traffic.pages"></span></span></div>
</section>
<section class="panel mt">
<h2 data-i18n="map.visitors"></h2>
<div class="mapbox"><div class="map" id="map-traffic"></div><div class="maplist" id="maplist-traffic"></div></div>
</section>
<section class="grid cols-3 mt">
<div class="panel"><h2 data-i18n="traffic.topPages"></h2><div id="t-pages"></div></div>
<div class="panel"><h2 data-i18n="traffic.referrers"></h2><div id="t-refs"></div></div>
<div class="panel"><h2 data-i18n="traffic.cities"></h2><div id="t-cities"></div></div>
</section>
<section class="grid cols-3 mt">
<div class="panel"><h2 data-i18n="traffic.browsers"></h2><div id="t-browsers"></div></div>
<div class="panel"><h2 data-i18n="traffic.oses"></h2><div id="t-oses"></div></div>
<div class="panel"><h2 data-i18n="traffic.devices"></h2><div id="t-devices"></div></div>
</section>
<section class="grid cols-2 mt">
<div class="panel"><h2 data-i18n="traffic.bots"></h2><div id="t-bots"></div></div>
<div class="panel"><h2 data-i18n="traffic.status"></h2><div id="t-status"></div><p class="empty" data-i18n="traffic.privacy"></p></div>
</section>
</div>
<section class="panel mt">
<h2 data-i18n="hosts.title"></h2>
<div class="hosts" id="hosts"></div>
<h2 class="mt" data-i18n="sources.title"></h2>
<table class="stack" id="sources">
<thead><tr>
<th data-i18n="col.host"></th><th data-i18n="col.source"></th><th data-i18n="col.state"></th>
<th data-i18n="col.lines"></th><th data-i18n="col.malformed"></th><th data-i18n="col.lastEvent"></th>
</tr></thead>
<tbody></tbody>
</table>
</section>
<footer><span data-i18n="footer"></span> <span id="ver"></span><div id="attrib"></div></footer>
<nav class="tabbar" id="tabbar" data-i18n-aria="nav.label"></nav>
<div class="more-sheet" id="more" hidden></div>
</div>
<div class="scrim" id="scrim" hidden></div>
<aside id="detail" hidden aria-live="polite"></aside>
<aside id="detail" role="dialog" aria-modal="true" data-i18n-aria="detail.title" hidden></aside>
<script src="/i18n.js"></script>
<script src="/world.js"></script>
<script src="/app.js"></script>
<script src="/geo.js"></script>
<script src="/live.js"></script>
</body>
</html>
+136
View File
@@ -0,0 +1,136 @@
/* Urutau - AO VIVO page. Everything is prefixed lv- (the shell already owns .live, .panel, .btn...). */
.lv {
--lv-gap: 8px;
position: relative; height: clamp(560px, calc(100dvh - 215px), 920px); overflow: hidden;
border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
background:
radial-gradient(900px 420px at 50% 40%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 70%),
linear-gradient(180deg, color-mix(in srgb, var(--bg) 94%, var(--accent)), var(--bg-2));
}
.lv-view { position: absolute; inset: 0; }
.lv-cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: pan-y; outline-offset: -3px; }
.lv-cv.lv-globe { cursor: grab; }
.lv-cv.lv-grab { cursor: grabbing; }
/* toolbar */
.lv-bar { position: absolute; top: 10px; left: 10px; display: flex; flex-wrap: wrap; gap: 6px; z-index: 2; }
.lv-btn {
display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer;
min-height: 36px; min-width: 36px; padding: 6px 12px; border-radius: 10px; font-size: 13px;
background: var(--panel); color: var(--text); border: 1px solid var(--line);
backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.lv-btn:hover { border-color: var(--accent); }
.lv-btn[aria-pressed="true"].lv-pause, .lv-btn[aria-pressed="true"].lv-fs { border-color: var(--accent); color: var(--accent); }
.lv-seg { display: inline-flex; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--panel); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.lv-seg .lv-btn { border: 0; border-radius: 0; background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
.lv-seg .lv-btn[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.lv-ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
/* status notes */
.lv-notes { position: absolute; top: 10px; right: 10px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 52%; z-index: 2; pointer-events: none; }
.lv-note {
font-size: 12px; padding: 4px 10px; border-radius: 999px; color: var(--muted);
background: var(--panel); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.lv-note[hidden], .lv-hint[hidden] { display: none; }
.lv-hint { position: absolute; left: 12px; top: 54px; font-size: 11px; color: var(--muted); pointer-events: none; z-index: 1; }
/* dock of panels */
.lv-dock {
position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 2;
display: flex; align-items: flex-end; gap: var(--lv-gap); overflow-x: auto; overflow-y: hidden; padding-bottom: 2px;
scrollbar-width: thin;
}
.lv-nodock .lv-dock { display: none; }
.lv-card {
background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px;
backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); min-width: 0; flex: 0 0 auto;
}
.lv-card-h {
display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%;
background: none; border: 0; padding: 0 0 6px; cursor: pointer; color: var(--muted); text-align: left;
}
.lv-card-t { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600; }
.lv-card-h .lv-ic { width: 14px; height: 14px; transition: transform .15s; }
.lv-collapsed .lv-card-h { padding-bottom: 0; }
.lv-collapsed .lv-card-h .lv-ic { transform: rotate(-90deg); }
.lv-collapsed .lv-card-b { display: none; }
.lv-card-b { max-height: 128px; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; }
.lv-c-rate { width: 150px; }
.lv-c-cats { width: 310px; }
.lv-c-hosts { width: 160px; }
.lv-c-cty { width: 200px; }
.lv-c-rec { flex: 1 1 340px; min-width: 300px; }
.lv-collapsed { width: auto; flex: 0 0 auto; min-width: 0; }
.lv-c-rec.lv-collapsed { flex: 0 0 auto; min-width: 0; }
.lv-rate-v { font-size: 34px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; color: var(--text); }
.lv-rate-u { font-size: 11px; color: var(--muted); margin: 3px 0 6px; }
.lv-spark { display: block; width: 100%; height: 28px; }
/* category and host chips (legend + filters) */
.lv-k-notfound { --k: var(--cat-notfound); } .lv-k-scanner { --k: var(--cat-scanner); } .lv-k-bruteforce { --k: var(--cat-bruteforce); }
.lv-k-exploit { --k: var(--cat-exploit); } .lv-k-ssh-fail { --k: var(--cat-ssh-fail); } .lv-k-ssh-probe { --k: var(--cat-ssh-probe); }
.lv-k-ban { --k: var(--cat-ban); }
.lv-chips { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 8px; }
.lv-hostchips { grid-template-columns: 1fr; }
.lv-chip {
display: flex; align-items: center; gap: 6px; min-width: 0; padding: 2px 4px; border-radius: 6px;
background: none; border: 0; cursor: pointer; font-size: 12px; color: var(--text); text-align: left; min-height: 24px;
}
.lv-chip:hover { background: var(--field); }
.lv-chip[aria-pressed="false"] { opacity: .4; }
.lv-chip[aria-pressed="false"] .lv-chip-l { text-decoration: line-through; }
.lv-sw { width: 10px; height: 10px; border-radius: 3px; background: var(--k); flex: none; }
.lv-hot .lv-sw { box-shadow: 0 0 0 2px color-mix(in srgb, var(--k) 35%, transparent); }
.lv-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--h, var(--accent)); flex: none; }
.lv-chip-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.lv-chip-n { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 11px; }
.lv-legend { font-size: 11px; color: var(--muted); margin-top: 5px; }
/* countries */
.lv-cty, .lv-rec { list-style: none; margin: 0; padding: 0; }
.lv-cty-i { position: relative; display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 2px 4px; min-height: 20px; }
.lv-cty-n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; position: relative; z-index: 1; }
.lv-cty-v { font-variant-numeric: tabular-nums; color: var(--muted); position: relative; z-index: 1; }
.lv-cty-b { position: absolute; left: 0; bottom: 0; height: 100%; width: var(--w, 0); border-radius: 4px; background: color-mix(in srgb, var(--accent) 18%, transparent); }
/* latest events (also the text alternative of the canvas) */
.lv-ev { display: grid; grid-template-columns: auto auto auto minmax(0, 1fr); align-items: center; gap: 6px; font-size: 11.5px; padding: 2px 0; }
.lv-ev-t { color: var(--muted); font-variant-numeric: tabular-nums; }
.lv-tag {
font-size: 10.5px; padding: 1px 6px; border-radius: 999px; white-space: nowrap;
border: 1px solid var(--k, var(--line)); background: color-mix(in srgb, var(--k, transparent) 20%, transparent);
}
.lv-tag.lv-hot { font-weight: 700; }
.lv-ip { background: none; border: 0; padding: 2px 0; cursor: pointer; color: var(--accent); font: inherit; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; text-decoration: underline dotted; white-space: nowrap; }
.lv-ip:hover { text-decoration: underline; }
.lv-ev-w { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.lv-empty { color: var(--muted); font-size: 12px; list-style: none; padding: 4px; }
.lv-btn:focus-visible, .lv-chip:focus-visible, .lv-card-h:focus-visible, .lv-ip:focus-visible, .lv-cv:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* presentation mode */
.lv-full { height: 100vh; border-radius: 0; border: 0; }
/* narrow screens: the panels become a strip below the map */
@media (max-width: 720px) {
.lv { height: auto; overflow: visible; display: flex; flex-direction: column; }
.lv-full { height: 100vh; overflow: auto; }
.lv-view { position: relative; inset: auto; height: 56vh; min-height: 340px; flex: none; }
.lv-full .lv-view { flex: 1; height: auto; }
.lv-dock { position: static; padding: 8px; border-top: 1px solid var(--line); align-items: stretch; }
.lv-card { flex: 0 0 82vw; width: 82vw; }
.lv-c-rate, .lv-c-cats, .lv-c-hosts, .lv-c-cty, .lv-c-rec { width: 82vw; min-width: 0; flex: 0 0 82vw; }
.lv-collapsed, .lv-c-rec.lv-collapsed { width: 82vw; flex: 0 0 82vw; }
.lv-card-b { max-height: 150px; }
.lv-btn { min-height: 40px; min-width: 40px; }
.lv-notes { top: auto; bottom: 8px; right: 8px; max-width: 80%; }
.lv-hint { top: auto; bottom: 10px; left: 10px; }
.lv-bar { gap: 4px; }
}
@media (prefers-reduced-motion: reduce) {
.lv-card-h .lv-ic { transition: none; }
}
File diff suppressed because it is too large. Load diff
+386 -170
View File
@@ -1,204 +1,420 @@
/* Urutau design system.
One vocabulary of surfaces, lines, text, status and chart colors. Every rule
below consumes these tokens: no component invents its own color, its own
font size or its own card. Dark is the identity theme (the original Urutau
palette); light swaps the values only. The theme is chosen before the first
paint by /i18n.js (loaded in <head>), never by a component. */
:root {
--bg: #070d14; --bg-2: #0b1420; --panel: rgba(13, 25, 38, .82); --line: rgba(148, 188, 205, .16);
--text: #e8f2f4; --muted: #8ea5b0; --accent: #38bdf8; --accent-2: #f0b35b;
--sev-critical: #ef4444; --sev-high: #f97316; --sev-medium: #f59e0b; --sev-low: #10b981; --sev-info: #64748b;
--radius: 16px; --field: rgba(148, 188, 205, .08); --shadow: 0 10px 30px rgba(0, 0, 0, .35);
--c-ssh-probe: #a5b4fc; color-scheme: dark;
/* surfaces, from the application background to the highest element */
--surface-base: #070d14;
--surface-sunken: #050a10;
--surface-panel: #0d1926;
--surface-raised: #13232f;
--surface-overlay: #172b3b;
/* lines and text */
--line: #223546;
--line-strong: #36506a;
--ink: #e8f2f4;
--ink-muted: #9db3bd;
--ink-faint: #7f96a1;
--heading: #f2f8fa;
/* brand */
--accent: #38bdf8;
--accent-soft: #0f2f45;
--on-accent: #04121c;
--signal: #2ee27a;
--rail: #060b11;
--rail-ink: #c4d4db;
--rail-ink-muted: #7f96a1;
--rail-line: #16242f;
--rail-active: #12303f;
--lead-bg: #0c2a3d;
--lead-bg-2: #0b1f30;
--lead-ink: #eef7fa;
--lead-ink-muted: #b4cdd6;
/* status: color with meaning only (danger, warning, ok, info) */
--ok: #34d399;
--ok-soft: #0e3326;
--warn: #f0b35b;
--warn-soft: #3a2b0e;
--danger: #f87171;
--danger-soft: #3d1619;
--info: #60a5fa;
--info-soft: #112c4a;
/* categorical palette for charts: fixed order, series n keeps its color */
--viz-1: #58a6ff;
--viz-2: #3fb950;
--viz-3: #d29922;
--viz-4: #f85149;
--viz-5: #bc8cff;
--viz-6: #39c5cf;
--viz-7: #ff9b4a;
--viz-8: #8b9eb0;
/* event categories, mapped onto the palette */
--cat-ok: var(--viz-2);
--cat-ssh-ok: var(--viz-2);
--cat-notfound: var(--viz-8);
--cat-scanner: var(--viz-3);
--cat-bruteforce: var(--viz-7);
--cat-exploit: var(--viz-4);
--cat-ssh-fail: var(--viz-1);
--cat-ssh-probe: var(--viz-5);
--cat-ban: var(--viz-6);
/* type */
--font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
--font-display: "Avenir Next", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
--font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
/* space and shape */
--s-1: 4px; --s-2: 8px; --s-3: 12px; --s-4: 16px; --s-5: 20px; --s-6: 28px;
--radius: 10px;
--radius-sm: 7px;
--shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 10px 28px rgba(0, 0, 0, .28);
--scrim: rgba(2, 6, 10, .62);
--rail-w: 232px;
color-scheme: dark;
/* compatibility aliases for scripts written against the first version */
--bg: var(--surface-base); --bg-2: var(--surface-sunken); --panel: var(--surface-panel); --text: var(--ink);
--muted: var(--ink-muted); --field: var(--surface-raised); --accent-2: var(--warn);
--sev-critical: var(--danger); --sev-high: var(--viz-7); --sev-medium: var(--warn); --sev-low: var(--ok); --sev-info: var(--ink-faint);
}
:root[data-theme="light"] {
--bg: #f0f4f8; --bg-2: #e2eaf0; --panel: rgba(255, 255, 255, .88); --line: rgba(15, 31, 38, .13);
--text: #0f1f26; --muted: #536b75; --accent: #0284c7; --accent-2: #d97706; --field: rgba(15, 31, 38, .05);
--shadow: 0 10px 30px rgba(15, 31, 38, .10); --c-ssh-probe: #6366f1; color-scheme: light;
--surface-base: #eff3f7;
--surface-sunken: #e2eaf0;
--surface-panel: #ffffff;
--surface-raised: #f4f7fa;
--surface-overlay: #ffffff;
--line: #d6e0e7;
--line-strong: #aebfcb;
--ink: #0f1f26;
--ink-muted: #46606b;
--ink-faint: #5f747d;
--heading: #08222d;
--accent: #0369a1;
--accent-soft: #dcecf7;
--on-accent: #ffffff;
--signal: #16a34a;
--ok: #15803d;
--ok-soft: #dcf3e4;
--warn: #8f5600;
--warn-soft: #fbefd0;
--danger: #c01f2f;
--danger-soft: #fbe4e6;
--info: #1d62c9;
--info-soft: #e1ecfb;
--viz-1: #1f6feb;
--viz-2: #1a7f37;
--viz-3: #9a6700;
--viz-4: #cf222e;
--viz-5: #8250df;
--viz-6: #1b7c83;
--viz-7: #bc4c00;
--viz-8: #6b7f8e;
--shadow: 0 1px 2px rgba(15, 31, 38, .08), 0 8px 24px rgba(15, 31, 38, .07);
--scrim: rgba(15, 31, 38, .45);
color-scheme: light;
}
@media (prefers-color-scheme: light) {
:root:not([data-theme="dark"]) {
--bg: #f0f4f8; --bg-2: #e2eaf0; --panel: rgba(255, 255, 255, .88); --line: rgba(15, 31, 38, .13);
--text: #0f1f26; --muted: #536b75; --accent: #0284c7; --accent-2: #d97706; --field: rgba(15, 31, 38, .05);
--shadow: 0 10px 30px rgba(15, 31, 38, .10); --c-ssh-probe: #6366f1; color-scheme: light;
:root:not([data-theme]) {
--surface-base: #eff3f7; --surface-sunken: #e2eaf0; --surface-panel: #ffffff; --surface-raised: #f4f7fa; --surface-overlay: #ffffff;
--line: #d6e0e7; --line-strong: #aebfcb; --ink: #0f1f26; --ink-muted: #46606b; --ink-faint: #5f747d; --heading: #08222d;
--accent: #0369a1; --accent-soft: #dcecf7; --on-accent: #ffffff; --signal: #16a34a;
--ok: #15803d; --ok-soft: #dcf3e4; --warn: #8f5600; --warn-soft: #fbefd0; --danger: #c01f2f; --danger-soft: #fbe4e6; --info: #1d62c9; --info-soft: #e1ecfb;
--viz-1: #1f6feb; --viz-2: #1a7f37; --viz-3: #9a6700; --viz-4: #cf222e; --viz-5: #8250df; --viz-6: #1b7c83; --viz-7: #bc4c00; --viz-8: #6b7f8e;
--shadow: 0 1px 2px rgba(15, 31, 38, .08), 0 8px 24px rgba(15, 31, 38, .07); --scrim: rgba(15, 31, 38, .45);
color-scheme: light;
}
}
/* ---------------------------------------------------------------- base */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; min-height: 100%; background: var(--bg-2); }
html { -webkit-text-size-adjust: 100%; font-size: 16px; background: var(--surface-base); }
body {
margin: 0; min-height: 100vh; color: var(--text); font: 14px/1.45 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
background: radial-gradient(1100px 500px at 15% 0, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%) no-repeat,
linear-gradient(180deg, var(--bg), var(--bg-2));
overflow-x: hidden;
margin: 0; min-height: 100vh; background: var(--surface-base); color: var(--ink);
font: 400 .9375rem/1.5 var(--font-sans); overflow-x: hidden;
}
a { color: var(--accent); }
a { color: var(--accent); text-underline-offset: 2px; }
button, select, input { font: inherit; color: inherit; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 16px; }
header.top { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 12px; margin-right: auto; min-width: 0; }
.brand img { width: 44px; height: 44px; border-radius: 12px; flex: none; }
.brand h1 { font-size: 20px; margin: 0; letter-spacing: .02em; }
.brand small { display: block; color: var(--muted); font-size: 12px; max-width: 46ch; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn, select, .seg button, input[type="text"], input[type="number"], input[type="password"] {
background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 7px 12px; min-height: 36px;
h1, h2, h3, p, dl, dd, ul { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
[hidden] { display: none !important; }
.mono { font-family: var(--font-mono); font-size: .875rem; }
.num { font-variant-numeric: tabular-nums; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--on-accent); padding: 8px 12px; border-radius: var(--radius-sm); z-index: 100; }
.skip:focus { left: 8px; }
/* ---------------------------------------------------------------- controls */
.btn, select, input[type="text"], input[type="number"], input[type="password"], input[type="search"] {
background: var(--surface-raised); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 6px 12px; min-height: 36px;
}
.btn, .seg button { cursor: pointer; }
.btn:hover, .seg button:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: #04121c; border-color: transparent; font-weight: 600; }
.seg { display: inline-flex; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.seg button { border: 0; border-radius: 0; background: transparent; }
.seg button[aria-pressed="true"] { background: var(--accent); color: #04121c; font-weight: 600; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.live { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sev-info); display: inline-block; flex: none; }
.dot.on { background: var(--sev-low); box-shadow: 0 0 8px var(--sev-low); }
.dot.off { background: var(--sev-critical); }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); margin-bottom: 14px; }
.panel {
background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px;
box-shadow: var(--shadow); backdrop-filter: blur(10px); min-width: 0;
.btn { cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; color: var(--ink); white-space: nowrap; }
.btn:hover:not(:disabled), select:hover { border-color: var(--line-strong); background: var(--surface-overlay); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.btn.icon { width: 36px; padding: 0; }
.btn svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; background: var(--surface-raised); }
.seg button { background: transparent; border: 0; padding: 6px 14px; min-height: 34px; cursor: pointer; color: var(--ink-muted); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { color: var(--ink); background: var(--surface-overlay); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--ink-muted); min-height: 36px; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.linkish { color: var(--accent); cursor: pointer; background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 2px; text-align: left; }
/* ---------------------------------------------------------------- shell */
.app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh; background: linear-gradient(to right, var(--rail) calc(var(--rail-w) - 1px), var(--rail-line) calc(var(--rail-w) - 1px), var(--rail-line) var(--rail-w), transparent var(--rail-w)); }
.rail {
position: sticky; top: 0; height: 100vh; background: var(--rail); border-right: 1px solid var(--rail-line);
display: flex; flex-direction: column; padding: var(--s-4) var(--s-3); gap: var(--s-4); overflow-y: auto;
}
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.kpi .v { font-size: 28px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; margin-top: 4px; }
.kpi.hot .v { color: var(--sev-critical); }
.kpi.warn .v { color: var(--sev-high); }
.cols-2 { grid-template-columns: 1fr 1fr; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.mt { margin-top: 14px; }
.rail-brand { display: flex; align-items: center; gap: var(--s-3); padding: 4px var(--s-2); color: var(--rail-ink); text-decoration: none; }
.rail-brand img, .top-brand img { width: 36px; height: 36px; border-radius: 9px; flex: none; }
.brand-name { font: 700 1.25rem/1 var(--font-display); letter-spacing: .02em; color: #f2f8fa; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
display: flex; align-items: center; gap: var(--s-3); min-height: 40px; padding: 8px var(--s-3); border-radius: var(--radius-sm);
color: var(--rail-ink); text-decoration: none; font-weight: 500; border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--rail-line); }
.nav-item[aria-current="page"] { background: var(--rail-active); color: #fff; border-left-color: var(--accent); }
.nav-ico { width: 20px; height: 20px; flex: none; display: inline-flex; }
.nav-ico svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.rail-foot { margin-top: auto; padding: var(--s-2); color: var(--rail-ink-muted); font-size: .8125rem; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-6);
background: var(--surface-base); border-bottom: 1px solid var(--line);
}
.top-brand { display: none; }
.topbar h1 { font: 700 1.375rem/1.2 var(--font-display); color: var(--heading); margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: var(--s-2); flex: none; }
.conn { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-muted); font-size: .8125rem; margin-right: var(--s-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ink-faint); display: inline-block; flex: none; }
.dot.on { background: var(--signal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--signal) 25%, transparent); }
.dot.off { background: var(--danger); }
.slice { padding: var(--s-3) var(--s-6) 0; display: flex; flex-direction: column; gap: var(--s-2); }
.slice-ctl { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.slice-ctl select { max-width: 100%; }
.slice-txt { color: var(--ink-muted); font-size: .875rem; }
.slice-txt strong { color: var(--ink); font-weight: 600; }
main#view { padding: var(--s-4) var(--s-6) var(--s-6); display: flex; flex-direction: column; gap: var(--s-5); max-width: 1480px; width: 100%; outline: none; }
.err-banner { margin: var(--s-3) var(--s-6) 0; background: var(--danger-soft); border: 1px solid var(--danger); color: var(--ink); border-radius: var(--radius-sm); padding: 8px 12px; }
.shell-foot { margin-top: auto; padding: var(--s-5) var(--s-6) var(--s-6); color: var(--ink-faint); font-size: .8125rem; text-align: center; }
.shell-foot div { margin-top: 4px; }
.tabbar { display: none; }
.more-sheet { display: none; }
/* ---------------------------------------------------------------- primitives */
.lead {
position: relative; overflow: hidden; border-radius: var(--radius); padding: 22px 26px; color: var(--lead-ink);
background: linear-gradient(135deg, var(--lead-bg), var(--lead-bg-2)); border: 1px solid var(--line-strong);
display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--s-5); align-items: center;
}
.lead::after { content: ""; position: absolute; right: -60px; top: -80px; width: 280px; height: 280px; border-radius: 50%; border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent); box-shadow: 0 0 0 44px color-mix(in srgb, var(--accent) 6%, transparent), 0 0 0 88px color-mix(in srgb, var(--accent) 4%, transparent); pointer-events: none; }
.lead h2 { font: 700 1.5rem/1.2 var(--font-display); max-width: 44ch; color: var(--lead-ink); position: relative; z-index: 1; overflow-wrap: anywhere; }
.lead p { margin-top: 8px; color: var(--lead-ink-muted); max-width: 70ch; position: relative; z-index: 1; overflow-wrap: anywhere; }
.lead .pulse { width: 20px; height: 20px; border-radius: 50%; background: var(--signal); box-shadow: 0 0 0 9px color-mix(in srgb, var(--signal) 18%, transparent); position: relative; z-index: 1; }
.lead.tone-danger .pulse { background: var(--danger); box-shadow: 0 0 0 9px color-mix(in srgb, var(--danger) 20%, transparent); }
.lead.tone-neutral .pulse { background: var(--ink-faint); box-shadow: none; }
.panel { background: var(--surface-panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; display: flex; flex-direction: column; }
.panel-h { display: flex; align-items: center; gap: var(--s-3); padding: var(--s-3) var(--s-4) 0; flex-wrap: wrap; }
.panel-h h2 { font: 700 1rem/1.3 var(--font-display); color: var(--heading); margin-right: auto; }
.panel-h .acts { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.panel .hint { padding: 2px var(--s-4) 0; color: var(--ink-muted); font-size: .875rem; }
.panel-b { padding: var(--s-3) var(--s-4) var(--s-4); min-width: 0; flex: 1; }
.grid { display: grid; gap: var(--s-4); }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); }
.grid.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.main-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid > * { min-width: 0; }
.stat { background: var(--surface-panel); border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 0 0 var(--radius) var(--radius); padding: var(--s-3) var(--s-4) var(--s-4); box-shadow: var(--shadow); min-width: 0; }
.stat .l { color: var(--ink-muted); font-size: .875rem; font-weight: 600; }
.stat .v { font: 800 1.875rem/1.1 var(--font-display); color: var(--heading); margin-top: 6px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat .s { color: var(--ink-faint); font-size: .875rem; margin-top: 4px; }
.stat.tone-danger { border-top-color: var(--danger); } .stat.tone-danger .v { color: var(--danger); }
.stat.tone-warn { border-top-color: var(--warn); } .stat.tone-warn .v { color: var(--warn); }
.stat.tone-ok { border-top-color: var(--ok); } .stat.tone-ok .v { color: var(--ok); }
.stat.tone-info { border-top-color: var(--info); } .stat.tone-info .v { color: var(--info); }
.empty { color: var(--ink-muted); padding: var(--s-4) 0; }
.empty strong { display: block; color: var(--ink); font-weight: 600; }
.note { color: var(--ink-muted); font-size: .875rem; }
.badge { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .8125rem; font-weight: 600; border: 1px solid var(--line); white-space: nowrap; background: var(--surface-raised); color: var(--ink-muted); }
.badge.tone-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 55%, transparent); }
.badge.tone-warn { background: var(--warn-soft); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.badge.tone-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 55%, transparent); }
.badge.tone-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 55%, transparent); }
.chip { display: inline-block; margin: 0 4px 2px 0; padding: 0 7px; border-radius: 6px; background: var(--surface-raised); border: 1px solid var(--line); font-size: .8125rem; white-space: nowrap; }
.cat { display: inline-block; padding: 0 8px; border-radius: 6px; font-size: .8125rem; font-weight: 600; color: var(--on-accent); background: var(--ink-faint); white-space: nowrap; }
.cat.c-notfound { background: var(--cat-notfound); } .cat.c-scanner { background: var(--cat-scanner); } .cat.c-bruteforce { background: var(--cat-bruteforce); }
.cat.c-exploit { background: var(--cat-exploit); } .cat.c-ssh-fail { background: var(--cat-ssh-fail); } .cat.c-ssh-probe { background: var(--cat-ssh-probe); }
.cat.c-ban { background: var(--cat-ban); } .cat.c-ssh-ok, .cat.c-ok { background: var(--cat-ok); }
.t-banned { color: var(--warn); font-weight: 600; }
/* bars (top-N lists) */
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 7px 0; border-top: 1px solid var(--line); }
.bar-row:first-child { border-top: 0; padding-top: 0; }
.bar-row .k { overflow-wrap: anywhere; }
.bar-row .n { color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.bar-row .sub { grid-column: 1 / -1; color: var(--ink-muted); font-size: .8125rem; overflow-wrap: anywhere; }
.bar-row .bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--surface-raised); overflow: hidden; }
.bar-row .bar i { display: block; height: 100%; background: var(--accent); }
/* charts */
.chart-wrap { position: relative; }
.chart-wrap svg { width: 100%; height: 230px; display: block; }
.chart-wrap .tip {
position: absolute; pointer-events: none; background: var(--bg-2); border: 1px solid var(--line); border-radius: 10px;
padding: 8px 10px; font-size: 12px; z-index: 5; min-width: 130px; box-shadow: var(--shadow);
}
.tip[hidden] { display: none; }
.chart-wrap svg { width: 100%; height: auto; display: block; }
.tip { position: absolute; pointer-events: none; background: var(--surface-overlay); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 8px 10px; font-size: .8125rem; z-index: 5; min-width: 140px; box-shadow: var(--shadow); }
.tip div { display: flex; justify-content: space-between; gap: 12px; }
.axis { fill: var(--muted); font-size: 10px; }
.axis { fill: var(--ink-faint); font-size: 11px; font-family: var(--font-sans); }
.gridline { stroke: var(--line); stroke-width: 1; }
.hover-col { fill: transparent; }
.hover-col:hover { fill: color-mix(in srgb, var(--text) 8%, transparent); }
.b-notfound { fill: var(--sev-info); } .b-scanner { fill: var(--sev-medium); } .b-bruteforce { fill: var(--sev-high); }
.b-exploit { fill: var(--sev-critical); } .b-ssh-fail { fill: var(--accent); } .b-ssh-probe { fill: var(--c-ssh-probe); }
.b-ban { fill: var(--accent-2); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; }
.legend button { background: none; border: 0; padding: 2px 0; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text); font-size: 12px; }
.legend button[aria-pressed="false"] { opacity: .4; text-decoration: line-through; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw.b-notfound { background: var(--sev-info); } .sw.b-scanner { background: var(--sev-medium); } .sw.b-bruteforce { background: var(--sev-high); }
.sw.b-exploit { background: var(--sev-critical); } .sw.b-ssh-fail { background: var(--accent); } .sw.b-ssh-probe { background: var(--c-ssh-probe); }
.sw.b-ban { background: var(--accent-2); }
.hover-col:hover { fill: color-mix(in srgb, var(--ink) 8%, transparent); }
.b-notfound { fill: var(--cat-notfound); } .b-scanner { fill: var(--cat-scanner); } .b-bruteforce { fill: var(--cat-bruteforce); }
.b-exploit { fill: var(--cat-exploit); } .b-ssh-fail { fill: var(--cat-ssh-fail); } .b-ssh-probe { fill: var(--cat-ssh-probe); } .b-ban { fill: var(--cat-ban); }
.b-treq { fill: var(--accent); fill-opacity: .38; } .b-tpages { fill: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: var(--s-2); }
.legend button, .legend span.li { background: none; border: 0; padding: 4px 0; display: inline-flex; align-items: center; gap: 6px; color: var(--ink); font-size: .875rem; }
.legend button { cursor: pointer; }
.legend button[aria-pressed="false"] { opacity: .45; text-decoration: line-through; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; background: var(--ink-faint); }
.sw.b-notfound { background: var(--cat-notfound); } .sw.b-scanner { background: var(--cat-scanner); } .sw.b-bruteforce { background: var(--cat-bruteforce); }
.sw.b-exploit { background: var(--cat-exploit); } .sw.b-ssh-fail { background: var(--cat-ssh-fail); } .sw.b-ssh-probe { background: var(--cat-ssh-probe); } .sw.b-ban { background: var(--cat-ban); }
.sw.b-treq { background: color-mix(in srgb, var(--accent) 38%, transparent); } .sw.b-tpages { background: var(--accent); }
/* map */
.mapbox { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); gap: var(--s-4); align-items: start; }
.map svg { width: 100%; height: auto; display: block; }
.mapc { fill: var(--surface-raised); stroke: var(--line); stroke-width: .6; }
.mapc.hit { fill: var(--danger); }
.map.good .mapc.hit { fill: var(--accent); }
/* tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 6px 8px; white-space: nowrap; }
th { text-align: left; font: 600 .75rem/1.2 var(--font-mono); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-muted); padding: 8px 10px; white-space: nowrap; border-bottom: 2px solid var(--line-strong); }
th button { background: none; border: 0; padding: 0; cursor: pointer; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; }
td { padding: 8px; border-top: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
th button:hover { color: var(--ink); }
th[aria-sort="ascending"] button::after { content: " \25B2"; font-size: .7em; }
th[aria-sort="descending"] button::after { content: " \25BC"; font-size: .7em; }
td { padding: 7px 10px; border-top: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
tr.row { cursor: pointer; }
tr.row:hover td, tr.row:focus-visible td { background: var(--field); }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid transparent; white-space: nowrap; }
.lv-hostile { background: color-mix(in srgb, var(--sev-critical) 22%, transparent); color: var(--sev-critical); border-color: var(--sev-critical); }
.lv-suspicious { background: color-mix(in srgb, var(--sev-medium) 20%, transparent); color: var(--sev-medium); border-color: var(--sev-medium); }
.lv-low { background: color-mix(in srgb, var(--sev-low) 16%, transparent); color: var(--sev-low); border-color: var(--sev-low); }
.chip { display: inline-block; margin: 0 4px 2px 0; padding: 0 6px; border-radius: 6px; background: var(--field); font-size: 11px; white-space: nowrap; }
.banned { color: var(--accent-2); font-weight: 600; }
.bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 10px; padding: 5px 0; border-top: 1px solid var(--line); }
.bar-row:first-of-type { border-top: 0; }
.bar-row .k { overflow-wrap: anywhere; }
.bar-row .n { color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-row .bar { grid-column: 1 / -1; height: 3px; border-radius: 2px; background: var(--field); overflow: hidden; }
.bar-row .bar i { display: block; height: 100%; background: var(--accent); }
.empty { color: var(--muted); padding: 8px 0; }
.feed { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow-y: auto; }
.feed li { padding: 6px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 2px 8px; align-items: baseline; }
.feed li:first-child { border-top: 0; }
.feed .t { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.feed .what { grid-column: 1 / -1; color: var(--muted); font-size: 12.5px; overflow-wrap: anywhere; }
.feed a, .linkish { color: var(--accent); cursor: pointer; background: none; border: 0; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
.cat { display: inline-block; padding: 0 7px; border-radius: 6px; font-size: 11px; font-weight: 600; color: #04121c; }
.cat.b-notfound { background: var(--sev-info); color: #fff; } .cat.b-scanner { background: var(--sev-medium); } .cat.b-bruteforce { background: var(--sev-high); }
.cat.b-exploit { background: var(--sev-critical); color: #fff; } .cat.b-ssh-fail { background: var(--accent); } .cat.b-ssh-probe { background: var(--c-ssh-probe); }
.cat.b-ban { background: var(--accent-2); } .cat.b-ssh-ok { background: var(--sev-low); } .cat.b-ok { background: var(--sev-low); }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.toolbar input[type="text"] { flex: 1 1 140px; min-width: 0; }
.toolbar input[type="number"] { width: 84px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.hosts { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.host { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.host h3 { margin: 0 0 4px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.host .meta { color: var(--muted); font-size: 12px; }
.host dl { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; margin: 8px 0 0; font-size: 12.5px; }
.host dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.host dt { color: var(--muted); }
.st-following, .st-ok { color: var(--sev-low); } .st-waiting, .st-backfill { color: var(--sev-medium); } .st-error { color: var(--sev-critical); }
tr.row:hover td, tr.row:focus-visible td { background: var(--surface-raised); }
td.nw, td.nw * { white-space: nowrap; overflow-wrap: normal; }
.origin { display: block; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td small { display: block; color: var(--ink-muted); font-size: .8125rem; overflow-wrap: anywhere; }
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; margin-bottom: var(--s-3); }
.toolbar input[type="text"], .toolbar input[type="search"] { flex: 1 1 180px; min-width: 0; }
.toolbar input[type="number"] { width: 90px; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); margin-top: var(--s-3); color: var(--ink-muted); font-size: .875rem; flex-wrap: wrap; }
.pager .btns { display: flex; gap: var(--s-2); align-items: center; }
/* feed */
.feed { list-style: none; padding: 0; max-height: 420px; overflow-y: auto; }
.feed li { padding: 7px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: auto auto minmax(0, 1fr); gap: 2px 8px; align-items: baseline; }
.feed li:first-child { border-top: 0; padding-top: 0; }
.feed .t { color: var(--ink-muted); font-size: .8125rem; font-variant-numeric: tabular-nums; }
.feed .what { grid-column: 1 / -1; color: var(--ink-muted); font-size: .875rem; overflow-wrap: anywhere; }
.feed li.empty { display: block; }
/* hosts and sources */
.hosts { display: grid; gap: var(--s-3); grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.host { border: 1px solid var(--line); border-radius: var(--radius); padding: var(--s-3) var(--s-4); background: var(--surface-raised); }
.host h3 { font: 700 1rem/1.3 var(--font-display); display: flex; align-items: center; gap: 8px; color: var(--heading); overflow-wrap: anywhere; }
.host .meta { color: var(--ink-muted); font-size: .875rem; margin-top: 2px; overflow-wrap: anywhere; }
.host dl { display: grid; grid-template-columns: 1fr auto; gap: 3px 8px; margin: 10px 0 0; font-size: .875rem; }
.host dd { text-align: right; font-variant-numeric: tabular-nums; }
.host dt { color: var(--ink-muted); }
.st-following { color: var(--ok); } .st-waiting, .st-backfill { color: var(--warn); } .st-error { color: var(--danger); } .st-disabled { color: var(--ink-muted); }
.kv { display: grid; grid-template-columns: minmax(120px, auto) minmax(0, 1fr); gap: 6px var(--s-4); }
.kv dt { color: var(--ink-muted); } .kv dd { overflow-wrap: anywhere; }
/* drawer */
.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 40; }
aside#detail {
position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); background: var(--bg-2); border-left: 1px solid var(--line);
box-shadow: var(--shadow); z-index: 20; padding: 18px 16px; overflow-y: auto; overflow-x: hidden;
position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); background: var(--surface-panel); border-left: 1px solid var(--line-strong);
box-shadow: var(--shadow); z-index: 50; padding: var(--s-4); overflow-y: auto; overflow-x: hidden;
}
aside#detail[hidden] { display: none; }
aside#detail h2 { font-size: 18px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 0; overflow-wrap: anywhere; }
aside#detail dl { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 6px 10px; margin: 14px 0; }
aside#detail dt { color: var(--muted); }
aside#detail dd { margin: 0; overflow-wrap: anywhere; }
aside#detail ul { margin: 0; padding-left: 16px; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 15; }
.scrim[hidden] { display: none; }
footer { color: var(--muted); font-size: 12px; text-align: center; padding: 20px 0 6px; }
.err-banner { background: color-mix(in srgb, var(--sev-critical) 18%, transparent); border: 1px solid var(--sev-critical); border-radius: 10px; padding: 8px 12px; margin-bottom: 12px; }
.err-banner[hidden] { display: none; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
aside#detail .dh { display: flex; align-items: center; gap: var(--s-2); flex-wrap: wrap; margin-bottom: var(--s-3); }
aside#detail h2 { font: 700 1.25rem/1.2 var(--font-mono); color: var(--heading); margin-right: auto; overflow-wrap: anywhere; }
aside#detail .kv { margin: var(--s-3) 0; grid-template-columns: 112px minmax(0, 1fr); }
aside#detail ul { padding-left: 16px; }
aside#detail li { overflow-wrap: anywhere; margin-bottom: 2px; }
/* ---------------------------------------------------------------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: var(--s-4); }
.login .panel { width: min(400px, 100%); padding: 26px 22px; text-align: center; }
.login img { width: 84px; height: 84px; border-radius: 20px; }
.login h1 { margin: 10px 0 2px; }
.login p { color: var(--muted); margin: 0 0 16px; }
.login img { width: 84px; height: 84px; border-radius: 20px; margin: 0 auto; }
.login h1 { margin: 10px 0 2px; font: 700 1.5rem/1.2 var(--font-display); color: var(--heading); }
.login p { color: var(--ink-muted); margin: 0 0 16px; }
.login form { display: grid; gap: 10px; }
.login .msg { color: var(--sev-critical); min-height: 1.4em; }
.login .controls { justify-content: center; margin-top: 14px; }
.login .msg { color: var(--danger); min-height: 1.4em; }
.login .controls { display: flex; justify-content: center; gap: var(--s-2); margin-top: 14px; }
/* ---------------------------------------------------------------- responsive */
@media (max-width: 1180px) {
.app { --rail-w: 68px; }
.rail { padding: var(--s-3) var(--s-2); align-items: center; }
.brand-name, .nav-label, .rail-foot { display: none; }
.nav-item { justify-content: center; padding: 8px; border-left: 0; width: 44px; }
.nav-item[aria-current="page"] { box-shadow: inset 3px 0 0 var(--accent); }
.grid.g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
.cols-main, .cols-3 { grid-template-columns: 1fr; }
.cols-2 { grid-template-columns: 1fr; }
.grid.g2, .grid.g3, .grid.main-side, .mapbox { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
.wrap { padding: 12px; }
.brand small { display: none; }
.kpi .v { font-size: 24px; }
.app { display: block; padding-bottom: 68px; }
.rail { display: none; }
.app { background: none; }
.topbar { padding: var(--s-2) var(--s-4); gap: var(--s-2); }
.top-brand { display: inline-flex; }
.top-brand img { width: 30px; height: 30px; }
.topbar h1 { font-size: 1.125rem; }
.conn span:not(.dot) { display: none; }
.conn { margin-right: 0; }
.slice { padding: var(--s-3) var(--s-4) 0; }
main#view { padding: var(--s-3) var(--s-4) var(--s-5); gap: var(--s-4); }
.err-banner { margin: var(--s-3) var(--s-4) 0; }
.shell-foot { padding: var(--s-4); }
.lead { padding: 18px; grid-template-columns: 1fr; }
.lead .pulse { display: none; }
.lead h2 { font-size: 1.25rem; }
.grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s-3); }
.stat { padding: var(--s-3); } .stat .v { font-size: 1.5rem; }
.tabbar {
display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
background: var(--rail); border-top: 1px solid var(--rail-line); padding: 4px 4px max(4px, env(safe-area-inset-bottom));
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: 56px; border: 0; background: none; color: var(--rail-ink); text-decoration: none; font-size: .75rem; border-radius: var(--radius-sm); cursor: pointer; padding: 4px 2px; }
.tab .nav-ico svg { width: 22px; height: 22px; }
.tab span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab[aria-current="page"], .tab[aria-expanded="true"] { background: var(--rail-active); color: #fff; }
.more-sheet { position: fixed; left: 0; right: 0; bottom: 68px; z-index: 31; background: var(--surface-overlay); border-top: 1px solid var(--line-strong); border-radius: 14px 14px 0 0; padding: var(--s-3); box-shadow: var(--shadow); }
.more-sheet:not([hidden]) { display: block; }
.more-sheet a { display: flex; align-items: center; gap: var(--s-3); min-height: 48px; padding: 8px var(--s-3); color: var(--ink); text-decoration: none; border-radius: var(--radius-sm); }
.more-sheet a[aria-current="page"] { background: var(--accent-soft); }
.more-sheet .nav-ico { color: var(--accent); }
.tbl-wrap { overflow: visible; }
table.stack thead { display: none; }
table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
table.stack tr { border-top: 1px solid var(--line); padding: 8px 0; }
table.stack tr:first-child { border-top: 0; }
table.stack td { border: 0; padding: 2px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; text-align: left; flex: none; }
table.stack td::before { content: attr(data-label); color: var(--ink-muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; text-align: left; flex: none; }
table.stack td > * { min-width: 0; }
.chart-wrap svg { height: 190px; }
table.stack td.nw, table.stack td.nw * { white-space: normal; }
.origin { max-width: none; white-space: normal; }
.kv { grid-template-columns: 1fr; gap: 0; }
.kv dt { margin-top: 8px; }
aside#detail .kv { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
#ips td:first-child, #ips td:nth-child(2), #sources td:nth-child(-n+2), #sources td:nth-child(n+4) { white-space: nowrap; overflow-wrap: normal; }
@media (max-width: 720px) {
#ips td, #sources td { white-space: normal !important; max-width: none !important; }
#ips td:first-child { font-weight: 600; }
}
.tabs { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 14px; }
.tabs button[role="tab"] { background: var(--field); border: 1px solid var(--line); border-radius: 10px; padding: 8px 18px; cursor: pointer; font-weight: 600; }
.tabs button[aria-selected="true"] { background: var(--accent); color: #04121c; border-color: transparent; }
.tabs select { margin-left: auto; max-width: 100%; }
.tabs select[hidden] { display: none; }
.mapbox { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 1fr); gap: 14px; align-items: start; }
.map svg { width: 100%; height: auto; display: block; }
.mapc { fill: var(--field); stroke: var(--line); stroke-width: .6; }
.mapc.hit { fill: var(--sev-critical); stroke: var(--line); }
.map.good .mapc.hit { fill: var(--accent); }
.maplist .bar-row { padding: 4px 0; }
.sw.t-req { background: color-mix(in srgb, var(--accent) 38%, transparent); }
.sw.t-pages { background: var(--accent); }
.b-treq { fill: color-mix(in srgb, var(--accent) 38%, transparent); }
.b-tpages { fill: var(--accent); }
.bar-row .sub { grid-column: 1 / -1; color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }
.origin { display: block; }
.origin small, td small { display: block; color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }
footer #attrib { margin-top: 4px; opacity: .8; }
@media (max-width: 960px) { .mapbox { grid-template-columns: 1fr; } }
/* compact IP table: one line per IP on desktop */
#ips td { padding: 5px 8px; }
#ips .origin { display: block; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#ips td:nth-child(4) { white-space: nowrap; }
#ips td:nth-child(4) .chip { margin-bottom: 0; }
@media (max-width: 720px) {
#ips .origin { max-width: none; white-space: normal; }
}