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