mirror of
https://github.com/neocities/neocities.git
synced 2025-07-22 10:36:07 +02:00
use web app for bans, not system
This commit is contained in:
parent
ab95fa01af
commit
a420132632
5 changed files with 26 additions and 8 deletions
13
app.rb
13
app.rb
|
@ -336,12 +336,14 @@ end
|
||||||
|
|
||||||
get '/new' do
|
get '/new' do
|
||||||
dashboard_if_signed_in
|
dashboard_if_signed_in
|
||||||
|
require_unbanned_ip
|
||||||
@site = Site.new
|
@site = Site.new
|
||||||
@site.username = params[:username] unless params[:username].nil?
|
@site.username = params[:username] unless params[:username].nil?
|
||||||
erb :'new'
|
erb :'new'
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/create' do
|
post '/create' do
|
||||||
|
require_unbanned_ip
|
||||||
dashboard_if_signed_in
|
dashboard_if_signed_in
|
||||||
@site = Site.new(
|
@site = Site.new(
|
||||||
username: params[:username],
|
username: params[:username],
|
||||||
|
@ -1051,6 +1053,7 @@ def dashboard_if_signed_in
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_login_ajax
|
def require_login_ajax
|
||||||
|
halt 'You are banned.' if Site.banned_ip?(request.ip)
|
||||||
halt 'You are not logged in!' unless signed_in?
|
halt 'You are not logged in!' unless signed_in?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1063,6 +1066,7 @@ def csrf_token
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_login
|
def require_login
|
||||||
|
require_unbanned_ip
|
||||||
redirect '/' unless signed_in?
|
redirect '/' unless signed_in?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1075,6 +1079,15 @@ def current_site
|
||||||
@site ||= Site[id: session[:id]]
|
@site ||= Site[id: session[:id]]
|
||||||
end
|
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
|
def title
|
||||||
out = "Neocities"
|
out = "Neocities"
|
||||||
return out if request.path == '/'
|
return out if request.path == '/'
|
||||||
|
|
|
@ -59,6 +59,8 @@ class Site < Sequel::Model
|
||||||
SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162', '37x37', '146x88', '302x182', '90x63', '82x62', '348x205']
|
SCREENSHOT_RESOLUTIONS = ['235x141', '105x63', '270x162', '37x37', '146x88', '302x182', '90x63', '82x62', '348x205']
|
||||||
THUMBNAIL_RESOLUTIONS = ['105x63', '90x63']
|
THUMBNAIL_RESOLUTIONS = ['105x63', '90x63']
|
||||||
|
|
||||||
|
BANNED_TIME = 2592000 # 30 days in seconds
|
||||||
|
|
||||||
many_to_one :server
|
many_to_one :server
|
||||||
|
|
||||||
many_to_many :tags
|
many_to_many :tags
|
||||||
|
@ -103,6 +105,13 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
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)
|
def is_following?(site)
|
||||||
followings_dataset.select(:id).filter(site_id: site.id).first ? true : false
|
followings_dataset.select(:id).filter(site_id: site.id).first ? true : false
|
||||||
end
|
end
|
||||||
|
@ -186,11 +195,7 @@ class Site < Sequel::Model
|
||||||
DB.transaction {
|
DB.transaction {
|
||||||
FileUtils.mv files_path, File.join(PUBLIC_ROOT, 'banned_sites', username)
|
FileUtils.mv files_path, File.join(PUBLIC_ROOT, 'banned_sites', username)
|
||||||
self.is_banned = true
|
self.is_banned = true
|
||||||
|
self.updated_at = Time.now
|
||||||
if !['127.0.0.1', nil, ''].include? ip
|
|
||||||
`sudo ufw insert 1 deny from #{ip}`
|
|
||||||
end
|
|
||||||
|
|
||||||
save(validate: false)
|
save(validate: false)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class Tag < Sequel::Model
|
class Tag < Sequel::Model
|
||||||
NAME_LENGTH_MAX = 25
|
NAME_LENGTH_MAX = 20
|
||||||
NAME_WORDS_MAX = 2
|
NAME_WORDS_MAX = 2
|
||||||
many_to_many :sites
|
many_to_many :sites
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@
|
||||||
<div class="alert txt-Center">
|
<div class="alert txt-Center">
|
||||||
<p style="padding:5px">
|
<p style="padding:5px">
|
||||||
<% flash.keys.each do |key| %>
|
<% flash.keys.each do |key| %>
|
||||||
<%= flash[key] %>
|
<%== flash[key] %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -119,7 +119,7 @@
|
||||||
|
|
||||||
<hr>
|
<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">
|
<div class="recaptcha">
|
||||||
<%== recaptcha_tag :challenge, ssl: request.ssl? %>
|
<%== recaptcha_tag :challenge, ssl: request.ssl? %>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue