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 ),
41 kicked = s.kicked and true or false
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 _, r in ipairs(ipt:find({table="filter", chain="luci_splash_filter", options={"MAC"}})) do
62 local c = clients[r.options[2]:lower()]
63 if c and c.packets == 0 then
64 c.bytes = tonumber(r.bytes)
65 c.packets = tonumber(r.packets)
69 uci:foreach("luci_splash", "whitelist",
71 if s.mac and clients[s.mac:lower()] then
72 clients[s.mac:lower()].policy="whitelist"
76 uci:foreach("luci_splash", "blacklist",
78 if s.mac and clients[s.mac:lower()] then
79 clients[s.mac:lower()].policy=(s.kicked and "kicked" or "blacklist")
83 if luci.fs.access(leasefile) then
84 for l in io.lines(leasefile) do
85 local time, mac, ip, name = l:match("^(%d+) (%S+) (%S+) (%S+)")
86 if time and mac and ip then
87 local c = clients[mac:lower()]
90 c.hostname = ( name ~= "*" ) and name or nil
96 for i, a in ipairs(luci.sys.net.arptable()) do
97 local c = clients[a["HW address"]:lower()]
98 if c and not c.ip then
99 c.ip = a["IP address"]
103 local function showmac(mac)
105 mac = mac:gsub("(%S%S:%S%S):%S%S:%S%S:(%S%S:%S%S)", "%1:XX:XX:%2")
114 <div id="cbi-splash-leases" class="cbi-map">
115 <h2><a id="content" name="content"><%:ff_splash Client-Splash%></a></h2>
116 <fieldset id="cbi-table-table" class="cbi-section">
117 <legend><%:ff_splash_clients Active Clients%></legend>
118 <div class="cbi-section-node">
119 <% if is_admin then %><form action="<%=REQUEST_URI%>" method="post"><% end %>
120 <table class="cbi-section-table">
121 <tr class="cbi-section-table-titles">
122 <th class="cbi-section-table-cell"><%:ff_splash_hostname Hostname%></th>
123 <th class="cbi-section-table-cell"><%:ff_splash_ip IP Address%></th>
124 <th class="cbi-section-table-cell"><%:ff_splash_mac MAC Address%></th>
125 <th class="cbi-section-table-cell"><%:ff_splash_timeleft Time remaining%></th>
126 <th class="cbi-section-table-cell"><%:ff_splash_traffic Outgoing traffic%></th>
127 <th class="cbi-section-table-cell"><%:ff_splash_policy Policy%></th>
132 for _, c in utl.spairs(clients,
134 if clients[a].policy == clients[b].policy then
135 return (clients[a].start > clients[b].start)
137 return (clients[a].policy > clients[b].policy)
144 <tr class="cbi-section-table-row cbi-rowstyle-<%=2-(count%2)%>">
145 <td class="cbi-section-table-cell"><%=c.hostname or "<em>" .. translate("ff_splash_unknown", "unknown") .. "</em>"%></td>
146 <td class="cbi-section-table-cell"><%=c.ip or "<em>" .. translate("ff_splash_unknown", "unknown") .. "</em>"%></td>
147 <td class="cbi-section-table-cell"><%=showmac(c.mac)%></td>
148 <td class="cbi-section-table-cell"><%=
149 (c.limit >= os.time()) and wat.date_format(c.limit-os.time()) or
150 (c.policy ~= "normal") and "-" or "<em>" .. translate("ff_splash_expired", "expired") .. "</em>"
152 <td class="cbi-section-table-cell"><%=wat.byte_format(c.bytes)%></td>
153 <td class="cbi-section-table-cell">
154 <% if is_admin then %>
155 <select name="policy.<%=c.mac:lower()%>" style="width:200px">
156 <option value="whitelist"<%=c.policy=="whitelist" and ' selected="selected"'%>><%:ff_splash_whitelisted whitelisted%></option>
157 <option value="normal"<%=c.policy=="normal" and not c.kicked and ' selected="selected"'%>><%:ff_splash_splashed splashed%></option>
158 <option value="blacklist"<%=c.policy=="blacklist" and ' selected="selected"'%>><%:ff_splash_blacklisted blacklisted%></option>
159 <% if c.policy == "normal" then -%>
160 <option value="kick"<%=c.kicked and ' selected="selected"'%>><%:ff_splash_tempblock temporarily blocked%> (<%=wat.date_format(c.limit-os.time())%>)</option>
163 <input type="submit" class="cbi-button cbi-button-save" name="save.<%=c.mac:lower()%>" value="<%:save Save%>" />
175 <tr class="cbi-section-table-row">
176 <td colspan="7" class="cbi-section-table-cell">
177 <br /><em><%:ff_splash_noclients No clients connected%></em><br />
182 <% if is_admin then %></form><% end %>