adding second elopage webhook

This commit is contained in:
Dario 2020-02-27 14:59:25 +01:00
parent 7e4759b33e
commit 15a08227e6
5 changed files with 92 additions and 4 deletions

View File

@ -93,8 +93,7 @@ bool KeyPair::generateFromPassphrase(const char* passphrase, const Mnemonic* wor
sha512_final(&state, hash); sha512_final(&state, hash);
//crypto_auth_hmacsha512_final(&state, hash); //crypto_auth_hmacsha512_final(&state, hash);
/*
// debug passphrase // debug passphrase
printf("\passsphrase: <%s>\n", passphrase); printf("\passsphrase: <%s>\n", passphrase);
printf("size word indices: %u\n", word_indices->size()); printf("size word indices: %u\n", word_indices->size());

View File

@ -109,7 +109,7 @@ void ElopageWebhook::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::
// write stream result also to file // write stream result also to file
static Poco::Mutex mutex; static Poco::Mutex mutex;
Profiler timeUsed;
mutex.lock(); mutex.lock();
Poco::FileOutputStream file("elopage_webhook_requests.txt", std::ios::out | std::ios::app); 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 << completeRequest << std::endl;
file << std::endl; file << std::endl;
file.close(); 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(); mutex.unlock();
UniLib::controller::TaskPtr handleElopageTask(new HandleElopageRequestTask(elopageRequestData)); UniLib::controller::TaskPtr handleElopageTask(new HandleElopageRequestTask(elopageRequestData));
handleElopageTask->scheduleTask(handleElopageTask); handleElopageTask->scheduleTask(handleElopageTask);

View File

@ -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();
}

View File

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

View File

@ -14,6 +14,7 @@
#include "PassphrasePage.h" #include "PassphrasePage.h"
#include "SaveKeysPage.h" #include "SaveKeysPage.h"
#include "ElopageWebhook.h" #include "ElopageWebhook.h"
#include "ElopageWebhookLight.h"
#include "UpdateUserPasswordPage.h" #include "UpdateUserPasswordPage.h"
#include "Error500Page.h" #include "Error500Page.h"
#include "CheckTransactionPage.h" #include "CheckTransactionPage.h"
@ -70,6 +71,13 @@ Poco::Net::HTTPRequestHandler* PageRequestHandlerFactory::createRequestHandler(c
return pageRequestHandler; 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 // check if user has valid session
Poco::Net::NameValueCollection cookies; Poco::Net::NameValueCollection cookies;
request.getCookies(cookies); request.getCookies(cookies);