Introduction
Introduction Statistics Contact Development Disclaimer Help
analyze_controller.rb - warvox - VoIP based wardialing tool, forked from rapid7…
git clone git://jay.scot/warvox
Log
Files
Refs
README
---
analyze_controller.rb (6328B)
---
1 class AnalyzeController < ApplicationController
2
3 def index
4 @jobs = Job.order('id DESC').paginate(
5 page: params[:page],
6 per_page: 30
7 )
8 end
9
10 def view
11 @job_id = params[:id]
12 @job = Job.find(@job_id)
13 @shown = params[:show]
14
15 if request.format.html?
16 ltypes = Call.select('DISTINCT line_type').where(job_id: @job_id).…
17 res_types = {}
18
19 ltypes.each do |k|
20 next if not k
21 res_types[k.capitalize.to_sym] = Call.where(job_id: @job_id, lin…
22 end
23
24 @lines_by_type = res_types
25 end
26
27 sort_by = params[:sort_by] || 'number'
28 sort_dir = params[:sort_dir] || 'asc'
29
30 @results = []
31 @results_total_count = 0
32
33 if request.format.json?
34
35 @results_total_count = Call.where("job_id = ? AND analysis_complet…
36
37 if params[:iDisplayLength] == '-1'
38 @results_per_page = nil
39 else
40 @results_per_page = (params[:iDisplayLength] || 20).to_i
41 end
42 @results_offset = (params[:iDisplayStart] || 0).to_i
43
44 calls_search
45
46 @results_total_display_count = Call.where(@search_conditions).count()
47 @results = Call.where(@search_conditions).includes(:provider).limit(…
48
49 end
50
51 respond_to do |format|
52 format.html
53 format.json {
54 render content_type: 'application/json', json: render_to_string(…
55 }
56 end
57
58 end
59
60 def view_matches
61 @result = Call.find(params[:call_id])
62 @match_scopes = [
63 { scope: 'job', label: 'This Job' },
64 { scope: 'project', label: 'This Project' },
65 { scope: 'global', label: 'All Projects' }
66 ]
67
68 @job_id = params[:job_id]
69
70 if @job_id
71 @match_scope = params[:match_scope] || "job"
72 else
73 @match_scope = params[:match_scope] || "project"
74 end
75
76 @results = @result.paginate_matches(@match_scope, 30.0, params[:page…
77 end
78
79 def index
80 @shown = params[:show]
81
82 ltypes = Line.select('DISTINCT line_type').where(project_id: @projec…
83 res_types = {}
84
85 ltypes.each do |k|
86 next if not k
87 res_types[k.capitalize.to_sym] = Line.where(project_id: @project.i…
88 end
89
90 @lines_by_type = res_types
91
92 sort_by = params[:sort_by] || 'number'
93 sort_dir = params[:sort_dir] || 'asc'
94
95 @results = []
96 @results_total_count = @project.calls.where("analysis_completed_at I…
97
98 if request.format.json?
99 if params[:iDisplayLength] == '-1'
100 @results_per_page = nil
101 else
102 @results_per_page = (params[:iDisplayLength] || 20).to_i
103 end
104 @results_offset = (params[:iDisplayStart] || 0).to_i
105
106 project_search
107 @results = Call.where(@search_conditions).includes(:provider).limi…
108 @results_total_display_count = Call.where(@search_conditions).incl…
109 end
110
111 respond_to do |format|
112 format.html
113 format.json {
114 render content_type: 'application/json', json: render_to_string(…
115 }
116 end
117
118 end
119
120 def resource
121 ctype = 'text/html'
122 cpath = nil
123 cdata = "File not found"
124
125 res = CallMedium.where(call_id: params[:result_id].to_i).first
126
127 if res
128 case params[:rtype]
129 when 'big_sig'
130 ctype = 'image/png'
131 cdata = res.png_sig_freq
132 when 'big_sig_dots'
133 ctype = 'image/png'
134 cdata = res.png_big_dots
135 when 'small_sig'
136 ctype = 'image/png'
137 cdata = res.png_sig
138 when 'big_freq'
139 ctype = 'image/png'
140 cdata = res.png_big_freq
141 when 'small_freq'
142 ctype = 'image/png'
143 cdata = res.png_sig_freq
144 when 'mp3'
145 ctype = 'audio/mpeg'
146 cdata = res.mp3
147 when 'sig'
148 ctype = 'text/plain'
149 cdata = res.fprint
150 when 'raw'
151 ctype = 'octet/binary-stream'
152 cdata = res.audio
153 end
154 end
155
156 send_data(cdata, type: ctype, disposition: 'inline')
157 end
158
159 #
160 # Generate a SQL sort by option based on the incoming DataTables param…
161 #
162 # Returns the SQL String.
163 def calls_sort_option
164 column = case params[:iSortCol_0].to_s
165 when '1'
166 'number'
167 when '2'
168 'line_type'
169 when '3'
170 'peak_freq'
171 end
172 column + ' ' + (params[:sSortDir_0] =~ /^A/i ? 'asc' : 'desc') if co…
173 end
174
175 def calls_search
176 @search_conditions = []
177 terms = params[:sSearch].to_s
178 terms = Shellword.shellwords(terms) rescue terms.split(/\s+/)
179 where = "job_id = ? AND analysis_completed_at IS NOT NULL "
180 param = [ @job_id ]
181 glue = "AND "
182 terms.each do |w|
183 next if w == "undefined"
184 where << glue
185 case w
186 when /^F(\d+)$/i # F2100 = peak frequency between 2095hz and 2…
187 freq = $1.to_i
188 where << "( peak_freq > ? AND peak_freq < ? ) "
189 param << freq - 5.0
190 param << freq + 5.0
191 else
192 where << "( number ILIKE ? OR caller_id ILIKE ? OR line_type I…
193 param << "%#{w}%"
194 param << "%#{w}%"
195 param << "%#{w}%"
196 end
197 glue = "AND " if glue.empty?
198 end
199 @search_conditions = [ where, *param ]
200 end
201
202 def project_search
203 @search_conditions = []
204 terms = params[:sSearch].to_s
205 terms = Shellword.shellwords(terms) rescue terms.split(/\s+/)
206 where = "project_id = ? AND analysis_completed_at IS NOT NULL "
207 param = [ @project.id ]
208 glue = "AND "
209 terms.each do |w|
210 next if w == "undefined"
211 where << glue
212 case w
213 when /^F(\d+)$/i # F2100 = peak frequency between 2095hz and 2…
214 freq = $1.to_i
215 where << "( peak_freq > ? AND peak_freq < ? ) "
216 param << freq - 5.0
217 param << freq + 5.0
218 else
219 where << "( number ILIKE ? OR caller_id ILIKE ? OR line_type I…
220 param << "%#{w}%"
221 param << "%#{w}%"
222 param << "%#{w}%"
223 end
224 glue = "AND " if glue.empty?
225 end
226 @search_conditions = [ where, *param ]
227 end
228
229 end
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.