Class: CryptedDownload
- Inherits:
-
Object
- Object
- CryptedDownload
- Includes:
- Mongrel::HttpHandlerPlugin
- Defined in:
- lib/mongrel_crypted_download/init.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.generate(file_name, path, uri_prefix, request) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mongrel_crypted_download/init.rb', line 27 def self.generate(file_name, path, uri_prefix, request) secret_string = request..keys.first key=EzCrypto::Key.with_password secret_string, secret_string path=key.encrypt path = 1.minute.from_now.to_i.to_s path = CGI::escape(path) return "#{uri_prefix}/?path=#{path}&file-name=#{file_name}×tamp=#{}" end |
Instance Method Details
#process(request, response) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/mongrel_crypted_download/init.rb', line 8 def process(request, response) query = Mongrel::HttpRequest.query_parse(request.params['QUERY_STRING']) = Mongrel::HttpRequest.query_parse(request.params['HTTP_COOKIE']) secret_string = .keys.first query['path'] = CGI::unescape(query['path']) key=EzCrypto::Key.with_password secret_string, secret_string query['path']=key.decrypt query['path'] if secret_string.nil? or query['timestamp'].nil? or query['path'].nil? response.start(500){} elsif query['timestamp'].to_i < Time.now.to_i response.start(408){} else send_file(File.("." + query['path'] + query['file-name']), response) end end |