modules/admin-full: Added conntrack network page
authorSteven Barth <steven@midlink.org>
Wed, 8 Oct 2008 21:46:20 +0000 (21:46 +0000)
committerSteven Barth <steven@midlink.org>
Wed, 8 Oct 2008 21:46:20 +0000 (21:46 +0000)
i18n/english/luasrc/i18n/admin-core.en.lua
i18n/english/luasrc/i18n/admin-core.en.xml
i18n/english/luasrc/i18n/default.en.lua
i18n/english/luasrc/i18n/default.en.xml
i18n/german/luasrc/i18n/admin-core.de.lua
i18n/german/luasrc/i18n/admin-core.de.xml
i18n/german/luasrc/i18n/default.de.lua
i18n/german/luasrc/i18n/default.de.xml
libs/sys/luasrc/sys.lua
modules/admin-full/luasrc/controller/admin/network.lua
modules/admin-full/luasrc/model/cbi/admin_network/conntrack.lua [new file with mode: 0644]

index f5d0a28..7eacad3 100644 (file)
@@ -163,6 +163,8 @@ dhcp_dnsmasq_dhcpleasemax = '<abbr title="maximal">max.</abbr> <abbr title="Dyna
 dhcp_dnsmasq_addnhosts = 'additional hostfile'
 dhcp_dnsmasq_queryport = 'query port'
 a_n_switch = 'Switch'
+a_n_conntrack = 'Active Connections'
+a_n_conntrack_desc = 'This page gives an overview over currently active network connections.'
 a_n_routes = 'Routes'
 a_network1 = 'In this area you find all network-related settings.'
 a_network2 = 'On most routers the network switch can be freely configured and splitted up into several <abbr title="Virtual Local Area Network">VLAN</abbr>s.'
index 255bd5d..dff5516 100644 (file)
 <i18n:msg xml:id="dhcp_dnsmasq_addnhosts">additional hostfile</i18n:msg>
 <i18n:msg xml:id="dhcp_dnsmasq_queryport">query port</i18n:msg>
 <i18n:msg xml:id="a_n_switch">Switch</i18n:msg>
+<i18n:msg xml:id="a_n_conntrack">Active Connections</i18n:msg>
+<i18n:msg xml:id="a_n_conntrack_desc">This page gives an overview over currently active network connections.</i18n:msg>
 <i18n:msg xml:id="a_n_routes">Routes</i18n:msg>
 <i18n:msg xml:id="a_network1">In this area you find all network-related settings.</i18n:msg>
 <i18n:msg xml:id="a_network2">On most routers the network switch can be freely configured and splitted up into several <abbr title="Virtual Local Area Network">VLAN</abbr>s.</i18n:msg>
index 77925f0..3613f10 100644 (file)
@@ -21,6 +21,7 @@ confirmation = 'Confirmation'
 delete = 'Delete'
 descr = 'Description'
 design = 'Design'
+destination = 'Destination'
 device = 'Device'
 devices = 'Devices'
 disable = 'disable'
@@ -79,6 +80,7 @@ service = 'Service'
 services = 'Services'
 settings = 'Settings'
 size = 'Size'
+source = 'Source'
 start = 'Start'
 static = 'static'
 status = 'Status'
index 24e4aee..cf67c7f 100644 (file)
@@ -26,6 +26,7 @@
 <i18n:msg xml:id="delete">Delete</i18n:msg>
 <i18n:msg xml:id="descr">Description</i18n:msg>
 <i18n:msg xml:id="design">Design</i18n:msg>
+<i18n:msg xml:id="destination">Destination</i18n:msg>
 <i18n:msg xml:id="device">Device</i18n:msg>
 <i18n:msg xml:id="devices">Devices</i18n:msg>
 <i18n:msg xml:id="disable">disable</i18n:msg>
@@ -84,6 +85,7 @@
 <i18n:msg xml:id="services">Services</i18n:msg>
 <i18n:msg xml:id="settings">Settings</i18n:msg>
 <i18n:msg xml:id="size">Size</i18n:msg>
+<i18n:msg xml:id="source">Source</i18n:msg>
 <i18n:msg xml:id="start">Start</i18n:msg>
 <i18n:msg xml:id="static">static</i18n:msg>
 <i18n:msg xml:id="status">Status</i18n:msg>
