Sync up recent work, merge up schemas - warvox - VoIP based wardialing tool, forked from rapid7/warvox.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit ed69a4cfab7489d66d8c9946e8b7531d293e563c
(DIR) parent 08c1cd940e4cce5310d4d80dc68770d802eb7290
(HTM) Author: HD Moore <hd_moore@rapid7.com>
Date: Sat, 12 Jan 2013 20:57:08 -0600
Sync up recent work, merge up schemas
Diffstat:
M Gemfile | 3 +--
M Gemfile.lock | 9 +++++++++
M app/assets/stylesheets/bootstrap_a… | 32 +++++++++++++++++++++++++++++++
M app/controllers/application_contro… | 5 ++++-
M app/controllers/jobs_controller.rb | 7 +++++--
M app/controllers/projects_controlle… | 1 +
M app/models/call.rb | 10 ++++++++++
M app/models/job.rb | 7 +++++++
M app/views/projects/show.html.erb | 104 ++++++++++++++++++++++++-------
M app/views/shared/graphs/_call_resu… | 7 -------
M app/views/shared/graphs/_lines_by_… | 5 -----
A app/views/shared/graphs/_sparkline… | 67 +++++++++++++++++++++++++++++++
M db/migrate/20121228171549_initial_… | 28 ++++++++++++++++++++++++++--
D db/migrate/20130106000000_add_inde… | 29 -----------------------------
A db/migrate/20130113004653_create_r… | 40 +++++++++++++++++++++++++++++++
M db/schema.rb | 21 ++++++++++++++++++---
M lib/warvox/jobs/analysis.rb | 2 +-
17 files changed, 301 insertions(+), 76 deletions(-)
---
(DIR) diff --git a/Gemfile b/Gemfile
@@ -33,8 +33,7 @@ gem 'rails_bootstrap_navbar'
gem 'less-rails-bootstrap'
gem 'therubyracer'
-
-# gem "therubyracer", :group => :assets, :platform => :ruby
+gem 'reportable', :git => 'git@github.com:hmoore-r7/reportable.git', :require => 'saulabs/reportable'
gem 'will_paginate', '~> 3.0'
gem 'will_paginate-bootstrap'
(DIR) diff --git a/Gemfile.lock b/Gemfile.lock
@@ -6,6 +6,14 @@ GIT
activerecord (~> 3.2.0)
pg_array_parser (~> 0.0.8)
+GIT
+ remote: git@github.com:hmoore-r7/reportable.git
+ revision: f8532eeb704c511bb75b5bd4fd9656243c9b118b
+ specs:
+ reportable (1.2.0)
+ activerecord (>= 3.0)
+ activesupport (>= 3.0.0)
+
GEM
remote: http://rubygems.org/
specs:
@@ -171,6 +179,7 @@ DEPENDENCIES
rails (>= 3.2.11)
rails-settings-cached
rails_bootstrap_navbar
+ reportable!
sass-rails (~> 3.2.3)
therubyracer
thin
(DIR) diff --git a/app/assets/stylesheets/bootstrap_and_overrides.css.less b/app/assets/stylesheets/bootstrap_and_overrides.css.less
@@ -39,6 +39,9 @@
@lightGray: #666666;
@blue: #0197b8;
+@darkOrange: #BB4607;
+@lightOrange: #F8ECE6;
+
@linkColor: @blue;
@linkColorHover: @darkGray;
@@ -81,10 +84,39 @@
// End of DataTables
+
+.sparkline {
+ width: 100px;
+ height: 20px;
+}
+
.call-detail {
font-size: 10px;
}
+.project-header {
+ margin-bottom: 30px;
+ border-bottom: 1px solid #eeeeee;
+}
+
+.stat-box {
+ padding: 10px;
+
+ background-color: #eeeeee;
+ border: 1px solid #bbbbbb;
+ font-size: 18px;
+ font-weight: bold;
+ color: @darkGray;
+ width: 65px;
+ margin: auto auto;
+ text-align: center;
+}
+
+.stat-subtitle {
+ text-align: center;
+ font-size: 12px;
+ margin-top: 1px;
+}
.fwd_match_span {
width: 100px;
(DIR) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
@@ -1,10 +1,13 @@
class ApplicationController < ActionController::Base
- helper :all
protect_from_forgery
+ helper :all
+
helper_method :current_user_session, :current_user
before_filter :require_user, :load_project
add_breadcrumb :projects, :root_path
+
+
private
def current_user_session
(DIR) diff --git a/app/controllers/jobs_controller.rb b/app/controllers/jobs_controller.rb
@@ -145,7 +145,7 @@ class JobsController < ApplicationController
respond_to do |format|
format.html
format.xml { render :xml => @job }
- end
+ end
end
def purge_calls
@@ -158,7 +158,7 @@ class JobsController < ApplicationController
def dialer
@job = Job.new(params[:job])
- @job.created_by = current_user.login
+ @job.created_by = @current_user.login
@job.task = 'dialer'
@job.range.gsub!(/[^0-9X:,\n]/, '')
@job.cid_mask.gsub!(/[^0-9X]/, '') if @job.cid_mask != "SELF"
@@ -185,6 +185,7 @@ class JobsController < ApplicationController
:task => 'analysis', :scope => 'job', :target_id => @job.id, :force => true,
:project_id => @project.id, :status => 'submitted'
})
+ @new.created_by = @current_user.login
respond_to do |format|
if @new.schedule
flash[:notice] = 'Analysis job was successfully created.'
@@ -215,6 +216,8 @@ class JobsController < ApplicationController
})
end
+ @new.created_by = @current_user.login
+
respond_to do |format|
if @new.schedule
flash[:notice] = 'Analysis job was successfully created.'
(DIR) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
@@ -23,6 +23,7 @@ class ProjectsController < ApplicationController
format.html # show.html.erb
format.xml { render :xml => @project }
end
+
end
# GET /projects/new
(DIR) diff --git a/app/models/call.rb b/app/models/call.rb
@@ -1,4 +1,14 @@
class Call < ActiveRecord::Base
+
+ reportable :hourly, :aggregation => :count, :grouping => :hour, :live_data => true, :cacheable => false
+ reportable :daily, :aggregation => :count, :grouping => :day, :live_data => true, :cacheable => false
+ reportable :weekly, :aggregation => :count, :grouping => :week, :live_data => true, :cacheable => false
+ reportable :monthly, :aggregation => :count, :grouping => :month, :live_data => true, :cacheable => false
+ reportable :analyzed_hourly, :aggregation => :count, :grouping => :hour, :date_column => :analysis_completed_at, :live_data => true, :cacheable => false
+ reportable :analyzed_daily, :aggregation => :count, :grouping => :day, :date_column => :analysis_completed_at, :live_data => true, :cacheable => false
+ reportable :analyzed_weekly, :aggregation => :count, :grouping => :week, :date_column => :analysis_completed_at, :live_data => true, :cacheable => false
+ reportable :analyzed_monthly, :aggregation => :count, :grouping => :month, :date_column => :analysis_completed_at, :live_data => true, :cacheable => false
+
belongs_to :project
belongs_to :provider
belongs_to :job
(DIR) diff --git a/app/models/job.rb b/app/models/job.rb
@@ -1,5 +1,10 @@
class Job < ActiveRecord::Base
+ reportable :hourly, :aggregation => :count, :grouping => :hour, :date_column => :created_at, :cacheable => false
+ reportable :daily, :aggregation => :count, :grouping => :day, :date_column => :created_at, :cacheable => false
+ reportable :weeky, :aggregation => :count, :grouping => :week, :date_column => :created_at, :cacheable => false
+ reportable :monthly, :aggregation => :count, :grouping => :month, :date_column => :created_at, :cacheable => false
+
class JobValidator < ActiveModel::Validator
def validate(record)
case record.task
@@ -100,6 +105,8 @@ class Job < ActiveRecord::Base
:seconds => self.seconds.to_i,
:cid_mask => self.cid_mask
})
+ $stderr.puts self.inspect
+
return self.save
when 'analysis'
self.status = 'submitted'
(DIR) diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb
@@ -1,24 +1,80 @@
-<h1 class='title'>View Project</h1>
-<p>
- <b>Name:</b>
- <%=h @project.name %>
-</p>
-
-<p>
- <b>Description:</b>
- <%=h @project.description %>
-</p>
-
-<p>
- <b>Default Include:</b>
- <%=h @project.included %>
-</p>
-
-<p>
- <b>Default Exclude:</b>
- <%=h @project.excluded %>
-</p>
-
-
-<%= link_to 'Edit', edit_project_path(@project) %> |
-<%= link_to 'Back', projects_path %>
+
+
+
+<div class="row-fluid">
+ <div class="span12">
+ <a class="btn btn-small pull-right" href="<%= edit_project_path(@project) %>" rel="tooltip" title="Update project settings"><i class="icon-wrench"></i> Settings</a>
+ <h1 class='title'>Project <%= @project.name %></h1>
+ <p class='project-header'><%=h @project.description %></p>
+ </div>
+</div>
+
+
+<div class="row-fluid">
+ <div class="span2">
+ <div class="stat-box">
+ <div><%= number_with_delimiter( @project.calls.count ) %></div>
+ <span class="stat-subtitle">Calls</span>
+ </div>
+ </div>
+ <div class="span2">
+ <div class="stat-box">
+ <div><%= number_with_delimiter( @project.calls.where(:answered => true).count ) %></div>
+ <span class="stat-subtitle">Answered</span>
+ </div>
+ </div>
+ <div class="span2">
+ <div class="stat-box">
+ <div><%= number_with_delimiter( @project.calls.where('analysis_completed_at IS NOT NULL').count ) %></div>
+ <span class="stat-subtitle">Analyzed</span>
+ </div>
+ </div>
+
+ <div class="span2">
+ <div class="stat-box">
+ <div><%= number_with_delimiter( @project.calls.where(:line_type => 'voice').count ) %></div>
+ <span class="stat-subtitle">Voice</span>
+ </div>
+ </div>
+ <div class="span2">
+ <div class="stat-box">
+ <div><%= number_with_delimiter( @project.calls.where(:line_type => 'fax').count ) %></div>
+ <span class="stat-subtitle">Fax</span>
+ </div>
+ </div>
+ <div class="span2">
+ <div class="stat-box">
+ <div><%= number_with_delimiter( @project.calls.where(:line_type => 'modem').count ) %></div>
+ <span class="stat-subtitle">Modem</span>
+ </div>
+ </div>
+</div>
+
+
+
+<div class="row-fluid">
+ <div class="span2">
+ <%= render :partial => 'shared/graphs/sparkline', :locals => { :points => @project.calls.hourly_report.to_a.map{|x| x[1] } } %>
+ Calls/Hour
+ </div>
+ <div class="span2">
+ <%= render :partial => 'shared/graphs/sparkline', :locals => { :points => @project.calls.daily_report.to_a.map{|x| x[1] } } %>
+ Calls/Day
+ </div>
+ <div class="span2">
+ <%= render :partial => 'shared/graphs/sparkline', :locals => { :points => @project.calls.weekly_report.to_a.map{|x| x[1] } } %>
+ Calls/Week
+ </div>
+ <div class="span2">
+ <%= render :partial => 'shared/graphs/sparkline', :locals => { :points => @project.calls.analyzed_hourly_report.to_a.map{|x| x[1] } } %>
+ Analysis/Hour
+ </div>
+ <div class="span2">
+ <%= render :partial => 'shared/graphs/sparkline', :locals => { :points => @project.calls.analyzed_daily_report.to_a.map{|x| x[1] } } %>
+ Analysis/Day
+ </div>
+ <div class="span2">
+ <%= render :partial => 'shared/graphs/sparkline', :locals => { :points => @project.calls.analyzed_weekly_report.to_a.map{|x| x[1] } } %>
+ Analysis/Week
+ </div>
+</div>
(DIR) diff --git a/app/views/shared/graphs/_call_results.html.erb b/app/views/shared/graphs/_call_results.html.erb
@@ -12,9 +12,6 @@ line_data << raw("{ name: 'Answered', data: [ #{@call_results[:Answered].to_i.to
<div id="<%= graph_id %>"></div>
<%= javascript_tag do %>
-
- $(function () {
- var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
@@ -53,8 +50,4 @@ line_data << raw("{ name: 'Answered', data: [ #{@call_results[:Answered].to_i.to
series: [ <%= line_data %> ]
});
});
-
-});
-
-
<% end %>
(DIR) diff --git a/app/views/shared/graphs/_lines_by_type.html.erb b/app/views/shared/graphs/_lines_by_type.html.erb
@@ -13,8 +13,6 @@ end
<%= javascript_tag do %>
- $(function () {
- var chart;
$(document).ready(function() {
chart = new Highcharts.Chart({
chart: {
@@ -54,7 +52,4 @@ end
});
});
-});
-
-
<% end %>
(DIR) diff --git a/app/views/shared/graphs/_sparkline.html.erb b/app/views/shared/graphs/_sparkline.html.erb
@@ -0,0 +1,67 @@
+<% graph_id = "g" + rand(0x10000000).to_s %>
+
+<div class="sparkline" id="<%= graph_id %>"></div>
+
+<%= javascript_tag do %>
+ $(document).ready(function() {
+ var chart = new Highcharts.Chart({
+ chart: {
+ renderTo: '<%= graph_id %>',
+ defaultSeriesType: 'area',
+ margin:[0,0,0,0],
+ // borderWidth: 0;
+ },
+ title:{
+ text:''
+ },
+ credits:{
+ enabled:false
+ },
+ xAxis: {
+ labels: {
+ enabled:false
+ }
+ },
+ yAxis: {
+ maxPadding:0,
+ minPadding:0,
+ endOnTick:false,
+ labels: {
+ enabled:false
+ }
+ },
+ legend: {
+ enabled:false
+ },
+ tooltip: {
+ enabled:false
+ },
+ plotOptions: {
+ series:{
+ lineWidth:1,
+ shadow:false,
+ states:{
+ hover:{
+ lineWidth:1
+ }
+ },
+ marker:{
+ //enabled:false,
+ radius:1,
+ states:{
+ hover:{
+ radius:2
+ }
+ }
+ }
+ }
+ },
+ series: [{
+ color:'#666',
+ fillColor:'rgba(204,204,204,.25)',
+ data: [ <%= raw(points.join(", ")) %> ]
+ }]
+ });
+});
+
+<% end %>
(DIR) diff --git a/db/migrate/20121228171549_initial_schema.rb b/db/migrate/20121228171549_initial_schema.rb
@@ -94,8 +94,8 @@ class InitialSchema < ActiveRecord::Migration
# Generated by the analysis job
t.integer "analysis_job_id"
- t.boolean "analysis_started_at"
- t.boolean "analysis_completed_at"
+ t.timestamp "analysis_started_at"
+ t.timestamp "analysis_completed_at"
t.float "peak_freq"
t.text "peak_freq_data"
t.text "line_type"
@@ -140,9 +140,33 @@ class InitialSchema < ActiveRecord::Migration
t.boolean "enabled", :default => true
end
+ add_index :jobs, :project_id
+ add_index :lines, :number
+ add_index :lines, :project_id
+ add_index :line_attributes, :line_id
+ add_index :line_attributes, :project_id
+ add_index :calls, :number
+ add_index :calls, :job_id
+ add_index :calls, :provider_id
+ add_index :call_media, :call_id
+ add_index :call_media, :project_id
+ add_index :signature_fp, :signature_id
+
end
def down
+ remove_index :jobs, :project_id
+ remove_index :lines, :number
+ remove_index :lines, :project_id
+ remove_index :line_attributes, :line_id
+ remove_index :line_attributes, :project_id
+ remove_index :calls, :number
+ remove_index :calls, :job_id
+ remove_index :calls, :provider_id
+ remove_index :call_media, :call_id
+ remove_index :call_media, :project_id
+ remove_index :signature_fp, :signature_id
+
drop_table "providers"
drop_table "signature_fp"
drop_table "signatures"
(DIR) diff --git a/db/migrate/20130106000000_add_indexes.rb b/db/migrate/20130106000000_add_indexes.rb
@@ -1,29 +0,0 @@
-class AddIndexes < ActiveRecord::Migration
- def up
- add_index :jobs, :project_id
- add_index :lines, :number
- add_index :lines, :project_id
- add_index :line_attributes, :line_id
- add_index :line_attributes, :project_id
- add_index :calls, :number
- add_index :calls, :job_id
- add_index :calls, :provider_id
- add_index :call_media, :call_id
- add_index :call_media, :project_id
- add_index :signature_fp, :signature_id
- end
-
- def down
- remove_index :jobs, :project_id
- remove_index :lines, :number
- remove_index :lines, :project_id
- remove_index :line_attributes, :line_id
- remove_index :line_attributes, :project_id
- remove_index :calls, :number
- remove_index :calls, :job_id
- remove_index :calls, :provider_id
- remove_index :call_media, :call_id
- remove_index :call_media, :project_id
- remove_index :signature_fp, :signature_id
- end
-end
(DIR) diff --git a/db/migrate/20130113004653_create_reportable_cache.rb b/db/migrate/20130113004653_create_reportable_cache.rb
@@ -0,0 +1,40 @@
+class CreateReportableCache < ActiveRecord::Migration
+
+ def self.up
+ create_table :reportable_cache, :force => true do |t|
+ t.string :model_name, :null => false, :limit => 100
+ t.string :report_name, :null => false, :limit => 100
+ t.string :grouping, :null => false, :limit => 10
+ t.string :aggregation, :null => false, :limit => 10
+ t.string :conditions, :null => false, :limit => 100
+ t.float :value, :null => false, :default => 0
+ t.datetime :reporting_period, :null => false
+
+ t.timestamps
+ end
+
+ add_index :reportable_cache, [
+ :model_name,
+ :report_name,
+ :grouping,
+ :aggregation,
+ :conditions
+ ], :name => :name_model_grouping_agregation
+ add_index :reportable_cache, [
+ :model_name,
+ :report_name,
+ :grouping,
+ :aggregation,
+ :conditions,
+ :reporting_period
+ ], :unique => true, :name => :name_model_grouping_aggregation_period
+ end
+
+ def self.down
+ remove_index :reportable_cache, :name => :name_model_grouping_agregation
+ remove_index :reportable_cache, :name => :name_model_grouping_aggregation_period
+
+ drop_table :reportable_cache
+ end
+
+end
(DIR) diff --git a/db/schema.rb b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20130106000000) do
+ActiveRecord::Schema.define(:version => 20130113004653) do
add_extension "intarray"
@@ -44,8 +44,8 @@ ActiveRecord::Schema.define(:version => 20130106000000) do
t.integer "ring_length"
t.text "caller_id"
t.integer "analysis_job_id"
- t.boolean "analysis_started_at"
- t.boolean "analysis_completed_at"
+ t.datetime "analysis_started_at"
+ t.datetime "analysis_completed_at"
t.float "peak_freq"
t.text "peak_freq_data"
t.text "line_type"
@@ -121,6 +121,21 @@ ActiveRecord::Schema.define(:version => 20130106000000) do
t.boolean "enabled", :default => true
end
+ create_table "reportable_cache", :force => true do |t|
+ t.string "model_name", :limit => 100, :null => false
+ t.string "report_name", :limit => 100, :null => false
+ t.string "grouping", :limit => 10, :null => false
+ t.string "aggregation", :limit => 10, :null => false
+ t.string "conditions", :limit => 100, :null => false
+ t.float "value", :default => 0.0, :null => false
+ t.datetime "reporting_period", :null => false
+ t.datetime "created_at", :null => false
+ t.datetime "updated_at", :null => false
+ end
+
+ add_index "reportable_cache", ["model_name", "report_name", "grouping", "aggregation", "conditions", "reporting_period"], :name => "name_model_grouping_aggregation_period", :unique => true
+ add_index "reportable_cache", ["model_name", "report_name", "grouping", "aggregation", "conditions"], :name => "name_model_grouping_agregation"
+
create_table "settings", :force => true do |t|
t.string "var", :null => false
t.text "value"
(DIR) diff --git a/lib/warvox/jobs/analysis.rb b/lib/warvox/jobs/analysis.rb
@@ -148,7 +148,7 @@ class Analysis < Base
def run_analyze_call(cid, jid)
- dr = Call.find(cid)
+ dr = Call.find(cid, :include => :job)
dr.analysis_started_at = Time.now.utc
dr.analysis_job_id = jid
dr.save