2024-08-07 14:05:18 +00:00
|
|
|
/*
|
2024-09-17 19:00:25 +00:00
|
|
|
* Deskflow -- mouse and keyboard sharing utility
|
2025-01-24 00:11:17 +00:00
|
|
|
* SPDX-FileCopyrightText: (C) 2021 Symless Ltd.
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
2024-08-07 14:05:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "ServerConnection.h"
|
|
|
|
|
|
|
|
|
|
#include "ServerMessage.h"
|
2025-03-06 23:08:08 +00:00
|
|
|
#include "common/Settings.h"
|
2024-08-10 23:58:24 +00:00
|
|
|
#include "gui/config/ServerConfigDialogState.h"
|
2024-08-08 17:41:59 +00:00
|
|
|
#include "messages.h"
|
2024-08-07 14:05:18 +00:00
|
|
|
|
|
|
|
|
#include <QMessageBox>
|
2024-08-07 17:40:31 +00:00
|
|
|
#include <QPushButton>
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
namespace deskflow::gui {
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
//
|
|
|
|
|
// ServerConnection::Deps
|
|
|
|
|
//
|
|
|
|
|
|
2025-02-17 19:16:20 +00:00
|
|
|
messages::NewClientPromptResult ServerConnection::Deps::showNewClientPrompt(
|
|
|
|
|
QWidget *parent, const QString &clientName, bool serverRequiresPeerAuth
|
|
|
|
|
) const
|
2024-10-17 18:04:35 +00:00
|
|
|
{
|
2025-02-17 19:16:20 +00:00
|
|
|
return messages::showNewClientPrompt(parent, clientName, serverRequiresPeerAuth);
|
2024-08-08 17:41:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// ServerConnection
|
|
|
|
|
//
|
|
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
ServerConnection::ServerConnection(
|
2024-08-08 17:41:59 +00:00
|
|
|
QWidget *parent, IAppConfig &appConfig, IServerConfig &serverConfig,
|
2024-10-17 18:04:35 +00:00
|
|
|
const config::ServerConfigDialogState &serverConfigDialogState, std::shared_ptr<Deps> deps
|
|
|
|
|
)
|
2024-08-08 17:41:59 +00:00
|
|
|
: m_pParent(parent),
|
2024-08-07 14:05:18 +00:00
|
|
|
m_appConfig(appConfig),
|
2024-08-08 17:41:59 +00:00
|
|
|
m_serverConfig(serverConfig),
|
2024-08-10 23:58:24 +00:00
|
|
|
m_serverConfigDialogState(serverConfigDialogState),
|
2024-10-17 18:04:35 +00:00
|
|
|
m_pDeps(deps)
|
|
|
|
|
{
|
|
|
|
|
}
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ServerConnection::handleLogLine(const QString &logLine)
|
|
|
|
|
{
|
2024-08-08 17:41:59 +00:00
|
|
|
ServerMessage message(logLine);
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-08-09 18:20:10 +00:00
|
|
|
if (!message.isNewClientMessage()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-10 23:58:24 +00:00
|
|
|
if (m_messageShowing) {
|
|
|
|
|
qDebug("new client message already shown, skipping for now");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_serverConfigDialogState.isVisible()) {
|
|
|
|
|
qDebug("server config dialog visible, skipping new client prompt");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-09 18:20:10 +00:00
|
|
|
if (m_appConfig.useExternalConfig()) {
|
|
|
|
|
qDebug("external config enabled, skipping new client prompt");
|
|
|
|
|
return;
|
2024-08-07 14:05:18 +00:00
|
|
|
}
|
2024-08-09 18:20:10 +00:00
|
|
|
|
|
|
|
|
const auto client = message.getClientName();
|
|
|
|
|
|
|
|
|
|
if (m_receivedClients.contains(client)) {
|
2024-10-17 18:04:35 +00:00
|
|
|
qDebug("already got request, skipping new client prompt for: %s", qPrintable(client));
|
2024-08-09 18:20:10 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleNewClient(message.getClientName());
|
2024-08-07 14:05:18 +00:00
|
|
|
}
|
|
|
|
|
|
2024-10-17 18:04:35 +00:00
|
|
|
void ServerConnection::handleNewClient(const QString &clientName)
|
|
|
|
|
{
|
2024-08-08 17:41:59 +00:00
|
|
|
using enum messages::NewClientPromptResult;
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-08-09 18:20:10 +00:00
|
|
|
m_receivedClients.append(clientName);
|
|
|
|
|
|
2024-08-07 14:05:18 +00:00
|
|
|
if (m_serverConfig.isFull()) {
|
2024-10-17 18:04:35 +00:00
|
|
|
qDebug("server config full, skipping new client prompt for: %s", qPrintable(clientName));
|
2024-08-07 14:05:18 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_serverConfig.screenExists(clientName)) {
|
2024-10-17 18:04:35 +00:00
|
|
|
qDebug("client already added, skipping new client prompt for: %s", qPrintable(clientName));
|
2024-08-07 14:05:18 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 04:08:10 +00:00
|
|
|
Q_EMIT messageShowing();
|
2024-08-07 14:05:18 +00:00
|
|
|
|
2024-08-09 18:20:10 +00:00
|
|
|
m_messageShowing = true;
|
2025-03-06 23:08:08 +00:00
|
|
|
const bool tlsEnabled = Settings::value(Settings::Security::TlsEnabled).toBool();
|
2025-02-15 04:37:15 +00:00
|
|
|
const auto result =
|
2025-03-06 23:08:08 +00:00
|
|
|
m_pDeps->showNewClientPrompt(m_pParent, clientName, tlsEnabled && m_appConfig.requireClientCerts());
|
2024-08-09 18:20:10 +00:00
|
|
|
m_messageShowing = false;
|
|
|
|
|
|
2024-08-08 17:41:59 +00:00
|
|
|
if (result == Add) {
|
2024-08-07 17:40:31 +00:00
|
|
|
qDebug("accepted dialog, adding client: %s", qPrintable(clientName));
|
2024-10-21 04:08:10 +00:00
|
|
|
Q_EMIT configureClient(clientName);
|
2024-08-08 17:41:59 +00:00
|
|
|
} else if (result == Ignore) {
|
2024-08-07 17:40:31 +00:00
|
|
|
qDebug("declined dialog, ignoring client: %s", qPrintable(clientName));
|
|
|
|
|
} else {
|
2024-08-08 17:41:59 +00:00
|
|
|
qFatal("unexpected add client result");
|
2024-08-07 14:05:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-17 19:00:25 +00:00
|
|
|
} // namespace deskflow::gui
|