Remove the endpoint "Map" feature.

Remove the endpoint map and its button from the Qt and GTK+ UIs. It
depends on GeoIP Legacy for coordinate information and those databases
are being deprecated in favor of MaxMind DB. We *could* upgrade the code
to use mmdbresolve, but according to
https://dev.maxmind.com/geoip/geoip2/geolite2/ they're also going to
remove coordinate information from GeoLite2:

"In addition, in 2019, latitude and longitude coordinates in the
 GeoLite2 databases will be removed.* Latitude and longitude coordinates
 will continue to be provided in GeoIP2 databases. Please check back for
 updates."

Change-Id: I43e1593d282a0f1aae897b1f4724117d1496b21e
Reviewed-on: https://code.wireshark.org/review/26229
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Gerald Combs <gerald@wireshark.org>
This commit is contained in:
Gerald Combs 2018-03-02 11:24:31 -08:00
parent 84c7246e4c
commit f529ab5d0a
17 changed files with 4 additions and 546 deletions

View File

@ -1629,7 +1629,6 @@ set(INSTALL_FILES
colorfilters
dfilters
enterprises.tsv
ipmap.html
manuf
pdml2html.xsl
services
@ -2376,15 +2375,6 @@ if(BUILD_wireshark_gtk AND GTK_FOUND)
target_link_libraries(wireshark-gtk ${wireshark_gtk_LIBS})
install(TARGETS wireshark-gtk RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
# Map for endpoints dialog
ADD_CUSTOM_COMMAND(
TARGET wireshark-gtk
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${PROJECT_SOURCE_DIR}/ipmap.html"
$<TARGET_FILE_DIR:wireshark-gtk>
)
if(WIN32)
add_custom_target(copy_gtk_dlls)
set_target_properties(copy_gtk_dlls PROPERTIES FOLDER "Copy Tasks")

View File

@ -58,7 +58,7 @@ EXTRA_PROGRAMS = wireshark-gtk wireshark tshark tfshark capinfos captype \
# Wireshark configuration files are put in $(pkgdatadir).
#
dist_pkgdata_DATA = COPYING manuf services cfilters colorfilters dfilters \
smi_modules ipmap.html pdml2html.xsl enterprises.tsv wka
smi_modules pdml2html.xsl enterprises.tsv wka
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = wireshark.pc
@ -785,7 +785,6 @@ EXTRA_DIST = \
fix \
idl \
image \
ipmap.html \
m4 \
macosx-support-lib-patches \
make-version.pl \

2
debian/control vendored
View File

@ -195,7 +195,7 @@ Package: libwireshark-data
Section: libs
Architecture: all
Multi-Arch: foreign
Depends: ${misc:Depends}, libjs-openlayers
Depends: ${misc:Depends}
Conflicts: wireshark-common (<< 1.4.0~rc2-1)
Replaces: wireshark-common (<< 1.4.0~rc2-1)
Recommends: geoip-database, geoip-database-extra

View File

@ -1,17 +0,0 @@
Description: Use system's OpenLayers.js to avoid privacy breach
Forwarded: not-needed
Author: Balint Reczey <balint@balintreczey.hu>
diff --git a/ipmap.html b/ipmap.html
index c1e83d0..94f4535 100644
--- a/ipmap.html
+++ b/ipmap.html
@@ -8,7 +8,7 @@
line-height: 17px;
}
</style>
- <script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>
+ <script type="text/javascript" src="file:///usr/share/javascript/openlayers/OpenLayers.js"></script>
<script type="text/javascript" src="http://openstreetmap.org/openlayers/OpenStreetMap.js"></script>
<script type="text/javascript">

View File

@ -1,4 +1,3 @@
02_use_packaged_openlayers_js.patch
04_asn2wrs_ply.patch
05_note-README-when-running-as-root.patch
06_release-version.patch

View File

@ -41,6 +41,7 @@ since version 2.5.0:
* HTTP Referer statistics are now supported.
* The Windows packages are now built using Microsoft Visual Studio 2017.
* The IP map feature (the “Map” button in the “Endpoints” dialog) has been removed.
The following features are new (or have been significantly updated)
since version 2.4.0:

View File

@ -262,8 +262,7 @@ current display filter. Note that in this example we have GeoIP configured which
gives us extra geographic columns. See <<ChGeoIPDbPaths>> for more information.
The btn:[Copy] button will copy the list values to the clipboard in CSV
(Comma Separated Values) or YAML format. The btn:[Map] button will show the
endpoints mapped in your web browser.
(Comma Separated Values) or YAML format.
btn:[Endpoint Types] lets you choose which traffic type tabs are shown. See
<<ChStatEndpoints>> above for a list of endpoint types. The enabled

View File

@ -1,106 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Wireshark: IP Location Map</title>
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif; font-size: 13px;
line-height: 17px;
}
</style>
<script type="text/javascript" src="http://openlayers.org/api/OpenLayers.js"></script>
<script type="text/javascript" src="http://openstreetmap.org/openlayers/OpenStreetMap.js"></script>
<script type="text/javascript">
<!--
var map, layer;
var selectControl, selectedFeature;
function onPopupClose(event) {
selectControl.unselect(this.feature);
}
function EndpointSelected(event) {
var feature = event.feature;
popup = new OpenLayers.Popup.FramedCloud("endpoint",
feature.geometry.getBounds().getCenterLonLat(),
new OpenLayers.Size(25,25),
"<h3>"+ feature.attributes.title + "</h3>" +
feature.attributes.description,
null, true, onPopupClose);
feature.popup = popup;
popup.feature = feature;
map.addPopup(popup);
}
function EndpointUnselected(event) {
var feature = event.feature;
if (feature.popup) {
popup.feature = null;
map.removePopup(feature.popup);
feature.popup.destroy();
feature.popup = null;
}
}
function init() {
var endpoints = {
"type": "FeatureCollection",
"features": [ // Start endpoint list - MUST match hostlist_table.c
]
};
map = new OpenLayers.Map('map', {
controls: [
new OpenLayers.Control.PanZoomBar(),
new OpenLayers.Control.ZoomBox(),
new OpenLayers.Control.ScaleLine(),
new OpenLayers.Control.MousePosition(),
new OpenLayers.Control.Navigation(),
new OpenLayers.Control.Attribution()
]
//projection: new OpenLayers.Projection("EPSG:900913"),
//displayProjection: new OpenLayers.Projection("EPSG:4326"),
//maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34, 20037508.34, 20037508.34),
//numZoomLevels: 18,
//maxResolution: 156543,
//units: "m"
});
layer = new OpenLayers.Layer.WMS("OpenLayers WMS",
"http://vmap0.tiles.osgeo.org/wms/vmap0",
{layers: 'basic'},
{wrapDateLine: true} );
map.addLayer(layer);
//map.addLayer(new OpenLayers.Layer.OSM.Mapnik("Mapnik"));
//map.addLayer(new OpenLayers.Layer.Text("IP Locations", {
// location: map_file, projection: new OpenLayers.Projection("EPSG:4326")} ) );
//
//map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
var geojson_format = new OpenLayers.Format.GeoJSON();
var vector_layer = new OpenLayers.Layer.Vector("IP Endpoints");
map.addLayer(vector_layer);
vector_layer.addFeatures(geojson_format.read(endpoints));
if (endpoints.features.length < 1) {
document.getElementById("statusmsg").innerHTML = "No endpoints to map";
} else {
map.zoomToExtent(vector_layer.getDataExtent());
}
selectControl = new OpenLayers.Control.SelectFeature(vector_layer);
map.addControl(selectControl);
selectControl.activate();
vector_layer.events.on({
'featureselected': EndpointSelected,
'featureunselected': EndpointUnselected
});
}
// -->
</script>
</head>
<body onload="init()">
<div id="statusmsg" style="float: right; z-index: 9999;"></div>
<div id="map" style="z-index: 0;"></div>
</body>
</html>

