class SshGuard::Core
Attributes
database[R]
firewall[R]
Public Class Methods
i_am_root?()
click to toggle source
# File lib/ssh_guard.rb, line 47 def self.i_am_root? `whoami` =~ /^root$/ end
new()
click to toggle source
# File lib/ssh_guard.rb, line 19 def initialize unless i_am_root? raise "ssh_guard should be started as root!!!" end @database = Database.new @parser = Parser.new @firewall = FirewallAdapters::IPFWAdapter.new @log_file = "/var/log/secure.log" end
Public Instance Methods
<<(line)
click to toggle source
# File lib/ssh_guard.rb, line 29 def <<(line) if entry = @parser.parse_line(line) if database.should_block? entry[:ip_address] firewall.block_host entry[:ip_address] unless firewall.blocked?(entry[:ip_address]) else database.add_entry(entry) unless firewall.blocked?(entry[:ip_address]) end end end
i_am_root?()
click to toggle source
# File lib/ssh_guard.rb, line 50 def i_am_root? self.class.i_am_root? end
start()
click to toggle source
# File lib/ssh_guard.rb, line 39 def start IO.popen("tail -f #{@log_file}") do |f| while line = f.gets self << line if line =~ /sshd/ end end end