index c0169b4..f43155f 100644 (file)
@@ -25,6 +25,8 @@ a_n_routes_static = 'Statische Routen'
 a_n_routes_kernel4 = 'Aktive IPv4-Routen'
 a_n_switch = 'Switch'
 a_n_switch1 = 'Die Netzwerkschnittstellen am Router können zu verschienden VLANs zusammengefasst werden, in denen Geräte miteinander direkt kommunizieren können. VLANs werden auch häufig dazu genutzt, um Netzwerke voneiander zu trennen. So ist oftmals eine Schnittstelle als Uplink zu einem größerem Netz, wie dem Internet vorkonfiguriert und die anderen Schnittstellen bilden ein VLAN für das lokale Netzwerk.'
+a_n_conntrack = 'Aktive Verbindungen'
+a_n_conntrack_desc = 'Diese Seite gibt eine Übersicht über aktive Netzwerkverbindungen.'
 a_network1 = 'In diesem Bereich finden sich alle netzwerkbezogenen Einstellungen.'
 a_network2 = 'Der Netzwerkswitch kann bei den meisten Routern frei konfiguriert und in mehrere VLANs aufgeteilt werden.'
 a_network3 = 'Schnittstellen und PPPoE/PPTP-Einstellungen ermöglichen die freie Organisation des Netzwerks und die Anbindung an ein WAN.'
index f0f90b0..093eb65 100644 (file)
@@ -29,6 +29,8 @@
 <i18n:msg xml:id="a_n_routes_kernel4">Aktive IPv4-Routen</i18n:msg>
 <i18n:msg xml:id="a_n_switch">Switch</i18n:msg>
 <i18n:msg xml:id="a_n_switch1">Die Netzwerkschnittstellen am Router können zu verschienden VLANs zusammengefasst werden, in denen Geräte miteinander direkt kommunizieren können. VLANs werden auch häufig dazu genutzt, um Netzwerke voneiander zu trennen. So ist oftmals eine Schnittstelle als Uplink zu einem größerem Netz, wie dem Internet vorkonfiguriert und die anderen Schnittstellen bilden ein VLAN für das lokale Netzwerk.</i18n:msg>
+<i18n:msg xml:id="a_n_conntrack">Aktive Verbindungen</i18n:msg>
+<i18n:msg xml:id="a_n_conntrack_desc">Diese Seite gibt eine Übersicht über aktive Netzwerkverbindungen.</i18n:msg>
 <i18n:msg xml:id="a_network1">In diesem Bereich finden sich alle netzwerkbezogenen Einstellungen.</i18n:msg>
 <i18n:msg xml:id="a_network2">Der Netzwerkswitch kann bei den meisten Routern frei konfiguriert und in mehrere VLANs aufgeteilt werden.</i18n:msg>
 <i18n:msg xml:id="a_network3">Schnittstellen und PPPoE/PPTP-Einstellungen ermöglichen die freie Organisation des Netzwerks und die Anbindung an ein WAN.</i18n:msg>
index aedaa81..8700c1c 100644 (file)
@@ -21,6 +21,7 @@ confirmation = 'Bestätigung'
 delete = 'Löschen'
 descr = 'Beschreibung'
 design = 'Design'
+destination = 'Ziel'
 device = 'Gerät'
 devices = 'Geräte'
 disable = 'deaktivieren'
@@ -79,6 +80,7 @@ service = 'Dienst'
 services = 'Dienste'
 settings = 'Einstellungen'
 size = 'Größe'
+source = 'Quelle'
 start = 'Start'
 static = 'statisch'
 statistics = 'Statistiken'
index d24c56c..91a067d 100644 (file)
@@ -30,6 +30,7 @@
 <i18n:msg xml:id="delete">Löschen</i18n:msg>
 <i18n:msg xml:id="descr">Beschreibung</i18n:msg>
 <i18n:msg xml:id="design">Design</i18n:msg>
+<i18n:msg xml:id="destination">Ziel</i18n:msg>
 <i18n:msg xml:id="device">Gerät</i18n:msg>
 <i18n:msg xml:id="devices">Geräte</i18n:msg>
 <i18n:msg xml:id="disable">deaktivieren</i18n:msg>
 <i18n:msg xml:id="services">Dienste</i18n:msg>
 <i18n:msg xml:id="settings">Einstellungen</i18n:msg>
 <i18n:msg xml:id="size">Größe</i18n:msg>
