intrusion 0.1.4 → 0.1.5

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 +7 -0
  2. data/lib/intrusion.rb +15 -11
  3. metadata +10 -11
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8cec93ae0194185a1bc1ba65793e4c6f21daeae0
4
+ data.tar.gz: ff74f7f95f692c9cac1c4fb0631d8584e122b567
5
+ SHA512:
6
+ metadata.gz: e574f9d89b9d5e3c7025382ea95d6956e59a3683d573dcb97d1a7fb119c69da5dc609d4d9903816ce9968d117d509f1f9ccaead21485d19f69fc5460c6af4e19
7
+ data.tar.gz: 53d445041d4c05434cf9c9f9101fda9d6b520ef817550e46b9e4de0516334ba4aa3ca938185fbb8bde76fefaaf36fa02fd3a24ca90f039f7ab9170f64848289a
data/lib/intrusion.rb CHANGED
@@ -5,21 +5,25 @@ module Intrusion
5
5
  ids_load.each { |d| return true if d[:ip] == ip and d[:counter] > 9 }
6
6
  return false
7
7
  end
8
-
8
+
9
+ def ids_counter(ip)
10
+ ids_load.each { |d| return d[:counter] if d[:ip] == ip }
11
+ return 0
12
+ end
13
+
9
14
  # report suspicious activity
10
15
  def ids_report!(ip, block=false)
11
16
  dt = ids_load
12
- found = false
17
+ found = nil
13
18
  dt.each { |d| found = d if d[:ip] == ip }
14
19
  if found
15
20
  block ? found[:counter] = 10 : found[:counter] += 1
16
21
  else
17
- dt << { :ip => ip, :counter => 1 }
22
+ dt << { ip: ip, counter: block ? 10 : 1 }
18
23
  end
19
24
 
20
- # update
21
- self.ids = dt.to_yaml
22
- return self.save
25
+ # update record
26
+ return self.update_attributes(ids: dt.to_yaml)
23
27
  end
24
28
 
25
29
  # reset counter and stay
@@ -29,19 +33,19 @@ module Intrusion
29
33
  dt.each { |d| found = d if d[:ip] == ip }
30
34
 
31
35
  if found
32
- dt.delete found
36
+ dt.delete(found)
33
37
 
34
38
  # update
35
- self.ids = dt.to_yaml
36
- return self.save
39
+ return self.update_attributes(ids: dt.to_yaml)
40
+
37
41
  end
38
42
  return false
39
43
  end
40
44
 
41
45
  # convert yaml string helper
42
46
  def ids_load
43
- dt = []
44
- dt = YAML::load(ids) if ids
47
+ dt = ids.blank? ? [] : YAML::load(ids) rescue []
48
+ dt = [] unless dt.class == Array
45
49
  return dt
46
50
  end
47
51
 
metadata CHANGED
@@ -1,45 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intrusion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
5
- prerelease:
4
+ version: 0.1.5
6
5
  platform: ruby
7
6
  authors:
8
7
  - Simon Wepfer
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000 Z
11
+ date: 2014-11-30 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: intrusion detection and prevention for rails apps
13
+ description: Expand your objects with blockable feature. Useful for handling failed
14
+ login attempts and security exceptions indicating hacking attempts.
15
15
  email: sw@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
21
+ homepage: http://netsense.ch/en
22
22
  licenses: []
23
+ metadata: {}
23
24
  post_install_message:
24
25
  rdoc_options: []
25
26
  require_paths:
26
27
  - lib
27
28
  required_ruby_version: !ruby/object:Gem::Requirement
28
- none: false
29
29
  requirements:
30
- - - ! '>='
30
+ - - ">="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0'
33
33
  required_rubygems_version: !ruby/object:Gem::Requirement
34
- none: false
35
34
  requirements:
36
- - - ! '>='
35
+ - - ">="
37
36
  - !ruby/object:Gem::Version
38
37
  version: '0'
39
38
  requirements: []
40
39
  rubyforge_project:
41
- rubygems_version: 1.8.15
40
+ rubygems_version: 2.2.2
42
41
  signing_key:
43
- specification_version: 3
42
+ specification_version: 4
44
43
  summary: intrusion detection and prevention for rails apps
45
44
  test_files: []