Merge branch 'dev' of github.com:amnezia-vpn/desktop-client into feature/v2ray-container
This commit is contained in:
commit
fe3228ed74
31 changed files with 598 additions and 241 deletions
|
|
@ -10,7 +10,6 @@
|
|||
#include <QJsonObject>
|
||||
#include <QKeyEvent>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QMetaEnum>
|
||||
#include <QSysInfo>
|
||||
#include <QThread>
|
||||
|
|
@ -67,6 +66,7 @@
|
|||
#include "pages_logic/ViewConfigLogic.h"
|
||||
#include "pages_logic/VpnLogic.h"
|
||||
#include "pages_logic/WizardLogic.h"
|
||||
#include "pages_logic/AdvancedServerSettingsLogic.h"
|
||||
|
||||
#include "pages_logic/protocols/CloakLogic.h"
|
||||
#include "pages_logic/protocols/OpenVpnLogic.h"
|
||||
|
|
@ -159,7 +159,7 @@ void UiLogic::initalizeUiLogic()
|
|||
emit goToPage(Page::Start, true, false);
|
||||
}
|
||||
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
|
||||
qInfo().noquote() << QString("Started %1 version %2").arg(APPLICATION_NAME).arg(APP_VERSION);
|
||||
qInfo().noquote() << QString("%1 (%2)").arg(QSysInfo::prettyProductName()).arg(QSysInfo::currentCpuArchitecture());
|
||||
|
|
@ -201,8 +201,8 @@ void UiLogic::keyPressEvent(Qt::Key key)
|
|||
qApp->quit();
|
||||
break;
|
||||
case Qt::Key_H:
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
selectedDockerContainer = m_settings->defaultContainer(selectedServerIndex);
|
||||
m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
m_selectedDockerContainer = m_settings->defaultContainer(m_selectedServerIndex);
|
||||
|
||||
//updateSharingPage(selectedServerIndex, m_settings->serverCredentials(selectedServerIndex), selectedDockerContainer);
|
||||
emit goToPage(Page::ShareConnection);
|
||||
|
|
@ -216,7 +216,7 @@ void UiLogic::keyPressEvent(Qt::Key key)
|
|||
emit goToPage(Page::Start);
|
||||
break;
|
||||
case Qt::Key_S:
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
emit goToPage(Page::ServerSettings);
|
||||
break;
|
||||
case Qt::Key_P:
|
||||
|
|
@ -264,15 +264,13 @@ QString UiLogic::containerDesc(int container)
|
|||
|
||||
void UiLogic::onGotoCurrentProtocolsPage()
|
||||
{
|
||||
selectedServerIndex = m_settings->defaultServerIndex();
|
||||
selectedDockerContainer = m_settings->defaultContainer(selectedServerIndex);
|
||||
m_selectedServerIndex = m_settings->defaultServerIndex();
|
||||
m_selectedDockerContainer = m_settings->defaultContainer(m_selectedServerIndex);
|
||||
emit goToPage(Page::ServerContainers);
|
||||
}
|
||||
|
||||
void UiLogic::installServer(QMap<DockerContainer, QJsonObject> &containers)
|
||||
void UiLogic::installServer(QPair<DockerContainer, QJsonObject> &container)
|
||||
{
|
||||
if (containers.isEmpty()) return;
|
||||
|
||||
emit goToPage(Page::ServerConfiguringProgress);
|
||||
QEventLoop loop;
|
||||
QTimer::singleShot(500, &loop, SLOT(quit()));
|
||||
|
|
@ -327,43 +325,55 @@ void UiLogic::installServer(QMap<DockerContainer, QJsonObject> &containers)
|
|||
pageLogic<ServerConfiguringProgressLogic>()->set_pushButtonCancelVisible(visible);
|
||||
};
|
||||
|
||||
int count = 0;
|
||||
ErrorCode error;
|
||||
for (QMap<DockerContainer, QJsonObject>::iterator i = containers.begin(); i != containers.end(); i++, count++) {
|
||||
progressBarFunc.setTextFunc(QString("Installing %1 %2 %3").arg(count+1).arg(tr("of")).arg(containers.size()));
|
||||
bool isServerCreated = false;
|
||||
ErrorCode errorCode = addAlreadyInstalledContainersGui(true, isServerCreated);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
if (!isContainerAlreadyAddedToGui(container.first)) {
|
||||
progressBarFunc.setTextFunc(QString("Installing %1").arg(ContainerProps::containerToString(container.first)));
|
||||
auto installAction = [&] () {
|
||||
return m_serverController->setupContainer(m_installCredentials, container.first, container.second);
|
||||
};
|
||||
errorCode = pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
|
||||
noButton, waitInfoFunc,
|
||||
busyInfoFunc, cancelButtonFunc);
|
||||
m_serverController->disconnectFromHost(m_installCredentials);
|
||||
|
||||
error = pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([&] () {
|
||||
return m_serverController->setupContainer(installCredentials, i.key(), i.value());
|
||||
}, pageFunc, progressBarFunc, noButton, waitInfoFunc, busyInfoFunc, cancelButtonFunc);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
if (!isServerCreated) {
|
||||
QJsonObject server;
|
||||
server.insert(config_key::hostName, m_installCredentials.hostName);
|
||||
server.insert(config_key::userName, m_installCredentials.userName);
|
||||
server.insert(config_key::password, m_installCredentials.password);
|
||||
server.insert(config_key::port, m_installCredentials.port);
|
||||
server.insert(config_key::description, m_settings->nextAvailableServerName());
|
||||
|
||||
m_serverController->disconnectFromHost(installCredentials);
|
||||
}
|
||||
server.insert(config_key::containers, QJsonArray{container.second});
|
||||
server.insert(config_key::defaultContainer, ContainerProps::containerToString(container.first));
|
||||
|
||||
if (error == ErrorCode::NoError) {
|
||||
QJsonObject server;
|
||||
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());
|
||||
m_settings->addServer(server);
|
||||
m_settings->setDefaultServer(m_settings->serversCount() - 1);
|
||||
} else {
|
||||
m_settings->setContainerConfig(m_settings->serversCount() - 1, container.first, container.second);
|
||||
m_settings->setDefaultContainer(m_settings->serversCount() - 1, container.first);
|
||||
}
|
||||
onUpdateAllPages();
|
||||
|
||||
QJsonArray containerConfigs;
|
||||
for (const QJsonObject &cfg : containers) {
|
||||
containerConfigs.append(cfg);
|
||||
emit setStartPage(Page::Vpn);
|
||||
qApp->processEvents();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
onUpdateAllPages();
|
||||
emit showWarningMessage("Attention! The container you are trying to install is already installed on the server. "
|
||||
"All installed containers have been added to the application ");
|
||||
emit setStartPage(Page::Vpn);
|
||||
return;
|
||||
}
|
||||
server.insert(config_key::containers, containerConfigs);
|
||||
server.insert(config_key::defaultContainer, ContainerProps::containerToString(containers.firstKey()));
|
||||
|
||||
m_settings->addServer(server);
|
||||
m_settings->setDefaultServer(m_settings->serversCount() - 1);
|
||||
onUpdateAllPages();
|
||||
|
||||
emit setStartPage(Page::Vpn);
|
||||
qApp->processEvents();
|
||||
}
|
||||
else {
|
||||
emit closePage();
|
||||
}
|
||||
emit showWarningMessage(tr("Error occurred while configuring server.") + "\n" +
|
||||
tr("Error message: ") + errorString(errorCode) + "\n" +
|
||||
tr("See logs for details."));
|
||||
emit closePage();
|
||||
}
|
||||
|
||||
PageProtocolLogicBase *UiLogic::protocolLogic(Proto p)
|
||||
|
|
@ -499,4 +509,72 @@ void UiLogic::registerPagesLogic()
|
|||
registerPageLogic<ViewConfigLogic>();
|
||||
registerPageLogic<VpnLogic>();
|
||||
registerPageLogic<WizardLogic>();
|
||||
registerPageLogic<AdvancedServerSettingsLogic>();
|
||||
}
|
||||
|
||||
ErrorCode UiLogic::addAlreadyInstalledContainersGui(bool createNewServer, bool &isServerCreated)
|
||||
{
|
||||
isServerCreated = false;
|
||||
ServerCredentials credentials;
|
||||
if (createNewServer) {
|
||||
credentials = m_installCredentials;
|
||||
} else {
|
||||
credentials = m_settings->serverCredentials(m_selectedServerIndex);
|
||||
}
|
||||
|
||||
QMap<DockerContainer, QJsonObject> installedContainers;
|
||||
ErrorCode errorCode = m_serverController->getAlreadyInstalledContainers(credentials, installedContainers);
|
||||
m_serverController->disconnectFromHost(credentials);
|
||||
if (errorCode != ErrorCode::NoError) {
|
||||
return errorCode;
|
||||
}
|
||||
|
||||
if (!installedContainers.empty()) {
|
||||
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::description, m_settings->nextAvailableServerName());
|
||||
}
|
||||
|
||||
for (auto container = installedContainers.begin(); container != installedContainers.end(); container++) {
|
||||
if (isContainerAlreadyAddedToGui(container.key())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (createNewServer) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
if (createNewServer) {
|
||||
server.insert(config_key::defaultContainer, ContainerProps::containerToString(installedContainers.firstKey()));
|
||||
m_settings->addServer(server);
|
||||
m_settings->setDefaultServer(m_settings->serversCount() - 1);
|
||||
isServerCreated = true;
|
||||
}
|
||||
}
|
||||
|
||||
return ErrorCode::NoError;
|
||||
}
|
||||
|
||||
bool UiLogic::isContainerAlreadyAddedToGui(DockerContainer container)
|
||||
{
|
||||
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) {
|
||||
const QJsonObject containerConfig = m_settings->containerConfig(i, container);
|
||||
if (!containerConfig.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue