* applications/luci-splash: Rewrote luci-splash using an own daemon implementation
authorSteven Barth <steven@midlink.org>
Sun, 29 Jun 2008 14:42:53 +0000 (14:42 +0000)
committerSteven Barth <steven@midlink.org>
Sun, 29 Jun 2008 14:42:53 +0000 (14:42 +0000)
* Minor tweaks in luci.dispatcher

12 files changed:
applications/luci-splash/htdocs/cgi-bin/luci-splash [deleted file]
applications/luci-splash/htdocs/luci/splash/index.html [new file with mode: 0644]
applications/luci-splash/luasrc/controller/splash/splash.lua
applications/luci-splash/root/etc/init.d/luci_splash
applications/luci-splash/root/etc/luci_splash_httpd.conf [deleted file]
applications/luci-splash/root/usr/bin/luci-splashd [new file with mode: 0755]
applications/luci-splash/root/usr/lib/luci-splash/htdocs/cgi-bin/index.cgi [deleted file]
applications/luci-splash/root/usr/lib/luci-splash/htdocs/index.html [deleted file]
contrib/package/luci/Makefile
libs/sgi-cgi/htdocs/cgi-bin/index.cgi [deleted file]
libs/sgi-cgi/htdocs/index.html
libs/web/luasrc/dispatcher.lua

diff --git a/applications/luci-splash/htdocs/cgi-bin/luci-splash b/applications/luci-splash/htdocs/cgi-bin/luci-splash
deleted file mode 100755 (executable)
index c75593f..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/sh
-echo "Status: 302 Found"
-echo "Location: /cgi-bin/luci/splash/splash$PATH_INFO"
-echo
\ No newline at end of file
diff --git a/applications/luci-splash/htdocs/luci/splash/index.html b/applications/luci-splash/htdocs/luci/splash/index.html
new file mode 100644 (file)
index 0000000..486409a
--- /dev/null
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="refresh" content="0; URL=/cgi-bin/luci/splash" />
+</head>
+<body style="background-color: black">
+<a style="color: white; text-decoration: none" href="/cgi-bin/luci/splash">LuCI - Lua Configuration Interface</a>
+</body>
+</html>
index 617e0f8..6512ee5 100644 (file)
@@ -1,16 +1,23 @@
 module("luci.controller.splash.splash", package.seeall)
 
 function index()
-       local page = node("admin", "services", "splash")
-       page.target = cbi("splash/splash")
-       page.title  = "Client-Splash"
+       entry({"admin", "services", "splash"}, cbi("splash/splash"), "Client-Splash")
 
+       node("splash").target = call("action_dispatch")
        node("splash", "splash", "activate").target = call("action_activate")
-       node("splash", "splash", "allowed").target  = call("action_allowed")
-       node("splash", "splash", "unknown").target  = call("action_unknown")
        node("splash", "splash", "splash").target   = template("splash_splash/splash")
 end
 
+function action_dispatch()
+       local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR"))
+       local status = luci.sys.execl("luci-splash status "..mac)[1]
+       if status == "whitelisted" or status == "lease" then
+               luci.http.redirect(luci.dispatcher.build_url())
+       else
+               luci.http.redirect(luci.dispatcher.build_url("splash", "splash", "splash"))
+       end
+end
+
 function action_activate()
        local mac = luci.sys.net.ip4mac(luci.http.getenv("REMOTE_ADDR"))
        if mac and luci.http.formvalue("accept") then
@@ -19,12 +26,4 @@ function action_activate()
        else
                luci.http.redirect(luci.dispatcher.build_url())
        end
-end
-
-function action_allowed()
-       luci.http.redirect(luci.dispatcher.build_url())
-end
-
-function action_unknown()
-       luci.http.redirect(luci.dispatcher.build_url())
 end
\ No newline at end of file
index 20f7865..eb006e9 100755 (executable)
@@ -62,8 +62,8 @@ start() {
        iptables -t nat -A luci_splash_leases -j DROP
        
        ### Start the splash httpd
-       httpd -c /etc/luci_splash_httpd.conf -p 8082 -h /usr/lib/luci-splash/htdocs
-       
+       start-stop-daemon -S -b -q -x /usr/bin/luci-splashd
+
        ### Hook in the chain
        iptables -t nat -A prerouting_rule -j luci_splash
 }
