mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-22 02:01:08 +07:00
refactor: remove serverConfig struct (#2595)
* refactor: remove serverConfig struct * refactor: add warnings for api v1 configs * refactor: moved the server type definition to a separate namespace * refactor: simplified gateway stacks * fix: fixed server description * fix: fixed postAsync reply usage * fix: fixed validateConfig call * fix: fixed server name in notifications * fix: fixed initPrepareConfigHandler for lagacy configs
This commit is contained in:
@@ -2,14 +2,13 @@
|
||||
|
||||
#include "amneziaApplication.h"
|
||||
#include "core/configurators/wireguardConfigurator.h"
|
||||
#include "core/utils/api/apiEnums.h"
|
||||
#include "core/utils/serverConfigUtils.h"
|
||||
#include "core/utils/constants/apiKeys.h"
|
||||
#include "core/utils/constants/apiConstants.h"
|
||||
#include "core/utils/api/apiUtils.h"
|
||||
#include "core/utils/qrCodeUtils.h"
|
||||
#include "ui/controllers/systemController.h"
|
||||
#include "version.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include <QClipboard>
|
||||
#include <QDebug>
|
||||
#include <QSet>
|
||||
@@ -67,7 +66,17 @@ SubscriptionUiController::SubscriptionUiController(ServersController* serversCon
|
||||
ApiDevicesModel* apiDevicesModel,
|
||||
SettingsController* settingsController,
|
||||
QObject *parent)
|
||||
: QObject(parent), m_serversController(serversController), m_apiServicesModel(apiServicesModel), m_servicesCatalogController(servicesCatalogController), m_subscriptionController(subscriptionController), m_apiSubscriptionPlansModel(apiSubscriptionPlansModel), m_apiBenefitsModel(apiBenefitsModel), m_apiAccountInfoModel(apiAccountInfoModel), m_apiCountryModel(apiCountryModel), m_apiDevicesModel(apiDevicesModel), m_settingsController(settingsController)
|
||||
: QObject(parent),
|
||||
m_serversController(serversController),
|
||||
m_apiServicesModel(apiServicesModel),
|
||||
m_servicesCatalogController(servicesCatalogController),
|
||||
m_subscriptionController(subscriptionController),
|
||||
m_apiSubscriptionPlansModel(apiSubscriptionPlansModel),
|
||||
m_apiBenefitsModel(apiBenefitsModel),
|
||||
m_apiAccountInfoModel(apiAccountInfoModel),
|
||||
m_apiCountryModel(apiCountryModel),
|
||||
m_apiDevicesModel(apiDevicesModel),
|
||||
m_settingsController(settingsController)
|
||||
{
|
||||
connect(m_apiServicesModel, &ApiServicesModel::serviceSelectionChanged, this, [this]() {
|
||||
ApiServicesModel::ApiServicesData selectedServiceData = m_apiServicesModel->selectedServiceData();
|
||||
@@ -76,14 +85,14 @@ SubscriptionUiController::SubscriptionUiController(ServersController* serversCon
|
||||
});
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::exportVpnKey(int serverIndex, const QString &fileName)
|
||||
bool SubscriptionUiController::exportVpnKey(const QString &serverId, const QString &fileName)
|
||||
{
|
||||
if (fileName.isEmpty()) {
|
||||
emit errorOccurred(ErrorCode::PermissionsError);
|
||||
return false;
|
||||
}
|
||||
|
||||
prepareVpnKeyExport(serverIndex);
|
||||
prepareVpnKeyExport(serverId);
|
||||
if (m_vpnKey.isEmpty()) {
|
||||
emit errorOccurred(ErrorCode::ApiConfigEmptyError);
|
||||
return false;
|
||||
@@ -93,7 +102,8 @@ bool SubscriptionUiController::exportVpnKey(int serverIndex, const QString &file
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::exportNativeConfig(int serverIndex, const QString &serverCountryCode, const QString &fileName)
|
||||
|
||||
bool SubscriptionUiController::exportNativeConfig(const QString &serverId, const QString &serverCountryCode, const QString &fileName)
|
||||
{
|
||||
if (fileName.isEmpty()) {
|
||||
emit errorOccurred(ErrorCode::PermissionsError);
|
||||
@@ -101,7 +111,7 @@ bool SubscriptionUiController::exportNativeConfig(int serverIndex, const QString
|
||||
}
|
||||
|
||||
QString nativeConfig;
|
||||
ErrorCode errorCode = m_subscriptionController->exportNativeConfig(serverIndex, serverCountryCode, nativeConfig);
|
||||
ErrorCode errorCode = m_subscriptionController->exportNativeConfig(serverId, serverCountryCode, nativeConfig);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit errorOccurred(errorCode);
|
||||
return false;
|
||||
@@ -111,9 +121,10 @@ bool SubscriptionUiController::exportNativeConfig(int serverIndex, const QString
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::revokeNativeConfig(int serverIndex, const QString &serverCountryCode)
|
||||
|
||||
bool SubscriptionUiController::revokeNativeConfig(const QString &serverId, const QString &serverCountryCode)
|
||||
{
|
||||
ErrorCode errorCode = m_subscriptionController->revokeNativeConfig(serverIndex, serverCountryCode);
|
||||
ErrorCode errorCode = m_subscriptionController->revokeNativeConfig(serverId, serverCountryCode);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit errorOccurred(errorCode);
|
||||
return false;
|
||||
@@ -121,10 +132,11 @@ bool SubscriptionUiController::revokeNativeConfig(int serverIndex, const QString
|
||||
return true;
|
||||
}
|
||||
|
||||
void SubscriptionUiController::prepareVpnKeyExport(int serverIndex)
|
||||
|
||||
void SubscriptionUiController::prepareVpnKeyExport(const QString &serverId)
|
||||
{
|
||||
QString vpnKey;
|
||||
ErrorCode errorCode = m_subscriptionController->prepareVpnKeyExport(serverIndex, vpnKey);
|
||||
ErrorCode errorCode = m_subscriptionController->prepareVpnKeyExport(serverId, vpnKey);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit errorOccurred(errorCode);
|
||||
return;
|
||||
@@ -140,6 +152,7 @@ void SubscriptionUiController::prepareVpnKeyExport(int serverIndex)
|
||||
emit vpnKeyExportReady();
|
||||
}
|
||||
|
||||
|
||||
void SubscriptionUiController::copyVpnKeyToClipboard()
|
||||
{
|
||||
auto clipboard = amnApp->getClipboard();
|
||||
@@ -170,14 +183,12 @@ bool SubscriptionUiController::importPremiumFromAppStore(const QString &storePro
|
||||
productId = QStringLiteral("amnezia_premium_6_month");
|
||||
}
|
||||
|
||||
ServerConfig serverConfig;
|
||||
int duplicateServerIndex = -1;
|
||||
ErrorCode errorCode = m_subscriptionController->processAppStorePurchase(
|
||||
m_apiServicesModel->getCountryCode(),
|
||||
m_apiServicesModel->getSelectedServiceType(),
|
||||
m_apiServicesModel->getSelectedServiceProtocol(),
|
||||
productId,
|
||||
serverConfig,
|
||||
&duplicateServerIndex);
|
||||
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
@@ -260,11 +271,8 @@ bool SubscriptionUiController::importFreeFromGateway()
|
||||
}
|
||||
|
||||
SubscriptionController::ProtocolData protocolData = m_subscriptionController->generateProtocolData(serviceProtocol);
|
||||
|
||||
ServerConfig serverConfig;
|
||||
ErrorCode errorCode = m_subscriptionController->importServiceFromGateway(userCountryCode, serviceType,
|
||||
serviceProtocol, protocolData,
|
||||
serverConfig);
|
||||
serviceProtocol, protocolData);
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
emit installServerFromApiFinished(tr("%1 installed successfully.").arg(m_apiServicesModel->getSelectedServiceName()));
|
||||
@@ -278,12 +286,10 @@ bool SubscriptionUiController::importFreeFromGateway()
|
||||
bool SubscriptionUiController::importTrialFromGateway(const QString &email)
|
||||
{
|
||||
emit trialEmailError(QString());
|
||||
ServerConfig serverConfig;
|
||||
ErrorCode errorCode = m_subscriptionController->importTrialFromGateway(m_apiServicesModel->getCountryCode(),
|
||||
m_apiServicesModel->getSelectedServiceType(),
|
||||
m_apiServicesModel->getSelectedServiceProtocol(),
|
||||
email,
|
||||
serverConfig);
|
||||
email);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
if (errorCode == ErrorCode::ApiTrialAlreadyUsedError) {
|
||||
emit trialEmailError(
|
||||
@@ -298,21 +304,17 @@ bool SubscriptionUiController::importTrialFromGateway(const QString &email)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::updateServiceFromGateway(const int serverIndex, const QString &newCountryCode, const QString &newCountryName,
|
||||
bool SubscriptionUiController::updateServiceFromGateway(const QString &serverId, const QString &newCountryCode, const QString &newCountryName,
|
||||
bool reloadServiceConfig)
|
||||
{
|
||||
bool isConnectEvent = newCountryCode.isEmpty() && newCountryName.isEmpty() && !reloadServiceConfig;
|
||||
bool wasSubscriptionExpired = false;
|
||||
ServerConfig oldServerConfig = m_serversController->getServerConfig(serverIndex);
|
||||
if (oldServerConfig.isApiV2()) {
|
||||
const ApiV2ServerConfig *oldApiV2 = oldServerConfig.as<ApiV2ServerConfig>();
|
||||
if (oldApiV2) {
|
||||
wasSubscriptionExpired = oldApiV2->apiConfig.subscriptionExpiredByServer
|
||||
|| oldApiV2->apiConfig.isSubscriptionExpired();
|
||||
}
|
||||
if (const auto oldApiV2 = m_serversController->apiV2Config(serverId)) {
|
||||
wasSubscriptionExpired = oldApiV2->apiConfig.subscriptionExpiredByServer
|
||||
|| oldApiV2->apiConfig.isSubscriptionExpired();
|
||||
}
|
||||
|
||||
ErrorCode errorCode = m_subscriptionController->updateServiceFromGateway(serverIndex, newCountryCode, isConnectEvent);
|
||||
ErrorCode errorCode = m_subscriptionController->updateServiceFromGateway(serverId, newCountryCode, isConnectEvent);
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
if (wasSubscriptionExpired) {
|
||||
@@ -336,27 +338,10 @@ bool SubscriptionUiController::updateServiceFromGateway(const int serverIndex, c
|
||||
}
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::updateServiceFromTelegram(const int serverIndex)
|
||||
|
||||
bool SubscriptionUiController::deactivateDevice(const QString &serverId)
|
||||
{
|
||||
#ifdef Q_OS_IOS
|
||||
IosController::Instance()->requestInetAccess();
|
||||
QThread::msleep(10);
|
||||
#endif
|
||||
|
||||
ErrorCode errorCode = m_subscriptionController->updateServiceFromTelegram(serverIndex);
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
emit updateServerFromApiFinished();
|
||||
return true;
|
||||
} else {
|
||||
emit errorOccurred(errorCode);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::deactivateDevice(int serverIndex)
|
||||
{
|
||||
ErrorCode errorCode = m_subscriptionController->deactivateDevice(serverIndex);
|
||||
ErrorCode errorCode = m_subscriptionController->deactivateDevice(serverId);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit errorOccurred(errorCode);
|
||||
return false;
|
||||
@@ -365,9 +350,10 @@ bool SubscriptionUiController::deactivateDevice(int serverIndex)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::deactivateExternalDevice(int serverIndex, const QString &uuid, const QString &serverCountryCode)
|
||||
|
||||
bool SubscriptionUiController::deactivateExternalDevice(const QString &serverId, const QString &uuid, const QString &serverCountryCode)
|
||||
{
|
||||
ErrorCode errorCode = m_subscriptionController->deactivateExternalDevice(serverIndex, uuid, serverCountryCode);
|
||||
ErrorCode errorCode = m_subscriptionController->deactivateExternalDevice(serverId, uuid, serverCountryCode);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit errorOccurred(errorCode);
|
||||
return false;
|
||||
@@ -376,12 +362,19 @@ bool SubscriptionUiController::deactivateExternalDevice(int serverIndex, const Q
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void SubscriptionUiController::validateConfig()
|
||||
{
|
||||
int serverIndex = m_serversController->getDefaultServerIndex();
|
||||
bool hasInstalledContainers = m_serversController->hasInstalledContainers(serverIndex);
|
||||
const QString serverId = m_serversController->getDefaultServerId();
|
||||
if (!serverId.isEmpty() && m_serversController->isLegacyApiV1Server(serverId)) {
|
||||
emit unsupportedConnectDrawerRequested();
|
||||
emit configValidated(false);
|
||||
return;
|
||||
}
|
||||
|
||||
ErrorCode errorCode = m_subscriptionController->validateAndUpdateConfig(serverIndex, hasInstalledContainers);
|
||||
bool hasInstalledContainers = m_serversController->hasInstalledContainers(serverId);
|
||||
|
||||
ErrorCode errorCode = m_subscriptionController->validateAndUpdateConfig(serverId, hasInstalledContainers);
|
||||
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
if (errorCode == ErrorCode::ApiSubscriptionExpiredError) {
|
||||
@@ -395,22 +388,25 @@ void SubscriptionUiController::validateConfig()
|
||||
emit configValidated(true);
|
||||
}
|
||||
|
||||
void SubscriptionUiController::setCurrentProtocol(int serverIndex, const QString &protocolName)
|
||||
void SubscriptionUiController::setCurrentProtocol(const QString &serverId, const QString &protocolName)
|
||||
{
|
||||
m_subscriptionController->setCurrentProtocol(serverIndex, protocolName);
|
||||
m_subscriptionController->setCurrentProtocol(serverId, protocolName);
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::isVlessProtocol(int serverIndex)
|
||||
|
||||
bool SubscriptionUiController::isVlessProtocol(const QString &serverId)
|
||||
{
|
||||
return m_subscriptionController->isVlessProtocol(serverIndex);
|
||||
return m_subscriptionController->isVlessProtocol(serverId);
|
||||
}
|
||||
|
||||
void SubscriptionUiController::removeApiConfig(int serverIndex)
|
||||
|
||||
void SubscriptionUiController::removeApiConfig(const QString &serverId)
|
||||
{
|
||||
m_subscriptionController->removeApiConfig(serverIndex);
|
||||
m_subscriptionController->removeApiConfig(serverId);
|
||||
emit apiConfigRemoved(tr("Api config removed"));
|
||||
}
|
||||
|
||||
|
||||
QList<QString> SubscriptionUiController::getQrCodes()
|
||||
{
|
||||
return m_qrCodes;
|
||||
@@ -426,7 +422,7 @@ QString SubscriptionUiController::getVpnKey()
|
||||
return m_vpnKey;
|
||||
}
|
||||
|
||||
bool SubscriptionUiController::getAccountInfo(int serverIndex, bool reload)
|
||||
bool SubscriptionUiController::getAccountInfo(const QString &serverId, bool reload)
|
||||
{
|
||||
if (reload) {
|
||||
QEventLoop wait;
|
||||
@@ -434,15 +430,18 @@ bool SubscriptionUiController::getAccountInfo(int serverIndex, bool reload)
|
||||
wait.exec(QEventLoop::ExcludeUserInputEvents);
|
||||
}
|
||||
QJsonObject accountInfo;
|
||||
ErrorCode errorCode = m_subscriptionController->getAccountInfo(serverIndex, accountInfo);
|
||||
ErrorCode errorCode = m_subscriptionController->getAccountInfo(serverId, accountInfo);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit errorOccurred(errorCode);
|
||||
return false;
|
||||
}
|
||||
|
||||
ServerConfig serverConfig = m_serversController->getServerConfig(serverIndex);
|
||||
QJsonObject serverConfigJson = serverConfig.toJson();
|
||||
m_apiAccountInfoModel->updateModel(accountInfo, serverConfigJson);
|
||||
const auto apiV2 = m_serversController->apiV2Config(serverId);
|
||||
if (!apiV2.has_value()) {
|
||||
emit errorOccurred(ErrorCode::InternalError);
|
||||
return false;
|
||||
}
|
||||
m_apiAccountInfoModel->updateModel(accountInfo, apiV2->toJson());
|
||||
|
||||
if (reload) {
|
||||
updateApiCountryModel();
|
||||
@@ -463,9 +462,9 @@ void SubscriptionUiController::updateApiDevicesModel()
|
||||
m_apiDevicesModel->updateModel(m_apiAccountInfoModel->getIssuedConfigsInfo(), m_settingsController->getInstallationUuid(false));
|
||||
}
|
||||
|
||||
void SubscriptionUiController::getRenewalLink(int serverIndex)
|
||||
void SubscriptionUiController::getRenewalLink(const QString &serverId)
|
||||
{
|
||||
if (serverIndex < 0) {
|
||||
if (serverId.isEmpty()) {
|
||||
emit errorOccurred(ErrorCode::InternalError);
|
||||
return;
|
||||
}
|
||||
@@ -483,6 +482,6 @@ void SubscriptionUiController::getRenewalLink(int serverIndex)
|
||||
}
|
||||
emit renewalLinkReceived(url);
|
||||
});
|
||||
watcher->setFuture(m_subscriptionController->getRenewalLink(serverIndex));
|
||||
watcher->setFuture(m_subscriptionController->getRenewalLink(serverId));
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "ui/models/api/apiAccountInfoModel.h"
|
||||
#include "ui/models/api/apiCountryModel.h"
|
||||
#include "ui/models/api/apiDevicesModel.h"
|
||||
|
||||
class SubscriptionUiController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -34,10 +35,10 @@ public:
|
||||
Q_PROPERTY(QString vpnKey READ getVpnKey NOTIFY vpnKeyExportReady)
|
||||
|
||||
public slots:
|
||||
bool exportNativeConfig(int serverIndex, const QString &serverCountryCode, const QString &fileName);
|
||||
bool revokeNativeConfig(int serverIndex, const QString &serverCountryCode);
|
||||
bool exportVpnKey(int serverIndex, const QString &fileName);
|
||||
void prepareVpnKeyExport(int serverIndex);
|
||||
bool exportNativeConfig(const QString &serverId, const QString &serverCountryCode, const QString &fileName);
|
||||
bool revokeNativeConfig(const QString &serverId, const QString &serverCountryCode);
|
||||
bool exportVpnKey(const QString &serverId, const QString &fileName);
|
||||
void prepareVpnKeyExport(const QString &serverId);
|
||||
void copyVpnKeyToClipboard();
|
||||
|
||||
bool fillAvailableServices();
|
||||
@@ -45,21 +46,21 @@ public slots:
|
||||
bool importFreeFromGateway();
|
||||
bool restoreServiceFromAppStore();
|
||||
bool importTrialFromGateway(const QString &email);
|
||||
bool updateServiceFromGateway(const int serverIndex, const QString &newCountryCode, const QString &newCountryName,
|
||||
bool updateServiceFromGateway(const QString &serverId, const QString &newCountryCode, const QString &newCountryName,
|
||||
bool reloadServiceConfig = false);
|
||||
bool updateServiceFromTelegram(const int serverIndex);
|
||||
bool deactivateDevice(int serverIndex);
|
||||
bool deactivateExternalDevice(int serverIndex, const QString &uuid, const QString &serverCountryCode);
|
||||
bool deactivateDevice(const QString &serverId);
|
||||
bool deactivateExternalDevice(const QString &serverId, const QString &uuid, const QString &serverCountryCode);
|
||||
|
||||
void validateConfig();
|
||||
|
||||
void setCurrentProtocol(int serverIndex, const QString &protocolName);
|
||||
bool isVlessProtocol(int serverIndex);
|
||||
void setCurrentProtocol(const QString &serverId, const QString &protocolName);
|
||||
bool isVlessProtocol(const QString &serverId);
|
||||
|
||||
void removeApiConfig(int serverIndex);
|
||||
void removeApiConfig(const QString &serverId);
|
||||
|
||||
bool getAccountInfo(const QString &serverId, bool reload);
|
||||
void getRenewalLink(const QString &serverId);
|
||||
|
||||
bool getAccountInfo(int serverIndex, bool reload);
|
||||
void getRenewalLink(int serverIndex);
|
||||
void updateApiCountryModel();
|
||||
void updateApiDevicesModel();
|
||||
|
||||
@@ -80,6 +81,8 @@ signals:
|
||||
|
||||
void vpnKeyExportReady();
|
||||
|
||||
void unsupportedConnectDrawerRequested();
|
||||
|
||||
private:
|
||||
QList<QString> getQrCodes();
|
||||
int getQrCodesCount();
|
||||
|
||||
@@ -25,9 +25,12 @@ ConnectionUiController::ConnectionUiController(ConnectionController* connectionC
|
||||
|
||||
void ConnectionUiController::openConnection()
|
||||
{
|
||||
int serverIndex = m_serversController->getDefaultServerIndex();
|
||||
const QString serverId = m_serversController->getDefaultServerId();
|
||||
if (serverId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ErrorCode errorCode = m_connectionController->openConnection(serverIndex);
|
||||
ErrorCode errorCode = m_connectionController->openConnection(serverId);
|
||||
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit connectionErrorOccurred(errorCode);
|
||||
@@ -100,16 +103,6 @@ void ConnectionUiController::onConnectionStateChanged(Vpn::ConnectionState state
|
||||
emit connectionStateChanged();
|
||||
}
|
||||
|
||||
void ConnectionUiController::onCurrentContainerUpdated()
|
||||
{
|
||||
if (m_isConnected || m_isConnectionInProgress) {
|
||||
emit reconnectWithUpdatedContainer(tr("Settings updated successfully, reconnection..."));
|
||||
openConnection();
|
||||
} else {
|
||||
emit reconnectWithUpdatedContainer(tr("Settings updated successfully"));
|
||||
}
|
||||
}
|
||||
|
||||
void ConnectionUiController::onTranslationsUpdated()
|
||||
{
|
||||
onConnectionStateChanged(getCurrentConnectionState());
|
||||
|
||||
@@ -38,8 +38,6 @@ public slots:
|
||||
ErrorCode getLastConnectionError();
|
||||
void onConnectionStateChanged(Vpn::ConnectionState state);
|
||||
|
||||
void onCurrentContainerUpdated();
|
||||
|
||||
void onTranslationsUpdated();
|
||||
|
||||
signals:
|
||||
|
||||
@@ -19,8 +19,7 @@
|
||||
#include "ui/utils/macosUtil.h"
|
||||
#endif
|
||||
|
||||
PageController::PageController(ServersController* serversController,
|
||||
SettingsController* settingsController,
|
||||
PageController::PageController(ServersController* serversController, SettingsController* settingsController,
|
||||
QObject *parent)
|
||||
: QObject(parent), m_serversController(serversController), m_settingsController(settingsController)
|
||||
{
|
||||
@@ -57,14 +56,7 @@ PageController::PageController(ServersController* serversController,
|
||||
|
||||
bool PageController::isStartPageVisible()
|
||||
{
|
||||
if (m_serversController->getServersCount()) {
|
||||
if (m_serversController->getDefaultServerIndex() < 0) {
|
||||
m_serversController->setDefaultServerIndex(0);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return m_serversController->getServersCount() == 0;
|
||||
}
|
||||
|
||||
QString PageController::getPagePath(PageLoader::PageEnum page)
|
||||
|
||||
@@ -94,8 +94,7 @@ class PageController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit PageController(ServersController* serversController,
|
||||
SettingsController* settingsController,
|
||||
explicit PageController(ServersController* serversController, SettingsController* settingsController,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
Q_PROPERTY(int safeAreaTopMargin READ getSafeAreaTopMargin NOTIFY safeAreaTopMarginChanged)
|
||||
@@ -164,6 +163,8 @@ signals:
|
||||
void showPassphraseRequestDrawer();
|
||||
void passphraseRequestDrawerClosed(QString passphrase);
|
||||
|
||||
void unsupportedConnectDrawerRequested();
|
||||
|
||||
void escapePressed();
|
||||
void closeTopDrawer();
|
||||
|
||||
|
||||
@@ -8,46 +8,46 @@ ExportUiController::ExportUiController(ExportController* exportController, QObje
|
||||
{
|
||||
}
|
||||
|
||||
void ExportUiController::generateFullAccessConfig(int serverIndex)
|
||||
void ExportUiController::generateFullAccessConfig(const QString &serverId)
|
||||
{
|
||||
clearPreviousConfig();
|
||||
auto result = m_exportController->generateFullAccessConfig(serverIndex);
|
||||
auto result = m_exportController->generateFullAccessConfig(serverId);
|
||||
applyExportResult(result);
|
||||
}
|
||||
|
||||
void ExportUiController::generateConnectionConfig(int serverIndex, int containerIndex, const QString &clientName)
|
||||
void ExportUiController::generateConnectionConfig(const QString &serverId, int containerIndex, const QString &clientName)
|
||||
{
|
||||
clearPreviousConfig();
|
||||
auto result = m_exportController->generateConnectionConfig(serverIndex, containerIndex, clientName);
|
||||
auto result = m_exportController->generateConnectionConfig(serverId, containerIndex, clientName);
|
||||
applyExportResult(result);
|
||||
}
|
||||
|
||||
void ExportUiController::generateOpenVpnConfig(int serverIndex, const QString &clientName)
|
||||
void ExportUiController::generateOpenVpnConfig(const QString &serverId, const QString &clientName)
|
||||
{
|
||||
clearPreviousConfig();
|
||||
auto result = m_exportController->generateOpenVpnConfig(serverIndex, clientName);
|
||||
auto result = m_exportController->generateOpenVpnConfig(serverId, clientName);
|
||||
applyExportResult(result);
|
||||
}
|
||||
|
||||
void ExportUiController::generateWireGuardConfig(int serverIndex, const QString &clientName)
|
||||
void ExportUiController::generateWireGuardConfig(const QString &serverId, const QString &clientName)
|
||||
{
|
||||
clearPreviousConfig();
|
||||
auto result = m_exportController->generateWireGuardConfig(serverIndex, clientName);
|
||||
auto result = m_exportController->generateWireGuardConfig(serverId, clientName);
|
||||
applyExportResult(result);
|
||||
}
|
||||
|
||||
void ExportUiController::generateAwgConfig(int serverIndex, int containerIndex, const QString &clientName)
|
||||
void ExportUiController::generateAwgConfig(const QString &serverId, int containerIndex, const QString &clientName)
|
||||
{
|
||||
clearPreviousConfig();
|
||||
auto result = m_exportController->generateAwgConfig(serverIndex, containerIndex, clientName);
|
||||
auto result = m_exportController->generateAwgConfig(serverId, containerIndex, clientName);
|
||||
applyExportResult(result);
|
||||
}
|
||||
|
||||
|
||||
void ExportUiController::generateXrayConfig(int serverIndex, const QString &clientName)
|
||||
void ExportUiController::generateXrayConfig(const QString &serverId, const QString &clientName)
|
||||
{
|
||||
clearPreviousConfig();
|
||||
auto result = m_exportController->generateXrayConfig(serverIndex, clientName);
|
||||
auto result = m_exportController->generateXrayConfig(serverId, clientName);
|
||||
applyExportResult(result);
|
||||
}
|
||||
|
||||
@@ -71,20 +71,20 @@ void ExportUiController::exportConfig(const QString &fileName)
|
||||
SystemController::saveFile(fileName, m_config);
|
||||
}
|
||||
|
||||
void ExportUiController::updateClientManagementModel(int serverIndex, int containerIndex)
|
||||
void ExportUiController::updateClientManagementModel(const QString &serverId, int containerIndex)
|
||||
{
|
||||
m_exportController->updateClientManagementModel(serverIndex, containerIndex);
|
||||
m_exportController->updateClientManagementModel(serverId, containerIndex);
|
||||
}
|
||||
|
||||
void ExportUiController::revokeConfig(int row, int serverIndex, int containerIndex)
|
||||
void ExportUiController::revokeConfig(int row, const QString &serverId, int containerIndex)
|
||||
{
|
||||
m_exportController->revokeConfig(row, serverIndex, containerIndex);
|
||||
m_exportController->revokeConfig(row, serverId, containerIndex);
|
||||
emit revokeConfigFinished();
|
||||
}
|
||||
|
||||
void ExportUiController::renameClient(int row, const QString &clientName, int serverIndex, int containerIndex)
|
||||
void ExportUiController::renameClient(int row, const QString &clientName, const QString &serverId, int containerIndex)
|
||||
{
|
||||
m_exportController->renameClient(row, clientName, serverIndex, containerIndex);
|
||||
m_exportController->renameClient(row, clientName, serverId, containerIndex);
|
||||
}
|
||||
|
||||
int ExportUiController::getQrCodesCount()
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QObject>
|
||||
|
||||
#include "core/controllers/selfhosted/exportController.h"
|
||||
#include "core/utils/errorCodes.h"
|
||||
|
||||
class ExportUiController : public QObject
|
||||
{
|
||||
@@ -17,12 +18,13 @@ public:
|
||||
Q_PROPERTY(QString nativeConfigString READ getNativeConfigString NOTIFY exportConfigChanged)
|
||||
|
||||
public slots:
|
||||
void generateFullAccessConfig(int serverIndex);
|
||||
void generateConnectionConfig(int serverIndex, int containerIndex, const QString &clientName);
|
||||
void generateOpenVpnConfig(int serverIndex, const QString &clientName);
|
||||
void generateWireGuardConfig(int serverIndex, const QString &clientName);
|
||||
void generateAwgConfig(int serverIndex, int containerIndex, const QString &clientName);
|
||||
void generateXrayConfig(int serverIndex, const QString &clientName);
|
||||
void generateFullAccessConfig(const QString &serverId);
|
||||
|
||||
void generateConnectionConfig(const QString &serverId, int containerIndex, const QString &clientName);
|
||||
void generateOpenVpnConfig(const QString &serverId, const QString &clientName);
|
||||
void generateWireGuardConfig(const QString &serverId, const QString &clientName);
|
||||
void generateAwgConfig(const QString &serverId, int containerIndex, const QString &clientName);
|
||||
void generateXrayConfig(const QString &serverId, const QString &clientName);
|
||||
|
||||
QString getConfig();
|
||||
QString getNativeConfigString();
|
||||
@@ -30,9 +32,11 @@ public slots:
|
||||
|
||||
void exportConfig(const QString &fileName);
|
||||
|
||||
void updateClientManagementModel(int serverIndex, int containerIndex);
|
||||
void revokeConfig(int row, int serverIndex, int containerIndex);
|
||||
void renameClient(int row, const QString &clientName, int serverIndex, int containerIndex);
|
||||
void updateClientManagementModel(const QString &serverId, int containerIndex);
|
||||
|
||||
void revokeConfig(int row, const QString &serverId, int containerIndex);
|
||||
|
||||
void renameClient(int row, const QString &clientName, const QString &serverId, int containerIndex);
|
||||
|
||||
signals:
|
||||
void generateConfig(int type);
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "core/controllers/selfhosted/installController.h"
|
||||
#include "core/utils/selfhosted/sshSession.h"
|
||||
#include "core/utils/networkUtilities.h"
|
||||
#include "logger.h"
|
||||
#include "core/utils/protocolEnum.h"
|
||||
#include "core/protocols/protocolUtils.h"
|
||||
#include "core/utils/constants/configKeys.h"
|
||||
@@ -27,33 +26,12 @@
|
||||
#include "ui/models/services/socks5ProxyConfigModel.h"
|
||||
#include "ui/models/services/torConfigModel.h"
|
||||
#include "core/utils/utilities.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "core/models/containerConfig.h"
|
||||
#include "core/models/protocols/awgProtocolConfig.h"
|
||||
#include "core/models/protocols/wireGuardProtocolConfig.h"
|
||||
#include "core/models/protocols/openVpnProtocolConfig.h"
|
||||
#include "core/models/protocols/xrayProtocolConfig.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
Logger logger("InstallUiController");
|
||||
|
||||
namespace configKey
|
||||
{
|
||||
constexpr char serviceInfo[] = "service_info";
|
||||
constexpr char serviceType[] = "service_type";
|
||||
constexpr char serviceProtocol[] = "service_protocol";
|
||||
constexpr char userCountryCode[] = "user_country_code";
|
||||
|
||||
constexpr char serverCountryCode[] = "server_country_code";
|
||||
constexpr char serverCountryName[] = "server_country_name";
|
||||
constexpr char availableCountries[] = "available_countries";
|
||||
|
||||
constexpr char apiConfig[] = "api_config";
|
||||
constexpr char authData[] = "auth_data";
|
||||
}
|
||||
}
|
||||
|
||||
InstallUiController::InstallUiController(InstallController *installController,
|
||||
ServersController *serversController,
|
||||
SettingsController *settingsController,
|
||||
@@ -101,19 +79,18 @@ InstallUiController::~InstallUiController()
|
||||
{
|
||||
}
|
||||
|
||||
void InstallUiController::install(DockerContainer container, int port, TransportProto transportProto, int serverIndex)
|
||||
void InstallUiController::install(DockerContainer container, int port, TransportProto transportProto, const QString &serverId)
|
||||
{
|
||||
const bool isNewServer = serverIndex < 0;
|
||||
const bool isNewServer = serverId.isEmpty();
|
||||
|
||||
ServerCredentials serverCredentials;
|
||||
if (isNewServer) {
|
||||
serverCredentials = m_processedServerCredentials;
|
||||
} else {
|
||||
serverCredentials = m_serversController->getServerCredentials(serverIndex);
|
||||
serverCredentials = m_serversController->getServerCredentials(serverId);
|
||||
m_processedServerCredentials = ServerCredentials();
|
||||
}
|
||||
|
||||
QMap<DockerContainer, QJsonObject> preparedContainers;
|
||||
QString finishMessage;
|
||||
ErrorCode errorCode;
|
||||
|
||||
@@ -131,9 +108,13 @@ void InstallUiController::install(DockerContainer container, int port, Transport
|
||||
return;
|
||||
}
|
||||
|
||||
int serverIndex = m_serversController->getServersCount() - 1;
|
||||
ServerConfig serverConfig = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containers = serverConfig.containers();
|
||||
const QString newServerId = m_serversController->getServerId(m_serversController->getServersCount() - 1);
|
||||
const auto admin = m_serversController->selfHostedAdminConfig(newServerId);
|
||||
if (!admin.has_value()) {
|
||||
emit installationErrorOccurred(ErrorCode::InternalError);
|
||||
return;
|
||||
}
|
||||
QMap<DockerContainer, ContainerConfig> containers = admin->containers;
|
||||
int containersCount = containers.size();
|
||||
|
||||
if (wasContainerInstalled) {
|
||||
@@ -148,20 +129,28 @@ void InstallUiController::install(DockerContainer container, int port, Transport
|
||||
|
||||
emit installServerFinished(finishMessage);
|
||||
} else {
|
||||
ServerConfig serverConfig = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containers = serverConfig.containers();
|
||||
const auto adminBefore = m_serversController->selfHostedAdminConfig(serverId);
|
||||
if (!adminBefore.has_value()) {
|
||||
emit installationErrorOccurred(ErrorCode::InternalError);
|
||||
return;
|
||||
}
|
||||
QMap<DockerContainer, ContainerConfig> containers = adminBefore->containers;
|
||||
int containersCount = containers.size();
|
||||
|
||||
bool wasContainerInstalled = false;
|
||||
errorCode = m_installController->installContainer(serverIndex, container, port, transportProto,
|
||||
errorCode = m_installController->installContainer(serverId, container, port, transportProto,
|
||||
wasContainerInstalled);
|
||||
if (errorCode) {
|
||||
emit installationErrorOccurred(errorCode);
|
||||
return;
|
||||
}
|
||||
|
||||
ServerConfig newServerConfig = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> newContainers = newServerConfig.containers();
|
||||
const auto adminAfter = m_serversController->selfHostedAdminConfig(serverId);
|
||||
if (!adminAfter.has_value()) {
|
||||
emit installationErrorOccurred(ErrorCode::InternalError);
|
||||
return;
|
||||
}
|
||||
QMap<DockerContainer, ContainerConfig> newContainers = adminAfter->containers;
|
||||
int newContainersCount = newContainers.size();
|
||||
|
||||
bool hasNewContainers = (newContainersCount - containersCount) > (wasContainerInstalled ? 1 : 0);
|
||||
@@ -181,17 +170,25 @@ void InstallUiController::install(DockerContainer container, int port, Transport
|
||||
}
|
||||
}
|
||||
|
||||
void InstallUiController::scanServerForInstalledContainers(int serverIndex)
|
||||
void InstallUiController::scanServerForInstalledContainers(const QString &serverId)
|
||||
{
|
||||
ServerConfig serverBefore = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containersBefore = serverBefore.containers();
|
||||
const auto serverBefore = m_serversController->selfHostedAdminConfig(serverId);
|
||||
if (!serverBefore.has_value()) {
|
||||
emit installationErrorOccurred(ErrorCode::InternalError);
|
||||
return;
|
||||
}
|
||||
QMap<DockerContainer, ContainerConfig> containersBefore = serverBefore->containers;
|
||||
int containersCountBefore = containersBefore.size();
|
||||
|
||||
ErrorCode errorCode = m_installController->scanServerForInstalledContainers(serverIndex);
|
||||
ErrorCode errorCode = m_installController->scanServerForInstalledContainers(serverId);
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
ServerConfig serverAfter = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containersAfter = serverAfter.containers();
|
||||
const auto serverAfter = m_serversController->selfHostedAdminConfig(serverId);
|
||||
if (!serverAfter.has_value()) {
|
||||
emit installationErrorOccurred(ErrorCode::InternalError);
|
||||
return;
|
||||
}
|
||||
QMap<DockerContainer, ContainerConfig> containersAfter = serverAfter->containers;
|
||||
int containersCountAfter = containersAfter.size();
|
||||
|
||||
bool isInstalledContainerAdded = containersCountAfter > containersCountBefore;
|
||||
@@ -202,7 +199,7 @@ void InstallUiController::scanServerForInstalledContainers(int serverIndex)
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
|
||||
void InstallUiController::updateContainer(int serverIndex, int containerIndex, int protocolIndex)
|
||||
void InstallUiController::updateContainer(const QString &serverId, int containerIndex, int protocolIndex)
|
||||
{
|
||||
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||
|
||||
@@ -250,32 +247,26 @@ void InstallUiController::updateContainer(int serverIndex, int containerIndex, i
|
||||
default:
|
||||
return;
|
||||
}
|
||||
ContainerConfig oldContainerConfig = m_serversController->getContainerConfig(serverIndex, container);
|
||||
ContainerConfig oldContainerConfig = m_serversController->getContainerConfig(serverId, container);
|
||||
|
||||
ErrorCode errorCode = m_installController->updateContainer(serverIndex, container, oldContainerConfig, containerConfig);
|
||||
ErrorCode errorCode = m_installController->updateContainer(serverId, container, oldContainerConfig, containerConfig);
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
ContainerConfig updatedConfig = m_serversController->getContainerConfig(serverIndex, container);
|
||||
ContainerConfig updatedConfig = m_serversController->getContainerConfig(serverId, container);
|
||||
m_protocolModel->updateModel(updatedConfig);
|
||||
|
||||
auto defaultContainer = m_serversController->getServerConfig(serverIndex).defaultContainer();
|
||||
if ((serverIndex == m_serversController->getDefaultServerIndex()) && (container == defaultContainer)) {
|
||||
emit currentContainerUpdated();
|
||||
} else {
|
||||
emit updateContainerFinished(tr("Settings updated successfully"));
|
||||
}
|
||||
|
||||
emit updateContainerFinished(tr("Settings updated successfully"));
|
||||
return;
|
||||
}
|
||||
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
|
||||
void InstallUiController::rebootServer(int serverIndex)
|
||||
void InstallUiController::rebootServer(const QString &serverId)
|
||||
{
|
||||
QString serverName = m_serversController->getServerConfig(serverIndex).displayName();
|
||||
const QString serverName = m_serversController->notificationDisplayName(serverId);
|
||||
|
||||
const auto errorCode = m_installController->rebootServer(serverIndex);
|
||||
const auto errorCode = m_installController->rebootServer(serverId);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
emit rebootServerFinished(tr("Server '%1' was rebooted").arg(serverName));
|
||||
} else {
|
||||
@@ -283,19 +274,22 @@ void InstallUiController::rebootServer(int serverIndex)
|
||||
}
|
||||
}
|
||||
|
||||
void InstallUiController::removeServer(int serverIndex)
|
||||
void InstallUiController::removeServer(const QString &serverId)
|
||||
{
|
||||
QString serverName = m_serversController->getServerConfig(serverIndex).displayName();
|
||||
if (serverId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
const QString serverName = m_serversController->notificationDisplayName(serverId);
|
||||
|
||||
m_serversController->removeServer(serverIndex);
|
||||
m_serversController->removeServer(serverId);
|
||||
emit removeServerFinished(tr("Server '%1' was removed").arg(serverName));
|
||||
}
|
||||
|
||||
void InstallUiController::removeAllContainers(int serverIndex)
|
||||
void InstallUiController::removeAllContainers(const QString &serverId)
|
||||
{
|
||||
QString serverName = m_serversController->getServerConfig(serverIndex).displayName();
|
||||
const QString serverName = m_serversController->notificationDisplayName(serverId);
|
||||
|
||||
ErrorCode errorCode = m_installController->removeAllContainers(serverIndex);
|
||||
ErrorCode errorCode = m_installController->removeAllContainers(serverId);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
emit removeAllContainersFinished(tr("All containers from server '%1' have been removed").arg(serverName));
|
||||
return;
|
||||
@@ -303,14 +297,14 @@ void InstallUiController::removeAllContainers(int serverIndex)
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
|
||||
void InstallUiController::removeContainer(int serverIndex, int containerIndex)
|
||||
void InstallUiController::removeContainer(const QString &serverId, int containerIndex)
|
||||
{
|
||||
QString serverName = m_serversController->getServerConfig(serverIndex).displayName();
|
||||
const QString serverName = m_serversController->notificationDisplayName(serverId);
|
||||
|
||||
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||
QString containerName = ContainerUtils::containerHumanNames().value(container);
|
||||
|
||||
ErrorCode errorCode = m_installController->removeContainer(serverIndex, container);
|
||||
ErrorCode errorCode = m_installController->removeContainer(serverId, container);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
|
||||
emit removeContainerFinished(tr("%1 has been removed from the server '%2'").arg(containerName, serverName));
|
||||
@@ -319,17 +313,17 @@ void InstallUiController::removeContainer(int serverIndex, int containerIndex)
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
|
||||
void InstallUiController::clearCachedProfile(int serverIndex, int containerIndex)
|
||||
void InstallUiController::clearCachedProfile(const QString &serverId, int containerIndex)
|
||||
{
|
||||
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||
if (ContainerUtils::containerService(container) == ServiceType::Other) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_installController->clearCachedProfile(serverIndex, container);
|
||||
m_installController->clearCachedProfile(serverId, container);
|
||||
|
||||
emit cachedProfileCleared(tr("%1 cached profile cleared").arg(ContainerUtils::containerHumanNames().value(container)));
|
||||
ContainerConfig updatedConfig = m_serversController->getContainerConfig(serverIndex, container);
|
||||
ContainerConfig updatedConfig = m_serversController->getContainerConfig(serverId, container);
|
||||
m_protocolModel->updateModel(updatedConfig);
|
||||
}
|
||||
|
||||
@@ -354,9 +348,9 @@ void InstallUiController::setProcessedServerCredentials(const QString &hostName,
|
||||
m_processedServerCredentials.secretData = secretData;
|
||||
}
|
||||
|
||||
void InstallUiController::mountSftpDrive(int serverIndex, const QString &port, const QString &password, const QString &username)
|
||||
void InstallUiController::mountSftpDrive(const QString &serverId, const QString &port, const QString &password, const QString &username)
|
||||
{
|
||||
ServerCredentials serverCredentials = m_serversController->getServerCredentials(serverIndex);
|
||||
ServerCredentials serverCredentials = m_serversController->getServerCredentials(serverId);
|
||||
ErrorCode errorCode = m_installController->mountSftpDrive(serverCredentials, port, password, username);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit installationErrorOccurred(errorCode);
|
||||
@@ -399,40 +393,35 @@ void InstallUiController::setEncryptedPassphrase(QString passphrase)
|
||||
|
||||
void InstallUiController::addEmptyServer()
|
||||
{
|
||||
SelfHostedServerConfig serverConfig;
|
||||
serverConfig.hostName = m_processedServerCredentials.hostName;
|
||||
serverConfig.userName = m_processedServerCredentials.userName;
|
||||
serverConfig.password = m_processedServerCredentials.secretData;
|
||||
serverConfig.port = m_processedServerCredentials.port;
|
||||
serverConfig.description = m_settingsController->nextAvailableServerName();
|
||||
serverConfig.defaultContainer = DockerContainer::None;
|
||||
|
||||
m_serversController->addServer(ServerConfig(serverConfig));
|
||||
m_installController->addEmptyServer(m_processedServerCredentials);
|
||||
emit installServerFinished(tr("Server added successfully"));
|
||||
}
|
||||
|
||||
void InstallUiController::validateConfig()
|
||||
{
|
||||
int serverIndex = m_serversController->getDefaultServerIndex();
|
||||
m_installController->validateConfig(serverIndex);
|
||||
const QString serverId = m_serversController->getDefaultServerId();
|
||||
if (serverId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
m_installController->validateConfig(serverId);
|
||||
}
|
||||
|
||||
void InstallUiController::updateProtocols(int serverIndex, int containerIndex)
|
||||
void InstallUiController::updateProtocols(const QString &serverId, int containerIndex)
|
||||
{
|
||||
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||
ContainerConfig containerConfig = m_serversController->getContainerConfig(serverIndex, container);
|
||||
ContainerConfig containerConfig = m_serversController->getContainerConfig(serverId, container);
|
||||
containerConfig.container = container;
|
||||
m_protocolModel->updateModel(containerConfig);
|
||||
}
|
||||
|
||||
void InstallUiController::openServerSettings(int serverIndex, int containerIndex, int protocolIndex)
|
||||
void InstallUiController::openServerSettings(const QString &serverId, int containerIndex, int protocolIndex)
|
||||
{
|
||||
updateProtocolConfigModel(serverIndex, containerIndex, protocolIndex);
|
||||
updateProtocolConfigModel(serverId, containerIndex, protocolIndex);
|
||||
}
|
||||
|
||||
void InstallUiController::openClientSettings(int serverIndex, int containerIndex, int protocolIndex)
|
||||
void InstallUiController::openClientSettings(const QString &serverId, int containerIndex, int protocolIndex)
|
||||
{
|
||||
updateProtocolConfigModel(serverIndex, containerIndex, protocolIndex);
|
||||
updateProtocolConfigModel(serverId, containerIndex, protocolIndex);
|
||||
}
|
||||
|
||||
int InstallUiController::defaultPort(int protocolIndex)
|
||||
@@ -465,10 +454,10 @@ bool InstallUiController::defaultTransportProtoChangeable(int protocolIndex)
|
||||
return ProtocolUtils::defaultTransportProtoChangeable(proto);
|
||||
}
|
||||
|
||||
void InstallUiController::updateProtocolConfigModel(int serverIndex, int containerIndex, int protocolIndex)
|
||||
void InstallUiController::updateProtocolConfigModel(const QString &serverId, int containerIndex, int protocolIndex)
|
||||
{
|
||||
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||
ContainerConfig containerConfig = m_serversController->getContainerConfig(serverIndex, container);
|
||||
ContainerConfig containerConfig = m_serversController->getContainerConfig(serverId, container);
|
||||
containerConfig.container = container;
|
||||
Proto protocolType = static_cast<Proto>(protocolIndex);
|
||||
|
||||
@@ -490,4 +479,3 @@ void InstallUiController::updateProtocolConfigModel(int serverIndex, int contain
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,24 +52,24 @@ public:
|
||||
~InstallUiController();
|
||||
|
||||
public slots:
|
||||
void install(DockerContainer container, int port, TransportProto transportProto, int serverIndex);
|
||||
void install(DockerContainer container, int port, TransportProto transportProto, const QString &serverId);
|
||||
void setProcessedServerCredentials(const QString &hostName, const QString &userName, const QString &secretData);
|
||||
void clearProcessedServerCredentials();
|
||||
|
||||
void scanServerForInstalledContainers(int serverIndex);
|
||||
void scanServerForInstalledContainers(const QString &serverId);
|
||||
|
||||
void updateContainer(int serverIndex, int containerIndex, int protocolIndex);
|
||||
void updateContainer(const QString &serverId, int containerIndex, int protocolIndex);
|
||||
|
||||
void removeServer(int serverIndex);
|
||||
void rebootServer(int serverIndex);
|
||||
void removeAllContainers(int serverIndex);
|
||||
void removeContainer(int serverIndex, int containerIndex);
|
||||
void removeServer(const QString &serverId);
|
||||
void rebootServer(const QString &serverId);
|
||||
void removeAllContainers(const QString &serverId);
|
||||
void removeContainer(const QString &serverId, int containerIndex);
|
||||
|
||||
void clearCachedProfile(int serverIndex, int containerIndex);
|
||||
void clearCachedProfile(const QString &serverId, int containerIndex);
|
||||
|
||||
QRegularExpression ipAddressRegExp();
|
||||
|
||||
void mountSftpDrive(int serverIndex, const QString &port, const QString &password, const QString &username);
|
||||
void mountSftpDrive(const QString &serverId, const QString &port, const QString &password, const QString &username);
|
||||
|
||||
bool checkSshConnection();
|
||||
|
||||
@@ -78,12 +78,12 @@ public slots:
|
||||
void addEmptyServer();
|
||||
|
||||
void validateConfig();
|
||||
|
||||
Q_INVOKABLE void updateProtocols(int serverIndex, int containerIndex);
|
||||
|
||||
void openServerSettings(int serverIndex, int containerIndex, int protocolIndex);
|
||||
void openClientSettings(int serverIndex, int containerIndex, int protocolIndex);
|
||||
|
||||
|
||||
Q_INVOKABLE void updateProtocols(const QString &serverId, int containerIndex);
|
||||
|
||||
void openServerSettings(const QString &serverId, int containerIndex, int protocolIndex);
|
||||
void openClientSettings(const QString &serverId, int containerIndex, int protocolIndex);
|
||||
|
||||
int defaultPort(int protocolIndex);
|
||||
int getPortForInstall(int protocolIndex);
|
||||
int defaultTransportProto(int protocolIndex);
|
||||
@@ -114,8 +114,6 @@ signals:
|
||||
void serverIsBusy(const bool isBusy);
|
||||
void cancelInstallation();
|
||||
|
||||
void currentContainerUpdated();
|
||||
|
||||
void cachedProfileCleared(const QString &message);
|
||||
void apiConfigRemoved(const QString &message);
|
||||
|
||||
@@ -145,7 +143,7 @@ private:
|
||||
|
||||
QString m_privateKeyPassphrase;
|
||||
|
||||
void updateProtocolConfigModel(int serverIndex, int containerIndex, int protocolIndex);
|
||||
void updateProtocolConfigModel(const QString &serverId, int containerIndex, int protocolIndex);
|
||||
};
|
||||
|
||||
#endif // INSTALLUICONTROLLER_H
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
#include "serversUiController.h"
|
||||
|
||||
#include "core/utils/api/apiEnums.h"
|
||||
#include "core/utils/constants/apiKeys.h"
|
||||
#include "core/utils/constants/apiConstants.h"
|
||||
#include "core/utils/api/apiUtils.h"
|
||||
#include "core/utils/containerEnum.h"
|
||||
#include "core/utils/containers/containerUtils.h"
|
||||
#include "core/utils/protocolEnum.h"
|
||||
#include "core/utils/protocolEnum.h"
|
||||
#include "core/protocols/protocolUtils.h"
|
||||
#include "core/utils/constants/configKeys.h"
|
||||
#include "core/utils/constants/protocolConstants.h"
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "core/models/protocolConfig.h"
|
||||
#include "core/models/containerConfig.h"
|
||||
#include "core/models/protocols/awgProtocolConfig.h"
|
||||
|
||||
using namespace amnezia;
|
||||
|
||||
namespace
|
||||
namespace {
|
||||
int rowForServerId(const QVector<ServerDescription> &list, const QString &serverId)
|
||||
{
|
||||
namespace configKey
|
||||
{
|
||||
constexpr char apiConfig[] = "api_config";
|
||||
constexpr char serverCountryCode[] = "server_country_code";
|
||||
constexpr char serverCountryName[] = "server_country_name";
|
||||
constexpr char userCountryCode[] = "user_country_code";
|
||||
constexpr char serviceType[] = "service_type";
|
||||
if (serverId.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < list.size(); ++i) {
|
||||
if (list.at(i).serverId == serverId) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
bool descriptionsHaveGatewayServers(const QVector<ServerDescription> &list)
|
||||
{
|
||||
for (const auto &d : list) {
|
||||
if (d.isServerFromGatewayApi) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} // namespace
|
||||
ServersUiController::ServersUiController(ServersController* serversController,
|
||||
SettingsController* settingsController,
|
||||
ServersModel* serversModel,
|
||||
@@ -47,48 +47,70 @@ ServersUiController::ServersUiController(ServersController* serversController,
|
||||
{
|
||||
}
|
||||
|
||||
void ServersUiController::removeServer(int index)
|
||||
void ServersUiController::removeServer(const QString &serverId)
|
||||
{
|
||||
m_serversController->removeServer(index);
|
||||
updateModel();
|
||||
}
|
||||
|
||||
void ServersUiController::editServerName(int index, const QString &name)
|
||||
{
|
||||
ServerConfig serverConfig = m_serversController->getServerConfig(index);
|
||||
|
||||
if (serverConfig.isApiV1()) {
|
||||
ApiV1ServerConfig* apiV1 = serverConfig.as<ApiV1ServerConfig>();
|
||||
if (apiV1) {
|
||||
apiV1->name = name;
|
||||
}
|
||||
} else if (serverConfig.isApiV2()) {
|
||||
ApiV2ServerConfig* apiV2 = serverConfig.as<ApiV2ServerConfig>();
|
||||
if (apiV2) {
|
||||
apiV2->name = name;
|
||||
apiV2->nameOverriddenByUser = true;
|
||||
}
|
||||
} else {
|
||||
serverConfig.visit([&name](auto& arg) {
|
||||
arg.description = name;
|
||||
});
|
||||
if (serverId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_serversController->editServer(index, serverConfig);
|
||||
m_serversController->removeServer(serverId);
|
||||
updateModel();
|
||||
}
|
||||
|
||||
void ServersUiController::setDefaultServerIndex(int index)
|
||||
void ServersUiController::removeServerAtIndex(int index)
|
||||
{
|
||||
m_serversController->setDefaultServerIndex(index);
|
||||
updateModel();
|
||||
emit defaultServerIndexChanged(index);
|
||||
const QString serverId = getServerId(index);
|
||||
if (!serverId.isEmpty()) {
|
||||
removeServer(serverId);
|
||||
}
|
||||
}
|
||||
|
||||
void ServersUiController::setDefaultContainer(int serverIndex, int containerIndex)
|
||||
void ServersUiController::setDefaultServerAtIndex(int index)
|
||||
{
|
||||
const QString serverId = getServerId(index);
|
||||
if (!serverId.isEmpty()) {
|
||||
setDefaultServer(serverId);
|
||||
}
|
||||
}
|
||||
|
||||
void ServersUiController::setDefaultContainerAtIndex(int index, int containerIndex)
|
||||
{
|
||||
const QString serverId = getServerId(index);
|
||||
if (!serverId.isEmpty()) {
|
||||
setDefaultContainer(serverId, containerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
void ServersUiController::editServerName(const QString &serverId, const QString &name)
|
||||
{
|
||||
if (serverId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!m_serversController->renameServer(serverId, name)) {
|
||||
emit errorOccurred(tr("Legacy API v1 configs are no longer supported. Remove this server to continue."));
|
||||
emit finished(tr("Use the remove action to delete this legacy config."));
|
||||
return;
|
||||
}
|
||||
updateModel();
|
||||
}
|
||||
|
||||
void ServersUiController::setDefaultServer(const QString &serverId)
|
||||
{
|
||||
if (serverId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
m_serversController->setDefaultServer(serverId);
|
||||
updateModel();
|
||||
emit defaultServerIdChanged(serverId);
|
||||
}
|
||||
|
||||
void ServersUiController::setDefaultContainer(const QString &serverId, int containerIndex)
|
||||
{
|
||||
if (serverId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
auto container = static_cast<DockerContainer>(containerIndex);
|
||||
m_serversController->setDefaultContainer(serverIndex, container);
|
||||
m_serversController->setDefaultContainer(serverId, container);
|
||||
updateModel();
|
||||
}
|
||||
|
||||
@@ -98,129 +120,123 @@ void ServersUiController::toggleAmneziaDns(bool enabled)
|
||||
updateModel();
|
||||
}
|
||||
|
||||
void ServersUiController::onDefaultServerChanged(int index)
|
||||
void ServersUiController::onDefaultServerChanged(const QString &/*defaultServerId*/)
|
||||
{
|
||||
setProcessedServerIndex(index);
|
||||
updateModel();
|
||||
setProcessedServerId(m_serversController->getDefaultServerId());
|
||||
updateDefaultServerContainersModel();
|
||||
emit defaultServerIndexChanged(index);
|
||||
emit defaultServerIdChanged(m_serversController->getDefaultServerId());
|
||||
}
|
||||
|
||||
void ServersUiController::updateModel()
|
||||
{
|
||||
int defaultIndex = m_serversController->getDefaultServerIndex();
|
||||
bool wasEmpty = !hasServersFromGatewayApi();
|
||||
int serversCount = m_serversController->getServersCount();
|
||||
QVector<ServerDescription> descriptions =
|
||||
m_serversController->buildServerDescriptions(m_settingsController->isAmneziaDnsEnabled());
|
||||
|
||||
if (m_processedServerIndex >= serversCount) {
|
||||
setProcessedServerIndex(defaultIndex);
|
||||
} else if (m_processedServerIndex >= 0) {
|
||||
setProcessedServerIndex(m_processedServerIndex);
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
const bool hadServersFromGatewayBefore = descriptionsHaveGatewayServers(m_orderedServerDescriptions);
|
||||
const bool hasServersFromGatewayNow = descriptionsHaveGatewayServers(descriptions);
|
||||
const int listCount = descriptions.size();
|
||||
const int defaultRowInDescriptions = rowForServerId(descriptions, defaultServerId);
|
||||
|
||||
m_orderedServerDescriptions = descriptions;
|
||||
|
||||
if (listCount == 0) {
|
||||
setProcessedServerId(QString());
|
||||
} else if (m_processedServerIndex >= listCount) {
|
||||
setProcessedServerId(defaultServerId);
|
||||
} else if (!m_processedServerId.isEmpty()) {
|
||||
const int row = rowForServerId(m_orderedServerDescriptions, m_processedServerId);
|
||||
if (row < 0) {
|
||||
setProcessedServerId(defaultServerId);
|
||||
} else {
|
||||
setProcessedServerId(m_processedServerId);
|
||||
}
|
||||
} else if (defaultRowInDescriptions >= 0) {
|
||||
setProcessedServerId(defaultServerId);
|
||||
}
|
||||
|
||||
m_serversModel->updateModel(m_serversController->getServers(), defaultIndex, m_settingsController->isAmneziaDnsEnabled());
|
||||
|
||||
|
||||
|
||||
m_serversModel->updateModel(m_orderedServerDescriptions, defaultRowInDescriptions);
|
||||
|
||||
updateContainersModel();
|
||||
updateDefaultServerContainersModel();
|
||||
|
||||
bool isEmpty = !hasServersFromGatewayApi();
|
||||
if (wasEmpty != isEmpty) {
|
||||
|
||||
if (hadServersFromGatewayBefore != hasServersFromGatewayNow) {
|
||||
emit hasServersFromGatewayApiChanged();
|
||||
}
|
||||
|
||||
emit defaultServerIndexChanged(defaultIndex);
|
||||
|
||||
emit defaultServerIdChanged(defaultServerId);
|
||||
emit defaultServerIndexChanged(defaultServerIndex());
|
||||
}
|
||||
|
||||
int ServersUiController::getDefaultServerIndex() const
|
||||
QString ServersUiController::getDefaultServerId() const
|
||||
{
|
||||
return m_serversController->getDefaultServerIndex();
|
||||
return m_serversController->getDefaultServerId();
|
||||
}
|
||||
|
||||
QString ServersUiController::getDefaultServerName() const
|
||||
{
|
||||
int defaultIndex = getDefaultServerIndex();
|
||||
return m_serversController->getServerConfig(defaultIndex).displayName();
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == defaultServerId) {
|
||||
return description.serverName;
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString ServersUiController::getDefaultServerDefaultContainerName() const
|
||||
{
|
||||
int defaultIndex = getDefaultServerIndex();
|
||||
const ServerConfig server = m_serversController->getServerConfig(defaultIndex);
|
||||
return ContainerUtils::containerHumanNames().value(server.defaultContainer());
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == defaultServerId) {
|
||||
return ContainerUtils::containerHumanNames().value(description.defaultContainer);
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString ServersUiController::getDefaultServerDescriptionCollapsed() const
|
||||
{
|
||||
int defaultIndex = getDefaultServerIndex();
|
||||
const ServerConfig server = m_serversController->getServerConfig(defaultIndex);
|
||||
QString description = getDefaultServerDescription(server, defaultIndex);
|
||||
|
||||
if (server.isApiConfig()) {
|
||||
return description;
|
||||
}
|
||||
|
||||
DockerContainer container = server.defaultContainer();
|
||||
QString containerName = ContainerUtils::containerHumanNames().value(container);
|
||||
QString protocolVersion;
|
||||
QString hostName = server.hostName();
|
||||
|
||||
if (ContainerUtils::isAwgContainer(container)) {
|
||||
ContainerConfig containerConfig = server.containerConfig(container);
|
||||
if (auto* awgProtocolConfig = containerConfig.getAwgProtocolConfig()) {
|
||||
QString version = awgProtocolConfig->serverConfig.protocolVersion;
|
||||
if (version == protocols::awg::awgV2) {
|
||||
protocolVersion = QObject::tr(" (version 2)");
|
||||
} else if (version == protocols::awg::awgV1_5) {
|
||||
protocolVersion = QObject::tr(" (version 1.5)");
|
||||
}
|
||||
|
||||
if (container == DockerContainer::Awg && !awgProtocolConfig->serverConfig.isThirdPartyConfig) {
|
||||
containerName = "AmneziaWG Legacy";
|
||||
}
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == defaultServerId) {
|
||||
return description.collapsedServerDescription;
|
||||
}
|
||||
}
|
||||
|
||||
return description + containerName + protocolVersion + " | " + hostName;
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString ServersUiController::getDefaultServerImagePathCollapsed() const
|
||||
{
|
||||
int defaultIndex = getDefaultServerIndex();
|
||||
const ServerConfig server = m_serversController->getServerConfig(defaultIndex);
|
||||
|
||||
if (server.isApiV2()) {
|
||||
const ApiV2ServerConfig* apiV2 = server.as<ApiV2ServerConfig>();
|
||||
if (!apiV2) return QString();
|
||||
const QString countryCode = apiV2->apiConfig.serverCountryCode;
|
||||
if (countryCode.isEmpty()) {
|
||||
return "";
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == defaultServerId) {
|
||||
if (!description.isApiV2 || description.apiServerCountryCode.isEmpty()) {
|
||||
return "";
|
||||
}
|
||||
return QString("qrc:/countriesFlags/images/flagKit/%1.svg").arg(description.apiServerCountryCode.toUpper());
|
||||
}
|
||||
return QString("qrc:/countriesFlags/images/flagKit/%1.svg").arg(countryCode.toUpper());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
QString ServersUiController::getDefaultServerDescriptionExpanded() const
|
||||
{
|
||||
int defaultIndex = getDefaultServerIndex();
|
||||
const ServerConfig server = m_serversController->getServerConfig(defaultIndex);
|
||||
QString description = getDefaultServerDescription(server, defaultIndex);
|
||||
|
||||
if (server.isApiConfig()) {
|
||||
return description;
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == defaultServerId) {
|
||||
return description.expandedServerDescription;
|
||||
}
|
||||
}
|
||||
|
||||
return description + server.hostName();
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool ServersUiController::isDefaultServerDefaultContainerHasSplitTunneling() const
|
||||
{
|
||||
int defaultIndex = getDefaultServerIndex();
|
||||
const ServerConfig server = m_serversController->getServerConfig(defaultIndex);
|
||||
DockerContainer defaultContainer = server.defaultContainer();
|
||||
|
||||
ContainerConfig containerConfig = server.containerConfig(defaultContainer);
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
const DockerContainer defaultContainer = m_serversController->getDefaultContainer(defaultServerId);
|
||||
const ContainerConfig containerConfig = m_serversController->getContainerConfig(defaultServerId, defaultContainer);
|
||||
|
||||
if (defaultContainer == DockerContainer::Awg || defaultContainer == DockerContainer::WireGuard) {
|
||||
auto hasSplitTunnelingFromAllowedIps = [](const QStringList& allowedIps, const QString& nativeConfig) -> bool {
|
||||
@@ -265,16 +281,13 @@ bool ServersUiController::isDefaultServerDefaultContainerHasSplitTunneling() con
|
||||
|
||||
bool ServersUiController::isDefaultServerFromApi() const
|
||||
{
|
||||
int defaultIndex = getDefaultServerIndex();
|
||||
const ServerConfig server = m_serversController->getServerConfig(defaultIndex);
|
||||
const int configVersion = server.configVersion();
|
||||
return configVersion == apiDefs::ConfigSource::Telegram
|
||||
|| configVersion == apiDefs::ConfigSource::AmneziaGateway;
|
||||
}
|
||||
|
||||
int ServersUiController::getProcessedServerIndex() const
|
||||
{
|
||||
return m_processedServerIndex;
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == defaultServerId) {
|
||||
return description.isApiV2;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int ServersUiController::getProcessedContainerIndex() const
|
||||
@@ -291,186 +304,196 @@ void ServersUiController::setProcessedContainerIndex(int index)
|
||||
}
|
||||
}
|
||||
|
||||
void ServersUiController::setProcessedServerIndex(int index)
|
||||
QString ServersUiController::getProcessedServerId() const
|
||||
{
|
||||
if (index >= m_serversController->getServersCount()) {
|
||||
return m_processedServerId;
|
||||
}
|
||||
|
||||
void ServersUiController::setProcessedServerId(const QString &serverId)
|
||||
{
|
||||
const int index = serverId.isEmpty() ? -1 : serverIndexForId(serverId);
|
||||
if (!serverId.isEmpty() && index < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_processedServerIndex != index) {
|
||||
if (m_processedServerIndex != index || m_processedServerId != serverId) {
|
||||
m_processedServerIndex = index;
|
||||
m_processedServerId = serverId;
|
||||
m_serversModel->setProcessedServerIndex(index);
|
||||
|
||||
if (index >= 0) {
|
||||
updateContainersModel();
|
||||
|
||||
ServerConfig server = m_serversController->getServerConfig(index);
|
||||
setProcessedContainerIndex(static_cast<int>(server.defaultContainer()));
|
||||
|
||||
if (server.isApiV2()) {
|
||||
const ApiV2ServerConfig* apiV2 = server.as<ApiV2ServerConfig>();
|
||||
if (apiV2 && !apiV2->apiConfig.availableCountries.isEmpty()) {
|
||||
emit updateApiCountryModel();
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == serverId) {
|
||||
setProcessedContainerIndex(static_cast<int>(description.defaultContainer));
|
||||
break;
|
||||
}
|
||||
emit updateApiServicesModel();
|
||||
}
|
||||
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId != serverId) {
|
||||
continue;
|
||||
}
|
||||
if (description.isApiV2) {
|
||||
if (description.isCountrySelectionAvailable && !description.apiAvailableCountries.isEmpty()) {
|
||||
emit updateApiCountryModel();
|
||||
}
|
||||
emit updateApiServicesModel();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
emit processedServerIdChanged(m_processedServerId);
|
||||
emit processedServerIndexChanged(m_processedServerIndex);
|
||||
}
|
||||
}
|
||||
|
||||
int ServersUiController::getProcessedServerIndex() const
|
||||
{
|
||||
return m_processedServerIndex;
|
||||
}
|
||||
|
||||
void ServersUiController::setProcessedServerIndex(int index)
|
||||
{
|
||||
if (index < 0) {
|
||||
setProcessedServerId(QString());
|
||||
return;
|
||||
}
|
||||
const QString id = getServerId(index);
|
||||
if (!id.isEmpty()) {
|
||||
setProcessedServerId(id);
|
||||
}
|
||||
}
|
||||
|
||||
int ServersUiController::defaultServerIndex() const
|
||||
{
|
||||
return rowForServerId(m_orderedServerDescriptions, getDefaultServerId());
|
||||
}
|
||||
|
||||
bool ServersUiController::processedServerIsPremium() const
|
||||
{
|
||||
ServerConfig server = m_serversController->getServerConfig(m_processedServerIndex);
|
||||
if (server.isApiV1()) {
|
||||
const ApiV1ServerConfig* apiV1 = server.as<ApiV1ServerConfig>();
|
||||
return apiV1 ? apiV1->isPremium() : false;
|
||||
} else if (server.isApiV2()) {
|
||||
const ApiV2ServerConfig* apiV2 = server.as<ApiV2ServerConfig>();
|
||||
return apiV2 ? (apiV2->isPremium() || apiV2->isExternalPremium()) : false;
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == m_processedServerId) {
|
||||
return description.isPremium;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const ServerCredentials ServersUiController::getProcessedServerCredentials() const
|
||||
{
|
||||
return m_serversController->getServerCredentials(m_processedServerIndex);
|
||||
return m_serversController->getServerCredentials(m_processedServerId);
|
||||
}
|
||||
|
||||
bool ServersUiController::isDefaultServerCurrentlyProcessed() const
|
||||
{
|
||||
return m_serversController->getDefaultServerIndex() == m_processedServerIndex;
|
||||
return m_serversController->getDefaultServerId() == m_processedServerId;
|
||||
}
|
||||
|
||||
bool ServersUiController::isProcessedServerHasWriteAccess() const
|
||||
{
|
||||
ServerCredentials credentials = m_serversController->getServerCredentials(m_processedServerIndex);
|
||||
ServerCredentials credentials = m_serversController->getServerCredentials(m_processedServerId);
|
||||
return (!credentials.userName.isEmpty() && !credentials.secretData.isEmpty());
|
||||
}
|
||||
|
||||
|
||||
QString ServersUiController::getDefaultServerDescription(const ServerConfig& server, int index) const
|
||||
QString ServersUiController::getDefaultServerDescription(const QString &serverId) const
|
||||
{
|
||||
QString description;
|
||||
|
||||
if (server.isApiV2()) {
|
||||
const ApiV2ServerConfig* apiV2 = server.as<ApiV2ServerConfig>();
|
||||
if (!apiV2) return QString();
|
||||
if (!apiV2->apiConfig.serverCountryCode.isEmpty()) {
|
||||
return apiV2->apiConfig.serverCountryName;
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == serverId) {
|
||||
return description.baseDescription;
|
||||
}
|
||||
return apiV2->description;
|
||||
} else if (server.isApiV1()) {
|
||||
const ApiV1ServerConfig* apiV1 = server.as<ApiV1ServerConfig>();
|
||||
return apiV1 ? apiV1->description : QString();
|
||||
} else {
|
||||
ServerCredentials credentials = m_serversController->getServerCredentials(index);
|
||||
if (!credentials.userName.isEmpty() && !credentials.secretData.isEmpty()) {
|
||||
bool isAmneziaDnsEnabled = m_settingsController->isAmneziaDnsEnabled();
|
||||
if (isAmneziaDnsEnabled && isAmneziaDnsContainerInstalled(index)) {
|
||||
description += "Amnezia DNS | ";
|
||||
}
|
||||
} else {
|
||||
if (server.dns1() == protocols::dns::amneziaDnsIp) {
|
||||
description += "Amnezia DNS | ";
|
||||
}
|
||||
}
|
||||
return description;
|
||||
}
|
||||
}
|
||||
|
||||
bool ServersUiController::isAmneziaDnsContainerInstalled(int serverIndex) const
|
||||
{
|
||||
const ServerConfig server = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containers = server.containers();
|
||||
|
||||
return containers.contains(DockerContainer::Dns);
|
||||
return QString();
|
||||
}
|
||||
|
||||
bool ServersUiController::hasServersFromGatewayApi() const
|
||||
{
|
||||
QVector<ServerConfig> servers = m_serversController->getServers();
|
||||
for (const ServerConfig &server : servers) {
|
||||
if (server.isApiV2()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return listHasServersFromGatewayApi();
|
||||
}
|
||||
|
||||
bool ServersUiController::isAdVisible() const
|
||||
{
|
||||
int defaultIndex = getDefaultServerIndex();
|
||||
if (defaultIndex < 0) {
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
if (defaultServerId.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
ServerConfig server = m_serversController->getServerConfig(defaultIndex);
|
||||
if (server.isApiV2()) {
|
||||
const ApiV2ServerConfig* apiV2 = server.as<ApiV2ServerConfig>();
|
||||
if (!apiV2) return false;
|
||||
return apiV2->apiConfig.serviceInfo.isAdVisible;
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == defaultServerId) {
|
||||
return description.isAdVisible;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString ServersUiController::adHeader() const
|
||||
{
|
||||
int defaultIndex = getDefaultServerIndex();
|
||||
if (defaultIndex < 0) {
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
if (defaultServerId.isEmpty()) {
|
||||
return QString();
|
||||
}
|
||||
ServerConfig server = m_serversController->getServerConfig(defaultIndex);
|
||||
if (server.isApiV2()) {
|
||||
const ApiV2ServerConfig* apiV2 = server.as<ApiV2ServerConfig>();
|
||||
if (!apiV2) return QString();
|
||||
return apiV2->apiConfig.serviceInfo.adHeader;
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == defaultServerId) {
|
||||
return description.adHeader;
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString ServersUiController::adDescription() const
|
||||
{
|
||||
int defaultIndex = getDefaultServerIndex();
|
||||
if (defaultIndex < 0) {
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
if (defaultServerId.isEmpty()) {
|
||||
return QString();
|
||||
}
|
||||
ServerConfig server = m_serversController->getServerConfig(defaultIndex);
|
||||
if (server.isApiV2()) {
|
||||
const ApiV2ServerConfig* apiV2 = server.as<ApiV2ServerConfig>();
|
||||
if (!apiV2) return QString();
|
||||
return apiV2->apiConfig.serviceInfo.adDescription;
|
||||
for (const auto &description : m_orderedServerDescriptions) {
|
||||
if (description.serverId == defaultServerId) {
|
||||
return description.adDescription;
|
||||
}
|
||||
}
|
||||
return QString();
|
||||
}
|
||||
|
||||
QString ServersUiController::getServerId(int index) const
|
||||
{
|
||||
if (index < 0 || index >= m_orderedServerDescriptions.size()) {
|
||||
return QString();
|
||||
}
|
||||
return m_orderedServerDescriptions.at(index).serverId;
|
||||
}
|
||||
|
||||
int ServersUiController::getServerIndexById(const QString &serverId) const
|
||||
{
|
||||
return rowForServerId(m_orderedServerDescriptions, serverId);
|
||||
}
|
||||
|
||||
void ServersUiController::updateContainersModel()
|
||||
{
|
||||
if (m_processedServerIndex < 0 || m_processedServerIndex >= m_serversController->getServersCount()) {
|
||||
if (m_processedServerId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ServerConfig server = m_serversController->getServerConfig(m_processedServerIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containers = server.containers();
|
||||
const QMap<DockerContainer, ContainerConfig> containers =
|
||||
m_serversController->getServerContainersMap(m_processedServerId);
|
||||
m_containersModel->updateModel(containers);
|
||||
}
|
||||
|
||||
void ServersUiController::updateDefaultServerContainersModel()
|
||||
{
|
||||
int defaultIndex = m_serversController->getDefaultServerIndex();
|
||||
if (defaultIndex < 0 || defaultIndex >= m_serversController->getServersCount()) {
|
||||
const QString defaultServerId = m_serversController->getDefaultServerId();
|
||||
if (defaultServerId.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
ServerConfig server = m_serversController->getServerConfig(defaultIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containers = server.containers();
|
||||
const QMap<DockerContainer, ContainerConfig> containers =
|
||||
m_serversController->getServerContainersMap(defaultServerId);
|
||||
m_defaultServerContainersModel->updateModel(containers);
|
||||
}
|
||||
|
||||
QStringList ServersUiController::getAllInstalledServicesName(int serverIndex) const
|
||||
{
|
||||
QStringList servicesName;
|
||||
ServerConfig server = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containers = server.containers();
|
||||
|
||||
const QString serverId = getServerId(serverIndex);
|
||||
const QMap<DockerContainer, ContainerConfig> containers = m_serversController->getServerContainersMap(serverId);
|
||||
|
||||
for (auto it = containers.begin(); it != containers.end(); ++it) {
|
||||
DockerContainer container = it.key();
|
||||
if (ContainerUtils::containerService(container) == ServiceType::Other) {
|
||||
@@ -489,3 +512,13 @@ QStringList ServersUiController::getAllInstalledServicesName(int serverIndex) co
|
||||
return servicesName;
|
||||
}
|
||||
|
||||
int ServersUiController::serverIndexForId(const QString &serverId) const
|
||||
{
|
||||
return rowForServerId(m_orderedServerDescriptions, serverId);
|
||||
}
|
||||
|
||||
bool ServersUiController::listHasServersFromGatewayApi() const
|
||||
{
|
||||
return descriptionsHaveGatewayServers(m_orderedServerDescriptions);
|
||||
}
|
||||
|
||||
|
||||
@@ -6,35 +6,39 @@
|
||||
#include <QSet>
|
||||
#include <QJsonObject>
|
||||
#include <QStringList>
|
||||
#include <QVector>
|
||||
|
||||
#include "core/controllers/serversController.h"
|
||||
#include "core/models/serverDescription.h"
|
||||
#include "core/controllers/settingsController.h"
|
||||
#include "ui/models/serversModel.h"
|
||||
#include "ui/models/containersModel.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
|
||||
class ServersUiController : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(int defaultIndex READ getDefaultServerIndex NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(QString defaultServerName READ getDefaultServerName NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(QString defaultServerDefaultContainerName READ getDefaultServerDefaultContainerName NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(QString defaultServerDescriptionCollapsed READ getDefaultServerDescriptionCollapsed NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(QString defaultServerImagePathCollapsed READ getDefaultServerImagePathCollapsed NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(QString defaultServerDescriptionExpanded READ getDefaultServerDescriptionExpanded NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(bool isDefaultServerDefaultContainerHasSplitTunneling READ isDefaultServerDefaultContainerHasSplitTunneling NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(bool isDefaultServerFromApi READ isDefaultServerFromApi NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(QString defaultServerId READ getDefaultServerId NOTIFY defaultServerIdChanged)
|
||||
Q_PROPERTY(int defaultServerIndex READ defaultServerIndex NOTIFY defaultServerIndexChanged)
|
||||
|
||||
Q_PROPERTY(QString defaultServerName READ getDefaultServerName NOTIFY defaultServerIdChanged)
|
||||
Q_PROPERTY(QString defaultServerDefaultContainerName READ getDefaultServerDefaultContainerName NOTIFY defaultServerIdChanged)
|
||||
Q_PROPERTY(QString defaultServerDescriptionCollapsed READ getDefaultServerDescriptionCollapsed NOTIFY defaultServerIdChanged)
|
||||
Q_PROPERTY(QString defaultServerImagePathCollapsed READ getDefaultServerImagePathCollapsed NOTIFY defaultServerIdChanged)
|
||||
Q_PROPERTY(QString defaultServerDescriptionExpanded READ getDefaultServerDescriptionExpanded NOTIFY defaultServerIdChanged)
|
||||
Q_PROPERTY(bool isDefaultServerDefaultContainerHasSplitTunneling READ isDefaultServerDefaultContainerHasSplitTunneling NOTIFY defaultServerIdChanged)
|
||||
Q_PROPERTY(bool isDefaultServerFromApi READ isDefaultServerFromApi NOTIFY defaultServerIdChanged)
|
||||
|
||||
Q_PROPERTY(int processedIndex READ getProcessedServerIndex WRITE setProcessedServerIndex NOTIFY processedServerIndexChanged)
|
||||
Q_PROPERTY(QString processedServerId READ getProcessedServerId WRITE setProcessedServerId NOTIFY processedServerIdChanged)
|
||||
Q_PROPERTY(int processedServerIndex READ getProcessedServerIndex WRITE setProcessedServerIndex NOTIFY processedServerIndexChanged)
|
||||
Q_PROPERTY(int processedContainerIndex READ getProcessedContainerIndex WRITE setProcessedContainerIndex NOTIFY processedContainerIndexChanged)
|
||||
Q_PROPERTY(bool processedServerIsPremium READ processedServerIsPremium NOTIFY processedServerIndexChanged)
|
||||
|
||||
Q_PROPERTY(bool hasServersFromGatewayApi READ hasServersFromGatewayApi NOTIFY hasServersFromGatewayApiChanged)
|
||||
|
||||
Q_PROPERTY(bool isAdVisible READ isAdVisible NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(QString adHeader READ adHeader NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(QString adDescription READ adDescription NOTIFY defaultServerIndexChanged)
|
||||
Q_PROPERTY(bool isAdVisible READ isAdVisible NOTIFY defaultServerIdChanged)
|
||||
Q_PROPERTY(QString adHeader READ adHeader NOTIFY defaultServerIdChanged)
|
||||
Q_PROPERTY(QString adDescription READ adDescription NOTIFY defaultServerIdChanged)
|
||||
|
||||
public:
|
||||
explicit ServersUiController(ServersController* serversController,
|
||||
@@ -45,15 +49,22 @@ public:
|
||||
QObject *parent = nullptr);
|
||||
|
||||
public slots:
|
||||
void removeServer(int index);
|
||||
void editServerName(int index, const QString &name);
|
||||
void setDefaultServerIndex(int index);
|
||||
void setDefaultContainer(int serverIndex, int containerIndex);
|
||||
void removeServer(const QString &serverId);
|
||||
void removeServerAtIndex(int index);
|
||||
|
||||
void editServerName(const QString &serverId, const QString &name);
|
||||
|
||||
void setDefaultServer(const QString &serverId);
|
||||
void setDefaultServerAtIndex(int index);
|
||||
|
||||
void setDefaultContainer(const QString &serverId, int containerIndex);
|
||||
void setDefaultContainerAtIndex(int index, int containerIndex);
|
||||
|
||||
void toggleAmneziaDns(bool enabled);
|
||||
void onDefaultServerChanged(int index);
|
||||
void onDefaultServerChanged(const QString &defaultServerId);
|
||||
|
||||
// Getters for properties
|
||||
int getDefaultServerIndex() const;
|
||||
QString getDefaultServerId() const;
|
||||
QString getDefaultServerName() const;
|
||||
QString getDefaultServerDefaultContainerName() const;
|
||||
QString getDefaultServerDescriptionCollapsed() const;
|
||||
@@ -62,8 +73,14 @@ public slots:
|
||||
bool isDefaultServerDefaultContainerHasSplitTunneling() const;
|
||||
bool isDefaultServerFromApi() const;
|
||||
|
||||
QString getProcessedServerId() const;
|
||||
void setProcessedServerId(const QString &serverId);
|
||||
|
||||
int getProcessedServerIndex() const;
|
||||
void setProcessedServerIndex(int index);
|
||||
|
||||
int defaultServerIndex() const;
|
||||
|
||||
int getProcessedContainerIndex() const;
|
||||
void setProcessedContainerIndex(int index);
|
||||
bool processedServerIsPremium() const;
|
||||
@@ -78,12 +95,16 @@ public slots:
|
||||
QString adHeader() const;
|
||||
QString adDescription() const;
|
||||
|
||||
QString getServerId(int index) const;
|
||||
int getServerIndexById(const QString &serverId) const;
|
||||
QStringList getAllInstalledServicesName(int serverIndex) const;
|
||||
|
||||
signals:
|
||||
void errorOccurred(const QString &errorMessage);
|
||||
void finished(const QString &message);
|
||||
void defaultServerIdChanged(const QString &serverId);
|
||||
void defaultServerIndexChanged(int index);
|
||||
void processedServerIdChanged(const QString &serverId);
|
||||
void processedServerIndexChanged(int index);
|
||||
void processedContainerIndexChanged(int index);
|
||||
void hasServersFromGatewayApiChanged();
|
||||
@@ -94,20 +115,23 @@ public:
|
||||
void updateModel();
|
||||
|
||||
private:
|
||||
QString getDefaultServerDescription(const ServerConfig& server, int index) const;
|
||||
bool isAmneziaDnsContainerInstalled(int serverIndex) const;
|
||||
QString getDefaultServerDescription(const QString &serverId) const;
|
||||
int serverIndexForId(const QString &serverId) const;
|
||||
bool listHasServersFromGatewayApi() const;
|
||||
|
||||
void updateContainersModel();
|
||||
void updateDefaultServerContainersModel();
|
||||
void updateApiModelsForProcessedServer();
|
||||
|
||||
|
||||
ServersController* m_serversController;
|
||||
SettingsController* m_settingsController;
|
||||
ServersModel* m_serversModel;
|
||||
ContainersModel* m_containersModel;
|
||||
ContainersModel* m_defaultServerContainersModel;
|
||||
|
||||
QVector<amnezia::ServerDescription> m_orderedServerDescriptions;
|
||||
|
||||
int m_processedServerIndex = -1;
|
||||
QString m_processedServerId;
|
||||
int m_processedContainerIndex = -1;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user