summaryrefslogtreecommitdiffhomepage
path: root/contrib/package/luci-splash/src/luci_splash
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/package/luci-splash/src/luci_splash')
-rw-r--r--contrib/package/luci-splash/src/luci_splash/htdocs/cgi-bin/index.cgi49
-rw-r--r--contrib/package/luci-splash/src/luci_splash/htdocs/index.html10
-rw-r--r--contrib/package/luci-splash/src/luci_splash/splash.lua74
-rw-r--r--contrib/package/luci-splash/src/luci_splash/sync.lua3
4 files changed, 136 insertions, 0 deletions
diff --git a/contrib/package/luci-splash/src/luci_splash/htdocs/cgi-bin/index.cgi b/contrib/package/luci-splash/src/luci_splash/htdocs/cgi-bin/index.cgi
new file mode 100644
index 0000000000..0117198cfb
--- /dev/null
+++ b/contrib/package/luci-splash/src/luci_splash/htdocs/cgi-bin/index.cgi
@@ -0,0 +1,49 @@
+#!/usr/bin/haserl --shell=luac
+dofile("/usr/lib/luci_splash")
+
+require("ffluci.template")
+
+function dispatch()
+ local mac = get_usermac()
+ if not mac then
+ return action_nodata()
+ end
+
+ if isblacklisted(mac) then
+ return action_blocked()
+ end
+
+ if iswhitelisted(mac) or haslease(mac) then
+ return action_allowed()
+ end
+
+ return action_splash(mac)
+end
+
+function action_splash(mac)
+ if ffluci.http.formvalue("activate") then
+ add_lease(mac)
+ ffluci.http.textheader()
+ print("Got splashed!")
+ else
+ ffluci.http.textheader()
+ print("Get splashed!")
+ end
+end
+
+function action_allowed()
+ ffluci.http.textheader()
+ print("Already allowed!")
+end
+
+function action_blocked()
+ ffluci.http.textheader()
+ print("Blocked!")
+end
+
+function action_nodata()
+ ffluci.http.textheader()
+ print("No data!")
+end
+
+dispatch() \ No newline at end of file
diff --git a/contrib/package/luci-splash/src/luci_splash/htdocs/index.html b/contrib/package/luci-splash/src/luci_splash/htdocs/index.html
new file mode 100644
index 0000000000..58387a5fec
--- /dev/null
+++ b/contrib/package/luci-splash/src/luci_splash/htdocs/index.html
@@ -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/index.cgi" />
+</head>
+<body style="background-color: black">
+<a style="color: white; text-decoration: none" href="/cgi-bin/index.cgi">FFLuCI - Freifunk Lua Configuration Interface</a>
+</body>
+</html> \ No newline at end of file
diff --git a/contrib/package/luci-splash/src/luci_splash/splash.lua b/contrib/package/luci-splash/src/luci_splash/splash.lua
new file mode 100644
index 0000000000..b659d20011
--- /dev/null
+++ b/contrib/package/luci-splash/src/luci_splash/splash.lua
@@ -0,0 +1,74 @@
+package.path = "/usr/lib/lua/?.lua;/usr/lib/lua/?/init.lua;" .. package.path
+package.cpath = "/usr/lib/lua/?.so;" .. package.cpath
+
+require("ffluci.http")
+require("ffluci.sys")
+require("ffluci.model.uci")
+
+ucis = ffluci.model.uci.Session("/var/state")
+
+function add_lease(mac)
+ local key = ucis:add("luci_splash", "lease")
+ ucis:set("luci_splash", key, "mac", mac)
+ add_rule(mac)
+end
+
+function add_rule(mac)
+ return os.execute("iptables -t nat -I luci_splash_leases -m mac --source-mac '"..mac.."' -j RETURN")
+end
+
+function remove_rule(mac)
+ return os.execute("iptables -t nat -D luci_splash_leases -m mac --source-mac '"..mac.."' -j RETURN")
+end
+
+function get_usermac()
+ local ip = ffluci.http.remote_addr()
+ local mac = nil
+
+ for i, l in ipairs(ffluci.sys.net.arptable()) do
+ if l["IP address"] == ip then
+ mac = l["HW address"]
+ end
+ end
+
+ return mac
+end
+
+function haslease(mac)
+ mac = mac:lower()
+ local list = ucis:show("luci_splash").luci_splash
+
+ for k, v in pairs(list) do
+ if v[".type"] == "lease" and v.mac and v.mac:lower() == mac then
+ return true
+ end
+ end
+
+ return false
+end
+
+function isblacklisted(mac)
+ mac = mac:lower()
+ local list = ucis:show("luci_splash").luci_splash
+
+ for k, v in pairs(list) do
+ if v[".type"] == "blacklist" and v.mac and v.mac:lower() == mac then
+ return true
+ end
+ end
+
+ return false
+end
+
+function iswhitelisted(mac)
+ mac = mac:lower()
+ local list = ucis:show("luci_splash").luci_splash
+
+ for k, v in pairs(list) do
+ if v[".type"] == "whitelist" and v.mac and v.mac:lower() == mac then
+ return true
+ end
+ end
+
+ return false
+end \ No newline at end of file
diff --git a/contrib/package/luci-splash/src/luci_splash/sync.lua b/contrib/package/luci-splash/src/luci_splash/sync.lua
new file mode 100644
index 0000000000..fd32a1ca16
--- /dev/null
+++ b/contrib/package/luci-splash/src/luci_splash/sync.lua
@@ -0,0 +1,3 @@
+#!/usr/bin/haserl --shell=luac --accept-none
+dofile("splash.lua")
+