From: Jo-Philipp Wich Date: Sun, 13 Mar 2011 22:12:42 +0000 (+0000) Subject: modules/admin-full: merge "Active Connections" and "Realtime Connections" X-Git-Tag: 0.11.0~2200 X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=6ea0204a554536367dd762b8b96b5de57171afa9;hp=380726158d37052a8301973affa6281dd1aa6ebc modules/admin-full: merge "Active Connections" and "Realtime Connections" --- diff --git a/modules/admin-full/luasrc/controller/admin/status.lua b/modules/admin-full/luasrc/controller/admin/status.lua index c816625bf..a7e18d3a4 100644 --- a/modules/admin-full/luasrc/controller/admin/status.lua +++ b/modules/admin-full/luasrc/controller/admin/status.lua @@ -21,18 +21,17 @@ function index() entry({"admin", "status"}, alias("admin", "status", "interfaces"), i18n("Status"), 20).index = true entry({"admin", "status", "interfaces"}, template("admin_status/index"), i18n("Overview"), 1) entry({"admin", "status", "iptables"}, call("action_iptables"), i18n("Firewall"), 2).leaf = true - entry({"admin", "status", "conntrack"}, template("admin_status/conntrack"), i18n("Active Connections"), 3) - entry({"admin", "status", "routes"}, template("admin_status/routes"), i18n("Routes"), 4) - entry({"admin", "status", "syslog"}, call("action_syslog"), i18n("System Log"), 5) - entry({"admin", "status", "dmesg"}, call("action_dmesg"), i18n("Kernel Log"), 6) + entry({"admin", "status", "routes"}, template("admin_status/routes"), i18n("Routes"), 3) + entry({"admin", "status", "syslog"}, call("action_syslog"), i18n("System Log"), 4) + entry({"admin", "status", "dmesg"}, call("action_dmesg"), i18n("Kernel Log"), 5) - entry({"admin", "status", "load"}, template("admin_status/load"), i18n("Realtime Load"), 7).leaf = true + entry({"admin", "status", "load"}, template("admin_status/load"), i18n("Realtime Load"), 6).leaf = true entry({"admin", "status", "load_status"}, call("action_load")).leaf = true - entry({"admin", "status", "bandwidth"}, template("admin_status/bandwidth"), i18n("Realtime Traffic"), 8).leaf = true + entry({"admin", "status", "bandwidth"}, template("admin_status/bandwidth"), i18n("Realtime Traffic"), 7).leaf = true entry({"admin", "status", "bandwidth_status"}, call("action_bandwidth")).leaf = true - entry({"admin", "status", "connections"}, template("admin_status/connections"), i18n("Realtime Connections"), 9).leaf = true + entry({"admin", "status", "connections"}, template("admin_status/connections"), i18n("Realtime Connections"), 8).leaf = true entry({"admin", "status", "connections_status"}, call("action_connections")).leaf = true end @@ -120,13 +119,18 @@ function action_load() end function action_connections() - local fs = require "luci.fs" - if fs.access("/var/lib/luci-bwc/connections") then - luci.http.prepare_content("application/json") + local fs = require "luci.fs" + local sys = require "luci.sys" + + luci.http.prepare_content("application/json") + + luci.http.write("{ connections: ") + luci.http.write_json(sys.net.conntrack()) + if fs.access("/var/lib/luci-bwc/connections") then local bwc = io.popen("luci-bwc -c 2>/dev/null") if bwc then - luci.http.write("[") + luci.http.write(", statistics: [") while true do local ln = bwc:read("*l") @@ -137,9 +141,7 @@ function action_connections() luci.http.write("]") bwc:close() end - - return end - luci.http.status(404, "No data available") + luci.http.write(" }") end diff --git a/modules/admin-full/luasrc/view/admin_status/connections.htm b/modules/admin-full/luasrc/view/admin_status/connections.htm index eb4839852..7ce791ba9 100644 --- a/modules/admin-full/luasrc/view/admin_status/connections.htm +++ b/modules/admin-full/luasrc/view/admin_status/connections.htm @@ -57,12 +57,35 @@ $Id$ var label_scale; + var conn_table; + function update_graph() { bwxhr.get('<%=build_url("admin/status/connections_status")%>', null, - function(x, data) + function(x, json) { + var conn = json.connections; + + while (conn_table.rows.length > 1) + conn_table.rows[0].parentNode.deleteRow(-1); + + for (var i = 0; i < conn.length; i++) + { + var c = conn[i]; + var tr = conn_table.rows[0].parentNode.insertRow(-1); + tr.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2)); + + tr.insertCell(-1).innerHTML = c.layer3.toUpperCase(); + tr.insertCell(-1).innerHTML = c.layer4.toUpperCase(); + tr.insertCell(-1).innerHTML = String.format(c.layer3 == 'ipv6' ? '[%s]:%d' : '%s:%d', c.src, c.sport); + tr.insertCell(-1).innerHTML = String.format(c.layer3 == 'ipv6' ? '[%s]:%d' : '%s:%d', c.dst, c.dport); + tr.insertCell(-1).innerHTML = String.format('%1024.2mB (%d <%:Pkts.%>)', c.bytes, c.packets); + } + + + var data = json.statistics; + var data_max = 0; var data_scale = 0; @@ -177,7 +200,7 @@ $Id$ window.setTimeout( function() { var svg = document.getElementById('bwsvg'); - + try { G = svg.getSVGDocument ? svg.getSVGDocument() : svg.contentDocument; @@ -226,7 +249,9 @@ $Id$ label_otr_avg = document.getElementById('lb_otr_avg'); label_otr_peak = document.getElementById('lb_otr_peak'); - label_scale = document.getElementById('scale'); + label_scale = document.getElementById('scale'); + + conn_table = document.getElementById('connections'); /* plot horizontal time interval lines */ @@ -260,41 +285,62 @@ $Id$

<%:Realtime Connections%>

- -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
<%:UDP:%>0<%:Average:%>0<%:Peak:%>0
<%:TCP:%>0<%:Average:%>0<%:Peak:%>0
<%:Other:%>0<%:Average:%>0<%:Peak:%>0
+
<%:This page gives an overview over currently active network connections.%>
+ +
+ <%:Active Connections%> + + +
-
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
<%:UDP:%>0<%:Average:%>0<%:Peak:%>0
<%:TCP:%>0<%:Average:%>0<%:Peak:%>0
<%:Other:%>0<%:Average:%>0<%:Peak:%>0
+
+ +
+ + + + + + + + + + +
<%:Network%><%:Protocol%><%:Source%><%:Destination%><%:Transfer%>
<%:Collecting data...%>
+
+
<%+footer%> diff --git a/modules/admin-full/luasrc/view/admin_status/conntrack.htm b/modules/admin-full/luasrc/view/admin_status/conntrack.htm deleted file mode 100644 index 2697c1cda..000000000 --- a/modules/admin-full/luasrc/view/admin_status/conntrack.htm +++ /dev/null @@ -1,82 +0,0 @@ -<%# -LuCI - Lua Configuration Interface -Copyright 2008-2009 Steven Barth -Copyright 2008-2011 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$ - --%> - -<%- - require "luci.sys" - local style = true --%> - -<%+header%> - -
-

<%:Active Connections%>

-
<%:This page gives an overview over currently active network connections.%>
- -
- ARP -
- - - - - - - - <% luci.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; luci.sys.net.conntrack(function(c) %> - - - - - - - <% style = not style; end) %> -
<%:Network%><%:Protocol%><%:Source%><%:Destination%>
<%=c.layer3:upper()%><%=c.layer4:upper()%><%= - c.layer3 == "ipv6" - and "[%s]:%d" %{ c.src, c.sport } - or "%s:%d" %{ c.src, c.sport } - %><%= - c.layer3 == "ipv6" - and "[%s]:%d" %{ c.dst, c.dport } - or "%s:%d" %{ c.dst, c.dport } - %>
-
-
-
-
- -<%+footer%>