Sha256: 7b8827a409d75af3395a73bd9976f3f5627891b09514b314f8fdf7259133c9a0

Contents?: true

Size: 1.9 KB

Versions: 5

Compression:

Stored size: 1.9 KB

Contents

=begin
                  Arachni
  Copyright (c) 2010-2012 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.1
#
class Log

    class Entry
        include DataMapper::Resource

       def self.default_repository_name
         :log
       end

        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( :log, "sqlite3://#{@settings.db}/log.db" )
        DataMapper.repository( :log ) {
            DataMapper.finalize
            Entry.auto_upgrade!
        }
    end

    def entry
        DataMapper.repository( :log ) { 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

        DataMapper.repository( :log ) {
            Entry.create(
                :action => action,
                :owner  => owner,
                :object => object,
                :client_addr => addr,
                :client_host => host,
                :datestamp   => Time.now.asctime
            )
        }
    end

end

end
end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
arachni-0.4.0.4 lib/arachni/ui/web/log.rb
arachni-0.4.0.3 lib/arachni/ui/web/log.rb
arachni-0.4.0.2 lib/arachni/ui/web/log.rb
arachni-0.4.0.1 lib/arachni/ui/web/log.rb
arachni-0.4 lib/arachni/ui/web/log.rb