diff options
| author | mo khan <mo@mokhan.ca> | 2015-02-04 20:36:55 -0700 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2015-02-04 20:36:55 -0700 |
| commit | 5bb42397569d7f0108178009c0c130128239ab34 (patch) | |
| tree | 25618c49b01bae816d7b87bb4b10e2efab18f891 | |
| parent | a4c55cad877844d8996ac7494ea91a922586a6d0 (diff) | |
add listen to watch filesystem.
| -rw-r--r-- | Gemfile | 1 | ||||
| -rw-r--r-- | Gemfile.lock | 13 | ||||
| -rw-r--r-- | app/controllers/agents/files_controller.rb | 2 | ||||
| -rw-r--r-- | app/workers/cloud_queries.rb | 15 | ||||
| -rw-r--r-- | lib/tasks/scan.rake | 11 |
5 files changed, 31 insertions, 11 deletions
@@ -23,6 +23,7 @@ gem 'jbuilder', '~> 2.0' # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', '~> 0.4.0', group: :doc gem 'typhoeus' +gem 'listen' # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/Gemfile.lock b/Gemfile.lock index dce8439..cb96b48 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -47,6 +47,8 @@ GEM columnize (~> 0.8) debugger-linecache (~> 1.2) slop (~> 3.6) + celluloid (0.16.0) + timers (~> 4.0.0) coffee-rails (4.1.0) coffee-script (>= 2.2.0) railties (>= 4.0.0, < 5.0) @@ -72,6 +74,7 @@ GEM globalid (0.3.0) activesupport (>= 4.1.0) hike (1.2.3) + hitimes (1.2.2) i18n (0.7.0) jbuilder (2.2.6) activesupport (>= 3.0.0, < 5) @@ -81,6 +84,10 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (1.8.2) + listen (2.8.5) + celluloid (>= 0.15.2) + rb-fsevent (>= 0.9.3) + rb-inotify (>= 0.9) loofah (2.0.1) nokogiri (>= 1.5.9) mail (2.6.3) @@ -120,6 +127,9 @@ GEM rake (>= 0.8.7) thor (>= 0.18.1, < 2.0) rake (10.4.2) + rb-fsevent (0.9.4) + rb-inotify (0.9.5) + ffi (>= 0.5.0) rdoc (4.2.0) sass (3.4.11) sass-rails (5.0.1) @@ -154,6 +164,8 @@ GEM thread (0.1.4) thread_safe (0.3.4) tilt (1.4.1) + timers (4.0.1) + hitimes turbolinks (2.5.3) coffee-rails typhoeus (0.7.1) @@ -180,6 +192,7 @@ DEPENDENCIES foundation-rails jbuilder (~> 2.0) jquery-rails + listen pg rails (= 4.2.0) sass-rails (~> 5.0) diff --git a/app/controllers/agents/files_controller.rb b/app/controllers/agents/files_controller.rb index 9afd766..1d711e2 100644 --- a/app/controllers/agents/files_controller.rb +++ b/app/controllers/agents/files_controller.rb @@ -12,7 +12,7 @@ module Agents @file = Disposition.find_by(fingerprint: params[:id]) Publisher.publish("queries", { fingerprint: params[:id], - data: params + payload: params[:payload] }) end diff --git a/app/workers/cloud_queries.rb b/app/workers/cloud_queries.rb index 35102b5..00e6bd2 100644 --- a/app/workers/cloud_queries.rb +++ b/app/workers/cloud_queries.rb @@ -7,13 +7,14 @@ class CloudQueries def work(json) logger.info "Query for: #{json.inspect}" attributes = JSON.parse(json) - fingerprint = attributes["fingerprint"] - disposition = Disposition.find_by(fingerprint: fingerprint) - if disposition.present? - logger.info("#{disposition.state} disposition for: #{fingerprint}") - else - logger.info("Unknown disposition for: #{fingerprint}") - end + #fingerprint = attributes["fingerprint"] + #disposition = Disposition.find_by(fingerprint: fingerprint) + + #if disposition.present? + #logger.info("#{disposition.state} disposition for: #{fingerprint}") + #else + #logger.info("Unknown disposition for: #{fingerprint}") + #end ack! end diff --git a/lib/tasks/scan.rake b/lib/tasks/scan.rake index e357fd4..f3f60ba 100644 --- a/lib/tasks/scan.rake +++ b/lib/tasks/scan.rake @@ -7,10 +7,15 @@ namespace :scan do Dir['**/**/*'].each do |file| if File.file?(file) result = `shasum -a 256 #{file}` - sha = result.split(' ').first + sha, * = result.split(' ') + full_path = File.expand_path(file) - uri = URI("http://localhost:3000/agents/#{agent.id}/files/#{sha}") - puts [sha, Net::HTTP.get(uri)].inspect + url = "http://localhost:3000/agents/#{agent.id}/files/#{sha}" + Typhoeus.get(url, body: { + payload: { + full_path: full_path + } + }) end end end |
