public
Clone URL: git://github.com/defunkt/exception_logger.git
Search Repo:
add RSS feed support

git-svn-id: 
http://svn.techno-weenie.net/projects/plugins/exception_logger@2038 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Sep 03 20:57:56 -0700 2006
commit  e2d703cdf6d96bbb2b21eeb4a3bedcd1cfc65be5
tree    05c0ee2d42230f31af80a36f3dcfd55e5b48c127
parent  89fee3e9213d3fc6e100e7e9ef435d9dc6ed7d6d
0
...
25
26
27
 
 
 
 
 
 
28
 
 
 
 
29
30
31
32
33
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
36
37
...
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
0
@@ -25,13 +25,39 @@
0
   config.after_initialize do
0
     require 'application' unless Object.const_defined?(:ApplicationController)
0
     LoggedExceptionsController.class_eval do
0
+ # set the same session key as the app
0
+ session :session_key => '_beast_session_id'
0
+
0
+ # include any custom auth modules you need
0
+ include AuthenticationSystem
0
+
0
       before_filter :login_required
0
+
0
+ # optional, sets the application name for the rss feeds
0
+ self.application_name = "Beast"
0
+
0
       protected
0
         # only allow admins
0
         # this obviously depends on how your auth system works
0
         def authorized?
0
           current_user.is_a?(Admin)
0
         end
0
+
0
+ # assume app's login required doesn't use http basic
0
+ def login_required_with_basic
0
+ respond_to do |accepts|
0
+ # alias_method_chain will alias the app's login_required to login_required_without_basic
0
+ accepts.html { login_required_without_basic }
0
+
0
+ # access_denied_with_basic_auth is defined in LoggedExceptionsController
0
+ # get_auth_data returns back the user/password pair
0
+ accepts.rss do
0
+ access_denied_with_basic_auth unless self.current_user = User.authenticate(*get_auth_data)
0
+ end
0
+ end
0
+ end
0
+
0
+ alias_method_chain :login_required, :basic
0
     end
0
   end
0
 
...
301
302
303
 
 
 
 
...
301
302
303
304
305
306
307
0
@@ -301,4 +301,8 @@
0
   opacity:.8;
0
   font-size: 11px;
0
 }
0
+
0
+#feed {
0
+ margin-top: 15px;
0
+}
...
1
 
2
3
4
...
10
11
12
 
 
 
 
13
14
15
...
28
29
30
 
 
 
 
 
 
31
32
33
...
42
43
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
...
1
2
3
4
5
...
11
12
13
14
15
16
17
18
19
20
...
33
34
35
36
37
38
39
40
41
42
43
44
...
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
0
@@ -1,4 +1,5 @@
0
 class LoggedExceptionsController < ActionController::Base
0
+ cattr_accessor :application_name
0
   layout nil
0
 
0
   def index
0
@@ -10,6 +11,10 @@
0
   def query
0
     conditions = []
0
     parameters = []
0
+ unless params[:id].blank?
0
+ conditions << 'id = ?'
0
+ parameters << params[:id]
0
+ end
0
     unless params[:query].blank?
0
       conditions << 'message LIKE ?'
0
       parameters << "%#{params[:query]}%"
0
@@ -28,6 +33,12 @@
0
     end
0
     @exception_pages, @exceptions = paginate :logged_exceptions, :order => 'created_at desc', :per_page => 30,
0
       :conditions => conditions.empty? ? nil : parameters.unshift(conditions * ' and ')
0
+
0
+ respond_to do |format|
0
+ format.html { redirect_to :action => 'index' unless action_name == 'index' }
0
+ format.js
0
+ format.rss { render :action => 'query.rxml' }
0
+ end
0
   end
0
   
0
   def show
0
@@ -42,5 +53,31 @@
0
     LoggedException.delete_all ['id in (?)', params[:ids]] unless params[:ids].blank?
0
     query
0
   end
0
+
0
+ private
0
+ def access_denied_with_basic_auth
0
+ headers["Status"] = "Unauthorized"
0
+ headers["WWW-Authenticate"] = %(Basic realm="Web Password")
0
+ render :text => "Could't authenticate you", :status => '401 Unauthorized'
0
+ end
0
+
0
+ # gets BASIC auth info
0
+ def get_auth_data
0
+ user, pass = '', ''
0
+ # extract authorisation credentials
0
+ if request.env.has_key? 'X-HTTP_AUTHORIZATION'
0
+ # try to get it where mod_rewrite might have put it
0
+ authdata = request.env['X-HTTP_AUTHORIZATION'].to_s.split
0
+ elsif request.env.has_key? 'HTTP_AUTHORIZATION'
0
+ # this is the regular location
0
+ authdata = request.env['HTTP_AUTHORIZATION'].to_s.split
0
+ end
0
+
0
+ # at the moment we only support basic authentication
0
+ if authdata && authdata[0] == 'Basic'
0
+ user, pass = Base64.decode64(authdata[1]).split(':')[0..1]
0
+ end
0
+ return [user, pass]
0
+ end
0
 end
...
1
2
 
3
4
5
...
15
16
17
18
19
20
21
22
23
24
25
...
34
35
36
37
38
39
40
41
42
43
44
...
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
...
1
 
2
3
4
5
...
15
16
17
 
 
 
 
 
18
19
20
...
29
30
31
 
 
 
32
33
34
35
36
...
41
42
43
 
 
 
 
 
 
 
44
45
 
46
47
48
49
50
51
 
 
 
 
 
 
52
53
54
55
0
@@ -1,5 +1,5 @@
0
 <div id="exceptions">
0
-
0
+<%= session[:user_id] ; controller.reset_session %>
0
 <div class="pages">
0
   <%= link_to_remote 'Delete Visible', :url => { :action => 'destroy_all' }, :with => "ExceptionLogger.deleteAll()" %>
0
 <% if @exception_pages.page_count > 1 %>
0
@@ -15,11 +15,6 @@
0
     <tr>
0
       <th>Exception</th>
0
       <th>Date</th>
0
-<!--
0
-      <th></th>
0
-
0
-      <th><%= link_to_function "All", "$$('#exceptions table input').each(function(a){a.checked= (a.checked ? '' : 'checked'); });" %></th>
0
--->
0
     </tr>
0
   </thead>
0
 
0
@@ -34,9 +29,6 @@
0
 
0
 </td>
0
       <td nowrap=nowrap class="time">
0
-<!--
0
-
0
--->
0
 <%
0
 if Date.today == exc.created_at.to_date
0
   if exc.created_at > Time.now - 4.hours
0
0
0
@@ -49,28 +41,15 @@
0
 <%= exc.created_at.strftime("%b %d, %Y") %>
0
 <% end %>
0
 </td>
0
-
0
-
0
-<!--
0
-      <td style="padding-right:0;">
0
-        <input type="checkbox" />
0
-        </td>
0
--->
0
       <td><%= link_to_remote 'Delete', {:url => { :action => 'destroy', :id => exc }} , :class => "util" %></td>
0
 
0
-
0
     </tr>
0
   <% end -%>
0
   </tbody>
0
 
0
 </table>
0
 
0
-<!--
0
-<%= submit_tag "Delete", :style => "float:right;"%>
0
-<br />
0
--->
0
-
0
-<% if @exception_pages.page_count>1 %>
0
+<% if @exception_pages.page_count > 1 %>
0
 <div class="pages pages-bottom">
0
 Pages: <strong><%= pagination_remote_links @exception_pages, :params => { :action => :index } %></strong>
0
 </div>
...
19
20
21
 
 
 
 
22
23
24
...
60
61
62
 
63
64
65
...
19
20
21
22
23
24
25
26
27
28
...
64
65
66
67
68
69
70
0
@@ -19,6 +19,10 @@
0
 
0
 <h3>Filters</h3>
0
 
0
+<ul id="all_exceptions" class="filters">
0
+ <li><%= link_to 'Latest Exceptions', :action => 'index', :id => nil %></li>
0
+</ul>
0
+
0
 <h4>Exception</h4>
0
 
0
 <ul id="exception_names" class="filters">
0
@@ -60,6 +64,7 @@
0
   </form>
0
 </div>
0
 
0
+<%= render :partial => 'feed' %>
0
 
0
 </div> <!-- right -->
0
 
...
1
2
 
...
1
2
3
0
@@ -1,3 +1,4 @@
0
 page[:exceptions].replace :partial => "exceptions"
0
 page[:showpage].hide
0
+page[:feed].replace :partial => 'feed'

Comments

    No one has commented yet.