mirror of
https://github.com/owasp-modsecurity/ModSecurity.git
synced 2025-08-14 05:45:59 +03:00
Adds AuditLogWriter{Serial,Parallel} classes
Furhter those classes will be used to persist (or send) the auditlogs.
This commit is contained in:
parent
e44d6e280d
commit
885fe14f30
@ -81,6 +81,9 @@ libmodsecurity_la_SOURCES = \
|
||||
parser/driver.cc \
|
||||
assay.cc \
|
||||
audit_log.cc \
|
||||
audit_log_writer.cc \
|
||||
audit_log_writer_serial.cc \
|
||||
audit_log_writer_parallel.cc \
|
||||
modsecurity.cc \
|
||||
rules.cc \
|
||||
utils.cc \
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
@ -24,6 +24,8 @@
|
||||
#include <fstream>
|
||||
#include <regex>
|
||||
|
||||
#include "src/audit_log_writer_parallel.h"
|
||||
#include "src/audit_log_writer_serial.h"
|
||||
|
||||
#define PARTS_CONSTAINS(a, c) \
|
||||
if (new_parts.find(toupper(a)) != std::string::npos \
|
||||
@ -101,7 +103,29 @@ bool AuditLog::setType(AuditLogType audit_type) {
|
||||
|
||||
|
||||
bool AuditLog::init() {
|
||||
return true;
|
||||
if (m_type == ParallelAuditLogType) {
|
||||
m_writer = new AuditLogWriterParallel();
|
||||
}
|
||||
|
||||
if (m_type == SerialAuditLogType) {
|
||||
m_writer = new AuditLogWriterSerial();
|
||||
}
|
||||
|
||||
if (m_writer == NULL || m_writer->init() == false) {
|
||||
std::cout << "not able to open the log for write." << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Sanity check */
|
||||
if (m_status == RelevantOnlyAuditLogStatus) {
|
||||
if (m_relevant.empty()) {
|
||||
std::cout << "m_relevant cannot be null while status is " << \
|
||||
"RelevantOnly" << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
@ -23,6 +23,7 @@
|
||||
#define SRC_AUDIT_LOG_H_
|
||||
|
||||
#include "modsecurity/assay.h"
|
||||
#include "src/audit_log_writer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -39,6 +40,7 @@ class AuditLog {
|
||||
m_parts(AAuditLogPart | BAuditLogPart | CAuditLogPart | FAuditLogPart
|
||||
| HAuditLogPart | ZAuditLogPart),
|
||||
m_type(ParallelAuditLogType),
|
||||
m_writer(NULL),
|
||||
m_relevant("")
|
||||
{ }
|
||||
|
||||
@ -174,7 +176,7 @@ class AuditLog {
|
||||
AuditLogType m_type;
|
||||
std::string m_relevant;
|
||||
|
||||
// AuditLogWriter *m_writer;
|
||||
AuditLogWriter *m_writer;
|
||||
};
|
||||
|
||||
} // namespace ModSecurity
|
||||
|
33
src/audit_log_writer.cc
Normal file
33
src/audit_log_writer.cc
Normal file
@ -0,0 +1,33 @@
|
||||
/**
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "src/audit_log_writer.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "src/audit_log.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
std::string AuditLogWriter::file_name(const std::string& unique_id) {
|
||||
time_t timer;
|
||||
time(&timer);
|
||||
|
||||
/** TODO: return file with time stamp and etc. */
|
||||
return std::string("/tmp/temp_audit_log_file.txt");
|
||||
}
|
||||
|
||||
|
||||
} // namespace ModSecurity
|
45
src/audit_log_writer.h
Normal file
45
src/audit_log_writer.h
Normal file
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRC_AUDIT_LOG_WRITER_H_
|
||||
#define SRC_AUDIT_LOG_WRITER_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
/** @ingroup ModSecurity_CPP_API */
|
||||
class AuditLogWriter : public std::ofstream {
|
||||
public:
|
||||
AuditLogWriter() { }
|
||||
|
||||
virtual bool close() { return true; }
|
||||
virtual bool init() { return true; }
|
||||
virtual bool write(const std::string& log) { return true; }
|
||||
|
||||
std::string file_name(const std::string& unique_id);
|
||||
};
|
||||
|
||||
} // namespace ModSecurity
|
||||
#endif
|
||||
|
||||
#endif // SRC_AUDIT_LOG_WRITER_H_
|
23
src/audit_log_writer_parallel.cc
Normal file
23
src/audit_log_writer_parallel.cc
Normal file
@ -0,0 +1,23 @@
|
||||
/**
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "src/audit_log_writer_parallel.h"
|
||||
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
||||
|
||||
} // namespace ModSecurity
|
34
src/audit_log_writer_parallel.h
Normal file
34
src/audit_log_writer_parallel.h
Normal file
@ -0,0 +1,34 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SRC_AUDIT_LOG_WRITER_PARALLEL_H_
|
||||
#define SRC_AUDIT_LOG_WRITER_PARALLEL_H_
|
||||
|
||||
#include "src/audit_log_writer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
/** @ingroup ModSecurity_CPP_API */
|
||||
class AuditLogWriterParallel : public AuditLogWriter {
|
||||
public:
|
||||
AuditLogWriterParallel() { }
|
||||
};
|
||||
|
||||
} // namespace ModSecurity
|
||||
#endif
|
||||
|
||||
#endif // SRC_AUDIT_LOG_WRITER_PARALLEL_H_
|
37
src/audit_log_writer_serial.cc
Normal file
37
src/audit_log_writer_serial.cc
Normal file
@ -0,0 +1,37 @@
|
||||
/**
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "src/audit_log_writer_serial.h"
|
||||
|
||||
#include "src/audit_log.h"
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
|
||||
bool AuditLogWriterSerial::init() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool AuditLogWriterSerial::close() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool AuditLogWriterSerial::write(const std::string& log) {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace ModSecurity
|
44
src/audit_log_writer_serial.h
Normal file
44
src/audit_log_writer_serial.h
Normal file
@ -0,0 +1,44 @@
|
||||
/*
|
||||
* ModSecurity, http://www.modsecurity.org/
|
||||
* Copyright (c) 2015 Trustwave Holdings, Inc. (http://www.trustwave.com/)
|
||||
*
|
||||
* You may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* If any of the files related to licensing are missing or if you have any
|
||||
* other questions related to licensing please contact Trustwave Holdings, Inc.
|
||||
* directly using the email address security@modsecurity.org.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#ifndef SRC_AUDIT_LOG_WRITER_SERIAL_H_
|
||||
#define SRC_AUDIT_LOG_WRITER_SERIAL_H_
|
||||
|
||||
#include "src/audit_log_writer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
namespace ModSecurity {
|
||||
|
||||
/** @ingroup ModSecurity_CPP_API */
|
||||
class AuditLogWriterSerial : public AuditLogWriter {
|
||||
public:
|
||||
AuditLogWriterSerial() { }
|
||||
|
||||
bool init() override;
|
||||
bool close() override;
|
||||
bool write(const std::string& log) override;
|
||||
};
|
||||
|
||||
} // namespace ModSecurity
|
||||
#endif
|
||||
|
||||
#endif // SRC_AUDIT_LOG_WRITER_SERIAL_H_
|
Loading…
x
Reference in New Issue
Block a user