mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
mechanism to report spam ips to stopforumspam
This commit is contained in:
parent
7be37ce595
commit
bedc08cb58
10 changed files with 38 additions and 25 deletions
1
Gemfile
1
Gemfile
|
@ -45,6 +45,7 @@ gem 'htmlentities'
|
||||||
gem 'rinku'
|
gem 'rinku'
|
||||||
gem 'image_optim'
|
gem 'image_optim'
|
||||||
gem 'image_optim_pack'
|
gem 'image_optim_pack'
|
||||||
|
gem 'ipaddress'
|
||||||
|
|
||||||
platform :mri, :rbx do
|
platform :mri, :rbx do
|
||||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||||
|
|
|
@ -109,6 +109,7 @@ GEM
|
||||||
image_size (1.5.0)
|
image_size (1.5.0)
|
||||||
in_threads (1.3.1)
|
in_threads (1.3.1)
|
||||||
io-extra (1.2.8)
|
io-extra (1.2.8)
|
||||||
|
ipaddress (0.8.3)
|
||||||
jimson-temp (0.9.5)
|
jimson-temp (0.9.5)
|
||||||
blankslate (>= 3.1.2)
|
blankslate (>= 3.1.2)
|
||||||
multi_json (~> 1.0)
|
multi_json (~> 1.0)
|
||||||
|
@ -294,6 +295,7 @@ DEPENDENCIES
|
||||||
image_optim
|
image_optim
|
||||||
image_optim_pack
|
image_optim_pack
|
||||||
io-extra
|
io-extra
|
||||||
|
ipaddress
|
||||||
jdbc-postgres
|
jdbc-postgres
|
||||||
jruby-openssl
|
jruby-openssl
|
||||||
json
|
json
|
||||||
|
@ -346,4 +348,4 @@ DEPENDENCIES
|
||||||
zipruby
|
zipruby
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
1.12.5
|
1.13.7
|
||||||
|
|
9
Rakefile
9
Rakefile
|
@ -266,15 +266,6 @@ task :prime_site_updated_at => [:environment] do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'hash_ips'
|
|
||||||
task :hash_ips => [:environment] do
|
|
||||||
Site.select(:id,:ip).order(:id).all.each do |s|
|
|
||||||
next if s.ip.nil? || s.ip.match(/#{$config['ip_hash_salt']}/)
|
|
||||||
s.ip = s.ip
|
|
||||||
s.save_changes validate: false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
desc 'prime_site_files'
|
desc 'prime_site_files'
|
||||||
task :prime_site_files => [:environment] do
|
task :prime_site_files => [:environment] do
|
||||||
Site.where(is_banned: false).where(is_deleted: false).select(:id, :username).all.each do |site|
|
Site.where(is_banned: false).where(is_deleted: false).select(:id, :username).all.each do |site|
|
||||||
|
|
12
app/admin.rb
12
app/admin.rb
|
@ -236,7 +236,7 @@ post '/admin/banhammer' do
|
||||||
site.ban!
|
site.ban!
|
||||||
deleted_count += 1
|
deleted_count += 1
|
||||||
|
|
||||||
if !params[:ban_using_ips].empty? && !site.ip.empty?
|
if !params[:ban_using_ips].empty? && IPAddress.valid?(site.ip)
|
||||||
sites = Site.filter(ip: site.ip, is_banned: false).all
|
sites = Site.filter(ip: site.ip, is_banned: false).all
|
||||||
sites.each do |s|
|
sites.each do |s|
|
||||||
next if usernames.include?(s.username)
|
next if usernames.include?(s.username)
|
||||||
|
@ -244,6 +244,16 @@ post '/admin/banhammer' do
|
||||||
end
|
end
|
||||||
ip_deleted_count += 1
|
ip_deleted_count += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if params[:classifier] == 'spam' || params[:classifier] == 'phishing'
|
||||||
|
next unless IPAddress.valid?(site.ip)
|
||||||
|
StopForumSpamWorker.perform_async(
|
||||||
|
username: site.username,
|
||||||
|
email: site.email,
|
||||||
|
ip: site.ip,
|
||||||
|
evidence: "#{params[:classifier]}\n#{site.screenshot_url(Site::SCREENSHOT_RESOLUTIONS.first)}"
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
flash[:success] = "#{ip_deleted_count + deleted_count} sites have been banned, including #{ip_deleted_count} matching IPs."
|
flash[:success] = "#{ip_deleted_count + deleted_count} sites have been banned, including #{ip_deleted_count} matching IPs."
|
||||||
|
|
|
@ -257,7 +257,7 @@ post '/site/:username/report' do |username|
|
||||||
redirect request.referer if current_site.id == site.id
|
redirect request.referer if current_site.id == site.id
|
||||||
report.reporting_site_id = current_site.id
|
report.reporting_site_id = current_site.id
|
||||||
else
|
else
|
||||||
report.ip = Site.hash_ip request.ip
|
report.ip = request.ip
|
||||||
end
|
end
|
||||||
|
|
||||||
report.save
|
report.save
|
||||||
|
|
|
@ -24,6 +24,7 @@ development:
|
||||||
education_tag_whitelist:
|
education_tag_whitelist:
|
||||||
- mrteacher
|
- mrteacher
|
||||||
screenshots_url: http://screenshots:derp@127.0.0.1:12345
|
screenshots_url: http://screenshots:derp@127.0.0.1:12345
|
||||||
|
stop_forum_spam_api_key: testkey
|
||||||
test:
|
test:
|
||||||
database: 'postgres://localhost/neocities_test'
|
database: 'postgres://localhost/neocities_test'
|
||||||
database_pool: 1
|
database_pool: 1
|
||||||
|
@ -47,3 +48,4 @@ test:
|
||||||
- 10.0.0.2
|
- 10.0.0.2
|
||||||
education_tag_whitelist:
|
education_tag_whitelist:
|
||||||
- mrteacher
|
- mrteacher
|
||||||
|
stop_forum_spam_api_key: testkey
|
||||||
|
|
|
@ -19,3 +19,4 @@ proxy_ips:
|
||||||
- 10.0.0.2
|
- 10.0.0.2
|
||||||
education_tag_whitelist:
|
education_tag_whitelist:
|
||||||
- mrteacher
|
- mrteacher
|
||||||
|
stop_forum_spam_api_key: testkey
|
||||||
|
|
|
@ -296,19 +296,15 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
|
|
||||||
def ip_create_limit?(ip)
|
def ip_create_limit?(ip)
|
||||||
hashed_ip = hash_ip ip
|
Site.where('created_at > ?', Date.today.to_time).where(ip: ip).count > IP_CREATE_LIMIT ||
|
||||||
Site.where('created_at > ?', Date.today.to_time).where(ip: hashed_ip).count > IP_CREATE_LIMIT ||
|
Site.where(ip: ip).count > TOTAL_IP_CREATE_LIMIT
|
||||||
Site.where(ip: hashed_ip).count > TOTAL_IP_CREATE_LIMIT
|
|
||||||
end
|
|
||||||
|
|
||||||
def hash_ip(ip)
|
|
||||||
SCrypt::Engine.hash_secret ip, $config['ip_hash_salt']
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def banned_ip?(ip)
|
def banned_ip?(ip)
|
||||||
return false if ENV['RACK_ENV'] == 'production' && ip == '127.0.0.1'
|
return false if ENV['RACK_ENV'] == 'production' && ip == '127.0.0.1'
|
||||||
|
return false if ip.blank?
|
||||||
return true if Site.where(is_banned: true).
|
return true if Site.where(is_banned: true).
|
||||||
where(ip: hash_ip(ip)).
|
where(Sequel.or(ip: ip, ip: hash_ip(ip))).
|
||||||
where(['updated_at > ?', Time.now-BANNED_TIME]).
|
where(['updated_at > ?', Time.now-BANNED_TIME]).
|
||||||
first
|
first
|
||||||
|
|
||||||
|
@ -317,6 +313,10 @@ class Site < Sequel::Model
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def hash_ip(ip)
|
||||||
|
SCrypt::Engine.hash_secret ip, $config['ip_hash_salt']
|
||||||
|
end
|
||||||
|
|
||||||
def ssl_sites
|
def ssl_sites
|
||||||
select(:id, :username, :domain, :ssl_key, :ssl_cert).
|
select(:id, :username, :domain, :ssl_key, :ssl_cert).
|
||||||
exclude(domain: nil).
|
exclude(domain: nil).
|
||||||
|
@ -326,10 +326,6 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ip=(ip)
|
|
||||||
super self.class.hash_ip(ip)
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_following?(site)
|
def is_following?(site)
|
||||||
followings_dataset.select(:follows__id).filter(site_id: site.id).first ? true : false
|
followings_dataset.select(:follows__id).filter(site_id: site.id).first ? true : false
|
||||||
end
|
end
|
||||||
|
|
|
@ -60,7 +60,7 @@ describe 'signup' do
|
||||||
site.site_updated_at.must_equal nil
|
site.site_updated_at.must_equal nil
|
||||||
site.is_education.must_equal false
|
site.is_education.must_equal false
|
||||||
|
|
||||||
site.ip.must_equal Site.hash_ip('127.0.0.1')
|
site.ip.must_equal '127.0.0.1'
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails if site with same ip has been banned' do
|
it 'fails if site with same ip has been banned' do
|
||||||
|
|
10
workers/stop_forum_spam_worker.rb
Normal file
10
workers/stop_forum_spam_worker.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
class StopForumSpamWorker
|
||||||
|
include Sidekiq::Worker
|
||||||
|
sidekiq_options queue: :stop_forum_spam, retry: 1, backtrace: true
|
||||||
|
|
||||||
|
def perform(opts)
|
||||||
|
opts.merge! api_key: $config['stop_forum_spam_api_key']
|
||||||
|
res = HTTP.post 'https://stopforumspam.com/add', opts
|
||||||
|
puts res.inspect
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Reference in a new issue