Allow manually setting public IP

This commit is contained in:
Anders Pitman committed 2022-01-05 22:49:42 -07:00
1 parent e38dd91657
commit 85902ca944
1 file changed
+17 -10
+17 -10
View File
@@ -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)