mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
adding elopage webhook page
This commit is contained in:
parent
ea9c34035d
commit
8fcd28d189
2
dependencies/iroha-ed25519
vendored
2
dependencies/iroha-ed25519
vendored
@ -1 +1 @@
|
||||
Subproject commit a0977c22d23f7e8cb596f1d9d812de74115f407b
|
||||
Subproject commit 7307ffb8a89d2459f0c07ea5cab27c0d3496df00
|
||||
25
src/cpp/HTTPInterface/ElopageWebhook.cpp
Normal file
25
src/cpp/HTTPInterface/ElopageWebhook.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
#include "ElopageWebhook.h"
|
||||
#include "Poco/Net/HTTPServerRequest.h"
|
||||
#include "Poco/Net/HTTPServerResponse.h"
|
||||
#include "Poco/DeflatingStream.h"
|
||||
|
||||
#include "../ServerConfig.h"
|
||||
|
||||
|
||||
void ElopageWebhook::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");
|
||||
|
||||
response.setChunkedTransferEncoding(true);
|
||||
response.setContentType("application/json");
|
||||
bool _compressResponse(request.hasToken("Accept-Encoding", "gzip"));
|
||||
if (_compressResponse) response.set("Content-Encoding", "gzip");
|
||||
|
||||
|
||||
std::ostream& _responseStream = response.send();
|
||||
Poco::DeflatingOutputStream _gzipStream(_responseStream, Poco::DeflatingStreamBuf::STREAM_GZIP, 1);
|
||||
std::ostream& responseStream = _compressResponse ? _gzipStream : _responseStream;
|
||||
|
||||
if (_compressResponse) _gzipStream.close();
|
||||
}
|
||||
15
src/cpp/HTTPInterface/ElopageWebhook.h
Normal file
15
src/cpp/HTTPInterface/ElopageWebhook.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef Elopage_Webhook_INCLUDED
|
||||
#define Elopage_Webhook_INCLUDED
|
||||
|
||||
|
||||
#include "Poco/Net/HTTPRequestHandler.h"
|
||||
|
||||
|
||||
class ElopageWebhook : public Poco::Net::HTTPRequestHandler
|
||||
{
|
||||
public:
|
||||
void handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response);
|
||||
};
|
||||
|
||||
|
||||
#endif // Elopage_Webhook_INCLUDED
|
||||
@ -11,6 +11,7 @@
|
||||
#include "CheckEmailPage.h"
|
||||
#include "PassphrasePage.h"
|
||||
#include "SaveKeysPage.h"
|
||||
#include "ElopageWebhook.h"
|
||||
|
||||
#include "../SingletonManager/SessionManager.h"
|
||||
|
||||
@ -36,6 +37,10 @@ Poco::Net::HTTPRequestHandler* PageRequestHandlerFactory::createRequestHandler(c
|
||||
}
|
||||
}
|
||||
|
||||
if (url_first_part == "/elopage_webhook_261") {
|
||||
return new ElopageWebhook;
|
||||
}
|
||||
|
||||
// check if user has valid session
|
||||
Poco::Net::NameValueCollection cookies;
|
||||
request.getCookies(cookies);
|
||||
|
||||
@ -8,6 +8,12 @@
|
||||
#include "Poco/Net/RejectCertificateHandler.h"
|
||||
#include "Poco/SharedPtr.h"
|
||||
|
||||
#include "Poco/Mutex.h"
|
||||
#include "Poco/FileStream.h"
|
||||
#include "Poco/LocalDateTime.h"
|
||||
#include "Poco/DateTimeFormat.h"
|
||||
#include "Poco/DateTimeFormatter.h"
|
||||
|
||||
using Poco::Net::SSLManager;
|
||||
using Poco::Net::Context;
|
||||
using Poco::Net::KeyConsoleHandler;
|
||||
@ -118,4 +124,31 @@ namespace ServerConfig {
|
||||
delete g_CPUScheduler;
|
||||
}
|
||||
}
|
||||
|
||||
void writeToFile(std::istream& datas, std::string& fileName)
|
||||
{
|
||||
static Poco::Mutex mutex;
|
||||
|
||||
mutex.lock();
|
||||
|
||||
Poco::FileOutputStream file(fileName, std::ios::out | std::ios::app);
|
||||
|
||||
if (!file.good()) {
|
||||
printf("[ServerConfig::writeToFile] error creating file with name: %s\n", fileName.data());
|
||||
mutex.unlock();
|
||||
return;
|
||||
}
|
||||
|
||||
Poco::LocalDateTime now;
|
||||
|
||||
std::string dateTimeStr = Poco::DateTimeFormatter::format(now, Poco::DateTimeFormat::ISO8601_FORMAT);
|
||||
file << dateTimeStr << std::endl;
|
||||
|
||||
for (std::string line; std::getline(datas, line); ) {
|
||||
file << line << std::endl;
|
||||
}
|
||||
file << std::endl;
|
||||
file.close();
|
||||
mutex.unlock();
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@
|
||||
#include "Poco/Util/LayeredConfiguration.h"
|
||||
#include "Poco/Net/Context.h"
|
||||
|
||||
|
||||
#include "tasks/CPUSheduler.h"
|
||||
|
||||
namespace ServerConfig {
|
||||
@ -34,5 +35,7 @@ namespace ServerConfig {
|
||||
bool initEMailAccount(const Poco::Util::LayeredConfiguration& cfg);
|
||||
bool initSSLClientContext();
|
||||
|
||||
void writeToFile(std::istream& datas, std::string& fileName);
|
||||
|
||||
void unload();
|
||||
};
|
||||
Loading…
x
Reference in New Issue
Block a user