diff --git a/applications/luci-splash/root/etc/luci_splash_httpd.conf b/applications/luci-splash/root/etc/luci_splash_httpd.conf
deleted file mode 100644 (file)
index 6007e80..0000000
+++ /dev/null
@@ -1 +0,0 @@
-E404:index.html
\ No newline at end of file
diff --git a/applications/luci-splash/root/usr/bin/luci-splashd b/applications/luci-splash/root/usr/bin/luci-splashd
new file mode 100755 (executable)
index 0000000..33391cc
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/lua
+require("socket")
+
+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)
+               local srv = client:getsockname()
+               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
diff --git a/applications/luci-splash/root/usr/lib/luci-splash/htdocs/cgi-bin/index.cgi b/applications/luci-splash/root/usr/lib/luci-splash/htdocs/cgi-bin/index.cgi
deleted file mode 100755 (executable)
index 29679a2..0000000
+++ /dev/null
@@ -1,53 +0,0 @@
-#!/usr/bin/lua
-
-require("luci.sys")
-require("luci.model.uci")
-
-luci.model.uci.set_savedir(luci.model.uci.savedir_state)
-
-local srv
-local net
-local ip = os.getenv("REMOTE_ADDR")
-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
-                               net = section[".name"]
-                               srv = section.ipaddr
-                               return
-                       end
-               end
-       end)
-
-local stat = false
-luci.model.uci.foreach("luci_splash", "iface",
-       function (section)
-               if section.network == net then
-                       stat = true
-               end
-       end)
-
-if not srv then
-       print("Content-Type: text/plain\n")
-       print("Unable to detect network settings!")
-elseif not stat then
-       print("Status: 302 Found")
-       print("Location: http://" .. srv)
-else
-       local action = "splash"
-       
-       local mac = luci.sys.net.ip4mac(ip)
-       if not mac then
-               action = "unknown"
-       end
-       
-       local status = luci.sys.execl("luci-splash status "..mac)[1]
-       
-       if status == "whitelisted" or status == "lease" then
-               action = "allowed"
-       end
-       
-       print("Status: 302 Found")
-       print("Location: http://" .. srv .. "/cgi-bin/luci-splash/" .. action)
-end
diff --git a/applications/luci-splash/root/usr/lib/luci-splash/htdocs/index.html b/applications/luci-splash/root/usr/lib/luci-splash/htdocs/index.html
deleted file mode 100644 (file)
index 39ba558..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<meta http-equiv="refresh" content="0; URL=/cgi-bin/index.cgi" />
-</head>
-<body style="background-color: black">
-<a style="color: white; text-decoration: none" href="/cgi-bin/index.cgi">LuCI - Lua Configuration Interface</a>
-</body>
-</html>
\ No newline at end of file
index 54cb7fb..68bcc99 100644 (file)
@@ -334,7 +334,7 @@ endef
 
 define Package/luci-app-splash
   $(call Package/luci/fftemplate)
-  DEPENDS+=+iptables-mod-nat +iptables-mod-ipopt
+  DEPENDS+=+luasocket +iptables-mod-nat +iptables-mod-ipopt
   TITLE:=Freifunk DHCP-Splash application
 endef
 
diff --git a/libs/sgi-cgi/htdocs/cgi-bin/index.cgi b/libs/sgi-cgi/htdocs/cgi-bin/index.cgi
deleted file mode 100755 (executable)
index fc1148d..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/usr/bin/lua
-print("Status: 302 Found")
-print("Location: luci\n")
index 39ba558..0a7238b 100644 (file)
@@ -2,9 +2,9 @@
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
-<meta http-equiv="refresh" content="0; URL=/cgi-bin/index.cgi" />
+<meta http-equiv="refresh" content="0; URL=/cgi-bin/luci" />
 </head>
 <body style="background-color: black">
-<a style="color: white; text-decoration: none" href="/cgi-bin/index.cgi">LuCI - Lua Configuration Interface</a>
+<a style="color: white; text-decoration: none" href="/cgi-bin/luci">LuCI - Lua Configuration Interface</a>
 </body>
-</html>
\ No newline at end of file
+</html>
index 426dd66..7c28f6a 100644 (file)
@@ -314,7 +314,7 @@ end
 
 -- Shortcut for creating a dispatching node
 function entry(path, target, title, order)
-       local c = node(path)
+       local c = node(unpack(path))
        
        c.target = target
        c.title  = title
@@ -328,11 +328,6 @@ end
 function node(...)
        local c = context.tree
        arg.n = nil
-       if arg[1] then
-               if type(arg[1]) == "table" then
-                       arg = arg[1]
-               end
-       end
 
        for k,v in ipairs(arg) do
                if not c.nodes[v] then