fix (plugin): fix finding local ip for onlyoffice (#409)

This commit is contained in:
Jimmy 2021-09-27 12:03:54 +02:00 committed by GitHub
parent 110280e94b
commit 642f04c955
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -227,15 +227,32 @@ func IframeContentHandler(ctx App, res http.ResponseWriter, req *http.Request) {
if err != nil {
return ""
}
maybeips := []string{}
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
return ipnet.IP.String()
maybeips = append(maybeips, ipnet.IP.String())
}
}
}
return ""
}()
// if there is just one interface, we can just pick that one
if len(maybeips) == 1 {
return maybeips[0]
}
// if not, fallback to capturing our outgoing local ip
conn, err := net.Dial("udp", "8.8.8.8:80")
if err != nil {
return ""
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP.String()
}()
filestashServerLocation = fmt.Sprintf("http://%s:%d", localip, Config.Get("general.port").Int())
contentType = func(p string) string {
var (