Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# CHANGELOG

## v2.2.1 (25 September 2026)

### Home

- Redesigned overview: status tiles for protection, devices, blocklist size and HTTPS inspection, a last-24-hours activity panel, setup progress and device connection details
- Device identity uses MAC address first, then DNS hostname, then IPv4 when no stronger identity is available
- Decision logs can show user-defined device names while retaining the client IP, and device-modal activity now refreshes live
- Removed outdated explanatory text and unused instruction components

### Stats

- Stats now come from the decision log, with a 24 hour / 7 day window selector
- New figures: block rate, active clients, distinct domains, inspection errors, requests over time, most requested domains, blocks by policy, and traffic by layer and outcome
- Live proxy traffic reports upload, download, and total bytes handled since GateSentry started
- `/decisions/summary` accepts `?days=N` and reports unique clients and domains, top domains, blocks by policy and an hourly/daily timeline

## v2.2.0 (24 September 2026)

### HTTPS inspection
Expand Down
26 changes: 15 additions & 11 deletions application/dns/discovery/mdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,20 +260,28 @@ func (b *MDNSBrowser) processEntry(entry *bonjour.ServiceEntry) {
return
}

// Try to find an existing device to enrich
var existing *Device
// Associate the observation using the most stable available identity:
// MAC address, then hostname, then the current IP address.
mac := ""
if ipv4 != "" {
existing = b.store.FindDeviceByIP(ipv4)
mac = LookupARPEntry(ipv4)
}
if existing == nil && ipv6 != "" {
existing = b.store.FindDeviceByIP(ipv6)
var existing *Device
if mac != "" {
existing = b.store.FindDeviceByMAC(mac)
}
if existing == nil && hostname != "" {
existing = b.store.FindDeviceByHostname(hostname)
}
if existing == nil && instanceName != "" {
existing = b.store.FindDeviceByHostname(instanceName)
}
if existing == nil && ipv4 != "" {
existing = b.store.FindDeviceByIP(ipv4)
}
if existing == nil && ipv6 != "" {
existing = b.store.FindDeviceByIP(ipv6)
}

// Build the device struct for upsert
device := &Device{
Expand Down Expand Up @@ -310,12 +318,8 @@ func (b *MDNSBrowser) processEntry(entry *bonjour.ServiceEntry) {
}
}

// Attempt MAC lookup from ARP cache if we have an IPv4 address
if device.IPv4 != "" {
mac := LookupARPEntry(device.IPv4)
if mac != "" {
device.MACs = []string{mac}
}
if mac != "" {
device.MACs = []string{mac}
}

deviceID := b.store.UpsertDevice(device)
Expand Down
16 changes: 9 additions & 7 deletions application/dns/discovery/passive.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,14 @@ func (ds *DeviceStore) ObservePassiveQuery(clientIP string) {
return
}

existing := ds.FindDeviceByIP(clientIP)
if existing != nil {
ds.TouchDevice(existing.ID)
return
}

mac := LookupARPEntry(clientIP)

// Associate observations by the most stable identity available: MAC first,
// then an already-known address. Hostname-aware sources add the hostname
// fallback before reaching the address fallback.
if mac != "" {
existingByMAC := ds.FindDeviceByMAC(mac)
if existingByMAC != nil {
// Known device, new IP — update the address
if net.ParseIP(clientIP).To4() != nil {
ds.UpdateDeviceIP(existingByMAC.ID, clientIP, "")
} else {
Expand All @@ -42,6 +38,12 @@ func (ds *DeviceStore) ObservePassiveQuery(clientIP string) {
}
}

existing := ds.FindDeviceByIP(clientIP)
if existing != nil {
ds.TouchDevice(existing.ID)
return
}

// New device, unknown MAC — create a passive entry
now := time.Now()
device := &Device{
Expand Down
35 changes: 16 additions & 19 deletions application/dns/discovery/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,43 +96,40 @@ func TestReverseIPv6Invalid(t *testing.T) {
// --- Device.GetDisplayName tests ---

func TestDeviceGetDisplayName(t *testing.T) {
// ManualName takes priority
d := &Device{ManualName: "My Device", Hostnames: []string{"host1"}}
// A manual name is the only label that overrides stable identity.
d := &Device{ManualName: "My Device", MACs: []string{"aa:bb:cc:dd:ee:ff"}, Hostnames: []string{"host1"}}
if d.GetDisplayName() != "My Device" {
t.Errorf("Expected ManualName, got %q", d.GetDisplayName())
}

// DisplayName next
d = &Device{DisplayName: "Display", Hostnames: []string{"host1"}}
if d.GetDisplayName() != "Display" {
t.Errorf("Expected DisplayName, got %q", d.GetDisplayName())
// MAC address is the preferred automatic label.
d = &Device{DisplayName: "stale name", MACs: []string{"aa:bb:cc:dd:ee:ff"}, Hostnames: []string{"host1"}}
if d.GetDisplayName() != "aa:bb:cc:dd:ee:ff" {
t.Errorf("Expected MAC label, got %q", d.GetDisplayName())
}

// Hostname next
d = &Device{Hostnames: []string{"host1"}}
// A hostname is used when no MAC is known.
d = &Device{Hostnames: []string{"host1"}, IPv4: "192.168.1.1"}
if d.GetDisplayName() != "host1" {
t.Errorf("Expected hostname, got %q", d.GetDisplayName())
}

// mDNS name next
d = &Device{MDNSNames: []string{"printer._http._tcp"}}
// DNSName and mDNS names are hostname fallbacks.
d = &Device{DNSName: "printer", IPv4: "192.168.1.1"}
if d.GetDisplayName() != "printer" {
t.Errorf("Expected DNS name, got %q", d.GetDisplayName())
}
d = &Device{MDNSNames: []string{"printer._http._tcp"}, IPv4: "192.168.1.1"}
if d.GetDisplayName() != "printer._http._tcp" {
t.Errorf("Expected mDNS name, got %q", d.GetDisplayName())
}

// MAC fallback
d = &Device{MACs: []string{"aa:bb:cc:dd:ee:ff"}}
if d.GetDisplayName() != "Unknown (aa:bb:cc:dd:ee:ff)" {
t.Errorf("Expected MAC fallback, got %q", d.GetDisplayName())
}

// IPv4 fallback
// IPv4 is the final automatic fallback.
d = &Device{IPv4: "192.168.1.1"}
if d.GetDisplayName() != "Unknown (192.168.1.1)" {
if d.GetDisplayName() != "192.168.1.1" {
t.Errorf("Expected IPv4 fallback, got %q", d.GetDisplayName())
}

// Ultimate fallback
d = &Device{}
if d.GetDisplayName() != "Unknown" {
t.Errorf("Expected Unknown, got %q", d.GetDisplayName())
Expand Down
19 changes: 10 additions & 9 deletions application/dns/discovery/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,30 @@ type Device struct {
Persistent bool `json:"persistent"`
}

// GetDisplayName returns the best available name for this device.
// Priority: ManualName > first Hostname > first MDNSName > "Unknown (<MAC>)" > "Unknown (<IPv4>)"
// GetDisplayName returns the most stable available label for this device.
// A user-assigned name always wins. Automatic labels prefer MAC identity,
// followed by a DNS hostname and finally the current IP address.
func (d *Device) GetDisplayName() string {
if d.ManualName != "" {
return d.ManualName
}
if d.DisplayName != "" {
return d.DisplayName
if len(d.MACs) > 0 {
return d.MACs[0]
}
if len(d.Hostnames) > 0 {
return d.Hostnames[0]
}
if d.DNSName != "" {
return d.DNSName
}
if len(d.MDNSNames) > 0 {
return d.MDNSNames[0]
}
if len(d.MACs) > 0 {
return "Unknown (" + d.MACs[0] + ")"
}
if d.IPv4 != "" {
return "Unknown (" + d.IPv4 + ")"
return d.IPv4
}
if d.IPv6 != "" {
return "Unknown (" + d.IPv6 + ")"
return d.IPv6
}
return "Unknown"
}
Expand Down
73 changes: 71 additions & 2 deletions application/logger/decisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gatesentry2logger
import (
"encoding/json"
"fmt"
"net"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -152,6 +153,48 @@ type DecisionSummary struct {
TopReasons []DecisionCount `json:"top_reasons"`
AffectedAddresses []DecisionCount `json:"affected_addresses"`
InspectionFailures int `json:"inspection_failures"`
// UniqueClients and UniqueDomains count distinct client addresses and
// hosts seen in the window.
UniqueClients int `json:"unique_clients"`
UniqueDomains int `json:"unique_domains"`
// TopDomains ranks every requested host, blocked or not.
TopDomains []DecisionCount `json:"top_domains"`
// BlocksByGroup counts blocks per policy group ID; the handler names them.
BlocksByGroup []DecisionCount `json:"blocks_by_group"`
// Timeline buckets the window by hour (up to two days) or by day.
Timeline []TimelineBucket `json:"timeline"`
}

// TimelineBucket is one slice of the summary window.
type TimelineBucket struct {
Start int64 `json:"start"`
Total int `json:"total"`
Blocked int `json:"blocked"`
}

// decisionHost reduces a logged URL to its host so proxy URLs and DNS names
// count toward the same domain.
func decisionHost(raw string) string {
host := raw
if i := strings.Index(host, "://"); i >= 0 {
host = host[i+3:]
}
if i := strings.IndexAny(host, "/?#"); i >= 0 {
host = host[:i]
}
if h, _, err := net.SplitHostPort(host); err == nil {
host = h
}
return strings.TrimSuffix(strings.ToLower(host), ".")
}

// timelineStep picks the bucket size for a window: hourly for up to two
// days so a daily view has shape, daily beyond that.
func timelineStep(from, to int64) int64 {
if to-from <= 2*86400 {
return 3600
}
return 86400
}

// DecisionSummary aggregates decisions in the filter window into counts by
Expand All @@ -171,6 +214,14 @@ func (L *Log) DecisionSummary(f DecisionFilter) (DecisionSummary, error) {
blockedDomains := map[string]int{}
reasons := map[string]int{}
addresses := map[string]int{}
domains := map[string]int{}
groups := map[string]int{}
step := timelineStep(from, to)
start := from - from%step
buckets := make([]TimelineBucket, 0, (to-start)/step+1)
for t := start; t <= to; t += step {
buckets = append(buckets, TimelineBucket{Start: t})
}
err := L.Database.View(func(tx *buntdb.Tx) error {
return tx.DescendRange("entries",
"{\"time\":"+gatesentry2utils.Int64toString(to)+"}",
Expand All @@ -184,14 +235,27 @@ func (L *Log) DecisionSummary(f DecisionFilter) (DecisionSummary, error) {
return true
}
s.Total++
blocked := e.Action == string(gatesentryPolicy.ActionDecisionBlock)
if host := decisionHost(e.URL); host != "" {
domains[host]++
}
if blocked && e.GroupID != "" {
groups[e.GroupID]++
}
if i := (e.Time - start) / step; e.Time >= start && int(i) < len(buckets) {
buckets[i].Total++
if blocked {
buckets[i].Blocked++
}
}
if e.Action != "" {
s.ByAction[e.Action]++
}
if e.Layer != "" {
s.ByLayer[e.Layer]++
}
if e.Action == string(gatesentryPolicy.ActionDecisionBlock) && e.URL != "" {
blockedDomains[e.URL]++
if blocked && e.URL != "" {
blockedDomains[decisionHost(e.URL)]++
}
if e.Reason != "" {
reasons[e.Reason]++
Expand All @@ -211,6 +275,11 @@ func (L *Log) DecisionSummary(f DecisionFilter) (DecisionSummary, error) {
s.TopBlockedDomains = topN(blockedDomains, 10)
s.TopReasons = topN(reasons, 10)
s.AffectedAddresses = topN(addresses, 10)
s.UniqueClients = len(addresses)
s.UniqueDomains = len(domains)
s.TopDomains = topN(domains, 10)
s.BlocksByGroup = topN(groups, 10)
s.Timeline = buckets
return s, nil
}

Expand Down
39 changes: 39 additions & 0 deletions application/logger/decisions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,42 @@ func TestDecisionSummaryNilLogger(t *testing.T) {
t.Fatalf("nil logger summary total = %d, want 0", s.Total)
}
}

func TestDecisionSummaryReportsReachAndTimeline(t *testing.T) {
l := newTestLogDecision(t)
time.Sleep(150 * time.Millisecond)
now := time.Now().Unix()
s, err := l.DecisionSummary(DecisionFilter{From: now - 86400})
if err != nil {
t.Fatalf("summary: %v", err)
}
if s.UniqueClients != 2 || s.UniqueDomains != 5 {
t.Fatalf("clients=%d domains=%d, want 2 and 5", s.UniqueClients, s.UniqueDomains)
}
if len(s.TopDomains) == 0 || s.TopDomains[0].Key != "ads.example" {
t.Fatalf("top domains = %+v, want ads.example first", s.TopDomains)
}
if len(s.BlocksByGroup) != 2 || s.BlocksByGroup[0].Key != "kids" || s.BlocksByGroup[0].Count != 2 {
t.Fatalf("blocks by group = %+v, want kids=2 first", s.BlocksByGroup)
}
total, blocked := 0, 0
for _, b := range s.Timeline {
total += b.Total
blocked += b.Blocked
}
if len(s.Timeline) < 24 || total != 6 || blocked != 3 {
t.Fatalf("timeline buckets=%d total=%d blocked=%d, want >=24, 6, 3", len(s.Timeline), total, blocked)
}
}

func TestDecisionHostStripsSchemeAndPath(t *testing.T) {
for in, want := range map[string]string{
"https://www.Example.com:443/a?b": "www.example.com",
"http://site.example/path": "site.example",
"dns.example.": "dns.example",
} {
if got := decisionHost(in); got != want {
t.Fatalf("decisionHost(%q) = %q, want %q", in, got, want)
}
}
}
7 changes: 7 additions & 0 deletions application/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,18 @@ var GSBASEPATH = "/"

// const INSTALLATIONID = "3";
var GSVerString = ""
var proxyTrafficSnapshot func() (uploadBytes, downloadBytes uint64, startedAt time.Time)

func SetGSVer(v string) {
GSVerString = v
}

// SetProxyTrafficSnapshot configures process-lifetime proxy traffic reporting.
// It must be called before Start launches the web server.
func SetProxyTrafficSnapshot(snapshot func() (uploadBytes, downloadBytes uint64, startedAt time.Time)) {
proxyTrafficSnapshot = snapshot
}

func SetInstallationID(a string) {
INSTALLATIONID = a
}
Expand Down
1 change: 1 addition & 0 deletions application/webserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func GSwebserverStart(port int) {
GetInstallationId: R.GetInstallationId,
GetTotalConsumptionData: R.GetTotalConsumptionData,
GetApplicationVersion: R.GetApplicationVersion,
GetProxyTraffic: proxyTrafficSnapshot,
Reload: func() {
if err := R.Init(); err != nil {
fmt.Printf("Unable to reload GateSentry: %v\n", err)
Expand Down
Loading
Loading