Fix AS detail view and add prefix sorting
- Fix GetASDetails to properly handle timestamp from MAX(last_updated) - Parse timestamp string from SQLite aggregate function result - Add natural sorting of prefixes by IP address in AS detail view - Sort IPv4 and IPv6 prefixes separately by network address - Remove SQL ORDER BY since we're sorting in Go - This fixes the issue where AS detail pages showed no prefixes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -8,6 +9,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -500,6 +502,43 @@ func (s *Server) handleASDetail() http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// Sort prefixes by network address
|
||||
sort.Slice(ipv4Prefixes, func(i, j int) bool {
|
||||
// Parse the prefixes to compare network addresses
|
||||
ipI, netI, _ := net.ParseCIDR(ipv4Prefixes[i].Prefix)
|
||||
ipJ, netJ, _ := net.ParseCIDR(ipv4Prefixes[j].Prefix)
|
||||
|
||||
// Compare by network address first
|
||||
cmp := bytes.Compare(ipI.To4(), ipJ.To4())
|
||||
if cmp != 0 {
|
||||
return cmp < 0
|
||||
}
|
||||
|
||||
// If network addresses are equal, compare by mask length
|
||||
onesI, _ := netI.Mask.Size()
|
||||
onesJ, _ := netJ.Mask.Size()
|
||||
|
||||
return onesI < onesJ
|
||||
})
|
||||
|
||||
sort.Slice(ipv6Prefixes, func(i, j int) bool {
|
||||
// Parse the prefixes to compare network addresses
|
||||
ipI, netI, _ := net.ParseCIDR(ipv6Prefixes[i].Prefix)
|
||||
ipJ, netJ, _ := net.ParseCIDR(ipv6Prefixes[j].Prefix)
|
||||
|
||||
// Compare by network address first
|
||||
cmp := bytes.Compare(ipI.To16(), ipJ.To16())
|
||||
if cmp != 0 {
|
||||
return cmp < 0
|
||||
}
|
||||
|
||||
// If network addresses are equal, compare by mask length
|
||||
onesI, _ := netI.Mask.Size()
|
||||
onesJ, _ := netJ.Mask.Size()
|
||||
|
||||
return onesI < onesJ
|
||||
})
|
||||
|
||||
// Prepare template data
|
||||
data := struct {
|
||||
ASN *database.ASN
|
||||
|
||||
Reference in New Issue
Block a user