diff --git a/client/amnezia_application.cpp b/client/amnezia_application.cpp index 7bac2cf6..60397994 100644 --- a/client/amnezia_application.cpp +++ b/client/amnezia_application.cpp @@ -457,7 +457,7 @@ void AmneziaApplication::initControllers() QTimer::singleShot(1000, this, [this]() { m_connectionController->openConnection(); }); } connect(m_settingsController.get(), &SettingsController::amneziaDnsToggled, m_serversModel.get(), &ServersModel::toggleAmneziaDns); - connect(m_settingsController.get(), &SettingsController::strictKillSwitchEnabledChanged, m_vpnConnection.get(), &VpnConnection::onKillswitchModeChanged); + connect(m_settingsController.get(), &SettingsController::strictKillSwitchEnabledChanged, m_vpnConnection.get(), &VpnConnection::onKillSwitchModeChanged); m_sitesController.reset(new SitesController(m_settings, m_vpnConnection, m_sitesModel)); m_engine->rootContext()->setContextProperty("SitesController", m_sitesController.get()); diff --git a/client/ui/controllers/settingsController.cpp b/client/ui/controllers/settingsController.cpp index 8c43e16f..3808375a 100644 --- a/client/ui/controllers/settingsController.cpp +++ b/client/ui/controllers/settingsController.cpp @@ -256,7 +256,7 @@ bool SettingsController::isStrictKillSwitchEnabled() void SettingsController::toggleStrictKillSwitch(bool enable) { m_settings->setStrictKillSwitchEnabled(enable); - emit strictKillSwitchEnabledChanged(); + emit strictKillSwitchEnabledChanged(enable); } bool SettingsController::isNotificationPermissionGranted() diff --git a/client/ui/controllers/settingsController.h b/client/ui/controllers/settingsController.h index 0956a82c..1485e1a0 100644 --- a/client/ui/controllers/settingsController.h +++ b/client/ui/controllers/settingsController.h @@ -104,7 +104,7 @@ signals: void secondaryDnsChanged(); void loggingStateChanged(); void killSwitchEnabledChanged(); - void strictKillSwitchEnabledChanged(); + void strictKillSwitchEnabledChanged(bool enabled); void restoreBackupFinished(); void changeSettingsFinished(const QString &finishedMessage); diff --git a/client/vpnconnection.cpp b/client/vpnconnection.cpp index bdd44c61..3e3ef23b 100644 --- a/client/vpnconnection.cpp +++ b/client/vpnconnection.cpp @@ -52,10 +52,12 @@ void VpnConnection::onBytesChanged(quint64 receivedBytes, quint64 sentBytes) emit bytesChanged(receivedBytes, sentBytes); } -void VpnConnection::onKillswitchModeChanged() +void VpnConnection::onKillSwitchModeChanged(bool enabled) { #ifdef AMNEZIA_DESKTOP - IpcClient::Interface()->refreshKillSwitch(); + if (IpcClient::Interface()) { + IpcClient::Interface()->refreshKillSwitch(enabled); + } #endif } diff --git a/client/vpnconnection.h b/client/vpnconnection.h index cc7bf0f5..cb5aaaf9 100644 --- a/client/vpnconnection.h +++ b/client/vpnconnection.h @@ -55,7 +55,7 @@ public slots: void addRoutes(const QStringList &ips); void deleteRoutes(const QStringList &ips); void flushDns(); - void onKillswitchModeChanged(); + void onKillSwitchModeChanged(bool enabled); signals: void bytesChanged(quint64 receivedBytes, quint64 sentBytes); diff --git a/ipc/ipc_interface.rep b/ipc/ipc_interface.rep index c36893b9..c692817d 100644 --- a/ipc/ipc_interface.rep +++ b/ipc/ipc_interface.rep @@ -30,7 +30,7 @@ class IpcInterface SLOT( bool disableKillSwitch() ); SLOT( bool disableAllTraffic() ); - SLOT( bool refreshKillSwitch() ); + SLOT( bool refreshKillSwitch( bool enabled ) ); SLOT( bool allowTrafficTo( const QStringList ranges ) ); SLOT( bool enablePeerTraffic( const QJsonObject &configStr) ); SLOT( bool enableKillSwitch( const QJsonObject &excludeAddr, int vpnAdapterIndex) ); diff --git a/ipc/ipcserver.cpp b/ipc/ipcserver.cpp index 598c7144..ced2987e 100644 --- a/ipc/ipcserver.cpp +++ b/ipc/ipcserver.cpp @@ -204,7 +204,7 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr) return KillSwitch::instance()->enablePeerTraffic(configStr); } -bool IpcServer::refreshKillSwitch() +bool IpcServer::refreshKillSwitch(bool enabled) { - return KillSwitch::instance()->refresh(); + return KillSwitch::instance()->refresh(enabled); } diff --git a/ipc/ipcserver.h b/ipc/ipcserver.h index 93d827a1..31cd007f 100644 --- a/ipc/ipcserver.h +++ b/ipc/ipcserver.h @@ -39,7 +39,7 @@ public: virtual bool enablePeerTraffic(const QJsonObject &configStr) override; virtual bool enableKillSwitch(const QJsonObject &excludeAddr, int vpnAdapterIndex) override; virtual bool disableKillSwitch() override; - virtual bool refreshKillSwitch() override; + virtual bool refreshKillSwitch( bool enabled ) override; virtual bool updateResolvers(const QString& ifname, const QList& resolvers) override; private: diff --git a/service/server/killswitch.cpp b/service/server/killswitch.cpp index 261ac789..24e162aa 100644 --- a/service/server/killswitch.cpp +++ b/service/server/killswitch.cpp @@ -49,8 +49,13 @@ bool KillSwitch::init() return true; } -bool KillSwitch::refresh() +bool KillSwitch::refresh(bool enabled) { +#ifdef Q_OS_WIN + QSettings RegHLM("HKEY_LOCAL_MACHINE\\Software\\" + QString(ORGANIZATION_NAME) + + "\\" + QString(APPLICATION_NAME), QSettings::NativeFormat); + RegHLM.setValue("strictKillSwitchEnabled", enabled); +#endif if (isStrictKillSwitchEnabled()) { return disableAllTraffic(); } else { @@ -60,6 +65,11 @@ bool KillSwitch::refresh() bool KillSwitch::isStrictKillSwitchEnabled() { +#ifdef Q_OS_WIN + QSettings RegHLM("HKEY_LOCAL_MACHINE\\Software\\" + QString(ORGANIZATION_NAME) + + "\\" + QString(APPLICATION_NAME), QSettings::NativeFormat); + return RegHLM.value("strictKillSwitchEnabled", false).toBool(); +#endif m_appSettigns = QSharedPointer(new SecureQSettings(ORGANIZATION_NAME, APPLICATION_NAME, nullptr)); return m_appSettigns->value("Conf/strictKillSwitchEnabled", false).toBool(); } diff --git a/service/server/killswitch.h b/service/server/killswitch.h index 4659606d..a468c6c2 100644 --- a/service/server/killswitch.h +++ b/service/server/killswitch.h @@ -12,7 +12,7 @@ class KillSwitch : public QObject public: static KillSwitch *instance(); bool init(); - bool refresh(); + bool refresh(bool enabled); bool disableKillSwitch(); bool disableAllTraffic(); bool enablePeerTraffic( const QJsonObject &configStr);