libs/web: Added missing on_commit trigger
[project/luci.git] / applications / luci-splash / root / usr / bin / luci-splashd
1 #!/usr/bin/lua
2
3 require("socket")
4 require("luci.sys")
5 require("luci.model.uci")
6
7 luci.model.uci.set_savedir(luci.model.uci.savedir_state)
8
9 local server = socket.bind("0.0.0.0", arg[1] or 8082)
10 server:settimeout(0, "t")
11
12 while true do
13         local client = server:accept()
14         
15         if client then
16                 client:settimeout(1)
17                 local ip = client:getpeername()
18                 local srv
19                 luci.model.uci.foreach("network", "interface",
20                         function (section)
21                             if section.ipaddr then
22                                 local p = luci.sys.net.mask4prefix(section.netmask)
23                                 if luci.sys.net.belongs(ip, section.ipaddr, p) then
24                                     srv = section.ipaddr
25                                     return
26                                 end
27                             end
28                         end)
29
30                 client:receive()
31                 client:send("HTTP/1.0 302 Found\r\nLocation: http://" .. srv ..
32                  (arg[2] or "/luci/splash") .. "\r\n\r\n")
33                 client:close() 
34         else
35                 socket.sleep(0.1)
36         end
37 end