mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-23 02:00:20 +07:00
Merge remote-tracking branch 'origin/dev' into ios-wireguard
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
#include "defines.h"
|
||||
#include "ui/qautostart.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
|
||||
using namespace amnezia;
|
||||
using namespace PageEnumNS;
|
||||
|
||||
@@ -11,7 +15,8 @@ AppSettingsLogic::AppSettingsLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent),
|
||||
m_checkBoxAutostartChecked{false},
|
||||
m_checkBoxAutoConnectChecked{false},
|
||||
m_checkBoxStartMinimizedChecked{false}
|
||||
m_checkBoxStartMinimizedChecked{false},
|
||||
m_checkBoxSaveLogsChecked{false}
|
||||
{
|
||||
|
||||
}
|
||||
@@ -21,6 +26,7 @@ void AppSettingsLogic::onUpdatePage()
|
||||
set_checkBoxAutostartChecked(Autostart::isAutostart());
|
||||
set_checkBoxAutoConnectChecked(m_settings.isAutoConnect());
|
||||
set_checkBoxStartMinimizedChecked(m_settings.isStartMinimized());
|
||||
set_checkBoxSaveLogsChecked(m_settings.isSaveLogs());
|
||||
|
||||
QString ver = QString("%1: %2 (%3)")
|
||||
.arg(tr("Software version"))
|
||||
@@ -47,7 +53,38 @@ void AppSettingsLogic::onCheckBoxStartMinimizedToggled(bool checked)
|
||||
m_settings.setStartMinimized(checked);
|
||||
}
|
||||
|
||||
void AppSettingsLogic::onCheckBoxSaveLogsCheckedToggled(bool checked)
|
||||
{
|
||||
m_settings.setSaveLogs(checked);
|
||||
}
|
||||
|
||||
void AppSettingsLogic::onPushButtonOpenLogsClicked()
|
||||
{
|
||||
Debug::openLogsFolder();
|
||||
}
|
||||
|
||||
void AppSettingsLogic::onPushButtonExportLogsClicked()
|
||||
{
|
||||
QString log = Debug::getLogFile();
|
||||
QString ext = ".log";
|
||||
|
||||
QString fileName = QFileDialog::getSaveFileName(nullptr, tr("Save log"),
|
||||
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), "*" + ext);
|
||||
|
||||
if (fileName.isEmpty()) return;
|
||||
if (!fileName.endsWith(ext)) fileName.append(ext);
|
||||
|
||||
QFile save(fileName);
|
||||
save.open(QIODevice::WriteOnly);
|
||||
save.write(log.toUtf8());
|
||||
save.close();
|
||||
|
||||
QFileInfo fi(fileName);
|
||||
QDesktopServices::openUrl(fi.absoluteDir().absolutePath());
|
||||
}
|
||||
|
||||
void AppSettingsLogic::onPushButtonClearLogsClicked()
|
||||
{
|
||||
Debug::clearLogs();
|
||||
Debug::clearServiceLogs();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ class AppSettingsLogic : public PageLogicBase
|
||||
AUTO_PROPERTY(bool, checkBoxAutostartChecked)
|
||||
AUTO_PROPERTY(bool, checkBoxAutoConnectChecked)
|
||||
AUTO_PROPERTY(bool, checkBoxStartMinimizedChecked)
|
||||
AUTO_PROPERTY(bool, checkBoxSaveLogsChecked)
|
||||
AUTO_PROPERTY(QString, labelVersionText)
|
||||
|
||||
public:
|
||||
@@ -19,7 +20,10 @@ public:
|
||||
Q_INVOKABLE void onCheckBoxAutostartToggled(bool checked);
|
||||
Q_INVOKABLE void onCheckBoxAutoconnectToggled(bool checked);
|
||||
Q_INVOKABLE void onCheckBoxStartMinimizedToggled(bool checked);
|
||||
Q_INVOKABLE void onCheckBoxSaveLogsCheckedToggled(bool checked);
|
||||
Q_INVOKABLE void onPushButtonOpenLogsClicked();
|
||||
Q_INVOKABLE void onPushButtonExportLogsClicked();
|
||||
Q_INVOKABLE void onPushButtonClearLogsClicked();
|
||||
|
||||
public:
|
||||
explicit AppSettingsLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
NetworkSettingsLogic::NetworkSettingsLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent),
|
||||
m_checkBoxUseAmneziaDnsChecked{false},
|
||||
m_ipAddressRegex{Utils::ipAddressRegExp()}
|
||||
{
|
||||
|
||||
@@ -12,6 +13,8 @@ NetworkSettingsLogic::NetworkSettingsLogic(UiLogic *logic, QObject *parent):
|
||||
|
||||
void NetworkSettingsLogic::onUpdatePage()
|
||||
{
|
||||
set_checkBoxUseAmneziaDnsChecked(m_settings.useAmneziaDns());
|
||||
|
||||
set_lineEditDns1Text(m_settings.primaryDns());
|
||||
set_lineEditDns2Text(m_settings.secondaryDns());
|
||||
}
|
||||
@@ -41,3 +44,8 @@ void NetworkSettingsLogic::onPushButtonResetDns2Clicked()
|
||||
m_settings.setSecondaryDns(m_settings.cloudFlareNs2);
|
||||
onUpdatePage();
|
||||
}
|
||||
|
||||
void NetworkSettingsLogic::onCheckBoxUseAmneziaDnsToggled(bool checked)
|
||||
{
|
||||
m_settings.setUseAmneziaDns(checked);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ class NetworkSettingsLogic : public PageLogicBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
AUTO_PROPERTY(bool, checkBoxUseAmneziaDnsChecked)
|
||||
|
||||
AUTO_PROPERTY(QString, lineEditDns1Text)
|
||||
AUTO_PROPERTY(QString, lineEditDns2Text)
|
||||
READONLY_PROPERTY(QRegExp, ipAddressRegex)
|
||||
@@ -21,6 +23,8 @@ public:
|
||||
Q_INVOKABLE void onPushButtonResetDns1Clicked();
|
||||
Q_INVOKABLE void onPushButtonResetDns2Clicked();
|
||||
|
||||
Q_INVOKABLE void onCheckBoxUseAmneziaDnsToggled(bool checked);
|
||||
|
||||
public:
|
||||
explicit NetworkSettingsLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~NetworkSettingsLogic() = default;
|
||||
|
||||
@@ -38,8 +38,6 @@ void QrDecoderLogic::onDetectedQrCode(const QString &code)
|
||||
|
||||
|
||||
if (magic == amnezia::qrMagicCode) {
|
||||
qDebug() << "QrDecoderLogic::onDetectedQrCode magic code detected" << magic << ba.size();
|
||||
|
||||
quint8 chunksCount; s >> chunksCount;
|
||||
if (totalChunksCount() != chunksCount) {
|
||||
m_chunks.clear();
|
||||
|
||||
@@ -12,6 +12,9 @@
|
||||
#include <functional>
|
||||
|
||||
#include "../uilogic.h"
|
||||
#include "../pages_logic/VpnLogic.h"
|
||||
#include "vpnconnection.h"
|
||||
|
||||
|
||||
ServerContainersLogic::ServerContainersLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent)
|
||||
@@ -42,8 +45,17 @@ void ServerContainersLogic::onPushButtonProtoSettingsClicked(DockerContainer c,
|
||||
|
||||
void ServerContainersLogic::onPushButtonDefaultClicked(DockerContainer c)
|
||||
{
|
||||
if (m_settings.defaultContainer(uiLogic()->selectedServerIndex) == c) return;
|
||||
|
||||
m_settings.setDefaultContainer(uiLogic()->selectedServerIndex, c);
|
||||
uiLogic()->onUpdateAllPages();
|
||||
|
||||
if (uiLogic()->selectedServerIndex != m_settings.defaultServerIndex()) return;
|
||||
if (!uiLogic()->m_vpnConnection) return;
|
||||
if (!uiLogic()->m_vpnConnection->isConnected()) return;
|
||||
|
||||
uiLogic()->vpnLogic()->onDisconnect();
|
||||
uiLogic()->vpnLogic()->onConnect();
|
||||
}
|
||||
|
||||
void ServerContainersLogic::onPushButtonShareClicked(DockerContainer c)
|
||||
|
||||
@@ -28,8 +28,8 @@ void ServerSettingsLogic::onUpdatePage()
|
||||
set_pushButtonClearVisible(m_settings.haveAuthData(uiLogic()->selectedServerIndex));
|
||||
set_pushButtonClearClientCacheVisible(m_settings.haveAuthData(uiLogic()->selectedServerIndex));
|
||||
set_pushButtonShareFullVisible(m_settings.haveAuthData(uiLogic()->selectedServerIndex));
|
||||
QJsonObject server = m_settings.server(uiLogic()->selectedServerIndex);
|
||||
QString port = server.value(config_key::port).toString();
|
||||
const QJsonObject &server = m_settings.server(uiLogic()->selectedServerIndex);
|
||||
const QString &port = server.value(config_key::port).toString();
|
||||
set_labelServerText(QString("%1@%2%3%4")
|
||||
.arg(server.value(config_key::userName).toString())
|
||||
.arg(server.value(config_key::hostName).toString())
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
#include <QBuffer>
|
||||
#include <QImage>
|
||||
#include <QDataStream>
|
||||
#include <QZXing>
|
||||
//#include <QZXing>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "QZXing.h"
|
||||
#include "QZXingImageProvider.h"
|
||||
#include "QZXingFilter.h"
|
||||
|
||||
#include "ShareConnectionLogic.h"
|
||||
|
||||
#include "configurators/cloak_configurator.h"
|
||||
@@ -60,21 +64,24 @@ void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked()
|
||||
set_shareAmneziaQrCodeTextSeriesLength(0);
|
||||
|
||||
QJsonObject serverConfig;
|
||||
int serverIndex = uiLogic()->selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->selectedDockerContainer;
|
||||
|
||||
// Full access
|
||||
if (shareFullAccess()) {
|
||||
serverConfig = m_settings.server(uiLogic()->selectedServerIndex);
|
||||
serverConfig = m_settings.server(serverIndex);
|
||||
}
|
||||
// Container share
|
||||
else {
|
||||
ServerCredentials credentials = m_settings.serverCredentials(uiLogic()->selectedServerIndex);
|
||||
QJsonObject containerConfig = m_settings.containerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
containerConfig.insert(config_key::container, ContainerProps::containerToString(uiLogic()->selectedDockerContainer));
|
||||
ServerCredentials credentials = m_settings.serverCredentials(serverIndex);
|
||||
QJsonObject containerConfig = m_settings.containerConfig(serverIndex, container);
|
||||
containerConfig.insert(config_key::container, ContainerProps::containerToString(container));
|
||||
|
||||
ErrorCode e = ErrorCode::NoError;
|
||||
for (Proto p: ContainerProps::protocolsForContainer(uiLogic()->selectedDockerContainer)) {
|
||||
QJsonObject protoConfig = m_settings.protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, p);
|
||||
for (Proto p: ContainerProps::protocolsForContainer(container)) {
|
||||
QJsonObject protoConfig = m_settings.protocolConfig(serverIndex, container, p);
|
||||
|
||||
QString cfg = VpnConfigurator::genVpnProtocolConfig(credentials, uiLogic()->selectedDockerContainer, containerConfig, p, &e);
|
||||
QString cfg = VpnConfigurator::genVpnProtocolConfig(credentials, container, containerConfig, p, &e);
|
||||
if (e) {
|
||||
cfg = "Error generating config";
|
||||
break;
|
||||
@@ -85,12 +92,17 @@ void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked()
|
||||
|
||||
QByteArray ba;
|
||||
if (!e) {
|
||||
serverConfig = m_settings.server(uiLogic()->selectedServerIndex);
|
||||
serverConfig = m_settings.server(serverIndex);
|
||||
serverConfig.remove(config_key::userName);
|
||||
serverConfig.remove(config_key::password);
|
||||
serverConfig.remove(config_key::port);
|
||||
serverConfig.insert(config_key::containers, QJsonArray {containerConfig});
|
||||
serverConfig.insert(config_key::defaultContainer, ContainerProps::containerToString(uiLogic()->selectedDockerContainer));
|
||||
serverConfig.insert(config_key::defaultContainer, ContainerProps::containerToString(container));
|
||||
|
||||
auto dns = VpnConfigurator::getDnsForConfig(serverIndex);
|
||||
serverConfig.insert(config_key::dns1, dns.first);
|
||||
serverConfig.insert(config_key::dns2, dns.second);
|
||||
|
||||
}
|
||||
else {
|
||||
set_textEditShareAmneziaCodeText(tr("Error while generating connection profile"));
|
||||
@@ -111,12 +123,15 @@ void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked()
|
||||
|
||||
void ShareConnectionLogic::onPushButtonShareOpenVpnGenerateClicked()
|
||||
{
|
||||
ServerCredentials credentials = m_settings.serverCredentials(uiLogic()->selectedServerIndex);
|
||||
const QJsonObject &containerConfig = m_settings.containerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer);
|
||||
int serverIndex = uiLogic()->selectedServerIndex;
|
||||
DockerContainer container = uiLogic()->selectedDockerContainer;
|
||||
ServerCredentials credentials = m_settings.serverCredentials(serverIndex);
|
||||
|
||||
const QJsonObject &containerConfig = m_settings.containerConfig(serverIndex, container);
|
||||
|
||||
ErrorCode e = ErrorCode::NoError;
|
||||
QString cfg = OpenVpnConfigurator::genOpenVpnConfig(credentials, uiLogic()->selectedDockerContainer, containerConfig, &e);
|
||||
cfg = VpnConfigurator::processConfigWithExportSettings(uiLogic()->selectedDockerContainer, Proto::OpenVpn, cfg);
|
||||
QString cfg = OpenVpnConfigurator::genOpenVpnConfig(credentials, container, containerConfig, &e);
|
||||
cfg = VpnConfigurator::processConfigWithExportSettings(serverIndex, container, Proto::OpenVpn, cfg);
|
||||
|
||||
set_textEditShareOpenVpnCodeText(QJsonDocument::fromJson(cfg.toUtf8()).object()[config_key::config].toString());
|
||||
}
|
||||
@@ -202,7 +217,7 @@ void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked()
|
||||
errorString(e));
|
||||
return;
|
||||
}
|
||||
cfg = VpnConfigurator::processConfigWithExportSettings(container, Proto::WireGuard, cfg);
|
||||
cfg = VpnConfigurator::processConfigWithExportSettings(serverIndex, container, Proto::WireGuard, cfg);
|
||||
cfg = QJsonDocument::fromJson(cfg.toUtf8()).object()[config_key::config].toString();
|
||||
|
||||
set_textEditShareWireGuardCodeText(cfg);
|
||||
@@ -223,7 +238,7 @@ void ShareConnectionLogic::onPushButtonShareIkev2GenerateClicked()
|
||||
Ikev2Configurator::ConnectionData connData = Ikev2Configurator::prepareIkev2Config(credentials, container);
|
||||
|
||||
QString cfg = Ikev2Configurator::genIkev2Config(connData);
|
||||
cfg = VpnConfigurator::processConfigWithExportSettings(container, Proto::Ikev2, cfg);
|
||||
cfg = VpnConfigurator::processConfigWithExportSettings(serverIndex, container, Proto::Ikev2, cfg);
|
||||
cfg = QJsonDocument::fromJson(cfg.toUtf8()).object()[config_key::cert].toString();
|
||||
|
||||
set_textEditShareIkev2CertText(cfg);
|
||||
|
||||
@@ -98,27 +98,32 @@ void SitesLogic::onPushButtonAddCustomSitesClicked()
|
||||
}
|
||||
}
|
||||
|
||||
void SitesLogic::onPushButtonSitesDeleteClicked(int row)
|
||||
void SitesLogic::onPushButtonSitesDeleteClicked(QStringList items)
|
||||
{
|
||||
Settings::RouteMode mode = m_settings.routeMode();
|
||||
|
||||
auto siteModel = qobject_cast<SitesModel*> (tableViewSitesModel());
|
||||
if (!siteModel) {
|
||||
return;
|
||||
}
|
||||
if (row < 0 || row >= siteModel->rowCount()) {
|
||||
if (!siteModel || items.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
QStringList sites;
|
||||
QStringList sites;
|
||||
QStringList ips;
|
||||
|
||||
for (const QString &s: items) {
|
||||
bool ok;
|
||||
int row = s.toInt(&ok);
|
||||
if (!ok || row < 0 || row >= siteModel->rowCount()) return;
|
||||
sites.append(siteModel->data(row, 0).toString());
|
||||
m_settings.removeVpnSites(mode, sites);
|
||||
|
||||
if (uiLogic()->m_vpnConnection->connectionState() == VpnProtocol::Connected) {
|
||||
ips.append(siteModel->data(row, 1).toString());
|
||||
}
|
||||
}
|
||||
|
||||
m_settings.removeVpnSites(mode, sites);
|
||||
|
||||
if (uiLogic()->m_vpnConnection->connectionState() == VpnProtocol::Connected) {
|
||||
QStringList ips;
|
||||
ips.append(siteModel->data(row, 1).toString());
|
||||
uiLogic()->m_vpnConnection->deleteRoutes(ips);
|
||||
uiLogic()->m_vpnConnection->flushDns();
|
||||
}
|
||||
@@ -137,18 +142,53 @@ void SitesLogic::onPushButtonSitesImportClicked(const QString& fileName)
|
||||
Settings::RouteMode mode = m_settings.routeMode();
|
||||
|
||||
QStringList ips;
|
||||
QMap<QString, QString> sites;
|
||||
|
||||
while (!file.atEnd()) {
|
||||
QString line = file.readLine();
|
||||
QStringList line_ips;
|
||||
QStringList line_sites;
|
||||
|
||||
int pos = 0;
|
||||
QRegExp rx = Utils::ipAddressWithSubnetRegExp();
|
||||
while ((pos = rx.indexIn(line, pos)) != -1) {
|
||||
ips << rx.cap(0);
|
||||
pos += rx.matchedLength();
|
||||
int posDomain = 0;
|
||||
QRegExp domainRx = Utils::domainRegExp();
|
||||
while ((posDomain = domainRx.indexIn(line, posDomain)) != -1) {
|
||||
line_sites.append(domainRx.cap(0));
|
||||
posDomain += domainRx.matchedLength();
|
||||
}
|
||||
|
||||
int posIp = 0;
|
||||
QRegExp ipRx = Utils::ipAddressWithSubnetRegExp();
|
||||
while ((posIp = ipRx.indexIn(line, posIp)) != -1) {
|
||||
line_ips.append(ipRx.cap(0));
|
||||
posIp += ipRx.matchedLength();
|
||||
}
|
||||
|
||||
// domain regex cover ip regex, so remove ips from sites
|
||||
for (const QString& ip: line_ips) {
|
||||
line_sites.removeAll(ip);
|
||||
}
|
||||
|
||||
if (line_sites.size() == 1 && line_ips.size() == 1) {
|
||||
sites.insert(line_sites.at(0), line_ips.at(0));
|
||||
}
|
||||
else if (line_sites.size() > 0 && line_ips.size() == 0) {
|
||||
for (const QString& site: line_sites) {
|
||||
sites.insert(site, "");
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (const QString& site: line_sites) {
|
||||
sites.insert(site, "");
|
||||
}
|
||||
for (const QString& ip: line_ips) {
|
||||
ips.append(ip);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
m_settings.addVpnIps(mode, ips);
|
||||
m_settings.addVpnSites(mode, sites);
|
||||
|
||||
uiLogic()->m_vpnConnection->addRoutes(QStringList() << ips);
|
||||
uiLogic()->m_vpnConnection->flushDns();
|
||||
@@ -156,3 +196,16 @@ void SitesLogic::onPushButtonSitesImportClicked(const QString& fileName)
|
||||
onUpdatePage();
|
||||
}
|
||||
|
||||
void SitesLogic::onPushButtonSitesExportClicked()
|
||||
{
|
||||
Settings::RouteMode mode = m_settings.routeMode();
|
||||
|
||||
QVariantMap sites = m_settings.vpnSites(mode);
|
||||
|
||||
QString data;
|
||||
for (auto s : sites.keys()) {
|
||||
data += s + "\t" + sites.value(s).toString() + "\n";
|
||||
}
|
||||
uiLogic()->saveTextFile("Sites", ".txt", data);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,10 @@ public:
|
||||
Q_INVOKABLE void onUpdatePage() override;
|
||||
|
||||
Q_INVOKABLE void onPushButtonAddCustomSitesClicked();
|
||||
Q_INVOKABLE void onPushButtonSitesDeleteClicked(int row);
|
||||
Q_INVOKABLE void onPushButtonSitesDeleteClicked(QStringList items);
|
||||
Q_INVOKABLE void onPushButtonSitesImportClicked(const QString &fileName);
|
||||
Q_INVOKABLE void onPushButtonSitesExportClicked();
|
||||
|
||||
|
||||
public:
|
||||
explicit SitesLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <functional>
|
||||
#include "../uilogic.h"
|
||||
#include "defines.h"
|
||||
#include <configurators/vpn_configurator.h>
|
||||
|
||||
|
||||
VpnLogic::VpnLogic(UiLogic *logic, QObject *parent):
|
||||
@@ -33,15 +34,24 @@ VpnLogic::VpnLogic(UiLogic *logic, QObject *parent):
|
||||
onConnect();
|
||||
});
|
||||
}
|
||||
else {
|
||||
onConnectionStateChanged(VpnProtocol::Disconnected);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VpnLogic::onUpdatePage()
|
||||
{
|
||||
Settings::RouteMode mode = m_settings.routeMode();
|
||||
set_radioButtonVpnModeAllSitesChecked(mode == Settings::VpnAllSites);
|
||||
set_radioButtonVpnModeForwardSitesChecked(mode == Settings::VpnOnlyForwardSites);
|
||||
set_radioButtonVpnModeExceptSitesChecked(mode == Settings::VpnAllExceptSites);
|
||||
DockerContainer selectedContainer = m_settings.defaultContainer(m_settings.defaultServerIndex());
|
||||
|
||||
set_isCustomRoutesSupported (selectedContainer == DockerContainer::OpenVpn ||
|
||||
selectedContainer == DockerContainer::ShadowSocks||
|
||||
selectedContainer == DockerContainer::Cloak);
|
||||
|
||||
set_radioButtonVpnModeAllSitesChecked(mode == Settings::VpnAllSites || !isCustomRoutesSupported());
|
||||
set_radioButtonVpnModeForwardSitesChecked(mode == Settings::VpnOnlyForwardSites && isCustomRoutesSupported());
|
||||
set_radioButtonVpnModeExceptSitesChecked(mode == Settings::VpnAllExceptSites && isCustomRoutesSupported());
|
||||
|
||||
const QJsonObject &server = uiLogic()->m_settings.defaultServer();
|
||||
QString serverString = QString("%2 (%3)")
|
||||
@@ -49,10 +59,19 @@ void VpnLogic::onUpdatePage()
|
||||
.arg(server.value(config_key::hostName).toString());
|
||||
set_labelCurrentServer(serverString);
|
||||
|
||||
DockerContainer selectedContainer = m_settings.defaultContainer(m_settings.defaultServerIndex());
|
||||
QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer);
|
||||
set_labelCurrentService(selectedContainerName);
|
||||
|
||||
auto dns = VpnConfigurator::getDnsForConfig(m_settings.defaultServerIndex());
|
||||
set_amneziaDnsEnabled(dns.first == protocols::dns::amneziaDnsIp);
|
||||
if (dns.first == protocols::dns::amneziaDnsIp) {
|
||||
set_labelCurrentDns("On your server");
|
||||
}
|
||||
else {
|
||||
set_labelCurrentDns(dns.first + ", " + dns.second);
|
||||
}
|
||||
|
||||
|
||||
set_isContainerWorkingOnPlatform(ContainerProps::isWorkingOnPlatform(selectedContainer));
|
||||
if (!isContainerWorkingOnPlatform()) {
|
||||
set_labelErrorText(tr("AmneziaVPN not supporting selected protocol on this device. Select another protocol."));
|
||||
|
||||
@@ -16,6 +16,9 @@ class VpnLogic : public PageLogicBase
|
||||
AUTO_PROPERTY(QString, labelStateText)
|
||||
AUTO_PROPERTY(QString, labelCurrentServer)
|
||||
AUTO_PROPERTY(QString, labelCurrentService)
|
||||
AUTO_PROPERTY(QString, labelCurrentDns)
|
||||
AUTO_PROPERTY(bool, amneziaDnsEnabled)
|
||||
|
||||
AUTO_PROPERTY(bool, pushButtonConnectEnabled)
|
||||
AUTO_PROPERTY(bool, pushButtonConnectVisible)
|
||||
AUTO_PROPERTY(bool, widgetVpnModeEnabled)
|
||||
@@ -24,6 +27,8 @@ class VpnLogic : public PageLogicBase
|
||||
AUTO_PROPERTY(QString, labelErrorText)
|
||||
AUTO_PROPERTY(QString, labelVersionText)
|
||||
|
||||
AUTO_PROPERTY(bool, isCustomRoutesSupported)
|
||||
|
||||
AUTO_PROPERTY(bool, radioButtonVpnModeAllSitesChecked)
|
||||
AUTO_PROPERTY(bool, radioButtonVpnModeForwardSitesChecked)
|
||||
AUTO_PROPERTY(bool, radioButtonVpnModeExceptSitesChecked)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <QTimer>
|
||||
#include <QProcess>
|
||||
#include <QStorageInfo>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "OtherProtocolsLogic.h"
|
||||
#include "core/servercontroller.h"
|
||||
@@ -17,7 +18,9 @@ using namespace amnezia;
|
||||
using namespace PageEnumNS;
|
||||
|
||||
OtherProtocolsLogic::OtherProtocolsLogic(UiLogic *logic, QObject *parent):
|
||||
PageProtocolLogicBase(logic, parent)
|
||||
PageProtocolLogicBase(logic, parent),
|
||||
m_checkBoxSftpRestoreChecked{false}
|
||||
|
||||
{
|
||||
|
||||
}
|
||||
@@ -41,17 +44,12 @@ void OtherProtocolsLogic::updateProtocolPage(const QJsonObject &config, DockerCo
|
||||
set_labelTftpPortText(config.value(config_key::port).toString());
|
||||
|
||||
set_labelTorWebSiteAddressText(config.value(config_key::site).toString());
|
||||
set_pushButtonSftpMountEnabled(true);
|
||||
}
|
||||
|
||||
//QJsonObject OtherProtocolsLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
|
||||
void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
|
||||
{
|
||||
#ifdef Q_OS_WINDOWS
|
||||
QString OtherProtocolsLogic::getNextDriverLetter() const
|
||||
{
|
||||
QProcess drivesProc;
|
||||
drivesProc.start("wmic logicaldisk get caption");
|
||||
drivesProc.waitForFinished();
|
||||
@@ -68,53 +66,93 @@ void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
|
||||
if (letter == "C:") {
|
||||
// set err info
|
||||
qDebug() << "Can't find free drive letter";
|
||||
return;
|
||||
return "";
|
||||
}
|
||||
return letter;
|
||||
}
|
||||
#endif
|
||||
|
||||
//QJsonObject OtherProtocolsLogic::getProtocolConfigFromPage(QJsonObject oldConfig)
|
||||
//{
|
||||
|
||||
//}
|
||||
|
||||
|
||||
void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
|
||||
{
|
||||
QString mountPath;
|
||||
QString cmd;
|
||||
QString host = m_settings.serverCredentials(uiLogic()->selectedServerIndex).hostName;
|
||||
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
mountPath = getNextDriverLetter() + ":";
|
||||
// QString cmd = QString("net use \\\\sshfs\\%1@x.x.x.x!%2 /USER:%1 %3")
|
||||
// .arg(labelTftpUserNameText())
|
||||
// .arg(labelTftpPortText())
|
||||
// .arg(labelTftpPasswordText());
|
||||
|
||||
cmd = "C:\\Program Files\\SSHFS-Win\\bin\\sshfs.exe";
|
||||
#elif defined AMNEZIA_DESKTOP
|
||||
mountPath = QString("%1/sftp:%2:%3")
|
||||
.arg(QStandardPaths::writableLocation(QStandardPaths::HomeLocation))
|
||||
.arg(host)
|
||||
.arg(labelTftpPortText());
|
||||
QDir dir(mountPath);
|
||||
if (!dir.exists()){
|
||||
dir.mkpath(mountPath);
|
||||
}
|
||||
|
||||
cmd = "/usr/local/bin/sshfs";
|
||||
#endif
|
||||
|
||||
#ifdef AMNEZIA_DESKTOP
|
||||
set_pushButtonSftpMountEnabled(false);
|
||||
QProcess *p = new QProcess;
|
||||
m_sftpMountProcesses.append(p);
|
||||
p->setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
connect(p, &QProcess::readyRead, this, [this, p, letter](){
|
||||
connect(p, &QProcess::readyRead, this, [this, p, mountPath](){
|
||||
QString s = p->readAll();
|
||||
if (s.contains("The service sshfs has been started")) {
|
||||
QDesktopServices::openUrl(QUrl("file:///" + letter + ":"));
|
||||
QDesktopServices::openUrl(QUrl("file:///" + mountPath));
|
||||
set_pushButtonSftpMountEnabled(true);
|
||||
}
|
||||
qDebug() << s;
|
||||
});
|
||||
|
||||
// QString cmd = QString("net use \\\\sshfs\\%1@51.77.32.168!%2 /USER:%1 %3")
|
||||
// .arg(labelTftpUserNameText())
|
||||
// .arg(labelTftpPortText())
|
||||
// .arg(labelTftpPasswordText());
|
||||
|
||||
p->setProgram("C:\\Program Files\\SSHFS-Win\\bin\\sshfs.exe");
|
||||
|
||||
QString host = m_settings.serverCredentials(uiLogic()->selectedServerIndex).hostName;
|
||||
p->setProgram(cmd);
|
||||
|
||||
QString args = QString(
|
||||
"%1@%2:/ %3: "
|
||||
"%1@%2:/ %3 "
|
||||
"-o port=%4 "
|
||||
"-f "
|
||||
"-o reconnect"
|
||||
"-orellinks "
|
||||
"-ofstypename=SSHFS "
|
||||
"-o reconnect "
|
||||
"-o rellinks "
|
||||
"-o fstypename=SSHFS "
|
||||
"-o ssh_command=/usr/bin/ssh.exe "
|
||||
"-oUserKnownHostsFile=/dev/null "
|
||||
"-oStrictHostKeyChecking=no "
|
||||
"-o UserKnownHostsFile=/dev/null "
|
||||
"-o StrictHostKeyChecking=no "
|
||||
"-o password_stdin")
|
||||
.arg(labelTftpUserNameText())
|
||||
.arg(host)
|
||||
.arg(letter)
|
||||
.arg(mountPath)
|
||||
.arg(labelTftpPortText());
|
||||
|
||||
|
||||
p->setNativeArguments(args);
|
||||
// args.replace("\n", " ");
|
||||
// args.replace("\r", " ");
|
||||
//#ifndef Q_OS_WIN
|
||||
// args.replace("reconnect-orellinks", "");
|
||||
//#endif
|
||||
p->setArguments(args.split(" ", QString::SkipEmptyParts));
|
||||
p->start();
|
||||
p->waitForStarted(50);
|
||||
if (p->state() != QProcess::Running) {
|
||||
qDebug() << "onPushButtonSftpMountDriveClicked process not started";
|
||||
qDebug() << args;
|
||||
}
|
||||
else {
|
||||
p->write((labelTftpPasswordText() + "\n").toUtf8());
|
||||
@@ -123,7 +161,6 @@ void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked()
|
||||
//qDebug().noquote() << "onPushButtonSftpMountDriveClicked" << args;
|
||||
|
||||
set_pushButtonSftpMountEnabled(true);
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,13 @@ private:
|
||||
Settings m_settings;
|
||||
UiLogic *m_uiLogic;
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
#ifdef AMNEZIA_DESKTOP
|
||||
QList <QProcess *> m_sftpMountProcesses;
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
QString getNextDriverLetter() const;
|
||||
#endif
|
||||
|
||||
};
|
||||
#endif // OTHER_PROTOCOLS_LOGIC_H
|
||||
|
||||
Reference in New Issue
Block a user