2323
2424namespace modsecurity {
2525
26- std::string RuleMessage::disruptiveErrorLog (const RuleMessage *rm) {
26+
27+ std::string RuleMessage::_details (const RuleMessage *rm) {
2728 std::string msg;
2829
29- msg.append (" [client " + std::string (rm->m_clientIpAddress ) + " ]" );
30- msg.append (" ModSecurity: " );
31- msg.append (rm->m_disruptiveMessage );
32- msg.append (rm->m_match );
3330 msg.append (" [file \" " + std::string (rm->m_ruleFile ) + " \" ]" );
3431 msg.append (" [line \" " + std::to_string (rm->m_ruleLine ) + " \" ]" );
3532 msg.append (" [id \" " + std::to_string (rm->m_ruleId ) + " \" ]" );
@@ -50,91 +47,55 @@ std::string RuleMessage::disruptiveErrorLog(const RuleMessage *rm) {
5047 msg.append (" [unique_id \" " + rm->m_id + " \" ]" );
5148 msg.append (" [ref \" " + rm->m_reference + " \" ]" );
5249
53- return modsecurity::utils::string::toHexIfNeeded ( msg) ;
50+ return msg;
5451}
5552
56- std::string RuleMessage::noClientErrorLog (const RuleMessage *rm, bool disruptive) {
57- std::string msg;
58- if (disruptive == false ) {
59- return RuleMessage::noClientErrorLog (rm);
60- }
6153
62- msg.append (" Message: " );
63- msg.append (rm->m_disruptiveMessage );
64- msg.append (rm->m_match );
65- msg.append (" [file \" " + std::string (rm->m_ruleFile ) + " \" ]" );
66- msg.append (" [line \" " + std::to_string (rm->m_ruleLine ) + " \" ]" );
67- msg.append (" [id \" " + std::to_string (rm->m_ruleId ) + " \" ]" );
68- msg.append (" [rev \" " + rm->m_rev + " \" ]" );
69- msg.append (" [msg \" " + rm->m_message + " \" ]" );
70- msg.append (" [data \" " + rm->m_data + " \" ]" );
71- msg.append (" [severity \" " +
72- std::to_string (rm->m_severity ) + " \" ]" );
73- msg.append (" [ver \" " + rm->m_ver + " \" ]" );
74- msg.append (" [maturity \" " + std::to_string (rm->m_maturity ) + " \" ]" );
75- msg.append (" [accuracy \" " + std::to_string (rm->m_accuracy ) + " \" ]" );
76- for (auto &a : rm->m_tags ) {
77- msg.append (" [tag \" " + a + " \" ]" );
78- }
79- msg.append (" [ref \" " + rm->m_reference + " \" ]" );
80-
81- return modsecurity::utils::string::toHexIfNeeded (msg);
82- }
83-
84- std::string RuleMessage::noClientErrorLog (const RuleMessage *rm) {
54+ std::string RuleMessage::_errorLogTail (const RuleMessage *rm) {
8555 std::string msg;
8656
87- msg.append (" ModSecurity: Warning. " );
88- msg.append (rm->m_match );
89- msg.append (" [file \" " + std::string (rm->m_ruleFile ) + " \" ]" );
90- msg.append (" [line \" " + std::to_string (rm->m_ruleLine ) + " \" ]" );
91- msg.append (" [id \" " + std::to_string (rm->m_ruleId ) + " \" ]" );
92- msg.append (" [rev \" " + rm->m_rev + " \" ]" );
93- msg.append (" [msg \" " + rm->m_message + " \" ]" );
94- msg.append (" [data \" " + rm->m_data + " \" ]" );
95- msg.append (" [severity \" " +
96- std::to_string (rm->m_severity ) + " \" ]" );
97- msg.append (" [ver \" " + rm->m_ver + " \" ]" );
98- msg.append (" [maturity \" " + std::to_string (rm->m_maturity ) + " \" ]" );
99- msg.append (" [accuracy \" " + std::to_string (rm->m_accuracy ) + " \" ]" );
100- for (auto &a : rm->m_tags ) {
101- msg.append (" [tag \" " + a + " \" ]" );
102- }
103- msg.append (" [ref \" " + rm->m_reference + " \" ]" );
104-
105- return modsecurity::utils::string::toHexIfNeeded (msg);
106- }
107-
108- std::string RuleMessage::errorLogTail (const RuleMessage *rm) {
109- std::string msg;
110-
111- msg.append (" [hostname \" " + std::string (rm->m_serverIpAddress ) \
112- + " \" ]" );
57+ msg.append (" [hostname \" " + std::string (rm->m_serverIpAddress ) + " \" ]" );
11358 msg.append (" [uri \" " + rm->m_uriNoQueryStringDecoded + " \" ]" );
11459 msg.append (" [unique_id \" " + rm->m_id + " \" ]" );
11560
116- return modsecurity::utils::string::toHexIfNeeded ( msg) ;
61+ return msg;
11762}
11863
119- std::string RuleMessage::errorLog (const RuleMessage *rm) {
120- std::string msg;
12164
122- msg.append (" [client " + std::string (rm->m_clientIpAddress ) + " ] " );
123- msg.append (noClientErrorLog (rm));
124- msg.append (" " + errorLogTail (rm));
65+ std::string RuleMessage::log (const RuleMessage *rm, int props, int code) {
66+ std::string msg (" " );
12567
126- return msg;
127- }
68+ if (props & ClientLogMessageInfo) {
69+ msg.append (" [client " + std::string (rm->m_clientIpAddress ) + " ] " );
70+ }
12871
129- std::string RuleMessage::log (const RuleMessage *rm) {
130- std::string msg (" " );
131- if (rm->m_isDisruptive ) {
132- msg.append (disruptiveErrorLog (rm));
133- } else {
134- msg.append (errorLog (rm));
72+ if (rm->m_isDisruptive )
73+ {
74+ msg.append (" ModSecurity: Access denied with code " );
75+ if (code == -1 ) {
76+ msg.append (" %d" );
77+ }
78+ else
79+ {
80+ msg.append (std::to_string (code));
81+ }
82+ msg.append (" (phase " );
83+ msg.append (std::to_string (rm->m_rule ->m_phase - 1 ) + " ). " );
84+ }
85+ else
86+ {
87+ msg.append (" ModSecurity: Warning. " );
13588 }
13689
137- return msg;
90+ msg.append (rm->m_match );
91+ msg.append (_details (rm));
92+
93+ if (props & ErrorLogTailLogMessageInfo) {
94+ msg.append (" " + _errorLogTail (rm));
95+ }
96+
97+ return modsecurity::utils::string::toHexIfNeeded (msg);
13898}
13999
100+
140101} // namespace modsecurity
0 commit comments