Second try...
[project/luci.git] / applications / luci-olsr / luasrc / controller / olsr.lua
index 0482a8f..577f596 100644 (file)
@@ -1,18 +1,26 @@
 module("luci.controller.olsr", package.seeall)
 
 function index()
+       if not luci.fs.isfile("/etc/config/olsr") then
+               return
+       end
+       
+       require("luci.i18n").loadc("olsr")
+       local i18n = luci.i18n.translate
+       
        local page  = node("admin", "status", "olsr")
        page.target = call("action_index")
        page.title  = "OLSR"
+       page.i18n   = "olsr"
        
        local page  = node("admin", "status", "olsr", "routes")
        page.target = call("action_routes")
-       page.title  = "Routen"
+       page.title  = i18n("olsr_routes", "Routen")
        page.order  = 10
        
        local page  = node("admin", "status", "olsr", "topology")
        page.target = call("action_topology")
-       page.title  = "Topologie"
+       page.title  = i18n("olsr_topology", "Topologie")
        page.order  = 20
        
        local page  = node("admin", "status", "olsr", "hna")
@@ -25,7 +33,7 @@ function index()
        page.title  = "MID"
        page.order  = 50
 
-       entry({"admin", "services", "olsrd"}, cbi("olsr/olsrd.lua"), "OLSRd")
+       entry({"admin", "services", "olsrd"}, cbi("olsr/olsrd"), "OLSR").i18n = "olsr"
 end
 
 function action_index()
@@ -37,15 +45,18 @@ function action_index()
        end
        
        local function compare(a, b)
-               if tonumber(a.ETX) == 0 then
+               local c = tonumber(a.ETX)
+               local d = tonumber(b.ETX)
+               
+               if not c or c == 0 then
                        return false
                end
                
-               if tonumber(b.ETX) == 0 then
+               if not d or d == 0 then
                        return true
                end
                
-               return tonumber(a.ETX) < tonumber(b.ETX)
+               return c < d
        end
        
        table.sort(data.Links, compare)
@@ -62,15 +73,18 @@ function action_routes()
        end
        
        local function compare(a, b)
-               if tonumber(a.ETX) == 0 then
+               local c = tonumber(a.ETX)
+               local d = tonumber(b.ETX)
+               
+               if not c or c == 0 then
                        return false
                end
                
-               if tonumber(b.ETX) == 0 then
+               if not d or d == 0 then
                        return true
                end
                
-               return tonumber(a.ETX) < tonumber(b.ETX)
+               return c < d
        end
        
        table.sort(data.Routes, compare)
@@ -149,15 +163,23 @@ function fetch_txtinfo(otable)
                local lines = luci.util.split(tbl, "\n")
                local name  = table.remove(lines, 1):sub(8)
                local keys  = luci.util.split(table.remove(lines, 1), "\t")
+               local split = #keys - 1
                
                data[name] = {}
                
                for j, line in ipairs(lines) do
-                       local fields = luci.util.split(line, "\t")
+                       local fields = luci.util.split(line, "\t", split)
                        data[name][j] = {}
                        for k, key in pairs(keys) do
                                data[name][j][key] = fields[k] 
                        end
+                       
+                       if data[name][j].Linkcost then
+                               data[name][j].LinkQuality,
+                               data[name][j].NLQ,
+                               data[name][j].ETX =
+                                data[name][j].Linkcost:match("(.*)/(.*)\t(.*)")
+                       end
                end
        end