repsheet_visualizer 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e94ea6745421bc91f5402614572cc4ba36c36892
4
- data.tar.gz: 9f3ad8a26e7c2f161f82397b3a883b1d013fe104
3
+ metadata.gz: 1b737b725b7160b792f3ea3b2cb515e8a72b938a
4
+ data.tar.gz: 6c353ceeb6a2c36b639fc4822fd0c79c0ffe5133
5
5
  SHA512:
6
- metadata.gz: e4b606bc0185ac1331cf4216bbfe570de19f0bfe510bf38d698c78869ca4d744de84493d486acff3a28198b8fa42ca397e540ad832d083c6c5263aa3d23622f6
7
- data.tar.gz: 357db6d3cfb1fa9eba2fad54487f644ca0f38e2de0777c2c4cc3ddd5d2ef7d2a9f971bf0fd63c11f9112c6708430737a8a1a25529968c4b14a63cffdc38b7b49
6
+ metadata.gz: 4c154468545845141adf4d6d3d1cf96b35fc33c269bbe456f54862832c366ac554bacb28c2139de1e5ed5793d08b9c1be51b8222a9e296f45cf138cca54ed850
7
+ data.tar.gz: 41464c6aff82d33219ad62596123931ce7fa7e5f0801f9d30957cbb7e0ee5274545bcdb013b5699dc9e68feec703e740b9cf733a6fd3c357310d163046884b48
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- repsheet_visualizer (0.1.8)
4
+ repsheet_visualizer (0.1.9)
5
5
  geoip
6
6
  json
7
7
  redis
@@ -18,6 +18,10 @@ class RepsheetVisualizer < Sinatra::Base
18
18
  "allow"
19
19
  end
20
20
  end
21
+
22
+ def h(text)
23
+ Rack::Utils.escape_html(text)
24
+ end
21
25
  end
22
26
 
23
27
  def redis_connection
@@ -41,7 +45,6 @@ class RepsheetVisualizer < Sinatra::Base
41
45
  defined?(settings.redis_expiry) ? (settings.redis_expiry * 60 * 60) : (24 * 60 * 60)
42
46
  end
43
47
 
44
- # This is the actual application
45
48
  get '/' do
46
49
  @suspects, @blacklisted = Backend.summary(redis_connection)
47
50
  erb :actors
@@ -59,7 +62,8 @@ class RepsheetVisualizer < Sinatra::Base
59
62
 
60
63
  get '/activity/:ip' do
61
64
  @ip = params[:ip]
62
- @data = Backend.activity(redis_connection)
65
+ @data = Backend.activity(redis_connection, @ip)
66
+ @action = action(@ip)
63
67
  erb :activity
64
68
  end
65
69
 
@@ -24,8 +24,8 @@ class Backend
24
24
  [{},{}]
25
25
  end
26
26
 
27
- def self.activity(connection)
28
- connection.lrange("#{@ip}:requests", 0, -1)
27
+ def self.activity(connection, actor)
28
+ connection.lrange("#{actor}:requests", 0, -1)
29
29
  end
30
30
 
31
31
  def self.worldview(connection, database)
@@ -52,10 +52,10 @@ class Backend
52
52
  next if connection.get("#{actor}:repsheet:blacklist") == "true"
53
53
  suspects[actor] = Hash.new 0
54
54
  suspects[actor][:detected] = triggered_rules(connection, actor).join(", ")
55
- suspects[actor][:total] = connection.zscore("offenders", actor).to_i
55
+ suspects[actor][:total] = score_actor(connection, actor, nil, true)
56
56
  end
57
57
 
58
- [suspects, blacklist(connection)]
58
+ [suspects, blacklist(connection, true)]
59
59
  end
60
60
 
61
61
  def self.standard(connection)
@@ -68,29 +68,31 @@ class Backend
68
68
  if !detected.empty? && blacklist != "true"
69
69
  suspects[actor] = Hash.new 0
70
70
  suspects[actor][:detected] = detected.join(", ")
71
- suspects[actor][:total] = score_actor(connection, actor)
71
+ suspects[actor][:total] = score_actor(connection, actor, detected)
72
72
  end
73
73
  end
74
74
 
75
75
  [suspects, blacklist(connection)]
76
76
  end
77
77
 
78
- def self.blacklist(connection)
78
+ def self.blacklist(connection, optimized=false)
79
79
  blacklisted = {}
80
80
 
