This repository has been archived by the owner on Jan 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
map.c
187 lines (155 loc) · 6.38 KB
/
map.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* Copyright (C) 2008-10 Luca Deri <[email protected]>
*
* http://www.ntop.org/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "ntop.h"
#include "globals-report.h"
#define MAX_NUM_MAP_HOSTS 5120
const char *map_head = "<script type=\"text/javascript\" src=\"http://maps.googleapis.com/maps/api/js?sensor=false";
const char *map_head2 = "\"></script>\n <script type=\"text/javascript\"><!--\n\n function load_map() { \n";
const char *map_head3 = " addReflections();\n";
const char *map_head4 = " \n function createMarker(point,html) { \n var infowindow = new google.maps.InfoWindow({ \n content: html \n }); \n var marker = new google.maps.Marker({ \n position: point \n }); \n google.maps.event.addListener(marker, \"click\", function() { \n infowindow.open(map,marker); \n }); \n marker.setMap(map); \n } \n \n var myOptions = { \n zoom: 2, \n center: new google.maps.LatLng(43.72, 10.40), \n panControl: true, \n zoomControl: true, \n scaleControl: true, \n mapTypeId: google.maps.MapTypeId.ROADMAP \n };\n \n var map = new google.maps.Map(document.getElementById(\"map\"),myOptions); \n";
const char *map_tail = "\n }\n\n --></script>\n </head>\n <body onload=\"load_map()\">\n <center><div id=\"map\" style=\"width: 800px; height: 600px\"></div></center>\n\n";
const char *map_tail2 = "\n }\n\n --></script>\n <div id=\"map\" style=\"width: 800px; height: 600px\"></div>\n<script type=\"text/javascript\">\nload_map();\n</script>\n";
/* ******************************************** */
static char *googleMapsKey = NULL;
void init_maps() {
char value[128];
if(fetchPrefsValue("google_maps.key", value, sizeof(value)) == -1) {
storePrefsValue("google_maps.key", GOOGLE_DEFAULT_MAP_KEY);
googleMapsKey = GOOGLE_DEFAULT_MAP_KEY;
} else {
googleMapsKey = strdup(value);
}
}
/* ************************************************** */
#if 0
static char* escape_string(char *in, char *out, u_int out_len) {
int i, i_max=strlen(in), j;
for(i=0, j=0; i<i_max; i++) {
switch(in[i]) {
case '\'':
case '\"':
out[j++] = '\\';
if(j >= out_len-1) return(out);
/* No break here */
default:
out[j++] = in[i];
if(j >= out_len-1) return(out);
break;
}
}
return(out);
}
#endif
/* ************************************************** */
void createAllHostsMap(void) {
HostTraffic *el;
int num_hosts = 0;
sendString((char*)map_head);
//sendString(googleMapsKey);
sendString((char*)map_head2);
sendString((char*)map_head3);
sendString((char*)map_head4);
for(el=getFirstHost(myGlobals.actualReportDeviceId);
el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) {
if(el->geo_ip) {
char buf[512];
#if 0
char buf1[256] = { 0 };
int showSymIp;
if((el->hostResolvedName[0] != '\0')
&& strcmp(el->hostResolvedName, el->hostNumIpAddress)
&& (!subnetPseudoLocalHost(el)))
showSymIp = 1;
else
showSymIp = 0;
#endif
safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf),
"createMarker(new google.maps.LatLng(%.2f, %.2f), \""
#if 0
"%s%s"
#endif
"<A HREF=/%s.html>%s</A><br>%s<br>%s\");\n",
el->geo_ip->latitude, el->geo_ip->longitude,
#if 0
showSymIp ? escape_string(el->hostResolvedName, buf1, sizeof(buf1)) : "", showSymIp ? "<br>" : "",
#endif
el->hostNumIpAddress, el->hostNumIpAddress,
el->geo_ip->city ? el->geo_ip->city : "",
el->geo_ip->country_name ? el->geo_ip->country_name : "");
sendString(buf);
num_hosts++;
if(num_hosts > MAX_NUM_MAP_HOSTS) break; /* Too many hosts */
}
}
sendString((char*)map_tail);
if(num_hosts > MAX_NUM_MAP_HOSTS)
sendString("<p><center><b><font color=red>WARNING:</font></b>You have more hosts to display than the number typically supported by Google maps. Some hosts have not been rendered.</center></p>");
// sendString("<p><center><b><font color=red>NOTE:</font></b> ");
// sendString("make sure you get your key <a href=http://code.google.com/apis/maps/>here</A>"
// " for using Google Maps from ntop and register it as \'google_maps.key\' key <A href=/"CONST_EDIT_PREFS"#google_maps.key>here</A>.</center></p>\n");
}
/* ************************************************** */
void createHostMap(HostTraffic *host) {
HostTraffic *el;
int num_hosts = 0;
sendString((char*)map_head);
//sendString(googleMapsKey);
sendString((char*)map_head2);
sendString((char*)map_head4);
for(el=getFirstHost(myGlobals.actualReportDeviceId);
el != NULL; el = getNextHost(myGlobals.actualReportDeviceId, el)) {
if((el->l2Host == host->l2Host) && (el->hostIpAddress.hostFamily == host->hostIpAddress.hostFamily)) {
if((CM_PointEst(host->sent_to_matrix, el->serialHostIndex) > 0)
|| (CM_PointEst(host->recv_from_matrix, el->serialHostIndex) > 0)) {
if(el->geo_ip) {
char buf[512];
#if 0
char buf1[256] = { 0 };
int showSymIp;
if((el->hostResolvedName[0] != '\0')
&& strcmp(el->hostResolvedName, el->hostNumIpAddress)
&& (!privateIPAddress(el)))
showSymIp = 1;
else
showSymIp = 0;
#endif
safe_snprintf(__FILE__, __LINE__, buf, sizeof(buf),
"createMarker(new google.maps.LatLng(%.2f, %.2f), \""
#if 0
"%s%s"
#endif
"<A HREF=/%s.html>%s</A><br>%s<br>%s\");\n",
el->geo_ip->latitude, el->geo_ip->longitude,
#if 0
showSymIp ? escape_string(el->hostResolvedName, buf1, sizeof(buf1)) : "",
showSymIp ? "<br>" : "",
#endif
el->hostNumIpAddress, el->hostNumIpAddress,
el->geo_ip->city ? el->geo_ip->city : "",
el->geo_ip->country_name ? el->geo_ip->country_name : "");
sendString(buf);
num_hosts++;
if(num_hosts > MAX_NUM_MAP_HOSTS) break; /* Too many hosts */
}
}
}
}
sendString((char*)map_tail2);
}