aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorluigi1111 <luigi1111w@gmail.com>2020-12-19 17:22:01 -0600
committerluigi1111 <luigi1111w@gmail.com>2020-12-19 17:22:01 -0600
commite0d8af253e4933b73255a9d8a4ed82ce044e43f8 (patch)
tree415cb78090eaff67f82f265c949cd461f663073f /src
parentMerge pull request #7075 (diff)
parentdaemon: the ban command can now load IPs from a file (ban @filename) (diff)
downloadmonero-e0d8af253e4933b73255a9d8a4ed82ce044e43f8.tar.xz
Merge pull request #7141
9de3787 daemon: the ban command can now load IPs from a file (ban @filename) (moneromooo-monero)
Diffstat (limited to 'src')
-rw-r--r--src/daemon/command_parser_executor.cpp42
-rw-r--r--src/daemon/command_server.cpp4
2 files changed, 42 insertions, 4 deletions
diff --git a/src/daemon/command_parser_executor.cpp b/src/daemon/command_parser_executor.cpp
index aac891c4a..767ce7bc6 100644
--- a/src/daemon/command_parser_executor.cpp
+++ b/src/daemon/command_parser_executor.cpp
@@ -28,6 +28,7 @@
#include "common/dns_utils.h"
#include "common/command_line.h"
+#include "net/parse.h"
#include "daemon/command_parser_executor.h"
#undef MONERO_DEFAULT_LOG_CATEGORY
@@ -657,7 +658,6 @@ bool t_command_parser_executor::ban(const std::vector<std::string>& args)
std::cout << "Invalid syntax: Expects one or two parameters. For more details, use the help command." << std::endl;
return true;
}
- std::string ip = args[0];
time_t seconds = P2P_IP_BLOCKTIME;
if (args.size() > 1)
{
@@ -676,7 +676,45 @@ bool t_command_parser_executor::ban(const std::vector<std::string>& args)
return true;
}
}
- return m_executor.ban(ip, seconds);
+ if (boost::starts_with(args[0], "@"))
+ {
+ const std::string ban_list = args[0].substr(1);
+
+ try
+ {
+ const boost::filesystem::path ban_list_path(ban_list);
+ boost::system::error_code ec;
+ if (!boost::filesystem::exists(ban_list_path, ec))
+ {
+ std::cout << "Can't find ban list file " + ban_list + " - " + ec.message() << std::endl;
+ return true;
+ }
+
+ bool ret = true;
+ std::ifstream ifs(ban_list_path.string());
+ for (std::string line; std::getline(ifs, line); )
+ {
+ const expect<epee::net_utils::network_address> parsed_addr = net::get_network_address(line, 0);
+ if (!parsed_addr)
+ {
+ std::cout << "Invalid IP address: " << line << " - " << parsed_addr.error() << std::endl;
+ continue;
+ }
+ ret &= m_executor.ban(parsed_addr->host_str(), seconds);
+ }
+ return ret;
+ }
+ catch (const std::exception &e)
+ {
+ std::cout << "Error loading ban list: " << e.what() << std::endl;
+ return false;
+ }
+ }
+ else
+ {
+ const std::string ip = args[0];
+ return m_executor.ban(ip, seconds);
+ }
}
bool t_command_parser_executor::unban(const std::vector<std::string>& args)
diff --git a/src/daemon/command_server.cpp b/src/daemon/command_server.cpp
index dd5f76188..4768bb842 100644
--- a/src/daemon/command_server.cpp
+++ b/src/daemon/command_server.cpp
@@ -234,8 +234,8 @@ t_command_server::t_command_server(
m_command_lookup.set_handler(
"ban"
, std::bind(&t_command_parser_executor::ban, &m_parser, p::_1)
- , "ban <IP> [<seconds>]"
- , "Ban a given <IP> for a given amount of <seconds>."
+ , "ban [<IP>|@<filename>] [<seconds>]"
+ , "Ban a given <IP> or list of IPs from a file for a given amount of <seconds>."
);
m_command_lookup.set_handler(
"unban"