Created
July 28, 2011 17:20
-
-
Save therobot/1112016 to your computer and use it in GitHub Desktop.
Small script that stops denyhosts, delete an ip from all the blacklist files and starts denyhosts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
base_path="/var/lib/denyhosts" | |
hosts_deny="/etc/hosts.deny" | |
denyhosts_files=%w(hosts hosts-restricted hosts-root hosts-valid users-hosts) | |
files=denyhosts_files.map{|file| "#{base_path}/#{file}"}.push hosts_deny | |
denyhosts_stop="/etc/init.d/denyhosts stop" | |
denyhosts_start="/etc/init.d/denyhosts start" | |
if ARGV.length!= 1 | |
puts "Wrong number of arguments" | |
puts "Usage: unban-ip" | |
else | |
`#{denyhosts_stop}` | |
ip=ARGV[0] | |
files.each do |file| | |
text=File.read(file) | |
if file == hosts_deny | |
buffer=text.gsub(/sshd: #{ip}\n/,"") | |
else | |
buffer=text.gsub(/#{ip}:(.*)\n/,"") | |
end | |
File.open(file,"w") {|fw| fw.write buffer } | |
end | |
`#{denyhosts_start}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment