does_header_has added to block tor scanner

master
moneroexamples 8 years ago
parent ca4a06fa2e
commit e20d4e113b

@ -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) {
// 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>")
// ([&](string tx_hash) {
// return xmrblocks.show_tx(tx_hash);
// });
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>")

@ -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
*

Loading…
Cancel
Save