Revert "Config, websocketserver: Add feature to bind to loopback (default)"

This reverts commit 1da0214201.
This commit is contained in:
tt2468 2022-06-07 23:07:09 -07:00
parent e04bca0993
commit 711746524c
5 changed files with 4 additions and 34 deletions

View File

@ -28,7 +28,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
#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));

View File

@ -38,7 +38,6 @@ struct Config {
std::atomic<bool> FirstLoad;
std::atomic<bool> ServerEnabled;
std::atomic<uint16_t> ServerPort;
std::atomic<bool> BindLoopback;
std::atomic<bool> Ipv4Only;
std::atomic<bool> DebugEnabled;
std::atomic<bool> AlertsEnabled;

View File

@ -77,21 +77,6 @@ std::string Utils::Platform::GetLocalAddress()
return preferredAddresses[0].first.toStdString();
}
std::string Utils::Platform::GetLoopbackAddress(bool allowIpv6)
{
std::vector<QString> 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;

View File

@ -26,7 +26,6 @@ with this program. If not, see <https://www.gnu.org/licenses/>
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);

View File

@ -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;
}