update logging

This commit is contained in:
Dario 2019-10-18 12:18:34 +02:00
parent 0134ac732e
commit 43044f2c28
8 changed files with 34 additions and 15 deletions

View File

@ -23,7 +23,7 @@ KeyPair::KeyPair()
KeyPair::~KeyPair() KeyPair::~KeyPair()
{ {
printf("[KeyPair::~KeyPair] privkey: %d, soduium privkey: %d \n", mPrivateKey, mSodiumSecret); //printf("[KeyPair::~KeyPair] privkey: %d, soduium privkey: %d \n", mPrivateKey, mSodiumSecret);
if (mPrivateKey) { if (mPrivateKey) {
delete mPrivateKey; delete mPrivateKey;
mPrivateKey = nullptr; mPrivateKey = nullptr;
@ -106,7 +106,7 @@ bool KeyPair::generateFromPassphrase(const char* passphrase, Mnemonic* word_sour
printf("Sodium Private: \t%s\n", getHex(*mSodiumSecret, mSodiumSecret->size()).data()); printf("Sodium Private: \t%s\n", getHex(*mSodiumSecret, mSodiumSecret->size()).data());
printf("// ********* Keys End ************ //\n"); printf("// ********* Keys End ************ //\n");
*/ */
printf("[KeyPair::generateFromPassphrase] finished!\n"); //printf("[KeyPair::generateFromPassphrase] finished!\n");
// using // using
return true; return true;
} }

View File

@ -16,7 +16,7 @@
#include "Poco/Logger.h" #include "Poco/Logger.h"
#include "Poco/AsyncChannel.h" #include "Poco/AsyncChannel.h"
#include "Poco/SimpleFileChannel.h" #include "Poco/SimpleFileChannel.h"
#include "Poco/ConsoleChannel.h"
#include "MySQL/Poco/Connector.h" #include "MySQL/Poco/Connector.h"
@ -136,6 +136,13 @@ int Gradido_LoginServer::main(const std::vector<std::string>& args)
return Application::EXIT_CONFIG; return Application::EXIT_CONFIG;
} }
// logging for request handling
Poco::AutoPtr<Poco::ConsoleChannel> requestLogConsoleChannel(new Poco::ConsoleChannel);
Poco::AutoPtr<Poco::AsyncChannel> requestLogAsyncChannel(new Poco::AsyncChannel(requestLogConsoleChannel));
Poco::Logger& requestLog = Poco::Logger::get("requestLog");
requestLog.setChannel(requestLogAsyncChannel);
requestLog.setLevel("information");
// set-up a server socket // set-up a server socket
Poco::Net::ServerSocket svs(port); Poco::Net::ServerSocket svs(port);
// set-up a HTTPServer instance // set-up a HTTPServer instance

View File

@ -21,7 +21,7 @@
#include "../model/Profiler.h" #include "../model/Profiler.h"
PageRequestHandlerFactory::PageRequestHandlerFactory() PageRequestHandlerFactory::PageRequestHandlerFactory()
: mRemoveGETParameters("^/([a-zA-Z0-9_-]*)") : mRemoveGETParameters("^/([a-zA-Z0-9_-]*)"), mLogging(Poco::Logger::get("requestLog"))
{ {
} }
@ -35,15 +35,15 @@ Poco::Net::HTTPRequestHandler* PageRequestHandlerFactory::createRequestHandler(c
mRemoveGETParameters.extract(uri, url_first_part); mRemoveGETParameters.extract(uri, url_first_part);
if (uri != "/favicon.ico") { if (uri != "/favicon.ico") {
printf("[PageRequestHandlerFactory] uri: %s, first part: %s\n", uri.data(), url_first_part.data()); //printf("[PageRequestHandlerFactory] uri: %s, first part: %s\n", uri.data(), url_first_part.data());
auto referer = request.find("Referer"); /*auto referer = request.find("Referer");
if (referer != request.end()) { if (referer != request.end()) {
printf("referer: %s\n", referer->second.data()); printf("referer: %s\n", referer->second.data());
} }*/
} }
if (url_first_part == "/elopage_webhook_261") { if (url_first_part == "/elopage_webhook_261") {
//printf("choose elopage\n"); printf("call from elopage\n");
return new ElopageWebhook; return new ElopageWebhook;
} }
@ -59,6 +59,16 @@ Poco::Net::HTTPRequestHandler* PageRequestHandlerFactory::createRequestHandler(c
auto sm = SessionManager::getInstance(); auto sm = SessionManager::getInstance();
auto s = sm->getSession(session_id); auto s = sm->getSession(session_id);
// for debugging
std::stringstream logStream;
auto referer = request.find("Referer");
logStream << "call " << uri;
if (s) {logStream << ", with session: " << std::to_string(s->getHandle()); }
if (referer != request.end()) { logStream << ", from: " << referer->second;}
logStream << std::endl;
mLogging.information(logStream.str());
// end debugging
// TODO: count invalid session requests from IP and block IP for some time to prevent brute force session hijacking // TODO: count invalid session requests from IP and block IP for some time to prevent brute force session hijacking
// or use log file and configure fail2ban for this to do // or use log file and configure fail2ban for this to do
@ -79,7 +89,7 @@ Poco::Net::HTTPRequestHandler* PageRequestHandlerFactory::createRequestHandler(c
sm->releaseSession(s); sm->releaseSession(s);
// remove cookie // remove cookie
printf("session released\n"); //printf("session released\n");
return new LoginPage; return new LoginPage;
} }
if(url_first_part == "/user_delete") { if(url_first_part == "/user_delete") {
@ -101,7 +111,7 @@ Poco::Net::HTTPRequestHandler* PageRequestHandlerFactory::createRequestHandler(c
return new SaveKeysPage(s); return new SaveKeysPage(s);
} }
if (s && !s->getUser().isNull()) { if (s && !s->getUser().isNull()) {
printf("[PageRequestHandlerFactory] go to dashboard page with user\n"); //printf("[PageRequestHandlerFactory] go to dashboard page with user\n");
return new DashboardPage(s); return new DashboardPage(s);
} }
} else { } else {

View File

@ -3,6 +3,7 @@
#include "Poco/Net/HTTPRequestHandlerFactory.h" #include "Poco/Net/HTTPRequestHandlerFactory.h"
#include "Poco/RegularExpression.h" #include "Poco/RegularExpression.h"
#include "Poco/Logger.h"
#include "../model/Session.h" #include "../model/Session.h"
#define HTTP_PAGES_COUNT 1 #define HTTP_PAGES_COUNT 1
@ -17,6 +18,7 @@ protected:
Poco::Net::HTTPRequestHandler* handleCheckEmail(Session* session, const std::string uri, const Poco::Net::HTTPServerRequest& request); Poco::Net::HTTPRequestHandler* handleCheckEmail(Session* session, const std::string uri, const Poco::Net::HTTPServerRequest& request);
Poco::RegularExpression mRemoveGETParameters; Poco::RegularExpression mRemoveGETParameters;
Poco::Logger& mLogging;
}; };
#endif // __DR_PAGE_REQUEST_HANDLER_FACTORY_H #endif // __DR_PAGE_REQUEST_HANDLER_FACTORY_H

View File

@ -443,7 +443,7 @@ bool Session::loadFromEmailVerificationCode(Poco::UInt64 emailVerificationCode)
mEmailVerificationCode = emailVerificationCode; mEmailVerificationCode = emailVerificationCode;
updateState(SESSION_STATE_EMAIL_VERIFICATION_WRITTEN); updateState(SESSION_STATE_EMAIL_VERIFICATION_WRITTEN);
printf("[Session::loadFromEmailVerificationCode] time: %s\n", usedTime.string().data()); //printf("[Session::loadFromEmailVerificationCode] time: %s\n", usedTime.string().data());
return true; return true;
} }
catch (const Poco::Exception& ex) { catch (const Poco::Exception& ex) {

View File

@ -31,7 +31,7 @@ int PrepareEmailTask::run()
return -1; return -1;
} }
printf("[PrepareEmailTask] time: %s\n", timeUsed.string().data()); //printf("[PrepareEmailTask] time: %s\n", timeUsed.string().data());
/* /*
session.login(); session.login();
session.startTLS(pContext); session.startTLS(pContext);

View File

@ -33,6 +33,6 @@ int SendEmailTask::run()
if (prepare->send(mMailMessage)) { if (prepare->send(mMailMessage)) {
return -1; return -1;
} }
printf("[SendEmailTask] time: %s\n", timeUsed.string().data()); //printf("[SendEmailTask] time: %s\n", timeUsed.string().data());
return 0; return 0;
} }

View File

@ -61,8 +61,8 @@ enum PageState
state = PAGE_ERROR; state = PAGE_ERROR;
} }
} }
printf("SaveKeysPage: hasErrors: %d, session state: %d, target state: %d\n", //printf("SaveKeysPage: hasErrors: %d, session state: %d, target state: %d\n",
hasErrors, mSession->getSessionState(), SESSION_STATE_KEY_PAIR_GENERATED); //hasErrors, mSession->getSessionState(), SESSION_STATE_KEY_PAIR_GENERATED);
} }
getErrors(mSession); getErrors(mSession);
%> %>