Use HLM to store strictMode flag

This commit is contained in:
Mykola Baibuz 2025-02-18 22:26:56 +02:00
parent 7a3520cb20
commit 84d95477cb
10 changed files with 24 additions and 12 deletions

View file

@ -457,7 +457,7 @@ void AmneziaApplication::initControllers()
QTimer::singleShot(1000, this, [this]() { m_connectionController->openConnection(); }); QTimer::singleShot(1000, this, [this]() { m_connectionController->openConnection(); });
} }
connect(m_settingsController.get(), &SettingsController::amneziaDnsToggled, m_serversModel.get(), &ServersModel::toggleAmneziaDns); 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_sitesController.reset(new SitesController(m_settings, m_vpnConnection, m_sitesModel));
m_engine->rootContext()->setContextProperty("SitesController", m_sitesController.get()); m_engine->rootContext()->setContextProperty("SitesController", m_sitesController.get());

View file

@ -256,7 +256,7 @@ bool SettingsController::isStrictKillSwitchEnabled()
void SettingsController::toggleStrictKillSwitch(bool enable) void SettingsController::toggleStrictKillSwitch(bool enable)
{ {
m_settings->setStrictKillSwitchEnabled(enable); m_settings->setStrictKillSwitchEnabled(enable);
emit strictKillSwitchEnabledChanged(); emit strictKillSwitchEnabledChanged(enable);
} }
bool SettingsController::isNotificationPermissionGranted() bool SettingsController::isNotificationPermissionGranted()

View file

@ -104,7 +104,7 @@ signals:
void secondaryDnsChanged(); void secondaryDnsChanged();
void loggingStateChanged(); void loggingStateChanged();
void killSwitchEnabledChanged(); void killSwitchEnabledChanged();
void strictKillSwitchEnabledChanged(); void strictKillSwitchEnabledChanged(bool enabled);
void restoreBackupFinished(); void restoreBackupFinished();
void changeSettingsFinished(const QString &finishedMessage); void changeSettingsFinished(const QString &finishedMessage);

View file

@ -52,10 +52,12 @@ void VpnConnection::onBytesChanged(quint64 receivedBytes, quint64 sentBytes)
emit bytesChanged(receivedBytes, sentBytes); emit bytesChanged(receivedBytes, sentBytes);
} }
void VpnConnection::onKillswitchModeChanged() void VpnConnection::onKillSwitchModeChanged(bool enabled)
{ {
#ifdef AMNEZIA_DESKTOP #ifdef AMNEZIA_DESKTOP
IpcClient::Interface()->refreshKillSwitch(); if (IpcClient::Interface()) {
IpcClient::Interface()->refreshKillSwitch(enabled);
}
#endif #endif
} }

View file

@ -55,7 +55,7 @@ public slots:
void addRoutes(const QStringList &ips); void addRoutes(const QStringList &ips);
void deleteRoutes(const QStringList &ips); void deleteRoutes(const QStringList &ips);
void flushDns(); void flushDns();
void onKillswitchModeChanged(); void onKillSwitchModeChanged(bool enabled);
signals: signals:
void bytesChanged(quint64 receivedBytes, quint64 sentBytes); void bytesChanged(quint64 receivedBytes, quint64 sentBytes);

View file

@ -30,7 +30,7 @@ class IpcInterface
SLOT( bool disableKillSwitch() ); SLOT( bool disableKillSwitch() );
SLOT( bool disableAllTraffic() ); SLOT( bool disableAllTraffic() );
SLOT( bool refreshKillSwitch() ); SLOT( bool refreshKillSwitch( bool enabled ) );
SLOT( bool allowTrafficTo( const QStringList ranges ) ); SLOT( bool allowTrafficTo( const QStringList ranges ) );
SLOT( bool enablePeerTraffic( const QJsonObject &configStr) ); SLOT( bool enablePeerTraffic( const QJsonObject &configStr) );
SLOT( bool enableKillSwitch( const QJsonObject &excludeAddr, int vpnAdapterIndex) ); SLOT( bool enableKillSwitch( const QJsonObject &excludeAddr, int vpnAdapterIndex) );

View file

@ -204,7 +204,7 @@ bool IpcServer::enablePeerTraffic(const QJsonObject &configStr)
return KillSwitch::instance()->enablePeerTraffic(configStr); return KillSwitch::instance()->enablePeerTraffic(configStr);
} }
bool IpcServer::refreshKillSwitch() bool IpcServer::refreshKillSwitch(bool enabled)
{ {
return KillSwitch::instance()->refresh(); return KillSwitch::instance()->refresh(enabled);
} }

View file

@ -39,7 +39,7 @@ public:
virtual bool enablePeerTraffic(const QJsonObject &configStr) override; virtual bool enablePeerTraffic(const QJsonObject &configStr) override;
virtual bool enableKillSwitch(const QJsonObject &excludeAddr, int vpnAdapterIndex) override; virtual bool enableKillSwitch(const QJsonObject &excludeAddr, int vpnAdapterIndex) override;
virtual bool disableKillSwitch() override; virtual bool disableKillSwitch() override;
virtual bool refreshKillSwitch() override; virtual bool refreshKillSwitch( bool enabled ) override;
virtual bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) override; virtual bool updateResolvers(const QString& ifname, const QList<QHostAddress>& resolvers) override;
private: private:

View file

@ -49,8 +49,13 @@ bool KillSwitch::init()
return true; 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()) { if (isStrictKillSwitchEnabled()) {
return disableAllTraffic(); return disableAllTraffic();
} else { } else {
@ -60,6 +65,11 @@ bool KillSwitch::refresh()
bool KillSwitch::isStrictKillSwitchEnabled() 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<SecureQSettings>(new SecureQSettings(ORGANIZATION_NAME, APPLICATION_NAME, nullptr)); m_appSettigns = QSharedPointer<SecureQSettings>(new SecureQSettings(ORGANIZATION_NAME, APPLICATION_NAME, nullptr));
return m_appSettigns->value("Conf/strictKillSwitchEnabled", false).toBool(); return m_appSettigns->value("Conf/strictKillSwitchEnabled", false).toBool();
} }

View file

@ -12,7 +12,7 @@ class KillSwitch : public QObject
public: public:
static KillSwitch *instance(); static KillSwitch *instance();
bool init(); bool init();
bool refresh(); bool refresh(bool enabled);
bool disableKillSwitch(); bool disableKillSwitch();
bool disableAllTraffic(); bool disableAllTraffic();
bool enablePeerTraffic( const QJsonObject &configStr); bool enablePeerTraffic( const QJsonObject &configStr);