public
Clone URL: git://github.com/defunkt/exception_logger.git
technoweenie (author)
Sun Sep 03 20:57:56 -0700 2006
commit  e2d703cdf6d96bbb2b21eeb4a3bedcd1cfc65be5
tree    05c0ee2d42230f31af80a36f3dcfd55e5b48c127
parent  89fee3e9213d3fc6e100e7e9ef435d9dc6ed7d6d
exception_logger / lib / logged_exceptions_controller.rb
100644 82 lines (73 sloc) 2.682 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class LoggedExceptionsController < ActionController::Base
  cattr_accessor :application_name
  layout nil
 
  def index
    @exception_names = LoggedException.find_exception_class_names
    @controller_actions = LoggedException.find_exception_controllers_and_actions
    query
  end
 
  def query
    conditions = []
    parameters = []
    unless params[:id].blank?
      conditions << 'id = ?'
      parameters << params[:id]
    end
    unless params[:query].blank?
      conditions << 'message LIKE ?'
      parameters << "%#{params[:query]}%"
    end
    unless params[:date_ranges_filter].blank?
      conditions << 'created_at >= ?'
      parameters << params[:date_ranges_filter].to_f.days.ago.utc
    end
    unless params[:exception_names_filter].blank?
      conditions << 'exception_class = ?'
      parameters << params[:exception_names_filter]
    end
    unless params[:controller_actions_filter].blank?
      conditions << 'controller_name = ? AND action_name = ?'
      parameters += params[:controller_actions_filter].split('/').collect(&:downcase)
    end
    @exception_pages, @exceptions = paginate :logged_exceptions, :order => 'created_at desc', :per_page => 30,
      :conditions => conditions.empty? ? nil : parameters.unshift(conditions * ' and ')
    
    respond_to do |format|
      format.html { redirect_to :action => 'index' unless action_name == 'index' }
      format.js
      format.rss { render :action => 'query.rxml' }
    end
  end
  
  def show
    @exc = LoggedException.find params[:id]
  end
  
  def destroy
    LoggedException.destroy params[:id]
  end
  
  def destroy_all
    LoggedException.delete_all ['id in (?)', params[:ids]] unless params[:ids].blank?
    query
  end
 
  private
    def access_denied_with_basic_auth
      headers["Status"] = "Unauthorized"
      headers["WWW-Authenticate"] = %(Basic realm="Web Password")
      render :text => "Could't authenticate you", :status => '401 Unauthorized'
    end
 
    # gets BASIC auth info
    def get_auth_data
      user, pass = '', ''
      # extract authorisation credentials
      if request.env.has_key? 'X-HTTP_AUTHORIZATION'
        # try to get it where mod_rewrite might have put it
        authdata = request.env['X-HTTP_AUTHORIZATION'].to_s.split
      elsif request.env.has_key? 'HTTP_AUTHORIZATION'
        # this is the regular location
        authdata = request.env['HTTP_AUTHORIZATION'].to_s.split
      end
       
      # at the moment we only support basic authentication
      if authdata && authdata[0] == 'Basic'
        user, pass = Base64.decode64(authdata[1]).split(':')[0..1]
      end
      return [user, pass]
    end
end