etr / libhttpserver

C++ library for creating an embedded Rest HTTP server (and more)
GNU Lesser General Public License v2.1
882 stars 184 forks source link

Banned IP entry into an error log #332

Open RobertFojtikAEN opened 11 months ago

RobertFojtikAEN commented 11 months ago

Is there any issue to write banned IP entry to an error log ?

Something like that:

if ((((static_cast<webserver*>(cls))->default_policy == http_utils::ACCEPT) &&
            ((static_cast<webserver*>(cls))->bans.count(ip_representation(addr))) &&
            (!(static_cast<webserver*>(cls))->allowances.count(ip_representation(addr)))) ||
        (((static_cast<webserver*>(cls))->default_policy == http_utils::REJECT) &&
         ((!(static_cast<webserver*>(cls))->allowances.count(ip_representation(addr))) ||
          ((static_cast<webserver*>(cls))->bans.count(ip_representation(addr)))))) {

    //log banned IP
    std::string msg = "IP '" + httpserver::http::get_ip_str(addr) + "' rejected\n";
    webserver* dws = static_cast<webserver*>(cls);
    dws->log_error(msg);

    return MHD_NO;
}