View File

@ -19,13 +19,6 @@ do
rm -f "$PLUGINS_PATH"/$plugin.so "$PLUGINS_PATH"/$plugin.la
done
#
# Get rid of any ipmap.html file that was dropped into Contents/MacOS;
# it belongs in, and is installed in, Contents/Resources/share/wireshark,
# and we don't need the extra copy.
#
rm -f "$2/Wireshark.app/Contents/MacOS/ipmap.html"
# Setting PATH
# if /etc/paths.d/Wireshark already exists we overwrite it.
#

View File

@ -228,7 +228,6 @@ Delete "$INSTDIR\pdml2html.xsl"
Delete "$INSTDIR\pcrepattern.3.txt"
Delete "$INSTDIR\user-guide.chm"
Delete "$INSTDIR\example_snmp_users_file"
Delete "$INSTDIR\ipmap.html"
Delete "$INSTDIR\radius\*.*"
Delete "$INSTDIR\dtds\*.*"
Delete "$SMPROGRAMS\${PROGRAM_NAME}\*.*"

View File

@ -451,7 +451,6 @@ File "${STAGING_DIR}\wireshark-filter.html"
File "${STAGING_DIR}\dumpcap.exe"
File "${STAGING_DIR}\dumpcap.html"
File "${STAGING_DIR}\extcap.html"
File "${STAGING_DIR}\ipmap.html"
; C-runtime redistributable
!ifdef VCREDIST_EXE

