Commit from LuCI Translation Portal by user keksdosenmann. 412 of 412 messages transl...
[project/luci.git] / applications / luci-splash / root / usr / bin / luci-splashd
1 #!/usr/bin/lua
2
3 local nixio = require "nixio", require "nixio.util"
4 local server = nixio.bind(nil, arg[1] or 8082)
5 local stat = server:listen(32)
6
7 local function remapipv6(adr)
8 local map = "::ffff:"
9 if adr:sub(1, #map) == map then
10 return adr:sub(#map+1)
11 else
12 return adr
13 end
14 end
15
16 while stat do
17 local client = server:accept()
18
19 if client then
20 client:setopt("socket", "rcvtimeo", 1)
21 client:setopt("socket", "sndtimeo", 1)
22 local srv = remapipv6(client:getsockname())
23
24 client:read(1024)
25 client:writeall("HTTP/1.1 302 Found\r\nLocation: http://" .. srv ..
26 (arg[2] or "/luci/splash") .. "\r\nContent-Length: 0\r\nConnection: close\r\n\r\n")
27 client:close()
28 end
29 end