Class: SshGuard::FirewallAdapters::IPFWAdapter
- Inherits:
-
Object
- Object
- SshGuard::FirewallAdapters::IPFWAdapter
- Defined in:
- lib/ssh_guard/firewall_adapters.rb
Instance Method Summary collapse
- #block_host(host) ⇒ Object
- #blocked?(host) ⇒ Boolean
-
#initialize ⇒ IPFWAdapter
constructor
A new instance of IPFWAdapter.
Constructor Details
#initialize ⇒ IPFWAdapter
Returns a new instance of IPFWAdapter.
4 5 6 |
# File 'lib/ssh_guard/firewall_adapters.rb', line 4 def initialize @logger = Logger.new(STDOUT) end |
Instance Method Details
#block_host(host) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/ssh_guard/firewall_adapters.rb', line 7 def block_host(host) unless blocked?(host) `ipfw add 100 deny tcp from #{host} to me ssh` @logger.warn("Blocking host #{host}!") end end |
#blocked?(host) ⇒ Boolean
14 15 16 |
# File 'lib/ssh_guard/firewall_adapters.rb', line 14 def blocked?(host) `ipfw list | grep "deny tcp from #{host} to me dst-port 22"` =~ /deny tcp from #{host} to me dst-port 22$/ ? true : false end |