From b2fd94d20ef5756d69c879f739ef5654ce98a77b Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Mon, 6 Feb 2023 19:19:49 +0300 Subject: [PATCH 01/12] added a check for the existence of the container before installing it --- client/core/defs.h | 1 + client/core/errorstrings.cpp | 1 + client/core/servercontroller.cpp | 28 ++++++++++++++++++++++++++++ client/core/servercontroller.h | 1 + 4 files changed, 31 insertions(+) diff --git a/client/core/defs.h b/client/core/defs.h index 3f861401..884cb60f 100644 --- a/client/core/defs.h +++ b/client/core/defs.h @@ -32,6 +32,7 @@ enum ErrorCode ServerContainerMissingError, ServerDockerFailedError, ServerCancelInstallation, + ServerContainerAlreadyInstalledError, // Ssh connection errors SshSocketError, SshTimeoutError, SshProtocolError, diff --git a/client/core/errorstrings.cpp b/client/core/errorstrings.cpp index 1e7eb395..9460365f 100644 --- a/client/core/errorstrings.cpp +++ b/client/core/errorstrings.cpp @@ -16,6 +16,7 @@ QString errorString(ErrorCode code){ case(ServerContainerMissingError): return QObject::tr("Server error: Docker container missing"); case(ServerDockerFailedError): return QObject::tr("Server error: Docker failed"); case(ServerCancelInstallation): return QObject::tr("Installation canceled by user"); + case(ServerContainerAlreadyInstalledError): return QObject::tr("Container already installed"); // Ssh connection errors case(SshSocketError): return QObject::tr("Ssh connection error"); diff --git a/client/core/servercontroller.cpp b/client/core/servercontroller.cpp index 375215b7..e2095492 100644 --- a/client/core/servercontroller.cpp +++ b/client/core/servercontroller.cpp @@ -415,6 +415,9 @@ ErrorCode ServerController::setupContainer(const ServerCredentials &credentials, //qDebug().noquote() << QJsonDocument(config).toJson(); ErrorCode e = ErrorCode::NoError; + e = isContainerAlreadyInstalled(credentials, container); + if (e) return e; + e = installDockerWorker(credentials, container); if (e) return e; qDebug().noquote() << "ServerController::setupContainer installDockerWorker finished"; @@ -856,3 +859,28 @@ QString ServerController::replaceVars(const QString &script, const Vars &vars) //qDebug().noquote() << script; return s; } + +ErrorCode ServerController::isContainerAlreadyInstalled(const ServerCredentials &credentials, DockerContainer container) +{ + QString stdOut; + auto cbReadStdOut = [&](const QString &data, QSharedPointer proc) { + stdOut += data + "\n"; + }; + auto cbReadStdErr = [&](const QString &data, QSharedPointer ) { + stdOut += data + "\n"; + }; + + QString script = QString("sudo docker ps | grep %1").arg(ContainerProps::containerToString(container)); + + ErrorCode errorCode = runScript(credentials, + replaceVars(script, genVarsForScript(credentials, container)), cbReadStdOut, cbReadStdErr); + + if (errorCode != ErrorCode::NoError) { + return errorCode; + } + + if (!stdOut.isEmpty()) { + return ErrorCode::ServerContainerAlreadyInstalledError; + } + return ErrorCode::NoError; +} diff --git a/client/core/servercontroller.h b/client/core/servercontroller.h index 04ae1a15..0473b508 100644 --- a/client/core/servercontroller.h +++ b/client/core/servercontroller.h @@ -82,6 +82,7 @@ private: ErrorCode runContainerWorker(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config); ErrorCode configureContainerWorker(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config); ErrorCode startupContainerWorker(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config = QJsonObject()); + ErrorCode isContainerAlreadyInstalled(const ServerCredentials &credentials, DockerContainer container); std::shared_ptr m_settings; std::shared_ptr m_configurator; From b5778a9cb54bf3561c0d85760513f54d7ffb085c Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Tue, 7 Feb 2023 10:39:18 +0300 Subject: [PATCH 02/12] if the container already exists, then add it to the list of containers in the client --- client/ui/pages_logic/ServerContainersLogic.cpp | 4 ++-- client/ui/uilogic.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/ui/pages_logic/ServerContainersLogic.cpp b/client/ui/pages_logic/ServerContainersLogic.cpp index 4a7d2343..70df71e9 100644 --- a/client/ui/pages_logic/ServerContainersLogic.cpp +++ b/client/ui/pages_logic/ServerContainersLogic.cpp @@ -87,11 +87,11 @@ void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int p emit uiLogic()->goToPage(Page::ServerConfiguringProgress); qApp->processEvents(); - ErrorCode e = uiLogic()->pageLogic()->doInstallAction([this, c, &config](){ + ErrorCode error = uiLogic()->pageLogic()->doInstallAction([this, c, &config](){ return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), c, config); }); - if (!e) { + if (error == ErrorCode::NoError || error == ErrorCode::ServerContainerAlreadyInstalledError) { m_settings->setContainerConfig(uiLogic()->selectedServerIndex, c, config); if (ContainerProps::containerService(c) == ServiceType::Vpn) { m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, c); diff --git a/client/ui/uilogic.cpp b/client/ui/uilogic.cpp index 3d442cab..5328fc3b 100644 --- a/client/ui/uilogic.cpp +++ b/client/ui/uilogic.cpp @@ -337,7 +337,7 @@ void UiLogic::installServer(QMap &containers) m_serverController->disconnectFromHost(installCredentials); } - if (error == ErrorCode::NoError) { + if (error == ErrorCode::NoError || error == ErrorCode::ServerContainerAlreadyInstalledError) { QJsonObject server; server.insert(config_key::hostName, installCredentials.hostName); server.insert(config_key::userName, installCredentials.userName); From ddc3fe7807b0177288d1cf8d8641a5deae93fe2e Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Mon, 20 Feb 2023 09:46:50 +0300 Subject: [PATCH 03/12] Added the advanced settings page - added a button to scan the server for installed containers - added a check on the presence of installed containers before configuring the server, if the containers are already installed, then we will add them to the GUI - added new control element - PopupWarning.qml --- client/core/servercontroller.cpp | 36 +++-- client/core/servercontroller.h | 2 +- client/resources.qrc | 2 + client/ui/pages.h | 2 +- .../AdvancedServerSettingsLogic.cpp | 63 +++++++++ .../pages_logic/AdvancedServerSettingsLogic.h | 30 +++++ .../ui/pages_logic/GeneralSettingsLogic.cpp | 20 +-- .../ui/pages_logic/ServerContainersLogic.cpp | 55 ++++---- client/ui/pages_logic/ServerListLogic.cpp | 2 +- client/ui/pages_logic/ServerSettingsLogic.cpp | 42 +++--- .../ui/pages_logic/ShareConnectionLogic.cpp | 28 ++-- client/ui/pages_logic/StartPageLogic.cpp | 2 +- client/ui/pages_logic/ViewConfigLogic.cpp | 4 +- .../ui/pages_logic/protocols/CloakLogic.cpp | 14 +- .../ui/pages_logic/protocols/OpenVpnLogic.cpp | 14 +- .../protocols/OtherProtocolsLogic.cpp | 2 +- .../protocols/ShadowSocksLogic.cpp | 14 +- client/ui/qml/Controls/PopupWarning.qml | 34 +++++ .../qml/Pages/PageAdvancedServerSettings.qml | 100 ++++++++++++++ client/ui/qml/Pages/PageServerSettings.qml | 31 ++--- client/ui/qml/main.qml | 8 ++ client/ui/uilogic.cpp | 123 ++++++++++++++---- client/ui/uilogic.h | 15 ++- 23 files changed, 487 insertions(+), 156 deletions(-) create mode 100644 client/ui/pages_logic/AdvancedServerSettingsLogic.cpp create mode 100644 client/ui/pages_logic/AdvancedServerSettingsLogic.h create mode 100644 client/ui/qml/Controls/PopupWarning.qml create mode 100644 client/ui/qml/Pages/PageAdvancedServerSettings.qml diff --git a/client/core/servercontroller.cpp b/client/core/servercontroller.cpp index e2095492..9b52071c 100644 --- a/client/core/servercontroller.cpp +++ b/client/core/servercontroller.cpp @@ -415,9 +415,6 @@ ErrorCode ServerController::setupContainer(const ServerCredentials &credentials, //qDebug().noquote() << QJsonDocument(config).toJson(); ErrorCode e = ErrorCode::NoError; - e = isContainerAlreadyInstalled(credentials, container); - if (e) return e; - e = installDockerWorker(credentials, container); if (e) return e; qDebug().noquote() << "ServerController::setupContainer installDockerWorker finished"; @@ -860,7 +857,7 @@ QString ServerController::replaceVars(const QString &script, const Vars &vars) return s; } -ErrorCode ServerController::isContainerAlreadyInstalled(const ServerCredentials &credentials, DockerContainer container) +ErrorCode ServerController::getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap &installedContainers) { QString stdOut; auto cbReadStdOut = [&](const QString &data, QSharedPointer proc) { @@ -870,17 +867,36 @@ ErrorCode ServerController::isContainerAlreadyInstalled(const ServerCredentials stdOut += data + "\n"; }; - QString script = QString("sudo docker ps | grep %1").arg(ContainerProps::containerToString(container)); - - ErrorCode errorCode = runScript(credentials, - replaceVars(script, genVarsForScript(credentials, container)), cbReadStdOut, cbReadStdErr); + QString script = QString("sudo docker ps --format '{{.Names}} {{.Ports}}'"); + ErrorCode errorCode = runScript(credentials, script, cbReadStdOut, cbReadStdErr); if (errorCode != ErrorCode::NoError) { return errorCode; } - if (!stdOut.isEmpty()) { - return ErrorCode::ServerContainerAlreadyInstalledError; + auto containersInfo = stdOut.split("\n"); + for (auto &containerInfo : containersInfo) { + if (containerInfo.isEmpty()) { + continue; + } + const static QRegularExpression containerAndPortRegExp("(amnezia-[a-z]*).*?>([0-9]*)/(udp|tcp).*"); + QRegularExpressionMatch containerAndPortMatch = containerAndPortRegExp.match(containerInfo); + if (containerAndPortMatch.hasMatch()) { + QString name = containerAndPortMatch.captured(1); + QString port = containerAndPortMatch.captured(2); + QString transportProto = containerAndPortMatch.captured(3); + DockerContainer container = ContainerProps::containerFromString(name); + Proto mainProto = ContainerProps::defaultProtocol(container); + QJsonObject config { + { config_key::container, name }, + { ProtocolProps::protoToString(mainProto), QJsonObject { + { config_key::port, port }, + { config_key::transport_proto, transportProto }} + } + }; + installedContainers.insert(container, config); + } } + return ErrorCode::NoError; } diff --git a/client/core/servercontroller.h b/client/core/servercontroller.h index 0473b508..39f1f502 100644 --- a/client/core/servercontroller.h +++ b/client/core/servercontroller.h @@ -74,6 +74,7 @@ public: QSsh::SshConnection *connectToHost(const QSsh::SshConnectionParameters &sshParams); void setCancelInstallation(const bool cancel); + ErrorCode getAlreadyInstalledContainers(const ServerCredentials &credentials, QMap &installedContainers); private: ErrorCode installDockerWorker(const ServerCredentials &credentials, DockerContainer container); @@ -82,7 +83,6 @@ private: ErrorCode runContainerWorker(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config); ErrorCode configureContainerWorker(const ServerCredentials &credentials, DockerContainer container, QJsonObject &config); ErrorCode startupContainerWorker(const ServerCredentials &credentials, DockerContainer container, const QJsonObject &config = QJsonObject()); - ErrorCode isContainerAlreadyInstalled(const ServerCredentials &credentials, DockerContainer container); std::shared_ptr m_settings; std::shared_ptr m_configurator; diff --git a/client/resources.qrc b/client/resources.qrc index 4651f91e..27f421a9 100644 --- a/client/resources.qrc +++ b/client/resources.qrc @@ -164,5 +164,7 @@ images/svg/settings_suggest_black_24dp.svg server_scripts/website_tor/Dockerfile ui/qml/Controls/PopupWithQuestion.qml + ui/qml/Pages/PageAdvancedServerSettings.qml + ui/qml/Controls/PopupWarning.qml diff --git a/client/ui/pages.h b/client/ui/pages.h index 69f417fa..dfc9a509 100644 --- a/client/ui/pages.h +++ b/client/ui/pages.h @@ -24,7 +24,7 @@ enum class Page {Start = 0, NewServer, NewServerProtocols, Vpn, Wizard, WizardLow, WizardMedium, WizardHigh, WizardVpnMode, ServerConfiguringProgress, GeneralSettings, AppSettings, NetworkSettings, ServerSettings, ServerContainers, ServersList, ShareConnection, Sites, - ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig}; + ProtocolSettings, ProtocolShare, QrDecoder, QrDecoderIos, About, ViewConfig, AdvancedServerSettings}; Q_ENUM_NS(Page) static void declareQmlPageEnum() { diff --git a/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp b/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp new file mode 100644 index 00000000..0a7ae2c0 --- /dev/null +++ b/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp @@ -0,0 +1,63 @@ +#include "AdvancedServerSettingsLogic.h" + +#include "VpnLogic.h" +#include "ui/uilogic.h" +#include "core/errorstrings.h" +#include "core/servercontroller.h" + +AdvancedServerSettingsLogic::AdvancedServerSettingsLogic(UiLogic *uiLogic, QObject *parent): PageLogicBase(uiLogic, parent), + m_labelWaitInfoVisible{true}, + m_pushButtonClearVisible{true}, + m_pushButtonClearText{tr("Clear server from Amnezia software")} +{ +} + +void AdvancedServerSettingsLogic::onUpdatePage() +{ + set_labelWaitInfoVisible(false); + set_labelWaitInfoText(""); + set_pushButtonClearVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); + const QJsonObject &server = m_settings->server(uiLogic()->m_selectedServerIndex); + const QString &port = server.value(config_key::port).toString(); + + const QString &userName = server.value(config_key::userName).toString(); + const QString &hostName = server.value(config_key::hostName).toString(); + QString name = QString("%1%2%3%4%5").arg(userName, + userName.isEmpty() ? "" : "@", + hostName, + port.isEmpty() ? "" : ":", + port); + + set_labelServerText(name); + + DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex); + QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer); + set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName); +} + +void AdvancedServerSettingsLogic::onPushButtonClearServer() +{ + set_pageEnabled(false); + set_pushButtonClearText(tr("Uninstalling Amnezia software...")); + + if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex) { + uiLogic()->pageLogic()->onDisconnect(); + } + + ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); + m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); + if (e) { + uiLogic()->set_dialogConnectErrorText(tr("Error occurred while configuring server.") + "\n" + + errorString(e) + "\n" + tr("See logs for details.")); + emit uiLogic()->showConnectErrorDialog(); + } else { + set_labelWaitInfoVisible(true); + set_labelWaitInfoText(tr("Amnezia server successfully uninstalled")); + } + + m_settings->setContainers(uiLogic()->m_selectedServerIndex, {}); + m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, DockerContainer::None); + + set_pageEnabled(true); + set_pushButtonClearText(tr("Clear server from Amnezia software")); +} diff --git a/client/ui/pages_logic/AdvancedServerSettingsLogic.h b/client/ui/pages_logic/AdvancedServerSettingsLogic.h new file mode 100644 index 00000000..396b375a --- /dev/null +++ b/client/ui/pages_logic/AdvancedServerSettingsLogic.h @@ -0,0 +1,30 @@ +#ifndef ADVANCEDSERVERSETTINGSLOGIC_H +#define ADVANCEDSERVERSETTINGSLOGIC_H + +#include "PageLogicBase.h" + +class UiLogic; + +class AdvancedServerSettingsLogic : public PageLogicBase +{ + Q_OBJECT + + AUTO_PROPERTY(bool, labelWaitInfoVisible) + AUTO_PROPERTY(QString, labelWaitInfoText) + + AUTO_PROPERTY(QString, pushButtonClearText) + AUTO_PROPERTY(bool, pushButtonClearVisible) + + AUTO_PROPERTY(QString, labelServerText) + AUTO_PROPERTY(QString, labelCurrentVpnProtocolText) + +public: + explicit AdvancedServerSettingsLogic(UiLogic *uiLogic, QObject *parent = nullptr); + ~AdvancedServerSettingsLogic() = default; + + Q_INVOKABLE void onUpdatePage() override; + + Q_INVOKABLE void onPushButtonClearServer(); +}; + +#endif // ADVANCEDSERVERSETTINGSLOGIC_H diff --git a/client/ui/pages_logic/GeneralSettingsLogic.cpp b/client/ui/pages_logic/GeneralSettingsLogic.cpp index c4b04c01..cbdf2692 100644 --- a/client/ui/pages_logic/GeneralSettingsLogic.cpp +++ b/client/ui/pages_logic/GeneralSettingsLogic.cpp @@ -12,29 +12,29 @@ GeneralSettingsLogic::GeneralSettingsLogic(UiLogic *logic, QObject *parent): void GeneralSettingsLogic::onUpdatePage() { - uiLogic()->selectedServerIndex = m_settings->defaultServerIndex(); - set_existsAnyServer(uiLogic()->selectedServerIndex >= 0); - uiLogic()->selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex()); + uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex(); + set_existsAnyServer(uiLogic()->m_selectedServerIndex >= 0); + uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex()); set_pushButtonGeneralSettingsShareConnectionEnable(m_settings->haveAuthData(m_settings->defaultServerIndex())); } void GeneralSettingsLogic::onPushButtonGeneralSettingsServerSettingsClicked() { - uiLogic()->selectedServerIndex = m_settings->defaultServerIndex(); - uiLogic()->selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex()); + uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex(); + uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(m_settings->defaultServerIndex()); emit uiLogic()->goToPage(Page::ServerSettings); } void GeneralSettingsLogic::onPushButtonGeneralSettingsShareConnectionClicked() { - uiLogic()->selectedServerIndex = m_settings->defaultServerIndex(); - uiLogic()->selectedDockerContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex); + uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex(); + uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex); - qobject_cast(uiLogic()->protocolsModel())->setSelectedServerIndex(uiLogic()->selectedServerIndex); - qobject_cast(uiLogic()->protocolsModel())->setSelectedDockerContainer(uiLogic()->selectedDockerContainer); + qobject_cast(uiLogic()->protocolsModel())->setSelectedServerIndex(uiLogic()->m_selectedServerIndex); + qobject_cast(uiLogic()->protocolsModel())->setSelectedDockerContainer(uiLogic()->m_selectedDockerContainer); - uiLogic()->pageLogic()->updateSharingPage(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer); + uiLogic()->pageLogic()->updateSharingPage(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer); emit uiLogic()->goToPage(Page::ShareConnection); } diff --git a/client/ui/pages_logic/ServerContainersLogic.cpp b/client/ui/pages_logic/ServerContainersLogic.cpp index 70df71e9..6e9896ce 100644 --- a/client/ui/pages_logic/ServerContainersLogic.cpp +++ b/client/ui/pages_logic/ServerContainersLogic.cpp @@ -24,34 +24,34 @@ ServerContainersLogic::ServerContainersLogic(UiLogic *logic, QObject *parent): void ServerContainersLogic::onUpdatePage() { ContainersModel *c_model = qobject_cast(uiLogic()->containersModel()); - c_model->setSelectedServerIndex(uiLogic()->selectedServerIndex); + c_model->setSelectedServerIndex(uiLogic()->m_selectedServerIndex); ProtocolsModel *p_model = qobject_cast(uiLogic()->protocolsModel()); - p_model->setSelectedServerIndex(uiLogic()->selectedServerIndex); + p_model->setSelectedServerIndex(uiLogic()->m_selectedServerIndex); - set_isManagedServer(m_settings->haveAuthData(uiLogic()->selectedServerIndex)); + set_isManagedServer(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); emit updatePage(); } void ServerContainersLogic::onPushButtonProtoSettingsClicked(DockerContainer c, Proto p) { qDebug()<< "ServerContainersLogic::onPushButtonProtoSettingsClicked" << c << p; - uiLogic()->selectedDockerContainer = c; - uiLogic()->protocolLogic(p)->updateProtocolPage(m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, p), - uiLogic()->selectedDockerContainer, - m_settings->haveAuthData(uiLogic()->selectedServerIndex)); + uiLogic()->m_selectedDockerContainer = c; + uiLogic()->protocolLogic(p)->updateProtocolPage(m_settings->protocolConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, p), + uiLogic()->m_selectedDockerContainer, + m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); emit uiLogic()->goToProtocolPage(p); } void ServerContainersLogic::onPushButtonDefaultClicked(DockerContainer c) { - if (m_settings->defaultContainer(uiLogic()->selectedServerIndex) == c) return; + if (m_settings->defaultContainer(uiLogic()->m_selectedServerIndex) == c) return; - m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, c); + m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c); uiLogic()->onUpdateAllPages(); - if (uiLogic()->selectedServerIndex != m_settings->defaultServerIndex()) return; + if (uiLogic()->m_selectedServerIndex != m_settings->defaultServerIndex()) return; if (!uiLogic()->m_vpnConnection) return; if (!uiLogic()->m_vpnConnection->isConnected()) return; @@ -61,21 +61,21 @@ void ServerContainersLogic::onPushButtonDefaultClicked(DockerContainer c) void ServerContainersLogic::onPushButtonShareClicked(DockerContainer c) { - uiLogic()->pageLogic()->updateSharingPage(uiLogic()->selectedServerIndex, c); + uiLogic()->pageLogic()->updateSharingPage(uiLogic()->m_selectedServerIndex, c); emit uiLogic()->goToPage(Page::ShareConnection); } void ServerContainersLogic::onPushButtonRemoveClicked(DockerContainer container) { //buttonSetEnabledFunc(false); - ErrorCode e = m_serverController->removeContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), container); - m_settings->removeContainerConfig(uiLogic()->selectedServerIndex, container); + ErrorCode e = m_serverController->removeContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), container); + m_settings->removeContainerConfig(uiLogic()->m_selectedServerIndex, container); //buttonSetEnabledFunc(true); - if (m_settings->defaultContainer(uiLogic()->selectedServerIndex) == container) { - const auto &c = m_settings->containers(uiLogic()->selectedServerIndex); - if (c.isEmpty()) m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, DockerContainer::None); - else m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, c.keys().first()); + if (m_settings->defaultContainer(uiLogic()->m_selectedServerIndex) == container) { + const auto &c = m_settings->containers(uiLogic()->m_selectedServerIndex); + if (c.isEmpty()) m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, DockerContainer::None); + else m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c.keys().first()); } uiLogic()->onUpdateAllPages(); } @@ -87,14 +87,21 @@ void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int p emit uiLogic()->goToPage(Page::ServerConfiguringProgress); qApp->processEvents(); - ErrorCode error = uiLogic()->pageLogic()->doInstallAction([this, c, &config](){ - return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), c, config); - }); + uiLogic()->getInstalledContainers(false); //todo its work like should be? - if (error == ErrorCode::NoError || error == ErrorCode::ServerContainerAlreadyInstalledError) { - m_settings->setContainerConfig(uiLogic()->selectedServerIndex, c, config); - if (ContainerProps::containerService(c) == ServiceType::Vpn) { - m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, c); + ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex); + + if (!uiLogic()->isContainerAlreadyAddedToGui(c, credentials)) { + auto installAction = [this, c, &config](){ + return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config); + }; + ErrorCode error = uiLogic()->pageLogic()->doInstallAction(installAction); + + if (error == ErrorCode::NoError) { + m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, c, config); + if (ContainerProps::containerService(c) == ServiceType::Vpn) { + m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c); + } } } diff --git a/client/ui/pages_logic/ServerListLogic.cpp b/client/ui/pages_logic/ServerListLogic.cpp index 42a629b3..79d13c8b 100644 --- a/client/ui/pages_logic/ServerListLogic.cpp +++ b/client/ui/pages_logic/ServerListLogic.cpp @@ -20,7 +20,7 @@ void ServerListLogic::onServerListPushbuttonDefaultClicked(int index) void ServerListLogic::onServerListPushbuttonSettingsClicked(int index) { - uiLogic()->selectedServerIndex = index; + uiLogic()->m_selectedServerIndex = index; uiLogic()->goToPage(Page::ServerSettings); } diff --git a/client/ui/pages_logic/ServerSettingsLogic.cpp b/client/ui/pages_logic/ServerSettingsLogic.cpp index 32a62e08..35a93bbb 100644 --- a/client/ui/pages_logic/ServerSettingsLogic.cpp +++ b/client/ui/pages_logic/ServerSettingsLogic.cpp @@ -27,10 +27,10 @@ void ServerSettingsLogic::onUpdatePage() { set_labelWaitInfoVisible(false); set_labelWaitInfoText(""); - set_pushButtonClearVisible(m_settings->haveAuthData(uiLogic()->selectedServerIndex)); - set_pushButtonClearClientCacheVisible(m_settings->haveAuthData(uiLogic()->selectedServerIndex)); - set_pushButtonShareFullVisible(m_settings->haveAuthData(uiLogic()->selectedServerIndex)); - const QJsonObject &server = m_settings->server(uiLogic()->selectedServerIndex); + set_pushButtonClearVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); + set_pushButtonClearClientCacheVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); + set_pushButtonShareFullVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); + const QJsonObject &server = m_settings->server(uiLogic()->m_selectedServerIndex); const QString &port = server.value(config_key::port).toString(); const QString &userName = server.value(config_key::userName).toString(); @@ -45,7 +45,7 @@ void ServerSettingsLogic::onUpdatePage() set_labelServerText(name); set_lineEditDescriptionText(server.value(config_key::description).toString()); - DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex); + DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex); QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer); set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName); } @@ -55,12 +55,12 @@ void ServerSettingsLogic::onPushButtonClearServer() set_pageEnabled(false); set_pushButtonClearText(tr("Uninstalling Amnezia software...")); - if (m_settings->defaultServerIndex() == uiLogic()->selectedServerIndex) { + if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex) { uiLogic()->pageLogic()->onDisconnect(); } - ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->selectedServerIndex)); - m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->selectedServerIndex)); + ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); + m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); if (e) { uiLogic()->set_dialogConnectErrorText( tr("Error occurred while configuring server.") + "\n" + @@ -73,8 +73,8 @@ void ServerSettingsLogic::onPushButtonClearServer() set_labelWaitInfoText(tr("Amnezia server successfully uninstalled")); } - m_settings->setContainers(uiLogic()->selectedServerIndex, {}); - m_settings->setDefaultContainer(uiLogic()->selectedServerIndex, DockerContainer::None); + m_settings->setContainers(uiLogic()->m_selectedServerIndex, {}); + m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, DockerContainer::None); set_pageEnabled(true); set_pushButtonClearText(tr("Clear server from Amnezia software")); @@ -82,15 +82,15 @@ void ServerSettingsLogic::onPushButtonClearServer() void ServerSettingsLogic::onPushButtonForgetServer() { - if (m_settings->defaultServerIndex() == uiLogic()->selectedServerIndex && uiLogic()->m_vpnConnection->isConnected()) { + if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex && uiLogic()->m_vpnConnection->isConnected()) { uiLogic()->pageLogic()->onDisconnect(); } - m_settings->removeServer(uiLogic()->selectedServerIndex); + m_settings->removeServer(uiLogic()->m_selectedServerIndex); - if (m_settings->defaultServerIndex() == uiLogic()->selectedServerIndex) { + if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex) { m_settings->setDefaultServer(0); } - else if (m_settings->defaultServerIndex() > uiLogic()->selectedServerIndex) { + else if (m_settings->defaultServerIndex() > uiLogic()->m_selectedServerIndex) { m_settings->setDefaultServer(m_settings->defaultServerIndex() - 1); } @@ -99,7 +99,7 @@ void ServerSettingsLogic::onPushButtonForgetServer() } - uiLogic()->selectedServerIndex = -1; + uiLogic()->m_selectedServerIndex = -1; uiLogic()->onUpdateAllPages(); if (m_settings->serversCount() == 0) { @@ -114,9 +114,9 @@ void ServerSettingsLogic::onPushButtonClearClientCacheClicked() { set_pushButtonClearClientCacheText(tr("Cache cleared")); - const auto &containers = m_settings->containers(uiLogic()->selectedServerIndex); - for (DockerContainer container: containers.keys()) { - m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, container); + const auto &containers = m_settings->containers(uiLogic()->m_selectedServerIndex); + for (DockerContainer container : containers.keys()) { + m_settings->clearLastConnectionConfig(uiLogic()->m_selectedServerIndex, container); } QTimer::singleShot(3000, this, [this]() { @@ -127,9 +127,9 @@ void ServerSettingsLogic::onPushButtonClearClientCacheClicked() void ServerSettingsLogic::onLineEditDescriptionEditingFinished() { const QString &newText = lineEditDescriptionText(); - QJsonObject server = m_settings->server(uiLogic()->selectedServerIndex); + QJsonObject server = m_settings->server(uiLogic()->m_selectedServerIndex); server.insert(config_key::description, newText); - m_settings->editServer(uiLogic()->selectedServerIndex, server); + m_settings->editServer(uiLogic()->m_selectedServerIndex, server); uiLogic()->onUpdateAllPages(); } @@ -168,7 +168,7 @@ void ServerSettingsLogic::onPushButtonShareFullClicked() } } #else - uiLogic()->pageLogic()->updateSharingPage(uiLogic()->selectedServerIndex, DockerContainer::None); + uiLogic()->pageLogic()->updateSharingPage(uiLogic()->m_selectedServerIndex, DockerContainer::None); emit uiLogic()->goToShareProtocolPage(Proto::Any); #endif } diff --git a/client/ui/pages_logic/ShareConnectionLogic.cpp b/client/ui/pages_logic/ShareConnectionLogic.cpp index 85849391..26563359 100644 --- a/client/ui/pages_logic/ShareConnectionLogic.cpp +++ b/client/ui/pages_logic/ShareConnectionLogic.cpp @@ -68,8 +68,8 @@ void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked() set_shareAmneziaQrCodeTextSeriesLength(0); QJsonObject serverConfig; - int serverIndex = uiLogic()->selectedServerIndex; - DockerContainer container = uiLogic()->selectedDockerContainer; + int serverIndex = uiLogic()->m_selectedServerIndex; + DockerContainer container = uiLogic()->m_selectedDockerContainer; // Full access if (shareFullAccess()) { @@ -127,8 +127,8 @@ void ShareConnectionLogic::onPushButtonShareAmneziaGenerateClicked() void ShareConnectionLogic::onPushButtonShareOpenVpnGenerateClicked() { - int serverIndex = uiLogic()->selectedServerIndex; - DockerContainer container = uiLogic()->selectedDockerContainer; + int serverIndex = uiLogic()->m_selectedServerIndex; + DockerContainer container = uiLogic()->m_selectedDockerContainer; ServerCredentials credentials = m_settings->serverCredentials(serverIndex); const QJsonObject &containerConfig = m_settings->containerConfig(serverIndex, container); @@ -142,8 +142,8 @@ void ShareConnectionLogic::onPushButtonShareOpenVpnGenerateClicked() void ShareConnectionLogic::onPushButtonShareShadowSocksGenerateClicked() { - int serverIndex = uiLogic()->selectedServerIndex; - DockerContainer container = uiLogic()->selectedDockerContainer; + int serverIndex = uiLogic()->m_selectedServerIndex; + DockerContainer container = uiLogic()->m_selectedDockerContainer; ServerCredentials credentials = m_settings->serverCredentials(serverIndex); QJsonObject protoConfig = m_settings->protocolConfig(serverIndex, container, Proto::ShadowSocks); @@ -186,8 +186,8 @@ void ShareConnectionLogic::onPushButtonShareShadowSocksGenerateClicked() void ShareConnectionLogic::onPushButtonShareCloakGenerateClicked() { - int serverIndex = uiLogic()->selectedServerIndex; - DockerContainer container = uiLogic()->selectedDockerContainer; + int serverIndex = uiLogic()->m_selectedServerIndex; + DockerContainer container = uiLogic()->m_selectedDockerContainer; ServerCredentials credentials = m_settings->serverCredentials(serverIndex); QJsonObject protoConfig = m_settings->protocolConfig(serverIndex, container, Proto::Cloak); @@ -209,8 +209,8 @@ void ShareConnectionLogic::onPushButtonShareCloakGenerateClicked() void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked() { - int serverIndex = uiLogic()->selectedServerIndex; - DockerContainer container = uiLogic()->selectedDockerContainer; + int serverIndex = uiLogic()->m_selectedServerIndex; + DockerContainer container = uiLogic()->m_selectedDockerContainer; ServerCredentials credentials = m_settings->serverCredentials(serverIndex); const QJsonObject &containerConfig = m_settings->containerConfig(serverIndex, container); @@ -236,8 +236,8 @@ void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked() void ShareConnectionLogic::onPushButtonShareIkev2GenerateClicked() { - int serverIndex = uiLogic()->selectedServerIndex; - DockerContainer container = uiLogic()->selectedDockerContainer; + int serverIndex = uiLogic()->m_selectedServerIndex; + DockerContainer container = uiLogic()->m_selectedDockerContainer; ServerCredentials credentials = m_settings->serverCredentials(serverIndex); Ikev2Configurator::ConnectionData connData = m_configurator->ikev2Configurator->prepareIkev2Config(credentials, container); @@ -259,8 +259,8 @@ void ShareConnectionLogic::onPushButtonShareIkev2GenerateClicked() void ShareConnectionLogic::updateSharingPage(int serverIndex, DockerContainer container) { - uiLogic()->selectedDockerContainer = container; - uiLogic()->selectedServerIndex = serverIndex; + uiLogic()->m_selectedDockerContainer = container; + uiLogic()->m_selectedServerIndex = serverIndex; set_shareFullAccess(container == DockerContainer::None); m_shareAmneziaQrCodeTextSeries.clear(); diff --git a/client/ui/pages_logic/StartPageLogic.cpp b/client/ui/pages_logic/StartPageLogic.cpp index 3c15199d..f2a3fae8 100644 --- a/client/ui/pages_logic/StartPageLogic.cpp +++ b/client/ui/pages_logic/StartPageLogic.cpp @@ -155,7 +155,7 @@ void StartPageLogic::onPushButtonConnect() set_pushButtonConnectEnabled(true); set_pushButtonConnectText(tr("Connect")); - uiLogic()->installCredentials = serverCredentials; + uiLogic()->m_installCredentials = serverCredentials; if (ok) emit uiLogic()->goToPage(Page::NewServer); } diff --git a/client/ui/pages_logic/ViewConfigLogic.cpp b/client/ui/pages_logic/ViewConfigLogic.cpp index 9ccd9d3e..5f711498 100644 --- a/client/ui/pages_logic/ViewConfigLogic.cpp +++ b/client/ui/pages_logic/ViewConfigLogic.cpp @@ -79,8 +79,8 @@ void ViewConfigLogic::importConfig() if (!configJson().contains(config_key::containers) || configJson().value(config_key::containers).toArray().isEmpty()) { - uiLogic()->selectedServerIndex = m_settings->defaultServerIndex(); - uiLogic()->selectedDockerContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex); + uiLogic()->m_selectedServerIndex = m_settings->defaultServerIndex(); + uiLogic()->m_selectedDockerContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex); uiLogic()->onUpdateAllPages(); emit uiLogic()->goToPage(Page::Vpn); emit uiLogic()->setStartPage(Page::Vpn); diff --git a/client/ui/pages_logic/protocols/CloakLogic.cpp b/client/ui/pages_logic/protocols/CloakLogic.cpp index 6e179013..d62f8624 100644 --- a/client/ui/pages_logic/protocols/CloakLogic.cpp +++ b/client/ui/pages_logic/protocols/CloakLogic.cpp @@ -55,10 +55,10 @@ QJsonObject CloakLogic::getProtocolConfigFromPage(QJsonObject oldConfig) void CloakLogic::onPushButtonSaveClicked() { - QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, Proto::Cloak); + QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, Proto::Cloak); protocolConfig = getProtocolConfigFromPage(protocolConfig); - QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer); + QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer); QJsonObject newContainerConfig = containerConfig; newContainerConfig.insert(ProtocolProps::protoToString(Proto::Cloak), protocolConfig); @@ -113,8 +113,8 @@ void CloakLogic::onPushButtonSaveClicked() progressBarFunc.setTextVisibleFunc(true); progressBarFunc.setTextFunc(QString("Configuring...")); ErrorCode e = uiLogic()->pageLogic()->doInstallAction([this, containerConfig, &newContainerConfig](){ - return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), - uiLogic()->selectedDockerContainer, + return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), + uiLogic()->m_selectedDockerContainer, containerConfig, newContainerConfig); }, @@ -123,11 +123,11 @@ void CloakLogic::onPushButtonSaveClicked() busyInfoFuncy, cancelButtonFunc); if (!e) { - m_settings->setContainerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, newContainerConfig); - m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer); + m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig); + m_settings->clearLastConnectionConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer); } - qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->selectedServerIndex << uiLogic()->selectedDockerContainer; + qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->m_selectedServerIndex << uiLogic()->m_selectedDockerContainer; } void CloakLogic::onPushButtonCancelClicked() diff --git a/client/ui/pages_logic/protocols/OpenVpnLogic.cpp b/client/ui/pages_logic/protocols/OpenVpnLogic.cpp index 7ed71962..d5deecf3 100644 --- a/client/ui/pages_logic/protocols/OpenVpnLogic.cpp +++ b/client/ui/pages_logic/protocols/OpenVpnLogic.cpp @@ -105,10 +105,10 @@ void OpenVpnLogic::updateProtocolPage(const QJsonObject &openvpnConfig, DockerCo void OpenVpnLogic::onPushButtonSaveClicked() { - QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, Proto::OpenVpn); + QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, Proto::OpenVpn); protocolConfig = getProtocolConfigFromPage(protocolConfig); - QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer); + QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer); QJsonObject newContainerConfig = containerConfig; newContainerConfig.insert(ProtocolProps::protoToString(Proto::OpenVpn), protocolConfig); @@ -163,8 +163,8 @@ void OpenVpnLogic::onPushButtonSaveClicked() progressBarFunc.setTextVisibleFunc(true); progressBarFunc.setTextFunc(QString("Configuring...")); ErrorCode e = uiLogic()->pageLogic()->doInstallAction([this, containerConfig, &newContainerConfig](){ - return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), - uiLogic()->selectedDockerContainer, + return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), + uiLogic()->m_selectedDockerContainer, containerConfig, newContainerConfig); }, @@ -173,10 +173,10 @@ void OpenVpnLogic::onPushButtonSaveClicked() busyInfoFuncy, cancelButtonFunc); if (!e) { - m_settings->setContainerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, newContainerConfig); - m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer); + m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig); + m_settings->clearLastConnectionConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer); } - qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->selectedServerIndex << uiLogic()->selectedDockerContainer; + qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->m_selectedServerIndex << uiLogic()->m_selectedDockerContainer; } QJsonObject OpenVpnLogic::getProtocolConfigFromPage(QJsonObject oldConfig) diff --git a/client/ui/pages_logic/protocols/OtherProtocolsLogic.cpp b/client/ui/pages_logic/protocols/OtherProtocolsLogic.cpp index 8bd9d105..965a3baf 100644 --- a/client/ui/pages_logic/protocols/OtherProtocolsLogic.cpp +++ b/client/ui/pages_logic/protocols/OtherProtocolsLogic.cpp @@ -81,7 +81,7 @@ void OtherProtocolsLogic::onPushButtonSftpMountDriveClicked() { QString mountPath; QString cmd; - QString host = m_settings->serverCredentials(uiLogic()->selectedServerIndex).hostName; + QString host = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex).hostName; #ifdef Q_OS_WINDOWS diff --git a/client/ui/pages_logic/protocols/ShadowSocksLogic.cpp b/client/ui/pages_logic/protocols/ShadowSocksLogic.cpp index 94a8ee04..5259a6e0 100644 --- a/client/ui/pages_logic/protocols/ShadowSocksLogic.cpp +++ b/client/ui/pages_logic/protocols/ShadowSocksLogic.cpp @@ -49,9 +49,9 @@ QJsonObject ShadowSocksLogic::getProtocolConfigFromPage(QJsonObject oldConfig) void ShadowSocksLogic::onPushButtonSaveClicked() { - QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, Proto::ShadowSocks); + QJsonObject protocolConfig = m_settings->protocolConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, Proto::ShadowSocks); - QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer); + QJsonObject containerConfig = m_settings->containerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer); QJsonObject newContainerConfig = containerConfig; newContainerConfig.insert(ProtocolProps::protoToString(Proto::ShadowSocks), protocolConfig); ServerConfiguringProgressLogic::PageFunc pageFunc; @@ -105,8 +105,8 @@ void ShadowSocksLogic::onPushButtonSaveClicked() progressBarFunc.setTextVisibleFunc(true); progressBarFunc.setTextFunc(QString("Configuring...")); ErrorCode e = uiLogic()->pageLogic()->doInstallAction([this, containerConfig, &newContainerConfig](){ - return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->selectedServerIndex), - uiLogic()->selectedDockerContainer, + return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), + uiLogic()->m_selectedDockerContainer, containerConfig, newContainerConfig); }, @@ -115,10 +115,10 @@ void ShadowSocksLogic::onPushButtonSaveClicked() busyInfoFuncy, cancelButtonFunc); if (!e) { - m_settings->setContainerConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer, newContainerConfig); - m_settings->clearLastConnectionConfig(uiLogic()->selectedServerIndex, uiLogic()->selectedDockerContainer); + m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig); + m_settings->clearLastConnectionConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer); } - qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->selectedServerIndex << uiLogic()->selectedDockerContainer; + qDebug() << "Protocol saved with code:" << e << "for" << uiLogic()->m_selectedServerIndex << uiLogic()->m_selectedDockerContainer; } void ShadowSocksLogic::onPushButtonCancelClicked() diff --git a/client/ui/qml/Controls/PopupWarning.qml b/client/ui/qml/Controls/PopupWarning.qml new file mode 100644 index 00000000..57c332eb --- /dev/null +++ b/client/ui/qml/Controls/PopupWarning.qml @@ -0,0 +1,34 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts + +Popup { + id: root + + property string popupWarningText + + anchors.centerIn: Overlay.overlay + modal: true + closePolicy: Popup.NoAutoClose + width: parent.width - 20 + + ColumnLayout { + width: parent.width + Text { + horizontalAlignment: Text.AlignHCenter + Layout.fillWidth: true + wrapMode: Text.WordWrap + font.pixelSize: 16 + text: root.popupWarningText + } + + BlueButtonType { + Layout.preferredWidth: parent.width / 2 + Layout.fillWidth: true + text: "Continue" + onClicked: { + root.close() + } + } + } +} diff --git a/client/ui/qml/Pages/PageAdvancedServerSettings.qml b/client/ui/qml/Pages/PageAdvancedServerSettings.qml new file mode 100644 index 00000000..a0d2a3f6 --- /dev/null +++ b/client/ui/qml/Pages/PageAdvancedServerSettings.qml @@ -0,0 +1,100 @@ +import QtQuick +import QtQuick.Controls +import QtQuick.Layouts +import PageEnum 1.0 +import "./" +import "../Controls" +import "../Config" + +PageBase { + id: root + page: PageEnum.AdvancedServerSettings + logic: AdvancedServerSettingsLogic + + enabled: AdvancedServerSettingsLogic.pageEnabled + + BackButton { + id: back + } + Caption { + id: caption + text: qsTr("Advanced server settings") + anchors.horizontalCenter: parent.horizontalCenter + } + + FlickableType { + id: fl + anchors.top: caption.bottom + anchors.bottom: logo.top + contentHeight: content.height + + ColumnLayout { + id: content + enabled: logic.pageEnabled + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.rightMargin: 15 + + LabelType { + Layout.fillWidth: true + font.pixelSize: 20 + horizontalAlignment: Text.AlignHCenter + text: AdvancedServerSettingsLogic.labelCurrentVpnProtocolText + } + + TextFieldType { + Layout.fillWidth: true + font.pixelSize: 20 + horizontalAlignment: Text.AlignHCenter + text: AdvancedServerSettingsLogic.labelServerText + readOnly: true + background: Item {} + } + + LabelType { + Layout.fillWidth: true + text: AdvancedServerSettingsLogic.labelWaitInfoText + visible: AdvancedServerSettingsLogic.labelWaitInfoVisible + } + + BlueButtonType { + Layout.fillWidth: true + Layout.topMargin: 10 + text: "Scan the server for installed containers" + visible: AdvancedServerSettingsLogic.pushButtonClearVisible + onClicked: { + UiLogic.getInstalledContainers(false) + } + } + + BlueButtonType { + Layout.fillWidth: true + Layout.topMargin: 10 + text: AdvancedServerSettingsLogic.pushButtonClearText + visible: AdvancedServerSettingsLogic.pushButtonClearVisible + onClicked: { + popupClearServer.open() + } + } + + PopupWithQuestion { + id: popupClearServer + questionText: "Attention! All containers will be deleted on the server. This means that configuration files, keys and certificates will be deleted. Continue?" + yesFunc: function() { + AdvancedServerSettingsLogic.onPushButtonClearServer() + close() + } + noFunc: function() { + close() + } + } + } + } + + + Logo { + id : logo + anchors.bottom: parent.bottom + } +} diff --git a/client/ui/qml/Pages/PageServerSettings.qml b/client/ui/qml/Pages/PageServerSettings.qml index 85bc07e3..7a21bfd2 100644 --- a/client/ui/qml/Pages/PageServerSettings.qml +++ b/client/ui/qml/Pages/PageServerSettings.qml @@ -74,6 +74,7 @@ PageBase { UiLogic.goToPage(PageEnum.ServerContainers) } } + BlueButtonType { Layout.fillWidth: true Layout.topMargin: 10 @@ -86,33 +87,21 @@ PageBase { BlueButtonType { Layout.fillWidth: true - Layout.topMargin: 60 - text: ServerSettingsLogic.pushButtonClearClientCacheText - visible: ServerSettingsLogic.pushButtonClearClientCacheVisible + Layout.topMargin: 10 + text: qsTr("Advanced server settings") + visible: ServerSettingsLogic.pushButtonShareFullVisible //todo onClicked: { - ServerSettingsLogic.onPushButtonClearClientCacheClicked() + UiLogic.goToPage(PageEnum.AdvancedServerSettings) } } BlueButtonType { Layout.fillWidth: true - Layout.topMargin: 10 - text: ServerSettingsLogic.pushButtonClearText - visible: ServerSettingsLogic.pushButtonClearVisible - onClicked: { - popupClearServer.open() - } - } - - PopupWithQuestion { - id: popupClearServer - questionText: "Attention! All containers will be deleted on the server. This means that configuration files, keys and certificates will be deleted. Continue?" - yesFunc: function() { - ServerSettingsLogic.onPushButtonClearServer() - close() - } - noFunc: function() { - close() + Layout.topMargin: 60 + text: ServerSettingsLogic.pushButtonClearClientCacheText + visible: ServerSettingsLogic.pushButtonClearClientCacheVisible + onClicked: { + ServerSettingsLogic.onPushButtonClearClientCacheClicked() } } diff --git a/client/ui/qml/main.qml b/client/ui/qml/main.qml index 10552c11..6e2c7911 100644 --- a/client/ui/qml/main.qml +++ b/client/ui/qml/main.qml @@ -230,6 +230,10 @@ Window { function onToggleLogPanel() { drawer_log.visible = !drawer_log.visible } + function onShowWarningMessage(message) { + popupWarning.popupWarningText = message + popupWarning.open() + } } MessageDialog { @@ -353,4 +357,8 @@ Window { } } } + + PopupWarning { + id: popupWarning + } } diff --git a/client/ui/uilogic.cpp b/client/ui/uilogic.cpp index 5328fc3b..1646b256 100644 --- a/client/ui/uilogic.cpp +++ b/client/ui/uilogic.cpp @@ -67,6 +67,7 @@ #include "pages_logic/ViewConfigLogic.h" #include "pages_logic/VpnLogic.h" #include "pages_logic/WizardLogic.h" +#include "pages_logic/AdvancedServerSettingsLogic.h" #include "pages_logic/protocols/CloakLogic.h" #include "pages_logic/protocols/OpenVpnLogic.h" @@ -157,7 +158,7 @@ void UiLogic::initalizeUiLogic() emit goToPage(Page::Start, true, false); } - selectedServerIndex = m_settings->defaultServerIndex(); + m_selectedServerIndex = m_settings->defaultServerIndex(); qInfo().noquote() << QString("Started %1 version %2").arg(APPLICATION_NAME).arg(APP_VERSION); qInfo().noquote() << QString("%1 (%2)").arg(QSysInfo::prettyProductName()).arg(QSysInfo::currentCpuArchitecture()); @@ -199,8 +200,8 @@ void UiLogic::keyPressEvent(Qt::Key key) qApp->quit(); break; case Qt::Key_H: - selectedServerIndex = m_settings->defaultServerIndex(); - selectedDockerContainer = m_settings->defaultContainer(selectedServerIndex); + m_selectedServerIndex = m_settings->defaultServerIndex(); + m_selectedDockerContainer = m_settings->defaultContainer(m_selectedServerIndex); //updateSharingPage(selectedServerIndex, m_settings->serverCredentials(selectedServerIndex), selectedDockerContainer); emit goToPage(Page::ShareConnection); @@ -214,7 +215,7 @@ void UiLogic::keyPressEvent(Qt::Key key) emit goToPage(Page::Start); break; case Qt::Key_S: - selectedServerIndex = m_settings->defaultServerIndex(); + m_selectedServerIndex = m_settings->defaultServerIndex(); emit goToPage(Page::ServerSettings); break; case Qt::Key_P: @@ -262,8 +263,8 @@ QString UiLogic::containerDesc(int container) void UiLogic::onGotoCurrentProtocolsPage() { - selectedServerIndex = m_settings->defaultServerIndex(); - selectedDockerContainer = m_settings->defaultContainer(selectedServerIndex); + m_selectedServerIndex = m_settings->defaultServerIndex(); + m_selectedDockerContainer = m_settings->defaultContainer(m_selectedServerIndex); emit goToPage(Page::ServerContainers); } @@ -325,24 +326,44 @@ void UiLogic::installServer(QMap &containers) pageLogic()->set_pushButtonCancelVisible(visible); }; - int count = 0; - ErrorCode error; - for (QMap::iterator i = containers.begin(); i != containers.end(); i++, count++) { - progressBarFunc.setTextFunc(QString("Installing %1 %2 %3").arg(count+1).arg(tr("of")).arg(containers.size())); - - error = pageLogic()->doInstallAction([&] () { - return m_serverController->setupContainer(installCredentials, i.key(), i.value()); - }, pageFunc, progressBarFunc, noButton, waitInfoFunc, busyInfoFunc, cancelButtonFunc); - - m_serverController->disconnectFromHost(installCredentials); + ErrorCode error = getInstalledContainers(true); + if (error != ErrorCode::NoError) { + return; } - if (error == ErrorCode::NoError || error == ErrorCode::ServerContainerAlreadyInstalledError) { + int count = 0; + bool isSomethingInstalled = false; + for (QMap::iterator i = containers.begin(); i != containers.end(); i++, count++) { + if (isContainerAlreadyAddedToGui(i.key(), m_installCredentials)) { + continue; + } + + isSomethingInstalled = true; + + progressBarFunc.setTextFunc(QString("Installing %1 %2 %3").arg(count + 1).arg(tr("of")).arg(containers.size())); + auto installAction = [&] () { + return m_serverController->setupContainer(m_installCredentials, i.key(), i.value()); + }; + error = pageLogic()->doInstallAction(installAction, pageFunc, progressBarFunc, + noButton, waitInfoFunc, + busyInfoFunc, cancelButtonFunc); + + m_serverController->disconnectFromHost(m_installCredentials); + } + + if (error == ErrorCode::NoError) { + if (!isSomethingInstalled) { + emit showWarningMessage("Attention! The container you are trying to install is already installed on the server. " + "All installed containers have been added to the application "); + emit setStartPage(Page::Vpn); + return; + } + QJsonObject server; - server.insert(config_key::hostName, installCredentials.hostName); - server.insert(config_key::userName, installCredentials.userName); - server.insert(config_key::password, installCredentials.password); - server.insert(config_key::port, installCredentials.port); + server.insert(config_key::hostName, m_installCredentials.hostName); + server.insert(config_key::userName, m_installCredentials.userName); + server.insert(config_key::password, m_installCredentials.password); + server.insert(config_key::port, m_installCredentials.port); server.insert(config_key::description, m_settings->nextAvailableServerName()); QJsonArray containerConfigs; @@ -358,8 +379,7 @@ void UiLogic::installServer(QMap &containers) emit setStartPage(Page::Vpn); qApp->processEvents(); - } - else { + } else { emit closePage(); } } @@ -497,4 +517,61 @@ void UiLogic::registerPagesLogic() registerPageLogic(); registerPageLogic(); registerPageLogic(); + registerPageLogic(); +} + +ErrorCode UiLogic::getInstalledContainers(bool addNewServerToGui) +{ + QMap installedContainers; + ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(m_installCredentials, installedContainers); + if (errorCode != ErrorCode::NoError) { + return errorCode; + } + + QJsonObject server; + QJsonArray containerConfigs; + if (addNewServerToGui) { + server.insert(config_key::hostName, m_installCredentials.hostName); + server.insert(config_key::userName, m_installCredentials.userName); + server.insert(config_key::password, m_installCredentials.password); + server.insert(config_key::port, m_installCredentials.port); + server.insert(config_key::description, m_settings->nextAvailableServerName()); + } + + for (auto container = installedContainers.begin(); container != installedContainers.end(); container++) { + if (isContainerAlreadyAddedToGui(container.key(), m_installCredentials)) { + continue; + } + + if (addNewServerToGui) { + containerConfigs.append(container.value()); + server.insert(config_key::containers, containerConfigs); + + } else { + m_settings->setContainerConfig(m_selectedServerIndex, container.key(), container.value()); + } + } + + if (addNewServerToGui) { + server.insert(config_key::defaultContainer, ContainerProps::containerToString(installedContainers.firstKey())); + m_settings->addServer(server); + m_settings->setDefaultServer(m_settings->serversCount() - 1); + } + + onUpdateAllPages(); + return ErrorCode::NoError; +} + +bool UiLogic::isContainerAlreadyAddedToGui(DockerContainer container, const ServerCredentials &selectedServerCredentials) +{ + for (int i = 0; i < m_settings->serversCount(); i++) { + const ServerCredentials credentials = m_settings->serverCredentials(i); + if (selectedServerCredentials.hostName == credentials.hostName && selectedServerCredentials.port == credentials.port) { + const QJsonObject containerConfig = m_settings->containerConfig(i, container); + if (!containerConfig.isEmpty()) { + return true; + } + } + } + return false; } diff --git a/client/ui/uilogic.h b/client/ui/uilogic.h index 4cc006dd..bc72223c 100644 --- a/client/ui/uilogic.h +++ b/client/ui/uilogic.h @@ -42,6 +42,7 @@ class StartPageLogic; class ViewConfigLogic; class VpnLogic; class WizardLogic; +class AdvancedServerSettingsLogic; class PageProtocolLogicBase; class OpenVpnLogic; @@ -61,6 +62,7 @@ class UiLogic : public QObject AUTO_PROPERTY(int, pagesStackDepth) AUTO_PROPERTY(int, currentPageValue) AUTO_PROPERTY(QString, dialogConnectErrorText) + AUTO_PROPERTY(QString, popupWarningText) READONLY_PROPERTY(QObject *, containersModel) READONLY_PROPERTY(QObject *, protocolsModel) @@ -87,6 +89,7 @@ public: friend class ViewConfigLogic; friend class VpnLogic; friend class WizardLogic; + friend class AdvancedServerSettingsLogic; friend class PageProtocolLogicBase; friend class OpenVpnLogic; @@ -112,11 +115,11 @@ public: Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data); Q_INVOKABLE void copyToClipboard(const QString& text); + Q_INVOKABLE amnezia::ErrorCode getInstalledContainers(bool addNewServerToGui); + void shareTempFile(const QString &suggestedName, QString ext, const QString& data); signals: - void dialogConnectErrorTextChanged(); - void goToPage(PageEnumNS::Page page, bool reset = true, bool slide = true); void goToProtocolPage(Proto protocol, bool reset = true, bool slide = true); void goToShareProtocolPage(Proto protocol, bool reset = true, bool slide = true); @@ -129,6 +132,7 @@ signals: void hide(); void raise(); void toggleLogPanel(); + void showWarningMessage(QString message); private slots: // containers - INOUT arg @@ -136,6 +140,7 @@ private slots: private: PageEnumNS::Page currentPage(); + bool isContainerAlreadyAddedToGui(DockerContainer container, const ServerCredentials &selectedServerCredentials); public: Q_INVOKABLE PageProtocolLogicBase *protocolLogic(Proto p); @@ -178,8 +183,8 @@ private: NotificationHandler* m_notificationHandler; - int selectedServerIndex = -1; // server index to use when proto settings page opened - DockerContainer selectedDockerContainer; // same - ServerCredentials installCredentials; // used to save cred between pages new_server and new_server_protocols and wizard + int m_selectedServerIndex = -1; // server index to use when proto settings page opened + DockerContainer m_selectedDockerContainer; // same + ServerCredentials m_installCredentials; // used to save cred between pages new_server and new_server_protocols and wizard }; #endif // UILOGIC_H From 480b2181f084427962b68678d9dfa320c4e40ef2 Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Wed, 22 Feb 2023 10:01:43 +0300 Subject: [PATCH 04/12] made error output in the same style - some code style refactoring --- .../AdvancedServerSettingsLogic.cpp | 6 +- client/ui/pages_logic/AppSettingsLogic.cpp | 7 +- .../ServerConfiguringProgressLogic.cpp | 4 - .../ui/pages_logic/ServerContainersLogic.cpp | 36 ++++-- client/ui/pages_logic/ServerSettingsLogic.cpp | 33 ----- client/ui/pages_logic/ServerSettingsLogic.h | 3 - .../ui/pages_logic/ShareConnectionLogic.cpp | 7 +- client/ui/pages_logic/ShareConnectionLogic.h | 1 - .../qml/Pages/PageAdvancedServerSettings.qml | 1 - client/ui/qml/Pages/PageServerSettings.qml | 1 - client/ui/qml/main.qml | 6 - client/ui/uilogic.cpp | 119 +++++++++--------- client/ui/uilogic.h | 3 +- 13 files changed, 92 insertions(+), 135 deletions(-) diff --git a/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp b/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp index 0a7ae2c0..832fc6fd 100644 --- a/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp +++ b/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp @@ -47,9 +47,9 @@ void AdvancedServerSettingsLogic::onPushButtonClearServer() ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); if (e) { - uiLogic()->set_dialogConnectErrorText(tr("Error occurred while configuring server.") + "\n" + - errorString(e) + "\n" + tr("See logs for details.")); - emit uiLogic()->showConnectErrorDialog(); + emit uiLogic()->showWarningMessage(tr("Error occurred while configuring server.") + "\n" + + tr("Error message: ") + errorString(e) + "\n" + + tr("See logs for details.")); } else { set_labelWaitInfoVisible(true); set_labelWaitInfoText(tr("Amnezia server successfully uninstalled")); diff --git a/client/ui/pages_logic/AppSettingsLogic.cpp b/client/ui/pages_logic/AppSettingsLogic.cpp index 3590c480..e5358009 100644 --- a/client/ui/pages_logic/AppSettingsLogic.cpp +++ b/client/ui/pages_logic/AppSettingsLogic.cpp @@ -7,7 +7,6 @@ #include #include -#include #include using namespace amnezia; @@ -96,10 +95,8 @@ void AppSettingsLogic::onPushButtonRestoreAppConfigClicked() if (ok) { emit uiLogic()->goToPage(Page::Vpn); emit uiLogic()->setStartPage(Page::Vpn); - } - else { - QMessageBox::warning(nullptr, APPLICATION_NAME, - tr("Can't import config, file is corrupted.")); + } else { + emit uiLogic()->showWarningMessage(tr("Can't import config, file is corrupted.")); } } diff --git a/client/ui/pages_logic/ServerConfiguringProgressLogic.cpp b/client/ui/pages_logic/ServerConfiguringProgressLogic.cpp index c6e7085b..f6a8abdb 100644 --- a/client/ui/pages_logic/ServerConfiguringProgressLogic.cpp +++ b/client/ui/pages_logic/ServerConfiguringProgressLogic.cpp @@ -3,7 +3,6 @@ #include "core/errorstrings.h" #include #include -#include #include "core/servercontroller.h" @@ -142,9 +141,6 @@ ErrorCode ServerConfiguringProgressLogic::doInstallAction(const std::functiongoToPage(Page::ServerConfiguringProgress); qApp->processEvents(); - uiLogic()->getInstalledContainers(false); //todo its work like should be? - ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex); + ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, credentials); - if (!uiLogic()->isContainerAlreadyAddedToGui(c, credentials)) { - auto installAction = [this, c, &config](){ - return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config); - }; - ErrorCode error = uiLogic()->pageLogic()->doInstallAction(installAction); + if (errorCode == ErrorCode::NoError) { + if (!uiLogic()->isContainerAlreadyAddedToGui(c, credentials)) { + auto installAction = [this, c, &config]() { + return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config); + }; + errorCode = uiLogic()->pageLogic()->doInstallAction(installAction); - if (error == ErrorCode::NoError) { - m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, c, config); - if (ContainerProps::containerService(c) == ServiceType::Vpn) { - m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c); + if (errorCode == ErrorCode::NoError) { + m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, c, config); + if (ContainerProps::containerService(c) == ServiceType::Vpn) { + m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, c); + } } + } else { + emit uiLogic()->showWarningMessage("Attention! The container you are trying to install is already installed on the server. " + "All installed containers have been added to the application "); } - } - uiLogic()->onUpdateAllPages(); + uiLogic()->onUpdateAllPages(); + } + if (errorCode != ErrorCode::NoError) { + emit uiLogic()->showWarningMessage(tr("Error occurred while configuring server.") + "\n" + + tr("Error message: ") + errorString(errorCode) + "\n" + + tr("See logs for details.")); + } emit uiLogic()->closePage(); } diff --git a/client/ui/pages_logic/ServerSettingsLogic.cpp b/client/ui/pages_logic/ServerSettingsLogic.cpp index 35a93bbb..858a77d1 100644 --- a/client/ui/pages_logic/ServerSettingsLogic.cpp +++ b/client/ui/pages_logic/ServerSettingsLogic.cpp @@ -16,10 +16,8 @@ ServerSettingsLogic::ServerSettingsLogic(UiLogic *logic, QObject *parent): PageLogicBase(logic, parent), m_labelWaitInfoVisible{true}, - m_pushButtonClearVisible{true}, m_pushButtonClearClientCacheVisible{true}, m_pushButtonShareFullVisible{true}, - m_pushButtonClearText{tr("Clear server from Amnezia software")}, m_pushButtonClearClientCacheText{tr("Clear client cached profile")} { } @@ -27,7 +25,6 @@ void ServerSettingsLogic::onUpdatePage() { set_labelWaitInfoVisible(false); set_labelWaitInfoText(""); - set_pushButtonClearVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); set_pushButtonClearClientCacheVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); set_pushButtonShareFullVisible(m_settings->haveAuthData(uiLogic()->m_selectedServerIndex)); const QJsonObject &server = m_settings->server(uiLogic()->m_selectedServerIndex); @@ -50,36 +47,6 @@ void ServerSettingsLogic::onUpdatePage() set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName); } -void ServerSettingsLogic::onPushButtonClearServer() -{ - set_pageEnabled(false); - set_pushButtonClearText(tr("Uninstalling Amnezia software...")); - - if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex) { - uiLogic()->pageLogic()->onDisconnect(); - } - - ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); - m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); - if (e) { - uiLogic()->set_dialogConnectErrorText( - tr("Error occurred while configuring server.") + "\n" + - errorString(e) + "\n" + - tr("See logs for details.")); - emit uiLogic()->showConnectErrorDialog(); - } - else { - set_labelWaitInfoVisible(true); - set_labelWaitInfoText(tr("Amnezia server successfully uninstalled")); - } - - m_settings->setContainers(uiLogic()->m_selectedServerIndex, {}); - m_settings->setDefaultContainer(uiLogic()->m_selectedServerIndex, DockerContainer::None); - - set_pageEnabled(true); - set_pushButtonClearText(tr("Clear server from Amnezia software")); -} - void ServerSettingsLogic::onPushButtonForgetServer() { if (m_settings->defaultServerIndex() == uiLogic()->m_selectedServerIndex && uiLogic()->m_vpnConnection->isConnected()) { diff --git a/client/ui/pages_logic/ServerSettingsLogic.h b/client/ui/pages_logic/ServerSettingsLogic.h index d561ec48..a75dfa47 100644 --- a/client/ui/pages_logic/ServerSettingsLogic.h +++ b/client/ui/pages_logic/ServerSettingsLogic.h @@ -16,9 +16,7 @@ class ServerSettingsLogic : public PageLogicBase AUTO_PROPERTY(bool, labelWaitInfoVisible) AUTO_PROPERTY(QString, labelWaitInfoText) - AUTO_PROPERTY(QString, pushButtonClearText) AUTO_PROPERTY(QString, pushButtonClearClientCacheText) - AUTO_PROPERTY(bool, pushButtonClearVisible) AUTO_PROPERTY(bool, pushButtonClearClientCacheVisible) AUTO_PROPERTY(bool, pushButtonShareFullVisible) AUTO_PROPERTY(QString, labelServerText) @@ -28,7 +26,6 @@ class ServerSettingsLogic : public PageLogicBase public: Q_INVOKABLE void onUpdatePage() override; - Q_INVOKABLE void onPushButtonClearServer(); Q_INVOKABLE void onPushButtonForgetServer(); Q_INVOKABLE void onPushButtonShareFullClicked(); Q_INVOKABLE void onPushButtonClearClientCacheClicked(); diff --git a/client/ui/pages_logic/ShareConnectionLogic.cpp b/client/ui/pages_logic/ShareConnectionLogic.cpp index 26563359..821cc0fc 100644 --- a/client/ui/pages_logic/ShareConnectionLogic.cpp +++ b/client/ui/pages_logic/ShareConnectionLogic.cpp @@ -1,7 +1,6 @@ #include #include #include -#include #include "qrcodegen.hpp" @@ -218,9 +217,9 @@ void ShareConnectionLogic::onPushButtonShareWireGuardGenerateClicked() ErrorCode e = ErrorCode::NoError; QString cfg = m_configurator->wireguardConfigurator->genWireguardConfig(credentials, container, containerConfig, &e); if (e) { - QMessageBox::warning(nullptr, APPLICATION_NAME, - tr("Error occurred while configuring server.") + "\n" + - errorString(e)); + emit uiLogic()->showWarningMessage(tr("Error occurred while generating the config.") + "\n" + + tr("Error message: ") + errorString(e) + "\n" + + tr("See logs for details.")); return; } cfg = m_configurator->processConfigWithExportSettings(serverIndex, container, Proto::WireGuard, cfg); diff --git a/client/ui/pages_logic/ShareConnectionLogic.h b/client/ui/pages_logic/ShareConnectionLogic.h index 5d46be97..3b9655aa 100644 --- a/client/ui/pages_logic/ShareConnectionLogic.h +++ b/client/ui/pages_logic/ShareConnectionLogic.h @@ -50,6 +50,5 @@ public: QList genQrCodeImageSeries(const QByteArray &data); QString svgToBase64(const QString &image); - }; #endif // SHARE_CONNECTION_LOGIC_H diff --git a/client/ui/qml/Pages/PageAdvancedServerSettings.qml b/client/ui/qml/Pages/PageAdvancedServerSettings.qml index a0d2a3f6..4e9d1106 100644 --- a/client/ui/qml/Pages/PageAdvancedServerSettings.qml +++ b/client/ui/qml/Pages/PageAdvancedServerSettings.qml @@ -92,7 +92,6 @@ PageBase { } } - Logo { id : logo anchors.bottom: parent.bottom diff --git a/client/ui/qml/Pages/PageServerSettings.qml b/client/ui/qml/Pages/PageServerSettings.qml index 7a21bfd2..60459955 100644 --- a/client/ui/qml/Pages/PageServerSettings.qml +++ b/client/ui/qml/Pages/PageServerSettings.qml @@ -128,7 +128,6 @@ PageBase { } } - Logo { id : logo anchors.bottom: parent.bottom diff --git a/client/ui/qml/main.qml b/client/ui/qml/main.qml index 6e2c7911..b8758384 100644 --- a/client/ui/qml/main.qml +++ b/client/ui/qml/main.qml @@ -242,12 +242,6 @@ Window { text: qsTr("It's public key. Private key required") visible: false } - MessageDialog { - id: connectErrorDialog - title: "AmneziaVPN" - text: UiLogic.dialogConnectErrorText - visible: false - } Drawer { id: drawer_log diff --git a/client/ui/uilogic.cpp b/client/ui/uilogic.cpp index 1646b256..ed44efad 100644 --- a/client/ui/uilogic.cpp +++ b/client/ui/uilogic.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -326,62 +325,64 @@ void UiLogic::installServer(QMap &containers) pageLogic()->set_pushButtonCancelVisible(visible); }; - ErrorCode error = getInstalledContainers(true); - if (error != ErrorCode::NoError) { - return; - } + ErrorCode errorCode = addAlreadyInstalledContainersGui(true, m_installCredentials); + if (errorCode == ErrorCode::NoError) { + int count = 0; + bool isSomethingInstalled = false; + for (QMap::iterator i = containers.begin(); i != containers.end(); i++, count++) { + if (isContainerAlreadyAddedToGui(i.key(), m_installCredentials)) { + continue; + } - int count = 0; - bool isSomethingInstalled = false; - for (QMap::iterator i = containers.begin(); i != containers.end(); i++, count++) { - if (isContainerAlreadyAddedToGui(i.key(), m_installCredentials)) { - continue; + isSomethingInstalled = true; + + progressBarFunc.setTextFunc(QString("Installing %1 %2 %3").arg(count + 1).arg(tr("of")).arg(containers.size())); + auto installAction = [&] () { + return m_serverController->setupContainer(m_installCredentials, i.key(), i.value()); + }; + errorCode = pageLogic()->doInstallAction(installAction, pageFunc, progressBarFunc, + noButton, waitInfoFunc, + busyInfoFunc, cancelButtonFunc); + + m_serverController->disconnectFromHost(m_installCredentials); } - isSomethingInstalled = true; + if (errorCode == ErrorCode::NoError) { + if (!isSomethingInstalled) { + onUpdateAllPages(); + emit showWarningMessage("Attention! The container you are trying to install is already installed on the server. " + "All installed containers have been added to the application "); + emit setStartPage(Page::Vpn); + return; + } - progressBarFunc.setTextFunc(QString("Installing %1 %2 %3").arg(count + 1).arg(tr("of")).arg(containers.size())); - auto installAction = [&] () { - return m_serverController->setupContainer(m_installCredentials, i.key(), i.value()); - }; - error = pageLogic()->doInstallAction(installAction, pageFunc, progressBarFunc, - noButton, waitInfoFunc, - busyInfoFunc, cancelButtonFunc); + QJsonObject server; + server.insert(config_key::hostName, m_installCredentials.hostName); + server.insert(config_key::userName, m_installCredentials.userName); + server.insert(config_key::password, m_installCredentials.password); + server.insert(config_key::port, m_installCredentials.port); + server.insert(config_key::description, m_settings->nextAvailableServerName()); - m_serverController->disconnectFromHost(m_installCredentials); - } + QJsonArray containerConfigs; + for (const QJsonObject &cfg : containers) { + containerConfigs.append(cfg); + } + server.insert(config_key::containers, containerConfigs); + server.insert(config_key::defaultContainer, ContainerProps::containerToString(containers.firstKey())); + + m_settings->addServer(server); + m_settings->setDefaultServer(m_settings->serversCount() - 1); + onUpdateAllPages(); - if (error == ErrorCode::NoError) { - if (!isSomethingInstalled) { - emit showWarningMessage("Attention! The container you are trying to install is already installed on the server. " - "All installed containers have been added to the application "); emit setStartPage(Page::Vpn); + qApp->processEvents(); return; } - - QJsonObject server; - server.insert(config_key::hostName, m_installCredentials.hostName); - server.insert(config_key::userName, m_installCredentials.userName); - server.insert(config_key::password, m_installCredentials.password); - server.insert(config_key::port, m_installCredentials.port); - server.insert(config_key::description, m_settings->nextAvailableServerName()); - - QJsonArray containerConfigs; - for (const QJsonObject &cfg : containers) { - containerConfigs.append(cfg); - } - server.insert(config_key::containers, containerConfigs); - server.insert(config_key::defaultContainer, ContainerProps::containerToString(containers.firstKey())); - - m_settings->addServer(server); - m_settings->setDefaultServer(m_settings->serversCount() - 1); - onUpdateAllPages(); - - emit setStartPage(Page::Vpn); - qApp->processEvents(); - } else { - emit closePage(); } + emit showWarningMessage(tr("Error occurred while configuring server.") + "\n" + + tr("Error message: ") + errorString(errorCode) + "\n" + + tr("See logs for details.")); + emit closePage(); } PageProtocolLogicBase *UiLogic::protocolLogic(Proto p) @@ -520,45 +521,45 @@ void UiLogic::registerPagesLogic() registerPageLogic(); } -ErrorCode UiLogic::getInstalledContainers(bool addNewServerToGui) +ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, const ServerCredentials& credentials) { QMap installedContainers; - ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(m_installCredentials, installedContainers); + ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(credentials, installedContainers); + m_serverController->disconnectFromHost(credentials); if (errorCode != ErrorCode::NoError) { return errorCode; } QJsonObject server; QJsonArray containerConfigs; - if (addNewServerToGui) { - server.insert(config_key::hostName, m_installCredentials.hostName); - server.insert(config_key::userName, m_installCredentials.userName); - server.insert(config_key::password, m_installCredentials.password); - server.insert(config_key::port, m_installCredentials.port); + if (createNewServer) { + server.insert(config_key::hostName, credentials.hostName); + server.insert(config_key::userName, credentials.userName); + server.insert(config_key::password, credentials.password); + server.insert(config_key::port, credentials.port); server.insert(config_key::description, m_settings->nextAvailableServerName()); } for (auto container = installedContainers.begin(); container != installedContainers.end(); container++) { - if (isContainerAlreadyAddedToGui(container.key(), m_installCredentials)) { + if (isContainerAlreadyAddedToGui(container.key(), credentials)) { continue; } - if (addNewServerToGui) { + if (createNewServer) { containerConfigs.append(container.value()); server.insert(config_key::containers, containerConfigs); - } else { m_settings->setContainerConfig(m_selectedServerIndex, container.key(), container.value()); + m_settings->setDefaultContainer(m_selectedServerIndex, installedContainers.firstKey()); } } - if (addNewServerToGui) { + if (createNewServer) { server.insert(config_key::defaultContainer, ContainerProps::containerToString(installedContainers.firstKey())); m_settings->addServer(server); m_settings->setDefaultServer(m_settings->serversCount() - 1); } - onUpdateAllPages(); return ErrorCode::NoError; } diff --git a/client/ui/uilogic.h b/client/ui/uilogic.h index bc72223c..339f119c 100644 --- a/client/ui/uilogic.h +++ b/client/ui/uilogic.h @@ -61,7 +61,6 @@ class UiLogic : public QObject AUTO_PROPERTY(bool, pageEnabled) AUTO_PROPERTY(int, pagesStackDepth) AUTO_PROPERTY(int, currentPageValue) - AUTO_PROPERTY(QString, dialogConnectErrorText) AUTO_PROPERTY(QString, popupWarningText) READONLY_PROPERTY(QObject *, containersModel) @@ -115,7 +114,7 @@ public: Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data); Q_INVOKABLE void copyToClipboard(const QString& text); - Q_INVOKABLE amnezia::ErrorCode getInstalledContainers(bool addNewServerToGui); + Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool createNewServer, const ServerCredentials& credentials); void shareTempFile(const QString &suggestedName, QString ext, const QString& data); From 2580475f6716351f5bbfdad0d306824eb1be2d2a Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Sat, 25 Feb 2023 17:59:22 +0300 Subject: [PATCH 05/12] added a button to scan the server for already installed containers - refactoring of old code, redundant sections of code removed --- client/core/defs.h | 1 - client/core/errorstrings.cpp | 1 - client/core/servercontroller.cpp | 6 +- .../AdvancedServerSettingsLogic.cpp | 29 +++- .../pages_logic/AdvancedServerSettingsLogic.h | 3 +- .../pages_logic/NewServerProtocolsLogic.cpp | 5 +- .../ui/pages_logic/ServerContainersLogic.cpp | 6 +- client/ui/pages_logic/WizardLogic.cpp | 22 +-- client/ui/pages_logic/WizardLogic.h | 2 +- .../qml/Pages/PageAdvancedServerSettings.qml | 14 +- client/ui/uilogic.cpp | 136 +++++++++--------- client/ui/uilogic.h | 9 +- 12 files changed, 136 insertions(+), 98 deletions(-) diff --git a/client/core/defs.h b/client/core/defs.h index 884cb60f..3f861401 100644 --- a/client/core/defs.h +++ b/client/core/defs.h @@ -32,7 +32,6 @@ enum ErrorCode ServerContainerMissingError, ServerDockerFailedError, ServerCancelInstallation, - ServerContainerAlreadyInstalledError, // Ssh connection errors SshSocketError, SshTimeoutError, SshProtocolError, diff --git a/client/core/errorstrings.cpp b/client/core/errorstrings.cpp index 9460365f..1e7eb395 100644 --- a/client/core/errorstrings.cpp +++ b/client/core/errorstrings.cpp @@ -16,7 +16,6 @@ QString errorString(ErrorCode code){ case(ServerContainerMissingError): return QObject::tr("Server error: Docker container missing"); case(ServerDockerFailedError): return QObject::tr("Server error: Docker failed"); case(ServerCancelInstallation): return QObject::tr("Installation canceled by user"); - case(ServerContainerAlreadyInstalledError): return QObject::tr("Container already installed"); // Ssh connection errors case(SshSocketError): return QObject::tr("Ssh connection error"); diff --git a/client/core/servercontroller.cpp b/client/core/servercontroller.cpp index 9b52071c..f1cf0046 100644 --- a/client/core/servercontroller.cpp +++ b/client/core/servercontroller.cpp @@ -879,7 +879,7 @@ ErrorCode ServerController::getAlreadyInstalledContainers(const ServerCredential if (containerInfo.isEmpty()) { continue; } - const static QRegularExpression containerAndPortRegExp("(amnezia-[a-z]*).*?>([0-9]*)/(udp|tcp).*"); + const static QRegularExpression containerAndPortRegExp("(amnezia[-a-z]*).*?>([0-9]*)/(udp|tcp).*"); QRegularExpressionMatch containerAndPortMatch = containerAndPortRegExp.match(containerInfo); if (containerAndPortMatch.hasMatch()) { QString name = containerAndPortMatch.captured(1); @@ -890,8 +890,8 @@ ErrorCode ServerController::getAlreadyInstalledContainers(const ServerCredential QJsonObject config { { config_key::container, name }, { ProtocolProps::protoToString(mainProto), QJsonObject { - { config_key::port, port }, - { config_key::transport_proto, transportProto }} + { config_key::port, port }, + { config_key::transport_proto, transportProto }} } }; installedContainers.insert(container, config); diff --git a/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp b/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp index 832fc6fd..0b02241c 100644 --- a/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp +++ b/client/ui/pages_logic/AdvancedServerSettingsLogic.cpp @@ -35,7 +35,7 @@ void AdvancedServerSettingsLogic::onUpdatePage() set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName); } -void AdvancedServerSettingsLogic::onPushButtonClearServer() +void AdvancedServerSettingsLogic::onPushButtonClearServerClicked() { set_pageEnabled(false); set_pushButtonClearText(tr("Uninstalling Amnezia software...")); @@ -47,7 +47,7 @@ void AdvancedServerSettingsLogic::onPushButtonClearServer() ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); m_serverController->disconnectFromHost(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex)); if (e) { - emit uiLogic()->showWarningMessage(tr("Error occurred while configuring server.") + "\n" + + emit uiLogic()->showWarningMessage(tr("Error occurred while cleaning the server.") + "\n" + tr("Error message: ") + errorString(e) + "\n" + tr("See logs for details.")); } else { @@ -61,3 +61,28 @@ void AdvancedServerSettingsLogic::onPushButtonClearServer() set_pageEnabled(true); set_pushButtonClearText(tr("Clear server from Amnezia software")); } + +void AdvancedServerSettingsLogic::onPushButtonScanServerClicked() +{ + set_labelWaitInfoVisible(false); + set_pageEnabled(false); + + bool isServerCreated; + auto containersCount = m_settings->containers(uiLogic()->m_selectedServerIndex).size(); + ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, isServerCreated); + if (errorCode != ErrorCode::NoError) { + emit uiLogic()->showWarningMessage(tr("Error occurred while scanning the server.") + "\n" + + tr("Error message: ") + errorString(errorCode) + "\n" + + tr("See logs for details.")); + } + auto newContainersCount = m_settings->containers(uiLogic()->m_selectedServerIndex).size(); + if (containersCount != newContainersCount) { + emit uiLogic()->showWarningMessage(tr("All containers installed on the server are added to the GUI")); + } else { + emit uiLogic()->showWarningMessage(tr("No installed containers found on the server")); + } + + + onUpdatePage(); + set_pageEnabled(true); +} diff --git a/client/ui/pages_logic/AdvancedServerSettingsLogic.h b/client/ui/pages_logic/AdvancedServerSettingsLogic.h index 396b375a..692968f1 100644 --- a/client/ui/pages_logic/AdvancedServerSettingsLogic.h +++ b/client/ui/pages_logic/AdvancedServerSettingsLogic.h @@ -24,7 +24,8 @@ public: Q_INVOKABLE void onUpdatePage() override; - Q_INVOKABLE void onPushButtonClearServer(); + Q_INVOKABLE void onPushButtonClearServerClicked(); + Q_INVOKABLE void onPushButtonScanServerClicked(); }; #endif // ADVANCEDSERVERSETTINGSLOGIC_H diff --git a/client/ui/pages_logic/NewServerProtocolsLogic.cpp b/client/ui/pages_logic/NewServerProtocolsLogic.cpp index cabe1bc0..a1db7565 100644 --- a/client/ui/pages_logic/NewServerProtocolsLogic.cpp +++ b/client/ui/pages_logic/NewServerProtocolsLogic.cpp @@ -17,7 +17,6 @@ void NewServerProtocolsLogic::onUpdatePage() void NewServerProtocolsLogic::onPushButtonConfigureClicked(DockerContainer c, int port, TransportProto tp) { - QMap containers; Proto mainProto = ContainerProps::defaultProtocol(c); QJsonObject config { @@ -28,8 +27,8 @@ void NewServerProtocolsLogic::onPushButtonConfigureClicked(DockerContainer c, in } }; - containers.insert(c, config); + QPair container(c, config); - uiLogic()->installServer(containers); + uiLogic()->installServer(container); } diff --git a/client/ui/pages_logic/ServerContainersLogic.cpp b/client/ui/pages_logic/ServerContainersLogic.cpp index 91efc2c6..aeec8161 100644 --- a/client/ui/pages_logic/ServerContainersLogic.cpp +++ b/client/ui/pages_logic/ServerContainersLogic.cpp @@ -88,11 +88,11 @@ void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int p emit uiLogic()->goToPage(Page::ServerConfiguringProgress); qApp->processEvents(); - ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex); - ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, credentials); + bool isServerCreated = false; + ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, isServerCreated); if (errorCode == ErrorCode::NoError) { - if (!uiLogic()->isContainerAlreadyAddedToGui(c, credentials)) { + if (!uiLogic()->isContainerAlreadyAddedToGui(c)) { auto installAction = [this, c, &config]() { return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config); }; diff --git a/client/ui/pages_logic/WizardLogic.cpp b/client/ui/pages_logic/WizardLogic.cpp index 5fe820f1..23a20aed 100644 --- a/client/ui/pages_logic/WizardLogic.cpp +++ b/client/ui/pages_logic/WizardLogic.cpp @@ -18,7 +18,7 @@ void WizardLogic::onUpdatePage() set_radioButtonMediumChecked(true); } -QMap WizardLogic::getInstallConfigsFromWizardPage() const +QPair WizardLogic::getInstallConfigsFromWizardPage() const { QJsonObject cloakConfig { { config_key::container, ContainerProps::containerToString(DockerContainer::Cloak) }, @@ -33,27 +33,29 @@ QMap WizardLogic::getInstallConfigsFromWizardPage( { config_key::container, ContainerProps::containerToString(DockerContainer::OpenVpn) } }; - QMap containers; + QPair container; + + DockerContainer dockerContainer; if (radioButtonHighChecked()) { - containers.insert(DockerContainer::Cloak, cloakConfig); + container = {DockerContainer::Cloak, cloakConfig}; } if (radioButtonMediumChecked()) { - containers.insert(DockerContainer::ShadowSocks, ssConfig); + container = {DockerContainer::ShadowSocks, ssConfig}; } if (radioButtonLowChecked()) { - containers.insert(DockerContainer::OpenVpn, openVpnConfig); + container = {DockerContainer::OpenVpn, openVpnConfig}; } - return containers; + return container; } void WizardLogic::onPushButtonVpnModeFinishClicked() { - auto containers = getInstallConfigsFromWizardPage(); - uiLogic()->installServer(containers); + auto container = getInstallConfigsFromWizardPage(); + uiLogic()->installServer(container); if (checkBoxVpnModeChecked()) { m_settings->setRouteMode(Settings::VpnOnlyForwardSites); } else { @@ -63,6 +65,6 @@ void WizardLogic::onPushButtonVpnModeFinishClicked() void WizardLogic::onPushButtonLowFinishClicked() { - auto containers = getInstallConfigsFromWizardPage(); - uiLogic()->installServer(containers); + auto container = getInstallConfigsFromWizardPage(); + uiLogic()->installServer(container); } diff --git a/client/ui/pages_logic/WizardLogic.h b/client/ui/pages_logic/WizardLogic.h index 3827c86e..a2e45af7 100644 --- a/client/ui/pages_logic/WizardLogic.h +++ b/client/ui/pages_logic/WizardLogic.h @@ -25,7 +25,7 @@ public: explicit WizardLogic(UiLogic *uiLogic, QObject *parent = nullptr); ~WizardLogic() = default; - QMap getInstallConfigsFromWizardPage() const; + QPair getInstallConfigsFromWizardPage() const; }; #endif // WIZARD_LOGIC_H diff --git a/client/ui/qml/Pages/PageAdvancedServerSettings.qml b/client/ui/qml/Pages/PageAdvancedServerSettings.qml index 4e9d1106..e00f7326 100644 --- a/client/ui/qml/Pages/PageAdvancedServerSettings.qml +++ b/client/ui/qml/Pages/PageAdvancedServerSettings.qml @@ -16,12 +16,21 @@ PageBase { BackButton { id: back } + Caption { id: caption text: qsTr("Advanced server settings") anchors.horizontalCenter: parent.horizontalCenter } + BusyIndicator { + z: 99 + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + visible: !AdvancedServerSettingsLogic.pageEnabled + running: !AdvancedServerSettingsLogic.pageEnabled + } + FlickableType { id: fl anchors.top: caption.bottom @@ -54,6 +63,7 @@ PageBase { LabelType { Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter text: AdvancedServerSettingsLogic.labelWaitInfoText visible: AdvancedServerSettingsLogic.labelWaitInfoVisible } @@ -64,7 +74,7 @@ PageBase { text: "Scan the server for installed containers" visible: AdvancedServerSettingsLogic.pushButtonClearVisible onClicked: { - UiLogic.getInstalledContainers(false) + AdvancedServerSettingsLogic.onPushButtonScanServerClicked() } } @@ -82,8 +92,8 @@ PageBase { id: popupClearServer questionText: "Attention! All containers will be deleted on the server. This means that configuration files, keys and certificates will be deleted. Continue?" yesFunc: function() { - AdvancedServerSettingsLogic.onPushButtonClearServer() close() + AdvancedServerSettingsLogic.onPushButtonClearServerClicked() } noFunc: function() { close() diff --git a/client/ui/uilogic.cpp b/client/ui/uilogic.cpp index ed44efad..895a526c 100644 --- a/client/ui/uilogic.cpp +++ b/client/ui/uilogic.cpp @@ -267,10 +267,8 @@ void UiLogic::onGotoCurrentProtocolsPage() emit goToPage(Page::ServerContainers); } -void UiLogic::installServer(QMap &containers) +void UiLogic::installServer(QPair &container) { - if (containers.isEmpty()) return; - emit goToPage(Page::ServerConfiguringProgress); QEventLoop loop; QTimer::singleShot(500, &loop, SLOT(quit())); @@ -325,57 +323,48 @@ void UiLogic::installServer(QMap &containers) pageLogic()->set_pushButtonCancelVisible(visible); }; - ErrorCode errorCode = addAlreadyInstalledContainersGui(true, m_installCredentials); + bool isServerCreated = false; + ErrorCode errorCode = addAlreadyInstalledContainersGui(true, isServerCreated); if (errorCode == ErrorCode::NoError) { - int count = 0; - bool isSomethingInstalled = false; - for (QMap::iterator i = containers.begin(); i != containers.end(); i++, count++) { - if (isContainerAlreadyAddedToGui(i.key(), m_installCredentials)) { - continue; - } - - isSomethingInstalled = true; - - progressBarFunc.setTextFunc(QString("Installing %1 %2 %3").arg(count + 1).arg(tr("of")).arg(containers.size())); + if (!isContainerAlreadyAddedToGui(container.first)) { + progressBarFunc.setTextFunc(QString("Installing %1").arg(ContainerProps::containerToString(container.first))); auto installAction = [&] () { - return m_serverController->setupContainer(m_installCredentials, i.key(), i.value()); + return m_serverController->setupContainer(m_installCredentials, container.first, container.second); }; errorCode = pageLogic()->doInstallAction(installAction, pageFunc, progressBarFunc, - noButton, waitInfoFunc, - busyInfoFunc, cancelButtonFunc); - + noButton, waitInfoFunc, + busyInfoFunc, cancelButtonFunc); m_serverController->disconnectFromHost(m_installCredentials); - } - if (errorCode == ErrorCode::NoError) { - if (!isSomethingInstalled) { + if (errorCode == ErrorCode::NoError) { + if (!isServerCreated) { + QJsonObject server; + server.insert(config_key::hostName, m_installCredentials.hostName); + server.insert(config_key::userName, m_installCredentials.userName); + server.insert(config_key::password, m_installCredentials.password); + server.insert(config_key::port, m_installCredentials.port); + server.insert(config_key::description, m_settings->nextAvailableServerName()); + + server.insert(config_key::containers, QJsonArray{container.second}); + server.insert(config_key::defaultContainer, ContainerProps::containerToString(container.first)); + + m_settings->addServer(server); + m_settings->setDefaultServer(m_settings->serversCount() - 1); + } else { + m_settings->setContainerConfig(m_settings->serversCount() - 1, container.first, container.second); + m_settings->setDefaultContainer(m_settings->serversCount() - 1, container.first); + } onUpdateAllPages(); - emit showWarningMessage("Attention! The container you are trying to install is already installed on the server. " - "All installed containers have been added to the application "); + emit setStartPage(Page::Vpn); + qApp->processEvents(); return; } - - QJsonObject server; - server.insert(config_key::hostName, m_installCredentials.hostName); - server.insert(config_key::userName, m_installCredentials.userName); - server.insert(config_key::password, m_installCredentials.password); - server.insert(config_key::port, m_installCredentials.port); - server.insert(config_key::description, m_settings->nextAvailableServerName()); - - QJsonArray containerConfigs; - for (const QJsonObject &cfg : containers) { - containerConfigs.append(cfg); - } - server.insert(config_key::containers, containerConfigs); - server.insert(config_key::defaultContainer, ContainerProps::containerToString(containers.firstKey())); - - m_settings->addServer(server); - m_settings->setDefaultServer(m_settings->serversCount() - 1); + } else { onUpdateAllPages(); - + emit showWarningMessage("Attention! The container you are trying to install is already installed on the server. " + "All installed containers have been added to the application "); emit setStartPage(Page::Vpn); - qApp->processEvents(); return; } } @@ -521,8 +510,16 @@ void UiLogic::registerPagesLogic() registerPageLogic(); } -ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, const ServerCredentials& credentials) +ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool &isServerCreated) { + isServerCreated = false; + ServerCredentials credentials; + if (createNewServer) { + credentials = m_installCredentials; + } else { + credentials = m_settings->serverCredentials(m_selectedServerIndex); + } + QMap installedContainers; ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(credentials, installedContainers); m_serverController->disconnectFromHost(credentials); @@ -530,44 +527,47 @@ ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, const return errorCode; } - QJsonObject server; - QJsonArray containerConfigs; - if (createNewServer) { - server.insert(config_key::hostName, credentials.hostName); - server.insert(config_key::userName, credentials.userName); - server.insert(config_key::password, credentials.password); - server.insert(config_key::port, credentials.port); - server.insert(config_key::description, m_settings->nextAvailableServerName()); - } + if (!installedContainers.empty()) { + QJsonObject server; + QJsonArray containerConfigs; + if (createNewServer) { + server.insert(config_key::hostName, credentials.hostName); + server.insert(config_key::userName, credentials.userName); + server.insert(config_key::password, credentials.password); + server.insert(config_key::port, credentials.port); + server.insert(config_key::description, m_settings->nextAvailableServerName()); + } - for (auto container = installedContainers.begin(); container != installedContainers.end(); container++) { - if (isContainerAlreadyAddedToGui(container.key(), credentials)) { - continue; + for (auto container = installedContainers.begin(); container != installedContainers.end(); container++) { + if (isContainerAlreadyAddedToGui(container.key())) { + continue; + } + + if (createNewServer) { + containerConfigs.append(container.value()); + server.insert(config_key::containers, containerConfigs); + } else { + m_settings->setContainerConfig(m_selectedServerIndex, container.key(), container.value()); + m_settings->setDefaultContainer(m_selectedServerIndex, installedContainers.firstKey()); + } } if (createNewServer) { - containerConfigs.append(container.value()); - server.insert(config_key::containers, containerConfigs); - } else { - m_settings->setContainerConfig(m_selectedServerIndex, container.key(), container.value()); - m_settings->setDefaultContainer(m_selectedServerIndex, installedContainers.firstKey()); + server.insert(config_key::defaultContainer, ContainerProps::containerToString(installedContainers.firstKey())); + m_settings->addServer(server); + m_settings->setDefaultServer(m_settings->serversCount() - 1); + isServerCreated = true; } } - if (createNewServer) { - server.insert(config_key::defaultContainer, ContainerProps::containerToString(installedContainers.firstKey())); - m_settings->addServer(server); - m_settings->setDefaultServer(m_settings->serversCount() - 1); - } - return ErrorCode::NoError; } -bool UiLogic::isContainerAlreadyAddedToGui(DockerContainer container, const ServerCredentials &selectedServerCredentials) +bool UiLogic::isContainerAlreadyAddedToGui(DockerContainer container) { for (int i = 0; i < m_settings->serversCount(); i++) { const ServerCredentials credentials = m_settings->serverCredentials(i); - if (selectedServerCredentials.hostName == credentials.hostName && selectedServerCredentials.port == credentials.port) { + if (m_installCredentials.hostName == credentials.hostName && m_installCredentials.port == credentials.port) { const QJsonObject containerConfig = m_settings->containerConfig(i, container); if (!containerConfig.isEmpty()) { return true; diff --git a/client/ui/uilogic.h b/client/ui/uilogic.h index 339f119c..92035fe5 100644 --- a/client/ui/uilogic.h +++ b/client/ui/uilogic.h @@ -53,6 +53,7 @@ class OtherProtocolsLogic; class VpnConnection; +class CreateServerTest; class UiLogic : public QObject { @@ -97,6 +98,8 @@ public: friend class OtherProtocolsLogic; + friend class CreateServerTest; + Q_INVOKABLE virtual void onUpdatePage() {} // UiLogic is set as logic class for some qml pages Q_INVOKABLE void onUpdateAllPages(); @@ -114,7 +117,7 @@ public: Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data); Q_INVOKABLE void copyToClipboard(const QString& text); - Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool createNewServer, const ServerCredentials& credentials); + Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool createNewServer, bool &isServerCreated); void shareTempFile(const QString &suggestedName, QString ext, const QString& data); @@ -135,11 +138,11 @@ signals: private slots: // containers - INOUT arg - void installServer(QMap &containers); + void installServer(QPair &container); private: PageEnumNS::Page currentPage(); - bool isContainerAlreadyAddedToGui(DockerContainer container, const ServerCredentials &selectedServerCredentials); + bool isContainerAlreadyAddedToGui(DockerContainer container); public: Q_INVOKABLE PageProtocolLogicBase *protocolLogic(Proto p); From be39d28be72e265694343a918696b3aa713ba945 Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Sat, 25 Feb 2023 18:48:10 +0300 Subject: [PATCH 06/12] renamed selectedServerIndex for android --- client/ui/pages_logic/ServerSettingsLogic.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ui/pages_logic/ServerSettingsLogic.cpp b/client/ui/pages_logic/ServerSettingsLogic.cpp index 858a77d1..92b093a5 100644 --- a/client/ui/pages_logic/ServerSettingsLogic.cpp +++ b/client/ui/pages_logic/ServerSettingsLogic.cpp @@ -121,7 +121,7 @@ void ServerSettingsLogic::onPushButtonShareFullClicked() auto appContext = activity.callObjectMethod( "getApplicationContext", "()Landroid/content/Context;"); if (appContext.isValid()) { - QAndroidActivityResultReceiver *receiver = new authResultReceiver(uiLogic(), uiLogic()->selectedServerIndex); + QAndroidActivityResultReceiver *receiver = new authResultReceiver(uiLogic(), uiLogic()->m_selectedServerIndex); auto intent = QJniObject::callStaticObjectMethod( "org/amnezia/vpn/AuthHelper", "getAuthIntent", "(Landroid/content/Context;)Landroid/content/Intent;", appContext.object()); @@ -130,7 +130,7 @@ void ServerSettingsLogic::onPushButtonShareFullClicked() QtAndroidPrivate::startActivity(intent.object(), 1, receiver); } } else { - uiLogic()->pageLogic()->updateSharingPage(uiLogic()->selectedServerIndex, DockerContainer::None); + uiLogic()->pageLogic()->updateSharingPage(uiLogic()->m_selectedServerIndex, DockerContainer::None); emit uiLogic()->goToShareProtocolPage(Proto::Any); } } From 4bd6fbd4457956f34247e98d9de37d55abc00ad9 Mon Sep 17 00:00:00 2001 From: Dmitriy Karpushin Date: Mon, 6 Mar 2023 12:11:37 +0300 Subject: [PATCH 07/12] Support of targetSdk 31 with its behaviour changes --- client/android/build.gradle | 2 +- client/android/shadowsocks/build.gradle | 2 +- client/android/shadowsocks/src/main/AndroidManifest.xml | 3 ++- .../src/main/java/org/amnezia/vpn/shadowsocks/core/Core.kt | 6 +++--- client/android/src/org/amnezia/vpn/NotificationUtil.kt | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/client/android/build.gradle b/client/android/build.gradle index 94604ad8..16507a89 100644 --- a/client/android/build.gradle +++ b/client/android/build.gradle @@ -135,7 +135,7 @@ android { defaultConfig { resConfig "en" minSdkVersion = 24 - targetSdkVersion = 30 + targetSdkVersion = 31 versionCode 10 // Change to a higher number versionName "2.0.10" // Change to a higher number diff --git a/client/android/shadowsocks/build.gradle b/client/android/shadowsocks/build.gradle index d87139fe..69ebd0bd 100644 --- a/client/android/shadowsocks/build.gradle +++ b/client/android/shadowsocks/build.gradle @@ -53,7 +53,7 @@ dependencies { implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0" implementation "androidx.room:room-runtime:2.2.5" // runtime implementation "androidx.preference:preference:1.1.0" - implementation "androidx.work:work-runtime-ktx:2.3.4" + implementation "androidx.work:work-runtime-ktx:2.7.1" implementation "androidx.browser:browser:1.3.0-alpha01" implementation "androidx.constraintlayout:constraintlayout:1.1.3" implementation "com.google.android.material:material:1.2.0-alpha05" diff --git a/client/android/shadowsocks/src/main/AndroidManifest.xml b/client/android/shadowsocks/src/main/AndroidManifest.xml index 9769ab7a..ee498ab8 100644 --- a/client/android/shadowsocks/src/main/AndroidManifest.xml +++ b/client/android/shadowsocks/src/main/AndroidManifest.xml @@ -68,7 +68,8 @@ android:name="org.amnezia.vpn.shadowsocks.core.BootReceiver" android:directBootAware="true" android:enabled="false" - android:process=":QtOnlyProcess"> + android:process=":QtOnlyProcess" + android:exported="true"> diff --git a/client/android/shadowsocks/src/main/java/org/amnezia/vpn/shadowsocks/core/Core.kt b/client/android/shadowsocks/src/main/java/org/amnezia/vpn/shadowsocks/core/Core.kt index 170bfb75..93bfcacc 100644 --- a/client/android/shadowsocks/src/main/java/org/amnezia/vpn/shadowsocks/core/Core.kt +++ b/client/android/shadowsocks/src/main/java/org/amnezia/vpn/shadowsocks/core/Core.kt @@ -84,8 +84,9 @@ object Core { fun init(app: Application, configureClass: KClass) { Core.app = app configureIntent = { - PendingIntent.getActivity(it, 0, Intent(it, configureClass.java) - .setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), 0) + PendingIntent.getActivity(it, 0, + Intent(it, configureClass.java).setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT), + PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) } if (Build.VERSION.SDK_INT >= 24) { // migrate old files @@ -99,7 +100,6 @@ object Core { // overhead of debug mode is minimal: https://github.com/Kotlin/kotlinx.coroutines/blob/f528898/docs/debugging.md#debug-mode System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON) - WorkManager.initialize(deviceStorage, Configuration.Builder().build()) // handle data restored/crash if (Build.VERSION.SDK_INT >= 24 && DataStore.directBootAware && diff --git a/client/android/src/org/amnezia/vpn/NotificationUtil.kt b/client/android/src/org/amnezia/vpn/NotificationUtil.kt index 15e706ed..d2808d5d 100644 --- a/client/android/src/org/amnezia/vpn/NotificationUtil.kt +++ b/client/android/src/org/amnezia/vpn/NotificationUtil.kt @@ -99,7 +99,7 @@ object NotificationUtil { val mainActivityName = "org.amnezia.vpn.qt.VPNActivity" val activity = Class.forName(mainActivityName) val intent = Intent(service, activity) - val pendingIntent = PendingIntent.getActivity(service, 0, intent, 0) + val pendingIntent = PendingIntent.getActivity(service, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) // Build our notification sNotificationBuilder?.let { it.setSmallIcon(org.amnezia.vpn.R.drawable.ic_amnezia_round) From e16d835727a290175d0eba94265983d761b070c6 Mon Sep 17 00:00:00 2001 From: pokamest Date: Thu, 16 Mar 2023 12:35:01 +0000 Subject: [PATCH 08/12] CentOS docker autostart fix --- client/server_scripts/install_docker.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/client/server_scripts/install_docker.sh b/client/server_scripts/install_docker.sh index baff7cb6..bb14e4cf 100644 --- a/client/server_scripts/install_docker.sh +++ b/client/server_scripts/install_docker.sh @@ -6,4 +6,5 @@ if [[ -f "$pm_apt" ]]; then export DEBIAN_FRONTEND=noninteractive; fi;\ if [[ -z "$docker_service" ]]; then sudo $pm update -y -q; sudo $pm install -y -q curl $docker_pkg; fi;\ docker_service=$(systemctl list-units --full -all | grep docker.service | grep -v inactive | grep -v dead | grep -v failed);\ if [[ -z "$docker_service" ]]; then sleep 5 && sudo systemctl start docker && sleep 5; fi;\ +if [[ -f "$pm_yum" ]]; then sudo systemctl enable docker && sudo systemctl start docker; fi;\ docker --version From 433e6901c6cd617ba3d1f07282c99fc03c123b3d Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Thu, 16 Mar 2023 16:46:29 +0300 Subject: [PATCH 09/12] fixed a bug when existing containers were overwritten in the GUI when clicking the "scan installed containers" button --- client/ui/pages_logic/ServerListLogic.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/client/ui/pages_logic/ServerListLogic.cpp b/client/ui/pages_logic/ServerListLogic.cpp index 79d13c8b..e91b1e33 100644 --- a/client/ui/pages_logic/ServerListLogic.cpp +++ b/client/ui/pages_logic/ServerListLogic.cpp @@ -21,6 +21,7 @@ void ServerListLogic::onServerListPushbuttonDefaultClicked(int index) void ServerListLogic::onServerListPushbuttonSettingsClicked(int index) { uiLogic()->m_selectedServerIndex = index; + uiLogic()->m_installCredentials = m_settings->serverCredentials(index); uiLogic()->goToPage(Page::ServerSettings); } From a92f1b82d00ee2342ba61ba67d20b72323d7fde4 Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Thu, 16 Mar 2023 16:47:26 +0300 Subject: [PATCH 10/12] fixed a bug with incorrect port detection when clicking the "scan installed containers" button --- client/core/servercontroller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/core/servercontroller.cpp b/client/core/servercontroller.cpp index 94968789..c0f6adae 100644 --- a/client/core/servercontroller.cpp +++ b/client/core/servercontroller.cpp @@ -917,7 +917,7 @@ ErrorCode ServerController::getAlreadyInstalledContainers(const ServerCredential if (containerInfo.isEmpty()) { continue; } - const static QRegularExpression containerAndPortRegExp("(amnezia[-a-z]*).*?>([0-9]*)/(udp|tcp).*"); + const static QRegularExpression containerAndPortRegExp("(amnezia[-a-z]*).*?:([0-9]*)->[0-9]*/(udp|tcp).*"); QRegularExpressionMatch containerAndPortMatch = containerAndPortRegExp.match(containerInfo); if (containerAndPortMatch.hasMatch()) { QString name = containerAndPortMatch.captured(1); From 7e1bcf84f0b51e4be1d47c18ea226ab3d75da2b3 Mon Sep 17 00:00:00 2001 From: "vladimir.kuznetsov" Date: Thu, 16 Mar 2023 18:59:06 +0300 Subject: [PATCH 11/12] fixed saving site from "fake web site" field when configuring openvpn over cloak via wizard --- client/ui/qml/Pages/PageSetupWizardHighLevel.qml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/ui/qml/Pages/PageSetupWizardHighLevel.qml b/client/ui/qml/Pages/PageSetupWizardHighLevel.qml index 8b4bd322..e0f194ff 100644 --- a/client/ui/qml/Pages/PageSetupWizardHighLevel.qml +++ b/client/ui/qml/Pages/PageSetupWizardHighLevel.qml @@ -54,12 +54,12 @@ You SHOULD set this website address to some foreign website which is not blocked text: WizardLogic.lineEditHighWebsiteMaskingText onEditingFinished: { let _text = website_masking.text - _text.replace("http://", ""); - _text.replace("https://", ""); + _text = _text.replace("http://", ""); + _text = _text.replace("https://", ""); if (!_text) { return } - _text = _text.split("/").first(); + _text = _text.split("/")[0]; WizardLogic.lineEditHighWebsiteMaskingText = _text } onAccepted: { From cba78190a86d8b5b03022183364bede5b9bc6ed5 Mon Sep 17 00:00:00 2001 From: pokamest Date: Thu, 16 Mar 2023 11:43:18 -0700 Subject: [PATCH 12/12] iOS build fix --- client/CMakeLists.txt | 26 ++++++++++---------------- client/vpnconnection.cpp | 4 ++-- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index 7466c595..50d6d0f7 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -303,13 +303,14 @@ if(IOS) find_library(FW_AUTHENTICATIONSERVICES AuthenticationServices) find_library(FW_UIKIT UIKit) + find_library(FW_AVFOUNDATION AVFoundation) find_library(FW_FOUNDATION Foundation) find_library(FW_STOREKIT StoreKit) find_library(FW_USERNOTIFICATIONS UserNotifications) set(LIBS ${LIBS} ${FW_AUTHENTICATIONSERVICES} ${FW_UIKIT} - ${FW_FOUNDATION} ${FW_STOREKIT} + ${FW_AVFOUNDATION} ${FW_FOUNDATION} ${FW_STOREKIT} ${FW_USERNOTIFICATIONS} ) @@ -463,14 +464,13 @@ if(IOS) PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" ) -target_sources(${PROJECT} PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/ios/Media.xcassets - -) -set_source_files_properties( - ${CMAKE_CURRENT_LIST_DIR}/ios/Media.xcassets - PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" -) + target_sources(${PROJECT} PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/ios/Media.xcassets + ) + set_source_files_properties( + ${CMAKE_CURRENT_LIST_DIR}/ios/Media.xcassets + PROPERTIES MACOSX_PACKAGE_LOCATION "Resources" + ) add_subdirectory(ios/networkextension) add_dependencies(${PROJECT} networkextension) @@ -498,19 +498,13 @@ set_source_files_properties( ) set_target_properties (${PROJECT} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual) - set_target_properties(${PROJECT} PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER "match AppStore org.amnezia.AmneziaVPN") - set_target_properties(${PROJECT} PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER[variant=Debug] "match Development org.amnezia.AmneziaVPN") - - set_target_properties ("networkextension" PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual) - + set_target_properties("networkextension" PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_STYLE Manual) set_target_properties("networkextension" PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER "match AppStore org.amnezia.AmneziaVPN.network-extension") - set_target_properties("networkextension" PROPERTIES XCODE_ATTRIBUTE_PROVISIONING_PROFILE_SPECIFIER[variant=Debug] "match Development org.amnezia.AmneziaVPN.network-extension") - endif() if(ANDROID) diff --git a/client/vpnconnection.cpp b/client/vpnconnection.cpp index 4ff67a07..e01f7e61 100644 --- a/client/vpnconnection.cpp +++ b/client/vpnconnection.cpp @@ -105,8 +105,8 @@ void VpnConnection::onConnectionStateChanged(VpnProtocol::VpnConnectionState sta } else { m_isIOSConnected = false; - m_receivedBytes = 0; - m_sentBytes = 0; +// m_receivedBytes = 0; +// m_sentBytes = 0; } #endif emit connectionStateChanged(state);