local ipt = require "luci.sys.iptparser".IptParser()
local uci = require "luci.model.uci".cursor_state()
local wat = require "luci.tools.webadmin"
+local fs = require "nixio.fs"
+luci.i18n.loadc("splash")
+
local clients = { }
local leasetime = tonumber(uci:get("luci_splash", "general", "leasetime") or 1) * 60 * 60
local leasefile = "/tmp/dhcp.leases"
start = tonumber(s.start),
limit = ( tonumber(s.start) + leasetime ),
mac = s.mac:upper(),
+ ipaddr = s.ipaddr,
policy = "normal",
packets = 0,
bytes = 0,
- kicked = s.kicked and true or false
}
end
end)
end
end
-for _, r in ipairs(ipt:find({table="filter", chain="luci_splash_counter"})) do
- if r.options and #r.options >= 2 and r.options[1] == "MAC" then
- local c = clients[r.options[2]:lower()]
- if c and c.packets == 0 then
- c.bytes = tonumber(r.bytes)
- c.packets = tonumber(r.packets)
+for mac, client in pairs(clients) do
+ client.bytes_in = 0
+ client.bytes_out = 0
+ client.packets_in = 0
+ client.packets_out = 0
+
+ if client.ipaddr then
+ local rin = ipt:find({table="mangle", chain="luci_splash_mark_in", destination=client.ipaddr})
+ local rout = ipt:find({table="mangle", chain="luci_splash_mark_out", options={"MAC", client.mac:upper()}})
+
+ if rin and #rin > 0 then
+ client.bytes_in = rin[1].bytes
+ client.packets_in = rin[1].packets
+ end
+
+ if rout and #rout > 0 then
+ client.bytes_out = rout[1].bytes
+ client.packets_out = rout[1].packets
end
end
end
end
end)
-if luci.fs.access(leasefile) then
+if fs.access(leasefile) then
for l in io.lines(leasefile) do
local time, mac, ip, name = l:match("^(%d+) (%S+) (%S+) (%S+)")
if time and mac and ip then
<%+header%>
<div id="cbi-splash-leases" class="cbi-map">
- <h2><a id="content" name="content"><%:ff_splash Client-Splash%></a></h2>
+ <h2><a id="content" name="content"><%:Client-Splash%></a></h2>
<fieldset id="cbi-table-table" class="cbi-section">
- <legend><%:ff_splash_clients Active Clients%></legend>
+ <legend><%:Active Clients%></legend>
<div class="cbi-section-node">
<% if is_admin then %><form action="<%=REQUEST_URI%>" method="post"><% end %>
<table class="cbi-section-table">
<tr class="cbi-section-table-titles">
- <th class="cbi-section-table-cell"><%:ff_splash_hostname Hostname%></th>
- <th class="cbi-section-table-cell"><%:ff_splash_ip IP Address%></th>
- <th class="cbi-section-table-cell"><%:ff_splash_mac MAC Address%></th>
- <th class="cbi-section-table-cell"><%:ff_splash_timeleft Time remaining%></th>
- <th class="cbi-section-table-cell"><%:ff_splash_traffic Outgoing traffic%></th>
- <th class="cbi-section-table-cell"><%:ff_splash_policy Policy%></th>
+ <th class="cbi-section-table-cell"><%:Hostname%></th>
+ <th class="cbi-section-table-cell"><%:IP Address%></th>
+ <th class="cbi-section-table-cell"><%:MAC Address%></th>
+ <th class="cbi-section-table-cell"><%:Time remaining%></th>
+ <th class="cbi-section-table-cell"><%:Traffic in/out%></th>
+ <th class="cbi-section-table-cell"><%:Policy%></th>
</tr>
<%-
count = count + 1
-%>
<tr class="cbi-section-table-row cbi-rowstyle-<%=2-(count%2)%>">
- <td class="cbi-section-table-cell"><%=c.hostname or "<em>" .. translate("ff_splash_unknown", "unknown") .. "</em>"%></td>
- <td class="cbi-section-table-cell"><%=c.ip or "<em>" .. translate("ff_splash_unknown", "unknown") .. "</em>"%></td>
+ <td class="cbi-section-table-cell"><%=c.hostname or "<em>" .. translate("unknown") .. "</em>"%></td>
+ <td class="cbi-section-table-cell"><%=c.ip or "<em>" .. translate("unknown") .. "</em>"%></td>
<td class="cbi-section-table-cell"><%=showmac(c.mac)%></td>
<td class="cbi-section-table-cell"><%=
(c.limit >= os.time()) and wat.date_format(c.limit-os.time()) or
- (c.policy ~= "normal") and "-" or "<em>" .. translate("ff_splash_expired", "expired") .. "</em>"
+ (c.policy ~= "normal") and "-" or "<em>" .. translate("expired") .. "</em>"
%></td>
- <td class="cbi-section-table-cell"><%=wat.byte_format(c.bytes)%></td>
+ <td class="cbi-section-table-cell"><%=wat.byte_format(c.bytes_in)%> / <%=wat.byte_format(c.bytes_out)%></td>
<td class="cbi-section-table-cell">
<% if is_admin then %>
<select name="policy.<%=c.mac:lower()%>" style="width:200px">
- <option value="whitelist"<%=c.policy=="whitelist" and ' selected="selected"'%>><%:ff_splash_whitelisted whitelisted%></option>
- <option value="normal"<%=c.policy=="normal" and not c.kicked and ' selected="selected"'%>><%:ff_splash_splashed splashed%></option>
- <option value="blacklist"<%=c.policy=="blacklist" and ' selected="selected"'%>><%:ff_splash_blacklisted blacklisted%></option>
+ <option value="whitelist"<%=c.policy=="whitelist" and ' selected="selected"'%>><%:whitelisted%></option>
+ <option value="normal"<%=c.policy=="normal" and not c.kicked and ' selected="selected"'%>><%:splashed%></option>
+ <option value="blacklist"<%=c.policy=="blacklist" and ' selected="selected"'%>><%:blacklisted%></option>
<% if c.policy == "normal" then -%>
- <option value="kick"<%=c.kicked and ' selected="selected"'%>><%:ff_splash_tempblock temporarily blocked%> (<%=wat.date_format(c.limit-os.time())%>)</option>
+ <option value="kicked"><%:temporarily blocked%></option>
<%- end %>
</select>
- <input type="submit" class="cbi-button cbi-button-save" name="save.<%=c.mac:lower()%>" value="<%:save Save%>" />
+ <input type="submit" class="cbi-button cbi-button-save" name="save.<%=c.mac:lower()%>" value="<%:Save%>" />
<% else %>
<%=c.policy%>
<% end %>
-%>
<tr class="cbi-section-table-row">
<td colspan="7" class="cbi-section-table-cell">
- <br /><em><%:ff_splash_noclients No clients connected%></em><br />
+ <br /><em><%:No clients connected%></em><br />
</td>
</tr>
<%- end -%>