2 LuCI - Lua Configuration Interface
3 Copyright 2009 Jo-Philipp Wich <xm@leipzig.freifunk.net>
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
17 local utl = require "luci.util"
18 local ipt = require "luci.sys.iptparser".IptParser()
19 local uci = require "luci.model.uci".cursor_state()
20 local wat = require "luci.tools.webadmin"
22 local leasetime = tonumber(uci:get("luci_splash", "general", "leasetime") or 1) * 60 * 60
23 local leasefile = "/tmp/dhcp.leases"
25 uci:foreach("dhcp", "dnsmasq",
27 if s.leasefile then leasefile = s.leasefile end
31 uci:foreach("luci_splash", "lease",
33 if s.start and s.mac then
34 clients[s.mac:lower()] = {
35 start = tonumber(s.start),
36 limit = ( tonumber(s.start) + leasetime ),
46 for _, r in ipairs(ipt:find({table="nat", chain="luci_splash_leases"})) do
47 if r.options and #r.options >= 2 and r.options[1] == "MAC" then
48 if not clients[r.options[2]:lower()] then
49 clients[r.options[2]:lower()] = {
52 mac = r.options[2]:upper(),
53 policy = ( r.target == "RETURN" ) and "whitelist" or "blacklist",
61 for mac, client in pairs(clients) do
65 client.packets_out = 0
68 local rin = ipt:find({table="mangle", chain="luci_splash_mark_in", destination=client.ipaddr})
69 local rout = ipt:find({table="mangle", chain="luci_splash_mark_out", options={"MAC", client.mac:upper()}})
71 if rin and #rin > 0 then
72 client.bytes_in = rin[1].bytes
73 client.packets_in = rin[1].packets
76 if rout and #rout > 0 then
77 client.bytes_out = rout[1].bytes
78 client.packets_out = rout[1].packets
83 uci:foreach("luci_splash", "whitelist",
85 if s.mac and clients[s.mac:lower()] then
86 clients[s.mac:lower()].policy="whitelist"
90 uci:foreach("luci_splash", "blacklist",
92 if s.mac and clients[s.mac:lower()] then
93 clients[s.mac:lower()].policy=(s.kicked and "kicked" or "blacklist")
97 if luci.fs.access(leasefile) then
98 for l in io.lines(leasefile) do
99 local time, mac, ip, name = l:match("^(%d+) (%S+) (%S+) (%S+)")
100 if time and mac and ip then
101 local c = clients[mac:lower()]
104 c.hostname = ( name ~= "*" ) and name or nil
110 for i, a in ipairs(luci.sys.net.arptable()) do
111 local c = clients[a["HW address"]:lower()]
112 if c and not c.ip then
113 c.ip = a["IP address"]
117 local function showmac(mac)
119 mac = mac:gsub("(%S%S:%S%S):%S%S:%S%S:(%S%S:%S%S)", "%1:XX:XX:%2")
128 <div id="cbi-splash-leases" class="cbi-map">
129 <h2><a id="content" name="content"><%:ff_splash Client-Splash%></a></h2>
130 <fieldset id="cbi-table-table" class="cbi-section">
131 <legend><%:ff_splash_clients Active Clients%></legend>
132 <div class="cbi-section-node">
133 <% if is_admin then %><form action="<%=REQUEST_URI%>" method="post"><% end %>
134 <table class="cbi-section-table">
135 <tr class="cbi-section-table-titles">
136 <th class="cbi-section-table-cell"><%:ff_splash_hostname Hostname%></th>
137 <th class="cbi-section-table-cell"><%:ff_splash_ip IP Address%></th>
138 <th class="cbi-section-table-cell"><%:ff_splash_mac MAC Address%></th>
139 <th class="cbi-section-table-cell"><%:ff_splash_timeleft Time remaining%></th>
140 <th class="cbi-section-table-cell"><%:ff_splash_traffic Traffic in/out%></th>
141 <th class="cbi-section-table-cell"><%:ff_splash_policy Policy%></th>
146 for _, c in utl.spairs(clients,
148 if clients[a].policy == clients[b].policy then
149 return (clients[a].start > clients[b].start)
151 return (clients[a].policy > clients[b].policy)
158 <tr class="cbi-section-table-row cbi-rowstyle-<%=2-(count%2)%>">
159 <td class="cbi-section-table-cell"><%=c.hostname or "<em>" .. translate("ff_splash_unknown", "unknown") .. "</em>"%></td>
160 <td class="cbi-section-table-cell"><%=c.ip or "<em>" .. translate("ff_splash_unknown", "unknown") .. "</em>"%></td>
161 <td class="cbi-section-table-cell"><%=showmac(c.mac)%></td>
162 <td class="cbi-section-table-cell"><%=
163 (c.limit >= os.time()) and wat.date_format(c.limit-os.time()) or
164 (c.policy ~= "normal") and "-" or "<em>" .. translate("ff_splash_expired", "expired") .. "</em>"
166 <td class="cbi-section-table-cell"><%=wat.byte_format(c.bytes_in)%> / <%=wat.byte_format(c.bytes_out)%></td>
167 <td class="cbi-section-table-cell">
168 <% if is_admin then %>
169 <select name="policy.<%=c.mac:lower()%>" style="width:200px">
170 <option value="whitelist"<%=c.policy=="whitelist" and ' selected="selected"'%>><%:ff_splash_whitelisted whitelisted%></option>
171 <option value="normal"<%=c.policy=="normal" and not c.kicked and ' selected="selected"'%>><%:ff_splash_splashed splashed%></option>
172 <option value="blacklist"<%=c.policy=="blacklist" and ' selected="selected"'%>><%:ff_splash_blacklisted blacklisted%></option>
173 <% if c.policy == "normal" then -%>
174 <option value="kicked"><%:ff_splash_tempblock temporarily blocked%></option>
177 <input type="submit" class="cbi-button cbi-button-save" name="save.<%=c.mac:lower()%>" value="<%:save Save%>" />
189 <tr class="cbi-section-table-row">
190 <td colspan="7" class="cbi-section-table-cell">
191 <br /><em><%:ff_splash_noclients No clients connected%></em><br />
196 <% if is_admin then %></form><% end %>