diff options
-rw-r--r-- | README.rst | 3 | ||||
-rw-r--r-- | gateways.go | 15 | ||||
-rw-r--r-- | main.go | 17 |
3 files changed, 23 insertions, 12 deletions
@@ -26,7 +26,8 @@ You can use ``geoipupdate`` to download MaxMind's City database:: Usage ----------------------- - +-api <tld> + domain for the api. Default: black.riseup.net -geodb <path> path to the GeoLite2-City database (default is "/var/lib/GeoIP/GeoLite2-City.mmdb") -port <port> diff --git a/gateways.go b/gateways.go index 05220c3..c4597a0 100644 --- a/gateways.go +++ b/gateways.go @@ -21,16 +21,10 @@ import ( "net/http" ) -const ( - // yes, I am cheating. The config file is also exposed on the top-level - // domain, which is served behind a letsencrypt certificate. this saves passing - // the certificate for the ca etc. - eipAPI = "https://black.riseup.net/1/config/eip-service.json" -) - type bonafide struct { client *http.Client eip *eipService + eipAPI string } type eipService struct { @@ -55,9 +49,10 @@ type coordinates struct { Longitude float64 } -func newBonafide() *bonafide { +func newBonafide(apiDomain string) *bonafide { client := &http.Client{} - return &bonafide{client, nil} + eipAPI := apiDomain + "/3/config/eip-service.json" + return &bonafide{client, nil, eipAPI} } func (b *bonafide) getGateways() ([]gateway, error) { @@ -71,7 +66,7 @@ func (b *bonafide) getGateways() ([]gateway, error) { } func (b *bonafide) fetchEipJSON() error { - resp, err := b.client.Post(eipAPI, "", nil) + resp, err := b.client.Post(b.eipAPI, "", nil) if err != nil { return err } @@ -36,6 +36,13 @@ import ( "github.com/tidwall/cities" ) +const ( + // The config file is also exposed on the top-level + // domain, which is served behind a letsencrypt certificate. this saves passing + // the certificate for the ca etc. + apiForRiseup = "https://black.riseup.net" +) + func floatToString(num float64) string { return strconv.FormatFloat(num, 'f', 6, 64) } @@ -213,6 +220,7 @@ func main() { var port = flag.Int("port", 9001, "port where the service listens on") var metricsPort = flag.Int("metricsPort", 9002, "port where the metrics server listens on") var dbpath = flag.String("geodb", "/var/lib/GeoIP/GeoLite2-City.mmdb", "path to the GeoLite2-City database") + var api = flag.String("api", "", "API to fetch eip-service.json from (default: black.riseup.net)") var notls = flag.Bool("notls", false, "disable TLS on the service") var key = flag.String("server_key", "", "path to the key file for TLS") var crt = flag.String("server_crt", "", "path to the cert file for TLS") @@ -234,6 +242,13 @@ func main() { } } + var configuredAPI string + if *api == "" { + configuredAPI = apiForRiseup + } else { + configuredAPI = "https://" + *api + } + db, err := geoip2.Open(*dbpath) if err != nil { log.Fatal(err) @@ -244,7 +259,7 @@ func main() { geoipdb := geodb{db, forbidden, nil, nil, nil, &earth} log.Println("Seeding gateway list...") - bonafide := newBonafide() + bonafide := newBonafide(configuredAPI) bonafide.getGateways() geoipdb.geolocateGateways(bonafide) |