repsheet_visualizer 0.0.7 → 0.0.8
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.
- data/Gemfile.lock +1 -1
- data/lib/repsheet_visualizer/application/app.rb +65 -46
- data/lib/repsheet_visualizer/application/public/javascripts/application.js +4 -1
- data/lib/repsheet_visualizer/application/views/activity.erb +1 -1
- data/lib/repsheet_visualizer/application/views/actors.erb +8 -6
- data/lib/repsheet_visualizer/version.rb +1 -1
- metadata +4 -4
data/Gemfile.lock
CHANGED
@@ -4,6 +4,11 @@ require 'redis'
|
|
4
4
|
require 'json'
|
5
5
|
|
6
6
|
class RepsheetVisualizer < Sinatra::Base
|
7
|
+
# Grab the mount point before every request
|
8
|
+
before do
|
9
|
+
@mount = mount
|
10
|
+
end
|
11
|
+
|
7
12
|
helpers do
|
8
13
|
def action(data)
|
9
14
|
if data[:blacklist].nil? || data[:blacklist] == "false"
|
@@ -14,10 +19,10 @@ class RepsheetVisualizer < Sinatra::Base
|
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
22
|
+
# Settings methods
|
17
23
|
def redis_connection
|
18
24
|
host = defined?(settings.redis_host) ? settings.redis_host : "localhost"
|
19
25
|
port = defined?(settings.redis_port) ? settings.redis_port : 6379
|
20
|
-
|
21
26
|
Redis.new(:host => host, :port => port)
|
22
27
|
end
|
23
28
|
|
@@ -32,64 +37,78 @@ class RepsheetVisualizer < Sinatra::Base
|
|
32
37
|
defined?(settings.mount) ? (settings.mount + "/") : "/"
|
33
38
|
end
|
34
39
|
|
35
|
-
get
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
# TODO: These methods should get moved out to another place
|
41
|
+
def summary(connection)
|
42
|
+
actors = {}
|
43
|
+
connection.keys("*:requests").map {|d| d.split(":").first}.reject {|ip| ip.empty?}.each do |actor|
|
44
|
+
actors[actor] = Hash.new 0
|
45
|
+
actors[actor][:repsheet] = connection.get("#{actor}:repsheet")
|
46
|
+
actors[actor][:blacklist] = connection.get("#{actor}:repsheet:blacklist")
|
47
|
+
actors[actor][:detected] = connection.smembers("#{actor}:detected").join(", ")
|
48
|
+
connection.smembers("#{actor}:detected").each do |rule|
|
49
|
+
actors[actor][:total] += connection.get("#{actor}:#{rule}:count").to_i
|
50
|
+
end
|
44
51
|
end
|
45
|
-
|
46
|
-
erb :actors
|
52
|
+
actors
|
47
53
|
end
|
48
54
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
def breakdown(connection)
|
56
|
+
data = {}
|
57
|
+
offenders = connection.keys("*:repsheet").map {|o| o.split(":").first}
|
58
|
+
offenders.each do |offender|
|
59
|
+
data[offender] = {"totals" => {}}
|
60
|
+
connection.smembers("#{offender}:detected").each do |rule|
|
61
|
+
data[offender]["totals"][rule] = connection.get "#{offender}:#{rule}:count"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
aggregate = Hash.new 0
|
65
|
+
data.each {|ip,data| data["totals"].each {|rule,count| aggregate[rule] += count.to_i}}
|
66
|
+
[data, aggregate]
|
55
67
|
end
|
56
68
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
69
|
+
def activity(connection)
|
70
|
+
connection.lrange("#{@ip}:requests", 0, -1)
|
71
|
+
end
|
72
|
+
|
73
|
+
def worldview(connection, database)
|
74
|
+
data = {}
|
75
|
+
offenders = connection.keys("*:repsheet*").map {|o| o.split(":").first}
|
76
|
+
offenders.each do |address|
|
77
|
+
details = database.country(address)
|
78
|
+
data[address] = [details.latitude, details.longitude]
|
63
79
|
end
|
64
|
-
|
65
|
-
|
80
|
+
data
|
81
|
+
end
|
82
|
+
|
83
|
+
# This is the actual application
|
84
|
+
get '/' do
|
85
|
+
@data = summary(redis_connection)
|
86
|
+
erb :actors
|
66
87
|
end
|
67
88
|
|
68
89
|
get '/breakdown' do
|
69
|
-
|
70
|
-
@data = {}
|
71
|
-
offenders = redis.keys("*:repsheet").map {|o| o.split(":").first}
|
72
|
-
offenders.each do |offender|
|
73
|
-
@data[offender] = {"totals" => {}}
|
74
|
-
redis.smembers("#{offender}:detected").each do |rule|
|
75
|
-
@data[offender]["totals"][rule] = redis.get "#{offender}:#{rule}:count"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
@aggregate = Hash.new 0
|
79
|
-
@data.each {|ip,data| data["totals"].each {|rule,count| @aggregate[rule] += count.to_i}}
|
80
|
-
@mount = mount
|
90
|
+
@data, @aggregate = breakdown(redis_connection)
|
81
91
|
erb :breakdown
|
82
92
|
end
|
83
93
|
|
84
94
|
get '/worldview' do
|
85
|
-
|
86
|
-
redis = redis_connection
|
87
|
-
@data = {}
|
88
|
-
offenders = redis.keys("*:repsheet*").map {|o| o.split(":").first}
|
89
|
-
offenders.each do |address|
|
90
|
-
details = db.country(address)
|
91
|
-
@data[address] = [details.latitude, details.longitude]
|
92
|
-
end
|
95
|
+
@data = worldview(redis_connection, geoip_database)
|
93
96
|
erb :worldview
|
94
97
|
end
|
98
|
+
|
99
|
+
get '/activity/:ip' do
|
100
|
+
@ip = params[:ip]
|
101
|
+
@data = activity(redis_connection)
|
102
|
+
erb :activity
|
103
|
+
end
|
104
|
+
|
105
|
+
post '/action' do
|
106
|
+
connection = redis_connection
|
107
|
+
if params["action"] == "allow"
|
108
|
+
connection.set("#{params[:ip]}:repsheet:blacklist", "false")
|
109
|
+
else
|
110
|
+
connection.set("#{params[:ip]}:repsheet:blacklist", "true")
|
111
|
+
end
|
112
|
+
redirect back
|
113
|
+
end
|
95
114
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
$(document).ready(function() {
|
2
|
-
|
2
|
+
// Bring up tablesorter and sort by people who have committed the
|
3
|
+
// most number of ModSecurity violations and who are not yet on
|
4
|
+
// the blacklist
|
5
|
+
$("#actors").tablesorter({sortList: [[2,0], [4,1]],widgets: ['zebra']});
|
3
6
|
});
|
4
7
|
|
5
8
|
function angle(d) {
|
@@ -56,24 +56,26 @@
|
|
56
56
|
<th>Repsheet?</th>
|
57
57
|
<th>Blacklist?</th>
|
58
58
|
<th>Triggered Rules</th>
|
59
|
+
<th>Offenses</th>
|
59
60
|
<th>Activity</th>
|
60
61
|
<th>Action</th>
|
61
62
|
</tr>
|
62
63
|
</thead>
|
63
64
|
<tbody>
|
64
|
-
<% @
|
65
|
+
<% @data.each do |actor,details| %>
|
65
66
|
<tr>
|
66
67
|
<td><%= actor %></td>
|
67
|
-
<td><%=
|
68
|
-
<td><%=
|
69
|
-
<td><%=
|
68
|
+
<td><%= details[:repsheet] %></td>
|
69
|
+
<td><%= details[:blacklist] %></td>
|
70
|
+
<td><%= details[:detected] %></td>
|
71
|
+
<td><%= details[:total] %></td>
|
70
72
|
<td><a href="<%= @mount %>activity/<%= actor %>">Click to see activity</a>
|
71
73
|
<td>
|
72
74
|
<form method="post" action="<%= @mount %>action" class="button_to">
|
73
75
|
<div>
|
74
|
-
<input value="<%= action(
|
76
|
+
<input value="<%= action(details) %>" type="submit" />
|
75
77
|
<input type="hidden" name="ip" value="<%= actor %>"/>
|
76
|
-
<input type="hidden" name="action" value="<%= action(
|
78
|
+
<input type="hidden" name="action" value="<%= action(details) %>"/>
|
77
79
|
</div>
|
78
80
|
</form>
|
79
81
|
</td>
|
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.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-29 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: geoip
|
@@ -176,7 +176,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
176
176
|
version: '0'
|
177
177
|
segments:
|
178
178
|
- 0
|
179
|
-
hash: -
|
179
|
+
hash: -3255625678553513827
|
180
180
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
181
181
|
none: false
|
182
182
|
requirements:
|
@@ -185,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
version: '0'
|
186
186
|
segments:
|
187
187
|
- 0
|
188
|
-
hash: -
|
188
|
+
hash: -3255625678553513827
|
189
189
|
requirements: []
|
190
190
|
rubyforge_project:
|
191
191
|
rubygems_version: 1.8.25
|