mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
refactor: refactor the application to the mvvm architecture (#2009)
* 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
This commit is contained in:
493
client/ui/controllers/selfhosted/installUiController.cpp
Executable file
493
client/ui/controllers/selfhosted/installUiController.cpp
Executable file
@@ -0,0 +1,493 @@
|
||||
#include "installUiController.h"
|
||||
|
||||
#include <QDesktopServices>
|
||||
#include <QDir>
|
||||
#include <QEventLoop>
|
||||
#include <QJsonObject>
|
||||
#include <QRandomGenerator>
|
||||
#include <QStandardPaths>
|
||||
|
||||
#include "core/utils/api/apiUtils.h"
|
||||
#include "core/controllers/selfhosted/installController.h"
|
||||
#include "core/utils/selfhosted/sshSession.h"
|
||||
#include "core/utils/networkUtilities.h"
|
||||
#include "logger.h"
|
||||
#include "core/utils/protocolEnum.h"
|
||||
#include "core/protocols/protocolUtils.h"
|
||||
#include "core/utils/constants/configKeys.h"
|
||||
#include "core/utils/constants/protocolConstants.h"
|
||||
#include "ui/models/protocols/awgConfigModel.h"
|
||||
#include "ui/models/protocols/wireguardConfigModel.h"
|
||||
#include "ui/models/protocols/openvpnConfigModel.h"
|
||||
#include "ui/models/protocols/xrayConfigModel.h"
|
||||
#ifdef Q_OS_WINDOWS
|
||||
#include "ui/models/protocols/ikev2ConfigModel.h"
|
||||
#endif
|
||||
#include "ui/models/services/sftpConfigModel.h"
|
||||
#include "ui/models/services/socks5ProxyConfigModel.h"
|
||||
#include "ui/models/services/torConfigModel.h"
|
||||
#include "core/utils/utilities.h"
|
||||
#include "core/models/serverConfig.h"
|
||||
#include "core/models/containerConfig.h"
|
||||
#include "core/models/protocols/awgProtocolConfig.h"
|
||||
#include "core/models/protocols/wireGuardProtocolConfig.h"
|
||||
#include "core/models/protocols/openVpnProtocolConfig.h"
|
||||
#include "core/models/protocols/xrayProtocolConfig.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
Logger logger("InstallUiController");
|
||||
|
||||
namespace configKey
|
||||
{
|
||||
constexpr char serviceInfo[] = "service_info";
|
||||
constexpr char serviceType[] = "service_type";
|
||||
constexpr char serviceProtocol[] = "service_protocol";
|
||||
constexpr char userCountryCode[] = "user_country_code";
|
||||
|
||||
constexpr char serverCountryCode[] = "server_country_code";
|
||||
constexpr char serverCountryName[] = "server_country_name";
|
||||
constexpr char availableCountries[] = "available_countries";
|
||||
|
||||
constexpr char apiConfig[] = "api_config";
|
||||
constexpr char authData[] = "auth_data";
|
||||
}
|
||||
}
|
||||
|
||||
InstallUiController::InstallUiController(InstallController *installController,
|
||||
ServersController *serversController,
|
||||
SettingsController *settingsController,
|
||||
ProtocolsModel *protocolsModel,
|
||||
UsersController *usersController,
|
||||
AwgConfigModel *awgConfigModel,
|
||||
WireGuardConfigModel *wireGuardConfigModel,
|
||||
OpenVpnConfigModel *openVpnConfigModel,
|
||||
XrayConfigModel *xrayConfigModel,
|
||||
TorConfigModel *torConfigModel,
|
||||
#ifdef Q_OS_WINDOWS
|
||||
Ikev2ConfigModel *ikev2ConfigModel,
|
||||
#endif
|
||||
SftpConfigModel *sftpConfigModel,
|
||||
Socks5ProxyConfigModel *socks5ConfigModel,
|
||||
QObject *parent)
|
||||
: QObject(parent),
|
||||
m_installController(installController),
|
||||
m_serversController(serversController),
|
||||
m_settingsController(settingsController),
|
||||
m_protocolModel(protocolsModel),
|
||||
m_usersController(usersController),
|
||||
m_awgConfigModel(awgConfigModel),
|
||||
m_wireGuardConfigModel(wireGuardConfigModel),
|
||||
m_openVpnConfigModel(openVpnConfigModel),
|
||||
m_xrayConfigModel(xrayConfigModel),
|
||||
m_torConfigModel(torConfigModel),
|
||||
#ifdef Q_OS_WINDOWS
|
||||
m_ikev2ConfigModel(ikev2ConfigModel),
|
||||
#endif
|
||||
m_sftpConfigModel(sftpConfigModel),
|
||||
m_socks5ConfigModel(socks5ConfigModel)
|
||||
{
|
||||
connect(m_installController, &InstallController::configValidated, this, &InstallUiController::configValidated);
|
||||
connect(m_installController, &InstallController::validationErrorOccurred, this, [this](ErrorCode errorCode) {
|
||||
if (errorCode == ErrorCode::NoInstalledContainersError) {
|
||||
emit noInstalledContainers();
|
||||
} else {
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
InstallUiController::~InstallUiController()
|
||||
{
|
||||
}
|
||||
|
||||
void InstallUiController::install(DockerContainer container, int port, TransportProto transportProto, int serverIndex)
|
||||
{
|
||||
const bool isNewServer = serverIndex < 0;
|
||||
|
||||
ServerCredentials serverCredentials;
|
||||
if (isNewServer) {
|
||||
serverCredentials = m_processedServerCredentials;
|
||||
} else {
|
||||
serverCredentials = m_serversController->getServerCredentials(serverIndex);
|
||||
m_processedServerCredentials = ServerCredentials();
|
||||
}
|
||||
|
||||
QMap<DockerContainer, QJsonObject> preparedContainers;
|
||||
QString finishMessage;
|
||||
ErrorCode errorCode;
|
||||
|
||||
if (isNewServer) {
|
||||
int existingServerIndex = -1;
|
||||
if (m_installController->isServerAlreadyExists(serverCredentials, existingServerIndex)) {
|
||||
emit serverAlreadyExists(existingServerIndex);
|
||||
return;
|
||||
}
|
||||
|
||||
bool wasContainerInstalled = false;
|
||||
errorCode = m_installController->installServer(serverCredentials, container, port, transportProto, wasContainerInstalled);
|
||||
if (errorCode) {
|
||||
emit installationErrorOccurred(errorCode);
|
||||
return;
|
||||
}
|
||||
|
||||
int serverIndex = m_serversController->getServersCount() - 1;
|
||||
ServerConfig serverConfig = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containers = serverConfig.containers();
|
||||
int containersCount = containers.size();
|
||||
|
||||
if (wasContainerInstalled) {
|
||||
finishMessage = tr("%1 installed successfully. ").arg(ContainerUtils::containerHumanNames().value(container));
|
||||
} else {
|
||||
finishMessage = tr("%1 is already installed on the server. ").arg(ContainerUtils::containerHumanNames().value(container));
|
||||
}
|
||||
|
||||
if (containersCount > 1) {
|
||||
finishMessage += tr("\nAdded containers that were already installed on the server");
|
||||
}
|
||||
|
||||
emit installServerFinished(finishMessage);
|
||||
} else {
|
||||
ServerConfig serverConfig = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containers = serverConfig.containers();
|
||||
int containersCount = containers.size();
|
||||
|
||||
bool wasContainerInstalled = false;
|
||||
errorCode = m_installController->installContainer(serverIndex, container, port, transportProto,
|
||||
wasContainerInstalled);
|
||||
if (errorCode) {
|
||||
emit installationErrorOccurred(errorCode);
|
||||
return;
|
||||
}
|
||||
|
||||
ServerConfig newServerConfig = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> newContainers = newServerConfig.containers();
|
||||
int newContainersCount = newContainers.size();
|
||||
|
||||
bool hasNewContainers = (newContainersCount - containersCount) > (wasContainerInstalled ? 1 : 0);
|
||||
|
||||
if (wasContainerInstalled) {
|
||||
finishMessage = tr("%1 installed successfully. ").arg(ContainerUtils::containerHumanNames().value(container));
|
||||
} else {
|
||||
finishMessage = tr("%1 is already installed on the server. ").arg(ContainerUtils::containerHumanNames().value(container));
|
||||
}
|
||||
|
||||
if (hasNewContainers) {
|
||||
finishMessage += tr("\nAlready installed containers were found on the server. "
|
||||
"All installed containers have been added to the application");
|
||||
}
|
||||
|
||||
emit installContainerFinished(finishMessage, ContainerUtils::containerService(container) == ServiceType::Other);
|
||||
}
|
||||
}
|
||||
|
||||
void InstallUiController::scanServerForInstalledContainers(int serverIndex)
|
||||
{
|
||||
ServerConfig serverBefore = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containersBefore = serverBefore.containers();
|
||||
int containersCountBefore = containersBefore.size();
|
||||
|
||||
ErrorCode errorCode = m_installController->scanServerForInstalledContainers(serverIndex);
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
ServerConfig serverAfter = m_serversController->getServerConfig(serverIndex);
|
||||
QMap<DockerContainer, ContainerConfig> containersAfter = serverAfter.containers();
|
||||
int containersCountAfter = containersAfter.size();
|
||||
|
||||
bool isInstalledContainerAdded = containersCountAfter > containersCountBefore;
|
||||
emit scanServerFinished(isInstalledContainerAdded);
|
||||
return;
|
||||
}
|
||||
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
|
||||
void InstallUiController::updateContainer(int serverIndex, int containerIndex, int protocolIndex)
|
||||
{
|
||||
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||
|
||||
Proto protocolType = static_cast<Proto>(protocolIndex);
|
||||
|
||||
ContainerConfig containerConfig;
|
||||
containerConfig.container = container;
|
||||
|
||||
switch (protocolType) {
|
||||
case Proto::Awg: {
|
||||
containerConfig.protocolConfig = m_awgConfigModel->getProtocolConfig();
|
||||
break;
|
||||
}
|
||||
case Proto::WireGuard: {
|
||||
containerConfig.protocolConfig = m_wireGuardConfigModel->getProtocolConfig();
|
||||
break;
|
||||
}
|
||||
case Proto::OpenVpn: {
|
||||
containerConfig.protocolConfig = m_openVpnConfigModel->getProtocolConfig();
|
||||
break;
|
||||
}
|
||||
case Proto::Xray:
|
||||
case Proto::SSXray: {
|
||||
containerConfig.protocolConfig = m_xrayConfigModel->getProtocolConfig();
|
||||
break;
|
||||
}
|
||||
case Proto::TorWebSite: {
|
||||
containerConfig.protocolConfig = m_torConfigModel->getProtocolConfig();
|
||||
break;
|
||||
}
|
||||
case Proto::Sftp: {
|
||||
containerConfig.protocolConfig = m_sftpConfigModel->getProtocolConfig();
|
||||
break;
|
||||
}
|
||||
case Proto::Socks5Proxy: {
|
||||
containerConfig.protocolConfig = m_socks5ConfigModel->getProtocolConfig();
|
||||
break;
|
||||
}
|
||||
#ifdef Q_OS_WINDOWS
|
||||
case Proto::Ikev2: {
|
||||
containerConfig.protocolConfig = m_ikev2ConfigModel->getProtocolConfig();
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
default:
|
||||
return;
|
||||
}
|
||||
ContainerConfig oldContainerConfig = m_serversController->getContainerConfig(serverIndex, container);
|
||||
|
||||
ErrorCode errorCode = m_installController->updateContainer(serverIndex, container, oldContainerConfig, containerConfig);
|
||||
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
ContainerConfig updatedConfig = m_serversController->getContainerConfig(serverIndex, container);
|
||||
m_protocolModel->updateModel(updatedConfig);
|
||||
|
||||
auto defaultContainer = m_serversController->getServerConfig(serverIndex).defaultContainer();
|
||||
if ((serverIndex == m_serversController->getDefaultServerIndex()) && (container == defaultContainer)) {
|
||||
emit currentContainerUpdated();
|
||||
} else {
|
||||
emit updateContainerFinished(tr("Settings updated successfully"));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
|
||||
void InstallUiController::rebootServer(int serverIndex)
|
||||
{
|
||||
QString serverName = m_serversController->getServerConfig(serverIndex).displayName();
|
||||
|
||||
const auto errorCode = m_installController->rebootServer(serverIndex);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
emit rebootServerFinished(tr("Server '%1' was rebooted").arg(serverName));
|
||||
} else {
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
void InstallUiController::removeServer(int serverIndex)
|
||||
{
|
||||
QString serverName = m_serversController->getServerConfig(serverIndex).displayName();
|
||||
|
||||
m_serversController->removeServer(serverIndex);
|
||||
emit removeServerFinished(tr("Server '%1' was removed").arg(serverName));
|
||||
}
|
||||
|
||||
void InstallUiController::removeAllContainers(int serverIndex)
|
||||
{
|
||||
QString serverName = m_serversController->getServerConfig(serverIndex).displayName();
|
||||
|
||||
ErrorCode errorCode = m_installController->removeAllContainers(serverIndex);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
emit removeAllContainersFinished(tr("All containers from server '%1' have been removed").arg(serverName));
|
||||
return;
|
||||
}
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
|
||||
void InstallUiController::removeContainer(int serverIndex, int containerIndex)
|
||||
{
|
||||
QString serverName = m_serversController->getServerConfig(serverIndex).displayName();
|
||||
|
||||
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||
QString containerName = ContainerUtils::containerHumanNames().value(container);
|
||||
|
||||
ErrorCode errorCode = m_installController->removeContainer(serverIndex, container);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
|
||||
emit removeContainerFinished(tr("%1 has been removed from the server '%2'").arg(containerName, serverName));
|
||||
return;
|
||||
}
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
|
||||
void InstallUiController::clearCachedProfile(int serverIndex, int containerIndex)
|
||||
{
|
||||
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||
if (ContainerUtils::containerService(container) == ServiceType::Other) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_installController->clearCachedProfile(serverIndex, container);
|
||||
|
||||
emit cachedProfileCleared(tr("%1 cached profile cleared").arg(ContainerUtils::containerHumanNames().value(container)));
|
||||
ContainerConfig updatedConfig = m_serversController->getContainerConfig(serverIndex, container);
|
||||
m_protocolModel->updateModel(updatedConfig);
|
||||
}
|
||||
|
||||
QRegularExpression InstallUiController::ipAddressRegExp()
|
||||
{
|
||||
return NetworkUtilities::ipAddressRegExp();
|
||||
}
|
||||
|
||||
void InstallUiController::clearProcessedServerCredentials()
|
||||
{
|
||||
m_processedServerCredentials = ServerCredentials();
|
||||
}
|
||||
|
||||
void InstallUiController::setProcessedServerCredentials(const QString &hostName, const QString &userName, const QString &secretData)
|
||||
{
|
||||
m_processedServerCredentials.hostName = hostName;
|
||||
if (m_processedServerCredentials.hostName.contains(":")) {
|
||||
m_processedServerCredentials.port = m_processedServerCredentials.hostName.split(":").at(1).toInt();
|
||||
m_processedServerCredentials.hostName = m_processedServerCredentials.hostName.split(":").at(0);
|
||||
}
|
||||
m_processedServerCredentials.userName = userName;
|
||||
m_processedServerCredentials.secretData = secretData;
|
||||
}
|
||||
|
||||
void InstallUiController::mountSftpDrive(int serverIndex, const QString &port, const QString &password, const QString &username)
|
||||
{
|
||||
ServerCredentials serverCredentials = m_serversController->getServerCredentials(serverIndex);
|
||||
ErrorCode errorCode = m_installController->mountSftpDrive(serverCredentials, port, password, username);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit installationErrorOccurred(errorCode);
|
||||
}
|
||||
}
|
||||
|
||||
bool InstallUiController::checkSshConnection()
|
||||
{
|
||||
m_privateKeyPassphrase = "";
|
||||
|
||||
auto passphraseCallback = [this]() {
|
||||
emit passphraseRequestStarted();
|
||||
QEventLoop loop;
|
||||
QObject::connect(this, &InstallUiController::passphraseRequestFinished, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
return m_privateKeyPassphrase;
|
||||
};
|
||||
|
||||
QString output;
|
||||
ErrorCode errorCode = m_installController->checkSshConnection(m_processedServerCredentials, output, passphraseCallback);
|
||||
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
emit installationErrorOccurred(errorCode);
|
||||
return false;
|
||||
} else {
|
||||
if (output.contains(tr("Please login as the user"))) {
|
||||
output.replace("\n", "");
|
||||
emit wrongInstallationUser(output);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void InstallUiController::setEncryptedPassphrase(QString passphrase)
|
||||
{
|
||||
m_privateKeyPassphrase = passphrase;
|
||||
emit passphraseRequestFinished();
|
||||
}
|
||||
|
||||
void InstallUiController::addEmptyServer()
|
||||
{
|
||||
SelfHostedServerConfig serverConfig;
|
||||
serverConfig.hostName = m_processedServerCredentials.hostName;
|
||||
serverConfig.userName = m_processedServerCredentials.userName;
|
||||
serverConfig.password = m_processedServerCredentials.secretData;
|
||||
serverConfig.port = m_processedServerCredentials.port;
|
||||
serverConfig.description = m_settingsController->nextAvailableServerName();
|
||||
serverConfig.defaultContainer = DockerContainer::None;
|
||||
|
||||
m_serversController->addServer(ServerConfig(serverConfig));
|
||||
emit installServerFinished(tr("Server added successfully"));
|
||||
}
|
||||
|
||||
void InstallUiController::validateConfig()
|
||||
{
|
||||
int serverIndex = m_serversController->getDefaultServerIndex();
|
||||
m_installController->validateConfig(serverIndex);
|
||||
}
|
||||
|
||||
void InstallUiController::updateProtocols(int serverIndex, int containerIndex)
|
||||
{
|
||||
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||
ContainerConfig containerConfig = m_serversController->getContainerConfig(serverIndex, container);
|
||||
containerConfig.container = container;
|
||||
m_protocolModel->updateModel(containerConfig);
|
||||
}
|
||||
|
||||
void InstallUiController::openServerSettings(int serverIndex, int containerIndex, int protocolIndex)
|
||||
{
|
||||
updateProtocolConfigModel(serverIndex, containerIndex, protocolIndex);
|
||||
}
|
||||
|
||||
void InstallUiController::openClientSettings(int serverIndex, int containerIndex, int protocolIndex)
|
||||
{
|
||||
updateProtocolConfigModel(serverIndex, containerIndex, protocolIndex);
|
||||
}
|
||||
|
||||
int InstallUiController::defaultPort(int protocolIndex)
|
||||
{
|
||||
Proto proto = static_cast<Proto>(protocolIndex);
|
||||
return ProtocolUtils::defaultPort(proto);
|
||||
}
|
||||
|
||||
int InstallUiController::getPortForInstall(int protocolIndex)
|
||||
{
|
||||
Proto proto = static_cast<Proto>(protocolIndex);
|
||||
return ProtocolUtils::getPortForInstall(proto);
|
||||
}
|
||||
|
||||
int InstallUiController::defaultTransportProto(int protocolIndex)
|
||||
{
|
||||
Proto proto = static_cast<Proto>(protocolIndex);
|
||||
return static_cast<int>(ProtocolUtils::defaultTransportProto(proto));
|
||||
}
|
||||
|
||||
bool InstallUiController::defaultPortChangeable(int protocolIndex)
|
||||
{
|
||||
Proto proto = static_cast<Proto>(protocolIndex);
|
||||
return ProtocolUtils::defaultPortChangeable(proto);
|
||||
}
|
||||
|
||||
bool InstallUiController::defaultTransportProtoChangeable(int protocolIndex)
|
||||
{
|
||||
Proto proto = static_cast<Proto>(protocolIndex);
|
||||
return ProtocolUtils::defaultTransportProtoChangeable(proto);
|
||||
}
|
||||
|
||||
void InstallUiController::updateProtocolConfigModel(int serverIndex, int containerIndex, int protocolIndex)
|
||||
{
|
||||
DockerContainer container = static_cast<DockerContainer>(containerIndex);
|
||||
ContainerConfig containerConfig = m_serversController->getContainerConfig(serverIndex, container);
|
||||
containerConfig.container = container;
|
||||
Proto protocolType = static_cast<Proto>(protocolIndex);
|
||||
|
||||
auto updateIfPresent = [&](auto* model, auto* config) {
|
||||
if (model && config) model->updateModel(container, *config);
|
||||
};
|
||||
|
||||
switch (protocolType) {
|
||||
case Proto::Awg: updateIfPresent(m_awgConfigModel, containerConfig.getAwgProtocolConfig()); break;
|
||||
case Proto::WireGuard: updateIfPresent(m_wireGuardConfigModel, containerConfig.getWireGuardProtocolConfig()); break;
|
||||
case Proto::OpenVpn: updateIfPresent(m_openVpnConfigModel, containerConfig.getOpenVpnProtocolConfig()); break;
|
||||
case Proto::Xray: updateIfPresent(m_xrayConfigModel, containerConfig.getXrayProtocolConfig()); break;
|
||||
case Proto::TorWebSite: updateIfPresent(m_torConfigModel, containerConfig.getTorProtocolConfig()); break;
|
||||
case Proto::Sftp: updateIfPresent(m_sftpConfigModel, containerConfig.getSftpProtocolConfig()); break;
|
||||
case Proto::Socks5Proxy: updateIfPresent(m_socks5ConfigModel, containerConfig.getSocks5ProxyProtocolConfig()); break;
|
||||
#ifdef Q_OS_WINDOWS
|
||||
case Proto::Ikev2: updateIfPresent(m_ikev2ConfigModel, containerConfig.getIkev2ProtocolConfig()); break;
|
||||
#endif
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user