Add a line to remove the rule first, in case it already existed

This commit is contained in:
sigonasr2 2025-04-22 14:09:01 -05:00
parent 629894c29c
commit 161ea0eaf4

View File

@ -68,6 +68,7 @@ int main(){
user.totalHits++; user.totalHits++;
if(user.totalHits>tooFrequentAccess){ if(user.totalHits>tooFrequentAccess){
ipBanList.insert(ipAddr); ipBanList.insert(ipAddr);
std::system(std::format("iptables -D INPUT -s {} -j DROP",ipAddr).c_str()); //In case the rule already existed, we are going to remove it first... No effect if it does not exist.
std::system(std::format("iptables -I INPUT 1 -s {} -j DROP",ipAddr).c_str()); std::system(std::format("iptables -I INPUT 1 -s {} -j DROP",ipAddr).c_str());
std::cout<<std::format("New offender {} detected and added to banlist!",ipAddr)<<std::endl; std::cout<<std::format("New offender {} detected and added to banlist!",ipAddr)<<std::endl;
} }