Skip to content
This repository was archived by the owner on Feb 25, 2021. It is now read-only.

Commit 82f9b98

Browse files
committed
spinner to let users know scan status
1 parent 91344f3 commit 82f9b98

File tree

8 files changed

+55
-6
lines changed

8 files changed

+55
-6
lines changed

app/assets/images/spinner.svg

+1
Loading

app/assets/javascripts/scans.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
$(function () {
2+
var loaded = false;
3+
var sid = $('#vulnerability-container').data('scan');
24
fetch_analytics();
35

46
function fetch_analytics() {
5-
var sid = $('#vulnerability-container').data('scan')
67
if (sid == undefined) {
78
return;
89
}

app/controllers/scans_controller.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,21 @@ def index
88

99
def show
1010
@vulnerabilities ||= @scan.vulnerabilities
11+
respond_to do |format|
12+
format.html
13+
format.json {
14+
render json: {
15+
scan: @scan,
16+
vulnerabilities: @vulnerabilities
17+
}
18+
}
19+
end
1120
end
1221

1322
def create
1423
url = params[:url]
1524
parameters = params[:parameters]
16-
method = params[:method].nil? ? "" : JSON.generate(params[:method])
25+
method = params[:method].nil? ? JSON.generate(['GET']) : JSON.generate(params[:method])
1726
headers = params[:headers]
1827
json = params[:json]
1928

app/views/scans/index.html.erb

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<th>#</th>
66
<th>URL</th>
77
<th>Vulnerability count</th>
8+
<th>Status</th>
89
<th></th>
910
</tr>
1011
</thead>
@@ -14,6 +15,7 @@
1415
<td><%= link_to scan_path(scan.id), scan_path(scan.id) %></td>
1516
<td><%= link_to scan.url, scan.url %></td>
1617
<td><%= scan.vulnerabilities.count %></td>
18+
<td><%= scan.status %></td>
1719
<td><%= link_to "Delete scan", scan_path(scan), method: :delete, class: 'btn btn-danger' %>
1820
</tr>
1921
<% end %>

app/views/scans/show.html.erb

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
<div class=" col-md-12">
1+
<div class="col-md-12">
22
<%= render partial: 'details', locals: { scan: @scan } %>
33

44
<div class="card card-outline-secondary text-xs-center">
55
<div class="card-block">
6+
<div id="spinner" style="display: none;">
7+
<%= image_tag 'spinner.svg' %>
8+
</div>
69
<table class="table">
710
<thead>
811
<tr>
@@ -34,3 +37,25 @@
3437
</div>
3538
</div>
3639
</div>
40+
41+
<%= javascript_tag do %>
42+
<% if @scan.status == 'processing' %>
43+
function fetch_scan() {
44+
$.ajax({
45+
url: '/scans/' + sid + '.json',
46+
method: 'GET',
47+
beforeSend: function() {
48+
$('#spinner').show();
49+
},
50+
success: function(data) {
51+
var status = data['scan']['status'];
52+
if (status == 'completed') {
53+
location.reload();
54+
}
55+
}
56+
});
57+
}
58+
var sid = $('#vulnerability-container').data('scan');
59+
setInterval(fetch_scan, 3000);
60+
<% end %>
61+
<% end %>

app/workers/scan_vulnerability_worker.rb

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def perform(scan_id, options = {})
2727
end
2828
end
2929
end
30+
scan.update_attributes(status: 'completed')
3031
rescue ActiveRecord::RecordNotFound => e
3132
Rails.logger.info e.message
3233
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class AddStatusToScans < ActiveRecord::Migration
2+
def up
3+
add_column :scans, :status, :string, default: 'processing'
4+
end
5+
6+
def down
7+
remove_column :scans, :status
8+
end
9+
end

db/schema.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
#
1212
# It's strongly recommended that you check this file into your version control system.
1313

14-
ActiveRecord::Schema.define(version: 20161011064845) do
14+
ActiveRecord::Schema.define(version: 20161014024647) do
1515

1616
create_table "scans", force: :cascade do |t|
1717
t.string "url"
1818
t.string "sid"
1919
t.string "parameters"
2020
t.string "method"
2121
t.string "cookies"
22-
t.datetime "created_at", null: false
23-
t.datetime "updated_at", null: false
22+
t.datetime "created_at", null: false
23+
t.datetime "updated_at", null: false
2424
t.boolean "json", default: false
2525
t.integer "user_id"
26+
t.string "status", default: "processing"
2627
end
2728

2829
add_index "scans", ["user_id"], name: "index_scans_on_user_id"

0 commit comments

Comments
 (0)