Use luci.fs.access instead of luci.fs.isfile where applicable
[project/luci.git] / applications / luci-olsr / luasrc / controller / olsr.lua
index f7a8ec106e4a3eb8f910255674fcedef18f18ba2..652f6b9d2c6e202eda1f4739cf099953d6c404e2 100644 (file)
@@ -1,7 +1,7 @@
 module("luci.controller.olsr", package.seeall)
 
 function index()
-       if not luci.fs.isfile("/etc/config/olsrd") then
+       if not luci.fs.access("/etc/config/olsrd") then
                return
        end
 
@@ -12,6 +12,7 @@ function index()
        page.target = call("action_index")
        page.title  = "OLSR"
        page.i18n   = "olsr"
+       page.subindex = true
 
        local page  = node("admin", "status", "olsr", "routes")
        page.target = call("action_routes")
@@ -33,20 +34,37 @@ function index()
        page.title  = "MID"
        page.order  = 50
 
-       entry(
+       local ol = entry(
                {"admin", "services", "olsrd"},
                cbi("olsr/olsrd"), "OLSR"
-       ).i18n = "olsr"
+       )
+       ol.i18n = "olsr"
+       ol.subindex = true
 
        entry(
                {"admin", "services", "olsrd", "hna"},
                cbi("olsr/olsrdhna"), "HNA Announcements"
-       ).i18n = "olsr"
+       )
 
-       entry(
+       oplg = entry(
                {"admin", "services", "olsrd", "plugins"},
                cbi("olsr/olsrdplugins"), "Plugins"
-       ).i18n = "olsr"
+       )
+       oplg.i18n = "olsr"
+       oplg.leaf = true
+       oplg.subindex = true
+
+       local uci = require("luci.model.uci").cursor()
+       uci:foreach("olsrd", "LoadPlugin",
+               function (section)
+                       local lib = section.library
+                       entry(
+                               {"admin", "services", "olsrd", "plugins", lib },
+                               cbi("olsr/olsrdplugins"),
+                               nil --'Plugin "%s"' % lib:gsub("^olsrd_",""):gsub("%.so.+$","")
+                       )
+               end
+       )
 end
 
 function action_index()
@@ -58,8 +76,8 @@ function action_index()
        end
 
        local function compare(a, b)
-               local c = tonumber(a.ETX)
-               local d = tonumber(b.ETX)
+               local c = tonumber(a.Cost)
+               local d = tonumber(b.Cost)
 
                if not c or c == 0 then
                        return false
@@ -114,7 +132,7 @@ function action_topology()
        end
 
        local function compare(a, b)
-               return a["Destination IP"] < b["Destination IP"]
+               return a["Dest. IP"] < b["Dest. IP"]
        end
 
        table.sort(data.Topology, compare)
@@ -131,7 +149,7 @@ function action_hna()
        end
 
        local function compare(a, b)
-               return a.Network < b.Network
+               return a.Destination < b.Destination
        end
 
        table.sort(data.HNA, compare)
@@ -148,7 +166,7 @@ function action_mid()
        end
 
        local function compare(a, b)
-               return a.IP < b.IP
+               return a["IP address"] < b["IP address"]
        end
 
        table.sort(data.MID, compare)
@@ -164,7 +182,14 @@ function fetch_txtinfo(otable)
        local rawdata = luci.sys.httpget("http://127.0.0.1:2006/"..otable)
 
        if #rawdata == 0 then
-               return nil
+               if luci.fs.access("/proc/net/ipv6_route", "r") then
+                       rawdata = luci.sys.httpget("http://[::1]:2006/"..otable)
+                       if #rawdata == 0 then
+                               return nil
+                       end
+               else
+                       return nil
+               end
        end
 
        local data = {}