| identify_matches.rb - warvox - VoIP based wardialing tool, forked from rapid7/w… | |
| git clone git://jay.scot/warvox | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| identify_matches.rb (1824B) | |
| --- | |
| 1 #!/usr/bin/env ruby | |
| 2 ################### | |
| 3 | |
| 4 # | |
| 5 # Load the library path | |
| 6 # | |
| 7 base = __FILE__ | |
| 8 while File.symlink?(base) | |
| 9 base = File.expand_path(File.readlink(base), File.dirname(base)) | |
| 10 end | |
| 11 $:.unshift(File.join(File.expand_path(File.dirname(base)), '..', 'lib')) | |
| 12 | |
| 13 require 'warvox' | |
| 14 | |
| 15 ENV['RAILS_ENV'] ||= 'production' | |
| 16 | |
| 17 $:.unshift(File.join(File.expand_path(File.dirname(base)), '..')) | |
| 18 require 'config/boot' | |
| 19 require 'config/environment' | |
| 20 | |
| 21 def usage | |
| 22 $stderr.puts "Usage: #{$0} [job|all] <fprint>" | |
| 23 exit | |
| 24 end | |
| 25 | |
| 26 # | |
| 27 # Script | |
| 28 # | |
| 29 | |
| 30 job = ARGV.shift | |
| 31 fp = ARGV.shift | |
| 32 | |
| 33 if(job and job == "-h") | |
| 34 usage() | |
| 35 end | |
| 36 | |
| 37 if(not job) | |
| 38 $stderr.puts "Listing all available jobs" | |
| 39 $stderr.puts "==========================" | |
| 40 DialJob.find(:all).each do |j| | |
| 41 puts "#{j.id}\t#{j.started_at} --> #{j.completed_at}" | |
| 42 end | |
| 43 exit | |
| 44 end | |
| 45 | |
| 46 fp = $stdin.read.strip if fp == "-" | |
| 47 job = nil if job.downcase == "all" | |
| 48 | |
| 49 if not fp | |
| 50 usage() | |
| 51 end | |
| 52 | |
| 53 | |
| 54 begin | |
| 55 res = nil | |
| 56 job = DialJob.find(job.to_i) if job | |
| 57 if job | |
| 58 res = DialResult.find_by_sql "SELECT dial_results.*, " + | |
| 59 " (( icount('#{fp}'::int[] & dial_results.fprint::int[]) / icount(… | |
| 60 "FROM dial_results " + | |
| 61 "WHERE " + | |
| 62 " icount(dial_results.fprint) > 0 AND " + | |
| 63 " dial_results.dial_job_id = '#{job.id}' " + | |
| 64 "ORDER BY matchscore DESC" | |
| 65 else | |
| 66 res = DialResult.find_by_sql "SELECT dial_results.*, " + | |
| 67 " (( icount('#{fp}'::int[] & dial_results.fprint::int[]) / icount(… | |
| 68 "FROM dial_results " + | |
| 69 "WHERE " + | |
| 70 " icount(dial_results.fprint) > 0 " + | |
| 71 "ORDER BY matchscore DESC" | |
| 72 end | |
| 73 res.each do |r| | |
| 74 $stdout.puts "#{"%.2f" % r.matchscore}\t#{r.dial_job_id}\t#{r.number… | |
| 75 end | |
| 76 rescue ActiveRecord::RecordNotFound | |
| 77 $stderr.puts "Job not found" | |
| 78 exit | |
| 79 end |