wafris 0.7.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lua/dist/wafris_core.lua +22 -16
- data/lib/wafris/configuration.rb +30 -8
- data/lib/wafris/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a2722b928a9589d9a25292b4116200e428fabfbbc7fa7d15e2eaada1a42927a
|
4
|
+
data.tar.gz: c3b941f3ed47136b92731e62df8dbb9d47c29d0817bf85e5b974bcd7b01c9ca8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e52e73b5d385e3a81ee4f5845f50dc00cd52683b595db3e5cb4f47ca7e573d49343525b8c2d6de423f9f189752b82f47acb71240d298b509f1da9b72023313e
|
7
|
+
data.tar.gz: b8cb1ccb52d9edc06756f78b277ff4ca2c2c39c94bea68e1e913b74dd620cf8033342759b232cfa086e6cf55f683729258cbb44488eca08f4d821ee751ab1929
|
@@ -1,3 +1,6 @@
|
|
1
|
+
local version = "v0.8:"
|
2
|
+
local wafris_prefix = "w:" .. version
|
3
|
+
|
1
4
|
local function get_time_bucket_from_timestamp(unix_time_milliseconds, minutes_flag)
|
2
5
|
local function calculate_years_number_of_days(yr)
|
3
6
|
return (yr % 4 == 0 and (yr % 100 ~= 0 or yr % 400 == 0)) and 366 or 365
|
@@ -46,10 +49,10 @@ local function get_time_bucket_from_timestamp(unix_time_milliseconds, minutes_fl
|
|
46
49
|
-- local minutes, seconds = math.floor(unix_time / 60 % 60), math.floor(unix_time % 60)
|
47
50
|
-- hours = hours > 12 and hours - 12 or hours == 0 and 12 or hours
|
48
51
|
if minutes_flag == false then
|
49
|
-
return string.format("%04d
|
52
|
+
return string.format("%04d%02d%02d%02d", year, month, days, hours)
|
50
53
|
elseif minutes_flag == true then
|
51
54
|
local minutes = math.floor(unix_time / 60 % 60)
|
52
|
-
return string.format("%04d
|
55
|
+
return string.format("%04d%02d%02d%02d%02d", year, month, days, hours, minutes)
|
53
56
|
end
|
54
57
|
end
|
55
58
|
|
@@ -60,25 +63,29 @@ local function get_request_id(timestamp, ip, max_requests)
|
|
60
63
|
return request_id
|
61
64
|
end
|
62
65
|
|
63
|
-
local function
|
64
|
-
|
66
|
+
local function add_to_graph_timebucket(timebucket, request_id)
|
67
|
+
local key = wafris_prefix .. "gr-ct:"
|
68
|
+
redis.call("PFADD", key .. timebucket, request_id)
|
69
|
+
-- Expire the key after 25 hours if it has no expiry
|
70
|
+
redis.call("EXPIRE", key, 90000)
|
65
71
|
end
|
66
72
|
|
67
73
|
-- For: Leaderboard of IPs with Request count as score
|
68
74
|
local function increment_timebucket_for(type, timebucket, property)
|
69
|
-
|
70
|
-
|
71
|
-
|
75
|
+
local key = wafris_prefix .. type .. "lb:" .. timebucket
|
76
|
+
redis.call("ZINCRBY", key, 1, property)
|
77
|
+
-- Expire the key after 25 hours if it has no expiry
|
78
|
+
redis.call("EXPIRE", key, 90000)
|
72
79
|
end
|
73
80
|
|
74
|
-
local function
|
81
|
+
local function increment_partial_hourly_request_counters(unix_time_milliseconds)
|
75
82
|
for i = 1, 60 do
|
76
83
|
local timebucket_in_milliseconds = unix_time_milliseconds + 60000 * (i - 1)
|
77
84
|
local timebucket = get_time_bucket_from_timestamp(timebucket_in_milliseconds, true)
|
78
|
-
local key = "
|
85
|
+
local key = wafris_prefix .. "hr-ct:" .. timebucket
|
79
86
|
redis.call("INCR", key)
|
80
87
|
-- Expire the key after 61 minutes if it has no expiry
|
81
|
-
redis.call("EXPIRE", key, 3660
|
88
|
+
redis.call("EXPIRE", key, 3660)
|
82
89
|
end
|
83
90
|
end
|
84
91
|
|
@@ -99,16 +106,15 @@ local request_id = get_request_id(nil, client_ip, max_requests)
|
|
99
106
|
local current_timebucket = get_time_bucket_from_timestamp(unix_time_milliseconds, false)
|
100
107
|
|
101
108
|
-- CARD DATA COLLECTION
|
102
|
-
|
109
|
+
increment_partial_hourly_request_counters(unix_time_milliseconds)
|
103
110
|
|
104
111
|
-- GRAPH DATA COLLECTION
|
105
|
-
|
112
|
+
add_to_graph_timebucket(current_timebucket, request_id)
|
106
113
|
|
107
114
|
-- LEADERBOARD DATA COLLECTION
|
108
|
-
|
109
|
-
increment_timebucket_for(
|
110
|
-
increment_timebucket_for("
|
111
|
-
increment_timebucket_for("request_path:", current_timebucket, request_path)
|
115
|
+
increment_timebucket_for("ip:", current_timebucket, client_ip)
|
116
|
+
increment_timebucket_for("ua:", current_timebucket, user_agent)
|
117
|
+
increment_timebucket_for("path:", current_timebucket, request_path)
|
112
118
|
increment_timebucket_for("host:", current_timebucket, host)
|
113
119
|
|
114
120
|
redis.call("ZRANGEBYSCORE", "blocked_ranges", client_ip_to_decimal, client_ip_to_decimal, "LIMIT", 0, 1)
|
data/lib/wafris/configuration.rb
CHANGED
@@ -6,11 +6,20 @@ module Wafris
|
|
6
6
|
attr_accessor :redis_pool_size
|
7
7
|
|
8
8
|
def initialize
|
9
|
-
@redis =
|
10
|
-
url: ENV['REDIS_URL'],
|
11
|
-
ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
|
12
|
-
)
|
9
|
+
@redis = set_redis
|
13
10
|
@redis_pool_size = 20
|
11
|
+
set_version
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_redis
|
15
|
+
if ENV['REDIS_URL']
|
16
|
+
Redis.new(
|
17
|
+
url: ENV['REDIS_URL'],
|
18
|
+
ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
|
19
|
+
)
|
20
|
+
else
|
21
|
+
Redis.new
|
22
|
+
end
|
14
23
|
end
|
15
24
|
|
16
25
|
def connection_pool
|
@@ -31,6 +40,15 @@ module Wafris
|
|
31
40
|
CONNECTION_ERROR
|
32
41
|
end
|
33
42
|
|
43
|
+
def set_version
|
44
|
+
version_line = File.open(
|
45
|
+
file_path("wafris_core"),
|
46
|
+
&:readline
|
47
|
+
)
|
48
|
+
version = version_line.slice(/v\d.\d/)
|
49
|
+
redis.set('version', version)
|
50
|
+
end
|
51
|
+
|
34
52
|
def core_sha
|
35
53
|
@core_sha ||= redis.script(:load, wafris_core)
|
36
54
|
end
|
@@ -43,10 +61,14 @@ module Wafris
|
|
43
61
|
|
44
62
|
def read_lua_dist(filename)
|
45
63
|
File.read(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
64
|
+
file_path(filename)
|
65
|
+
)
|
66
|
+
end
|
67
|
+
|
68
|
+
def file_path(filename)
|
69
|
+
File.join(
|
70
|
+
File.dirname(__FILE__),
|
71
|
+
"../lua/dist/#{filename}.lua"
|
50
72
|
)
|
51
73
|
end
|
52
74
|
end
|
data/lib/wafris/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wafris
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Micahel Buckbee
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2023-06-
|
12
|
+
date: 2023-06-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: connection_pool
|