View File

@ -75,9 +75,6 @@
<Component Id="cmpExtcap_html" Guid="*">
<File Id="filExtcap_html" KeyPath="yes" Source="$(var.Staging.Dir)\extcap.html" />
</Component>
<Component Id="cmpIpmap_html" Guid="*">
<File Id="filIpmap_html" KeyPath="yes" Source="$(var.Staging.Dir)\ipmap.html" />
</Component>
</DirectoryRef>
</Fragment>
<Fragment>

View File

@ -49,10 +49,6 @@
#include "ui/gtk/dlg_utils.h"
#include "ui/gtk/help_dlg.h"
#include "ui/gtk/main.h"
#ifdef HAVE_GEOIP
#include "ui/gtk/webbrowser.h"
#include "ui/gtk/stock_icons.h"
#endif
#include "ui/gtk/old-gtk-compat.h"
@ -776,45 +772,6 @@ copy_as_csv_cb(GtkWindow *copy_bt, gpointer data _U_)
g_string_free(csv.CSV_str, TRUE); /* Free the memory */
}
#ifdef HAVE_GEOIP
static void
open_as_map_cb(GtkWindow *copy_bt, gpointer data _U_)
{
gchar *err_str;
gchar *file_uri;
gboolean uri_open;
hostlist_table *talkers;
gchar *map_filename;
talkers = (hostlist_table *)g_object_get_data(G_OBJECT(copy_bt), HOST_PTR_KEY);
if (!talkers) {
return;
}
map_filename = create_endpoint_geoip_map(talkers->hash.conv_array, &err_str);
if (!map_filename) {
simple_error_message_box("%s", err_str);
g_free(err_str);
return;
}
/* open the webbrowser */
file_uri = g_filename_to_uri(map_filename, NULL, NULL);
g_free(map_filename);
uri_open = browser_open_url (file_uri);
if(!uri_open) {
simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't open the file: \"%s\" in your web browser", file_uri);
g_free(file_uri);
return;
}
g_free(file_uri);
}
#endif /* HAVE_GEOIP */
static gint default_col_size[ENDP_NUM_COLUMNS+ENDP_NUM_GEOIP_COLUMNS];
static void
@ -1026,9 +983,6 @@ init_hostlist_table(struct register_ct* ct, const char *filter)
GtkWidget *close_bt, *help_bt;
gboolean ret;
GtkWidget *copy_bt;
#ifdef HAVE_GEOIP
GtkWidget *map_bt;
#endif
window_geometry_t tl_geom;
hosttable=g_new0(hostlist_table,1);
@ -1059,15 +1013,7 @@ init_hostlist_table(struct register_ct* ct, const char *filter)
/* Button row. */
/* XXX - maybe we want to have a "Copy as CSV" stock button here? */
/*copy_bt = gtk_button_new_with_label ("Copy content to clipboard as CSV");*/
#ifdef HAVE_GEOIP
if( strstr(hosttable->name, "IPv4") || strstr(hosttable->name, "IPv6") ) {
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_COPY, WIRESHARK_STOCK_MAP, GTK_STOCK_HELP, NULL);
} else {
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_COPY, GTK_STOCK_HELP, NULL);
}
#else
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_COPY, GTK_STOCK_HELP, NULL);
#endif
gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
@ -1079,15 +1025,6 @@ init_hostlist_table(struct register_ct* ct, const char *filter)
g_object_set_data(G_OBJECT(copy_bt), HOST_PTR_KEY, hosttable);
g_signal_connect(copy_bt, "clicked", G_CALLBACK(copy_as_csv_cb), NULL);
#ifdef HAVE_GEOIP
map_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_MAP);
if(map_bt != NULL) {
gtk_widget_set_tooltip_text(map_bt, "Show a map of the IP addresses (internet connection required).");
g_object_set_data(G_OBJECT(map_bt), HOST_PTR_KEY, hosttable);
g_signal_connect(map_bt, "clicked", G_CALLBACK(open_as_map_cb), NULL);
}
#endif /* HAVE_GEOIP */
help_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);
g_signal_connect(help_bt, "clicked", G_CALLBACK(topic_cb), (gpointer)HELP_STATS_ENDPOINTS_DIALOG);
@ -1115,28 +1052,6 @@ ct_nb_switch_page_cb(GtkNotebook *nb, gpointer *pg _U_, guint page, gpointer dat
}
}
#ifdef HAVE_GEOIP
static void
ct_nb_map_switch_page_cb(GtkNotebook *nb, gpointer *pg _U_, guint page, gpointer data)
{
GtkWidget *map_bt = (GtkWidget *) data;
void ** pages = (void **)g_object_get_data(G_OBJECT(nb), NB_PAGES_KEY);
page++;
if (pages && page > 0 && (int) page <= GPOINTER_TO_INT(pages[0]) && map_bt) {
g_object_set_data(G_OBJECT(map_bt), HOST_PTR_KEY, pages[page]);
if( strstr(((hostlist_table *)pages[page])->name, "IPv4") ||
strstr(((hostlist_table *)pages[page])->name, "IPv6") ) {
gtk_widget_set_sensitive(map_bt, TRUE);
} else {
gtk_widget_set_sensitive(map_bt, FALSE);
}
}
}
#endif /* HAVE_GEOIP */
static void
hostlist_win_destroy_notebook_cb(GtkWindow *win _U_, gpointer data)
{
@ -1264,9 +1179,6 @@ init_hostlist_notebook_cb(GtkWidget *w _U_, gpointer d _U_)
void ** pages;
GtkWidget *nb;
GtkWidget *copy_bt;
#ifdef HAVE_GEOIP
GtkWidget *map_bt;
#endif
window_geometry_t tl_geom;
init_host_page_data host_page_iter_data;
@ -1318,11 +1230,7 @@ init_hostlist_notebook_cb(GtkWidget *w _U_, gpointer d _U_)
g_signal_connect(filter_cb, "toggled", G_CALLBACK(hostlist_filter_toggle_dest), pages);
/* Button row. */
#ifdef HAVE_GEOIP
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_COPY, WIRESHARK_STOCK_MAP, GTK_STOCK_HELP, NULL);
#else
bbox = dlg_button_row_new(GTK_STOCK_CLOSE, GTK_STOCK_COPY, GTK_STOCK_HELP, NULL);
#endif
gtk_box_pack_end(GTK_BOX(vbox), bbox, FALSE, FALSE, 0);
/* Close */
@ -1335,15 +1243,6 @@ init_hostlist_notebook_cb(GtkWidget *w _U_, gpointer d _U_)
g_signal_connect(copy_bt, "clicked", G_CALLBACK(copy_as_csv_cb), NULL);
g_object_set_data(G_OBJECT(copy_bt), HOST_PTR_KEY, pages[host_page_iter_data.page]);
#ifdef HAVE_GEOIP
map_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), WIRESHARK_STOCK_MAP);
gtk_widget_set_tooltip_text(map_bt, "Show a map of the IP addresses (internet connection required).");
g_object_set_data(G_OBJECT(map_bt), HOST_PTR_KEY, pages[host_page_iter_data.page]);
g_signal_connect(map_bt, "clicked", G_CALLBACK(open_as_map_cb), NULL);
g_signal_connect(nb, "switch-page", G_CALLBACK(ct_nb_map_switch_page_cb), map_bt);
gtk_widget_set_sensitive(map_bt, FALSE);
#endif /* HAVE_GEOIP */
g_signal_connect(nb, "switch-page", G_CALLBACK(ct_nb_switch_page_cb), copy_bt);
help_bt = (GtkWidget *)g_object_get_data(G_OBJECT(bbox), GTK_STOCK_HELP);