+<i18n:msg xml:id="source">Quelle</i18n:msg>
 <i18n:msg xml:id="start">Start</i18n:msg>
 <i18n:msg xml:id="static">statisch</i18n:msg>
 <i18n:msg xml:id="statistics">Statistiken</i18n:msg>
index 566e815..a88afaf 100644 (file)
@@ -259,6 +259,38 @@ function net.arptable()
        return _parse_delimited_table(io.lines("/proc/net/arp"), "%s%s+")
 end
 
+--- Returns conntrack information
+-- @return     Table with the currently tracked IP connections
+function net.conntrack()
+       local connt = {}
+       if luci.fs.access("/proc/net/nf_conntrack") then
+               for line in io.lines("/tmp/nf_conntrack") do
+                       local entry = _parse_mixed_record(line, " +")
+                       entry.layer3 = entry[1]
+                       entry.layer4 = entry[2]
+                       for i=1, #entry do
+                               entry[i] = nil
+                       end
+
+                       connt[#connt+1] = entry
+               end
+       elseif luci.fs.access("/proc/net/ip_conntrack") then
+               for line in io.lines("/proc/net/nf_conntrack") do
+                       local entry = _parse_mixed_record(line, " +")
+                       entry.layer3 = "ipv4"
+                       entry.layer4 = entry[1]
+                       for i=1, #entry do
+                               entry[i] = nil
+                       end
+
+                       connt[#connt+1] = entry
+               end
+       else
+               return nil
+       end
+       return connt
+end
+
 --- Determine the current default route.
 -- @return     Table with the properties of the current default route.
 --                     The following fields are defined:
@@ -614,11 +646,12 @@ function _parse_delimited_table(iter, delimiter)
        return data
 end
 
-function _parse_mixed_record(cnt)
+function _parse_mixed_record(cnt, delimiter)
+       delimiter = delimiter or "  "
        local data = {}
 
        for i, l in pairs(luci.util.split(luci.util.trim(cnt), "\n")) do
-       for j, f in pairs(luci.util.split(luci.util.trim(l), "  ")) do
+               for j, f in pairs(luci.util.split(luci.util.trim(l), delimiter, nil, true)) do
                local k, x, v = f:match('([^%s][^:=]+) *([:=]*) *"*([^\n"]*)"*')
 
             if k then
index 72bf7cc..e3f80a1 100644 (file)
@@ -94,4 +94,11 @@ function index()
         i18n("a_n_routes_static")
        )
 
+       entry(
+               {"admin", "network", "conntrack"},
+               form("admin_network/conntrack"),
+               i18n("a_n_conntrack"),
+               60
+       )
+
 end
diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/conntrack.lua b/modules/admin-full/luasrc/model/cbi/admin_network/conntrack.lua
new file mode 100644 (file)
index 0000000..4cd6d2b
--- /dev/null
@@ -0,0 +1,44 @@
+--[[
+LuCI - Lua Configuration Interface
+
+Copyright 2008 Steven Barth <steven@midlink.org>
+Copyright 2008 Jo-Philipp Wich <xm@leipzig.freifunk.net>
+
+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$
+]]--
+
+f = SimpleForm("conntrack", translate("a_n_conntrack"), translate("a_n_conntrack_desc"))
+f.reset = false
+f.submit = false
+
+t = f:section(Table, luci.sys.net.conntrack())
+l3 = t:option(DummyValue, "layer3", translate("network"))
+function l3.cfgvalue(self, ...)
+       return DummyValue.cfgvalue(self, ...):upper()
+end
+
+
+l4 = t:option(DummyValue, "layer4", translate("protocol"))
+function l4.cfgvalue(self, ...)
+       return DummyValue.cfgvalue(self, ...):upper()
+end
+
+s = t:option(DummyValue, "src", translate("source"))
+function s.cfgvalue(self, section)
+       return "%s:%s" % { self.map:get(section, "src"),
+                                        self.map:get(section, "sport") or "*" }
+end
+
+d = t:option(DummyValue, "dst", translate("destination"))
+function d.cfgvalue(self, section)
+       return "%s:%s" % { self.map:get(section, "dst"),
+                                        self.map:get(section, "dport") or "*" }
+end
+
+return f
\ No newline at end of file