diff options
Diffstat (limited to 'contrib/package/ffluci-splash/src')
7 files changed, 0 insertions, 328 deletions
diff --git a/contrib/package/ffluci-splash/src/luci-splash.lua b/contrib/package/ffluci-splash/src/luci-splash.lua deleted file mode 100644 index 2fa6bdd4a9..0000000000 --- a/contrib/package/ffluci-splash/src/luci-splash.lua +++ /dev/null @@ -1,176 +0,0 @@ -#!/usr/bin/lua -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") - --- Init state session -uci = ffluci.model.uci.StateSession() - - -function main(argv) - local cmd = argv[1] - local arg = argv[2] - - if cmd == "status" then - if not arg then - os.exit(1) - end - - if iswhitelisted(arg) then - print("whitelisted") - os.exit(0) - end - - if haslease(arg) then - print("lease") - os.exit(0) - end - - print("unknown") - os.exit(0) - elseif cmd == "add" then - if not arg then - os.exit(1) - end - - if not haslease(arg) then - add_lease(arg) - else - print("already leased!") - os.exit(2) - end - os.exit(0) - elseif cmd == "remove" then - if not arg then - os.exit(1) - end - - remove_lease(arg) - os.exit(0) - elseif cmd == "sync" then - sync() - os.exit(0) - else - print("Usage: " .. argv[0] .. " <status|add|remove|sync> [MAC]") - os.exit(1) - end -end - --- Add a lease to state and invoke add_rule -function add_lease(mac) - local key = uci:add("luci_splash", "lease") - uci:set("luci_splash", key, "mac", mac) - uci:set("luci_splash", key, "start", os.time()) - add_rule(mac) -end - - --- Remove a lease from state and invoke remove_rule -function remove_lease(mac) - mac = mac:lower() - - for k, v in pairs(uci:sections("luci_splash")) do - if v[".type"] == "lease" and v.mac:lower() == mac then - remove_rule(mac) - uci:del("luci_splash", k) - end - end -end - - --- Add an iptables rule -function add_rule(mac) - return os.execute("iptables -t nat -I luci_splash_leases -m mac --mac-source '"..mac.."' -j RETURN") -end - - --- Remove an iptables rule -function remove_rule(mac) - return os.execute("iptables -t nat -D luci_splash_leases -m mac --mac-source '"..mac.."' -j RETURN") -end - - --- Check whether a MAC-Address is listed in the lease state list -function haslease(mac) - mac = mac:lower() - - for k, v in pairs(uci:sections("luci_splash")) do - if v[".type"] == "lease" and v.mac and v.mac:lower() == mac then - return true - end - end - - return false -end - - --- Check whether a MAC-Address is whitelisted -function iswhitelisted(mac) - mac = mac:lower() - - for k, v in pairs(uci:sections("luci_splash")) do - if v[".type"] == "whitelist" and v.mac and v.mac:lower() == mac then - return true - end - end - - return false -end - - --- Returns a list of MAC-Addresses for which a rule is existing -function listrules() - local cmd = "iptables -t nat -L luci_splash_leases | grep RETURN |" - cmd = cmd .. "egrep -io [0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+:[0-9a-f]+" - return ffluci.util.split(ffluci.sys.exec(cmd)) -end - - --- Synchronise leases, remove abandoned rules -function sync() - local written = {} - local time = os.time() - - uci:t_load("luci_splash") - - -- Current leases in state files - local leases = uci:t_sections("luci_splash") - - -- Convert leasetime to seconds - local leasetime = tonumber(uci:t_get("luci_splash", "general", "leasetime")) * 3600 - - -- Clean state file - uci:t_revert("luci_splash") - - - -- For all leases - for k, v in pairs(leases) do - if v[".type"] == "lease" then - if os.difftime(time, tonumber(v.start)) > leasetime then - -- Remove expired - remove_rule(v.mac) - else - -- Rewrite state - local n = uci:t_add("luci_splash", "lease") - uci:t_set("luci_splash", n, "mac", v.mac) - uci:t_set("luci_splash", n, "start", v.start) - written[v.mac:lower()] = 1 - end - end - end - - - -- Delete rules without state - for i, r in ipairs(listrules()) do - if #r > 0 and not written[r:lower()] then - remove_rule(r) - end - end - - uci:t_save("luci_splash") -end - -main(arg)
\ No newline at end of file diff --git a/contrib/package/ffluci-splash/src/luci-splash/htdocs/cgi-bin/index.cgi b/contrib/package/ffluci-splash/src/luci-splash/htdocs/cgi-bin/index.cgi deleted file mode 100644 index 3bff85ee51..0000000000 --- a/contrib/package/ffluci-splash/src/luci-splash/htdocs/cgi-bin/index.cgi +++ /dev/null @@ -1,52 +0,0 @@ -#!/usr/bin/haserl --shell=luac -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") - -local srv -local net -local ip = ffluci.http.remote_addr() -for k, v in pairs(ffluci.model.uci.sections("network")) do - if v[".type"] == "interface" and v.ipaddr then - local p = ffluci.sys.net.mask4prefix(v.netmask) - if ffluci.sys.net.belongs(ip, v.ipaddr, p) then - net = k - srv = v.ipaddr - break - end - end -end - -local stat = false -for k, v in pairs(ffluci.model.uci.sections("luci_splash")) do - if v[".type"] == "iface" and v.network == net then - stat = true - end -end - -if not srv then - ffluci.http.textheader() - return print("Unable to detect network settings!") -end - -if not stat then - ffluci.http.redirect("http://" .. srv) -end - -local action = "splash" - -local mac = ffluci.sys.net.ip4mac(ip) -if not mac then - action = "unknown" -end - -local status = ffluci.sys.execl("luci-splash status "..mac)[1] - -if status == "whitelisted" or status == "lease" then - action = "allowed" -end - -ffluci.http.redirect("http://" .. srv .. "/cgi-bin/luci-splash/" .. action)
\ No newline at end of file diff --git a/contrib/package/ffluci-splash/src/luci-splash/htdocs/index.html b/contrib/package/ffluci-splash/src/luci-splash/htdocs/index.html deleted file mode 100644 index 58387a5fec..0000000000 --- a/contrib/package/ffluci-splash/src/luci-splash/htdocs/index.html +++ /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">FFLuCI - Freifunk Lua Configuration Interface</a> -</body> -</html>
\ No newline at end of file diff --git a/contrib/package/ffluci-splash/src/luci_splash.cron b/contrib/package/ffluci-splash/src/luci_splash.cron deleted file mode 100644 index eae4294741..0000000000 --- a/contrib/package/ffluci-splash/src/luci_splash.cron +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -[ "$(date +%M | cut -c2)" == "5" ] && luci-splash sync
\ No newline at end of file diff --git a/contrib/package/ffluci-splash/src/luci_splash.init b/contrib/package/ffluci-splash/src/luci_splash.init deleted file mode 100644 index 20f7865fd4..0000000000 --- a/contrib/package/ffluci-splash/src/luci_splash.init +++ /dev/null @@ -1,85 +0,0 @@ -#!/bin/sh /etc/rc.common -START=70 - -iface_add() { - local cfg="$1" - - config_get net "$cfg" network - [ -n "$net" ] || return 0 - - config_get iface "$net" ifname - [ -n "$iface" ] || return 0 - iface="${iface%%:*}" - - config_get ipaddr "$net" ipaddr - [ -n "$ipaddr" ] || return 0 - - config_get netmask "$net" netmask - [ -n "$netmask" ] || return 0 - - eval "$(ipcalc.sh $ipaddr $netmask)" - - iptables -t nat -A luci_splash -i "$iface" -s "$NETWORK/$PREFIX" -j luci_splash_portal - iptables -t nat -A luci_splash_portal -i "$iface" -s "$NETWORK/$PREFIX" -d "$ipaddr" -p tcp -m multiport --dports 22,80,443 -j RETURN -} - -blacklist_add() { - local cfg="$1" - - config_get mac "$cfg" mac - [ -n "$mac" ] && iptables -t nat -A luci_splash_portal -m mac --mac-source "$mac" -j DROP -} - -whitelist_add() { - local cfg="$1" - - config_get mac "$cfg" mac - [ -n "$mac" ] && iptables -t nat -A luci_splash_portal -m mac --mac-source "$mac" -j RETURN -} - -start() { - ### Read chains from config - include /lib/network - scan_interfaces - config_load luci_splash - - ### Create subchains - iptables -t nat -N luci_splash - iptables -t nat -N luci_splash_portal - iptables -t nat -N luci_splash_leases - - ### Build the main and portal rule - config_foreach blacklist_add blacklist - config_foreach whitelist_add whitelist - config_foreach iface_add iface - - ### Build the portal rule - iptables -t nat -A luci_splash_portal -p udp --dport 53 -j RETURN - iptables -t nat -A luci_splash_portal -j luci_splash_leases - - ### Build the leases rule - iptables -t nat -A luci_splash_leases -p tcp --dport 80 -j REDIRECT --to-ports 8082 - 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 - - ### Hook in the chain - iptables -t nat -A prerouting_rule -j luci_splash -} - -stop() { - ### Hook out the chain - iptables -t nat -D prerouting_rule -j luci_splash - - ### Clear subchains - iptables -t nat -F luci_splash_leases - iptables -t nat -F luci_splash_portal - iptables -t nat -F luci_splash - - ### Delete subchains - iptables -t nat -X luci_splash_leases - iptables -t nat -X luci_splash_portal - iptables -t nat -X luci_splash -} - diff --git a/contrib/package/ffluci-splash/src/luci_splash.uci b/contrib/package/ffluci-splash/src/luci_splash.uci deleted file mode 100644 index c4cfef5dd9..0000000000 --- a/contrib/package/ffluci-splash/src/luci_splash.uci +++ /dev/null @@ -1,2 +0,0 @@ -config core general - option leasetime 1
\ No newline at end of file diff --git a/contrib/package/ffluci-splash/src/luci_splash_httpd.conf b/contrib/package/ffluci-splash/src/luci_splash_httpd.conf deleted file mode 100644 index 6007e80dba..0000000000 --- a/contrib/package/ffluci-splash/src/luci_splash_httpd.conf +++ /dev/null @@ -1 +0,0 @@ -E404:index.html
\ No newline at end of file |