2019-07-12 16:54:26 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// qt
|
|
|
|
#include <QHostAddress>
|
|
|
|
#include <QJsonArray>
|
|
|
|
|
|
|
|
// utils
|
|
|
|
#include <utils/Logger.h>
|
|
|
|
#include <utils/settings.h>
|
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Checks the origin ip addresses for access allowed
|
|
|
|
///
|
|
|
|
class NetOrigin : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
private:
|
|
|
|
friend class HyperionDaemon;
|
2020-11-14 17:58:56 +01:00
|
|
|
NetOrigin(QObject* parent = nullptr, Logger* log = Logger::getInstance("NETWORK"));
|
2019-07-12 16:54:26 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
/// @brief Check if address is allowed to connect. The local address is the network adapter ip this connection comes from
|
|
|
|
/// @param address The peer address
|
|
|
|
/// @param local The local address of the socket (Differs based on NetworkAdapter IP or localhost)
|
|
|
|
/// @return True when allowed, else false
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool accessAllowed(const QHostAddress& address, const QHostAddress& local) const;
|
2019-07-12 16:54:26 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// @brief Check if address is in subnet of local
|
|
|
|
/// @return True or false
|
|
|
|
///
|
2020-08-08 23:12:43 +02:00
|
|
|
bool isLocalAddress(const QHostAddress& address, const QHostAddress& local) const;
|
2019-07-12 16:54:26 +02:00
|
|
|
|
2020-11-14 17:58:56 +01:00
|
|
|
static NetOrigin *getInstance() { return instance; }
|
|
|
|
static NetOrigin *instance;
|
2019-07-12 16:54:26 +02:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
///
|
|
|
|
/// @brief Handle settings update from SettingsManager
|
|
|
|
/// @param type settingyType from enum
|
|
|
|
/// @param config configuration object
|
|
|
|
///
|
2020-08-08 13:09:15 +02:00
|
|
|
void handleSettingsUpdate(settings::type type, const QJsonDocument& config);
|
2019-07-12 16:54:26 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
Logger* _log;
|
|
|
|
/// True when internet access is allowed
|
|
|
|
bool _internetAccessAllowed;
|
|
|
|
/// Whitelisted ip addresses
|
|
|
|
QList<QHostAddress> _ipWhitelist;
|
|
|
|
|
|
|
|
};
|