modules/freifunk: Fix a problem that happened when ipv6 was not enabled by adding...
authorManuel Munz <freifunk@somakoma.de>
Fri, 17 Dec 2010 03:35:17 +0000 (03:35 +0000)
committerManuel Munz <freifunk@somakoma.de>
Fri, 17 Dec 2010 03:35:17 +0000 (03:35 +0000)
modules/freifunk/luasrc/controller/freifunk/freifunk.lua
modules/freifunk/luasrc/view/freifunk/public_status.htm

index f4f9b97c0dc193722480a17f51459b326460c643..db4e00c1e617ca88466ea9fa4cf45e88ade45511 100644 (file)
@@ -256,23 +256,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")
index 5cfc0c72d56b49aeda6e7b0bae49f84f2e5196b9..94ca2cd21e29230d98ffd93e689c1a03d1cb3161 100644 (file)
@@ -133,59 +133,66 @@ local defroutev6 = sys.net.defaultroute6 ()
                                        u.innerHTML = st[i].mem;
                                        }
 
-                                       var u = document.getElementById('v4dst');
-                                       if (u)
-                                       {
-                                       u.innerHTML = st[i].defroutev4.dest;
-                                       }
-
-                                       var u = document.getElementById('v4gw');
-                                       if (u)
-                                       {
-                                       u.innerHTML = st[i].defroutev4.gateway;
-                                       }
-
-                                       var u = document.getElementById('v4dev');
-                                       if (u)
-                                       {
-                                       u.innerHTML = st[i].defroutev4.dev;
-                                       }
-
-                                       var u = document.getElementById('v4metr');
-                                       if (u)
-                                       {
-                                       u.innerHTML = st[i].defroutev4.metr;
-                                       }
-
-                                       var u = document.getElementById('v6dst');
-                                       if (u)
-                                       {
-                                       u.innerHTML = st[i].defroutev6.dest;
-                                       }
-
-                                       var u = document.getElementById('v6gw');
+                                       var u = document.getElementById('dyntime');
                                        if (u)
                                        {
-                                       u.innerHTML = st[i].defroutev6.gateway;
+                                       u.innerHTML = st[i].time;
                                        }
 
-                                       var u = document.getElementById('v6dev');
-                                       if (u)
+                                       if (st[i].defroutev4)
                                        {
-                                       u.innerHTML = st[i].defroutev6.dev;
+                                               var u = document.getElementById('v4dst');
+                                               if (u)
+                                               {
+                                               u.innerHTML = st[i].defroutev4.dest;
+                                               }
+
+                                               var u = document.getElementById('v4gw');
+                                               if (u)
+                                               {
+                                               u.innerHTML = st[i].defroutev4.gateway;
+                                               }
+
+                                               var u = document.getElementById('v4dev');
+                                               if (u)
+                                               {
+                                               u.innerHTML = st[i].defroutev4.dev;
+                                               }
+
+                                               var u = document.getElementById('v4metr');
+                                               if (u)
+                                               {
+                                               u.innerHTML = st[i].defroutev4.metr;
+                                               }
                                        }
 
-                                       var u = document.getElementById('v6metr');
-                                       if (u)
+                                       if (st[i].defroutev6)
                                        {
-                                       u.innerHTML = st[i].defroutev6.metr;
+                                               var u = document.getElementById('v6dst');
+                                               if (u)
+                                               {
+                                               u.innerHTML = st[i].defroutev6.dest;
+                                               }
+
+                                               var u = document.getElementById('v6gw');
+                                               if (u)
+                                               {
+                                               u.innerHTML = st[i].defroutev6.gateway;
+                                               }
+
+                                               var u = document.getElementById('v6dev');
+                                               if (u)
+                                               {
+                                               u.innerHTML = st[i].defroutev6.dev;
+                                               }
+
+                                               var u = document.getElementById('v6metr');
+                                               if (u)
+                                               {
+                                               u.innerHTML = st[i].defroutev6.metr;
+                                               }
                                        }
 
-                                       var u = document.getElementById('dyntime');
-                                       if (u)
-                                       {
-                                       u.innerHTML = st[i].time;
-                                       }
                                }
                                window.setTimeout(update_wifi_status, <%=interval%>);
                        }