mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
Feat: add the revoke call subscription from the apps
This commit is contained in:
@@ -491,7 +491,7 @@ ErrorCode SubscriptionController::updateServiceFromGateway(int serverIndex, cons
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
|
||||
ErrorCode SubscriptionController::deactivateDevice(int serverIndex)
|
||||
ErrorCode SubscriptionController::requestPremiumGatewayRevokeConfig(int serverIndex, QByteArray &responseBody)
|
||||
{
|
||||
ServerConfig serverConfigModel = m_serversRepository->server(serverIndex);
|
||||
|
||||
@@ -522,8 +522,28 @@ ErrorCode SubscriptionController::deactivateDevice(int serverIndex)
|
||||
QJsonObject apiPayload = gatewayRequestData.toJsonObject();
|
||||
|
||||
const bool isTestPurchase = apiV2->apiConfig.isTestPurchase;
|
||||
return executeRequest(QString("%1v1/revoke_config"), apiPayload, responseBody, isTestPurchase);
|
||||
}
|
||||
|
||||
ErrorCode SubscriptionController::deactivateDevice(int serverIndex)
|
||||
{
|
||||
ServerConfig serverConfigModel = m_serversRepository->server(serverIndex);
|
||||
|
||||
if (!serverConfigModel.isApiV2()) {
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
|
||||
const ApiV2ServerConfig* apiV2 = serverConfigModel.as<ApiV2ServerConfig>();
|
||||
if (!apiV2) {
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
|
||||
if (!apiV2->isPremium() && !apiV2->isExternalPremium()) {
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
|
||||
QByteArray responseBody;
|
||||
ErrorCode errorCode = executeRequest(QString("%1v1/revoke_config"), apiPayload, responseBody, isTestPurchase);
|
||||
ErrorCode errorCode = requestPremiumGatewayRevokeConfig(serverIndex, responseBody);
|
||||
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
|
||||
return errorCode;
|
||||
}
|
||||
@@ -535,6 +555,20 @@ ErrorCode SubscriptionController::deactivateDevice(int serverIndex)
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
|
||||
void SubscriptionController::revokeGatewayConfigBestEffort(int serverIndex)
|
||||
{
|
||||
if (serverIndex < 0 || serverIndex >= m_serversRepository->serversCount()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray responseBody;
|
||||
const ErrorCode errorCode = requestPremiumGatewayRevokeConfig(serverIndex, responseBody);
|
||||
if (errorCode != ErrorCode::NoError && errorCode != ErrorCode::ApiNotFoundError) {
|
||||
qWarning().noquote() << "SubscriptionController: revoke_config failed while removing server (error"
|
||||
<< static_cast<int>(errorCode) << "); removing locally anyway.";
|
||||
}
|
||||
}
|
||||
|
||||
ErrorCode SubscriptionController::deactivateExternalDevice(int serverIndex, const QString &uuid, const QString &serverCountryCode)
|
||||
{
|
||||
ServerConfig serverConfigModel = m_serversRepository->server(serverIndex);
|
||||
|
||||
@@ -67,6 +67,8 @@ public:
|
||||
|
||||
ErrorCode deactivateDevice(int serverIndex);
|
||||
|
||||
void revokeGatewayConfigBestEffort(int serverIndex);
|
||||
|
||||
ErrorCode deactivateExternalDevice(int serverIndex, const QString &uuid, const QString &serverCountryCode);
|
||||
|
||||
ErrorCode exportNativeConfig(int serverIndex, const QString &serverCountryCode, QString &nativeConfig);
|
||||
@@ -105,6 +107,8 @@ public:
|
||||
const QString &serviceProtocol);
|
||||
|
||||
private:
|
||||
ErrorCode requestPremiumGatewayRevokeConfig(int serverIndex, QByteArray &responseBody);
|
||||
|
||||
ErrorCode executeRequest(const QString &endpoint, const QJsonObject &apiPayload, QByteArray &responseBody, bool isTestPurchase = false);
|
||||
bool isApiKeyExpired(int serverIndex) const;
|
||||
|
||||
|
||||
@@ -170,7 +170,7 @@ void CoreController::initControllers()
|
||||
#ifdef Q_OS_WINDOWS
|
||||
m_ikev2ConfigModel,
|
||||
#endif
|
||||
m_sftpConfigModel, m_socks5ConfigModel, this);
|
||||
m_sftpConfigModel, m_socks5ConfigModel, m_subscriptionController, this);
|
||||
setQmlContextProperty("InstallController", m_installUiController);
|
||||
|
||||
m_importController = new ImportUiController(m_importCoreController, this);
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "core/utils/utilities.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "core/models/containerConfig.h"
|
||||
#include "core/controllers/api/subscriptionController.h"
|
||||
#include "core/models/protocols/awgProtocolConfig.h"
|
||||
#include "core/models/protocols/wireGuardProtocolConfig.h"
|
||||
#include "core/models/protocols/openVpnProtocolConfig.h"
|
||||
@@ -69,6 +70,7 @@ InstallUiController::InstallUiController(InstallController *installController,
|
||||
#endif
|
||||
SftpConfigModel *sftpConfigModel,
|
||||
Socks5ProxyConfigModel *socks5ConfigModel,
|
||||
SubscriptionController *subscriptionController,
|
||||
QObject *parent)
|
||||
: QObject(parent),
|
||||
m_installController(installController),
|
||||
@@ -85,7 +87,8 @@ InstallUiController::InstallUiController(InstallController *installController,
|
||||
m_ikev2ConfigModel(ikev2ConfigModel),
|
||||
#endif
|
||||
m_sftpConfigModel(sftpConfigModel),
|
||||
m_socks5ConfigModel(socks5ConfigModel)
|
||||
m_socks5ConfigModel(socks5ConfigModel),
|
||||
m_subscriptionController(subscriptionController)
|
||||
{
|
||||
connect(m_installController, &InstallController::configValidated, this, &InstallUiController::configValidated);
|
||||
connect(m_installController, &InstallController::validationErrorOccurred, this, [this](ErrorCode errorCode) {
|
||||
@@ -287,6 +290,10 @@ void InstallUiController::removeServer(int serverIndex)
|
||||
{
|
||||
QString serverName = m_serversController->getServerConfig(serverIndex).displayName();
|
||||
|
||||
if (m_subscriptionController) {
|
||||
m_subscriptionController->revokeGatewayConfigBestEffort(serverIndex);
|
||||
}
|
||||
|
||||
m_serversController->removeServer(serverIndex);
|
||||
emit removeServerFinished(tr("Server '%1' was removed").arg(serverName));
|
||||
}
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include "core/controllers/selfhosted/usersController.h"
|
||||
#include "core/controllers/selfhosted/installController.h"
|
||||
#include "core/utils/errorCodes.h"
|
||||
|
||||
class SubscriptionController;
|
||||
#include "core/utils/routeModes.h"
|
||||
#include "core/utils/commonStructs.h"
|
||||
#include "core/models/containerConfig.h"
|
||||
@@ -48,6 +50,7 @@ public:
|
||||
#endif
|
||||
SftpConfigModel* sftpConfigModel,
|
||||
Socks5ProxyConfigModel* socks5ConfigModel,
|
||||
SubscriptionController* subscriptionController,
|
||||
QObject *parent = nullptr);
|
||||
~InstallUiController();
|
||||
|
||||
@@ -141,6 +144,8 @@ private:
|
||||
SftpConfigModel* m_sftpConfigModel;
|
||||
Socks5ProxyConfigModel* m_socks5ConfigModel;
|
||||
|
||||
SubscriptionController* m_subscriptionController;
|
||||
|
||||
ServerCredentials m_processedServerCredentials;
|
||||
|
||||
QString m_privateKeyPassphrase;
|
||||
|
||||
Reference in New Issue
Block a user