1
|
From 98c38351acf58f2ea9987cd42e267e2e80168f99 Mon Sep 17 00:00:00 2001
|
2
|
From: Simone Mainardi <simonemainardi@gmail.com>
|
3
|
Date: Wed, 6 Jul 2016 11:46:37 +0200
|
4
|
Subject: [PATCH] Adds the ability to set a custom Google Maps API key
|
5
|
|
6
|
Users can now generate a custom Google Maps API key and
|
7
|
set it via ntopng Preferences page.
|
8
|
|
9
|
Addresses #646
|
10
|
---
|
11
|
httpdocs/inc/geolocation_disclaimer.inc | 5 ++++-
|
12
|
scripts/lua/admin/prefs.lua | 12 ++++++++++--
|
13
|
scripts/lua/host_details.lua | 7 ++++++-
|
14
|
scripts/lua/hosts_geomap.lua | 10 ++++++++--
|
15
|
scripts/lua/modules/lua_utils.lua | 10 ++++++++++
|
16
|
5 files changed, 38 insertions(+), 6 deletions(-)
|
17
|
|
18
|
diff --git a/httpdocs/inc/geolocation_disclaimer.inc b/httpdocs/inc/geolocation_disclaimer.inc
|
19
|
index f7a9fbc..85fbeff 100644
|
20
|
--- a/usr/local/share/ntopng/httpdocs/inc/geolocation_disclaimer.inc
|
21
|
+++ b/usr/local/share/ntopng/httpdocs/inc/geolocation_disclaimer.inc
|
22
|
@@ -8,5 +8,8 @@
|
23
|
<li> <small>Have active flows between peers with public IP addresses.</small>
|
24
|
</ol>
|
25
|
<li> <small>HTML <A HREF=http://diveintohtml5.info/geolocation.html>browser geolocation</A> is used to place on map hosts based on unknown locations.</small>
|
26
|
-</ul>
|
27
|
+<li> <small>A Google Maps Browser API Key may be required. Detailed information on key generation <a href="https://googlegeodevelopers.blogspot.it/2016/06/building-for-scale-updates-to-google.html">can be found here</a>.<br>
|
28
|
+ Once generated, the key can be submitted via ntopng <a href="@HTTP_PREFIX@/lua/admin/prefs.lua?subpage_active=users"><i class="fa fa-flask"></i> Preferences</a>.
|
29
|
+ </small>
|
30
|
+</ol>
|
31
|
</small>
|
32
|
diff --git a/scripts/lua/admin/prefs.lua b/scripts/lua/admin/prefs.lua
|
33
|
index 4b52392..fa9fa1e 100644
|
34
|
--- a/usr/local/share/ntopng/scripts/lua/admin/prefs.lua
|
35
|
+++ b/usr/local/share/ntopng/scripts/lua/admin/prefs.lua
|
36
|
@@ -202,13 +202,21 @@ function printUsers()
|
37
|
print('<input type=hidden name="subpage_active" value="users"/>\n')
|
38
|
print('<table class="table">')
|
39
|
|
40
|
+ print('<tr><th colspan=2 class="info">Web User Interface</th></tr>')
|
41
|
if prefs.is_autologout_enabled == true then
|
42
|
- print('<tr><th colspan=2 class="info">Web User Interface</th></tr>')
|
43
|
-
|
44
|
toggleTableButtonPrefs("Auto Logout",
|
45
|
"Toggle the automatic logout of web interface users with expired sessions.",
|
46
|
"On", "1", "success", "Off", "0", "danger", "toggle_autologout", "ntopng.prefs.is_autologon_enabled", "1")
|
47
|
end
|
48
|
+ prefsInputFieldPrefs("Google APIs Browser Key",
|
49
|
+ "Graphical hosts geomaps are based on Google Maps APIs. Google recently changed Maps API access policies "..
|
50
|
+ "and now requires a browser API key to be sumbitted for every request. Detailed information on how to obtain an API key "..
|
51
|
+ "<a href=\"https://googlegeodevelopers.blogspot.it/2016/06/building-for-scale-updates-to-google.html\">can be found here</a>. "..
|
52
|
+ "Once obtained, the API key can be placed in this field."
|
53
|
+ ,
|
54
|
+ "ntopng.prefs.",
|
55
|
+ "google_apis_browser_key",
|
56
|
+ "")
|
57
|
|
58
|
if ntop.isPro() then
|
59
|
|
60
|
diff --git a/scripts/lua/host_details.lua b/scripts/lua/host_details.lua
|
61
|
index acbdd80..780b913 100644
|
62
|
--- a/usr/local/share/ntopng/scripts/lua/host_details.lua
|
63
|
+++ b/usr/local/share/ntopng/scripts/lua/host_details.lua
|
64
|
@@ -1445,7 +1445,12 @@ print [[
|
65
|
</style>
|
66
|
|
67
|
</center>
|
68
|
- <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
|
69
|
+]]
|
70
|
+
|
71
|
+addGoogleMapsScript()
|
72
|
+
|
73
|
+print[[
|
74
|
+
|
75
|
<script src="]] print(ntop.getHttpPrefix()) print [[/js/markerclusterer.js"></script>
|
76
|
<div class="container-fluid">
|
77
|
<div class="row-fluid">
|
78
|
diff --git a/scripts/lua/hosts_geomap.lua b/scripts/lua/hosts_geomap.lua
|
79
|
index d170c94..c9581e1 100644
|
80
|
--- a/usr/local/share/ntopng/scripts/lua/hosts_geomap.lua
|
81
|
+++ b/usr/local/share/ntopng/scripts/lua/hosts_geomap.lua
|
82
|
@@ -22,6 +22,7 @@ for key, value in pairs(hosts_stats) do
|
83
|
end
|
84
|
|
85
|
|
86
|
+
|
87
|
if(num > 0) then
|
88
|
print [[
|
89
|
|
90
|
@@ -32,7 +33,12 @@ print [[
|
91
|
<hr>
|
92
|
<h2>Hosts GeoMap</H2>
|
93
|
|
94
|
- <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
|
95
|
+]]
|
96
|
+
|
97
|
+addGoogleMapsScript()
|
98
|
+
|
99
|
+print[[
|
100
|
+
|
101
|
<script src="]] print(ntop.getHttpPrefix()) print [[/js/markerclusterer.js"></script>
|
102
|
<div class="container-fluid">
|
103
|
<div class="row-fluid">
|
104
|
@@ -61,4 +67,4 @@ else
|
105
|
print("<div class=\"alert alert-danger\"><img src=".. ntop.getHttpPrefix() .. "/img/warning.png> No results found</div>")
|
106
|
end
|
107
|
|
108
|
-dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|
109
|
\ No newline at end of file
|
110
|
+dofile(dirs.installdir .. "/scripts/lua/inc/footer.lua")
|
111
|
diff --git a/scripts/lua/modules/lua_utils.lua b/scripts/lua/modules/lua_utils.lua
|
112
|
index 3f218d8..3e5e36b 100644
|
113
|
--- a/usr/local/share/ntopng/scripts/lua/modules/lua_utils.lua
|
114
|
+++ b/usr/local/share/ntopng/scripts/lua/modules/lua_utils.lua
|
115
|
@@ -947,6 +947,16 @@ function isIPv6(ip)
|
116
|
return true
|
117
|
end
|
118
|
|
119
|
+function addGoogleMapsScript()
|
120
|
+ local g_maps_key = ntop.getCache('ntopng.prefs.google_apis_browser_key')
|
121
|
+ if g_maps_key ~= nil and g_maps_key~= "" then
|
122
|
+ g_maps_key = "&key="..g_maps_key
|
123
|
+ else
|
124
|
+ g_maps_key = ""
|
125
|
+ end
|
126
|
+ print("<script src=\"https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"..g_maps_key.."\"></script>\n")
|
127
|
+end
|
128
|
+
|
129
|
|
130
|
|
131
|
function addGauge(name, url, maxValue, width, height)
|