Class: Burp::FilesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Burp::FilesController
- Defined in:
- app/controllers/burp/files_controller.rb
Instance Method Summary collapse
Methods inherited from ApplicationController
Instance Method Details
#create ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/controllers/burp/files_controller.rb', line 58 def create Burp.access.may_upload_a_file! do Util::UploadHandler.handle(params[:qqfile],request) do |file| errors = [] errors << {:size => "File to big, max size is 40 meg"} if file.size > 40.megabyte if errors.length > 0 render :json => {:errors => errors} else FileUtils.mkdir_p(upload_directory_path) FileUtils.mv(file.path,upload_directory_path+File.basename(file.path)) Burp::Util.create_smaller_images(upload_directory_path+File.basename(file.path)) if file.path.match(/(jpg|jpeg|gif|png)$/i) Util.commit("Burp: file upload",:path => upload_directory_path) render :json => {:success => true} end end end end |
#destroy ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/controllers/burp/files_controller.rb', line 22 def destroy file_path = "#{upload_directory_path}#{params[:id].gsub("burp/files/","")}#{params[:format].blank? ? "" : ".#{params[:format]}"}" if File.(file_path) != file_path render :text => "403, Forbiden!", :status => 403, :content_type => "text/plain" else File.unlink(file_path) end Util.commit("Burp: removed a file") redirect_to files_path end |
#index ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/controllers/burp/files_controller.rb', line 9 def index Burp.access.may_view_file_list! do @files = FileModel.all respond_to do |format| format.html {} format.json { render :json => {:paths => @files.map {|file| file.public_path }} } end end end |
#show ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/burp/files_controller.rb', line 36 def show file_path = "#{upload_directory_path}#{params[:id]}#{params[:format].blank? ? "" : ".#{params[:format]}"}" if File.(file_path) != file_path render :text => "403, Forbiden!", :status => 403, :content_type => "text/plain" elsif File.exist?(file_path) Burp.access.may_view_file!(file_path) do headers["Cache-Control"] = "Public" headers["Last-Modified"] = File.mtime(file_path).utc.rfc2822 # Stop session cookie form being set request.[:skip] = true send_file(file_path, :disposition => disposition(file_path)) end else render :text => "404, No such file", :status => 404, :content_type => "text/plain" end end |