wireshark/ui/qt/endpoint_dialog.cpp

157 lines
4.3 KiB
C++
Raw Normal View History

/* endpoint_dialog.cpp
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "endpoint_dialog.h"
#include <epan/maxmind_db.h>
#include <epan/prefs.h>
#include <epan/to_str.h>
#include "ui/recent.h"
#include "wsutil/filesystem.h"
Re-implement "Map" feature for Endpoints This feature was removed in v2.5.1rc0-427-gf529ab5d0a, anticipating that MaxMind would remove support for it in 2019. They have however changed their mind and maintained latitude and longitude information. They recommend displaying an accuracy radius, but the reported values are 50, 100, 200 and 1000km. When implemented literally, a marker in Ireland would cover the whole island plus mainland, so I have instead opted to use a fixed radius of 1km at deeper zoom levels. The old ipmap.html file was outdated and had broken tiles, I rewrote a new one from scratch using the light-weight Leaflet library combined with tiles from OpenStreetMap. This is more mobile-friendly and secure (https, SRI). To improve handling of nearby or overlapping nodes, clustering is used (individual nodes can still be inspected). Browser compatibility results: IE8 is unusable, IE9 partially works (tooltips sometimes disappear and the cluster radius control is gone), IE11 works. Of course Firefox 65 and Chromium 72 have no issues. The map popup description in the generated GeoJSON structure is now split in several properties, allowing presentation to be handled by the HTML page instead of the C code. Bug: 14693 Change-Id: If2ec9c518f7723ac0ab27b6272463356875a0ff2 Reviewed-on: https://code.wireshark.org/review/31952 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-09 23:19:54 +00:00
#include "wsutil/file_util.h"
#include "wsutil/pint.h"
#include "wsutil/str_util.h"
Re-implement "Map" feature for Endpoints This feature was removed in v2.5.1rc0-427-gf529ab5d0a, anticipating that MaxMind would remove support for it in 2019. They have however changed their mind and maintained latitude and longitude information. They recommend displaying an accuracy radius, but the reported values are 50, 100, 200 and 1000km. When implemented literally, a marker in Ireland would cover the whole island plus mainland, so I have instead opted to use a fixed radius of 1km at deeper zoom levels. The old ipmap.html file was outdated and had broken tiles, I rewrote a new one from scratch using the light-weight Leaflet library combined with tiles from OpenStreetMap. This is more mobile-friendly and secure (https, SRI). To improve handling of nearby or overlapping nodes, clustering is used (individual nodes can still be inspected). Browser compatibility results: IE8 is unusable, IE9 partially works (tooltips sometimes disappear and the cluster radius control is gone), IE11 works. Of course Firefox 65 and Chromium 72 have no issues. The map popup description in the generated GeoJSON structure is now split in several properties, allowing presentation to be handled by the HTML page instead of the C code. Bug: 14693 Change-Id: If2ec9c518f7723ac0ab27b6272463356875a0ff2 Reviewed-on: https://code.wireshark.org/review/31952 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-09 23:19:54 +00:00
#include <wsutil/utf8_entities.h>
#include <ui/qt/utils/qt_ui_utils.h>
Re-implement "Map" feature for Endpoints This feature was removed in v2.5.1rc0-427-gf529ab5d0a, anticipating that MaxMind would remove support for it in 2019. They have however changed their mind and maintained latitude and longitude information. They recommend displaying an accuracy radius, but the reported values are 50, 100, 200 and 1000km. When implemented literally, a marker in Ireland would cover the whole island plus mainland, so I have instead opted to use a fixed radius of 1km at deeper zoom levels. The old ipmap.html file was outdated and had broken tiles, I rewrote a new one from scratch using the light-weight Leaflet library combined with tiles from OpenStreetMap. This is more mobile-friendly and secure (https, SRI). To improve handling of nearby or overlapping nodes, clustering is used (individual nodes can still be inspected). Browser compatibility results: IE8 is unusable, IE9 partially works (tooltips sometimes disappear and the cluster radius control is gone), IE11 works. Of course Firefox 65 and Chromium 72 have no issues. The map popup description in the generated GeoJSON structure is now split in several properties, allowing presentation to be handled by the HTML page instead of the C code. Bug: 14693 Change-Id: If2ec9c518f7723ac0ab27b6272463356875a0ff2 Reviewed-on: https://code.wireshark.org/review/31952 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-09 23:19:54 +00:00
#include <ui/qt/utils/variant_pointer.h>
#include <ui/qt/widgets/wireshark_file_dialog.h>
#include <ui/qt/widgets/traffic_tab.h>
#include <ui/qt/widgets/traffic_types_list.h>
#include "main_application.h"
#include <QCheckBox>
#include <QDesktopServices>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QPushButton>
#include <QUrl>
#include <QTemporaryFile>
#include <QTreeView>
#include <QSortFilterProxyModel>
typedef enum
{
ENDP_COLUMN_ADDR,
ENDP_COLUMN_PORT,
ENDP_COLUMN_PACKETS,
ENDP_COLUMN_BYTES,
ENDP_COLUMN_PKT_AB,
ENDP_COLUMN_BYTES_AB,
ENDP_COLUMN_PKT_BA,
ENDP_COLUMN_BYTES_BA,
ENDP_NUM_COLUMNS,
ENDP_COLUMN_GEO_COUNTRY = ENDP_NUM_COLUMNS,
ENDP_COLUMN_GEO_CITY,
ENDP_COLUMN_GEO_AS_NUM,
ENDP_COLUMN_GEO_AS_ORG,
ENDP_NUM_GEO_COLUMNS
} endpoint_column_type_e;
static const QString table_name_ = QObject::tr("Endpoint");
static ATapDataModel * createModel(int protoId, QString filter)
{
return new EndpointDataModel(protoId, filter);
}
EndpointDialog::EndpointDialog(QWidget &parent, CaptureFile &cf) :
TrafficTableDialog(parent, cf, table_name_)
{
trafficList()->setProtocolInfo(table_name_, &(recent.endpoint_tabs));
trafficTab()->setProtocolInfo(table_name_, trafficList(), &(recent.endpoint_tabs_columns), &createModel);
trafficTab()->setFilter(cf.displayFilter());
connect(trafficTab(), &TrafficTab::filterAction, this, &EndpointDialog::filterAction);
connect(trafficTab()->tabBar(), &QTabBar::currentChanged, this, &EndpointDialog::tabChanged);
connect(trafficTab(), &TrafficTab::tabDataChanged, this, &EndpointDialog::tabChanged);
Re-implement "Map" feature for Endpoints This feature was removed in v2.5.1rc0-427-gf529ab5d0a, anticipating that MaxMind would remove support for it in 2019. They have however changed their mind and maintained latitude and longitude information. They recommend displaying an accuracy radius, but the reported values are 50, 100, 200 and 1000km. When implemented literally, a marker in Ireland would cover the whole island plus mainland, so I have instead opted to use a fixed radius of 1km at deeper zoom levels. The old ipmap.html file was outdated and had broken tiles, I rewrote a new one from scratch using the light-weight Leaflet library combined with tiles from OpenStreetMap. This is more mobile-friendly and secure (https, SRI). To improve handling of nearby or overlapping nodes, clustering is used (individual nodes can still be inspected). Browser compatibility results: IE8 is unusable, IE9 partially works (tooltips sometimes disappear and the cluster radius control is gone), IE11 works. Of course Firefox 65 and Chromium 72 have no issues. The map popup description in the generated GeoJSON structure is now split in several properties, allowing presentation to be handled by the HTML page instead of the C code. Bug: 14693 Change-Id: If2ec9c518f7723ac0ab27b6272463356875a0ff2 Reviewed-on: https://code.wireshark.org/review/31952 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-09 23:19:54 +00:00
#ifdef HAVE_MAXMINDDB
map_bt_ = buttonBox()->addButton(tr("Map"), QDialogButtonBox::ActionRole);
map_bt_->setToolTip(tr("Draw IPv4 or IPv6 endpoints on a map."));
QMenu *map_menu_ = new QMenu(map_bt_);
QAction *action;
action = map_menu_->addAction(tr("Open in browser"));
connect(action, &QAction::triggered, this, &EndpointDialog::openMap);
action = map_menu_->addAction(tr("Save As…"));
Re-implement "Map" feature for Endpoints This feature was removed in v2.5.1rc0-427-gf529ab5d0a, anticipating that MaxMind would remove support for it in 2019. They have however changed their mind and maintained latitude and longitude information. They recommend displaying an accuracy radius, but the reported values are 50, 100, 200 and 1000km. When implemented literally, a marker in Ireland would cover the whole island plus mainland, so I have instead opted to use a fixed radius of 1km at deeper zoom levels. The old ipmap.html file was outdated and had broken tiles, I rewrote a new one from scratch using the light-weight Leaflet library combined with tiles from OpenStreetMap. This is more mobile-friendly and secure (https, SRI). To improve handling of nearby or overlapping nodes, clustering is used (individual nodes can still be inspected). Browser compatibility results: IE8 is unusable, IE9 partially works (tooltips sometimes disappear and the cluster radius control is gone), IE11 works. Of course Firefox 65 and Chromium 72 have no issues. The map popup description in the generated GeoJSON structure is now split in several properties, allowing presentation to be handled by the HTML page instead of the C code. Bug: 14693 Change-Id: If2ec9c518f7723ac0ab27b6272463356875a0ff2 Reviewed-on: https://code.wireshark.org/review/31952 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-09 23:19:54 +00:00
connect(action, &QAction::triggered, this, &EndpointDialog::saveMap);
map_bt_->setMenu(map_menu_);
#endif
updateWidgets();
}
void EndpointDialog::captureFileClosing()
{
trafficTab()->disableTap();
displayFilterCheckBox()->setEnabled(false);
TrafficTableDialog::captureFileClosing();
}
void EndpointDialog::tabChanged(int idx)
{
Re-implement "Map" feature for Endpoints This feature was removed in v2.5.1rc0-427-gf529ab5d0a, anticipating that MaxMind would remove support for it in 2019. They have however changed their mind and maintained latitude and longitude information. They recommend displaying an accuracy radius, but the reported values are 50, 100, 200 and 1000km. When implemented literally, a marker in Ireland would cover the whole island plus mainland, so I have instead opted to use a fixed radius of 1km at deeper zoom levels. The old ipmap.html file was outdated and had broken tiles, I rewrote a new one from scratch using the light-weight Leaflet library combined with tiles from OpenStreetMap. This is more mobile-friendly and secure (https, SRI). To improve handling of nearby or overlapping nodes, clustering is used (individual nodes can still be inspected). Browser compatibility results: IE8 is unusable, IE9 partially works (tooltips sometimes disappear and the cluster radius control is gone), IE11 works. Of course Firefox 65 and Chromium 72 have no issues. The map popup description in the generated GeoJSON structure is now split in several properties, allowing presentation to be handled by the HTML page instead of the C code. Bug: 14693 Change-Id: If2ec9c518f7723ac0ab27b6272463356875a0ff2 Reviewed-on: https://code.wireshark.org/review/31952 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-09 23:19:54 +00:00
#ifdef HAVE_MAXMINDDB
if (idx == trafficTab()->currentIndex())
{
bool geoIp = trafficTab()->hasGeoIPData(idx);
map_bt_->setEnabled(geoIp);
}
2022-06-02 06:56:22 +00:00
#else
Q_UNUSED(idx);
#endif
TrafficTableDialog::currentTabChanged();
}
Re-implement "Map" feature for Endpoints This feature was removed in v2.5.1rc0-427-gf529ab5d0a, anticipating that MaxMind would remove support for it in 2019. They have however changed their mind and maintained latitude and longitude information. They recommend displaying an accuracy radius, but the reported values are 50, 100, 200 and 1000km. When implemented literally, a marker in Ireland would cover the whole island plus mainland, so I have instead opted to use a fixed radius of 1km at deeper zoom levels. The old ipmap.html file was outdated and had broken tiles, I rewrote a new one from scratch using the light-weight Leaflet library combined with tiles from OpenStreetMap. This is more mobile-friendly and secure (https, SRI). To improve handling of nearby or overlapping nodes, clustering is used (individual nodes can still be inspected). Browser compatibility results: IE8 is unusable, IE9 partially works (tooltips sometimes disappear and the cluster radius control is gone), IE11 works. Of course Firefox 65 and Chromium 72 have no issues. The map popup description in the generated GeoJSON structure is now split in several properties, allowing presentation to be handled by the HTML page instead of the C code. Bug: 14693 Change-Id: If2ec9c518f7723ac0ab27b6272463356875a0ff2 Reviewed-on: https://code.wireshark.org/review/31952 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-09 23:19:54 +00:00
#ifdef HAVE_MAXMINDDB
void EndpointDialog::openMap()
{
QUrl map_file = trafficTab()->createGeoIPMap(false);
Re-implement "Map" feature for Endpoints This feature was removed in v2.5.1rc0-427-gf529ab5d0a, anticipating that MaxMind would remove support for it in 2019. They have however changed their mind and maintained latitude and longitude information. They recommend displaying an accuracy radius, but the reported values are 50, 100, 200 and 1000km. When implemented literally, a marker in Ireland would cover the whole island plus mainland, so I have instead opted to use a fixed radius of 1km at deeper zoom levels. The old ipmap.html file was outdated and had broken tiles, I rewrote a new one from scratch using the light-weight Leaflet library combined with tiles from OpenStreetMap. This is more mobile-friendly and secure (https, SRI). To improve handling of nearby or overlapping nodes, clustering is used (individual nodes can still be inspected). Browser compatibility results: IE8 is unusable, IE9 partially works (tooltips sometimes disappear and the cluster radius control is gone), IE11 works. Of course Firefox 65 and Chromium 72 have no issues. The map popup description in the generated GeoJSON structure is now split in several properties, allowing presentation to be handled by the HTML page instead of the C code. Bug: 14693 Change-Id: If2ec9c518f7723ac0ab27b6272463356875a0ff2 Reviewed-on: https://code.wireshark.org/review/31952 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-09 23:19:54 +00:00
if (!map_file.isEmpty()) {
QDesktopServices::openUrl(map_file);
}
}
void EndpointDialog::saveMap()
{
QString destination_file =
WiresharkFileDialog::getSaveFileName(this, tr("Save Endpoints Map"),
"ipmap.html",
"HTML files (*.html);;GeoJSON files (*.json)");
if (destination_file.isEmpty()) {
return;
}
QUrl map_file = trafficTab()->createGeoIPMap(destination_file.endsWith(".json"));
Re-implement "Map" feature for Endpoints This feature was removed in v2.5.1rc0-427-gf529ab5d0a, anticipating that MaxMind would remove support for it in 2019. They have however changed their mind and maintained latitude and longitude information. They recommend displaying an accuracy radius, but the reported values are 50, 100, 200 and 1000km. When implemented literally, a marker in Ireland would cover the whole island plus mainland, so I have instead opted to use a fixed radius of 1km at deeper zoom levels. The old ipmap.html file was outdated and had broken tiles, I rewrote a new one from scratch using the light-weight Leaflet library combined with tiles from OpenStreetMap. This is more mobile-friendly and secure (https, SRI). To improve handling of nearby or overlapping nodes, clustering is used (individual nodes can still be inspected). Browser compatibility results: IE8 is unusable, IE9 partially works (tooltips sometimes disappear and the cluster radius control is gone), IE11 works. Of course Firefox 65 and Chromium 72 have no issues. The map popup description in the generated GeoJSON structure is now split in several properties, allowing presentation to be handled by the HTML page instead of the C code. Bug: 14693 Change-Id: If2ec9c518f7723ac0ab27b6272463356875a0ff2 Reviewed-on: https://code.wireshark.org/review/31952 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-02-09 23:19:54 +00:00
if (!map_file.isEmpty()) {
QString source_file = map_file.toLocalFile();
QFile::remove(destination_file);
if (!QFile::rename(source_file, destination_file)) {
QMessageBox::warning(this, tr("Map file error"),
tr("Failed to save map file %1.").arg(destination_file));
QFile::remove(source_file);
}
}
}
#endif
void EndpointDialog::on_buttonBox_helpRequested()
{
mainApp->helpTopicAction(HELP_STATS_ENDPOINTS_DIALOG);
}
void init_endpoint_table(struct register_ct* ct, const char *filter)
{
mainApp->emitStatCommandSignal("Endpoints", filter, GINT_TO_POINTER(get_conversation_proto_id(ct)));
}