diff options
author | Steven Barth <steven@midlink.org> | 2009-06-16 14:27:43 +0000 |
---|---|---|
committer | Steven Barth <steven@midlink.org> | 2009-06-16 14:27:43 +0000 |
commit | b3a7ff9f8f0569e2c091f1738e7231be242a6dab (patch) | |
tree | 23d9552af13edabc86dc87cd9ecdebe55c7585da /libs/lucid-http/luasrc | |
parent | b8c3aa96d40747feb41ceb72e747a3ee0fa84bf9 (diff) |
Catchall workaround for strange sockaddresses by Jow
Diffstat (limited to 'libs/lucid-http/luasrc')
-rw-r--r-- | libs/lucid-http/luasrc/lucid/http/handler/catchall.lua | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/libs/lucid-http/luasrc/lucid/http/handler/catchall.lua b/libs/lucid-http/luasrc/lucid/http/handler/catchall.lua index 30af84ba2a..a5cdce5341 100644 --- a/libs/lucid-http/luasrc/lucid/http/handler/catchall.lua +++ b/libs/lucid-http/luasrc/lucid/http/handler/catchall.lua @@ -14,6 +14,8 @@ $Id$ local srv = require "luci.lucid.http.server" local proto = require "luci.http.protocol" local util = require "luci.util" +local ip = require "luci.ip" +local ipairs = ipairs --- Catchall Handler -- @cstyle instance @@ -37,7 +39,21 @@ end function Redirect.handle_GET(self, request) local target = self.target local protocol = request.env.HTTPS and "https://" or "http://" - local server = request.env.SERVER_ADDR + local server + + if request.env.REMOTE_ADDR and not request.env.REMOTE_ADDR:find(":") then + local compare = ip.IPv4(request.env.REMOTE_ADDR) + for _, iface in ipairs(request.server.interfaces) do + if iface.family == "inet" and iface.addr and iface.netmask then + if ip.IPv4(iface.addr, iface.netmask):contains(compare) then + server = iface.addr + break + end + end + end + else + server = request.env.SERVER_ADDR + end if server:find(":") then server = "[" .. server .. "]" end |