Class: Burp::FilesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/burp/files_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#init_body_classes, #menu, #set_site_name

Instance Method Details

#createObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/burp/files_controller.rb', line 59

def create 
  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
        target_path = upload_directory_path + make_url_safe(File.basename(file.path))
        
        FileUtils.mkdir_p(upload_directory_path)
        FileUtils.mv(file.path, target_path)
        FileUtils.chmod(0644, target_path)
        
        Burp::Util.create_smaller_images(target_path) if target_path.match(/(jpg|jpeg|gif|png)$/i)
        
        Util.commit("Burp: file upload", :path => upload_directory_path)
        render :json => {:success => true}
      end
    end
  end
  
end

#destroyObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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.expand_path(file_path) != file_path
    render :text => "403, Forbiden!", :status => 403, :content_type => "text/plain"
  else
    File.unlink(file_path)  
    Util.remove_all_versions_of_image(file_path)
  end
  
  Util.commit("Burp: removed a file")
  
  redirect_to files_path, notice: "#{File.basename(file_path)} has been removed."
end

#indexObject



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/burp/files_controller.rb', line 9

def index
  
  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

#showObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/burp/files_controller.rb', line 37

def show
  file_path = "#{upload_directory_path}#{params[:id]}#{params[:format].blank? ? "" : ".#{params[:format]}"}"
  
  if File.expand_path(file_path) != file_path
    render :text => "403, Forbiden!", :status => 403, :content_type => "text/plain"
  elsif File.exist?(file_path)
    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.session_options[: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