intrusion 0.1.8 → 0.2.1
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/intrusion.rb +34 -8
- metadata +13 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 943e04b12f074446b6d07fecd57c158945586b81f96fcab783747530564ef905
|
4
|
+
data.tar.gz: 631bbc1a142fa86c1f0e42c43199add90dea0e9aee934c342c8d96ef746be028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89d672e112dd6bcb025c1ab21eb5e47baa6dd301094922b9c2e2dbaa092491039f9ecd44b803043e1a2af840c555458fdd9f0e5b78e7cd8947f6b01edb22ed25
|
7
|
+
data.tar.gz: de59a116b9f48b3e1373f537658f557f236e91a5683fe743b0e8b360e2a19ea6703430c37e2fff1516fc71488f412db3802019141a830a974b7b8f7b7ce2df5f
|
data/lib/intrusion.rb
CHANGED
@@ -1,9 +1,32 @@
|
|
1
1
|
# Intrusion main module
|
2
|
+
|
2
3
|
module Intrusion
|
4
|
+
|
5
|
+
DefaultConfig = Struct.new(:threshold) do
|
6
|
+
def initialize
|
7
|
+
self.threshold = 10
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.configure
|
12
|
+
@config = DefaultConfig.new
|
13
|
+
yield(@config) if block_given?
|
14
|
+
@config
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.config
|
18
|
+
@config || configure
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.reset
|
22
|
+
@config = nil
|
23
|
+
@cache = nil
|
24
|
+
end
|
25
|
+
|
3
26
|
# check if ip is blocked
|
4
27
|
def ids_is_blocked?(address)
|
5
28
|
ids_load.each do |d|
|
6
|
-
return true if d[:ip] == address && d[:counter]
|
29
|
+
return true if d[:ip] == address && d[:counter] >= Intrusion.config.threshold
|
7
30
|
end
|
8
31
|
false
|
9
32
|
end
|
@@ -20,13 +43,11 @@ module Intrusion
|
|
20
43
|
found = nil
|
21
44
|
dt.each { |d| found = d if d[:ip] == address }
|
22
45
|
if found
|
23
|
-
block ? found[:counter] =
|
46
|
+
block ? found[:counter] = Intrusion.config.threshold : found[:counter] += 1
|
24
47
|
else
|
25
|
-
dt << { ip: address, counter: block ?
|
48
|
+
dt << { ip: address, counter: block ? Intrusion.config.threshold : 1 }
|
26
49
|
end
|
27
|
-
|
28
|
-
# update record
|
29
|
-
update(ids: dt.to_yaml)
|
50
|
+
ids_save!(dt)
|
30
51
|
end
|
31
52
|
|
32
53
|
# reset counter and stay
|
@@ -37,8 +58,7 @@ module Intrusion
|
|
37
58
|
|
38
59
|
if found
|
39
60
|
dt.delete(found)
|
40
|
-
|
41
|
-
return update(ids: dt.to_yaml)
|
61
|
+
return ids_save!(dt)
|
42
62
|
end
|
43
63
|
false
|
44
64
|
end
|
@@ -51,4 +71,10 @@ module Intrusion
|
|
51
71
|
rescue RuntimeError
|
52
72
|
[]
|
53
73
|
end
|
74
|
+
|
75
|
+
# save current state to object or file
|
76
|
+
def ids_save!(dt)
|
77
|
+
update(ids: dt.to_yaml)
|
78
|
+
end
|
79
|
+
|
54
80
|
end
|
metadata
CHANGED
@@ -1,27 +1,30 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intrusion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Duncombe
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Intrusion is a gem helping you to block objects for IP addresses within
|
14
14
|
your Ruby on Rails Application.
|
15
|
-
email:
|
15
|
+
email: simon@duncom.be
|
16
16
|
executables: []
|
17
17
|
extensions: []
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/intrusion.rb
|
21
|
-
homepage:
|
22
|
-
licenses:
|
23
|
-
|
24
|
-
|
21
|
+
homepage: https://github.com/symontech/intrusion
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata:
|
25
|
+
source_code_uri: https://github.com/symontech/intrusion
|
26
|
+
documentation_uri: https://github.com/symontech/intrusion#readme
|
27
|
+
post_install_message:
|
25
28
|
rdoc_options: []
|
26
29
|
require_paths:
|
27
30
|
- lib
|
@@ -36,8 +39,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
36
39
|
- !ruby/object:Gem::Version
|
37
40
|
version: '0'
|
38
41
|
requirements: []
|
39
|
-
rubygems_version: 3.
|
40
|
-
signing_key:
|
42
|
+
rubygems_version: 3.2.29
|
43
|
+
signing_key:
|
41
44
|
specification_version: 4
|
42
45
|
summary: intrusion detection and prevention for rails applications
|
43
46
|
test_files: []
|