added saving the list of clients for wireguard
- added error handling when getting/saving a list of clients
This commit is contained in:
parent
8c137ecc52
commit
a7030cdcb9
5 changed files with 87 additions and 53 deletions
|
|
@ -21,11 +21,15 @@ void ClientManagementModel::setContent(const QVector<QVariant> &data)
|
|||
endResetModel();
|
||||
}
|
||||
|
||||
QJsonObject ClientManagementModel::getContent()
|
||||
QJsonObject ClientManagementModel::getContent(Proto protocol)
|
||||
{
|
||||
QJsonObject clientsTable;
|
||||
for (const auto &item : m_content) {
|
||||
clientsTable[item.toJsonObject()["openvpnCertId"].toString()] = item.toJsonObject();
|
||||
if (protocol == Proto::OpenVpn) {
|
||||
clientsTable[item.toJsonObject()["openvpnCertId"].toString()] = item.toJsonObject();
|
||||
} else if (protocol == Proto::WireGuard) {
|
||||
clientsTable[item.toJsonObject()["wireguardPublicKey"].toString()] = item.toJsonObject();
|
||||
}
|
||||
}
|
||||
return clientsTable;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ public:
|
|||
|
||||
void clearData();
|
||||
void setContent(const QVector<QVariant> &data);
|
||||
QJsonObject getContent();
|
||||
QJsonObject getContent(Proto protocol);
|
||||
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
void setData(const QModelIndex &index, QVariant data, int role = Qt::DisplayRole);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#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"
|
||||
|
|
@ -16,7 +20,7 @@ void ClientInfoLogic::setCurrentClientId(int index)
|
|||
}
|
||||
|
||||
void ClientInfoLogic::onUpdatePage()
|
||||
{
|
||||
{
|
||||
DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex);
|
||||
QString selectedContainerName = ContainerProps::containerHumanNames().value(selectedContainer);
|
||||
set_labelCurrentVpnProtocolText(tr("Service: ") + selectedContainerName);
|
||||
|
|
@ -39,20 +43,26 @@ void ClientInfoLogic::onUpdatePage()
|
|||
}
|
||||
|
||||
void ClientInfoLogic::onLineEditNameAliasEditingFinished()
|
||||
{
|
||||
{
|
||||
auto model = qobject_cast<ClientManagementModel*>(uiLogic()->clientManagementModel());
|
||||
auto modelIndex = model->index(m_currentClientIndex);
|
||||
model->setData(modelIndex, m_lineEditNameAliasText, ClientManagementModel::ClientRoles::NameRole);
|
||||
|
||||
auto clientsTable = model->getContent();
|
||||
|
||||
DockerContainer selectedContainer = m_settings->defaultContainer(uiLogic()->selectedServerIndex);
|
||||
auto protocols = ContainerProps::protocolsForContainer(selectedContainer);
|
||||
if (!protocols.empty()) {
|
||||
auto currentMainProtocol = protocols.front();
|
||||
m_serverController->setClientsList(m_settings->serverCredentials(uiLogic()->selectedServerIndex),
|
||||
auto clientsTable = model->getContent(currentMainProtocol);
|
||||
ErrorCode error = m_serverController->setClientsList(m_settings->serverCredentials(uiLogic()->selectedServerIndex),
|
||||
selectedContainer,
|
||||
currentMainProtocol,
|
||||
clientsTable);
|
||||
if (error != ErrorCode::NoError) {
|
||||
QMessageBox::warning(nullptr, APPLICATION_NAME,
|
||||
tr("An error occurred while getting the list of clients.") + "\n" + errorString(error));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#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"
|
||||
|
|
@ -24,8 +28,13 @@ void ClientManagementLogic::onUpdatePage()
|
|||
if (!protocols.empty()) {
|
||||
m_currentMainProtocol = protocols.front();
|
||||
|
||||
ErrorCode e = m_serverController->getClientsList(m_settings->serverCredentials(uiLogic()->selectedServerIndex),
|
||||
ErrorCode error = m_serverController->getClientsList(m_settings->serverCredentials(uiLogic()->selectedServerIndex),
|
||||
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));
|
||||
return;
|
||||
}
|
||||
}
|
||||
QVector<QVariant> clientsArray;
|
||||
for (auto &clientId : clients.keys()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue