NetOrigin.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. // qt
  3. #include <QHostAddress>
  4. #include <QJsonArray>
  5. // utils
  6. #include <utils/Logger.h>
  7. #include <utils/settings.h>
  8. ///
  9. /// @brief Checks the origin ip addresses for access allowed
  10. ///
  11. class NetOrigin : public QObject
  12. {
  13. Q_OBJECT
  14. private:
  15. friend class HyperionDaemon;
  16. NetOrigin(QObject* parent = nullptr, Logger* log = Logger::getInstance("NETWORK"));
  17. public:
  18. ///
  19. /// @brief Check if address is allowed to connect. The local address is the network adapter ip this connection comes from
  20. /// @param address The peer address
  21. /// @param local The local address of the socket (Differs based on NetworkAdapter IP or localhost)
  22. /// @return True when allowed, else false
  23. ///
  24. bool accessAllowed(const QHostAddress& address, const QHostAddress& local) const;
  25. ///
  26. /// @brief Check if address is in subnet of local
  27. /// @return True or false
  28. ///
  29. bool isLocalAddress(const QHostAddress& address, const QHostAddress& local) const;
  30. static NetOrigin *getInstance() { return instance; }
  31. static NetOrigin *instance;
  32. private slots:
  33. ///
  34. /// @brief Handle settings update from SettingsManager
  35. /// @param type settingyType from enum
  36. /// @param config configuration object
  37. ///
  38. void handleSettingsUpdate(settings::type type, const QJsonDocument& config);
  39. private:
  40. Logger* _log;
  41. /// True when internet access is allowed
  42. bool _internetAccessAllowed;
  43. /// Whitelisted ip addresses
  44. QList<QHostAddress> _ipWhitelist;
  45. };