From 85902ca944be454eb95d9010376a0927f5d1bf88 Mon Sep 17 00:00:00 2001 From: Anders Pitman Date: Wed, 5 Jan 2022 22:49:42 -0700 Subject: [PATCH] Allow manually setting public IP --- boringproxy.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/boringproxy.go b/boringproxy.go index e2c5648..4cb94e2 100644 --- a/boringproxy.go +++ b/boringproxy.go @@ -51,6 +51,7 @@ func Listen() { httpPort := flagSet.Int("http-port", 80, "HTTP (insecure) port") httpsPort := flagSet.Int("https-port", 443, "HTTPS (secure) port") allowHttp := flagSet.Bool("allow-http", false, "Allow unencrypted (HTTP) requests") + publicIp := flagSet.String("public-ip", "", "Public IP") err := flagSet.Parse(os.Args[2:]) if err != nil { fmt.Fprintf(os.Stderr, "%s: parsing flags: %s\n", os.Args[0], err) @@ -65,21 +66,27 @@ func Listen() { namedropClient := namedrop.NewClient(db, db.GetAdminDomain(), "takingnames.io/namedrop") - ip, err := namedropClient.GetPublicIp() - if err != nil { - fmt.Printf("WARNING: Failed to determine public IP: %s\n", err.Error()) - } else { - err = namedrop.CheckPublicAddress(ip, *httpPort) - if err != nil { - fmt.Printf("WARNING: Failed to access port %d from the internet\n", *httpPort) - } + var ip string - err = namedrop.CheckPublicAddress(ip, *httpsPort) + if *publicIp != "" { + ip = *publicIp + } else { + ip, err = namedropClient.GetPublicIp() if err != nil { - fmt.Printf("WARNING: Failed to access port %d from the internet\n", *httpsPort) + fmt.Printf("WARNING: Failed to determine public IP: %s\n", err.Error()) } } + err = namedrop.CheckPublicAddress(ip, *httpPort) + if err != nil { + fmt.Printf("WARNING: Failed to access %s:%d from the internet\n", ip, *httpPort) + } + + err = namedrop.CheckPublicAddress(ip, *httpsPort) + if err != nil { + fmt.Printf("WARNING: Failed to access %s:%d from the internet\n", ip, *httpsPort) + } + autoCerts := true if *httpPort != 80 || *httpsPort != 443 { fmt.Printf("WARNING: LetsEncrypt only supports HTTP/HTTPS ports 80/443. You are using %d/%d. Disabling automatic certificate management\n", *httpPort, *httpsPort)