diff --git a/src/Config.cpp b/src/Config.cpp index 3cb9730e..f3c615e6 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -323,6 +323,10 @@ void Config::FirstRunPasswordSetup() // check if the password is already set auto config = GetConfig(); + if (!config) { + return; + } + if (!(config->Secret.isEmpty()) && !(config->Salt.isEmpty())) { return; } diff --git a/src/Utils.cpp b/src/Utils.cpp index c67281e6..01ccdcac 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -509,9 +509,9 @@ QSystemTrayIcon* Utils::GetTrayIcon() { return reinterpret_cast(systemTray); } -void Utils::SysTrayNotify(QString text, - QSystemTrayIcon::MessageIcon icon, QString title) { - if (!GetConfig()->AlertsEnabled || +void Utils::SysTrayNotify(QString text, QSystemTrayIcon::MessageIcon icon, QString title) { + auto config = GetConfig(); + if ((config && !config->AlertsEnabled) || !QSystemTrayIcon::isSystemTrayAvailable() || !QSystemTrayIcon::supportsMessages()) { diff --git a/src/WSRequestHandler.cpp b/src/WSRequestHandler.cpp index 20f9cb73..0ad58204 100644 --- a/src/WSRequestHandler.cpp +++ b/src/WSRequestHandler.cpp @@ -194,7 +194,8 @@ WSRequestHandler::WSRequestHandler(ConnectionProperties& connProperties) : } RpcResponse WSRequestHandler::processRequest(const RpcRequest& request) { - if (GetConfig()->AuthRequired + auto config = GetConfig(); + if ((config && config->AuthRequired) && (!authNotRequired.contains(request.methodName())) && (!_connProperties.isAuthenticated())) { diff --git a/src/WSRequestHandler_General.cpp b/src/WSRequestHandler_General.cpp index 15d4ba76..39824735 100644 --- a/src/WSRequestHandler_General.cpp +++ b/src/WSRequestHandler_General.cpp @@ -115,13 +115,13 @@ RpcResponse WSRequestHandler::GetVersion(const RpcRequest& request) { * @since 0.3 */ RpcResponse WSRequestHandler::GetAuthRequired(const RpcRequest& request) { - bool authRequired = GetConfig()->AuthRequired; + auto config = GetConfig(); + bool authRequired = (config && config->AuthRequired); OBSDataAutoRelease data = obs_data_create(); obs_data_set_bool(data, "authRequired", authRequired); if (authRequired) { - auto config = GetConfig(); obs_data_set_string(data, "challenge", config->SessionChallenge.toUtf8()); obs_data_set_string(data, "salt", @@ -155,7 +155,8 @@ RpcResponse WSRequestHandler::Authenticate(const RpcRequest& request) { return request.failed("auth not specified!"); } - if (GetConfig()->CheckAuth(auth) == false) { + auto config = GetConfig(); + if (!config || (config->CheckAuth(auth) == false)) { return request.failed("Authentication Failed."); } diff --git a/src/WSServer.cpp b/src/WSServer.cpp index 8f1ec8bf..3e6f9934 100644 --- a/src/WSServer.cpp +++ b/src/WSServer.cpp @@ -135,13 +135,14 @@ void WSServer::broadcast(const RpcEvent& event) { std::string message = OBSRemoteProtocol::encodeEvent(event); - if (GetConfig()->DebugEnabled) { + auto config = GetConfig(); + if (config && config->DebugEnabled) { blog(LOG_INFO, "Update << '%s'", message.c_str()); } QMutexLocker locker(&_clMutex); for (connection_hdl hdl : _connections) { - if (GetConfig()->AuthRequired) { + if (config && config->AuthRequired) { bool authenticated = _connectionProperties[hdl].isAuthenticated(); if (!authenticated) { continue; @@ -184,14 +185,15 @@ void WSServer::onMessage(connection_hdl hdl, server::message_ptr message) ConnectionProperties& connProperties = _connectionProperties[hdl]; locker.unlock(); - if (GetConfig()->DebugEnabled) { + auto config = GetConfig(); + if (config && config->DebugEnabled) { blog(LOG_INFO, "Request >> '%s'", payload.c_str()); } WSRequestHandler requestHandler(connProperties); std::string response = OBSRemoteProtocol::processMessage(requestHandler, payload); - if (GetConfig()->DebugEnabled) { + if (config && config->DebugEnabled) { blog(LOG_INFO, "Response << '%s'", response.c_str()); } diff --git a/src/forms/settings-dialog.cpp b/src/forms/settings-dialog.cpp index f852186c..4835a8c4 100644 --- a/src/forms/settings-dialog.cpp +++ b/src/forms/settings-dialog.cpp @@ -43,17 +43,18 @@ SettingsDialog::SettingsDialog(QWidget* parent) : void SettingsDialog::showEvent(QShowEvent* event) { auto conf = GetConfig(); + if (conf) { + ui->serverEnabled->setChecked(conf->ServerEnabled); + ui->serverPort->setValue(conf->ServerPort); + ui->lockToIPv4->setChecked(conf->LockToIPv4); - ui->serverEnabled->setChecked(conf->ServerEnabled); - ui->serverPort->setValue(conf->ServerPort); - ui->lockToIPv4->setChecked(conf->LockToIPv4); + ui->debugEnabled->setChecked(conf->DebugEnabled); + ui->alertsEnabled->setChecked(conf->AlertsEnabled); - ui->debugEnabled->setChecked(conf->DebugEnabled); - ui->alertsEnabled->setChecked(conf->AlertsEnabled); - - ui->authRequired->blockSignals(true); - ui->authRequired->setChecked(conf->AuthRequired); - ui->authRequired->blockSignals(false); + ui->authRequired->blockSignals(true); + ui->authRequired->setChecked(conf->AuthRequired); + ui->authRequired->blockSignals(false); + } ui->password->setText(CHANGE_ME); ui->password->setEnabled(ui->authRequired->isChecked()); @@ -94,6 +95,9 @@ void SettingsDialog::AuthCheckboxChanged() { void SettingsDialog::FormAccepted() { auto conf = GetConfig(); + if (!conf) { + return; + } conf->ServerEnabled = ui->serverEnabled->isChecked(); conf->ServerPort = ui->serverPort->value(); @@ -107,7 +111,7 @@ void SettingsDialog::FormAccepted() { conf->SetPassword(ui->password->text()); } - if (!GetConfig()->Secret.isEmpty()) + if (!conf->Secret.isEmpty()) conf->AuthRequired = true; else conf->AuthRequired = false;