mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
fixes for not found page and ip banner
This commit is contained in:
parent
ead6e41897
commit
b06704f669
2 changed files with 25 additions and 27 deletions
49
app.rb
49
app.rb
|
@ -192,20 +192,20 @@ end
|
||||||
post '/change_name' do
|
post '/change_name' do
|
||||||
require_login
|
require_login
|
||||||
current_username = current_site.username
|
current_username = current_site.username
|
||||||
|
|
||||||
if current_site.username == params[:name]
|
if current_site.username == params[:name]
|
||||||
flash[:error] = 'You already have this name.'
|
flash[:error] = 'You already have this name.'
|
||||||
redirect '/settings'
|
redirect '/settings'
|
||||||
end
|
end
|
||||||
|
|
||||||
current_site.username = params[:name]
|
current_site.username = params[:name]
|
||||||
|
|
||||||
if current_site.valid?
|
if current_site.valid?
|
||||||
DB.transaction {
|
DB.transaction {
|
||||||
current_site.save
|
current_site.save
|
||||||
FileUtils.mv site_base_path(current_username), site_base_path(current_site.username)
|
FileUtils.mv site_base_path(current_username), site_base_path(current_site.username)
|
||||||
}
|
}
|
||||||
|
|
||||||
flash[:success] = "Site/user name has been changed. You will need to use this name to login, <b>don't forget it</b>."
|
flash[:success] = "Site/user name has been changed. You will need to use this name to login, <b>don't forget it</b>."
|
||||||
redirect '/settings'
|
redirect '/settings'
|
||||||
else
|
else
|
||||||
|
@ -390,40 +390,39 @@ get '/admin' do
|
||||||
end
|
end
|
||||||
|
|
||||||
def ban_site(username)
|
def ban_site(username)
|
||||||
site = Site[username: params[:username]]
|
site = Site[username: username]
|
||||||
|
|
||||||
return false if site.nil?
|
return false if site.nil?
|
||||||
return false if site.is_banned
|
return false if site.is_banned == true
|
||||||
|
|
||||||
DB.transaction {
|
DB.transaction {
|
||||||
FileUtils.mv site_base_path(site.username), File.join(settings.public_folder, 'banned_sites', site.username)
|
FileUtils.mv site_base_path(site.username), File.join(settings.public_folder, 'banned_sites', site.username)
|
||||||
site.is_banned = true
|
site.is_banned = true
|
||||||
site.save validate: false
|
site.save(validate: false)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !['127.0.0.1', nil, ''].include? site.ip
|
if !['127.0.0.1', nil, ''].include? site.ip
|
||||||
`sudo ufw insert 1 deny from #{site.ip}`
|
`sudo ufw insert 1 deny from #{site.ip}`
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/admin/banip' do
|
post '/admin/banip' do
|
||||||
require_admin
|
require_admin
|
||||||
site = Site[username: params[:username]]
|
site = Site[username: params[:username]]
|
||||||
|
|
||||||
if site.nil?
|
if site.nil?
|
||||||
flash[:error] = 'User not found'
|
flash[:error] = 'User not found'
|
||||||
redirect '/admin'
|
redirect '/admin'
|
||||||
end
|
end
|
||||||
|
|
||||||
if site.ip.nil? || site.ip.empty?
|
if site.ip.nil? || site.ip.empty?
|
||||||
flash[:error] = 'IP is blank, cannot continue'
|
flash[:error] = 'IP is blank, cannot continue'
|
||||||
redirect '/admin'
|
redirect '/admin'
|
||||||
end
|
end
|
||||||
|
|
||||||
sites = Site.filter(ip: site.ip).all
|
sites = Site.filter(ip: site.ip).all
|
||||||
sites.each {|site| ban_site site.username}
|
sites.each {|s| ban_site(s.username)}
|
||||||
flash[:error] = "#{sites.length} sites have been banned."
|
flash[:error] = "#{sites.length} sites have been banned."
|
||||||
redirect '/admin'
|
redirect '/admin'
|
||||||
end
|
end
|
||||||
|
@ -437,12 +436,12 @@ post '/admin/banhammer' do
|
||||||
flash[:error] = 'User not found'
|
flash[:error] = 'User not found'
|
||||||
redirect '/admin'
|
redirect '/admin'
|
||||||
end
|
end
|
||||||
|
|
||||||
if site.is_banned
|
if site.is_banned
|
||||||
flash[:error] = 'User is already banned'
|
flash[:error] = 'User is already banned'
|
||||||
redirect '/admin'
|
redirect '/admin'
|
||||||
end
|
end
|
||||||
|
|
||||||
ban_site params[:username]
|
ban_site params[:username]
|
||||||
|
|
||||||
flash[:success] = 'MISSION ACCOMPLISHED'
|
flash[:success] = 'MISSION ACCOMPLISHED'
|
||||||
|
@ -512,7 +511,7 @@ get '/password_reset_confirm' do
|
||||||
flash[:error] = 'Could not find a site with this token.'
|
flash[:error] = 'Could not find a site with this token.'
|
||||||
redirect '/'
|
redirect '/'
|
||||||
end
|
end
|
||||||
|
|
||||||
reset_site = Site[password_reset_token: params[:token]]
|
reset_site = Site[password_reset_token: params[:token]]
|
||||||
|
|
||||||
if reset_site.nil?
|
if reset_site.nil?
|
||||||
|
@ -532,7 +531,7 @@ get '/password_reset_confirm' do
|
||||||
else
|
else
|
||||||
flash[:error] = 'Could not find a site with this token.'
|
flash[:error] = 'Could not find a site with this token.'
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect '/'
|
redirect '/'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -545,16 +544,16 @@ post '/custom_domain' do
|
||||||
original_domain = current_site.domain
|
original_domain = current_site.domain
|
||||||
current_site.domain = params[:domain]
|
current_site.domain = params[:domain]
|
||||||
if current_site.valid?
|
if current_site.valid?
|
||||||
|
|
||||||
DB.transaction do
|
DB.transaction do
|
||||||
current_site.save
|
current_site.save
|
||||||
|
|
||||||
if !params[:domain].empty? && !params[:domain].nil?
|
if !params[:domain].empty? && !params[:domain].nil?
|
||||||
File.open(File.join(DIR_ROOT, 'domains', "#{current_site.username}.conf"), 'w') do |file|
|
File.open(File.join(DIR_ROOT, 'domains', "#{current_site.username}.conf"), 'w') do |file|
|
||||||
file.write erb(:'templates/domain', layout: false)
|
file.write erb(:'templates/domain', layout: false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
flash[:success] = 'The domain has been successfully updated.'
|
flash[:success] = 'The domain has been successfully updated.'
|
||||||
redirect '/custom_domain'
|
redirect '/custom_domain'
|
||||||
|
@ -568,17 +567,17 @@ get '/contact' do
|
||||||
end
|
end
|
||||||
|
|
||||||
post '/contact' do
|
post '/contact' do
|
||||||
|
|
||||||
@errors = []
|
@errors = []
|
||||||
|
|
||||||
if params[:email].empty? || params[:subject].empty? || params[:body].empty?
|
if params[:email].empty? || params[:subject].empty? || params[:body].empty?
|
||||||
@errors << 'Please fill out all fields'
|
@errors << 'Please fill out all fields'
|
||||||
end
|
end
|
||||||
|
|
||||||
if !recaptcha_valid?
|
if !recaptcha_valid?
|
||||||
@errors << 'Captcha was not filled out (or was filled out incorrectly)'
|
@errors << 'Captcha was not filled out (or was filled out incorrectly)'
|
||||||
end
|
end
|
||||||
|
|
||||||
if !@errors.empty?
|
if !@errors.empty?
|
||||||
slim :'contact'
|
slim :'contact'
|
||||||
else
|
else
|
||||||
|
@ -589,7 +588,7 @@ post '/contact' do
|
||||||
subject: "[NeoCities Contact]: #{params[:subject]}",
|
subject: "[NeoCities Contact]: #{params[:subject]}",
|
||||||
body: params[:body]
|
body: params[:body]
|
||||||
})
|
})
|
||||||
|
|
||||||
flash[:success] = 'Your contact has been sent.'
|
flash[:success] = 'Your contact has been sent.'
|
||||||
redirect '/'
|
redirect '/'
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,5 +6,4 @@
|
||||||
|
|
||||||
p It you believe this to be in error, please <a href="/contact" title="get in touch with us">contact us</a> and report the problem. Thank you!
|
p It you believe this to be in error, please <a href="/contact" title="get in touch with us">contact us</a> and report the problem. Thank you!
|
||||||
- if request.referer
|
- if request.referer
|
||||||
|
a class="btn-Action" href="#{request.referer}" Go Back
|
||||||
a class="btn-Action" href="#{request.referer}" Go Back
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue