From 642f04c955e5a608aced50fb012fd8d6b0df9f19 Mon Sep 17 00:00:00 2001 From: Jimmy <19169592+jimtheyounger@users.noreply.github.com> Date: Mon, 27 Sep 2021 12:03:54 +0200 Subject: [PATCH] fix (plugin): fix finding local ip for onlyoffice (#409) --- server/plugin/plg_editor_onlyoffice/index.go | 23 +++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/server/plugin/plg_editor_onlyoffice/index.go b/server/plugin/plg_editor_onlyoffice/index.go index b173d245..fa84168e 100644 --- a/server/plugin/plg_editor_onlyoffice/index.go +++ b/server/plugin/plg_editor_onlyoffice/index.go @@ -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 (