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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/intrusion.rb +34 -8
  3. metadata +13 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f7c0b79c12c817d564e55ecba6f86540a09bb083ac97b5ad7b8e3a31c07fa53
4
- data.tar.gz: 876156a63816e18184eb72af76f3634e80a15542d6d66e39d26fdaf2176b2860
3
+ metadata.gz: 943e04b12f074446b6d07fecd57c158945586b81f96fcab783747530564ef905
4
+ data.tar.gz: 631bbc1a142fa86c1f0e42c43199add90dea0e9aee934c342c8d96ef746be028
5
5
  SHA512:
6
- metadata.gz: 702186b662da7e7db61cfc65264f3fab1e833d32743add8afe39675a567b58a0c4afd85c7ad0d91f3a1eae35b371e7160f4a315bbbd1140591f168e03537fd19
7
- data.tar.gz: 13adcc68d21d57813d5d2771239d03b61fcedf31c434a91e378de2253972ef66377d1166f55e81f788cca779622edd58c8a64f3e44a0568780665d48066e1f42
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] > 9
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] = 10 : found[:counter] += 1
46
+ block ? found[:counter] = Intrusion.config.threshold : found[:counter] += 1
24
47
  else
25
- dt << { ip: address, counter: block ? 10 : 1 }
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
- # update
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.8
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: 2020-10-08 00:00:00.000000000 Z
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: sd@netsense.ch
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: http://github.com/symontech/intrusion
22
- licenses: []
23
- metadata: {}
24
- post_install_message:
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.0.8
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: []