Fix update_db() calls

dev v0.6
marcelb 8 months ago
parent 02689b498d
commit 68e509b385
  1. 2
      .vscode/tasks.json
  2. 12
      src/ipban.cpp
  3. BIN
      test/test
  4. 21
      test/test.cpp

@ -9,7 +9,7 @@
"-g",
"${fileDirname}/test.cpp",
"${fileDirname}/../src/*.cpp",
"${fileDirname}/../exec/src/*.cpp",
"${fileDirname}/../../exec/src/*.cpp",
"-o",
"${fileDirname}/test.o"
],

@ -32,14 +32,6 @@ marcelb::ipban::ipban(const uint& _duration, const uint& _fail_interval, const u
marcelb::ipban::~ipban() {
run_unban_bot = false;
unban_bot.get();
/**
* ako aplikaciju sruši napadač - želimo da ostane banovan - unbanovat će se po isteku intervala
*/
// for (uint i=0; i<banned.size(); i++) {
// unban(banned.begin() + i);
// }
}
void marcelb::ipban::load_db() {
@ -78,7 +70,7 @@ bool marcelb::ipban::ban(const string& ip) {
status = ufw_ban(ip);
io.lock();
banned.push_back({ip, time(NULL)});
status = status && update_db();
status &= update_db();
io.unlock();
}
return status;
@ -88,7 +80,7 @@ bool marcelb::ipban::unban(vector<_ban>::iterator ban_itr) {
bool status = ufw_unban(ban_itr->ip);
io.lock();
banned.erase(ban_itr);
status = status && update_db();
status &= update_db();
io.unlock();
return status;
}

Binary file not shown.

@ -33,24 +33,23 @@ int main() {
// i++;
// }
myban.add_white_list("192.168.2.74");
// myban.add_white_list("192.168.2.74");
cout << myban.ban("192.168.2.74") << endl;
sleep(2);
cout << myban.ban("192.168.2.75") << endl;
sleep(200);
// cout << myban.ban("192.168.2.74") << endl;
// sleep(2);
// cout << myban.ban("192.168.2.75") << endl;
// // sleep(200);
// myban.fail("192.168.2.74");
// sleep(120);
// sleep(5);
// myban.unfail("192.168.2.74");
// // myban.unfail("192.168.2.74");
// sleep(2);
// myban.fail("192.168.2.74");
// sleep(120);
// sleep(5);
// myban.fail("192.168.2.74");
sleep(100);
return 0;
}
Loading…
Cancel
Save