Domain name improvements

This commit is contained in:
Martin Lensment 2014-07-01 17:29:21 +03:00
parent c5355ca8f5
commit 51091679c4
6 changed files with 34 additions and 6 deletions

View file

@ -31,9 +31,12 @@ gem 'jbuilder', '~> 2.0'
# Replacement for erb
gem 'haml-rails', '~> 0.5.3'
#For XML parsing
# For XML parsing
gem 'nokogiri', '~> 1.6.2.1'
# For punycode
gem 'simpleidn', '~> 0.0.5'
group :assets do
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer', platforms: :ruby

View file

@ -141,6 +141,7 @@ GEM
rdoc (~> 4.0, < 5.0)
shoulda-matchers (2.6.1)
activesupport (>= 3.0.0)
simpleidn (0.0.5)
slop (3.5.0)
spring (1.1.3)
sprockets (2.11.0)
@ -195,6 +196,7 @@ DEPENDENCIES
sass-rails (~> 4.0.3)
sdoc (~> 0.4.0)
shoulda-matchers (~> 2.6.1)
simpleidn (~> 0.0.5)
spring
therubyracer
turbolinks

View file

@ -1,7 +1,6 @@
class Domain < ActiveRecord::Base
#TODO whois requests ip whitelist for full info for own domains and partial info for other domains
#TODO most inputs should be trimmed before validatation, probably some global logic?
belongs_to :registrar
belongs_to :ns_set
@ -11,6 +10,13 @@ class Domain < ActiveRecord::Base
validates :name, domain_name: true
def name=(value)
value.strip!
write_attribute(:name, SimpleIDN.to_unicode(value))
write_attribute(:name_puny, SimpleIDN.to_ascii(value))
write_attribute(:name_dirty, value)
end
class << self
def check_availability(domains)
res = []

View file

@ -17,10 +17,19 @@ class DomainNameValidator < ActiveModel::EachValidator
value = value.mb_chars.downcase.strip
general_domains = /(.pri.ee|.edu.ee|.aip.ee|.org.ee|.med.ee|.riik.ee|.ee)/ #TODO Add more general domains here
unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ #äõöüšž
ok = value =~ /\A[a-zA-Z0-9#{unicode_chars}][a-zA-Z0-9#{unicode_chars}-]{0,61}[a-zA-Z0-9#{unicode_chars}]#{general_domains}\z/
ok &&= !(value[2] == '-' && value[3] == '-')
# it's punycode
if value[2] == '-' && value[3] == '-'
regexp = /\Axn--[a-zA-Z0-9-]{0,61}#{general_domains}\z/
return false unless value =~ regexp
value = SimpleIDN.to_unicode(value)
end
unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ #äõöüšž
regexp = /\A[a-zA-Z0-9#{unicode_chars}][a-zA-Z0-9#{unicode_chars}-]{0,61}[a-zA-Z0-9#{unicode_chars}]#{general_domains}\z/
value =~ regexp
end
end
end

View file

@ -0,0 +1,6 @@
class AddNameDirtyToDomains < ActiveRecord::Migration
def change
add_column :domains, :name_dirty, :string
add_column :domains, :name_puny, :string
end
end

View file

@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140627082711) do
ActiveRecord::Schema.define(version: 20140701130945) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -59,6 +59,8 @@ ActiveRecord::Schema.define(version: 20140627082711) do
t.string "auth_info"
t.datetime "created_at"
t.datetime "updated_at"
t.string "name_dirty"
t.string "name_puny"
end
create_table "epp_sessions", force: true do |t|