Commit 65840126 authored by Steve Kemp's avatar Steve Kemp
Browse files

Correctly give new entries an .auto suffix.

parent 573113c0
#!/usr/bin/ruby
#
#
# NAME
#
# firewall-whitelist -- Automatically whitelist IP addresses.
......@@ -85,7 +85,7 @@ expired = 0
if ( File.directory?( $PREFIX ) )
Dir.foreach( $PREFIX ) do |entry|
if ( ( entry =~ /\.auto$/i ) &&
if ( ( entry =~ /\.auto$/i ) &&
(File.mtime( "#{$PREFIX}/#{entry}" ) < ( Time.now - 8 * 24 * 60 * 60 ) ) )
then
puts "Removing #{$PREFIX}/#{entry}" if ( $VERBOSE )
......@@ -105,7 +105,7 @@ ip_addresses = {}
# Run last to find the IPs, store unique ones in a hash.
#
IO.popen("/usr/bin/last -i") {|pipe| pipe.readlines}.each do |l|
next unless l =~ /[ \t]((\d{1,3}\.){3,3}\d{1,3}|[0-9a-f:]+)[ \t]/
next unless l =~ /[ \t]((\d{1,3}\.){3,3}\d{1,3}|[0-9a-f:]+)[ \t]/
ip_addresses[ $1 ] = 1
end
......@@ -124,7 +124,7 @@ ip_addresses.each_key do |ip|
puts "Found IP address: #{ip}" if ( $VERBOSE )
if ( File.exists?( "/etc/symbiosis/firewall/whitelist.d/#{ip}" ) )
if ( File.exists?( "/etc/symbiosis/firewall/whitelist.d/#{ip}.auto" ) )
puts "\tAlready whitelisted" if ( $VERBOSE )
else
# ensure the directory exists.
......@@ -133,7 +133,7 @@ ip_addresses.each_key do |ip|
end
# create the file
system( "touch /etc/symbiosis/firewall/whitelist.d/#{ip}" )
system( "touch /etc/symbiosis/firewall/whitelist.d/#{ip}.auto" )
updated=true
puts "\tAdding to whitelist" if ( $VERBOSE )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment