rules: add support for resource excludes
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include "../helpers/FsUtils.hpp"
|
||||
#include "../GlobalState.hpp"
|
||||
|
||||
#include "../debug/log.hpp"
|
||||
|
||||
static CConfig::eConfigIPAction strToAction(const std::string& s) {
|
||||
// TODO: allow any case I'm lazy it's 1am
|
||||
if (s == "ALLOW" || s == "allow" || s == "Allow")
|
||||
@@ -32,6 +34,14 @@ CConfig::CConfig() {
|
||||
parsed.action = strToAction(ic.action);
|
||||
parsed.difficulty = ic.difficulty;
|
||||
|
||||
if (!ic.exclude_regex.empty()) {
|
||||
parsed.exclude_regex = std::make_unique<re2::RE2>(ic.exclude_regex);
|
||||
if (parsed.exclude_regex->error_code() != RE2::NoError) {
|
||||
Debug::log(CRIT, "Regex \"{}\" failed to parse", ic.exclude_regex);
|
||||
throw std::runtime_error("Failed to parse regex");
|
||||
}
|
||||
}
|
||||
|
||||
for (const auto& ir : ic.ip_ranges) {
|
||||
parsed.ip_ranges.emplace_back(CIPRange(ir));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
#include <re2/re2.h>
|
||||
|
||||
#include "IPRange.hpp"
|
||||
|
||||
class CConfig {
|
||||
@@ -18,13 +20,15 @@ class CConfig {
|
||||
struct SIPRangeConfig {
|
||||
std::string action = "";
|
||||
std::vector<std::string> ip_ranges;
|
||||
int difficulty = -1;
|
||||
int difficulty = -1;
|
||||
std::string exclude_regex = "";
|
||||
};
|
||||
|
||||
struct SIPRangeConfigParsed {
|
||||
eConfigIPAction action = IP_ACTION_DENY;
|
||||
std::vector<CIPRange> ip_ranges;
|
||||
int difficulty = -1;
|
||||
eConfigIPAction action = IP_ACTION_DENY;
|
||||
std::vector<CIPRange> ip_ranges;
|
||||
int difficulty = -1;
|
||||
std::unique_ptr<re2::RE2> exclude_regex;
|
||||
};
|
||||
|
||||
struct SConfig {
|
||||
|
||||
Reference in New Issue
Block a user