Method: Burp::Util::UploadHandler.handle

Defined in:
app/lib/burp/util/upload_handler.rb

.handle(file_or_file_name, request) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/lib/burp/util/upload_handler.rb', line 9

def self.handle file_or_file_name,request
    
  tempfile = handle_raw_data(file_or_file_name,request)
    
  shasum = `shasum #{tempfile.path}`.match(/^([0-9a-f]{40})/i)[1]
  new_dir = "/tmp/#{shasum}_#{Time.now.to_i}/"
  new_path = "#{new_dir}#{tempfile.original_filename}"  
    

  Dir.mkdir(new_dir)
  FileUtils.mv(tempfile.path,new_path)
    
  tempfile.close(true)
    
  yield(UploadedFile.new(new_path,shasum))
ensure
  File.unlink(new_path) if new_path && File.exist?(new_path)
  Dir.rmdir(new_dir) if new_dir && File.exist?(new_dir)
end