Browse Source

ffho-status-page: hide non-public location data

backport from https://github.com/ffgtso/ffgt_packages-v2015.1/commit/3a0209c2c436ea1f253f011392580d57f91605d0
Karsten Böddeker 8 years ago
parent
commit
e1dbd71dcf
1 changed files with 12 additions and 9 deletions
  1. 12 9
      ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/status

+ 12 - 9
ffho/ffho-status-page/files/lib/gluon/status-page/www/cgi-bin/status

@@ -16,14 +16,6 @@ local model = platform_info.get_model()
 local release = util.trim(fs.readfile("/lib/gluon/release") or "")
 local primary_mac = require('gluon.sysconfig').primary_mac
 local nodeid = require('gluon.util').node_id()
-local latitude = uci:get_first('gluon-node-info', 'location', 'latitude')
-local longitude = uci:get_first('gluon-node-info', 'location', 'longitude')
-local location = ""
-if latitude and longitude then
-  location = "<a href=https://map.hochstift.freifunk.net/#!v:m;n:" .. nodeid .. ">" .. latitude .. ", " .. longitude .. "</a>"
-else
-  location = "<a href=https://map.hochstift.freifunk.net/#!v:m;n:" .. nodeid .. ">none</a>"
-end
 
 local contact = uci:get_first('gluon-node-info', 'owner', 'contact', '')
 if contact == '' then
@@ -48,6 +40,17 @@ for k, v in data:gmatch('([^\n:]+):%s*(%d+) kB') do
         fields[k] = tonumber(v)
 end
 
+function location()
+  local locationid = uci:get_first('gluon-node-info', 'location')
+  if locationid then
+    local location = uci:get_all('gluon-node-info', locationid)
+    if uci:get_bool('gluon-node-info', locationid, 'share_location') and location.latitude and location.longitude then
+      return "<a href=https://map.hochstift.freifunk.net/#!v:m;n:" .. nodeid .. ">" .. location.latitude .. ", " .. location.longitude .. "</a>"
+    end
+  end
+  return '<a href=https://map.hochstift.freifunk.net/#!v:m;n:' .. nodeid .. '>none</a>'
+end
+
 function escape_html(s)
   return (s:gsub('&', '&amp;'):gsub('<', '&lt;'):gsub('>', '&gt;'):gsub('"', '&quot;'))
 end
@@ -103,7 +106,7 @@ io.write("MAC:         " .. escape_html(primary_mac) .. "\n")
 io.write("Contact:     " .. escape_html(contact) .. "\n")
 io.write("Uptime:      " .. escape_html(util.trim(sys.exec("uptime | sed 's/^ \+//'"))) .. "\n")
 io.write("Autoupdater: " .. escape_html(autoupdater) .. "\n")
-io.write("Location:    " .. location .. "\n")
+io.write("Location:    " .. location() .. "\n")
 io.write("IPs:         " .. escape_html(util.trim(addresses)) .. "\n")
 io.write("Memory:      " .. string.format("%.1f %% used, %.1f %% free",(fields.MemTotal-fields.MemFree)/fields.MemTotal*100,fields.MemFree/fields.MemTotal*100) .. "\n")
 io.write("</pre>")