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) { -// CROW_ROUTE(app, "/tx/") -// ([&](string tx_hash) { -// return xmrblocks.show_tx(tx_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);; + } + + + + 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 *