From e20d4e113b78232751a63faf4e59a2665f215d7c Mon Sep 17 00:00:00 2001 From: moneroexamples Date: Sat, 20 Aug 2016 18:08:11 +0800 Subject: [PATCH] does_header_has added to block tor scanner --- main.cpp | 29 +++++++++++++++++++---------- src/page.h | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index dd78022..90dce8b 100644 --- a/main.cpp +++ b/main.cpp @@ -120,22 +120,31 @@ int main(int ac, const char* av[]) { }); CROW_ROUTE(app, "/block/") - ([&](string block_hash) { - return xmrblocks.show_block(block_hash); - }); + ([&](const crow::request& req, string block_hash) { + + // 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);; + } + -// CROW_ROUTE(app, "/tx/") -// ([&](string tx_hash) { -// return xmrblocks.show_tx(tx_hash); -// }); + + return crow::response(xmrblocks.show_block(block_hash)); + }); CROW_ROUTE(app, "/tx/") ([&](const crow::request& req, string tx_hash) { - for (const auto& m : req.headers) - cout << m.first << ": " << m.second << endl; + // 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 ""; + return crow::response(xmrblocks.show_tx(tx_hash)); }); CROW_ROUTE(app, "/tx//") diff --git a/src/page.h b/src/page.h index 0a3b75e..0469c79 100644 --- a/src/page.h +++ b/src/page.h @@ -19,6 +19,7 @@ #include "tools.h" #include "rpccalls.h" #include "mylmdb.h" +#include "../ext/crow/http_request.h" #include #include @@ -58,6 +59,29 @@ namespace xmreg { DEFINE_MEMBER_GETTER(tx_blob, string) + + string + does_header_has(const crow::request& req, + const string& field = "Accept", + const string& value = "q=.2, */*; q=.2") + { + string accept = req.get_header_value(field); + + if (!accept.empty()) + { + if (accept.find(value) != std::string::npos) + { + cout << value << " found" << endl; + + return accept; + } + } + + return string {}; + } + + + /** * @brief The tx_details struct *