View File

@ -35,14 +35,6 @@ static const QString table_name_ = QObject::tr("Endpoint");
EndpointDialog::EndpointDialog(QWidget &parent, CaptureFile &cf, int cli_proto_id, const char *filter) :
TrafficTableDialog(parent, cf, filter, table_name_)
{
#ifdef HAVE_GEOIP
map_bt_ = buttonBox()->addButton(tr("Map"), QDialogButtonBox::ActionRole);
map_bt_->setToolTip(tr("Draw IPv4 or IPv6 endpoints on a map."));
connect(map_bt_, SIGNAL(clicked()), this, SLOT(createMap()));
connect(trafficTableTabWidget(), SIGNAL(currentChanged(int)), this, SLOT(tabChanged()));
#endif
addProgressFrame(&parent);
QList<int> endp_protos;
@ -70,10 +62,6 @@ EndpointDialog::EndpointDialog(QWidget &parent, CaptureFile &cf, int cli_proto_i
fillTypeMenu(endp_protos);
#ifdef HAVE_GEOIP
tabChanged();
#endif
QPushButton *close_bt = buttonBox()->button(QDialogButtonBox::Close);
if (close_bt) {
close_bt->setDefault(true);
@ -156,38 +144,9 @@ bool EndpointDialog::addTrafficTable(register_ct_t *table)
EndpointTreeWidget::tapReset,
get_hostlist_packet_func(table),
EndpointTreeWidget::tapDraw);
#ifdef HAVE_GEOIP
connect(endp_tree, SIGNAL(geoIPStatusChanged()), this, SLOT(tabChanged()));
#endif
return true;
}
#ifdef HAVE_GEOIP
void EndpointDialog::tabChanged()
{
EndpointTreeWidget *cur_tree = qobject_cast<EndpointTreeWidget *>(trafficTableTabWidget()->currentWidget());
map_bt_->setEnabled(cur_tree && cur_tree->hasGeoIPData());
}
void EndpointDialog::createMap()
{
EndpointTreeWidget *cur_tree = qobject_cast<EndpointTreeWidget *>(trafficTableTabWidget()->currentWidget());
if (!cur_tree) {
return;
}
gchar *err_str;
gchar *map_path = create_endpoint_geoip_map(cur_tree->trafficTreeHash()->conv_array, &err_str);
if (!map_path) {
QMessageBox::warning(this, tr("Map file error"), err_str);
g_free(err_str);
return;
}
QDesktopServices::openUrl(QUrl::fromLocalFile(gchar_free_to_qstring(map_path)));
}
#endif
void EndpointDialog::on_buttonBox_helpRequested()
{
wsApp->helpTopicAction(HELP_STATS_ENDPOINTS_DIALOG);

View File

@ -64,17 +64,10 @@ public slots:
void captureFileClosing();
private:
#ifdef HAVE_GEOIP
QPushButton *map_bt_;
#endif
bool addTrafficTable(register_ct_t* table);
private slots:
#ifdef HAVE_GEOIP
void tabChanged();
void createMap();
#endif
void on_buttonBox_helpRequested();
};

View File

@ -14,25 +14,6 @@
#include "traffic_table_ui.h"
#include <wsutil/utf8_entities.h>
#ifdef HAVE_GEOIP
#include <GeoIP.h>
#include "epan/address.h"
#include "epan/addr_resolv.h"
#include "epan/geoip_db.h"
#include "epan/strutil.h"
#include "wsutil/pint.h"
#include "wsutil/str_util.h"
#include "epan/packet_info.h"
#include "epan/conversation_table.h"
#include <errno.h>
#include <stdio.h>
#include "wsutil/filesystem.h"
#include "wsutil/file_util.h"
#include "wsutil/tempfile.h"
#endif
const char *conv_column_titles[CONV_NUM_COLUMNS] = {
"Address A",
"Port A",
@ -67,220 +48,6 @@ const char *endp_column_titles[ENDP_NUM_COLUMNS] = {
const char *endp_conn_title = "Connection";
#ifdef HAVE_GEOIP
#define MAX_TPL_LINE_LEN 4096
gchar *
create_endpoint_geoip_map(const GArray *endp_array, gchar **err_str) {
char *tpl_filename, *tpl_line;
FILE *tpl_file, *out_file;
char *map_path;
gchar *map_filename = NULL;
guint i;
GString *tpl_entry;
gchar *esc_entry;
int db_lon, db_lat, db_country4, db_country6, db_city4, db_city6, db_asn4, db_asn6;
guint cur_db;
const char *map_endpoint_opener = "{\n";
db_lon = db_lat = db_country4 = db_country6 = db_city4 = db_city6 = db_asn4 = db_asn6 = -1;
/* Create a location map HTML file from a template */
/* XXX - add error handling */
tpl_filename = get_datafile_path("ipmap.html");
tpl_file = ws_fopen(tpl_filename, "r");
if(tpl_file == NULL) {
if (err_str) {
GString *err_descr = g_string_new("");
g_string_printf(err_descr, file_open_error_message(errno, FALSE), tpl_filename);
*err_str = g_string_free(err_descr, FALSE);
}
g_free(tpl_filename);
return NULL;
}
g_free(tpl_filename);
#if 1
/* We should probably create a file with a temporary name and a .html extension instead */
if (! create_tempdir(&map_path, "Wireshark IP Map ")) {
if (err_str) {
GString *err_descr = g_string_new("");
g_string_printf(err_descr, "Could not create temporary directory\n%s",
map_path);
*err_str = g_string_free(err_descr, FALSE);
}
fclose(tpl_file);
return NULL;
}
#else
/* Debugging only */
map_path = "/tmp";
#endif
map_filename = g_strdup_printf("%s%cipmap.html", map_path, G_DIR_SEPARATOR);
out_file = ws_fopen(map_filename, "w");
if(out_file == NULL) {
if (err_str) {
GString *err_descr = g_string_new("");
g_string_printf(err_descr, file_open_error_message(errno, FALSE), map_filename);
*err_str = g_string_free(err_descr, FALSE);
}
g_free(map_filename);
fclose(tpl_file);
return NULL;
}
tpl_line = (char *)g_malloc(MAX_TPL_LINE_LEN);
while (fgets(tpl_line, MAX_TPL_LINE_LEN, tpl_file) != NULL) {
fputs(tpl_line, out_file);
/* MUST match ipmap.html */
if (strstr(tpl_line, "// Start endpoint list")) {
break;
}
}
for (cur_db = 0; cur_db < geoip_db_num_dbs(); cur_db++) {
switch (geoip_db_type(cur_db)) {
case WS_LON_FAKE_EDITION:
db_lon = cur_db;
break;
case WS_LAT_FAKE_EDITION:
db_lat = cur_db;
break;
case GEOIP_COUNTRY_EDITION:
db_country4 = cur_db;
break;
case GEOIP_COUNTRY_EDITION_V6:
db_country6 = cur_db;
break;
case GEOIP_CITY_EDITION_REV0:
case GEOIP_CITY_EDITION_REV1:
db_city4 = cur_db;
break;
case GEOIP_CITY_EDITION_REV0_V6:
case GEOIP_CITY_EDITION_REV1_V6:
db_city6 = cur_db;
break;
}
}
if(db_lon < 0 || db_lat < 0) {
if (err_str) {
*err_str = g_strdup("Unable to open GeoIP database");
}
/* We can't write the map file, so close it and get rid of it */
fclose(out_file);
ws_unlink(map_filename);
g_free(map_filename);
fclose(tpl_file);
g_free(tpl_line);
return NULL;
}
/* Fill in our map data */
tpl_entry = g_string_new("");
for (i = 0; i < endp_array->len; i++) {
char *lat = NULL, *lon = NULL, *country = NULL, *city = NULL, *asn = NULL;
hostlist_talker_t *endp_item = &g_array_index(endp_array, hostlist_talker_t, i);
if (endp_item->myaddress.type == AT_IPv4) {
lon = geoip_db_lookup_ipv4(db_lon, pntoh32(endp_item->myaddress.data), NULL);
lat = geoip_db_lookup_ipv4(db_lat, pntoh32(endp_item->myaddress.data), NULL);
country = geoip_db_lookup_ipv4(db_country4, pntoh32(endp_item->myaddress.data), "-");
city = geoip_db_lookup_ipv4(db_city4, pntoh32(endp_item->myaddress.data), "-");
asn = geoip_db_lookup_ipv4(db_asn4, pntoh32(endp_item->myaddress.data), "-");
} else if (endp_item->myaddress.type == AT_IPv6) {
const ws_in6_addr *addr = (const ws_in6_addr *) endp_item->myaddress.data;
lon = geoip_db_lookup_ipv6(db_lon, *addr, NULL);
lat = geoip_db_lookup_ipv6(db_lat, *addr, NULL);
country = geoip_db_lookup_ipv6(db_country6, *addr, "-");
city = geoip_db_lookup_ipv6(db_city6, *addr, "-");
asn = geoip_db_lookup_ipv6(db_asn6, *addr, "-");
} else {
continue;
}
/*
{
'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [-122.583889, 37.898889] },
'properties': { 'title': 'host.example.com', 'description': 'AS: AS12345 Ewok Holdings, Inc.<br/>Country: US<br/>City: Muir Woods, CA<br/>Packets: 6<br/>Bytes: 980' }
},
*/
if (lon && lat) {
char* addr_str;
g_string_printf(tpl_entry, "%s", map_endpoint_opener);
/* Longitude + latitude */
g_string_append_printf(tpl_entry, " 'type': 'Feature', 'geometry': { 'type': 'Point', 'coordinates': [%s, %s] },\n", lon, lat);
/* Address */
addr_str = address_to_display(NULL, &endp_item->myaddress);
g_string_append_printf(tpl_entry, " 'properties': { 'title': '%s', ", addr_str);
wmem_free(NULL, addr_str);
/* Description */
/* City */
esc_entry = string_replace(city, "'", "&#39;");
g_string_append_printf(tpl_entry, "'description': '<div class=\"geoip_property\">City: %s</div>", esc_entry);
g_free(esc_entry);
/* Country */
esc_entry = string_replace(country, "'", "&#39;");
g_string_append_printf(tpl_entry, "<div class=\"geoip_property\">Country: %s</div>", esc_entry);
g_free(esc_entry);
/* Packets */
esc_entry = format_size(endp_item->tx_frames + endp_item->rx_frames,
(format_size_flags_e)(format_size_unit_none|format_size_prefix_si));
g_string_append_printf(tpl_entry, "<div class=\"geoip_property\">Packets: %s</div>", esc_entry);
g_free(esc_entry);
/* Bytes */
esc_entry = format_size(endp_item->tx_bytes + endp_item->rx_bytes,
(format_size_flags_e)(format_size_unit_none|format_size_prefix_si));
g_string_append_printf(tpl_entry, "<div class=\"geoip_property\">Bytes: %s</div>", esc_entry);
g_free(esc_entry);
/* ASN */
esc_entry = string_replace(asn, "'", "&#39;");
g_string_append_printf(tpl_entry, "<div class=\"geoip_property\">AS Number: %s</div>", esc_entry);
g_free(esc_entry);
/* XXX - We could add specific icons, e.g. depending on the amount of packets or bytes */
g_string_append(tpl_entry, "' }\n");
g_string_append(tpl_entry, "}");
fputs(tpl_entry->str, out_file);
map_endpoint_opener = ",\n{\n";
}
wmem_free(NULL, lat);
wmem_free(NULL, lon);
wmem_free(NULL, country);
wmem_free(NULL, city);
wmem_free(NULL, asn);
/* XXX Display an error if we we have no entries */
}
while (fgets(tpl_line, MAX_TPL_LINE_LEN, tpl_file) != NULL) {
fputs(tpl_line, out_file);
}
g_free(tpl_line);
fclose(tpl_file);
fclose(out_file);
return map_filename;
}
#endif
/*
* Editor modelines
*

View File

@ -60,19 +60,6 @@ extern const char *endp_column_titles[ENDP_NUM_COLUMNS];
extern const char *endp_conn_title;
#ifdef HAVE_GEOIP
/** Create an HTML file containing a map showing the geograpical
* locations of IPv4 and IPv6 addresses. The map is named "ipmap.html".
*
* @param [in] endp_array GArray of hostlist_talker_t structs.
* @param [in,out] err_str Set to error string on failure. Error string must
* be g_freed. May be NULL.
* @return Path of the map file if it was successfully written or NULL
* on failure. The path must be g_freed.
*/
gchar *create_endpoint_geoip_map(const GArray *endp_array, gchar **err_str);
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */