8
8
#include " ../src_websocket/websocketclient.h"
9
9
#include " ../src_interfaces/databasecontroller.h"
10
10
#include " ../src_interfaces/firewallcontroller.h"
11
+ #include " ../src_interfaces/configcontroller.h"
11
12
#include < QtCore/QFile>
12
13
#include < QtNetwork/QSslCertificate>
13
14
#include < QtNetwork/QSslKey>
14
15
#include < QCoreApplication>
15
16
#include < QDir>
17
+ #include < QSettings>
16
18
WebSocketController::WebSocketController (QObject *parent, DatabaseController* i_db) : QObject(parent), m_db(i_db)
17
19
{
18
20
19
- server = new QWebSocketServer (QStringLiteral (" WP Daemon Websocket Listener" ), QWebSocketServer::NonSecureMode, this );
21
+ m_settings = new ConfigController (this );
22
+ bool enable_ssl = m_settings->settings ()->value (" enable_ssl" , " false" ).toBool ();
23
+
24
+ if (!enable_ssl) {
25
+ server = new QWebSocketServer (QStringLiteral (" WP Daemon Websocket Listener" ), QWebSocketServer::NonSecureMode, this );
26
+ } else {
27
+ qDebug () << " Running in Secure Mode" ;
28
+ server = new QWebSocketServer (QStringLiteral (" WP Daemon Websocket Listener" ), QWebSocketServer::SecureMode, this );
20
29
21
30
22
31
QSslConfiguration sslConfiguration;
23
- /* QFile certFile(QStringLiteral(":/localhost.cert"));
24
- QFile keyFile(QStringLiteral(":/localhost.key"));
32
+ /* QFile certFile(QStringLiteral(":/localhost.cert"));
33
+ QFile keyFile(QStringLiteral(":/localhost.key")); */
34
+
25
35
26
- */
27
- /* QFile certFile(qApp->applicationDirPath().append(QDir::separator()).append(QStringLiteral("fullchain.cert")));
28
- QFile keyFile(qApp->applicationDirPath().append(QDir::separator()).append(QStringLiteral("fullchain.key")));
36
+ QFile certFile (m_settings->settings ()->value (" ssl_certificate_file" , qApp->applicationDirPath ().append (QDir::separator ()).append (QStringLiteral (" fullchain.cert" ))).toString ());
37
+ QFile keyFile (m_settings->settings ()->value (" ssl_key_file" , qApp->applicationDirPath ().append (QDir::separator ()).append (QStringLiteral (" fullchain.key" ))).toString ());
29
38
certFile.open (QIODevice::ReadOnly);
30
39
keyFile.open (QIODevice::ReadOnly);
31
40
QSslCertificate certificate (&certFile, QSsl::Pem);
@@ -36,8 +45,9 @@ QFile keyFile(QStringLiteral(":/localhost.key"));
36
45
sslConfiguration.setLocalCertificate (certificate);
37
46
sslConfiguration.setPrivateKey (sslKey);
38
47
sslConfiguration.setProtocol (QSsl::TlsV1SslV3);
48
+ server->setMaxPendingConnections (3 );
39
49
server->setSslConfiguration (sslConfiguration);
40
- */
50
+ }
41
51
if (!server->listen (QHostAddress::LocalHost, 65300 )) {
42
52
qFatal (" Failed to open web socket server." );
43
53
// return 1;
0 commit comments