mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-12-05 06:33:57 +09:00
* fix: share double-stop guard via VpnProtocol base class * feat: add local proxy core module * feat: local proxy settings api * feat: wire local proxy into app controllers * feat: local proxy settings ui * feat: arbitrate shared xray engine ownership via ipc tokens * fix: remove connection type * chore: add qthttpserver to desktop ci qt modules * fix: local proxy port fallback and active port reporting * fix: keep text field button aligned when error is shown * fix: hide local proxy for free servers and guard device unlink * fix: show local proxy state per server * fix: anchor text field button to content * fix: adapt local proxy pages to design * fix: copy logic and port logic * refactor: move local proxy files to controllers and utils * refactor: merge local proxy into LocalProxyController * refactor: reuse gateway config request and keep local proxy state in memory --------- Co-authored-by: vkamn <vk@amnezia.org>
48 lines
1.5 KiB
C++
48 lines
1.5 KiB
C++
#include "xrayConfigUtils.h"
|
|
|
|
#include "core/utils/constants/configKeys.h"
|
|
#include "core/utils/containers/containerUtils.h"
|
|
|
|
#include <QJsonArray>
|
|
|
|
using namespace amnezia;
|
|
|
|
std::optional<QString> xrayConfigUtils::extractLastConfig(const QJsonObject &serverConfig)
|
|
{
|
|
const QJsonArray containers = serverConfig.value(configKey::containers).toArray();
|
|
const QString targetContainer = ContainerUtils::containerToString(DockerContainer::Xray);
|
|
|
|
for (const QJsonValue &value : containers) {
|
|
const QJsonObject container = value.toObject();
|
|
if (container.value(configKey::container).toString() != targetContainer) {
|
|
continue;
|
|
}
|
|
|
|
const QJsonObject proto = container.value(QString(configKey::xray)).toObject();
|
|
const QString serialized = proto.value(configKey::lastConfig).toString();
|
|
if (!serialized.isEmpty()) {
|
|
return serialized;
|
|
}
|
|
}
|
|
|
|
return std::nullopt;
|
|
}
|
|
|
|
bool xrayConfigUtils::setInboundPort(QJsonObject &xrayConfig, int port)
|
|
{
|
|
if (!xrayConfig.value(QLatin1String("inbounds")).isArray()) {
|
|
return false;
|
|
}
|
|
|
|
QJsonArray inbounds = xrayConfig.value(QLatin1String("inbounds")).toArray();
|
|
if (inbounds.isEmpty() || !inbounds.at(0).isObject()) {
|
|
return false;
|
|
}
|
|
|
|
QJsonObject firstInbound = inbounds.at(0).toObject();
|
|
firstInbound.insert(QLatin1String("port"), port);
|
|
inbounds[0] = firstInbound;
|
|
xrayConfig.insert(QLatin1String("inbounds"), inbounds);
|
|
return true;
|
|
}
|