2020-10-07 10:36:04 +00:00
|
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
2020-12-26 19:56:06 +00:00
|
|
|
// Copyright (c) 2020-2021, The Monero Project.
|
2020-10-07 10:36:04 +00:00
|
|
|
|
|
|
|
#include "torinfodialog.h"
|
|
|
|
#include "ui_torinfodialog.h"
|
|
|
|
|
2021-05-02 18:22:38 +00:00
|
|
|
#include <QPushButton>
|
2020-10-07 10:36:04 +00:00
|
|
|
#include <QDesktopServices>
|
2021-05-02 18:22:38 +00:00
|
|
|
#include <QMessageBox>
|
2020-10-07 10:36:04 +00:00
|
|
|
|
2021-05-02 18:22:38 +00:00
|
|
|
#include "utils/TorManager.h"
|
|
|
|
|
|
|
|
TorInfoDialog::TorInfoDialog(QWidget *parent, AppContext *ctx)
|
2020-10-07 10:36:04 +00:00
|
|
|
: QDialog(parent)
|
|
|
|
, ui(new Ui::TorInfoDialog)
|
|
|
|
, m_ctx(ctx)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2021-05-02 18:22:38 +00:00
|
|
|
if (!torManager()->torConnected && !torManager()->errorMsg.isEmpty()) {
|
|
|
|
ui->message->setText(torManager()->errorMsg);
|
2020-10-07 10:36:04 +00:00
|
|
|
} else {
|
2021-05-02 18:22:38 +00:00
|
|
|
ui->message->hide();
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 18:22:38 +00:00
|
|
|
if (torManager()->isLocalTor()) {
|
|
|
|
ui->frame_logs->setHidden(true);
|
2020-10-07 10:36:04 +00:00
|
|
|
} else {
|
2021-05-02 18:22:38 +00:00
|
|
|
ui->logs->setPlainText(torManager()->torLogs);
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
2021-05-02 18:22:38 +00:00
|
|
|
initConnectionSettings();
|
|
|
|
initPrivacyLevel();
|
|
|
|
onConnectionStatusChanged(torManager()->torConnected);
|
|
|
|
|
|
|
|
connect(torManager(), &TorManager::connectionStateChanged, this, &TorInfoDialog::onConnectionStatusChanged);
|
|
|
|
connect(torManager(), &TorManager::logsUpdated, this, &TorInfoDialog::onLogsUpdated);
|
|
|
|
|
|
|
|
connect(ui->buttonBox->button(QDialogButtonBox::Apply), &QPushButton::clicked, this, &TorInfoDialog::onApplySettings);
|
|
|
|
|
|
|
|
connect(ui->line_host, &QLineEdit::textEdited, this, &TorInfoDialog::onSettingsChanged);
|
|
|
|
connect(ui->line_port, &QLineEdit::textEdited, this, &TorInfoDialog::onSettingsChanged);
|
|
|
|
connect(ui->check_useLocalTor, &QCheckBox::stateChanged, this, &TorInfoDialog::onSettingsChanged);
|
|
|
|
connect(ui->btnGroup_privacyLevel, &QButtonGroup::idToggled, this, &TorInfoDialog::onSettingsChanged);
|
|
|
|
|
|
|
|
ui->label_changes->hide();
|
|
|
|
|
|
|
|
#ifndef HAS_TOR_BIN
|
|
|
|
ui->check_useLocalTor->setChecked(true);
|
|
|
|
ui->check_useLocalTor->setEnabled(false);
|
|
|
|
ui->check_useLocalTor->setToolTip("Feather was bundled without Tor");
|
|
|
|
#endif
|
|
|
|
|
2020-10-07 10:36:04 +00:00
|
|
|
this->adjustSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorInfoDialog::onLogsUpdated() {
|
2021-05-02 18:22:38 +00:00
|
|
|
ui->logs->setPlainText(torManager()->torLogs);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorInfoDialog::onConnectionStatusChanged(bool connected) {
|
|
|
|
if (connected) {
|
|
|
|
ui->icon_connectionStatus->setPixmap(QPixmap(":/assets/images/status_connected.png").scaledToWidth(16, Qt::SmoothTransformation));
|
|
|
|
ui->label_testConnectionStatus->setText("Connected");
|
|
|
|
} else {
|
|
|
|
ui->icon_connectionStatus->setPixmap(QPixmap(":/assets/images/status_disconnected.png").scaledToWidth(16, Qt::SmoothTransformation));
|
|
|
|
ui->label_testConnectionStatus->setText("Disconnected");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorInfoDialog::onApplySettings() {
|
|
|
|
config()->set(Config::socks5Host, ui->line_host->text());
|
|
|
|
config()->set(Config::socks5Port, ui->line_port->text());
|
|
|
|
|
|
|
|
int id = ui->btnGroup_privacyLevel->checkedId();
|
|
|
|
config()->set(Config::torPrivacyLevel, id);
|
|
|
|
|
|
|
|
ui->label_changes->hide();
|
|
|
|
|
|
|
|
bool useLocalTor = ui->check_useLocalTor->isChecked();
|
|
|
|
if (config()->get(Config::useLocalTor).toBool() && useLocalTor && torManager()->isStarted()) {
|
|
|
|
QMessageBox::warning(this, "Warning", "Feather is running the bundled Tor daemon, "
|
|
|
|
"but the option to never start a bundled Tor daemon was selected. "
|
|
|
|
"A restart is required to apply the setting.");
|
|
|
|
}
|
|
|
|
config()->set(Config::useLocalTor, useLocalTor);
|
|
|
|
|
|
|
|
ui->icon_connectionStatus->setPixmap(QPixmap(":/assets/images/status_lagging.png").scaledToWidth(16, Qt::SmoothTransformation));
|
|
|
|
ui->label_testConnectionStatus->setText("Connecting");
|
|
|
|
|
|
|
|
emit torSettingsChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorInfoDialog::onSettingsChanged() {
|
|
|
|
ui->label_changes->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorInfoDialog::initConnectionSettings() {
|
|
|
|
bool localTor = torManager()->isLocalTor();
|
|
|
|
ui->label_connectionSettingsMessage->setVisible(!localTor);
|
|
|
|
ui->frame_connectionSettings->setVisible(localTor);
|
|
|
|
|
|
|
|
ui->line_host->setText(config()->get(Config::socks5Host).toString());
|
|
|
|
ui->line_port->setText(config()->get(Config::socks5Port).toString());
|
|
|
|
|
|
|
|
ui->check_useLocalTor->setChecked(config()->get(Config::useLocalTor).toBool());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorInfoDialog::initPrivacyLevel() {
|
|
|
|
ui->btnGroup_privacyLevel->setId(ui->radio_allTorExceptNode, Config::allTorExceptNode);
|
|
|
|
ui->btnGroup_privacyLevel->setId(ui->radio_allTorExceptInitSync, Config::allTorExceptInitSync);
|
|
|
|
ui->btnGroup_privacyLevel->setId(ui->radio_allTor, Config::allTor);
|
|
|
|
|
|
|
|
int privacyLevel = config()->get(Config::torPrivacyLevel).toInt();
|
|
|
|
auto button = ui->btnGroup_privacyLevel->button(privacyLevel);
|
|
|
|
if (button) {
|
|
|
|
button->setChecked(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_ctx->nodes->connection().isLocal()) {
|
|
|
|
ui->label_notice->setText("You are connected to a local node. Traffic is not routed over Tor.");
|
|
|
|
}
|
2021-05-04 23:09:19 +00:00
|
|
|
else if (Utils::isTorsocks()) {
|
|
|
|
ui->label_notice->setText("Feather was started with torsocks, all traffic is routed over Tor");
|
|
|
|
}
|
|
|
|
else if (WhonixOS::detect()) {
|
|
|
|
ui->label_notice->setText("Feather is running on Whonix, all traffic is routed over Tor");
|
|
|
|
}
|
|
|
|
else if (TailsOS::detect()) {
|
|
|
|
ui->label_notice->setText("Feather is running on Tails, all traffic is routed over Tor");
|
|
|
|
}
|
|
|
|
else {
|
2021-05-02 18:22:38 +00:00
|
|
|
ui->frame_notice->hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
QPixmap iconNoTor(":/assets/images/securityLevelStandardWhite.png");
|
|
|
|
QPixmap iconNoSync(":/assets/images/securityLevelSaferWhite.png");
|
|
|
|
QPixmap iconAllTor(":/assets/images/securityLevelSafestWhite.png");
|
|
|
|
ui->icon_noTor->setPixmap(iconNoTor.scaledToHeight(16, Qt::SmoothTransformation));
|
|
|
|
ui->icon_noSync->setPixmap(iconNoSync.scaledToHeight(16, Qt::SmoothTransformation));
|
|
|
|
ui->icon_allTor->setPixmap(iconAllTor.scaledToHeight(16, Qt::SmoothTransformation));
|
|
|
|
}
|
|
|
|
|
|
|
|
void TorInfoDialog::onStopTor() {
|
|
|
|
torManager()->stop();
|
2020-10-07 10:36:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TorInfoDialog::~TorInfoDialog() {
|
|
|
|
delete ui;
|
|
|
|
}
|