mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-17 08:16:06 +03:00
* refactor: move business logic from servers model * refactor: move containersModel initialization * refactor: added protocol ui controller and removed settings class from protocols model * refactor: moved cli management to separate controller * refactor: moved app split to separate controller * refactor: moved site split to separate controller * refactor: moved allowed dns to separate controller * refactor: moved language logic to separate ui controller * refactor: removed Settings from devices model * refactor: moved configs and services api logit to separate core controller * refactor: added a layer with a repository between the storage and controllers * refactor: use child parent system instead of smart pointers for controllers and models initialization * refactor: moved install functions from server controller to install controller * refactor: install controller refactoring * chore: renamed exportController to exportUiController * refactor: separate export controller * refactor: removed VpnConfigurationsController * chore: renamed ServerController to SshSession * refactor: replaced ServerController to SshSession * chore: moved qml controllers to separate folder * chore: include fixes * chore: moved utils from core root to core/utils * chore: include fixes * chore: rename core/utils files to camelCase foramt * chore: include fixes * chore: moved some utils to api and selfhosted folders * chore: include fixes * chore: remove unused file * chore: moved serialization folder to core/utils * chore: include fixes * chore: moved some files from client root to core/utils * chore: include fixes * chore: moved ui utils to ui/utils folder * chore: include fixes * chore: move utils from root to ui/utils * chore: include fixes * chore: moved configurators to core/configurators * chore: include fixes * refactor: moved iap logic from ui controller to core * refactor: moved remaining core logic from ApiConfigsController to SubscriptionController * chore: rename apiNewsController to apiNewsUiController * refactor: moved core logic from news ui controller to core * chore: renamed apiConfigsController to subscriptionUiController * chore: include fixes * refactor: merge ApiSettingsController with SubscriptionUiController * chore: moved ui selfhosted controllers to separate folder * chore: include fixes * chore: rename connectionController to connectiomUiController * refactor: moved core logic from connectionUiController * chore: rename settingsController to settingsUiController * refactor: move core logic from settingsUiController * refactor: moved core controller signal/slot connections to separate class * fix: newsController fixes after refactoring * chore: rename model to camelCase * chore: include fixes * chore: remove unused code * chore: move selfhosted core to separate folder * chore: include fixes * chore: rename importController to importUiController * refactor: move core logic from importUiController * chore: minor fixes * chore: remove prem v1 migration * refactor: remove openvpn over cloak and openvpn over shadowsocks * refactor: removed protocolsForContainer function * refactor: add core models * refactor: replace json with c++ structs for server config * refactor: move getDnsPair to ServerConfigUtils * feat: add admin selfhosted config export test * feat: add multi import test * refactor: use coreController for tests * feat: add few simple tests * chore: qrepos in all core controllers * feat: add test for settings * refactor: remove repo dependency from configurators * chore: moved protocols to core folder * chore: include fixes * refactor: moved containersDefs, defs, apiDefs, protocolsDefs to different places * chore: include fixes * chore: build fixes * chore: build fixes * refactor: remove q repo and interface repo * feat: add test for ui servers model and controller * chore: renamed to camelCase * chore: include fixes * refactor: moved core logic from sites ui controller * fix: fixed api config processing * fix: fixed processed server index processing * refactor: protocol models now use c++ structs instead of json configs * refactor: servers model now use c++ struct instead of json config * fix: fixed default server index processing * fix: fix logs init * fix: fix secure settings load keys * chore: build fixes * fix: fixed clear settings * fix: fixed restore backup * fix: sshSession usage * fix: fixed export functions signatures * fix: return missing part from buildContainerWorker * fix: fixed server description on page home * refactor: add container config helpers functions * refactor: c++ structs instead of json * chore: add dns protocol config struct * refactor: move config utils functions to config structs * feat: add test for selfhosted server setup * refactor: separate resources.qrc * fix: fixed server rename * chore: return nameOverriddenByUser * fix: build fixes * fix: fixed models init * refactor: cleanup models usage * fix: fixed models init * chore: cleanup connections and functions signatures * chore: cleanup updateModel calls * feat: added cache to servers repo * chore: cleanup unused functions * chore: ssxray processing * chore: remove transportProtoWithDefault and portWithDefault functions * chore: removed proto types any and l2tp * refactor: moved some constants * fix: fixed native configs export * refactor: remove json from processConfigWith functions * fix: fixed processed server index usage * fix: qml warning fixes * chore: merge fixes * chore: update tests * fix: fixed xray config processing * fix: fixed split tunneling processing * chore: rename sites controllers and model * chore: rename fixes * chore: minor fixes * chore: remove ability to load backup from "file with connection settings" button * fix: fixed api device revoke * fix: remove full model update when renaming a user * fix: fixed premium/free server rename * fix: fixed selfhosted new server install * fix: fixed updateContainer function * fix: fixed revoke for external premium configs * feat: add native configs qr processing * chore: codestyle fixes * fix: fixed admin config create * chore: again remove ability to load backup from "file with connection settings" button * chore: minor fixes * fix: fixed variables initialization * fix: fixed qml imports * fix: minor fixes * fix: fix vpnConnection function calls * feat: add buckup error handling * fix: fixed admin config revok * fix: fixed selfhosted awg installation * fix: ad visability * feat: add empty check for primary dns * chore: minor fixes
143 lines
4.8 KiB
C++
143 lines
4.8 KiB
C++
// Copyright (c) Qv2ray, A Qt frontend for V2Ray. Written in C++.
|
|
// This file is part of the Qv2ray VPN client.
|
|
//
|
|
// Qv2ray, A Qt frontend for V2Ray. Written in C++
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
// Copyright (c) 2024 AmneziaVPN
|
|
// This file has been modified for AmneziaVPN
|
|
//
|
|
// This file is based on the work of the Qv2ray VPN client.
|
|
// The original code of the Qv2ray, A Qt frontend for V2Ray. Written in C++ and licensed under GPL3.
|
|
//
|
|
// The modified version of this file is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this file. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#include "3rd/QJsonStruct/QJsonIO.hpp"
|
|
#include "3rd/QJsonStruct/QJsonStruct.hpp"
|
|
#include "core/utils/utilities.h"
|
|
#include "serialization.h"
|
|
|
|
#define OUTBOUND_TAG_PROXY "PROXY"
|
|
#define JADD(...) FOR_EACH(JADDEx, __VA_ARGS__)
|
|
|
|
namespace amnezia::serialization::ss
|
|
{
|
|
QJsonObject Deserialize(const QString &ssUri, QString *alias, QString *errMessage)
|
|
{
|
|
ShadowSocksServerObject server;
|
|
QString d_name;
|
|
|
|
// auto ssUri = _ssUri.toStdString();
|
|
if (ssUri.length() < 5)
|
|
{
|
|
*errMessage = QObject::tr("SS URI is too short");
|
|
}
|
|
|
|
auto uri = ssUri.mid(5);
|
|
auto hashPos = uri.lastIndexOf("#");
|
|
|
|
if (hashPos >= 0)
|
|
{
|
|
// Get the name/remark
|
|
d_name = uri.mid(uri.lastIndexOf("#") + 1);
|
|
uri.truncate(hashPos);
|
|
}
|
|
|
|
auto atPos = uri.indexOf('@');
|
|
|
|
if (atPos < 0)
|
|
{
|
|
// Old URI scheme
|
|
QString decoded = QByteArray::fromBase64(uri.toUtf8(), QByteArray::Base64Option::OmitTrailingEquals);
|
|
auto colonPos = decoded.indexOf(':');
|
|
|
|
if (colonPos < 0)
|
|
{
|
|
*errMessage = QObject::tr("Can't find the colon separator between method and password");
|
|
}
|
|
|
|
server.method = decoded.left(colonPos);
|
|
decoded.remove(0, colonPos + 1);
|
|
atPos = decoded.lastIndexOf('@');
|
|
|
|
if (atPos < 0)
|
|
{
|
|
*errMessage = QObject::tr("Can't find the at separator between password and hostname");
|
|
}
|
|
|
|
server.password = decoded.mid(0, atPos);
|
|
decoded.remove(0, atPos + 1);
|
|
colonPos = decoded.lastIndexOf(':');
|
|
|
|
if (colonPos < 0)
|
|
{
|
|
*errMessage = QObject::tr("Can't find the colon separator between hostname and port");
|
|
}
|
|
|
|
server.address = decoded.mid(0, colonPos);
|
|
server.port = decoded.mid(colonPos + 1).toInt();
|
|
}
|
|
else
|
|
{
|
|
// SIP002 URI scheme
|
|
auto x = QUrl::fromUserInput(uri);
|
|
server.address = x.host();
|
|
server.port = x.port();
|
|
const auto userInfo = Utils::SafeBase64Decode(x.userName());
|
|
const auto userInfoSp = userInfo.indexOf(':');
|
|
|
|
if (userInfoSp < 0)
|
|
{
|
|
*errMessage = QObject::tr("Can't find the colon separator between method and password");
|
|
return QJsonObject{};
|
|
}
|
|
|
|
const auto method = userInfo.mid(0, userInfoSp);
|
|
server.method = method;
|
|
server.password = userInfo.mid(userInfoSp + 1);
|
|
}
|
|
|
|
d_name = QUrl::fromPercentEncoding(d_name.toUtf8());
|
|
QJsonObject root;
|
|
QJsonArray outbounds;
|
|
outbounds.append(outbounds::GenerateOutboundEntry(OUTBOUND_TAG_PROXY, "shadowsocks", outbounds::GenerateShadowSocksOUT({ server }), {}));
|
|
JADD(outbounds)
|
|
QJsonObject inbound = inbounds::GenerateInboundEntry();
|
|
root["inbounds"] = QJsonArray{ inbound };
|
|
*alias = alias->isEmpty() ? d_name : *alias + "_" + d_name;
|
|
return root;
|
|
}
|
|
|
|
const QString Serialize(const ShadowSocksServerObject &server, const QString &alias, bool)
|
|
{
|
|
QUrl url;
|
|
const auto plainUserInfo = server.method + ":" + server.password;
|
|
const auto userinfo = plainUserInfo.toUtf8().toBase64(QByteArray::Base64UrlEncoding | QByteArray::OmitTrailingEquals);
|
|
url.setUserInfo(userinfo);
|
|
url.setScheme("ss");
|
|
url.setHost(server.address);
|
|
url.setPort(server.port);
|
|
url.setFragment(alias);
|
|
return url.toString(QUrl::ComponentFormattingOption::FullyEncoded);
|
|
}
|
|
} // namespace amnezia::serialization::ss
|
|
|