From 711746524c5fba2239a973c10feaa688415c5ac0 Mon Sep 17 00:00:00 2001 From: tt2468 Date: Tue, 7 Jun 2022 23:07:09 -0700 Subject: [PATCH] Revert "Config, websocketserver: Add feature to bind to loopback (default)" This reverts commit 1da0214201f96e6e53dfa88701cb8f3721946bde. --- src/Config.cpp | 5 ----- src/Config.h | 1 - src/utils/Platform.cpp | 15 --------------- src/utils/Platform.h | 1 - src/websocketserver/WebSocketServer.cpp | 16 ++++------------ 5 files changed, 4 insertions(+), 34 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index 7d7aba68..cbe6be1d 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -28,7 +28,6 @@ with this program. If not, see #define PARAM_FIRSTLOAD "FirstLoad" #define PARAM_ENABLED "ServerEnabled" #define PARAM_PORT "ServerPort" -#define PARAM_BINDLOOPBACK "BindLoopback" #define PARAM_ALERTS "AlertsEnabled" #define PARAM_AUTHREQUIRED "AuthRequired" #define PARAM_PASSWORD "ServerPassword" @@ -44,7 +43,6 @@ Config::Config() FirstLoad(true), ServerEnabled(true), ServerPort(4455), - BindLoopback(true), Ipv4Only(false), DebugEnabled(false), AlertsEnabled(false), @@ -66,7 +64,6 @@ void Config::Load() ServerEnabled = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ENABLED); AlertsEnabled = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ALERTS); ServerPort = config_get_uint(obsConfig, CONFIG_SECTION_NAME, PARAM_PORT); - BindLoopback = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_BINDLOOPBACK); AuthRequired = config_get_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_AUTHREQUIRED); ServerPassword = config_get_string(obsConfig, CONFIG_SECTION_NAME, PARAM_PASSWORD); @@ -134,7 +131,6 @@ void Config::Save() if (!PortOverridden) { config_set_uint(obsConfig, CONFIG_SECTION_NAME, PARAM_PORT, ServerPort); } - config_set_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_BINDLOOPBACK, BindLoopback); config_set_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ALERTS, AlertsEnabled); if (!PasswordOverridden) { config_set_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired); @@ -155,7 +151,6 @@ void Config::SetDefaultsToGlobalStore() config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_FIRSTLOAD, FirstLoad); config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ENABLED, ServerEnabled); config_set_default_uint(obsConfig, CONFIG_SECTION_NAME, PARAM_PORT, ServerPort); - config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_BINDLOOPBACK, BindLoopback); config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_ALERTS, AlertsEnabled); config_set_default_bool(obsConfig, CONFIG_SECTION_NAME, PARAM_AUTHREQUIRED, AuthRequired); config_set_default_string(obsConfig, CONFIG_SECTION_NAME, PARAM_PASSWORD, QT_TO_UTF8(ServerPassword)); diff --git a/src/Config.h b/src/Config.h index 4c337ec9..74a501f3 100644 --- a/src/Config.h +++ b/src/Config.h @@ -38,7 +38,6 @@ struct Config { std::atomic FirstLoad; std::atomic ServerEnabled; std::atomic ServerPort; - std::atomic BindLoopback; std::atomic Ipv4Only; std::atomic DebugEnabled; std::atomic AlertsEnabled; diff --git a/src/utils/Platform.cpp b/src/utils/Platform.cpp index b4a00cb8..0e9defd5 100644 --- a/src/utils/Platform.cpp +++ b/src/utils/Platform.cpp @@ -77,21 +77,6 @@ std::string Utils::Platform::GetLocalAddress() return preferredAddresses[0].first.toStdString(); } -std::string Utils::Platform::GetLoopbackAddress(bool allowIpv6) -{ - std::vector validAddresses; - for (auto address : QNetworkInterface::allAddresses()) { - if (address == QHostAddress::LocalHost) - return address.toString().toStdString(); - else if (address == QHostAddress::LocalHostIPv6 && allowIpv6) - return address.toString().toStdString(); - else if (address.isLoopback()) - return address.toString().toStdString(); - } - - return ""; -} - QString Utils::Platform::GetCommandLineArgument(QString arg) { QCommandLineParser parser; diff --git a/src/utils/Platform.h b/src/utils/Platform.h index 2f4ef18e..22d52626 100644 --- a/src/utils/Platform.h +++ b/src/utils/Platform.h @@ -26,7 +26,6 @@ with this program. If not, see namespace Utils { namespace Platform { std::string GetLocalAddress(); -std::string GetLoopbackAddress(bool allowIpv6 = true); QString GetCommandLineArgument(QString arg); bool GetCommandLineFlagSet(QString arg); void SendTrayNotification(QSystemTrayIcon::MessageIcon icon, QString title, QString body); diff --git a/src/websocketserver/WebSocketServer.cpp b/src/websocketserver/WebSocketServer.cpp index e646063b..6b5d89b9 100644 --- a/src/websocketserver/WebSocketServer.cpp +++ b/src/websocketserver/WebSocketServer.cpp @@ -107,25 +107,17 @@ void WebSocketServer::Start() _server.reset(); websocketpp::lib::error_code errorCode; - if (conf->BindLoopback) { - std::string addr = Utils::Platform::GetLoopbackAddress(!conf->Ipv4Only); - if (addr.empty()) { - blog(LOG_ERROR, "[WebSocketServer::Start] Failed to find loopback interface. Server not started."); - return; - } - _server.listen(addr, std::to_string(conf->ServerPort), errorCode); - blog(LOG_INFO, "[WebSocketServer::Start] Locked to loopback interface."); - } else if (conf->Ipv4Only) { + if (conf->Ipv4Only) { + blog(LOG_INFO, "[WebSocketServer::Start] Locked to IPv4 bindings"); _server.listen(websocketpp::lib::asio::ip::tcp::v4(), conf->ServerPort, errorCode); - blog(LOG_INFO, "[WebSocketServer::Start] Locked to IPv4 bindings."); } else { + blog(LOG_INFO, "[WebSocketServer::Start] Not locked to IPv4 bindings"); _server.listen(conf->ServerPort, errorCode); - blog(LOG_INFO, "[WebSocketServer::Start] Not locked to IPv4 bindings."); } if (errorCode) { std::string errorCodeMessage = errorCode.message(); - blog(LOG_ERROR, "[WebSocketServer::Start] Listen failed: %s", errorCodeMessage.c_str()); + blog(LOG_INFO, "[WebSocketServer::Start] Listen failed: %s", errorCodeMessage.c_str()); return; }