diff --git a/client/amnezia_application.cpp b/client/amnezia_application.cpp index 8706be58..7bac2cf6 100644 --- a/client/amnezia_application.cpp +++ b/client/amnezia_application.cpp @@ -457,6 +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); m_sitesController.reset(new SitesController(m_settings, m_vpnConnection, m_sitesModel)); m_engine->rootContext()->setContextProperty("SitesController", m_sitesController.get()); diff --git a/client/vpnconnection.cpp b/client/vpnconnection.cpp index 042c51c7..bdd44c61 100644 --- a/client/vpnconnection.cpp +++ b/client/vpnconnection.cpp @@ -52,6 +52,13 @@ void VpnConnection::onBytesChanged(quint64 receivedBytes, quint64 sentBytes) emit bytesChanged(receivedBytes, sentBytes); } +void VpnConnection::onKillswitchModeChanged() +{ +#ifdef AMNEZIA_DESKTOP + IpcClient::Interface()->refreshKillSwitch(); +#endif +} + void VpnConnection::onConnectionStateChanged(Vpn::ConnectionState state) { diff --git a/client/vpnconnection.h b/client/vpnconnection.h index 0160edce..cc7bf0f5 100644 --- a/client/vpnconnection.h +++ b/client/vpnconnection.h @@ -48,14 +48,14 @@ public: public slots: void connectToVpn(int serverIndex, - const ServerCredentials &credentials, DockerContainer container, const QJsonObject &vpnConfiguration); + const ServerCredentials &credentials, DockerContainer container, const QJsonObject &vpnConfiguration); void disconnectFromVpn(); - void addRoutes(const QStringList &ips); void deleteRoutes(const QStringList &ips); void flushDns(); + void onKillswitchModeChanged(); signals: void bytesChanged(quint64 receivedBytes, quint64 sentBytes); diff --git a/ipc/ipc_interface.rep b/ipc/ipc_interface.rep index 0ce7626a..c36893b9 100644 --- a/ipc/ipc_interface.rep +++ b/ipc/ipc_interface.rep @@ -30,6 +30,7 @@ class IpcInterface SLOT( bool disableKillSwitch() ); SLOT( bool disableAllTraffic() ); + SLOT( bool refreshKillSwitch() ); 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 e3f729a0..598c7144 100644 --- a/ipc/ipcserver.cpp +++ b/ipc/ipcserver.cpp @@ -203,3 +203,8 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr) { return KillSwitch::instance()->enablePeerTraffic(configStr); } + +bool IpcServer::refreshKillSwitch() +{ + return KillSwitch::instance()->refresh(); +} diff --git a/ipc/ipcserver.h b/ipc/ipcserver.h index 452534cd..93d827a1 100644 --- a/ipc/ipcserver.h +++ b/ipc/ipcserver.h @@ -39,6 +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 updateResolvers(const QString& ifname, const QList& resolvers) override; private: diff --git a/service/server/killswitch.cpp b/service/server/killswitch.cpp index 89dc0917..261ac789 100644 --- a/service/server/killswitch.cpp +++ b/service/server/killswitch.cpp @@ -43,15 +43,24 @@ bool KillSwitch::init() MacOSFirewall::install(); } #endif - m_appSettigns = QSharedPointer(new SecureQSettings(ORGANIZATION_NAME, APPLICATION_NAME, nullptr)); if (isStrictKillSwitchEnabled()) { return disableAllTraffic(); } return true; } +bool KillSwitch::refresh() +{ + if (isStrictKillSwitchEnabled()) { + return disableAllTraffic(); + } else { + return disableKillSwitch(); + } +} + bool KillSwitch::isStrictKillSwitchEnabled() { + m_appSettigns = QSharedPointer(new SecureQSettings(ORGANIZATION_NAME, APPLICATION_NAME, nullptr)); return m_appSettigns->value("Conf/strictKillSwitchEnabled", false).toBool(); } @@ -98,7 +107,6 @@ bool KillSwitch::disableKillSwitch() { #endif return true; - } bool KillSwitch::disableAllTraffic() { diff --git a/service/server/killswitch.h b/service/server/killswitch.h index d6fc0a0e..4659606d 100644 --- a/service/server/killswitch.h +++ b/service/server/killswitch.h @@ -12,6 +12,7 @@ class KillSwitch : public QObject public: static KillSwitch *instance(); bool init(); + bool refresh(); bool disableKillSwitch(); bool disableAllTraffic(); bool enablePeerTraffic( const QJsonObject &configStr);