@@ -49,6 +49,46 @@ class AntiDDoSWorker{
49
49
ConnectRedisServer ();
50
50
}
51
51
52
+ static int PostRequestHook (request_rec *r){
53
+ // ignore whitelist
54
+ if (Config::Whitelist ().ContainsIP (r->connection ->client_ip )){
55
+ return DECLINED;
56
+ }
57
+
58
+ AntiDDoSWorker worker = AntiDDoSWorker ();
59
+
60
+ int score = 0 ;
61
+
62
+ for (int i = 0 ; i < Config::Filters ().Count (); i++){
63
+ score += Config::Filters ().Get (i).GetScore (r, true );
64
+ }
65
+
66
+ if (score > 0 ){
67
+ ap_log_error (APLOG_MARK, APLOG_NOTICE, 0 , r->server ,
68
+ " add score for %s from postrequest (%i)" , r->connection ->client_ip , score);
69
+
70
+ worker.IncreaseScore (r->connection ->client_ip , score);
71
+
72
+ if (worker.GetScore (r->connection ->client_ip ) > Config::MaxHits ())
73
+ {
74
+ worker.TickDownScore (r->connection ->client_ip );
75
+ if (worker.GetScore (r->connection ->client_ip ) > Config::MaxHits ()){
76
+ worker.Block (r->connection ->client_ip );
77
+
78
+ r->status = 429 ;
79
+
80
+ ap_log_error (APLOG_MARK, APLOG_WARNING, 0 , r->server ,
81
+ " block access, client exceeded score limit: %s (postrequest)" , r->connection ->client_ip );
82
+
83
+ return OK;
84
+ }
85
+
86
+ }
87
+ }
88
+
89
+ return DECLINED;
90
+ }
91
+
52
92
static int PreRequestHook (request_rec *r){
53
93
if (Config::Whitelist ().ContainsIP (r->connection ->client_ip )){
54
94
ap_log_error (APLOG_MARK, APLOG_INFO, 0 , r->server ,
@@ -74,7 +114,7 @@ class AntiDDoSWorker{
74
114
}
75
115
76
116
if (score > 0 ){
77
- ap_log_error (APLOG_MARK, APLOG_CRIT , 0 , r->server ,
117
+ ap_log_error (APLOG_MARK, APLOG_NOTICE , 0 , r->server ,
78
118
" add score for %s (%i)" , r->connection ->client_ip , score);
79
119
80
120
worker.IncreaseScore (r->connection ->client_ip , score);
@@ -87,7 +127,7 @@ class AntiDDoSWorker{
87
127
88
128
r->status = 429 ;
89
129
90
- ap_log_error (APLOG_MARK, APLOG_INFO , 0 , r->server ,
130
+ ap_log_error (APLOG_MARK, APLOG_WARNING , 0 , r->server ,
91
131
" block access, client exceeded score limit: %s" , r->connection ->client_ip );
92
132
93
133
return OK;
0 commit comments