does_header_has added to block tor scanner
This commit is contained in:
parent
ca4a06fa2e
commit
e20d4e113b
29
main.cpp
29
main.cpp
|
@ -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>")
|
||||
|
|
24
src/page.h
24
src/page.h
|
@ -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…
Reference in New Issue