wafris 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/wafris/configuration.rb +0 -8
- data/lib/wafris/version.rb +1 -1
- data/lib/wafris.rb +0 -56
- metadata +2 -3
- data/lib/lua/dist/get_graph_data.lua +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9ad06b7e5b23c313860cbdd76ee405cda36958112889cc591b3733270e31312
|
4
|
+
data.tar.gz: 98239b5926e3d57f732c37638ec4166ffb170d1f1f79cc1c36779f803f0c07e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1db5393514faa4b605923e039d7270f9eaddcc4d62e5b6f8897372a7b7c4c3a297e8d0900bf18acb53ebf2bb32b43c8ddf6c2ae0a2b1eca67df4ba547446d4b6
|
7
|
+
data.tar.gz: fcb42f4ba9a8d1a07f55ebdda5e76dd3e9651675b96f3d7a5ae7024978ac4e81bf35ae9d8fc1c71a67fc10f2f79e0baa8b781bf3a36eeac202fb44b7c386f040
|
data/lib/wafris/configuration.rb
CHANGED
data/lib/wafris/version.rb
CHANGED
data/lib/wafris.rb
CHANGED
@@ -48,61 +48,5 @@ module Wafris
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
52
|
-
def add_block(ip)
|
53
|
-
configuration.connection_pool.with do |conn|
|
54
|
-
conn.zadd(
|
55
|
-
'blocked_ranges',
|
56
|
-
IPAddr.new(ip).to_i,
|
57
|
-
ip
|
58
|
-
)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def remove_block(ip)
|
63
|
-
configuration.connection_pool.with do |conn|
|
64
|
-
conn.zrem(
|
65
|
-
'blocked_ranges',
|
66
|
-
ip
|
67
|
-
)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def request_buckets(_now)
|
72
|
-
graph_data = []
|
73
|
-
configuration.connection_pool.with do |conn|
|
74
|
-
time = Time.now.to_f * 1000
|
75
|
-
graph_data = conn.evalsha(
|
76
|
-
configuration.graph_sha,
|
77
|
-
argv: [
|
78
|
-
time.to_i
|
79
|
-
]
|
80
|
-
)
|
81
|
-
end
|
82
|
-
|
83
|
-
return graph_data
|
84
|
-
end
|
85
|
-
|
86
|
-
def ips_with_num_requests
|
87
|
-
configuration.connection_pool.with do |conn|
|
88
|
-
return conn.zunion(
|
89
|
-
*leader_timebuckets,
|
90
|
-
0, -1, with_scores: true
|
91
|
-
)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
private
|
96
|
-
|
97
|
-
def leader_timebuckets
|
98
|
-
timebuckets = []
|
99
|
-
|
100
|
-
time = Time.now.utc
|
101
|
-
24.times do |hours|
|
102
|
-
timebuckets << "ip-leader-sset:#{(time - 60 * 60 * hours).strftime("%Y-%m-%d-%H")}"
|
103
|
-
end
|
104
|
-
|
105
|
-
return timebuckets
|
106
|
-
end
|
107
51
|
end
|
108
52
|
end
|
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.2.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-
|
12
|
+
date: 2023-05-17 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: connection_pool
|
@@ -185,7 +185,6 @@ executables: []
|
|
185
185
|
extensions: []
|
186
186
|
extra_rdoc_files: []
|
187
187
|
files:
|
188
|
-
- lib/lua/dist/get_graph_data.lua
|
189
188
|
- lib/lua/dist/wafris_core.lua
|
190
189
|
- lib/lua/src/get_time_buckets.lua
|
191
190
|
- lib/lua/src/queries.lua
|
@@ -1,81 +0,0 @@
|
|
1
|
-
-- Compiled from:
|
2
|
-
-- src/get_time_buckets.lua
|
3
|
-
|
4
|
-
-- Code was pulled from https://otland.net/threads/how-convert-timestamp-to-date-type.251657/
|
5
|
-
-- An alternate solution is https://gist.github.com/markuman/e96d04139cd8acc33604
|
6
|
-
local function get_time_bucket_from_timestamp(unix_time_milliseconds)
|
7
|
-
local function calculate_years_number_of_days(yr)
|
8
|
-
return (yr % 4 == 0 and (yr % 100 ~= 0 or yr % 400 == 0)) and 366 or 365
|
9
|
-
end
|
10
|
-
|
11
|
-
local function get_year_and_day_number(year, days)
|
12
|
-
while days >= calculate_years_number_of_days(year) do
|
13
|
-
days = days - calculate_years_number_of_days(year)
|
14
|
-
year = year + 1
|
15
|
-
end
|
16
|
-
return year, days
|
17
|
-
end
|
18
|
-
|
19
|
-
local function get_month_and_month_day(days, year)
|
20
|
-
local days_in_each_month = {
|
21
|
-
31,
|
22
|
-
(calculate_years_number_of_days(year) == 366 and 29 or 28),
|
23
|
-
31,
|
24
|
-
30,
|
25
|
-
31,
|
26
|
-
30,
|
27
|
-
31,
|
28
|
-
31,
|
29
|
-
30,
|
30
|
-
31,
|
31
|
-
30,
|
32
|
-
31,
|
33
|
-
}
|
34
|
-
|
35
|
-
for month = 1, #days_in_each_month do
|
36
|
-
if days - days_in_each_month[month] <= 0 then
|
37
|
-
return month, days
|
38
|
-
end
|
39
|
-
days = days - days_in_each_month[month]
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
local unix_time = unix_time_milliseconds / 1000
|
44
|
-
local year = 1970
|
45
|
-
local days = math.ceil(unix_time / 86400)
|
46
|
-
local month = nil
|
47
|
-
|
48
|
-
year, days = get_year_and_day_number(year, days)
|
49
|
-
month, days = get_month_and_month_day(days, year)
|
50
|
-
local hours = math.floor(unix_time / 3600 % 24)
|
51
|
-
-- local minutes, seconds = math.floor(unix_time / 60 % 60), math.floor(unix_time % 60)
|
52
|
-
-- hours = hours > 12 and hours - 12 or hours == 0 and 12 or hours
|
53
|
-
return string.format("%04d-%02d-%02d-%02d", year, month, days, hours)
|
54
|
-
end
|
55
|
-
|
56
|
-
local function get_time_buckets(unix_time_milliseconds)
|
57
|
-
local time_buckets = {}
|
58
|
-
|
59
|
-
for i = 23, 0, -1 do
|
60
|
-
table.insert(time_buckets, get_time_bucket_from_timestamp(unix_time_milliseconds - (1000 * 60 * 60 * i)))
|
61
|
-
end
|
62
|
-
return time_buckets
|
63
|
-
end
|
64
|
-
|
65
|
-
local function num_requests(time_bucket)
|
66
|
-
local request_keys = redis.call("KEYS", "unique-requests:" .. time_bucket)
|
67
|
-
redis.call("PFMERGE", "merged_unique-requests", unpack(request_keys))
|
68
|
-
return redis.call("PFCOUNT", "merged_unique-requests")
|
69
|
-
end
|
70
|
-
|
71
|
-
local graph_data = {}
|
72
|
-
local unix_time_milliseconds = ARGV[1]
|
73
|
-
local time_buckets = get_time_buckets(unix_time_milliseconds)
|
74
|
-
-- use the get_time_buckets method to get each time bucket and
|
75
|
-
-- the associated count for that bucket
|
76
|
-
for bucket in pairs(time_buckets) do
|
77
|
-
table.insert(graph_data, time_buckets[bucket])
|
78
|
-
table.insert(graph_data, num_requests(time_buckets[bucket]))
|
79
|
-
end
|
80
|
-
|
81
|
-
return graph_data
|