diff options
Diffstat (limited to 'cmd/web/util.go')
| -rw-r--r-- | cmd/web/util.go | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/cmd/web/util.go b/cmd/web/util.go index 2c32922..454912f 100644 --- a/cmd/web/util.go +++ b/cmd/web/util.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "io" "net" "net/http" @@ -22,9 +23,38 @@ func UnauthorizedIfNotLocal(h http.Handler) http.Handler { }) } +var isLocalCIDR = "127.0.0.1/8" + func isLocal(addr string) bool { - _, localNet, _ := net.ParseCIDR("127.0.0.1/8") - return localNet.Contains(net.ParseIP(strings.Split(addr, ":")[0])) + if strings.Contains(isLocalCIDR, ",") { + for _, cidr := range strings.Split(isLocalCIDR, ",") { + _, localNet, err := net.ParseCIDR(cidr) + if err != nil { + panic(err) + } + if localNet.Contains(net.ParseIP(strings.Split(addr, ":")[0])) { + return true + } + } + + return false + } else { + _, localNet, err := net.ParseCIDR(isLocalCIDR) + if err != nil { + panic(err) + } + return localNet.Contains(net.ParseIP(strings.Split(addr, ":")[0])) + } +} + +var shareLink = "" + +func getShareLink() string { + if shareLink != "" { + return shareLink + } + + return fmt.Sprintf("http://%s:%s/", GetHostIP(), getPort()) } // GetHostIP attempts to guess the IP address of the current machine and |
