From 1e9b205464d0611db5fe7e036c3628ebe484c803 Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Wed, 28 Oct 2009 17:38:09 +0000 Subject: [PATCH] More NIU --- modules/niu/luasrc/controller/niu/network.lua | 10 +++- .../niu/luasrc/model/cbi/niu/network/assign.lua | 17 ++++++ .../niu/luasrc/model/cbi/niu/network/assign1.lua | 66 ++++++++++++++++++++++ .../niu/luasrc/model/cbi/niu/network/routes.lua | 17 ++++++ .../niu/luasrc/model/cbi/niu/network/routes1.lua | 55 ++++++++++++++++++ modules/niu/luasrc/view/niu/network.htm | 10 ++-- 6 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 modules/niu/luasrc/model/cbi/niu/network/assign.lua create mode 100644 modules/niu/luasrc/model/cbi/niu/network/assign1.lua create mode 100644 modules/niu/luasrc/model/cbi/niu/network/routes.lua create mode 100644 modules/niu/luasrc/model/cbi/niu/network/routes1.lua diff --git a/modules/niu/luasrc/controller/niu/network.lua b/modules/niu/luasrc/controller/niu/network.lua index b17e6e760..41da30a37 100644 --- a/modules/niu/luasrc/controller/niu/network.lua +++ b/modules/niu/luasrc/controller/niu/network.lua @@ -20,8 +20,14 @@ function index() .dbtemplate = "niu/network" entry({"niu", "network", "lan"}, - cbi("niu/network/lan", {on_success_to={"niu"}}), "Configure LAN") + cbi("niu/network/lan", {on_success_to={"niu"}}), "Configure LAN", 10) entry({"niu", "network", "wan"}, - cbi("niu/network/wan", {on_success_to={"niu"}}), "Configure Internet") + cbi("niu/network/wan", {on_success_to={"niu"}}), "Configure Internet", 20) + + entry({"niu", "network", "assign"}, cbi("niu/network/assign", + {on_success_to={"niu"}}), "Address Assignment", 30) + + entry({"niu", "network", "routes"}, cbi("niu/network/routes", + {on_success_to={"niu"}}), "Custom Routing", 40) end diff --git a/modules/niu/luasrc/model/cbi/niu/network/assign.lua b/modules/niu/luasrc/model/cbi/niu/network/assign.lua new file mode 100644 index 000000000..b61e4f400 --- /dev/null +++ b/modules/niu/luasrc/model/cbi/niu/network/assign.lua @@ -0,0 +1,17 @@ +local cursor = require "luci.model.uci".cursor() +local d = Delegator() +d.allow_finish = true +d.allow_back = true +d.allow_cancel = true + +d:add("assign1", load("niu/network/assign1")) + +function d.on_cancel() + cursor:revert("dhcp") +end + +function d.on_done() + cursor:commit("dhcp") +end + +return d \ No newline at end of file diff --git a/modules/niu/luasrc/model/cbi/niu/network/assign1.lua b/modules/niu/luasrc/model/cbi/niu/network/assign1.lua new file mode 100644 index 000000000..704e9ae66 --- /dev/null +++ b/modules/niu/luasrc/model/cbi/niu/network/assign1.lua @@ -0,0 +1,66 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- + +local uci = require "luci.model.uci".cursor() +local sys = require "luci.sys" +local wa = require "luci.tools.webadmin" +local fs = require "nixio.fs" + +m2 = Map("dhcp", "Address Assignment") + +local leasefn, leasefp, leases +uci:foreach("dhcp", "dnsmasq", + function(section) + leasefn = section.leasefile + end +) +local leasefp = leasefn and fs.access(leasefn) and io.lines(leasefn) +if leasefp then + leases = {} + for lease in leasefp do + table.insert(leases, luci.util.split(lease, " ")) + end +end + +if leases then + v = m2:section(Table, leases, translate("dhcp_leases_active")) + ip = v:option(DummyValue, 3, translate("ipaddress")) + + mac = v:option(DummyValue, 2, translate("macaddress")) + + ltime = v:option(DummyValue, 1, translate("dhcp_timeremain")) + function ltime.cfgvalue(self, ...) + local value = DummyValue.cfgvalue(self, ...) + return wa.date_format(os.difftime(tonumber(value), os.time())) + end +end + +s = m2:section(TypedSection, "host") +s.addremove = true +s.anonymous = true +s.template = "cbi/tblsection" + +hn = s:option(Value, "name", translate("hostnames_hostname")) +mac = s:option(Value, "mac", translate("macaddress")) +ip = s:option(Value, "ip", translate("ipaddress")) +sys.net.arptable(function(entry) + ip:value(entry["IP address"]) + mac:value( + entry["HW address"], + entry["HW address"] .. " (" .. entry["IP address"] .. ")" + ) +end) + + +return m2 diff --git a/modules/niu/luasrc/model/cbi/niu/network/routes.lua b/modules/niu/luasrc/model/cbi/niu/network/routes.lua new file mode 100644 index 000000000..64a587c81 --- /dev/null +++ b/modules/niu/luasrc/model/cbi/niu/network/routes.lua @@ -0,0 +1,17 @@ +local cursor = require "luci.model.uci".cursor() +local d = Delegator() +d.allow_finish = true +d.allow_back = true +d.allow_cancel = true + +d:add("routes1", load("niu/network/routes1")) + +function d.on_cancel() + cursor:revert("network") +end + +function d.on_done() + cursor:commit("network") +end + +return d \ No newline at end of file diff --git a/modules/niu/luasrc/model/cbi/niu/network/routes1.lua b/modules/niu/luasrc/model/cbi/niu/network/routes1.lua new file mode 100644 index 000000000..3e8e29715 --- /dev/null +++ b/modules/niu/luasrc/model/cbi/niu/network/routes1.lua @@ -0,0 +1,55 @@ +--[[ +LuCI - Lua Configuration Interface + +Copyright 2008 Steven Barth + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +$Id$ +]]-- + +m = Map("network", translate("a_n_routes"), translate("a_n_routes1")) + +local routes6 = luci.sys.net.routes6() +local bit = require "bit" + +s = m:section(TypedSection, "route", translate("a_n_routes_static4")) +s.addremove = true +s.anonymous = true + +s.template = "cbi/tblsection" + +iface1 = s:option(ListValue, "interface", translate("interface")) + +s:option(Value, "target", translate("target"), translate("a_n_r_target1")) +s:option(Value, "netmask", translate("netmask"), translate("a_n_r_netmask1")).rmemepty = true +s:option(Value, "gateway", translate("gateway")) + +if routes6 then + s = m:section(TypedSection, "route6", translate("a_n_routes_static6")) + s.addremove = true + s.anonymous = true + + s.template = "cbi/tblsection" + + iface2 = s:option(ListValue, "interface", translate("interface")) + + s:option(Value, "target", translate("target"), translate("a_n_r_target6")) + s:option(Value, "gateway", translate("gateway6")).rmempty = true +end + +m.uci:foreach("network", "interface", function(s) + if s[".name"] ~= "loopback" then + iface:value(s[".name"]) + if iface2 then + iface2:value(s[".name"]) + end + end +end) + + +return m diff --git a/modules/niu/luasrc/view/niu/network.htm b/modules/niu/luasrc/view/niu/network.htm index 71296371f..a022b0af8 100644 --- a/modules/niu/luasrc/view/niu/network.htm +++ b/modules/niu/luasrc/view/niu/network.htm @@ -7,10 +7,6 @@ local nws = {} str.uci_state:foreach("network", "interface", function(s) nws[#nws+1] = s end) - -local function cmp(a, b) - return (a.order or 100) < (b.order or 100) -end %>
Status:
@@ -23,7 +19,11 @@ for _, v in ipairs(nws) do if v[".name"] ~= "loopback" then
    <% -for k, v in utl.spairs(dsp.node("niu", "network").nodes, cmp) do +local nodes = dsp.node("niu", "network").nodes +local function cmp(a, b) + return (nodes[a].order or 100) < (nodes[b].order or 100) +end +for k, v in utl.spairs(nodes, cmp) do %>
  • "><%=v.title%>
  • <% -- 2.11.0