use web app for bans, not system

This commit is contained in:
Kyle Drake 2014-06-27 21:23:28 -04:00
parent ab95fa01af
commit a420132632
5 changed files with 26 additions and 8 deletions

13
app.rb
View file

@ -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, <a href="/contact">contact the site admin</a>.'
redirect '/'
end
end
def title
out = "Neocities"
return out if request.path == '/'

View file

@ -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

View file

@ -1,5 +1,5 @@
class Tag < Sequel::Model
NAME_LENGTH_MAX = 25
NAME_LENGTH_MAX = 20
NAME_WORDS_MAX = 2
many_to_many :sites

View file

@ -98,7 +98,7 @@
<div class="alert txt-Center">
<p style="padding:5px">
<% flash.keys.each do |key| %>
<%= flash[key] %>
<%== flash[key] %>
<% end %>
</p>
</div>

View file

@ -119,7 +119,7 @@
<hr>
<p><b>Last thing!</b> Enter these two words correctly (with spaces) so we know you're not a robot (don't worry robots, we still love you).</p>
<p><b>Last thing!</b> Enter the captcha correctly so we know you're not a robot (don't worry robots, we still love you).</p>
<div class="recaptcha">
<%== recaptcha_tag :challenge, ssl: request.ssl? %>