does_header_has added to block tor scanner

This commit is contained in:
moneroexamples 2016-08-20 18:08:11 +08:00
parent ca4a06fa2e
commit e20d4e113b
2 changed files with 43 additions and 10 deletions

View File

@ -120,22 +120,31 @@ int main(int ac, const char* av[]) {
});
CROW_ROUTE(app, "/block/<string>")
([&](string block_hash) {
return xmrblocks.show_block(block_hash);
});
([&](const crow::request& req, string block_hash) {
// CROW_ROUTE(app, "/tx/<string>")
// ([&](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/<string>")
([&](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/<string>/<uint>")

View File

@ -19,6 +19,7 @@
#include "tools.h"
#include "rpccalls.h"
#include "mylmdb.h"
#include "../ext/crow/http_request.h"
#include <algorithm>
#include <limits>
@ -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
*