Sha256: 6c35056ab52cb0c5b1dd6e5a572664487201d5700e1db529915d43e6293a5e73

Contents?: true

Size: 1.66 KB

Versions: 1

Compression:

Stored size: 1.66 KB

Contents

=begin
                  Arachni
  Copyright (c) 2010-2011 Tasos "Zapotek" Laskos <tasos.laskos@gmail.com>

  This is free software; you can copy and distribute and modify
  this program under the term of the GPL v2.0 License
  (See LICENSE file for details)

=end

require 'datamapper'

module Arachni
module UI
module Web

#
# A simple logger using DataMapper
#
# @author: Tasos "Zapotek" Laskos
#                                      <tasos.laskos@gmail.com>
#                                      <zapotek@segfault.gr>
# @version: 0.1
#
class Log

    class Entry
        include DataMapper::Resource

        property :id,           Serial
        property :action,       String
        property :object,       String
        property :client_addr,  String
        property :client_host,  String
        property :owner,        String
        property :datestamp,     DateTime
    end


    def initialize( opts, settings )

        @opts     = opts
        @settings = settings

        DataMapper::setup( :default, "sqlite3://#{@settings.db}/log.db" )
        DataMapper.finalize

        Entry.auto_upgrade!
    end

    def entry
        Entry
    end

    def method_missing( sym, *args, &block )

        owner, action = sym.to_s.split( '_', 2 )

        if args && args[1]
            object = args[1]
        end

        if env = args[0]
            addr = env['REMOTE_ADDR']
            host = env['REMOTE_HOST']
        end

        Entry.create(
            :action => action,
            :owner  => owner,
            :object => object,
            :client_addr => addr,
            :client_host => host,
            :datestamp   => Time.now
        )
    end

end

end
end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
arachni-0.2.2.1 lib/ui/web/log.rb