2008-06-29 14:42:53 +00:00
|
|
|
#!/usr/bin/lua
|
2008-07-13 02:15:21 +00:00
|
|
|
|
2008-06-29 14:42:53 +00:00
|
|
|
require("socket")
|
2008-08-08 12:26:45 +00:00
|
|
|
require("luci.ip")
|
2008-07-12 15:38:11 +00:00
|
|
|
require("luci.model.uci")
|
|
|
|
|
2008-08-26 23:00:44 +00:00
|
|
|
local uci = luci.model.uci.cursor_state()
|
|
|
|
uci:load("network")
|
2008-06-29 14:42:53 +00:00
|
|
|
|
|
|
|
local server = socket.bind("0.0.0.0", arg[1] or 8082)
|
|
|
|
server:settimeout(0, "t")
|
|
|
|
|
|
|
|
while true do
|
|
|
|
local client = server:accept()
|
|
|
|
|
|
|
|
if client then
|
|
|
|
client:settimeout(1)
|
2008-07-12 15:38:11 +00:00
|
|
|
local srv
|
2008-08-08 12:26:45 +00:00
|
|
|
local ip = luci.ip.IPv4(client:getpeername())
|
2008-08-26 23:00:44 +00:00
|
|
|
uci:foreach("network", "interface",
|
2008-07-12 15:38:11 +00:00
|
|
|
function (section)
|
|
|
|
if section.ipaddr then
|
2008-08-08 12:26:45 +00:00
|
|
|
local net = luci.ip.IPv4(section.ipaddr, section.netmask)
|
|
|
|
if ip and net and net:contains(ip) then
|
2008-07-12 15:38:11 +00:00
|
|
|
srv = section.ipaddr
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2008-06-29 14:42:53 +00:00
|
|
|
client:receive()
|
|
|
|
client:send("HTTP/1.0 302 Found\r\nLocation: http://" .. srv ..
|
|
|
|
(arg[2] or "/luci/splash") .. "\r\n\r\n")
|
|
|
|
client:close()
|
|
|
|
else
|
|
|
|
socket.sleep(0.1)
|
|
|
|
end
|
|
|
|
end
|