Added logging
This commit is contained in:
@@ -67,3 +67,5 @@ install(TARGETS ${PROJECT_NAME}
|
||||
install(DIRECTORY docroot/
|
||||
DESTINATION /opt/ypchat/docroot
|
||||
)
|
||||
install(CODE "file(MAKE_DIRECTORY /opt/ypchat/logs)")
|
||||
install(CODE "execute_process(COMMAND chmod 777 /opt/ypchat/logs)")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 9.0.2, 2024-04-08T09:10:17. -->
|
||||
<!-- Written by QtCreator 9.0.2, 2024-05-08T20:43:18. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
@@ -379,7 +379,7 @@
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">singlechat.wt</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeRunConfiguration.singlechat.wt</value>
|
||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey">singlechat.wt</value>
|
||||
<value type="QString" key="RunConfiguration.Arguments">--docroot ../docroot/ --http-port=4500 --http-address=0.0.0.0</value>
|
||||
<value type="QString" key="RunConfiguration.Arguments">--docroot="../docroot/;/style.css,/resources" --http-port=4500 --http-address=0.0.0.0</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
|
||||
|
||||
@@ -220,7 +220,6 @@ void App::handleLogin(Wt::WLineEdit* userName, Wt::WComboBox* countryWidget, Wt:
|
||||
validateName(nick);
|
||||
validateGender(genderWidget);
|
||||
validateAge(ageWidget);
|
||||
|
||||
setUserData(nick, countryWidget, ageWidget, genderWidget);
|
||||
connectToServer();
|
||||
startChat();
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <Wt/Auth/HashFunction.h>
|
||||
#include <Wt/WLocalDateTime.h>
|
||||
#include <Wt/Utils.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
@@ -18,6 +19,26 @@ Broadcast::Broadcast(Wt::WServer *server):
|
||||
downloadCountries();
|
||||
thread_ = std::thread(std::bind(&Broadcast::run, this));
|
||||
lastTimeoutCheck_ = Wt::WDateTime::currentDateTime();
|
||||
checkAndLogStart();
|
||||
}
|
||||
|
||||
void Broadcast::checkAndLogStart() {
|
||||
const std::string logFilePath = "/opt/ypchat/logs/starts.log";
|
||||
std::ifstream infile(logFilePath);
|
||||
if (!infile.good()) {
|
||||
std::ofstream outfile(logFilePath);
|
||||
outfile.close();
|
||||
}
|
||||
infile.close();
|
||||
Wt::WDateTime now = Wt::WDateTime::currentDateTime();
|
||||
std::string timestamp = now.toString("yyyy-MM-dd HH:mm:ss").toUTF8();
|
||||
std::ofstream outfile(logFilePath, std::ios_base::app);
|
||||
if (outfile.is_open()) {
|
||||
outfile << timestamp << std::endl;
|
||||
outfile.close();
|
||||
} else {
|
||||
std::cerr << "Fehler beim Öffnen der Datei: " << logFilePath << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
Broadcast::~Broadcast() {
|
||||
@@ -36,6 +57,25 @@ void Broadcast::connect(Client *client, const std::function<void ()> &fct) {
|
||||
connection->addBroadcast(userlistBroadcast);
|
||||
connection->addBroadcast(newUserBroadcast);
|
||||
}
|
||||
logClientLogin(client->json());
|
||||
}
|
||||
|
||||
void Broadcast::logClientLogin(const Wt::Json::Object &clientJson) {
|
||||
const std::string logFilePath = "/opt/ypchat/logs/logins.log";
|
||||
std::ifstream infile(logFilePath);
|
||||
if (!infile.good()) {
|
||||
std::ofstream outfile(logFilePath);
|
||||
outfile.close();
|
||||
}
|
||||
infile.close();
|
||||
std::string clientData = Wt::Json::serialize(clientJson);
|
||||
std::ofstream outfile(logFilePath, std::ios_base::app);
|
||||
if (outfile.is_open()) {
|
||||
outfile << clientData << std::endl;
|
||||
outfile.close();
|
||||
} else {
|
||||
std::cerr << "Fehler beim Öffnen der Datei: " << logFilePath << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void Broadcast::disconnect(Client *client) {
|
||||
|
||||
@@ -147,6 +147,8 @@ private:
|
||||
void sendBlockedMessage(std::string sessionId, std::string toUserName);
|
||||
void sendBlockDone(std::string sessionId, std::string toUserName);
|
||||
void sendUnblockDone(std::string sessionId, std::string toUserName);
|
||||
void checkAndLogStart();
|
||||
void logClientLogin(const Wt::Json::Object &clientJson);
|
||||
};
|
||||
|
||||
#endif // BROADCAST_H
|
||||
|
||||
Reference in New Issue
Block a user