NIU:
authorSteven Barth <steven@midlink.org>
Fri, 13 Nov 2009 18:26:06 +0000 (18:26 +0000)
committerSteven Barth <steven@midlink.org>
Fri, 13 Nov 2009 18:26:06 +0000 (18:26 +0000)
WAN Ehternet / DSL complete.
Custom Routes complete.
Conntrack introduced.
Overall minor fixes.

modules/niu/luasrc/controller/niu/network.lua
modules/niu/luasrc/model/cbi/niu/network/assign1.lua
modules/niu/luasrc/model/cbi/niu/network/etherwan.lua
modules/niu/luasrc/model/cbi/niu/network/lan1.lua
modules/niu/luasrc/model/cbi/niu/network/routes1.lua
modules/niu/luasrc/model/cbi/niu/network/wan.lua
modules/niu/luasrc/model/cbi/niu/network/wandevice.lua
modules/niu/luasrc/view/niu/network/conntrack.htm [new file with mode: 0644]
modules/niu/luasrc/view/niu/network/rtable.htm [new file with mode: 0644]

index 36aff63..c90662b 100644 (file)
@@ -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
index e226e23..fdd0dc0 100644 (file)
@@ -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"
index e3da1c0..4f2744b 100644 (file)
@@ -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")
 
 
 
