From 98c38351acf58f2ea9987cd42e267e2e80168f99 Mon Sep 17 00:00:00 2001 From: Simone Mainardi Date: Wed, 6 Jul 2016 11:46:37 +0200 Subject: [PATCH] Adds the ability to set a custom Google Maps API key Users can now generate a custom Google Maps API key and set it via ntopng Preferences page. Addresses #646 --- httpdocs/inc/geolocation_disclaimer.inc | 5 ++++- scripts/lua/admin/prefs.lua | 12 ++++++++++-- scripts/lua/host_details.lua | 7 ++++++- scripts/lua/hosts_geomap.lua | 10 ++++++++-- scripts/lua/modules/lua_utils.lua | 10 ++++++++++ 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/httpdocs/inc/geolocation_disclaimer.inc b/httpdocs/inc/geolocation_disclaimer.inc index f7a9fbc..85fbeff 100644 --- a/usr/local/share/ntopng/httpdocs/inc/geolocation_disclaimer.inc +++ b/usr/local/share/ntopng/httpdocs/inc/geolocation_disclaimer.inc @@ -8,5 +8,8 @@
  • Have active flows between peers with public IP addresses.
  • HTML browser geolocation is used to place on map hosts based on unknown locations. - +
  • A Google Maps Browser API Key may be required. Detailed information on key generation can be found here.
    + Once generated, the key can be submitted via ntopng Preferences. +
    + diff --git a/scripts/lua/admin/prefs.lua b/scripts/lua/admin/prefs.lua index 4b52392..fa9fa1e 100644 --- a/usr/local/share/ntopng/scripts/lua/admin/prefs.lua +++ b/usr/local/share/ntopng/scripts/lua/admin/prefs.lua @@ -202,13 +202,21 @@ function printUsers() print('\n') print('') + print('') if prefs.is_autologout_enabled == true then - print('') - toggleTableButtonPrefs("Auto Logout", "Toggle the automatic logout of web interface users with expired sessions.", "On", "1", "success", "Off", "0", "danger", "toggle_autologout", "ntopng.prefs.is_autologon_enabled", "1") end + prefsInputFieldPrefs("Google APIs Browser Key", + "Graphical hosts geomaps are based on Google Maps APIs. Google recently changed Maps API access policies ".. + "and now requires a browser API key to be sumbitted for every request. Detailed information on how to obtain an API key ".. + "can be found here. ".. + "Once obtained, the API key can be placed in this field." + , + "ntopng.prefs.", + "google_apis_browser_key", + "") if ntop.isPro() then diff --git a/scripts/lua/host_details.lua b/scripts/lua/host_details.lua index acbdd80..780b913 100644 --- a/usr/local/share/ntopng/scripts/lua/host_details.lua +++ b/usr/local/share/ntopng/scripts/lua/host_details.lua @@ -1445,7 +1445,12 @@ print [[ - +]] + +addGoogleMapsScript() + +print[[ +
    diff --git a/scripts/lua/hosts_geomap.lua b/scripts/lua/hosts_geomap.lua index d170c94..c9581e1 100644 --- a/usr/local/share/ntopng/scripts/lua/hosts_geomap.lua +++ b/usr/local/share/ntopng/scripts/lua/hosts_geomap.lua @@ -22,6 +22,7 @@ for key, value in pairs(hosts_stats) do end + if(num > 0) then print [[ @@ -32,7 +33,12 @@ print [[

    Hosts GeoMap

    - +]] + +addGoogleMapsScript() + +print[[ +
    @@ -61,4 +67,4 @@ else print("
    No results found
    ") end -dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua") \ No newline at end of file +dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua") diff --git a/scripts/lua/modules/lua_utils.lua b/scripts/lua/modules/lua_utils.lua index 3f218d8..3e5e36b 100644 --- a/usr/local/share/ntopng/scripts/lua/modules/lua_utils.lua +++ b/usr/local/share/ntopng/scripts/lua/modules/lua_utils.lua @@ -947,6 +947,16 @@ function isIPv6(ip) return true end +function addGoogleMapsScript() + local g_maps_key = ntop.getCache('ntopng.prefs.google_apis_browser_key') + if g_maps_key ~= nil and g_maps_key~= "" then + g_maps_key = "&key="..g_maps_key + else + g_maps_key = "" + end + print("\n") +end + function addGauge(name, url, maxValue, width, height)
    Web User Interface
    Web User Interface