From 15a08227e67d5a6d96ac491cdf2b166ea6885c49 Mon Sep 17 00:00:00 2001 From: Dario Date: Thu, 27 Feb 2020 14:59:25 +0100 Subject: [PATCH] adding second elopage webhook --- src/cpp/Crypto/KeyPair.cpp | 3 +- src/cpp/HTTPInterface/ElopageWebhook.cpp | 6 +- src/cpp/HTTPInterface/ElopageWebhookLight.cpp | 63 +++++++++++++++++++ src/cpp/HTTPInterface/ElopageWebhookLight.h | 16 +++++ .../PageRequestHandlerFactory.cpp | 8 +++ 5 files changed, 92 insertions(+), 4 deletions(-) create mode 100644 src/cpp/HTTPInterface/ElopageWebhookLight.cpp create mode 100644 src/cpp/HTTPInterface/ElopageWebhookLight.h diff --git a/src/cpp/Crypto/KeyPair.cpp b/src/cpp/Crypto/KeyPair.cpp index 00d2648b1..21a1739d2 100644 --- a/src/cpp/Crypto/KeyPair.cpp +++ b/src/cpp/Crypto/KeyPair.cpp @@ -93,8 +93,7 @@ bool KeyPair::generateFromPassphrase(const char* passphrase, const Mnemonic* wor sha512_final(&state, hash); //crypto_auth_hmacsha512_final(&state, hash); - - + /* // debug passphrase printf("\passsphrase: <%s>\n", passphrase); printf("size word indices: %u\n", word_indices->size()); diff --git a/src/cpp/HTTPInterface/ElopageWebhook.cpp b/src/cpp/HTTPInterface/ElopageWebhook.cpp index 3f1b65fd9..9017ac6a5 100644 --- a/src/cpp/HTTPInterface/ElopageWebhook.cpp +++ b/src/cpp/HTTPInterface/ElopageWebhook.cpp @@ -109,7 +109,7 @@ void ElopageWebhook::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: // write stream result also to file static Poco::Mutex mutex; - + Profiler timeUsed; mutex.lock(); Poco::FileOutputStream file("elopage_webhook_requests.txt", std::ios::out | std::ios::app); @@ -129,8 +129,10 @@ void ElopageWebhook::handleRequest(Poco::Net::HTTPServerRequest& request, Poco:: file << completeRequest << std::endl; file << std::endl; file.close(); + std::string timeUsedStr = timeUsed.string(); + printf("[%s] time for elopage request write to file and maybe wait on lock: %s\n", dateTimeStr.data(), timeUsedStr.data()); mutex.unlock(); - + UniLib::controller::TaskPtr handleElopageTask(new HandleElopageRequestTask(elopageRequestData)); handleElopageTask->scheduleTask(handleElopageTask); diff --git a/src/cpp/HTTPInterface/ElopageWebhookLight.cpp b/src/cpp/HTTPInterface/ElopageWebhookLight.cpp new file mode 100644 index 000000000..99bbfc46d --- /dev/null +++ b/src/cpp/HTTPInterface/ElopageWebhookLight.cpp @@ -0,0 +1,63 @@ +#include "ElopageWebhookLight.h" +#include "Poco/Net/HTTPServerRequest.h" +#include "Poco/Net/HTTPServerResponse.h" +#include "Poco/URI.h" +#include "Poco/Logger.h" +#include "Poco/Data/Binding.h" +#include "Poco/FileStream.h" + + + + +void ElopageWebhookLight::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response) +{ + // simply write request to file for later lookup + //ServerConfig::writeToFile(request.stream(), "elopage_webhook_requests.txt"); + + // empty response, we didn't need to set anything + //response.setStatus(Poco::Net::HTTPResponse::HTTP_NO_CONTENT); + std::ostream& _responseStream = response.send(); + _responseStream << "200 OK"; + + std::istream& stream = request.stream(); + std::string completeRequest; + Poco::Net::NameValueCollection elopageRequestData; + int breakCount = 100; + while (stream.good() && breakCount > 0) { + // char dummy; + std::string line; + std::getline(stream, line); + completeRequest += line; + + stream.good(); + breakCount--; + } + + // write stream result also to file + static Poco::Mutex mutex; + Profiler timeUsed; + mutex.lock(); + + Poco::FileOutputStream file("elopage_webhook_requests_2.txt", std::ios::out | std::ios::app); + + if (!file.good()) { + Poco::Logger& logging(Poco::Logger::get("errorLog")); + logging.error("[ElopageWebhookLight::handleRequest] error creating file with name: elopage_webhook_requests_2.txt"); + //printf("[ElopageWebhook::handleRequest] error creating file with name: elopage_webhook_requests.txt\n"); + mutex.unlock(); + return; + } + + Poco::LocalDateTime now; + + std::string dateTimeStr = Poco::DateTimeFormatter::format(now, Poco::DateTimeFormat::ISO8601_FORMAT); + file << dateTimeStr << std::endl; + file << completeRequest << std::endl; + file << std::endl; + file.close(); + std::string timeUsedStr = timeUsed.string(); + printf("[%s] time for elopage request light write to file and maybe wait on lock: %s\n", dateTimeStr.data(), timeUsedStr.data()); + mutex.unlock(); + +} + diff --git a/src/cpp/HTTPInterface/ElopageWebhookLight.h b/src/cpp/HTTPInterface/ElopageWebhookLight.h new file mode 100644 index 000000000..df6aee097 --- /dev/null +++ b/src/cpp/HTTPInterface/ElopageWebhookLight.h @@ -0,0 +1,16 @@ +#ifndef Elopage_Webhook_LIGHT_INCLUDED +#define Elopage_Webhook_LIGHT_INCLUDED + + +#include "PageRequestMessagedHandler.h" + + +class ElopageWebhookLight : public PageRequestMessagedHandler +{ +public: + void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response); +}; + + + +#endif // Elopage_Webhook_LIGHT_INCLUDED diff --git a/src/cpp/HTTPInterface/PageRequestHandlerFactory.cpp b/src/cpp/HTTPInterface/PageRequestHandlerFactory.cpp index 92d58c666..cfff35012 100644 --- a/src/cpp/HTTPInterface/PageRequestHandlerFactory.cpp +++ b/src/cpp/HTTPInterface/PageRequestHandlerFactory.cpp @@ -14,6 +14,7 @@ #include "PassphrasePage.h" #include "SaveKeysPage.h" #include "ElopageWebhook.h" +#include "ElopageWebhookLight.h" #include "UpdateUserPasswordPage.h" #include "Error500Page.h" #include "CheckTransactionPage.h" @@ -70,6 +71,13 @@ Poco::Net::HTTPRequestHandler* PageRequestHandlerFactory::createRequestHandler(c return pageRequestHandler; } + if (url_first_part == "/elopage_webhook_211") { + mLogging.information(dateTimeString + " call from elopage light"); + auto pageRequestHandler = new ElopageWebhookLight; + pageRequestHandler->setProfiler(timeUsed); + return pageRequestHandler; + } + // check if user has valid session Poco::Net::NameValueCollection cookies; request.getCookies(cookies);