index 77b0fa7..e8069d5 100644 (file)
@@ -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
index a1d1508..094831e 100644 (file)
@@ -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("<abbr title=\"Internet Protocol Version 4\
 s:option(Value, "gateway", translate("<abbr title=\"Internet Protocol Version 4\">IPv4</abbr>-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
index 6c23738..b7351ff 100644 (file)
@@ -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")
index 1f65196..db7d902 100644 (file)
@@ -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 (file)
index 0000000..09b1d6b
--- /dev/null
@@ -0,0 +1,75 @@
+<%#
+LuCI - Lua Configuration Interface
+Copyright 2008-2009 Steven Barth <steven@midlink.org>
+Copyright 2008-2009 Jo-Philipp Wich <xm@subsignal.org>
+
+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%>
+
+<div class="cbi-map" id="cbi-conntrack">
+       <h2><a id="content" name="content"><%:Active Connections%></a></h2>
+       <div class="cbi-map-descr"><%:This page gives an overview over currently active network connections.%></div>
+
+       <fieldset class="cbi-section" id="cbi-table-table">
+               <legend>ARP</legend>
+               <div class="cbi-section-node">
+                       <table class="cbi-section-table">
+                               <tr class="cbi-section-table-titles">
+                                       <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Address%></th>
+                                       <th class="cbi-section-table-cell"><%_<abbr title="Media Access Control">MAC</abbr>-Address%></th>
+                                       <th class="cbi-section-table-cell"><%:Interface%></th>
+                               </tr>
+
+                               <% sys.net.arptable(function(e) %>
+                               <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
+                                       <td class="cbi-value-field"><%=e["IP address"]%></td>
+                                       <td class="cbi-value-field"><%=e["HW address"]%></td>
+                                       <td class="cbi-value-field"><%=e["Device"]%></td>
+                               </tr>
+                               <% style = not style; end) %>
+                       </table>
+               </div>
+       </fieldset>
+       <br />
+
+       <fieldset class="cbi-section" id="cbi-table-table">
+               <legend><%:Active Connections%></legend>
+               <div class="cbi-section-node">
+                       <table class="cbi-section-table">
+                               <tr class="cbi-section-table-titles">
+                                       <th class="cbi-section-table-cell"><%:Network%></th>
+                                       <th class="cbi-section-table-cell"><%:Protocol%></th>
+                                       <th class="cbi-section-table-cell"><%:Source%></th>
+                                       <th class="cbi-section-table-cell"><%:Destination%></th>
+                               </tr>
+
+                               <% style = true; sys.net.conntrack(function(c) %>
+                               <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
+                                       <td class="cbi-value-field"><%=c.layer3:upper()%></td>
+                                       <td class="cbi-value-field"><%=c.layer4:upper()%></td>
+                                       <td class="cbi-value-field"><%=c.src%></td>
+                                       <td class="cbi-value-field"><%=c.dst%></td>
+                               </tr>
+                               <% style = not style; end) %>
+                       </table>
+               </div>
+       </fieldset>
+       <br />
+</div>
+       
+<%+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 (file)
index 0000000..4452a87
--- /dev/null
@@ -0,0 +1,111 @@
+<%#
+LuCI - Lua Configuration Interface
+Copyright 2008-2009 Steven Barth <steven@midlink.org>
+Copyright 2008-2009 Jo-Philipp Wich <xm@subsignal.org>
+
+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
+-%>
+
+<div><a href="?toggle_rtable=1"> &gt; <%:Toggle display of Routing Information%> &lt; </a></div>
+<br />
+
+<% if inst:get("network", "lan", "_showrtable") ~= "0" then %>
+<div class="cbi-map" id="x-cbi-network">
+
+       <fieldset class="cbi-section" id="x-cbi-table-table">
+               <legend><%_Active <abbr title="Internet Protocol Version 4">IPv4</abbr>-Routes%></legend>
+
+               <div class="cbi-section-node">
+                       <table class="cbi-section-table">
+                               <tr class="cbi-section-table-titles">
+                                       <th class="cbi-section-table-cell"><%:Network%></th>
+                                       <th class="cbi-section-table-cell"><%:Target%></th>
+                                       <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Netmask%></th>
+                                       <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 4">IPv4</abbr>-Gateway%></th>
+                                       <th class="cbi-section-table-cell"><%:Metric%></th>
+                               </tr>
+                               <% luci.sys.net.routes(function(rt) %>
+                               <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
+                                       <td class="cbi-value-field"><%=ifc[rt.device]%></td>
+                                       <td class="cbi-value-field"><%=rt.dest:network():string()%></td>
+                                       <td class="cbi-value-field"><%=rt.dest:mask():string()%></td>
+                                       <td class="cbi-value-field"><%=rt.gateway:string()%></td>
+                                       <td class="cbi-value-field"><%=rt.metric%></td>
+                               </tr>
+                               <% style = not style; end) %>
+                       </table>
+               </div>
+       </fieldset>
+       <br />
+
+       <% if fs.access("/proc/net/ipv6_route") then style = true %>
+       <fieldset class="cbi-section" id="x-cbi-table-table-2">
+               <legend><%_Active <abbr title="Internet Protocol Version 6">IPv6</abbr>-Routes%></legend>
+
+               <div class="cbi-section-node">
+                       <table class="cbi-section-table">
+                               <tr class="cbi-section-table-titles">
+                                       <th class="cbi-section-table-cell"><%:Network%></th>
+                                       <th class="cbi-section-table-cell"><%:Target%></th>
+                                       <th class="cbi-section-table-cell"><%_<abbr title="Internet Protocol Version 6">IPv6</abbr>-Gateway%></th>
+                                       <th class="cbi-section-table-cell"><%:Metric%></th>
+                               </tr>
+                               <% luci.sys.net.routes6(function(rt) %>
+                               <tr class="cbi-section-table-row cbi-rowstyle-<%=(style and 1 or 2)%>">
+                                       <td class="cbi-value-field"><%=ifc[rt.device]%></td>
+                                       <td class="cbi-value-field"><%=rt.dest:string()%></td>
+                                       <td class="cbi-value-field"><%=rt.source:string()%></td>
+                                       <td class="cbi-value-field"><%- 
+                                               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))
+                                       -%></td>
+                               </tr>
+                               <% style = not style; end) %>
+                       </table>
+               </div>
+       </fieldset>
+       <br />
+       <% end %>
+</div>
+<% end %>