Merge pull request #207 from amnezia-vpn/bugfix/add-server-with-same-credentials

bugfix/add-server-with-same-credentials
This commit is contained in:
pokamest 2023-04-05 01:50:11 +01:00 committed by GitHub
commit 3fb34e28a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 20 deletions

View file

@ -68,7 +68,7 @@ void AdvancedServerSettingsLogic::onPushButtonScanServerClicked()
bool isServerCreated;
auto containersCount = m_settings->containers(uiLogic()->m_selectedServerIndex).size();
ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, isServerCreated);
ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(isServerCreated);
if (errorCode != ErrorCode::NoError) {
emit uiLogic()->showWarningMessage(tr("Error occurred while scanning the server.") + "\n" +
tr("Error message: ") + errorString(errorCode) + "\n" +

View file

@ -4,9 +4,7 @@
#include <QApplication>
#include "protocols/CloakLogic.h"
#include "protocols/OpenVpnLogic.h"
#include "protocols/ShadowSocksLogic.h"
#include "protocols/PageProtocolLogicBase.h"
#include "core/servercontroller.h"
#include <functional>
@ -90,7 +88,7 @@ void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int p
qApp->processEvents();
bool isServerCreated = false;
ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(false, isServerCreated);
ErrorCode errorCode = uiLogic()->addAlreadyInstalledContainersGui(isServerCreated);
if (errorCode == ErrorCode::NoError) {
if (!uiLogic()->isContainerAlreadyAddedToGui(c)) {

View file

@ -332,7 +332,7 @@ void UiLogic::installServer(QPair<DockerContainer, QJsonObject> &container)
};
bool isServerCreated = false;
ErrorCode errorCode = addAlreadyInstalledContainersGui(true, isServerCreated);
ErrorCode errorCode = addAlreadyInstalledContainersGui(isServerCreated);
if (errorCode == ErrorCode::NoError) {
if (!isContainerAlreadyAddedToGui(container.first)) {
progressBarFunc.setTextFunc(QString("Installing %1").arg(ContainerProps::containerToString(container.first)));
@ -520,18 +520,26 @@ void UiLogic::registerPagesLogic()
registerPageLogic<AdvancedServerSettingsLogic>();
}
ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool &isServerCreated)
ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool &isServerCreated)
{
isServerCreated = false;
ServerCredentials credentials;
if (createNewServer) {
credentials = m_installCredentials;
} else {
credentials = m_settings->serverCredentials(m_selectedServerIndex);
ServerCredentials installCredentials = m_installCredentials;
bool createNewServer = true;
int serverIndex;
for (int i = 0; i < m_settings->serversCount(); i++) {
const ServerCredentials credentials = m_settings->serverCredentials(i);
if (m_installCredentials.hostName == credentials.hostName && m_installCredentials.port == credentials.port) {
createNewServer = false;
isServerCreated = true;
installCredentials = credentials;
serverIndex = i;
break;
}
}
QMap<DockerContainer, QJsonObject> installedContainers;
ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(credentials, installedContainers);
ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(installCredentials, installedContainers);
if (errorCode != ErrorCode::NoError) {
return errorCode;
}
@ -540,10 +548,10 @@ ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool &
QJsonObject server;
QJsonArray containerConfigs;
if (createNewServer) {
server.insert(config_key::hostName, credentials.hostName);
server.insert(config_key::userName, credentials.userName);
server.insert(config_key::password, credentials.password);
server.insert(config_key::port, credentials.port);
server.insert(config_key::hostName, installCredentials.hostName);
server.insert(config_key::userName, installCredentials.userName);
server.insert(config_key::password, installCredentials.password);
server.insert(config_key::port, installCredentials.port);
server.insert(config_key::description, m_settings->nextAvailableServerName());
}
@ -556,8 +564,8 @@ ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool &
containerConfigs.append(container.value());
server.insert(config_key::containers, containerConfigs);
} else {
m_settings->setContainerConfig(m_selectedServerIndex, container.key(), container.value());
m_settings->setDefaultContainer(m_selectedServerIndex, installedContainers.firstKey());
m_settings->setContainerConfig(serverIndex, container.key(), container.value());
m_settings->setDefaultContainer(serverIndex, installedContainers.firstKey());
}
}

View file

@ -117,7 +117,7 @@ public:
Q_INVOKABLE void saveBinaryFile(const QString& desc, QString ext, const QString& data);
Q_INVOKABLE void copyToClipboard(const QString& text);
Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool createNewServer, bool &isServerCreated);
Q_INVOKABLE amnezia::ErrorCode addAlreadyInstalledContainersGui(bool &isServerCreated);
void shareTempFile(const QString &suggestedName, QString ext, const QString& data);