mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
ability to ban based on IP
This commit is contained in:
parent
6b424a2e88
commit
70d7c0a92f
2 changed files with 41 additions and 11 deletions
42
app.rb
42
app.rb
|
@ -389,19 +389,11 @@ get '/admin' do
|
|||
slim :'admin'
|
||||
end
|
||||
|
||||
post '/admin/banhammer' do
|
||||
require_admin
|
||||
def ban_site(sitename)
|
||||
site = Site[username: params[:username]]
|
||||
|
||||
if site.is_banned
|
||||
flash[:error] = 'User is already banned'
|
||||
redirect '/admin'
|
||||
end
|
||||
|
||||
if site.nil?
|
||||
flash[:error] = 'User not found'
|
||||
redirect '/admin'
|
||||
end
|
||||
return false if site.nil?
|
||||
return false if site.is_banned
|
||||
|
||||
DB.transaction {
|
||||
FileUtils.mv site_base_path(site.username), File.join(settings.public_folder, 'banned_sites', site.username)
|
||||
|
@ -412,6 +404,34 @@ post '/admin/banhammer' do
|
|||
if !['127.0.0.1', nil, ''].include? site.ip
|
||||
`sudo ufw insert 1 deny from #{site.ip}`
|
||||
end
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
post '/admin/banip' do
|
||||
require_admin
|
||||
sites = Site.filter(ip: params[:ip]).all
|
||||
sites.each {|site| ban_site site.username}
|
||||
flash[:error] = "#{sites.length} sites have been banned."
|
||||
redirect '/admin'
|
||||
end
|
||||
|
||||
post '/admin/banhammer' do
|
||||
require_admin
|
||||
|
||||
site = Site[username: params[:username]]
|
||||
|
||||
if site.nil?
|
||||
flash[:error] = 'User not found'
|
||||
redirect '/admin'
|
||||
end
|
||||
|
||||
if site.is_banned
|
||||
flash[:error] = 'User is already banned'
|
||||
redirect '/admin'
|
||||
end
|
||||
|
||||
ban_site params[:username]
|
||||
|
||||
flash[:success] = 'MISSION ACCOMPLISHED'
|
||||
redirect '/admin'
|
||||
|
|
|
@ -14,6 +14,16 @@
|
|||
input type="text" name="username" placeholder="edwardsnowden" autocapitalize="off" autocorrect="off"
|
||||
br
|
||||
input.btn.btn-danger type="submit" value="Ban"
|
||||
|
||||
h3 Ban By IP
|
||||
p All sites with this IP address will be removed.
|
||||
form action="/admin/banip" method="POST"
|
||||
input name="csrf_token" type="hidden" value="#{csrf_token}"
|
||||
p Site Name:
|
||||
input type="text" name="ip" placeholder="3.1.33.7" autocapitalize="off" autocorrect="off"
|
||||
br
|
||||
input.btn.btn-danger type="submit" value="Ban"
|
||||
|
||||
.col.col-50
|
||||
h2 Banned Terrorists
|
||||
.scroll-Admin
|
||||
|
|
Loading…
Add table
Reference in a new issue