diff options
| author | 2024-11-01 14:35:23 +0000 | |
|---|---|---|
| committer | 2024-11-01 15:53:04 +0000 | |
| commit | 8a3aba4044ee10df332631c4c66ed60299566e58 (patch) | |
| tree | afb185a313dff83d61c26e3b95f47b62d3ab5694 /modules/dnsbl.cpp | |
| parent | Default <options:extbanformat> to name. (diff) | |
| parent | Use fmtlib instead of iostream in ConvToStr where available. (diff) | |
Merge branch 'insp4' into master.
Diffstat (limited to 'modules/dnsbl.cpp')
| -rw-r--r-- | modules/dnsbl.cpp | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/modules/dnsbl.cpp b/modules/dnsbl.cpp index 3058dbd41..67bdc46a9 100644 --- a/modules/dnsbl.cpp +++ b/modules/dnsbl.cpp @@ -96,6 +96,9 @@ public: // A range of DNSBL result types to match against. CharState records; + // A map of DNSBL replies to their descriptions. + insp::flat_map<uint32_t, std::string> replies; + // The message to send to users who's IP address is in a DNSBL. std::string reason; @@ -365,12 +368,16 @@ public: if (match) { + const auto it = config->replies.find(result); + const auto reasonstr = it == config->replies.end() ? FMT::format("Result {}", result) : it->second; + const std::string reason = Template::Replace(config->reason, { { "dnsbl", config->name }, { "dnsbl.url", Percent::Encode(config->name) }, { "ip", them->GetAddress() }, { "network", ServerInstance->Config->Network }, { "network.url", Percent::Encode(ServerInstance->Config->Network) }, + { "reason", reasonstr }, { "result", ConvToStr(result) }, }); @@ -421,9 +428,9 @@ public: } } - ServerInstance->SNO.WriteGlobalSno('d', "{} {} ({}) detected as being on the '{}' DNSBL with result {}{}", + ServerInstance->SNO.WriteGlobalSno('d', "{} {} ({}) detected as being on the '{}' DNSBL: {}{}", them->IsFullyConnected() ? "User" : "Connecting user", them->GetRealMask(), them->GetAddress(), - config->name, result, them->exempt ? " -- exempt" : ""); + config->name, reasonstr, them->exempt ? " -- exempt" : ""); } else config->stats_misses++; @@ -594,6 +601,30 @@ public: auto entry = std::make_shared<DNSBLEntry>(this, tag); newdnsbls.push_back(entry); } + for (const auto& [_, tag] : ServerInstance->Config->ConfTags("dnsblreply")) + { + const auto dnsblname = tag->getString("name"); + auto dnsbl = std::find_if(newdnsbls.begin(), newdnsbls.end(), [&dnsblname](const auto& d) + { + return insp::equalsci(d->name, dnsblname); + }); + if (dnsbl == newdnsbls.end()) + throw ModuleException(this, "<dnsblreply:name> must be set to the name of a DNSBL at " + tag->source.str()); + + const auto dnsbldesc = tag->getString("description"); + if (dnsbldesc.empty()) + throw ModuleException(this, "<dnsblreply:description> must not be empty at " + tag->source.str()); + + const auto dnsblreply = tag->getNum<uint32_t>("reply", std::numeric_limits<uint32_t>::max()); + if (dnsblreply > 16'777'215) + { + throw ModuleException(this, FMT::format("<dnsblreply:reply> ({}) is not a valid DNSBL reply at {}", + dnsblreply, tag->source.str())); + } + + (*dnsbl)->replies[dnsblreply] = dnsbldesc; + } + data.dnsbls.swap(newdnsbls); } |
