49 lines
1.3 KiB
C++
49 lines
1.3 KiB
C++
#pragma once
|
|
#include "bsc/model/Connection.hpp"
|
|
#include <map>
|
|
#include <optional>
|
|
#include <regex>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
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<Operator> 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<Rule>& rules() const noexcept { return rules_; }
|
|
[[nodiscard]] std::optional<Rule> find_match(const bsc::model::Connection& conn) const;
|
|
private:
|
|
std::vector<Rule> rules_;
|
|
std::map<std::string, std::vector<std::string>> aliases_;
|
|
};
|
|
|
|
} // namespace bsc::rule
|