mirror of
https://github.com/neocities/neocities.git
synced 2025-08-06 01:24:56 +02:00
block ips rake task
This commit is contained in:
parent
3095185121
commit
7445f8006b
6 changed files with 60 additions and 6 deletions
28
Rakefile
28
Rakefile
|
@ -1,4 +1,4 @@
|
|||
require "rake/testtask"
|
||||
require 'rake/testtask'
|
||||
|
||||
task :environment do
|
||||
require './environment.rb'
|
||||
|
@ -53,3 +53,29 @@ task :update_screenshots => [:environment] do
|
|||
ScreenshotWorker.perform_async s.username
|
||||
}
|
||||
end
|
||||
|
||||
desc 'Update banned IPs list'
|
||||
task :update_blocked_ips => [:environment] do
|
||||
|
||||
uri = URI.parse('http://www.stopforumspam.com/downloads/listed_ip_90.zip')
|
||||
blocked_ips_zip = Tempfile.new('blockedipszip', Dir.tmpdir, 'wb')
|
||||
blocked_ips_zip.binmode
|
||||
|
||||
Net::HTTP.start(uri.host, uri.port) do |http|
|
||||
resp = http.get(uri.path)
|
||||
blocked_ips_zip.write(resp.body)
|
||||
blocked_ips_zip.flush
|
||||
end
|
||||
|
||||
Zip::File.open(blocked_ips_zip.path) do |zip_file|
|
||||
ips = zip_file.glob('listed_ip_90.txt').first.get_input_stream.read
|
||||
insert_hashes = []
|
||||
ips.each_line {|ip| insert_hashes << {ip: ip.strip, created_at: Time.now}}
|
||||
ips = nil
|
||||
|
||||
DB.transaction do
|
||||
DB[:blocked_ips].delete
|
||||
DB[:blocked_ips].multi_insert insert_hashes
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue