mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-09-30 19:47:47 +03:00
Writes audit log in parallel mode
First version still missing the index among other things
This commit is contained in:
@@ -15,9 +15,83 @@
|
||||
|
||||
#include "src/audit_log_writer_parallel.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include "src/audit_log.h"
|
||||
#include "modsecurity/assay.h"
|
||||
#include "src/utils.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
||||
inline std::string AuditLogWriterParallel::logFilePath(time_t *t,
|
||||
int part) {
|
||||
struct tm timeinfo;
|
||||
char tstr[300];
|
||||
size_t len;
|
||||
std::string name("");
|
||||
|
||||
localtime_r(t, &timeinfo);
|
||||
|
||||
if (part & YearMonthDayDirectory) {
|
||||
memset(tstr, '\0', 300);
|
||||
strftime(tstr, 299, "/%Y%m%d", &timeinfo);
|
||||
name = tstr;
|
||||
}
|
||||
|
||||
if (part & YearMonthDayAndTimeDirectory) {
|
||||
memset(tstr, '\0', 300);
|
||||
strftime(tstr, 299, "/%Y%m%d-%H%M", &timeinfo);
|
||||
name = name + tstr;
|
||||
}
|
||||
|
||||
if (part & YearMonthDayAndTimeFileName) {
|
||||
memset(tstr, '\0', 300);
|
||||
strftime(tstr, 299, "/%Y%m%d-%H%M%S", &timeinfo);
|
||||
name = name + tstr;
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
bool AuditLogWriterParallel::init() {
|
||||
/** TODO:: Check if the directory exists. */
|
||||
/** TODO:: Checking if we have permission to write in the target dir */
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool AuditLogWriterParallel::close() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool AuditLogWriterParallel::write(Assay *assay) {
|
||||
std::string log = assay->to_json(0);
|
||||
std::string fileName = logFilePath(&assay->timeStamp,
|
||||
YearMonthDayDirectory | YearMonthDayAndTimeDirectory
|
||||
| YearMonthDayAndTimeFileName);
|
||||
fileName = fileName + "-" + assay->id;
|
||||
|
||||
std::string logPath = m_audit->m_storage_dir;
|
||||
|
||||
createDir((logPath +
|
||||
logFilePath(&assay->timeStamp, YearMonthDayDirectory)).c_str());
|
||||
createDir((logPath +
|
||||
logFilePath(&assay->timeStamp, YearMonthDayDirectory
|
||||
| YearMonthDayAndTimeDirectory)).c_str());
|
||||
|
||||
std::ofstream f;
|
||||
f.open(logPath + fileName, std::fstream::out | std::fstream::app);
|
||||
f << log;
|
||||
f.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ModSecurity
|
||||
|
Reference in New Issue
Block a user