| 1 | --[[ |
|---|
| 2 | LuCI - Lua Configuration Interface |
|---|
| 3 | |
|---|
| 4 | Copyright 2008 Steven Barth <steven@midlink.org> |
|---|
| 5 | |
|---|
| 6 | Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 7 | you may not use this file except in compliance with the License. |
|---|
| 8 | You may obtain a copy of the License at |
|---|
| 9 | |
|---|
| 10 | http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 11 | |
|---|
| 12 | $Id$ |
|---|
| 13 | ]]-- |
|---|
| 14 | |
|---|
| 15 | local uci = require "luci.model.uci".cursor() |
|---|
| 16 | local sys = require "luci.sys" |
|---|
| 17 | local wa = require "luci.tools.webadmin" |
|---|
| 18 | local fs = require "nixio.fs" |
|---|
| 19 | |
|---|
| 20 | m2 = Map("luci_ethers", translate("dhcp_leases")) |
|---|
| 21 | |
|---|
| 22 | local leasefn, leasefp, leases |
|---|
| 23 | uci:foreach("dhcp", "dnsmasq", |
|---|
| 24 | function(section) |
|---|
| 25 | leasefn = section.leasefile |
|---|
| 26 | end |
|---|
| 27 | ) |
|---|
| 28 | local leasefp = leasefn and fs.access(leasefn) and io.lines(leasefn) |
|---|
| 29 | if leasefp then |
|---|
| 30 | leases = {} |
|---|
| 31 | for lease in leasefp do |
|---|
| 32 | table.insert(leases, luci.util.split(lease, " ")) |
|---|
| 33 | end |
|---|
| 34 | end |
|---|
| 35 | |
|---|
| 36 | if leases then |
|---|
| 37 | v = m2:section(Table, leases, translate("dhcp_leases_active")) |
|---|
| 38 | ip = v:option(DummyValue, 3, translate("ipaddress")) |
|---|
| 39 | |
|---|
| 40 | mac = v:option(DummyValue, 2, translate("macaddress")) |
|---|
| 41 | |
|---|
| 42 | ltime = v:option(DummyValue, 1, translate("dhcp_timeremain")) |
|---|
| 43 | function ltime.cfgvalue(self, ...) |
|---|
| 44 | local value = DummyValue.cfgvalue(self, ...) |
|---|
| 45 | return wa.date_format(os.difftime(tonumber(value), os.time())) |
|---|
| 46 | end |
|---|
| 47 | end |
|---|
| 48 | |
|---|
| 49 | s = m2:section(TypedSection, "static_lease", translate("luci_ethers")) |
|---|
| 50 | s.addremove = true |
|---|
| 51 | s.anonymous = true |
|---|
| 52 | s.template = "cbi/tblsection" |
|---|
| 53 | |
|---|
| 54 | mac = s:option(Value, "macaddr", translate("macaddress")) |
|---|
| 55 | ip = s:option(Value, "ipaddr", translate("ipaddress")) |
|---|
| 56 | sys.net.arptable(function(entry) |
|---|
| 57 | ip:value(entry["IP address"]) |
|---|
| 58 | mac:value( |
|---|
| 59 | entry["HW address"], |
|---|
| 60 | entry["HW address"] .. " (" .. entry["IP address"] .. ")" |
|---|
| 61 | ) |
|---|
| 62 | end) |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | return m2 |
|---|