mirror of
https://github.com/g4klx/DAPNETGateway.git
synced 2026-08-26 12:32:45 -04:00
Add config options for REGEX support. Also add README.REGEX
This commit is contained in:
parent
4c47986da0
commit
08157c342c
6 changed files with 53 additions and 10 deletions
18
Conf.cpp
18
Conf.cpp
|
|
@ -37,6 +37,8 @@ CConf::CConf(const std::string& file) :
|
|||
m_file(file),
|
||||
m_callsign(),
|
||||
m_whiteList(),
|
||||
m_blacklistRegexfile(),
|
||||
m_whitelistRegexfile(),
|
||||
m_rptAddress(),
|
||||
m_rptPort(0U),
|
||||
m_myAddress(),
|
||||
|
|
@ -105,7 +107,11 @@ bool CConf::read()
|
|||
m_whiteList.push_back(ric);
|
||||
p = ::strtok(NULL, ",\r\n");
|
||||
}
|
||||
} else if (::strcmp(key, "RptAddress") == 0)
|
||||
} else if (::strcmp(key,"BlacklistRegexfile") == 0)
|
||||
m_blacklistRegexfile = value;
|
||||
else if (::strcmp(key,"WhitelistRegexfile") == 0)
|
||||
m_whitelistRegexfile = value;
|
||||
else if (::strcmp(key, "RptAddress") == 0)
|
||||
m_rptAddress = value;
|
||||
else if (::strcmp(key, "RptPort") == 0)
|
||||
m_rptPort = (unsigned int)::atoi(value);
|
||||
|
|
@ -155,6 +161,16 @@ std::vector<uint32_t> CConf::getWhiteList() const
|
|||
return m_whiteList;
|
||||
}
|
||||
|
||||
std::string CConf::getblacklistRegexfile() const
|
||||
{
|
||||
return m_blacklistRegexfile;
|
||||
}
|
||||
|
||||
std::string CConf::getwhitelistRegexfile() const
|
||||
{
|
||||
return m_whitelistRegexfile;
|
||||
}
|
||||
|
||||
std::string CConf::getRptAddress() const
|
||||
{
|
||||
return m_rptAddress;
|
||||
|
|
|
|||
4
Conf.h
4
Conf.h
|
|
@ -33,6 +33,8 @@ public:
|
|||
// The General section
|
||||
std::string getCallsign() const;
|
||||
std::vector<unsigned int> getWhiteList() const;
|
||||
std::string getblacklistRegexfile() const;
|
||||
std::string getwhitelistRegexfile() const;
|
||||
std::string getRptAddress() const;
|
||||
unsigned int getRptPort() const;
|
||||
std::string getMyAddress() const;
|
||||
|
|
@ -56,6 +58,8 @@ private:
|
|||
|
||||
std::string m_callsign;
|
||||
std::vector<unsigned int> m_whiteList;
|
||||
std::string m_blacklistRegexfile;
|
||||
std::string m_whitelistRegexfile;
|
||||
std::string m_rptAddress;
|
||||
unsigned int m_rptPort;
|
||||
std::string m_myAddress;
|
||||
|
|
|
|||
|
|
@ -270,11 +270,11 @@ int CDAPNETGateway::run()
|
|||
std::vector<std::regex> regexBlacklist;
|
||||
std::vector<std::regex> regexWhitelist;
|
||||
|
||||
m_regexBlacklist = new CREGEX("/tmp/blregexes.txt");
|
||||
m_regexBlacklist = new CREGEX(m_conf.getblacklistRegexfile());
|
||||
if (m_regexBlacklist->load())
|
||||
regexBlacklist = m_regexBlacklist->get();
|
||||
|
||||
m_regexWhitelist = new CREGEX("/tmp/wlregexes.txt");
|
||||
m_regexWhitelist = new CREGEX(m_conf.getwhitelistRegexfile());
|
||||
if (m_regexWhitelist->load())
|
||||
regexWhitelist = m_regexWhitelist->get();
|
||||
|
||||
|
|
@ -312,8 +312,8 @@ int CDAPNETGateway::run()
|
|||
CPOCSAGMessage* message = m_dapnetNetwork->readMessage();
|
||||
if (message != NULL) {
|
||||
bool found = true;
|
||||
bool blacklistregexmatch = false;
|
||||
bool whitelistregexmatch = true;
|
||||
bool blacklistRegexmatch = false;
|
||||
bool whitelistRegexmatch = true;
|
||||
|
||||
// If we have a white list of RICs, use it.
|
||||
if (!whiteList.empty())
|
||||
|
|
@ -326,25 +326,25 @@ int CDAPNETGateway::run()
|
|||
bool ret = std::regex_match(messageBody,regex);
|
||||
//If the regex matches the message body, don't send the message
|
||||
if (ret) {
|
||||
blacklistregexmatch = true;
|
||||
blacklistRegexmatch = true;
|
||||
LogDebug("Blacklist REGEX match: Not queueing message to %07u, type %u, message: \"%.*s\"", message->m_ric, message->m_type, message->m_length, messageBody.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!regexWhitelist.empty() && !blacklistregexmatch) {
|
||||
if(!regexWhitelist.empty() && !blacklistRegexmatch) {
|
||||
for (std::regex regex : regexWhitelist) {
|
||||
bool ret = std::regex_match(messageBody,regex);
|
||||
//If the regex does not match the message body, don't send the message
|
||||
if (!ret) {
|
||||
whitelistregexmatch = false;
|
||||
whitelistRegexmatch = false;
|
||||
LogDebug("No whitelist REGEX match: Not queueing message to %07u, type %u, message: \"%.*s\"", message->m_ric, message->m_type, message->m_length, messageBody.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (found && !blacklistregexmatch && whitelistregexmatch) {
|
||||
if (found && !blacklistRegexmatch && whitelistRegexmatch) {
|
||||
switch (message->m_functional) {
|
||||
case FUNCTIONAL_ALPHANUMERIC:
|
||||
LogDebug("Queueing message to %07u, type %u, func Alphanumeric: \"%.*s\"", message->m_ric, message->m_type, message->m_length, message->m_message);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
[General]
|
||||
Callsign=g9bf
|
||||
# WhiteList=12345,78901
|
||||
#BlacklistRegexfile=/tmp/blregexes.txt
|
||||
#WhitelistRegexfile=/tmp/wlregexes.txt
|
||||
RptAddress=127.0.0.1
|
||||
RptPort=3800
|
||||
LocalAddress=127.0.0.1
|
||||
|
|
|
|||
21
README.REGEX
Normal file
21
README.REGEX
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The REGEX functionality allows you to whitelist or blacklist messages based on
|
||||
pattern matching the message body itself (not the RIC).
|
||||
|
||||
The options for this are:
|
||||
|
||||
|
||||
WhitelistRegexfile=
|
||||
BlacklistRegexfile=
|
||||
|
||||
REGEXs are placed in the the respective textfile, one per line. These need to
|
||||
be a full match, i.e. they need to match the entire message, begining with ^
|
||||
and ending with $.
|
||||
|
||||
For example:
|
||||
|
||||
^NAGIOS.*$ - matches all Nagios alerts
|
||||
|
||||
^(G|M|2).+$ - Matches messages with the first character as a G.M or 2 - i.e.
|
||||
match all UK callsigns.
|
||||
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ bool CREGEX::load()
|
|||
}
|
||||
|
||||
size_t size = m_regex.size();
|
||||
LogInfo("Loaded %u REGEXes", size);
|
||||
LogInfo("Loaded %u REGEX from file %s", size, regexFile.c_str());
|
||||
|
||||
size = m_regex.size();
|
||||
if (size == 0U)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue