wafris 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/lua/dist/wafris_core.lua +21 -15
- data/lib/wafris/configuration.rb +18 -4
- 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: bc80b768ee486f172f3eb2d617fde7622bff15fca6078819e89ddbae2b112f97
|
4
|
+
data.tar.gz: 6a2528038d9ca8d278ce2a599051e74803635626ee35a67f224bc531d9fa1d7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0401a246649e42b5b2f801dae3ae5b362aca9d42446c45e93f3aa8e1c32e23c63b0e065cc8ae6e5f9131be420090d80d72fa5f1d0e85e9cdb9073036657db3b
|
7
|
+
data.tar.gz: 2bf8cf0a8b1a0d13e0aef0c8bd08d869c619b3655b68a4de6a631b60f620212d171be294c9edfcb500bdfb1a856dc3e1fe578815e8d2b0ba6aa1ab9a57fb6324
|
@@ -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,22 +63,26 @@ 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, "NX")
|
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, "NX")
|
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
88
|
redis.call("EXPIRE", key, 3660, "NX")
|
@@ -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
@@ -11,6 +11,7 @@ module Wafris
|
|
11
11
|
ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE }
|
12
12
|
)
|
13
13
|
@redis_pool_size = 20
|
14
|
+
set_version
|
14
15
|
end
|
15
16
|
|
16
17
|
def connection_pool
|
@@ -31,6 +32,15 @@ module Wafris
|
|
31
32
|
CONNECTION_ERROR
|
32
33
|
end
|
33
34
|
|
35
|
+
def set_version
|
36
|
+
version_line = File.open(
|
37
|
+
file_path("wafris_core"),
|
38
|
+
&:readline
|
39
|
+
)
|
40
|
+
version = version_line.slice(/v\d.\d/)
|
41
|
+
redis.set('version', version)
|
42
|
+
end
|
43
|
+
|
34
44
|
def core_sha
|
35
45
|
@core_sha ||= redis.script(:load, wafris_core)
|
36
46
|
end
|
@@ -43,10 +53,14 @@ module Wafris
|
|
43
53
|
|
44
54
|
def read_lua_dist(filename)
|
45
55
|
File.read(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
56
|
+
file_path(filename)
|
57
|
+
)
|
58
|
+
end
|
59
|
+
|
60
|
+
def file_path(filename)
|
61
|
+
File.join(
|
62
|
+
File.dirname(__FILE__),
|
63
|
+
"../lua/dist/#{filename}.lua"
|
50
64
|
)
|
51
65
|
end
|
52
66
|
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.0
|
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
|