diff --git a/client/CMakeLists.txt b/client/CMakeLists.txt index cc192268..004b64f9 100644 --- a/client/CMakeLists.txt +++ b/client/CMakeLists.txt @@ -108,7 +108,7 @@ set(HEADERS ${HEADERS} ${CMAKE_CURRENT_LIST_DIR}/core/errorstrings.h ${CMAKE_CURRENT_LIST_DIR}/core/scripts_registry.h ${CMAKE_CURRENT_LIST_DIR}/core/server_defs.h - ${CMAKE_CURRENT_LIST_DIR}/core/servercontroller.h + ${CMAKE_CURRENT_LIST_DIR}/core/controllers/serverController.h ${CMAKE_CURRENT_LIST_DIR}/protocols/protocols_defs.h ${CMAKE_CURRENT_LIST_DIR}/protocols/qml_register_protocols.h ${CMAKE_CURRENT_LIST_DIR}/ui/notificationhandler.h @@ -147,7 +147,7 @@ set(SOURCES ${SOURCES} ${CMAKE_CURRENT_LIST_DIR}/core/errorstrings.cpp ${CMAKE_CURRENT_LIST_DIR}/core/scripts_registry.cpp ${CMAKE_CURRENT_LIST_DIR}/core/server_defs.cpp - ${CMAKE_CURRENT_LIST_DIR}/core/servercontroller.cpp + ${CMAKE_CURRENT_LIST_DIR}/core/controllers/serverController.cpp ${CMAKE_CURRENT_LIST_DIR}/protocols/protocols_defs.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/notificationhandler.cpp ${CMAKE_CURRENT_LIST_DIR}/ui/qautostart.cpp diff --git a/client/amnezia_application.cpp b/client/amnezia_application.cpp index d8039d9b..cb1512cc 100644 --- a/client/amnezia_application.cpp +++ b/client/amnezia_application.cpp @@ -139,7 +139,8 @@ void AmneziaApplication::init() &ConnectionController::openConnection); connect(m_notificationHandler.get(), &NotificationHandler::disconnectRequested, m_connectionController.get(), &ConnectionController::closeConnection); - connect(this, &AmneziaApplication::translationsUpdated, m_notificationHandler.get(), &NotificationHandler::onTranslationsUpdated); + connect(this, &AmneziaApplication::translationsUpdated, m_notificationHandler.get(), + &NotificationHandler::onTranslationsUpdated); m_engine->load(url); m_systemController->setQmlRoot(m_engine->rootObjects().value(0)); @@ -226,14 +227,13 @@ void AmneziaApplication::loadTranslator() updateTranslator(locale); } - void AmneziaApplication::updateTranslator(const QLocale &locale) { if (!m_translator->isEmpty()) { QCoreApplication::removeTranslator(m_translator.get()); } - QString strFileName = QString(":/translations/amneziavpn")+QLatin1String("_")+locale.name()+".qm"; + QString strFileName = QString(":/translations/amneziavpn") + QLatin1String("_") + locale.name() + ".qm"; if (m_translator->load(strFileName)) { if (QCoreApplication::installTranslator(m_translator.get())) { m_settings->setAppLanguage(locale); @@ -330,7 +330,8 @@ void AmneziaApplication::initControllers() m_connectionController.reset(new ConnectionController(m_serversModel, m_containersModel, m_vpnConnection)); m_engine->rootContext()->setContextProperty("ConnectionController", m_connectionController.get()); - connect(this, &AmneziaApplication::translationsUpdated, m_connectionController.get(), &ConnectionController::onTranslationsUpdated); + connect(this, &AmneziaApplication::translationsUpdated, m_connectionController.get(), + &ConnectionController::onTranslationsUpdated); m_pageController.reset(new PageController(m_serversModel, m_settings)); m_engine->rootContext()->setContextProperty("PageController", m_pageController.get()); @@ -361,4 +362,10 @@ void AmneziaApplication::initControllers() m_systemController.reset(new SystemController(m_settings)); m_engine->rootContext()->setContextProperty("SystemController", m_systemController.get()); + + m_cloudController.reset(new CloudController(m_serversModel, m_containersModel)); + m_engine->rootContext()->setContextProperty("CloudController", m_cloudController.get()); + + connect(m_cloudController.get(), &CloudController::serverConfigUpdated, this, + [this]() { m_containersModel->setCurrentlyProcessedServerIndex(m_serversModel->getDefaultServerIndex()); }); } diff --git a/client/amnezia_application.h b/client/amnezia_application.h index 2dd74fcb..394ff943 100644 --- a/client/amnezia_application.h +++ b/client/amnezia_application.h @@ -24,6 +24,7 @@ #include "ui/controllers/settingsController.h" #include "ui/controllers/sitesController.h" #include "ui/controllers/systemController.h" +#include "ui/controllers/cloudController.h" #include "ui/models/containers_model.h" #include "ui/models/languageModel.h" #include "ui/models/protocols/cloakConfigModel.h" @@ -116,6 +117,7 @@ private: QScopedPointer m_settingsController; QScopedPointer m_sitesController; QScopedPointer m_systemController; + QScopedPointer m_cloudController; }; #endif // AMNEZIA_APPLICATION_H diff --git a/client/configurators/cloak_configurator.cpp b/client/configurators/cloak_configurator.cpp index fab378e2..9c540967 100644 --- a/client/configurators/cloak_configurator.cpp +++ b/client/configurators/cloak_configurator.cpp @@ -4,7 +4,7 @@ #include #include -#include "core/servercontroller.h" +#include "core/controllers/serverController.h" #include "containers/containers_defs.h" CloakConfigurator::CloakConfigurator(std::shared_ptr settings, QObject *parent): diff --git a/client/configurators/ikev2_configurator.cpp b/client/configurators/ikev2_configurator.cpp index 4ca0e5da..752d1750 100644 --- a/client/configurators/ikev2_configurator.cpp +++ b/client/configurators/ikev2_configurator.cpp @@ -11,7 +11,7 @@ #include "containers/containers_defs.h" #include "core/scripts_registry.h" #include "core/server_defs.h" -#include "core/servercontroller.h" +#include "core/controllers/serverController.h" #include "utilities.h" Ikev2Configurator::Ikev2Configurator(std::shared_ptr settings, QObject *parent) diff --git a/client/configurators/openvpn_configurator.cpp b/client/configurators/openvpn_configurator.cpp index a62bdd9c..e45c8506 100644 --- a/client/configurators/openvpn_configurator.cpp +++ b/client/configurators/openvpn_configurator.cpp @@ -16,7 +16,7 @@ #include "containers/containers_defs.h" #include "core/scripts_registry.h" #include "core/server_defs.h" -#include "core/servercontroller.h" +#include "core/controllers/serverController.h" #include "settings.h" #include "utilities.h" diff --git a/client/configurators/openvpn_configurator.h b/client/configurators/openvpn_configurator.h index 3b84e0a0..342bf753 100644 --- a/client/configurators/openvpn_configurator.h +++ b/client/configurators/openvpn_configurator.h @@ -32,9 +32,9 @@ public: ErrorCode signCert(DockerContainer container, const ServerCredentials &credentials, QString clientId); -private: - ConnectionData createCertRequest(); + static ConnectionData createCertRequest(); +private: ConnectionData prepareOpenVpnConfig(const ServerCredentials &credentials, DockerContainer container, ErrorCode *errorCode = nullptr); diff --git a/client/configurators/shadowsocks_configurator.cpp b/client/configurators/shadowsocks_configurator.cpp index a71064c8..99e4158c 100644 --- a/client/configurators/shadowsocks_configurator.cpp +++ b/client/configurators/shadowsocks_configurator.cpp @@ -5,7 +5,7 @@ #include #include "containers/containers_defs.h" -#include "core/servercontroller.h" +#include "core/controllers/serverController.h" ShadowSocksConfigurator::ShadowSocksConfigurator(std::shared_ptr settings, QObject *parent): ConfiguratorBase(settings, parent) diff --git a/client/configurators/wireguard_configurator.cpp b/client/configurators/wireguard_configurator.cpp index 14059977..7b7d94d2 100644 --- a/client/configurators/wireguard_configurator.cpp +++ b/client/configurators/wireguard_configurator.cpp @@ -15,7 +15,7 @@ #include "containers/containers_defs.h" #include "core/scripts_registry.h" #include "core/server_defs.h" -#include "core/servercontroller.h" +#include "core/controllers/serverController.h" #include "settings.h" #include "utilities.h" diff --git a/client/containers/containers_defs.cpp b/client/containers/containers_defs.cpp index 20fc59f4..d2231415 100644 --- a/client/containers/containers_defs.cpp +++ b/client/containers/containers_defs.cpp @@ -54,7 +54,7 @@ QVector ContainerProps::protocolsForContainer(amnezia::DockerCon case DockerContainer::ShadowSocks: return { Proto::OpenVpn, Proto::ShadowSocks }; - case DockerContainer::Cloak: return { Proto::OpenVpn, Proto::ShadowSocks, Proto::Cloak }; + case DockerContainer::Cloak: return { Proto::OpenVpn, /*Proto::ShadowSocks,*/ Proto::Cloak }; case DockerContainer::Ipsec: return { Proto::Ikev2 /*, Protocol::L2tp */ }; diff --git a/client/core/servercontroller.cpp b/client/core/controllers/serverController.cpp similarity index 99% rename from client/core/servercontroller.cpp rename to client/core/controllers/serverController.cpp index b0f8146f..96306a58 100644 --- a/client/core/servercontroller.cpp +++ b/client/core/controllers/serverController.cpp @@ -24,8 +24,8 @@ #include "containers/containers_defs.h" #include "logger.h" -#include "scripts_registry.h" -#include "server_defs.h" +#include "core/scripts_registry.h" +#include "core/server_defs.h" #include "settings.h" #include "utilities.h" diff --git a/client/core/servercontroller.h b/client/core/controllers/serverController.h similarity index 98% rename from client/core/servercontroller.h rename to client/core/controllers/serverController.h index 3191386c..ea6fd001 100644 --- a/client/core/servercontroller.h +++ b/client/core/controllers/serverController.h @@ -5,8 +5,8 @@ #include #include "containers/containers_defs.h" -#include "defs.h" -#include "sshclient.h" +#include "core/defs.h" +#include "core/sshclient.h" class Settings; class VpnConfigurator; diff --git a/client/core/errorstrings.cpp b/client/core/errorstrings.cpp index cd66186d..44135bae 100644 --- a/client/core/errorstrings.cpp +++ b/client/core/errorstrings.cpp @@ -58,7 +58,7 @@ QString errorString(ErrorCode code){ case (OpenVpnTapAdapterError): return QObject::tr("Can't setup OpenVPN TAP network adapter"); case (AddressPoolError): return QObject::tr("VPN pool error: no available addresses"); - case (ImportInvalidConfigError): return QObject::tr("The config does not contain any containers and credentiaks for connecting to the server"); + case (ImportInvalidConfigError): return QObject::tr("The config does not contain any containers and credentials for connecting to the server"); case(InternalError): default: diff --git a/client/protocols/openvpnprotocol.cpp b/client/protocols/openvpnprotocol.cpp index c38c6eea..f91cfe09 100644 --- a/client/protocols/openvpnprotocol.cpp +++ b/client/protocols/openvpnprotocol.cpp @@ -214,7 +214,7 @@ ErrorCode OpenVpnProtocol::start() m_openVpnProcess->setProgram(PermittedProcess::OpenVPN); QStringList arguments({ "--config", configPath(), "--management", m_managementHost, QString::number(mgmtPort), - "--management-client" /*, "--log", vpnLogFileNamePath */ + "--management-client" , "--log", "/Users/nethius/Documents/git/log" }); m_openVpnProcess->setArguments(arguments); diff --git a/client/protocols/protocols_defs.h b/client/protocols/protocols_defs.h index 9472164b..fa326b2a 100644 --- a/client/protocols/protocols_defs.h +++ b/client/protocols/protocols_defs.h @@ -67,7 +67,13 @@ namespace amnezia constexpr char cloak[] = "cloak"; constexpr char sftp[] = "sftp"; - } + constexpr char configVersion[] = "config_version"; + constexpr char apiEdnpoint[] = "api_endpoint"; + constexpr char serviceTypeId[] = "service_type_id"; + constexpr char accessToken[] = "access_token"; + constexpr char certificate[] = "certificate"; + constexpr char publicKey[] = "public_key"; + } namespace protocols { diff --git a/client/translations/amneziavpn_ru.ts b/client/translations/amneziavpn_ru.ts index e0bab018..20a7f022 100644 --- a/client/translations/amneziavpn_ru.ts +++ b/client/translations/amneziavpn_ru.ts @@ -23,44 +23,52 @@ + + CloudController + + + Error when retrieving configuration from cloud server + + + ConnectionController - + VPN Protocols is not installed. Please install VPN container at first - + Connection... - + Connected - + Settings updated successfully, Reconnnection... - + Reconnection... - - - + + + Connect - + Disconnection... @@ -130,7 +138,7 @@ ImportController - + Scanned %1 of %2. @@ -139,50 +147,55 @@ InstallController - + %1 installed successfully. - + %1 is already installed on the server. - + +Added containers that were already installed on the server + + + + Already installed containers were found on the server. All installed containers have been added to the application - + Settings updated successfully - + Server '%1' was removed - + All containers from server '%1' have been removed - + %1 has been removed from the server '%2' - + Please login as the user - + Server added successfully @@ -250,12 +263,12 @@ Already installed containers were found on the server. All installed containers PageHome - + VPN protocol - + Servers @@ -865,71 +878,76 @@ And if you don't like the app, all the more support it - the donation will + Allow application screenshots + + + + Auto start - + Launch the application every time - + starts - + Start minimized - + Launch application minimized - + Language - + Logging - + Enabled - + Disabled - + Reset settings and remove all data from the application - + Reset settings and remove all data from the application? - + All settings will be reset to default. All installed AmneziaVPN services will still remain on the server. - + Continue Продолжить - + Cancel @@ -1525,17 +1543,17 @@ It's okay as long as it's from someone you trust. PageSetupWizardEasy - + What is the level of internet control in your region? - + Set up a VPN yourself - + I want to choose a VPN protocol @@ -1545,7 +1563,7 @@ It's okay as long as it's from someone you trust. Продолжить - + Set up later @@ -1765,13 +1783,17 @@ It's okay as long as it's from someone you trust. - + + File with accessing settings to + + + + Connection to - - + File with connection settings to @@ -1801,23 +1823,19 @@ It's okay as long as it's from someone you trust. - - Protocols - - - - + + Protocol - - + + Connection format - + Share @@ -2264,7 +2282,7 @@ It's okay as long as it's from someone you trust. - The config does not contain any containers and credentiaks for connecting to the server + The config does not contain any containers and credentials for connecting to the server @@ -2433,6 +2451,16 @@ It's okay as long as it's from someone you trust. error 0x%1: %2 + + + WireGuard Configuration Highlighter + + + + + &Randomize colors + + SelectLanguageDrawer @@ -2459,22 +2487,22 @@ It's okay as long as it's from someone you trust. SettingsController - + Software version - + All settings have been reset to default values - + Cached profiles cleared - + Backup file is corrupted @@ -2504,7 +2532,7 @@ It's okay as long as it's from someone you trust. - Show content + Show connection settings @@ -2592,7 +2620,7 @@ It's okay as long as it's from someone you trust. VpnConnection - + Mbps diff --git a/client/translations/amneziavpn_zh_CN.ts b/client/translations/amneziavpn_zh_CN.ts index 37e27786..109ad9c8 100644 --- a/client/translations/amneziavpn_zh_CN.ts +++ b/client/translations/amneziavpn_zh_CN.ts @@ -23,44 +23,52 @@ VPN已连接 + + CloudController + + + Error when retrieving configuration from cloud server + + + ConnectionController - - - + + + Connect 连接 - + VPN Protocols is not installed. Please install VPN container at first 不存在VPN协议,请先安装 - + Connection... 连接中 - + Connected 已连接 - + Reconnection... 重连中 - + Disconnection... 断开中 - + Settings updated successfully, Reconnnection... 配置已更新,重连中 @@ -130,7 +138,7 @@ ImportController - + Scanned %1 of %2. 扫描 %1 of %2. @@ -147,41 +155,46 @@ - + %1 installed successfully. %1 安装成功。 - + %1 is already installed on the server. 服务器上已经安装 %1。 - + +Added containers that were already installed on the server + + + + Already installed containers were found on the server. All installed containers have been added to the application 在服务上发现已经安装协议并添加到应用程序 - + Settings updated successfully 配置更新成功 - + Server '%1' was removed 已移除服务器 '%1' - + All containers from server '%1' have been removed 服务器 '%1' 的所有容器已移除 - + %1 has been removed from the server '%2' %1 已从服务器 '%2' 上移除 @@ -202,12 +215,12 @@ Already installed containers were found on the server. All installed containers 协议已从 - + Please login as the user 请以用户身份登录 - + Server added successfully 服务器添加成功 @@ -275,12 +288,12 @@ Already installed containers were found on the server. All installed containers PageHome - + VPN protocol VPN协议 - + Servers 服务器 @@ -892,71 +905,76 @@ And if you don't like the app, all the more support it - the donation will + Allow application screenshots + + + + Auto start 自动运行 - + Launch the application every time 总是在系统 - + starts 启动时自动运行运用程序 - + Start minimized 最小化 - + Launch application minimized 开启应用程序时窗口最小化 - + Language 语言 - + Logging 日志 - + Enabled 开启 - + Disabled 禁用 - + Reset settings and remove all data from the application 重置并清理应用的所有数据 - + Reset settings and remove all data from the application? 重置并清理应用的所有数据? - + All settings will be reset to default. All installed AmneziaVPN services will still remain on the server. 所有配置恢复为默认值。在服务器上保留所有已安装的AmneziaVPN服务。 - + Continue 继续 - + Cancel 取消 @@ -1561,17 +1579,17 @@ It's okay as long as it's from someone you trust. PageSetupWizardEasy - + What is the level of internet control in your region? 您所在地区的互联网控制力度如何? - + Set up a VPN yourself 自己架设VPN - + I want to choose a VPN protocol 我想选择VPN协议 @@ -1581,7 +1599,7 @@ It's okay as long as it's from someone you trust. 继续 - + Set up later 稍后设置 @@ -1827,33 +1845,37 @@ It's okay as long as it's from someone you trust. - + File with accessing settings to + + + + File with connection settings to 连接配置文件的内容为: - Protocols - 协议 + 协议 - + + Protocol 协议 - + Connection to 连接到 - - + + Connection format 连接方式 - + Share 共享 @@ -2305,8 +2327,12 @@ It's okay as long as it's from someone you trust. + The config does not contain any containers and credentials for connecting to the server + + + The config does not contain any containers and credentiaks for connecting to the server - 该配置不包含任何用于连接到服务器的容器和凭据。 + 该配置不包含任何用于连接到服务器的容器和凭据。 @@ -2469,6 +2495,16 @@ It's okay as long as it's from someone you trust. error 0x%1: %2 错误 0x%1: %2 + + + WireGuard Configuration Highlighter + + + + + &Randomize colors + + SelectLanguageDrawer @@ -2495,22 +2531,22 @@ It's okay as long as it's from someone you trust. SettingsController - + Software version 软件版本 - + Backup file is corrupted 备份文件已损坏 - + All settings have been reset to default values 所配置恢复为默认值 - + Cached profiles cleared 缓存的配置文件已清除 @@ -2540,8 +2576,12 @@ It's okay as long as it's from someone you trust. + Show connection settings + + + Show content - 展示内容 + 展示内容 @@ -2628,7 +2668,7 @@ It's okay as long as it's from someone you trust. VpnConnection - + Mbps diff --git a/client/ui/controllers/cloudController.cpp b/client/ui/controllers/cloudController.cpp new file mode 100644 index 00000000..99309d90 --- /dev/null +++ b/client/ui/controllers/cloudController.cpp @@ -0,0 +1,109 @@ +#include "cloudController.h" + +#include +#include +#include + +#include "configurators/openvpn_configurator.h" + +CloudController::CloudController(const QSharedPointer &serversModel, + const QSharedPointer &containersModel, QObject *parent) + : QObject(parent), m_serversModel(serversModel), m_containersModel(containersModel) +{ +} + +QString CloudController::genPublicKey(ServiceTypeId serviceTypeId) +{ + switch (serviceTypeId) + { + case ServiceTypeId::AmneziaFreeRuWG: return "."; + case ServiceTypeId::AmneziaFreeRuCloak: return "."; + case ServiceTypeId::AmneziaFreeRuAWG: return "."; + case ServiceTypeId::AmneziaFreeRuReverseWG: return "."; + case ServiceTypeId::AmneziaFreeRuReverseCloak: return "."; + case ServiceTypeId::AmneziaFreeRuReverseAWG: return "."; + } +} + +QString CloudController::genCertificateRequest(ServiceTypeId serviceTypeId) +{ + switch (serviceTypeId) + { + case ServiceTypeId::AmneziaFreeRuWG: return ""; + case ServiceTypeId::AmneziaFreeRuCloak: { + auto data = OpenVpnConfigurator::createCertRequest(); + return data.request; + } + case ServiceTypeId::AmneziaFreeRuAWG: return ""; + case ServiceTypeId::AmneziaFreeRuReverseWG: return ""; + case ServiceTypeId::AmneziaFreeRuReverseCloak: return ""; + case ServiceTypeId::AmneziaFreeRuReverseAWG: return ""; + } +} + +bool CloudController::updateServerConfigFromCloud() +{ + auto serverConfig = m_serversModel->getDefaultServerConfig(); + + auto containerConfig = serverConfig.value(config_key::containers).toArray(); + + if (serverConfig.value(config_key::configVersion).toInt() && containerConfig.isEmpty()) { + QNetworkAccessManager manager; + + QNetworkRequest request; + request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json"); + QString endpoint = serverConfig.value(config_key::apiEdnpoint).toString(); + request.setUrl(endpoint.replace("https", "http")); // + + ServiceTypeId serviceTypeId = static_cast(serverConfig.value(config_key::serviceTypeId).toInt()); + + QJsonObject obj; + obj[config_key::serviceTypeId] = serviceTypeId; + obj[config_key::accessToken] = serverConfig.value(config_key::accessToken); + + obj[config_key::publicKey] = genPublicKey(serviceTypeId); + obj[config_key::certificate] = genCertificateRequest(serviceTypeId); + + QByteArray requestBody = QJsonDocument(obj).toJson(); + + QScopedPointer reply; + reply.reset(manager.post(request, requestBody)); + + QEventLoop wait; + QObject::connect(reply.get(), &QNetworkReply::finished, &wait, &QEventLoop::quit); + wait.exec(); + + if(reply->error() == QNetworkReply::NoError){ + QString contents = QString::fromUtf8(reply->readAll()); + auto data = QJsonDocument::fromJson(contents.toUtf8()).object().value(config_key::config).toString(); + + data.replace("vpn://", ""); + QByteArray ba = QByteArray::fromBase64(data.toUtf8(), QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals); + + QByteArray ba_uncompressed = qUncompress(ba); + if (!ba_uncompressed.isEmpty()) { + ba = ba_uncompressed; + } + + QJsonObject cloudConfig = QJsonDocument::fromJson(ba).object(); + serverConfig.insert("cloudConfig", cloudConfig); + serverConfig.insert(config_key::dns1, cloudConfig.value(config_key::dns1)); + serverConfig.insert(config_key::dns2, cloudConfig.value(config_key::dns2)); + serverConfig.insert(config_key::containers, cloudConfig.value(config_key::containers)); + serverConfig.insert(config_key::hostName, cloudConfig.value(config_key::hostName)); + serverConfig.insert(config_key::defaultContainer, cloudConfig.value(config_key::defaultContainer)); + m_serversModel->editServer(serverConfig); + emit serverConfigUpdated(); + } else{ + QString err = reply->errorString(); + qDebug() << reply->error(); + qDebug() << err; + qDebug() << reply->attribute(QNetworkRequest::HttpStatusCodeAttribute); + emit errorOccurred(tr("Error when retrieving configuration from cloud server")); + return false; + } + + } + + return true; +} diff --git a/client/ui/controllers/cloudController.h b/client/ui/controllers/cloudController.h new file mode 100644 index 00000000..409e0981 --- /dev/null +++ b/client/ui/controllers/cloudController.h @@ -0,0 +1,43 @@ +#ifndef CLOUDCONTROLLER_H +#define CLOUDCONTROLLER_H + +#include + +#include "ui/models/containers_model.h" +#include "ui/models/servers_model.h" + +class CloudController : public QObject +{ + Q_OBJECT + + enum ServiceTypeId + { + AmneziaFreeRuWG = 0, + AmneziaFreeRuCloak, + AmneziaFreeRuAWG, + AmneziaFreeRuReverseWG, + AmneziaFreeRuReverseCloak, + AmneziaFreeRuReverseAWG + + }; + +public: + explicit CloudController(const QSharedPointer &serversModel, + const QSharedPointer &containersModel, QObject *parent = nullptr); + +public slots: + bool updateServerConfigFromCloud(); + +signals: + void errorOccurred(const QString &errorMessage); + void serverConfigUpdated(); + +private: + QString genPublicKey(ServiceTypeId serviceTypeId); + QString genCertificateRequest(ServiceTypeId serviceTypeId); + + QSharedPointer m_serversModel; + QSharedPointer m_containersModel; +}; + +#endif // CLOUDCONTROLLER_H diff --git a/client/ui/controllers/connectionController.cpp b/client/ui/controllers/connectionController.cpp index 74438dcc..de05d624 100644 --- a/client/ui/controllers/connectionController.cpp +++ b/client/ui/controllers/connectionController.cpp @@ -40,6 +40,7 @@ void ConnectionController::openConnection() } qApp->processEvents(); + emit connectToVpn(serverIndex, credentials, container, containerConfig); } diff --git a/client/ui/controllers/importController.cpp b/client/ui/controllers/importController.cpp index aaea8db3..8198a5a1 100644 --- a/client/ui/controllers/importController.cpp +++ b/client/ui/controllers/importController.cpp @@ -141,7 +141,9 @@ void ImportController::importConfig() credentials.userName = m_config.value(config_key::userName).toString(); credentials.secretData = m_config.value(config_key::password).toString(); - if (credentials.isValid() || m_config.contains(config_key::containers)) { + if (credentials.isValid() + || m_config.contains(config_key::containers) + || m_config.contains(config_key::configVersion)) { // todo m_serversModel->addServer(m_config); m_serversModel->setDefaultServerIndex(m_serversModel->getServersCount() - 1); @@ -167,7 +169,11 @@ QJsonObject ImportController::extractAmneziaConfig(QString &data) ba = ba_uncompressed; } - return QJsonDocument::fromJson(ba).object(); + QJsonObject config = QJsonDocument::fromJson(ba).object(); + + qDebug() << config; + + return config; } QJsonObject ImportController::extractOpenVpnConfig(const QString &data) diff --git a/client/ui/controllers/installController.cpp b/client/ui/controllers/installController.cpp index 72cc34b6..4885aa80 100644 --- a/client/ui/controllers/installController.cpp +++ b/client/ui/controllers/installController.cpp @@ -7,7 +7,7 @@ #include #include "core/errorstrings.h" -#include "core/servercontroller.h" +#include "core/controllers/serverController.h" #include "utilities.h" namespace diff --git a/client/ui/models/containers_model.cpp b/client/ui/models/containers_model.cpp index 6cf855a6..0ffdc00b 100644 --- a/client/ui/models/containers_model.cpp +++ b/client/ui/models/containers_model.cpp @@ -1,6 +1,6 @@ #include "containers_model.h" -#include "core/servercontroller.h" +#include "core/controllers/serverController.h" ContainersModel::ContainersModel(std::shared_ptr settings, QObject *parent) : m_settings(settings), QAbstractListModel(parent) diff --git a/client/ui/models/servers_model.cpp b/client/ui/models/servers_model.cpp index 7eea94e5..e0fe0787 100644 --- a/client/ui/models/servers_model.cpp +++ b/client/ui/models/servers_model.cpp @@ -168,6 +168,14 @@ void ServersModel::addServer(const QJsonObject &server) endResetModel(); } +void ServersModel::editServer(const QJsonObject &server) +{ + beginResetModel(); + m_settings->editServer(m_currentlyProcessedServerIndex, server); + m_servers = m_settings->serversArray(); + endResetModel(); +} + void ServersModel::removeServer() { beginResetModel(); @@ -219,3 +227,8 @@ ServerCredentials ServersModel::serverCredentials(int index) const return credentials; } + +QJsonObject ServersModel::getDefaultServerConfig() +{ + return m_servers.at(m_defaultServerIndex).toObject(); +} diff --git a/client/ui/models/servers_model.h b/client/ui/models/servers_model.h index d7b15844..feff3ec8 100644 --- a/client/ui/models/servers_model.h +++ b/client/ui/models/servers_model.h @@ -55,10 +55,13 @@ public slots: QString getCurrentlyProcessedServerHostName(); void addServer(const QJsonObject &server); + void editServer(const QJsonObject &server); void removeServer(); bool isDefaultServerConfigContainsAmneziaDns(); + QJsonObject getDefaultServerConfig(); + protected: QHash roleNames() const override; diff --git a/client/ui/qml/Components/ConnectButton.qml b/client/ui/qml/Components/ConnectButton.qml index 76e83da5..2fdcb9b2 100644 --- a/client/ui/qml/Components/ConnectButton.qml +++ b/client/ui/qml/Components/ConnectButton.qml @@ -138,6 +138,10 @@ Button { } onClicked: { + if (!CloudController.updateServerConfigFromCloud()) { + return + } + if (!ContainersModel.isAnyContainerInstalled()) { PageController.setTriggeredBtConnectButton(true) diff --git a/client/vpnconnection.cpp b/client/vpnconnection.cpp index 1cff01e6..5cc6a6a0 100644 --- a/client/vpnconnection.cpp +++ b/client/vpnconnection.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include "core/controllers/serverController.h" #ifdef AMNEZIA_DESKTOP #include "core/ipcclient.h" @@ -258,9 +258,7 @@ QJsonObject VpnConnection::createVpnConfiguration(int serverIndex, const ServerC for (ProtocolEnumNS::Proto proto : ContainerProps::protocolsForContainer(container)) { QJsonObject vpnConfigData = QJsonDocument::fromJson(createVpnConfigurationForProto(serverIndex, credentials, container, - containerConfig, proto, errorCode) - .toUtf8()) - .object(); + containerConfig, proto, errorCode).toUtf8()).object(); if (errorCode && *errorCode) { return {};