intrusion 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +5 -5
  2. data/lib/intrusion.rb +52 -52
  3. metadata +9 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8cec93ae0194185a1bc1ba65793e4c6f21daeae0
4
- data.tar.gz: ff74f7f95f692c9cac1c4fb0631d8584e122b567
2
+ SHA256:
3
+ metadata.gz: d6151639617a3b7284f48de675227ab59c8150b42b8134f697ebc8328b997984
4
+ data.tar.gz: 7ca22d37ccf3c3bf0acbea7d18515a4933c173b458d950c9e5cb975a19765529
5
5
  SHA512:
6
- metadata.gz: e574f9d89b9d5e3c7025382ea95d6956e59a3683d573dcb97d1a7fb119c69da5dc609d4d9903816ce9968d117d509f1f9ccaead21485d19f69fc5460c6af4e19
7
- data.tar.gz: 53d445041d4c05434cf9c9f9101fda9d6b520ef817550e46b9e4de0516334ba4aa3ca938185fbb8bde76fefaaf36fa02fd3a24ca90f039f7ab9170f64848289a
6
+ metadata.gz: d9fe80409942f12b85c4f2234550568b7d6a83b8b69ac4f8a60ec48dab59c98f8f58b7beb68cd40ef6b7dd3be804e0efb1aa659debde26a0e2dea5dc417f046f
7
+ data.tar.gz: 874aecd912cf2217d4c776393eae257c9e9debf75b24bbec577b51e6dfe8aec3186ce569c338717ff06cd5aad252c95669e60e1b3868b1fbd37162a320347a7c
data/lib/intrusion.rb CHANGED
@@ -1,52 +1,52 @@
1
- module Intrusion
2
-
3
- # check if ip is blocked
4
- def ids_is_blocked?(ip)
5
- ids_load.each { |d| return true if d[:ip] == ip and d[:counter] > 9 }
6
- return false
7
- end
8
-
9
- def ids_counter(ip)
10
- ids_load.each { |d| return d[:counter] if d[:ip] == ip }
11
- return 0
12
- end
13
-
14
- # report suspicious activity
15
- def ids_report!(ip, block=false)
16
- dt = ids_load
17
- found = nil
18
- dt.each { |d| found = d if d[:ip] == ip }
19
- if found
20
- block ? found[:counter] = 10 : found[:counter] += 1
21
- else
22
- dt << { ip: ip, counter: block ? 10 : 1 }
23
- end
24
-
25
- # update record
26
- return self.update_attributes(ids: dt.to_yaml)
27
- end
28
-
29
- # reset counter and stay
30
- def ids_unblock!(ip)
31
- dt = ids_load
32
- found = false
33
- dt.each { |d| found = d if d[:ip] == ip }
34
-
35
- if found
36
- dt.delete(found)
37
-
38
- # update
39
- return self.update_attributes(ids: dt.to_yaml)
40
-
41
- end
42
- return false
43
- end
44
-
45
- # convert yaml string helper
46
- def ids_load
47
- dt = ids.blank? ? [] : YAML::load(ids) rescue []
48
- dt = [] unless dt.class == Array
49
- return dt
50
- end
51
-
52
- end
1
+ # Intrusion main module
2
+ module Intrusion
3
+ # check if ip is blocked
4
+ def ids_is_blocked?(address)
5
+ ids_load.each do |d|
6
+ return true if d[:ip] == address && d[:counter] > 9
7
+ end
8
+ false
9
+ end
10
+
11
+ # return block counter of address
12
+ def ids_counter(address)
13
+ ids_load.each { |d| return d[:counter] if d[:ip] == address }
14
+ 0
15
+ end
16
+
17
+ # report suspicious activity
18
+ def ids_report!(address, block = false)
19
+ dt = ids_load
20
+ found = nil
21
+ dt.each { |d| found = d if d[:ip] == address }
22
+ if found
23
+ block ? found[:counter] = 10 : found[:counter] += 1
24
+ else
25
+ dt << { ip: address, counter: block ? 10 : 1 }
26
+ end
27
+
28
+ # update record
29
+ update_attributes(ids: dt.to_yaml)
30
+ end
31
+
32
+ # reset counter and stay
33
+ def ids_unblock!(address)
34
+ dt = ids_load
35
+ found = false
36
+ dt.each { |d| found = d if d[:ip] == address }
37
+
38
+ if found
39
+ dt.delete(found)
40
+ # update
41
+ return update_attributes(ids: dt.to_yaml)
42
+ end
43
+ false
44
+ end
45
+
46
+ # convert yaml string helper
47
+ def ids_load
48
+ dt = ids.blank? ? [] : YAML.load(ids, Intrusion) rescue []
49
+ dt = [] unless dt.class == Array
50
+ dt
51
+ end
52
+ end
metadata CHANGED
@@ -1,24 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intrusion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
- - Simon Wepfer
7
+ - Simon Duncombe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-30 00:00:00.000000000 Z
11
+ date: 2018-04-15 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Expand your objects with blockable feature. Useful for handling failed
14
- login attempts and security exceptions indicating hacking attempts.
15
- email: sw@netsense.ch
13
+ description: Intrusion is a gem helping you to block objects for IP addresses within
14
+ your Ruby on Rails Application.
15
+ email: sd@netsense.ch
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - lib/intrusion.rb
21
- homepage: http://netsense.ch/en
21
+ homepage: http://github.com/symontech/intrusion
22
22
  licenses: []
23
23
  metadata: {}
24
24
  post_install_message:
@@ -37,8 +37,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
37
37
  version: '0'
38
38
  requirements: []
39
39
  rubyforge_project:
40
- rubygems_version: 2.2.2
40
+ rubygems_version: 2.7.3
41
41
  signing_key:
42
42
  specification_version: 4
43
- summary: intrusion detection and prevention for rails apps
43
+ summary: intrusion detection and prevention for rails applications
44
44
  test_files: []