mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
punycode support for domains, validate for registered domains
This commit is contained in:
parent
19638ff712
commit
fda95b7f07
6 changed files with 22 additions and 7 deletions
1
Gemfile
1
Gemfile
|
@ -36,6 +36,7 @@ gem 'base32'
|
|||
gem 'coveralls', require: false
|
||||
gem 'sanitize'
|
||||
gem 'will_paginate'
|
||||
gem 'simpleidn'
|
||||
|
||||
platform :mri, :rbx do
|
||||
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic
|
||||
|
|
|
@ -175,6 +175,7 @@ GEM
|
|||
json (~> 1.8)
|
||||
simplecov-html (~> 0.10.0)
|
||||
simplecov-html (0.10.0)
|
||||
simpleidn (0.0.6)
|
||||
sinatra (1.4.6)
|
||||
rack (~> 1.4)
|
||||
rack-protection (~> 1.4)
|
||||
|
@ -277,6 +278,7 @@ DEPENDENCIES
|
|||
shotgun
|
||||
sidekiq
|
||||
simplecov
|
||||
simpleidn
|
||||
sinatra
|
||||
sinatra-flash
|
||||
sinatra-xsendfile
|
||||
|
|
2
Rakefile
2
Rakefile
|
@ -69,7 +69,7 @@ desc 'Compile domain map for nginx'
|
|||
task :compile_domain_map => [:environment] do
|
||||
File.open('./files/map.txt', 'w') do |file|
|
||||
Site.exclude(domain: nil).exclude(domain: '').select(:username,:domain).all.collect do |site|
|
||||
file.write ".#{site.domain} #{site.username};\n"
|
||||
file.write ".#{site.values[:domain]} #{site.username};\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -102,7 +102,6 @@ end
|
|||
get '/api/info' do
|
||||
if params[:sitename]
|
||||
site = Site[username: params[:sitename]]
|
||||
|
||||
api_error 400, 'site_not_found', "could not find site #{params[:sitename]}" if site.nil? || site.is_banned
|
||||
api_success api_info_for(site)
|
||||
else
|
||||
|
|
|
@ -225,6 +225,16 @@ post '/settings/:username/custom_domain' do
|
|||
|
||||
@site.domain = params[:domain]
|
||||
|
||||
begin
|
||||
Socket.gethostbyname @site.values[:domain]
|
||||
rescue SocketError => e
|
||||
if e.message =~ /name or service not known/i
|
||||
flash[:error] = 'Domain needs to be valid and already registered.'
|
||||
redirect "/settings/#{@site.username}#custom_domain"
|
||||
end
|
||||
raise e
|
||||
end
|
||||
|
||||
if @site.valid?
|
||||
@site.save_changes
|
||||
flash[:success] = 'The domain has been successfully updated.'
|
||||
|
|
|
@ -812,6 +812,14 @@ class Site < Sequel::Model
|
|||
# super
|
||||
# end
|
||||
|
||||
def domain=(domain)
|
||||
super SimpleIDN.to_ascii(domain)
|
||||
end
|
||||
|
||||
def domain
|
||||
SimpleIDN.to_unicode values[:domain]
|
||||
end
|
||||
|
||||
def validate
|
||||
super
|
||||
|
||||
|
@ -864,15 +872,10 @@ class Site < Sequel::Model
|
|||
end
|
||||
|
||||
if !values[:domain].nil? && !values[:domain].empty?
|
||||
|
||||
if values[:domain] =~ /neocities\.org/ || values[:domain] =~ /neocitiesops\.net/
|
||||
errors.add :domain, "Domain is already being used.. by Neocities."
|
||||
end
|
||||
|
||||
if !(values[:domain] =~ /^[a-zA-Z0-9.-]+\.[a-zA-Z0-9]+$/i) || values[:domain].length > 90
|
||||
errors.add :domain, "Domain provided is not valid. Must take the form of domain.com"
|
||||
end
|
||||
|
||||
site = Site[domain: values[:domain]]
|
||||
if !site.nil? && site.id != self.id
|
||||
errors.add :domain, "Domain provided is already being used by another site, please choose another."
|
||||
|
|
Loading…
Add table
Reference in a new issue