From dc1b9f98f2da2121486031edc6189503b531ae87 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 28 May 2024 15:39:05 +0200 Subject: [PATCH] Add support for showing anycast addresses in the UI --- assets/data/img/flags/__.png | Bin 0 -> 461 bytes desktop/angular/docker.sh | 4 ++-- .../app/pages/spn/map-renderer/map-renderer.ts | 2 ++ .../app/shared/netquery/pipes/location.pipe.ts | 3 +++ service/intel/geoip/country_info.go | 12 ++++++++++++ service/intel/geoip/country_info_test.go | 5 +++++ 6 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 assets/data/img/flags/__.png diff --git a/assets/data/img/flags/__.png b/assets/data/img/flags/__.png new file mode 100644 index 0000000000000000000000000000000000000000..38232f4be33ddbb1ff060a0a2d343dcc69a83b21 GIT binary patch literal 461 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbKJV{wqX6XVU3I`u#fXMsm#F#`j) zFbFd;%$g$s6x7R7|^7X?f&di>_ zX!`7VtJiN@ynNN1`HL1VSut_S^h3u^?K^zDsI26atb zAB+zj;O=O6VxP9+Ky62ZP{-f-oge?duQm{M>X|PgSt)tnu6?E=_q7j?U%Ic*J=XKy zzBc*Fo-e}h_>7MkFZ=(0zLN#d(WN(R+QS(b&fiuQ)SBbI5@<7nr>mdKI;Vst0H8ze A-v9sr literal 0 HcmV?d00001 diff --git a/desktop/angular/docker.sh b/desktop/angular/docker.sh index bbd896e78..c0deab8cf 100755 --- a/desktop/angular/docker.sh +++ b/desktop/angular/docker.sh @@ -11,8 +11,8 @@ mnt="$( cd ../.. && pwd )" docker run \ -ti \ --rm \ - -v $mnt:/portmaster-ui \ - -w /portmaster-ui/modules/portmaster \ + -v $mnt:/portmaster \ + -w /portmaster/desktop/angular \ -p 8081:8080 \ node:latest \ npm start -- --host 0.0.0.0 --port 8080 diff --git a/desktop/angular/src/app/pages/spn/map-renderer/map-renderer.ts b/desktop/angular/src/app/pages/spn/map-renderer/map-renderer.ts index bea5ee57e..b794a8cc9 100644 --- a/desktop/angular/src/app/pages/spn/map-renderer/map-renderer.ts +++ b/desktop/angular/src/app/pages/spn/map-renderer/map-renderer.ts @@ -195,6 +195,8 @@ export class MapRendererComponent implements OnInit, AfterViewInit, OnDestroy { data.forEach((country: any) => { this.countryNames[country.properties.iso_a2] = country.properties.name }) + // Add special country values. + this.countryNames["__"] = "Anycast" this.worldGroup.selectAll() .data(data) diff --git a/desktop/angular/src/app/shared/netquery/pipes/location.pipe.ts b/desktop/angular/src/app/shared/netquery/pipes/location.pipe.ts index 522ed86a1..4b53f8fe3 100644 --- a/desktop/angular/src/app/shared/netquery/pipes/location.pipe.ts +++ b/desktop/angular/src/app/shared/netquery/pipes/location.pipe.ts @@ -11,6 +11,9 @@ export class ConnectionLocationPipe implements PipeTransform { return ''; } if (!!conn.country) { + if (conn.country === "__") { + return "Anycast" + } return conn.country; } diff --git a/service/intel/geoip/country_info.go b/service/intel/geoip/country_info.go index 06a87c4e9..3651a5bb6 100644 --- a/service/intel/geoip/country_info.go +++ b/service/intel/geoip/country_info.go @@ -11,6 +11,14 @@ func (l *Location) AddCountryInfo() { return } + // Check for anycast. + if l.IsAnycast { + // Reset data for anycast. + l.Country.Code = "__" + l.Coordinates.Latitude = 0 + l.Coordinates.Longitude = 0 + } + // Get country info. info, ok := countries[l.Country.Code] if !ok { @@ -83,6 +91,10 @@ func init() { } var countries = map[string]CountryInfo{ + "__": { + Name: "Anycast", + Center: Coordinates{AccuracyRadius: earthCircumferenceInKm}, + }, "MN": { Name: "Mongolia", Continent: ContinentInfo{Region: "AS-E"}, diff --git a/service/intel/geoip/country_info_test.go b/service/intel/geoip/country_info_test.go index 57cb6e8fe..a422767b5 100644 --- a/service/intel/geoip/country_info_test.go +++ b/service/intel/geoip/country_info_test.go @@ -9,6 +9,11 @@ func TestCountryInfo(t *testing.T) { t.Parallel() for key, country := range countries { + // Skip special anycast country. + if key == "__" { + continue + } + if key != country.Code { t.Errorf("%s has a wrong country code of %q", key, country.Code) }