admin-full/diagnostics: Allow to use ping6 and traceroute6 when available, #487
[project/luci.git] / modules / admin-full / luasrc / controller / admin / network.lua
index 5a10266..6f55ff7 100644 (file)
@@ -10,7 +10,6 @@ You may obtain a copy of the License at
 
        http://www.apache.org/licenses/LICENSE-2.0
 
-$Id$
 ]]--
 
 module("luci.controller.admin.network", package.seeall)
@@ -39,17 +38,20 @@ function index()
                        page.target = cbi("admin_network/vlan")
                        page.title  = _("Switch")
                        page.order  = 20
+
+                       page = entry({"admin", "network", "switch_status"}, call("switch_status"), nil)
+                       page.leaf = true
                end
 
 
                local has_wifi = false
-               
+
                uci:foreach("wireless", "wifi-device",
                        function(s)
                                has_wifi = true
                                return false
                        end)
-               
+
                if has_wifi then
                        page = entry({"admin", "network", "wireless_join"}, call("wifi_join"), nil)
                        page.leaf = true
@@ -154,6 +156,12 @@ function index()
 
                page = entry({"admin", "network", "diag_traceroute"}, call("diag_traceroute"), nil)
                page.leaf = true
+
+               page = entry({"admin", "network", "diag_ping6"}, call("diag_ping6"), nil)
+               page.leaf = true
+
+               page = entry({"admin", "network", "diag_traceroute6"}, call("diag_traceroute6"), nil)
+               page.leaf = true
 --     end
 end
 
@@ -214,14 +222,17 @@ function wifi_delete(network)
        local wnet = ntm:get_wifinet(network)
        if wnet then
                local dev = wnet:get_device()
-               local net = wnet:get_network()
+               local nets = wnet:get_networks()
                if dev then
                        luci.sys.call("env -i /sbin/wifi down %q >/dev/null" % dev:name())
                        ntm:del_wifinet(network)
                        ntm:commit("wireless")
-                       if net and net:is_empty() then
-                               ntm:del_network(net:name())
-                               ntm:commit("network")
+                       local _, net
+                       for _, net in ipairs(nets) do
+                               if net:is_empty() then
+                                       ntm:del_network(net:name())
+                                       ntm:commit("network")
+                               end
                        end
                        luci.sys.call("env -i /sbin/wifi up %q >/dev/null" % dev:name())
                end
@@ -270,11 +281,13 @@ function iface_status()
                                }
                        end
                        for _, a in ipairs(device:ip6addrs()) do
-                               data.ip6addrs[#data.ip6addrs+1] = {
-                                       addr      = a:host():string(),
-                                       netmask   = a:mask():string(),
-                                       prefix    = a:prefix()
-                               }
+                               if not a:is6linklocal() then
+                                       data.ip6addrs[#data.ip6addrs+1] = {
+                                               addr      = a:host():string(),
+                                               netmask   = a:mask():string(),
+                                               prefix    = a:prefix()
+                                       }
+                               end
                        end
 
                        for _, device in ipairs(net:get_interfaces() or {}) do
@@ -405,7 +418,19 @@ function lease_status()
        local s = require "luci.tools.status"
 
        luci.http.prepare_content("application/json")
+       luci.http.write('[')
        luci.http.write_json(s.dhcp_leases())
+       luci.http.write(',')
+       luci.http.write_json(s.dhcp6_leases())
+       luci.http.write(']')
+end
+
+function switch_status()
+       local path = luci.dispatcher.context.requestpath
+       local s = require "luci.tools.status"
+
+       luci.http.prepare_content("application/json")
+       luci.http.write_json(s.switch_status(path[#path]))
 end
 
 function diag_command(cmd)
@@ -444,3 +469,11 @@ end
 function diag_nslookup()
        diag_command("nslookup %q 2>&1")
 end
+
+function diag_ping6()
+       diag_command("ping6 -c 5 %q 2>&1")
+end
+
+function diag_traceroute6()
+       diag_command("traceroute6 -q 1 -w 2 -n %q 2>&1")
+end