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:
aiamnezia
2025-12-30 11:02:59 +04:00
parent 300558c33c
commit 41ab51a5ef
8 changed files with 101 additions and 6 deletions

View File

@@ -29,7 +29,6 @@ CoreController::CoreController(const QSharedPointer<VpnConnection> &vpnConnectio
initLocalProxy();
auto locale = m_settings->getAppLanguage();
m_translator.reset(new QTranslator());
updateTranslator(m_settings->getAppLanguage());
}

View File

@@ -199,7 +199,7 @@ QJsonObject ConfigManager::deserializeConfig(const QString &configStr, QString *
outConfig = amnezia::serialization::vmess_new::Deserialize(configStr, safePrefix, safeErrorMsg);
}
if (configStr.startsWith("vmess://")) {
else if (configStr.startsWith("vmess://")) {
ProxyLogger::getInstance().debug("Deserializing VMess config");
outConfig = amnezia::serialization::vmess::Deserialize(configStr, safePrefix, safeErrorMsg);
}

View File

@@ -31,8 +31,6 @@ bool ProxyService::updateConfig(const QString& configStr)
bool ProxyService::startXray()
{
ProxyLogger::getInstance().info("Starting Xray");
auto activeConfig = m_configManager->getActiveConfigPath();
qDebug() << activeConfig;
bool success = m_xrayController->start(m_configManager->getActiveConfigPath());
if (success) {
ProxyLogger::getInstance().info("Xray started successfully");

View File

@@ -114,6 +114,8 @@ namespace amnezia
constexpr char nameOverriddenByUser[] = "nameOverriddenByUser";
constexpr char server_uuid[] = "server_uuid";
}
namespace protocols

View File

@@ -8,6 +8,7 @@
#include "containers/containers_defs.h"
#include "logger.h"
#include <QUuid>
namespace
{
@@ -43,6 +44,8 @@ Settings::Settings(QObject *parent) : QObject(parent), m_settings(ORGANIZATION_N
}
}
migrateServerUuids();
m_gatewayEndpoint = gatewayEndpoint;
}
@@ -62,8 +65,16 @@ QJsonObject Settings::server(int index) const
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();
servers.append(server);
servers.append(serverWithUuid);
setServersArray(servers);
}
@@ -479,6 +490,31 @@ void Settings::setInstallationUuid(const QString &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
{
return serverCredentials(defaultServerIndex());
@@ -588,3 +624,36 @@ void Settings::setReadNewsIds(const QStringList &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();
}

View File

@@ -239,11 +239,20 @@ public:
QStringList readNewsIds() const;
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:
void saveLogsChanged(bool enabled);
void screenshotsEnabledChanged(bool enabled);
void serverRemoved(int serverIndex);
void settingsCleared();
void localProxySettingsChanged();
private:
QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
@@ -251,6 +260,8 @@ private:
void setInstallationUuid(const QString &uuid);
void migrateServerUuids();
mutable SecureQSettings m_settings;
QString m_gatewayEndpoint;

View File

@@ -179,6 +179,9 @@ QVariant ServersModel::data(const QModelIndex &index, int role) const
case AdEndpointRole: {
return apiConfig.value(apiDefs::key::serviceInfo).toObject().value(apiDefs::key::adEndpoint).toString();
}
case ServerUuidRole: {
return server.value(config_key::server_uuid).toString();
}
}
return QVariant();
@@ -443,6 +446,8 @@ QHash<int, QByteArray> ServersModel::roleNames() const
roles[AdDescriptionRole] = "adDescription";
roles[AdEndpointRole] = "adEndpoint";
roles[ServerUuidRole] = "serverUuid";
return roles;
}
@@ -972,3 +977,10 @@ QString ServersModel::adDescription()
{
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();
}

View File

@@ -52,7 +52,9 @@ public:
AdDescriptionRole,
AdEndpointRole,
HasAmneziaDns
HasAmneziaDns,
ServerUuidRole
};
ServersModel(std::shared_ptr<Settings> settings, QObject *parent = nullptr);
@@ -156,6 +158,8 @@ public slots:
bool isAdVisible();
QString adHeader();
QString adDescription();
QString getServerUuid(int index) const;
protected:
QHash<int, QByteArray> roleNames() const override;