Refresh killswitch mode when it toggled

This commit is contained in:
Mykola Baibuz 2025-02-17 22:43:38 +02:00
parent 1fa96a09a0
commit 7a3520cb20
8 changed files with 28 additions and 4 deletions

View file

@ -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());

View file

@ -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)
{

View file

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

View file

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

View file

@ -203,3 +203,8 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr)
{
return KillSwitch::instance()->enablePeerTraffic(configStr);
}
bool IpcServer::refreshKillSwitch()
{
return KillSwitch::instance()->refresh();
}

View file

@ -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<QHostAddress>& resolvers) override;
private:

View file

@ -43,15 +43,24 @@ bool KillSwitch::init()
MacOSFirewall::install();
}
#endif
m_appSettigns = QSharedPointer<SecureQSettings>(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<SecureQSettings>(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() {

View file

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