mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-24 02:00:24 +07:00
feat: add server UUID management and local proxy settings
- Implemented UUID migration for servers to ensure each server has a unique identifier. - Added methods for managing local proxy settings, including owner UUID, port, and HTTP enablement. - Updated server model to include server UUID role for better data handling.
This commit is contained in:
@@ -29,7 +29,6 @@ CoreController::CoreController(const QSharedPointer<VpnConnection> &vpnConnectio
|
|||||||
|
|
||||||
initLocalProxy();
|
initLocalProxy();
|
||||||
|
|
||||||
auto locale = m_settings->getAppLanguage();
|
|
||||||
m_translator.reset(new QTranslator());
|
m_translator.reset(new QTranslator());
|
||||||
updateTranslator(m_settings->getAppLanguage());
|
updateTranslator(m_settings->getAppLanguage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ QJsonObject ConfigManager::deserializeConfig(const QString &configStr, QString *
|
|||||||
outConfig = amnezia::serialization::vmess_new::Deserialize(configStr, safePrefix, safeErrorMsg);
|
outConfig = amnezia::serialization::vmess_new::Deserialize(configStr, safePrefix, safeErrorMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configStr.startsWith("vmess://")) {
|
else if (configStr.startsWith("vmess://")) {
|
||||||
ProxyLogger::getInstance().debug("Deserializing VMess config");
|
ProxyLogger::getInstance().debug("Deserializing VMess config");
|
||||||
outConfig = amnezia::serialization::vmess::Deserialize(configStr, safePrefix, safeErrorMsg);
|
outConfig = amnezia::serialization::vmess::Deserialize(configStr, safePrefix, safeErrorMsg);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,6 @@ bool ProxyService::updateConfig(const QString& configStr)
|
|||||||
bool ProxyService::startXray()
|
bool ProxyService::startXray()
|
||||||
{
|
{
|
||||||
ProxyLogger::getInstance().info("Starting Xray");
|
ProxyLogger::getInstance().info("Starting Xray");
|
||||||
auto activeConfig = m_configManager->getActiveConfigPath();
|
|
||||||
qDebug() << activeConfig;
|
|
||||||
bool success = m_xrayController->start(m_configManager->getActiveConfigPath());
|
bool success = m_xrayController->start(m_configManager->getActiveConfigPath());
|
||||||
if (success) {
|
if (success) {
|
||||||
ProxyLogger::getInstance().info("Xray started successfully");
|
ProxyLogger::getInstance().info("Xray started successfully");
|
||||||
|
|||||||
@@ -114,6 +114,8 @@ namespace amnezia
|
|||||||
|
|
||||||
constexpr char nameOverriddenByUser[] = "nameOverriddenByUser";
|
constexpr char nameOverriddenByUser[] = "nameOverriddenByUser";
|
||||||
|
|
||||||
|
constexpr char server_uuid[] = "server_uuid";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace protocols
|
namespace protocols
|
||||||
|
|||||||
+70
-1
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include "containers/containers_defs.h"
|
#include "containers/containers_defs.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -43,6 +44,8 @@ Settings::Settings(QObject *parent) : QObject(parent), m_settings(ORGANIZATION_N
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
migrateServerUuids();
|
||||||
|
|
||||||
m_gatewayEndpoint = gatewayEndpoint;
|
m_gatewayEndpoint = gatewayEndpoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,8 +65,16 @@ QJsonObject Settings::server(int index) const
|
|||||||
|
|
||||||
void Settings::addServer(const QJsonObject &server)
|
void Settings::addServer(const QJsonObject &server)
|
||||||
{
|
{
|
||||||
|
QJsonObject serverWithUuid = server;
|
||||||
|
if (!serverWithUuid.contains(config_key::server_uuid)) {
|
||||||
|
QString uuid = QUuid::createUuid().toString();
|
||||||
|
uuid.remove(0, 1);
|
||||||
|
uuid.chop(1);
|
||||||
|
serverWithUuid.insert(config_key::server_uuid, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
QJsonArray servers = serversArray();
|
QJsonArray servers = serversArray();
|
||||||
servers.append(server);
|
servers.append(serverWithUuid);
|
||||||
setServersArray(servers);
|
setServersArray(servers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -479,6 +490,31 @@ void Settings::setInstallationUuid(const QString &uuid)
|
|||||||
setValue("Conf/installationUuid", uuid);
|
setValue("Conf/installationUuid", uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Settings::migrateServerUuids()
|
||||||
|
{
|
||||||
|
QJsonArray servers = serversArray();
|
||||||
|
bool hasChanges = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < servers.size(); ++i) {
|
||||||
|
QJsonObject server = servers.at(i).toObject();
|
||||||
|
if (!server.contains(config_key::server_uuid)) {
|
||||||
|
QString uuid = QUuid::createUuid().toString();
|
||||||
|
qDebug() << "Migrating server uuid: " << uuid;
|
||||||
|
// Remove {} from uuid (as in getInstallationUuid)
|
||||||
|
uuid.remove(0, 1);
|
||||||
|
uuid.chop(1);
|
||||||
|
server.insert(config_key::server_uuid, uuid);
|
||||||
|
servers.replace(i, server);
|
||||||
|
qDebug() << "Server uuid migrated: " << server;
|
||||||
|
hasChanges = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasChanges) {
|
||||||
|
setServersArray(servers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ServerCredentials Settings::defaultServerCredentials() const
|
ServerCredentials Settings::defaultServerCredentials() const
|
||||||
{
|
{
|
||||||
return serverCredentials(defaultServerIndex());
|
return serverCredentials(defaultServerIndex());
|
||||||
@@ -588,3 +624,36 @@ void Settings::setReadNewsIds(const QStringList &ids)
|
|||||||
{
|
{
|
||||||
setValue("News/readIds", ids);
|
setValue("News/readIds", ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString Settings::localProxyOwnerUuid() const
|
||||||
|
{
|
||||||
|
return value("Conf/localProxyOwnerUuid", "").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setLocalProxyOwnerUuid(const QString &uuid)
|
||||||
|
{
|
||||||
|
setValue("Conf/localProxyOwnerUuid", uuid);
|
||||||
|
emit localProxySettingsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
quint16 Settings::localProxyPort() const
|
||||||
|
{
|
||||||
|
return value("Conf/localProxyPort", 0).toUInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setLocalProxyPort(quint16 port)
|
||||||
|
{
|
||||||
|
setValue("Conf/localProxyPort", port);
|
||||||
|
emit localProxySettingsChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Settings::isLocalProxyHttpEnabled() const
|
||||||
|
{
|
||||||
|
return value("Conf/localProxyHttpEnabled", false).toBool();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Settings::setLocalProxyHttpEnabled(bool enabled)
|
||||||
|
{
|
||||||
|
setValue("Conf/localProxyHttpEnabled", enabled);
|
||||||
|
emit localProxySettingsChanged();
|
||||||
|
}
|
||||||
|
|||||||
@@ -239,11 +239,20 @@ public:
|
|||||||
QStringList readNewsIds() const;
|
QStringList readNewsIds() const;
|
||||||
void setReadNewsIds(const QStringList &ids);
|
void setReadNewsIds(const QStringList &ids);
|
||||||
|
|
||||||
|
// Local proxy settings
|
||||||
|
QString localProxyOwnerUuid() const;
|
||||||
|
void setLocalProxyOwnerUuid(const QString &uuid);
|
||||||
|
quint16 localProxyPort() const;
|
||||||
|
void setLocalProxyPort(quint16 port);
|
||||||
|
bool isLocalProxyHttpEnabled() const;
|
||||||
|
void setLocalProxyHttpEnabled(bool enabled);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void saveLogsChanged(bool enabled);
|
void saveLogsChanged(bool enabled);
|
||||||
void screenshotsEnabledChanged(bool enabled);
|
void screenshotsEnabledChanged(bool enabled);
|
||||||
void serverRemoved(int serverIndex);
|
void serverRemoved(int serverIndex);
|
||||||
void settingsCleared();
|
void settingsCleared();
|
||||||
|
void localProxySettingsChanged();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
|
||||||
@@ -251,6 +260,8 @@ private:
|
|||||||
|
|
||||||
void setInstallationUuid(const QString &uuid);
|
void setInstallationUuid(const QString &uuid);
|
||||||
|
|
||||||
|
void migrateServerUuids();
|
||||||
|
|
||||||
mutable SecureQSettings m_settings;
|
mutable SecureQSettings m_settings;
|
||||||
|
|
||||||
QString m_gatewayEndpoint;
|
QString m_gatewayEndpoint;
|
||||||
|
|||||||
@@ -179,6 +179,9 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
|
|||||||
case AdEndpointRole: {
|
case AdEndpointRole: {
|
||||||
return apiConfig.value(apiDefs::key::serviceInfo).toObject().value(apiDefs::key::adEndpoint).toString();
|
return apiConfig.value(apiDefs::key::serviceInfo).toObject().value(apiDefs::key::adEndpoint).toString();
|
||||||
}
|
}
|
||||||
|
case ServerUuidRole: {
|
||||||
|
return server.value(config_key::server_uuid).toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
@@ -443,6 +446,8 @@ QHash<int, QByteArray> ServersModel::roleNames() const
|
|||||||
roles[AdDescriptionRole] = "adDescription";
|
roles[AdDescriptionRole] = "adDescription";
|
||||||
roles[AdEndpointRole] = "adEndpoint";
|
roles[AdEndpointRole] = "adEndpoint";
|
||||||
|
|
||||||
|
roles[ServerUuidRole] = "serverUuid";
|
||||||
|
|
||||||
return roles;
|
return roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -972,3 +977,10 @@ QString ServersModel::adDescription()
|
|||||||
{
|
{
|
||||||
return data(m_defaultServerIndex, AdDescriptionRole).toString();
|
return data(m_defaultServerIndex, AdDescriptionRole).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString ServersModel::getServerUuid(int index) const
|
||||||
|
{
|
||||||
|
if (index < 0 || index >= m_servers.size())
|
||||||
|
return QString();
|
||||||
|
return m_servers.at(index).toObject().value(config_key::server_uuid).toString();
|
||||||
|
}
|
||||||
|
|||||||
@@ -52,7 +52,9 @@ public:
|
|||||||
AdDescriptionRole,
|
AdDescriptionRole,
|
||||||
AdEndpointRole,
|
AdEndpointRole,
|
||||||
|
|
||||||
HasAmneziaDns
|
HasAmneziaDns,
|
||||||
|
|
||||||
|
ServerUuidRole
|
||||||
};
|
};
|
||||||
|
|
||||||
ServersModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
ServersModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
|
||||||
@@ -157,6 +159,8 @@ public slots:
|
|||||||
QString adHeader();
|
QString adHeader();
|
||||||
QString adDescription();
|
QString adDescription();
|
||||||
|
|
||||||
|
QString getServerUuid(int index) const;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QHash<int, QByteArray> roleNames() const override;
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user