Add DBus network checker for Linux
This commit is contained in:
parent
e730521576
commit
319043818a
12 changed files with 65 additions and 11 deletions
|
@ -51,7 +51,7 @@ NetworkWatcher::NetworkWatcher() { MZ_COUNT_CTOR(NetworkWatcher); }
|
||||||
NetworkWatcher::~NetworkWatcher() { MZ_COUNT_DTOR(NetworkWatcher); }
|
NetworkWatcher::~NetworkWatcher() { MZ_COUNT_DTOR(NetworkWatcher); }
|
||||||
|
|
||||||
void NetworkWatcher::initialize() {
|
void NetworkWatcher::initialize() {
|
||||||
logger.debug() << "Initialize";
|
logger.debug() << "Initialize NetworkWatcher";
|
||||||
|
|
||||||
#if defined(MZ_WINDOWS)
|
#if defined(MZ_WINDOWS)
|
||||||
m_impl = new WindowsNetworkWatcher(this);
|
m_impl = new WindowsNetworkWatcher(this);
|
||||||
|
@ -73,6 +73,8 @@ void NetworkWatcher::initialize() {
|
||||||
&NetworkWatcher::unsecuredNetwork);
|
&NetworkWatcher::unsecuredNetwork);
|
||||||
connect(m_impl, &NetworkWatcherImpl::networkChanged, this,
|
connect(m_impl, &NetworkWatcherImpl::networkChanged, this,
|
||||||
&NetworkWatcher::networkChange);
|
&NetworkWatcher::networkChange);
|
||||||
|
connect(m_impl, &NetworkWatcherImpl::sleepMode, this,
|
||||||
|
&NetworkWatcher::sleepMode);
|
||||||
|
|
||||||
m_impl->initialize();
|
m_impl->initialize();
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void networkChange();
|
void networkChange();
|
||||||
|
void sleepMode();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void settingsChanged();
|
void settingsChanged();
|
||||||
|
|
|
@ -41,6 +41,8 @@ signals:
|
||||||
// TODO: Only windows-networkwatcher has this, the other plattforms should
|
// TODO: Only windows-networkwatcher has this, the other plattforms should
|
||||||
// too.
|
// too.
|
||||||
void networkChanged(QString newBSSID);
|
void networkChanged(QString newBSSID);
|
||||||
|
void sleepMode();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_active = false;
|
bool m_active = false;
|
||||||
|
|
|
@ -41,6 +41,9 @@ void LinuxNetworkWatcher::initialize() {
|
||||||
connect(m_worker, &LinuxNetworkWatcherWorker::unsecuredNetwork, this,
|
connect(m_worker, &LinuxNetworkWatcherWorker::unsecuredNetwork, this,
|
||||||
&LinuxNetworkWatcher::unsecuredNetwork);
|
&LinuxNetworkWatcher::unsecuredNetwork);
|
||||||
|
|
||||||
|
connect(m_worker, &LinuxNetworkWatcherWorker::sleepMode, this,
|
||||||
|
&NetworkWatcherImpl::sleepMode);
|
||||||
|
|
||||||
// Let's wait a few seconds to allow the UI to be fully loaded and shown.
|
// Let's wait a few seconds to allow the UI to be fully loaded and shown.
|
||||||
// This is not strictly needed, but it's better for user experience because
|
// This is not strictly needed, but it's better for user experience because
|
||||||
// it makes the UI faster to appear, plus it gives a bit of delay between the
|
// it makes the UI faster to appear, plus it gives a bit of delay between the
|
||||||
|
|
|
@ -33,7 +33,21 @@
|
||||||
#define NM_802_11_AP_SEC_WEAK_CRYPTO \
|
#define NM_802_11_AP_SEC_WEAK_CRYPTO \
|
||||||
(NM_802_11_AP_SEC_PAIR_WEP40 | NM_802_11_AP_SEC_PAIR_WEP104)
|
(NM_802_11_AP_SEC_PAIR_WEP40 | NM_802_11_AP_SEC_PAIR_WEP104)
|
||||||
|
|
||||||
|
|
||||||
|
enum NMState {
|
||||||
|
NM_STATE_UNKNOWN = 0,
|
||||||
|
NM_STATE_ASLEEP = 10,
|
||||||
|
NM_STATE_DISCONNECTED = 20,
|
||||||
|
NM_STATE_DISCONNECTING = 30,
|
||||||
|
NM_STATE_CONNECTING = 40,
|
||||||
|
NM_STATE_CONNECTED_LOCAL = 50,
|
||||||
|
NM_STATE_CONNECTED_SITE = 60,
|
||||||
|
NM_STATE_CONNECTED_GLOBAL = 70
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
constexpr const char* DBUS_NETWORKMANAGER = "org.freedesktop.NetworkManager";
|
constexpr const char* DBUS_NETWORKMANAGER = "org.freedesktop.NetworkManager";
|
||||||
|
constexpr const char* DBUS_NETWORKMANAGER_PATH = "/org/freedesktop/NetworkManager";
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
Logger logger("LinuxNetworkWatcherWorker");
|
Logger logger("LinuxNetworkWatcherWorker");
|
||||||
|
@ -73,7 +87,7 @@ void LinuxNetworkWatcherWorker::initialize() {
|
||||||
// documentation:
|
// documentation:
|
||||||
// https://developer.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.html
|
// https://developer.gnome.org/NetworkManager/stable/gdbus-org.freedesktop.NetworkManager.html
|
||||||
|
|
||||||
QDBusInterface nm(DBUS_NETWORKMANAGER, "/org/freedesktop/NetworkManager",
|
QDBusInterface nm(DBUS_NETWORKMANAGER, DBUS_NETWORKMANAGER_PATH,
|
||||||
DBUS_NETWORKMANAGER, QDBusConnection::systemBus());
|
DBUS_NETWORKMANAGER, QDBusConnection::systemBus());
|
||||||
if (!nm.isValid()) {
|
if (!nm.isValid()) {
|
||||||
logger.error()
|
logger.error()
|
||||||
|
@ -108,6 +122,12 @@ void LinuxNetworkWatcherWorker::initialize() {
|
||||||
SLOT(propertyChanged(QString, QVariantMap, QStringList)));
|
SLOT(propertyChanged(QString, QVariantMap, QStringList)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDBusConnection::systemBus().connect(DBUS_NETWORKMANAGER,
|
||||||
|
DBUS_NETWORKMANAGER_PATH,
|
||||||
|
DBUS_NETWORKMANAGER,
|
||||||
|
"StateChanged",
|
||||||
|
this, SLOT(NMStateChanged(quint32)));
|
||||||
|
|
||||||
if (m_devicePaths.isEmpty()) {
|
if (m_devicePaths.isEmpty()) {
|
||||||
logger.warning() << "No wifi devices found";
|
logger.warning() << "No wifi devices found";
|
||||||
return;
|
return;
|
||||||
|
@ -173,5 +193,16 @@ void LinuxNetworkWatcherWorker::checkDevices() {
|
||||||
emit unsecuredNetwork(ssid, bssid);
|
emit unsecuredNetwork(ssid, bssid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LinuxNetworkWatcherWorker::NMStateChanged(quint32 state)
|
||||||
|
{
|
||||||
|
if (state == NM_STATE_ASLEEP) {
|
||||||
|
emit sleepMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug() << "NMStateChanged " << state;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ class LinuxNetworkWatcherWorker final : public QObject {
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void unsecuredNetwork(const QString& networkName, const QString& networkId);
|
void unsecuredNetwork(const QString& networkName, const QString& networkId);
|
||||||
|
void sleepMode();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void initialize();
|
void initialize();
|
||||||
|
@ -30,6 +31,7 @@ class LinuxNetworkWatcherWorker final : public QObject {
|
||||||
private slots:
|
private slots:
|
||||||
void propertyChanged(QString interface, QVariantMap properties,
|
void propertyChanged(QString interface, QVariantMap properties,
|
||||||
QStringList list);
|
QStringList list);
|
||||||
|
void NMStateChanged(quint32 state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// We collect the list of DBus wifi network device paths during the
|
// We collect the list of DBus wifi network device paths during the
|
||||||
|
|
|
@ -286,6 +286,12 @@ void VpnConnection::connectToVpn(int serverIndex, const ServerCredentials &crede
|
||||||
emit connectionStateChanged(Vpn::ConnectionState::Error);
|
emit connectionStateChanged(Vpn::ConnectionState::Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VpnConnection::restartConnection()
|
||||||
|
{
|
||||||
|
this->disconnectFromVpn();
|
||||||
|
this->connectToVpn(m_serverIndex, m_serverCredentials, m_dockerContainer, m_vpnConfiguration);
|
||||||
|
}
|
||||||
|
|
||||||
void VpnConnection::createProtocolConnections()
|
void VpnConnection::createProtocolConnections()
|
||||||
{
|
{
|
||||||
connect(m_vpnProtocol.data(), &VpnProtocol::protocolError, this, &VpnConnection::vpnProtocolError);
|
connect(m_vpnProtocol.data(), &VpnProtocol::protocolError, this, &VpnConnection::vpnProtocolError);
|
||||||
|
@ -299,8 +305,12 @@ void VpnConnection::createProtocolConnections()
|
||||||
qDebug() << "Connection Lose";
|
qDebug() << "Connection Lose";
|
||||||
auto result = IpcClient::Interface()->stopNetworkCheck();
|
auto result = IpcClient::Interface()->stopNetworkCheck();
|
||||||
result.waitForFinished(3000);
|
result.waitForFinished(3000);
|
||||||
this->disconnectFromVpn();
|
this->restartConnection();
|
||||||
this->connectToVpn(m_serverIndex, m_serverCredentials, m_dockerContainer, m_vpnConfiguration);
|
});
|
||||||
|
connect(IpcClient::Interface().data(), &IpcInterfaceReplica::networkChange,
|
||||||
|
this, [this]() {
|
||||||
|
qDebug() << "Network change";
|
||||||
|
this->restartConnection();
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ public slots:
|
||||||
const ServerCredentials &credentials, DockerContainer container, const QJsonObject &vpnConfiguration);
|
const ServerCredentials &credentials, DockerContainer container, const QJsonObject &vpnConfiguration);
|
||||||
|
|
||||||
void disconnectFromVpn();
|
void disconnectFromVpn();
|
||||||
|
void restartConnection();
|
||||||
|
|
||||||
|
|
||||||
void addRoutes(const QStringList &ips);
|
void addRoutes(const QStringList &ips);
|
||||||
|
|
|
@ -36,5 +36,6 @@ class IpcInterface
|
||||||
SLOT( bool stopNetworkCheck() );
|
SLOT( bool stopNetworkCheck() );
|
||||||
|
|
||||||
SIGNAL( connectionLose() );
|
SIGNAL( connectionLose() );
|
||||||
|
SIGNAL( networkChange() );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -42,9 +42,6 @@ public:
|
||||||
virtual bool startNetworkCheck(const QString& serverIpv4Gateway, const QString& deviceIpv4Address) override;
|
virtual bool startNetworkCheck(const QString& serverIpv4Gateway, const QString& deviceIpv4Address) override;
|
||||||
virtual bool stopNetworkCheck() override;
|
virtual bool stopNetworkCheck() override;
|
||||||
|
|
||||||
signals:
|
|
||||||
void ConnectionLose();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_localpid = 0;
|
int m_localpid = 0;
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,7 @@
|
||||||
|
|
||||||
#include "ipc.h"
|
#include "ipc.h"
|
||||||
#include "localserver.h"
|
#include "localserver.h"
|
||||||
#include "utilities.h"
|
|
||||||
|
|
||||||
#include "router.h"
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
|
@ -47,6 +45,10 @@ LocalServer::LocalServer(QObject *parent) : QObject(parent),
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_networkWatcher.initialize();
|
||||||
|
|
||||||
|
connect(&m_networkWatcher, &NetworkWatcher::sleepMode, &m_ipcServer, &IpcServer::networkChange);
|
||||||
|
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
// Signal handling for a proper shutdown.
|
// Signal handling for a proper shutdown.
|
||||||
QObject::connect(qApp, &QCoreApplication::aboutToQuit,
|
QObject::connect(qApp, &QCoreApplication::aboutToQuit,
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "ipcserver.h"
|
#include "ipcserver.h"
|
||||||
|
|
||||||
#include "../../client/daemon/daemonlocalserver.h"
|
#include "../../client/daemon/daemonlocalserver.h"
|
||||||
|
#include "../../client/mozilla/networkwatcher.h"
|
||||||
|
|
||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include "windows/daemon/windowsdaemon.h"
|
#include "windows/daemon/windowsdaemon.h"
|
||||||
|
@ -41,6 +41,8 @@ public:
|
||||||
IpcProcessTun2Socks m_tun2socks;
|
IpcProcessTun2Socks m_tun2socks;
|
||||||
QRemoteObjectHost m_serverNode;
|
QRemoteObjectHost m_serverNode;
|
||||||
bool m_isRemotingEnabled = false;
|
bool m_isRemotingEnabled = false;
|
||||||
|
|
||||||
|
NetworkWatcher m_networkWatcher;
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
DaemonLocalServer server{qApp};
|
DaemonLocalServer server{qApp};
|
||||||
LinuxDaemon daemon;
|
LinuxDaemon daemon;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue