Merge branch 'dev'
This commit is contained in:
commit
af29637163
201 changed files with 2229 additions and 1503287 deletions
|
|
@ -44,10 +44,11 @@ void AdvancedServerSettingsLogic::onPushButtonClearServerClicked()
|
|||
uiLogic()->pageLogic<VpnLogic>()->onDisconnect();
|
||||
}
|
||||
|
||||
ErrorCode e = m_serverController->removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex));
|
||||
if (e) {
|
||||
ServerController serverController(m_settings);
|
||||
ErrorCode errorCode = serverController.removeAllContainers(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex));
|
||||
if (errorCode) {
|
||||
emit uiLogic()->showWarningMessage(tr("Error occurred while cleaning the server.") + "\n" +
|
||||
tr("Error message: ") + errorString(e) + "\n" +
|
||||
tr("Error message: ") + errorString(errorCode) + "\n" +
|
||||
tr("See logs for details."));
|
||||
} else {
|
||||
set_labelWaitInfoVisible(true);
|
||||
|
|
|
|||
213
client/ui/pages_logic/ClientInfoLogic.cpp
Normal file
213
client/ui/pages_logic/ClientInfoLogic.cpp
Normal file
|
|
@ -0,0 +1,213 @@
|
|||
#include "ClientInfoLogic.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "defines.h"
|
||||
#include "core/errorstrings.h"
|
||||
#include "core/servercontroller.h"
|
||||
#include "ui/models/clientManagementModel.h"
|
||||
#include "ui/uilogic.h"
|
||||
|
||||
namespace {
|
||||
bool isErrorOccured(ErrorCode error) {
|
||||
if (error != ErrorCode::NoError) {
|
||||
QMessageBox::warning(nullptr, APPLICATION_NAME,
|
||||
QObject::tr("An error occurred while saving the list of clients.") + "\n" + errorString(error));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
ClientInfoLogic::ClientInfoLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ClientInfoLogic::setCurrentClientId(int index)
|
||||
{
|
||||
m_currentClientIndex = index;
|
||||
}
|
||||
|
||||
void ClientInfoLogic::onUpdatePage()
|
||||
{
|
||||
set_pageContentVisible(false);
|
||||
set_busyIndicatorIsRunning(true);
|
||||
|
||||
const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex);
|
||||
const DockerContainer container = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
|
||||
const QString containerNameString = ContainerProps::containerHumanNames().value(container);
|
||||
set_labelCurrentVpnProtocolText(tr("Service: ") + containerNameString);
|
||||
|
||||
const QVector<amnezia::Proto> protocols = ContainerProps::protocolsForContainer(container);
|
||||
if (!protocols.empty()) {
|
||||
const Proto currentMainProtocol = protocols.front();
|
||||
|
||||
auto model = qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel());
|
||||
const QModelIndex modelIndex = model->index(m_currentClientIndex);
|
||||
|
||||
set_lineEditNameAliasText(model->data(modelIndex, ClientManagementModel::ClientRoles::NameRole).toString());
|
||||
if (currentMainProtocol == Proto::OpenVpn) {
|
||||
const QString certId = model->data(modelIndex, ClientManagementModel::ClientRoles::OpenVpnCertIdRole).toString();
|
||||
QString certData = model->data(modelIndex, ClientManagementModel::ClientRoles::OpenVpnCertDataRole).toString();
|
||||
|
||||
if (certData.isEmpty() && !certId.isEmpty()) {
|
||||
QString stdOut;
|
||||
auto cbReadStdOut = [&](const QString &data, libssh::Client &) {
|
||||
stdOut += data + "\n";
|
||||
return ErrorCode::NoError;
|
||||
};
|
||||
|
||||
const QString getOpenVpnCertData = QString("sudo docker exec -i $CONTAINER_NAME bash -c 'cat /opt/amnezia/openvpn/pki/issued/%1.crt'")
|
||||
.arg(certId);
|
||||
ServerController serverController(m_settings);
|
||||
const QString script = serverController.replaceVars(getOpenVpnCertData, serverController.genVarsForScript(credentials, container));
|
||||
ErrorCode error = serverController.runScript(credentials, script, cbReadStdOut);
|
||||
certData = stdOut;
|
||||
if (isErrorOccured(error)) {
|
||||
set_busyIndicatorIsRunning(false);
|
||||
emit uiLogic()->closePage();
|
||||
return;
|
||||
}
|
||||
}
|
||||
set_labelOpenVpnCertId(certId);
|
||||
set_textAreaOpenVpnCertData(certData);
|
||||
} else if (currentMainProtocol == Proto::WireGuard) {
|
||||
set_textAreaWireGuardKeyData(model->data(modelIndex, ClientManagementModel::ClientRoles::WireGuardPublicKey).toString());
|
||||
}
|
||||
}
|
||||
set_pageContentVisible(true);
|
||||
set_busyIndicatorIsRunning(false);
|
||||
}
|
||||
|
||||
void ClientInfoLogic::onLineEditNameAliasEditingFinished()
|
||||
{
|
||||
set_busyIndicatorIsRunning(true);
|
||||
|
||||
auto model = qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel());
|
||||
const QModelIndex modelIndex = model->index(m_currentClientIndex);
|
||||
model->setData(modelIndex, m_lineEditNameAliasText, ClientManagementModel::ClientRoles::NameRole);
|
||||
|
||||
const DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
|
||||
const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex);
|
||||
const QVector<amnezia::Proto> protocols = ContainerProps::protocolsForContainer(selectedContainer);
|
||||
if (!protocols.empty()) {
|
||||
const Proto currentMainProtocol = protocols.front();
|
||||
const QJsonObject clientsTable = model->getContent(currentMainProtocol);
|
||||
ErrorCode error = setClientsList(credentials,
|
||||
selectedContainer,
|
||||
currentMainProtocol,
|
||||
clientsTable);
|
||||
isErrorOccured(error);
|
||||
}
|
||||
|
||||
set_busyIndicatorIsRunning(false);
|
||||
}
|
||||
|
||||
void ClientInfoLogic::onRevokeOpenVpnCertificateClicked()
|
||||
{
|
||||
set_busyIndicatorIsRunning(true);
|
||||
const DockerContainer container = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
|
||||
const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex);
|
||||
|
||||
auto model = qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel());
|
||||
const QModelIndex modelIndex = model->index(m_currentClientIndex);
|
||||
const QString certId = model->data(modelIndex, ClientManagementModel::ClientRoles::OpenVpnCertIdRole).toString();
|
||||
|
||||
const QString getOpenVpnCertData = QString("sudo docker exec -i $CONTAINER_NAME bash -c '"
|
||||
"cd /opt/amnezia/openvpn ;\\"
|
||||
"easyrsa revoke %1 ;\\"
|
||||
"easyrsa gen-crl ;\\"
|
||||
"cp pki/crl.pem .'").arg(certId);
|
||||
ServerController serverController(m_settings);
|
||||
const QString script = serverController.replaceVars(getOpenVpnCertData,
|
||||
serverController.genVarsForScript(credentials, container));
|
||||
auto error = serverController.runScript(credentials, script);
|
||||
if (isErrorOccured(error)) {
|
||||
set_busyIndicatorIsRunning(false);
|
||||
emit uiLogic()->goToPage(Page::ServerSettings);
|
||||
return;
|
||||
}
|
||||
|
||||
model->removeRows(m_currentClientIndex);
|
||||
const QJsonObject clientsTable = model->getContent(Proto::OpenVpn);
|
||||
error = setClientsList(credentials, container, Proto::OpenVpn, clientsTable);
|
||||
if (isErrorOccured(error)) {
|
||||
set_busyIndicatorIsRunning(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const QJsonObject &containerConfig = m_settings->containerConfig(uiLogic()->m_selectedServerIndex, container);
|
||||
error = serverController.startupContainerWorker(credentials, container, containerConfig);
|
||||
if (isErrorOccured(error)) {
|
||||
set_busyIndicatorIsRunning(false);
|
||||
return;
|
||||
}
|
||||
|
||||
set_busyIndicatorIsRunning(false);
|
||||
}
|
||||
|
||||
void ClientInfoLogic::onRevokeWireGuardKeyClicked()
|
||||
{
|
||||
set_busyIndicatorIsRunning(true);
|
||||
ErrorCode error;
|
||||
const DockerContainer container = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
|
||||
const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex);
|
||||
|
||||
ServerController serverController(m_settings);
|
||||
|
||||
const QString wireGuardConfigFile = "opt/amnezia/wireguard/wg0.conf";
|
||||
const QString wireguardConfigString = serverController.getTextFileFromContainer(container, credentials, wireGuardConfigFile, &error);
|
||||
if (isErrorOccured(error)) {
|
||||
set_busyIndicatorIsRunning(false);
|
||||
return;
|
||||
}
|
||||
|
||||
auto model = qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel());
|
||||
const QModelIndex modelIndex = model->index(m_currentClientIndex);
|
||||
const QString key = model->data(modelIndex, ClientManagementModel::ClientRoles::WireGuardPublicKey).toString();
|
||||
|
||||
auto configSections = wireguardConfigString.split("[", Qt::SkipEmptyParts);
|
||||
for (auto §ion : configSections) {
|
||||
if (section.contains(key)) {
|
||||
configSections.removeOne(section);
|
||||
}
|
||||
}
|
||||
QString newWireGuardConfig = configSections.join("[");
|
||||
newWireGuardConfig.insert(0, "[");
|
||||
error = serverController.uploadTextFileToContainer(container, credentials, newWireGuardConfig,
|
||||
protocols::wireguard::serverConfigPath,
|
||||
libssh::SftpOverwriteMode::SftpOverwriteExisting);
|
||||
if (isErrorOccured(error)) {
|
||||
set_busyIndicatorIsRunning(false);
|
||||
return;
|
||||
}
|
||||
|
||||
model->removeRows(m_currentClientIndex);
|
||||
const QJsonObject clientsTable = model->getContent(Proto::WireGuard);
|
||||
error = setClientsList(credentials, container, Proto::WireGuard, clientsTable);
|
||||
if (isErrorOccured(error)) {
|
||||
set_busyIndicatorIsRunning(false);
|
||||
return;
|
||||
}
|
||||
|
||||
const QString script = "sudo docker exec -i $CONTAINER_NAME bash -c 'wg syncconf wg0 <(wg-quick strip /opt/amnezia/wireguard/wg0.conf)'";
|
||||
error = serverController.runScript(credentials,
|
||||
serverController.replaceVars(script, serverController.genVarsForScript(credentials, container)));
|
||||
if (isErrorOccured(error)) {
|
||||
set_busyIndicatorIsRunning(false);
|
||||
return;
|
||||
}
|
||||
|
||||
set_busyIndicatorIsRunning(false);
|
||||
}
|
||||
|
||||
ErrorCode ClientInfoLogic::setClientsList(const ServerCredentials &credentials, DockerContainer container, Proto mainProtocol, const QJsonObject &clietns)
|
||||
{
|
||||
const QString mainProtocolString = ProtocolProps::protoToString(mainProtocol);
|
||||
const QString clientsTableFile = QString("opt/amnezia/%1/clientsTable").arg(mainProtocolString);
|
||||
ServerController serverController(m_settings);
|
||||
ErrorCode error = serverController.uploadTextFileToContainer(container, credentials, QJsonDocument(clietns).toJson(), clientsTableFile);
|
||||
return error;
|
||||
}
|
||||
42
client/ui/pages_logic/ClientInfoLogic.h
Normal file
42
client/ui/pages_logic/ClientInfoLogic.h
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef CLIENTINFOLOGIC_H
|
||||
#define CLIENTINFOLOGIC_H
|
||||
|
||||
#include "PageLogicBase.h"
|
||||
|
||||
#include "core/defs.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "protocols/protocols_defs.h"
|
||||
|
||||
class UiLogic;
|
||||
|
||||
class ClientInfoLogic : public PageLogicBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
AUTO_PROPERTY(QString, lineEditNameAliasText)
|
||||
AUTO_PROPERTY(QString, labelOpenVpnCertId)
|
||||
AUTO_PROPERTY(QString, textAreaOpenVpnCertData)
|
||||
AUTO_PROPERTY(QString, labelCurrentVpnProtocolText)
|
||||
AUTO_PROPERTY(QString, textAreaWireGuardKeyData)
|
||||
AUTO_PROPERTY(bool, busyIndicatorIsRunning);
|
||||
AUTO_PROPERTY(bool, pageContentVisible);
|
||||
|
||||
public:
|
||||
ClientInfoLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~ClientInfoLogic() = default;
|
||||
|
||||
void setCurrentClientId(int index);
|
||||
|
||||
public slots:
|
||||
void onUpdatePage() override;
|
||||
void onLineEditNameAliasEditingFinished();
|
||||
void onRevokeOpenVpnCertificateClicked();
|
||||
void onRevokeWireGuardKeyClicked();
|
||||
|
||||
private:
|
||||
ErrorCode setClientsList(const ServerCredentials &credentials, DockerContainer container, Proto mainProtocol, const QJsonObject &clietns);
|
||||
|
||||
int m_currentClientIndex;
|
||||
};
|
||||
|
||||
#endif // CLIENTINFOLOGIC_H
|
||||
143
client/ui/pages_logic/ClientManagementLogic.cpp
Normal file
143
client/ui/pages_logic/ClientManagementLogic.cpp
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
#include "ClientManagementLogic.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "defines.h"
|
||||
#include "core/errorstrings.h"
|
||||
#include "core/servercontroller.h"
|
||||
#include "ui/pages_logic/ClientInfoLogic.h"
|
||||
#include "ui/models/clientManagementModel.h"
|
||||
#include "ui/uilogic.h"
|
||||
|
||||
ClientManagementLogic::ClientManagementLogic(UiLogic *logic, QObject *parent):
|
||||
PageLogicBase(logic, parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ClientManagementLogic::onUpdatePage()
|
||||
{
|
||||
set_busyIndicatorIsRunning(true);
|
||||
|
||||
qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel())->clearData();
|
||||
DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->m_selectedServerIndex);
|
||||
QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer);
|
||||
set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName);
|
||||
|
||||
QJsonObject clients;
|
||||
|
||||
auto protocols = ContainerProps::protocolsForContainer(selectedContainer);
|
||||
if (!protocols.empty()) {
|
||||
m_currentMainProtocol = protocols.front();
|
||||
|
||||
const ServerCredentials credentials = m_settings->serverCredentials(uiLogic()->m_selectedServerIndex);
|
||||
|
||||
ErrorCode error = getClientsList(credentials, selectedContainer, m_currentMainProtocol, clients);
|
||||
if (error != ErrorCode::NoError) {
|
||||
QMessageBox::warning(nullptr, APPLICATION_NAME,
|
||||
tr("An error occurred while getting the list of clients.") + "\n" + errorString(error));
|
||||
set_busyIndicatorIsRunning(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
QVector<QVariant> clientsArray;
|
||||
for (auto &clientId : clients.keys()) {
|
||||
clientsArray.push_back(clients[clientId].toObject());
|
||||
}
|
||||
qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel())->setContent(clientsArray);
|
||||
|
||||
set_busyIndicatorIsRunning(false);
|
||||
}
|
||||
|
||||
void ClientManagementLogic::onClientItemClicked(int index)
|
||||
{
|
||||
uiLogic()->pageLogic<ClientInfoLogic>()->setCurrentClientId(index);
|
||||
emit uiLogic()->goToClientInfoPage(m_currentMainProtocol);
|
||||
}
|
||||
|
||||
ErrorCode ClientManagementLogic::getClientsList(const ServerCredentials &credentials, DockerContainer container, Proto mainProtocol, QJsonObject &clietns)
|
||||
{
|
||||
ErrorCode error = ErrorCode::NoError;
|
||||
QString stdOut;
|
||||
auto cbReadStdOut = [&](const QString &data, libssh::Client &) {
|
||||
stdOut += data + "\n";
|
||||
return ErrorCode::NoError;
|
||||
};
|
||||
|
||||
const QString mainProtocolString = ProtocolProps::protoToString(mainProtocol);
|
||||
|
||||
ServerController serverController(m_settings);
|
||||
|
||||
const QString clientsTableFile = QString("/opt/amnezia/%1/clientsTable").arg(mainProtocolString);
|
||||
const QByteArray clientsTableString = serverController.getTextFileFromContainer(container, credentials, clientsTableFile, &error);
|
||||
if (error != ErrorCode::NoError) {
|
||||
return error;
|
||||
}
|
||||
QJsonObject clientsTable = QJsonDocument::fromJson(clientsTableString).object();
|
||||
int count = 0;
|
||||
|
||||
if (mainProtocol == Proto::OpenVpn) {
|
||||
const QString getOpenVpnClientsList = "sudo docker exec -i $CONTAINER_NAME bash -c 'ls /opt/amnezia/openvpn/pki/issued'";
|
||||
QString script = serverController.replaceVars(getOpenVpnClientsList, serverController.genVarsForScript(credentials, container));
|
||||
error = serverController.runScript(credentials, script, cbReadStdOut);
|
||||
if (error != ErrorCode::NoError) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (!stdOut.isEmpty()) {
|
||||
QStringList certsIds = stdOut.split("\n", Qt::SkipEmptyParts);
|
||||
certsIds.removeAll("AmneziaReq.crt");
|
||||
|
||||
for (auto &openvpnCertId : certsIds) {
|
||||
openvpnCertId.replace(".crt", "");
|
||||
if (!clientsTable.contains(openvpnCertId)) {
|
||||
|
||||
QJsonObject client;
|
||||
client["openvpnCertId"] = openvpnCertId;
|
||||
client["clientName"] = QString("Client %1").arg(count);
|
||||
client["openvpnCertData"] = "";
|
||||
clientsTable[openvpnCertId] = client;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (mainProtocol == Proto::WireGuard) {
|
||||
const QString wireGuardConfigFile = "opt/amnezia/wireguard/wg0.conf";
|
||||
const QString wireguardConfigString = serverController.getTextFileFromContainer(container, credentials, wireGuardConfigFile, &error);
|
||||
if (error != ErrorCode::NoError) {
|
||||
return error;
|
||||
}
|
||||
|
||||
auto configLines = wireguardConfigString.split("\n", Qt::SkipEmptyParts);
|
||||
QStringList wireguardKeys;
|
||||
for (const auto &line : configLines) {
|
||||
auto configPair = line.split(" = ", Qt::SkipEmptyParts);
|
||||
if (configPair.front() == "PublicKey") {
|
||||
wireguardKeys.push_back(configPair.back());
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &wireguardKey : wireguardKeys) {
|
||||
if (!clientsTable.contains(wireguardKey)) {
|
||||
QJsonObject client;
|
||||
client["clientName"] = QString("Client %1").arg(count);
|
||||
client["wireguardPublicKey"] = wireguardKey;
|
||||
clientsTable[wireguardKey] = client;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const QByteArray newClientsTableString = QJsonDocument(clientsTable).toJson();
|
||||
if (clientsTableString != newClientsTableString) {
|
||||
error = serverController.uploadTextFileToContainer(container, credentials, newClientsTableString, clientsTableFile);
|
||||
}
|
||||
|
||||
if (error != ErrorCode::NoError) {
|
||||
return error;
|
||||
}
|
||||
|
||||
clietns = clientsTable;
|
||||
|
||||
return error;
|
||||
}
|
||||
33
client/ui/pages_logic/ClientManagementLogic.h
Normal file
33
client/ui/pages_logic/ClientManagementLogic.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef CLIENTMANAGMENTLOGIC_H
|
||||
#define CLIENTMANAGMENTLOGIC_H
|
||||
|
||||
#include "PageLogicBase.h"
|
||||
|
||||
#include "core/defs.h"
|
||||
#include "containers/containers_defs.h"
|
||||
#include "protocols/protocols_defs.h"
|
||||
|
||||
class UiLogic;
|
||||
|
||||
class ClientManagementLogic : public PageLogicBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
AUTO_PROPERTY(QString, labelCurrentVpnProtocolText)
|
||||
AUTO_PROPERTY(bool, busyIndicatorIsRunning);
|
||||
|
||||
public:
|
||||
ClientManagementLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~ClientManagementLogic() = default;
|
||||
|
||||
public slots:
|
||||
void onUpdatePage() override;
|
||||
void onClientItemClicked(int index);
|
||||
|
||||
private:
|
||||
ErrorCode getClientsList(const ServerCredentials &credentials, DockerContainer container, Proto mainProtocol, QJsonObject &clietns);
|
||||
|
||||
amnezia::Proto m_currentMainProtocol;
|
||||
};
|
||||
|
||||
#endif // CLIENTMANAGMENTLOGIC_H
|
||||
|
|
@ -11,7 +11,6 @@ PageLogicBase::PageLogicBase(UiLogic *logic, QObject *parent):
|
|||
{
|
||||
m_settings = logic->m_settings;
|
||||
m_configurator = logic->m_configurator;
|
||||
m_serverController = logic->m_serverController;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,6 @@ protected:
|
|||
|
||||
std::shared_ptr<Settings> m_settings;
|
||||
std::shared_ptr<VpnConfigurator> m_configurator;
|
||||
std::shared_ptr<ServerController> m_serverController;
|
||||
|
||||
signals:
|
||||
void updatePage();
|
||||
|
|
|
|||
|
|
@ -96,19 +96,18 @@ ErrorCode ServerConfiguringProgressLogic::doInstallAction(const std::function<Er
|
|||
progress.setValueFunc(0);
|
||||
timer.start(1000);
|
||||
|
||||
ServerController serverController(m_settings);
|
||||
|
||||
QMetaObject::Connection cancelDoInstallActionConnection;
|
||||
if (cancelButton.setVisibleFunc) {
|
||||
cancelDoInstallActionConnection = connect(this, &ServerConfiguringProgressLogic::cancelDoInstallAction,
|
||||
m_serverController.get(), &ServerController::setCancelInstallation);
|
||||
&serverController, &ServerController::setCancelInstallation);
|
||||
}
|
||||
|
||||
|
||||
QMetaObject::Connection serverBusyConnection;
|
||||
if (serverBusyInfo.setVisibleFunc && serverBusyInfo.setTextFunc) {
|
||||
serverBusyConnection = connect(m_serverController.get(),
|
||||
&ServerController::serverIsBusy,
|
||||
this,
|
||||
[&serverBusyInfo, &timer, &cancelButton](const bool isBusy) {
|
||||
auto onServerIsBusy = [&serverBusyInfo, &timer, &cancelButton](const bool isBusy) {
|
||||
isBusy ? timer.stop() : timer.start(1000);
|
||||
serverBusyInfo.setVisibleFunc(isBusy);
|
||||
serverBusyInfo.setTextFunc(isBusy ? "Amnesia has detected that your server is currently "
|
||||
|
|
@ -118,7 +117,9 @@ ErrorCode ServerConfiguringProgressLogic::doInstallAction(const std::function<Er
|
|||
if (cancelButton.setVisibleFunc) {
|
||||
cancelButton.setVisibleFunc(isBusy ? true : false);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
serverBusyConnection = connect(&serverController, &ServerController::serverIsBusy, this, onServerIsBusy);
|
||||
}
|
||||
|
||||
ErrorCode e = action();
|
||||
|
|
@ -182,5 +183,5 @@ ErrorCode ServerConfiguringProgressLogic::doInstallAction(const std::function<Er
|
|||
|
||||
void ServerConfiguringProgressLogic::onPushButtonCancelClicked()
|
||||
{
|
||||
cancelDoInstallAction(true);
|
||||
emit cancelDoInstallAction(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,7 +68,8 @@ void ServerContainersLogic::onPushButtonShareClicked(DockerContainer c)
|
|||
void ServerContainersLogic::onPushButtonRemoveClicked(DockerContainer container)
|
||||
{
|
||||
//buttonSetEnabledFunc(false);
|
||||
ErrorCode e = m_serverController->removeContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), container);
|
||||
ServerController serverController(m_settings);
|
||||
ErrorCode e = serverController.removeContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), container);
|
||||
m_settings->removeContainerConfig(uiLogic()->m_selectedServerIndex, container);
|
||||
//buttonSetEnabledFunc(true);
|
||||
|
||||
|
|
@ -82,7 +83,8 @@ void ServerContainersLogic::onPushButtonRemoveClicked(DockerContainer container)
|
|||
|
||||
void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int port, TransportProto tp)
|
||||
{
|
||||
QJsonObject config = m_serverController->createContainerInitialConfig(c, port, tp);
|
||||
ServerController serverController(m_settings);
|
||||
QJsonObject config = serverController.createContainerInitialConfig(c, port, tp);
|
||||
|
||||
emit uiLogic()->goToPage(Page::ServerConfiguringProgress);
|
||||
qApp->processEvents();
|
||||
|
|
@ -93,7 +95,8 @@ void ServerContainersLogic::onPushButtonContinueClicked(DockerContainer c, int p
|
|||
if (errorCode == ErrorCode::NoError) {
|
||||
if (!uiLogic()->isContainerAlreadyAddedToGui(c)) {
|
||||
auto installAction = [this, c, &config]() {
|
||||
return m_serverController->setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config);
|
||||
ServerController serverController(m_settings);
|
||||
return serverController.setupContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex), c, config);
|
||||
};
|
||||
errorCode = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@
|
|||
#include "configurators/vpn_configurator.h"
|
||||
#include "../uilogic.h"
|
||||
#include "utilities.h"
|
||||
#include "core/servercontroller.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
#include <QStandardPaths>
|
||||
#include <QEventLoop>
|
||||
|
||||
#ifdef Q_OS_ANDROID
|
||||
#include <QJniObject>
|
||||
|
|
@ -94,8 +96,7 @@ void StartPageLogic::onPushButtonConnect()
|
|||
set_labelWaitInfoText(tr("Please fill in all fields"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (lineEditIpText().isEmpty() ||
|
||||
lineEditLoginText().isEmpty() ||
|
||||
lineEditPasswordText().isEmpty() ) {
|
||||
|
|
@ -111,7 +112,7 @@ void StartPageLogic::onPushButtonConnect()
|
|||
serverCredentials.hostName = serverCredentials.hostName.split(":").at(0);
|
||||
}
|
||||
serverCredentials.userName = lineEditLoginText();
|
||||
if (pushButtonConnectKeyChecked()){
|
||||
if (pushButtonConnectKeyChecked()) {
|
||||
QString key = textEditSshKeyText();
|
||||
if (key.startsWith("ssh-rsa")) {
|
||||
emit uiLogic()->showPublicKeyWarning();
|
||||
|
|
@ -123,28 +124,44 @@ void StartPageLogic::onPushButtonConnect()
|
|||
}
|
||||
|
||||
serverCredentials.password = key;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
serverCredentials.password = lineEditPasswordText();
|
||||
}
|
||||
|
||||
set_pushButtonConnectEnabled(false);
|
||||
set_pushButtonConnectText(tr("Connecting..."));
|
||||
|
||||
ErrorCode e = ErrorCode::NoError;
|
||||
#ifdef Q_DEBUG
|
||||
//QString output = m_serverController->checkSshConnection(serverCredentials, &e);
|
||||
#else
|
||||
ServerController serverController(m_settings);
|
||||
ErrorCode errorCode = ErrorCode::NoError;
|
||||
|
||||
if (pushButtonConnectKeyChecked()) {
|
||||
auto passphraseCallback = [this, &serverController]() {
|
||||
emit showPassphraseRequestMessage();
|
||||
QEventLoop loop;
|
||||
QObject::connect(this, &StartPageLogic::passphraseDialogClosed, &loop, &QEventLoop::quit);
|
||||
loop.exec();
|
||||
|
||||
return m_privateKeyPassphrase;
|
||||
};
|
||||
|
||||
QString decryptedPrivateKey;
|
||||
errorCode = serverController.getDecryptedPrivateKey(serverCredentials, decryptedPrivateKey, passphraseCallback);
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
serverCredentials.password = decryptedPrivateKey;
|
||||
}
|
||||
}
|
||||
|
||||
QString output;
|
||||
#endif
|
||||
if (errorCode == ErrorCode::NoError) {
|
||||
output = serverController.checkSshConnection(serverCredentials, &errorCode);
|
||||
}
|
||||
|
||||
bool ok = true;
|
||||
if (e) {
|
||||
if (errorCode) {
|
||||
set_labelWaitInfoVisible(true);
|
||||
set_labelWaitInfoText(errorString(e));
|
||||
set_labelWaitInfoText(errorString(errorCode));
|
||||
ok = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (output.contains("Please login as the user")) {
|
||||
output.replace("\n", "");
|
||||
set_labelWaitInfoVisible(true);
|
||||
|
|
|
|||
|
|
@ -23,6 +23,8 @@ class StartPageLogic : public PageLogicBase
|
|||
AUTO_PROPERTY(QString, labelWaitInfoText)
|
||||
AUTO_PROPERTY(bool, pushButtonBackFromStartVisible)
|
||||
|
||||
AUTO_PROPERTY(QString, privateKeyPassphrase);
|
||||
|
||||
READONLY_PROPERTY(QRegularExpression, ipAddressPortRegex)
|
||||
public:
|
||||
Q_INVOKABLE void onUpdatePage() override;
|
||||
|
|
@ -47,5 +49,8 @@ public:
|
|||
explicit StartPageLogic(UiLogic *uiLogic, QObject *parent = nullptr);
|
||||
~StartPageLogic() = default;
|
||||
|
||||
signals:
|
||||
void showPassphraseRequestMessage();
|
||||
void passphraseDialogClosed();
|
||||
};
|
||||
#endif // START_PAGE_LOGIC_H
|
||||
|
|
|
|||
|
|
@ -112,15 +112,16 @@ void CloakLogic::onPushButtonSaveClicked()
|
|||
|
||||
progressBarFunc.setTextVisibleFunc(true);
|
||||
progressBarFunc.setTextFunc(QString("Configuring..."));
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
|
||||
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
|
||||
uiLogic()->m_selectedDockerContainer,
|
||||
containerConfig,
|
||||
newContainerConfig);
|
||||
},
|
||||
pageFunc, progressBarFunc,
|
||||
saveButtonFunc, waitInfoFunc,
|
||||
busyInfoFuncy, cancelButtonFunc);
|
||||
|
||||
auto installAction = [this, containerConfig, &newContainerConfig]() {
|
||||
ServerController serverController(m_settings);
|
||||
return serverController.updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
|
||||
uiLogic()->m_selectedDockerContainer, containerConfig, newContainerConfig);
|
||||
};
|
||||
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
|
||||
saveButtonFunc, waitInfoFunc,
|
||||
busyInfoFuncy, cancelButtonFunc);
|
||||
|
||||
if (!e) {
|
||||
m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);
|
||||
|
|
|
|||
|
|
@ -162,15 +162,16 @@ void OpenVpnLogic::onPushButtonSaveClicked()
|
|||
|
||||
progressBarFunc.setTextVisibleFunc(true);
|
||||
progressBarFunc.setTextFunc(QString("Configuring..."));
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
|
||||
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
|
||||
uiLogic()->m_selectedDockerContainer,
|
||||
containerConfig,
|
||||
newContainerConfig);
|
||||
},
|
||||
pageFunc, progressBarFunc,
|
||||
saveButtonFunc, waitInfoFunc,
|
||||
busyInfoFuncy, cancelButtonFunc);
|
||||
|
||||
auto installAction = [this, containerConfig, &newContainerConfig]() {
|
||||
ServerController serverController(m_settings);
|
||||
return serverController.updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
|
||||
uiLogic()->m_selectedDockerContainer, containerConfig, newContainerConfig);
|
||||
};
|
||||
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
|
||||
saveButtonFunc, waitInfoFunc,
|
||||
busyInfoFuncy, cancelButtonFunc);
|
||||
|
||||
if (!e) {
|
||||
m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);
|
||||
|
|
|
|||
|
|
@ -104,15 +104,15 @@ void ShadowSocksLogic::onPushButtonSaveClicked()
|
|||
|
||||
progressBarFunc.setTextVisibleFunc(true);
|
||||
progressBarFunc.setTextFunc(QString("Configuring..."));
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction([this, containerConfig, &newContainerConfig](){
|
||||
return m_serverController->updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
|
||||
uiLogic()->m_selectedDockerContainer,
|
||||
containerConfig,
|
||||
newContainerConfig);
|
||||
},
|
||||
pageFunc, progressBarFunc,
|
||||
saveButtonFunc, waitInfoFunc,
|
||||
busyInfoFuncy, cancelButtonFunc);
|
||||
|
||||
auto installAction = [this, containerConfig, &newContainerConfig]() {
|
||||
ServerController serverController(m_settings);
|
||||
return serverController.updateContainer(m_settings->serverCredentials(uiLogic()->m_selectedServerIndex),
|
||||
uiLogic()->m_selectedDockerContainer, containerConfig, newContainerConfig);
|
||||
};
|
||||
ErrorCode e = uiLogic()->pageLogic<ServerConfiguringProgressLogic>()->doInstallAction(installAction, pageFunc, progressBarFunc,
|
||||
saveButtonFunc, waitInfoFunc,
|
||||
busyInfoFuncy, cancelButtonFunc);
|
||||
|
||||
if (!e) {
|
||||
m_settings->setContainerConfig(uiLogic()->m_selectedServerIndex, uiLogic()->m_selectedDockerContainer, newContainerConfig);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue