Class: EgaliteErrorController

Inherits:
Egalite::Controller show all
Defined in:
lib/egalite/errorconsole.rb

Constant Summary

Constants inherited from Egalite::Controller

Egalite::Controller::MIME_TYPES

Instance Attribute Summary

Attributes inherited from Egalite::Controller

#env, #log_values, #params, #req, #template_file

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Egalite::Controller

#after_filter, #after_filter_html, #after_filter_return_value, #cookies, #db, #delegate, #errorlog, #escape_html, #file_form, #filter_on_html_load, #form, #id, #include, #link_to, #notfound, #raw, #redirect, #redirect_permanent, #send_data, #send_file, #session, #table_by_array, #tags, #url_for

Class Method Details

.database=(db) ⇒ Object



6
7
8
# File 'lib/egalite/errorconsole.rb', line 6

def self.database=(db)
  @@database=db
end

.password=(pass) ⇒ Object



3
4
5
# File 'lib/egalite/errorconsole.rb', line 3

def self.password=(pass)
  @@password=pass
end

Instance Method Details

#before_filterObject



9
10
11
12
13
14
# File 'lib/egalite/errorconsole.rb', line 9

def before_filter
  return false unless @@password
  Egalite::Auth::Basic.authorize(req, 'EgaliteError') { |username,password|
    username == 'admin' and password == @@password
  }
end

#delete(md5) ⇒ Object



59
60
61
62
# File 'lib/egalite/errorconsole.rb', line 59

def delete(md5)
  @@database[:logs].filter(:md5 => md5).update(:checked_at => Time.now)
  redirect :action => nil
end

#detail(id) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/egalite/errorconsole.rb', line 63

def detail(id)
  rec = @@database[:logs].filter(:id => id.to_i).first
  return "no record found." unless rec
  raw("<html><body>"+Egalite::HTMLTagBuilder.ul([
    rec[:id],
    rec[:severity],
    rec[:created_at],
    rec[:md5],
    rec[:ipaddress],
    rec[:url],
    rec[:text],
  ]) +"</body></html>")
end

#display(recs) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/egalite/errorconsole.rb', line 24

def display(recs)
  hb = Egalite::HTMLTagBuilder
  raw("<body><html>" +
    table_by_array(
      ['種別番号(詳細)', '発生回数', '内容', 'URL', '削除'],
      recs.map { |rec|
        [hb.a(url_for(:action => :group, :id => rec[:md5]),rec[:md5]),
         rec[:count],
         rec[:text][0..50],
         rec[:url][0..50],
         hb.a(url_for(:action => :delete, :id => rec[:md5]),'削除'),
        ]
      }
    ) + "</body></html>")
end

#frequent(lim) ⇒ Object



43
44
45
46
# File 'lib/egalite/errorconsole.rb', line 43

def frequent(lim)
  lim ||= 100
  display(@@database.fetch("SELECT md5, text, url, count(*) as count FROM logs WHERE checked_at is null AND severity != 'security' GROUP BY md5, text, url ORDER BY count(*) DESC LIMIT ?",lim.to_i))
end

#getObject



15
16
17
18
19
20
21
22
23
# File 'lib/egalite/errorconsole.rb', line 15

def get
  hb = Egalite::HTMLTagBuilder
  raw("<html><body>" + 
    hb.ol([ hb.a('latest','最新エラー一覧'),
            hb.a('frequent','高頻度エラー一覧'),
            hb.a('security','セキュリティエラー一覧'),
            "<form action='detail'>エラー番号: <input type='text' name='id'><input type='submit'></form>",
    ]) + "</body></html>")
end

#group(md5) ⇒ Object



51
52
53
54
55
56
57
58
# File 'lib/egalite/errorconsole.rb', line 51

def group(md5)
  rec = @@database[:logs].filter(:md5 => md5).first
  raw("<html><body>"+Egalite::HTMLTagBuilder.ul([
    rec[:md5],
    rec[:url],
    rec[:text],
  ]) +"</body></html>")
end

#latest(lim) ⇒ Object



39
40
41
42
# File 'lib/egalite/errorconsole.rb', line 39

def latest(lim)
  lim ||= 100
  display(@@database.fetch("SELECT md5, text, url, count(*) as count FROM logs WHERE checked_at is null AND severity != 'security' GROUP BY md5, text, url ORDER BY max(created_at) DESC LIMIT ?",lim.to_i))
end

#security(lim) ⇒ Object



47
48
49
50
# File 'lib/egalite/errorconsole.rb', line 47

def security(lim)
  lim ||= 100
  display(@@database.fetch("SELECT md5, text, url, count(*) as count FROM logs WHERE checked_at is null AND severity == 'security' GROUP BY md5, text, url ORDER BY count(*) DESC LIMIT ?",lim.to_i))
end