diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
commit | e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch) | |
tree | 68cb5ef9081156392f1dd62a00c6ccc1451b93df /ui/qt/endpoint_dialog.cpp | |
parent | Initial commit. (diff) | |
download | wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip |
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | ui/qt/endpoint_dialog.cpp | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/ui/qt/endpoint_dialog.cpp b/ui/qt/endpoint_dialog.cpp new file mode 100644 index 00000000..38a30be2 --- /dev/null +++ b/ui/qt/endpoint_dialog.cpp @@ -0,0 +1,156 @@ +/* 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" +#include "wsutil/file_util.h" +#include "wsutil/pint.h" +#include "wsutil/str_util.h" +#include <wsutil/utf8_entities.h> + +#include <ui/qt/utils/qt_ui_utils.h> +#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); + +#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…")); + 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) +{ +#ifdef HAVE_MAXMINDDB + if (idx == trafficTab()->currentIndex()) + { + bool geoIp = trafficTab()->hasGeoIPData(idx); + map_bt_->setEnabled(geoIp); + } +#else + Q_UNUSED(idx); +#endif + + TrafficTableDialog::currentTabChanged(); +} + +#ifdef HAVE_MAXMINDDB +void EndpointDialog::openMap() +{ + QUrl map_file = trafficTab()->createGeoIPMap(false); + 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")); + 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))); +} |