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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/repsheet_visualizer/application/app.rb +6 -2
- data/lib/repsheet_visualizer/application/backend.rb +13 -11
- data/lib/repsheet_visualizer/application/views/activity.erb +6 -6
- data/lib/repsheet_visualizer/application/views/actors.erb +4 -4
- data/lib/repsheet_visualizer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b737b725b7160b792f3ea3b2cb515e8a72b938a
|
4
|
+
data.tar.gz: 6c353ceeb6a2c36b639fc4822fd0c79c0ffe5133
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c154468545845141adf4d6d3d1cf96b35fc33c269bbe456f54862832c366ac554bacb28c2139de1e5ed5793d08b9c1be51b8222a9e296f45cf138cca54ed850
|
7
|
+
data.tar.gz: 41464c6aff82d33219ad62596123931ce7fa7e5f0801f9d30957cbb7e0ee5274545bcdb013b5699dc9e68feec703e740b9cf733a6fd3c357310d163046884b48
|
data/Gemfile.lock
CHANGED
@@ -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("#{
|
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
|
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] =
|
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.
|
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
|
-
|
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
|
-
|
21
|
-
|
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
|
50
|
+
<input value="<%= @action %>" type="submit" />
|
51
51
|
<input type="hidden" name="ip" value="<%= @ip %>"/>
|
52
|
-
<input type="hidden" name="action" value="<%= action
|
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,
|
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,
|
171
|
+
<input type="hidden" name="action" value="<%= action(actor, 'true') %>"/>
|
172
172
|
</div>
|
173
173
|
</form>
|
174
174
|
</td>
|