From 4a856bc6f2b4a2c9b651ae612dee504e5acc53f2 Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sat, 20 Aug 2016 18:13:52 +0800 Subject: [PATCH] does_header_has added to block tor scanner --- main.cpp | 14 ++++++++++---- src/page.h | 10 ++++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index 90dce8b..51eb0e0 100644 --- a/main.cpp +++ b/main.cpp @@ -115,8 +115,16 @@ int main(int ac, const char* av[]) { }); CROW_ROUTE(app, "/block/") - ([&](size_t block_height) { - return xmrblocks.show_block(block_height); + ([&](const crow::request& req, size_t block_height) { + + // there is some robot scanning everything + // on the explorer. I block it with this + if (!xmreg::does_header_has(req, "Accept", "q=.2, */*; q=.2").empty()) + { + return crow::response(400); + } + + return crow::response(xmrblocks.show_block(block_height)); }); CROW_ROUTE(app, "/block/") @@ -129,8 +137,6 @@ int main(int ac, const char* av[]) { return crow::response(400);; } - - return crow::response(xmrblocks.show_block(block_hash)); }); diff --git a/src/page.h b/src/page.h index 0469c79..3e602e8 100644 --- a/src/page.h +++ b/src/page.h @@ -60,6 +60,14 @@ namespace xmreg { + /** + * Check if a given header filed contains value string + * + * @param req + * @param field + * @param value + * @return string + */ string does_header_has(const crow::request& req, const string& field = "Accept", @@ -71,8 +79,6 @@ namespace xmreg { { if (accept.find(value) != std::string::npos) { - cout << value << " found" << endl; - return accept; } }