modules/admin-full: add DNS resolution to connections status page, order connections...
authorJo-Philipp Wich <jow@openwrt.org>
Sun, 4 Mar 2012 18:36:05 +0000 (18:36 +0000)
committerJo-Philipp Wich <jow@openwrt.org>
Sun, 4 Mar 2012 18:36:05 +0000 (18:36 +0000)
modules/admin-full/luasrc/controller/admin/status.lua
modules/admin-full/luasrc/view/admin_status/connections.htm

index f77d91b3434552aa833705c48c638f3bd8602094..d7d301c542e11722a8108be99d14f4b240fce9f8 100644 (file)
@@ -37,6 +37,8 @@ function index()
 
        entry({"admin", "status", "realtime", "connections"}, template("admin_status/connections"), _("Connections"), 4).leaf = true
        entry({"admin", "status", "realtime", "connections_status"}, call("action_connections")).leaf = true
+
+       entry({"admin", "status", "nameinfo"}, call("action_nameinfo")).leaf = true
 end
 
 function action_syslog()
@@ -153,3 +155,16 @@ function action_connections()
 
        luci.http.write(" }")
 end
+
+function action_nameinfo(...)
+       local i
+       local rv = { }
+       for i = 1, select('#', ...) do
+               local addr = select(i, ...)
+               local fqdn = nixio.getnameinfo(addr)
+               rv[addr] = fqdn or (addr:match(":") and "[%s]" % addr or addr)
+       end
+
+       luci.http.prepare_content("application/json")
+       luci.http.write_json(rv)
+end
index bfa2a33a4507c36c9280409e283fd4416658932a..9c9eb01c966408682693eee45b5ed1caa9a4f992 100644 (file)
@@ -59,6 +59,8 @@ $Id$
 
        var conn_table;
 
+       var dns_cache = { };
+
 
        /* wait for SVG */
        window.setTimeout(
@@ -149,19 +151,47 @@ $Id$
                                                while (conn_table.rows.length > 1)
                                                        conn_table.rows[0].parentNode.deleteRow(-1);
 
+
+                                               var lookup_queue = [ ];
+
+                                               conn.sort(function(a, b) {
+                                                       return b.bytes - a.bytes;
+                                               });
+
                                                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.className = 'cbi-section-table-row cbi-rowstyle-' + (1 + (i % 2));
+
+                                                       if (!dns_cache[c.src])
+                                                               lookup_queue.push(c.src);
+
+                                                       if (!dns_cache[c.dst])
+                                                               lookup_queue.push(c.dst);
+
+                                                       var src = dns_cache[c.src] || (c.layer3 == 'ipv6' ? '[' + c.src + ']' : c.src);
+                                                       var dst = dns_cache[c.dst] || (c.layer3 == 'ipv6' ? '[' + c.dst + ']' : c.dst);
 
                                                        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);
+                                                       tr.insertCell(-1).innerHTML = String.format('%s:%d', src, c.sport);
+                                                       tr.insertCell(-1).innerHTML = String.format('%s:%d', dst, c.dport);
+
+                                                       var traf = tr.insertCell(-1);
+                                                           traf.style.whiteSpace = 'nowrap';
+                                                           traf.innerHTML = String.format('%1024.2mB (%d <%:Pkts.%>)', c.bytes, c.packets);
                                                }
 
+                                               if (lookup_queue.length > 0)
+                                                       XHR.get('<%=build_url("admin/status/nameinfo")%>/' + lookup_queue.slice(0, 100).join('/'), null,
+                                                               function(x, json)
+                                                               {
+                                                                       for (var addr in json)
+                                                                               dns_cache[addr] = json[addr];
+                                                               }
+                                                       );
+
 
                                                var data = json.statistics;