class EgaliteErrorController

Public Class Methods

database=(db) click to toggle source
# File lib/egalite/errorconsole.rb, line 6
def self.database=(db)
  @@database=db
end
password=(pass) click to toggle source
# File lib/egalite/errorconsole.rb, line 3
def self.password=(pass)
  @@password=pass
end

Public Instance Methods

before_filter() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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
get() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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