mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
Merge pull request #59 from internetee/110331910-whois_reserved_blocked_domains
110331910 whois reserved domains
This commit is contained in:
commit
4095450fb8
5 changed files with 76 additions and 16 deletions
|
@ -2,7 +2,7 @@ class Admin::ReservedDomainsController < AdminController
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
|
|
||||||
def index
|
def index
|
||||||
names = ReservedDomain.pluck(:names).each_with_object({}){|e_h,h| h.merge!(e_h)}
|
names = ReservedDomain.pluck(:name, :password).each_with_object({}){|domain, hash| hash[domain[0]] = domain[1]}
|
||||||
names.names = nil if names.blank?
|
names.names = nil if names.blank?
|
||||||
@reserved_domains = names.to_yaml.gsub(/---.?\n/, '').gsub(/\.\.\..?\n/, '')
|
@reserved_domains = names.to_yaml.gsub(/---.?\n/, '').gsub(/\.\.\..?\n/, '')
|
||||||
end
|
end
|
||||||
|
@ -24,13 +24,12 @@ class Admin::ReservedDomainsController < AdminController
|
||||||
ReservedDomain.transaction do
|
ReservedDomain.transaction do
|
||||||
# removing old ones
|
# removing old ones
|
||||||
existing = ReservedDomain.any_of_domains(names.keys).pluck(:id)
|
existing = ReservedDomain.any_of_domains(names.keys).pluck(:id)
|
||||||
ReservedDomain.where.not(id: existing).delete_all
|
ReservedDomain.where.not(id: existing).destroy_all
|
||||||
|
|
||||||
#updating and adding
|
#updating and adding
|
||||||
names.each do |name, psw|
|
names.each do |name, psw|
|
||||||
rec = ReservedDomain.by_domain(name).first
|
rec = ReservedDomain.find_or_initialize_by(name: name)
|
||||||
rec ||= ReservedDomain.new
|
rec.password = psw
|
||||||
rec.names = {name => psw}
|
|
||||||
|
|
||||||
unless rec.save
|
unless rec.save
|
||||||
result = false
|
result = false
|
||||||
|
@ -39,7 +38,6 @@ class Admin::ReservedDomainsController < AdminController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if result
|
if result
|
||||||
flash[:notice] = I18n.t('record_updated')
|
flash[:notice] = I18n.t('record_updated')
|
||||||
redirect_to :back
|
redirect_to :back
|
||||||
|
|
|
@ -1,25 +1,61 @@
|
||||||
class ReservedDomain < ActiveRecord::Base
|
class ReservedDomain < ActiveRecord::Base
|
||||||
include Versions # version/reserved_domain_version.rb
|
include Versions # version/reserved_domain_version.rb
|
||||||
before_save :fill_empty_passwords
|
before_save :fill_empty_passwords
|
||||||
|
before_save :generate_data
|
||||||
|
before_destroy :remove_data
|
||||||
|
|
||||||
def fill_empty_passwords
|
|
||||||
return unless names
|
|
||||||
names.each { |k, v| names[k] = SecureRandom.hex if v.blank? }
|
|
||||||
end
|
|
||||||
|
|
||||||
class << self
|
class << self
|
||||||
def pw_for(domain_name)
|
def pw_for(domain_name)
|
||||||
name_in_unicode = SimpleIDN.to_ascii(domain_name)
|
name_in_ascii = SimpleIDN.to_ascii(domain_name)
|
||||||
by_domain(domain_name).select("names -> '#{domain_name}' AS pw").first.try(:pw) ||
|
by_domain(domain_name).first.try(:password) || by_domain(name_in_ascii).first.try(:password)
|
||||||
by_domain(name_in_unicode).select("names -> '#{name_in_unicode}' AS pw").first.try(:pw)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def by_domain name
|
def by_domain name
|
||||||
where("names ? '#{name}'")
|
where(name: name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def any_of_domains names
|
def any_of_domains names
|
||||||
where("names ?| ARRAY['#{names.join("','")}']")
|
where(name: names)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def fill_empty_passwords
|
||||||
|
self.password = SecureRandom.hex unless self.password
|
||||||
|
end
|
||||||
|
|
||||||
|
def name= val
|
||||||
|
super SimpleIDN.to_unicode(val)
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_data
|
||||||
|
@json = generate_json
|
||||||
|
@body = generate_body
|
||||||
|
update_whois_server
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_whois_server
|
||||||
|
wr = Whois::Record.find_or_initialize_by(name: name)
|
||||||
|
wr.body = @body
|
||||||
|
wr.json = @json
|
||||||
|
wr.save
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_body
|
||||||
|
template = Rails.root.join("app/views/for_models/whois_other.erb".freeze)
|
||||||
|
ERB.new(template.read, nil, "-").result(binding)
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_json
|
||||||
|
h = HashWithIndifferentAccess.new
|
||||||
|
h[:name] = self.name
|
||||||
|
h[:status] = 'Reserved'
|
||||||
|
h
|
||||||
|
end
|
||||||
|
|
||||||
|
def remove_data
|
||||||
|
Whois::Record.where(name: name).delete_all
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
8
app/views/for_models/whois_other.erb
Normal file
8
app/views/for_models/whois_other.erb
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
Estonia .ee Top Level Domain WHOIS server
|
||||||
|
|
||||||
|
Domain:
|
||||||
|
name: <%= @json['name'] %>
|
||||||
|
status: <%= @json['status'] %>
|
||||||
|
|
||||||
|
Estonia .ee Top Level Domain WHOIS server
|
||||||
|
More information at http://internet.ee
|
|
@ -0,0 +1,18 @@
|
||||||
|
class NameAndPasswordForReservedDomain < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
add_column :reserved_domains, :name, :string
|
||||||
|
add_column :reserved_domains, :password, :string
|
||||||
|
add_index :reserved_domains, :name
|
||||||
|
|
||||||
|
ReservedDomain.find_each do |domain|
|
||||||
|
names = domain.names
|
||||||
|
domain.update_columns(name: names.keys.first, password: names.values.first)
|
||||||
|
end
|
||||||
|
|
||||||
|
remove_column :reserved_domains, :names
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
|
@ -73,7 +73,7 @@ admin3 = {
|
||||||
[admin1, admin2, admin3].each do |at|
|
[admin1, admin2, admin3].each do |at|
|
||||||
admin = AdminUser.where(at)
|
admin = AdminUser.where(at)
|
||||||
next if admin.present?
|
next if admin.present?
|
||||||
admin = AdminUser.new(at.merge({ password_confirmation: 'testtest' }))
|
admin = AdminUser.new(at.merge({ password_confirmation: 'testtest', password: 'testtest' }))
|
||||||
admin.roles = ['admin']
|
admin.roles = ['admin']
|
||||||
admin.save
|
admin.save
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue