TODO netlogon_user_flags_ntlmv2_enabled
[wireshark-sm.git] / ui / qt / remote_capture_dialog.cpp
blob0885c7603d8d5d56b32855b11ed8a7c2777cce56
1 /* remote_capture_dialog.cpp
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 // XXX This shouldn't exist. These controls should be in ManageInterfacesDialog instead.
12 #include "config.h"
13 #ifdef HAVE_PCAP_REMOTE
14 #include <ui/qt/utils/qt_ui_utils.h>
15 #include <ui/qt/utils/variant_pointer.h>
16 #include "ui/capture_globals.h"
17 #include "remote_capture_dialog.h"
18 #include <ui_remote_capture_dialog.h>
19 #include "ui/capture_opts.h"
20 #include "capture/capture-pcap-util.h"
21 #include "ui/capture_ui_utils.h"
22 #include "epan/prefs.h"
23 #include "epan/to_str.h"
24 #include "ui/ws_ui_util.h"
25 #include "ui/recent.h"
27 #include <QMessageBox>
29 RemoteCaptureDialog::RemoteCaptureDialog(QWidget *parent) :
30 QDialog(parent),
31 ui(new Ui::RemoteCaptureDialog)
33 ui->setupUi(this);
35 fillComboBox();
36 connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(apply_remote()));
37 connect(this, SIGNAL(remoteAdded(GList *, remote_options*)), parent, SIGNAL(remoteAdded(GList *, remote_options*)));
38 connect(ui->hostCombo, &QComboBox::currentTextChanged, this, &RemoteCaptureDialog::hostChanged);
41 RemoteCaptureDialog::~RemoteCaptureDialog()
43 delete ui;
46 void RemoteCaptureDialog::hostChanged(const QString host)
48 if (!host.compare(tr("Clear list"))) {
49 recent_free_remote_host_list();
50 ui->hostCombo->clear();
51 } else {
52 const struct remote_host *rh = nullptr;
53 int index = ui->hostCombo->findText(host);
54 if (index != -1) {
55 rh = VariantPointer<const struct remote_host>::asPtr(ui->hostCombo->itemData(index));
57 if (rh) {
58 ui->portText->setText(QString(rh->remote_port));
59 if (rh->auth_type == CAPTURE_AUTH_NULL) {
60 ui->nullAuth->setChecked(true);
61 } else {
62 ui->pwAuth->setChecked(true);
69 static void fillBox(void *value, void *user_data)
71 QComboBox *cb = (QComboBox *)user_data;
72 struct remote_host* rh = (struct remote_host*)value;
73 cb->addItem(QString((char*)rh->r_host), VariantPointer<const struct remote_host>::asQVariant(rh));
76 void RemoteCaptureDialog::fillComboBox()
78 int remote_host_list_size;
80 ui->hostCombo->addItem(QString(""));
81 remote_host_list_size = recent_get_remote_host_list_size();
82 if (remote_host_list_size > 0) {
83 recent_remote_host_list_foreach(fillBox, ui->hostCombo);
84 ui->hostCombo->insertSeparator(remote_host_list_size+1);
85 ui->hostCombo->addItem(tr("Clear list"));
89 void RemoteCaptureDialog::apply_remote()
91 int err;
92 char *err_str;
93 remote_options global_remote_opts;
95 QString host = ui->hostCombo->currentText();
96 if (host.isEmpty()) {
97 return;
99 global_remote_opts.src_type = CAPTURE_IFREMOTE;
100 global_remote_opts.remote_host_opts.remote_host = qstring_strdup(host);
101 QString port = ui->portText->text();
102 global_remote_opts.remote_host_opts.remote_port = qstring_strdup(port);
103 if (ui->pwAuth->isChecked()) {
104 global_remote_opts.remote_host_opts.auth_type = CAPTURE_AUTH_PWD;
105 } else {
106 global_remote_opts.remote_host_opts.auth_type = CAPTURE_AUTH_NULL;
108 QString user = ui->userText->text();
109 global_remote_opts.remote_host_opts.auth_username = qstring_strdup(user);
110 QString pw = ui->pwText->text();
111 global_remote_opts.remote_host_opts.auth_password = qstring_strdup(pw);
112 global_remote_opts.remote_host_opts.datatx_udp = false;
113 global_remote_opts.remote_host_opts.nocap_rpcap = true;
114 global_remote_opts.remote_host_opts.nocap_local = false;
115 #ifdef HAVE_PCAP_SETSAMPLING
116 global_remote_opts.sampling_method = CAPTURE_SAMP_NONE;
117 global_remote_opts.sampling_param = 0;
118 #endif
120 GList *rlist = get_remote_interface_list(global_remote_opts.remote_host_opts.remote_host,
121 global_remote_opts.remote_host_opts.remote_port,
122 global_remote_opts.remote_host_opts.auth_type,
123 global_remote_opts.remote_host_opts.auth_username,
124 global_remote_opts.remote_host_opts.auth_password,
125 &err, &err_str);
126 if (rlist == NULL) {
127 if (err == 0)
128 QMessageBox::warning(this, tr("Error"), tr("No remote interfaces found."));
129 else if (err == CANT_GET_INTERFACE_LIST)
130 QMessageBox::critical(this, tr("Error"), err_str);
131 else if (err == DONT_HAVE_PCAP)
132 QMessageBox::critical(this, tr("Error"), tr("PCAP not found"));
133 else
134 QMessageBox::critical(this, tr("Error"), "Unknown error");
135 return;
138 // Add the remote host even if it already exists, to update the port and
139 // auth type and move it to the front.
140 struct remote_host* rh;
141 rh = (struct remote_host *)g_malloc (sizeof (*rh));
142 rh->r_host = qstring_strdup(host);
143 rh->remote_port = qstring_strdup(port);
144 rh->auth_type = global_remote_opts.remote_host_opts.auth_type;
145 rh->auth_password = g_strdup("");
146 rh->auth_username = g_strdup("");
147 recent_add_remote_host(global_remote_opts.remote_host_opts.remote_host, rh);
149 // We don't need to add the new entry to hostCombo since we only call
150 // this when accepting the dialog.
152 // Tell the parent ManageInterfacesDialog we added this.
153 // XXX: If the remote hostname already exists in ManageInterfacesDialog,
154 // this doesn't remove it. Most of the time it won't, but there is the
155 // corner case of a host existing with empty (hence default, 2002) port,
156 // and then adding it a second time explicitly starting port 2002.
157 // Someone could bind rpcapd to multiple ports on the same host for
158 // some reason too, I suppose.
159 emit remoteAdded(rlist, &global_remote_opts);
162 void RemoteCaptureDialog::on_pwAuth_toggled(bool checked)
164 if (checked) {
165 ui->userLabel->setEnabled(true);
166 ui->userText->setEnabled(true);
167 ui->pwLabel->setEnabled(true);
168 ui->pwText->setEnabled(true);
172 void RemoteCaptureDialog::on_nullAuth_toggled(bool checked)
174 if (checked) {
175 ui->userLabel->setEnabled(false);
176 ui->userText->setEnabled(false);
177 ui->pwLabel->setEnabled(false);
178 ui->pwText->setEnabled(false);
181 #endif /* HAVE_PCAP_REMOTE */