Merge pull request #682 from cshore/pull-request-pppoe-server
[project/luci.git] / modules / luci-mod-freifunk / luasrc / view / freifunk / public_status.htm
index 715ac75..1dc1d8b 100644 (file)
@@ -2,6 +2,7 @@
 local utl = require "luci.util"
 local sys = require "luci.sys"
 local twa = require "luci.tools.webadmin"
+local ip  = require "luci.ip"
 
 -- System
 
@@ -22,12 +23,12 @@ local load = string.format("%.2f, %.2f, %.2f", loads[1] / 65535.0, loads[2] / 65
 
 local mem = string.format(
        "%.2f MB (%.2f %s, %.2f %s, %.2f %s)",
-       memory.total / 1024 / 1024,
-       (memory.total - memory.free) / 1024 / 1024,
+       meminfo.total / 1024 / 1024,
+       (meminfo.total - meminfo.free) / 1024 / 1024,
        tostring(i18n.translate("used")),
-       memory.free / 1024 / 1024,
+       meminfo.free / 1024 / 1024,
        tostring(i18n.translate("free")),
-       memory.buffered / 1024 / 1024,
+       meminfo.buffered / 1024 / 1024,
        tostring(i18n.translate("buffered"))
 )
 
@@ -48,27 +49,32 @@ for _, dev in ipairs(devices) do
 end
 local has_iwinfo = pcall(require, "iwinfo")
 
--- Routes
-local defroutev4 = sys.net.defaultroute()
-local defroutev6 = sys.net.defaultroute6()
-
-if defroutev4 then
-       defroutev4.dest = defroutev4.dest:string()
-       defroutev4.gateway = defroutev4.gateway:string()
-else
-       -- probably policy routing activated, try olsr-default table
-       local dr4 = sys.exec("ip r s t olsr-default")
-       if dr4 then
-               defroutev4 = { }
-               defroutev4.dest, defroutev4.gateway, defroutev4.device, defroutev4.metric = dr4:match("^(%w+) via (%d+.%d+.%d+.%d+) dev ([%w-]+) +metric (%d+)")
-       end
+
+-- Find default routes
+
+local _, r, def4, def6
+
+for _, r in ipairs(ip.routes({ type = 1, dest_exact = "0.0.0.0/0" })) do
+       def4 = {
+               gateway = r.gw:string(),
+               dest = r.dest:string(),
+               dev = r.dev,
+               metr = r.metric or 0
+       }
+       break
 end
 
-if defroutev6 then
-       defroutev6.dest = defroutev6.dest:string()
-       defroutev6.nexthop = defroutev6.nexthop:string()
+for _, r in ipairs(ip.routes({ type = 1, dest_exact = "::/0" })) do
+       def6 = {
+               gateway = r.gw:string(),
+               dest = r.dest:string(),
+               dev = r.dev,
+               metr = r.metric or 0
+       }
+       break
 end
 
+
 if luci.http.formvalue("status") == "1" then
        local rv = { }
        for dev in pairs(netdevs) do
@@ -86,23 +92,6 @@ if luci.http.formvalue("status") == "1" then
                rv[#rv+1] = j
        end
 
-       if defroutev6 then
-               def6 = {
-                       gateway = defroutev6.nexthop,
-                       dest = defroutev6.dest,
-                       dev = defroutev6.device,
-                       metr = defroutev6.metric
-               }
-       end
-
-       if defroutev4 then
-               def4 = {
-                       gateway = defroutev4.gateway,
-                       dest = defroutev4.dest,
-                       dev = defroutev4.device,
-                       metr = defroutev4.metric
-               }
-       end
 
        rv[#rv+1] = {
                time = time,
@@ -275,7 +264,7 @@ end
                        netlist[#netlist+1] = net:ifname()
                        netdevs[net:ifname()] = dev:name()
 
-                       if net.iwdata.device then
+                       if net.iwinfo.signal and net.iwinfo.bssid then
                                local signal = net.iwinfo.signal or "N/A"
                                local noise = net.iwinfo.noise or "N/A"
                                local q = net.iwinfo.quality or "0"
@@ -310,7 +299,7 @@ end
                                if bitrate ~= "N/A" then
                                        bitrate = ( bitrate / 1000 ).."Mb/s"
                                end
-                               local interface = net.iwdata.ifname or "N/A"
+                               local interface = net.iwinfo.ifname or "N/A"
        %>
                                                <tr class="cbi-section-table-row cbi-rowstyle-1">
                                                <td class="cbi-value-field" id="<%=net:ifname()%>-signal"><%=signal_string%></td>
@@ -336,7 +325,7 @@ end
                <div class="cbi-section">
                        <div class="cbi-section-node">
 
-<% if not defroutev4 and not defroutev6 then %>
+<% if not def4 and not def6 then %>
        <%:No default routes known.%>
 <%else%>
                                <table class="cbi-section-table">
@@ -347,23 +336,22 @@ end
                                                        <th class="cbi-section-table-cell"><%:Metric%></th>
                                                </tr>
 
-       <% if defroutev4 then %>
-
+       <% if def4 then %>
                                                <tr class="cbi-section-table-row cbi-rowstyle-1">
-                                                       <td class="cbi-value-field" id="v4dst"><%=defroutev4.dest%></td>
-                                                       <td class="cbi-value-field" id="v4dev"><%=defroutev4.device%></td>
-                                                       <td class="cbi-value-field" id="v4gw"><%=defroutev4.gateway%></td>
-                                                       <td class="cbi-value-field" id="v4metr"><%=defroutev4.metric%></td>
+                                                       <td class="cbi-value-field" id="v4dst"><%=def4.dest%></td>
+                                                       <td class="cbi-value-field" id="v4dev"><%=def4.dev%></td>
+                                                       <td class="cbi-value-field" id="v4gw"><%=def4.gateway%></td>
+                                                       <td class="cbi-value-field" id="v4metr"><%=def4.metr%></td>
                                                </tr>
 
        <% end
-       if defroutev6 then %>
+       if def6 then %>
 
                                                <tr class="cbi-section-table-row cbi-rowstyle-2">
-                                                       <td class="cbi-value-field" id="v6dst"><%=defroutev6.dest%></td>
-                                                       <td class="cbi-value-field" id="v6dev"><%=defroutev6.device%></td>
-                                                       <td class="cbi-value-field" id="v6gw"><%=defroutev6.nexthop%></td>
-                                                       <td class="cbi-value-field" id="v6metr"><%=defroutev6.metric%></td>
+                                                       <td class="cbi-value-field" id="v6dst"><%=def6.dest%></td>
+                                                       <td class="cbi-value-field" id="v6dev"><%=def6.dev%></td>
+                                                       <td class="cbi-value-field" id="v6gw"><%=def6.gateway%></td>
+                                                       <td class="cbi-value-field" id="v6metr"><%=def6.metr%></td>
                                                </tr>
 
        <% end %>