(no commit message)
[project/luci.git] / modules / freifunk / luasrc / controller / freifunk / freifunk.lua
index f4f9b97..b9f551b 100644 (file)
@@ -15,6 +15,7 @@ module("luci.controller.freifunk.freifunk", package.seeall)
 
 function index()
        local i18n = luci.i18n.translate
+       local uci = require "luci.model.uci".cursor()
 
        local page  = node()
        page.lock   = true
@@ -79,9 +80,15 @@ function index()
        entry({"freifunk", "map"}, template("freifunk-map/frame"), i18n("Karte"), 50)
        entry({"freifunk", "map", "content"}, template("freifunk-map/map"), nil, 51)
 
-       entry({"freifunk", "services"}, template("freifunk-services/services"), i18n("Services"), 60)
-       entry({"freifunk", "services", "content"}, template("freifunk-services/services"), nil, 61)
+       uci:foreach("olsrd", "LoadPlugin", function(s)
+               if s.library == "olsrd_nameservice.so.0.3" then
+                       has_serv = true
+               end
+       end)
 
+       if has_serv then
+               entry({"freifunk", "services"}, template("freifunk-services/services"), i18n("Services"), 60)
+       end
 end
 
 local function fetch_olsrd()
@@ -256,23 +263,33 @@ function public_status_json()
        membuffers / 1024,
        tostring(i18n.translate("buffered"))
        )
-       
+
        local dr4 = sys.net.defaultroute()
        local dr6 = sys.net.defaultroute6()
-
+       
+       if dr6 then
+               def6 = { 
+               gateway = dr6.nexthop:string(),
+               dest = dr6.dest:string(),
+               dev = dr6.device,
+               metr = dr6.metric }
+       end   
+
+       if dr4 then
+               def4 = { 
+               gateway = dr4.gateway:string(),
+               dest = dr4.dest:string(),
+               dev = dr4.device,
+               metr = dr4.metric }
+       end
+       
        rv[#rv+1] = {
                time = os.date("%c"),
                uptime = twa.date_format(tonumber(sys.uptime())),
                load = string.format("%.2f, %.2f, %.2f", load1, load5, load15),
                mem = mem,
-               defroutev4 = {  gateway = dr4.gateway:string(),
-                               dest = dr4.dest:string(),
-                               dev = dr4.device,
-                               metr = dr4.metric },
-               defroutev6 = {  gateway = dr6.nexthop:string(),
-                               dest = dr6.dest:string(),
-                               dev = dr6.device,
-                               metr = dr6.metric }
+               defroutev4 = def4,
+               defroutev6 = def6
        }
 
        luci.http.prepare_content("application/json")