diff --git a/app.rb b/app.rb index a53d1db2..4cf026a8 100644 --- a/app.rb +++ b/app.rb @@ -336,12 +336,14 @@ end get '/new' do dashboard_if_signed_in + require_unbanned_ip @site = Site.new @site.username = params[:username] unless params[:username].nil? erb :'new' end post '/create' do + require_unbanned_ip dashboard_if_signed_in @site = Site.new( username: params[:username], @@ -1051,6 +1053,7 @@ def dashboard_if_signed_in end def require_login_ajax + halt 'You are banned.' if Site.banned_ip?(request.ip) halt 'You are not logged in!' unless signed_in? end @@ -1063,6 +1066,7 @@ def csrf_token end def require_login + require_unbanned_ip redirect '/' unless signed_in? end @@ -1075,6 +1079,15 @@ def current_site @site ||= Site[id: session[:id]] end +def require_unbanned_ip + if Site.banned_ip?(request.ip) + session[:id] = nil + flash[:error] = 'Your IP address has been banned due to misconduct. '+ + 'If you believe this to be in error, contact the site admin.' + redirect '/' + end +end + def title out = "Neocities" return out if request.path == '/' diff --git a/models/site.rb b/models/site.rb index 4def7d66..fd28fdd8 100644 --- a/models/site.rb +++ b/models/site.rb @@ -59,6 +59,8 @@ class Site < Sequel::Model SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162', '37x37', '146x88', '302x182', '90x63', '82x62', '348x205'] THUMBNAIL_RESOLUTIONS = ['105x63', '90x63'] + BANNED_TIME = 2592000 # 30 days in seconds + many_to_one :server many_to_many :tags @@ -103,6 +105,13 @@ class Site < Sequel::Model end end + def self.banned_ip?(ip) + !Site.where(is_banned: true). + where(ip: ip). + where(['updated_at > ?', Time.now-BANNED_TIME]). + first.nil? + end + def is_following?(site) followings_dataset.select(:id).filter(site_id: site.id).first ? true : false end @@ -186,11 +195,7 @@ class Site < Sequel::Model DB.transaction { FileUtils.mv files_path, File.join(PUBLIC_ROOT, 'banned_sites', username) self.is_banned = true - - if !['127.0.0.1', nil, ''].include? ip - `sudo ufw insert 1 deny from #{ip}` - end - + self.updated_at = Time.now save(validate: false) } end diff --git a/models/tag.rb b/models/tag.rb index 1da21af6..89371cd9 100644 --- a/models/tag.rb +++ b/models/tag.rb @@ -1,5 +1,5 @@ class Tag < Sequel::Model - NAME_LENGTH_MAX = 25 + NAME_LENGTH_MAX = 20 NAME_WORDS_MAX = 2 many_to_many :sites diff --git a/views/index.erb b/views/index.erb index 11b0f2bb..5fce8f86 100644 --- a/views/index.erb +++ b/views/index.erb @@ -98,7 +98,7 @@
<% flash.keys.each do |key| %> - <%= flash[key] %> + <%== flash[key] %> <% end %>
Last thing! Enter these two words correctly (with spaces) so we know you're not a robot (don't worry robots, we still love you).
+Last thing! Enter the captcha correctly so we know you're not a robot (don't worry robots, we still love you).