From 0784b7b9d512602f519aa7c0e826f97ef5ca25ff Mon Sep 17 00:00:00 2001 From: Steven Barth Date: Fri, 13 Nov 2009 18:26:06 +0000 Subject: [PATCH 1/1] NIU: WAN Ehternet / DSL complete. Custom Routes complete. Conntrack introduced. Overall minor fixes. --- modules/niu/luasrc/controller/niu/network.lua | 13 ++- .../niu/luasrc/model/cbi/niu/network/assign1.lua | 38 ++++++- .../niu/luasrc/model/cbi/niu/network/etherwan.lua | 13 ++- modules/niu/luasrc/model/cbi/niu/network/lan1.lua | 3 + .../niu/luasrc/model/cbi/niu/network/routes1.lua | 10 +- modules/niu/luasrc/model/cbi/niu/network/wan.lua | 36 ++++++- .../niu/luasrc/model/cbi/niu/network/wandevice.lua | 26 +++-- modules/niu/luasrc/view/niu/network/conntrack.htm | 75 ++++++++++++++ modules/niu/luasrc/view/niu/network/rtable.htm | 111 +++++++++++++++++++++ 9 files changed, 297 insertions(+), 28 deletions(-) create mode 100644 modules/niu/luasrc/view/niu/network/conntrack.htm create mode 100644 modules/niu/luasrc/view/niu/network/rtable.htm diff --git a/modules/niu/luasrc/controller/niu/network.lua b/modules/niu/luasrc/controller/niu/network.lua index 36aff630d..c90662b6e 100644 --- a/modules/niu/luasrc/controller/niu/network.lua +++ b/modules/niu/luasrc/controller/niu/network.lua @@ -12,7 +12,7 @@ You may obtain a copy of the License at $Id$ ]]-- -local req = require +local require = require module "luci.controller.niu.network" function index() @@ -27,10 +27,17 @@ function index() uci.inst_state:foreach("dhcp", "dhcp", function(s) if s.interface == "lan" and s.ignore ~= "1" then entry({"niu", "network", "assign"}, cbi("niu/network/assign", - {on_success_to={"niu"}}), "Assign local addresses", 30) + {on_success_to={"niu"}}), "Display and Customize Address Assignment", 30) end end) entry({"niu", "network", "routes"}, cbi("niu/network/routes", - {on_success_to={"niu"}}), "Assign custom routes", 40) + {on_success_to={"niu"}}), "Display and Customize Routing", 40) + + entry({"niu", "network", "conntrack"}, call("cnntrck"), + "Display Local Network Activity", 50) +end + +function cnntrck() + require "luci.template".render("niu/network/conntrack") end diff --git a/modules/niu/luasrc/model/cbi/niu/network/assign1.lua b/modules/niu/luasrc/model/cbi/niu/network/assign1.lua index e226e2376..fdd0dc00b 100644 --- a/modules/niu/luasrc/model/cbi/niu/network/assign1.lua +++ b/modules/niu/luasrc/model/cbi/niu/network/assign1.lua @@ -14,10 +14,39 @@ $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 function date_format(secs) + local suff = {"min", "h", "d"} + local mins = 0 + local hour = 0 + local days = 0 + + secs = math.floor(secs) + if secs > 60 then + mins = math.floor(secs / 60) + secs = secs % 60 + end + + if mins > 60 then + hour = math.floor(mins / 60) + mins = mins % 60 + end + + if hour > 24 then + days = math.floor(hour / 24) + hour = hour % 24 + end + + if days > 0 then + return string.format("%.0fd %02.0fh %02.0fmin %02.0fs", days, hour, mins, secs) + else + return string.format("%02.0fh %02.0fmin %02.0fs", hour, mins, secs) + end +end + +m2 = Map("dhcp", "Display and Customize Address Assignment") local leasefn, leasefp, leases uci:foreach("dhcp", "dnsmasq", @@ -42,11 +71,12 @@ if leases then ltime = v:option(DummyValue, 1, translate("Leasetime remaining")) function ltime.cfgvalue(self, ...) local value = DummyValue.cfgvalue(self, ...) - return wa.date_format(os.difftime(tonumber(value), os.time())) + return date_format(os.difftime(tonumber(value), os.time())) end end -s = m2:section(TypedSection, "host") +s = m2:section(TypedSection, "host", "Static Assignment", +"You can assign fixed addresses and DNS names to devices in you local network to make reaching them more easy.") s.addremove = true s.anonymous = true s.template = "cbi/tblsection" diff --git a/modules/niu/luasrc/model/cbi/niu/network/etherwan.lua b/modules/niu/luasrc/model/cbi/niu/network/etherwan.lua index e3da1c0aa..4f2744b81 100644 --- a/modules/niu/luasrc/model/cbi/niu/network/etherwan.lua +++ b/modules/niu/luasrc/model/cbi/niu/network/etherwan.lua @@ -23,7 +23,7 @@ local has_pppoe = fs.glob("/usr/lib/pppd/*/rp-pppoe.so")() local has_pppoa = fs.glob("/usr/lib/pppd/*/pppoatm.so")() -m = Map("network", translate("m_n_internet")) +m = Map("network", "Configure Ethernet Adapter") nw.init(m.uci) s = m:section(NamedSection, "wan", "interface") @@ -32,15 +32,14 @@ s.addremove = false s:tab("general", translate("General Settings")) s:tab("expert", translate("Expert Settings")) -p = s:taboption("general", ListValue, "proto", translate("Protocol")) +p = s:taboption("general", ListValue, "proto", "Connection Type") p.override_scheme = true -p.default = "static" -p:value("static", translate("static")) -p:value("dhcp", "DHCP") -if has_pppoe then p:value("pppoe", "PPPoE") end +p.default = "dhcp" +p:value("dhcp", "Cable / Ethernet / DHCP") +if has_pppoe then p:value("pppoe", "DSL / PPPoE") end if has_pppoa then p:value("pppoa", "PPPoA") end if has_pptp then p:value("pptp", "PPTP") end -p:value("none", translate("none")) +p:value("static", "Static Ethernet") diff --git a/modules/niu/luasrc/model/cbi/niu/network/lan1.lua b/modules/niu/luasrc/model/cbi/niu/network/lan1.lua index 77b0fa76e..e8069d5b3 100644 --- a/modules/niu/luasrc/model/cbi/niu/network/lan1.lua +++ b/modules/niu/luasrc/model/cbi/niu/network/lan1.lua @@ -100,6 +100,9 @@ s:tab("expert", translate("Expert Settings")) start = s:taboption("expert", Value, "start", translate("First leased address")) limit = s:taboption("expert", Value, "limit", translate("Number of leased addresses"), "") time = s:taboption("expert", Value, "leasetime", "Lease Time") +local dd = s:taboption("expert", Flag, "dynamicdhcp", "Also generate addresses for unknown devices") +dd.rmempty = false +dd.default = "1" return m, m2 diff --git a/modules/niu/luasrc/model/cbi/niu/network/routes1.lua b/modules/niu/luasrc/model/cbi/niu/network/routes1.lua index a1d150807..094831e72 100644 --- a/modules/niu/luasrc/model/cbi/niu/network/routes1.lua +++ b/modules/niu/luasrc/model/cbi/niu/network/routes1.lua @@ -12,12 +12,15 @@ You may obtain a copy of the License at $Id$ ]]-- -m = Map("network", translate("Routes"), translate("a_n_routes1")) +m = Map("network", translate("Display and Customize Routing"), +translate("With additional static routes you allow computers on your network to reach unannounced remote hosts or networks.")) local routes6 = luci.sys.net.routes6() local bit = require "bit" -s = m:section(TypedSection, "route", translate("Static IPv4 Routes")) +m:append(Template("niu/network/rtable")) + +s = m:section(TypedSection, "route", "Static IPv4 Routes") s.addremove = true s.anonymous = true @@ -30,7 +33,7 @@ s:option(Value, "netmask", translate("IPv4-Gateway")) if routes6 then - s = m:section(TypedSection, "route6", translate("Static IPv6 Routes")) + s = m:section(TypedSection, "route6", "Static IPv6 Routes") s.addremove = true s.anonymous = true @@ -51,5 +54,4 @@ m.uci:foreach("network", "interface", function(s) end end) - return m diff --git a/modules/niu/luasrc/model/cbi/niu/network/wan.lua b/modules/niu/luasrc/model/cbi/niu/network/wan.lua index 6c23738eb..b7351ff19 100644 --- a/modules/niu/luasrc/model/cbi/niu/network/wan.lua +++ b/modules/niu/luasrc/model/cbi/niu/network/wan.lua @@ -1,11 +1,45 @@ local cursor = require "luci.model.uci".cursor() + +if not cursor:get("network", "wan") then + cursor:section("network", "interface", "wan", {proto = "none"}) + cursor:save("network") +end + +local function deviceroute(self) + cursor:unload("network") + local wd = cursor:get("network", "wan", "_wandev") or "" + + if wd == "none" then + cursor:set("network", "wan", "proto", "none") + end + + if wd:find("ethernet:") == 1 then + cursor:set("network", "wan", "defaultroute", "1") + cursor:set("network", "wan", "ifname", wd:sub(10)) + self:set_route("etherwan") + else + cursor:delete("network", "wan", "ifname") + end + + if wd:find("wlan:") == 1 then + + else + cursor:delete_all("wireless", "wifi-iface", {network = "wan"}) + end + + cursor:save("wireless") + cursor:save("network") +end + + local d = Delegator() d.allow_finish = true d.allow_back = true d.allow_cancel = true d:add("device", load("niu/network/wandevice")) -d:add("etherwan", load("niu/network/etherwan")) +d:add("deviceroute", deviceroute) +d:set("etherwan", load("niu/network/etherwan")) function d.on_cancel() cursor:revert("network") diff --git a/modules/niu/luasrc/model/cbi/niu/network/wandevice.lua b/modules/niu/luasrc/model/cbi/niu/network/wandevice.lua index 1f65196f1..db7d90254 100644 --- a/modules/niu/luasrc/model/cbi/niu/network/wandevice.lua +++ b/modules/niu/luasrc/model/cbi/niu/network/wandevice.lua @@ -12,19 +12,27 @@ You may obtain a copy of the License at $Id$ ]]-- -local cursor = require "luci.model.uci".cursor() +local cursor = require "luci.model.uci".inst_state local nw = require "luci.model.network" nw.init(cursor) -f = Form("wandev", "Internet Device") -l = f:field(ListValue, "device", "Gerät") -l:value("ethernet:eth0", "Ethernet / Cable / DSL (eth0)") -l:value("none", "No Internet Connection") +m = Map("network", "Configure Internet Connection") +s = m:section(NamedSection, "wan", "interface", "Internet Connection Device") +s.anonymous = true +s.addremove = false + +l = s:option(ListValue, "_wandev", "Internet Connection via") -function f.handle(self, state, data) - if state == FORM_VALID then - +for _, iface in ipairs(nw.get_interfaces()) do + if iface:name():find("eth") == 1 then + local net = iface:get_network() + if not net or net:name() == "wan" or os.getenv("LUCI_SYSROOT") then + l:value("ethernet:%s" % iface:name(), + "Cable / DSL / Ethernet Adapter (%s)" % iface:name()) + end end end -return f +l:value("none", "No Internet Connection") + +return m diff --git a/modules/niu/luasrc/view/niu/network/conntrack.htm b/modules/niu/luasrc/view/niu/network/conntrack.htm new file mode 100644 index 000000000..09b1d6b1c --- /dev/null +++ b/modules/niu/luasrc/view/niu/network/conntrack.htm @@ -0,0 +1,75 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008-2009 Steven Barth +Copyright 2008-2009 Jo-Philipp Wich + +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 sys = require "luci.sys" + local style = true +-%> + +<%+header%> + +
+

<%:Active Connections%>

+
<%:This page gives an overview over currently active network connections.%>
+ +
+ ARP +
+ + + + + + + + <% sys.net.arptable(function(e) %> + + + + + + <% style = not style; end) %> +
<%_IPv4-Address%><%_MAC-Address%><%:Interface%>
<%=e["IP address"]%><%=e["HW address"]%><%=e["Device"]%>
+
+
+
+ +
+ <%:Active Connections%> +
+ + + + + + + + + <% style = true; sys.net.conntrack(function(c) %> + + + + + + + <% style = not style; end) %> +
<%:Network%><%:Protocol%><%:Source%><%:Destination%>
<%=c.layer3:upper()%><%=c.layer4:upper()%><%=c.src%><%=c.dst%>
+
+
+
+
+ +<%+footer%> + diff --git a/modules/niu/luasrc/view/niu/network/rtable.htm b/modules/niu/luasrc/view/niu/network/rtable.htm new file mode 100644 index 000000000..4452a87db --- /dev/null +++ b/modules/niu/luasrc/view/niu/network/rtable.htm @@ -0,0 +1,111 @@ +<%# +LuCI - Lua Configuration Interface +Copyright 2008-2009 Steven Barth +Copyright 2008-2009 Jo-Philipp Wich + +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 fs = require "nixio.fs" + local bit = require "nixio".bit + local sys = require "luci.sys" + local uci = require "luci.model.uci" + local inst = uci.inst + local state = uci.inst_state + local http = require "luci.http" + local style = true + + + local ifc = {__index = function(self, key) + local net = key + state:foreach("network", "interface", function(s) + if s.ifname == key then + net = s[".name"] + end + end) + rawset(self, key, net) + return net + end} + setmetatable(ifc, ifc) + + if http.formvalue("toggle_rtable") then + local cursor = uci.cursor() + local rt = cursor:get("network", "lan", "_showrtable") or "1" + cursor:set("network", "lan", "_showrtable", rt == "1" and "0" or "1") + cursor:save("network") + cursor:unload("network") + end +-%> + + +
+ +<% if inst:get("network", "lan", "_showrtable") ~= "0" then %> +
+ +
+ <%_Active IPv4-Routes%> + +
+ + + + + + + + + <% luci.sys.net.routes(function(rt) %> + + + + + + + + <% style = not style; end) %> +
<%:Network%><%:Target%><%_IPv4-Netmask%><%_IPv4-Gateway%><%:Metric%>
<%=ifc[rt.device]%><%=rt.dest:network():string()%><%=rt.dest:mask():string()%><%=rt.gateway:string()%><%=rt.metric%>
+
+
+
+ + <% if fs.access("/proc/net/ipv6_route") then style = true %> +
+ <%_Active IPv6-Routes%> + +
+ + + + + + + + <% luci.sys.net.routes6(function(rt) %> + + + + + + + <% style = not style; end) %> +
<%:Network%><%:Target%><%_IPv6-Gateway%><%:Metric%>
<%=ifc[rt.device]%><%=rt.dest:string()%><%=rt.source:string()%><%- + local metr = rt.metric + local lower = bit.band(metr, 0xffff) + local higher = bit.rshift(bit.band(metr, 0xffff0000), 16) + write(string.format("%04X%04X", higher, lower)) + -%>
+
+
+
+ <% end %> +
+<% end %> -- 2.11.0