@@ -63,6 +63,8 @@ function _M.new(options)
63
63
end
64
64
65
65
function _M .check (self , ip )
66
+ ngx .req .set_header (' X-Foxsec-IP-Reputation-Below-Threshold' , ' false' )
67
+ ngx .req .set_header (' X-Foxsec-Block' , ' false' )
66
68
if self .whitelist then
67
69
if iputils .ip_in_cidrs (ip , self .whitelist ) then
68
70
return
@@ -76,20 +78,27 @@ function _M.check(self, ip)
76
78
ngx .req .set_header (' X-Foxsec-IP-Reputation-Below-Threshold' , ' true' )
77
79
ngx .req .set_header (' X-Foxsec-Block' , ' true' )
78
80
if self .statsd then
79
- self .statsd .incr (" iprepd.status.rejected " )
81
+ self .statsd .incr (" iprepd.status.below_threshold " )
80
82
end
81
83
82
84
if self .dont_block == 1 then
83
- ngx .log (ngx .ERR , ' [logonly] ' .. ip .. ' rejected with a reputation of ' .. reputation )
85
+ ngx .log (ngx .ERR , ip .. ' is below threshold with a reputation of ' .. reputation )
84
86
else
85
87
ngx .log (ngx .ERR , ip .. ' rejected with a reputation of ' .. reputation )
88
+ if self .statsd then
89
+ self .statsd .incr (" iprepd.status.rejected" )
90
+ end
86
91
ngx .exit (ngx .HTTP_FORBIDDEN )
87
92
end
93
+ else
94
+ if self .statsd then
95
+ self .statsd .incr (" iprepd.status.accepted" )
96
+ end
88
97
end
98
+
99
+ return
89
100
end
90
101
91
- ngx .req .set_header (' X-Foxsec-IP-Reputation-Below-Threshold' , ' false' )
92
- ngx .req .set_header (' X-Foxsec-Block' , ' false' )
93
102
if self .statsd then
94
103
self .statsd .incr (" iprepd.status.accepted" )
95
104
end
@@ -125,6 +134,9 @@ function _M.get_reputation(self, ip)
125
134
self .cache :set (ip , 100 , self .cache_ttl )
126
135
else
127
136
ngx .log (ngx .ERR , ' iprepd responded with a ' .. resp .status .. ' http status code' )
137
+ if self .statsd then
138
+ self .statsd .incr (" iprepd.err." .. resp .status )
139
+ end
128
140
if self .cache_errors == 1 then
129
141
ngx .log (ngx .ERR , ' cache_errors is enabled, setting reputation of ' .. ip .. ' to 100 within the cache' )
130
142
self .cache :set (ip , 100 , self .cache_ttl )
0 commit comments