2008-06-29 14:42:53 +00:00
|
|
|
#!/usr/bin/lua
|
|
|
|
require("socket")
|
2008-07-12 15:38:11 +00:00
|
|
|
require("luci.model.uci")
|
|
|
|
|
|
|
|
luci.model.uci.set_savedir(luci.model.uci.savedir_state)
|
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 ip = client:getpeername()
|
|
|
|
local srv
|
|
|
|
luci.model.uci.foreach("network", "interface",
|
|
|
|
function (section)
|
|
|
|
if section.ipaddr then
|
|
|
|
local p = luci.sys.net.mask4prefix(section.netmask)
|
|
|
|
if luci.sys.net.belongs(ip, section.ipaddr, p) then
|
|
|
|
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
|