summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorkali kaneko (leap communications) <kali@leap.se>2021-08-31 21:32:55 +0200
committerkali kaneko (leap communications) <kali@leap.se>2021-11-09 22:08:06 +0100
commit01ec91df04b079246434952a5d8f34c6d4e3914b (patch)
tree61f921c824a8a138ffa9b7631fe71fdf9ebfb9a0 /main.go
parentba67fe02dbda8c6f0c3b0a46ecf892e9a73846de (diff)
[feat] make api configurable
Diffstat (limited to 'main.go')
-rw-r--r--main.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/main.go b/main.go
index 811e737..0c21c7c 100644
--- a/main.go
+++ b/main.go
@@ -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)