#pragma once #include "bsc/model/Connection.hpp" #include #include #include #include #include namespace bsc::rule { enum class OperatorType { Simple, Regexp, Network, Range, List, Lists, Unknown }; struct Operator { OperatorType type{OperatorType::Unknown}; std::string operand; std::string data; bool sensitive{false}; std::vector list; [[nodiscard]] bool matches(const bsc::model::Connection& conn) const; }; struct Rule { std::int64_t created{0}; std::string name; std::string description; bool enabled{true}; bool precedence{false}; bool nolog{false}; std::string action{"allow"}; std::string duration{"once"}; Operator op; [[nodiscard]] bool matches(const bsc::model::Connection& conn) const; }; class Loader { public: void load_aliases(const std::string& path); void load_directory(const std::string& dir); bool save_rule(const Rule& rule, const std::string& dir) const; [[nodiscard]] const std::vector& rules() const noexcept { return rules_; } [[nodiscard]] std::optional find_match(const bsc::model::Connection& conn) const; private: std::vector rules_; std::map> aliases_; }; } // namespace bsc::rule