81
81
  connection.keys("*:*:blacklist").map {|d| d.split(":").first}.reject {|ip| ip.empty?}.each do |actor|
82
82
  next unless connection.get("#{actor}:repsheet:blacklist") == "true"
83
-
83
+ detected = triggered_rules(connection, actor)
84
84
  blacklisted[actor] = Hash.new 0
85
- blacklisted[actor][:detected] = triggered_rules(connection, actor).join(", ")
86
- blacklisted[actor][:total] = score_actor(connection, actor)
85
+ blacklisted[actor][:detected] = detected.join(", ")
86
+ blacklisted[actor][:total] = score_actor(connection, actor, detected, optimized)
87
87
  end
88
88
 
89
89
  blacklisted
90
90
  end
91
91
 
92
- def self.score_actor(connection, actor)
93
- connection.zrange("#{actor}:detected", 0, -1).reduce(0) do |memo, rule|
92
+ def self.score_actor(connection, actor, detected, optimized=false)
93
+ return connection.zscore("offenders", "#{actor}").to_i
94
+
95
+ detected.reduce(0) do |memo, rule|
94
96
  memo += connection.zscore("#{actor}:detected", rule).to_i
95
97
  end
96
98
  end
@@ -10,15 +10,15 @@
10
10
  <link href="<%= @mount %>css/bootstrap.css" rel="stylesheet">
11
11
  <style>
12
12
  body {
13
- padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
13
+ padding-top: 60px; /* 60px to make the container go all the way to the bottom of the topbar */
14
14
  }
15
15
  </style>
16
16
  <link href="<%= @mount %>css/bootstrap-responsive.css" rel="stylesheet">
17
17
 
18
18
  <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
19
19
  <!--[if lt IE 9]>
20
- <script src="<%= @mount %>javascripts/html5shiv.js"></script>
21
- <![endif]-->
20
+ <script src="<%= @mount %>javascripts/html5shiv.js"></script>
21
+ <![endif]-->
22
22
 
23
23
  <link rel="shortcut icon" href="/<%= @mount %>/images/favicon.ico">
24
24
 
@@ -47,9 +47,9 @@
47
47
  <h2>Activity for <%= @ip %></h2>
48
48
  <form method="post" action="<%= @mount %>action" class="button_to">
49
49
  <div>
50
- <input value="<%= action(@ip) %>" type="submit" />
50
+ <input value="<%= @action %>" type="submit" />
51
51
  <input type="hidden" name="ip" value="<%= @ip %>"/>
52
- <input type="hidden" name="action" value="<%= action(@ip) %>"/>
52
+ <input type="hidden" name="action" value="<%= @action %>"/>
53
53
  </div>
54
54
  </form>
55
55
 
@@ -59,7 +59,7 @@
59
59
 
60
60
  <ul>
61
61
  <% @data.each do |action| %>
62
- <li><%= action %></li>
62
+ <li><%= h action %></li>
63
63
  <% end %>
64
64
  </ul>
65
65
  </div>
@@ -128,9 +128,9 @@
128
128
  <td width=90>
129
129
  <form method="post" action="<%= @mount %>action" class="button_to">
130
130
  <div>
131
- <input value="<%= action(actor) %>" type="submit" />
131
+ <input value="<%= action(actor, 'false') %>" type="submit" />
132
132
  <input type="hidden" name="ip" value="<%= actor %>"/>
133
- <input type="hidden" name="action" value="<%= action(actor) %>"/>
133
+ <input type="hidden" name="action" value="<%= action(actor, 'false') %>"/>
134
134
  </div>
135
135
  </form>
136
136
  </td>
@@ -166,9 +166,9 @@
166
166
  <td width=70>
167
167
  <form method="post" action="<%= @mount %>action" class="button_to">
168
168
  <div>
169
- <input value="<%= action(actor, details[:blacklist]) %>" type="submit" />
169
+ <input value="<%= action(actor, 'true') %>" type="submit" />
170
170
  <input type="hidden" name="ip" value="<%= actor %>"/>
171
- <input type="hidden" name="action" value="<%= action(actor, details[:blacklist]) %>"/>
171
+ <input type="hidden" name="action" value="<%= action(actor, 'true') %>"/>
172
172
  </div>
173
173
  </form>
174
174
  </td>
@@ -1,3 +1,3 @@
1
1
  module RepsheetVisualizer
2
- VERSION = "0.1.8"
2
+ VERSION = "0.1.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repsheet_visualizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bedra