diff --git a/res/icons/lua.svg b/res/icons/lua.svg
index ee4cc488..af115a93 100644
--- a/res/icons/lua.svg
+++ b/res/icons/lua.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/src/common/xtools.cpp b/src/common/xtools.cpp
index f75f6719..466edbe8 100644
--- a/src/common/xtools.cpp
+++ b/src/common/xtools.cpp
@@ -884,6 +884,7 @@ QVariantMap saveSocketItem(const SocketItem &context)
obj.insert(keys.enableMulticast, context.enableMulticast);
obj.insert(keys.justMulticast, context.justMulticast);
obj.insert(keys.path, context.path);
+ obj.insert(keys.secureMode, context.secureMode);
return obj;
}
@@ -902,6 +903,7 @@ SocketItem loadSocketItem(const QVariantMap &obj)
ctx.enableMulticast = obj.value(keys.enableMulticast).toBool();
ctx.justMulticast = obj.value(keys.justMulticast).toBool();
ctx.path = obj.value(keys.path).toString();
+ ctx.secureMode = obj.value(keys.secureMode).toBool();
return ctx;
}
diff --git a/src/common/xtools.h b/src/common/xtools.h
index cb9ace02..3f7598ee 100644
--- a/src/common/xtools.h
+++ b/src/common/xtools.h
@@ -242,7 +242,8 @@ struct SocketItem
quint16 multicastPort;
bool enableMulticast;
bool justMulticast;
- QString path; // For WebSocket
+ QString path; // For WebSocket
+ bool secureMode; // For WebSocket
};
struct SocketItemKeys
{
@@ -256,7 +257,8 @@ struct SocketItemKeys
const QString multicastPort{"multicastPort"};
const QString enableMulticast{"enableMulticast"};
const QString justMulticast{"justMulticast"};
- const QString path{"path"}; // For WebSocket
+ const QString path{"path"}; // For WebSocket
+ const QString secureMode{"secureMode"}; // For WebSocket
};
SocketItem defaultSocketItem();
QVariantMap saveSocketItem(const SocketItem &context);
diff --git a/src/device/socket.cpp b/src/device/socket.cpp
index c31f5424..6393da9a 100644
--- a/src/device/socket.cpp
+++ b/src/device/socket.cpp
@@ -32,6 +32,11 @@ void Socket::load(const QVariantMap ¶meters)
m_enableMulticast = item.enableMulticast;
m_justMulticast = item.justMulticast;
m_path = item.path;
+#if 0
+ m_secureMode = item.secureMode;
+#else
+ m_secureMode = false;
+#endif
}
void Socket::setDataChannel(int channel)
diff --git a/src/device/socket.h b/src/device/socket.h
index 2a837000..3338d122 100644
--- a/src/device/socket.h
+++ b/src/device/socket.h
@@ -35,6 +35,7 @@ protected:
bool m_justMulticast{false};
QString m_path{""}; // For WebSocket
+ bool m_secureMode{false};
protected:
QString makeFlag(const QString &address, quint16 port) const;
diff --git a/src/device/socketui.cpp b/src/device/socketui.cpp
index 9f9f313e..34058e52 100644
--- a/src/device/socketui.cpp
+++ b/src/device/socketui.cpp
@@ -37,6 +37,7 @@ SocketUi::SocketUi(QWidget *parent)
});
setPathWidgetsVisible(false);
+ setSecureModeWidgetsVisible(false);
}
SocketUi::~SocketUi() {}
@@ -54,7 +55,10 @@ QVariantMap SocketUi::save() const
item.multicastPort = ui->spinBoxMulticastPort->value();
item.enableMulticast = ui->checkBoxEnableMulticast->isChecked();
item.justMulticast = ui->checkBoxJustMulticast->isChecked();
+#if 0
item.path = ui->lineEditPath->text();
+#endif
+ item.secureMode = ui->checkBoxSecureMode->isChecked();
return saveSocketItem(item);
}
@@ -77,7 +81,10 @@ void SocketUi::load(const QVariantMap ¶meters)
ui->spinBoxMulticastPort->setValue(item.multicastPort);
ui->checkBoxEnableMulticast->setChecked(item.enableMulticast);
ui->checkBoxJustMulticast->setChecked(item.justMulticast);
+#if 0
ui->lineEditPath->setText(item.path);
+#endif
+ ui->checkBoxSecureMode->setChecked(item.secureMode);
}
void SocketUi::setServerWidgetsVisible(bool visible)
@@ -126,6 +133,11 @@ void SocketUi::setPathWidgetsVisible(bool visible)
ui->lineEditPath->setVisible(visible);
}
+void SocketUi::setSecureModeWidgetsVisible(bool visible)
+{
+ ui->checkBoxSecureMode->setVisible(visible);
+}
+
void SocketUi::setServerWidgetsEnabled(bool enabled)
{
ui->labelServerIp->setEnabled(enabled);
@@ -175,6 +187,11 @@ void SocketUi::setPathWidgetsEnabled(bool enabled)
ui->lineEditPath->setEnabled(enabled);
}
+void SocketUi::setSecureWidgetsEnabled(bool enabled)
+{
+ ui->checkBoxSecureMode->setEnabled(enabled);
+}
+
void SocketUi::setupClients(const QStringList &clients)
{
QString current = ui->comboBoxWriteTo->currentData().toString();
diff --git a/src/device/socketui.h b/src/device/socketui.h
index 0a655a33..068b9abe 100644
--- a/src/device/socketui.h
+++ b/src/device/socketui.h
@@ -41,6 +41,7 @@ protected:
void setWriteToWidgetsVisible(bool visible);
void setMulticastWidgetsVisible(bool visible);
void setPathWidgetsVisible(bool visible);
+ void setSecureModeWidgetsVisible(bool visible);
void setServerWidgetsEnabled(bool enabled);
void setChannelWidgetsEnabled(bool enabled);
@@ -48,6 +49,7 @@ protected:
void setWriteToWidgetsEnabled(bool enabled);
void setMulticastWidgetsEnabled(bool enabled);
void setPathWidgetsEnabled(bool enabled);
+ void setSecureWidgetsEnabled(bool enabled);
void setupClients(const QStringList &clients);
diff --git a/src/device/socketui.ui b/src/device/socketui.ui
index f39c1cf2..01368dc9 100644
--- a/src/device/socketui.ui
+++ b/src/device/socketui.ui
@@ -7,7 +7,7 @@
0
0
232
- 296
+ 326
@@ -26,135 +26,9 @@
0
- -
-
-
-
-
-
- Enable multicast
-
-
-
- -
-
-
- Just multicast
-
-
-
-
-
- -
-
-
- Channel
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
- Server IP
-
-
-
- -
-
-
- Write to
-
-
-
- -
-
-
- 65535
-
-
- 1024
-
-
-
- -
-
-
- -
-
-
- 239.168.3.255
-
-
-
- -
-
-
- Multicast Port
-
-
-
- -
-
-
- 1
-
-
- 65535
-
-
-
- -
-
-
- User name
-
-
-
- -
-
-
- -
+
-
- -
-
-
- true
-
-
-
- -
-
-
- Authentication
-
-
-
- -
-
-
-
- 0
- 0
-
-
-
- Server port
-
-
-
- -
-
-
- Password
-
-
-
-
@@ -175,17 +49,34 @@
- -
-
+
-
+
- Multicast IP
+ Write to
- -
-
+
-
+
- Path
+ Multicast Port
+
+
+
+ -
+
+
+ 65535
+
+
+ 1024
+
+
+
+ -
+
+
+ Authentication
@@ -196,6 +87,122 @@
+ -
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Server port
+
+
+
+ -
+
+
+ Path
+
+
+
+ -
+
+
-
+
+
+ Enable multicast
+
+
+
+ -
+
+
+ Just multicast
+
+
+
+
+
+ -
+
+
+ Password
+
+
+
+ -
+
+
+ 239.168.3.255
+
+
+
+ -
+
+
+ Multicast IP
+
+
+
+ -
+
+
+ 1
+
+
+ 65535
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+ Server IP
+
+
+
+ -
+
+
+ true
+
+
+
+ -
+
+
+ -
+
+
+ User name
+
+
+
+ -
+
+
+ Channel
+
+
+
+ -
+
+
+ Secure Mode
+
+
+
diff --git a/src/device/websocketclient.cpp b/src/device/websocketclient.cpp
index cd040d13..faba5624 100644
--- a/src/device/websocketclient.cpp
+++ b/src/device/websocketclient.cpp
@@ -28,13 +28,19 @@ QObject *WebSocketClient::initDevice()
m_webSocket,
[this](const QByteArray &message) { onBinaryMessageReceived(message); });
connect(m_webSocket, &QWebSocket::disconnected, m_webSocket, [this]() {
+ qInfo() << "WebSocketClient disconnected:" << m_webSocket->errorString();
emit errorOccurred("");
});
connect(m_webSocket, xWebSocketErrorOccurred, m_webSocket, [this]() {
emit errorOccurred(m_webSocket->errorString());
});
- QString url = QString("ws://%1:%2/%3").arg(m_serverAddress).arg(m_serverPort).arg(m_path);
+ QString flag = m_secureMode ? "wss" : "ws";
+ QString url = flag + QString("://%2:%3/%4").arg(m_serverAddress).arg(m_serverPort).arg(m_path);
+ if (url.lastIndexOf('/') == url.length() - 1) {
+ url.chop(1); // Remove trailing slash if present
+ }
+
if (m_authentication) {
QNetworkRequest request(url);
QString username = m_username;
diff --git a/src/device/websocketclientui.cpp b/src/device/websocketclientui.cpp
index ea20abbd..6ca9f010 100644
--- a/src/device/websocketclientui.cpp
+++ b/src/device/websocketclientui.cpp
@@ -15,7 +15,9 @@ WebSocketClientUi::WebSocketClientUi(QWidget *parent)
{
setWriteToWidgetsVisible(false);
setMulticastWidgetsVisible(false);
- setPathWidgetsVisible(true);
+#if 0
+ setSecureModeWidgetsVisible(true);
+#endif
}
WebSocketClientUi::~WebSocketClientUi() {}
diff --git a/src/device/websocketserver.cpp b/src/device/websocketserver.cpp
index f2e83a48..99ca4a5f 100644
--- a/src/device/websocketserver.cpp
+++ b/src/device/websocketserver.cpp
@@ -8,6 +8,7 @@
**************************************************************************************************/
#include "websocketserver.h"
+#include
#include
#include "common/xtools.h"
@@ -20,8 +21,18 @@ WebSocketServer::~WebSocketServer() {}
QObject *WebSocketServer::initDevice()
{
- m_webSocketServer = new QWebSocketServer(QStringLiteral("WebSocket Server"),
- QWebSocketServer::NonSecureMode);
+ if (m_secureMode) {
+ m_webSocketServer = new QWebSocketServer(QStringLiteral("WebSocket Server"),
+ QWebSocketServer::SecureMode);
+ QSslConfiguration sslConfig = QSslConfiguration::defaultConfiguration();
+ sslConfig.setPeerVerifyMode(QSslSocket::VerifyNone);
+ m_webSocketServer->setSslConfiguration(sslConfig);
+ qInfo() << "WebSocketServer: using secure mode";
+
+ } else {
+ m_webSocketServer = new QWebSocketServer(QStringLiteral("WebSocket Server"),
+ QWebSocketServer::NonSecureMode);
+ }
connect(m_webSocketServer, &QWebSocketServer::acceptError, m_webSocketServer, [this]() {
emit errorOccurred(m_webSocketServer->errorString());
});
@@ -32,21 +43,23 @@ QObject *WebSocketServer::initDevice()
m_sockets.append(socket);
this->setupSocket(socket);
});
+ connect(m_webSocketServer, &QWebSocketServer::serverError, m_webSocketServer, [this]() {
+ qInfo() << "WebSocketServer: server error occurred:" << m_webSocketServer->errorString();
+ });
+ connect(m_webSocketServer,
+ &QWebSocketServer::sslErrors,
+ m_webSocketServer,
+ [this](QList errors) { qInfo() << "SSL errors:" << errors; });
if (!m_webSocketServer->listen(QHostAddress(m_serverAddress), m_serverPort)) {
m_webSocketServer->deleteLater();
m_webSocketServer = nullptr;
qWarning() << "WebSocketServer: listen failed";
-
return nullptr;
}
- qInfo("Web socket server info: %s:%d/%s",
- m_serverAddress.toLatin1().data(),
- m_serverPort,
- m_path.toLatin1().data());
-
+ qInfo("Web socket server info: %s:%d", m_serverAddress.toLatin1().data(), m_serverPort);
return m_webSocketServer;
}
diff --git a/src/device/websocketserverui.cpp b/src/device/websocketserverui.cpp
index 235b9110..164193fc 100644
--- a/src/device/websocketserverui.cpp
+++ b/src/device/websocketserverui.cpp
@@ -15,7 +15,9 @@ WebSocketServerUi::WebSocketServerUi(QWidget *parent)
{
setAuthenticationWidgetsVisible(false);
setMulticastWidgetsVisible(false);
- setPathWidgetsVisible(true);
+#if 0
+ setSecureModeWidgetsVisible(true);
+#endif
}
WebSocketServerUi::~WebSocketServerUi() {}